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,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)
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user