Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file session_server.h |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2 session server manipulation |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_SESSION_SERVER_H_ |
| 16 | #define NC_SESSION_SERVER_H_ |
| 17 | |
| 18 | #include <stdint.h> |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 19 | #include <libyang/libyang.h> |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 20 | |
Michal Vasko | 709598e | 2016-11-28 14:48:32 +0100 | [diff] [blame] | 21 | #ifdef NC_ENABLED_TLS |
| 22 | # include <openssl/x509.h> |
| 23 | #endif |
| 24 | |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 25 | #ifdef NC_ENABLED_SSH |
| 26 | # include <libssh/libssh.h> |
| 27 | # include <libssh/callbacks.h> |
| 28 | # include <libssh/server.h> |
| 29 | #endif |
| 30 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 31 | #include "session.h" |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 32 | #include "netconf.h" |
| 33 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 34 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 35 | * @defgroup server_session Server Session |
| 36 | * @ingroup server |
| 37 | * |
| 38 | * @brief Server-side NETCONF session manipulation. |
| 39 | * @{ |
| 40 | */ |
| 41 | |
| 42 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 43 | * @brief Prototype of callbacks that are called if some RPCs are received. |
| 44 | * |
| 45 | * If \p session termination reason is changed in the callback, one last reply |
| 46 | * is sent and then the session is considered invalid. |
| 47 | * |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 48 | * The callback is set via nc_set_global_rpc_clb(). |
| 49 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 50 | * @param[in] rpc Parsed client RPC request. |
| 51 | * @param[in] session Session the RPC arrived on. |
| 52 | * @return Server reply. If NULL, an operation-failed error will be sent to the client. |
| 53 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 54 | typedef struct nc_server_reply *(*nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session); |
| 55 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 56 | /** |
Michal Vasko | 7b09624 | 2016-01-29 15:55:10 +0100 | [diff] [blame] | 57 | * @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] | 58 | * |
| 59 | * @param[in] session Session to modify. |
| 60 | * @param[in] reason Reason of termination. |
| 61 | */ |
| 62 | void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason); |
| 63 | |
| 64 | /** |
Michal Vasko | 142cfea | 2017-08-07 10:12:11 +0200 | [diff] [blame] | 65 | * @brief Set the session-id of the session responsible for this session's termination. |
| 66 | * |
| 67 | * @param[in] session Session to modify. Must have term_reason set to #NC_SESSION_TERM_KILLED. |
| 68 | * @param[in] sid SID of the killing session. |
| 69 | */ |
| 70 | void nc_session_set_killed_by(struct nc_session *session, uint32_t sid); |
| 71 | |
| 72 | /** |
| 73 | * @brief Set the status of a session. |
| 74 | * |
| 75 | * @param[in] session Session to modify. |
| 76 | * @param[in] status Status of the session. |
| 77 | */ |
| 78 | void nc_session_set_status(struct nc_session *session, NC_STATUS status); |
| 79 | |
| 80 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 81 | * @brief Set a global nc_rpc_clb that is called if the particular RPC request is |
| 82 | * received and the private field in the corresponding RPC schema node is NULL. |
| 83 | * |
| 84 | * @param[in] clb An user-defined nc_rpc_clb function callback, NULL to default. |
| 85 | */ |
| 86 | void nc_set_global_rpc_clb(nc_rpc_clb clb); |
| 87 | |
| 88 | /**@} Server Session */ |
| 89 | |
| 90 | /** |
| 91 | * @addtogroup server |
| 92 | * @{ |
| 93 | */ |
| 94 | |
| 95 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 96 | * @brief Initialize libssh and/or libssl/libcrypto and the server using a libyang context. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 97 | * |
| 98 | * The context is not modified internally, only its dictionary is used for holding |
Michal Vasko | a43589b | 2016-02-17 13:24:59 +0100 | [diff] [blame] | 99 | * all the strings, which is thread-safe. Reading models is considered thread-safe |
| 100 | * as models cannot be removed and are rarely modified (augments or deviations). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 101 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 102 | * If the RPC callbacks on schema nodes (mentioned in @ref howtoserver) are modified after |
Michal Vasko | 5494f51 | 2016-03-01 12:13:44 +0100 | [diff] [blame] | 103 | * server initialization with that particular context, they will be called (changes |
| 104 | * will take effect). However, there could be race conditions as the access to |
| 105 | * these callbacks is not thread-safe. |
| 106 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 107 | * Server capabilities are generated based on its content. Changing the context |
| 108 | * in ways that result in changed capabilities (adding models, changing features) |
| 109 | * is discouraged after sessions are established as it is not possible to change |
| 110 | * capabilities of a session. |
| 111 | * |
| 112 | * This context can safely be destroyed only after calling the last libnetconf2 |
| 113 | * function in an application. |
| 114 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 115 | * Supported RPCs of models in the context are expected to have their callback |
| 116 | * in the corresponding RPC schema node set to a nc_rpc_clb function callback using nc_set_rpc_callback(). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 117 | * This callback is called by nc_ps_poll() if the particular RPC request is |
| 118 | * received. Callbacks for ietf-netconf:get-schema (supporting YANG and YIN format |
| 119 | * only) and ietf-netconf:close-session are set internally if left unset. |
| 120 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 121 | * @param[in] ctx Core NETCONF server context. |
| 122 | * @return 0 on success, -1 on error. |
| 123 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 124 | int nc_server_init(struct ly_ctx *ctx); |
| 125 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 126 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 127 | * @brief Destroy any dynamically allocated libssh and/or libssl/libcrypto and |
| 128 | * server resources. |
Michal Vasko | b48aa81 | 2016-01-18 14:13:09 +0100 | [diff] [blame] | 129 | */ |
| 130 | void nc_server_destroy(void); |
| 131 | |
| 132 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 133 | * @brief Set the with-defaults capability extra parameters. |
| 134 | * |
| 135 | * For the capability to be actually advertised, the server context must also |
| 136 | * include the ietf-netconf-with-defaults model. |
| 137 | * |
| 138 | * Changing this option has the same ill effects as changing capabilities while |
| 139 | * sessions are already established. |
| 140 | * |
| 141 | * @param[in] basic_mode basic-mode with-defaults parameter. |
| 142 | * @param[in] also_supported NC_WD_MODE bit array, also-supported with-defaults |
| 143 | * parameter. |
| 144 | * @return 0 on success, -1 on error. |
| 145 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 146 | int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported); |
| 147 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 148 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 149 | * @brief Get with-defaults capability extra parameters. |
| 150 | * |
| 151 | * At least one argument must be non-NULL. |
| 152 | * |
| 153 | * @param[in,out] basic_mode basic-mode parameter. |
| 154 | * @param[in,out] also_supported also-supported parameter. |
| 155 | */ |
| 156 | void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported); |
| 157 | |
| 158 | /** |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 159 | * @brief Set capability of the server. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 160 | * |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 161 | * Capability can be used when some behavior or extension of the server is not defined |
| 162 | * as a YANG module. The provided value will be advertised in the server's \<hello\> |
| 163 | * messages. Note, that libnetconf only checks that the provided value is non-empty |
| 164 | * string. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 165 | * |
Michal Vasko | 50d2a5c | 2017-02-14 10:29:49 +0100 | [diff] [blame] | 166 | * @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] | 167 | */ |
Radek Krejci | 658782b | 2016-12-04 22:04:55 +0100 | [diff] [blame] | 168 | int nc_server_set_capability(const char *value); |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 169 | |
| 170 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 171 | * @brief Set server timeout for receiving a hello message. |
| 172 | * |
| 173 | * @param[in] hello_timeout Hello message timeout. 0 for infinite waiting. |
| 174 | */ |
| 175 | void nc_server_set_hello_timeout(uint16_t hello_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 176 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 177 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 178 | * @brief get server timeout for receiving a hello message. |
| 179 | * |
| 180 | * @return Hello message timeout, 0 is infinite. |
| 181 | */ |
| 182 | uint16_t nc_server_get_hello_timeout(void); |
| 183 | |
| 184 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 185 | * @brief Set server timeout for dropping an idle session. |
| 186 | * |
| 187 | * @param[in] idle_timeout Idle session timeout. 0 to never drop a session |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 188 | * because of inactivity. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 189 | */ |
| 190 | void nc_server_set_idle_timeout(uint16_t idle_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 191 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 192 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 193 | * @brief Get server timeout for dropping an idle session. |
| 194 | * |
| 195 | * @return Idle session timeout, 0 for for never dropping |
| 196 | * a session because of inactivity. |
| 197 | */ |
| 198 | uint16_t nc_server_get_idle_timeout(void); |
| 199 | |
| 200 | /** |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 201 | * @brief Get all the server capabilities including all the schemas. |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 202 | * |
| 203 | * A few capabilities (with-defaults, interleave) depend on the current |
| 204 | * server options. |
| 205 | * |
| 206 | * @param[in] ctx Context to read most capabilities from. |
| 207 | * @return Array of capabilities stored in the \p ctx dictionary, NULL on error. |
| 208 | */ |
| 209 | const char **nc_server_get_cpblts(struct ly_ctx *ctx); |
| 210 | |
Radek Krejci | 24a1841 | 2018-05-16 15:09:10 +0200 | [diff] [blame] | 211 | /** |
| 212 | * @brief Get the server capabilities including the schemas with the specified YANG version. |
| 213 | * |
| 214 | * A few capabilities (with-defaults, interleave) depend on the current |
| 215 | * server options. |
| 216 | * |
| 217 | * @param[in] ctx Context to read most capabilities from. |
| 218 | * @param[in] version YANG version of the schemas to be included in result, with |
| 219 | * LYS_VERSION_UNDEF the result is the same as from nc_server_get_cpblts(). |
| 220 | * @return Array of capabilities stored in the \p ctx dictionary, NULL on error. |
| 221 | */ |
| 222 | const char **nc_server_get_cpblts_version(struct ly_ctx *ctx, LYS_VERSION version); |
| 223 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 224 | /**@} Server */ |
| 225 | |
| 226 | /** |
| 227 | * @addtogroup server_session |
| 228 | * @{ |
| 229 | */ |
| 230 | |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 231 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 232 | * @brief Accept a new session on a pre-established transport session. |
| 233 | * |
| 234 | * @param[in] fdin File descriptor to read (unencrypted) XML data from. |
| 235 | * @param[in] fdout File descriptor to write (unencrypted) XML data to. |
| 236 | * @param[in] username NETCONF username as provided by the transport protocol. |
| 237 | * @param[out] session New session on success. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 238 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 239 | * 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] | 240 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 241 | NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, struct nc_session **session); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 242 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 243 | /** |
| 244 | * @brief Create an empty structure for polling sessions. |
| 245 | * |
| 246 | * @return Empty pollsession structure, NULL on error. |
| 247 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 248 | struct nc_pollsession *nc_ps_new(void); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 249 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 250 | /** |
| 251 | * @brief Free a pollsession structure. |
| 252 | * |
Michal Vasko | 01082bf | 2016-04-07 10:44:21 +0200 | [diff] [blame] | 253 | * !IMPORTANT! Make sure that \p ps is not accessible (is not used) |
| 254 | * by any thread before and after this call! |
| 255 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 256 | * @param[in] ps Pollsession structure to free. |
| 257 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 258 | void nc_ps_free(struct nc_pollsession *ps); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 259 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 260 | /** |
| 261 | * @brief Add a session to a pollsession structure. |
| 262 | * |
| 263 | * @param[in] ps Pollsession structure to modify. |
| 264 | * @param[in] session Session to add to \p ps. |
| 265 | * @return 0 on success, -1 on error. |
| 266 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 267 | 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] | 268 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 269 | /** |
| 270 | * @brief Remove a session from a pollsession structure. |
| 271 | * |
| 272 | * @param[in] ps Pollsession structure to modify. |
| 273 | * @param[in] session Session to remove from \p ps. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 274 | * @return 0 on success, -1 on not found. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 275 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 276 | int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session); |
| 277 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 278 | /** |
Michal Vasko | e1ee05b | 2017-03-21 10:10:18 +0100 | [diff] [blame] | 279 | * @brief Get a session from a pollsession structure matching the session ID. |
| 280 | * |
| 281 | * @param[in] ps Pollsession structure to read from. |
Michal Vasko | 4871c9d | 2017-10-09 14:48:39 +0200 | [diff] [blame] | 282 | * @param[in] idx Index of the session. |
| 283 | * @return Session on index, NULL if out-of-bounds. |
Michal Vasko | e1ee05b | 2017-03-21 10:10:18 +0100 | [diff] [blame] | 284 | */ |
Michal Vasko | 4871c9d | 2017-10-09 14:48:39 +0200 | [diff] [blame] | 285 | 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] | 286 | |
| 287 | /** |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 288 | * @brief Learn the number of sessions in a pollsession structure. |
| 289 | * |
Michal Vasko | f4462fd | 2017-02-15 14:29:05 +0100 | [diff] [blame] | 290 | * Does not lock \p ps structure for efficiency. |
| 291 | * |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 292 | * @param[in] ps Pollsession structure to check. |
Michal Vasko | c72d0e6 | 2016-07-26 11:36:11 +0200 | [diff] [blame] | 293 | * @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] | 294 | */ |
| 295 | uint16_t nc_ps_session_count(struct nc_pollsession *ps); |
| 296 | |
Michal Vasko | 30a5d6b | 2017-02-15 14:29:39 +0100 | [diff] [blame] | 297 | #define NC_PSPOLL_NOSESSIONS 0x0001 /**< No sessions to poll. */ |
| 298 | #define NC_PSPOLL_TIMEOUT 0x0002 /**< Timeout elapsed. */ |
| 299 | #define NC_PSPOLL_RPC 0x0004 /**< RPC was correctly parsed and processed. */ |
| 300 | #define NC_PSPOLL_BAD_RPC 0x0008 /**< RPC was received, but failed to be parsed. */ |
| 301 | #define NC_PSPOLL_REPLY_ERROR 0x0010 /**< Response to the RPC was a \<rpc-reply\> of type error. */ |
| 302 | #define NC_PSPOLL_SESSION_TERM 0x0020 /**< Some session was terminated. */ |
| 303 | #define NC_PSPOLL_SESSION_ERROR 0x0040 /**< Some session was terminated incorrectly (not by a \<close-session\> or \<kill-session\> RPC). */ |
| 304 | #define NC_PSPOLL_ERROR 0x0080 /**< Other fatal errors (they are printed). */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 305 | |
| 306 | #ifdef NC_ENABLED_SSH |
Michal Vasko | e645de3 | 2017-05-26 14:02:50 +0200 | [diff] [blame] | 307 | # define NC_PSPOLL_SSH_MSG 0x00100 /**< SSH message received (and processed, if relevant, only with SSH support). */ |
| 308 | # define NC_PSPOLL_SSH_CHANNEL 0x0200 /**< New SSH channel opened on an existing session (only with SSH support). */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 309 | #endif |
| 310 | |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 311 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 312 | * @brief Poll sessions and process any received RPCs. |
| 313 | * |
Michal Vasko | e4300a8 | 2017-05-24 10:35:42 +0200 | [diff] [blame] | 314 | * Only one event on one session is handled in one function call. If this event |
| 315 | * is a session termination (#NC_PSPOLL_SESSION_TERM returned), the session |
| 316 | * should be removed from \p ps. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 317 | * |
| 318 | * @param[in] ps Pollsession structure to use. |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 319 | * @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] | 320 | * infinite waiting. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 321 | * @param[in] session Session that was processed and that specific return bits concern. |
| 322 | * Can be NULL. |
Michal Vasko | ade892d | 2017-02-22 13:40:35 +0100 | [diff] [blame] | 323 | * @return Bitfield of NC_PSPOLL_* macros. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 324 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 325 | 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] | 326 | |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 327 | /** |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 328 | * @brief Remove sessions from a pollsession structure and |
| 329 | * call nc_session_free() on them. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 330 | * |
Michal Vasko | ade892d | 2017-02-22 13:40:35 +0100 | [diff] [blame] | 331 | * 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] | 332 | * |
| 333 | * @param[in] ps Pollsession structure to clear. |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 334 | * @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] | 335 | * @param[in] data_free Session user data destructor. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 336 | */ |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 337 | 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] | 338 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 339 | #if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS) |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 340 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 341 | /**@} Server Session */ |
| 342 | |
| 343 | /** |
| 344 | * @addtogroup server |
| 345 | * @{ |
| 346 | */ |
| 347 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 348 | /** |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 349 | * @brief Add a new endpoint. |
| 350 | * |
| 351 | * Before the endpoint can accept any connections, its address and port must |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 352 | * be set via nc_server_endpt_set_address() and nc_server_endpt_set_port(). |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 353 | * |
| 354 | * @param[in] name Arbitrary unique endpoint name. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 355 | * @param[in] ti Transport protocol to use. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 356 | * @return 0 on success, -1 on error. |
| 357 | */ |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 358 | int nc_server_add_endpt(const char *name, NC_TRANSPORT_IMPL ti); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * @brief Stop listening on and remove an endpoint. |
| 362 | * |
| 363 | * @param[in] name Endpoint name. NULL matches all endpoints. |
Michal Vasko | 5905037 | 2016-11-22 14:33:55 +0100 | [diff] [blame] | 364 | * @param[in] ti Endpoint transport protocol. NULL matches any protocol. |
| 365 | * Redundant to set if \p name is set, endpoint names are |
| 366 | * unique disregarding their protocol. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 367 | * @return 0 on success, -1 on not finding any match. |
| 368 | */ |
Michal Vasko | 5905037 | 2016-11-22 14:33:55 +0100 | [diff] [blame] | 369 | int nc_server_del_endpt(const char *name, NC_TRANSPORT_IMPL ti); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 370 | |
| 371 | /** |
Michal Vasko | e8e0770 | 2017-03-15 10:19:30 +0100 | [diff] [blame] | 372 | * @brief Get the number of currently configured listening endpoints. |
| 373 | * Note that an ednpoint without address and/or port will be included |
| 374 | * even though it is not, in fact, listening. |
| 375 | * |
| 376 | * @return Number of added listening endpoints. |
| 377 | */ |
| 378 | int nc_server_endpt_count(void); |
| 379 | |
| 380 | /** |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 381 | * @brief Change endpoint listening address. |
| 382 | * |
| 383 | * On error the previous listening socket (if any) is left untouched. |
| 384 | * |
| 385 | * @param[in] endpt_name Existing endpoint name. |
| 386 | * @param[in] address New listening address. |
| 387 | * @return 0 on success, -1 on error. |
| 388 | */ |
| 389 | int nc_server_endpt_set_address(const char *endpt_name, const char *address); |
| 390 | |
| 391 | /** |
| 392 | * @brief Change endpoint listening port. |
| 393 | * |
| 394 | * On error the previous listening socket (if any) is left untouched. |
| 395 | * |
| 396 | * @param[in] endpt_name Existing endpoint name. |
| 397 | * @param[in] port New listening port. |
| 398 | * @return 0 on success, -1 on error. |
| 399 | */ |
| 400 | int nc_server_endpt_set_port(const char *endpt_name, uint16_t port); |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 401 | |
Olivier Matz | ac7fa2f | 2018-10-11 10:02:04 +0200 | [diff] [blame] | 402 | /** |
| 403 | * @brief Change endpoint permissions. |
| 404 | * |
| 405 | * This is only valid on unix transport endpoint. |
| 406 | * On error the previous listening socket (if any) is left untouched. |
| 407 | * |
| 408 | * @param[in] endpt_name Existing endpoint name. |
| 409 | * @param[in] mode New mode, -1 to use default. |
| 410 | * @param[in] uid New uid, -1 to use default. |
| 411 | * @param[in] gid New gid, -1 to use default. |
| 412 | * @return 0 on success, -1 on error. |
| 413 | */ |
| 414 | int nc_server_endpt_set_perms(const char *endpt_name, mode_t mode, uid_t uid, gid_t gid); |
| 415 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 416 | /**@} Server */ |
| 417 | |
| 418 | /** |
| 419 | * @addtogroup server_session |
| 420 | */ |
| 421 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 422 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 423 | * @brief Accept new sessions on all the listening endpoints. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 424 | * |
Michal Vasko | b70c8b8 | 2017-03-17 09:09:29 +0100 | [diff] [blame] | 425 | * Once a new (TCP/IP) conection is established a different (quite long) timeout |
| 426 | * is used for waiting for transport-related data, which means this call can block |
| 427 | * for much longer that \p timeout, but only with slow/faulty/malicious clients. |
| 428 | * |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 429 | * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 430 | * non-blocking call, -1 for infinite waiting. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 431 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 432 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 433 | * 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] | 434 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 435 | NC_MSG_TYPE nc_accept(int timeout, struct nc_session **session); |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 436 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 437 | #endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */ |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 438 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 439 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 440 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 441 | /** |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 442 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF \p orig_session. |
Michal Vasko | ade892d | 2017-02-22 13:40:35 +0100 | [diff] [blame] | 443 | * 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] | 444 | * |
| 445 | * @param[in] orig_session Session that has a new SSH channel ready. |
| 446 | * @param[out] session New session. |
| 447 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 448 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
| 449 | */ |
| 450 | NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session); |
| 451 | |
| 452 | /** |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 453 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF session |
Michal Vasko | ade892d | 2017-02-22 13:40:35 +0100 | [diff] [blame] | 454 | * that was polled in \p ps. Call this function only when nc_ps_poll() on \p ps returns #NC_PSPOLL_SSH_CHANNEL. |
Michal Vasko | c0fde01 | 2016-03-01 09:07:23 +0100 | [diff] [blame] | 455 | * 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] | 456 | * |
| 457 | * @param[in] ps Unmodified pollsession structure from the previous nc_ps_poll() call. |
| 458 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 459 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 460 | * 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] | 461 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 462 | 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] | 463 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 464 | /**@} Server Session */ |
| 465 | |
| 466 | /** |
| 467 | * @defgroup server_ssh Server SSH |
| 468 | * @ingroup server |
| 469 | * |
| 470 | * @brief Server-side settings for SSH connections. |
| 471 | * @{ |
| 472 | */ |
| 473 | |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 474 | /** |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 475 | * @brief Add an authorized client SSH public key. This public key can be used for |
| 476 | * publickey authentication (for any SSH connection, even Call Home) afterwards. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 477 | * |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 478 | * @param[in] pubkey_base64 Authorized public key binary content encoded in base64. |
| 479 | * @param[in] type Authorized public key SSH type. |
| 480 | * @param[in] username Username that the client with the public key must use. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 481 | * @return 0 on success, -1 on error. |
| 482 | */ |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 483 | int nc_server_ssh_add_authkey(const char *pubkey_base64, NC_SSH_KEY_TYPE type, const char *username); |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 484 | |
| 485 | /** |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 486 | * @brief Add an authorized client SSH public key. This public key can be used for |
| 487 | * publickey authentication (for any SSH connection, even Call Home) afterwards. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 488 | * |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 489 | * @param[in] pubkey_path Path to the public key. |
| 490 | * @param[in] username Username that the client with the public key must use. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 491 | * @return 0 on success, -1 on error. |
| 492 | */ |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 493 | int nc_server_ssh_add_authkey_path(const char *pubkey_path, const char *username); |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 494 | |
| 495 | /** |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 496 | * @brief Remove an authorized client SSH public key. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 497 | * |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 498 | * @param[in] pubkey_path Path to an authorized public key. NULL matches all the keys. |
| 499 | * @param[in] pubkey_base64 Authorized public key content. NULL matches any key. |
| 500 | * @param[in] type Authorized public key type. 0 matches all types. |
| 501 | * @param[in] username Username for an authorized public key. NULL matches all the usernames. |
| 502 | * @return 0 on success, -1 on not finding any match. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 503 | */ |
Michal Vasko | 17dfda9 | 2016-12-01 14:06:16 +0100 | [diff] [blame] | 504 | int nc_server_ssh_del_authkey(const char *pubkey_path, const char *pubkey_base64, NC_SSH_KEY_TYPE type, |
| 505 | const char *username); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 506 | |
| 507 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 508 | * @brief Add endpoint SSH host keys the server will identify itself with. Only the name is set, the key itself |
| 509 | * wil be retrieved using a callback. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 510 | * |
| 511 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 512 | * @param[in] name Arbitrary name of the host key. |
Michal Vasko | 7d25588 | 2017-02-09 13:35:08 +0100 | [diff] [blame] | 513 | * @param[in] idx Optional index where to add the key. -1 adds at the end. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 514 | * @return 0 on success, -1 on error. |
| 515 | */ |
Michal Vasko | 7d25588 | 2017-02-09 13:35:08 +0100 | [diff] [blame] | 516 | int nc_server_ssh_endpt_add_hostkey(const char *endpt_name, const char *name, int16_t idx); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 517 | |
| 518 | /** |
Michal Vasko | ebba760 | 2018-03-23 13:14:08 +0100 | [diff] [blame] | 519 | * @brief Set the callback for SSH password authentication. If none is set, local system users are used. |
| 520 | * |
| 521 | * @param[in] passwd_auth_clb Callback that should authenticate the user. Username can be directly obtained from \p session. |
| 522 | * Zero return indicates success, non-zero an error. |
| 523 | * @param[in] user_data Optional arbitrary user data that will be passed to \p passwd_auth_clb. |
| 524 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 525 | */ |
| 526 | void nc_server_ssh_set_passwd_auth_clb(int (*passwd_auth_clb)(const struct nc_session *session, const char *password, |
| 527 | void *user_data), |
| 528 | void *user_data, void (*free_user_data)(void *user_data)); |
| 529 | |
| 530 | /** |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 531 | * @brief Set the callback for SSH interactive authentication. If none is set, local system users are used. |
| 532 | * |
| 533 | * @param[in] interactive_auth_clb Callback that should authenticate the user. |
| 534 | * Zero return indicates success, non-zero an error. |
| 535 | * @param[in] user_data Optional arbitrary user data that will be passed to \p passwd_auth_clb. |
| 536 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 537 | */ |
David Sedlák | 9d21a66 | 2018-08-23 10:57:55 +0200 | [diff] [blame] | 538 | void nc_server_ssh_set_interactive_auth_clb(int (*interactive_auth_clb)(const struct nc_session *session, const ssh_message msg, |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 539 | void *user_data), |
| 540 | void *user_data, void (*free_user_data)(void *user_data)); |
| 541 | |
| 542 | /** |
| 543 | * @brief Set the callback for SSH public key authentication. If none is set, local system users are used. |
| 544 | * |
| 545 | * @param[in] pubkey_auth_clb Callback that should authenticate the user. |
| 546 | * Zero return indicates success, non-zero an error. |
| 547 | * @param[in] user_data Optional arbitrary user data that will be passed to \p passwd_auth_clb. |
| 548 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 549 | */ |
David Sedlák | 9d21a66 | 2018-08-23 10:57:55 +0200 | [diff] [blame] | 550 | void nc_server_ssh_set_pubkey_auth_clb(int (*pubkey_auth_clb)(const struct nc_session *session, ssh_key key, void *user_data), |
bhart | 3bc2f58 | 2018-06-05 12:40:32 -0500 | [diff] [blame] | 551 | void *user_data, void (*free_user_data)(void *user_data)); |
| 552 | |
| 553 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 554 | * @brief Set the callback for retrieving host keys. Any RSA, DSA, and ECDSA keys can be added. However, |
| 555 | * a maximum of one key of each type will be used during SSH authentication, later keys replacing |
| 556 | * the earlier ones. |
| 557 | * |
| 558 | * @param[in] hostkey_clb Callback that should return the key itself. Zero return indicates success, non-zero |
| 559 | * an error. On success exactly ONE of \p privkey_path or \p privkey_data is expected |
| 560 | * to be set. The one set will be freed. |
| 561 | * - \p privkey_path expects a PEM file, |
| 562 | * - \p privkey_data expects a base-64 encoded ANS.1 DER data, |
| 563 | * - \p privkey_data_rsa flag whether \p privkey_data are the data of an RSA (1) or a DSA (0) key. |
| 564 | * @param[in] user_data Optional arbitrary user data that will be passed to \p hostkey_clb. |
| 565 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 566 | */ |
| 567 | void nc_server_ssh_set_hostkey_clb(int (*hostkey_clb)(const char *name, void *user_data, char **privkey_path, |
| 568 | char **privkey_data, int *privkey_data_rsa), |
| 569 | void *user_data, void (*free_user_data)(void *user_data)); |
| 570 | |
| 571 | /** |
| 572 | * @brief Delete endpoint SSH host key. Their order is preserved. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 573 | * |
| 574 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 7d25588 | 2017-02-09 13:35:08 +0100 | [diff] [blame] | 575 | * @param[in] name Name of the host key. NULL matches all the keys, but if \p idx != -1 then this must be NULL. |
| 576 | * @param[in] idx Index of the hostkey. -1 matches all indices, but if \p name != NULL then this must be -1. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 577 | * @return 0 on success, -1 on error. |
| 578 | */ |
Michal Vasko | 7d25588 | 2017-02-09 13:35:08 +0100 | [diff] [blame] | 579 | int nc_server_ssh_endpt_del_hostkey(const char *endpt_name, const char *name, int16_t idx); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 580 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 581 | /** |
Michal Vasko | fbfe8b6 | 2017-02-14 10:22:30 +0100 | [diff] [blame] | 582 | * @brief Move endpoint SSH host key. |
| 583 | * |
| 584 | * @param[in] endpt_name Exisitng endpoint name. |
| 585 | * @param[in] key_mov Name of the host key that will be moved. |
| 586 | * @param[in] key_after Name of the key that will preceed \p key_mov. NULL if \p key_mov is to be moved at the beginning. |
| 587 | * @return 0 in success, -1 on error. |
| 588 | */ |
| 589 | int nc_server_ssh_endpt_mov_hostkey(const char *endpt_name, const char *key_mov, const char *key_after); |
| 590 | |
| 591 | /** |
| 592 | * @brief Modify endpoint SSH host key. |
| 593 | * |
| 594 | * @param[in] endpt_name Exisitng endpoint name. |
| 595 | * @param[in] name Name of an existing host key. |
| 596 | * @param[in] new_name New name of the host key \p name. |
| 597 | * @return 0 in success, -1 on error. |
| 598 | */ |
| 599 | int nc_server_ssh_endpt_mod_hostkey(const char *endpt_name, const char *name, const char *new_name); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 600 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 601 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 602 | * @brief Set endpoint accepted SSH authentication methods. All (publickey, password, interactive) |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 603 | * are supported by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 604 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 605 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 606 | * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE. |
| 607 | * @return 0 on success, -1 on error. |
| 608 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 609 | int nc_server_ssh_endpt_set_auth_methods(const char *endpt_name, int auth_methods); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 610 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 611 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 612 | * @brief Set endpoint SSH authentication attempts of every client. 3 by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 613 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 614 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 5e6f4cc | 2016-01-20 13:27:44 +0100 | [diff] [blame] | 615 | * @param[in] auth_attempts Failed authentication attempts before a client is dropped. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 616 | * @return 0 on success, -1 on error. |
| 617 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 618 | int nc_server_ssh_endpt_set_auth_attempts(const char *endpt_name, uint16_t auth_attempts); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 619 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 620 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 621 | * @brief Set endpoint SSH authentication timeout. 10 seconds by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 622 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 623 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 624 | * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped. |
| 625 | * @return 0 on success, -1 on error. |
| 626 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 627 | int nc_server_ssh_endpt_set_auth_timeout(const char *endpt_name, uint16_t auth_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 628 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 629 | /**@} Server SSH */ |
| 630 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 631 | #endif /* NC_ENABLED_SSH */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 632 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 633 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 634 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 635 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 636 | * @defgroup server_tls Server TLS |
| 637 | * @ingroup server |
| 638 | * |
| 639 | * @brief Server-side settings for TLS connections. |
| 640 | * @{ |
| 641 | */ |
| 642 | |
| 643 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 644 | * @brief Set the server TLS certificate. Only the name is set, the certificate itself |
| 645 | * wil be retrieved using a callback. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 646 | * |
| 647 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 648 | * @param[in] name Arbitrary certificate name. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 649 | * @return 0 on success, -1 on error. |
| 650 | */ |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 651 | int nc_server_tls_endpt_set_server_cert(const char *endpt_name, const char *name); |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 652 | |
| 653 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 654 | * @brief Set the callback for retrieving server certificate and matching private key. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 655 | * |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 656 | * @param[in] cert_clb Callback that should return the certificate and the key itself. Zero return indicates success, |
| 657 | * non-zero an error. On success exactly ONE of \p cert_path or \p cert_data and ONE of |
| 658 | * \p privkey_path and \p privkey_data is expected to be set. Those set will be freed. |
| 659 | * - \p cert_path expects a PEM file, |
| 660 | * - \p cert_data expects a base-64 encoded ASN.1 DER data, |
| 661 | * - \p privkey_path expects a PEM file, |
| 662 | * - \p privkey_data expects a base-64 encoded ANS.1 DER data, |
| 663 | * - \p privkey_data_rsa flag whether \p privkey_data are the data of an RSA (1) or a DSA (0) key. |
| 664 | * @param[in] user_data Optional arbitrary user data that will be passed to \p cert_clb. |
| 665 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 666 | */ |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 667 | void nc_server_tls_set_server_cert_clb(int (*cert_clb)(const char *name, void *user_data, char **cert_path, char **cert_data, |
| 668 | char **privkey_path, char **privkey_data, int *privkey_data_rsa), |
| 669 | void *user_data, void (*free_user_data)(void *user_data)); |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 670 | |
| 671 | /** |
Andrew Langefeld | 440b6c7 | 2018-08-27 16:26:20 -0500 | [diff] [blame] | 672 | * @brief Set the callback for retrieving server certificate chain |
| 673 | * |
| 674 | * @param[in] cert_chain_clb Callback that should return all the certificates of the chain. Zero return indicates success, |
| 675 | * non-zero an error. On success, \p cert_paths and \p cert_data are expected to be set or left |
| 676 | * NULL. Both will be (deeply) freed. |
| 677 | * - \p cert_paths expect an array of PEM files, |
| 678 | * - \p cert_path_count number of \p cert_paths array members, |
| 679 | * - \p cert_data expect an array of base-64 encoded ASN.1 DER cert data, |
| 680 | * - \p cert_data_count number of \p cert_data array members. |
| 681 | * @param[in] user_data Optional arbitrary user data that will be passed to \p cert_clb. |
| 682 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 683 | */ |
| 684 | void nc_server_tls_set_server_cert_chain_clb(int (*cert_chain_clb)(const char *name, void *user_data, char ***cert_paths, |
| 685 | int *cert_path_count, char ***cert_data, int *cert_data_count), |
| 686 | void *user_data, void (*free_user_data)(void *user_data)); |
| 687 | |
| 688 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 689 | * @brief Add a trusted certificate list. Can be both a CA or a client one. Can be |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 690 | * safely used together with nc_server_tls_endpt_set_trusted_ca_paths(). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 691 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 692 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 693 | * @param[in] name Arbitary name identifying this certificate list. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 694 | * @return 0 on success, -1 on error. |
| 695 | */ |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 696 | int nc_server_tls_endpt_add_trusted_cert_list(const char *endpt_name, const char *name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 697 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 698 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 699 | * @brief Set the callback for retrieving trusted certificates. |
| 700 | * |
| 701 | * @param[in] cert_list_clb Callback that should return all the certificates of a list. Zero return indicates success, |
| 702 | * non-zero an error. On success, \p cert_paths and \p cert_data are expected to be set or left |
| 703 | * NULL. Both will be (deeply) freed. |
| 704 | * - \p cert_paths expect an array of PEM files, |
| 705 | * - \p cert_path_count number of \p cert_paths array members, |
| 706 | * - \p cert_data expect an array of base-64 encoded ASN.1 DER cert data, |
| 707 | * - \p cert_data_count number of \p cert_data array members. |
| 708 | * @param[in] user_data Optional arbitrary user data that will be passed to \p cert_clb. |
| 709 | * @param[in] free_user_data Optional callback that will be called during cleanup to free any \p user_data. |
| 710 | */ |
| 711 | void nc_server_tls_set_trusted_cert_list_clb(int (*cert_list_clb)(const char *name, void *user_data, char ***cert_paths, |
| 712 | int *cert_path_count, char ***cert_data, int *cert_data_count), |
| 713 | void *user_data, void (*free_user_data)(void *user_data)); |
| 714 | |
| 715 | /** |
| 716 | * @brief Remove a trusted certificate. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 717 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 718 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 719 | * @param[in] name Name of the certificate list to delete. NULL deletes all the lists. |
| 720 | * @return 0 on success, -1 on not found. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 721 | */ |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 722 | int nc_server_tls_endpt_del_trusted_cert_list(const char *endpt_name, const char *name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 723 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 724 | /** |
| 725 | * @brief Set trusted Certificate Authority certificate locations. There can only be |
Michal Vasko | 5d2ad08 | 2016-02-09 11:47:59 +0100 | [diff] [blame] | 726 | * one file and one directory, they are replaced if already set. Can be safely |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 727 | * used with nc_server_tls_endpt_add_trusted_cert() or its _path variant. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 728 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 729 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 730 | * @param[in] ca_file Path to a trusted CA cert store file in PEM format. Can be NULL. |
| 731 | * @param[in] ca_dir Path to a trusted CA cert store hashed directory (c_rehash utility |
| 732 | * can be used to create hashes) with PEM files. Can be NULL. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 733 | * @return 0 on success, -1 on error. |
| 734 | */ |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 735 | int nc_server_tls_endpt_set_trusted_ca_paths(const char *endpt_name, const char *ca_file, const char *ca_dir); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 736 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 737 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 738 | * @brief Set Certificate Revocation List locations. There can only be one file |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 739 | * and one directory, they are replaced if already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 740 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 741 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 742 | * @param[in] crl_file Path to a CRL store file in PEM format. Can be NULL. |
| 743 | * @param[in] crl_dir Path to a CRL store hashed directory (c_rehash utility |
| 744 | * can be used to create hashes) with PEM files. Can be NULL. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 745 | * @return 0 on success, -1 on error. |
| 746 | */ |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 747 | int nc_server_tls_endpt_set_crl_paths(const char *endpt_name, const char *crl_file, const char *crl_dir); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 748 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 749 | /** |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 750 | * @brief Destroy and clean CRLs. Certificates, private keys, and CTN entries are |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 751 | * not affected. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 752 | * |
| 753 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 754 | */ |
Michal Vasko | c6b9c7b | 2016-01-28 11:10:08 +0100 | [diff] [blame] | 755 | void nc_server_tls_endpt_clear_crls(const char *endpt_name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 756 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 757 | /** |
Michal Vasko | 58c22a2 | 2016-11-23 13:49:53 +0100 | [diff] [blame] | 758 | * @brief Add a cert-to-name entry. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 759 | * |
Michal Vasko | 3cf4aaa | 2017-02-01 15:03:36 +0100 | [diff] [blame] | 760 | * It is possible to add an entry step-by-step, specifying first only \p ip and in later calls |
| 761 | * \p fingerprint, \p map_type, and optionally \p name spearately. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 762 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 763 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 3cf4aaa | 2017-02-01 15:03:36 +0100 | [diff] [blame] | 764 | * @param[in] id Priority of the entry. It must be unique. If already exists, the entry with this id |
| 765 | * is modified. |
| 766 | * @param[in] fingerprint Matching certificate fingerprint. If NULL, kept temporarily unset. |
| 767 | * @param[in] map_type Type of username-certificate mapping. If 0, kept temporarily unset. |
| 768 | * @param[in] name Specific username used only if \p map_type == NC_TLS_CTN_SPECIFED. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 769 | * @return 0 on success, -1 on error. |
| 770 | */ |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 771 | int nc_server_tls_endpt_add_ctn(const char *endpt_name, uint32_t id, const char *fingerprint, |
| 772 | NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 773 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 774 | /** |
Michal Vasko | 58c22a2 | 2016-11-23 13:49:53 +0100 | [diff] [blame] | 775 | * @brief Remove a cert-to-name entry. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 776 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 777 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 778 | * @param[in] id Priority of the entry. -1 matches all the priorities. |
| 779 | * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints. |
| 780 | * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types. |
| 781 | * @param[in] name Specific username for the entry. NULL matches all the usernames. |
| 782 | * @return 0 on success, -1 on not finding any match. |
| 783 | */ |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 784 | int nc_server_tls_endpt_del_ctn(const char *endpt_name, int64_t id, const char *fingerprint, |
| 785 | NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 786 | |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 787 | /** |
| 788 | * @brief Get a cert-to-name entry. |
| 789 | * |
| 790 | * If a parameter is NULL, it is ignored. If its dereferenced value is NULL, |
| 791 | * it is filled and returned. If the value is set, it is used as a filter. |
| 792 | * Returns first matching entry. |
| 793 | * |
| 794 | * @param[in] endpt_name Existing endpoint name. |
| 795 | * @param[in,out] id Priority of the entry. |
| 796 | * @param[in,out] fingerprint Fingerprint fo the entry. |
| 797 | * @param[in,out] map_type Mapping type of the entry. |
| 798 | * @param[in,out] name Specific username for the entry. |
| 799 | * @return 0 on success, -1 on not finding any match. |
| 800 | */ |
Michal Vasko | f585ac7 | 2016-11-25 15:16:38 +0100 | [diff] [blame] | 801 | int nc_server_tls_endpt_get_ctn(const char *endpt_name, uint32_t *id, char **fingerprint, NC_TLS_CTN_MAPTYPE *map_type, |
| 802 | char **name); |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 803 | |
Michal Vasko | 7060bcf | 2016-11-28 14:48:11 +0100 | [diff] [blame] | 804 | /** |
Michal Vasko | 709598e | 2016-11-28 14:48:32 +0100 | [diff] [blame] | 805 | * @brief Get client certificate. |
| 806 | * |
| 807 | * @param[in] session Session to get the information from. |
| 808 | * @return Const session client certificate. |
| 809 | */ |
| 810 | const X509 *nc_session_get_client_cert(const struct nc_session *session); |
| 811 | |
| 812 | /** |
Michal Vasko | 7060bcf | 2016-11-28 14:48:11 +0100 | [diff] [blame] | 813 | * @brief Set TLS authentication additional verify callback. |
| 814 | * |
| 815 | * Server will always perform cert-to-name based on its configuration. Only after it passes |
| 816 | * and this callback is set, it is also called. It should return exactly what OpenSSL |
| 817 | * verify callback meaning 1 for success, 0 to deny the user. |
| 818 | * |
| 819 | * @param[in] verify_clb Additional user verify callback. |
| 820 | */ |
| 821 | void nc_server_tls_set_verify_clb(int (*verify_clb)(const struct nc_session *session)); |
| 822 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 823 | /**@} Server TLS */ |
| 824 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 825 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 826 | |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 827 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 828 | * @addtogroup server_session |
| 829 | * @{ |
| 830 | */ |
| 831 | |
| 832 | /** |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 833 | * @brief Get session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 834 | * |
| 835 | * @param[in] session Session to get the information from. |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 836 | * @return Session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 837 | */ |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 838 | time_t nc_session_get_start_time(const struct nc_session *session); |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 839 | |
Michal Vasko | 3486a7c | 2017-03-03 13:28:07 +0100 | [diff] [blame] | 840 | /** |
| 841 | * @brief Set session notification subscription flag. |
| 842 | * |
| 843 | * It is used only to ignore timeouts, because they are |
| 844 | * ignored for sessions with active subscriptions. |
| 845 | * |
| 846 | * @param[in] session Session to modify. |
| 847 | * @param[in] notif_status 0 for no active subscriptions, non-zero for an active subscription. |
| 848 | */ |
| 849 | void nc_session_set_notif_status(struct nc_session *session, int notif_status); |
| 850 | |
| 851 | /** |
| 852 | * @brief Get session notification subscription flag. |
| 853 | * |
| 854 | * @param[in] session Session to get the information from. |
| 855 | * @return 0 for no active subscription, non-zero for an active subscription. |
| 856 | */ |
| 857 | int nc_session_get_notif_status(const struct nc_session *session); |
| 858 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 859 | /**@} Server Session */ |
| 860 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 861 | #endif /* NC_SESSION_SERVER_H_ */ |