su: Set the USER and SHELL variables
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
77560bbc3e
commit
b742a08cbe
@ -70,9 +70,14 @@ Result<int> luna_main(int argc, char** argv)
|
||||
hostname = g_sysinfo.nodename;
|
||||
|
||||
if (getuid() == 0) prompt_end = '#';
|
||||
|
||||
username = getenv("USER");
|
||||
if (!username)
|
||||
{
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
if (pw) { username = pw->pw_name; }
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -92,11 +92,10 @@ Result<int> luna_main(int argc, char** argv)
|
||||
setuid(entry->pw_uid);
|
||||
|
||||
chdir(entry->pw_dir);
|
||||
if (setenv("HOME", entry->pw_dir, 1) < 0)
|
||||
{
|
||||
perror("setenv");
|
||||
return 1;
|
||||
}
|
||||
|
||||
setenv("HOME", entry->pw_dir, 1);
|
||||
setenv("USER", entry->pw_name, 1);
|
||||
setenv("SHELL", entry->pw_shell, 1);
|
||||
|
||||
execl(entry->pw_shell, entry->pw_shell, NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user