ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 5f3c183b854a16dddca6fc1fa7a5bef8d685539c
parent ab373918376f5d9c57d79eabd8a87dc4277bba83
Author: sin <sin@2f30.org>
Date:   Sat Oct 19 19:07:30 +0100

Setup a sane PATH across su(1)

Also added a config.h for the basic configuration of ubase.

Diffstat:
Makefile | 2+-
config.h | 4++++
su.c | 9++++++++-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git 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 @@ -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 @@ -8,6 +8,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#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)