Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [day] [month] [year] [list]
Date: Wed, 4 Jul 2012 13:25:41 +0200
From: Frank Dittrich <frank_dittrich@...mail.com>
To: john-dev@...ts.openwall.com
Subject: New --list=help instead of --list=?, bash completion support for
 --list=option[:value], and more

The patches in this series depend on each other.

The first 3 patches should be applied to bleeding-jumbo and magnum-jumbo
as well as to 1.7.9-jumbo-6-fixes.

The last patch should be applied to bleeding-jumbo only, since it adds
get_source to the output of --list=help:format-methods.


Patch 0001 adds --list=help instead of --list=? (but --list=? continues
to be supported)

Patch 0002 adds --list=help:help, --list=help:format-methods, and
improves the output in case of a wrong method name in
--list=format-methods:WHICH (it will provide a list of valid method
names in addition to the error message).

Patch 0003 uses the functionality provided by patches 0001 and 0002 to
support the new --list options.
If --list=help is supported, bash completion will not list "?" as a
possible completion, because "help" is listed as one of the possible
completions.
This also means that
$ ./john --list=?[tab]
will not longer result in a trailing space being added if the john
version supports --list=help.
Does anybody insist on a fix?

The bash completion script continues to use --list=? (changed to
--list=\?), because jumbo-6 doesn't know --list=help.


Patch 0004 adds get_source to the list of method names for
--list=help:format-methods.


Frank

>From 04160f6af5734bd496d30ed271582ca2da1f2b58 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Wed, 4 Jul 2012 08:55:21 +0200
Subject: [PATCH 1/4] =?UTF-8?q?New=20--list=3Dhelp=20instead=20of=20--list=3D?=
 =?UTF-8?q?=3F?=

---
 doc/OPTIONS   |    2 +-
 src/john.c    |   29 +++++++++++++++++++++--------
 src/options.c |    2 +-
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/doc/OPTIONS b/doc/OPTIONS
index b3ab602..0ea34f5 100644
--- a/doc/OPTIONS
+++ b/doc/OPTIONS
@@ -282,7 +282,7 @@ the log file.
 --list=WHAT               list capabilities
 
 This option can be used to gain information about what rules, modes etc are
-available. Use --list=? for a list of valid arguments. For example, the now
+available. Use --list=help for a list of valid arguments. For example, the now
 deprecated --subformat=LIST is now --list=subformats.
 The different variants of list externals may be worth mentioning:
 
diff --git a/src/john.c b/src/john.c
index b956ff0..16bf7c3 100644
--- a/src/john.c
+++ b/src/john.c
@@ -514,14 +514,13 @@ static void CPU_detect_or_fallback(char **argv, int make_check)
 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)?
+	 * 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("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, format-methods[:WHICH], ");
+	puts("help[:format-methods], 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
 	printf("opencl-devices, ");
 #endif
@@ -547,11 +546,25 @@ static void john_init(char *name, int argc, char **argv)
 		john_register_all(); /* for printing by opt_init() */
 	opt_init(name, argc, argv);
 
-	if (options.listconf && !strcasecmp(options.listconf, "?"))
+	/*
+	 * --list=? needs to be supported, because it has been supported in the released
+	 * john-1.7.9-jumbo-6 version, and it is used by the bash completion script.
+	 * --list=? is, however, not longer mentioned in doc/OPTIONS and in the usage
+	 * output. Instead, --list=help is.
+	 */
+	if (options.listconf &&
+	    (!strcasecmp(options.listconf, "help") ||
+	    (!strcmp(options.listconf, "?"))))
 	{
 		john_list_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");
+		exit(0);
+	}
 	if (options.listconf && !strcasecmp(options.listconf, "hidden-options"))
 	{
 		puts("--subformat=FORMAT        pick a benchmark format for --format=crypt");
diff --git a/src/options.c b/src/options.c
index e82550d..13a81d9 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 --list=? or doc/OPTIONS\n" \
+"--list=WHAT               list capabilities, see --list=help 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


>From f48a2fec4550cfd7acce17d9606495753e842354 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
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
 	   <conf section name> will be ignored by current
 	   bash completion scripts. */
 	puts("<conf section name>");
 }
 
+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


>From a26e770b0ab95c5fb607d4eb570b32e538938a4b Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Wed, 4 Jul 2012 12:55:53 +0200
Subject: [PATCH 3/4] Bash completion: add support for --list=option[:value]

Additionally, escape the ? in --list=? in john.bash_completion
---
 run/john.bash_completion |   58 +++++++++++++++++++--------------------------
 1 files changed, 25 insertions(+), 33 deletions(-)

diff --git a/run/john.bash_completion b/run/john.bash_completion
index 51dbd6a..aa80fec 100644
--- a/run/john.bash_completion
+++ b/run/john.bash_completion
@@ -63,9 +63,6 @@
 #
 # FIXME: Should completion for --make-charset really list existing .chr files?
 #
-# FIXME: Should I generally use LC_ALL=C, not just in a few places?
-#	 (This could also be a little bit faster.)
-#
 # TODO:
 #       --wordlist=~user/filename or --wordlist=~/dir/file doesn't work,
 #	  but pressing [tab] expands this to something useful
@@ -90,6 +87,9 @@ _john()
 {
 	local first cur options valopts compreplya compreplyb encodings formats subformats list hidden dir cmd i ver ver1 ver2 ver3 prev words
 
+	# Without LC_ALL=C, [A-Z] match [a-z] (case "${cur}" in ... esac)
+	LC_ALL=C
+
 	COMPREPLY=()
 
 	if [[ "${COMP_WORDBREAKS}" == *:* ]] ; then
@@ -451,7 +451,7 @@ _john()
 		-?(-)en?(c|co|cod|codi|codin|coding)+(=|:)*)
 			if [[ "${valopts}" == *--encoding=* ]] ; then
 				# --encoding=LIST writes to stderr
-				list=`${first} --list=? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
+				list=`${first} --list=\? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
 				if [[ "_${list}" == *encoding* ]] ; then
 					cmd="${first} --list=encodings"
 				else
@@ -537,14 +537,14 @@ _john()
 					# should I even test this (with --test=0, and filter out those
 					# with a message:
 					# appears to be unsupported on this system; will not load such hashes.
-					subformats=`${first}  --test=0 --format=crypt --subformat=? 2>&1|sed -n 's#,# #g;/^Subformat / s#^[^:]*:\(.*\)$#\L\1# p'`
+					subformats=`${first} --test=0 --format=crypt --subformat=? 2>&1|sed -n 's#,# #g;/^Subformat / s#^[^:]*:\(.*\)$#\L\1# p'`
 					COMPREPLY=( $(compgen -W "${subformats}" -- ${cur}) )
 				fi
 			fi
 			return 0
 			;;
 		-?(-)+(pla?(t|tf|tfo|tfor|tform)|d?(e|ev|evi|evic|evice))+(=|:)[Ll]?([Ii]|[Ii][Ss]|[Ii][Ss][Tt]))
-			list=`${first} --list=? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
+			list=`${first} --list=\? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
 			# Only complete to lIST if --list=cuda-devices and --list=opencl-devices don't exist
 			# CUDA doesn't allow --device=LIST
 			# workaround: check if --platform= is allowed
@@ -555,7 +555,7 @@ _john()
 			return 0
 			;;
 		-?(-)+(pla?(t|tf|tfo|tfor|tform)|d?(e|ev|evi|evic|evice))+(=|:))
-			list=`${first} --list=? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
+			list=`${first} --list=\? 2>/dev/null|sed 's#\(,\)\?\( or\)\?[ ]*[<].*$##; s#,##g'`
 			# Only list possible completions if --list=cuda-devices
 			# and --list=opencl-devices don't exist.
 			# --device=LIST isn't supported for CUDA, but for CUDA
@@ -568,30 +568,13 @@ _john()
 			fi
 			return 0
 			;;
-		-?(-)li?(s|st)+(=|:)format-methods)
-			if [[ "_${__john_completion}" == "_2" && "${valopts}" == *--list=* ]] ; then
-				list=`${first} --list=? 2>/dev/null`
-				if [[ "_${list}" == _*format-methods* ]] ; then
-					cur=${cur#*[=:]}
-					COMPREPLY=( $(compgen -W "${cur}:" -- ${cur}) )
-					compopt -o nospace
-				fi
-			fi
-			return 0
-			;;
-		-?(-)li?(s|st)+(+(=|:)format-methods:|=format-methods=)*)
-			# --list=format-methods has been introduced after --list= got moved
-			# into the main usage output, so there's no need to check ${hidden}
-			if [[ "${valopts}" == *--list=* ]] ; then
-				list=`${first} --list=? 2>/dev/null`
-				if [[ "_${list}" == _*format-methods* ]] ; then
-					cur=${cur#*[=:]}
-					cur=${cur#*[=:]}
-					# for now, a hard coded list of methods produced with
-					# $ ./john --list=format-methods| \
-					#   sed -n '/^\s/ s#^\s*\([^(\[]*\).*$#\1# p'|sort -u
-					COMPREPLY=( $(compgen -W "binary binary_hash clear_keys cmp_all cmp_exact cmp_one crypt_all get_hash get_key get_source init prepare salt salt_hash set_key set_salt split valid" -- ${cur}) )
-				fi
+		-?(-)li?(s|st)+(+(=|:)+([a-z_-]):|:+([a-z_-])=)*([a-z_-]))
+			cur=${cur#*[=:]}
+			cmd=${cur%[=:]*}
+			cur=${cur#*[=:]}
+			list=`${first} --list=help:${cmd} 2>/dev/null |sed 's#,# #g'`
+			if [[ $? -eq 0 ]] ; then
+				COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
 			fi
 			return 0
 			;;
@@ -610,15 +593,24 @@ _john()
 				# (or --list:format-methods[:WHICH] or --list:format-methods=WHICH, but
 				# not --list:format-methods=WHICH)
 				# format-methods[:WHICH],
-				list=`${first} --list=? 2>/dev/null|sed 's#\(,\)\?\(or\)\?[ ]*[<].*$##; s#,##g'`
+				list=`${first} --list=\? 2>/dev/null|sed 's#\(,\)\?\(or\)\?[ ]*[<].*$##; s#,##g'`
 				if [[ $? -eq 0 ]] ; then
 					# add "?" to the list of possible completions, but don't add any
 					# section names like "Options"...
-					COMPREPLY=( $(compgen -W "${list} ?" -- ${cur}) )
+					if [[ "${list}" == *help* ]] ; then
+						# Don't advertise --list=?
+						COMPREPLY=( $(compgen -W "${list}" -- ${cur}) )
+					else
+						# Add "?" to the possible completions
+						COMPREPLY=( $(compgen -W "${list} ?" -- ${cur}) )
+					fi
 					# if the only value contains a ':', special treatment required
 					if [[ ${#COMPREPLY[@]} -eq 1 && "_${COMPREPLY[0]}" == _*:* ]] ; then
 						if [[ "_${COMPREPLY[0]}" == _*\[:* ]] ; then
 							COMPREPLY[0]=${COMPREPLY[0]%\[*}
+							if [[ "_${__john_completion}" == "_2" && "_${COMPREPLY[0]}" == _${cur} ]] ; then
+								COMPREPLY[0]=${COMPREPLY[0]%:*}:
+							fi
 						else
 							COMPREPLY[0]=${COMPREPLY[0]%:*}:
 						fi
-- 
1.7.7.6


>From 2a3a6d36e4b914bc4750076487e76dadce517203 Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Wed, 4 Jul 2012 13:23:03 +0200
Subject: [PATCH 4/4] Add get_source to --list=help:format-methods output

---
 src/john.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/john.c b/src/john.c
index cb7b3c3..80cbc39 100644
--- a/src/john.c
+++ b/src/john.c
@@ -541,7 +541,8 @@ static void john_list_help_options()
 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");
+	puts("set_key, get_key, clear_keys, crypt_all, get_hash, cmp_all, cmp_one, cmp_exact,");
+	puts("get_source");
 }
 
 static void john_init(char *name, int argc, char **argv)
-- 
1.7.7.6


Powered by blists - more mailing lists

Your e-mail address:

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