mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
passwd+su: Convert fprintf(stderr, ...) to warnln()
This commit is contained in:
parent
77656aed8e
commit
2b41155c07
Notes:
sideshowbarker
2024-07-18 23:58:43 +09:00
Author: https://github.com/awesomekling
Commit: 2b41155c07
2 changed files with 10 additions and 8 deletions
|
@ -35,7 +35,7 @@
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (geteuid() != 0) {
|
if (geteuid() != 0) {
|
||||||
fprintf(stderr, "Not running as root :^(\n");
|
warnln("Not running as root :^(");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ int main(int argc, char** argv)
|
||||||
: Core::Account::from_uid(current_uid, Core::Account::OpenPasswdFile::ReadWrite, Core::Account::OpenShadowFile::ReadWrite);
|
: Core::Account::from_uid(current_uid, Core::Account::OpenPasswdFile::ReadWrite, Core::Account::OpenShadowFile::ReadWrite);
|
||||||
|
|
||||||
if (account_or_error.is_error()) {
|
if (account_or_error.is_error()) {
|
||||||
fprintf(stderr, "Core::Account::%s: %s\n", (username) ? "from_name" : "from_uid", account_or_error.error().characters());
|
warnln("Core::Account::{}: {}", (username) ? "from_name" : "from_uid", account_or_error.error());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
||||||
auto& target_account = account_or_error.value();
|
auto& target_account = account_or_error.value();
|
||||||
|
|
||||||
if (current_uid != 0 && current_uid != target_account.uid()) {
|
if (current_uid != 0 && current_uid != target_account.uid()) {
|
||||||
fprintf(stderr, "You can't modify passwd for %s\n", username);
|
warnln("You can't modify passwd for {}", username);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ int main(int argc, char** argv)
|
||||||
} else {
|
} else {
|
||||||
auto new_password = Core::get_password("New password: ");
|
auto new_password = Core::get_password("New password: ");
|
||||||
if (new_password.is_error()) {
|
if (new_password.is_error()) {
|
||||||
fprintf(stderr, "%s\n", strerror(new_password.error()));
|
warnln("{}", strerror(new_password.error()));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,10 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_positional_argument(user, "User to switch to (defaults to user with UID 0)", "user", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(user, "User to switch to (defaults to user with UID 0)", "user", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
if (geteuid() != 0)
|
if (geteuid() != 0) {
|
||||||
fprintf(stderr, "Not running as root :(\n");
|
warnln("Not running as root :(");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
auto account_or_error = (user)
|
auto account_or_error = (user)
|
||||||
? Core::Account::from_name(user, Core::Account::OpenPasswdFile::No, Core::Account::OpenShadowFile::ReadOnly)
|
? Core::Account::from_name(user, Core::Account::OpenPasswdFile::No, Core::Account::OpenShadowFile::ReadOnly)
|
||||||
|
@ -73,12 +75,12 @@ int main(int argc, char** argv)
|
||||||
if (getuid() != 0 && account.has_password()) {
|
if (getuid() != 0 && account.has_password()) {
|
||||||
auto password = Core::get_password();
|
auto password = Core::get_password();
|
||||||
if (password.is_error()) {
|
if (password.is_error()) {
|
||||||
fprintf(stderr, "%s\n", strerror(password.error()));
|
warnln("{}", strerror(password.error()));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!account.authenticate(password.value().characters())) {
|
if (!account.authenticate(password.value().characters())) {
|
||||||
fprintf(stderr, "Incorrect or disabled password.\n");
|
warnln("Incorrect or disabled password.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue