libnetconf2  3.0.17
NETCONF server and client library in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
session_server.h
Go to the documentation of this file.
1 
16 #ifndef NC_SESSION_SERVER_H_
17 #define NC_SESSION_SERVER_H_
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include <libyang/libyang.h>
24 #include <stdint.h>
25 #include <sys/types.h>
26 
27 #ifdef NC_ENABLED_SSH_TLS
28 # include <openssl/x509.h>
29 
30 # include <libssh/callbacks.h>
31 # include <libssh/libssh.h>
32 # include <libssh/server.h>
33 #endif /* NC_ENABLED_SSH_TLS */
34 
35 #include "netconf.h"
36 #include "session.h"
37 
58 typedef struct nc_server_reply *(*nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session);
59 
66 void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason);
67 
74 void nc_session_set_killed_by(struct nc_session *session, uint32_t sid);
75 
82 void nc_session_set_status(struct nc_session *session, NC_STATUS status);
83 
93 
102 struct nc_server_reply *nc_clb_default_get_schema(struct lyd_node *rpc, struct nc_session *session);
103 
112 struct nc_server_reply *nc_clb_default_close_session(struct lyd_node *rpc, struct nc_session *session);
113 
129 int nc_server_init(void);
130 
135 void nc_server_destroy(void);
136 
152 int nc_server_init_ctx(struct ly_ctx **ctx);
153 
168 int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported);
169 
178 void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported);
179 
190 int nc_server_set_capability(const char *value);
191 
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 
211 char **nc_server_get_cpblts(const struct ly_ctx *ctx);
212 
224 char **nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version);
225 
246 NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx,
247  struct nc_session **session);
248 
254 struct nc_pollsession *nc_ps_new(void);
255 
264 void nc_ps_free(struct nc_pollsession *ps);
265 
273 int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session);
274 
282 int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session);
283 
291 struct nc_session *nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx);
292 
301 typedef int (*nc_ps_session_match_cb)(struct nc_session *session, void *cb_data);
302 
311 struct nc_session *nc_ps_find_session(const struct nc_pollsession *ps, nc_ps_session_match_cb match_cb, void *cb_data);
312 
321 uint16_t nc_ps_session_count(struct nc_pollsession *ps);
322 
323 #define NC_PSPOLL_NOSESSIONS 0x0001
324 #define NC_PSPOLL_TIMEOUT 0x0002
325 #define NC_PSPOLL_RPC 0x0004
326 #define NC_PSPOLL_BAD_RPC 0x0008
327 #define NC_PSPOLL_REPLY_ERROR 0x0010
328 #define NC_PSPOLL_SESSION_TERM 0x0020
329 #define NC_PSPOLL_SESSION_ERROR 0x0040
330 #define NC_PSPOLL_ERROR 0x0080
332 #ifdef NC_ENABLED_SSH_TLS
333 # define NC_PSPOLL_SSH_MSG 0x00100
334 # define NC_PSPOLL_SSH_CHANNEL 0x0200
335 #endif /* NC_ENABLED_SSH_TLS */
336 
351 int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session);
352 
363 void nc_ps_clear(struct nc_pollsession *ps, int all, void (*data_free)(void *));
364 
379 int nc_server_endpt_count(void);
380 
392 int nc_server_add_endpt_unix_socket_listen(const char *endpt_name, const char *unix_socket_path, mode_t mode, uid_t uid, gid_t gid);
393 
400 void nc_server_del_endpt_unix_socket(const char *endpt_name);
401 
433 NC_MSG_TYPE nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session);
434 
435 #ifdef NC_ENABLED_SSH_TLS
436 
446 NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session);
447 
458 NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session);
459 
483 int nc_server_ssh_set_authkey_path_format(const char *path);
484 
501 typedef int (*nc_server_ssh_interactive_auth_clb)(const struct nc_session *session,
502  ssh_session ssh_sess, ssh_message msg, void *user_data);
503 
511 void nc_server_ssh_set_interactive_auth_clb(nc_server_ssh_interactive_auth_clb auth_clb, void *user_data, void (*free_user_data)(void *user_data));
512 
525 int nc_server_ssh_kbdint_get_nanswers(const struct nc_session *session, ssh_session libssh_session);
526 
538 int nc_server_ssh_set_pam_conf_filename(const char *filename);
539 
556 const X509 *nc_session_get_client_cert(const struct nc_session *session);
557 
567 void nc_server_tls_set_verify_clb(int (*verify_clb)(const struct nc_session *session));
568 
571 #endif /* NC_ENABLED_SSH_TLS */
572 
584 struct timespec nc_session_get_start_time(const struct nc_session *session);
585 
595 void nc_session_inc_notif_status(struct nc_session *session);
596 
603 void nc_session_dec_notif_status(struct nc_session *session);
604 
611 int nc_session_get_notif_status(const struct nc_session *session);
612 
615 #ifdef __cplusplus
616 }
617 #endif
618 
619 #endif /* NC_SESSION_SERVER_H_ */
NC_MSG_TYPE
Enumeration of NETCONF message types.
Definition: netconf.h:68
char ** nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version)
Get the server capabilities including the schemas with the specified YANG version.
int nc_server_init_ctx(struct ly_ctx **ctx)
Initialize a context which can serve as a default server context.
void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported)
Get with-defaults capability extra parameters.
NC_MSG_TYPE nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session)
Accept new sessions on all the listening endpoints.
int nc_server_add_endpt_unix_socket_listen(const char *endpt_name, const char *unix_socket_path, mode_t mode, uid_t uid, gid_t gid)
Create a new UNIX socket endpoint and start listening.
int nc_session_get_notif_status(const struct nc_session *session)
Get session notification subscription flag.
void nc_session_inc_notif_status(struct nc_session *session)
Increase session notification subscription flag count. Supports multiple subscriptions on one session...
int(* nc_server_ssh_interactive_auth_clb)(const struct nc_session *session, ssh_session ssh_sess, ssh_message msg, void *user_data)
Keyboard interactive authentication callback.
int nc_server_endpt_count(void)
Get the number of currently configured listening endpoints. Note that an ednpoint without address and...
NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session)
Accept a new NETCONF session on an SSH session of a running NETCONF session that was polled in ps...
libnetconf2 session manipulation
char ** nc_server_get_cpblts(const struct ly_ctx *ctx)
Get all the server capabilities including all the schemas.
int nc_server_set_capability(const char *value)
Set capability of the server.
NC_STATUS
Enumeration of possible session statuses.
Definition: session.h:76
int nc_server_ssh_kbdint_get_nanswers(const struct nc_session *session, ssh_session libssh_session)
Get the number of answers to Keyboard interactive authentication prompts.
int nc_server_init(void)
Initialize libssh and/or libssl/libcrypto and the server.
void nc_server_destroy(void)
Destroy any dynamically allocated libssh and/or libssl/libcrypto and server resources.
struct nc_session * nc_ps_find_session(const struct nc_pollsession *ps, nc_ps_session_match_cb match_cb, void *cb_data)
Find a session in a pollsession structure using a matching callback.
void nc_ps_clear(struct nc_pollsession *ps, int all, void(*data_free)(void *))
Remove sessions from a pollsession structure and call nc_session_free() on them.
void nc_server_set_content_id_clb(char *(*content_id_clb)(void *user_data), void *user_data, void(*free_user_data)(void *user_data))
Set the callback for getting yang-library capability identifier. If none is set, libyang context chan...
struct nc_server_reply *(* nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session)
Prototype of callbacks that are called if some RPCs are received.
int nc_server_ssh_set_pam_conf_filename(const char *filename)
Set the name of the PAM configuration file.
int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session)
Remove a session from a pollsession structure.
void nc_session_set_status(struct nc_session *session, NC_STATUS status)
Set the status of a session.
NC_SESSION_TERM_REASON
Enumeration of reasons of the NETCONF session termination as defined in RFC 6470. ...
Definition: netconf.h:54
void nc_session_dec_notif_status(struct nc_session *session)
Decrease session notification subscription flag count. Supports multiple subscriptions on one session...
void nc_set_global_rpc_clb(nc_rpc_clb clb)
Set a global nc_rpc_clb that is called if the particular RPC request is received and the private fiel...
enum NC_WITHDEFAULTS_MODE NC_WD_MODE
Enumeration of NETCONF with-defaults capability modes.
int nc_server_ssh_set_authkey_path_format(const char *path)
Set the format of the path to authorized_keys files.
uint16_t nc_ps_session_count(struct nc_pollsession *ps)
Learn the number of sessions in a pollsession structure.
void nc_server_del_endpt_unix_socket(const char *endpt_name)
Deletes a UNIX socket endpoint.
struct nc_session * nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx)
Get a session from a pollsession structure matching the session ID.
NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session)
Accept a new NETCONF session on an SSH session of a running NETCONF orig_session. Call this function ...
void nc_session_set_killed_by(struct nc_session *session, uint32_t sid)
Set the session-id of the session responsible for this session&#39;s termination.
int(* nc_ps_session_match_cb)(struct nc_session *session, void *cb_data)
Callback for finding a session in a pollsession structure.
int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported)
Set the with-defaults capability extra parameters.
void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason)
Set the termination reason for a session. Use only in nc_rpc_clb callbacks.
void nc_ps_free(struct nc_pollsession *ps)
Free a pollsession structure.
NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx, struct nc_session **session)
Accept a new session on a pre-established transport session.
int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session)
Add a session to a pollsession structure.
struct nc_pollsession * nc_ps_new(void)
Create an empty structure for polling sessions.
struct timespec nc_session_get_start_time(const struct nc_session *session)
Get session start time.
void nc_server_ssh_set_interactive_auth_clb(nc_server_ssh_interactive_auth_clb auth_clb, void *user_data, void(*free_user_data)(void *user_data))
Set the callback for SSH interactive authentication.
const X509 * nc_session_get_client_cert(const struct nc_session *session)
Get client certificate.
void nc_server_tls_set_verify_clb(int(*verify_clb)(const struct nc_session *session))
Set TLS authentication additional verify callback.
struct nc_server_reply * nc_clb_default_get_schema(struct lyd_node *rpc, struct nc_session *session)
Default RPC callback used for &quot;ietf-netconf-monitoring:get-schema&quot; RPC if no other specific or global...
libnetconf2&#39;s general public functions and structures definitions.
int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session)
Poll sessions and process any received RPCs.
struct nc_server_reply * nc_clb_default_close_session(struct lyd_node *rpc, struct nc_session *session)
Default RPC callback used for &quot;ietf-netconf:close-session&quot; RPC if no other specific or global callbac...