>From 44de7c4868182fd8e12afc6eb076a67e7abb566a Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Thu, 14 Jun 2012 15:07:52 +0200 Subject: [PATCH] Write the list of encodings to stdout instead of stderr (except for usage errors) The list should be written to stderr only when a wrong encoding has been specified with --encoding=..., when error() is used afterwards. When the user explicitely requests the encoding list (with --list=encodings or the deprecated --encodings=list), this is not an error. In this case, the program just prints the list of encodings, and terminates with exit(0). So the list should be written to stdout. --- src/john.c | 2 +- src/options.c | 2 +- src/unicode.c | 8 +++++--- src/unicode.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/john.c b/src/john.c index 12232a4..244c89a 100644 --- a/src/john.c +++ b/src/john.c @@ -692,7 +692,7 @@ static void john_init(char *name, int argc, char **argv) } if (options.listconf && !strcasecmp(options.listconf, "encodings")) { - listEncodings(); + listEncodings(stdout); exit(0); } #ifdef CL_VERSION_1_0 diff --git a/src/options.c b/src/options.c index eb47722..857fe49 100644 --- a/src/options.c +++ b/src/options.c @@ -393,7 +393,7 @@ void opt_init(char *name, int argc, char **argv) if (options.flags & FLG_STDOUT) options.flags &= ~FLG_PWD_REQ; if (options.encoding && !strcasecmp(options.encoding, "list")) { - listEncodings(); + listEncodings(stdout); exit(0); } diff --git a/src/unicode.c b/src/unicode.c index dd57f8a..99033a6 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -753,8 +753,10 @@ UTF8 *utf16_to_enc_r (UTF8 *dst, int dst_len, const UTF16 *source) { return dst; } -void listEncodings(void) { - fprintf(stderr, "Supported encodings within john are:\nutf-8, iso-8859-1 (or ansi)" +void listEncodings(FILE *stream) { + fprintf(stream, + "Supported encodings within john are:\nutf-8" + ", iso-8859-1 (or ansi)" ", iso-8859-7" ", iso-8859-15" ", koi8-r" @@ -847,7 +849,7 @@ int initUnicode(int type) { options.encodingStr = "raw"; } else { fprintf (stderr, "Invalid encoding. "); - listEncodings(); + listEncodings(stderr); error(); } } diff --git a/src/unicode.h b/src/unicode.h index 08918e1..85c77a7 100644 --- a/src/unicode.h +++ b/src/unicode.h @@ -104,7 +104,7 @@ extern int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16); #define UNICODE_MS_NEW 2 #define UNICODE_UNICODE 3 -extern void listEncodings(void); +extern void listEncodings(FILE *stream); extern int initUnicode(int type); extern UTF16 ucs2_upcase[0x10000]; /* NOTE, for multi-char converts, we put a 1 into these */ extern UTF16 ucs2_downcase[0x10000]; /* array. The 1 is not valid, just an indicator to check the multi-char */ -- 1.7.7.6