X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Ftincd.c;h=9c337f88cf9f438255a561dd07c4478f39e53692;hp=ca873ef2e37a4309f8f29d97d9c8e490578e6717;hb=bb2495e569fb161b42efd633eb1c471b8222b1fb;hpb=35932fe6c8cb481eb687f98424776ce429570c21 diff --git a/src/tincd.c b/src/tincd.c index ca873ef..9c337f8 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.17 2000/10/29 00:02:20 guus Exp $ + $Id: tincd.c,v 1.10.4.28 2000/11/15 01:06:13 zarq Exp $ */ #include "config.h" @@ -31,20 +31,38 @@ #include #include #include -#include -#include #include +#include #ifdef HAVE_SYS_IOCTL_H # include #endif +#ifdef HAVE_OPENSSL_RAND_H +# include +#else +# include +#endif + +#ifdef HAVE_OPENSSL_RSA_H +# include +#else +# include +#endif + +#ifdef HAVE_OPENSSL_ERR_H +# include +#else +# include +#endif + + + #include #include #include #include "conf.h" -#include "encr.h" #include "net.h" #include "netutl.h" #include "protocol.h" @@ -74,6 +92,8 @@ char *identname; /* program name for syslog */ char *pidfilename; /* pid file location */ static pid_t ppid; /* pid of non-detached part */ char **g_argv; /* a copy of the cmdline arguments */ +char **environment; /* A pointer to the environment on + startup */ void cleanup_and_exit(int); int detach(void); @@ -85,12 +105,13 @@ int write_pidfile(void); static struct option const long_options[] = { + { "config", required_argument, NULL, 'c' }, { "kill", no_argument, NULL, 'k' }, { "net", required_argument, NULL, 'n' }, { "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 } }; @@ -102,14 +123,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); @@ -205,9 +226,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) @@ -228,7 +246,8 @@ int keygen(int bits) void memory_full(int size) { - syslog(LOG_ERR, _("Memory exhausted (last is %s:%d) (couldn't allocate %d bytes), exiting."), cp_file, cp_line, size); + syslog(LOG_ERR, _("Memory exhausted (couldn't allocate %d bytes), exiting."), size); + cp_trace(); exit(1); } @@ -252,7 +271,7 @@ int detach(void) if(pid) /* parent process */ { signal(SIGTERM, parent_exit); -// sleep(600); /* wait 10 minutes */ + sleep(600); /* wait 10 minutes */ exit(1); } } @@ -369,6 +388,8 @@ void make_names(void) asprintf(&pidfilename, "/var/run/tinc.%s.pid", netname); if(!confbase) asprintf(&confbase, "%s/tinc/%s", CONFDIR, netname); + else + fprintf(stderr, _("Both netname and configuration directory given, using the latter...\n")); if(!identname) asprintf(&identname, "tinc.%s", netname); } @@ -396,6 +417,7 @@ main(int argc, char **argv, char **envp) unknown = _("unknown"); + environment = envp; parse_options(argc, argv, envp); if(show_version) @@ -423,6 +445,10 @@ main(int argc, char **argv, char **envp) make_names(); + /* Slllluuuuuuurrrrp! */ + + RAND_load_file("/dev/urandom", 1024); + if(generate_keys) exit(keygen(generate_keys)); @@ -437,17 +463,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(); @@ -459,7 +484,7 @@ main(int argc, char **argv, char **envp) } else { - syslog(LOG_ERR, _("Aieee! Not restarting.")); + syslog(LOG_ERR, _("Not restarting.")); exit(0); } } @@ -470,6 +495,7 @@ sigterm_handler(int a) { if(debug_lvl > DEBUG_NOTHING) syslog(LOG_NOTICE, _("Got TERM signal")); + cleanup_and_exit(0); } @@ -505,7 +531,7 @@ sigsegv_handler(int a) } else { - syslog(LOG_NOTICE, _("Aieee! Not restarting.")); + syslog(LOG_NOTICE, _("Not restarting.")); exit(0); } } @@ -514,7 +540,7 @@ RETSIGTYPE sighup_handler(int a) { if(debug_lvl > DEBUG_NOTHING) - syslog(LOG_NOTICE, _("Got HUP signal, rereading configuration and restarting")); + syslog(LOG_NOTICE, _("Got HUP signal")); sighup = 1; } @@ -536,11 +562,6 @@ RETSIGTYPE sigusr2_handler(int a) { dump_subnet_list(); -// if(debug_lvl > DEBUG_NOTHING) -// syslog(LOG_NOTICE, _("Got USR2 signal, forcing new key generation")); -/* FIXME: reprogram this. - regenerate_keys(); -*/ } RETSIGTYPE