Compare commits
No commits in common. "88180b34bd8259baa8d621ee2db1621cb98b23fb" and "b742a08cbe283cf674d47924d1be6f9696e6a9dd" have entirely different histories.
88180b34bd
...
b742a08cbe
@ -22,4 +22,3 @@ luna_app(rm.cpp rm)
|
|||||||
luna_app(stat.cpp stat)
|
luna_app(stat.cpp stat)
|
||||||
luna_app(uname.cpp uname)
|
luna_app(uname.cpp uname)
|
||||||
luna_app(base64.cpp base64)
|
luna_app(base64.cpp base64)
|
||||||
luna_app(login.cpp login)
|
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
#include <luna/String.h>
|
|
||||||
#include <os/ArgumentParser.h>
|
|
||||||
#include <os/File.h>
|
|
||||||
#include <stdio.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())
|
|
||||||
{
|
|
||||||
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", "-p", "--", username.chars(), nullptr);
|
|
||||||
|
|
||||||
perror("su");
|
|
||||||
return 1;
|
|
||||||
}
|
|
10
apps/su.cpp
10
apps/su.cpp
@ -54,11 +54,10 @@ char* getpass()
|
|||||||
Result<int> luna_main(int argc, char** argv)
|
Result<int> luna_main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
StringView name;
|
StringView name;
|
||||||
bool prompt_password;
|
|
||||||
|
|
||||||
if (geteuid() != 0)
|
if (geteuid() != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s must be setuid root!\n", argv[0]);
|
fprintf(stderr, "su must be setuid root!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,24 +65,23 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
parser.add_description("Switch to a different user (by default, root)."_sv);
|
parser.add_description("Switch to a different user (by default, root)."_sv);
|
||||||
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.parse(argc, argv);
|
parser.parse(argc, argv);
|
||||||
|
|
||||||
struct passwd* entry = getpwnam(name.chars());
|
struct passwd* entry = getpwnam(name.chars());
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: user %s not found!\n", argv[0], name.chars());
|
fprintf(stderr, "su: user %s not found!\n", name.chars());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prompt_password || getuid() != geteuid()) && *entry->pw_passwd)
|
if (getuid() != geteuid() && *entry->pw_passwd)
|
||||||
{
|
{
|
||||||
char* pass = getpass();
|
char* pass = getpass();
|
||||||
if (!pass) return 1;
|
if (!pass) return 1;
|
||||||
|
|
||||||
if (strcmp(pass, entry->pw_passwd))
|
if (strcmp(pass, entry->pw_passwd))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: wrong password!\n", argv[0]);
|
fprintf(stderr, "Wrong password!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Name=login
|
Name=shell
|
||||||
Command=/bin/login
|
Command=/bin/sh
|
||||||
Restart=true
|
Restart=true
|
||||||
Environment=PATH=/bin:/sbin
|
Environment=PATH=/bin:/sbin
|
@ -1,4 +1,2 @@
|
|||||||
Welcome to the Luna system!
|
Welcome to the Luna system!
|
||||||
Have a look around, you can run 'ls /bin' to list available commands.
|
Have a look around, you can run 'ls /bin' to list available commands.
|
||||||
|
|
||||||
You can use the username 'selene' with the password 'moon' to start a user session.
|
|
||||||
|
@ -275,8 +275,7 @@ namespace os
|
|||||||
|
|
||||||
if (!m_description.is_empty()) { puts(m_description.chars()); }
|
if (!m_description.is_empty()) { puts(m_description.chars()); }
|
||||||
|
|
||||||
if (m_switch_args.size() || m_value_args.size() || m_add_long_help_flag || m_add_long_version_flag ||
|
if (m_switch_args.size() || m_value_args.size())
|
||||||
m_add_short_help_flag || m_add_short_version_flag)
|
|
||||||
{
|
{
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
puts("Options:");
|
puts("Options:");
|
||||||
|
Loading…
Reference in New Issue
Block a user