Implement -p for su(1)
This commit is contained in:
parent
7e59506b4b
commit
acb9ae197e
18
su.c
18
su.c
@ -18,10 +18,11 @@ static void dologin(struct passwd *);
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s [-l] [username]\n", argv0);
|
||||
eprintf("usage: %s [-lp] [username]\n", argv0);
|
||||
}
|
||||
|
||||
static int lflag = 0;
|
||||
static int pflag = 0;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -37,6 +38,9 @@ main(int argc, char **argv)
|
||||
case 'l':
|
||||
lflag = 1;
|
||||
break;
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND;
|
||||
@ -100,11 +104,13 @@ main(int argc, char **argv)
|
||||
dologin(pw);
|
||||
} else {
|
||||
newargv = (char *const[]){pw->pw_shell, NULL};
|
||||
setenv("HOME", pw->pw_dir, 1);
|
||||
setenv("SHELL", pw->pw_dir, 1);
|
||||
if (strcmp(pw->pw_name, "root") != 0) {
|
||||
setenv("USER", pw->pw_name, 1);
|
||||
setenv("LOGNAME", pw->pw_name, 1);
|
||||
if (!pflag) {
|
||||
setenv("HOME", pw->pw_dir, 1);
|
||||
setenv("SHELL", pw->pw_dir, 1);
|
||||
if (strcmp(pw->pw_name, "root") != 0) {
|
||||
setenv("USER", pw->pw_name, 1);
|
||||
setenv("LOGNAME", pw->pw_name, 1);
|
||||
}
|
||||
}
|
||||
execve(pw->pw_shell, newargv, environ);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user