mirror of
https://github.com/hashcat/hashcat.git
synced 2024-12-22 14:48:12 +00:00
Move all outfile-check folder related host code into outfile_check.c
This commit is contained in:
parent
1e2869e8bd
commit
319d548766
@ -10,4 +10,7 @@
|
||||
|
||||
void *thread_outfile_remove (void *p);
|
||||
|
||||
int outcheck_ctx_init (outcheck_ctx_t *outcheck_ctx, const user_options_t *user_options, const folder_config_t *folder_config);
|
||||
void outcheck_ctx_destroy (outcheck_ctx_t *outcheck_ctx);
|
||||
|
||||
#endif // _OUTFILE_CHECK_H
|
||||
|
@ -903,6 +903,14 @@ typedef struct
|
||||
|
||||
} induct_ctx_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool enabled;
|
||||
|
||||
char *root_directory;
|
||||
|
||||
} outcheck_ctx_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
@ -976,7 +984,6 @@ typedef struct
|
||||
u32 maskpos;
|
||||
char *eff_restore_file;
|
||||
char *new_restore_file;
|
||||
char *outfile_check_directory;
|
||||
u32 pw_min;
|
||||
u32 pw_max;
|
||||
|
||||
@ -992,6 +999,7 @@ typedef struct
|
||||
session_ctx_t *session_ctx;
|
||||
bitmap_ctx_t *bitmap_ctx;
|
||||
induct_ctx_t *induct_ctx;
|
||||
outcheck_ctx_t *outcheck_ctx;
|
||||
|
||||
/**
|
||||
* used for restore
|
||||
|
111
src/hashcat.c
111
src/hashcat.c
@ -176,8 +176,6 @@ int main (int argc, char **argv)
|
||||
* folder
|
||||
*/
|
||||
|
||||
folder_config_t *folder_config = (folder_config_t *) mymalloc (sizeof (folder_config_t));
|
||||
|
||||
char *install_folder = NULL;
|
||||
char *shared_folder = NULL;
|
||||
|
||||
@ -189,6 +187,8 @@ int main (int argc, char **argv)
|
||||
shared_folder = SHARED_FOLDER;
|
||||
#endif
|
||||
|
||||
folder_config_t *folder_config = (folder_config_t *) mymalloc (sizeof (folder_config_t));
|
||||
|
||||
folder_config_init (folder_config, install_folder, shared_folder);
|
||||
|
||||
/**
|
||||
@ -327,6 +327,16 @@ int main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* tuning db
|
||||
*/
|
||||
|
||||
char tuning_db_file[256] = { 0 };
|
||||
|
||||
snprintf (tuning_db_file, sizeof (tuning_db_file) - 1, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE);
|
||||
|
||||
tuning_db_t *tuning_db = tuning_db_init (tuning_db_file);
|
||||
|
||||
/**
|
||||
* induction directory
|
||||
*/
|
||||
@ -339,60 +349,17 @@ int main (int argc, char **argv)
|
||||
|
||||
if (rc_induct_ctx_init == -1) return -1;
|
||||
|
||||
/**
|
||||
* tuning db
|
||||
*/
|
||||
|
||||
char tuning_db_file[256] = { 0 };
|
||||
|
||||
snprintf (tuning_db_file, sizeof (tuning_db_file) - 1, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE);
|
||||
|
||||
tuning_db_t *tuning_db = tuning_db_init (tuning_db_file);
|
||||
|
||||
/**
|
||||
* outfile-check directory
|
||||
*/
|
||||
|
||||
char *outfile_check_directory = NULL;
|
||||
outcheck_ctx_t *outcheck_ctx = (outcheck_ctx_t *) mymalloc (sizeof (outcheck_ctx_t));
|
||||
|
||||
if ((user_options->keyspace == false) && (user_options->benchmark == false) && (user_options->opencl_info == false))
|
||||
{
|
||||
if (user_options->outfile_check_dir == NULL)
|
||||
{
|
||||
outfile_check_directory = (char *) mymalloc (HCBUFSIZ_TINY);
|
||||
data.outcheck_ctx = outcheck_ctx;
|
||||
|
||||
snprintf (outfile_check_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
outfile_check_directory = user_options->outfile_check_dir;
|
||||
}
|
||||
const int rc_outcheck_ctx_init = outcheck_ctx_init (outcheck_ctx, user_options, folder_config);
|
||||
|
||||
struct stat outfile_check_stat;
|
||||
|
||||
if (stat (outfile_check_directory, &outfile_check_stat) == 0)
|
||||
{
|
||||
uint is_dir = S_ISDIR (outfile_check_stat.st_mode);
|
||||
|
||||
if (is_dir == 0)
|
||||
{
|
||||
log_error ("ERROR: Directory specified in outfile-check '%s' is not a valid directory", outfile_check_directory);
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (user_options->outfile_check_dir == NULL)
|
||||
{
|
||||
if (mkdir (outfile_check_directory, 0700) == -1)
|
||||
{
|
||||
log_error ("ERROR: %s: %s", outfile_check_directory, strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.outfile_check_directory = outfile_check_directory;
|
||||
if (rc_outcheck_ctx_init == -1) return -1;
|
||||
|
||||
/**
|
||||
* cpu affinity
|
||||
@ -2491,28 +2458,11 @@ int main (int argc, char **argv)
|
||||
|
||||
inner_threads_cnt++;
|
||||
|
||||
if (user_options->outfile_check_timer != 0)
|
||||
if (outcheck_ctx->enabled == true)
|
||||
{
|
||||
if (data.outfile_check_directory != NULL)
|
||||
{
|
||||
if ((hashconfig->hash_mode != 5200) &&
|
||||
!((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) &&
|
||||
!((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) &&
|
||||
(hashconfig->hash_mode != 9000))
|
||||
{
|
||||
hc_thread_create (inner_threads[inner_threads_cnt], thread_outfile_remove, NULL);
|
||||
hc_thread_create (inner_threads[inner_threads_cnt], thread_outfile_remove, NULL);
|
||||
|
||||
inner_threads_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
user_options->outfile_check_timer = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user_options->outfile_check_timer = 0;
|
||||
}
|
||||
inner_threads_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3907,28 +3857,9 @@ int main (int argc, char **argv)
|
||||
|
||||
// outfile-check directory
|
||||
|
||||
if (outfile_check_directory != NULL)
|
||||
{
|
||||
if (rmdir (outfile_check_directory) == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
// good, we can ignore
|
||||
}
|
||||
else if (errno == ENOTEMPTY)
|
||||
{
|
||||
// good, we can ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error ("ERROR: %s: %s", outfile_check_directory, strerror (errno));
|
||||
outcheck_ctx_destroy (outcheck_ctx);
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
local_free (outfile_check_directory);
|
||||
}
|
||||
// shutdown
|
||||
|
||||
time_t proc_stop;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
#include "logging.h"
|
||||
#include "interface.h"
|
||||
#include "timer.h"
|
||||
#include "folder.h"
|
||||
@ -39,9 +40,10 @@ void *thread_outfile_remove (void *p)
|
||||
// some hash-dependent constants
|
||||
|
||||
user_options_t *user_options = data.user_options;
|
||||
opencl_ctx_t *opencl_ctx = data.opencl_ctx;
|
||||
hashconfig_t *hashconfig = data.hashconfig;
|
||||
hashes_t *hashes = data.hashes;
|
||||
outcheck_ctx_t *outcheck_ctx = data.outcheck_ctx;
|
||||
opencl_ctx_t *opencl_ctx = data.opencl_ctx;
|
||||
|
||||
uint dgst_size = hashconfig->dgst_size;
|
||||
uint is_salted = hashconfig->is_salted;
|
||||
@ -49,8 +51,8 @@ void *thread_outfile_remove (void *p)
|
||||
uint hash_mode = hashconfig->hash_mode;
|
||||
char separator = hashconfig->separator;
|
||||
|
||||
char *outfile_dir = data.outfile_check_directory;
|
||||
uint outfile_check_timer = user_options->outfile_check_timer;
|
||||
char *root_directory = outcheck_ctx->root_directory;
|
||||
uint outfile_check_timer = user_options->outfile_check_timer;
|
||||
|
||||
// buffers
|
||||
hash_t hash_buf = { 0, 0, 0, 0, 0 };
|
||||
@ -80,11 +82,11 @@ void *thread_outfile_remove (void *p)
|
||||
|
||||
check_left--;
|
||||
|
||||
if (check_left == false)
|
||||
if (check_left == 0)
|
||||
{
|
||||
struct stat outfile_check_stat;
|
||||
|
||||
if (stat (outfile_dir, &outfile_check_stat) == 0)
|
||||
if (stat (root_directory, &outfile_check_stat) == 0)
|
||||
{
|
||||
uint is_dir = S_ISDIR (outfile_check_stat.st_mode);
|
||||
|
||||
@ -92,7 +94,7 @@ void *thread_outfile_remove (void *p)
|
||||
{
|
||||
if (outfile_check_stat.st_mtime > folder_mtime)
|
||||
{
|
||||
char **out_files_new = scan_directory (outfile_dir);
|
||||
char **out_files_new = scan_directory (root_directory);
|
||||
|
||||
int out_cnt_new = count_dictionaries (out_files_new);
|
||||
|
||||
@ -331,3 +333,89 @@ void *thread_outfile_remove (void *p)
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
int outcheck_ctx_init (outcheck_ctx_t *outcheck_ctx, const user_options_t *user_options, const folder_config_t *folder_config)
|
||||
{
|
||||
outcheck_ctx->enabled = false;
|
||||
|
||||
if (user_options->keyspace == true) return 0;
|
||||
if (user_options->benchmark == true) return 0;
|
||||
if (user_options->opencl_info == true) return 0;
|
||||
|
||||
if (user_options->outfile_check_timer == 0) return 0;
|
||||
|
||||
if ((user_options->hash_mode == 5200) ||
|
||||
((user_options->hash_mode >= 6200) && (user_options->hash_mode <= 6299)) ||
|
||||
((user_options->hash_mode >= 13700) && (user_options->hash_mode <= 13799)) ||
|
||||
(user_options->hash_mode == 9000)) return 0;
|
||||
|
||||
if (user_options->outfile_check_dir == NULL)
|
||||
{
|
||||
outcheck_ctx->root_directory = (char *) mymalloc (HCBUFSIZ_TINY);
|
||||
|
||||
snprintf (outcheck_ctx->root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR);
|
||||
}
|
||||
else
|
||||
{
|
||||
outcheck_ctx->root_directory = user_options->outfile_check_dir;
|
||||
}
|
||||
|
||||
struct stat outfile_check_stat;
|
||||
|
||||
if (stat (outcheck_ctx->root_directory, &outfile_check_stat) == 0)
|
||||
{
|
||||
const uint is_dir = S_ISDIR (outfile_check_stat.st_mode);
|
||||
|
||||
if (is_dir == 0)
|
||||
{
|
||||
log_error ("ERROR: Directory specified in outfile-check '%s' is not a valid directory", outcheck_ctx->root_directory);
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mkdir (outcheck_ctx->root_directory, 0700) == -1)
|
||||
{
|
||||
log_error ("ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
outcheck_ctx->enabled = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void outcheck_ctx_destroy (outcheck_ctx_t *outcheck_ctx)
|
||||
{
|
||||
if (outcheck_ctx->enabled == false)
|
||||
{
|
||||
myfree (outcheck_ctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (rmdir (outcheck_ctx->root_directory) == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
// good, we can ignore
|
||||
}
|
||||
else if (errno == ENOTEMPTY)
|
||||
{
|
||||
// good, we can ignore
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error ("ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno));
|
||||
|
||||
//return -1;
|
||||
}
|
||||
}
|
||||
|
||||
myfree (outcheck_ctx->root_directory);
|
||||
|
||||
myfree (outcheck_ctx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user