Implement -p for su(1)

This commit is contained in:
sin 2013-10-18 14:26:14 +01:00
parent 7e59506b4b
commit acb9ae197e

18
su.c
View File

@ -18,10 +18,11 @@ static void dologin(struct passwd *);
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-l] [username]\n", argv0); eprintf("usage: %s [-lp] [username]\n", argv0);
} }
static int lflag = 0; static int lflag = 0;
static int pflag = 0;
int int
main(int argc, char **argv) main(int argc, char **argv)
@ -37,6 +38,9 @@ main(int argc, char **argv)
case 'l': case 'l':
lflag = 1; lflag = 1;
break; break;
case 'p':
pflag = 1;
break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;
@ -100,11 +104,13 @@ main(int argc, char **argv)
dologin(pw); dologin(pw);
} else { } else {
newargv = (char *const[]){pw->pw_shell, NULL}; newargv = (char *const[]){pw->pw_shell, NULL};
setenv("HOME", pw->pw_dir, 1); if (!pflag) {
setenv("SHELL", pw->pw_dir, 1); setenv("HOME", pw->pw_dir, 1);
if (strcmp(pw->pw_name, "root") != 0) { setenv("SHELL", pw->pw_dir, 1);
setenv("USER", pw->pw_name, 1); if (strcmp(pw->pw_name, "root") != 0) {
setenv("LOGNAME", pw->pw_name, 1); setenv("USER", pw->pw_name, 1);
setenv("LOGNAME", pw->pw_name, 1);
}
} }
execve(pw->pw_shell, newargv, environ); execve(pw->pw_shell, newargv, environ);
} }