diff --git a/doc/NEWS b/doc/NEWS index a6fda198c5..7222f0f82e 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -488,6 +488,8 @@ Major changes from 1.9.0-jumbo-1 (May 2019) in this bleeding-edge version: - Add support to keepass2john for the current format of KeePass XML keyfiles. The formats needed no changes. [magnum; 2025] +- Optionally add colors to many warning/error messages. [magnum; 2026] + Major changes from 1.8.0-jumbo-1 (December 2014) to 1.9.0-jumbo-1 (May 2019): diff --git a/src/7z_common_plug.c b/src/7z_common_plug.c index 7fb8559963..6068d189ee 100644 --- a/src/7z_common_plug.c +++ b/src/7z_common_plug.c @@ -101,9 +101,6 @@ struct fmt_tests sevenzip_tests[] = { sevenzip_salt_t *sevenzip_salt; -#define YEL "\x1b[0;33m" -#define NRM "\x1b[0m" - int sevenzip_trust_padding; static char *comp_type[16] = { "stored", "LZMA1", "LZMA2", "PPMD", NULL, NULL, "BZIP2", "DEFLATE" }; @@ -140,15 +137,15 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self) && type != 128) { if (john_main_process && !warned[type]) { warned[type] = 1; - fprintf(stderr, YEL "Warning: Not loading files with unsupported compression type %s (0x%02x)\n" NRM, + fprintf_color(color_warning, stderr, "Warning: Not loading files with unsupported compression type %s (0x%02x)\n", comp_type[c_type] ? comp_type[c_type] : "(unknown)", type); #if !HAVE_LIBBZ2 if (type == 6) - fprintf(stderr, YEL "Rebuild with libbz2 to get support for that type.\n" NRM); + fprintf_color(color_warning, stderr, "Rebuild with libbz2 to get support for that type.\n"); #endif #if !HAVE_LIBZ if (type == 7) - fprintf(stderr, YEL "Rebuild with libz (zlib) to get support for that type.\n" NRM); + fprintf_color(color_warning, stderr, "Rebuild with libz (zlib) to get support for that type.\n"); #endif } goto err; @@ -156,7 +153,7 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self) if (john_main_process && !ldr_in_pot && !self_test_running && options.verbosity > VERB_DEFAULT && !warned[type]) { warned[type] = 1; - fprintf(stderr, YEL "Saw file(s) with compression type %s%s%s (0x%02x)\n" NRM, + fprintf_color(color_notice, stderr, "Saw file(s) with compression type %s%s%s (0x%02x)\n", precomp_type[p_type], p_type ? "+" : "", comp_type[c_type], type); } if ((p = strtokm(NULL, "$")) == NULL) /* NumCyclesPower */ @@ -174,11 +171,8 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self) goto err; len = atoi(p); if (len > 0 && strstr(self->params.label, "-opencl")) { - static int warned; - - if (!warned++) - fprintf(stderr, YEL "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n" NRM, - self->params.label); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n", self->params.label); goto err; } if (len > 16) @@ -355,7 +349,7 @@ int sevenzip_decrypt(unsigned char *derived_key) #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n", + fprintf_color(color_notice, stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n", sevenzip_salt->type, precomp_type[p_type] ? precomp_type[p_type] : "", p_type ? "+" : "", comp_type[c_type] ? comp_type[c_type] : "(unknown)", @@ -379,12 +373,11 @@ int sevenzip_decrypt(unsigned char *derived_key) if (buf[i] != 0) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) { - fprintf(stderr, YEL "Early padding check failed, "); + fprintf_color(color_warning, stderr, "Early padding check failed, "); dump_stderr_msg("padding", buf + 16 - pad_size, pad_size); - fprintf(stderr, NRM); } if (sevenzip_salt->type == 0x80) - fprintf(stderr, YEL "We don't have data for complete decryption\n"); + WARN_ONCE(color_warning, stderr, "We don't have data for complete decryption\n"); break; #else return 0; @@ -395,13 +388,13 @@ int sevenzip_decrypt(unsigned char *derived_key) } #if DEBUG if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "Early padding check passed\n"); + fprintf_color(color_notice, stderr, "Early padding check passed\n"); else nbytes = 0; -#else + if (self_test_running) +#endif if (sevenzip_salt->type == 0x80) /* We only have truncated data */ return 1; -#endif } /* Complete decryption */ @@ -417,9 +410,8 @@ int sevenzip_decrypt(unsigned char *derived_key) if (out[i] != 0) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) { - fprintf(stderr, YEL "Full data padding check failed, "); + fprintf_color(color_warning, stderr, "Full data padding check failed, "); dump_stderr_msg("padding", out + sevenzip_salt->aes_length - pad_size, pad_size); - fprintf(stderr, NRM); } break; #else @@ -431,7 +423,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } #if DEBUG if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "Padding check passed\n"); + fprintf_color(color_notice, stderr, "Padding check passed\n"); #endif } @@ -456,7 +448,7 @@ int sevenzip_decrypt(unsigned char *derived_key) out_size == crc_len) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n", + fprintf_color(color_notice, stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n", in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0], sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]); #endif @@ -465,7 +457,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } else { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n" NRM, + fprintf_color(color_warning, stderr, "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n", in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0], sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]); #endif @@ -488,7 +480,7 @@ int sevenzip_decrypt(unsigned char *derived_key) out_size == crc_len) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n", + fprintf_color(color_notice, stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n", in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]); #endif MEM_FREE(out); @@ -496,7 +488,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } else { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n" NRM, + fprintf_color(color_warning, stderr, "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n", in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]); #endif MEM_FREE(new_out); @@ -526,7 +518,7 @@ int sevenzip_decrypt(unsigned char *derived_key) if (ret == BZ_STREAM_END) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n", + fprintf_color(color_notice, stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n", sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size, crc_len - inf_stream.avail_out, crc_len); #endif @@ -535,7 +527,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } else { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n" NRM, + fprintf_color(color_warning, stderr, "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n", sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size, crc_len - inf_stream.avail_out, crc_len); #endif @@ -564,7 +556,7 @@ int sevenzip_decrypt(unsigned char *derived_key) if (ret == Z_STREAM_END) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n", + fprintf_color(color_notice, stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n", sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size, crc_len - inf_stream.avail_out, crc_len); #endif @@ -573,7 +565,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } else { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n" NRM, + fprintf_color(color_warning, stderr, "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n", sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size, crc_len - inf_stream.avail_out, crc_len); #endif @@ -586,7 +578,7 @@ int sevenzip_decrypt(unsigned char *derived_key) if (p_type) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props); + fprintf_color(color_notice, stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props); #endif if (p_type == 1) { uint32_t state; @@ -596,10 +588,7 @@ int sevenzip_decrypt(unsigned char *derived_key) } else if (p_type == 2) { if (!benchmark_running && options.verbosity >= VERB_DEFAULT) { - static int warned; - - if (!warned++) - fprintf(stderr, YEL "Can't decode BCJ2, so skipping CRC check" NRM); + WARN_ONCE(color_warning, stderr, "Can't decode BCJ2, so skipping CRC check"); } goto exit_good; } @@ -620,7 +609,7 @@ int sevenzip_decrypt(unsigned char *derived_key) Delta_Decode(state, sevenzip_salt->preproc_props + 1, out, crc_len); #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "DELTA decoding can't fail so result unknown\n" NRM); + fprintf_color(color_notice, stderr, "DELTA decoding can't fail so result unknown\n"); #endif } } @@ -636,13 +625,13 @@ int sevenzip_decrypt(unsigned char *derived_key) if (ccrc == sevenzip_salt->crc) { #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, "CRC check passed (%08x)\n", ccrc); + fprintf_color(color_notice, stderr, "CRC check passed (%08x)\n", ccrc); #endif goto exit_good; } #if DEBUG if (!benchmark_running && options.verbosity >= VERB_DEBUG) - fprintf(stderr, YEL "CRC failed, %08x vs %08x\n" NRM, ccrc, sevenzip_salt->crc); + fprintf_color(color_warning, stderr, "CRC failed, %08x vs %08x\n", ccrc, sevenzip_salt->crc); #endif exit_bad: diff --git a/src/LM_fmt.c b/src/LM_fmt.c index dd2f53f687..9cb96a909e 100644 --- a/src/LM_fmt.c +++ b/src/LM_fmt.c @@ -124,14 +124,12 @@ static void init(struct fmt_main *self) fmt_LM.params.max_keys_per_crypt = DES_bs_max_kpc; #endif - static int warned; - if (!warned && options.target_enc > CP_DOS_HI && !options.listconf && + if (options.target_enc > CP_DOS_HI && !options.listconf && sizeof(tests) / sizeof(tests[0]) > 16) { - fprintf_color(color_warning, stderr, + WARN_ONCE(color_warning, stderr, "Warning: LM formats incompatible with %s encoding, disabling some tests\n", cp_id2name(options.target_enc)); tests[16].ciphertext = NULL; // Truncates the array after 16 entries - warned = 1; } } diff --git a/src/argon2_fmt_plug.c b/src/argon2_fmt_plug.c index f4f3782210..ac7245c37a 100644 --- a/src/argon2_fmt_plug.c +++ b/src/argon2_fmt_plug.c @@ -272,11 +272,11 @@ static void set_salt(void *salt) static int allocate(uint8_t **memory, size_t size) { if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) { - fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER); goto fail; } if (thread_mem[THREAD_NUMBER].used) { - fprintf(stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER); goto fail; } @@ -299,15 +299,15 @@ static int allocate(uint8_t **memory, size_t size) static void deallocate(uint8_t *memory, size_t size) { if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) { - fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER); return; } if (!thread_mem[THREAD_NUMBER].used) - fprintf(stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER); if (thread_mem[THREAD_NUMBER].region.aligned_size < size) - fprintf(stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n", + fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n", THREAD_NUMBER, size, thread_mem[THREAD_NUMBER].region.aligned_size); thread_mem[THREAD_NUMBER].used = 0; @@ -343,7 +343,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) error_code = argon2_ctx(&context, saved_salt.type); if (error_code != ARGON2_OK) { failed = -1; - fprintf(stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code)); + fprintf_color(color_error, stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code)); #ifndef _OPENMP break; #endif @@ -352,7 +352,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP - fprintf(stderr, "Error: Argon2 failed in some threads\n"); + fprintf_color(color_error, stderr, "Error: Argon2 failed in some threads\n"); #endif error(); } diff --git a/src/armory_fmt_plug.c b/src/armory_fmt_plug.c index f70dcaf9cc..fa07672e0d 100644 --- a/src/armory_fmt_plug.c +++ b/src/armory_fmt_plug.c @@ -125,8 +125,7 @@ static void init(struct fmt_main *self) * calls that take a const pointer. */ if (!(secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN))) { - fprintf(stderr, "Failed to create secp256k1 context\n"); - error(); + error_msg("Failed to create secp256k1 context\n"); } } @@ -439,12 +438,10 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); - error(); + error_msg("OpenMP thread number out of range\n"); } #endif - fprintf(stderr, "Memory allocation failed: %s\n", strerror(failed)); - error(); + error_msg("Memory allocation failed: %s\n", strerror(failed)); } return cracked ? count : 0; diff --git a/src/as400_ssha1_fmt_plug.c b/src/as400_ssha1_fmt_plug.c index 09b88c42fb..ea5f85355a 100644 --- a/src/as400_ssha1_fmt_plug.c +++ b/src/as400_ssha1_fmt_plug.c @@ -46,6 +46,7 @@ john_register_one(&fmt_AS400_ssha1); #include "options.h" #include "unicode.h" #include "base64_convert.h" +#include "john.h" #define FORMAT_LABEL "as400-ssha1" #define FORMAT_NAME "AS400-SaltedSHA1" @@ -150,14 +151,12 @@ static int our_valid(char *ciphertext, struct fmt_main *self) if (strlen(&ciphertext[FORMAT_TAG_LEN + 2 * BINARY_SIZE + 1]) > 10) return 0; if (options.input_enc == UTF_8 && !valid_utf8((UTF8*)ciphertext)) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } return pDynamic->methods.valid(Convert(Conv_Buf, ciphertext), pDynamic); diff --git a/src/bench.c b/src/bench.c index e8fcdded8c..a6a97cbdbe 100644 --- a/src/bench.c +++ b/src/bench.c @@ -279,7 +279,7 @@ static void bench_set_keys(struct fmt_main *format, } if (warn == 1) { - fprintf(stderr, "Warning: not enough candidates under " + fprintf_color(color_warning, stderr, "Warning: not enough candidates under " "benchmark length %d\n", length); warn = 2; } diff --git a/src/bestcrypt_ve_fmt_plug.c b/src/bestcrypt_ve_fmt_plug.c index 774392d0e7..5457670c0a 100644 --- a/src/bestcrypt_ve_fmt_plug.c +++ b/src/bestcrypt_ve_fmt_plug.c @@ -31,6 +31,7 @@ john_register_one(&fmt_bestcrypt_ve); #endif #include "arch.h" +#include "john.h" #include "misc.h" #include "common.h" #include "formats.h" @@ -229,7 +230,8 @@ static int valid(char *ciphertext, struct fmt_main *self) if (atoi(p) != 8 && atoi(p) != 9 && atoi(p) != 10 && atoi(p) != 11 && atoi(p) != 15) goto err; if (atoi(p) == 11) { - fprintf(stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n"); + if (john_main_process && !ldr_in_pot) + fprintf_color(color_warning, stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n"); goto err; } if ((p = strtokm(NULL, "$")) == NULL) // salt @@ -401,11 +403,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); + fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed)); error(); } diff --git a/src/bitshares_fmt_plug.c b/src/bitshares_fmt_plug.c index 1e02f48748..4b888a3d7a 100644 --- a/src/bitshares_fmt_plug.c +++ b/src/bitshares_fmt_plug.c @@ -300,7 +300,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) any_cracked |= 1; if (memcmp(km, out_full, 4) != 0) { - fprintf(stderr, "Warning: " FORMAT_LABEL ": Good padding, but bad checksum" + fprintf_color(color_warning, stderr, "Warning: " FORMAT_LABEL ": Good padding, but bad checksum" " (corrupted data or false positive?) - will keep guessing\n"); fmt_bitshares.params.flags |= FMT_NOT_EXACT; } diff --git a/src/c3_fmt.c b/src/c3_fmt.c index bf3b841bf1..a1c720f7f9 100644 --- a/src/c3_fmt.c +++ b/src/c3_fmt.c @@ -142,14 +142,11 @@ static void init(struct fmt_main *self) * That's why, don't require FLG_TEST_CHK to be set. */ if (options.flags & FLG_PASSWD) { - fprintf(stderr, - "\n%s: --subformat option is only for --test or --list=format-tests\n", FORMAT_LABEL); - error(); + error_msg_main("\n%s: --subformat option is only for --test or --list=format-tests\n", FORMAT_LABEL); } if (!strcmp(options.subformat, "?")) { - fprintf(stderr, "Subformat may either be a verbatim salt, or: descrypt, md5crypt, bcrypt, sha256crypt, sha512crypt, sunmd5, scrypt, yescrypt, gost-yescrypt\n\n"); - error(); + error_msg_main("Subformat may either be a verbatim salt, or: descrypt, md5crypt, bcrypt, sha256crypt, sha512crypt, sunmd5, scrypt, yescrypt, gost-yescrypt\n\n"); } else if (!strcasecmp(options.subformat, "md5crypt") || !strcasecmp(options.subformat, "md5")) { static struct fmt_tests tests[] = { @@ -263,9 +260,8 @@ static void init(struct fmt_main *self) if (c && strlen(c) >= 13) tests[i].ciphertext = xstrdup(c); else { - fprintf(stderr, "%s not supported on this system\n", + error_msg_main("%s not supported on this system\n", options.subformat); - error(); } /* No need to replace tests that we're not going to use */ @@ -274,9 +270,8 @@ static void init(struct fmt_main *self) } if (strlen(tests[0].ciphertext) == 13) { - fprintf(stderr, "%s not supported on this system\n", + error_msg_main("%s not supported on this system\n", options.subformat); - error(); } } } @@ -371,7 +366,7 @@ static int valid(char *ciphertext, struct fmt_main *self) if (id != 10 && !ldr_in_pot) if (john_main_process) - fprintf(stderr, "Warning: " + fprintf_color(color_warning, stderr, "Warning: " "hash encoding string length %d, type id %c%c\n" "appears to be unsupported on this system; " "will not load such hashes.\n", diff --git a/src/color.c b/src/color.c index c2e04601b2..b6de9dffa8 100644 --- a/src/color.c +++ b/src/color.c @@ -1,5 +1,5 @@ /* - * This software is Copyright (c) 2025 magnum + * This software is Copyright (c) 2025-2026 magnum * and is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without * modifications, are permitted. @@ -9,20 +9,24 @@ #include "config.h" #include "options.h" -char *color_error, *color_notice, *color_warning, *color_end; +const char* const color_none = ""; +char *color_error = ""; +char *color_notice = ""; +char *color_warning = ""; +char *color_end = ""; /* - * Translate ^ to Esc, in place. - * Also turns a null pointer into a pointer to empty string. + * Return a new string where '^' is translated to 'Esc'. + * If input is a null pointer, return an empty string. */ char *parse_esc(const char *string) { + if (!string) + return (char*)color_none; + char *out = str_alloc_copy(string); char *s = out; - if (!s) - return NULL; - while (*s) { if (*s == '^') *s = 0x1b; @@ -40,5 +44,5 @@ void color_init() color_warning = parse_esc(cfg_get_param(SECTION_OPTIONS, NULL, "ColorWarning")); color_end = parse_esc(cfg_get_param(SECTION_OPTIONS, NULL, "ColorEnd")); } else - color_error = color_notice = color_warning = color_end = ""; + color_error = color_notice = color_warning = color_end = (char*)color_none; } diff --git a/src/color.h b/src/color.h index 29fff87c32..99a09929a6 100644 --- a/src/color.h +++ b/src/color.h @@ -1,5 +1,5 @@ /* - * This software is Copyright (c) 2025 magnum + * This software is Copyright (c) 2025-2026 magnum * and is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without * modifications, are permitted. @@ -8,36 +8,49 @@ #ifndef _JOHN_COLOR_H #define _JOHN_COLOR_H -extern char *parse_esc(const char *string); -extern void color_init(); - -/* Color escape sequences as strings */ -extern char *color_error, *color_notice, *color_warning, *color_end; - -#define printf_color(color, ...) fprintf_color(color, stdout, __VA_ARGS__); - -#define puts_color(color, string) \ - do { \ - fputs_color(color, string, stdout); \ - putchar('\n'); \ - } while (0) +#include +#include /* isatty */ +/* + * We might need to turn this into a real function that prints the components + * in a non-interleavable operation (for MPI in particular), but it's not all + * that trivial. We'll see how it turns out - worst case is that the color + * start/end sequences gets misplaced, and the flush helps a bit. + */ #define fprintf_color(color, handle, ...) \ do { \ - if (isatty(fileno(handle))) \ - fputs( (color) , handle); \ + int tty_ = isatty(fileno(handle)); \ + if (tty_) \ + fputs(color, handle); \ fprintf(handle, __VA_ARGS__); \ - if (isatty(fileno(handle))) \ + if (tty_) { \ fputs(color_end, handle); \ + if (handle == stdout) \ + fflush(stdout); \ + } \ } while (0) -#define fputs_color(color, string, handle) \ +#define printf_color(color, ...) fprintf_color(color, stdout, __VA_ARGS__) +#define puts_color(color, string) printf_color(color, string) +#define fputs_color(color, string, handle) fprintf_color(color, handle, string) + +/* + * Like fprintf_color but only once per session. + */ +#define WARN_ONCE(...) \ do { \ - if (isatty(fileno(handle))) \ - fputs( (color) , handle); \ - fputs(string, handle); \ - if (isatty(fileno(handle))) \ - fputs(color_end, handle); \ + static int warned; \ + if (!warned) { \ + fprintf_color(__VA_ARGS__); \ + warned = 1; \ + } \ } while (0) +extern char *parse_esc(const char *string); +extern void color_init(); + +/* Color escape sequences as strings */ +extern const char* const color_none; +extern char *color_error, *color_notice, *color_warning, *color_end; + #endif /* _JOHN_COLOR_H */ diff --git a/src/config.c b/src/config.c index e7fd1dbfcc..919693fc11 100644 --- a/src/config.c +++ b/src/config.c @@ -118,11 +118,11 @@ static void cfg_add_section(const char *name) if (!strcmp(last->name, name)) { if (!cfg_loading_john_local) { if (john_main_process) - fprintf(stderr, "Warning! john.conf section [%s] is multiple declared.\n", name); + fprintf_color(color_warning, stderr, "Warning! john.conf section [%s] is multiple declared.\n", name); } #ifndef BENCH_BUILD else if (john_main_process && options.verbosity >= VERB_DEFAULT) - fprintf(stderr, "Warning! Section [%s] overridden by john-local.conf\n", name); + fprintf_color(color_warning, stderr, "Warning! Section [%s] overridden by john-local.conf\n", name); #endif break; } diff --git a/src/cracker.c b/src/cracker.c index 0f39c658df..287e270032 100644 --- a/src/cracker.c +++ b/src/cracker.c @@ -2,7 +2,7 @@ * This file is part of John the Ripper password cracker, * Copyright (c) 1996-2003,2006,2010-2013,2015,2017 by Solar Designer * Copyright (c) 2009-2018 by JimF - * Copyright (c) 2011-2025 by magnum + * Copyright (c) 2011-2026 by magnum * * Redistribution and use in source and binary forms, with or without * modification, are permitted. @@ -303,7 +303,7 @@ static void crk_remove_salt(struct db_salt *salt) if (crk_db->salt_hash[hash] == salt) { if (options.verbosity >= VERB_DEBUG) { - fprintf(stderr, "Got rid of %s, %s\n", strncasecmp(crk_params->label, "wpapsk", 6) ? "a salt" : (char*)(salt->salt) + 4, crk_loaded_counts()); + fprintf_color(color_notice, stderr, "Got rid of %s, %s\n", strncasecmp(crk_params->label, "wpapsk", 6) ? "a salt" : (char*)(salt->salt) + 4, crk_loaded_counts()); status_update_counts(); } if (salt->next && @@ -720,7 +720,7 @@ int crk_reload_pot(void) if (salts && cfg_get_bool(SECTION_OPTIONS, NULL, "ShowSaltProgress", 0)) { - fprintf(stderr, "%s after pot sync\n", crk_loaded_counts()); + fprintf_color(color_notice, stderr, "%s after pot sync\n", crk_loaded_counts()); status_update_counts(); } } diff --git a/src/django_scrypt_fmt_plug.c b/src/django_scrypt_fmt_plug.c index 3f4402bc57..579c5b011d 100644 --- a/src/django_scrypt_fmt_plug.c +++ b/src/django_scrypt_fmt_plug.c @@ -30,6 +30,7 @@ john_register_one(&fmt_django_scrypt); #include "options.h" #include "base64_convert.h" #include "yescrypt/yescrypt.h" +#include "john.h" #define FORMAT_LABEL "django-scrypt" #define FORMAT_NAME "" @@ -236,12 +237,10 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); - error(); + error_msg_main("OpenMP thread number out of range\n"); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); - error(); + error_msg_main("scrypt failed: %s\n", strerror(failed)); } return count; diff --git a/src/encdatavault_common_plug.c b/src/encdatavault_common_plug.c index d07935071b..74d7382f51 100644 --- a/src/encdatavault_common_plug.c +++ b/src/encdatavault_common_plug.c @@ -11,6 +11,8 @@ * */ #include "encdatavault_common.h" +#include "loader.h" +#include "john.h" MAYBE_INLINE void enc_xor_block(uint64_t *dst, const uint64_t *src) { @@ -83,9 +85,8 @@ int valid_common(char *ciphertext, struct fmt_main *self, int is_pbkdf2) int version = atoi(p); if (version != 3 && version != 1) { - static int warned; - if (!self_test_running && !warned++) - fprintf(stderr, "%s: Warning: version %d not supported, not loading such hashes!\n", self->params.label, version); + if (!self_test_running && !ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: Warning: version %d not supported, not loading such hashes!\n", self->params.label, version); goto err; } if ((p = strtokm(NULL, "$")) == NULL) // algorithm id @@ -93,9 +94,8 @@ int valid_common(char *ciphertext, struct fmt_main *self, int is_pbkdf2) if (!isdec(p)) goto err; if (atoi(p) > 4 || atoi(p) < 1) { - static int warned; - if (!warned++) - fprintf(stderr, "%s: Warning: algorithm id %d not supported!\n", self->params.label, atoi(p)); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: Warning: algorithm id %d not supported!\n", self->params.label, atoi(p)); goto err; } if ((p = strtokm(NULL, "$")) == NULL) // Nonce @@ -115,9 +115,8 @@ int valid_common(char *ciphertext, struct fmt_main *self, int is_pbkdf2) goto err; saltlen = atoi(p); if (saltlen > PBKDF2_32_MAX_SALT_SIZE) { - static int warned; - if (!warned++) - fprintf(stderr, "%s: Warning: salt length %d too big!\n", self->params.label, saltlen); + if (!ldr_in_pot) + WARN_ONCE(color_warning, stderr, "%s: Warning: salt length %d too big!\n", self->params.label, saltlen); goto err; } if ((p = strtokm(NULL, "$")) == NULL) // Salt diff --git a/src/ethereum_fmt_plug.c b/src/ethereum_fmt_plug.c index 305717120a..e64fb4bea9 100644 --- a/src/ethereum_fmt_plug.c +++ b/src/ethereum_fmt_plug.c @@ -256,15 +256,13 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); - error(); + error_msg("OpenMP thread number out of range\n"); } #endif #ifndef _OPENMP fail_with_errno: #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); - error(); + error_msg("scrypt failed: %s\n", strerror(failed)); } return count; diff --git a/src/external.c b/src/external.c index a71cb1cd19..03aa7b0fe1 100644 --- a/src/external.c +++ b/src/external.c @@ -283,7 +283,7 @@ void ext_init(char *mode, struct db_main *db) (ext_flags & (EXT_USES_GENERATE | EXT_USES_FILTER)) == EXT_USES_FILTER && f_generate) if (john_main_process) - fprintf(stderr, "Warning: external mode defines generate(), " + fprintf_color(color_warning, stderr, "Warning: external mode defines generate(), " "but is only used for filter()\n"); ext_mode = mode; diff --git a/src/formats.c b/src/formats.c index 495c916e8a..072c68dcb6 100644 --- a/src/formats.c +++ b/src/formats.c @@ -1,7 +1,7 @@ /* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-2001,2006,2008,2010-2013,2015 by Solar Designer - * Copyright (c) 2011-2025, magnum + * Copyright (c) 2011-2026, magnum * Copyright (c) 2009-2018, JimF */ @@ -384,14 +384,14 @@ int fmt_check_custom_list(void) char *exclude_fmt = &(req_format->data[1]); if (!exclude_fmt[0]) - error_msg("Error: '%s' in format list doesn't make sense\n", req_format->data); + error_msg_main("Error: '%s' in format list doesn't make sense\n", req_format->data); num_e += exclude_formats_up_to(exclude_fmt, &full_fmt_list); } else if (req_format->data[0] == '-') { char *exclude_fmt = &(req_format->data[1]); if (!exclude_fmt[0]) - error_msg("Error: '%s' in format list doesn't make sense\n", req_format->data); + error_msg_main("Error: '%s' in format list doesn't make sense\n", req_format->data); num_e += exclude_formats(exclude_fmt, &full_fmt_list); } } while ((req_format = req_format->next)); @@ -422,7 +422,7 @@ int fmt_check_custom_list(void) char *require_fmt = &(req_format->data[1]); if (!require_fmt[0]) - error_msg("Error: '%s' in format list doesn't make sense\n", req_format->data); + error_msg_main("Error: '%s' in format list doesn't make sense\n", req_format->data); prune_formats(require_fmt, had_i); if (!fmt_list) { @@ -442,7 +442,7 @@ int fmt_check_custom_list(void) return 1; } else - error_msg("Error: Format list '%s' made no sense\n", options.format_list); + error_msg_main("Error: Format list '%s' made no sense\n", options.format_list); } return 0; @@ -483,7 +483,7 @@ void fmt_init(struct fmt_main *format) if (john_main_process && !(options.flags & FLG_TEST_CHK) && !options.listconf && options.target_enc != UTF_8 && format->params.flags & FMT_UTF8) - fprintf(stderr, "Warning: %s format should always be " + fprintf_color(color_warning, stderr, "Warning: %s format should always be " "UTF-8. Use --target-encoding=utf8\n", format->params.label); @@ -1129,7 +1129,7 @@ static char *fmt_self_test_body(struct fmt_main *format, if (!binary_align_warned && !is_aligned(binary, format->params.binary_align) && format->params.binary_size > 0) { - puts("Warning: binary() returned misaligned pointer"); + puts_color(color_warning, "Warning: binary() returned misaligned pointer"); binary_align_warned = 1; } @@ -1146,7 +1146,7 @@ static char *fmt_self_test_body(struct fmt_main *format, if (((unsigned char*)binary)[format->params.binary_size-1] == 0xCC) { /* possibly did not clean the binary. */ - puts("Warning: binary() not pre-cleaning buffer"); + puts_color(color_warning, "Warning: binary() not pre-cleaning buffer"); binary_cleaned_warned = 1; } } @@ -1170,7 +1170,7 @@ static char *fmt_self_test_body(struct fmt_main *format, if (!salt_align_warned && !is_aligned(salt, format->params.salt_align) && format->params.salt_size > 0) { - puts("Warning: salt() returned misaligned pointer"); + puts_color(color_warning, "Warning: salt() returned misaligned pointer"); salt_align_warned = 1; } @@ -1183,7 +1183,7 @@ static char *fmt_self_test_body(struct fmt_main *format, dyna_salt_create(salt); if (dyna_salt_cmp(copy, salt, format->params.salt_size)) { - puts("Warning: No dupe-salt detection"); + puts_color(color_warning, "Warning: No dupe-salt detection"); salt_dupe_warned = 1; // These can be useful in tracking down salt // dupe problems. @@ -1212,7 +1212,7 @@ static char *fmt_self_test_body(struct fmt_main *format, p3 = *((dyna_salt_t**)salt); if (dyna_salt_smash_check(salt, 0xC3)) { /* possibly did not clean the salt. */ - puts("Warning: salt() not pre-cleaning buffer"); + puts_color(color_warning, "Warning: salt() not pre-cleaning buffer"); salt_cleaned_warned = 1; } } @@ -1229,7 +1229,7 @@ static char *fmt_self_test_body(struct fmt_main *format, salt = format->methods.salt(ciphertext); if (((unsigned char*)salt)[format->params.salt_size-1] == 0xC3) { /* possibly did not clean the salt. */ - puts("Warning: salt() not pre-cleaning buffer"); + puts_color(color_warning, "Warning: salt() not pre-cleaning buffer"); salt_cleaned_warned = 1; } } diff --git a/src/gpu_common.c b/src/gpu_common.c index 65838f9105..1eb088de4e 100644 --- a/src/gpu_common.c +++ b/src/gpu_common.c @@ -6,7 +6,7 @@ * This software is * Copyright (c) 2010-2012 Samuele Giovanni Tonon * Copyright (c) 2010-2013 Lukas Odzioba - * Copyright (c) 2010-2013 magnum + * Copyright (c) 2010-2026 magnum * Copyright (c) 2012-2015 Claudio André * and is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without @@ -458,7 +458,7 @@ int id2adl(const hw_bus busInfo) { void gpu_check_temp(void) { #if HAVE_LIBDL - static int warned, warnedTemperature; + static int warnedTemperature; int i, hot_gpu = 0, alerts = 0; if (gpu_temp_limit < 0) @@ -472,13 +472,8 @@ void gpu_check_temp(void) dev_get_temp[dev](temp_dev_id[dev], &temp, &fan, &util, &cl, &ml); if (temp > 125 || temp < 10) { - if (!warned++) { - log_event("Device %d probably invalid temp reading (%d%sC).", - dev + 1, temp, gpu_degree_sign); - fprintf(stderr, - "Device %d probably invalid temp reading (%d%sC).\n", - dev + 1, temp, gpu_degree_sign); - } + WARN_AND_LOG_ONCE(color_warning, stderr, "GPU device %d probably invalid temp reading (%d%sC)", + dev + 1, temp, gpu_degree_sign); return; } @@ -492,15 +487,10 @@ void gpu_check_temp(void) if (cool_gpu_down == 1) warnedTemperature++; - log_event("Device %d overheat (%d%sC, fan %s), %s%s.", - dev + 1, temp, gpu_degree_sign, s_fan, - (cool_gpu_down > 0) ? "sleeping" : "aborting job", - (hot_gpu) ? " again" : ""); - fprintf(stderr, - "Device %d overheat (%d%sC, fan %s), %s%s.\n", - dev + 1, temp, gpu_degree_sign, s_fan, - (cool_gpu_down > 0) ? "sleeping" : "aborting job", - (hot_gpu) ? " again" : ""); + WARN_AND_LOG(color_warning, stderr, "GPU device %d overheat (%d%sC, fan %s), %s%s", + dev + 1, temp, gpu_degree_sign, s_fan, + (cool_gpu_down > 0) ? "sleeping" : "aborting job", + (hot_gpu) ? " again" : ""); } hot_gpu = 1; /*** @@ -532,11 +522,9 @@ void gpu_check_temp(void) if (fan >= 0) sprintf(s_fan, "%u%%", fan); - log_event("Device %d is waking up (%d%sC, fan %s).", - dev + 1, temp, gpu_degree_sign, s_fan); - fprintf(stderr, - "Device %d is waking up (%d%sC, fan %s).\n", - dev + 1, temp, gpu_degree_sign, s_fan); + WARN_AND_LOG(color_warning, stderr, + "GPU device %d is waking up (%d%sC, fan %s)", + dev + 1, temp, gpu_degree_sign, s_fan); } hot_gpu = 0; } @@ -557,7 +545,7 @@ void gpu_log_temp(void) fan = temp = util = -1; dev_get_temp[dev](temp_dev_id[dev], &temp, &fan, &util, &cl, &ml); - n = sprintf(s_gpu, "Device %d:", dev + 1); + n = sprintf(s_gpu, "GPU device %d:", dev + 1); if (temp >= 0) n += sprintf(s_gpu + n, " temp: %u%sC", temp, gpu_degree_sign); if (util > 0) @@ -565,7 +553,7 @@ void gpu_log_temp(void) if (fan >= 0) n += sprintf(s_gpu + n, " fan: %u%%", fan); if (temp >= 0 || util > 0 || fan > 0) - log_event("- %s", s_gpu); + log_event("%s", s_gpu); } #endif } diff --git a/src/inc.c b/src/inc.c index 0085449a52..52f1187786 100644 --- a/src/inc.c +++ b/src/inc.c @@ -133,10 +133,7 @@ void inc_hybrid_fix_state(void) static void inc_format_error(const char *charset) { - log_event("! Incorrect charset file format: %.100s", charset); - if (john_main_process) - fprintf(stderr, "Incorrect charset file format: %s\n", charset); - error(); + error_msg_main("Incorrect charset file format: %.100s\n", charset); } static int is_mixedcase(char *chars) @@ -505,19 +502,11 @@ void do_incremental_crack(struct db_main *db, const char *mode) fprintf(stderr, "Using charset file supplied as option: %s\n", mode); charset = mode; } else { - log_event("! Unknown incremental mode: %s", mode); - if (john_main_process) - fprintf(stderr, "Unknown incremental mode: %s\n", - mode); - error(); + error_msg_main("Unknown incremental mode: %s\n", mode); } } else { - log_event("! No charset defined"); - if (john_main_process) - fprintf(stderr, "No charset defined for mode: %s\n", - mode); - error(); + error_msg_main("No charset defined for mode: %s\n", mode); } } @@ -531,7 +520,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) log_event("! MaxLen = %d is too large%s, reduced", max_length, options.force_maxlength ? "" : " for this hash type"); if (john_main_process && !options.force_maxlength) - fprintf(stderr, "Warning: MaxLen = %d is too large " + fprintf_color(color_warning, stderr, "Warning: MaxLen = %d is too large " "for the current hash type, reduced to %d\n", max_length, our_fmt_len); max_length = our_fmt_len; @@ -587,33 +576,20 @@ void do_incremental_crack(struct db_main *db, const char *mode) } if (min_length > max_length) { - log_event("! MinLen = %d exceeds MaxLen = %d", - min_length, max_length); - if (john_main_process) - fprintf(stderr, "MinLen = %d exceeds MaxLen = %d; " + error_msg_main("MinLen = %d exceeds MaxLen = %d; " "MaxLen can be increased up to %d\n", min_length, max_length, CHARSET_LENGTH); - error(); } if (min_length > our_fmt_len) { - log_event("! MinLen = %d is too large for this hash type", - min_length); - if (john_main_process) - fprintf(stderr, - "MinLen = %d exceeds the maximum possible " + error_msg_main("MinLen = %d exceeds the maximum possible " "length for the current hash type (%d)\n", min_length, db->format->params.plaintext_length); - error(); } if (max_length > CHARSET_LENGTH) { - log_event("! MaxLen = %d exceeds the compile-time limit of %d", - max_length, CHARSET_LENGTH); - if (john_main_process) - fprintf(stderr, "MaxLen = %d exceeds the compile-time " + error_msg_main("MaxLen = %d exceeds the compile-time " "limit of %d\n", max_length, CHARSET_LENGTH); - error(); } if (!(file = fopen(path_expand(charset), "rb"))) @@ -633,11 +609,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) if (header->min != CHARSET_MIN || header->max != CHARSET_MAX || header->length != CHARSET_LENGTH) { - log_event("! Incompatible charset file: %.100s", charset); - if (john_main_process) - fprintf(stderr, "Incompatible charset file: %s\n", - charset); - error(); + error_msg_main("Incompatible charset file: %s\n", charset); } #if CHARSET_SIZE < 0xff @@ -653,11 +625,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) if (!rec_restoring_now) rec_check = check; if (rec_check != check) { - log_event("! Charset file has changed: %.100s", charset); - if (john_main_process) - fprintf(stderr, "Charset file has changed: %s\n", - charset); - error(); + error_msg_main("Charset file has changed: %s\n", charset); } if (fread(allchars, header->count, 1, file) != 1) { @@ -672,14 +640,9 @@ void do_incremental_crack(struct db_main *db, const char *mode) if (expand(allchars, "", sizeof(allchars))) inc_format_error(charset); if (extra && expand(allchars, extra, sizeof(allchars))) { - log_event("! Extra characters not in compile-time " - "specified range ('\\x%02x' to '\\x%02x')", - CHARSET_MIN, CHARSET_MAX); - if (john_main_process) - fprintf(stderr, "Extra characters not in compile-time " + error_msg_main("Extra characters not in compile-time " "specified range ('\\x%02x' to '\\x%02x')\n", CHARSET_MIN, CHARSET_MAX); - error(); } /* Calculate the actual real_* based on sanitized and expanded allchars */ @@ -714,7 +677,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) if ((unsigned int)max_count > real_count) { log_event("! Only %u characters available", real_count); - fprintf(stderr, "Warning: only %u characters available\n", + fprintf_color(color_warning, stderr, "Warning: only %u characters available\n", real_count); } } @@ -728,7 +691,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) log_event("! Mixed-case charset, " "but the hash type is case-insensitive"); if (john_main_process) - fprintf(stderr, "Warning: mixed-case charset, " + fprintf_color(color_warning, stderr, "Warning: mixed-case charset, " "but the current hash type is case-insensitive;\n" "some candidate passwords may be unnecessarily " "tried more than once.\n"); @@ -737,7 +700,7 @@ void do_incremental_crack(struct db_main *db, const char *mode) if (!(db->format->params.flags & FMT_8_BIT) && has_8bit(allchars)) { log_event("! 8-bit charset, but the hash type is 7-bit"); if (john_main_process) - fprintf(stderr, "Warning: 8-bit charset, but the current" + fprintf_color(color_warning, stderr, "Warning: 8-bit charset, but the current" " hash type is 7-bit;\n" "some candidate passwords may be redundant.\n"); } @@ -783,11 +746,8 @@ void do_incremental_crack(struct db_main *db, const char *mode) counts[length][fixed]++; if (counts[length][fixed] != count) { - log_event("! Unexpected count: %d != %d", + error_msg_main("Unexpected count: %d != %d\n", counts[length][fixed] + 1, count + 1); - fprintf(stderr, "Unexpected count: %d != %d\n", - counts[length][fixed] + 1, count + 1); - error(); } } @@ -877,11 +837,8 @@ void do_incremental_crack(struct db_main *db, const char *mode) counts[length][fixed]++; if (counts[length][fixed] != count) { - log_event("! Unexpected count: %d != %d", - counts[length][fixed] + 1, count + 1); - fprintf(stderr, "Unexpected count: %d != %d\n", + error_msg_main("Unexpected count: %d != %d\n", counts[length][fixed] + 1, count + 1); - error(); } if (skip) diff --git a/src/john.c b/src/john.c index 6429867c3f..b9cda69ebd 100644 --- a/src/john.c +++ b/src/john.c @@ -1,7 +1,7 @@ /* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-2024 by Solar Designer - * Copyright (c) 2009-2025, magnum + * Copyright (c) 2009-2026, magnum * Copyright (c) 2021, Claudio * Copyright (c) 2009-2018, JimF * @@ -283,11 +283,11 @@ static void john_register_all(void) /* Do we have --format=LIST? If so, re-build fmt_list from it, in requested order. */ if (options.format_list && !fmt_check_custom_list()) - error_msg("Could not parse format list '%s'\n", options.format_list); + error_msg_main("Could not parse format list '%s'\n", options.format_list); if (!fmt_list) { if (john_main_process) { - fprintf(stderr, "Error: No format matched requested %s '%s'\n", fmt_type(options.format), options.format); + fprintf_color(color_error, stderr, "Error: No format matched requested %s '%s'\n", fmt_type(options.format), options.format); } error(); } @@ -432,13 +432,12 @@ static void john_omp_show_info(void) if (msg) { #if OS_FORK if (!(options.flags & (FLG_PIPE_CHK | FLG_STDIN_CHK))) - fprintf(stderr, "Warning: %s for this hash type, " + fprintf_color(color_warning, stderr, "Warning: %s for this hash type, " "consider --fork=%d\n", msg, john_omp_threads_orig); else #endif - fprintf(stderr, "Warning: %s for this hash type\n", - msg); + fprintf_color(color_warning, stderr, "Warning: %s for this hash type\n", msg); } } @@ -477,32 +476,32 @@ static void john_omp_show_info(void) "MPIOMPmutex", 1)) { if (cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIOMPverbose", 1) && mpi_id == 0) - fprintf(stderr, "MPI in use, disabling OMP " + fprintf_color(color_notice, stderr, "MPI in use, disabling OMP " "(see doc/README.mpi)\n"); omp_set_num_threads(1); john_omp_threads_orig = 0; /* Mute later warning */ } else if (john_omp_threads_orig > 1 && cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIOMPverbose", 1) && mpi_id == 0) - fprintf(stderr, "Note: Running both MPI and OMP" + fprintf_color(color_notice, stderr, "Note: Running both MPI and OMP" " (see doc/README.mpi)\n"); } else #endif if (options.fork) { #if OS_FORK if (john_omp_threads_new > 1) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Will run %d OpenMP threads per process " "(%u total across %u processes)\n", john_omp_threads_new, john_omp_threads_new * options.fork, options.fork); else if (john_omp_threads_orig > 1) - fputs("Warning: OpenMP was disabled due to --fork; " + fputs_color(color_warning, "Warning: OpenMP was disabled due to --fork; " "a non-OpenMP build may be faster\n", stderr); #endif } else { if (john_omp_threads_new > 1) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Will run %d OpenMP threads\n", john_omp_threads_new); } @@ -513,10 +512,10 @@ static void john_omp_show_info(void) const char *format = database.format ? database.format->params.label : options.format; if (format && strstr(format, "-opencl")) - fputs("Warning: OpenMP is disabled; " + fputs_color(color_warning, "Warning: OpenMP is disabled; " "GPU may be under-utilized\n", stderr); else - fputs("Warning: OpenMP is disabled; " + fputs_color(color_warning, "Warning: OpenMP is disabled; " "a non-OpenMP build may be faster\n", stderr); } } @@ -684,9 +683,7 @@ static void john_wait(void) int waiting_for = john_child_count; - log_event("Waiting for %d child%s to terminate", - waiting_for, waiting_for == 1 ? "" : "ren"); - fprintf(stderr, "Waiting for %d child%s to terminate\n", + WARN_AND_LOG(color_notice, stderr, "Waiting for %d child%s to terminate", waiting_for, waiting_for == 1 ? "" : "ren"); /* @@ -737,9 +734,7 @@ static void john_mpi_wait(void) } if (john_main_process) { - log_event("Waiting for other node%s to terminate", - mpi_p > 2 ? "s" : ""); - fprintf(stderr, "Waiting for other node%s to terminate session%s\n", + WARN_AND_LOG(color_notice, stderr, "Waiting for other node%s to terminate session%s", mpi_p > 2 ? "s" : "", john_session_name); mpi_teardown(); } @@ -805,7 +800,7 @@ static void john_load_conf(void) if (options.verbosity < 1 || options.verbosity > VERB_DEBUG) { if (john_main_process) - fprintf(stderr, "Invalid verbosity level in " + fprintf_color(color_error, stderr, "Invalid verbosity level in " "config file, use 1-%u (default %u)" " or %u for debug\n", VERB_MAX, VERB_DEFAULT, VERB_DEBUG); @@ -926,7 +921,7 @@ static void john_load_conf_db(void) if (database.format && options.target_enc != ENC_RAW && options.target_enc != ISO_8859_1 && database.format->params.flags & FMT_UNICODE && !(database.format->params.flags & FMT_ENC)) { if (john_main_process) - fprintf(stderr, "This format does not yet support" + fprintf_color(color_error, stderr, "This format does not yet support" " other encodings than ISO-8859-1\n"); error(); } @@ -940,7 +935,7 @@ static void john_load_conf_db(void) if (options.target_enc != options.input_enc && options.input_enc != UTF_8) { if (john_main_process) - fprintf(stderr, "Target encoding can only be specified" + fprintf_color(color_error, stderr, "Target encoding can only be specified" " if input encoding is UTF-8\n"); error(); } @@ -1084,13 +1079,14 @@ static void john_load(void) if (!(options.flags & FLG_LOOPBACK_CHK) && options.req_maxlength > options.length) { - fprintf(stderr, "Can't set max length larger than %u " + fprintf_color(color_error, stderr, "Can't set max length larger than %u " "for stdout format\n", options.length); error(); } if (options.verbosity <= 1) if (john_main_process) - fprintf(stderr, "Warning: Verbosity decreased to minimum, candidates will not be printed!\n"); + fprintf_color(color_warning, stderr, + "Warning: Verbosity decreased to minimum, candidates will not be printed!\n"); john_load_conf_db(); } @@ -1128,7 +1124,7 @@ static void john_load(void) database.password_count != 1 ? "es" : ""); else if (john_main_process && !options.loader.showformats) - printf("%s%d password hash%s cracked, %d left\n", + printf_color(color_notice, "%s%d password hash%s cracked, %d left\n", database.guess_count ? "\n" : "", database.guess_count, database.guess_count != 1 ? "es" : "", @@ -1183,7 +1179,7 @@ static void john_load(void) !(strstr(database.format->params.label, "-opencl") || strstr(database.format->params.label, "-ztex"))) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_error, stderr, "The \"--devices\" option is valid only for OpenCL or ZTEX formats\n"); error(); } @@ -1193,19 +1189,19 @@ static void john_load(void) if (!strstr(database.format->params.label, "-opencl")) { if (options.lws) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_error, stderr, "The \"--lws\" option is valid only for OpenCL formats\n"); error(); } if (options.gws) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_error, stderr, "The \"--gws\" option is valid only for OpenCL formats\n"); error(); } if (options.flags & (FLG_SCALAR | FLG_VECTOR)) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_error, stderr, "The \"--force-scalar\" and \"--force-vector\" options are valid only for OpenCL formats\n"); error(); } @@ -1216,13 +1212,13 @@ static void john_load(void) if (strstr(database.format->params.label, "-ztex") && options.fork) { if (ztex_detected_list->count == 1) { - fprintf(stderr, "Number of ZTEX devices must be " + fprintf_color(color_error, stderr, "Number of ZTEX devices must be " "a multiple of forks. " "With 1 device \"--fork\" is useless.\n"); error(); } if (ztex_detected_list->count % options.fork) { - fprintf(stderr, "Number of ZTEX devices must be " + fprintf_color(color_error, stderr, "Number of ZTEX devices must be " "a multiple of forks. " "Suggesting to use \"--fork=%d\".\n", ztex_detected_list->count); @@ -1239,7 +1235,7 @@ static void john_load(void) #endif fmt_init(database.format); if (john_main_process) - printf("%s (%s%s%s [%s])\n", + printf_color(color_notice, "%s (%s%s%s [%s])\n", john_loaded_counts(&database, "Loaded"), database.format->params.label, database.format->params.format_name[0] ? ", " : "", @@ -1262,7 +1258,7 @@ static void john_load(void) build_fake_salts_for_regen_lost(&database); if (john_main_process && cracked) { - printf("Cracked %d password hash%s%s%s%s, use \"--show\"\n", + printf_color(color_notice, "Cracked %d password hash%s%s%s%s, use \"--show\"\n", cracked, cracked != 1 ? "es" : "", loaded_extra_pots ? "" : (cracked != 1 ? " (are in " : " (is in "), loaded_extra_pots ? "" : path_expand(options.activepot), @@ -1272,14 +1268,13 @@ static void john_load(void) if (!database.password_count) { log_discard(); if (john_main_process) - printf("No password hashes %s (see FAQ)\n", + printf_color(color_notice, "No password hashes %s (see FAQ)\n", total ? "left to crack" : "loaded"); /* skip tunable cost reporting if no hashes were loaded */ i = FMT_TUNABLE_COSTS; } else if (john_main_process && database.password_count < total) { - log_event("%s", john_loaded_counts(&database, "Remaining")); - printf("%s\n", john_loaded_counts(&database, "Remaining")); + WARN_AND_LOG(color_notice, stdout, "%s", john_loaded_counts(&database, "Remaining")); } if (john_main_process) @@ -1350,7 +1345,7 @@ static void john_load(void) "loopback", loop_db.plaintexts->count); if (john_main_process && options.verbosity >= VERB_DEFAULT) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Reassembled %ld split passwords for " "loopback\n", loop_db.plaintexts->count); @@ -1380,7 +1375,7 @@ static void john_load(void) options.node_count, options.fork ? " (fork)" : mpi_p > 1 ? " (MPI)" : ""); #endif - fprintf(stderr, "Node numbers %u-%u of %u%s\n", + fprintf_color(color_notice, stderr, "Node numbers %u-%u of %u%s\n", options.node_min, options.node_max, #ifndef HAVE_MPI options.node_count, options.fork ? " (fork)" : ""); @@ -1391,7 +1386,7 @@ static void john_load(void) } else if (john_main_process) { log_event("- Node number %u of %u", options.node_min, options.node_count); - fprintf(stderr, "Node number %u of %u\n", + fprintf_color(color_notice, stderr, "Node number %u of %u\n", options.node_min, options.node_count); } @@ -1438,7 +1433,8 @@ static void john_load(void) } if (john_main_process) - fprintf(stderr, "%s: To fully use the %d devices %s, " + fprintf_color(dev_as_number ? color_error : color_warning, stderr, + "%s: To fully use the %d devices %s, " "you must specify --fork=%d\n" #if HAVE_MPI "or run %d MPI processes per node " @@ -1460,7 +1456,7 @@ static void john_load(void) strstr(database.format->params.label, "-opencl") && !strstr(database.format->params.label, "mscash2-opencl") && get_number_of_devices_in_use() > 1) { - fprintf(stderr, "The usage of multiple OpenCL devices at once " + fprintf_color(color_error, stderr, "The usage of multiple OpenCL devices at once " "is unsupported in this build for the selected format\n"); error(); } @@ -1624,7 +1620,7 @@ static void john_init(char *name, int argc, char **argv) if (options.internal_cp != options.input_enc && options.input_enc != UTF_8) { if (john_main_process) - fprintf(stderr, "-internal-codepage can only be " + fprintf_color(color_error, stderr, "-internal-codepage can only be " "specified if input encoding is UTF-8\n"); error(); } @@ -1724,7 +1720,7 @@ static void john_run(void) if (options.abort_file && stat(path_expand(options.abort_file), &trigger_stat) == 0) { if (john_main_process) - fprintf(stderr, "Abort file %s present, " + fprintf_color(color_error, stderr, "Abort file %s present, " "refusing to start\n", options.abort_file); error(); } @@ -1742,7 +1738,7 @@ static void john_run(void) if (!(options.flags & FLG_NOTESTS)) ldr_free_db(test_db, 1); if (where) { - fprintf(stderr, "Self test failed (%s)\n", + fprintf_color(color_error, stderr, "Self test failed (%s)\n", where); error(); } @@ -1767,7 +1763,7 @@ static void john_run(void) /* Format supports internal (eg. GPU-side) mask */ if (database.format->params.flags & FMT_MASK && !(options.flags & FLG_MASK_CHK) && john_main_process) - fprintf(stderr, "Note: This format may be a lot faster with --mask acceleration (see doc/MASK).\n"); + fprintf_color(color_notice, stderr, "Note: This format may be a lot faster with --mask acceleration (see doc/MASK).\n"); /* Some formats truncate at max. length */ if (!(database.format->params.flags & FMT_TRUNC) && @@ -1796,7 +1792,7 @@ static void john_run(void) /* Some formats have a minimum plaintext length */ if (options.eff_maxlength < options.eff_minlength) { if (john_main_process) - fprintf(stderr, "Invalid option: " + fprintf_color(color_error, stderr, "Invalid option: " "--max-length smaller than " "minimum length\n"); error(); @@ -1805,12 +1801,12 @@ static void john_run(void) if (options.req_minlength < database.format->params.plaintext_min_length) { if (john_main_process) - fprintf(stderr, "Note: --min-length set smaller than " + fprintf_color(color_notice, stderr, "Note: --min-length set smaller than " "normal minimum length for format\n"); } } else if (database.format->params.plaintext_min_length) if (john_main_process) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Note: Minimum length forced to %d " "by format\n", options.eff_minlength); @@ -1910,24 +1906,24 @@ static void john_run(void) switch (database.options->flags & (DB_SPLIT | DB_NODUP)) { case DB_SPLIT: - fprintf(stderr, "%s%s\n", might, partial); + fprintf_color(color_notice, stderr, "%s%s\n", might, partial); break; case DB_NODUP: - fprintf(stderr, "%s%s\n", might, not_all); + fprintf_color(color_notice, stderr, "%s%s\n", might, not_all); break; case (DB_SPLIT | DB_NODUP): - fprintf(stderr, "%s%s and%s\n", + fprintf_color(color_notice, stderr, "%s%s and%s\n", might, partial, not_all); } if (database.format->methods.prepare != fmt_default_prepare) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Use the \"--show --format=%s\" options" " to display all of the cracked " "passwords reliably\n", database.format->params.label); else - fputs("Use the \"--show\" option to display all" + fputs_color(color_notice, "Use the \"--show\" option to display all" " of the cracked passwords reliably\n", stderr); } @@ -1948,7 +1944,7 @@ static void john_done(void) log_event("Warning: Incremental mask started at length %d", mask_iter_warn); if (john_main_process) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Warning: incremental mask started at length %d" " - try the CPU format for shorter lengths.\n", mask_iter_warn); @@ -1957,7 +1953,7 @@ static void john_done(void) event_abort = 0; log_event("Done catching up with '%s'", options.catchup); if (john_main_process) - fprintf(stderr, "Done catching up with '%s'\n", options.catchup); + fprintf_color(color_notice, stderr, "Done catching up with '%s'\n", options.catchup); } if (event_abort) { char *abort_msg = (aborted_by_timer) ? @@ -1978,7 +1974,7 @@ static void john_done(void) fprintf(stderr, "Session%s completed\n", john_session_name); } else { log_event("Main process session completed, but some child processes failed"); - fprintf(stderr, "Main process session%s completed, but some child processes failed\n", john_session_name); + fprintf_color(color_error, stderr, "Main process session%s completed, but some child processes failed\n", john_session_name); exit_status = 1; } fmt_done(database.format); @@ -2142,7 +2138,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) // size is actuall static uint8_t buffer[8192]; if (size > sizeof(buffer) - 1) { - fprintf(stderr, "size (-max_len) is greater than supported value, aborting!\n"); + fprintf_color(color_error, stderr, "size (-max_len) is greater than supported value, aborting!\n"); exit(-1); } memcpy(buffer, data, size); diff --git a/src/keepass_common.h b/src/keepass_common.h index fc9838945b..d7593711af 100644 --- a/src/keepass_common.h +++ b/src/keepass_common.h @@ -135,24 +135,18 @@ static int keepass_valid(char *ciphertext, struct fmt_main *self) goto err; #if !KEEPASS_ARGON2 if (!strcmp(p, "ef636ddf") || !strcmp(p, "9e298b19")) { - static int warned; - - if (!ldr_in_pot && john_main_process && !warned) { - fprintf(stderr, "%s: Argon2 hash(es) not supported, skipping.\n", + if (!ldr_in_pot && john_main_process) { + WARN_ONCE(color_warning, stderr, "%s: Argon2 hash(es) not supported, skipping.\n", self->params.label); - warned = 1; } goto err; } #endif #if !KEEPASS_AES if (!strcmp(p, "c9d9f39a")) { - static int warned; - - if (!ldr_in_pot && john_main_process && !warned) { - fprintf(stderr, "%s: AES hash(es) not supported, skipping.\n", + if (!ldr_in_pot && john_main_process) { + WARN_ONCE(color_warning, stderr, "%s: AES hash(es) not supported, skipping.\n", self->params.label); - warned = 1; } goto err; } @@ -202,7 +196,7 @@ static int keepass_valid(char *ciphertext, struct fmt_main *self) static int warned; if (!ldr_in_pot && john_main_process && warned < content_size) { - fprintf(stderr, + fprintf_color(color_warning, stderr, "%s: Input rejected due to larger size than compile-time limit.\n" "Bump KEEPASS_MAX_CONTENT_SIZE in keepass_common.h to >= 0x%x, and rebuild\n", self->params.label, content_size); @@ -244,7 +238,7 @@ static int keepass_valid(char *ciphertext, struct fmt_main *self) static int warned; if (!ldr_in_pot && john_main_process && warned < content_size) { - fprintf(stderr, + fprintf_color(color_warning, stderr, "%s: Input rejected due to larger size than compile-time limit.\n" "Bump KEEPASS_MAX_CONTENT_SIZE in keepass_common.h to >= 0x%x, and rebuild\n", self->params.label, content_size); @@ -419,7 +413,7 @@ static void *keepass_get_salt(char *ciphertext) p = strtokm(NULL, "*"); int keyfilesize = atoi(p); if (keyfilesize != 64) - fprintf(stderr, "Warning: keepass possible bug indication %s:%d size %d\n", + fprintf_color(color_warning, stderr, "Warning: keepass possible bug indication %s:%d size %d\n", __FILE__, __LINE__, keyfilesize); p = strtokm(NULL, "*"); for (i = 0; i < keyfilesize / 2; i++) diff --git a/src/keepass_fmt_plug.c b/src/keepass_fmt_plug.c index 6863f0552d..8ba3191227 100644 --- a/src/keepass_fmt_plug.c +++ b/src/keepass_fmt_plug.c @@ -116,11 +116,11 @@ static void done(void) static int allocate(uint8_t **memory, size_t size) { if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) { - fprintf(stderr, "Error: KeePass: Thread number %d out of range\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: KeePass: Thread number %d out of range\n", THREAD_NUMBER); goto fail; } if (thread_mem[THREAD_NUMBER].used) { - fprintf(stderr, "Error: KeePass: Thread %d: Memory allocated twice\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: KeePass: Thread %d: Memory allocated twice\n", THREAD_NUMBER); goto fail; } @@ -143,15 +143,15 @@ static int allocate(uint8_t **memory, size_t size) static void deallocate(uint8_t *memory, size_t size) { if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) { - fprintf(stderr, "Error: KeePass: Thread number %d out of range\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: KeePass: Thread number %d out of range\n", THREAD_NUMBER); return; } if (!thread_mem[THREAD_NUMBER].used) - fprintf(stderr, "Error: KeePass: Thread %d: Freed memory not in use\n", THREAD_NUMBER); + fprintf_color(color_error, stderr, "Error: KeePass: Thread %d: Freed memory not in use\n", THREAD_NUMBER); if (thread_mem[THREAD_NUMBER].region.aligned_size < size) - fprintf(stderr, "Error: KeePass: Thread %d: Freeing incorrect size %zu, was %zu\n", + fprintf_color(color_error, stderr, "Error: KeePass: Thread %d: Freeing incorrect size %zu, was %zu\n", THREAD_NUMBER, size, thread_mem[THREAD_NUMBER].region.aligned_size); thread_mem[THREAD_NUMBER].used = 0; @@ -243,7 +243,7 @@ static int transform_key(char *masterkey, unsigned char *final_key) error_code = argon2_ctx(&context, cur_salt->type); if (error_code != ARGON2_OK) { ret = -1; - fprintf(stderr, "Error: Keepass: Argon2 failed: %s\n", + fprintf_color(color_error, stderr, "Error: Keepass: Argon2 failed: %s\n", argon2_error_message(error_code)); } } @@ -420,7 +420,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) } if (failed) { #ifdef _OPENMP - fprintf(stderr, "Error: Keepass: Argon2 or alloc_region failed in some threads\n"); + fprintf_color(color_error, stderr, "Error: Keepass: Argon2 or alloc_region failed in some threads\n"); #endif error(); } diff --git a/src/keplr_fmt_plug.c b/src/keplr_fmt_plug.c index 4ec971cc8c..a5a573be81 100644 --- a/src/keplr_fmt_plug.c +++ b/src/keplr_fmt_plug.c @@ -254,11 +254,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); + fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed)); error(); } diff --git a/src/krb5pa-sha1_fmt_plug.c b/src/krb5pa-sha1_fmt_plug.c index 83171fa1be..2c5ab89352 100644 --- a/src/krb5pa-sha1_fmt_plug.c +++ b/src/krb5pa-sha1_fmt_plug.c @@ -199,11 +199,8 @@ static int valid(char *ciphertext, struct fmt_main *self) // We support a max. total salt length of 52. // We could opt to emit a warning if rejected here. if (saltlen > MAX_SALTLEN) { - static int warned = 0; - if (!ldr_in_pot) - if (!warned++) - fprintf(stderr, "%s: One or more hashes rejected due to salt length limitation\n", FORMAT_LABEL); + WARN_ONCE(color_warning, stderr, "%s: One or more hashes rejected due to salt length limitation\n", FORMAT_LABEL); return 0; } diff --git a/src/loader.c b/src/loader.c index b62db9891e..1cc05507be 100644 --- a/src/loader.c +++ b/src/loader.c @@ -1,7 +1,7 @@ /* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-2000,2003,2005,2010-2012,2015 by Solar Designer - * Copyright (c) 2012-2025, magnum + * Copyright (c) 2012-2026, magnum * Copyright (c) 2009-2018, JimF */ #if AC_BUILT @@ -113,20 +113,17 @@ static MAYBE_INLINE char *check_bom(char *string) return string; if (!memcmp(string, "\xEF\xBB\xBF", 3)) { - static int warned; - if (options.input_enc == UTF_8) string += 3; - else if (john_main_process && !warned++) - fprintf(stderr, + else if (john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: UTF-8 BOM seen in password hash file. You probably want --input-encoding=UTF8\n"); } if (options.input_enc == UTF_8 && (!memcmp(string, "\xFE\xFF", 2) || !memcmp(string, "\xFF\xFE", 2))) { - static int warned; - - if (john_main_process && !warned++) - fprintf(stderr, "Warning: UTF-16 BOM seen in password hash file. " - "File may not be read properly unless you re-encode it\n"); + if (john_main_process) + WARN_ONCE(color_warning, stderr, + "Warning: UTF-16 BOM seen in password hash file. " + "File may not be read properly unless you re-encode it\n"); } return string; } @@ -212,7 +209,7 @@ static void read_file(struct db_main *db, char *name, int flags, char line_buf[LINE_BUFFER_SIZE], *line, *ex_size_line; int warn_enc; - warn_enc = (john_main_process && (options.target_enc != ENC_RAW) && + warn_enc = (!ldr_in_pot && john_main_process && (options.target_enc != ENC_RAW) && cfg_get_bool(SECTION_OPTIONS, NULL, "WarnEncoding", 0)); if (stat(path_expand(name), &file_stat)) { @@ -225,9 +222,7 @@ static void read_file(struct db_main *db, char *name, int flags, return; if (ldr_in_pot && S_ISFIFO(file_stat.st_mode)) { - if (john_main_process) - fprintf(stderr, "Error, cannot use FIFO as pot file: %s\n", path_expand(name)); - error(); + error_msg_main("Error: Cannot use FIFO as pot file: %s\n", path_expand(name)); } if (!(file = fopen(path_expand(name), "r"))) { @@ -254,13 +249,17 @@ static void read_file(struct db_main *db, char *name, int flags, options.input_enc == UTF_8)) { if (!valid_utf8((UTF8*)u8check)) { warn_enc = 0; - fprintf(stderr, "Warning: invalid UTF-8 seen reading %s\n", path_expand(name)); + fprintf_color(color_warning, stderr, + "Warning: Invalid UTF-8 seen reading %s\n", + path_expand(name)); } } else if (options.input_enc != UTF_8 && (line != line_buf || valid_utf8((UTF8*)u8check) > 1)) { warn_enc = 0; - fprintf(stderr, "Warning: UTF-8 seen reading %s\n", path_expand(name)); + fprintf_color(color_warning, stderr, + "Warning: UTF-8 seen reading %s\n", + path_expand(name)); } } process_line(db, line); @@ -386,9 +385,7 @@ static int wild_cmp(const char *search_str, const char *full_str) if (pos) { if (pos != strrchr(search_str, '*')) { - if (john_main_process) - fprintf(stderr, "Only one wildcard allowed in name\n"); - error(); + error_msg_main("Only one wildcard allowed in name\n"); } /* Check string before wildcard, if any */ @@ -714,7 +711,7 @@ static int ldr_split_line(char **login, char **ciphertext, alt->params.flags |= FMT_WARNED; if (john_main_process) fprintf(stderr, - "Warning: only loading hashes of type " + "Warning: Only loading hashes of type " "\"%s\", but also saw type \"%s\"\n" "Use the \"--format=%s\" option to force " "loading hashes of that type instead\n", @@ -778,7 +775,7 @@ static int ldr_split_line(char **login, char **ciphertext, #ifdef LDR_WARN_AMBIGUOUS if (john_main_process) fprintf(stderr, - "Warning: detected hash type \"%s\", but the string is " + "Warning: Detected hash type \"%s\", but the string is " "also recognized as \"%s\"\n" "Use the \"--format=%s\" option to force loading these " "as that type instead\n", @@ -1012,18 +1009,13 @@ static void ldr_load_pw_line(struct db_main *db, char *line) if (john_main_process) { if (format->params.binary_size) - fprintf(stderr, "Warning: " - "excessive partial hash " - "collisions detected\n%s", - db->password_hash_func != - fmt_default_binary_hash ? "" : - "(cause: the \"format\" lacks " - "proper binary_hash() function " - "definitions)\n"); + fprintf_color(color_warning, stderr, + "Warning: Excessive partial hash collisions detected\n%s", + db->password_hash_func != fmt_default_binary_hash ? "" : + "(cause: the \"format\" lacks proper binary_hash() function definitions)\n"); else - fprintf(stderr, "Warning: " - "check for duplicates partially " - "bypassed to speedup loading\n"); + fprintf_color(color_warning, stderr, + "Warning: Check for duplicates partially bypassed to speedup loading\n"); } dupe_checking = 0; current_pw = NULL; /* no match */ @@ -1887,9 +1879,7 @@ static void ldr_fill_user_words(struct db_main *db) pexit(STR_MACRO(jtr_ftell64)); jtr_fseek64(file, 0, SEEK_SET); if (file_len < 3) { - if (john_main_process) - fprintf(stderr, "Error, per-user seed file is empty\n"); - error(); + error_msg_main("Error: Per-user seed file is empty\n"); } #ifdef HAVE_MMAP diff --git a/src/logger.h b/src/logger.h index 0bb8001bac..652b22ad69 100644 --- a/src/logger.h +++ b/src/logger.h @@ -50,6 +50,43 @@ extern int log_lock(int fd, int cmd, int type, const char *name, #endif /* #if defined(F_SETLK) && defined(F_SETLKW) && defined(F_UNLCK) && defined(F_RDLCK) && defined(F_WRLCK) */ +/* + * Macro for warning/notice AND logging. Arguments are like to fprintf_color + * but with no ending linefeed (will be added here to screen but not to log). + */ +#define WARN_AND_LOG(color, stream, ...) \ + do { \ + fprintf_color(color, stream, __VA_ARGS__); \ + fputc('\n', stream); \ + if (stream == stdout) \ + fflush(stdout); \ + log_event(__VA_ARGS__); \ + } while (0) + +/* + * Macro to only log something once per session. + */ +#define LOG_ONCE(...) \ + do { \ + static int warned; \ + if (!warned) { \ + log_event(__VA_ARGS__); \ + warned = 1; \ + } \ + } while (0) + +/* + * Like WARN_AND_LOG, but once per session. + */ +#define WARN_AND_LOG_ONCE(color, stream, ...) \ + do { \ + static int warned; \ + if (!warned) { \ + WARN_AND_LOG(color, stream, __VA_ARGS__); \ + warned = 1; \ + } \ + } while (0) + /* * Initializes the logger (opens john.pot and a log file). */ diff --git a/src/luks_fmt_plug.c b/src/luks_fmt_plug.c index 9f8d3e979c..de8abb724b 100644 --- a/src/luks_fmt_plug.c +++ b/src/luks_fmt_plug.c @@ -273,8 +273,6 @@ static uint32_t (*crypt_out)[BINARY_SIZE / sizeof(uint32_t)]; static void init(struct fmt_main *self) { - static int warned = 0; - omp_autotune(self, OMP_SCALE); saved_key = mem_calloc(sizeof(*saved_key), self->params.max_keys_per_crypt); @@ -293,12 +291,10 @@ static void init(struct fmt_main *self) * to re-run luks2john and retry the passwords that have been stored for the current LUKS hashes * once the redesign of john's LUKS format implementation has been completed.) */ - if (!options.listconf && !(options.flags & FLG_TEST_CHK) && !warned) { - warned = 1; - fprintf(stderr, + if (!options.listconf && !(options.flags & FLG_TEST_CHK)) { + WARN_ONCE(color_warning, stderr, "WARNING, LUKS format hash representation will change in future releases,\n" "see doc/README.LUKS\n"); // FIXME: address github issue #557 after 1.8.0-jumbo-1 - fflush(stderr); } // This printf will 'help' debug a system that truncates that monster hash, but does not cause compiler to die. diff --git a/src/mask.c b/src/mask.c index 951e815374..067652705c 100644 --- a/src/mask.c +++ b/src/mask.c @@ -1,6 +1,6 @@ /* * This file is part of John the Ripper password cracker, - * Copyright (c) 2013-2018 by magnum + * Copyright (c) 2013-2026 by magnum * Copyright (c) 2014 by Sayantan Datta * * Redistribution and use in source and binary forms, with or without @@ -97,7 +97,6 @@ uint64_t mask_parent_keys; */ static char* parse_hex(char *string) { - static int warned; unsigned char *s = (unsigned char*)string; unsigned char *d = s; @@ -111,8 +110,8 @@ static char* parse_hex(char *string) } else if (*s == '\\' && s[1] == 'x' && atoi16[s[2]] != 0x7f && atoi16[s[3]] != 0x7f) { char c = (atoi16[s[2]] << 4) + atoi16[s[3]]; - if (!c && !warned++ && john_main_process) - fprintf(stderr, "Warning: \\x00 in mask terminates the string\n"); + if (!c && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: \\x00 in mask terminates the string\n"); if (strchr("\\[]?-", c)) *d++ = '\\'; *d++ = c; @@ -159,7 +158,7 @@ static char* expand_cplhdr(char *string, int *conv_err) if (conv_err[pidx]) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_error, stderr, "Error: Selected internal codepage can't hold all chars of mask placeholder ?%d\n", pidx + 1); error(); @@ -2341,14 +2340,14 @@ void mask_init(struct db_main *db, char *unprocessed_mask) mask_int_cand.int_cpu_mask_ctx->ranges[mask_max_skip_loc].pos + 1; if (inc_min > options.eff_maxlength) { if (john_main_process) - fprintf(stderr, "Error: %s cannot use internal mask under these premises,\n" + fprintf_color(color_error, stderr, "Error: %s cannot use internal mask under these premises,\n" "try using --mask-internal-target=0 option.\n", mask_fmt->params.label); error(); } if (options.eff_minlength < inc_min) { mask_iter_warn = inc_min; if (john_main_process) - fprintf(stderr, "Note: %s format can't currently increment length from %d, using %d instead\n", + fprintf_color(color_warning, stderr, "Note: %s format can't currently increment length from %d, using %d instead\n", mask_fmt->params.label, options.eff_minlength, inc_min); options.eff_minlength = inc_min; } @@ -2425,7 +2424,7 @@ static void finalize_mask(int len) } } else { if (mask_num_qw && john_main_process) - fprintf(stderr, "Warning: ?w has no special meaning unless running hybrid mask\n"); + fprintf_color(color_warning, stderr, "Warning: ?w has no special meaning unless running hybrid mask\n"); if (mask_add_len > len) mask_add_len = len; } @@ -2435,13 +2434,13 @@ static void finalize_mask(int len) mask_fmt->params.flags &= ~FMT_MASK; format_cannot_reset = 0; if (john_main_process) { - fprintf(stderr, "Note: Disabling internal mask due to stacked rules\n"); - log_event("- Disabling internal mask due to stacked rules"); + WARN_ONCE(color_notice, stderr, "Note: Disabling internal mask due to stacked rules\n"); + LOG_ONCE("- Disabling internal mask due to stacked rules"); } } #if defined(HAVE_OPENCL) || defined(HAVE_ZTEX) else if ((mask_fmt->params.flags & FMT_MASK) && options.req_int_cand_target > 0) { - log_event("- Overriding format's target internal mask factor of %d with user requested %d", + LOG_ONCE("- Overriding format's target internal mask factor of %d with user requested %d", mask_int_cand_target, options.req_int_cand_target); mask_int_cand_target = options.req_int_cand_target; } @@ -2464,9 +2463,7 @@ static void finalize_mask(int len) options.eff_minlength, options.eff_maxlength, mask_num_qw, mask_add_len, options.eff_maxlength * mask_num_qw + mask_add_len); #endif if (options.eff_maxlength == 0) { - if (john_main_process) - fprintf(stderr, "Error: Hybrid mask would truncate input to length 0!\n"); - error(); + error_msg_main("Error: Hybrid mask would truncate input to length 0!\n"); } } @@ -2514,9 +2511,14 @@ static void finalize_mask(int len) mask_tot_cand = cand * mask_int_cand.num_int_cand; if ((john_main_process || !cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIAllGPUsSame", 0)) && - mask_int_cand.num_int_cand > 1) - log_event("- Requested internal mask factor: %d, actual now %d", - mask_int_cand_target, mask_int_cand.num_int_cand); + mask_int_cand.num_int_cand > 1) { + static int old_factor = -1; + if (mask_int_cand.num_int_cand != old_factor) { + log_event("- Requested internal mask factor: %d, actual now %d", + mask_int_cand_target, mask_int_cand.num_int_cand); + old_factor = mask_int_cand.num_int_cand; + } + } } void mask_crk_init(struct db_main *db) @@ -2633,6 +2635,7 @@ int do_mask_crack(const char *extern_key) } mask_cur_len = i; + log_event("- Mask length now %u", mask_cur_len); if (format_cannot_reset) save_restore(&cpu_mask_ctx, 0, RESTORE); diff --git a/src/misc.c b/src/misc.c index 1ba53919b6..ee84a43cff 100644 --- a/src/misc.c +++ b/src/misc.c @@ -32,6 +32,7 @@ #include "logger.h" #include "params.h" #include "misc.h" +#include "color.h" #include "options.h" #include "john_mpi.h" @@ -40,8 +41,9 @@ void real_error(const char *file, int line) { #ifndef _JOHN_MISC_NO_LOG - log_event("Terminating on error, %s:%d", file, line); + log_event("! Terminating on error, %s:%d", file, line); log_done(); + fputs(color_end, stderr); #else fprintf(stderr, "Terminating on error, %s:%d\n", file, line); #endif @@ -49,17 +51,20 @@ void real_error(const char *file, int line) exit(1); } -void real_error_msg(const char *file, int line, const char *format, ...) +void real_error_msg(const char *file, int line, const char *format, ...) { va_list args; -#if defined(HAVE_MPI) && !defined(_JOHN_MISC_NO_LOG) +#if !defined(_JOHN_MISC_NO_LOG) + fputs(color_error, stderr); +#ifdef HAVE_MPI if (mpi_p > 1) fprintf(stderr, "%u@%s: ", mpi_id + 1, mpi_name); else -#elif OS_FORK && !defined(_JOHN_MISC_NO_LOG) +#elif OS_FORK if (options.fork) fprintf(stderr, "%u: ", options.node_min); +#endif #endif va_start(args, format); vfprintf(stderr, format, args); @@ -73,6 +78,7 @@ void real_pexit(const char *file, int line, const char *format, ...) va_list args; #if !defined(_JOHN_MISC_NO_LOG) + fputs(color_error, stderr); #if HAVE_MPI if (mpi_p > 1) fprintf(stderr, "%u@%s: ", mpi_id + 1, mpi_name); diff --git a/src/misc.h b/src/misc.h index f27b1f561a..7f07ce4c51 100644 --- a/src/misc.h +++ b/src/misc.h @@ -18,7 +18,9 @@ #define _JOHN_MISC_H #include + #include "jumbo.h" +#include "color.h" #if !AC_BUILT #include @@ -62,7 +64,15 @@ extern void real_error_msg(const char *file, int line, const char *format, ...) ; #endif -#define error_msg(...) real_error_msg(__FILE__, __LINE__, __VA_ARGS__) +#define error_msg(...) real_error_msg(__FILE__, __LINE__, __VA_ARGS__) + +#define error_msg_main(...) \ + do { \ + if (john_main_process) \ + real_error_msg(__FILE__, __LINE__, __VA_ARGS__); \ + else \ + real_error(__FILE__, __LINE__); \ + } while(0) /* * Similar to perror(), but supports formatted output, and calls error(). diff --git a/src/mkv.c b/src/mkv.c index 0ab6b9425e..40b4914d64 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -391,11 +391,8 @@ void get_markov_options(struct db_main *db, dummy_token = strtokm(NULL, ":"); if (dummy_token) { - if (john_main_process) - fprintf(stderr, - "Too many markov parameters specified:" - " %s\n", dummy_token); - error(); + error_msg_main("Error: Too many markov parameters specified: %s\n", + dummy_token); } } @@ -403,10 +400,7 @@ void get_markov_options(struct db_main *db, mode = SUBSECTION_DEFAULT; if (cfg_get_section(SECTION_MARKOV, mode) == NULL) { - if (john_main_process) - fprintf(stderr, - "Section [" SECTION_MARKOV "%s] not found\n", mode); - error(); + error_msg_main("Error: Section [" SECTION_MARKOV "%s] not found\n", mode); } if (options.mkv_stats == NULL) @@ -415,12 +409,7 @@ void get_markov_options(struct db_main *db, *statfile = options.mkv_stats; if (*statfile == NULL) { - log_event("Statsfile not defined"); - if (john_main_process) - fprintf(stderr, - "Statsfile not defined in section [" - SECTION_MARKOV "%s]\n", mode); - error(); + error_msg_main("Error: Statsfile not defined in section [" SECTION_MARKOV "%s]\n", mode); } /* treat 'empty' level token same as NULL, i.e. pull in from config */ if (NULL != lvl_token && !strlen(lvl_token)) @@ -428,9 +417,7 @@ void get_markov_options(struct db_main *db, if (lvl_token != NULL) { if (sscanf(lvl_token, "%d-%d", &minlevel, &level) != 2) { if (sscanf(lvl_token, "%d", &level) != 1) { - if (john_main_process) - fprintf(stderr, "Could not parse markov" " level\n"); - error(); + error_msg_main("Error: Could not parse markov level\n"); } if (level == 0) /* get min. and max. level from markov section */ @@ -452,19 +439,14 @@ void get_markov_options(struct db_main *db, if (level <= 0) if ((level = cfg_get_int(SECTION_MARKOV, mode, "MkvLvl")) == -1) { - log_event("no markov level defined!"); - if (john_main_process) - fprintf(stderr, - "no markov level defined in section [" - SECTION_MARKOV "%s]\n", mode); - error(); + error_msg_main("Error: No markov level defined in section [" SECTION_MARKOV "%s]\n", mode); } if (level > MAX_MKV_LVL) { - log_event("! Level = %d is too large (max=%d)", level, MAX_MKV_LVL); if (john_main_process) - fprintf(stderr, "Warning: Level = %d is too large " - "(max = %d)\n", level, MAX_MKV_LVL); + WARN_AND_LOG(color_warning, stderr, + "Warning: Level = %d is too large (max = %d)", + level, MAX_MKV_LVL); level = MAX_MKV_LVL; } @@ -474,7 +456,7 @@ void get_markov_options(struct db_main *db, if (level < minlevel) { if (john_main_process) - fprintf(stderr, "Warning: max level(%d) < min level(%d)" + fprintf_color(color_warning, stderr, "Warning: max level(%d) < min level(%d)" ", min level set to %d\n", level, minlevel, level); minlevel = level; } @@ -491,12 +473,7 @@ void get_markov_options(struct db_main *db, if (maxlen <= 0) { if ((maxlen = cfg_get_int(SECTION_MARKOV, mode, "MkvMaxLen")) == -1) { - log_event("no markov max length defined!"); - if (john_main_process) - fprintf(stderr, - "no markov max length defined in " - "section [" SECTION_MARKOV "%s]\n", mode); - error(); + error_msg_main("Error: No markov max length defined in section [" SECTION_MARKOV "%s]\n", mode); } else { maxlen -= mask_add_len; if (mask_num_qw > 1) @@ -505,17 +482,16 @@ void get_markov_options(struct db_main *db, } if (our_fmt_len <= MAX_MKV_LEN && maxlen > our_fmt_len) { - log_event("! MaxLen = %d is too large for this hash type", maxlen); if (john_main_process) - fprintf(stderr, "Warning: " - "MaxLen = %d is too large for the current hash" - " type, reduced to %d\n", maxlen, our_fmt_len); + WARN_AND_LOG(color_warning, stderr, "Warning: " + "MaxLen = %d is too large for the current hash" + " type, reduced to %d", maxlen, our_fmt_len); maxlen = our_fmt_len; } else if (maxlen > MAX_MKV_LEN) { - log_event("! MaxLen = %d is too large (max=%d)", maxlen, MAX_MKV_LEN); if (john_main_process) - fprintf(stderr, "Warning: Maxlen = %d is too large (max" - " = %d)\n", maxlen, MAX_MKV_LEN); + WARN_AND_LOG(color_warning, stderr, + "Warning: Maxlen = %d is too large (max = %d)", + maxlen, MAX_MKV_LEN); maxlen = MAX_MKV_LEN; } @@ -531,7 +507,7 @@ void get_markov_options(struct db_main *db, if (minlen > maxlen) { if (john_main_process) - fprintf(stderr, "Warning: minimum length(%d) > maximum" + fprintf_color(color_warning, stderr, "Warning: minimum length(%d) > maximum" " length(%d), minimum length set to %d\n", minlen, maxlen, maxlen); minlen = maxlen; @@ -568,9 +544,7 @@ void get_markov_start_end(char *start_token, char *end_token, } /* NOTE, end_token can be an empty string. Treat "" and mkv_max as equal */ else if (end_token != NULL && *end_token) { - if (john_main_process) - fprintf(stderr, "invalid end: %s\n", end_token); - error(); + error_msg_main("Error: Invalid end: %s\n", end_token); } } /* @@ -584,26 +558,20 @@ void get_markov_start_end(char *start_token, char *end_token, */ /* NOTE, start_token can be an empty string. Treat "" and "0" equal */ else if (start_token != NULL && *start_token) { - if (john_main_process) - fprintf(stderr, "invalid start: %s\n", start_token); - error(); + error_msg_main("Error: Invalid start: %s\n", start_token); } if (start_token != NULL && strlen(start_token) && start_token[strlen(start_token) - 1] == '%') { if (*mkv_start >= 100) { - log_event("! Start = %s is too large (max < 100%%)", end_token); - if (john_main_process) - fprintf(stderr, "Error: Start = %s is too large" - " (max < 100%%)\n", start_token); - exit(1); + error_msg_main("Error: Start = %s is too large (max < 100%%)\n", + start_token); } else if (*mkv_start > 0) { *mkv_start *= mkv_max / 100; - log_event("- Start: %s converted to %" PRId64, start_token, - *mkv_start); if (john_main_process) - fprintf(stderr, "Start: %s converted to %" PRId64 - "\n", start_token, *mkv_start); + WARN_AND_LOG(color_notice, stderr, + "Start: %s converted to %" PRId64, + start_token, *mkv_start); } } if (end_token != NULL && strlen(end_token) && @@ -611,37 +579,32 @@ void get_markov_start_end(char *start_token, char *end_token, if (*mkv_end >= 100) { if (*mkv_end > 100) { if (john_main_process) - fprintf(stderr, "Warning: End = %s is " + fprintf_color(color_warning, stderr, "Warning: End = %s is " "too large (max = 100%%)\n", end_token); } *mkv_end = 0; } else if (*mkv_end > 0) { *mkv_end *= mkv_max / 100; - log_event("- End: %s converted to %" PRId64 "", end_token, *mkv_end); if (john_main_process) - fprintf(stderr, "End: %s converted to %" PRId64 - "\n", end_token, *mkv_end); + WARN_AND_LOG(color_notice, stderr, + "End: %s converted to %" PRId64, + end_token, *mkv_end); } } if (*mkv_end == 0) *mkv_end = mkv_max; if (*mkv_end > mkv_max) { - log_event("! End = %" PRId64 " is too large (max=%" PRId64 ")", *mkv_end, - mkv_max); if (john_main_process) - fprintf(stderr, "Warning: End = %" PRId64 " is too large " - "(max = %" PRId64 ")\n", *mkv_end, mkv_max); + WARN_AND_LOG(color_warning, stderr, + "Warning: End = %" PRId64 " is too large (max = %" PRId64 ")", + *mkv_end, mkv_max); *mkv_end = mkv_max; } if (*mkv_start > *mkv_end) { - log_event("! MKV start > end (%" PRId64 " > %" PRId64 ")", *mkv_start, - *mkv_end); - if (john_main_process) - fprintf(stderr, "Error: MKV start > end (%" PRId64 " > %" PRId64 - ")\n", *mkv_start, *mkv_end); - error(); + error_msg_main("Error: MKV start > end (%" PRId64 " > %" PRId64 ")\n", + *mkv_start, *mkv_end); } } diff --git a/src/monero_fmt_plug.c b/src/monero_fmt_plug.c index d453102569..cc1dcbad20 100644 --- a/src/monero_fmt_plug.c +++ b/src/monero_fmt_plug.c @@ -273,11 +273,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "Memory allocation failed\n"); + fprintf_color(color_error, stderr, "Memory allocation failed\n"); error(); } diff --git a/src/mscash_common_plug.c b/src/mscash_common_plug.c index e88670fbbf..227466fd5c 100644 --- a/src/mscash_common_plug.c +++ b/src/mscash_common_plug.c @@ -19,7 +19,7 @@ #include "unicode.h" #include "johnswap.h" #include "mscash_common.h" - +#include "john.h" /************************************** * Common stuff for mscash(1) hashes @@ -101,22 +101,17 @@ int mscash1_common_valid(char *ciphertext, struct fmt_main *self) // This is tricky: Max supported salt length is 19 characters of Unicode saltlen = enc_to_utf16(realsalt, MSCASH1_MAX_SALT_LENGTH+1, (UTF8*)strnzcpy(insalt, &ciphertext[FORMAT_TAG_LEN], l - FORMAT_TAG_LEN), l - 3); if (saltlen < 0) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } if (saltlen > MSCASH1_MAX_SALT_LENGTH) { - static int warned = 0; - - if (!ldr_in_pot) - if (!warned++) - fprintf(stderr, "%s: One or more hashes rejected due to salt length limitation\n", self->params.label); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: One or more hashes rejected due to salt length limitation\n", self->params.label); return 0; } return 1; @@ -330,22 +325,17 @@ int mscash2_common_valid(char *ciphertext, int max_salt_length, struct fmt_main ++i; saltlen = enc_to_utf16(realsalt, max_salt_length, (UTF8*)strnzcpy(insalt, &ciphertext[i], l-i), l-(i+1)); if (saltlen < 0) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } if (saltlen > max_salt_length) { - static int warned = 0; - - if (!ldr_in_pot) - if (!warned++) - fprintf(stderr, "%s: One or more hashes rejected due to salt length limitation\n", self->params.label); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: One or more hashes rejected due to salt length limitation\n", self->params.label); return 0; } diff --git a/src/multibit_fmt_plug.c b/src/multibit_fmt_plug.c index 359465910d..7567358189 100644 --- a/src/multibit_fmt_plug.c +++ b/src/multibit_fmt_plug.c @@ -437,11 +437,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); + fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed)); error(); } diff --git a/src/ntlmv1_mschapv2_fmt_plug.c b/src/ntlmv1_mschapv2_fmt_plug.c index cb1c10e8c6..aad62eb849 100644 --- a/src/ntlmv1_mschapv2_fmt_plug.c +++ b/src/ntlmv1_mschapv2_fmt_plug.c @@ -1074,16 +1074,14 @@ static char *get_key(int index) static void *get_binary(char *ciphertext) { static uchar *binary; - static int warned = 0, loaded = 0; + static int loaded = 0; DES_cblock *challenge = my->methods.salt(ciphertext); int i, j; if (!binary) binary = mem_alloc_tiny(FULL_BINARY_SIZE, BINARY_ALIGN); - if (john_main_process) - if (!warned && !ldr_in_pot && !bench_or_test_running && ++loaded > 100) { - warned = 1; - fprintf(stderr, "%s: Note: slow loading. For short runs, try " + if (john_main_process && !ldr_in_pot && !bench_or_test_running && ++loaded > 100) { + WARN_ONCE(color_warning, stderr, "%s: Note: slow loading. For short runs, try " "--format=%s-naive\ninstead. That version loads " "faster but runs slower.\n", my->params.label, my->params.label); diff --git a/src/o10glogon_fmt_plug.c b/src/o10glogon_fmt_plug.c index ee8d0dedfc..e1c5cb0e60 100644 --- a/src/o10glogon_fmt_plug.c +++ b/src/o10glogon_fmt_plug.c @@ -43,6 +43,7 @@ john_register_one(&fmt_o10glogon); #include "md5.h" #include "unicode.h" #include "base64_convert.h" +#include "john.h" #define FORMAT_LABEL "o10glogon" #define FORMAT_NAME "Oracle 10g-logon protocol" @@ -142,14 +143,12 @@ static int valid(char *ciphertext, struct fmt_main *self) tmp[cp-ciphertext] = 0; len = enc_to_utf16((UTF16 *)cur_key_mixedcase, MAX_USERNAME_LEN+1, (unsigned char*)tmp, strlen(tmp)); if (len < 0 || (len == 0 && cp-ciphertext)) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } if (len > MAX_USERNAME_LEN) diff --git a/src/o3logon_fmt_plug.c b/src/o3logon_fmt_plug.c index b7e34b258e..591e2bb7b1 100644 --- a/src/o3logon_fmt_plug.c +++ b/src/o3logon_fmt_plug.c @@ -38,7 +38,7 @@ john_register_one(&fmt_o3logon); #include "sha.h" #include "unicode.h" #include "base64_convert.h" - +#include "john.h" #define FORMAT_LABEL "o3logon" #define FORMAT_NAME "Oracle O3LOGON protocol" @@ -139,14 +139,12 @@ static int valid(char *ciphertext, struct fmt_main *self) tmp[cp-ciphertext] = 0; len = enc_to_utf16((UTF16 *)cur_key_mixedcase, MAX_USERNAME_LEN+1, (unsigned char*)tmp, strlen(tmp)); if (len < 0 || (len == 0 && cp-ciphertext)) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } if (len > MAX_USERNAME_LEN) diff --git a/src/oldoffice_common_plug.c b/src/oldoffice_common_plug.c index 84ccd4188c..2f50fca891 100644 --- a/src/oldoffice_common_plug.c +++ b/src/oldoffice_common_plug.c @@ -207,13 +207,10 @@ void *oldoffice_get_salt(char *ciphertext) cs.salt[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; - if (cs.type == 5 && !ldr_in_pot) { - static int warned; - - if (john_main_process && !warned++) { - fprintf(stderr, "Note: The support for OldOffice type 5 is experimental and may be incorrect.\n"); - fprintf(stderr, " For latest news see https://github.com/openwall/john/issues/4705\n"); - } + if (cs.type == 5 && !ldr_in_pot && john_main_process) { + WARN_ONCE(color_warning, stderr, + "Note: The support for OldOffice type 5 is experimental and may be incorrect.\n" + " For latest news see https://github.com/openwall/john/issues/4705\n"); } MEM_FREE(keeptr); diff --git a/src/opencl_DES_fmt_plug.c b/src/opencl_DES_fmt_plug.c index dc3ff58f39..00fd3b457d 100644 --- a/src/opencl_DES_fmt_plug.c +++ b/src/opencl_DES_fmt_plug.c @@ -23,6 +23,7 @@ john_register_one(&fmt_opencl_cryptdes); #include "opencl_DES_bs.h" #include "../run/opencl/opencl_DES_hst_dev_shared.h" #include "logger.h" +#include "john.h" #define FORMAT_NAME "traditional crypt(3)" @@ -111,13 +112,16 @@ static void init(struct fmt_main *pFmt) opencl_prepare_dev(gpu_id); if (force_kernel && !strcmp(force_kernel, "bs_b")) { - fprintf(stderr, "Using basic kernel (bs_b)\n"); + if (john_main_process) + WARN_AND_LOG_ONCE(color_notice, stderr, "Using basic kernel (bs_b)\n"); opencl_DES_bs_b_register_functions(pFmt); } else if (force_kernel && !strcmp(force_kernel, "bs_f")) { - fprintf(stderr, "Using fully unrolled, salt-specific kernels (bs_f)\n"); + if (john_main_process) + WARN_AND_LOG_ONCE(color_notice, stderr, "Using fully unrolled, salt-specific kernels (bs_f)\n"); opencl_DES_bs_f_register_functions(pFmt); } else if (force_kernel && !strcmp(force_kernel, "bs_h")) { - fprintf(stderr, "Using salt-specific kernels (bs_h)\n"); + if (john_main_process) + WARN_AND_LOG_ONCE(color_notice, stderr, "Using salt-specific kernels (bs_h)\n"); opencl_DES_bs_h_register_functions(pFmt); } else if ((USE_BASIC_KERNEL && !OVERRIDE_AUTO_CONFIG) || (OVERRIDE_AUTO_CONFIG && !HARDCODE_SALT && !FULL_UNROLL)) { diff --git a/src/opencl_autotune.h b/src/opencl_autotune.h index ed0476f36f..b242285e2f 100644 --- a/src/opencl_autotune.h +++ b/src/opencl_autotune.h @@ -156,10 +156,7 @@ static void autotune_run_extra(struct fmt_main *self, unsigned int rounds, default: if (cfg_lws < 0) { - fprintf(stderr, - "Error: AutotuneLWS must be a positive number (now set to %d)\n", - cfg_lws); - error(); + error_msg("Error: AutotuneLWS must be a positive number (now set to %d)\n", cfg_lws); } if (cpu(device_info[gpu_id])) local_work_size = @@ -234,7 +231,7 @@ static void autotune_run_extra(struct fmt_main *self, unsigned int rounds, uint32_t lws, gws, mpi_lws, mpi_gws; if (john_main_process) - log_event("- Enforcing same work sizes on all MPI nodes"); + log_event("OpenCL: Enforcing same work sizes on all MPI nodes"); lws = local_work_size; gws = global_work_size; MPI_Allreduce(&lws, &mpi_lws, 1, MPI_UNSIGNED, MPI_MIN, MPI_COMM_WORLD); @@ -276,7 +273,7 @@ static void autotune_run_extra(struct fmt_main *self, unsigned int rounds, create_clobj(global_work_size, self); if (!self_test_running && (!homogenous || john_main_process)) - log_event("- OpenCL LWS: "Zu"%s, GWS: "Zu" %s("Zu" blocks)", + log_event("OpenCL: LWS: "Zu"%s, GWS: "Zu" %s("Zu" blocks)", local_work_size, (need_best_lws && !needed_best_gws) ? " (auto-tuned)" : "", global_work_size, diff --git a/src/opencl_common.c b/src/opencl_common.c index af2c0b08ff..2058cd50c9 100644 --- a/src/opencl_common.c +++ b/src/opencl_common.c @@ -6,7 +6,7 @@ * This software is * Copyright (c) 2010-2012 Samuele Giovanni Tonon * Copyright (c) 2010-2013 Lukas Odzioba - * Copyright (c) 2010-2022 magnum + * Copyright (c) 2010-2026 magnum * Copyright (c) 2012-2015 Claudio André * * and is hereby released to the general public under the following terms: @@ -56,9 +56,6 @@ #include "john_mpi.h" #include "timer.h" -/* Set this to eg. 3 for some added debug and retry stuff */ -#define RACE_CONDITION_DEBUG 0 - #define LOG_SIZE 1024*16 /* Only output OpenCL build log if there was a fatal error @@ -341,11 +338,6 @@ static char *opencl_driver_info(int sequential_id) if (recommendation && strstr(recommendation, "N")) if (conf_major <= major && conf_minor <= minor) break; - -#ifdef OCL_DEBUG - fprintf(stderr, "Driver: %i, %i -> %s , %s\n", - conf_major, conf_minor, name, recommendation); -#endif } while ((line = line->next)); if (gpu_amd(device_info[sequential_id]) && @@ -431,7 +423,7 @@ static void load_opencl_environment() num_platforms = 0; if (num_platforms < 1 && options.verbosity > VERB_LEGACY) - fprintf(stderr, "%u: No OpenCL platforms were found: %s\n", + fprintf_color(color_warning, stderr, "%u: OpenCL: No platforms were found: %s\n", NODE, get_error_name(ret)); for (i = 0; i < num_platforms; i++) { @@ -447,7 +439,7 @@ static void load_opencl_environment() if (num_devices < 1 && options.verbosity > VERB_LEGACY) fprintf(stderr, - "%u: No OpenCL devices were found on platform #%d: %s\n", + "%u: OpenCL: No devices were found on platform #%d: %s\n", NODE, i, get_error_name(ret)); // Save platform and devices information @@ -456,19 +448,6 @@ static void load_opencl_environment() // Point to the end of the list device_pos += num_devices; - -#ifdef OCL_DEBUG - { - char opencl_data[LOG_SIZE]; - - SOFT_CLERROR(clGetPlatformInfo(platform_list[i], - CL_PLATFORM_NAME, sizeof(opencl_data), opencl_data, NULL), - "clGetPlatformInfo for CL_PLATFORM_NAME"); - - fprintf(stderr, "%u: OpenCL platform %d: %s, %d device(s).\n", - NODE, i, opencl_data, num_devices); - } -#endif } // Set NULL to the final buffer position. @@ -535,7 +514,6 @@ static int start_opencl_device(int sequential_id, int *err_type) { cl_context_properties properties[3]; char opencl_data[LOG_SIZE]; - int retry = 0; // Get the detailed information about the device // (populate device_info[d] bitfield). @@ -584,39 +562,26 @@ static int start_opencl_device(int sequential_id, int *err_type) &devices[sequential_id], NULL, NULL, &ret_code); if (ret_code != CL_SUCCESS) { - fprintf(stderr, "%u: Error creating context for device %d " - "(%d:%d): %s, %s\n", + fprintf_color(color_warning, stderr, "%u: Error creating OpenCL context for device %d " + "(%d:%d): %s\n", NODE, sequential_id + 1, get_platform_id(sequential_id), - get_device_id(sequential_id), get_error_name(ret_code), - retry < RACE_CONDITION_DEBUG ? "retrying" : "giving up"); - if (++retry > RACE_CONDITION_DEBUG) - error(); - usleep((retry + NODE) * 100); + get_device_id(sequential_id), get_error_name(ret_code)); } } while (ret_code != CL_SUCCESS); - retry = 0; do { queue[sequential_id] = clCreateCommandQueue(context[sequential_id], devices[sequential_id], 0, &ret_code); if (ret_code != CL_SUCCESS) { - fprintf(stderr, "%u: Error creating command queue for " - "device %d (%d:%d): %s, %s\n", NODE, + fprintf_color(color_warning, stderr, "%u: Error creating OpenCL command queue for " + "device %d (%d:%d): %s\n", NODE, sequential_id + 1, get_platform_id(sequential_id), - get_device_id(sequential_id), get_error_name(ret_code), - retry < RACE_CONDITION_DEBUG ? "retrying" : "giving up"); - if (++retry > RACE_CONDITION_DEBUG) - error(); - usleep((retry + NODE) * 100); + get_device_id(sequential_id), get_error_name(ret_code)); } } while (ret_code != CL_SUCCESS); -#ifdef OCL_DEBUG - fprintf(stderr, " Device %d: %s\n", sequential_id + 1, opencl_data); -#endif - // Success. return 1; } @@ -634,12 +599,12 @@ static void add_device_to_list(int sequential_id) if (found < 0) { #if HAVE_MPI if (mpi_p > 1) - fprintf(stderr, "%u@%s: ", mpi_id + 1, mpi_name); + fprintf_color(color_warning, stderr, "%u@%s: ", mpi_id + 1, mpi_name); #elif OS_FORK if (options.fork) - fprintf(stderr, "%u: ", options.node_min); + fprintf_color(color_warning, stderr, "%u: ", options.node_min); #endif - fprintf(stderr, "Error: --device must be between 1 and %d " + fprintf_color(color_error, stderr, "Error: --device must be between 1 and %d " "(the number of devices available).\n", get_number_of_available_devices()); error(); @@ -650,12 +615,12 @@ static void add_device_to_list(int sequential_id) if (! start_opencl_device(sequential_id, &i)) { #if HAVE_MPI if (mpi_p > 1) - fprintf(stderr, "%u@%s: ", mpi_id + 1, mpi_name); + fprintf_color(color_warning, stderr, "%u@%s: ", mpi_id + 1, mpi_name); #elif OS_FORK if (options.fork) - fprintf(stderr, "%u: ", options.node_min); + fprintf_color(color_warning, stderr, "%u: ", options.node_min); #endif - fprintf(stderr, "Device id %d not working correctly," + fprintf_color(color_warning, stderr, "OpenCL device id %d not working correctly," " skipping.\n", sequential_id + 1); return; } @@ -771,12 +736,12 @@ static void build_device_list(const char *device_list[MAX_GPU_DEVICES]) trial_list[i] != CL_DEVICE_TYPE_DEFAULT); } else if (!isdigit(ARCH_INDEX(device_list[n][0]))) { - fprintf(stderr, "Error: --device must be numerical, " + fprintf_color(color_error, stderr, "Error: --device must be numerical, " "or one of \"all\", \"cpu\", \"gpu\" and\n" "\"acc[elerator]\".\n"); error(); } else if (device_list[n][0] == '0') { - fprintf(stderr, "Error: --device must be between 1 and %d " + fprintf_color(color_error, stderr, "Error: --device must be between 1 and %d " "(the number of devices available).\n", get_number_of_available_devices()); error(); @@ -848,7 +813,7 @@ void opencl_load_environment(void) // Ensure that there is at least one OpenCL device available if (get_number_of_available_devices() == 0) { - fprintf(stderr, "No OpenCL devices found\n"); + fprintf_color(color_error, stderr, "No OpenCL devices found\n"); if (benchmark_running) { opencl_initialized = 1; opencl_unavailable = 1; @@ -894,7 +859,7 @@ void opencl_load_environment(void) // No working OpenCL device was found if (get_number_of_devices_in_use() == 0) { - fprintf(stderr, "No OpenCL devices found\n"); + fprintf_color(color_error, stderr, "No OpenCL devices found\n"); error(); } #if OS_FORK @@ -996,7 +961,7 @@ unsigned int opencl_get_vector_width(int sequential_id, int size) "clGetDeviceInfo for long vector width"); break; default: - fprintf(stderr, "%s() called with unknown type\n", __FUNCTION__); + fprintf_color(color_error, stderr, "%s() called with unknown type\n", __FUNCTION__); error(); } ocl_v_width = v_width; @@ -1158,7 +1123,7 @@ static void print_device_info(int sequential_id) "", "", #endif device_name, board_name); - log_event("Device %d: %s%s", sequential_id + 1, device_name, board_name); + log_event("OpenCL: Device %d: %s%s", sequential_id + 1, device_name, board_name); } static char *get_build_opts(int sequential_id, const char *opts) @@ -1242,20 +1207,10 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil int kludge_file = 0; if (mpi_p > 1) { -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d %s kludge locking %s...\n", - NODE, __FUNCTION__, kernel_source_file); -#endif if ((kludge_file = open(kernel_source_file, O_RDWR | O_APPEND)) < 0) pexit("Error opening %s", kernel_source_file); else jtr_lock(kludge_file, F_SETLKW, F_WRLCK, kernel_source_file); - -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d got a kludge lock\n", NODE); -#endif } #endif /* HAVE_MPI */ @@ -1285,7 +1240,7 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil if (!getcwd(old_cwd, sizeof(old_cwd))) { old_cwd[0] = 0; if (old_cwd_fd < 0) - fprintf(stderr, "Warning: Cannot save current directory: %s\n", strerror(errno)); + fprintf_color(color_warning, stderr, "Warning: Cannot save current directory: %s\n", strerror(errno)); } if (chdir(john_home)) pexit("chdir: %s", john_home); @@ -1294,7 +1249,7 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil build_code = clBuildProgram(*program, 0, NULL, build_opts, NULL, NULL); if ((old_cwd_fd >= 0 || old_cwd[0]) && /* We'll only have errno when we attempt a *chdir() here */ (old_cwd_fd < 0 || fchdir(old_cwd_fd)) && (!old_cwd[0] || chdir(old_cwd))) - fprintf(stderr, "Warning: Cannot restore current directory: %s\n", strerror(errno)); + fprintf_color(color_warning, stderr, "Warning: Cannot restore current directory: %s\n", strerror(errno)); if (old_cwd_fd >= 0) close(old_cwd_fd); @@ -1312,7 +1267,7 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil "clGetProgramBuildInfo II"); uint64_t end = john_get_nano(); - log_event("- build time: %ss", ns2string(end - start)); + log_event("OpenCL: Kernel build time: %ss", ns2string(end - start)); char *cleaned_log = build_log; if (cfg_get_bool(SECTION_OPTIONS, SUBSECTION_OPENCL, "MuteBogusWarnings", 1) && @@ -1375,32 +1330,16 @@ void opencl_build(int sequential_id, const char *opts, int save, const char *fil if (file == NULL) perror("Error creating binary cache file"); else { -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d %s locking %s...\n", NODE, __FUNCTION__, file_name); -#endif jtr_lock(fileno(file), F_SETLKW, F_WRLCK, file_name); -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d got a lock on %s\n", NODE, file_name); -#endif if (fwrite(source, source_size, 1, file) != 1) perror("Error caching kernel binary"); -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d closing %s\n", NODE, file_name); -#endif fclose(file); } MEM_FREE(source); } #if HAVE_MPI -#if RACE_CONDITION_DEBUG - if (mpi_p > 1 && options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d releasing kludge lock\n", NODE); -#endif if (mpi_p > 1) close(kludge_file); #endif /* HAVE_MPI */ @@ -1441,9 +1380,9 @@ cl_int opencl_build_from_binary(int sequential_id, cl_program *program, const ch } // Nvidia may return a single '\n' that we ignore else if (options.verbosity >= LOG_VERB && strlen(build_log) > 1) - fprintf(stderr, "Binary Build log: %s\n", build_log); + fprintf(stderr, "Binary build log: %s\n", build_log); - log_event("- build time: %ss", ns2string(end - start)); + log_event("OpenCL: Kernel build time: %ss", ns2string(end - start)); if (options.verbosity >= VERB_MAX) fprintf(stderr, "Build time: %ss\n", ns2string(end - start)); MEM_FREE(build_log); @@ -1832,7 +1771,7 @@ void opencl_find_best_lws(size_t group_size_limit, int sequential_id, */ if ((endTime - submitTime) > 10 * (endTime - startTime)) { if (options.verbosity > VERB_LEGACY) - fprintf(stderr, "Note: Profiling timers seem buggy\n"); + fprintf_color(color_notice, stderr, "Note: Profiling timers seem buggy\n"); startTime = submitTime; } @@ -1843,7 +1782,7 @@ void opencl_find_best_lws(size_t group_size_limit, int sequential_id, */ if ((wc_end - wc_start) > 10 * (endTime - startTime)) { if (options.verbosity > VERB_LEGACY) - fprintf(stderr, "Note: Profiling timers seem to be way off\n"); + fprintf_color(color_notice, stderr, "Note: Profiling timers seem to be way off\n"); startTime = wc_start; endTime = wc_end; } @@ -2236,18 +2175,8 @@ size_t opencl_read_source(const char *kernel_filename, char **kernel_source) if (!fp) pexit("Can't read source kernel"); -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d %s() locking (shared) %s...\n", NODE, __FUNCTION__, kernel_filename); -#endif - jtr_lock(fileno(fp), F_SETLKW, F_RDLCK, kernel_filename); -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d got a shared lock on %s\n", NODE, kernel_filename); -#endif - fseek(fp, 0, SEEK_END); source_size = ftell(fp); fseek(fp, 0, SEEK_SET); @@ -2256,13 +2185,9 @@ size_t opencl_read_source(const char *kernel_filename, char **kernel_source) read_size = fread(*kernel_source, sizeof(char), source_size, fp); if (read_size != source_size) fprintf(stderr, - "Error reading source: expected "Zu", got "Zu" bytes (%s).\n", + "OpenCL error reading kernel source: expected "Zu", got "Zu" bytes (%s).\n", source_size, read_size, feof(fp) ? "EOF" : strerror(errno)); -#if RACE_CONDITION_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d closing %s\n", NODE, kernel_filename); -#endif fclose(fp); return source_size; } @@ -2360,12 +2285,12 @@ void opencl_build_kernel(const char *kernel_filename, int sequential_id, const c */ if (gpu_nvidia(device_info[sequential_id]) && !platform_apple(get_platform_id(sequential_id))) { if (john_main_process || !cfg_get_bool(SECTION_OPTIONS, SUBSECTION_MPI, "MPIAllGPUsSame", 0)) - log_event("- Kernel binary caching disabled for this platform/device"); + LOG_ONCE("OpenCL: Kernel binary caching disabled for this platform/device"); use_cache = 0; } else #endif if (getenv("DUMP_BINARY")) { - log_event("- DUMP_BINARY is set, ignoring cached kernel"); + LOG_ONCE("OpenCL: DUMP_BINARY is set, ignoring cached kernel"); use_cache = 0; } else { use_cache = !stat(path_expand(bin_name), &bin_stat); @@ -2373,7 +2298,7 @@ void opencl_build_kernel(const char *kernel_filename, int sequential_id, const c if (use_cache && !stat(path_expand(kernel_filename), &source_stat) && source_stat.st_mtime > bin_stat.st_mtime) { use_cache = 0; - log_event("- cached kernel may be stale, ignoring"); + log_event("OpenCL: Cached kernel may be stale, ignoring"); } } @@ -2381,17 +2306,17 @@ void opencl_build_kernel(const char *kernel_filename, int sequential_id, const c if (use_cache) { size_t program_size = opencl_read_source(bin_name, &kernel_source); - log_event("- Building kernel from cached binary"); + log_event("OpenCL: Building kernel from cached binary"); ret_code = opencl_build_from_binary(sequential_id, &program[sequential_id], kernel_source, program_size); if (ret_code != CL_SUCCESS) - log_event("- Build from cached binary failed"); + log_event("OpenCL: Build from cached binary failed"); } if (!use_cache || ret_code != CL_SUCCESS) { - log_event("- Building kernel from source and caching binary"); + log_event("OpenCL: Building kernel from source and caching binary"); if (warn && options.verbosity > VERB_DEFAULT) { fflush(stdout); - fprintf(stderr, "Building the kernel, this could take a while\n"); + fprintf(stderr, "Building the OpenCL kernel, this could take a while\n"); } opencl_read_source(kernel_filename, &kernel_source); opencl_build(sequential_id, opts, 1, bin_name, &program[sequential_id], kernel_filename, kernel_source); @@ -2401,10 +2326,6 @@ void opencl_build_kernel(const char *kernel_filename, int sequential_id, const c #if HAVE_MPI if (mpi_p > 1 && !once++) { -#if RACE_CONDITION_DEBUG || MPI_DEBUG - if (options.verbosity == VERB_DEBUG) - fprintf(stderr, "Node %d reached %s() MPI build barrier\n", NODE, __FUNCTION__); -#endif MPI_Barrier(MPI_COMM_WORLD); if (mpi_id == 0 && options.verbosity >= VERB_DEFAULT) fprintf(stderr, "All nodes done OpenCL build\n"); @@ -2433,7 +2354,7 @@ int opencl_prepare_dev(int sequential_id) #if HAVE_MPI if (mpi_p > 1 && !once++) { // Avoid silly race conditions seen with nvidia -#if RACE_CONDITION_DEBUG || MPI_DEBUG +#if MPI_DEBUG if (options.verbosity == VERB_DEBUG) fprintf(stderr, "Node %d reached MPI prep barrier\n", NODE); #endif @@ -2453,14 +2374,9 @@ int opencl_prepare_dev(int sequential_id) if (gpu_nvidia(device_info[sequential_id])) { opencl_avoid_busy_wait[sequential_id] = cfg_get_bool(SECTION_OPTIONS, SUBSECTION_GPU, "AvoidBusyWait", 1); - static int warned; - /* Remove next line once (nearly) all formats has got the macros */ if (!opencl_avoid_busy_wait[sequential_id]) - if (!warned) { - warned = 1; - log_event("- Busy-wait reduction %sabled", opencl_avoid_busy_wait[sequential_id] ? "en" : "dis"); - } + LOG_ONCE("OpenCL: Busy-wait reduction %sabled", opencl_avoid_busy_wait[sequential_id] ? "en" : "dis"); } #endif @@ -2979,11 +2895,10 @@ void opencl_list_devices(void) ret = clGetPlatformIDs(MAX_PLATFORMS, platform_list, &num_platforms); if (!num_platforms) - fprintf(stderr, "Error: No OpenCL-capable platforms were detected" - " by the installed OpenCL driver.\n"); + fprintf_color(color_error, stderr, "Error: No platforms were detected by the installed OpenCL driver.\n"); if (ret != CL_SUCCESS && options.verbosity > VERB_LEGACY) - fprintf(stderr, "Throw clError: clGetPlatformIDs() = %s\n", + fprintf_color(color_warning, stderr, "Throw clError: clGetPlatformIDs() = %s\n", get_error_name(ret)); for (i = 0; i < num_platforms; i++) { @@ -2994,7 +2909,7 @@ void opencl_list_devices(void) if ((ret != CL_SUCCESS || num_devices < 1) && options.verbosity > VERB_LEGACY) - fprintf(stderr, "No OpenCL devices was found on platform #%d" + fprintf_color(color_warning, stderr, "No OpenCL devices was found on platform #%d" ", clGetDeviceIDs() = %s\n", i, get_error_name(ret)); @@ -3019,8 +2934,7 @@ void opencl_list_devices(void) printf(" Platform extensions: %s\n", dname); } } - fprintf(stderr, "Error: No OpenCL-capable devices were detected" - " by the installed OpenCL driver.\n\n"); + fprintf_color(color_error, stderr, "Error: No devices were detected by the installed OpenCL driver.\n\n"); return; } /* Initialize OpenCL environment */ diff --git a/src/opencl_common.h b/src/opencl_common.h index 772131cde4..f8a885f141 100644 --- a/src/opencl_common.h +++ b/src/opencl_common.h @@ -5,7 +5,7 @@ * * * Copyright (c) 2013-2015 Claudio André , - * Copyright (c) 2012-2013 magnum, + * Copyright (c) 2012-2026 magnum, * Others and * is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without @@ -250,10 +250,10 @@ void opencl_process_event(void); do { cl_int __err = (cl_error); \ if (__err != CL_SUCCESS) { \ if (!ocl_autotune_running || options.verbosity >= VERB_MAX) \ - fprintf(stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ + fprintf_color(color_error, stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ NODE, get_error_name(__err), __FILE__, __LINE__, message); \ else if (options.verbosity > VERB_LEGACY) \ - fprintf(stderr, " %u: %s\n", NODE, get_error_name(__err)); \ + fprintf_color(color_error, stderr, " %u: %s\n", NODE, get_error_name(__err)); \ if (ocl_autotune_running) \ return -1; \ else if (bench_or_test_running) \ @@ -267,7 +267,7 @@ void opencl_process_event(void); #define HANDLE_CLERROR(cl_error, message) \ do { cl_int __err = (cl_error); \ if (__err != CL_SUCCESS) { \ - fprintf(stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ + fprintf_color(color_error, stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ NODE, get_error_name(__err), __FILE__, __LINE__, (message)); \ error(); \ } \ @@ -277,7 +277,7 @@ void opencl_process_event(void); #define SOFT_CLERROR(cl_error, message) \ do { cl_int __err = (cl_error); \ if (__err != CL_SUCCESS) { \ - fprintf(stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ + fprintf_color(color_error, stderr, "%u: OpenCL %s error in %s:%d - %s\n", \ NODE, get_error_name(__err), __FILE__, __LINE__, (message)); \ } \ } while (0) diff --git a/src/opencl_diskcryptor_aes_fmt_plug.c b/src/opencl_diskcryptor_aes_fmt_plug.c index beace960f9..302207f8ee 100644 --- a/src/opencl_diskcryptor_aes_fmt_plug.c +++ b/src/opencl_diskcryptor_aes_fmt_plug.c @@ -171,14 +171,11 @@ static void create_clobj(size_t kpc, struct fmt_main *self) static void init(struct fmt_main *_self) { - static int warned = 0; - self = _self; opencl_prepare_dev(gpu_id); - if (!warned++ && !(options.flags & FLG_TEST_CHK) && !options.listconf) { - fprintf(stderr, "[ATTENTION] This format (%s) can only crack AES XTS DiskCryptor hashes.\n", FORMAT_LABEL); - } + if (!(options.flags & FLG_TEST_CHK) && !options.listconf) + WARN_ONCE(color_warning, stderr, "Warning: %s can only crack AES XTS DiskCryptor hashes.\n", FORMAT_LABEL); } static void reset(struct db_main *db) diff --git a/src/opencl_diskcryptor_fmt_plug.c b/src/opencl_diskcryptor_fmt_plug.c index 4328c0cd97..0c15454619 100644 --- a/src/opencl_diskcryptor_fmt_plug.c +++ b/src/opencl_diskcryptor_fmt_plug.c @@ -166,16 +166,13 @@ static void create_clobj(size_t kpc, struct fmt_main *self) static void init(struct fmt_main *_self) { - static int warned = 0; - self = _self; opencl_prepare_dev(gpu_id); Twofish_initialise(); - if (!warned++ && !(options.flags & FLG_TEST_CHK) && !options.listconf) { - fprintf(stderr, "[ATTENTION] This format (%s) does not support cascaded cipher modes yet.\n", FORMAT_LABEL); - } + if (!(options.flags & FLG_TEST_CHK) && !options.listconf) + WARN_ONCE(color_warning, stderr, "Warning: %s does not support cascaded cipher modes yet.\n", FORMAT_LABEL); } static void reset(struct db_main *db) diff --git a/src/opencl_dynamic_loader.c b/src/opencl_dynamic_loader.c index 063f9f4ee7..6678e3d7a9 100644 --- a/src/opencl_dynamic_loader.c +++ b/src/opencl_dynamic_loader.c @@ -20,6 +20,8 @@ #include #include +#include "color.h" + /* DLL handle */ static void *opencl_dll; static void load_opencl_dll(void); @@ -614,387 +616,387 @@ static void load_opencl_dll(void) ptr_clGetPlatformIDs = dlsym(opencl_dll, "clGetPlatformIDs"); if (!ptr_clGetPlatformIDs) { ptr_clGetPlatformIDs = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetPlatformIDs function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetPlatformIDs function\n"); } ptr_clGetPlatformInfo = dlsym(opencl_dll, "clGetPlatformInfo"); if (!ptr_clGetPlatformInfo) { ptr_clGetPlatformInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetPlatformInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetPlatformInfo function\n"); } ptr_clGetDeviceIDs = dlsym(opencl_dll, "clGetDeviceIDs"); if (!ptr_clGetDeviceIDs) { ptr_clGetDeviceIDs = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetDeviceIDs function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetDeviceIDs function\n"); } ptr_clGetDeviceInfo = dlsym(opencl_dll, "clGetDeviceInfo"); if (!ptr_clGetDeviceInfo) { ptr_clGetDeviceInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetDeviceInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetDeviceInfo function\n"); } ptr_clCreateSubDevices = dlsym(opencl_dll, "clCreateSubDevices"); if (!ptr_clCreateSubDevices) { ptr_clCreateSubDevices = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateSubDevices function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateSubDevices function\n"); } ptr_clRetainDevice = dlsym(opencl_dll, "clRetainDevice"); if (!ptr_clRetainDevice) { ptr_clRetainDevice = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainDevice function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainDevice function\n"); } ptr_clReleaseDevice = dlsym(opencl_dll, "clReleaseDevice"); if (!ptr_clReleaseDevice) { ptr_clReleaseDevice = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseDevice function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseDevice function\n"); } ptr_clCreateContext = dlsym(opencl_dll, "clCreateContext"); if (!ptr_clCreateContext) { ptr_clCreateContext = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateContext function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateContext function\n"); } ptr_clCreateContextFromType = dlsym(opencl_dll, "clCreateContextFromType"); if (!ptr_clCreateContextFromType) { ptr_clCreateContextFromType = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateContextFromType function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateContextFromType function\n"); } ptr_clRetainContext = dlsym(opencl_dll, "clRetainContext"); if (!ptr_clRetainContext) { ptr_clRetainContext = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainContext function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainContext function\n"); } ptr_clReleaseContext = dlsym(opencl_dll, "clReleaseContext"); if (!ptr_clReleaseContext) { ptr_clReleaseContext = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseContext function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseContext function\n"); } ptr_clGetContextInfo = dlsym(opencl_dll, "clGetContextInfo"); if (!ptr_clGetContextInfo) { ptr_clGetContextInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetContextInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetContextInfo function\n"); } ptr_clRetainCommandQueue = dlsym(opencl_dll, "clRetainCommandQueue"); if (!ptr_clRetainCommandQueue) { ptr_clRetainCommandQueue = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainCommandQueue function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainCommandQueue function\n"); } ptr_clReleaseCommandQueue = dlsym(opencl_dll, "clReleaseCommandQueue"); if (!ptr_clReleaseCommandQueue) { ptr_clReleaseCommandQueue = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseCommandQueue function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseCommandQueue function\n"); } ptr_clGetCommandQueueInfo = dlsym(opencl_dll, "clGetCommandQueueInfo"); if (!ptr_clGetCommandQueueInfo) { ptr_clGetCommandQueueInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetCommandQueueInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetCommandQueueInfo function\n"); } ptr_clCreateBuffer = dlsym(opencl_dll, "clCreateBuffer"); if (!ptr_clCreateBuffer) { ptr_clCreateBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateBuffer function\n"); } ptr_clCreateSubBuffer = dlsym(opencl_dll, "clCreateSubBuffer"); if (!ptr_clCreateSubBuffer) { ptr_clCreateSubBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateSubBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateSubBuffer function\n"); } ptr_clRetainMemObject = dlsym(opencl_dll, "clRetainMemObject"); if (!ptr_clRetainMemObject) { ptr_clRetainMemObject = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainMemObject function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainMemObject function\n"); } ptr_clReleaseMemObject = dlsym(opencl_dll, "clReleaseMemObject"); if (!ptr_clReleaseMemObject) { ptr_clReleaseMemObject = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseMemObject function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseMemObject function\n"); } ptr_clGetMemObjectInfo = dlsym(opencl_dll, "clGetMemObjectInfo"); if (!ptr_clGetMemObjectInfo) { ptr_clGetMemObjectInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetMemObjectInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetMemObjectInfo function\n"); } ptr_clSetMemObjectDestructorCallback = dlsym(opencl_dll, "clSetMemObjectDestructorCallback"); if (!ptr_clSetMemObjectDestructorCallback) { ptr_clSetMemObjectDestructorCallback = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clSetMemObjectDestructorCallback function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clSetMemObjectDestructorCallback function\n"); } ptr_clRetainSampler = dlsym(opencl_dll, "clRetainSampler"); if (!ptr_clRetainSampler) { ptr_clRetainSampler = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainSampler function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainSampler function\n"); } ptr_clReleaseSampler = dlsym(opencl_dll, "clReleaseSampler"); if (!ptr_clReleaseSampler) { ptr_clReleaseSampler = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseSampler function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseSampler function\n"); } ptr_clGetSamplerInfo = dlsym(opencl_dll, "clGetSamplerInfo"); if (!ptr_clGetSamplerInfo) { ptr_clGetSamplerInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetSamplerInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetSamplerInfo function\n"); } ptr_clCreateProgramWithSource = dlsym(opencl_dll, "clCreateProgramWithSource"); if (!ptr_clCreateProgramWithSource) { ptr_clCreateProgramWithSource = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateProgramWithSource function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateProgramWithSource function\n"); } ptr_clCreateProgramWithBinary = dlsym(opencl_dll, "clCreateProgramWithBinary"); if (!ptr_clCreateProgramWithBinary) { ptr_clCreateProgramWithBinary = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateProgramWithBinary function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateProgramWithBinary function\n"); } ptr_clCreateProgramWithBuiltInKernels = dlsym(opencl_dll, "clCreateProgramWithBuiltInKernels"); if (!ptr_clCreateProgramWithBuiltInKernels) { ptr_clCreateProgramWithBuiltInKernels = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateProgramWithBuiltInKernels function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateProgramWithBuiltInKernels function\n"); } ptr_clRetainProgram = dlsym(opencl_dll, "clRetainProgram"); if (!ptr_clRetainProgram) { ptr_clRetainProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainProgram function\n"); } ptr_clReleaseProgram = dlsym(opencl_dll, "clReleaseProgram"); if (!ptr_clReleaseProgram) { ptr_clReleaseProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseProgram function\n"); } ptr_clBuildProgram = dlsym(opencl_dll, "clBuildProgram"); if (!ptr_clBuildProgram) { ptr_clBuildProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clBuildProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clBuildProgram function\n"); } ptr_clCompileProgram = dlsym(opencl_dll, "clCompileProgram"); if (!ptr_clCompileProgram) { ptr_clCompileProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCompileProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCompileProgram function\n"); } ptr_clLinkProgram = dlsym(opencl_dll, "clLinkProgram"); if (!ptr_clLinkProgram) { ptr_clLinkProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clLinkProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clLinkProgram function\n"); } ptr_clUnloadPlatformCompiler = dlsym(opencl_dll, "clUnloadPlatformCompiler"); if (!ptr_clUnloadPlatformCompiler) { ptr_clUnloadPlatformCompiler = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clUnloadPlatformCompiler function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clUnloadPlatformCompiler function\n"); } ptr_clGetProgramInfo = dlsym(opencl_dll, "clGetProgramInfo"); if (!ptr_clGetProgramInfo) { ptr_clGetProgramInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetProgramInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetProgramInfo function\n"); } ptr_clGetProgramBuildInfo = dlsym(opencl_dll, "clGetProgramBuildInfo"); if (!ptr_clGetProgramBuildInfo) { ptr_clGetProgramBuildInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetProgramBuildInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetProgramBuildInfo function\n"); } ptr_clCreateKernel = dlsym(opencl_dll, "clCreateKernel"); if (!ptr_clCreateKernel) { ptr_clCreateKernel = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateKernel function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateKernel function\n"); } ptr_clCreateKernelsInProgram = dlsym(opencl_dll, "clCreateKernelsInProgram"); if (!ptr_clCreateKernelsInProgram) { ptr_clCreateKernelsInProgram = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateKernelsInProgram function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateKernelsInProgram function\n"); } ptr_clRetainKernel = dlsym(opencl_dll, "clRetainKernel"); if (!ptr_clRetainKernel) { ptr_clRetainKernel = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainKernel function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainKernel function\n"); } ptr_clReleaseKernel = dlsym(opencl_dll, "clReleaseKernel"); if (!ptr_clReleaseKernel) { ptr_clReleaseKernel = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseKernel function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseKernel function\n"); } ptr_clSetKernelArg = dlsym(opencl_dll, "clSetKernelArg"); if (!ptr_clSetKernelArg) { ptr_clSetKernelArg = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clSetKernelArg function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clSetKernelArg function\n"); } ptr_clGetKernelInfo = dlsym(opencl_dll, "clGetKernelInfo"); if (!ptr_clGetKernelInfo) { ptr_clGetKernelInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetKernelInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetKernelInfo function\n"); } ptr_clGetKernelArgInfo = dlsym(opencl_dll, "clGetKernelArgInfo"); if (!ptr_clGetKernelArgInfo) { ptr_clGetKernelArgInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetKernelArgInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetKernelArgInfo function\n"); } ptr_clGetKernelWorkGroupInfo = dlsym(opencl_dll, "clGetKernelWorkGroupInfo"); if (!ptr_clGetKernelWorkGroupInfo) { ptr_clGetKernelWorkGroupInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetKernelWorkGroupInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetKernelWorkGroupInfo function\n"); } ptr_clWaitForEvents = dlsym(opencl_dll, "clWaitForEvents"); if (!ptr_clWaitForEvents) { ptr_clWaitForEvents = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clWaitForEvents function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clWaitForEvents function\n"); } ptr_clGetEventInfo = dlsym(opencl_dll, "clGetEventInfo"); if (!ptr_clGetEventInfo) { ptr_clGetEventInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetEventInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetEventInfo function\n"); } ptr_clCreateUserEvent = dlsym(opencl_dll, "clCreateUserEvent"); if (!ptr_clCreateUserEvent) { ptr_clCreateUserEvent = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateUserEvent function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateUserEvent function\n"); } ptr_clRetainEvent = dlsym(opencl_dll, "clRetainEvent"); if (!ptr_clRetainEvent) { ptr_clRetainEvent = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clRetainEvent function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clRetainEvent function\n"); } ptr_clReleaseEvent = dlsym(opencl_dll, "clReleaseEvent"); if (!ptr_clReleaseEvent) { ptr_clReleaseEvent = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clReleaseEvent function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clReleaseEvent function\n"); } ptr_clSetUserEventStatus = dlsym(opencl_dll, "clSetUserEventStatus"); if (!ptr_clSetUserEventStatus) { ptr_clSetUserEventStatus = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clSetUserEventStatus function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clSetUserEventStatus function\n"); } ptr_clSetEventCallback = dlsym(opencl_dll, "clSetEventCallback"); if (!ptr_clSetEventCallback) { ptr_clSetEventCallback = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clSetEventCallback function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clSetEventCallback function\n"); } ptr_clGetEventProfilingInfo = dlsym(opencl_dll, "clGetEventProfilingInfo"); if (!ptr_clGetEventProfilingInfo) { ptr_clGetEventProfilingInfo = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetEventProfilingInfo function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetEventProfilingInfo function\n"); } ptr_clFlush = dlsym(opencl_dll, "clFlush"); if (!ptr_clFlush) { ptr_clFlush = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clFlush function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clFlush function\n"); } ptr_clFinish = dlsym(opencl_dll, "clFinish"); if (!ptr_clFinish) { ptr_clFinish = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clFinish function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clFinish function\n"); } ptr_clEnqueueReadBuffer = dlsym(opencl_dll, "clEnqueueReadBuffer"); if (!ptr_clEnqueueReadBuffer) { ptr_clEnqueueReadBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueReadBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueReadBuffer function\n"); } ptr_clEnqueueReadBufferRect = dlsym(opencl_dll, "clEnqueueReadBufferRect"); if (!ptr_clEnqueueReadBufferRect) { ptr_clEnqueueReadBufferRect = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueReadBufferRect function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueReadBufferRect function\n"); } ptr_clEnqueueWriteBuffer = dlsym(opencl_dll, "clEnqueueWriteBuffer"); if (!ptr_clEnqueueWriteBuffer) { ptr_clEnqueueWriteBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueWriteBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueWriteBuffer function\n"); } ptr_clEnqueueWriteBufferRect = dlsym(opencl_dll, "clEnqueueWriteBufferRect"); if (!ptr_clEnqueueWriteBufferRect) { ptr_clEnqueueWriteBufferRect = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueWriteBufferRect function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueWriteBufferRect function\n"); } ptr_clEnqueueFillBuffer = dlsym(opencl_dll, "clEnqueueFillBuffer"); if (!ptr_clEnqueueFillBuffer) { ptr_clEnqueueFillBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueFillBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueFillBuffer function\n"); } ptr_clEnqueueCopyBuffer = dlsym(opencl_dll, "clEnqueueCopyBuffer"); if (!ptr_clEnqueueCopyBuffer) { ptr_clEnqueueCopyBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueCopyBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueCopyBuffer function\n"); } ptr_clEnqueueCopyBufferRect = dlsym(opencl_dll, "clEnqueueCopyBufferRect"); if (!ptr_clEnqueueCopyBufferRect) { ptr_clEnqueueCopyBufferRect = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueCopyBufferRect function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueCopyBufferRect function\n"); } ptr_clEnqueueMapBuffer = dlsym(opencl_dll, "clEnqueueMapBuffer"); if (!ptr_clEnqueueMapBuffer) { ptr_clEnqueueMapBuffer = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueMapBuffer function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueMapBuffer function\n"); } ptr_clEnqueueUnmapMemObject = dlsym(opencl_dll, "clEnqueueUnmapMemObject"); if (!ptr_clEnqueueUnmapMemObject) { ptr_clEnqueueUnmapMemObject = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueUnmapMemObject function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueUnmapMemObject function\n"); } ptr_clEnqueueMigrateMemObjects = dlsym(opencl_dll, "clEnqueueMigrateMemObjects"); if (!ptr_clEnqueueMigrateMemObjects) { ptr_clEnqueueMigrateMemObjects = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueMigrateMemObjects function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueMigrateMemObjects function\n"); } ptr_clEnqueueNDRangeKernel = dlsym(opencl_dll, "clEnqueueNDRangeKernel"); if (!ptr_clEnqueueNDRangeKernel) { ptr_clEnqueueNDRangeKernel = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueNDRangeKernel function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueNDRangeKernel function\n"); } ptr_clEnqueueNativeKernel = dlsym(opencl_dll, "clEnqueueNativeKernel"); if (!ptr_clEnqueueNativeKernel) { ptr_clEnqueueNativeKernel = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueNativeKernel function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueNativeKernel function\n"); } ptr_clEnqueueMarkerWithWaitList = dlsym(opencl_dll, "clEnqueueMarkerWithWaitList"); if (!ptr_clEnqueueMarkerWithWaitList) { ptr_clEnqueueMarkerWithWaitList = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueMarkerWithWaitList function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueMarkerWithWaitList function\n"); } ptr_clEnqueueBarrierWithWaitList = dlsym(opencl_dll, "clEnqueueBarrierWithWaitList"); if (!ptr_clEnqueueBarrierWithWaitList) { ptr_clEnqueueBarrierWithWaitList = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueBarrierWithWaitList function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueBarrierWithWaitList function\n"); } ptr_clGetExtensionFunctionAddressForPlatform = dlsym(opencl_dll, "clGetExtensionFunctionAddressForPlatform"); if (!ptr_clGetExtensionFunctionAddressForPlatform) { ptr_clGetExtensionFunctionAddressForPlatform = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetExtensionFunctionAddressForPlatform function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetExtensionFunctionAddressForPlatform function\n"); } ptr_clSetCommandQueueProperty = dlsym(opencl_dll, "clSetCommandQueueProperty"); if (!ptr_clSetCommandQueueProperty) { ptr_clSetCommandQueueProperty = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clSetCommandQueueProperty function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clSetCommandQueueProperty function\n"); } ptr_clEnqueueMarker = dlsym(opencl_dll, "clEnqueueMarker"); if (!ptr_clEnqueueMarker) { ptr_clEnqueueMarker = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueMarker function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueMarker function\n"); } ptr_clEnqueueWaitForEvents = dlsym(opencl_dll, "clEnqueueWaitForEvents"); if (!ptr_clEnqueueWaitForEvents) { ptr_clEnqueueWaitForEvents = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueWaitForEvents function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueWaitForEvents function\n"); } ptr_clEnqueueBarrier = dlsym(opencl_dll, "clEnqueueBarrier"); if (!ptr_clEnqueueBarrier) { ptr_clEnqueueBarrier = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueBarrier function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueBarrier function\n"); } ptr_clUnloadCompiler = dlsym(opencl_dll, "clUnloadCompiler"); if (!ptr_clUnloadCompiler) { ptr_clUnloadCompiler = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clUnloadCompiler function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clUnloadCompiler function\n"); } ptr_clGetExtensionFunctionAddress = dlsym(opencl_dll, "clGetExtensionFunctionAddress"); if (!ptr_clGetExtensionFunctionAddress) { ptr_clGetExtensionFunctionAddress = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clGetExtensionFunctionAddress function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clGetExtensionFunctionAddress function\n"); } ptr_clCreateCommandQueue = dlsym(opencl_dll, "clCreateCommandQueue"); if (!ptr_clCreateCommandQueue) { ptr_clCreateCommandQueue = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateCommandQueue function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateCommandQueue function\n"); } ptr_clCreateSampler = dlsym(opencl_dll, "clCreateSampler"); if (!ptr_clCreateSampler) { ptr_clCreateSampler = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clCreateSampler function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clCreateSampler function\n"); } ptr_clEnqueueTask = dlsym(opencl_dll, "clEnqueueTask"); if (!ptr_clEnqueueTask) { ptr_clEnqueueTask = (void *)unimplemented_function; - fprintf(stderr, "Warning: Cannot find the clEnqueueTask function\n"); + fprintf_color(color_warning, stderr, "Warning: Cannot find the clEnqueueTask function\n"); } } diff --git a/src/opencl_generate_dynamic_loader.py b/src/opencl_generate_dynamic_loader.py index d9640bf6c5..3389d24624 100755 --- a/src/opencl_generate_dynamic_loader.py +++ b/src/opencl_generate_dynamic_loader.py @@ -48,6 +48,8 @@ #include #include +#include "color.h" + /* DLL handle */ static void *opencl_dll; static void load_opencl_dll(void); @@ -166,7 +168,7 @@ dynamic_loader.write(f'\tptr_{function_name} = dlsym(opencl_dll, "{function_name}");\n') dynamic_loader.write(f'\tif (!ptr_{function_name}) {{\n') dynamic_loader.write(f'\t\tptr_{function_name} = (void *)unimplemented_function;\n') - dynamic_loader.write(f'\t\tfprintf(stderr, "Warning: Cannot find the {function_name} function\\n");\n') + dynamic_loader.write(f'\t\tfprintf_color(color_warning, stderr, "Warning: Cannot find the {function_name} function\\n");\n') dynamic_loader.write('\t}\n') dynamic_loader.write('''} diff --git a/src/opencl_krb5pa-sha1_fmt_plug.c b/src/opencl_krb5pa-sha1_fmt_plug.c index aac6729721..80b8b754cc 100644 --- a/src/opencl_krb5pa-sha1_fmt_plug.c +++ b/src/opencl_krb5pa-sha1_fmt_plug.c @@ -336,11 +336,8 @@ static int valid(char *ciphertext, struct fmt_main *self) // We support a max. total salt length of 52. // We could opt to emit a warning if rejected here. if (saltlen > MAX_SALTLEN) { - static int warned = 0; - - if (!ldr_in_pot) - if (!warned++) - fprintf(stderr, "%s: One or more hashes rejected due to salt length limitation\n", FORMAT_LABEL); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: One or more hashes rejected due to salt length limitation\n", FORMAT_LABEL); return 0; } diff --git a/src/opencl_lm_b_plug.c b/src/opencl_lm_b_plug.c index 325984cba8..ed79be2dff 100644 --- a/src/opencl_lm_b_plug.c +++ b/src/opencl_lm_b_plug.c @@ -18,6 +18,7 @@ #include "bt_interface.h" #include "mask_ext.h" #include "logger.h" +#include "john.h" #define PADDING 2048 @@ -443,7 +444,7 @@ static void release_kernels(); static void init_kernels(char *bitmap_params, unsigned int full_unroll, size_t s_mem_lws, unsigned int use_local_mem, unsigned int use_last_build_opt) { - static unsigned int warned, last_build_opts[3]; + static unsigned int last_build_opts[3]; char build_opts[500]; cl_ulong const_cache_size; unsigned int i; @@ -453,22 +454,24 @@ static void init_kernels(char *bitmap_params, unsigned int full_unroll, size_t s char *kernel, *lm_kernel, *force_kernel = getenv("JOHN_DES_KERNEL"); if (force_kernel && !strcmp(force_kernel, "bs_f")) { - if (!warned++) fprintf(stderr, "Using fully unrolled kernel (lm_bs_f)\n"); + if (john_main_process) + WARN_AND_LOG_ONCE(color_notice, stderr, "Using fully unrolled kernel (lm_bs_f)"); full_unroll = 1; lm_kernel = "lm_bs_f"; kernel = "$JOHN/opencl/lm_kernel_f.cl"; } else if (force_kernel && !strcmp(force_kernel, "bs_b")) { - if (!warned++) fprintf(stderr, "Using basic kernel (lm_bs_b)\n"); + if (john_main_process) + WARN_AND_LOG_ONCE(color_notice, stderr, "Using basic kernel (lm_bs_b)"); full_unroll = 0; lm_kernel = "lm_bs_b"; kernel = "$JOHN/opencl/lm_kernel_b.cl"; } else if (use_last_build_opt ? last_build_opts[0] : full_unroll) { - if (!warned++) log_event("- Using fully unrolled kernel (lm_bs_f)"); + LOG_ONCE("Using fully unrolled kernel (lm_bs_f)"); lm_kernel = "lm_bs_f"; kernel = "$JOHN/opencl/lm_kernel_f.cl"; } else { - if (!warned++) log_event("- Using basic kernel (lm_bs_b)"); + LOG_ONCE("Using basic kernel (lm_bs_b)"); lm_kernel = "lm_bs_b"; kernel = "$JOHN/opencl/lm_kernel_b.cl"; } diff --git a/src/opencl_lm_fmt_plug.c b/src/opencl_lm_fmt_plug.c index 48897db4c1..afdeeedc5b 100644 --- a/src/opencl_lm_fmt_plug.c +++ b/src/opencl_lm_fmt_plug.c @@ -120,14 +120,12 @@ static void init(struct fmt_main *pFmt) opencl_lm_b_register_functions(pFmt); opencl_lm_init_global_variables(); - static int warned; - if (!warned && options.target_enc > CP_DOS_HI && !options.listconf && + if (options.target_enc > CP_DOS_HI && !options.listconf && sizeof(tests) / sizeof(tests[0]) > 16) { - fprintf_color(color_warning, stderr, + WARN_ONCE(color_warning, stderr, "Warning: LM formats incompatible with %s encoding, disabling some self-tests\n", cp_id2name(options.target_enc)); tests[16].ciphertext = NULL; // Truncates the array after 16 entries - warned = 1; } } diff --git a/src/opencl_ntlmv2_fmt_plug.c b/src/opencl_ntlmv2_fmt_plug.c index f9d4331e37..614a48c143 100644 --- a/src/opencl_ntlmv2_fmt_plug.c +++ b/src/opencl_ntlmv2_fmt_plug.c @@ -436,15 +436,11 @@ static int valid(char *ciphertext, struct fmt_main *self) return 0; if (saltlen < 0 || saltlen > SALT_MAX_LENGTH) { - static int warned = 0; - - if (!ldr_in_pot) - if (!warned++) - fprintf(stderr, "%s: One or more hashes rejected due " - "to salt length limitation.\nMax supported sum" - " of Username + Domainname lengths is %d" - " characters.\nTry the CPU format for " - "those.\n", FORMAT_LABEL, SALT_MAX_LENGTH); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, + "%s: One or more hashes rejected due to salt length limitation.\nMax supported sum" + " of Username + Domainname lengths is %d characters.\nTry the CPU format for those.\n", + FORMAT_LABEL, SALT_MAX_LENGTH); return 0; } return 1; diff --git a/src/opencl_oldoffice_fmt_plug.c b/src/opencl_oldoffice_fmt_plug.c index c2c8ad6973..1aca89fb12 100644 --- a/src/opencl_oldoffice_fmt_plug.c +++ b/src/opencl_oldoffice_fmt_plug.c @@ -473,14 +473,10 @@ static void *get_salt(char *ciphertext) } } - if (cs.type == 5 && !ldr_in_pot) { - static int warned; - - if (john_main_process && !warned++) { - fprintf(stderr, "Note: The support for OldOffice type 5 is experimental and may be incorrect.\n"); - fprintf(stderr, " For latest news see https://github.com/openwall/john/issues/4705\n"); - } - } + if (cs.type == 5 && !ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, + "Note: The support for OldOffice type 5 is experimental and may be incorrect.\n" + " For latest news see https://github.com/openwall/john/issues/4705\n"); MEM_FREE(keeptr); diff --git a/src/opencl_tc_fmt_plug.c b/src/opencl_tc_fmt_plug.c index 013f64ed8f..a727dabc3a 100644 --- a/src/opencl_tc_fmt_plug.c +++ b/src/opencl_tc_fmt_plug.c @@ -333,7 +333,7 @@ static void* get_salt(char *ciphertext) if (len > sizeof(tpath) - 1) { // should never get here! valid() should catch all lines with overly long paths if (john_main_process) - fprintf(stderr, "Error, path is too long in truecrypt_opencl::get_salt(), [%.10s...]\n", p); + fprintf_color(color_error, stderr, "Error, path is too long in truecrypt_opencl::get_salt(), [%.10s...]\n", p); error(); } memcpy(tpath, p, len); @@ -355,7 +355,7 @@ static void* get_salt(char *ciphertext) if (sz > MAX_KFILE_SZ) { if (john_main_process) - fprintf(stderr, "Error: keyfile '%s' is bigger than maximum size (MAX_KFILE_SZ is %d).\n", tpath, MAX_KFILE_SZ); + fprintf_color(color_error, stderr, "Error: keyfile '%s' is bigger than maximum size (MAX_KFILE_SZ is %d).\n", tpath, MAX_KFILE_SZ); error(); } diff --git a/src/opencl_tezos_fmt_plug.c b/src/opencl_tezos_fmt_plug.c index b16ca268ce..d09d1d56e9 100644 --- a/src/opencl_tezos_fmt_plug.c +++ b/src/opencl_tezos_fmt_plug.c @@ -231,6 +231,26 @@ static void done(void) } } +static void set_key(char *key, int index) +{ + size_t saved_len = strnlen(key, PLAINTEXT_LENGTH); + memcpy(host_pass[index].v, key, saved_len); + host_pass[index].length = saved_len; + new_keys = 1; + if (saved_len > max_key_length) + max_key_length = saved_len; +} + +static char *get_key(int index) +{ + static char ret[PLAINTEXT_LENGTH + 1]; + + memcpy(ret, host_pass[index].v, host_pass[index].length); + ret[host_pass[index].length] = 0; + + return ret; +} + static void set_salt(void *salt) { cur_salt = (struct custom_salt*)salt; @@ -264,11 +284,8 @@ static int crypt_all(int *pcount, struct db_salt *salt) BENCH_CLERROR(clFlush(queue[gpu_id]), "failed in clFlush"); } - static int warned; - if (!warned && 8 + cur_salt->email_length + max_key_length > 107) { - warned = 1; - fprintf(stderr, "Warning: over-long combination(s) of e-mail address and candidate password\n"); - } + if (8 + cur_salt->email_length + max_key_length > 107) + WARN_ONCE(color_warning, stderr, "Warning: over-long combination(s) of e-mail address and candidate password\n"); if (new_keys || ocl_autotune_running) { BENCH_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_in, CL_FALSE, 0, @@ -331,7 +348,7 @@ static int cmp_one(void *binary, int index) uint32_t magic = cracked[1 + index]; if (!magic || magic == 0x486954) return magic; - fprintf(stderr, FORMAT_LABEL ": Cracked something, but the magic 0x%08x is bad, skipping\n", magic); + fprintf_color(color_warning, stderr, FORMAT_LABEL ": Cracked something with password '%s', but the magic 0x%08x is bad, skipping\n", get_key(index), magic); return 0; } @@ -340,26 +357,6 @@ static int cmp_exact(char *source, int index) return 1; } -static void set_key(char *key, int index) -{ - size_t saved_len = strnlen(key, PLAINTEXT_LENGTH); - memcpy(host_pass[index].v, key, saved_len); - host_pass[index].length = saved_len; - new_keys = 1; - if (saved_len > max_key_length) - max_key_length = saved_len; -} - -static char *get_key(int index) -{ - static char ret[PLAINTEXT_LENGTH + 1]; - - memcpy(ret, host_pass[index].v, host_pass[index].length); - ret[host_pass[index].length] = 0; - - return ret; -} - struct fmt_main fmt_opencl_tezos = { { FORMAT_LABEL, diff --git a/src/opencl_wpapmk_fmt_plug.c b/src/opencl_wpapmk_fmt_plug.c index 827367136e..f58ed76421 100644 --- a/src/opencl_wpapmk_fmt_plug.c +++ b/src/opencl_wpapmk_fmt_plug.c @@ -209,7 +209,7 @@ static void init(struct fmt_main *_self) if ((t = strrchr(pf, '-'))) *t = 0; - fprintf(stderr, + fprintf_color(color_error, stderr, "The \"%s\" format takes hex keys of length 64 as input. Most normal\n" "cracking approaches does not make sense. You probably wanted to use the\n" "\"%s\" format (even for PMKID hashes).\n", diff --git a/src/options.c b/src/options.c index 70cba0a927..3cd102413d 100644 --- a/src/options.c +++ b/src/options.c @@ -419,9 +419,7 @@ void opt_init(char *name, int argc, char **argv) } exit(0); } else if (argc > 10000000 && !rec_restored) { - if (john_main_process) - fprintf(stderr, "Too many command-line arguments\n"); - error(); + error_msg_main("Too many command-line arguments\n"); } /* @@ -461,9 +459,7 @@ void opt_init(char *name, int argc, char **argv) options.flags |= FLG_MASK_SET; if ((options.flags & (FLG_TEST_CHK | FLG_NOTESTS)) == (FLG_TEST_CHK | FLG_NOTESTS) && !benchmark_time) { - if (john_main_process) - fprintf(stderr, "Can't run a self-test-only while also skipping self-test!\n"); - error(); + error_msg_main("Can't run a self-test-only while also skipping self-test!\n"); } #if HAVE_REXGEN @@ -483,8 +479,7 @@ void opt_init(char *name, int argc, char **argv) options.flags |= FLG_MASK_STACKED; if (!benchmark_time) { - fprintf(stderr, "Currently can't self-test with mask\n"); - error(); + error_msg_main("Currently can't self-test with mask\n"); } if (benchmark_time == 1) @@ -508,8 +503,7 @@ void opt_init(char *name, int argc, char **argv) !(options.flags & FLG_CRACKING_CHK)) options.flags |= FLG_REGEX_STACKED; else if (!(options.flags & FLG_CRACKING_CHK)) { - fprintf(stderr, "\\0 is only used with hybrid regex\n"); - error(); + error_msg_main("\\0 is only used with hybrid regex\n"); } } if (!(options.flags & FLG_REGEX_STACKED)) { @@ -567,9 +561,7 @@ void opt_init(char *name, int argc, char **argv) } } if (bad) { - fprintf(stderr, - "Invalid session name: all-digits suffix\n"); - error(); + error_msg_main("Invalid session name: all-digits suffix\n"); } #endif rec_name = options.session; @@ -580,19 +572,13 @@ void opt_init(char *name, int argc, char **argv) if (mpi_p > 1) { if (options.flags & FLG_RESTORE_CHK || rec_restored) { if (options.fork && options.fork != mpi_p) { - if (john_main_process) - fprintf(stderr, - "Node count in session file is %d.\n", - options.fork); - error(); + error_msg_main("Node count in session file is %d.\n", options.fork); } options.fork = 0; options.flags &= ~FLG_FORK; } else if (options.fork) { - if (john_main_process) - fprintf(stderr, "Can't use --fork with MPI.\n"); - error(); + error_msg_main("Can't use --fork with MPI.\n"); } } #endif @@ -621,7 +607,7 @@ void opt_init(char *name, int argc, char **argv) } if (options.catchup && options.max_cands) - error_msg("Can't combine --max-candidates and --catch-up options\n"); + error_msg_main("Can't combine --max-candidates and --catch-up options\n"); if (options.flags & FLG_STATUS_CHK) { #if OS_FORK @@ -677,10 +663,7 @@ void opt_init(char *name, int argc, char **argv) } dummy = strtok(NULL, ","); if (dummy) { - if (john_main_process) - fprintf(stderr, "max. %d different tunable cost parameters" - " supported\n", FMT_TUNABLE_COSTS); - error(); + error_msg_main("Max. %d different tunable cost parameters supported\n", FMT_TUNABLE_COSTS); } for ( i = 0; i < FMT_TUNABLE_COSTS; i++) { int negative; @@ -701,18 +684,12 @@ void opt_init(char *name, int argc, char **argv) &options.loader.min_cost[i], &options.loader.max_cost[i]) == 2) two_values = 1; if (two_values && negative) { - if (john_main_process) - fprintf(stderr, "Usage of negative --cost is not valid" - " for cost range (min:max)\n"); - error(); + error_msg_main("Usage of negative --cost is not valid for cost range (min:max)\n"); } if (!two_values) sscanf(range[i], "%u", &options.loader.min_cost[i]); if (negative && options.loader.min_cost[i] == 0) { - if (john_main_process) - fprintf(stderr, "Usage of negative --cost is not valid" - " for value 0\n"); - error(); + error_msg_main("Usage of negative --cost is not valid for value 0\n"); } if (!two_values) { if (negative) { @@ -724,9 +701,7 @@ void opt_init(char *name, int argc, char **argv) } } if (options.loader.max_cost[i] < options.loader.min_cost[i]) { - if (john_main_process) - fprintf(stderr, "Max. cost value must be >= min. cost value\n"); - error(); + error_msg_main("Max. cost value must be >= min. cost value\n"); } } } @@ -744,7 +719,7 @@ void opt_init(char *name, int argc, char **argv) if (strcmp(options.tune, "auto") && strcmp(options.tune, "report") && !isdec(options.tune)) - error_msg("Allowed arguments to --tune is auto, report or N, where N is a positive number"); + error_msg_main("Allowed arguments to --tune is auto, report or N, where N is a positive number"); } if (salts_str) { @@ -774,60 +749,37 @@ void opt_init(char *name, int argc, char **argv) else options.loader.max_pps = 0x7fffffff; } else if (options.loader.min_pps < 0) { - if (john_main_process) - fprintf(stderr, "Usage of negative -salt min " - "is not 'valid' if using Min and Max " - "salt range of values\n"); - error(); + error_msg_main("Usage of negative -salt min is not 'valid' if using Min and Max salt range of values\n"); } if (options.loader.min_pps > options.loader.max_pps) { - if (john_main_process) - fprintf(stderr, "Min number salts wanted is " - "less than Max salts wanted\n"); - error(); + error_msg_main("Min number salts wanted is less than Max salts wanted\n"); } } - if (john_main_process && options.flags & FLG_VERBOSITY && - (options.verbosity < 1 || options.verbosity > VERB_DEBUG)) { - fprintf(stderr, "Invalid --verbosity level, use 1-" - "%u (default %u) or %u for debug\n", - VERB_MAX, VERB_DEFAULT, VERB_DEBUG); - error(); + if (options.flags & FLG_VERBOSITY && (options.verbosity < 1 || options.verbosity > VERB_DEBUG)) { + error_msg_main("Invalid --verbosity level, use 1-%u (default %u) or %u for debug\n", VERB_MAX, VERB_DEFAULT, VERB_DEBUG); } if (options.length < 0) options.length = MAX_PLAINTEXT_LENGTH; else if (options.length < 1 || options.length > MAX_PLAINTEXT_LENGTH) { - if (john_main_process) - fprintf(stderr, "Invalid plaintext length requested\n"); - error(); + error_msg_main("Invalid plaintext length requested\n"); } if (options.req_length) { if (!rec_restored && (options.req_minlength != -1 || options.req_maxlength != 0)) { - if (john_main_process) - fprintf(stderr, "Invalid options: --length can't be used together with --min/max-length\n"); - error(); + error_msg_main("Invalid options: --length can't be used together with --min/max-length\n"); } options.req_minlength = options.req_maxlength = options.req_length; } if (options.req_maxlength && options.req_maxlength < options.req_minlength) { - if (john_main_process) - fprintf(stderr, "Invalid options: --min-length larger " - "than --max-length\n"); - error(); + error_msg_main("Invalid options: --min-length larger than --max-length\n"); } if (options.req_maxlength < 0 || options.req_maxlength > MAX_PLAINTEXT_LENGTH) { - if (john_main_process) - fprintf(stderr, "Invalid max length requested\n"); - error(); + error_msg_main("Invalid max length requested\n"); } if (options.force_maxkeys != 0 && options.force_maxkeys < 1) { - if (john_main_process) - fprintf(stderr, - "Invalid options: --mkpc must be at least 1\n"); - error(); + error_msg_main("Invalid options: --mkpc must be at least 1\n"); } /* @@ -848,8 +800,7 @@ void opt_init(char *name, int argc, char **argv) #if OS_FORK if ((options.flags & FLG_FORK) && (options.fork < 2 || options.fork > 1024)) { - fprintf(stderr, "--fork number must be between 2 and 1024\n"); - error(); + error_msg_main("--fork number must be between 2 and 1024\n"); } #endif @@ -897,10 +848,7 @@ void opt_init(char *name, int argc, char **argv) range == options.node_count) msg = "node numbers can't span the whole range"; if (msg) { - if (john_main_process) - fprintf(stderr, "Invalid node specification: %s: %s\n", - options.node_str, msg); - error(); + error_msg_main("Invalid node specification: %s: %s\n", options.node_str, msg); } #if OS_FORK } else if (options.fork) { @@ -953,14 +901,11 @@ void opt_init(char *name, int argc, char **argv) if (options.v_width != 1 && options.v_width != 2 && options.v_width != 3 && options.v_width != 4 && options.v_width != 8 && options.v_width != 16) { - if (john_main_process) - fprintf(stderr, "Vector width must be one of" - " 1, 2, 3, 4, 8 or 16\n"); - error(); + error_msg_main("Vector width must be one of 1, 2, 3, 4, 8 or 16\n"); } if (options.v_width == 3 && john_main_process) - fprintf(stderr, "Warning: vector width 3 is not " - "expected to work well with all formats\n"); + fprintf_color(color_warning, stderr, + "Warning: vector width 3 is not expected to work well with all formats\n"); } #endif /* @@ -970,17 +915,11 @@ void opt_init(char *name, int argc, char **argv) if (!(options.subformat && !strcasecmp(options.subformat, "list")) && (!options.listconf)) if ((options.flags & (FLG_PASSWD | FLG_PWD_REQ)) == FLG_PWD_REQ) { - if (john_main_process) - fprintf(stderr, "Password files required, " - "but none specified\n"); - error(); + error_msg_main("Password files required, but none specified\n"); } if ((options.flags & (FLG_PASSWD | FLG_PWD_SUP)) == FLG_PASSWD) { - if (john_main_process) - fprintf(stderr, "Password files specified, " - "but no option would use them\n"); - error(); + error_msg_main("Password files specified, but no option would use them\n"); } if ( (options.flags & FLG_SHOW_CHK) && show_uncracked_str) { @@ -1003,9 +942,8 @@ void opt_init(char *name, int argc, char **argv) options.loader.showinvalid = 1; } else { - fprintf(stderr, "Invalid option in --show switch. Valid options:\n" + error_msg_main("Invalid option in --show switch. Valid options:\n" "--show, --show=left, --show=formats, --show=types, --show=invalid\n"); - error(); } } @@ -1036,7 +974,7 @@ void opt_init(char *name, int argc, char **argv) if (!options.format) options.format = s; else if (strcmp(options.format, s)) - error_msg("Error: --regen-lost-salts parameter not matching --format option\n"); + error_msg_main("Error: --regen-lost-salts parameter not matching --format option\n"); } } @@ -1053,29 +991,18 @@ void opt_init(char *name, int argc, char **argv) sscanf(&field_sep_char_str[2], "%x", &xTmp); if (!xTmp || xTmp > 255) { - if (john_main_process) - fprintf(stderr, "trying to use an " - "invalid field separator char:" - " %s\n", - field_sep_char_str); - error(); + error_msg_main("Trying to use an invalid field separator char: %s\n",field_sep_char_str); } options.loader.field_sep_char = (char)xTmp; } else { - if (john_main_process) - fprintf(stderr, "trying to use an " - "invalid field separator char:" - " %s (must be single byte " - "character)\n", - field_sep_char_str); - error(); + error_msg_main("Trying to use an invalid field separator char: %s (must be single byte character)\n", field_sep_char_str); } if (options.loader.field_sep_char != ':') if (john_main_process) - fprintf(stderr, "using field sep char '%c' " - "(0x%02x)\n", options.loader.field_sep_char, - options.loader.field_sep_char); + fprintf_color(color_notice, stderr, "using field separator char '%c' (0x%02x)\n", + options.loader.field_sep_char, + options.loader.field_sep_char); } rec_argc = argc; rec_argv = argv; diff --git a/src/oracle_fmt_plug.c b/src/oracle_fmt_plug.c index 746d10b569..c9334baded 100644 --- a/src/oracle_fmt_plug.c +++ b/src/oracle_fmt_plug.c @@ -33,6 +33,7 @@ john_register_one(&fmt_oracle); #include "common.h" #include "formats.h" #include "unicode.h" +#include "john.h" #define FORMAT_LABEL "oracle" #define FORMAT_NAME "Oracle 10" @@ -135,14 +136,12 @@ static int valid(char *ciphertext, struct fmt_main *self) len = enc_to_utf16(name16, MAX_USERNAME_LEN + 1, (UTF8*)name, strlen(name)); if (len < 0) { - static int error_shown = 0; #ifdef HAVE_FUZZ if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK)) return 0; #endif - if (!error_shown) - fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); - error_shown = 1; + if (john_main_process) + WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label); return 0; } if (len > MAX_USERNAME_LEN) diff --git a/src/pdf_fmt_plug.c b/src/pdf_fmt_plug.c index 1fe5cd4b5a..5fa7324d16 100644 --- a/src/pdf_fmt_plug.c +++ b/src/pdf_fmt_plug.c @@ -283,7 +283,7 @@ static void pdf_compute_user_password(unsigned char *password, unsigned char *o log_event("+ RC4 key: %s", h_key); if (options.verbosity > VERB_DEFAULT) - fprintf(stderr, "+ RC4 key: %s\n", h_key); + fprintf_color(color_notice, stderr, "+ RC4 key: %s\n", h_key); } } diff --git a/src/pem_common_plug.c b/src/pem_common_plug.c index 6b97a467fd..beffeb943d 100644 --- a/src/pem_common_plug.c +++ b/src/pem_common_plug.c @@ -18,6 +18,8 @@ #include "jumbo.h" #include "aes.h" #include "asn1.h" +#include "loader.h" +#include "john.h" // $PEM$type$cipher$$salt$iterations$iv$blob_length$blob // type, and cipher should be enough for all possible combinations struct fmt_tests pem_tests[] = { @@ -39,7 +41,6 @@ struct fmt_tests pem_tests[] = { int pem_valid(char *ciphertext, struct fmt_main *self) { - static int kdf_warned, prf_warned; char *ctcopy, *keeptr, *p; int len, value, extra; @@ -56,18 +57,14 @@ int pem_valid(char *ciphertext, struct fmt_main *self) if ((p = strtokm(NULL, "$")) == NULL) goto err; if (strcmp(p, "pbkdf2") != 0) { - if (!self_test_running && !kdf_warned) { - fprintf(stderr, "Warning: %s kdf algorithm <%s> is not supported currently!\n", self->params.label, p); - kdf_warned = 1; - } + if (!ldr_in_pot && !self_test_running && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: %s kdf algorithm <%s> is not supported currently!\n", self->params.label, p); goto err; } if ((p = strtokm(NULL, "$")) == NULL) goto err; - if (!self_test_running && !prf_warned) { - fprintf(stderr, "Warning: %s prf algorithm <%s> is not supported currently!\n", self->params.label, p); - prf_warned = 1; - } + if (!ldr_in_pot && !self_test_running && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: %s prf algorithm <%s> is not supported currently!\n", self->params.label, p); goto err; } if (!isdec(p)) diff --git a/src/pkzip.c b/src/pkzip.c index 0b81f922e6..e6a9c30070 100644 --- a/src/pkzip.c +++ b/src/pkzip.c @@ -60,7 +60,8 @@ int winzip_common_valid(char *ciphertext, struct fmt_main *self) if (!strncmp(ciphertext, "$zip$", 5)) { if (!old_warn) - fprintf(stderr, "Warning, Older unhandled WinZip format hash seen. This hash can not be processed\n"); + fprintf_color(color_warning, stderr, + "Warning, Older unhandled WinZip format hash seen. This hash can not be processed\n"); old_warn = 1; return 0; } diff --git a/src/pp.c b/src/pp.c index ea7142a6f8..83d29ae278 100644 --- a/src/pp.c +++ b/src/pp.c @@ -1,5 +1,5 @@ /* - * Implementation in John the Ripper Copyright (c) 2015, magnum + * Implementation in John the Ripper Copyright (c) 2015-2026, magnum * This software is hereby released to the general public under * the following terms: Redistribution and use in source and binary * forms, with or without modification, are permitted. @@ -934,16 +934,14 @@ static int get_bits(mpz_t *op) */ static MAYBE_INLINE char *check_bom(char *string) { - static int warned; - if (((unsigned char*)string)[0] < 0xef) return string; if (!memcmp(string, "\xEF\xBB\xBF", 3)) string += 3; if (options.input_enc == UTF_8 && (!memcmp(string, "\xFE\xFF", 2) || !memcmp(string, "\xFF\xFE", 2))) { - if (john_main_process && !warned++) - fprintf(stderr, "Warning: UTF-16 BOM seen in wordlist.\n"); + if (john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: UTF-16 BOM seen in wordlist.\n"); string += 2; } return string; @@ -1220,7 +1218,7 @@ void do_prince_crack(struct db_main *db, const char *wordlist, int rules) log_event("! MaxLen = %d is too large for this hash type", pw_max); if (john_main_process) - fprintf(stderr, "Warning: MaxLen = %d is too large " + fprintf_color(color_warning, stderr, "Warning: MaxLen = %d is too large " "for the current hash type, reduced to %d\n", pw_max, our_fmt_len); @@ -1574,11 +1572,11 @@ void do_prince_crack(struct db_main *db, const char *wordlist, int rules) if (options.input_enc == UTF_8) { if (!valid_utf8((UTF8*)line)) { warn = 0; - fprintf(stderr, "Warning: invalid UTF-8 seen reading %s\n", wordlist); + fprintf_color(color_warning, stderr, "Warning: invalid UTF-8 seen reading %s\n", wordlist); } } else if (line != input_buf || valid_utf8((UTF8*)line) > 1) { warn = 0; - fprintf(stderr, "Warning: UTF-8 seen reading %s\n", wordlist); + fprintf_color(color_warning, stderr, "Warning: UTF-8 seen reading %s\n", wordlist); } } diff --git a/src/rar_common.h b/src/rar_common.h index bb07a24bcb..eba6bb136f 100644 --- a/src/rar_common.h +++ b/src/rar_common.h @@ -36,10 +36,6 @@ static unsigned char *aes_iv; #define FORMAT_TAG "$RAR3$*" #define FORMAT_TAG_LEN (sizeof(FORMAT_TAG)-1) -#define YEL "\x1b[0;33m" -#define RED "\x1b[0;31m" -#define NRM "\x1b[0m" - static struct fmt_tests cpu_tests[] = { {"$RAR3$*0*b109105f5fe0b899*d4f96690b1a8fe1f120b0290a85a2121", "test"}, {"$RAR3$*0*42ff7e92f24fb2f8*9d8516c8c847f1b941a0feef064aaf0d", "1234"}, @@ -298,12 +294,12 @@ static void *get_binary(char *ciphertext) #endif if (options.verbosity > VERB_DEFAULT && john_main_process && !ldr_in_pot && !bench_or_test_running) { if (file->method == 0x30) { - fprintf(stderr, YEL "%.32s(...) 0x30 size %"PRIu64", pad size %d\n" NRM, + fprintf_color(color_warning, stderr, "%.32s(...) 0x30 size %"PRIu64", pad size %d\n", ciphertext, file->unp_size, (int)(16 - (file->unp_size & 15)) & 15); } else if (file->type == 0) - fprintf(stderr, YEL "%.32s(...) solid\n" NRM, ciphertext); + fprintf_color(color_warning, stderr, "%.32s(...) solid\n", ciphertext); else - fprintf(stderr, YEL "%.32s(...) 0x%02x size %"PRIu64" unp_size %"PRIu64"\n" NRM, ciphertext, file->method, file->pack_size, file->unp_size); + fprintf_color(color_warning, stderr, "%.32s(...) 0x%02x size %"PRIu64" unp_size %"PRIu64"\n", ciphertext, file->method, file->pack_size, file->unp_size); } @@ -437,10 +433,8 @@ static int valid(char *ciphertext, struct fmt_main *self) goto error; #if !HAVE_UNRAR if (atoi(ptr) != 30) { - static int warned; - - if (!warned++ && john_main_process) - fprintf(stderr, "Warning: Packed RAR hash(es) seen but ignored, this build does not support them.\n"); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: Packed RAR hash(es) seen but ignored, this build does not support them.\n"); goto error; } #endif @@ -556,7 +550,7 @@ static MAYBE_INLINE int check_huffman(unsigned char *next) { HUFFMAN_FAIL: #ifdef DEBUG - fprintf(stderr, RED "failed early reject checks for Huffman encoding\n" NRM); + fprintf_color(color_error, stderr, "failed early reject checks for Huffman encoding\n"); #endif return 0; } @@ -643,7 +637,7 @@ inline static void check_rar(rar_file *cur_file, int index, unsigned char *key, if (!(plain[0] & 0x20) || // Reset bit must be set (plain[1] & 0x80)) { // MaxMB must be < 128 #ifdef DEBUG - fprintf(stderr, RED "failed PPM early reject check\n" NRM); + fprintf_color(color_error, stderr, "failed PPM early reject check\n"); #endif cracked[index] = 0; return; @@ -653,7 +647,7 @@ inline static void check_rar(rar_file *cur_file, int index, unsigned char *key, if ((plain[0] & 0x40) || // KeepOldTable can't be set !check_huffman(plain)) { // Huffman table check #ifdef DEBUG - fprintf(stderr, RED "failed LZ early reject check\n" NRM); + fprintf_color(color_error, stderr, "failed LZ early reject check\n"); #endif cracked[index] = 0; return; @@ -678,15 +672,15 @@ inline static void check_rar(rar_file *cur_file, int index, unsigned char *key, cracked[index] = !memcmp(&unpack_t->unp_crc, &cur_file->crc.c, 4); #ifdef DEBUG if (!cracked[index]) - fprintf(stderr, RED "'%s' passed unpack29 but failed CRC, %08x != %08x\n" NRM, get_key(index), ~JOHNSWAP(unpack_t->unp_crc), ~JOHNSWAP(cur_file->crc.w)); + fprintf_color(color_error, stderr, "'%s' passed unpack29 but failed CRC, %08x != %08x\n", get_key(index), ~JOHNSWAP(unpack_t->unp_crc), ~JOHNSWAP(cur_file->crc.w)); #endif } else { cracked[index] = 0; #ifdef DEBUG if (!memcmp(&unpack_t->unp_crc, &cur_file->crc.c, 4)) - fprintf(stderr, RED "Note: '%s' failed unpack29 yet passed CRC check (%08x)\n" NRM, get_key(index), ~JOHNSWAP(unpack_t->unp_crc)); + fprintf_color(color_error, stderr, "Note: '%s' failed unpack29 yet passed CRC check (%08x)\n", get_key(index), ~JOHNSWAP(unpack_t->unp_crc)); else - fprintf(stderr, RED "failed unpack29\n" NRM); + fprintf_color(color_error, stderr, "failed unpack29\n"); #endif } } diff --git a/src/regex.c b/src/regex.c index 7f1772c9ee..eb8c014d6a 100644 --- a/src/regex.c +++ b/src/regex.c @@ -77,7 +77,7 @@ int rexgen_restore_state_hybrid(const char *sig, FILE *file) if (ret != 1) return 1; restore_str = mem_alloc_tiny(len+2, 8); fgetl(restore_str, len+1, file); - log_event("resuming a regex expr or %s and state of %s\n", restore_regex, restore_str); + log_event("- Resuming a regex expr of %s and state of %s\n", restore_regex, restore_str); return 0; } return 1; @@ -131,7 +131,7 @@ static void rexgen_setlocale() if (ret) fprintf(stderr, "regex: Locale set to %s\n", ret); else - fprintf(stderr, "regex: Failed to set locale \"%s\"\n", john_locale); + fprintf_color(color_warning, stderr, "regex: Failed to set locale \"%s\"\n", john_locale); } } @@ -185,7 +185,7 @@ void SetupAlpha(const char *regex_alpha) } void parser_error(const char* msg) { - fprintf(stderr, "%s\n", msg); + fprintf_color(color_error, stderr, "Error in regex: %s\n", msg); } int do_regex_hybrid_crack(struct db_main *db, const char *regex, @@ -225,10 +225,8 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex, regex_ptr = c_regex_cb_mb(regex, callback, parser_error); if (!regex_ptr) { c_simplestring_delete(buffer); - fprintf(stderr, - "Error, invalid regex expression. John exiting now base_word=%s Regex= %s\n", + error_msg_main("Error: invalid regex expression. Base_word=%s Regex=%s\n", base_word, regex); - error(); } iter = c_regex_iterator(regex_ptr); @@ -250,7 +248,7 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex, } *cp = 0; #if DEBUG - fprintf(stderr, "buf=%s\n", Buf); + fprintf_color(color_notice, stderr, "buf=%s\n", Buf); #endif if (*regex == 0) regex = Buf; @@ -339,9 +337,7 @@ void do_regex_crack(struct db_main *db, const char *regex) regex_ptr = c_regex_cb_mb(regex, callback, parser_error); if (!regex_ptr) { - fprintf(stderr, - "Error, invalid regex expression. John exiting now\n"); - error(); + error_msg_main("Error: invalid regex expression\n"); } if (rec_restored && john_main_process) { @@ -435,11 +431,9 @@ char *prepare_regex(char *regex, int *bCase, char **regex_alpha) if (*regex == '=') ++regex; if (!strstr(regex, "\\0") && !(*regex_alpha)) { - fprintf(stderr, - "--regex need to contain \"\\0\" in hybrid mode (or an alpha option)\n"); - error(); + error_msg_main("Error: Regex need to contain \"\\0\" in hybrid mode (or an alpha option)\n"); } else { - log_event("- Rexgen (after rules): %s", regex); + log_event("- Regex (after rules): %s", regex); } return regex; } diff --git a/src/restic_fmt_plug.c b/src/restic_fmt_plug.c index b6d92b1272..eb48fddbc4 100644 --- a/src/restic_fmt_plug.c +++ b/src/restic_fmt_plug.c @@ -314,11 +314,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); + fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed)); error(); } diff --git a/src/rpp.c b/src/rpp.c index b66e280304..1da4396065 100644 --- a/src/rpp.c +++ b/src/rpp.c @@ -59,7 +59,7 @@ int rpp_init(struct rpp_context *ctx, const char *subsection) while (cp) { struct cfg_line *lp; if ((list = cfg_get_list(SECTION_RULES, cp)) == NULL) { - fprintf(stderr, "\"%s\" not found; ", cp); + fprintf_color(color_error, stderr, "\"%s\" not found\n", cp); return 1; } lp = list->head; @@ -134,10 +134,7 @@ static void rpp_process_rule(struct rpp_context *ctx) if (strlen(conv) == strlen8(input)) strcpy(ctx->input->data, conv); /* Always shorter than original */ else { - static int warned; - - if (!warned++) - log_event("- Rule preprocessor: Rejected rule(s) not fitting current internal codepage"); + LOG_ONCE("- Rule preprocessor: Rejected rule(s) not fitting current internal codepage"); input[1] = '-'; } } diff --git a/src/sapB_fmt_plug.c b/src/sapB_fmt_plug.c index c10e9a9494..1ac2bb5fc8 100644 --- a/src/sapB_fmt_plug.c +++ b/src/sapB_fmt_plug.c @@ -198,10 +198,8 @@ static struct saltstruct { static void init(struct fmt_main *self) { - static int warned = 0; - - if (options.target_enc == UTF_8 && !options.listconf && warned++ == 0) - fprintf(stderr, "Warning: SAP-B format should never be UTF-8.\nUse --target-encoding=iso-8859-1 or whatever is applicable.\n"); + if (options.target_enc == UTF_8 && !options.listconf) + WARN_ONCE(color_warning, stderr, "Warning: SAP-B format should never be UTF-8.\nUse --target-encoding=iso-8859-1 or whatever is applicable.\n"); half_hashes = cfg_get_bool(SECTION_OPTIONS, NULL, "SAPhalfHashes", 0); diff --git a/src/sapH_fmt_plug.c b/src/sapH_fmt_plug.c index 4f3beab7f8..77a13c16f5 100644 --- a/src/sapH_fmt_plug.c +++ b/src/sapH_fmt_plug.c @@ -38,6 +38,8 @@ john_register_one(&fmt_sapH); #include "sha.h" #include "sha2.h" #include "johnswap.h" +#include "loader.h" +#include "john.h" /* * Assumption is made that SIMD_COEF_32*SIMD_PARA_SHA1 is >= than @@ -200,11 +202,8 @@ static int valid(char *ciphertext, struct fmt_main *self) if (len < 1) goto err; if (len > SALT_LENGTH) { - static int warned; - if (!warned) { - fprintf(stderr, "Warning: " FORMAT_LABEL " salt longer than max supported\n"); - warned = 1; - } + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: " FORMAT_LABEL " salt longer than max supported\n"); goto err; } diff --git a/src/scrypt_fmt.c b/src/scrypt_fmt.c index 11cb2c9fa8..242c3dc56e 100644 --- a/src/scrypt_fmt.c +++ b/src/scrypt_fmt.c @@ -456,11 +456,11 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (failed) { #ifdef _OPENMP if (failed < 0) { - fprintf(stderr, "OpenMP thread number out of range\n"); + fprintf_color(color_error, stderr, "OpenMP thread number out of range\n"); error(); } #endif - fprintf(stderr, "scrypt failed: %s\n", strerror(failed)); + fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed)); error(); } diff --git a/src/single.c b/src/single.c index 1b156ca9ed..a6fb034c2b 100644 --- a/src/single.c +++ b/src/single.c @@ -200,7 +200,7 @@ static void single_init(void) fprintf(stderr, "Will not try cracked passwords against other salts\n"); if (options.seed_per_user && !retest_guessed && option_retest == -1) - fprintf(stderr, "Note: You might want --single-retest-guess when using --single-user-seed\n"); + fprintf_color(color_notice, stderr, "Note: You might want --single-retest-guess when using --single-user-seed\n"); } if ((words_pair_max = options.single_pair_max) < 0) @@ -267,7 +267,7 @@ static void single_init(void) if (key_count < single_db->format->params.min_keys_per_crypt) { if (john_main_process) { - fprintf(stderr, + fprintf_color(color_notice, stderr, "Note: Performance for this format/device may be lower due to single mode\n" " constraints. Format wanted %d keys per crypt but was limited to %d.\n", single_db->format->params.min_keys_per_crypt, @@ -302,7 +302,7 @@ static void single_init(void) if (length < options.eff_maxlength) { if (john_main_process) - fprintf(stderr, + fprintf_color(color_notice, stderr, "Note: Max. length decreased from %d to %d due to single mode buffer size\n" " limit of %sB (%sB needed). Use --max-length=N option to override, or\n" " increase SingleMaxBufferSize in john.conf (if you have enough RAM).\n", @@ -320,7 +320,7 @@ static void single_init(void) if (my_buf_share && calc_buf_size(length, key_count) > my_buf_share) { if (john_main_process) { - fprintf(stderr, + fprintf_color(color_notice, stderr, "Note: Can't run single mode with this many salts due to single mode buffer\n" " size limit of %sB (%d keys per batch would use %sB, decreased to\n" " %d for %sB). To work around this, increase SingleMaxBufferSize in\n" @@ -349,7 +349,7 @@ static void single_init(void) if (key_count < lim_kpc) { if (john_main_process) { - fprintf(stderr, + fprintf_color(color_notice, stderr, "Note: Performance for this many salts may be lower due to single mode buffer\n" " size limit of %sB (%d keys per batch would use %sB, decreased to\n" " %d for %sB). To work around this, ", @@ -359,10 +359,10 @@ static void single_init(void) key_count, human_prefix(calc_buf_size(length, key_count))); if (options.eff_maxlength > 8) - fprintf(stderr, "%s --max-length and/or ", + fprintf_color(color_notice, stderr, "%s --max-length and/or ", options.req_maxlength ? "decrease" : "use"); - fprintf(stderr, + fprintf_color(color_notice, stderr, "increase%sSingleMaxBufferSize in john.conf.\n", options.eff_maxlength > 8 ? "\n " : " "); } @@ -383,7 +383,7 @@ static void single_init(void) log_event("! No \"%s\" mode rules found", options.activesinglerules); if (john_main_process) - fprintf(stderr, "No \"%s\" mode rules found in %s\n", + fprintf_color(color_error, stderr, "No \"%s\" mode rules found in %s\n", options.activesinglerules, cfg_name); error(); } @@ -584,7 +584,7 @@ static int single_process_buffer(struct db_salt *salt) if (retest_guessed && ++recurse_depth > max_recursion) { log_event("- Disabled SingleRetestGuessed due to deep recursion"); if (john_main_process) - fprintf(stderr, + fprintf_color(color_warning, stderr, "Warning: Disabled SingleRetestGuessed due to deep recursion. You can run\n" " '--loopback --rules=none' later on instead.\n"); @@ -948,9 +948,9 @@ void do_single_crack(struct db_main *db) if (john_main_process && db->salt_count > 1 && status.guess_count && !retest_guessed) { if (single_disabled_recursion) - fprintf(stderr, "Warning: Disabled SingleRetestGuessed due to deep recursion. Consider running '--loopback --rules=none' next.\n"); + fprintf_color(color_warning, stderr, "Warning: Disabled SingleRetestGuessed due to deep recursion. Consider running '--loopback --rules=none' next.\n"); else - fprintf(stderr, "Consider running '--loopback --rules=none' next.\n"); + fprintf_color(color_notice, stderr, "Consider running '--loopback --rules=none' next.\n"); } return; } diff --git a/src/ssh_common_plug.c b/src/ssh_common_plug.c index c6a2952b19..70184cc009 100644 --- a/src/ssh_common_plug.c +++ b/src/ssh_common_plug.c @@ -11,6 +11,8 @@ #include "arch.h" #include "misc.h" #include "common.h" +#include "john.h" +#include "loader.h" #include "ssh_common.h" int ssh_valid(char *ciphertext, struct fmt_main *self) @@ -52,8 +54,9 @@ int ssh_valid(char *ciphertext, struct fmt_main *self) goto err; if (cipher < 0 || cipher > 6) { - fprintf(stderr, "%s: Cipher value of %d is not supported\n", - self->params.label, cipher); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: Cipher value of %d is not supported\n", + self->params.label, cipher); goto err; } @@ -76,15 +79,17 @@ int ssh_valid(char *ciphertext, struct fmt_main *self) #if !HAVE_LIBCRYPTO if (!strcasestr(self->params.label, "-opencl") && (cipher == 0 || cipher == 7)) { - fprintf(stderr, "%s: [3]DES is not supported in this build (need OpenSSL)\n", - self->params.label); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: [3]DES is not supported in this build (need OpenSSL)\n", + self->params.label); goto err; } #endif if (strcasestr(self->params.label, "-opencl") && (cipher == 2 || cipher == 6)) { - fprintf(stderr, "%s: Cipher value of %d is not yet supported with OpenCL\n", - self->params.label, cipher); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "%s: Cipher value of %d is not yet supported with OpenCL\n", + self->params.label, cipher); goto err; } diff --git a/src/status.c b/src/status.c index fda149fabe..6102917046 100644 --- a/src/status.c +++ b/src/status.c @@ -329,7 +329,10 @@ static void status_print_cracking(char *p, double percent) if (john_main_process && status.guess_count > last_count && cfg_get_bool(SECTION_OPTIONS, NULL, "ShowRemainOnStatus", 0)) { - n = sprintf(p, "%s\n", crk_loaded_counts()); + n = sprintf(p, "%s%s%s\n", + isatty(fileno(stderr)) ? color_notice : color_none, + crk_loaded_counts(), + isatty(fileno(stderr)) ? color_end : color_none); if (n > 0) p += n; status_update_counts(); @@ -478,7 +481,7 @@ void status_print(int level) suppressor_time -= status.suppressor_start_time; fprintf(stderr, "%s" - "Remaining hashes %u (%u removed)\n" + "%sRemaining hashes %u (%u removed)\n" "Remaining salts %u (%u removed)\n" "Time in seconds %.2f (%.2f new)\n" "Successful guesses %u (%u new, %s g/s)\n" @@ -488,8 +491,9 @@ void status_print(int level) " rejected %llu (%.2f%%, %s p/s)\n" " out of total %llu (%s p/s)\n" "Hash computations %llu (%llu new, %s c/s)\n" - "Hash combinations %s (%s new, %s C/s)\n", + "Hash combinations %s (%s new, %s C/s)%s\n", s_line, + isatty(fileno(stderr)) ? color_notice : color_none, status.password_count, prev.password_count ? prev.password_count - status.password_count : 0, status.salt_count, prev.salt_count ? prev.salt_count - status.salt_count : 0, time, new_time, @@ -508,7 +512,8 @@ void status_print(int level) status_get_cps(s_crypts_ps, status.crypts - prev.crypts, 0, new_time), status_get_c(s_combs, status.combs, status.combs_ehi), status.combs_ehi ? "N/A" : status_get_c(s_combs_new, status.combs - prev.combs, 0), - status.combs_ehi ? "N/A" : status_get_cps(s_combs_ps, status.combs - prev.combs, 0, new_time)); + status.combs_ehi ? "N/A" : status_get_cps(s_combs_ps, status.combs - prev.combs, 0, new_time), + isatty(fileno(stderr)) ? color_end : color_none); prev = status; prev_time = time; } diff --git a/src/subsets.c b/src/subsets.c index 7001e4f774..6c5dc05ca4 100644 --- a/src/subsets.c +++ b/src/subsets.c @@ -1,5 +1,5 @@ /* - * This software is Copyright (c) 2018 magnum + * This software is Copyright (c) 2018-2026 magnum * and is hereby released to the general public under the following terms: * Redistribution and use in source and binary forms, with or without * modification, are permitted. @@ -227,7 +227,6 @@ static void remove_dupes(UTF32 *string) /* Parse \U+HHHH and \U+HHHHH notation to characters, in place. */ static void parse_unicode(char *string) { - static int warned; unsigned char *s = (unsigned char*)string; unsigned char *d = s; @@ -249,9 +248,9 @@ static void parse_unicode(char *string) wc[0] = (atoi16[s[3]] << 16) + (atoi16[s[4]] << 12) + (atoi16[s[5]] << 8) + (atoi16[s[6]] << 4) + atoi16[s[7]]; wc[1] = 0; - if (!wc[0] && !warned++ && john_main_process) - fprintf(stderr, - "Warning: \\U+00000 in mask terminates the string\n"); + if (!wc[0] && john_main_process) + WARN_ONCE(color_warning, stderr, + "Warning: \\U+00000 in mask terminates the string\n"); if (wc[0] == '\\') *d++ = '\\'; @@ -270,9 +269,9 @@ static void parse_unicode(char *string) wc[0] = (atoi16[s[3]] << 12) + (atoi16[s[4]] << 8) + (atoi16[s[5]] << 4) + atoi16[s[6]]; wc[1] = 0; - if (!wc[0] && !warned++ && john_main_process) - fprintf(stderr, - "Warning: \\U+0000 in mask terminates the string\n"); + if (!wc[0] && john_main_process) + WARN_ONCE(color_warning, stderr, + "Warning: \\U+0000 in mask terminates the string\n"); if (wc[0] == '\\') *d++ = '\\'; @@ -478,7 +477,7 @@ int do_subsets_crack(struct db_main *db, char *req_charset) if (options.eff_minlength > maxlength) { if (john_main_process) - fprintf(stderr, "Subsets: Too large min. length\n"); + fprintf_color(color_error, stderr, "Subsets: Too large min. length\n"); error(); } @@ -520,7 +519,7 @@ int do_subsets_crack(struct db_main *db, char *req_charset) else if (options.input_enc == UTF_8) { if (!valid_utf8((UTF8*)charset)) { if (john_main_process) - fprintf(stderr, "Error in Unicode conversion. " + fprintf_color(color_error, stderr, "Error in Unicode conversion. " "Ensure --input-encoding is correct\n"); error(); } else { @@ -548,7 +547,7 @@ int do_subsets_crack(struct db_main *db, char *req_charset) if (required >= charcount) { if (john_main_process) - fprintf(stderr, "Error, required part of charset must be smaller " + fprintf_color(color_error, stderr, "Error, required part of charset must be smaller " "than charset (1..%d out of %d)\n", charcount - 1, charcount); error(); diff --git a/src/telegram_common_plug.c b/src/telegram_common_plug.c index 46a7a5c783..6cbef4cd32 100644 --- a/src/telegram_common_plug.c +++ b/src/telegram_common_plug.c @@ -165,10 +165,8 @@ int telegram_valid(char *ciphertext, struct fmt_main *self) if (version != 1 && version != 2) goto err; if (version == 2 && strstr(self->params.label, "-opencl")) { - static int warned; - - if (john_main_process && !warned++) - fprintf(stderr, "Warning: Telegram-opencl currently doesn't support v2 hashes.\n"); + if (!ldr_in_pot && john_main_process) + WARN_ONCE(color_warning, stderr, "Warning: Telegram-opencl currently doesn't support v2 hashes.\n"); goto err; } if ((p = strtokm(NULL, "*")) == NULL) // rounds diff --git a/src/tezos_fmt_plug.c b/src/tezos_fmt_plug.c index 10671a981f..a47b0d645c 100644 --- a/src/tezos_fmt_plug.c +++ b/src/tezos_fmt_plug.c @@ -155,7 +155,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) #endif { warned = 1; - fprintf(stderr, + fprintf_color(color_warning, stderr, "Warning: over-long combination(s) of e-mail address and candidate password\n"); } } diff --git a/src/truecrypt_fmt_plug.c b/src/truecrypt_fmt_plug.c index a1b18a7b74..118f9e474f 100644 --- a/src/truecrypt_fmt_plug.c +++ b/src/truecrypt_fmt_plug.c @@ -312,7 +312,7 @@ static void* get_salt(char *ciphertext) s->num_iterations = 1000; } else { // should never get here! valid() should catch all lines that do not have the tags. - fprintf(stderr, "Error, unknown type in truecrypt::get_salt(), [%s]\n", ciphertext); + fprintf_color(color_error, stderr, "Error, unknown type in truecrypt::get_salt(), [%s]\n", ciphertext); error(); } @@ -343,7 +343,7 @@ static void* get_salt(char *ciphertext) if (len > sizeof(tpath) - 1) { // should never get here! valid() should catch all lines with overly long paths if (john_main_process) - fprintf(stderr, "Error, path is too long in truecrypt::get_salt(), [%.10s...]\n", p); + fprintf_color(color_error, stderr, "Error, path is too long in truecrypt::get_salt(), [%.10s...]\n", p); error(); } memcpy(tpath, p, len); @@ -365,7 +365,7 @@ static void* get_salt(char *ciphertext) if (sz > MAX_KFILE_SZ) { if (john_main_process) - fprintf(stderr, "Error: keyfile '%s' is bigger than maximum size (MAX_KFILE_SZ is %d).\n", tpath, MAX_KFILE_SZ); + fprintf_color(color_error, stderr, "Error: keyfile '%s' is bigger than maximum size (MAX_KFILE_SZ is %d).\n", tpath, MAX_KFILE_SZ); error(); } diff --git a/src/unique.c b/src/unique.c index cfbd53e716..c411b04330 100644 --- a/src/unique.c +++ b/src/unique.c @@ -2,7 +2,7 @@ * This file is part of John the Ripper password cracker, * Copyright (c) 1998,1999,2002,2003,2005,2006,2011,2020 by Solar Designer * Copyright (c) 2011 by Jim Fougeron - * Copyright (c) 2016-2019 by magnum + * Copyright (c) 2016-2026 by magnum * * Redistribution and use in source and binary forms, with or without * modification, are permitted. @@ -461,7 +461,7 @@ int unique(int argc, char **argv) if (sscanf(argv[i], "-mem=%d%c", &log, &nul) < 1 || nul) log = 0; buf = ((1ULL << log) * UNIQUE_AVG_LEN) >> 30ULL; - fprintf(stderr, + fprintf_color(color_warning, stderr, "Warning: The -mem=%u option is deprecated, use -hash-size=%u (log2 of hash\n" " table size) and/or -buf=%u (total buffer size, in GB) instead\n", log, log, (uint32_t)MAX(1, buf)); diff --git a/src/wordlist.c b/src/wordlist.c index 9c84dae5c8..bfeee576ce 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -1,7 +1,7 @@ /* * This file is part of John the Ripper password cracker, * Copyright (c) 1996-99,2003,2004,2006,2009,2013,2017 by Solar Designer - * Copyright (c) 2009-2025, magnum + * Copyright (c) 2009-2026, magnum * Copyright (c) 2009-2018, JimF * * Redistribution and use in source and binary forms, with or without @@ -149,8 +149,7 @@ static void restore_line_number(void) if (skip_lines(rec_pos, line)) { if (ferror(word_file)) pexit("fgets"); - fprintf_color(color_error, stderr, "fgets: Unexpected EOF\n"); - error(); + error_msg("fgets: Unexpected EOF\n"); } } @@ -319,21 +318,16 @@ static MAYBE_INLINE void check_bom(char *line) return; if (!memcmp(line, "\xEF\xBB\xBF", 3)) { - static int warned; - if (options.input_enc == UTF_8) memmove(line, line + 3, strlen(line) - 2); - else if (!warned++) - fprintf_color(color_warning, stderr, "Warning: UTF-8 BOM seen in wordlist. You probably want --input-encoding=UTF8\n"); + else + WARN_ONCE(color_warning, stderr, + "Warning: UTF-8 BOM seen in wordlist. You probably want --input-encoding=UTF8\n"); } - if (options.input_enc == UTF_8 && (!memcmp(line, "\xFE\xFF", 2) || !memcmp(line, "\xFF\xFE", 2))) { - static int warned; - - if (!warned++) - fprintf_color(color_warning, stderr, - "Warning: UTF-16 BOM seen in wordlist. File may not be read properly unless you re-encode it\n"); - } + if (options.input_enc == UTF_8 && (!memcmp(line, "\xFE\xFF", 2) || !memcmp(line, "\xFF\xFE", 2))) + WARN_ONCE(color_warning, stderr, + "Warning: UTF-16 BOM seen in wordlist. File may not be read properly unless you re-encode it\n"); } /* @@ -622,9 +616,7 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) #if OS_FORK if (options.fork && file_is_fifo) { - if (john_main_process) - fprintf_color(color_error, stderr, "Error, cannot use --fork with FIFO as wordlist file.\n"); - error(); + error_msg_main("Error, cannot use --fork with FIFO as wordlist file.\n"); } #endif @@ -643,9 +635,7 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) pexit(STR_MACRO(jtr_ftell64)); jtr_fseek64(word_file, 0, SEEK_SET); if (file_len == 0 && !loopBack) { - if (john_main_process) - fprintf_color(color_error, stderr, "Error, wordlist file is empty\n"); - error(); + error_msg_main("Error, wordlist file is empty\n"); } ourshare = file_len; @@ -722,15 +712,12 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) } if (i > my_size) { fprintf_color(color_error, stderr, - "Error: wordlist grew " - "as we read it - " - "aborting\n"); + "Error: Wordlist grew as we read it - aborting\n"); error(); } } if (nWordFileLines != myWordFileLines) - fprintf_color(color_warning, stderr, "Warning: wordlist changed as" - " we read it\n"); + WARN_ONCE(color_warning, stderr, "Warning: Wordlist changed as we read it\n"); log_event("- Loaded this node's share of " "wordlist %s into memory " "(%"PRIu64" bytes of %"PRId64", max_size="Zu @@ -763,18 +750,12 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) MEM_ALIGN_NONE); if (fread(word_file_str, 1, (size_t)file_len, word_file) != file_len) { - if (ferror(word_file)) - pexit("fread"); - fprintf_color(color_error, stderr, - "fread: Unexpected EOF\n"); + fprintf_color(color_error, stderr, "Wordlist: %s\n", + feof(word_file) ? "Unexpected EOF" : strerror(errno)); error(); } - if (memchr(word_file_str, 0, (size_t)file_len)) { - static int warned; - - if (!warned++) - fprintf_color(color_warning, stderr, "Warning: Wordlist contains NUL bytes, lines may be truncated.\n"); - } + if (memchr(word_file_str, 0, (size_t)file_len)) + WARN_ONCE(color_warning, stderr, "Warning: Wordlist contains NUL bytes, lines may be truncated.\n"); } aep = word_file_str + file_len; *aep = 0; @@ -827,13 +808,8 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) { char *ep, ec; if (i > nWordFileLines) { - fprintf_color(color_warning, stderr, "Warning: wordlist " - "contains inconsequent " - "newlines, some words may be " - "skipped\n"); - log_event("- Warning: wordlist contains" - " inconsequent newlines, some" - " words may be skipped"); + WARN_AND_LOG_ONCE(color_warning, stderr, + "Warning: Wordlist contains inconsequent newlines, some words may be skipped"); i--; break; } diff --git a/src/wpapmk_fmt_plug.c b/src/wpapmk_fmt_plug.c index 015fbb161c..ab751a88fd 100644 --- a/src/wpapmk_fmt_plug.c +++ b/src/wpapmk_fmt_plug.c @@ -57,19 +57,16 @@ static void init(struct fmt_main *self) self->params.max_keys_per_crypt); if (options.flags & (FLG_BATCH_CHK | FLG_INC_CHK | FLG_SINGLE_CHK)) { - if (john_main_process) { - char *t, *pf = str_alloc_copy(self->params.label); + char *t, *pf = str_alloc_copy(self->params.label); - if ((t = strrchr(pf, '-'))) - *t = 0; + if ((t = strrchr(pf, '-'))) + *t = 0; - fprintf(stderr, + error_msg_main( "The \"%s\" format takes hex keys of length 64 as input. Most normal\n" "cracking approaches does not make sense. You probably wanted to use the\n" "\"%s\" format (even for PMKID hashes).\n", - self->params.label, pf); - } - error(); + self->params.label, pf); } }