diff options
author | Rob Austein <sra@hactrn.net> | 2015-07-01 17:34:57 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2015-07-01 17:34:57 -0400 |
commit | 303152d464631af69c2947631d0629aa31c099b3 (patch) | |
tree | a7e46151d6eaf836c27325b16f9e787003ec3c4c /p11util.c | |
parent | c45562762aab7e874eac71792f9eebb5185ee47d (diff) |
Debug p11util.
Diffstat (limited to 'p11util.c')
-rw-r--r-- | p11util.c | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -3,12 +3,7 @@ * things like setting PINs. */ -/* - * Apparently getopt_long() works everywhere we're likely to care - * about. At least, we've been getting away with it for years in - * rcynic. rcynic.c has code to wrap option and usage stuff using - * getopt_long(), proably just reuse that. - */ +#define _POSIX_SOURCE #include <stdio.h> #include <stdlib.h> @@ -86,20 +81,20 @@ static int getpin_tty(const char *prompt, OPT_FLG('s', "set-so-pin", "set Security Officer PIN") \ OPT_FLG('u', "set-user-pin", "set \"user\" PIN") \ OPT_ARG('i', "set-iterations", "set PBKDF2 iteration count") \ - OPT_ARG('p', "pin-from-stdin", "read PIN from stdin instead of /dev/tty") \ + OPT_FLG('p', "pin-from-stdin", "read PIN from stdin instead of /dev/tty") \ OPT_END #define OPT_END -static void usage (const int code, const char *jane) +static void usage(const int code, const char *jane) { assert(jane != NULL); FILE *f = code ? stderr : stdout; fprintf(f, "usage: %s [options]\noptions:\n", jane); -#define OPT_FLG(_short_, _long_, _help_) fprintf(f, " -%c --%-32s%s", _short_, _long_, _help_); -#define OPT_ARG(_short_, _long_, _help_) fprintf(f, " -%c ARG --%-32s%s", _short_, _long_ " ARG", _help_); +#define OPT_FLG(_short_, _long_, _help_) fprintf(f, " -%c --%-32s%s\n", _short_, _long_, _help_); +#define OPT_ARG(_short_, _long_, _help_) fprintf(f, " -%c ARG --%-32s%s\n", _short_, _long_ " ARG", _help_); OPTIONS; #undef OPT_ARG #undef OPT_FLG @@ -107,12 +102,12 @@ static void usage (const int code, const char *jane) exit(code); } -static void parse_args (int argc, char *argv[], - int *do_set_so_pin, - int *do_set_user_pin, - int *do_set_iterations, - int *read_from_stdin, - unsigned long *iterations) +static void parse_args(int argc, char *argv[], + int *do_set_so_pin, + int *do_set_user_pin, + int *do_set_iterations, + int *read_from_stdin, + unsigned long *iterations) { char *endptr; int c; @@ -134,6 +129,9 @@ static void parse_args (int argc, char *argv[], read_from_stdin != NULL && iterations != NULL); opterr = 0; + if (argc == 1) + usage(0, argv[0]); + while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) > 0) { switch (c) { @@ -270,7 +268,7 @@ static int set_pin(const char * const pin_type, const int read_from_stdin) return ok; } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { int do_set_so_pin = 0, do_set_user_pin = 0, do_set_iterations = 0, read_from_stdin = 0; unsigned long iterations; |