From 1b584af81fe3ef3cd816c04f829e23b06170e64d Mon Sep 17 00:00:00 2001 From: magnum Date: Mon, 4 Jan 2016 11:32:33 +0100 Subject: [PATCH] Allow $HOME to override the home directory (eg. ~/.john) in JOHN_SYSTEMWIDE builds. Closes 1901. --- src/path.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/path.c b/src/path.c index 2bee3c2..d640daf 100644 --- a/src/path.c +++ b/src/path.c @@ -9,6 +9,7 @@ */ #include +#include #include "misc.h" #include "params.h" @@ -32,7 +33,7 @@ static int user_home_length; void path_init(char **argv) { #if JOHN_SYSTEMWIDE - struct passwd *pw; + char *home_dir; #ifdef JOHN_PRIVATE_HOME char *private; #endif @@ -46,15 +47,23 @@ void path_init(char **argv) john_home_length = strlen(john_home_path); if (user_home_path) return; - pw = getpwuid(getuid()); - endpwent(); - if (!pw) return; - user_home_length = strlen(pw->pw_dir) + 1; + /* $HOME may override user's home directory */ + if (!(home_dir = getenv("HOME"))) { + struct passwd *pw; + + pw = getpwuid(getuid()); + endpwent(); + if (!pw) + return; + home_dir = pw->pw_dir; + } + + user_home_length = strlen(home_dir) + 1; if (user_home_length >= PATH_BUFFER_SIZE) return; user_home_path = mem_alloc(PATH_BUFFER_SIZE); - memcpy(user_home_path, pw->pw_dir, user_home_length - 1); + memcpy(user_home_path, home_dir, user_home_length - 1); user_home_path[user_home_length - 1] = '/'; #ifdef JOHN_PRIVATE_HOME -- 2.1.4