Setup a sane PATH across su(1)
Also added a config.h for the basic configuration of ubase.
This commit is contained in:
parent
ab37391837
commit
5f3c183b85
2
Makefile
2
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 \
|
||||
|
4
config.h
Normal file
4
config.h
Normal file
@ -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"
|
9
su.c
9
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)
|
||||
|
Loading…
Reference in New Issue
Block a user