From 5f3c183b854a16dddca6fc1fa7a5bef8d685539c Mon Sep 17 00:00:00 2001 From: sin Date: Sat, 19 Oct 2013 19:07:30 +0100 Subject: [PATCH] Setup a sane PATH across su(1) Also added a config.h for the basic configuration of ubase. --- Makefile | 2 +- config.h | 4 ++++ su.c | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 config.h diff --git a/Makefile b/Makefile index d9ff21e..cc09ded 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk .POSIX: .SUFFIXES: .c .o -HDR = arg.h grabmntinfo.h proc.h reboot.h util.h +HDR = arg.h config.h grabmntinfo.h proc.h reboot.h util.h LIB = \ util/agetcwd.o \ util/apathmax.o \ diff --git a/config.h b/config.h new file mode 100644 index 0000000..a85d6bd --- /dev/null +++ b/config.h @@ -0,0 +1,4 @@ +/* See LICENSE file for copyright and license details. */ + +#define ENV_SUPATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +#define ENV_PATH "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" diff --git a/su.c b/su.c index 339cba1..2cbc57e 100644 --- a/su.c +++ b/su.c @@ -8,6 +8,7 @@ #include #include #include +#include "config.h" #include "util.h" extern char **environ; @@ -112,6 +113,10 @@ main(int argc, char **argv) setenv("LOGNAME", pw->pw_name, 1); } } + if (strcmp(pw->pw_name, "root") == 0) + setenv("PATH", ENV_SUPATH, 1); + else + setenv("PATH", ENV_PATH, 1); execve(pflag ? getenv("SHELL") : pw->pw_shell, newargv, environ); } @@ -147,7 +152,9 @@ dologin(struct passwd *pw) msetenv("USER", pw->pw_name), msetenv("LOGNAME", pw->pw_name), msetenv("TERM", getenv("TERM")), - msetenv("PATH", getenv("PATH")), + msetenv("PATH", + strcmp(pw->pw_name, "root") == 0 ? + ENV_SUPATH : ENV_PATH), NULL }; if (chdir(pw->pw_dir) < 0)