Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 07 May 2011 21:48:24 +0200
From: magnum <rawsmooth@...dband.net>
To: john-dev@...ts.openwall.com
Subject: Plumbing changes (moved from john-users)

On 2011-05-07 00:20, magnum wrote:
> Maybe I should also implement that "auto-generated format list" for
> options.c that I have been thinking about... this would mitigate a lot
> of patch collisions. Together with your changes, most new formats would
> only add one line in Makefile and two in john.c

That was much easier than I feared. I did have to move the 
john_register_all() call in john.c main() so the formats are loaded when 
calling opt_init(). I hope this won't break anything?

Other than that, it was like hello_world.c and we should have done this 
ages ago!

Currently this code writes to column 79 (80th) at most but we can lower 
this by one in case it cause empty lines on Windows?

No rights reserved, yada yada, enjoy!
magnum


diff --git a/src/john.c b/src/john.c
index aa043a5..80cf173 100644
--- a/src/john.c
+++ b/src/john.c
@@ -368,6 +368,7 @@ static void john_init(char *name, int argc, char **argv)
 		path_init(argv);
 
     status_init(NULL, 1);
+    john_register_all();
     opt_init(name, argc, argv);
 
     if (options.flags & FLG_CONFIG_CLI)
@@ -386,7 +387,6 @@ static void john_init(char *name, int argc, char **argv)
 	}
 	}
 
-	john_register_all();
 	common_init();
 
 	sig_init();
diff --git a/src/options.c b/src/options.c
index 14e9e9f..9bdb10f 100644
--- a/src/options.c
+++ b/src/options.c
@@ -102,12 +102,6 @@ static struct opt_entry opt_list[] = {
 #define JOHN_COPYRIGHT \
 	"Solar Designer and others"
 
-#ifdef HAVE_CRYPT
-#define MAYBE_CRYPT "/crypt"
-#else
-#define MAYBE_CRYPT ""
-#endif
-
 #define JOHN_USAGE \
 "John the Ripper password cracker, version " JOHN_VERSION "\n" \
 "Copyright (c) 1996-2011 by " JOHN_COPYRIGHT "\n" \
@@ -134,15 +128,11 @@ static struct opt_entry opt_list[] = {
 "--salts=[-]COUNT[:MAX]     load salts with[out] at least COUNT passwords only\n" \
 "                           (or in range of COUNT to MAX)\n" \
 "--pot=NAME                 pot file to use\n" \
-"--format=NAME              force hash type NAME:\n" \
-"                           DES/BSDI/MD5/BF/AFS/LM/NT/XSHA/PO/raw-MD5/MD5-gen/\n" \
-"                           IPB2/raw-sha1/md5a/hmac-md5/phpass-md5/KRB5/bfegg/\n" \
-"                           nsldap/ssha/openssha/oracle/oracle11/MYSQL/\n" \
-"                           mysql-sha1/mscash/mscash2/lotus5/DOMINOSEC/\n" \
-"                           NETLM/NETNTLM/NETLMv2/NETNTLMv2/NETHALFLM/MSCHAPv2/\n" \
-"                           mssql/mssql05/epi/phps/mysql-fast/pix-md5/sapG/\n" \
-"                           sapB/md5ns/HDAA/DMD5/raw-md4/md4-gen/sha1-gen" \
-MAYBE_CRYPT "\n" \
+"--format=NAME              force hash type NAME:\n"
+
+/* The format-list is automatically generated now */
+
+#define JOHN_USAGE_TAIL \
 "--subformat=NAME           Some formats such as MD5-gen have subformats\n" \
 "                           (like md5_gen(0), md5_gen(7), etc).\n" \
 "                           This allows them to be specified.\n" \
@@ -158,10 +148,31 @@ MAYBE_CRYPT "\n" \
 "                           (say 100 loops for a fast algorithm).\n" \
 "                           For slow algorithms it should not be used.\n"
 
+void list_formats(void)
+{
+	int col = 27;
+	struct fmt_main *format;
+	if ((format = fmt_list)) {
+		printf("                           ");
+		do {
+			if (col + strlen(format->params.label) > 79) {
+				printf("\n                           ");
+				col = 27;
+			}
+			col += strlen(format->params.label) + 1;
+			printf("%s/", format->params.label);
+		} while ((format = format->next));
+	} else
+		printf("** Error listing formats **");
+	printf("\n");
+}
+
 void opt_init(char *name, int argc, char **argv)
 {
 	if (argc < 2) {
 		printf(JOHN_USAGE, name);
+		list_formats();
+		printf(JOHN_USAGE_TAIL);
 		exit(0);
 	}
 

Powered by blists - more mailing lists

Your e-mail address:

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