1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 16:18:09 +00:00

Use hc_path_create() for additional write checks on startup

This commit is contained in:
jsteube 2017-01-28 00:08:12 +01:00
parent 322862f8dc
commit 2d2eadd2f6
3 changed files with 57 additions and 0 deletions

View File

@ -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

View File

@ -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");

View File

@ -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;
}
}