#include "nufw_source.h"#include <config.h>#include "../lib/nuclient.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <locale.h>#include <sys/resource.h>#include <langinfo.h>#include <stdarg.h>#include <signal.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/types.h>#include <termios.h>#include "proto.h"#include "security.h"#include "debug.h"#include <nubase.h>Include dependency graph for nutcpc.c:

Go to the source code of this file.
Data Structures | |
| struct | nutcpc_context_t |
Defines | |
| #define | NUTCPC_VERSION PACKAGE_VERSION " $Revision: 4935 $" |
| #define | MAX_RETRY_TIME 30 |
Functions | |
| void | panic (const char *fmt,...) |
| char * | compute_run_pid () |
| int | test_nutcpc (pid_t *pid) |
| void | kill_nutcpc () |
| void | leave_client () |
| void | exit_clean () |
| ssize_t | my_getpass (char **lineptr, size_t *linelen) |
| char * | get_password () |
| char * | get_username () |
| static void | usage (void) |
| void | process_hup (int signum) |
| void | install_signals () |
| void | daemonize_process (nutcpc_context_t *context, char *runpid) |
| void | wipe (void *data, size_t datalen) |
| void | display_cert (nuauth_session_t *session) |
| nuauth_session_t * | do_connect (nutcpc_context_t *context, char *username) |
| void | main_loop (nutcpc_context_t *context) |
| char * | copy_filename (char *name) |
| void | parse_cmdline_options (int argc, char **argv, nutcpc_context_t *context, char **username) |
| void | init_library (nutcpc_context_t *context, char *username) |
| int | main (int argc, char **argv) |
Variables | |
| termios | orig |
| nuauth_session_t * | session = NULL |
| nuclient_error_t * | err = NULL |
| sigaction | old_sigterm |
| sigaction | old_sigint |
| int | forced_reconnect = 0 |
| #define MAX_RETRY_TIME 30 |
| #define NUTCPC_VERSION PACKAGE_VERSION " $Revision: 4935 $" |
| char* compute_run_pid | ( | ) |
Compure run pid filename: "$HOME/.nufw/nutcpc"
Definition at line 106 of file nutcpc.c.
References nu_get_home_dir(), and secure_snprintf().
Referenced by kill_nutcpc(), leave_client(), main(), and test_nutcpc().
Here is the call graph for this function:

| char* copy_filename | ( | char * | name | ) |
Copy a filename given on the command line. If it doesn't start with '/', add current directory as prefix.
Returns NULL on error, new allocated string otherwise.
Definition at line 648 of file nutcpc.c.
References RETURN_NO_LOG, and secure_snprintf().
Referenced by parse_cmdline_options().
Here is the call graph for this function:

| void daemonize_process | ( | nutcpc_context_t * | context, | |
| char * | runpid | |||
| ) |
Daemonize the process
Definition at line 441 of file nutcpc.c.
References nutcpc_context_t::donotuselock.
Referenced by main().
| void display_cert | ( | nuauth_session_t * | session | ) |
Display informations about the user certificate
Definition at line 499 of file nutcpc.c.
References nu_client_get_cert_infos(), nu_client_get_server_cert_infos(), and session.
Referenced by init_library().
Here is the call graph for this function:

| nuauth_session_t* do_connect | ( | nutcpc_context_t * | context, | |
| char * | username | |||
| ) |
Try to connect to nuauth.
Definition at line 515 of file nutcpc.c.
References nutcpc_context_t::cafile, nutcpc_context_t::certfile, nutcpc_context_t::debug_mode, err, get_password(), get_username(), nutcpc_context_t::keyfile, nutcpc_context_t::krb5_service, nu_client_connect(), nu_client_default_hostname(), nu_client_default_port(), nu_client_delete(), nu_client_new_callback(), nu_client_set_ca(), nu_client_set_debug(), nu_client_set_key(), nu_client_set_krb5_service(), nu_client_set_nuauth_cert_dn(), nu_client_set_password(), nu_client_set_pkcs12(), nu_client_set_username(), nu_client_strerror(), NUAUTH_IP, nutcpc_context_t::nuauthdn, nutcpc_context_t::password, nutcpc_context_t::pkcs12file, nutcpc_context_t::pkcs12password, nutcpc_context_t::port, SECURE_STRNCPY, session, nutcpc_context_t::srv_addr, and USERPCKT_SERVICE.
Referenced by init_library(), nufw_client_func(), and nussl_open_connection().
Here is the call graph for this function:

| void exit_clean | ( | ) |
Signal handler: catch SIGINT or SIGTERM. This function will exit nutcpc: deinit libnuclient, free memory, and then exit the process.
The function will first reinstall old handlers.
Definition at line 225 of file nutcpc.c.
References leave_client(), old_sigint, and old_sigterm.
Referenced by install_signals().
Here is the call graph for this function:

| char* get_password | ( | ) |
Callback used in nu_client_connect() call: read password
Definition at line 311 of file nutcpc.c.
References my_getpass().
Referenced by do_connect().
Here is the call graph for this function:

| char* get_username | ( | ) |
Callback used in nu_client_connect() call: read user name
Definition at line 348 of file nutcpc.c.
Referenced by do_connect().
| void init_library | ( | nutcpc_context_t * | context, | |
| char * | username | |||
| ) |
Initialize nuclient library
Definition at line 790 of file nutcpc.c.
References nutcpc_context_t::debug_mode, display_cert(), do_connect(), err, nu_client_error_init(), nu_client_global_init(), nu_client_strerror(), session, and nutcpc_context_t::srv_addr.
Referenced by main().
Here is the call graph for this function:

| void install_signals | ( | ) |
Install signal handlers:
Definition at line 412 of file nutcpc.c.
References exit_clean(), old_sigint, old_sigterm, and process_hup().
Referenced by main().
Here is the call graph for this function:

| void kill_nutcpc | ( | ) |
Kill existing instance of nutcpc: read pid file, and then send SIGTERM to the process.
Exit the program at the end of this function.
Definition at line 152 of file nutcpc.c.
References compute_run_pid(), and test_nutcpc().
Referenced by parse_cmdline_options().
Here is the call graph for this function:

| void leave_client | ( | ) |
Leave the client:
Definition at line 195 of file nutcpc.c.
References compute_run_pid(), err, nu_client_delete(), nu_client_error_destroy(), nu_client_global_deinit(), and session.
Referenced by exit_clean(), and main().
Here is the call graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 830 of file nutcpc.c.
References compute_run_pid(), daemonize_process(), init_library(), install_signals(), leave_client(), main_loop(), nu_check_version(), nu_get_version(), NUCLIENT_VERSION, NUTCPC_VERSION, and parse_cmdline_options().
Here is the call graph for this function:

| void main_loop | ( | nutcpc_context_t * | context | ) |
Main loop: program stay in this loop until it stops.
Definition at line 602 of file nutcpc.c.
References err, forced_reconnect, MAX_RETRY_TIME, nu_client_connect(), nu_client_reset(), nu_client_strerror(), nutcpc_context_t::port, session, nutcpc_context_t::srv_addr, and nutcpc_context_t::tempo.
Referenced by main(), and nufw_client_func().
Here is the call graph for this function:

| ssize_t my_getpass | ( | char ** | lineptr, | |
| size_t * | linelen | |||
| ) |
Read a password on terminal. Given buffer may grow up (resized by realloc).
| lineptr | Pointer to buffer | |
| linelen | Initial length (including nul byte) of the buffer |
Definition at line 273 of file nutcpc.c.
References orig.
Referenced by get_password().
| void panic | ( | const char * | fmt, | |
| ... | ||||
| ) |
| void parse_cmdline_options | ( | int | argc, | |
| char ** | argv, | |||
| nutcpc_context_t * | context, | |||
| char ** | username | |||
| ) |
Parse command line options
Definition at line 674 of file nutcpc.c.
References nutcpc_context_t::cafile, nutcpc_context_t::certfile, copy_filename(), nutcpc_context_t::debug_mode, nutcpc_context_t::donotuselock, nutcpc_context_t::interval, nutcpc_context_t::keyfile, kill_nutcpc(), nutcpc_context_t::krb5_service, nutcpc_context_t::nuauthdn, NUTCPC_VERSION, nutcpc_context_t::password, nutcpc_context_t::pkcs12file, nutcpc_context_t::pkcs12password, nutcpc_context_t::port, SECURE_STRNCPY, nutcpc_context_t::srv_addr, nutcpc_context_t::tempo, test_nutcpc(), and usage().
Referenced by main().
Here is the call graph for this function:

| void process_hup | ( | int | signum | ) |
Definition at line 402 of file nutcpc.c.
References forced_reconnect.
Referenced by install_signals().
| int test_nutcpc | ( | pid_t * | pid | ) |
Test if a nutcpc is currently running
Definition at line 127 of file nutcpc.c.
References compute_run_pid().
Referenced by kill_nutcpc(), and parse_cmdline_options().
Here is the call graph for this function:

| static void usage | ( | void | ) | [static] |
| nuclient_error_t* err = NULL |
Definition at line 58 of file nutcpc.c.
Referenced by _nu_client_new(), acl_check(), decimal_to_number(), do_connect(), init_library(), init_sasl(), ldap_conn_init(), leave_client(), main_loop(), mysasl_negotiate(), nu_client_check(), nu_client_connect(), nu_client_error_destroy(), nu_client_error_init(), nu_client_global_init(), nu_client_load_ca(), nu_client_load_key(), nu_client_load_pkcs12(), nu_client_new(), nu_client_new_callback(), nu_client_real_check(), nu_client_strerror(), nussl_sock_init(), packetsrv(), recv_message(), samp_recv(), samp_send(), sasl_user_check(), send_os(), str_to_long(), and str_to_ulong().
| int forced_reconnect = 0 |
| struct sigaction old_sigint |
| struct sigaction old_sigterm |
| struct termios orig |
| nuauth_session_t* session = NULL |
Definition at line 57 of file nutcpc.c.
Referenced by _nu_client_new(), acquire_nufw_session_by_addr(), activate_client_by_socket(), add_packet_to_send(), add_user_information(), ask_session_end(), auth_error_log(), compare(), create_message_autherr(), create_message_session(), declare_dead_nufw_session(), delete_client_by_socket_ext(), delete_session_from_hash(), display_cert(), do_connect(), encode_nufw(), encode_user(), exit_client(), get_client_sockets_by_ip(), get_nufw_server_by_addr(), increase_nufw_session_usage(), increase_refresh_delay(), init_library(), init_sasl(), kill_all_clients_cb(), leave_client(), log_user_session_thread(), main_loop(), modules_auth_error_log(), modules_user_check(), mysasl_negotiate(), mysasl_negotiate_v3(), nu_client_check(), nu_client_connect(), nu_client_delete(), nu_client_get_cert_infos(), nu_client_get_server_cert_infos(), nu_client_load_ca(), nu_client_load_key(), nu_client_load_pkcs12(), nu_client_new(), nu_client_new_callback(), nu_client_real_check(), nu_client_reset(), nu_client_set_ca(), nu_client_set_debug(), nu_client_set_key(), nu_client_set_krb5_service(), nu_client_set_max_delay(), nu_client_set_min_delay(), nu_client_set_nuauth_cert_dn(), nu_client_set_password(), nu_client_set_pkcs12(), nu_client_set_source(), nu_client_set_username(), nu_client_set_verbose(), nu_client_strerror(), nu_exit_clean(), nu_get_userdatas(), nu_get_usersecret(), nufw_client_func(), nufw_session_send(), recv_message(), release_nufw_session(), reset_refresh_delay(), samp_recv(), samp_send(), send_conntrack_message(), send_hello_pckt(), send_os(), send_user_pckt(), suppress_nufw_session(), tcptable_read(), user_session_modify(), and warn_clients().
1.4.7