From d0b2f3db0c497b8cd7292d853dcc6ed97f64a59a Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Tue, 21 Apr 2020 15:56:26 +0100 Subject: [PATCH] e_system: When setuid, set home also. This ensures we have a matching $HOME when using setuid, without which can potentially cause issues in eina_vpath on some systems (FreeBSD as example). --- src/bin/system/e_system_main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/system/e_system_main.c b/src/bin/system/e_system_main.c index 70d514ea2..5822eb936 100644 --- a/src/bin/system/e_system_main.c +++ b/src/bin/system/e_system_main.c @@ -93,20 +93,37 @@ deny: static void setuid_setup(void) { + struct passwd *pwent; + static char buf[4096]; + uid = getuid(); gid = getgid(); if (setuid(0) != 0) { - ERR("Unable to assume root user privileges\n"); + fprintf(stderr, "Unable to assume root user privileges\n"); exit(5); } if (setgid(0) != 0) { - ERR("Unable to assume root group privileges\n"); + fprintf(stderr, "Unable to assume root group privileges\n"); exit(7); } + pwent = getpwuid(getuid()); + if (!pwent) + { + fprintf(stderr, "Unable to obtain passwd entry\n"); + exit(1); + } + + snprintf(buf, sizeof(buf), "HOME=%s", pwent->pw_dir); + if (putenv(buf) == -1) + { + fprintf(stderr, "Unable to set $HOME environment\n"); + exit(1); + } + // die with parent - special as this is setuid #ifdef HAVE_PRCTL prctl(PR_SET_PDEATHSIG, SIGTERM);