API of libnuclient
[Libnuclient]

Collaboration diagram for API of libnuclient:

The high level API of libnuclient can be used to build a NuFW client. More...

Functions

int nu_client_check (nuauth_session_t *session, nuclient_error_t *err)
 Function called by client to initiate a check.
void nu_client_delete (nuauth_session_t *session)
 Destroy a client session: free all used memory.
int nu_client_global_init (nuclient_error_t *err)
 global initialisation function
void nu_client_global_deinit ()
 Global de init function.
void nu_client_set_username (nuauth_session_t *session, const char *username)
 Set username.
void nu_client_set_password (nuauth_session_t *session, const char *password)
 Set password.
char * nu_get_home_dir ()
int nu_client_load_key (nuauth_session_t *session, char *keyfile, char *certfile, nuclient_error_t *err)
int nu_client_load_pkcs12 (nuauth_session_t *session, char *pkcs12file, char *pkcs12password, nuclient_error_t *err)
int nu_client_load_ca (nuauth_session_t *session, char *cafile, nuclient_error_t *err)
char * nu_client_get_cert_infos (nuauth_session_t *session)
char * nu_client_get_server_cert_infos (nuauth_session_t *session)
int nu_client_set_nuauth_cert_dn (nuauth_session_t *session, char *nuauth_cert_dn, nuclient_error_t *err)
void nu_client_set_source (nuauth_session_t *session, struct sockaddr_storage *addr)
nuauth_session_tnu_client_new_callback (void *username_callback, void *passwd_callback, unsigned char diffie_hellman, nuclient_error_t *err)
 Create new session and use callbacks.
nuauth_session_tnu_client_new (const char *username, const char *password, unsigned char diffie_hellman, nuclient_error_t *err)
 Create new session.
void nu_client_reset (nuauth_session_t *session)
int nu_client_connect (nuauth_session_t *session, const char *hostname, const char *service, nuclient_error_t *err)
void nu_client_set_verbose (nuauth_session_t *session, unsigned char enabled)
void nu_client_set_min_delay (nuauth_session_t *session, unsigned int delay)
void nu_client_set_max_delay (nuauth_session_t *session, unsigned int delay)
int nu_client_error_init (nuclient_error_t **err)
 Allocate a structure to store client error.
void nu_client_error_destroy (nuclient_error_t *err)
 Destroy an error (free memory).
const char * nu_client_strerror (nuauth_session_t *session, nuclient_error_t *err)
 Convert an error to an human readable string.
const char * nu_get_version ()
int nu_check_version (const char *version)
void nu_client_set_debug (nuauth_session_t *session, unsigned char enabled)

Detailed Description

The high level API of libnuclient can be used to build a NuFW client.

A client needs to call a few functions in the correct order to be able to authenticate:

On error, don't forget to delete session with nu_client_delete()


Function Documentation

int nu_check_version ( const char *  version  ) 

Check if libnuclient if the specified version. Use NUCLIENT_VERSION as argument. See also function nu_get_version().

Returns:
Return 1 if ok, 0 if versions are different.

Definition at line 803 of file libnuclient.c.

References NUCLIENT_VERSION.

Referenced by main(), and pam_sm_authenticate().

int nu_client_check ( nuauth_session_t session,
nuclient_error_t err 
)

Function called by client to initiate a check.

It has to be run in an endless loop.

Parameters:
session A pointer to a valid nuauth_session_t session
err A pointer to a allocated nuclient_error_t
Returns:
1 if success, -1 if a problem occurs. Session is destroyed if nu_client_check() return -1;
Internal
It is in charge of cleaning session as the session may be used by user and we have no control of it.

Definition at line 162 of file checks.c.

References ask_session_end(), nuauth_session::connected, err, increase_refresh_delay(), INTERNAL_ERROR, NO_ERR, nu_client_real_check(), NU_EXIT_ERROR, nuauth_session::nussl, nussl_session_get_fd(), recv_message(), send_hello_pckt(), SENT_TEST_INTERVAL, nuauth_session::server_mode, session, SESSION_NOT_CONNECTED_ERR, SET_ERROR, nuauth_session::sleep_delay, SRV_TYPE_POLL, TIMEOUT_ERR, nuauth_session::timestamp_last_sent, and UNKNOWN_ERR.

Referenced by main_loop().

Here is the call graph for this function:

int nu_client_connect ( nuauth_session_t session,
const char *  hostname,
const char *  service,
nuclient_error_t err 
)

Try to connect to nuauth server:

Parameters:
session Pointer to client session
hostname String containing hostname of nuauth server (default: NUAUTH_IP)
service Port number (or string) on which nuauth server is listening (default: USERPCKT_SERVICE)
err Pointer to a nuclient_error_t: which contains the error
Returns:
Returns 0 on error (error description in err), 1 otherwise

Definition at line 610 of file libnuclient.c.

References nuauth_session::connected, err, init_sasl(), nu_client_load_ca(), nu_client_load_key(), nu_client_load_pkcs12(), nuauth_session::nussl, NUSSL_ERR, NUSSL_OK, nussl_open_connection(), nussl_session_create(), nussl_session_destroy(), nussl_set_hostinfo(), nuauth_session::pem_ca, nuauth_session::pem_cert, nuauth_session::pem_key, nuauth_session::pkcs12_file, nuauth_session::pkcs12_password, send_os(), session, and SET_ERROR.

Referenced by do_connect(), and main_loop().

Here is the call graph for this function:

void nu_client_delete ( nuauth_session_t session  ) 

Destroy a client session: free all used memory.

This destroy a session and free all related structures.

Parameters:
session A nuauth_session_t session to be cleaned

Definition at line 101 of file libnuclient.c.

References ask_session_end(), nu_exit_clean(), and session.

Referenced by do_connect(), exit_client(), and leave_client().

Here is the call graph for this function:

void nu_client_error_destroy ( nuclient_error_t err  ) 

Destroy an error (free memory).

Definition at line 724 of file libnuclient.c.

References err.

Referenced by exit_client(), and leave_client().

int nu_client_error_init ( nuclient_error_t **  err  ) 

Allocate a structure to store client error.

Definition at line 710 of file libnuclient.c.

References err.

Referenced by init_library(), and nufw_client_func().

char* nu_client_get_cert_infos ( nuauth_session_t session  ) 

Returns a formated string containing information about the user certificate

Parameters:
session Pointer to client session
Returns:

Definition at line 409 of file libnuclient.c.

References nuauth_session::nussl, nussl_get_cert_infos(), and session.

Referenced by display_cert().

Here is the call graph for this function:

char* nu_client_get_server_cert_infos ( nuauth_session_t session  ) 

Returns a formated string containing information about the server certificate

Parameters:
session Pointer to client session
Returns:

Definition at line 422 of file libnuclient.c.

References nuauth_session::nussl, nussl_get_server_cert_infos(), and session.

Referenced by display_cert().

Here is the call graph for this function:

void nu_client_global_deinit (  ) 

Global de init function.

Warning:
To be called once, when leaving.

Definition at line 152 of file libnuclient.c.

Referenced by exit_client(), and leave_client().

int nu_client_global_init ( nuclient_error_t err  ) 

global initialisation function

This function inits all library needed to initiate a connection to a nuauth server

Parameters:
err A pointer to a nuclient_error_t which contains at exit the error
Warning:
To be called only once.

Definition at line 118 of file libnuclient.c.

References err, INTERNAL_ERROR, load_sys_config(), nu_locale_charset, nussl_init(), NUSSL_INIT_ERR, NUSSL_OK, SASL_ERROR, and SET_ERROR.

Referenced by init_library(), and nufw_client_func().

Here is the call graph for this function:

int nu_client_load_ca ( nuauth_session_t session,
char *  cafile,
nuclient_error_t err 
)

Initialize TLS:

Parameters:
session Pointer to client session
cafile Complete path to a certificate authority file stored in PEM format (can be NULL)
err Pointer to a nuclient_error_t: which contains the error
Returns:
Returns 0 on error (error description in err), 1 otherwise

Definition at line 366 of file libnuclient.c.

References err, nu_get_home_dir(), nuauth_session::nussl, NUSSL_ERR, NUSSL_OK, nussl_ssl_trust_cert_file(), secure_snprintf(), session, and SET_ERROR.

Referenced by nu_client_connect().

Here is the call graph for this function:

int nu_client_load_key ( nuauth_session_t session,
char *  keyfile,
char *  certfile,
nuclient_error_t err 
)

Initialize TLS:

Parameters:
session Pointer to client session
keyfile Complete path to a key file stored in PEM format (can be NULL)
certfile Complete path to a certificate file stored in PEM format (can be NULL)
err Pointer to a nuclient_error_t: which contains the error
Returns:
Returns 0 on error (error description in err), 1 otherwise

Definition at line 274 of file libnuclient.c.

References err, nu_get_home_dir(), nuauth_session::nussl, NUSSL_ERR, NUSSL_OK, nussl_ssl_set_keypair(), secure_snprintf(), session, and SET_ERROR.

Referenced by nu_client_connect().

Here is the call graph for this function:

int nu_client_load_pkcs12 ( nuauth_session_t session,
char *  pkcs12file,
char *  pkcs12password,
nuclient_error_t err 
)

Initialize TLS:

Parameters:
session Pointer to client session
pkcs12file Complete path to a key and a certificate file stored in PEM format (can be NULL)
pkcs12password Password of the pkcs12 file
err Pointer to a nuclient_error_t: which contains the error
Returns:
Returns 0 on error (error description in err), 1 otherwise

Definition at line 342 of file libnuclient.c.

References err, nuauth_session::nussl, NUSSL_ERR, NUSSL_OK, nussl_ssl_set_pkcs12_keypair(), session, and SET_ERROR.

Referenced by nu_client_connect().

Here is the call graph for this function:

nuauth_session_t* nu_client_new ( const char *  username,
const char *  password,
unsigned char  diffie_hellman,
nuclient_error_t err 
)

Create new session.

This function has to be used to create a new nuauth_session_t if there is no plan to use a callback for getting username or password.

Parameters:
username User name string
password Password string
diffie_hellman If equals to 1, use Diffie Hellman for key exchange (very secure but initialization is slower)
err Pointer to a nuclient_error_t: which contains the error
Returns:
A pointer to a valid nuauth_session_t structure or NULL if init has failed

Definition at line 559 of file libnuclient.c.

References _nu_client_new(), BAD_CREDENTIALS_ERR, err, INTERNAL_ERROR, MEMORY_ERR, nuauth_session::password, secure_str_copy(), session, SET_ERROR, and nuauth_session::username.

Referenced by do_connect().

Here is the call graph for this function:

nuauth_session_t* nu_client_new_callback ( void *  username_callback,
void *  passwd_callback,
unsigned char  diffie_hellman,
nuclient_error_t err 
)

Create new session and use callbacks.

Callbacks are used to fetch username and password if they are necessary for SASL negotiation.

Parameters:
username_callback User name retrieving callback
passwd_callback Password retrieving callback
diffie_hellman If equals to 1, use Diffie Hellman for key exchange (very secure but initialization is slower)
err Pointer to a nuclient_error_t: which contains the error
Returns:
A pointer to a valid nuauth_session_t structure or NULL if init has failed

Definition at line 525 of file libnuclient.c.

References _nu_client_new(), BAD_CREDENTIALS_ERR, err, INTERNAL_ERROR, nuauth_session::passwd_callback, session, SET_ERROR, and nuauth_session::username_callback.

Referenced by do_connect().

Here is the call graph for this function:

void nu_client_reset ( nuauth_session_t session  ) 

Reset a session: close the connection and reset attributes. So the session can be used as nu_client_connect() input.

Definition at line 587 of file libnuclient.c.

References ask_session_end(), nuauth_session::connected, session, and nuauth_session::timestamp_last_sent.

Referenced by main_loop().

Here is the call graph for this function:

void nu_client_set_debug ( nuauth_session_t session,
unsigned char  enabled 
)

Enable or disabled debug mode

Parameters:
session Pointer to client session
enabled Enable debug if different than zero (1), disable otherwise

Definition at line 660 of file libnuclient.c.

References nuauth_session::debug_mode, and session.

Referenced by do_connect().

void nu_client_set_max_delay ( nuauth_session_t session,
unsigned int  delay 
)

Set maximum delay

Parameters:
session Pointer to client session
delay a timeval which will be equal to the maximum delay between two checks (in ms)

Definition at line 700 of file libnuclient.c.

References nuauth_session::max_sleep_delay, and session.

void nu_client_set_min_delay ( nuauth_session_t session,
unsigned int  delay 
)

Set minimum delay

Parameters:
session Pointer to client session
delay a timeval which will be equal to the minimum delay between two checks (in ms)

Definition at line 686 of file libnuclient.c.

References nuauth_session::min_sleep_delay, and session.

int nu_client_set_nuauth_cert_dn ( nuauth_session_t session,
char *  nuauth_cert_dn,
nuclient_error_t err 
)

Definition at line 431 of file libnuclient.c.

References nuauth_session::nuauth_cert_dn, and session.

Referenced by do_connect().

void nu_client_set_password ( nuauth_session_t session,
const char *  password 
)

Set password.

Definition at line 175 of file libnuclient.c.

References nu_client_to_utf8(), nu_locale_charset, nuauth_session::password, secure_str_copy(), and session.

Referenced by do_connect().

Here is the call graph for this function:

void nu_client_set_source ( nuauth_session_t session,
struct sockaddr_storage *  addr 
)

Set IP source of the socket used to connect to nuauth server

Parameters:
session Pointer to client session
addr Address of the socket

Definition at line 448 of file libnuclient.c.

References nuauth_session::has_src_addr, session, and nuauth_session::src_addr.

void nu_client_set_username ( nuauth_session_t session,
const char *  username 
)

Set username.

Definition at line 162 of file libnuclient.c.

References nu_client_to_utf8(), nu_locale_charset, secure_str_copy(), session, and nuauth_session::username.

Referenced by do_connect().

Here is the call graph for this function:

void nu_client_set_verbose ( nuauth_session_t session,
unsigned char  enabled 
)

Enable or disabled verbose mode

Parameters:
session Pointer to client session
enabled Enable verbose mode if different than zero (1), disable otherwise

Definition at line 673 of file libnuclient.c.

References session, and nuauth_session::verbose.

const char* nu_client_strerror ( nuauth_session_t session,
nuclient_error_t err 
)

Convert an error to an human readable string.

Definition at line 734 of file libnuclient.c.

References BAD_CREDENTIALS_ERR, BINDING_ERR, CANT_CONNECT_ERR, DNS_RESOLUTION_ERR, err, nuclient_error_t::error, nuclient_error_t::family, FILE_ACCESS_ERR, INTERNAL_ERROR, MEMORY_ERR, NO_ADDR_ERR, NO_ERR, nuauth_session::nussl, NUSSL_ERR, nussl_get_error(), NUSSL_INIT_ERR, SASL_ERROR, SEND_ERR, session, SESSION_NOT_CONNECTED_ERR, TCPTABLE_ERR, and TIMEOUT_ERR.

Referenced by do_connect(), init_library(), main_loop(), and nufw_client_func().

Here is the call graph for this function:

char* nu_get_home_dir (  ) 

Get user home directory

Returns:
A string that need to be freed

Definition at line 192 of file libnuclient.c.

Referenced by _get_runpid(), compute_run_pid(), load_sys_config(), nu_client_load_ca(), and nu_client_load_key().

const char* nu_get_version (  ) 

Get version of nuclient library (eg. "2.1.1-3")

Returns:
Nuclient version string

Definition at line 791 of file libnuclient.c.

References NUCLIENT_VERSION.

Referenced by main(), and pam_sm_authenticate().


Generated on Thu Jul 24 04:00:40 2008 for NuFW by  doxygen 1.4.7