diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index c2cb8381d7..43992966ae 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -81,6 +81,7 @@ target_link_libraries(gml-format LibGUI) target_link_libraries(grep LibRegex) target_link_libraries(gunzip LibCompress) target_link_libraries(gron LibMain) +target_link_libraries(groups LibMain) target_link_libraries(gzip LibCompress) target_link_libraries(id LibMain) target_link_libraries(jp LibMain) diff --git a/Userland/Utilities/groups.cpp b/Userland/Utilities/groups.cpp index 4d13e712d5..4a448ff5ac 100644 --- a/Userland/Utilities/groups.cpp +++ b/Userland/Utilities/groups.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -26,47 +28,24 @@ static void print_account_gids(const Core::Account& account) outln(); } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (unveil("/etc/passwd", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/etc/shadow", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/etc/group", "r") < 0) { - perror("unveil"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - - if (pledge("stdio rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::unveil("/etc/passwd", "r")); + TRY(Core::System::unveil("/etc/shadow", "r")); + TRY(Core::System::unveil("/etc/group", "r")); + TRY(Core::System::unveil(nullptr, nullptr)); + TRY(Core::System::pledge("stdio rpath", nullptr)); Vector usernames; Core::ArgsParser args_parser; args_parser.set_general_help("Print group memberships for each username or, if no username is specified, for the current process."); args_parser.add_positional_argument(usernames, "Usernames to list group memberships for", "usernames", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(arguments); if (usernames.is_empty()) { - auto result = Core::Account::from_uid(geteuid()); - if (result.is_error()) { - warnln("{}", result.error()); - return 1; - } - print_account_gids(result.value()); + auto account = TRY(Core::Account::from_uid(geteuid())); + print_account_gids(account); } for (auto username : usernames) {