Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 1 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 2 | * @file session_server.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief libnetconf2 session server manipulation |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | 95ea9ff | 2021-11-09 12:29:14 +0100 | [diff] [blame] | 6 | * @copyright |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 8 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 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 |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 12 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 13 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_SESSION_SERVER_H_ |
| 17 | #define NC_SESSION_SERVER_H_ |
| 18 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 23 | #include <libyang/libyang.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 24 | #include <stdint.h> |
Michal Vasko | cca9ba6 | 2021-11-25 13:26:17 +0100 | [diff] [blame] | 25 | #include <sys/types.h> |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 26 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 27 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 28 | # include <openssl/x509.h> |
Michal Vasko | 709598e | 2016-11-28 14:48:32 +0100 | [diff] [blame] | 29 | |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 30 | # include <libssh/callbacks.h> |
| 31 | # include <libssh/libssh.h> |
| 32 | # include <libssh/server.h> |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 33 | #endif /* NC_ENABLED_SSH_TLS */ |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 34 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 35 | #include "netconf.h" |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 36 | #include "session.h" |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 37 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 38 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 39 | * @defgroup server_session Server Session |
| 40 | * @ingroup server |
| 41 | * |
| 42 | * @brief Server-side NETCONF session manipulation. |
| 43 | * @{ |
| 44 | */ |
| 45 | |
| 46 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 47 | * @brief Prototype of callbacks that are called if some RPCs are received. |
| 48 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 49 | * If @p session termination reason is changed in the callback, one last reply |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 50 | * is sent and then the session is considered invalid. |
| 51 | * |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 52 | * The callback is set via nc_set_global_rpc_clb(). |
| 53 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 54 | * @param[in] rpc Parsed client RPC request. |
| 55 | * @param[in] session Session the RPC arrived on. |
| 56 | * @return Server reply. If NULL, an operation-failed error will be sent to the client. |
| 57 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 58 | typedef struct nc_server_reply *(*nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session); |
| 59 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 60 | /** |
Michal Vasko | 7b09624 | 2016-01-29 15:55:10 +0100 | [diff] [blame] | 61 | * @brief Set the termination reason for a session. Use only in #nc_rpc_clb callbacks. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 62 | * |
| 63 | * @param[in] session Session to modify. |
| 64 | * @param[in] reason Reason of termination. |
| 65 | */ |
| 66 | void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason); |
| 67 | |
| 68 | /** |
Michal Vasko | 142cfea | 2017-08-07 10:12:11 +0200 | [diff] [blame] | 69 | * @brief Set the session-id of the session responsible for this session's termination. |
| 70 | * |
| 71 | * @param[in] session Session to modify. Must have term_reason set to #NC_SESSION_TERM_KILLED. |
| 72 | * @param[in] sid SID of the killing session. |
| 73 | */ |
| 74 | void nc_session_set_killed_by(struct nc_session *session, uint32_t sid); |
| 75 | |
| 76 | /** |
| 77 | * @brief Set the status of a session. |
| 78 | * |
| 79 | * @param[in] session Session to modify. |
| 80 | * @param[in] status Status of the session. |
| 81 | */ |
| 82 | void nc_session_set_status(struct nc_session *session, NC_STATUS status); |
| 83 | |
| 84 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 85 | * @brief Set a global nc_rpc_clb that is called if the particular RPC request is |
| 86 | * received and the private field in the corresponding RPC schema node is NULL. |
| 87 | * |
Michal Vasko | 238b6c1 | 2021-12-14 15:14:09 +0100 | [diff] [blame] | 88 | * If this callback is set, the default callbacks for "get-schema" and "close-session" are not used. |
| 89 | * |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 90 | * @param[in] clb An user-defined nc_rpc_clb function callback, NULL to default. |
| 91 | */ |
| 92 | void nc_set_global_rpc_clb(nc_rpc_clb clb); |
| 93 | |
Michal Vasko | 238b6c1 | 2021-12-14 15:14:09 +0100 | [diff] [blame] | 94 | /** |
| 95 | * @brief Default RPC callback used for "ietf-netconf-monitoring:get-schema" RPC if no other specific |
| 96 | * or global callback is set. |
| 97 | * |
| 98 | * @param[in] rpc Received RPC. |
| 99 | * @param[in] session NC session @p rpc was received on. |
| 100 | * @return Server reply. |
| 101 | */ |
| 102 | struct nc_server_reply *nc_clb_default_get_schema(struct lyd_node *rpc, struct nc_session *session); |
| 103 | |
| 104 | /** |
| 105 | * @brief Default RPC callback used for "ietf-netconf:close-session" RPC if no other specific |
| 106 | * or global callback is set. |
| 107 | * |
| 108 | * @param[in] rpc Received RPC. |
| 109 | * @param[in] session NC session @p rpc was received on. |
| 110 | * @return Server reply. |
| 111 | */ |
| 112 | struct nc_server_reply *nc_clb_default_close_session(struct lyd_node *rpc, struct nc_session *session); |
| 113 | |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 114 | /** @} Server Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 115 | |
| 116 | /** |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 117 | * @defgroup server_functions Server Functions |
| 118 | * @ingroup server |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 119 | * @{ |
| 120 | */ |
| 121 | |
| 122 | /** |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 123 | * @brief Initialize libssh and/or libssl/libcrypto and the server. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 124 | * |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 125 | * Must be called before other nc_server* functions. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 126 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 127 | * @return 0 on success, -1 on error. |
| 128 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 129 | int nc_server_init(void); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 130 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 131 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 132 | * @brief Destroy any dynamically allocated libssh and/or libssl/libcrypto and |
| 133 | * server resources. |
Michal Vasko | b48aa81 | 2016-01-18 14:13:09 +0100 | [diff] [blame] | 134 | */ |
| 135 | void nc_server_destroy(void); |
| 136 | |
| 137 | /** |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 138 | * @brief Initialize a context which can serve as a default server context. |
| 139 | * |
| 140 | * Loads the default modules ietf-netconf and ietf-netconf-monitoring and their enabled features - ietf-netconf |
| 141 | * enabled features are : writable-running, candidate, rollback-on-error, validate, startup, url, xpath, confirmed-commit and |
| 142 | * ietf-netconf-monitoring has no features. |
| 143 | * |
| 144 | * If ctx is : |
| 145 | * - NULL: a new context will be created and if the call is successful you have to free it, |
| 146 | * - non NULL: context will be searched for the two modules and their features |
| 147 | * and if anything is missing, it will be implemented. |
| 148 | * |
| 149 | * @param[in,out] ctx Optional context in which the modules will be loaded. Created if ctx is null. |
| 150 | * @return 0 on success, -1 on error. |
| 151 | */ |
| 152 | int nc_server_init_ctx(struct ly_ctx **ctx); |
| 153 | |
| 154 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 155 | * @brief Set the with-defaults capability extra parameters. |
| 156 | * |
| 157 | * For the capability to be actually advertised, the server context must also |
| 158 | * include the ietf-netconf-with-defaults model. |
| 159 | * |
| 160 | * Changing this option has the same ill effects as changing capabilities while |
| 161 | * sessions are already established. |
| 162 | * |
| 163 | * @param[in] basic_mode basic-mode with-defaults parameter. |
| 164 | * @param[in] also_supported NC_WD_MODE bit array, also-supported with-defaults |
| 165 | * parameter. |
| 166 | * @return 0 on success, -1 on error. |
| 167 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 168 | int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported); |
| 169 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 170 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 171 | * @brief Get with-defaults capability extra parameters. |
| 172 | * |
| 173 | * At least one argument must be non-NULL. |
| 174 | * |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 175 | * @param[out] basic_mode basic-mode parameter. |
| 176 | * @param[out] also_supported also-supported parameter. |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 177 | */ |
| 178 | void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported); |
| 179 | |
| 180 | /** |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 181 | * @brief Set capability of the server. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 182 | * |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 183 | * Capability can be used when some behavior or extension of the server is not defined |
| 184 | * as a YANG module. The provided value will be advertised in the server's \<hello\> |
| 185 | * messages. Note, that libnetconf only checks that the provided value is non-empty |
| 186 | * string. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 187 | * |
Michal Vasko | 50d2a5c | 2017-02-14 10:29:49 +0100 | [diff] [blame] | 188 | * @param[in] value Capability string to be advertised in server's \<hello\> messages. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 189 | */ |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 190 | int nc_server_set_capability(const char *value); |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 191 | |
| 192 | /** |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 193 | * @brief Set the callback for getting yang-library capability identifier. If none is set, libyang context change count is used. |
| 194 | * |
| 195 | * @param[in] content_id_clb Callback that should return the yang-library content identifier. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 196 | * @param[in] user_data Optional arbitrary user data that will be passed to @p content_id_clb. |
| 197 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any @p user_data. |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 198 | */ |
| 199 | void nc_server_set_content_id_clb(char *(*content_id_clb)(void *user_data), void *user_data, |
| 200 | void (*free_user_data)(void *user_data)); |
| 201 | |
| 202 | /** |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 203 | * @brief Get all the server capabilities including all the schemas. |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 204 | * |
| 205 | * A few capabilities (with-defaults, interleave) depend on the current |
| 206 | * server options. |
| 207 | * |
| 208 | * @param[in] ctx Context to read most capabilities from. |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 209 | * @return Array of capabilities, NULL on error. |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 210 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 211 | char **nc_server_get_cpblts(const struct ly_ctx *ctx); |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 212 | |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 213 | /** |
| 214 | * @brief Get the server capabilities including the schemas with the specified YANG version. |
| 215 | * |
| 216 | * A few capabilities (with-defaults, interleave) depend on the current |
| 217 | * server options. |
| 218 | * |
| 219 | * @param[in] ctx Context to read most capabilities from. |
| 220 | * @param[in] version YANG version of the schemas to be included in result, with |
| 221 | * LYS_VERSION_UNDEF the result is the same as from nc_server_get_cpblts(). |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 222 | * @return Array of capabilities, NULL on error. |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 223 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 224 | char **nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version); |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 225 | |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 226 | /** @} Server Functions */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * @addtogroup server_session |
| 230 | * @{ |
| 231 | */ |
| 232 | |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 233 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 234 | * @brief Accept a new session on a pre-established transport session. |
| 235 | * |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 236 | * For detailed description, look at ::nc_accept(). |
| 237 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 238 | * @param[in] fdin File descriptor to read (unencrypted) XML data from. |
| 239 | * @param[in] fdout File descriptor to write (unencrypted) XML data to. |
| 240 | * @param[in] username NETCONF username as provided by the transport protocol. |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 241 | * @param[in] ctx Context for the session to use. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 242 | * @param[out] session New session on success. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 243 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 244 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 245 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 246 | NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx, |
| 247 | struct nc_session **session); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 248 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 249 | /** |
| 250 | * @brief Create an empty structure for polling sessions. |
| 251 | * |
| 252 | * @return Empty pollsession structure, NULL on error. |
| 253 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 254 | struct nc_pollsession *nc_ps_new(void); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 255 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 256 | /** |
| 257 | * @brief Free a pollsession structure. |
| 258 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 259 | * !IMPORTANT! Make sure that @p ps is not accessible (is not used) |
Michal Vasko | 01082bf | 2016-04-07 10:44:21 +0200 | [diff] [blame] | 260 | * by any thread before and after this call! |
| 261 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 262 | * @param[in] ps Pollsession structure to free. |
| 263 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 264 | void nc_ps_free(struct nc_pollsession *ps); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 265 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 266 | /** |
| 267 | * @brief Add a session to a pollsession structure. |
| 268 | * |
| 269 | * @param[in] ps Pollsession structure to modify. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 270 | * @param[in] session Session to add to @p ps. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 271 | * @return 0 on success, -1 on error. |
| 272 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 273 | int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 274 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 275 | /** |
| 276 | * @brief Remove a session from a pollsession structure. |
| 277 | * |
| 278 | * @param[in] ps Pollsession structure to modify. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 279 | * @param[in] session Session to remove from @p ps. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 280 | * @return 0 on success, -1 on not found. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 281 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 282 | int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session); |
| 283 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 284 | /** |
Michal Vasko | e1ee05b | 2017-03-21 10:10:18 +0100 | [diff] [blame] | 285 | * @brief Get a session from a pollsession structure matching the session ID. |
| 286 | * |
| 287 | * @param[in] ps Pollsession structure to read from. |
Michal Vasko | 4871c9d | 2017-10-09 14:48:39 +0200 | [diff] [blame] | 288 | * @param[in] idx Index of the session. |
| 289 | * @return Session on index, NULL if out-of-bounds. |
Michal Vasko | e1ee05b | 2017-03-21 10:10:18 +0100 | [diff] [blame] | 290 | */ |
Michal Vasko | 4871c9d | 2017-10-09 14:48:39 +0200 | [diff] [blame] | 291 | struct nc_session *nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx); |
Michal Vasko | e1ee05b | 2017-03-21 10:10:18 +0100 | [diff] [blame] | 292 | |
| 293 | /** |
Michal Vasko | 3ec3b11 | 2022-07-21 12:32:33 +0200 | [diff] [blame] | 294 | * @brief Callback for finding a session in a pollsession structure. |
| 295 | * |
| 296 | * @param[in] session Considered NETCONF session. |
| 297 | * @param[in] cb_data User data. |
| 298 | * @return 0 if the session does not match. |
| 299 | * @return non-zero if the session matches and should be returned. |
| 300 | */ |
| 301 | typedef int (*nc_ps_session_match_cb)(struct nc_session *session, void *cb_data); |
| 302 | |
| 303 | /** |
| 304 | * @brief Find a session in a pollsession structure using a matching callback. |
| 305 | * |
| 306 | * @param[in] ps Pollsession structure to read from. |
| 307 | * @param[in] match_cb Matching callback to use. |
| 308 | * @param[in] cb_data User data passed to @p cb. |
| 309 | * @return Found session, NULL if none matched. |
| 310 | */ |
| 311 | struct nc_session *nc_ps_find_session(const struct nc_pollsession *ps, nc_ps_session_match_cb match_cb, void *cb_data); |
| 312 | |
| 313 | /** |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 314 | * @brief Learn the number of sessions in a pollsession structure. |
| 315 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 316 | * Does not lock @p ps structure for efficiency. |
Michal Vasko | f4462fd | 2017-02-15 14:29:05 +0100 | [diff] [blame] | 317 | * |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 318 | * @param[in] ps Pollsession structure to check. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 319 | * @return Number of sessions (even invalid ones) in @p ps, -1 on error. |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 320 | */ |
| 321 | uint16_t nc_ps_session_count(struct nc_pollsession *ps); |
| 322 | |
Michal Vasko | 30a5d6b | 2017-02-15 14:29:39 +0100 | [diff] [blame] | 323 | #define NC_PSPOLL_NOSESSIONS 0x0001 /**< No sessions to poll. */ |
| 324 | #define NC_PSPOLL_TIMEOUT 0x0002 /**< Timeout elapsed. */ |
| 325 | #define NC_PSPOLL_RPC 0x0004 /**< RPC was correctly parsed and processed. */ |
| 326 | #define NC_PSPOLL_BAD_RPC 0x0008 /**< RPC was received, but failed to be parsed. */ |
| 327 | #define NC_PSPOLL_REPLY_ERROR 0x0010 /**< Response to the RPC was a \<rpc-reply\> of type error. */ |
| 328 | #define NC_PSPOLL_SESSION_TERM 0x0020 /**< Some session was terminated. */ |
| 329 | #define NC_PSPOLL_SESSION_ERROR 0x0040 /**< Some session was terminated incorrectly (not by a \<close-session\> or \<kill-session\> RPC). */ |
| 330 | #define NC_PSPOLL_ERROR 0x0080 /**< Other fatal errors (they are printed). */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 331 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 332 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 333 | # define NC_PSPOLL_SSH_MSG 0x00100 /**< SSH message received (and processed, if relevant, only with SSH support). */ |
| 334 | # define NC_PSPOLL_SSH_CHANNEL 0x0200 /**< New SSH channel opened on an existing session (only with SSH support). */ |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 335 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 336 | |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 337 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 338 | * @brief Poll sessions and process any received RPCs. |
| 339 | * |
Michal Vasko | e4300a8 | 2017-05-24 10:35:42 +0200 | [diff] [blame] | 340 | * Only one event on one session is handled in one function call. If this event |
| 341 | * is a session termination (#NC_PSPOLL_SESSION_TERM returned), the session |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 342 | * should be removed from @p ps. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 343 | * |
| 344 | * @param[in] ps Pollsession structure to use. |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 345 | * @param[in] timeout Poll timeout in milliseconds. 0 for non-blocking call, -1 for |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 346 | * infinite waiting. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 347 | * @param[in] session Session that was processed and that specific return bits concern. |
| 348 | * Can be NULL. |
Michal Vasko | ade892d | 2017-02-22 13:40:35 +0100 | [diff] [blame] | 349 | * @return Bitfield of NC_PSPOLL_* macros. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 350 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 351 | int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 352 | |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 353 | /** |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 354 | * @brief Remove sessions from a pollsession structure and |
| 355 | * call nc_session_free() on them. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 356 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 357 | * Calling this function with @p all false makes sense if nc_ps_poll() returned #NC_PSPOLL_SESSION_TERM. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 358 | * |
| 359 | * @param[in] ps Pollsession structure to clear. |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 360 | * @param[in] all Whether to free all sessions, or only the invalid ones. |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 361 | * @param[in] data_free Session user data destructor. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 362 | */ |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 363 | void nc_ps_clear(struct nc_pollsession *ps, int all, void (*data_free)(void *)); |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 364 | |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 365 | /** @} Server Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 366 | |
| 367 | /** |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 368 | * @addtogroup server_functions |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 369 | * @{ |
| 370 | */ |
| 371 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 372 | /** |
Michal Vasko | e8e0770 | 2017-03-15 10:19:30 +0100 | [diff] [blame] | 373 | * @brief Get the number of currently configured listening endpoints. |
| 374 | * Note that an ednpoint without address and/or port will be included |
| 375 | * even though it is not, in fact, listening. |
| 376 | * |
| 377 | * @return Number of added listening endpoints. |
| 378 | */ |
| 379 | int nc_server_endpt_count(void); |
| 380 | |
| 381 | /** |
Michal Vasko | 1b5973e | 2020-01-30 16:05:46 +0100 | [diff] [blame] | 382 | * @brief Check if an endpoint exists. |
| 383 | * |
| 384 | * @param[in] name Endpoint name. |
| 385 | * @return 0 if does not exists, non-zero otherwise. |
| 386 | */ |
| 387 | int nc_server_is_endpt(const char *name); |
| 388 | |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 389 | /** @} */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * @addtogroup server_session |
Michal Vasko | 4e6d324 | 2021-05-26 09:13:24 +0200 | [diff] [blame] | 393 | * @{ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 394 | */ |
| 395 | |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 396 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 397 | * @brief Accept new sessions on all the listening endpoints. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 398 | * |
Michal Vasko | b70c8b8 | 2017-03-17 09:09:29 +0100 | [diff] [blame] | 399 | * Once a new (TCP/IP) conection is established a different (quite long) timeout |
| 400 | * is used for waiting for transport-related data, which means this call can block |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 401 | * for much longer that @p timeout, but only with slow/faulty/malicious clients. |
Michal Vasko | b70c8b8 | 2017-03-17 09:09:29 +0100 | [diff] [blame] | 402 | * |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 403 | * Server capabilities are generated based on the content of @p ctx. The context must |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 404 | * not be destroyed before the accepted NETCONF session is freed. Basic usable context may |
| 405 | * be created by calling ::nc_server_init_ctx(). |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 406 | * |
| 407 | * Supported RPCs of models in the context are expected to have their callback |
| 408 | * in the corresponding RPC schema node set to a nc_rpc_clb function callback using ::nc_set_rpc_callback(). |
| 409 | * This callback is called by ::nc_ps_poll() if the particular RPC request is |
| 410 | * received. Callbacks for ietf-netconf:get-schema (supporting YANG and YIN format |
| 411 | * only) and ietf-netconf:close-session are set internally if left unset. |
| 412 | * |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 413 | * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 414 | * non-blocking call, -1 for infinite waiting. |
| 415 | * @param[in] ctx Context for the session to use. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 416 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 417 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 418 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 419 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 420 | NC_MSG_TYPE nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session); |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 421 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 422 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 423 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 424 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 425 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF @p orig_session. |
| 426 | * Call this function only when nc_ps_poll() returns #NC_PSPOLL_SSH_CHANNEL on @p orig_session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 427 | * |
| 428 | * @param[in] orig_session Session that has a new SSH channel ready. |
| 429 | * @param[out] session New session. |
| 430 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 431 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
| 432 | */ |
| 433 | NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session); |
| 434 | |
| 435 | /** |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 436 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF session |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 437 | * that was polled in @p ps. Call this function only when nc_ps_poll() on @p ps returns #NC_PSPOLL_SSH_CHANNEL. |
| 438 | * The new session is only returned in @p session, it is not added to @p ps. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 439 | * |
| 440 | * @param[in] ps Unmodified pollsession structure from the previous nc_ps_poll() call. |
| 441 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 442 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 443 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 444 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 445 | NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session); |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 446 | |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 447 | /** @} Server Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 448 | |
| 449 | /** |
| 450 | * @defgroup server_ssh Server SSH |
| 451 | * @ingroup server |
| 452 | * |
| 453 | * @brief Server-side settings for SSH connections. |
| 454 | * @{ |
| 455 | */ |
| 456 | |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 457 | /** |
Michal Vasko | ebba760 | 2018-03-23 13:14:08 +0100 | [diff] [blame] | 458 | * @brief Set the callback for SSH password authentication. If none is set, local system users are used. |
| 459 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 460 | * @param[in] passwd_auth_clb Callback that should authenticate the user. Username can be directly obtained from @p session. |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 461 | * Zero return indicates success, non-zero an error. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 462 | * @param[in] user_data Optional arbitrary user data that will be passed to @p passwd_auth_clb. |
| 463 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any @p user_data. |
Michal Vasko | ebba760 | 2018-03-23 13:14:08 +0100 | [diff] [blame] | 464 | */ |
| 465 | void nc_server_ssh_set_passwd_auth_clb(int (*passwd_auth_clb)(const struct nc_session *session, const char *password, |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 466 | void *user_data), void *user_data, void (*free_user_data)(void *user_data)); |
Michal Vasko | ebba760 | 2018-03-23 13:14:08 +0100 | [diff] [blame] | 467 | |
| 468 | /** |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 469 | * @brief Set the callback for SSH interactive authentication. If not set, local PAM-based authentication is used. |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 470 | * |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 471 | * @param[in] interactive_auth_clb Callback that should authenticate the user. |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 472 | * Zero return indicates success, non-zero an error. |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 473 | * @param[in] user_data Optional arbitrary user data that will be passed to @p interactive_auth_clb. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 474 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any @p user_data. |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 475 | */ |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 476 | void nc_server_ssh_set_interactive_auth_clb(int (*interactive_auth_clb)(const struct nc_session *session, |
roman | f578cd5 | 2023-10-19 09:47:40 +0200 | [diff] [blame] | 477 | ssh_session ssh_sess, ssh_message msg, void *user_data), void *user_data, void (*free_user_data)(void *user_data)); |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 478 | |
| 479 | /** |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 480 | * @brief Set the callback for SSH public key authentication. If none is set, local system users are used. |
| 481 | * |
| 482 | * @param[in] pubkey_auth_clb Callback that should authenticate the user. |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 483 | * Zero return indicates success, non-zero an error. |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 484 | * @param[in] user_data Optional arbitrary user data that will be passed to @p pubkey_auth_clb. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 485 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any @p user_data. |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 486 | */ |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 487 | void nc_server_ssh_set_pubkey_auth_clb(int (*pubkey_auth_clb)(const struct nc_session *session, ssh_key key, |
Michal Vasko | 1440a74 | 2021-03-31 11:11:03 +0200 | [diff] [blame] | 488 | void *user_data), void *user_data, void (*free_user_data)(void *user_data)); |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 489 | |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 490 | /** @} Server SSH */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 491 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 492 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 493 | * @defgroup server_tls Server TLS |
| 494 | * @ingroup server |
| 495 | * |
| 496 | * @brief Server-side settings for TLS connections. |
| 497 | * @{ |
| 498 | */ |
| 499 | |
| 500 | /** |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 501 | * @brief Get a cert-to-name entry. |
| 502 | * |
| 503 | * If a parameter is NULL, it is ignored. If its dereferenced value is NULL, |
| 504 | * it is filled and returned. If the value is set, it is used as a filter. |
| 505 | * Returns first matching entry. |
| 506 | * |
| 507 | * @param[in] endpt_name Existing endpoint name. |
| 508 | * @param[in,out] id Priority of the entry. |
| 509 | * @param[in,out] fingerprint Fingerprint fo the entry. |
| 510 | * @param[in,out] map_type Mapping type of the entry. |
| 511 | * @param[in,out] name Specific username for the entry. |
| 512 | * @return 0 on success, -1 on not finding any match. |
| 513 | */ |
Michal Vasko | f585ac7 | 2016-11-25 15:16:38 +0100 | [diff] [blame] | 514 | int nc_server_tls_endpt_get_ctn(const char *endpt_name, uint32_t *id, char **fingerprint, NC_TLS_CTN_MAPTYPE *map_type, |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 515 | char **name); |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 516 | |
Michal Vasko | 7060bcf | 2016-11-28 14:48:11 +0100 | [diff] [blame] | 517 | /** |
Michal Vasko | 709598e | 2016-11-28 14:48:32 +0100 | [diff] [blame] | 518 | * @brief Get client certificate. |
| 519 | * |
| 520 | * @param[in] session Session to get the information from. |
| 521 | * @return Const session client certificate. |
| 522 | */ |
| 523 | const X509 *nc_session_get_client_cert(const struct nc_session *session); |
| 524 | |
| 525 | /** |
Michal Vasko | 7060bcf | 2016-11-28 14:48:11 +0100 | [diff] [blame] | 526 | * @brief Set TLS authentication additional verify callback. |
| 527 | * |
| 528 | * Server will always perform cert-to-name based on its configuration. Only after it passes |
| 529 | * and this callback is set, it is also called. It should return exactly what OpenSSL |
| 530 | * verify callback meaning 1 for success, 0 to deny the user. |
| 531 | * |
| 532 | * @param[in] verify_clb Additional user verify callback. |
| 533 | */ |
| 534 | void nc_server_tls_set_verify_clb(int (*verify_clb)(const struct nc_session *session)); |
| 535 | |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 536 | /** @} Server TLS */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 537 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 538 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 539 | |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 540 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 541 | * @addtogroup server_session |
| 542 | * @{ |
| 543 | */ |
| 544 | |
| 545 | /** |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 546 | * @brief Get session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 547 | * |
| 548 | * @param[in] session Session to get the information from. |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 549 | * @return Session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 550 | */ |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 551 | time_t nc_session_get_start_time(const struct nc_session *session); |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 552 | |
Michal Vasko | 3486a7c | 2017-03-03 13:28:07 +0100 | [diff] [blame] | 553 | /** |
Michal Vasko | 71dbd77 | 2021-03-23 14:08:37 +0100 | [diff] [blame] | 554 | * @brief Increase session notification subscription flag count. |
| 555 | * Supports multiple subscriptions on one session. |
Michal Vasko | 3486a7c | 2017-03-03 13:28:07 +0100 | [diff] [blame] | 556 | * |
| 557 | * It is used only to ignore timeouts, because they are |
| 558 | * ignored for sessions with active subscriptions. |
| 559 | * |
| 560 | * @param[in] session Session to modify. |
Michal Vasko | 3486a7c | 2017-03-03 13:28:07 +0100 | [diff] [blame] | 561 | */ |
Michal Vasko | 71dbd77 | 2021-03-23 14:08:37 +0100 | [diff] [blame] | 562 | void nc_session_inc_notif_status(struct nc_session *session); |
| 563 | |
| 564 | /** |
| 565 | * @brief Decrease session notification subscription flag count. |
| 566 | * Supports multiple subscriptions on one session. |
| 567 | * |
| 568 | * @param[in] session Session to modify. |
| 569 | */ |
| 570 | void nc_session_dec_notif_status(struct nc_session *session); |
Michal Vasko | 3486a7c | 2017-03-03 13:28:07 +0100 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * @brief Get session notification subscription flag. |
| 574 | * |
| 575 | * @param[in] session Session to get the information from. |
| 576 | * @return 0 for no active subscription, non-zero for an active subscription. |
| 577 | */ |
| 578 | int nc_session_get_notif_status(const struct nc_session *session); |
| 579 | |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 580 | /** @} Server Session */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 581 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 582 | #ifdef __cplusplus |
| 583 | } |
| 584 | #endif |
| 585 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 586 | #endif /* NC_SESSION_SERVER_H_ */ |