su: don't set $PATH

Just /bin is too restrictive, and login shells set the path anyway via
the default profile. Also, carrying the path over for non-login shells
conforms to the behavior of util-linux's su.
This commit is contained in:
neeshy 2024-02-12 21:03:12 -05:00 committed by Roberto E. Vargas Caballero
parent e9bcdcc341
commit 4cd0b14380
2 changed files with 0 additions and 6 deletions

View File

@ -1,6 +1,5 @@
/* See LICENSE file for copyright and license details. */
#define ENV_SUPATH "/bin"
#define ENV_PATH "/bin"
#define PW_CIPHER "$6$" /* SHA-512 */
#undef UTMP_PATH

5
su.c
View File

@ -9,7 +9,6 @@
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "passwd.h"
#include "util.h"
@ -103,10 +102,6 @@ main(int argc, char *argv[])
newargv[0] = shell;
newargv[1] = NULL;
}
if (strcmp(pw->pw_name, "root") == 0)
setenv("PATH", ENV_SUPATH, 1);
else
setenv("PATH", ENV_PATH, 1);
execve(shell, newargv, environ);
weprintf("execve %s:", shell);
return (errno == ENOENT) ? 127 : 126;