blob: 7866bf990e6dc85f910f6bfab7acd1f15a4e41ad [file] [log] [blame]
romanf02273a2023-05-25 09:44:11 +02001/**
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
20extern "C" {
21#endif
22
23#include <libyang/libyang.h>
24#include <stdint.h>
roman3f9b65c2023-06-05 14:26:58 +020025#include <stdlib.h>
romanf02273a2023-05-25 09:44:11 +020026
romanf02273a2023-05-25 09:44:11 +020027#include "session_p.h"
28
29/**
30 * Enumeration of ietf-netconf-server's modules/trees (top-level containers)
31 */
32typedef 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 */
46int nc_server_config_get_endpt(const struct lyd_node *node, struct nc_endpt **endpt, struct nc_bind **bind);
47
roman3f9b65c2023-06-05 14:26:58 +020048#ifdef NC_ENABLED_SSH
romanf02273a2023-05-25 09:44:11 +020049/**
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 */
57int 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 */
67int 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 */
77int nc_server_config_get_pubkey(const struct lyd_node *node, const struct nc_client_auth *auth_client, struct nc_public_key **pubkey);
78
roman3f9b65c2023-06-05 14:26:58 +020079#endif /* NC_ENABLED_SSH */
80
romanf02273a2023-05-25 09:44:11 +020081/**
82 * @brief Compares the nth-parent name.
83 *
84 * @param[in] node Node of which nth-parent to compare.
85 * @param[in] parent_count Count of parents.
86 * @param[in] parent_name Expected name of the parent.
87 * @return 1 if the name matches, 0 otherwise.
88 */
89int equal_parent_name(const struct lyd_node *node, uint16_t parent_count, const char *parent_name);
90
91/**
roman3f9b65c2023-06-05 14:26:58 +020092 * @brief Get private key type from YANG identity stored in a string.
93 *
94 * @param[in] format Value of the YANG identityref.
95 * @return Private key format on success, NC_PRIVKEY_FORMAT_UNKNOWN otherwise.
96 */
97NC_PRIVKEY_FORMAT nc_server_config_get_private_key_type(const char *format);
98
99/**
romanf02273a2023-05-25 09:44:11 +0200100 * @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 */
108int 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 */
roman0bbc19c2023-05-26 09:59:09 +0200118int nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op, NC_MODULE module);
romanf02273a2023-05-25 09:44:11 +0200119
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 */
127int nc_server_config_listen(struct lyd_node *node, NC_OPERATION op);
128
129/** KEYSTORE **/
130
131/**
132 * @brief Checks if keystore tree is present in the data and if yes, tries to apply it's data.
133 *
134 * @param[in] data YANG data tree.
135 * @param[in] op Operation saying what to do with the top-level node.
136 * @return 0 either if keystore is not present or if it is and application was successful, 1 on error.
137 */
138int nc_server_config_fill_keystore(const struct lyd_node *data, NC_OPERATION op);
139
140/**
141 * @brief Parse the given node, which belongs to the ietf-keystore subtree, and apply it's data to the server's configuration.
142 *
143 * @param[in] node YANG data node.
144 * @param[in] op Operation saying what to do with the node.
145 * @return 0 on success, 1 on error.
146 */
147int nc_server_config_parse_keystore(const struct lyd_node *node, NC_OPERATION op);
148
149/**
150 * @brief Configures the keystore subtree in the ietf-keystore module.
151 *
152 * @param[in] node Keystore YANG data node.
153 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
154 * @return 0.
155 */
156int nc_server_config_ks_keystore(const struct lyd_node *node, NC_OPERATION op);
157
158/** TRUSTSTORE **/
159
160/**
161 * @brief Checks if truststore tree is present in the data and if yes, tries to apply it's data.
162 *
163 * @param[in] data YANG data tree.
164 * @param[in] op Operation saying what to do with the top-level node.
165 * @return 0 either if truststore is not present or if it is and application was successful, 1 on error.
166 */
167int nc_server_config_fill_truststore(const struct lyd_node *data, NC_OPERATION op);
168
169/**
170 * @brief Parse the given node, which belongs to the ietf-truststore subtree, and apply it's data to the server's configuration.
171 *
172 * @param[in] node YANG data node.
173 * @param[in] op Operation saying what to do with the node.
174 * @return 0 on success, 1 on error.
175 */
176int nc_server_config_parse_truststore(const struct lyd_node *node, NC_OPERATION op);
177
178/**
179 * @brief Configures the truststore subtree in the ietf-truststore module.
180 *
181 * @param[in] node Truststore YANG data node.
182 * @param[in] op Operation to be done on the subtree. Only does something if the operation is NC_OP_DELETE.
183 * @return 0.
184 */
185int nc_server_config_ts_truststore(const struct lyd_node *node, NC_OPERATION op);
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* NC_CONFIG_SERVER_P_H_ */