blob: 019db841f20908da2e59f5c76066995b908dc485 [file] [log] [blame]
romanc1d2b092023-02-02 08:58:27 +01001/**
romane028ef92023-02-24 16:33:08 +01002 * @file server_config.h
romanc1d2b092023-02-02 08:58:27 +01003 * @author Roman Janota <janota@cesnet.cz>
4 * @brief libnetconf2 server configuration
5 *
6 * @copyright
7 * Copyright (c) 2015 - 2021 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_H_
17#define NC_CONFIG_SERVER_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#include <libyang/libyang.h>
24#include <stdint.h>
25
26#include "netconf.h"
27#include "session.h"
28#include "session_p.h"
29
30/**
romanf02273a2023-05-25 09:44:11 +020031 * @brief Configure server based on the given diff data.
romanc1d2b092023-02-02 08:58:27 +010032 *
romanf6f37a52023-05-25 14:27:51 +020033 * Expected data are a validated instance of a ietf-netconf-server YANG data.
romanc1d2b092023-02-02 08:58:27 +010034 * The data must be in the diff format and supported operations are: create, replace,
35 * delete and none. Context must already have implemented the required modules, see
36 * ::nc_config_load_modules().
37 *
romanf6f37a52023-05-25 14:27:51 +020038 * @param[in] diff ietf-netconf-server YANG diff data.
romanc1d2b092023-02-02 08:58:27 +010039 * @return 0 on success, 1 on error.
40 */
romanf6f37a52023-05-25 14:27:51 +020041int nc_server_config_setup_diff(const struct lyd_node *diff);
romanc1d2b092023-02-02 08:58:27 +010042
43/**
romanf02273a2023-05-25 09:44:11 +020044 * @brief Configure server based on the given data.
45 *
46 * Expected data is a validated instance of a ietf-netconf-server YANG data.
47 * Behaves as if all the nodes in data had the replace operation. That means that the current configuration will be deleted
48 * and just the given data will all be applied.
romanf6f37a52023-05-25 14:27:51 +020049 * The data must not contain any operation attribute, see ::nc_config_setup_diff() which works with diff.
romanf02273a2023-05-25 09:44:11 +020050 * Context must already have implemented the required modules, see * ::nc_config_load_modules().
51 *
52 * @param[in] data ietf-netconf-server YANG data.
53 * @return 0 on success, 1 on error.
54 */
romanf6f37a52023-05-25 14:27:51 +020055int nc_server_config_setup_data(const struct lyd_node *data);
romanf02273a2023-05-25 09:44:11 +020056
57/**
romanc1d2b092023-02-02 08:58:27 +010058 * @brief Configure server based on the given ietf-netconf-server YANG data.
romanf6f37a52023-05-25 14:27:51 +020059 * Wrapper around ::nc_config_setup_server_data() hiding work with parsing the data.
romanc1d2b092023-02-02 08:58:27 +010060 *
61 * @param[in] ctx libyang context.
62 * @param[in] path Path to the file with YANG data in XML format.
63 * @return 0 on success, 1 on error.
64 */
65int nc_server_config_setup_path(const struct ly_ctx *ctx, const char *path);
66
67/**
68 * @brief Implements all the required modules and their features in the context.
69 * Needs to be called before any other configuration functions.
70 *
71 * If ctx is :
72 * - NULL: a new context will be created and if the call is successful you have to free it,
73 * - non NULL: modules will simply be implemented.
74 *
75 * Implemented modules: ietf-netconf-server, ietf-x509-cert-to-name, ietf-crypto-types,
76 * ietf-tcp-common, ietf-ssh-common, iana-ssh-encryption-algs, iana-ssh-key-exchange-algs,
77 * iana-ssh-mac-algs, iana-ssh-public-key-algs, ietf-keystore, ietf-ssh-server, ietf-truststore,
78 * ietf-tls-server and libnetconf2-netconf-server.
79 *
80 * @param[in, out] ctx Optional context in which the modules will be implemented. Created if ctx is null.
81 * @return 0 on success, 1 on error.
82 */
83int nc_server_config_load_modules(struct ly_ctx **ctx);
84
85/**
roman9b1379c2023-03-31 10:11:10 +020086 * @brief Creates new YANG configuration data nodes for a hostkey.
romanc1d2b092023-02-02 08:58:27 +010087 *
roman9b1379c2023-03-31 10:11:10 +020088 * @param[in] privkey_path Path to a file containing a private key.
89 * The private key has to be in a PEM format. Only RSA and ECDSA keys are supported.
90 * @param[in] pubkey_path Path to a file containing a public key. If NULL, public key will be
91 * generated from the private key.
92 * @param[in] ctx libyang context.
93 * @param[in] endpt_name Arbitrary identifier of the endpoint.
94 * If an endpoint with this identifier already exists, it's hostkey might be changed.
95 * @param[in] hostkey_name Arbitrary identifier of the hostkey.
96 * If a hostkey with this identifier already exists, it's contents will be changed.
97 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
98 * Otherwise the new YANG data will be added to the previous data and may override it.
99 * @return 0 on success, non-zero otherwise.
romanc1d2b092023-02-02 08:58:27 +0100100 */
roman466719d2023-05-05 16:14:37 +0200101int nc_server_config_new_ssh_hostkey(const char *privkey_path, const char *pubkey_path, const struct ly_ctx *ctx,
roman9b1379c2023-03-31 10:11:10 +0200102 const char *endpt_name, const char *hostkey_name, struct lyd_node **config);
romanc1d2b092023-02-02 08:58:27 +0100103
roman45cec4e2023-02-17 10:21:39 +0100104/**
roman9b1379c2023-03-31 10:11:10 +0200105 * @brief Creates new YANG configuration data nodes for a local-address and local-port.
106 *
107 * @param[in] address New listening address.
108 * @param[in] port New listening port.
109 * @param[in] ctx libyang context.
110 * @param[in] endpt_name Arbitrary identifier of the endpoint.
111 * If an endpoint with this identifier already exists, it's address and port will be overriden.
112 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
113 * Otherwise the new YANG data will be added to the previous data and may override it.
114 * @return 0 on success, non-zero otherwise.
roman45cec4e2023-02-17 10:21:39 +0100115 */
roman466719d2023-05-05 16:14:37 +0200116int nc_server_config_new_ssh_address_port(const char *address, const char *port, const struct ly_ctx *ctx,
roman9b1379c2023-03-31 10:11:10 +0200117 const char *endpt_name, struct lyd_node **config);
118
119/**
120 * @brief Creates new YANG configuration data nodes for host-key algorithms replacing any previous ones.
121 *
122 * Supported algorithms are: ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521,
123 * rsa-sha2-512, rsa-sha2-256, ssh-rsa and ssh-dss.
124 *
125 * @param[in] ctx libyang context
126 * @param[in] endpt_name Arbitrary identifier of the endpoint.
127 * If an endpoint with this identifier already exists, it's host-key algorithms will be replaced.
128 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
129 * Otherwise the new YANG data will be added to the previous data and may override it.
130 * @param[in] alg_count Number of following algorithms.
131 * @param[in] ... String literals of host-key algorithms in a decreasing order of preference.
132 * @return 0 on success, non-zero otherwise.
133 */
roman466719d2023-05-05 16:14:37 +0200134int nc_server_config_new_ssh_host_key_algs(const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200135 struct lyd_node **config, int alg_count, ...);
136
137/**
138 * @brief Creates new YANG configuration data nodes for key exchange algorithms replacing any previous ones.
139 *
140 * Supported algorithms are: diffie-hellman-group-exchange-sha1, curve25519-sha256, ecdh-sha2-nistp256,
141 * ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group18-sha512, diffie-hellman-group16-sha512,
142 * diffie-hellman-group-exchange-sha256 and diffie-hellman-group14-sha256.
143 *
144 * @param[in] ctx libyang context
145 * @param[in] endpt_name Arbitrary identifier of the endpoint.
146 * If an endpoint with this identifier already exists, it's key exchange algorithms will be replaced.
147 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
148 * Otherwise the new YANG data will be added to the previous data and may override it.
149 * @param[in] alg_count Number of following algorithms.
150 * @param[in] ... String literals of key exchange algorithms in a decreasing order of preference.
151 * @return 0 on success, non-zero otherwise.
152 */
roman466719d2023-05-05 16:14:37 +0200153int nc_server_config_new_ssh_key_exchange_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200154 int alg_count, ...);
155
156/**
157 * @brief Creates new YANG configuration data nodes for encryption algorithms replacing any previous ones.
158 *
159 * Supported algorithms are: aes256-ctr, aes192-ctr, aes128-ctr, aes256-cbc, aes192-cbc, aes128-cbc, blowfish-cbc
160 * triple-des-cbc and none.
161 *
162 * @param[in] ctx libyang context
163 * @param[in] endpt_name Arbitrary identifier of the endpoint.
164 * If an endpoint with this identifier already exists, it's encryption algorithms will be replaced.
165 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
166 * Otherwise the new YANG data will be added to the previous data and may override it.
167 * @param[in] alg_count Number of following algorithms.
168 * @param[in] ... String literals of encryption algorithms in a decreasing order of preference.
169 * @return 0 on success, non-zero otherwise.
170 */
roman466719d2023-05-05 16:14:37 +0200171int nc_server_config_new_ssh_encryption_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200172 int alg_count, ...);
173
174/**
175 * @brief Creates new YANG configuration data nodes for mac algorithms replacing any previous ones.
176 *
177 * Supported algorithms are: hmac-sha2-256, hmac-sha2-512 and hmac-sha1.
178 *
179 * @param[in] ctx libyang context
180 * @param[in] endpt_name Arbitrary identifier of the endpoint.
181 * If an endpoint with this identifier already exists, it's mac algorithms will be replaced.
182 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
183 * Otherwise the new YANG data will be added to the previous data and may override it.
184 * @param[in] alg_count Number of following algorithms.
185 * @param[in] ... String literals of mac algorithms in a decreasing order of preference.
186 * @return 0 on success, non-zero otherwise.
187 */
roman466719d2023-05-05 16:14:37 +0200188int nc_server_config_new_ssh_mac_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200189 int alg_count, ...);
190
191/**
192 * @brief Creates new YANG configuration data nodes for a client, which supports the public key authentication method.
193 *
194 * @param[in] pubkey_path Path to a file containing the user's public key.
195 * @param[in] ctx libyang context.
196 * @param[in] endpt_name Arbitrary identifier of the endpoint.
197 * If an endpoint with this identifier already exists, it's user might be changed.
198 * @param[in] user_name Arbitrary identifier of the user.
199 * If an user with this identifier already exists, it's contents will be changed.
200 * @param[in] pubkey_name Arbitrary identifier of the user's public key.
201 * If a public key with this identifier already exists for this user, it's contents will be changed.
202 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
203 * Otherwise the new YANG data will be added to the previous data and may override it.
204 * @return 0 on success, non-zero otherwise.
205 */
roman466719d2023-05-05 16:14:37 +0200206int nc_server_config_new_ssh_client_auth_pubkey(const char *pubkey_path, const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200207 const char *user_name, const char *pubkey_name, struct lyd_node **config);
208
209/**
210 * @brief Creates new YANG configuration data nodes for a client, which supports the password authentication method.
211 *
212 * This function sets the password for the given user.
213 *
214 * @param[in] password Cleartext user's password.
215 * @param[in] ctx libyang context.
216 * @param[in] endpt_name Arbitrary identifier of the endpoint.
217 * If an endpoint with this identifier already exists, it's user might be changed.
218 * @param[in] user_name Arbitrary identifier of the user.
219 * If an user with this identifier already exists, it's contents will be changed.
220 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
221 * Otherwise the new YANG data will be added to the previous data and may override it.
222 * @return 0 on success, non-zero otherwise.
223 */
roman466719d2023-05-05 16:14:37 +0200224int nc_server_config_new_ssh_client_auth_password(const char *password, const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200225 const char *user_name, struct lyd_node **config);
226
227/**
228 * @brief Creates new YANG configuration data nodes for a client, which supports the none authentication method.
229 *
230 * @param[in] ctx libyang context.
231 * @param[in] endpt_name Arbitrary identifier of the endpoint.
232 * If an endpoint with this identifier already exists, it's user might be changed.
233 * @param[in] user_name Arbitrary identifier of the user.
234 * If an user with this identifier already exists, it's contents will be changed.
235 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
236 * Otherwise the new YANG data will be added to the previous data and may override it.
237 * @return 0 on success, non-zero otherwise.
238 */
roman466719d2023-05-05 16:14:37 +0200239int nc_server_config_new_ssh_client_auth_none(const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200240 const char *user_name, struct lyd_node **config);
241
242/**
243 * @brief Creates new YANG configuration data nodes for a client, which supports the interactive authentication method.
244 *
245 * @param[in] pam_config_name Name of the PAM configuration file.
246 * @param[in] pam_config_name Optional. The absolute path to the directory in which the configuration file
247 * with the name conf_name is located. A newer version (>= 1.4) of PAM library is required to be able to specify
248 * the path. If NULL is passed, then the PAM's system directories will be searched (usually /etc/pam.d/).
249 * @param[in] ctx libyang context.
250 * @param[in] endpt_name Arbitrary identifier of the endpoint.
251 * If an endpoint with this identifier already exists, it's user might be changed.
252 * @param[in] user_name Arbitrary identifier of the user.
253 * If an user with this identifier already exists, it's contents will be changed.
254 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
255 * Otherwise the new YANG data will be added to the previous data and may override it.
256 * @return 0 on success, non-zero otherwise.
257 */
roman466719d2023-05-05 16:14:37 +0200258int nc_server_config_new_ssh_client_auth_interactive(const char *pam_config_name, const char *pam_config_dir,
roman9b1379c2023-03-31 10:11:10 +0200259 const struct ly_ctx *ctx, const char *endpt_name,
260 const char *user_name, struct lyd_node **config);
roman45cec4e2023-02-17 10:21:39 +0100261
romanc1d2b092023-02-02 08:58:27 +0100262#ifdef __cplusplus
263}
264#endif
265
266#endif /* NC_SESSION_SERVER_H_ */