libnetconf
0.10.0-146_trunk
NETCONF Library
|
libnetconf's functions for handling NETCONF sessions. More...
Macros | |
#define | nc_msgid char* |
Type representing NETCONF message-id attribute. More... | |
Enumerations | |
enum | NC_SESSION_STATUS { NC_SESSION_STATUS_ERROR = -1, NC_SESSION_STATUS_STARTUP = 0, NC_SESSION_STATUS_WORKING = 1, NC_SESSION_STATUS_CLOSING = 2, NC_SESSION_STATUS_CLOSED = 3, NC_SESSION_STATUS_DUMMY = 4 } |
Enumeration of the possible states of a NETCONF session. More... | |
enum | NC_SESSION_TERM_REASON { NC_SESSION_TERM_CLOSED, NC_SESSION_TERM_KILLED, NC_SESSION_TERM_DROPPED, NC_SESSION_TERM_TIMEOUT, NC_SESSION_TERM_BADHELLO, NC_SESSION_TERM_OTHER } |
Enumeration of reasons of the NETCONF session termination as defined in RFC 6470. More... | |
enum | NC_SSH_AUTH_TYPE { NC_SSH_AUTH_PUBLIC_KEYS = 1, NC_SSH_AUTH_PASSWORD = 2, NC_SSH_AUTH_INTERACTIVE = 4 } |
Available SSH authentication mechanisms. More... | |
enum | NC_TRANSPORT { NC_TRANSPORT_UNKNOWN = -1, NC_TRANSPORT_SSH, NC_TRANSPORT_TLS } |
Supported NETCONF transport protocols enumeration. To change currently used transport protocol, call nc_session_transport(). More... | |
Functions | |
void | nc_callback_ssh_host_authenticity_check (int(*func)(const char *hostname, ssh_session session)) |
Set a callback function to authorize authenticity of the remote host. More... | |
void | nc_callback_sshauth_interactive (char *(*func)(const char *name, const char *instruction, const char *prompt, int echo)) |
Set a callback function for passing user credentials into the libssh's keyboard-interactive authentication method. More... | |
void | nc_callback_sshauth_passphrase (char *(*func)(const char *username, const char *hostname, const char *priv_key_file)) |
Set a callback function for passing the user password into the libssh's publickey authentication method when connecting to 'hostname' as 'username'. More... | |
void | nc_callback_sshauth_password (char *(*func)(const char *username, const char *hostname)) |
Set a callback function for passing the user password into the libssh's password authentication method when connecting to 'hostname' as 'username'. More... | |
int | nc_cpblts_add (struct nc_cpblts *capabilities, const char *capability_string) |
Add another capability string into the NETCONF capabilities structure. More... | |
int | nc_cpblts_count (const struct nc_cpblts *c) |
Get the number of capabilities in the structure. More... | |
int | nc_cpblts_enabled (const struct nc_session *session, const char *capability_string) |
Check if the given capability is supported by the session. More... | |
void | nc_cpblts_free (struct nc_cpblts *c) |
Free NETCONF capabilities structure. More... | |
const char * | nc_cpblts_get (const struct nc_cpblts *c, const char *capability_string) |
Get complete capability string including parameters. More... | |
const char * | nc_cpblts_iter_next (struct nc_cpblts *c) |
Get the next capability string from the given NETCONF capabilities structure. More... | |
void | nc_cpblts_iter_start (struct nc_cpblts *c) |
Move NETCONF capabilities structure iterator to the beginning of the capability strings list. More... | |
struct nc_cpblts * | nc_cpblts_new (const char *const list[]) |
Create a new NETCONF capabilities structure. More... | |
int | nc_cpblts_remove (struct nc_cpblts *capabilities, const char *capability_string) |
Remove the specified capability string from the NETCONF capabilities structure. More... | |
int | nc_del_keypair_path (const char *privkey, const char *pubkey) |
Remove a private and a public key file. More... | |
struct nc_session * | nc_session_accept (const struct nc_cpblts *capabilities) |
Accept NETCONF session from a client. More... | |
struct nc_session * | nc_session_accept_inout (const struct nc_cpblts *capabilities, const char *username, int input, int output) |
Accept NETCONF session from a client. It allows to assign the specified username to it and set file descriptors for reading/writing NETCONF data. More... | |
struct nc_session * | nc_session_accept_username (const struct nc_cpblts *capabilities, const char *username) |
Accept NETCONF session from a client and assign it to the specified username. More... | |
struct nc_session * | nc_session_connect (const char *host, unsigned short port, const char *username, const struct nc_cpblts *cpblts) |
Create NETCONF session to the specified server. More... | |
struct nc_session * | nc_session_connect_channel (struct nc_session *session, const struct nc_cpblts *cpblts) |
Create another NETCONF session using already established SSH session. No authentication is needed in this case. More... | |
struct nc_session * | nc_session_connect_inout (int fd_in, int fd_out, const struct nc_cpblts *cpblts, const char *host, const char *port, const char *username, NC_TRANSPORT transport) |
Create NETCONF session communicating via given file descriptors. This is an alternative function to nc_session_connect(). More... | |
struct nc_session * | nc_session_connect_libssh_sess (const char *host, unsigned short port, const char *username, const struct nc_cpblts *cpblts, ssh_session ssh_sess) |
Create NETCONF session to the specified server using a custom SSH session. More... | |
struct nc_session * | nc_session_dummy (const char *sid, const char *username, const char *hostname, struct nc_cpblts *capabilities) |
Create a disconnected session structure. More... | |
void | nc_session_free (struct nc_session *session) |
Cleanup the session structure and free all the allocated resources. More... | |
struct nc_cpblts * | nc_session_get_cpblts (const struct nc_session *session) |
Get list of capabilities associated with the session. More... | |
struct nc_cpblts * | nc_session_get_cpblts_default (void) |
Get NULL terminated list of the default capabilities supported by libnetconf including the list of namespaces provided by the datastores created with ncds_new() and initialized by ncds_init(). More... | |
int | nc_session_get_eventfd (const struct nc_session *session) |
Get the input file descriptor to asynchronous control of input events. More... | |
const char * | nc_session_get_host (const struct nc_session *session) |
Get NETCONF session host. More... | |
const char * | nc_session_get_id (const struct nc_session *session) |
Get NETCONF session ID. More... | |
const char * | nc_session_get_port (const struct nc_session *session) |
Get NETCONF session port number. More... | |
NC_SESSION_STATUS | nc_session_get_status (const struct nc_session *session) |
Get information about the session current status. More... | |
NC_TRANSPORT | nc_session_get_transport (const struct nc_session *session) |
Get transport protocol used for the NETCONF session. More... | |
const char * | nc_session_get_user (const struct nc_session *session) |
Get NETCONF session username. More... | |
int | nc_session_get_version (const struct nc_session *session) |
Get NETCONF protocol version used in the given session. More... | |
int | nc_session_monitor (struct nc_session *session) |
Add the session into the internal list of monitored sessions that are returned as part of netconf-state information defined in RFC 6022. More... | |
int | nc_session_notif_allowed (struct nc_session *session) |
Tell me if the notification subscription is allowed on the given session. More... | |
int | nc_session_transport (NC_TRANSPORT proto) |
Set transport protocol for the sessions created by subsequent nc_session_connect() calls. By default, transport protocol is set to NC_TRANSPORT_SSH. More... | |
int | nc_set_keypair_path (const char *privkey, const char *pubkey) |
Set path to a private and a public key file used in case of SSH authentication via a publickey mechanism. More... | |
void | nc_ssh_pref (NC_SSH_AUTH_TYPE type, short int preference) |
Set the preference of the SSH authentication methods. More... | |
libnetconf's functions for handling NETCONF sessions.
#define nc_msgid char* |
Type representing NETCONF message-id attribute.
It corresponds to the following typedef: typedef char* nc_msgid;
We use a macro to avoid compiler warning of 'const nc_msgid' as return type of functions (because const is applied as 'char* const funct()' which is meaningless).
Yes, I know that const char* means "pointer to constant character (not string)", but I want to be clear from the API, that function returns pointer to something that should not be changed.
enum NC_SESSION_STATUS |
Enumeration of the possible states of a NETCONF session.
Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
enum NC_SSH_AUTH_TYPE |
enum NC_TRANSPORT |
Supported NETCONF transport protocols enumeration. To change currently used transport protocol, call nc_session_transport().
Note that NC_TRANSPORT_TLS is supported only when libnetconf is compiled with –enable-tls configure's option. If the option is not used, nc_session_transport() returns EXIT_FAILURE with NC_TRANSPORT_TLS value.
This setting is valuable only for client side NETCONF applications.
Enumerator | |
---|---|
NC_TRANSPORT_UNKNOWN |
Unknown transport protocol, this is not acceptable as input value |
NC_TRANSPORT_SSH |
NETCONF over SSH, this value is used by default |
NC_TRANSPORT_TLS |
NETCONF over TLS |
void nc_callback_ssh_host_authenticity_check | ( | int(*)(const char *hostname, ssh_session session) | func | ) |
Set a callback function to authorize authenticity of the remote host.
To make this function available, you have to include libnetconf_ssh.h.
If the func parameter is NULL, the callback is set back to the default function.
[in] | func | Callback function to use. Expected callback return values are:
|
void nc_callback_sshauth_interactive | ( | char *(*)(const char *name, const char *instruction, const char *prompt, int echo) | func | ) |
Set a callback function for passing user credentials into the libssh's keyboard-interactive authentication method.
To make this function available, you have to include libnetconf_ssh.h.
If the func parameter is NULL, the callback is set back to the default function.
[in] | func | Callback function to use for interactive authentication. |
void nc_callback_sshauth_passphrase | ( | char *(*)(const char *username, const char *hostname, const char *priv_key_file) | func | ) |
Set a callback function for passing the user password into the libssh's publickey authentication method when connecting to 'hostname' as 'username'.
To make this function available, you have to include libnetconf_ssh.h.
If the func parameter is NULL, the callback is set back to the default function.
[in] | func | Callback function to use. |
void nc_callback_sshauth_password | ( | char *(*)(const char *username, const char *hostname) | func | ) |
Set a callback function for passing the user password into the libssh's password authentication method when connecting to 'hostname' as 'username'.
To make this function available, you have to include libnetconf_ssh.h.
If the func parameter is NULL, the callback is set back to the default function.
[in] | func | Callback function to use. The callback function should return a password string for the given username and name of the remote host. |
int nc_cpblts_add | ( | struct nc_cpblts * | capabilities, |
const char * | capability_string | ||
) |
Add another capability string into the NETCONF capabilities structure.
This function is NOT thread safe.
capabilities | Current NETCONF capabilities structure. |
capability_string | Capability string to add. |
int nc_cpblts_count | ( | const struct nc_cpblts * | c | ) |
Get the number of capabilities in the structure.
Use this function to get the count of capabilities held by nc_cpblts structure.
c | NETCONF capabilities structure. |
int nc_cpblts_enabled | ( | const struct nc_session * | session, |
const char * | capability_string | ||
) |
Check if the given capability is supported by the session.
session | Established session where the given capability support will be checked. |
capability_string | NETCONF capability string to check. |
void nc_cpblts_free | ( | struct nc_cpblts * | c | ) |
Free NETCONF capabilities structure.
This function is NOT thread safe.
c | Capabilities structure to free. |
const char* nc_cpblts_get | ( | const struct nc_cpblts * | c, |
const char * | capability_string | ||
) |
Get complete capability string including parameters.
[in] | c | Capabilities structure to be examined |
[in] | capability_string | Capability identifier, parameters are ignored and only basic identifier is used to retrieve specific identifier including parameters from the given capability structure. |
const char* nc_cpblts_iter_next | ( | struct nc_cpblts * | c | ) |
Get the next capability string from the given NETCONF capabilities structure.
To move iterator to the beginning of the capability strings list, use nc_cpblts_iter_start().
This function is NOT thread safe.
c | NETCONF capabilities structure to be iterated. |
void nc_cpblts_iter_start | ( | struct nc_cpblts * | c | ) |
Move NETCONF capabilities structure iterator to the beginning of the capability strings list.
This function is NOT thread safe.
c | NETCONF capabilities structure to be iterated. |
struct nc_cpblts* nc_cpblts_new | ( | const char *const | list[] | ) |
Create a new NETCONF capabilities structure.
list | NULL terminated list of capabilities strings to initially add into the NETCONF capabilities structure. |
int nc_cpblts_remove | ( | struct nc_cpblts * | capabilities, |
const char * | capability_string | ||
) |
Remove the specified capability string from the NETCONF capabilities structure.
This function is NOT thread safe.
capabilities | Current NETCONF capabilities structure. |
capability_string | Capability string to remove. |
int nc_del_keypair_path | ( | const char * | privkey, |
const char * | pubkey | ||
) |
Remove a private and a public key file.
To make this function available, you have to include libnetconf_ssh.h.
[in] | privkey | Path to the private key file. |
[in] | pubkey | Path to the public key file |
struct nc_session* nc_session_accept | ( | const struct nc_cpblts * | capabilities | ) |
Accept NETCONF session from a client.
The caller process of this function is supposed to be launched as a subprocess of the transport protocol server (in case of SSH, it is called SSH Subsystem). Username assigned to the NETCONF session is guessed from the process's UID. This approach supposes that the transport protocol server launches the caller process with the changed UID according to the user logged in (OpenSSH's sshd does this, stunnel does not - see nc_session_accept_username() instead of this function).
Only one NETCONF session can be accepted in a single caller since it communicates with the transport protocol server directly via (redirected) stdin and stdout streams.
[in] | capabilities | NETCONF capabilities structure with the capabilities supported by the server. The caller can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
struct nc_session* nc_session_accept_inout | ( | const struct nc_cpblts * | capabilities, |
const char * | username, | ||
int | input, | ||
int | output | ||
) |
Accept NETCONF session from a client. It allows to assign the specified username to it and set file descriptors for reading/writing NETCONF data.
The same as nc_session_accept_username() except that it allows caller to set file descriptors where the libnetconf will read/write NETCONF (unencrypted) data.
[in] | capabilities | NETCONF capabilities structure with the capabilities supported by the server. The caller can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
[in] | username | Name of the user which will be assigned to the NETCONF session. This information is used for example by NACM subsystem. If NULL, the function act the same way as the nc_session_accept() function. |
[in] | input | File descriptor from which the NETCONF data will be read. |
[in] | output | File descriptor to which the NETCONF data will be written. |
struct nc_session* nc_session_accept_username | ( | const struct nc_cpblts * | capabilities, |
const char * | username | ||
) |
Accept NETCONF session from a client and assign it to the specified username.
The same as nc_session_accept() except that instead of guessing username from the process's UID, the specified username is assigned to the NETCONF session. This can be used especially in case that the transport protocol server (sshd, stunnel,...) does not change process's UID automatically.
[in] | capabilities | NETCONF capabilities structure with the capabilities supported by the server. The caller can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
[in] | username | Name of the user which will be assigned to the NETCONF session. This information is used for example by NACM subsystem. If NULL, the function act the same way as the nc_session_accept() function. |
struct nc_session* nc_session_connect | ( | const char * | host, |
unsigned short | port, | ||
const char * | username, | ||
const struct nc_cpblts * | cpblts | ||
) |
Create NETCONF session to the specified server.
This function can internally use various callbacks set by the client to perform SSH authentication. It selects authentication mechanism from the list provided by the SSH server and based on the preferences set by the client via nc_ssh_pref(). Then, appropriate callback function (set by nc_callback_sshauth_password(), nc_callback_sshauth_passphrase(), nc_set_publickey_path() or nc_set_privatekey_path()) is used to perform the authentication.
[in] | host | Hostname or address (both Ipv4 and IPv6 are accepted). 'localhost' is used by default if NULL is specified. |
[in] | port | Port number of the server. Default value 830 is used if 0 is specified. |
[in] | username | Name of the user to login to the server. The user running the application (detected from the effective UID) is used if NULL is specified. |
[in] | cpblts | NETCONF capabilities structure with capabilities supported by the client. Client can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
struct nc_session* nc_session_connect_channel | ( | struct nc_session * | session, |
const struct nc_cpblts * | cpblts | ||
) |
Create another NETCONF session using already established SSH session. No authentication is needed in this case.
This function works only if libnetconf is compiled with using libssh.
It is not applicable to the sessions created by nc_session_connect_inout().
[in] | session | Already established NETCONF session using nc_session_connect(). |
[in] | cpblts | NETCONF capabilities structure with capabilities supported by the client. Client can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
struct nc_session* nc_session_connect_inout | ( | int | fd_in, |
int | fd_out, | ||
const struct nc_cpblts * | cpblts, | ||
const char * | host, | ||
const char * | port, | ||
const char * | username, | ||
NC_TRANSPORT | transport | ||
) |
Create NETCONF session communicating via given file descriptors. This is an alternative function to nc_session_connect().
In this case the initiation of the transport session (SSH, TLS, ...) is done externally. libnetconf just uses provided file descriptors to read data from and write data to that external entity (process, functions,...).
Before calling this function, all necessary authentication process must be done so libnetconf can directly start with <hello> messages performing the NETCONF handshake.
Since connecting to a host and authentication is done before, the provided host, port, username anf transport arguments are only informative and libnetconf use them only for returning value by nc_session_get_*() functions. The cpblts argument is used during the NETCONF handshake in the same way as in the nc_session_connect() function.
It is not allowed to use nc_session_connect_channel() on the session created by this function.
[in] | fd_in | Opened file desriptor where the (unencrypted) data from the NETCONF server are read. |
[in] | fd_out | Opened file desriptor where the (unencrypted) data to the NETCONF server are written. |
[in] | cpblts | NETCONF capabilities structure with capabilities supported by the client. Client can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
[in] | host | Name of the host where we are connected to via the provided file descriptors. |
[in] | port | The port number of the remote host where we are connected. |
[in] | username | Name of the user we are connected to the remote host as. |
[in] | transport | The transport protocol used to connect to the remote host. |
struct nc_session* nc_session_connect_libssh_sess | ( | const char * | host, |
unsigned short | port, | ||
const char * | username, | ||
const struct nc_cpblts * | cpblts, | ||
ssh_session | ssh_sess | ||
) |
Create NETCONF session to the specified server using a custom SSH session.
This function works only if libnetconf is compiled with using libssh.
It shares all the functionality of nc_session_connect(), but also enables to use a customized SSH session with some specific options set.
[in] | host | Hostname or address (both Ipv4 and IPv6 are accepted). 'localhost' is used by default if NULL is specified. |
[in] | port | Port number of the server. Default value 830 is used if 0 is specified. |
[in] | username | Name of the user to login to the server. The user running the application (detected from the effective UID) is used if NULL is specified. |
[in] | cpblts | NETCONF capabilities structure with capabilities supported by the client. Client can use nc_session_get_cpblts_default() to get the structure with the list of all the capabilities supported by libnetconf (this is used in case of a NULL parameter). |
[in] | ssh_sess | Customized libssh SSH session structure. Options SSH_OPTIONS_HOST, SSH_OPTIONS_USER, SSH_OPTIONS_FD, and SSH_OPTIONS_TIMEOUT should not be set as they will get set internally and previous values will be ignored. The structure will get freed and it should not be manipulated after passed as a parameter. |
struct nc_session* nc_session_dummy | ( | const char * | sid, |
const char * | username, | ||
const char * | hostname, | ||
struct nc_cpblts * | capabilities | ||
) |
Create a disconnected session structure.
This creates a dummy session structure which is not supposed to exchange NETCONF messages between client and server. Instead, it can be successfully used by server (e.g. detached process that doesn't hold the real session structure) to access NETCONF datastores via libnetconf.
All the required parameters can be obtained from the real session structure by the session getter functions (nc_session_get_id(), nc_session_get_user() and nc_session_get_cpblts()). NULL values are not allowed.
[in] | sid | Session ID. |
[in] | username | Name of the user holding the session. |
[in] | hostname | Name (domain name, IP) of the opposite communication side (optional parameter, can be NULL). |
[in] | capabilities | List of capabilities supported by the session. |
void nc_session_free | ( | struct nc_session * | session | ) |
Cleanup the session structure and free all the allocated resources.
Do not use the given session structure after this call. If this session was created with nc_session_accept_tls() or nc_session_accept_libssh_channel(), the library transport structures are not freed or modified in any way.
[in] | session | Session to free. |
struct nc_cpblts* nc_session_get_cpblts | ( | const struct nc_session * | session | ) |
Get list of capabilities associated with the session.
Returned structure is connected with the session. Do not free or modify it.
[in] | session | NETCONF session structure |
struct nc_cpblts* nc_session_get_cpblts_default | ( | void | ) |
Get NULL terminated list of the default capabilities supported by libnetconf including the list of namespaces provided by the datastores created with ncds_new() and initialized by ncds_init().
The caller is supposed to free the returned structure with nc_cpblts_free().
int nc_session_get_eventfd | ( | const struct nc_session * | session | ) |
Get the input file descriptor to asynchronous control of input events.
The caller must avoid direct reading from the returned file descriptor. It is supposed to be used only by select, poll, epoll or an event library (e.g. libevent).
[in] | session | NETCONF session structure |
const char* nc_session_get_host | ( | const struct nc_session * | session | ) |
Get NETCONF session host.
[in] | session | NETCONF session structure |
const char* nc_session_get_id | ( | const struct nc_session * | session | ) |
Get NETCONF session ID.
[in] | session | NETCONF session structure |
const char* nc_session_get_port | ( | const struct nc_session * | session | ) |
Get NETCONF session port number.
[in] | session | NETCONF session structure |
NC_SESSION_STATUS nc_session_get_status | ( | const struct nc_session * | session | ) |
Get information about the session current status.
[in] | session | NETCONF session. |
NC_TRANSPORT nc_session_get_transport | ( | const struct nc_session * | session | ) |
Get transport protocol used for the NETCONF session.
[in] | session | NETCONF session structure |
const char* nc_session_get_user | ( | const struct nc_session * | session | ) |
Get NETCONF session username.
[in] | session | NETCONF session structure |
int nc_session_get_version | ( | const struct nc_session * | session | ) |
Get NETCONF protocol version used in the given session.
[in] | session | NETCONF session structure |
int nc_session_monitor | ( | struct nc_session * | session | ) |
Add the session into the internal list of monitored sessions that are returned as part of netconf-state information defined in RFC 6022.
session | Session to be monitored; |
int nc_session_notif_allowed | ( | struct nc_session * | session | ) |
Tell me if the notification subscription is allowed on the given session.
[in] | session | NETCONF session structure |
int nc_session_transport | ( | NC_TRANSPORT | proto | ) |
Set transport protocol for the sessions created by subsequent nc_session_connect() calls. By default, transport protocol is set to NC_TRANSPORT_SSH.
This function is thread-safe. Change made by calling this function applies only to the current thread.
int nc_set_keypair_path | ( | const char * | privkey, |
const char * | pubkey | ||
) |
Set path to a private and a public key file used in case of SSH authentication via a publickey mechanism.
To make this function available, you have to include libnetconf_ssh.h.
[in] | privkey | Path to the private key file. |
[in] | pubkey | Path to the public key file |
void nc_ssh_pref | ( | NC_SSH_AUTH_TYPE | type, |
short int | preference | ||
) |
Set the preference of the SSH authentication methods.
Allowed authentication types are defined as NC_SSH_AUTH_TYPE type. The default preferences are:
This function has no effect with configure's –disable-libssh option.
To make this function available, you have to include libnetconf_ssh.h header file.
[in] | type | Setting preference for the given authentication type. |
[in] | preference | Preference value. Higher value means higher preference. Negative value disables the given authentication type. On equality of values, the last set authentication type is preferred. |