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 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 19 | #include <libyang/libyang.h> |
| 20 | #include <stdint.h> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 21 | #include <stdlib.h> |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 22 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 23 | #include "session_p.h" |
| 24 | |
| 25 | /** |
| 26 | * Enumeration of ietf-netconf-server's modules/trees (top-level containers) |
| 27 | */ |
| 28 | typedef enum { |
| 29 | NC_MODULE_NETCONF_SERVER, |
| 30 | NC_MODULE_KEYSTORE, |
| 31 | NC_MODULE_TRUSTSTORE |
| 32 | } NC_MODULE; |
| 33 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 34 | #ifdef NC_ENABLED_SSH_TLS |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 35 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 36 | /** |
| 37 | * @brief Get private key type from YANG identity stored in a string. |
| 38 | * |
| 39 | * @param[in] format Value of the YANG identityref. |
| 40 | * @return Private key format on success, NC_PRIVKEY_FORMAT_UNKNOWN otherwise. |
| 41 | */ |
| 42 | NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format); |
| 43 | |
| 44 | #endif /* NC_ENABLED_SSH_TLS */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 45 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 46 | /** |
| 47 | * @brief Compares the nth-parent name. |
| 48 | * |
| 49 | * @param[in] node Node of which nth-parent to compare. |
| 50 | * @param[in] parent_count Count of parents. |
| 51 | * @param[in] parent_name Expected name of the parent. |
| 52 | * @return 1 if the name matches, 0 otherwise. |
| 53 | */ |
| 54 | int equal_parent_name(const struct lyd_node *node, uint16_t parent_count, const char *parent_name); |
| 55 | |
| 56 | /** |
| 57 | * @brief Generic realloc function for arrays of structures representing YANG lists whose first member is the key (char *) |
| 58 | * |
| 59 | * @param[in] key_value Value of the key, which will be assigned to the first member of the given struct. |
| 60 | * @param[in] size Size of a member of the array. |
| 61 | * @param[in,out] ptr Pointer to the beginning of the given array, which will be reallocated. |
| 62 | * @param[in,out] count Count of members in the array, incremented at the end. |
| 63 | * @return 0 on success, 1 on error. |
| 64 | */ |
| 65 | int nc_server_config_realloc(const char *key_value, void **ptr, size_t size, uint16_t *count); |
| 66 | |
| 67 | /** |
| 68 | * @brief Recursively parse the given tree and apply it's data to the server's configuration. |
| 69 | * |
| 70 | * @param[in] node YANG data tree. |
| 71 | * @param[in] parent_op Operation of the parent. |
| 72 | * @param[in] module Module for which to parse the data - either ietf-netconf-server, ietf-keystore or ietf-truststore |
| 73 | * @return 0 on success, 1 on error. |
| 74 | */ |
roman | 0bbc19c | 2023-05-26 09:59:09 +0200 | [diff] [blame] | 75 | 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] | 76 | |
| 77 | /** |
| 78 | * @brief Configures the listen subtree in the ietf-netconf-server module. |
| 79 | * |
| 80 | * @param[in] node Listen YANG data node. |
| 81 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 82 | * @return 0 on success, 1 on error. |
| 83 | */ |
roman | 6430c15 | 2023-10-12 11:28:47 +0200 | [diff] [blame] | 84 | int nc_server_config_listen(const struct lyd_node *node, NC_OPERATION op); |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 85 | |
roman | 6430c15 | 2023-10-12 11:28:47 +0200 | [diff] [blame] | 86 | /** |
| 87 | * @brief Configures the Call Home subtree in the ietf-netconf-server module. |
| 88 | * |
| 89 | * @param[in] node call-home YANG data node. |
| 90 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 91 | * @return 0 on success, 1 on error. |
| 92 | */ |
| 93 | int nc_server_config_ch(const struct lyd_node *node, NC_OPERATION op); |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 94 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 95 | #ifdef NC_ENABLED_SSH_TLS |
| 96 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 97 | /** KEYSTORE **/ |
| 98 | |
| 99 | /** |
| 100 | * @brief Checks if keystore tree is present in the data and if yes, tries to apply it's data. |
| 101 | * |
| 102 | * @param[in] data YANG data tree. |
| 103 | * @param[in] op Operation saying what to do with the top-level node. |
| 104 | * @return 0 either if keystore is not present or if it is and application was successful, 1 on error. |
| 105 | */ |
| 106 | int nc_server_config_fill_keystore(const struct lyd_node *data, NC_OPERATION op); |
| 107 | |
| 108 | /** |
| 109 | * @brief Parse the given node, which belongs to the ietf-keystore subtree, and apply it's data to the server's configuration. |
| 110 | * |
| 111 | * @param[in] node YANG data node. |
| 112 | * @param[in] op Operation saying what to do with the node. |
| 113 | * @return 0 on success, 1 on error. |
| 114 | */ |
| 115 | int nc_server_config_parse_keystore(const struct lyd_node *node, NC_OPERATION op); |
| 116 | |
| 117 | /** |
| 118 | * @brief Configures the keystore subtree in the ietf-keystore module. |
| 119 | * |
| 120 | * @param[in] node Keystore YANG data node. |
| 121 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 122 | * @return 0. |
| 123 | */ |
| 124 | int nc_server_config_ks_keystore(const struct lyd_node *node, NC_OPERATION op); |
| 125 | |
| 126 | /** TRUSTSTORE **/ |
| 127 | |
| 128 | /** |
| 129 | * @brief Checks if truststore tree is present in the data and if yes, tries to apply it's data. |
| 130 | * |
| 131 | * @param[in] data YANG data tree. |
| 132 | * @param[in] op Operation saying what to do with the top-level node. |
| 133 | * @return 0 either if truststore is not present or if it is and application was successful, 1 on error. |
| 134 | */ |
| 135 | int nc_server_config_fill_truststore(const struct lyd_node *data, NC_OPERATION op); |
| 136 | |
| 137 | /** |
| 138 | * @brief Parse the given node, which belongs to the ietf-truststore subtree, and apply it's data to the server's configuration. |
| 139 | * |
| 140 | * @param[in] node YANG data node. |
| 141 | * @param[in] op Operation saying what to do with the node. |
| 142 | * @return 0 on success, 1 on error. |
| 143 | */ |
| 144 | int nc_server_config_parse_truststore(const struct lyd_node *node, NC_OPERATION op); |
| 145 | |
| 146 | /** |
| 147 | * @brief Configures the truststore subtree in the ietf-truststore module. |
| 148 | * |
| 149 | * @param[in] node Truststore YANG data node. |
| 150 | * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE. |
| 151 | * @return 0. |
| 152 | */ |
| 153 | int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op); |
| 154 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 155 | #endif /* NC_ENABLED_SSH_TLS */ |
| 156 | |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 157 | #endif /* NC_CONFIG_SERVER_P_H_ */ |