From 954b7d0a4dcc527ed0f8db4d256c93bfaf17f528 Mon Sep 17 00:00:00 2001 From: nycex Date: Sat, 5 Jun 2021 20:41:24 +0200 Subject: [PATCH] apply suggested changes --- BUILD.md | 30 +++++++++++++++++++++++++++++- src/folder.c | 42 ++++++++++++++---------------------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/BUILD.md b/BUILD.md index 46af636a9..333b8ec81 100644 --- a/BUILD.md +++ b/BUILD.md @@ -31,7 +31,35 @@ The install target is linux FHS compatible and can be used like this: $ make install ``` -If you install it, cached kernels will go to either $HOME/.hashcat/, if that already exists, otherwise to $XDG_CACHE_HOME/hashcat/ or ~/.cache/hashcat/, if that environment variable is not set. Session files, restore- and pot-files etc. will go to either $HOME/.hashcat/, if that already exists, otherwise to $XDG_DATA_HOME/hashcat/ or ~/.local/share/hashcat/, if that environment variable is not set. +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) ### diff --git a/src/folder.c b/src/folder.c index 78892cb69..018e63cec 100644 --- a/src/folder.c +++ b/src/folder.c @@ -93,51 +93,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); - struct stat st = {0}; - if (stat (profile_dir, &st) == 0 && S_ISDIR (st.st_mode)) - return; - char *data_dir = (char *) hcmalloc (HCBUFSIZ_TINY); - if (getenv ("XDG_DATA_HOME")) + if (hc_path_is_directory (profile_dir)) return; + + char *xdg_data_home = getenv ("XDG_DATA_HOME"); + + if (xdg_data_home) { - strncpy (data_dir, getenv ("XDG_DATA_HOME"), HCBUFSIZ_TINY); + snprintf (profile_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_data_home); } else { - snprintf (data_dir, HCBUFSIZ_TINY, "%s/.local/share", home_dir); + snprintf (profile_dir, HCBUFSIZ_TINY, "%s/.local/share/hashcat", home_dir); } - - if (access (data_dir, R_OK) != -1) - { - snprintf (profile_dir, HCBUFSIZ_TINY, "%s/hashcat", data_dir); - } - - hcfree (data_dir); } static void get_cache_dir (char *cache_dir, const char *home_dir) { snprintf (cache_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT); - struct stat st = {0}; - if (stat (cache_dir, &st) == 0 && S_ISDIR (st.st_mode)) - return; - char *xdg_cache_dir = (char *) hcmalloc (HCBUFSIZ_TINY); - if (getenv ("XDG_CACHE_HOME")) + if (hc_path_is_directory (cache_dir)) return; + + char *xdg_cache_home = getenv ("XDG_CACHE_HOME"); + + if (xdg_cache_home) { - strncpy (xdg_cache_dir, getenv ("XDG_CACHE_HOME"), HCBUFSIZ_TINY); + snprintf (cache_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_cache_home); } else { - snprintf (xdg_cache_dir, HCBUFSIZ_TINY, "%s/.cache", home_dir); + snprintf (cache_dir, HCBUFSIZ_TINY, "%s/.cache/hashcat", home_dir); } - - if (access (xdg_cache_dir, R_OK) != -1) - { - snprintf (cache_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_cache_dir); - } - - hcfree (xdg_cache_dir); } static void get_session_dir (char *session_dir, const char *profile_dir)