commit acb9ae197e8e71c94c8fa16bc315930d9cbc6dcd
parent 7e59506b4b6c479cabc857bd79d89ec2b7dfe1e3
Author: sin <sin@2f30.org>
Date: Fri, 18 Oct 2013 14:26:14 +0100
Implement -p for su(1)
Diffstat:
M | su.c | | | 18 | ++++++++++++------ |
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/su.c b/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);
}