Use hc_path_create() for additional write checks on startup

pull/1003/head
jsteube 7 years ago
parent 322862f8dc
commit 2d2eadd2f6

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

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

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

Loading…
Cancel
Save