Compare commits

..

No commits in common. "1035b91a3dfae936144631d846652a7914acaeb5" and "411c6c40cd97d39837787f55c926721a8b6ef295" have entirely different histories.

5 changed files with 12 additions and 18 deletions

View File

@ -38,7 +38,7 @@ Result<int> luna_main(int argc, char** argv)
username = name.view(); username = name.view();
} }
execl("/bin/su", "login", "-lp", "--", username.chars(), nullptr); execl("/bin/su", "login", "-p", "--", username.chars(), nullptr);
perror("su"); perror("su");
return 1; return 1;

View File

@ -71,9 +71,12 @@ Result<int> luna_main(int argc, char** argv)
if (getuid() == 0) prompt_end = '#'; if (getuid() == 0) prompt_end = '#';
username = getenv("USER");
if (!username)
{
struct passwd* pw = getpwuid(getuid()); struct passwd* pw = getpwuid(getuid());
if (pw) { username = pw->pw_name; } if (pw) { username = pw->pw_name; }
else { username = getenv("USER"); } }
} }
while (1) while (1)

View File

@ -55,7 +55,6 @@ Result<int> luna_main(int argc, char** argv)
{ {
StringView name; StringView name;
bool prompt_password; bool prompt_password;
bool login;
if (geteuid() != 0) if (geteuid() != 0)
{ {
@ -68,7 +67,6 @@ Result<int> luna_main(int argc, char** argv)
parser.add_system_program_info("su"_sv); parser.add_system_program_info("su"_sv);
parser.add_positional_argument(name, "name"_sv, "root"_sv); parser.add_positional_argument(name, "name"_sv, "root"_sv);
parser.add_switch_argument(prompt_password, 'p', "prompt", "prompt for a password even if running as root"); parser.add_switch_argument(prompt_password, 'p', "prompt", "prompt for a password even if running as root");
parser.add_switch_argument(login, 'l', "login"_sv, "change directory to the user's home and start a login shell");
parser.parse(argc, argv); parser.parse(argc, argv);
struct passwd* entry = getpwnam(name.chars()); struct passwd* entry = getpwnam(name.chars());
@ -95,16 +93,10 @@ Result<int> luna_main(int argc, char** argv)
setgid(entry->pw_gid); setgid(entry->pw_gid);
setuid(entry->pw_uid); setuid(entry->pw_uid);
if (login)
{
chdir(entry->pw_dir); chdir(entry->pw_dir);
clearenv();
setenv("PATH", "/bin:/sbin", 1);
}
if (login || entry->pw_uid != 0) setenv("USER", entry->pw_name, 1);
setenv("HOME", entry->pw_dir, 1); setenv("HOME", entry->pw_dir, 1);
setenv("USER", entry->pw_name, 1);
setenv("SHELL", entry->pw_shell, 1); setenv("SHELL", entry->pw_shell, 1);
execl(entry->pw_shell, entry->pw_shell, NULL); execl(entry->pw_shell, entry->pw_shell, NULL);

View File

@ -1,3 +1,4 @@
Name=login Name=login
Command=/bin/login Command=/bin/login
Restart=true Restart=true
Environment=PATH=/bin:/sbin

View File

@ -54,10 +54,10 @@ static Result<void> _try_move_env()
if (!env) if (!env)
{ {
TRY(g_dynamic_env.try_append(nullptr));
guard.deactivate(); guard.deactivate();
env_is_dynamic = true; env_is_dynamic = true;
environ = g_dynamic_env.data(); environ = g_dynamic_env.data();
check(!environ);
return {}; return {};
} }
@ -109,12 +109,10 @@ extern "C"
{ {
if (element) free(element); if (element) free(element);
} }
g_dynamic_env.clear();
} }
environ = nullptr;
env_is_dynamic = false; env_is_dynamic = false;
environ = nullptr;
return 0; return 0;
} }