From 2d2eadd2f654e55ea02e951f020b27d42927319d Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 28 Jan 2017 00:08:12 +0100 Subject: [PATCH] Use hc_path_create() for additional write checks on startup --- include/shared.h | 1 + src/shared.c | 11 +++++++++++ src/user_options.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/include/shared.h b/include/shared.h index 9afd5f0a7..dc08ff278 100644 --- a/include/shared.h +++ b/include/shared.h @@ -46,5 +46,6 @@ bool hc_path_is_empty (const char *path); bool hc_path_exist (const char *path); bool hc_path_read (const char *path); bool hc_path_write (const char *path); +bool hc_path_create (const char *path); #endif // _SHARED_H diff --git a/src/shared.c b/src/shared.c index 44efc0306..fbffa6967 100644 --- a/src/shared.c +++ b/src/shared.c @@ -242,6 +242,17 @@ bool hc_path_write (const char *path) return true; } +bool hc_path_create (const char *path) +{ + if (hc_path_exist (path) == true) return false; + + if (creat (path, O_CREAT) == -1) return false; + + unlink (path); + + return true; +} + void setup_environment_variables () { char *compute = getenv ("COMPUTE"); diff --git a/src/user_options.c b/src/user_options.c index 408e68871..b796f1e91 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -1474,6 +1474,15 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: %m", logfile_ctx->logfile); + return -1; + } + } + else + { + if (hc_path_create (logfile_ctx->logfile) == false) + { + event_log_error (hashcat_ctx, "%s: %m", logfile_ctx->logfile); + return -1; } } @@ -1506,6 +1515,15 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: %m", outfile_ctx->filename); + return -1; + } + } + else + { + if (hc_path_create (outfile_ctx->filename) == false) + { + event_log_error (hashcat_ctx, "%s: %m", outfile_ctx->filename); + return -1; } } @@ -1584,6 +1602,15 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) return -1; } } + else + { + if (hc_path_create (pidfile_ctx->filename) == false) + { + event_log_error (hashcat_ctx, "%s: %m", pidfile_ctx->filename); + + return -1; + } + } // potfile @@ -1595,6 +1622,15 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: %m", potfile_ctx->filename); + return -1; + } + } + else + { + if (hc_path_create (potfile_ctx->filename) == false) + { + event_log_error (hashcat_ctx, "%s: %m", potfile_ctx->filename); + return -1; } } @@ -1610,6 +1646,15 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: %m", dictstat_ctx->filename); + return -1; + } + } + else + { + if (hc_path_create (dictstat_ctx->filename) == false) + { + event_log_error (hashcat_ctx, "%s: %m", dictstat_ctx->filename); + return -1; } }