Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [day] [month] [year] [list]
Date: Tue, 3 Jul 2012 08:07:16 +0200
From: Frank Dittrich <frank_dittrich@...mail.com>
To: john-dev@...ts.openwall.com
Subject: Make --list= a little bit more user friendly

Here is a patch I had for several days (but only committed to my local
branch prior to digging deeper into the dynamic formats).

I hope it enhances the usability of --list=.

In changes the description of --list=WHAT
from
  list capabilities, see doc/OPTIONS or --list=?
to
  list capabilities, see --list=? or doc/OPTIONS

This hopefully makes --list=? easier to notice.
(Jim didn't notice it and thought he'd have to reed doc/OPTIONS.
However, doc/OPTIONS doesn't describe all possible values.)


The second change will print the same list as --list=? if someone uses
an invalid value like --list=help or --list=WHAT.
If an invalid value was used, I'll use exit(1) instead of exit(0).
(Should I write to stderr in this case?)

To print the same list in several places, I moved the code into a
separate function.
That's why my patch will conflict with Jim's latest addition of
--list=format-methods in bleeding.
But the merge conflict should be easy to fix.

If we implement --list=help (more detailed than --list=?) later, then
any invalid value could result in printing the --list=help output
instead of the --list=? output.

Frank

>From 8edf4090ecfeac42abff9448db81b0fa2b3f0654 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Mon, 2 Jul 2012 18:47:09 +0200
Subject: [PATCH] Make --list= a little bit more user friendly

Allow invalid values like --list=help or --list=WHAT
to produce the same list as --list=?, but exit(1) instead of
exit(0) in this case
---
 src/john.c    |   45 ++++++++++++++++++++++++++++++---------------
 src/options.c |    2 +-
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/src/john.c b/src/john.c
index 471a165..2c30d62 100644
--- a/src/john.c
+++ b/src/john.c
@@ -566,7 +566,28 @@ static void CPU_detect_or_fallback(char **argv, int make_check)
 #else
 #define CPU_detect_or_fallback(argv, make_check)
 #endif
-
+static void john_list_options()
+{
+	/*
+	 * Should this list be sorted alphabetically?
+	 * Sould we add --list=help, providing a more detailed list than --list=?
+	 * (including a description similar to information currently only available
+	 * in doc/OPTIONS)?
+	 */
+	puts("subformats, inc-modes, rules, externals, ext-filters, ext-filters-only,");
+	puts("ext-modes, build-info, hidden-options, encodings, formats, format-details,");
+	printf("format-all-details, ");
+#ifdef CL_VERSION_1_0
+	printf("opencl-devices, ");
+#endif
+#ifdef HAVE_CUDA
+	printf("cuda-devices, ");
+#endif
+	/* NOTE: The following must end the list. Anything listed
+	   <conf section name> will be ignored by current
+	   bash completion scripts. */
+	puts("<conf section name>");
+}
 static void john_init(char *name, int argc, char **argv)
 {
 	int make_check = (argc == 2 && !strcmp(argv[1], "--make_check"));
@@ -582,19 +603,7 @@ static void john_init(char *name, int argc, char **argv)
 
 	if (options.listconf && !strcasecmp(options.listconf, "?"))
 	{
-		puts("subformats, inc-modes, rules, externals, ext-filters, ext-filters-only,");
-		puts("ext-modes, build-info, hidden-options, encodings, formats, format-details,");
-		printf("format-all-details, ");
-#ifdef CL_VERSION_1_0
-		printf("opencl-devices, ");
-#endif
-#ifdef HAVE_CUDA
-		printf("cuda-devices, ");
-#endif
-		/* NOTE: The following must end the list. Anything listed
-		   after <conf section name> will be ignored by current
-		   bash completion scripts. */
-		puts("<conf section name>");
+		john_list_options();
 		exit(0);
 	}
 	if (options.listconf && !strcasecmp(options.listconf, "hidden-options"))
@@ -861,8 +870,14 @@ static void john_init(char *name, int argc, char **argv)
 		//printf("Subsections of [%s]:\n", options.listconf);
 		if (cfg_print_subsections(options.listconf, NULL, NULL, 1))
 			exit(0);
-		else
+		else {
+			/* Just in case the user specified an invalid value
+			 * like help or list...
+			 * print the same list as with --list=?, but exit(1)
+			 */
+			john_list_options();
 			exit(1);
+		}
 	}
 
 	common_init();
diff --git a/src/options.c b/src/options.c
index 7370b4d..e82550d 100644
--- a/src/options.c
+++ b/src/options.c
@@ -198,7 +198,7 @@ static struct opt_entry opt_list[] = {
 "                         " // formats are prepended with a space
 
 #define JOHN_USAGE_TAIL \
-"--list=WHAT               list capabilities, see doc/OPTIONS or --list=?\n" \
+"--list=WHAT               list capabilities, see --list=? or doc/OPTIONS\n" \
 "--save-memory=LEVEL       enable memory saving, at LEVEL 1..3\n" \
 "--mem-file-size=SIZE      size threshold for wordlist preload (default 5 MB)\n" \
 "--nolog                   disables creation and writing to john.log file\n" \
-- 
1.7.7.6


Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ