roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file server_config_p.h |
| 3 | * @author Roman Janota <janota@cesnet.cz> |
| 4 | * @brief libnetconf2 server configuration |
| 5 | * |
| 6 | * @copyright |
| 7 | * Copyright (c) 2023 CESNET, z.s.p.o. |
| 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | #ifndef NC_CONFIG_SERVER_P_H_ |
| 17 | #define NC_CONFIG_SERVER_P_H_ |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | #include <libyang/libyang.h> |
| 24 | #include <stdint.h> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 25 | #include <stdlib.h> |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 26 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 27 | #include "session_p.h" |
| 28 | |
| 29 | /** |
| 30 | * Enumeration of ietf-netconf-server's modules/trees (top-level containers) |
| 31 | */ |
| 32 | typedef enum { |
| 33 | NC_MODULE_NETCONF_SERVER, |
| 34 | NC_MODULE_KEYSTORE, |
| 35 | NC_MODULE_TRUSTSTORE |
| 36 | } NC_MODULE; |
| 37 | |
| 38 | /** |
| 39 | * @brief Get the pointer to an endpoint structure based on node's location in the YANG data. |
| 40 | * |
| 41 | * @param[in] node Node from which the endpoint containing this node is derived. |
| 42 | * @param[out] endpt Endpoint containing the node. |
| 43 | * @param[out] bind Bind corresponding to the endpoint. Optional. |
| 44 | * @return 0 on success, 1 on error. |
| 45 | */ |
| 46 | int nc_server_config_get_endpt(const struct lyd_node *node, struct nc_endpt **endpt, struct nc_bind **bind); |
| 47 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 48 | #ifdef NC_ENABLED_SSH_TLS |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 49 | /** |
| 50 | * @brief Get the pointer to a hostkey structure based on node's location in the YANG data. |
| 51 | * |
| 52 | * @param[in] node Node from which the hotkey containing this node is derived. |
| 53 | * @param[in] opts Server SSH opts storing the array of the hostkey structures. |
| 54 | * @param[out] hostkey Hostkey containing the node. |
| 55 | * @return 0 on success, 1 on error. |
| 56 | */ |
| 57 | int nc_server_config_get_hostkey(const struct lyd_node *node, const struct nc_server_ssh_opts *opts, struct nc_hostkey **hostkey); |
| 58 | |
| 59 | /** |
| 60 | * @brief Get the pointer to a client authentication structure based on node's location in the YANG data. |
| 61 | * |
| 62 | * @param[in] node Node from which the client-authentication structure containing this node is derived. |
| 63 | * @param[in] opts Server SSH opts storing the array of the client authentication structures. |
| 64 | * @param[out] auth_client Client authentication structure containing the node. |
| 65 | * @return 0 on success, 1 on error. |
| 66 | */ |
| 67 | int nc_server_config_get_auth_client(const struct lyd_node *node, const struct nc_server_ssh_opts *opts, struct nc_client_auth **auth_client); |
| 68 | |
| 69 | /** |
| 70 | * @brief Get the pointer to a client authentication public key structure based on node's location in the YANG data. |
| 71 | * |
| 72 | * @param[in] node Node from which the ca-public key structure containing this node is derived. |
| 73 | * @param[in] auth_client Client authentication structure storing the array of the public key structures. |
| 74 | * @param[out] pubkey Public key structure containing the node. |
| 75 | * @return 0 on success, 1 on error. |
| 76 | */ |
| 77 | int nc_server_config_get_pubkey(const struct lyd_node *node, const struct nc_client_auth *auth_client, struct nc_public_key **pubkey); |
| 78 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 79 | /** |
| 80 | * @brief Get private key type from YANG identity stored in a string. |
| 81 | * |
| 82 | * @param[in] format Value of the YANG identityref. |
| 83 | * @return Private key format on success, NC_PRIVKEY_FORMAT_UNKNOWN otherwise. |
| 84 | */ |
| 85 | NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format); |
| 86 | |
| 87 | #endif /* NC_ENABLED_SSH_TLS */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 88 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 89 | /** |
| 90 | * @brief Compares the nth-parent name. |
| 91 | * |
| 92 | * @param[in] node Node of which nth-parent to compare. |
| 93 | * @param[in] parent_count Count of parents. |
| 94 | * @param[in] parent_name Expected name of the parent. |
| 95 | * @return 1 if the name matches, 0 otherwise. |
| 96 | */ |
| 97 | int equal_parent_name(const struct lyd_node *node, uint16_t parent_count, const char *parent_name); |
| 98 | |
| 99 | /** |
| 100 | * @brief Generic realloc function for arrays of structures representing YANG lists whose first member is the key (char *) |
| 101 | * |
| 102 | * @param[in] key_value Value of the key, which will be assigned to the first member of the given struct. |
| 103 | * @param[in] size Size of a member of the array. |
| 104 | * @param[in,out] ptr Pointer to the beginning of the given array, which will be reallocated. |
| 105 | * @param[in,out] count Count of members in the array, incremented at the end. |
| 106 | * @return 0 on success, 1 on error. |
| 107 | */ |
| 108 | int nc_server_config_realloc(const char *key_value, void **ptr, size_t size, uint16_t *count); |
| 109 | |
| 110 | /** |
| 111 | * @brief Recursively parse the given tree and apply it's data to the server's configuration. |
| 112 | * |
| 113 | * @param[in] node YANG data tree. |
| 114 | * @param[in] parent_op Operation of the parent. |
| 115 | * @param[in] module Module for which to parse the data - either ietf-netconf-server, ietf-keystore or ietf-truststore |
| 116 | * @return 0 on success, 1 on error. |
| 117 | */ |
roman | 0bbc19c | 2023-05-26 09:59:09 +0200 | [diff] [blame] | 118 | int nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op, NC_MODULE module); |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * @brief Configures the listen subtree in the ietf-netconf-server module. |
| 122 | * |
| 123 | * @param[in] node Listen YANG data node. |
| 124 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 125 | * @return 0 on success, 1 on error. |
| 126 | */ |
| 127 | int nc_server_config_listen(struct lyd_node *node, NC_OPERATION op); |
| 128 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 129 | #ifdef NC_ENABLED_SSH_TLS |
| 130 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 131 | /** KEYSTORE **/ |
| 132 | |
| 133 | /** |
| 134 | * @brief Checks if keystore tree is present in the data and if yes, tries to apply it's data. |
| 135 | * |
| 136 | * @param[in] data YANG data tree. |
| 137 | * @param[in] op Operation saying what to do with the top-level node. |
| 138 | * @return 0 either if keystore is not present or if it is and application was successful, 1 on error. |
| 139 | */ |
| 140 | int nc_server_config_fill_keystore(const struct lyd_node *data, NC_OPERATION op); |
| 141 | |
| 142 | /** |
| 143 | * @brief Parse the given node, which belongs to the ietf-keystore subtree, and apply it's data to the server's configuration. |
| 144 | * |
| 145 | * @param[in] node YANG data node. |
| 146 | * @param[in] op Operation saying what to do with the node. |
| 147 | * @return 0 on success, 1 on error. |
| 148 | */ |
| 149 | int nc_server_config_parse_keystore(const struct lyd_node *node, NC_OPERATION op); |
| 150 | |
| 151 | /** |
| 152 | * @brief Configures the keystore subtree in the ietf-keystore module. |
| 153 | * |
| 154 | * @param[in] node Keystore YANG data node. |
| 155 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 156 | * @return 0. |
| 157 | */ |
| 158 | int nc_server_config_ks_keystore(const struct lyd_node *node, NC_OPERATION op); |
| 159 | |
| 160 | /** TRUSTSTORE **/ |
| 161 | |
| 162 | /** |
| 163 | * @brief Checks if truststore tree is present in the data and if yes, tries to apply it's data. |
| 164 | * |
| 165 | * @param[in] data YANG data tree. |
| 166 | * @param[in] op Operation saying what to do with the top-level node. |
| 167 | * @return 0 either if truststore is not present or if it is and application was successful, 1 on error. |
| 168 | */ |
| 169 | int nc_server_config_fill_truststore(const struct lyd_node *data, NC_OPERATION op); |
| 170 | |
| 171 | /** |
| 172 | * @brief Parse the given node, which belongs to the ietf-truststore subtree, and apply it's data to the server's configuration. |
| 173 | * |
| 174 | * @param[in] node YANG data node. |
| 175 | * @param[in] op Operation saying what to do with the node. |
| 176 | * @return 0 on success, 1 on error. |
| 177 | */ |
| 178 | int nc_server_config_parse_truststore(const struct lyd_node *node, NC_OPERATION op); |
| 179 | |
| 180 | /** |
| 181 | * @brief Configures the truststore subtree in the ietf-truststore module. |
| 182 | * |
| 183 | * @param[in] node Truststore YANG data node. |
| 184 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 185 | * @return 0. |
| 186 | */ |
| 187 | int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op); |
| 188 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 189 | #endif /* NC_ENABLED_SSH_TLS */ |
| 190 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 191 | #ifdef __cplusplus |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | #endif /* NC_CONFIG_SERVER_P_H_ */ |