diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 420acdf5b9..d6bcfaf64f 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -106,6 +106,7 @@ target_link_libraries(test-pthread LibThreading) target_link_libraries(truncate LibMain) target_link_libraries(tt LibPthread) target_link_libraries(unzip LibArchive LibCompress) +target_link_libraries(userdel LibMain) target_link_libraries(utmpupdate LibMain) target_link_libraries(zip LibArchive LibCompress LibCrypto) target_link_libraries(cpp-lexer LibCpp) diff --git a/Userland/Utilities/userdel.cpp b/Userland/Utilities/userdel.cpp index ddb4383fc9..7a2c40e48d 100644 --- a/Userland/Utilities/userdel.cpp +++ b/Userland/Utilities/userdel.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -25,22 +27,11 @@ #include #include -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments arguments) { - if (pledge("stdio wpath rpath cpath fattr proc exec", nullptr) < 0) { - perror("pledge"); - return 1; - } - - if (unveil("/etc/", "rwc") < 0) { - perror("unveil"); - return 1; - } - - if (unveil("/bin/rm", "x") < 0) { - perror("unveil"); - return 1; - } + TRY(Core::System::pledge("stdio wpath rpath cpath fattr proc exec", nullptr)); + TRY(Core::System::unveil("/etc/", "rwc")); + TRY(Core::System::unveil("/bin/rm", "x")); const char* username = nullptr; bool remove_home = false; @@ -48,7 +39,7 @@ int main(int argc, char** argv) Core::ArgsParser args_parser; args_parser.add_option(remove_home, "Remove home directory", "remove", 'r'); args_parser.add_positional_argument(username, "Login user identity (username)", "login"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); auto account_or_error = Core::Account::from_name(username); @@ -60,18 +51,11 @@ int main(int argc, char** argv) auto& target_account = account_or_error.value(); if (remove_home) { - if (unveil(target_account.home_directory().characters(), "c") < 0) { - perror("unveil"); - return 1; - } + TRY(Core::System::unveil(target_account.home_directory().characters(), "c")); } else { - if (pledge("stdio wpath rpath cpath fattr", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio wpath rpath cpath fattr", nullptr)); } - - unveil(nullptr, nullptr); + TRY(Core::System::unveil(nullptr, nullptr)); char temp_passwd[] = "/etc/passwd.XXXXXX"; char temp_shadow[] = "/etc/shadow.XXXXXX";