All checks were successful
continuous-integration/drone/push Build is passing
Also, the console sends SIGINT to the foreground process group when ^C is pressed!
57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#include <bits/termios.h>
|
|
#include <luna/String.h>
|
|
#include <os/ArgumentParser.h>
|
|
#include <os/File.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <sys/ioctl.h>
|
|
#include <unistd.h>
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
{
|
|
StringView username;
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("Begin a new session on the system.");
|
|
parser.add_system_program_info("login"_sv);
|
|
parser.add_positional_argument(username, "user", false);
|
|
parser.parse(argc, argv);
|
|
|
|
if (geteuid() != 0)
|
|
{
|
|
os::eprintln("error: login must be run as root.");
|
|
return 1;
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
String name;
|
|
|
|
if (username.is_empty())
|
|
{
|
|
signal(SIGTTOU, SIG_IGN);
|
|
|
|
if (isatty(STDIN_FILENO))
|
|
{
|
|
pid_t pgid = getpgid(0);
|
|
ioctl(STDIN_FILENO, TIOCSPGRP, &pgid);
|
|
}
|
|
|
|
auto input = os::File::standard_input();
|
|
|
|
os::print("Username: ");
|
|
|
|
name = TRY(input->read_line());
|
|
name.trim("\n");
|
|
|
|
if (name.is_empty()) return 0;
|
|
|
|
username = name.view();
|
|
}
|
|
|
|
execl("/bin/su", "login", "-lp", "--", username.chars(), nullptr);
|
|
|
|
perror("su");
|
|
return 1;
|
|
}
|