2016-09-07 10:45:08 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-07 10:45:08 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-16 15:01:18 +00:00
|
|
|
#include "types.h"
|
2016-09-07 10:45:08 +00:00
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-09-21 21:06:11 +00:00
|
|
|
#include "shared.h"
|
2016-09-07 10:45:08 +00:00
|
|
|
#include "folder.h"
|
2021-06-05 18:48:03 +00:00
|
|
|
#include <libgen.h>
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (__APPLE__)
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2022-01-09 03:50:28 +00:00
|
|
|
#elif defined (__FreeBSD__) || defined (__NetBSD__)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/sysctl.h>
|
2016-09-07 10:45:08 +00:00
|
|
|
#endif
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
static int get_exec_path (char *exec_path, const size_t exec_path_sz)
|
2016-09-07 10:45:08 +00:00
|
|
|
{
|
2016-11-29 21:39:22 +00:00
|
|
|
#if defined (__linux__) || defined (__CYGWIN__)
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
char *tmp = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&tmp, "/proc/%d/exe", getpid ());
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-11-17 05:17:28 +00:00
|
|
|
const ssize_t len = readlink (tmp, exec_path, exec_path_sz - 1);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-12-20 00:46:30 +00:00
|
|
|
hcfree (tmp);
|
|
|
|
|
2016-11-20 13:01:13 +00:00
|
|
|
if (len == -1) return -1;
|
|
|
|
|
2016-09-07 18:30:14 +00:00
|
|
|
#elif defined (_WIN)
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2017-12-02 14:24:10 +00:00
|
|
|
memset (exec_path, 0, exec_path_sz);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2017-12-02 14:24:10 +00:00
|
|
|
const int len = 0;
|
2016-11-20 13:01:13 +00:00
|
|
|
|
2016-09-07 18:30:14 +00:00
|
|
|
#elif defined (__APPLE__)
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
u32 size = (u32) exec_path_sz;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
if (_NSGetExecutablePath (exec_path, &size) != 0) return -1;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-09-30 16:09:29 +00:00
|
|
|
const size_t len = strlen (exec_path);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-09-07 18:30:14 +00:00
|
|
|
#elif defined (__FreeBSD__)
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
int mib[4];
|
2016-09-30 16:09:29 +00:00
|
|
|
|
2016-09-07 10:45:08 +00:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = KERN_PROC_PATHNAME;
|
|
|
|
mib[3] = -1;
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
size_t size = exec_path_sz;
|
2016-09-30 16:09:29 +00:00
|
|
|
|
|
|
|
sysctl (mib, 4, exec_path, &size, NULL, 0);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-12-03 00:43:51 +00:00
|
|
|
const size_t len = strlen (exec_path);
|
2016-11-20 13:01:13 +00:00
|
|
|
|
2022-01-09 03:50:28 +00:00
|
|
|
#elif defined (__NetBSD__)
|
|
|
|
|
|
|
|
int mib[4];
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC_ARGS;
|
2022-03-31 17:19:16 +00:00
|
|
|
mib[2] = getpid ();
|
2022-01-09 03:50:28 +00:00
|
|
|
mib[3] = KERN_PROC_PATHNAME;
|
|
|
|
|
|
|
|
size_t size = exec_path_sz;
|
|
|
|
|
|
|
|
sysctl (mib, 4, exec_path, &size, NULL, 0);
|
|
|
|
|
|
|
|
const size_t len = strlen (exec_path);
|
|
|
|
|
2016-09-07 10:45:08 +00:00
|
|
|
#else
|
|
|
|
#error Your Operating System is not supported or detected
|
|
|
|
#endif
|
|
|
|
|
|
|
|
exec_path[len] = 0;
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return 0;
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-30 17:55:27 +00:00
|
|
|
static void get_install_dir (char *install_dir, const char *exec_path)
|
2016-09-07 10:45:08 +00:00
|
|
|
{
|
2016-10-13 08:07:04 +00:00
|
|
|
strncpy (install_dir, exec_path, HCBUFSIZ_TINY - 1);
|
|
|
|
|
|
|
|
char *last_slash = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
if ((last_slash = strrchr (install_dir, '/')) != NULL)
|
|
|
|
{
|
|
|
|
*last_slash = 0;
|
|
|
|
}
|
|
|
|
else if ((last_slash = strrchr (install_dir, '\\')) != NULL)
|
|
|
|
{
|
|
|
|
*last_slash = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
install_dir[0] = '.';
|
|
|
|
install_dir[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 14:05:12 +00:00
|
|
|
#if defined (_POSIX)
|
2016-10-30 17:55:27 +00:00
|
|
|
static void get_profile_dir (char *profile_dir, const char *home_dir)
|
2016-09-07 10:45:08 +00:00
|
|
|
{
|
2018-12-07 09:37:56 +00:00
|
|
|
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT);
|
2020-06-16 18:05:29 +00:00
|
|
|
|
2021-06-05 18:41:24 +00:00
|
|
|
if (hc_path_is_directory (profile_dir)) return;
|
|
|
|
|
|
|
|
char *xdg_data_home = getenv ("XDG_DATA_HOME");
|
|
|
|
|
|
|
|
if (xdg_data_home)
|
2020-07-05 11:59:03 +00:00
|
|
|
{
|
2021-06-05 18:41:24 +00:00
|
|
|
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_data_home);
|
2020-07-05 11:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-05 18:41:24 +00:00
|
|
|
snprintf (profile_dir, HCBUFSIZ_TINY, "%s/.local/share/hashcat", home_dir);
|
2020-07-05 12:47:51 +00:00
|
|
|
}
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 22:17:13 +00:00
|
|
|
static void get_cache_dir (char *cache_dir, const char *home_dir)
|
|
|
|
{
|
|
|
|
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT);
|
|
|
|
|
2021-06-05 18:41:24 +00:00
|
|
|
if (hc_path_is_directory (cache_dir)) return;
|
|
|
|
|
|
|
|
char *xdg_cache_home = getenv ("XDG_CACHE_HOME");
|
|
|
|
|
|
|
|
if (xdg_cache_home)
|
2021-06-04 22:17:13 +00:00
|
|
|
{
|
2021-06-05 18:41:24 +00:00
|
|
|
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_cache_home);
|
2021-06-04 22:17:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-05 18:41:24 +00:00
|
|
|
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/.cache/hashcat", home_dir);
|
2021-06-04 22:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 17:55:27 +00:00
|
|
|
static void get_session_dir (char *session_dir, const char *profile_dir)
|
2016-09-07 10:45:08 +00:00
|
|
|
{
|
2018-12-07 09:37:56 +00:00
|
|
|
snprintf (session_dir, HCBUFSIZ_TINY, "%s/%s", profile_dir, SESSIONS_FOLDER);
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
2022-02-12 01:03:48 +00:00
|
|
|
#endif // _POSIX
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
int count_dictionaries (char **dictionary_files)
|
|
|
|
{
|
|
|
|
if (dictionary_files == NULL) return 0;
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
for (int d = 0; dictionary_files[d] != NULL; d++)
|
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
return cnt;
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 22:19:13 +00:00
|
|
|
char *first_file_in_directory (const char *path)
|
|
|
|
{
|
2022-02-12 01:03:48 +00:00
|
|
|
DIR *d = NULL;
|
2016-11-05 22:19:13 +00:00
|
|
|
|
|
|
|
if ((d = opendir (path)) != NULL)
|
|
|
|
{
|
|
|
|
char *first_file = NULL;
|
|
|
|
|
2016-11-21 09:55:25 +00:00
|
|
|
#if 0
|
2016-11-05 22:19:13 +00:00
|
|
|
|
|
|
|
struct dirent e;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
memset (&e, 0, sizeof (e));
|
|
|
|
|
|
|
|
struct dirent *de = NULL;
|
|
|
|
|
|
|
|
if (readdir_r (d, &e, &de) != 0) break;
|
|
|
|
|
|
|
|
if (de == NULL) break;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
struct dirent *de = NULL;
|
2016-11-05 22:19:13 +00:00
|
|
|
|
|
|
|
while ((de = readdir (d)) != NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-01-05 15:15:12 +00:00
|
|
|
if (de->d_name[0] == '.') continue;
|
2016-11-05 22:19:13 +00:00
|
|
|
|
|
|
|
first_file = strdup (de->d_name);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir (d);
|
|
|
|
|
|
|
|
return first_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char **scan_directory (const char *path)
|
2016-09-07 10:45:08 +00:00
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
char *tmp_path = hcstrdup (path);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
size_t tmp_path_len = strlen (tmp_path);
|
|
|
|
|
|
|
|
while (tmp_path[tmp_path_len - 1] == '/' || tmp_path[tmp_path_len - 1] == '\\')
|
|
|
|
{
|
|
|
|
tmp_path[tmp_path_len - 1] = 0;
|
|
|
|
|
|
|
|
tmp_path_len = strlen (tmp_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **files = NULL;
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
size_t num_files = 0;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
DIR *d = NULL;
|
|
|
|
|
|
|
|
if ((d = opendir (tmp_path)) != NULL)
|
|
|
|
{
|
2016-11-21 09:55:25 +00:00
|
|
|
#if 0
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
struct dirent e;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
memset (&e, 0, sizeof (e));
|
|
|
|
|
|
|
|
struct dirent *de = NULL;
|
|
|
|
|
2016-10-10 07:18:10 +00:00
|
|
|
if (readdir_r (d, &e, &de) != 0) break;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
if (de == NULL) break;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
struct dirent *de = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
while ((de = readdir (d)) != NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-01-05 15:21:57 +00:00
|
|
|
if (de->d_name[0] == '.') continue;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
char *path_file = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&path_file, "%s/%s", tmp_path, de->d_name);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
DIR *d_test = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
|
|
|
if ((d_test = opendir (path_file)) != NULL)
|
|
|
|
{
|
|
|
|
closedir (d_test);
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (path_file);
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
files = (char **) hcrealloc (files, (num_files + 1) * sizeof (char *), sizeof (char *));
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
files[num_files] = path_file;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
num_files++;
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir (d);
|
|
|
|
}
|
|
|
|
else if (errno == ENOTDIR)
|
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
files = (char **) hcrealloc (files, (num_files + 1) * sizeof (char *), sizeof (char *));
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
files[num_files] = hcstrdup (path);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
num_files++;
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
files = (char **) hcrealloc (files, (num_files + 1) * sizeof (char *), sizeof (char *));
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
files[num_files] = NULL;
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (tmp_path);
|
2016-09-07 10:45:08 +00:00
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
return files;
|
2016-09-07 10:45:08 +00:00
|
|
|
}
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-10 07:12:36 +00:00
|
|
|
int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *install_folder, MAYBE_UNUSED const char *shared_folder)
|
2016-09-21 21:06:11 +00:00
|
|
|
{
|
2016-10-06 14:17:29 +00:00
|
|
|
folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
/**
|
|
|
|
* There's some buggy OpenCL runtime that do not support -I.
|
|
|
|
* A workaround is to chdir() to the OpenCL folder,
|
|
|
|
* then compile the kernels,
|
|
|
|
* then chdir() back to where we came from so we need to save it first
|
2020-06-03 09:10:31 +00:00
|
|
|
* - temporary disabled due to https://github.com/hashcat/hashcat/issues/2379
|
2016-09-21 21:06:11 +00:00
|
|
|
*/
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *cwd = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
if (getcwd (cwd, HCBUFSIZ_TINY - 1) == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "getcwd(): %s", strerror (errno));
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2017-02-14 16:54:36 +00:00
|
|
|
hcfree (cwd);
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* folders, as discussed on https://github.com/hashcat/hashcat/issues/20
|
|
|
|
*/
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
const size_t exec_path_sz = 1024;
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *exec_path = (char *) hcmalloc (exec_path_sz);
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
const int rc = get_exec_path (exec_path, exec_path_sz);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
if (rc == -1)
|
2016-10-09 20:41:55 +00:00
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "get_exec_path() failed.");
|
2016-10-09 20:41:55 +00:00
|
|
|
|
2017-02-14 16:54:36 +00:00
|
|
|
hcfree (cwd);
|
|
|
|
|
|
|
|
hcfree (exec_path);
|
|
|
|
|
2016-10-09 20:41:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
#if defined (_POSIX)
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-30 17:55:27 +00:00
|
|
|
static const char SLASH[] = "/";
|
|
|
|
|
2016-10-25 09:30:27 +00:00
|
|
|
if (install_folder == NULL) install_folder = SLASH; // makes library use easier
|
2016-10-02 23:27:55 +00:00
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
char *resolved_install_folder = realpath (install_folder, NULL);
|
|
|
|
char *resolved_exec_path = realpath (exec_path, NULL);
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
if (resolved_install_folder == NULL) resolved_install_folder = hcstrdup (SLASH);
|
2016-10-25 09:30:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This causes invalid error out if install_folder (/usr/local/bin) does not exist
|
2016-09-21 21:06:11 +00:00
|
|
|
if (resolved_install_folder == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", resolved_install_folder, strerror (errno));
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2017-02-14 16:54:36 +00:00
|
|
|
hcfree (cwd);
|
|
|
|
|
|
|
|
hcfree (exec_path);
|
|
|
|
|
|
|
|
hcfree (resolved_install_folder);
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-10-25 09:30:27 +00:00
|
|
|
*/
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
if (resolved_exec_path == NULL)
|
|
|
|
{
|
2019-06-26 13:52:11 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", exec_path, strerror (errno));
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2017-02-14 16:54:36 +00:00
|
|
|
hcfree (cwd);
|
|
|
|
|
|
|
|
hcfree (exec_path);
|
|
|
|
|
|
|
|
hcfree (resolved_install_folder);
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
char *install_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
get_install_dir (install_dir, resolved_exec_path);
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
char *profile_dir = NULL;
|
2021-06-06 09:03:44 +00:00
|
|
|
char *cache_dir = NULL;
|
2016-09-21 21:06:11 +00:00
|
|
|
char *session_dir = NULL;
|
|
|
|
char *shared_dir = NULL;
|
|
|
|
|
|
|
|
if (strcmp (install_dir, resolved_install_folder) == 0)
|
|
|
|
{
|
2016-11-16 12:36:26 +00:00
|
|
|
struct passwd pw;
|
2022-02-12 01:03:48 +00:00
|
|
|
struct passwd *pwp = NULL;
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-11-16 12:36:26 +00:00
|
|
|
char buf[HCBUFSIZ_TINY];
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
memset (buf, 0, sizeof (buf));
|
|
|
|
memset (&pw, 0, sizeof (pw));
|
|
|
|
|
2016-11-16 12:36:26 +00:00
|
|
|
getpwuid_r (getuid (), &pw, buf, HCBUFSIZ_TINY, &pwp);
|
|
|
|
|
|
|
|
const char *home_dir = pwp->pw_dir;
|
2016-10-13 08:07:04 +00:00
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
profile_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2021-06-06 09:03:44 +00:00
|
|
|
cache_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2019-09-12 01:05:01 +00:00
|
|
|
session_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
get_profile_dir (profile_dir, home_dir);
|
2021-06-06 09:03:44 +00:00
|
|
|
get_cache_dir (cache_dir, home_dir);
|
2016-10-13 08:07:04 +00:00
|
|
|
get_session_dir (session_dir, profile_dir);
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
shared_dir = hcstrdup (shared_folder);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2021-06-05 18:48:03 +00:00
|
|
|
hc_mkdir_rec (profile_dir, 0700);
|
2021-06-06 09:03:44 +00:00
|
|
|
hc_mkdir_rec (cache_dir, 0700);
|
|
|
|
hc_mkdir (session_dir, 0700);
|
2016-09-21 21:06:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
profile_dir = install_dir;
|
2021-06-06 09:03:44 +00:00
|
|
|
cache_dir = install_dir;
|
2016-09-21 21:06:11 +00:00
|
|
|
session_dir = install_dir;
|
|
|
|
shared_dir = install_dir;
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (resolved_install_folder);
|
|
|
|
hcfree (resolved_exec_path);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *install_dir = hcmalloc (HCBUFSIZ_TINY);
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
get_install_dir (install_dir, exec_path);
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
char *profile_dir = install_dir;
|
2021-06-06 09:03:44 +00:00
|
|
|
char *cache_dir = install_dir;
|
2016-09-21 21:06:11 +00:00
|
|
|
char *session_dir = install_dir;
|
|
|
|
char *shared_dir = install_dir;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (exec_path);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-02 07:50:06 +00:00
|
|
|
* There are a lot of problems related to bad support of -I parameters when building the kernel.
|
|
|
|
* Each OpenCL runtime handles it slightly differently.
|
|
|
|
* The most problematic is with new AMD drivers on Windows, which cannot handle quote characters!
|
|
|
|
* The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is loaded.
|
2016-09-21 21:06:11 +00:00
|
|
|
*/
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
char *cpath = NULL;
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
#if defined (_WIN)
|
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&cpath, "%s\\OpenCL\\", shared_dir);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
char *cpath_real = NULL;
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2017-12-02 14:24:10 +00:00
|
|
|
hc_asprintf (&cpath_real, "%s\\OpenCL\\", shared_dir);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&cpath, "%s/OpenCL/", shared_dir);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *cpath_real = (char *) hcmalloc (PATH_MAX);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
if (realpath (cpath, cpath_real) == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", cpath, strerror (errno));
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2017-02-14 16:54:36 +00:00
|
|
|
hcfree (cwd);
|
|
|
|
|
2017-02-14 13:45:27 +00:00
|
|
|
hcfree (shared_dir);
|
2017-08-10 13:05:47 +00:00
|
|
|
|
|
|
|
// Attention: since hcfree () doesn't set the pointer to NULL, we need to do it externally such that
|
|
|
|
// 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;
|
2021-06-06 09:03:44 +00:00
|
|
|
if (cache_dir == shared_dir) cache_dir = NULL;
|
2017-08-10 13:05:47 +00:00
|
|
|
if (session_dir == shared_dir) session_dir = NULL;
|
|
|
|
|
|
|
|
shared_dir = NULL;
|
|
|
|
|
2017-02-14 13:45:27 +00:00
|
|
|
hcfree (profile_dir);
|
2017-08-10 13:05:47 +00:00
|
|
|
|
|
|
|
if (session_dir == profile_dir) session_dir = NULL;
|
2021-06-06 09:03:44 +00:00
|
|
|
if (cache_dir == profile_dir) cache_dir = NULL;
|
2017-08-10 13:05:47 +00:00
|
|
|
|
|
|
|
profile_dir = NULL;
|
|
|
|
|
2021-06-04 22:17:13 +00:00
|
|
|
hcfree (cache_dir);
|
|
|
|
|
|
|
|
if (session_dir == cache_dir) session_dir = NULL;
|
|
|
|
|
|
|
|
cache_dir = NULL;
|
|
|
|
|
2017-02-14 13:45:27 +00:00
|
|
|
hcfree (session_dir);
|
|
|
|
|
2017-08-10 13:05:47 +00:00
|
|
|
session_dir = NULL;
|
|
|
|
|
|
|
|
hcfree (cpath_real);
|
|
|
|
|
|
|
|
cpath_real = NULL;
|
|
|
|
|
2016-09-21 21:06:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (cpath);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
//if (getenv ("TMP") == NULL)
|
2020-06-03 09:10:31 +00:00
|
|
|
/* temporary disabled due to https://github.com/hashcat/hashcat/issues/2379
|
2019-09-10 00:52:08 +00:00
|
|
|
if (true)
|
2016-09-21 21:06:11 +00:00
|
|
|
{
|
2016-12-20 00:46:30 +00:00
|
|
|
char *tmp;
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&tmp, "TMP=%s", cpath_real);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
putenv (tmp);
|
|
|
|
}
|
2020-06-03 09:10:31 +00:00
|
|
|
*/
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2021-06-24 07:24:02 +00:00
|
|
|
// not escaping here, using quotes later
|
2016-09-21 21:06:11 +00:00
|
|
|
// naive_escape (cpath_real, PATH_MAX, ' ', '\\');
|
|
|
|
|
2021-06-24 07:24:02 +00:00
|
|
|
#if defined (_WIN)
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2021-06-24 07:24:02 +00:00
|
|
|
naive_replace (cpath_real, '\\', '/');
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kernel cache, we need to make sure folder exist
|
|
|
|
*/
|
|
|
|
|
2022-02-12 01:03:48 +00:00
|
|
|
char *kernels_folder = NULL;
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2021-06-04 22:17:13 +00:00
|
|
|
hc_asprintf (&kernels_folder, "%s/kernels", cache_dir);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-01 11:51:06 +00:00
|
|
|
hc_mkdir (kernels_folder, 0700);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (kernels_folder);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* store for later use
|
|
|
|
*/
|
|
|
|
|
|
|
|
folder_config->cwd = cwd;
|
|
|
|
folder_config->install_dir = install_dir;
|
|
|
|
folder_config->profile_dir = profile_dir;
|
2021-06-04 22:17:13 +00:00
|
|
|
folder_config->cache_dir = cache_dir;
|
2016-09-21 21:06:11 +00:00
|
|
|
folder_config->session_dir = session_dir;
|
|
|
|
folder_config->shared_dir = shared_dir;
|
|
|
|
folder_config->cpath_real = cpath_real;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 14:17:29 +00:00
|
|
|
void folder_config_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-21 21:06:11 +00:00
|
|
|
{
|
2016-10-06 14:17:29 +00:00
|
|
|
folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (folder_config->cpath_real);
|
|
|
|
hcfree (folder_config->cwd);
|
|
|
|
hcfree (folder_config->install_dir);
|
2016-09-21 21:06:11 +00:00
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
memset (folder_config, 0, sizeof (folder_config_t));
|
2016-09-21 21:06:11 +00:00
|
|
|
}
|
2016-10-01 11:51:06 +00:00
|
|
|
|
2016-10-10 07:12:36 +00:00
|
|
|
int hc_mkdir (const char *name, MAYBE_UNUSED const int mode)
|
2016-10-01 11:51:06 +00:00
|
|
|
{
|
|
|
|
#if defined (_WIN)
|
|
|
|
return _mkdir (name);
|
|
|
|
#else
|
|
|
|
return mkdir (name, mode);
|
|
|
|
#endif
|
|
|
|
}
|
2021-06-05 18:48:03 +00:00
|
|
|
|
|
|
|
int hc_mkdir_rec (const char *path, MAYBE_UNUSED const int mode)
|
|
|
|
{
|
2021-06-06 09:03:44 +00:00
|
|
|
char *fullpath = hcstrdup (path);
|
|
|
|
|
|
|
|
char *subpath = dirname (fullpath);
|
2021-06-05 18:48:03 +00:00
|
|
|
|
|
|
|
if (strlen (subpath) > 1)
|
|
|
|
{
|
2021-06-06 09:03:44 +00:00
|
|
|
if (hc_mkdir_rec (subpath, mode) == -1) return -1;
|
2021-06-05 18:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hc_mkdir (path, mode) == -1)
|
|
|
|
{
|
2021-06-06 09:03:44 +00:00
|
|
|
if (errno != EEXIST) return -1;
|
2021-06-05 18:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hcfree (fullpath);
|
2021-06-06 09:03:44 +00:00
|
|
|
|
2021-06-05 18:48:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|