Skip to content

Commit 4666016

Browse files
committed
Modes: Colorize warnings and/or use _ONCE macros
1 parent 51f7b23 commit 4666016

File tree

8 files changed

+100
-155
lines changed

8 files changed

+100
-155
lines changed

src/external.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void ext_init(char *mode, struct db_main *db)
283283
(ext_flags & (EXT_USES_GENERATE | EXT_USES_FILTER)) ==
284284
EXT_USES_FILTER && f_generate)
285285
if (john_main_process)
286-
fprintf(stderr, "Warning: external mode defines generate(), "
287-
"but is only used for filter()\n");
286+
fprintf_color(color_warning, stderr,
287+
"Warning: external mode defines generate(), but is only used for filter()\n");
288288

289289
ext_mode = mode;
290290
}

src/inc.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@ void do_incremental_crack(struct db_main *db, const char *mode)
531531
log_event("! MaxLen = %d is too large%s, reduced", max_length,
532532
options.force_maxlength ? "" : " for this hash type");
533533
if (john_main_process && !options.force_maxlength)
534-
fprintf(stderr, "Warning: MaxLen = %d is too large "
535-
"for the current hash type, reduced to %d\n",
536-
max_length, our_fmt_len);
534+
fprintf_color(color_warning, stderr,
535+
"Warning: MaxLen = %d is too large "
536+
"for the current hash type, reduced to %d\n",
537+
max_length, our_fmt_len);
537538
max_length = our_fmt_len;
538539
}
539540

@@ -714,8 +715,9 @@ void do_incremental_crack(struct db_main *db, const char *mode)
714715

715716
if ((unsigned int)max_count > real_count) {
716717
log_event("! Only %u characters available", real_count);
717-
fprintf(stderr, "Warning: only %u characters available\n",
718-
real_count);
718+
fprintf_color(color_warning, stderr,
719+
"Warning: only %u characters available\n",
720+
real_count);
719721
}
720722
}
721723

@@ -728,18 +730,20 @@ void do_incremental_crack(struct db_main *db, const char *mode)
728730
log_event("! Mixed-case charset, "
729731
"but the hash type is case-insensitive");
730732
if (john_main_process)
731-
fprintf(stderr, "Warning: mixed-case charset, "
732-
"but the current hash type is case-insensitive;\n"
733-
"some candidate passwords may be unnecessarily "
734-
"tried more than once.\n");
733+
fprintf_color(color_warning, stderr,
734+
"Warning: mixed-case charset, "
735+
"but the current hash type is case-insensitive;\n"
736+
"some candidate passwords may be unnecessarily "
737+
"tried more than once.\n");
735738
}
736739

737740
if (!(db->format->params.flags & FMT_8_BIT) && has_8bit(allchars)) {
738741
log_event("! 8-bit charset, but the hash type is 7-bit");
739742
if (john_main_process)
740-
fprintf(stderr, "Warning: 8-bit charset, but the current"
741-
" hash type is 7-bit;\n"
742-
"some candidate passwords may be redundant.\n");
743+
fprintf_color(color_warning, stderr,
744+
"Warning: 8-bit charset, but the current"
745+
" hash type is 7-bit;\n"
746+
"some candidate passwords may be redundant.\n");
743747
}
744748

745749
char2 = NULL;

src/mask.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ uint64_t mask_parent_keys;
9797
*/
9898
static char* parse_hex(char *string)
9999
{
100-
static int warned;
101100
unsigned char *s = (unsigned char*)string;
102101
unsigned char *d = s;
103102

@@ -111,8 +110,8 @@ static char* parse_hex(char *string)
111110
} else if (*s == '\\' && s[1] == 'x' &&
112111
atoi16[s[2]] != 0x7f && atoi16[s[3]] != 0x7f) {
113112
char c = (atoi16[s[2]] << 4) + atoi16[s[3]];
114-
if (!c && !warned++ && john_main_process)
115-
fprintf(stderr, "Warning: \\x00 in mask terminates the string\n");
113+
if (!c && john_main_process)
114+
WARN_ONCE(color_warning, stderr, "Warning: \\x00 in mask terminates the string\n");
116115
if (strchr("\\[]?-", c))
117116
*d++ = '\\';
118117
*d++ = c;
@@ -157,13 +156,8 @@ static char* expand_cplhdr(char *string, int *conv_err)
157156
int pidx = s[1] - '1';
158157
char *cs = options.custom_mask[pidx];
159158

160-
if (conv_err[pidx]) {
161-
if (john_main_process)
162-
fprintf(stderr,
163-
"Error: Selected internal codepage can't hold all chars of mask placeholder ?%d\n",
164-
pidx + 1);
165-
error();
166-
}
159+
if (conv_err[pidx])
160+
error_msg("Error: Selected internal codepage can't hold all chars of mask placeholder ?%d\n", pidx + 1);
167161
if (*cs == 0) {
168162
if (john_main_process)
169163
fprintf(stderr, "Error: Custom mask placeholder ?%d not defined\n", pidx + 1);
@@ -2425,7 +2419,7 @@ static void finalize_mask(int len)
24252419
}
24262420
} else {
24272421
if (mask_num_qw && john_main_process)
2428-
fprintf(stderr, "Warning: ?w has no special meaning unless running hybrid mask\n");
2422+
fprintf_color(color_warning, stderr, "Warning: ?w has no special meaning unless running hybrid mask\n");
24292423
if (mask_add_len > len)
24302424
mask_add_len = len;
24312425
}
@@ -2436,12 +2430,12 @@ static void finalize_mask(int len)
24362430
format_cannot_reset = 0;
24372431
if (john_main_process) {
24382432
fprintf(stderr, "Note: Disabling internal mask due to stacked rules\n");
2439-
log_event("- Disabling internal mask due to stacked rules");
2433+
LOG_ONCE("- Disabling internal mask due to stacked rules");
24402434
}
24412435
}
24422436
#if defined(HAVE_OPENCL) || defined(HAVE_ZTEX)
24432437
else if ((mask_fmt->params.flags & FMT_MASK) && options.req_int_cand_target > 0) {
2444-
log_event("- Overriding format's target internal mask factor of %d with user requested %d",
2438+
LOG_ONCE("- Overriding format's target internal mask factor of %d with user requested %d",
24452439
mask_int_cand_target, options.req_int_cand_target);
24462440
mask_int_cand_target = options.req_int_cand_target;
24472441
}
@@ -2514,9 +2508,14 @@ static void finalize_mask(int len)
25142508
mask_tot_cand = cand * mask_int_cand.num_int_cand;
25152509

25162510
if ((john_main_process || !cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIAllGPUsSame", 0)) &&
2517-
mask_int_cand.num_int_cand > 1)
2518-
log_event("- Requested internal mask factor: %d, actual now %d",
2519-
mask_int_cand_target, mask_int_cand.num_int_cand);
2511+
mask_int_cand.num_int_cand > 1) {
2512+
static int old_factor = -1;
2513+
if (mask_int_cand.num_int_cand != old_factor) {
2514+
log_event("- Requested internal mask factor: %d, actual now %d",
2515+
mask_int_cand_target, mask_int_cand.num_int_cand);
2516+
old_factor = mask_int_cand.num_int_cand;
2517+
}
2518+
}
25202519
}
25212520

25222521
void mask_crk_init(struct db_main *db)
@@ -2633,6 +2632,7 @@ int do_mask_crack(const char *extern_key)
26332632
}
26342633

26352634
mask_cur_len = i;
2635+
log_event("- Mask length now %u", mask_cur_len);
26362636

26372637
if (format_cannot_reset)
26382638
save_restore(&cpu_mask_ctx, 0, RESTORE);

src/mkv.c

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -391,22 +391,15 @@ void get_markov_options(struct db_main *db,
391391

392392
dummy_token = strtokm(NULL, ":");
393393
if (dummy_token) {
394-
if (john_main_process)
395-
fprintf(stderr,
396-
"Too many markov parameters specified:"
397-
" %s\n", dummy_token);
398-
error();
394+
error_msg("Too many markov parameters specified: %s\n", dummy_token);
399395
}
400396
}
401397

402398
if (mode == NULL)
403399
mode = SUBSECTION_DEFAULT;
404400

405401
if (cfg_get_section(SECTION_MARKOV, mode) == NULL) {
406-
if (john_main_process)
407-
fprintf(stderr,
408-
"Section [" SECTION_MARKOV "%s] not found\n", mode);
409-
error();
402+
error_msg("Section [" SECTION_MARKOV "%s] not found\n", mode);
410403
}
411404

412405
if (options.mkv_stats == NULL)
@@ -415,22 +408,16 @@ void get_markov_options(struct db_main *db,
415408
*statfile = options.mkv_stats;
416409

417410
if (*statfile == NULL) {
418-
log_event("Statsfile not defined");
419-
if (john_main_process)
420-
fprintf(stderr,
421-
"Statsfile not defined in section ["
422-
SECTION_MARKOV "%s]\n", mode);
423-
error();
411+
error_msg("Statsfile not defined in section ["
412+
SECTION_MARKOV "%s]\n", mode);
424413
}
425414
/* treat 'empty' level token same as NULL, i.e. pull in from config */
426415
if (NULL != lvl_token && !strlen(lvl_token))
427416
lvl_token = 0;
428417
if (lvl_token != NULL) {
429418
if (sscanf(lvl_token, "%d-%d", &minlevel, &level) != 2) {
430419
if (sscanf(lvl_token, "%d", &level) != 1) {
431-
if (john_main_process)
432-
fprintf(stderr, "Could not parse markov" " level\n");
433-
error();
420+
error_msg("Could not parse markov level\n");
434421
}
435422
if (level == 0)
436423
/* get min. and max. level from markov section */
@@ -452,19 +439,13 @@ void get_markov_options(struct db_main *db,
452439

453440
if (level <= 0)
454441
if ((level = cfg_get_int(SECTION_MARKOV, mode, "MkvLvl")) == -1) {
455-
log_event("no markov level defined!");
456-
if (john_main_process)
457-
fprintf(stderr,
458-
"no markov level defined in section ["
459-
SECTION_MARKOV "%s]\n", mode);
460-
error();
442+
error_msg("no markov level defined in section ["
443+
SECTION_MARKOV "%s]\n", mode);
461444
}
462445

463446
if (level > MAX_MKV_LVL) {
464-
log_event("! Level = %d is too large (max=%d)", level, MAX_MKV_LVL);
465447
if (john_main_process)
466-
fprintf(stderr, "Warning: Level = %d is too large "
467-
"(max = %d)\n", level, MAX_MKV_LVL);
448+
WARN_AND_LOG(color_warning, stderr, "! Level = %d is too large (max=%d)", level, MAX_MKV_LVL);
468449
level = MAX_MKV_LVL;
469450
}
470451

@@ -474,8 +455,8 @@ void get_markov_options(struct db_main *db,
474455

475456
if (level < minlevel) {
476457
if (john_main_process)
477-
fprintf(stderr, "Warning: max level(%d) < min level(%d)"
478-
", min level set to %d\n", level, minlevel, level);
458+
fprintf_color(color_warning, stderr, "Warning: max level(%d) < min level(%d), min level set to %d\n",
459+
level, minlevel, level);
479460
minlevel = level;
480461
}
481462

@@ -491,12 +472,8 @@ void get_markov_options(struct db_main *db,
491472

492473
if (maxlen <= 0) {
493474
if ((maxlen = cfg_get_int(SECTION_MARKOV, mode, "MkvMaxLen")) == -1) {
494-
log_event("no markov max length defined!");
495-
if (john_main_process)
496-
fprintf(stderr,
497-
"no markov max length defined in "
498-
"section [" SECTION_MARKOV "%s]\n", mode);
499-
error();
475+
error_msg("no markov max length defined in "
476+
"section [" SECTION_MARKOV "%s]\n", mode);
500477
} else {
501478
maxlen -= mask_add_len;
502479
if (mask_num_qw > 1)
@@ -505,17 +482,16 @@ void get_markov_options(struct db_main *db,
505482
}
506483

507484
if (our_fmt_len <= MAX_MKV_LEN && maxlen > our_fmt_len) {
508-
log_event("! MaxLen = %d is too large for this hash type", maxlen);
509485
if (john_main_process)
510-
fprintf(stderr, "Warning: "
511-
"MaxLen = %d is too large for the current hash"
512-
" type, reduced to %d\n", maxlen, our_fmt_len);
486+
WARN_AND_LOG(color_warning, stderr,
487+
"Warning: MaxLen = %d is too large for the current hash"
488+
" type, reduced to %d", maxlen, our_fmt_len);
513489
maxlen = our_fmt_len;
514490
} else if (maxlen > MAX_MKV_LEN) {
515-
log_event("! MaxLen = %d is too large (max=%d)", maxlen, MAX_MKV_LEN);
516491
if (john_main_process)
517-
fprintf(stderr, "Warning: Maxlen = %d is too large (max"
518-
" = %d)\n", maxlen, MAX_MKV_LEN);
492+
WARN_AND_LOG(color_warning, stderr,
493+
"Warning: Maxlen = %d is too large (max = %d)",
494+
maxlen, MAX_MKV_LEN);
519495
maxlen = MAX_MKV_LEN;
520496
}
521497

@@ -531,9 +507,9 @@ void get_markov_options(struct db_main *db,
531507

532508
if (minlen > maxlen) {
533509
if (john_main_process)
534-
fprintf(stderr, "Warning: minimum length(%d) > maximum"
535-
" length(%d), minimum length set to %d\n",
536-
minlen, maxlen, maxlen);
510+
fprintf_color(color_warning, stderr,
511+
"Warning: minimum length(%d) > maximum length(%d), minimum length set to %d\n",
512+
minlen, maxlen, maxlen);
537513
minlen = maxlen;
538514
}
539515

@@ -568,9 +544,7 @@ void get_markov_start_end(char *start_token, char *end_token,
568544
}
569545
/* NOTE, end_token can be an empty string. Treat "" and mkv_max as equal */
570546
else if (end_token != NULL && *end_token) {
571-
if (john_main_process)
572-
fprintf(stderr, "invalid end: %s\n", end_token);
573-
error();
547+
error_msg("invalid end: %s\n", end_token);
574548
}
575549
}
576550
/*
@@ -584,64 +558,52 @@ void get_markov_start_end(char *start_token, char *end_token,
584558
*/
585559
/* NOTE, start_token can be an empty string. Treat "" and "0" equal */
586560
else if (start_token != NULL && *start_token) {
587-
if (john_main_process)
588-
fprintf(stderr, "invalid start: %s\n", start_token);
589-
error();
561+
error_msg("invalid start: %s\n", start_token);
590562
}
591563

592564
if (start_token != NULL && strlen(start_token) &&
593565
start_token[strlen(start_token) - 1] == '%') {
594566
if (*mkv_start >= 100) {
595-
log_event("! Start = %s is too large (max < 100%%)", end_token);
596-
if (john_main_process)
597-
fprintf(stderr, "Error: Start = %s is too large"
598-
" (max < 100%%)\n", start_token);
599-
exit(1);
567+
error_msg("Error: Start = %s is too large (max < 100%%)\n", start_token);
600568
} else if (*mkv_start > 0) {
601569
*mkv_start *= mkv_max / 100;
602-
log_event("- Start: %s converted to %" PRId64, start_token,
603-
*mkv_start);
604570
if (john_main_process)
605-
fprintf(stderr, "Start: %s converted to %" PRId64
606-
"\n", start_token, *mkv_start);
571+
WARN_AND_LOG(color_warning, stderr,
572+
"Start: %s converted to %" PRId64,
573+
start_token, *mkv_start);
607574
}
608575
}
609576
if (end_token != NULL && strlen(end_token) &&
610577
end_token[strlen(end_token) - 1] == '%') {
611578
if (*mkv_end >= 100) {
612579
if (*mkv_end > 100) {
613580
if (john_main_process)
614-
fprintf(stderr, "Warning: End = %s is "
615-
"too large (max = 100%%)\n", end_token);
581+
fprintf_color(color_warning, stderr,
582+
"Warning: End = %s is too large (max = 100%%)\n",
583+
end_token);
616584
}
617585
*mkv_end = 0;
618586
} else if (*mkv_end > 0) {
619587
*mkv_end *= mkv_max / 100;
620-
log_event("- End: %s converted to %" PRId64 "", end_token, *mkv_end);
621588
if (john_main_process)
622-
fprintf(stderr, "End: %s converted to %" PRId64
623-
"\n", end_token, *mkv_end);
589+
WARN_AND_LOG(color_warning, stderr,
590+
"End: %s converted to %" PRId64, end_token, *mkv_end);
624591
}
625592
}
626593
if (*mkv_end == 0)
627594
*mkv_end = mkv_max;
628595

629596
if (*mkv_end > mkv_max) {
630-
log_event("! End = %" PRId64 " is too large (max=%" PRId64 ")", *mkv_end,
631-
mkv_max);
632597
if (john_main_process)
633-
fprintf(stderr, "Warning: End = %" PRId64 " is too large "
634-
"(max = %" PRId64 ")\n", *mkv_end, mkv_max);
598+
WARN_AND_LOG(color_warning, stderr,
599+
"Warning: End = %" PRId64 " is too large (max = %" PRId64 ")",
600+
*mkv_end, mkv_max);
635601
*mkv_end = mkv_max;
636602
}
637603

638604
if (*mkv_start > *mkv_end) {
639-
log_event("! MKV start > end (%" PRId64 " > %" PRId64 ")", *mkv_start,
640-
*mkv_end);
641-
if (john_main_process)
642-
fprintf(stderr, "Error: MKV start > end (%" PRId64 " > %" PRId64
643-
")\n", *mkv_start, *mkv_end);
644-
error();
605+
error_msg("Error: MKV start > end (%" PRId64 " > %" PRId64 ")\n",
606+
*mkv_start, *mkv_end);
645607
}
646608
}
647609

0 commit comments

Comments
 (0)