diff options
author | Moritz Luedecke <ritze@skweez.net> | 2017-09-05 22:20:28 +0200 |
---|---|---|
committer | Moritz Luedecke <ritze@skweez.net> | 2017-09-05 22:20:28 +0200 |
commit | 68a35247008c8f5ebf8e23cbdb86cd2c0f3025a1 (patch) | |
tree | 308371af21cc342159145a07236dea0a35171a0b /pinentry-dmenu.c | |
parent | f5de98070f9e07307094aa81f973469ddd926d47 (diff) |
Get out the home dir even if the user used sudo or logged in as root
Diffstat (limited to 'pinentry-dmenu.c')
-rw-r--r-- | pinentry-dmenu.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/pinentry-dmenu.c b/pinentry-dmenu.c index 8ed5fa0..a2ff9ae 100644 --- a/pinentry-dmenu.c +++ b/pinentry-dmenu.c @@ -589,14 +589,25 @@ main(int argc, char *argv[]) { Bool bval; int i, val; const char *str; + struct passwd *pw; char path[PATH_MAX]; - struct passwd *pw = getpwuid(getuid()); + char *sudo_uid = getenv("SUDO_UID"); + char *home = getenv("HOME"); config_t cfg; + // This is a little workaround to get the home dir even if the user used + // sudo or logged in as root + if (sudo_uid) { + i = atoi(sudo_uid); + pw = getpwuid(i); + home = pw->pw_dir; + } + config_init(&cfg); - i = strlen(pw->pw_dir); - strcpy(path, pw->pw_dir); + i = strlen(home); + strcpy(path, home); strcpy(&path[i], CONFIG); + endpwent(); /* Read the file. If there is an error, report it and exit. */ if (config_read_file(&cfg, path)) { |