Skip to content

Commit 08cdb1f

Browse files
committed
Various core files: Colorize warnings and/or use _ONCE macros
1 parent 4666016 commit 08cdb1f

File tree

9 files changed

+155
-218
lines changed

9 files changed

+155
-218
lines changed

src/bench.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ static void bench_set_keys(struct fmt_main *format,
279279
}
280280

281281
if (warn == 1) {
282-
fprintf(stderr, "Warning: not enough candidates under "
283-
"benchmark length %d\n", length);
282+
fprintf_color(color_warning, stderr,
283+
"Warning: not enough candidates under benchmark length %d\n",
284+
length);
284285
warn = 2;
285286
}
286287

src/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ static void cfg_add_section(const char *name)
118118
if (!strcmp(last->name, name)) {
119119
if (!cfg_loading_john_local) {
120120
if (john_main_process)
121-
fprintf(stderr, "Warning! john.conf section [%s] is multiple declared.\n", name);
121+
fprintf_color(color_warning, stderr, "Warning! john.conf section [%s] is multiple declared.\n", name);
122122
}
123123
#ifndef BENCH_BUILD
124124
else if (john_main_process && options.verbosity >= VERB_DEFAULT)
125-
fprintf(stderr, "Warning! Section [%s] overridden by john-local.conf\n", name);
125+
fprintf_color(color_warning, stderr, "Warning! Section [%s] overridden by john-local.conf\n", name);
126126
#endif
127127
break;
128128
}

src/formats.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ void fmt_init(struct fmt_main *format)
455455
if (john_main_process && !(options.flags & FLG_TEST_CHK) &&
456456
!options.listconf && options.target_enc != UTF_8 &&
457457
format->params.flags & FMT_UTF8)
458-
fprintf(stderr, "Warning: %s format should always be "
459-
"UTF-8. Use --target-encoding=utf8\n",
460-
format->params.label);
458+
fprintf_color(color_warning, stderr,
459+
"Warning: %s format should always be UTF-8. Use --target-encoding=utf8\n",
460+
format->params.label);
461461

462462
if (john_main_process && !(options.flags & FLG_TEST_CHK) && !options.listconf) {
463463
if (format->params.flags & FMT_NOT_EXACT) {

src/john.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,14 @@ static void john_omp_show_info(void)
424424
if (msg) {
425425
#if OS_FORK
426426
if (!(options.flags & (FLG_PIPE_CHK | FLG_STDIN_CHK)))
427-
fprintf(stderr, "Warning: %s for this hash type, "
428-
"consider --fork=%d\n",
429-
msg, john_omp_threads_orig);
427+
fprintf_color(color_warning, stderr,
428+
"Warning: %s for this hash type, consider --fork=%d\n",
429+
msg, john_omp_threads_orig);
430430
else
431431
#endif
432-
fprintf(stderr, "Warning: %s for this hash type\n",
433-
msg);
432+
fprintf_color(color_warning, stderr,
433+
"Warning: %s for this hash type\n",
434+
msg);
434435
}
435436
}
436437

@@ -1082,7 +1083,8 @@ static void john_load(void)
10821083
}
10831084
if (options.verbosity <= 1)
10841085
if (john_main_process)
1085-
fprintf(stderr, "Warning: Verbosity decreased to minimum, candidates will not be printed!\n");
1086+
fprintf_color(color_warning, stderr,
1087+
"Warning: Verbosity decreased to minimum, candidates will not be printed!\n");
10861088
john_load_conf_db();
10871089
}
10881090

src/loader.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ static MAYBE_INLINE char *check_bom(char *string)
122122
"Warning: UTF-8 BOM seen in password hash file. You probably want --input-encoding=UTF8\n");
123123
}
124124
if (options.input_enc == UTF_8 && (!memcmp(string, "\xFE\xFF", 2) || !memcmp(string, "\xFF\xFE", 2))) {
125-
static int warned;
126-
127-
if (john_main_process && !warned++)
128-
fprintf(stderr, "Warning: UTF-16 BOM seen in password hash file. "
129-
"File may not be read properly unless you re-encode it\n");
125+
if (john_main_process)
126+
WARN_ONCE(color_warning, stderr,
127+
"Warning: UTF-16 BOM seen in password hash file. "
128+
"File may not be read properly unless you re-encode it\n");
130129
}
131130
return string;
132131
}
@@ -254,13 +253,17 @@ static void read_file(struct db_main *db, char *name, int flags,
254253
options.input_enc == UTF_8)) {
255254
if (!valid_utf8((UTF8*)u8check)) {
256255
warn_enc = 0;
257-
fprintf(stderr, "Warning: invalid UTF-8 seen reading %s\n", path_expand(name));
256+
fprintf_color(color_warning, stderr,
257+
"Warning: invalid UTF-8 seen reading %s\n",
258+
path_expand(name));
258259
}
259260
} else if (options.input_enc != UTF_8 &&
260261
(line != line_buf ||
261262
valid_utf8((UTF8*)u8check) > 1)) {
262263
warn_enc = 0;
263-
fprintf(stderr, "Warning: UTF-8 seen reading %s\n", path_expand(name));
264+
fprintf_color(color_warning, stderr,
265+
"Warning: UTF-8 seen reading %s\n",
266+
path_expand(name));
264267
}
265268
}
266269
process_line(db, line);
@@ -1012,18 +1015,13 @@ static void ldr_load_pw_line(struct db_main *db, char *line)
10121015

10131016
if (john_main_process) {
10141017
if (format->params.binary_size)
1015-
fprintf(stderr, "Warning: "
1016-
"excessive partial hash "
1017-
"collisions detected\n%s",
1018-
db->password_hash_func !=
1019-
fmt_default_binary_hash ? "" :
1020-
"(cause: the \"format\" lacks "
1021-
"proper binary_hash() function "
1022-
"definitions)\n");
1018+
fprintf_color(color_warning, stderr,
1019+
"Warning: excessive partial hash collisions detected\n%s",
1020+
db->password_hash_func != fmt_default_binary_hash ? "" :
1021+
"(cause: the \"format\" lacks proper binary_hash() function definitions)\n");
10231022
else
1024-
fprintf(stderr, "Warning: "
1025-
"check for duplicates partially "
1026-
"bypassed to speedup loading\n");
1023+
fprintf_color(color_warning, stderr,
1024+
"Warning: check for duplicates partially bypassed to speedup loading\n");
10271025
}
10281026
dupe_checking = 0;
10291027
current_pw = NULL; /* no match */

0 commit comments

Comments
 (0)