mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
passwd+su: Convert fprintf(stderr, ...) to warnln()
This commit is contained in:
parent
77656aed8e
commit
2b41155c07
2 changed files with 10 additions and 8 deletions
|
@ -35,7 +35,7 @@
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
if (geteuid() != 0) {
|
||||
fprintf(stderr, "Not running as root :^(\n");
|
||||
warnln("Not running as root :^(");
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ int main(int argc, char** argv)
|
|||
auto& target_account = account_or_error.value();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ int main(int argc, char** argv)
|
|||
} else {
|
||||
auto new_password = Core::get_password("New password: ");
|
||||
if (new_password.is_error()) {
|
||||
fprintf(stderr, "%s\n", strerror(new_password.error()));
|
||||
warnln("{}", strerror(new_password.error()));
|
||||
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.parse(argc, argv);
|
||||
|
||||
if (geteuid() != 0)
|
||||
fprintf(stderr, "Not running as root :(\n");
|
||||
if (geteuid() != 0) {
|
||||
warnln("Not running as root :(");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto account_or_error = (user)
|
||||
? 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()) {
|
||||
auto password = Core::get_password();
|
||||
if (password.is_error()) {
|
||||
fprintf(stderr, "%s\n", strerror(password.error()));
|
||||
warnln("{}", strerror(password.error()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!account.authenticate(password.value().characters())) {
|
||||
fprintf(stderr, "Incorrect or disabled password.\n");
|
||||
warnln("Incorrect or disabled password.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue