=== modified file 'plugins.d/mandosclient.c' --- plugins.d/mandosclient.c 2008-07-21 02:35:05 +0000 +++ plugins.d/mandosclient.c 2008-07-21 04:42:08 +0000 @@ -50,6 +50,8 @@ #include /* perror() */ #include +// getopt long +#include #ifndef CERT_ROOT #define CERT_ROOT "/conf/conf.d/cryptkeyreq/" @@ -60,6 +62,7 @@ #define DH_BITS 1024 bool debug = false; +char *interface = "eth0"; typedef struct { gnutls_session_t session; @@ -197,11 +200,15 @@ new_packet_length += ret; } - if(debug){ - fprintf(stderr, "decrypted password is: %s\n", *new_packet); - } - - /* Delete the GPGME plaintext data buffer */ + /* FIXME: check characters before printing to screen so to not print + terminal control characters */ + /* if(debug){ */ + /* fprintf(stderr, "decrypted password is: "); */ + /* fwrite(*new_packet, 1, new_packet_length, stderr); */ + /* fprintf(stderr, "\n"); */ + /* } */ + + /* Delete the GPGME plaintext data buffer */ gpgme_data_release(dh_plain); return new_packet_length; } @@ -321,7 +328,6 @@ size_t buffer_capacity = 0; ssize_t decrypted_buffer_size; int retval = 0; - const char interface[] = "eth0"; if(debug){ fprintf(stderr, "Setting up a tcp connection to %s\n", ip); @@ -552,36 +558,34 @@ int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) { AvahiServerConfig config; AvahiSServiceBrowser *sb = NULL; - const char db[] = "--debug"; int error; - int ret = 1; + int ret; int returncode = EXIT_SUCCESS; - char *basename = rindex(argv[0], '/'); - if(basename == NULL){ - basename = argv[0]; - } else { - basename++; - } - - char *program_name = malloc(strlen(basename) + sizeof(db)); - - if (program_name == NULL){ - perror("argv[0]"); - return EXIT_FAILURE; - } - - program_name[0] = '\0'; - - for (int i = 1; i < argc; i++){ - if (not strncmp(argv[i], db, 5)){ - strcat(strcat(strcat(program_name, db ), "="), basename); - if(not strcmp(argv[i], db) or not strcmp(argv[i], program_name)){ - debug = true; - } - } - } - free(program_name); - + + while (true){ + static struct option long_options[] = { + {"debug", no_argument, (int *)&debug, 1}, + {"interface", required_argument, 0, 'i'}, + {0, 0, 0, 0} }; + + int option_index = 0; + ret = getopt_long (argc, argv, "i:", long_options, &option_index); + + if (ret == -1){ + break; + } + + switch(ret){ + case 0: + break; + case 'i': + interface = optarg; + break; + default: + exit(EXIT_FAILURE); + } + } + if (not debug){ avahi_set_log_function(empty_log); } @@ -647,5 +651,5 @@ if (simple_poll) avahi_simple_poll_free(simple_poll); - return ret; + return returncode; } === modified file 'plugins.d/passprompt.c' --- plugins.d/passprompt.c 2008-07-20 23:34:51 +0000 +++ plugins.d/passprompt.c 2008-07-21 03:58:36 +0000 @@ -11,14 +11,16 @@ SIGQUIT, SIGHUP, SIGTERM */ #include /* NULL, size_t */ #include /* ssize_t */ -#include /* EXIT_SUCCESS, EXIT_FAILURE */ +#include /* EXIT_SUCCESS, EXIT_FAILURE, + getopt_long */ #include /* fprintf(), stderr, getline(), stdin, feof(), perror(), fputc(), - stdout */ + stdout, getopt_long */ #include /* errno, EINVAL */ #include /* or, not */ #include /* bool, false, true */ #include /* strlen, rindex, strncmp, strcmp */ +#include /* getopt_long */ volatile bool quit_now = false; bool debug = false; @@ -28,40 +30,41 @@ } int main(int argc, char **argv){ - ssize_t ret = -1; + ssize_t ret; size_t n; struct termios t_new, t_old; char *buffer = NULL; + char *prefix = NULL; int status = EXIT_SUCCESS; struct sigaction old_action, new_action = { .sa_handler = termination_handler, .sa_flags = 0 }; - const char db[] = "--debug"; - char *basename = rindex(argv[0], '/'); - if(basename == NULL){ - basename = argv[0]; - } else { - basename++; - } - - char *program_name = malloc(strlen(basename) + sizeof(db)); - if (program_name == NULL){ - perror("argv[0]"); - return EXIT_FAILURE; - } - - program_name[0] = '\0'; - - for (int i = 1; i < argc; i++){ - if (not strncmp(argv[i], db, 5)){ - strcat(strcat(strcat(program_name, db ), "="), basename); - if(not strcmp(argv[i], db) or not strcmp(argv[i], program_name)){ - debug = true; - } - } - } - free(program_name); - + + while (true){ + static struct option long_options[] = { + {"debug", no_argument, (int *)&debug, 1}, + {"prefix", required_argument, 0, 'p'}, + {0, 0, 0, 0} }; + + int option_index = 0; + ret = getopt_long (argc, argv, "p:", long_options, &option_index); + + if (ret == -1){ + break; + } + + switch(ret){ + case 0: + break; + case 'p': + prefix = optarg; + break; + default: + fprintf(stderr, "bad arguments\n"); + exit(EXIT_FAILURE); + } + } + if (debug){ fprintf(stderr, "Starting %s\n", argv[0]); } @@ -111,7 +114,12 @@ status = EXIT_FAILURE; break; } - fprintf(stderr, "Password: "); + + if(prefix){ + fprintf(stderr, "%s Password: ", prefix); + } else { + fprintf(stderr, "Password: "); + } ret = getline(&buffer, &n, stdin); if (ret > 0){ fprintf(stdout, "%s", buffer);