From ea98aaedccbbc7791840afa135fc1cd8e94aa4aa Mon Sep 17 00:00:00 2001 From: magnum Date: Fri, 14 Nov 2025 11:05:58 +0100 Subject: [PATCH 1/6] Logging tweaks Add some function-like macros for log/warn/both WARN_AND_LOG() is like fprintf_color() then log_event(), with same message. WARN_ONCE() is like fprintf_color() but only once per session. LOG_ONCE() is like log_event() but only once per session. WARN_AND_LOG_ONCE() does both, with same message. Also add error color to error(), pexit() and similar stuff in misc.c --- run/john.conf | 2 +- src/color.c | 5 +++-- src/color.h | 14 +++++++++----- src/john.c | 6 ++++++ src/logger.h | 35 +++++++++++++++++++++++++++++++++++ src/misc.c | 12 +++++++++--- src/misc.h | 16 +++++++++++++++- 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/run/john.conf b/run/john.conf index 2e8e9878779..c30b7553f84 100644 --- a/run/john.conf +++ b/run/john.conf @@ -113,7 +113,7 @@ TerminalReset = ^[0m # which define red for errors, green for notices and yellow for warnings). # Note that you don't strictly need to use ANSI sequences - other things are # fine too. -# Set this to N or comment it out to disable all color stuff. +# Set this to N to disable all color stuff. UseColors = Y ColorError = ^[0;31m ColorNotice = ^[0;32m diff --git a/src/color.c b/src/color.c index c2e04601b24..f01f47e780a 100644 --- a/src/color.c +++ b/src/color.c @@ -9,6 +9,7 @@ #include "config.h" #include "options.h" +const char* const color_none = ""; char *color_error, *color_notice, *color_warning, *color_end; /* @@ -34,11 +35,11 @@ char *parse_esc(const char *string) void color_init() { - if (cfg_get_bool(SECTION_OPTIONS, NULL, "UseColors", 0)) { + if (cfg_get_bool(SECTION_OPTIONS, NULL, "UseColors", 1)) { color_error = parse_esc(cfg_get_param(SECTION_OPTIONS, NULL, "ColorError")); color_notice = parse_esc(cfg_get_param(SECTION_OPTIONS, NULL, "ColorNotice")); 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 29fff87c32b..1800bc0d1f8 100644 --- a/src/color.h +++ b/src/color.h @@ -8,11 +8,8 @@ #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; +#include +#include /* isatty */ #define printf_color(color, ...) fprintf_color(color, stdout, __VA_ARGS__); @@ -40,4 +37,11 @@ extern char *color_error, *color_notice, *color_warning, *color_end; fputs(color_end, handle); \ } 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/john.c b/src/john.c index 29d9411704b..a980544d147 100644 --- a/src/john.c +++ b/src/john.c @@ -2093,6 +2093,12 @@ int main(int argc, char **argv) return base64conv(argc, argv); } + /* + * For having these as empty strings in case a color warning/error is + * printed before we init colors. + */ + color_error = color_notice = color_warning = color_end = (char*)color_none; + #if !(CPU_FALLBACK || OMP_FALLBACK || defined(CPU_FALLBACK_BINARY) || defined(OMP_FALLBACK_BINARY)) path_init(argv); #endif diff --git a/src/logger.h b/src/logger.h index 0bb8001bac7..32901245b15 100644 --- a/src/logger.h +++ b/src/logger.h @@ -50,6 +50,41 @@ 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 NL. + */ +#define WARN_AND_LOG(color, stream, ...) \ + do { \ + fprintf_color(color, stream, __VA_ARGS__); \ + fputc('\n', stream); \ + 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/misc.c b/src/misc.c index 1ba53919b69..0a61575e442 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" @@ -42,6 +43,7 @@ void real_error(const char *file, int line) #ifndef _JOHN_MISC_NO_LOG 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 f27b1f561ab..3eb91f6e769 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 @@ -37,6 +39,18 @@ #endif #endif +/* + * Like fprintf_color but only once per session. + */ +#define WARN_ONCE(...) \ + do { \ + static int warned; \ + if (!warned) { \ + fprintf_color(__VA_ARGS__); \ + warned = 1; \ + } \ + } while (0) + /* * Exit on error. Logs the event, closes john.pot and the log file, and * terminates the process with non-zero exit status. @@ -62,7 +76,7 @@ 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__) /* * Similar to perror(), but supports formatted output, and calls error(). From 97acf35616940a211cf4893b928fb2eea4451d51 Mon Sep 17 00:00:00 2001 From: magnum Date: Sat, 15 Nov 2025 11:01:28 +0100 Subject: [PATCH 2/6] OpenCL: Drop old race-condition debug stuff --- src/opencl_common.c | 89 +++------------------------------------------ 1 file changed, 5 insertions(+), 84 deletions(-) diff --git a/src/opencl_common.c b/src/opencl_common.c index af2c0b08ffd..4bbb611d8f3 100644 --- a/src/opencl_common.c +++ b/src/opencl_common.c @@ -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]) && @@ -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). @@ -585,38 +563,25 @@ static int start_opencl_device(int sequential_id, int *err_type) if (ret_code != CL_SUCCESS) { fprintf(stderr, "%u: Error creating context for device %d " - "(%d:%d): %s, %s\n", + "(%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, + "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; } @@ -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 */ @@ -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 */ @@ -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); @@ -2259,10 +2188,6 @@ size_t opencl_read_source(const char *kernel_filename, char **kernel_source) "Error reading 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; } @@ -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 From c19ef3f5584335fb61c846f92c73bb7846d0701d Mon Sep 17 00:00:00 2001 From: magnum Date: Mon, 17 Nov 2025 16:55:55 +0100 Subject: [PATCH 3/6] OpenCL: Add color to error output Also prefix log entries with "OpenCL:" for clarity. --- src/gpu_common.c | 39 +++---- src/opencl_autotune.h | 9 +- src/opencl_common.c | 75 ++++++------- src/opencl_common.h | 8 +- src/opencl_dynamic_loader.c | 156 +++++++++++++------------- src/opencl_generate_dynamic_loader.py | 4 +- 6 files changed, 136 insertions(+), 155 deletions(-) diff --git a/src/gpu_common.c b/src/gpu_common.c index 65838f91053..87c12e22757 100644 --- a/src/gpu_common.c +++ b/src/gpu_common.c @@ -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; /*** @@ -526,17 +516,14 @@ void gpu_check_temp(void) event_abort++; } else { - if (hot_gpu && options.verbosity > VERB_DEFAULT && - !warnedTemperature) { + if (hot_gpu && options.verbosity > VERB_DEFAULT && !warnedTemperature) { char s_fan[16] = "n/a"; 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 +544,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 +552,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/opencl_autotune.h b/src/opencl_autotune.h index ed0476f36fa..b242285e2f7 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 4bbb611d8f3..06afb561e9a 100644 --- a/src/opencl_common.c +++ b/src/opencl_common.c @@ -423,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++) { @@ -439,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 @@ -562,7 +562,7 @@ 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 " + 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), @@ -575,7 +575,7 @@ static int start_opencl_device(int sequential_id, int *err_type) devices[sequential_id], 0, &ret_code); if (ret_code != CL_SUCCESS) { - fprintf(stderr, "%u: Error creating command queue for " + 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)); @@ -599,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(); @@ -615,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; } @@ -736,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(); @@ -813,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; @@ -859,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 @@ -961,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; @@ -1123,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) @@ -1240,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); @@ -1249,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); @@ -1267,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) && @@ -1380,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); @@ -2185,7 +2185,7 @@ 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)); fclose(fp); @@ -2285,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); @@ -2298,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"); } } @@ -2306,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); @@ -2374,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 @@ -2900,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++) { @@ -2915,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)); @@ -2940,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 772131cde43..c12ef945e09 100644 --- a/src/opencl_common.h +++ b/src/opencl_common.h @@ -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_dynamic_loader.c b/src/opencl_dynamic_loader.c index 063f9f4ee7a..6678e3d7a99 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 d9640bf6c50..3389d246247 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('''} From c3b76cb85f3a9b7bd23c8b8f7abca3c99d9bb6ba Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 18 Nov 2025 00:05:56 +0100 Subject: [PATCH 4/6] Core files: Colorize warnings and/or use _ONCE macros --- src/bench.c | 5 +- src/config.c | 4 +- src/formats.c | 6 +-- src/john.c | 14 ++--- src/loader.c | 34 ++++++------ src/options.c | 145 ++++++++++++++------------------------------------ 6 files changed, 72 insertions(+), 136 deletions(-) diff --git a/src/bench.c b/src/bench.c index e8fcdded8c4..b8eaeab7a52 100644 --- a/src/bench.c +++ b/src/bench.c @@ -279,8 +279,9 @@ static void bench_set_keys(struct fmt_main *format, } if (warn == 1) { - fprintf(stderr, "Warning: not enough candidates under " - "benchmark length %d\n", length); + fprintf_color(color_warning, stderr, + "Warning: not enough candidates under benchmark length %d\n", + length); warn = 2; } diff --git a/src/config.c b/src/config.c index e7fd1dbfcc1..919693fc111 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/formats.c b/src/formats.c index b6fba4094c5..d893eb99d27 100644 --- a/src/formats.c +++ b/src/formats.c @@ -455,9 +455,9 @@ 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 " - "UTF-8. Use --target-encoding=utf8\n", - format->params.label); + fprintf_color(color_warning, stderr, + "Warning: %s format should always be UTF-8. Use --target-encoding=utf8\n", + format->params.label); if (john_main_process && !(options.flags & FLG_TEST_CHK) && !options.listconf) { if (format->params.flags & FMT_NOT_EXACT) { diff --git a/src/john.c b/src/john.c index a980544d147..494808b57c7 100644 --- a/src/john.c +++ b/src/john.c @@ -424,13 +424,14 @@ 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, " - "consider --fork=%d\n", - msg, john_omp_threads_orig); + 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); } } @@ -1082,7 +1083,8 @@ static void john_load(void) } 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(); } diff --git a/src/loader.c b/src/loader.c index b62db9891e9..af9c6348927 100644 --- a/src/loader.c +++ b/src/loader.c @@ -122,11 +122,10 @@ static MAYBE_INLINE char *check_bom(char *string) "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; } @@ -254,13 +253,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); @@ -1012,18 +1015,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 */ diff --git a/src/options.c b/src/options.c index 76635fe6ef5..af4fe3dc2ae 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("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("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("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("\\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("Invalid session name: all-digits suffix\n"); } #endif rec_name = options.session; @@ -580,19 +572,14 @@ 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("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("Can't use --fork with MPI.\n"); } } #endif @@ -678,10 +665,8 @@ 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("max. %d different tunable cost parameters supported\n", + FMT_TUNABLE_COSTS); } for ( i = 0; i < FMT_TUNABLE_COSTS; i++) { int negative; @@ -702,18 +687,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("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("Usage of negative --cost is not valid for value 0\n"); } if (!two_values) { if (negative) { @@ -725,9 +704,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("Max. cost value must be >= min. cost value\n"); } } } @@ -775,60 +752,39 @@ 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("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("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(); + error_msg("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("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("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("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("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("Invalid options: --mkpc must be at least 1\n"); } /* @@ -849,8 +805,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("--fork number must be between 2 and 1024\n"); } #endif @@ -898,10 +853,8 @@ 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("Invalid node specification: %s: %s\n", + options.node_str, msg); } #if OS_FORK } else if (options.fork) { @@ -954,14 +907,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("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 /* @@ -971,17 +921,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("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("Password files specified, but no option would use them\n"); } if ( (options.flags & FLG_SHOW_CHK) && show_uncracked_str) { @@ -1004,9 +948,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" - "--show, --show=left, --show=formats, --show=types, --show=invalid\n"); - error(); + error_msg("Invalid option in --show switch. Valid options:\n" + "--show, --show=left, --show=formats, --show=types, --show=invalid\n"); } } @@ -1054,29 +997,21 @@ 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("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("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; From f518972886afffd43eaa854bf4750af674032e9c Mon Sep 17 00:00:00 2001 From: magnum Date: Mon, 17 Nov 2025 16:56:44 +0100 Subject: [PATCH 5/6] Modes: Colorize warnings and/or use _ONCE macros --- src/external.c | 4 +- src/inc.c | 28 +++++++------ src/mask.c | 32 +++++++------- src/mkv.c | 112 ++++++++++++++++--------------------------------- src/pp.c | 18 ++++---- src/rpp.c | 5 +-- src/single.c | 4 +- src/subsets.c | 13 +++--- src/wordlist.c | 44 ++++++------------- 9 files changed, 101 insertions(+), 159 deletions(-) diff --git a/src/external.c b/src/external.c index a71cb1cd190..c1bc1b4059f 100644 --- a/src/external.c +++ b/src/external.c @@ -283,8 +283,8 @@ 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(), " - "but is only used for filter()\n"); + fprintf_color(color_warning, stderr, + "Warning: external mode defines generate(), but is only used for filter()\n"); ext_mode = mode; } diff --git a/src/inc.c b/src/inc.c index 0085449a52f..92975445184 100644 --- a/src/inc.c +++ b/src/inc.c @@ -531,9 +531,10 @@ 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 " - "for the current hash type, reduced to %d\n", - max_length, our_fmt_len); + 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; } @@ -714,8 +715,9 @@ 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", - real_count); + fprintf_color(color_warning, stderr, + "Warning: only %u characters available\n", + real_count); } } @@ -728,18 +730,20 @@ 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, " - "but the current hash type is case-insensitive;\n" - "some candidate passwords may be unnecessarily " - "tried more than once.\n"); + 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"); } 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" - " hash type is 7-bit;\n" - "some candidate passwords may be redundant.\n"); + 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"); } char2 = NULL; diff --git a/src/mask.c b/src/mask.c index 951e8153743..c5a7a44726c 100644 --- a/src/mask.c +++ b/src/mask.c @@ -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; @@ -157,13 +156,8 @@ static char* expand_cplhdr(char *string, int *conv_err) int pidx = s[1] - '1'; char *cs = options.custom_mask[pidx]; - if (conv_err[pidx]) { - if (john_main_process) - fprintf(stderr, - "Error: Selected internal codepage can't hold all chars of mask placeholder ?%d\n", - pidx + 1); - error(); - } + if (conv_err[pidx]) + error_msg("Error: Selected internal codepage can't hold all chars of mask placeholder ?%d\n", pidx + 1); if (*cs == 0) { if (john_main_process) fprintf(stderr, "Error: Custom mask placeholder ?%d not defined\n", pidx + 1); @@ -2425,7 +2419,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; } @@ -2436,12 +2430,12 @@ static void finalize_mask(int len) 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"); + 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; } @@ -2514,9 +2508,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 +2632,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/mkv.c b/src/mkv.c index 0ab6b9425e1..bc4c100dbf7 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -391,11 +391,7 @@ 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("Too many markov parameters specified: %s\n", dummy_token); } } @@ -403,10 +399,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("Section [" SECTION_MARKOV "%s] not found\n", mode); } if (options.mkv_stats == NULL) @@ -415,12 +408,8 @@ 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("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("Could not parse markov level\n"); } if (level == 0) /* get min. and max. level from markov section */ @@ -452,19 +439,13 @@ 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("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, "! Level = %d is too large (max=%d)", level, MAX_MKV_LVL); level = MAX_MKV_LVL; } @@ -474,8 +455,8 @@ void get_markov_options(struct db_main *db, if (level < minlevel) { if (john_main_process) - fprintf(stderr, "Warning: max level(%d) < min level(%d)" - ", min level set to %d\n", level, minlevel, level); + 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 +472,8 @@ 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("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,9 +507,9 @@ void get_markov_options(struct db_main *db, if (minlen > maxlen) { if (john_main_process) - fprintf(stderr, "Warning: minimum length(%d) > maximum" - " length(%d), minimum length set to %d\n", - minlen, maxlen, maxlen); + 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("invalid end: %s\n", end_token); } } /* @@ -584,26 +558,19 @@ 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("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("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_warning, stderr, + "Start: %s converted to %" PRId64, + start_token, *mkv_start); } } if (end_token != NULL && strlen(end_token) && @@ -611,37 +578,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 " - "too large (max = 100%%)\n", end_token); + 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_warning, 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("Error: MKV start > end (%" PRId64 " > %" PRId64 ")\n", + *mkv_start, *mkv_end); } } diff --git a/src/pp.c b/src/pp.c index ea7142a6f86..6e69fa5ad3c 100644 --- a/src/pp.c +++ b/src/pp.c @@ -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,10 +1218,10 @@ 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 " - "for the current hash type, reduced to %d\n", - pw_max, - our_fmt_len); + 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); 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/rpp.c b/src/rpp.c index b66e2803048..23a2b74794d 100644 --- a/src/rpp.c +++ b/src/rpp.c @@ -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/single.c b/src/single.c index 1b156ca9ed9..95ce4f7db70 100644 --- a/src/single.c +++ b/src/single.c @@ -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/subsets.c b/src/subsets.c index 7001e4f774a..71bed18f36d 100644 --- a/src/subsets.c +++ b/src/subsets.c @@ -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++ = '\\'; diff --git a/src/wordlist.c b/src/wordlist.c index 9c84dae5c85..401d876636c 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -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"); } /* @@ -722,15 +716,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 @@ -769,12 +760,8 @@ void do_wordlist_crack(struct db_main *db, const char *name, int rules) "fread: Unexpected EOF\n"); 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 +814,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; } From 908a43afcea143860b502077f8bac725727709fa Mon Sep 17 00:00:00 2001 From: magnum Date: Tue, 18 Nov 2025 21:34:21 +0100 Subject: [PATCH 6/6] Formats: Colorize warnings and/or use _ONCE macros --- src/7z_common_plug.c | 68 +++++++++++---------------- src/bestcrypt_ve_fmt_plug.c | 4 +- src/bitshares_fmt_plug.c | 5 +- src/c3_fmt.c | 11 +++-- src/keepass_common.h | 53 ++++++++++----------- src/mscash_common_plug.c | 28 ++++------- src/ntlmv1_mschapv2_fmt_plug.c | 15 +++--- src/oldoffice_common_plug.c | 11 ++--- src/opencl_diskcryptor_aes_fmt_plug.c | 7 +-- src/opencl_diskcryptor_fmt_plug.c | 7 +-- src/opencl_krb5pa-sha1_fmt_plug.c | 7 +-- src/opencl_lm_b_plug.c | 10 ++-- src/opencl_ntlmv2_fmt_plug.c | 14 ++---- src/opencl_oldoffice_fmt_plug.c | 12 ++--- src/opencl_tezos_fmt_plug.c | 7 +-- src/pem_common_plug.c | 15 +++--- src/pkzip.c | 3 +- src/rar_common.h | 6 +-- src/sapB_fmt_plug.c | 6 +-- src/sapH_fmt_plug.c | 9 ++-- src/telegram_common_plug.c | 6 +-- src/tezos_fmt_plug.c | 2 +- 22 files changed, 125 insertions(+), 181 deletions(-) diff --git a/src/7z_common_plug.c b/src/7z_common_plug.c index 6ab321a5cee..832d52fdf5c 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; @@ -595,12 +587,8 @@ int sevenzip_decrypt(unsigned char *derived_key) x86_Convert(out, crc_len, 0, &state, 0); } 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); - } + if (!benchmark_running && options.verbosity >= VERB_DEFAULT) + WARN_ONCE(color_warning, stderr, "Can't decode BCJ2, so skipping CRC check"); goto exit_good; } else if (p_type == 3) @@ -620,7 +608,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 +624,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/bestcrypt_ve_fmt_plug.c b/src/bestcrypt_ve_fmt_plug.c index 774392d0e77..1fd36c9ab99 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 diff --git a/src/bitshares_fmt_plug.c b/src/bitshares_fmt_plug.c index 1e02f487482..14ef4773d66 100644 --- a/src/bitshares_fmt_plug.c +++ b/src/bitshares_fmt_plug.c @@ -300,8 +300,9 @@ 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" - " (corrupted data or false positive?) - will keep guessing\n"); + 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 bf3b841bf19..d1973a6cbff 100644 --- a/src/c3_fmt.c +++ b/src/c3_fmt.c @@ -371,11 +371,12 @@ static int valid(char *ciphertext, struct fmt_main *self) if (id != 10 && !ldr_in_pot) if (john_main_process) - fprintf(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", - length, id > 0x20 ? '$' : '#', id > 0x20 ? id : '0' + id); + 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", + length, id > 0x20 ? '$' : '#', id > 0x20 ? id : '0' + id); if (!sup_length[length]) sup_length[length] = -1; diff --git a/src/keepass_common.h b/src/keepass_common.h index fc9838945bc..0a809e18e29 100644 --- a/src/keepass_common.h +++ b/src/keepass_common.h @@ -135,24 +135,20 @@ 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", - self->params.label); - warned = 1; + if (!ldr_in_pot && john_main_process) { + WARN_ONCE(color_warning, stderr, + "%s: Argon2 hash(es) not supported, skipping.\n", + self->params.label); } 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", - self->params.label); - warned = 1; + if (!ldr_in_pot && john_main_process) { + WARN_ONCE(color_warning, stderr, + "%s: AES hash(es) not supported, skipping.\n", + self->params.label); } goto err; } @@ -199,14 +195,14 @@ static int keepass_valid(char *ciphertext, struct fmt_main *self) if (extra) goto err; if (content_size > KEEPASS_MAX_CONTENT_SIZE) { - static int warned; + static int warned_size; - if (!ldr_in_pot && john_main_process && warned < content_size) { - fprintf(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); - warned = content_size; + if (!ldr_in_pot && john_main_process && warned_size < content_size) { + 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); + warned_size = content_size; } goto err; } @@ -241,14 +237,14 @@ static int keepass_valid(char *ciphertext, struct fmt_main *self) goto err; int content_size = atoi(p); if (content_size > KEEPASS_MAX_CONTENT_SIZE) { - static int warned; + static int warned_size; - if (!ldr_in_pot && john_main_process && warned < content_size) { - fprintf(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); - warned = content_size; + if (!ldr_in_pot && john_main_process && warned_size < content_size) { + 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); + warned_size = content_size; } goto err; } @@ -419,8 +415,9 @@ 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", - __FILE__, __LINE__, keyfilesize); + 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++) cs.keyfile[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 diff --git a/src/mscash_common_plug.c b/src/mscash_common_plug.c index e88670fbbf4..d3631293079 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_warning, 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_warning, 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/ntlmv1_mschapv2_fmt_plug.c b/src/ntlmv1_mschapv2_fmt_plug.c index cb1c10e8c66..a4dee0e3ef8 100644 --- a/src/ntlmv1_mschapv2_fmt_plug.c +++ b/src/ntlmv1_mschapv2_fmt_plug.c @@ -1074,20 +1074,17 @@ 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 " - "--format=%s-naive\ninstead. That version loads " - "faster but runs slower.\n", my->params.label, - my->params.label); - } + 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); if (chap_valid_short(ciphertext)) ciphertext += FORMAT_TAG_LEN + CHAP_CHALLENGE_LENGTH / 4 + 1; diff --git a/src/oldoffice_common_plug.c b/src/oldoffice_common_plug.c index 84ccd4188ca..2f50fca8918 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_diskcryptor_aes_fmt_plug.c b/src/opencl_diskcryptor_aes_fmt_plug.c index beace960f95..302207f8ee4 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 4328c0cd978..0c15454619b 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_krb5pa-sha1_fmt_plug.c b/src/opencl_krb5pa-sha1_fmt_plug.c index aac67297213..80b8b754cca 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 325984cba86..2cd3384f71b 100644 --- a/src/opencl_lm_b_plug.c +++ b/src/opencl_lm_b_plug.c @@ -443,7 +443,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 +453,22 @@ 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"); + 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"); + 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_ntlmv2_fmt_plug.c b/src/opencl_ntlmv2_fmt_plug.c index f9d4331e370..614a48c1432 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 c2c8ad69736..1aca89fb12c 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_tezos_fmt_plug.c b/src/opencl_tezos_fmt_plug.c index b16ca268ce2..83694028f18 100644 --- a/src/opencl_tezos_fmt_plug.c +++ b/src/opencl_tezos_fmt_plug.c @@ -264,11 +264,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, diff --git a/src/pem_common_plug.c b/src/pem_common_plug.c index 6b97a467fd4..beffeb943d5 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 0b81f922e66..e6a9c300700 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/rar_common.h b/src/rar_common.h index bb07a24bcb5..76a1598a33a 100644 --- a/src/rar_common.h +++ b/src/rar_common.h @@ -437,10 +437,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 diff --git a/src/sapB_fmt_plug.c b/src/sapB_fmt_plug.c index c10e9a9494e..1ac2bb5fc8c 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 2535c4f7996..28146bc5d7c 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/telegram_common_plug.c b/src/telegram_common_plug.c index 46a7a5c783b..6cbef4cd32a 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 10671a981fa..a47b0d645cc 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"); } }