X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ftincd.c;h=a99b81bc8de82b58013adbc2ad3cc737bacf3577;hp=89519c15da60e2e1e69905975b64e4fe0d384916;hb=b4c1d4e2d3287acd7ca438455c64e50a2828ad24;hpb=73f7efddd723b25c1477ec1139dc7211307ff660 diff --git a/src/tincd.c b/src/tincd.c index 89519c15..a99b81bc 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10.4.14 2000/10/20 19:46:58 guus Exp $ + $Id: tincd.c,v 1.10.4.23 2000/10/30 10:19:06 guus Exp $ */ #include "config.h" @@ -33,6 +33,8 @@ #include #include #include +#include +#include #ifdef HAVE_SYS_IOCTL_H # include @@ -43,10 +45,10 @@ #include #include "conf.h" -#include "encr.h" #include "net.h" #include "netutl.h" #include "protocol.h" +#include "subnet.h" #include "system.h" @@ -88,7 +90,7 @@ static struct option const long_options[] = { "help", no_argument, &show_help, 1 }, { "version", no_argument, &show_version, 1 }, { "no-detach", no_argument, &do_detach, 0 }, - { "keygen", optional_argument, NULL, 'K'}, + { "generate-keys", optional_argument, NULL, 'K'}, { NULL, 0, NULL, 0 } }; @@ -100,14 +102,14 @@ usage(int status) else { printf(_("Usage: %s [option]...\n\n"), program_name); - printf(_(" -c, --config=DIR Read configuration options from DIR.\n" - " -D, --no-detach Don't fork and detach.\n" - " -d Increase debug level.\n" - " -k, --kill Attempt to kill a running tincd and exit.\n" - " -n, --net=NETNAME Connect to net NETNAME.\n")); - printf(_(" -K, --keygen[=BITS] Generate public/private RSA keypair.\n" - " --help Display this help and exit.\n" - " --version Output version information and exit.\n\n")); + printf(_(" -c, --config=DIR Read configuration options from DIR.\n" + " -D, --no-detach Don't fork and detach.\n" + " -d Increase debug level.\n" + " -k, --kill Attempt to kill a running tincd and exit.\n" + " -n, --net=NETNAME Connect to net NETNAME.\n")); + printf(_(" -K, --generate-keys[=BITS] Generate public/private RSA keypair.\n" + " --help Display this help and exit.\n" + " --version Output version information and exit.\n\n")); printf(_("Report bugs to tinc@nl.linux.org.\n")); } exit(status); @@ -118,8 +120,7 @@ parse_options(int argc, char **argv, char **envp) { int r; int option_index = 0; - config_t *p; - + while((r = getopt_long(argc, argv, "c:Ddkn:K::", long_options, &option_index)) != EOF) { switch(r) @@ -204,9 +205,6 @@ int keygen(int bits) { RSA *rsa_key; - fprintf(stderr, _("Seeding the PRNG: please press some keys or move\nthe mouse if this program seems to have halted...\n")); - RAND_load_file("/dev/random", 1024); /* OpenSSL PRNG state apparently uses 1024 bytes, but it seems pretty sufficient anyway :) */ - fprintf(stderr, _("Generating %d bits keys:\n"), bits); rsa_key = RSA_generate_key(bits, 0xFFFF, indicator, NULL); if(!rsa_key) @@ -251,7 +249,7 @@ int detach(void) if(pid) /* parent process */ { signal(SIGTERM, parent_exit); -// sleep(600); /* wait 10 minutes */ + sleep(600); /* wait 10 minutes */ exit(1); } } @@ -281,11 +279,11 @@ int detach(void) openlog(identname, LOG_CONS | LOG_PID, LOG_DAEMON); - if(debug_lvl > 0) + if(debug_lvl > DEBUG_NOTHING) syslog(LOG_NOTICE, _("tincd %s (%s %s) starting, debug level %d"), VERSION, __DATE__, __TIME__, debug_lvl); else - syslog(LOG_NOTICE, _("tincd %s starting"), VERSION, debug_lvl); + syslog(LOG_NOTICE, _("tincd %s starting"), VERSION); xalloc_fail_func = memory_full; @@ -299,7 +297,7 @@ void cleanup_and_exit(int c) { close_network_connections(); - if(debug_lvl > 0) + if(debug_lvl > DEBUG_NOTHING) syslog(LOG_INFO, _("Total bytes written: tap %d, socket %d; bytes read: tap %d, socket %d"), total_tap_out, total_socket_out, total_tap_in, total_socket_in); @@ -422,6 +420,10 @@ main(int argc, char **argv, char **envp) make_names(); + /* Slllluuuuuuurrrrp! */ + + RAND_load_file("/dev/urandom", 1024); + if(generate_keys) exit(keygen(generate_keys)); @@ -436,17 +438,16 @@ main(int argc, char **argv, char **envp) if(detach()) exit(0); -/* FIXME: wt* is this suppose to do? - if(security_init()) - return 1; -*/ + if(debug_lvl >= DEBUG_ERROR) + ERR_load_crypto_strings(); + for(;;) { if(!setup_network_connections()) { main_loop(); cleanup_and_exit(1); - } + } syslog(LOG_ERR, _("Unrecoverable error")); cp_trace(); @@ -458,7 +459,7 @@ main(int argc, char **argv, char **envp) } else { - syslog(LOG_ERR, _("Aieee! Not restarting.")); + syslog(LOG_ERR, _("Not restarting.")); exit(0); } } @@ -467,15 +468,16 @@ main(int argc, char **argv, char **envp) RETSIGTYPE sigterm_handler(int a) { - if(debug_lvl > 0) + if(debug_lvl > DEBUG_NOTHING) syslog(LOG_NOTICE, _("Got TERM signal")); + cleanup_and_exit(0); } RETSIGTYPE sigquit_handler(int a) { - if(debug_lvl > 0) + if(debug_lvl > DEBUG_NOTHING) syslog(LOG_NOTICE, _("Got QUIT signal")); cleanup_and_exit(0); } @@ -504,7 +506,7 @@ sigsegv_handler(int a) } else { - syslog(LOG_NOTICE, _("Aieee! Not restarting.")); + syslog(LOG_NOTICE, _("Not restarting.")); exit(0); } } @@ -512,15 +514,15 @@ sigsegv_handler(int a) RETSIGTYPE sighup_handler(int a) { - if(debug_lvl > 0) - syslog(LOG_NOTICE, _("Got HUP signal, rereading configuration and restarting")); + if(debug_lvl > DEBUG_NOTHING) + syslog(LOG_NOTICE, _("Got HUP signal")); sighup = 1; } RETSIGTYPE sigint_handler(int a) { - if(debug_lvl > 0) + if(debug_lvl > DEBUG_NOTHING) syslog(LOG_NOTICE, _("Got INT signal, exiting")); cleanup_and_exit(0); } @@ -534,11 +536,7 @@ sigusr1_handler(int a) RETSIGTYPE sigusr2_handler(int a) { - if(debug_lvl > 1) - syslog(LOG_NOTICE, _("Got USR2 signal, forcing new key generation")); -/* FIXME: reprogram this. - regenerate_keys(); -*/ + dump_subnet_list(); } RETSIGTYPE