=== modified file 'TODO' --- TODO 2009-01-31 10:33:17 +0000 +++ TODO 2009-02-09 19:26:19 +0000 @@ -2,41 +2,35 @@ * mandos-client ** TODO [#A] Clean up /tmp directory on signal -** TODO [#C] IPv4 support * plugin-runner ** TODO [#B] use scandir(3) instead of readdir(3) * mandos (server) -** TODO [#B] Log level :bugs: +** TODO [#B] Log level :BUGS: ** TODO /etc/mandos/clients.d/*.conf Watch this directory and add/remove/update clients? ** TODO config for TXT record -** TODO [#B] Run-time communication with server :bugs: +** TODO [#B] Run-time communication with server :BUGS: Probably using D-Bus - See also [[*Mandos-tools]] *** Client class *** Main server + SetLogLevel syslogger.setLevel(logging.WARNING) - + Quit + [[http://log.ometer.com/2007-05.html][Best D-Bus practices]] -** TODO Implement --foreground :bugs: +** TODO Implement --foreground :BUGS: [[info:standards:Option%20Table][Table of Long Options]] ** TODO Implement --socket [[info:standards:Option%20Table][Table of Long Options]] -** TODO Date+time on console log messages :bugs: +** TODO Date+time on console log messages :BUGS: Is this the default? -** TODO delete hook when clients fall out by timeout - This will not be strictly necessary when the D-Bus interface is - implemented. * mandos.xml ** [[file:mandos.xml::XXX][Document D-Bus interface]] * Provide and install /etc/dbus-1/system.d/mandos.conf -* mandos-list +* mandos-ctl *** Handle "no D-Bus server" and/or "no Mandos server found" better *** [#B] --dump option @@ -52,8 +46,7 @@ * Package ** /usr/share/initramfs-tools/hooks/mandos *** TODO [#C] Do not install in initrd.img if configured not to. - Use "/etc/initramfs-tools/conf.d/mandos"? Definitely a debconf - question. + Use "/etc/initramfs-tools/hooksconf.d/mandos"? ** TODO [#C] /etc/bash_completion.d/mandos From XML sources directly? === modified file 'initramfs-tools-hook' --- initramfs-tools-hook 2009-02-07 05:05:03 +0000 +++ initramfs-tools-hook 2009-02-09 02:13:58 +0000 @@ -92,8 +92,8 @@ fi case "$base" in *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;; - "*") :;; - *) copy_exec "$file" "${PLUGINDIR}";; + "*") : ;; + *) copy_exec "$file" "${PLUGINDIR}" ;; esac done @@ -102,8 +102,8 @@ base="`basename \"$file\"`" case "$base" in *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;; - "*") :;; - *) copy_exec "$file" "${PLUGINDIR}";; + "*") : ;; + *) copy_exec "$file" "${PLUGINDIR}" ;; esac done @@ -139,7 +139,7 @@ fi # Key files -for file in "$keydir"/*; do +for file in "$keydir"/*; do if [ -d "$file" ]; then continue fi === modified file 'plugin-runner.c' --- plugin-runner.c 2009-02-09 05:09:39 +0000 +++ plugin-runner.c 2009-02-09 19:26:19 +0000 @@ -62,7 +62,8 @@ #include /* struct sigaction, sigemptyset(), sigaddset(), sigaction(), sigprocmask(), SIG_BLOCK, SIGCHLD, - SIG_UNBLOCK, kill() */ + SIG_UNBLOCK, kill(), sig_atomic_t + */ #include /* errno, EBADF */ #include /* intmax_t, SCNdMAX, PRIdMAX, */ === modified file 'plugins.d/mandos-client.c' --- plugins.d/mandos-client.c 2009-02-09 18:15:18 +0000 +++ plugins.d/mandos-client.c 2009-02-09 19:33:46 +0000 @@ -75,10 +75,13 @@ argp_state, struct argp, argp_parse(), ARGP_KEY_ARG, ARGP_KEY_END, ARGP_ERR_UNKNOWN */ -#include /* sigemptyset(), sigaddset(), sigaction(), SIGTERM, sigaction */ +#include /* sigemptyset(), sigaddset(), + sigaction(), SIGTERM, sigaction, + sig_atomic_t */ + #ifdef __linux__ #include /* klogctl() */ -#endif +#endif /* __linux__ */ /* Avahi */ /* All Avahi types, constants and functions @@ -136,9 +139,9 @@ ":!CTYPE-X.509:+CTYPE-OPENPGP" }; /* - * Make additional room in "buffer" for at least BUFFER_SIZE - * additional bytes. "buffer_capacity" is how much is currently - * allocated, "buffer_length" is how much is already used. + * Make additional room in "buffer" for at least BUFFER_SIZE more + * bytes. "buffer_capacity" is how much is currently allocated, + * "buffer_length" is how much is already used. */ size_t incbuffer(char **buffer, size_t buffer_length, size_t buffer_capacity){ @@ -198,7 +201,7 @@ } if(debug){ - fprintf(stderr, "Initialize gpgme\n"); + fprintf(stderr, "Initializing GPGME\n"); } /* Init GPGME */ @@ -788,7 +791,7 @@ AVAHI_GCC_UNUSED AvahiStringList *txt, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, - __attribute__((unused)) void* userdata){ + AVAHI_GCC_UNUSED void* userdata){ assert(r); /* Called whenever a service has been resolved successfully or @@ -830,7 +833,7 @@ const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, - __attribute__((unused)) void* userdata){ + AVAHI_GCC_UNUSED void* userdata){ assert(b); /* Called whenever a new services becomes available on the LAN or @@ -871,10 +874,18 @@ } } +sig_atomic_t quit_now = 0; + /* stop main loop after sigterm has been called */ static void handle_sigterm(__attribute__((unused)) int sig){ + if(quit_now){ + return; + } + quit_now = 1; int old_errno = errno; - avahi_simple_poll_quit(mc.simple_poll); + if(mc.simple_poll != NULL){ + avahi_simple_poll_quit(mc.simple_poll); + } errno = old_errno; } @@ -897,13 +908,17 @@ const char *seckey = PATHDIR "/" SECKEY; const char *pubkey = PATHDIR "/" PUBKEY; + /* Initialize Mandos context */ + mc = (mandos_context){ .simple_poll = NULL, .server = NULL, + .dh_bits = 1024, .priority = "SECURE256" + ":!CTYPE-X.509:+CTYPE-OPENPGP" }; bool gnutls_initialized = false; bool gpgme_initialized = false; double delay = 2.5; struct sigaction old_sigterm_action; struct sigaction sigterm_action = { .sa_handler = handle_sigterm }; - + { struct argp_option options[] = { { .name = "debug", .key = 128, @@ -999,11 +1014,11 @@ goto end; } } - + if(not debug){ avahi_set_log_function(empty_log); } - + /* Initialize Avahi early so avahi_simple_poll_quit() can be called from the signal handler */ /* Initialize the pseudo-RNG for Avahi */ @@ -1014,8 +1029,20 @@ exitcode = EXIT_FAILURE; goto end; } - + sigemptyset(&sigterm_action.sa_mask); + ret = sigaddset(&sigterm_action.sa_mask, SIGINT); + if(ret == -1){ + perror("sigaddset"); + exitcode = EXIT_FAILURE; + goto end; + } + ret = sigaddset(&sigterm_action.sa_mask, SIGHUP); + if(ret == -1){ + perror("sigaddset"); + exitcode = EXIT_FAILURE; + goto end; + } ret = sigaddset(&sigterm_action.sa_mask, SIGTERM); if(ret == -1){ perror("sigaddset"); @@ -1028,7 +1055,6 @@ exitcode = EXIT_FAILURE; goto end; } - /* If the interface is down, bring it up */ if(interface[0] != '\0'){ @@ -1041,7 +1067,7 @@ restore_loglevel = false; perror("klogctl"); } -#endif +#endif /* __linux__ */ sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP); if(sd < 0){ @@ -1054,7 +1080,7 @@ perror("klogctl"); } } -#endif +#endif /* __linux__ */ goto end; } strcpy(network.ifr_name, interface); @@ -1068,7 +1094,7 @@ perror("klogctl"); } } -#endif +#endif /* __linux__ */ exitcode = EXIT_FAILURE; goto end; } @@ -1085,7 +1111,7 @@ perror("klogctl"); } } -#endif +#endif /* __linux__ */ goto end; } } @@ -1115,7 +1141,7 @@ perror("klogctl"); } } -#endif +#endif /* __linux__ */ } uid = getuid(); @@ -1191,8 +1217,7 @@ } else { af = AF_INET; } - ret = start_mandos_communication(address, port, if_index, - af); + ret = start_mandos_communication(address, port, if_index, af); if(ret < 0){ exitcode = EXIT_FAILURE; } else {