>From f48a2fec4550cfd7acce17d9606495753e842354 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Wed, 4 Jul 2012 11:03:29 +0200 Subject: [PATCH 2/4] Add --list=help:help and improve output in case of wrong method name Currently, --list=help:help will just list help, format-methods But in future there might be more --list options with mandatory or optional values. If --list=format-methods:WHICH is used with an invalid message name, the list of valid method names gets printed. --- src/john.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/john.c b/src/john.c index 16bf7c3..cb7b3c3 100644 --- a/src/john.c +++ b/src/john.c @@ -511,14 +511,14 @@ static void CPU_detect_or_fallback(char **argv, int make_check) #else #define CPU_detect_or_fallback(argv, make_check) #endif + +/* + * FIXME: Should all the john_list_*() functions get an additional stream parameter, + * so that they can write to stderr instead of stdout in case fo an error? + */ static void john_list_options() { - /* - * Put "help" up front. For now, add the optional [:format-methods] hard coded. - * Think about a general solution if more such option appear. - * May be just change it to "help[:WHAT]" instead. - */ - puts("help[:format-methods], subformats, inc-modes, rules, externals, ext-filters,"); + puts("help[:WHAT], subformats, inc-modes, rules, externals, ext-filters,"); puts("ext-filters-only, ext-modes, build-info, hidden-options, encodings, formats,"); puts("format-details, format-all-details, format-methods[:WHICH],"); #ifdef CL_VERSION_1_0 @@ -527,12 +527,23 @@ static void john_list_options() #ifdef HAVE_CUDA printf("cuda-devices, "); #endif - /* NOTE: The following must end the list. Anything listed + /* NOTE: The following must end the list. Anything listed after will be ignored by current bash completion scripts. */ puts(""); } +static void john_list_help_options() +{ + puts("help, format-methods"); +} + +static void john_list_method_names() +{ + puts("init, prepare, valid, split, binary, salt, binary_hash, salt_hash, set_salt,"); + puts("set_key, get_key, clear_keys, crypt_all, get_hash, cmp_all, cmp_one, cmp_exact"); +} + static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); @@ -554,17 +565,31 @@ static void john_init(char *name, int argc, char **argv) */ if (options.listconf && (!strcasecmp(options.listconf, "help") || - (!strcmp(options.listconf, "?")))) + !strcmp(options.listconf, "?"))) { john_list_options(); exit(0); } + if (options.listconf && + (!strcasecmp(options.listconf, "help:help") || + !strcasecmp(options.listconf, "help:"))) + { + john_list_help_options(); + exit(0); + } if (options.listconf && !strcasecmp(options.listconf, "help:format-methods")) { - puts("init, prepare, valid, split, binary, salt, binary_hash, salt_hash, set_salt,"); - puts("set_key, get_key, clear_keys, crypt_all, get_hash, cmp_all, cmp_one, cmp_exact"); + john_list_method_names(); exit(0); } + if (options.listconf && !strncasecmp(options.listconf, "help:", 5)) + { + fprintf(stderr, + "%s is not a --list option that supports additional values.\nSupported options:\n", + options.listconf+5); + john_list_help_options(); + exit(1); + } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--subformat=FORMAT pick a benchmark format for --format=crypt"); @@ -858,6 +883,8 @@ static void john_init(char *name, int argc, char **argv) strcasecmp(&options.listconf[15], "salt_hash")) { fprintf(stderr, "Error, invalid option (invalid method name) %s\n", options.listconf); + fprintf(stderr, "Valid method names are:\n"); + john_list_method_names(); exit(1); } if (format->methods.init != fmt_default_init && !strcasecmp(&options.listconf[15], "init")) -- 1.7.7.6