>From 25469876da9dc344592765eb4ef25667d0c9f528 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Mon, 25 Jun 2012 09:57:35 +0200 Subject: [PATCH] print heading for --list=section only if subsections exist Otherwise, exit(1) instead of exit(0) --- src/config.c | 10 ++++++++-- src/config.h | 2 +- src/john.c | 20 +++++++++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/config.c b/src/config.c index eb88563..2fa4fb5 100644 --- a/src/config.c +++ b/src/config.c @@ -199,8 +199,9 @@ struct cfg_list *cfg_get_list(char *section, char *subsection) } #ifndef BENCH_BUILD -void cfg_print_subsections(char *section, char *function, char *notfunction) +int cfg_print_subsections(char *section, char *function, char *notfunction, int print_heading) { + int ret = 0; struct cfg_section *current; char *p1, *p2; @@ -214,9 +215,14 @@ void cfg_print_subsections(char *section, char *function, char *notfunction) if (!*p1 || *p2) continue; if (notfunction && ext_has_function(p1, notfunction)) continue; - if (!function || ext_has_function(p1, function)) + if (!function || ext_has_function(p1, function)) { + if (ret == 0 && print_heading != 0) + printf("Subsections of [%s]:\n", section); + ret++; printf("%s\n", p1); + } } while ((current = current->next)); + return ret; } #endif char *cfg_get_param(char *section, char *subsection, char *param) diff --git a/src/config.h b/src/config.h index 62888ef..9e9d68e 100644 --- a/src/config.h +++ b/src/config.h @@ -78,7 +78,7 @@ extern struct cfg_list *cfg_get_list(char *section, char *subsection); * If notfunction is non-null, that function must NOT be present (ie. * for listing external modes that has filter() but not generate() ) */ -void cfg_print_subsections(char *section, char *function, char *notfunction); +int cfg_print_subsections(char *section, char *function, char *notfunction, int print_heading); /* * Searches for a section with the supplied name and a parameter within the diff --git a/src/john.c b/src/john.c index 3fa4626..bdf447b 100644 --- a/src/john.c +++ b/src/john.c @@ -676,32 +676,32 @@ static void john_init(char *name, int argc, char **argv) if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { - cfg_print_subsections("Incremental", NULL, NULL); + cfg_print_subsections("Incremental", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { - cfg_print_subsections("List.Rules", NULL, NULL); + cfg_print_subsections("List.Rules", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { - cfg_print_subsections("List.External", NULL, NULL); + cfg_print_subsections("List.External", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { - cfg_print_subsections("List.External", "filter", NULL); + cfg_print_subsections("List.External", "filter", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { - cfg_print_subsections("List.External", "filter", "generate"); + cfg_print_subsections("List.External", "filter", "generate", 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { - cfg_print_subsections("List.External", "generate", NULL); + cfg_print_subsections("List.External", "generate", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "encodings")) @@ -798,9 +798,11 @@ static void john_init(char *name, int argc, char **argv) /* --list last resort: list subsections of any john.conf section name */ if (options.listconf) { - printf("Subsections of [%s]:\n", options.listconf); - cfg_print_subsections(options.listconf, NULL, NULL); - exit(0); + //printf("Subsections of [%s]:\n", options.listconf); + if (cfg_print_subsections(options.listconf, NULL, NULL, 1)) + exit(0); + else + exit(1); } common_init(); -- 1.7.7.6