mirror of git://git.suckless.org/ubase
su: check $SHELL for validity
If $SHELL isn't defined in the environment, the call to execve will fail when -p is specified. Fallback to the user's login shell if $SHELL is invalid.
This commit is contained in:
parent
cf9e26d7fa
commit
e9bcdcc341
6
su.c
6
su.c
|
@ -28,7 +28,7 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *usr = "root", *pass;
|
char *usr = "root", *pass;
|
||||||
char *shell, *term;
|
char *shell, *envshell, *term;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
char *newargv[3];
|
char *newargv[3];
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
@ -89,7 +89,9 @@ main(int argc, char *argv[])
|
||||||
newargv[2] = NULL;
|
newargv[2] = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (pflag) {
|
if (pflag) {
|
||||||
shell = getenv("SHELL");
|
envshell = getenv("SHELL");
|
||||||
|
if (envshell && envshell[0] != '\0')
|
||||||
|
shell = envshell;
|
||||||
} else {
|
} else {
|
||||||
setenv("HOME", pw->pw_dir, 1);
|
setenv("HOME", pw->pw_dir, 1);
|
||||||
setenv("SHELL", shell, 1);
|
setenv("SHELL", shell, 1);
|
||||||
|
|
Loading…
Reference in New Issue