libnetconf2  3.1.1
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 #include "netconf.h"
28 #include "session.h"
29 
30 #ifdef NC_ENABLED_SSH_TLS
31 # include <libssh/callbacks.h>
32 # include <libssh/libssh.h>
33 # include <libssh/server.h>
34 #endif /* NC_ENABLED_SSH_TLS */
35 
56 typedef struct nc_server_reply *(*nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session);
57 
64 void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason);
65 
72 void nc_session_set_killed_by(struct nc_session *session, uint32_t sid);
73 
80 void nc_session_set_status(struct nc_session *session, NC_STATUS status);
81 
91 
100 struct nc_server_reply *nc_clb_default_get_schema(struct lyd_node *rpc, struct nc_session *session);
101 
110 struct nc_server_reply *nc_clb_default_close_session(struct lyd_node *rpc, struct nc_session *session);
111 
127 int nc_server_init(void);
128 
133 void nc_server_destroy(void);
134 
150 int nc_server_init_ctx(struct ly_ctx **ctx);
151 
166 int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported);
167 
176 void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported);
177 
188 int nc_server_set_capability(const char *value);
189 
197 void nc_server_set_content_id_clb(char *(*content_id_clb)(void *user_data), void *user_data,
198  void (*free_user_data)(void *user_data));
199 
209 char **nc_server_get_cpblts(const struct ly_ctx *ctx);
210 
222 char **nc_server_get_cpblts_version(const struct ly_ctx *ctx, LYS_VERSION version);
223 
244 NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, const struct ly_ctx *ctx,
245  struct nc_session **session);
246 
252 struct nc_pollsession *nc_ps_new(void);
253 
262 void nc_ps_free(struct nc_pollsession *ps);
263 
271 int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session);
272 
280 int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session);
281 
289 struct nc_session *nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx);
290 
299 typedef int (*nc_ps_session_match_cb)(struct nc_session *session, void *cb_data);
300 
309 struct nc_session *nc_ps_find_session(const struct nc_pollsession *ps, nc_ps_session_match_cb match_cb, void *cb_data);
310 
319 uint16_t nc_ps_session_count(struct nc_pollsession *ps);
320 
321 #define NC_PSPOLL_NOSESSIONS 0x0001
322 #define NC_PSPOLL_TIMEOUT 0x0002
323 #define NC_PSPOLL_RPC 0x0004
324 #define NC_PSPOLL_BAD_RPC 0x0008
325 #define NC_PSPOLL_REPLY_ERROR 0x0010
326 #define NC_PSPOLL_SESSION_TERM 0x0020
327 #define NC_PSPOLL_SESSION_ERROR 0x0040
328 #define NC_PSPOLL_ERROR 0x0080
330 #ifdef NC_ENABLED_SSH_TLS
331 # define NC_PSPOLL_SSH_MSG 0x00100
332 # define NC_PSPOLL_SSH_CHANNEL 0x0200
333 #endif /* NC_ENABLED_SSH_TLS */
334 
349 int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session);
350 
361 void nc_ps_clear(struct nc_pollsession *ps, int all, void (*data_free)(void *));
362 
377 int nc_server_endpt_count(void);
378 
390 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);
391 
398 void nc_server_del_endpt_unix_socket(const char *endpt_name);
399 
431 NC_MSG_TYPE nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session);
432 
433 #ifdef NC_ENABLED_SSH_TLS
434 
444 NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session);
445 
456 NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session);
457 
481 int nc_server_ssh_set_authkey_path_format(const char *path);
482 
499 typedef int (*nc_server_ssh_interactive_auth_clb)(const struct nc_session *session,
500  ssh_session ssh_sess, ssh_message msg, void *user_data);
501 
509 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));
510 
523 int nc_server_ssh_kbdint_get_nanswers(const struct nc_session *session, ssh_session libssh_session);
524 
536 int nc_server_ssh_set_pam_conf_filename(const char *filename);
537 
554 const void *nc_session_get_client_cert(const struct nc_session *session);
555 
564 void nc_server_tls_set_verify_clb(int (*verify_clb)(const struct nc_session *session));
565 
568 #endif /* NC_ENABLED_SSH_TLS */
569 
581 struct timespec nc_session_get_start_time(const struct nc_session *session);
582 
592 void nc_session_inc_notif_status(struct nc_session *session);
593 
600 void nc_session_dec_notif_status(struct nc_session *session);
601 
608 int nc_session_get_notif_status(const struct nc_session *session);
609 
612 #ifdef __cplusplus
613 }
614 #endif
615 
616 #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.
const void * nc_session_get_client_cert(const struct nc_session *session)
Get client certificate.
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.
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...