1
mirror of https://github.com/hashcat/hashcat synced 2024-11-20 23:27:31 +01:00

Merge pull request #2456 from nycex/xdg

use XDG_DATA_HOME for profile_dir
This commit is contained in:
Jens Steube 2021-06-06 10:51:53 +02:00 committed by GitHub
commit c9db099330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 133 additions and 31 deletions

View File

@ -31,8 +31,35 @@ The install target is linux FHS compatible and can be used like this:
$ make install
```
If you install it, cached kernels, session files, restore- and pot-files etc. will go to $HOME/.hashcat/
If the $HOME/.hashcat folder exists, then:
- Session related files go to: $HOME/.hashcat/sessions/
- Cached kernels go to: $HOME/.hashcat/kernels/
- Potfiles go to: $HOME/.hashcat/
Otherwise, if environment variable XDG_DATA_HOME and XDG_CACHE_HOME exists, then:
- Session related files go to: $XDG_DATA_HOME/hashcat/sessions/
- Cached kernels go to: $XDG_CACHE_HOME/hashcat/kernels/
- Potfiles go to: $XDG_DATA_HOME/hashcat/
Otherwise, if environment variable XDG_DATA_HOME exists, then:
- Session related files go to: $XDG_DATA_HOME/hashcat/sessions/
- Cached kernels go to: $HOME/.cache/hashcat
- Potfiles go to: $XDG_DATA_HOME/hashcat/
Otherwise, if environment variable XDG_CACHE_HOME exists, then:
- Session related files go to: $HOME/.local/share/hashcat/sessions/
- Cached kernels go to: $XDG_CACHE_HOME/hashcat/kernels/
- Potfiles go to: $HOME/.local/share/hashcat/
Otherwise:
- Session related files go to: $HOME/.local/share/hashcat/sessions/
- Cached kernels go to: $HOME/.cache/hashcat
- Potfiles go to: $HOME/.local/share/hashcat/
### Building hashcat for Windows (using Windows Subsystem for Linux) ###

View File

@ -140,13 +140,13 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *de
int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_pos, const u64 pws_cnt);
void generate_source_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *shared_dir, char *source_file);
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *profile_dir, const char *device_name_chksum, char *cached_file);
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *cache_dir, const char *device_name_chksum, char *cached_file);
void generate_source_kernel_shared_filename (char *shared_dir, char *source_file);
void generate_cached_kernel_shared_filename (char *profile_dir, const char *device_name_chksum, char *cached_file);
void generate_cached_kernel_shared_filename (char *cache_dir, const char *device_name_chksum, char *cached_file);
void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *shared_dir, char *source_file);
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *profile_dir, const char *device_name_chksum, char *cached_file);
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *cache_dir, const char *device_name_chksum, char *cached_file);
void generate_source_kernel_amp_filename (const u32 attack_kern, char *shared_dir, char *source_file);
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *profile_dir, const char *device_name_chksum, char *cached_file);
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *cache_dir, const char *device_name_chksum, char *cached_file);
int backend_ctx_init (hashcat_ctx_t *hashcat_ctx);
void backend_ctx_destroy (hashcat_ctx_t *hashcat_ctx);

View File

@ -37,5 +37,6 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char
void folder_config_destroy (hashcat_ctx_t *hashcat_ctx);
int hc_mkdir (const char *name, MAYBE_UNUSED const int mode);
int hc_mkdir_rec (const char *path, MAYBE_UNUSED const int mode);
#endif // _FOLDER_H

View File

@ -2130,6 +2130,7 @@ typedef struct folder_config
char *cwd;
char *install_dir;
char *profile_dir;
char *cache_dir;
char *session_dir;
char *shared_dir;
char *cpath_real;

View File

@ -616,7 +616,7 @@ void generate_source_kernel_filename (const bool slow_candidates, const u32 atta
}
}
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *profile_dir, const char *device_name_chksum, char *cached_file)
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *cache_dir, const char *device_name_chksum, char *cached_file)
{
if (opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
{
@ -624,23 +624,23 @@ void generate_cached_kernel_filename (const bool slow_candidates, const u32 atta
{
if (slow_candidates == true)
{
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
else
{
if (attack_kern == ATTACK_KERN_STRAIGHT)
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_COMBI)
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_BF)
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_NONE)
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
}
else
{
snprintf (cached_file, 255, "%s/kernels/m%05d-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
}
else
@ -649,23 +649,23 @@ void generate_cached_kernel_filename (const bool slow_candidates, const u32 atta
{
if (slow_candidates == true)
{
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
else
{
if (attack_kern == ATTACK_KERN_STRAIGHT)
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_COMBI)
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_BF)
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
else if (attack_kern == ATTACK_KERN_NONE)
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
}
else
{
snprintf (cached_file, 255, "%s/kernels/m%05d-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
snprintf (cached_file, 255, "%s/kernels/m%05d-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
}
}
}
@ -675,9 +675,9 @@ void generate_source_kernel_shared_filename (char *shared_dir, char *source_file
snprintf (source_file, 255, "%s/OpenCL/shared.cl", shared_dir);
}
void generate_cached_kernel_shared_filename (char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
void generate_cached_kernel_shared_filename (char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
{
snprintf (cached_file, 255, "%s/kernels/shared.%s.kernel", profile_dir, device_name_chksum_amp_mp);
snprintf (cached_file, 255, "%s/kernels/shared.%s.kernel", cache_dir, device_name_chksum_amp_mp);
}
void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *shared_dir, char *source_file)
@ -692,15 +692,15 @@ void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_typ
}
}
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
{
if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE))
{
snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", profile_dir, device_name_chksum_amp_mp);
snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", cache_dir, device_name_chksum_amp_mp);
}
else
{
snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", profile_dir, device_name_chksum_amp_mp);
snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", cache_dir, device_name_chksum_amp_mp);
}
}
@ -709,9 +709,9 @@ void generate_source_kernel_amp_filename (const u32 attack_kern, char *shared_di
snprintf (source_file, 255, "%s/OpenCL/amp_a%u.cl", shared_dir, attack_kern);
}
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
{
snprintf (cached_file, 255, "%s/kernels/amp_a%u.%s.kernel", profile_dir, attack_kern, device_name_chksum_amp_mp);
snprintf (cached_file, 255, "%s/kernels/amp_a%u.%s.kernel", cache_dir, attack_kern, device_name_chksum_amp_mp);
}
// NVRTC
@ -8724,7 +8724,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
char cached_file[256] = { 0 };
generate_cached_kernel_shared_filename (folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
generate_cached_kernel_shared_filename (folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "shared_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_shared, &device_param->cuda_module_shared);
@ -8904,7 +8904,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
char cached_file[256] = { 0 };
generate_cached_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->profile_dir, device_name_chksum, cached_file);
generate_cached_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->cache_dir, device_name_chksum, cached_file);
/**
* load kernel
@ -8954,7 +8954,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
char cached_file[256] = { 0 };
generate_cached_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
generate_cached_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "mp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_mp, &device_param->cuda_module_mp);
@ -9003,7 +9003,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
char cached_file[256] = { 0 };
generate_cached_kernel_amp_filename (user_options_extra->attack_kern, folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
generate_cached_kernel_amp_filename (user_options_extra->attack_kern, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "amp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_amp, &device_param->cuda_module_amp);

View File

@ -9,6 +9,7 @@
#include "event.h"
#include "shared.h"
#include "folder.h"
#include <libgen.h>
#if defined (__APPLE__)
#include "event.h"
@ -93,6 +94,37 @@ static void get_install_dir (char *install_dir, const char *exec_path)
static void get_profile_dir (char *profile_dir, const char *home_dir)
{
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT);
if (hc_path_is_directory (profile_dir)) return;
char *xdg_data_home = getenv ("XDG_DATA_HOME");
if (xdg_data_home)
{
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_data_home);
}
else
{
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/.local/share/hashcat", home_dir);
}
}
static void get_cache_dir (char *cache_dir, const char *home_dir)
{
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT);
if (hc_path_is_directory (cache_dir)) return;
char *xdg_cache_home = getenv ("XDG_CACHE_HOME");
if (xdg_cache_home)
{
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_cache_home);
}
else
{
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/.cache/hashcat", home_dir);
}
}
static void get_session_dir (char *session_dir, const char *profile_dir)
@ -338,6 +370,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
get_install_dir (install_dir, resolved_exec_path);
char *profile_dir = NULL;
char *cache_dir = NULL;
char *session_dir = NULL;
char *shared_dir = NULL;
@ -353,19 +386,23 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
const char *home_dir = pwp->pw_dir;
profile_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
cache_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
session_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
get_profile_dir (profile_dir, home_dir);
get_cache_dir (cache_dir, home_dir);
get_session_dir (session_dir, profile_dir);
shared_dir = hcstrdup (shared_folder);
hc_mkdir (profile_dir, 0700);
hc_mkdir_rec (profile_dir, 0700);
hc_mkdir_rec (cache_dir, 0700);
hc_mkdir (session_dir, 0700);
}
else
{
profile_dir = install_dir;
cache_dir = install_dir;
session_dir = install_dir;
shared_dir = install_dir;
}
@ -380,6 +417,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
get_install_dir (install_dir, exec_path);
char *profile_dir = install_dir;
char *cache_dir = install_dir;
char *session_dir = install_dir;
char *shared_dir = install_dir;
@ -422,6 +460,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
// we prevent double-freeing the same memory address (this happens if e.g. profile_dir == session_dir)
if (profile_dir == shared_dir) profile_dir = NULL;
if (cache_dir == shared_dir) cache_dir = NULL;
if (session_dir == shared_dir) session_dir = NULL;
shared_dir = NULL;
@ -430,10 +469,18 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
hcfree (profile_dir);
if (session_dir == profile_dir) session_dir = NULL;
if (cache_dir == profile_dir) cache_dir = NULL;
profile_dir = NULL;
hcfree (cache_dir);
if (session_dir == cache_dir) session_dir = NULL;
cache_dir = NULL;
hcfree (session_dir);
session_dir = NULL;
@ -481,7 +528,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
char *kernels_folder;
hc_asprintf (&kernels_folder, "%s/kernels", profile_dir);
hc_asprintf (&kernels_folder, "%s/kernels", cache_dir);
hc_mkdir (kernels_folder, 0700);
@ -494,6 +541,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
folder_config->cwd = cwd;
folder_config->install_dir = install_dir;
folder_config->profile_dir = profile_dir;
folder_config->cache_dir = cache_dir;
folder_config->session_dir = session_dir;
folder_config->shared_dir = shared_dir;
folder_config->cpath_real = cpath_real;
@ -520,3 +568,28 @@ int hc_mkdir (const char *name, MAYBE_UNUSED const int mode)
return mkdir (name, mode);
#endif
}
int hc_mkdir_rec (const char *path, MAYBE_UNUSED const int mode)
{
char *subpath, *fullpath;
fullpath = hcstrdup (path);
subpath = dirname (fullpath);
if (strlen (subpath) > 1)
{
if (hc_mkdir_rec (subpath, mode) == -1) {
return -1;
};
}
if (hc_mkdir (path, mode) == -1)
{
if (errno != EEXIST)
{
return -1;
}
}
hcfree (fullpath);
return 0;
}