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,8 +70,13 @@ Result<int> luna_main(int argc, char** argv)
hostname = g_sysinfo.nodename; hostname = g_sysinfo.nodename;
if (getuid() == 0) prompt_end = '#'; if (getuid() == 0) prompt_end = '#';
struct passwd* pw = getpwuid(getuid());
if (pw) { username = pw->pw_name; } username = getenv("USER");
if (!username)
{
struct passwd* pw = getpwuid(getuid());
if (pw) { username = pw->pw_name; }
}
} }
while (1) while (1)

View File

@ -92,11 +92,10 @@ Result<int> luna_main(int argc, char** argv)
setuid(entry->pw_uid); setuid(entry->pw_uid);
chdir(entry->pw_dir); chdir(entry->pw_dir);
if (setenv("HOME", entry->pw_dir, 1) < 0)
{ setenv("HOME", entry->pw_dir, 1);
perror("setenv"); setenv("USER", entry->pw_name, 1);
return 1; setenv("SHELL", entry->pw_shell, 1);
}
execl(entry->pw_shell, entry->pw_shell, NULL); execl(entry->pw_shell, entry->pw_shell, NULL);