su: Set the USER and SHELL variables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-05-06 12:19:54 +02:00
parent 77560bbc3e
commit b742a08cbe
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 11 additions and 7 deletions

View File

@ -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)
{

View File

@ -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);