summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfaxe1008 <fabianblatz@gmail.com>2021-11-23 17:18:47 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-23 22:54:25 +0100
commitb49bed5152b32b456afb8e01051dce2a8b97176d (patch)
treed994b29dfd2d8e0b979f10a188c6c4de12d628d5
parentb2e7102194076f3a46a7846706b8abe883954e12 (diff)
downloadserenity-b49bed5152b32b456afb8e01051dce2a8b97176d.zip
userdel: Port to LibMain
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/userdel.cpp36
2 files changed, 11 insertions, 26 deletions
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 <LibCore/Account.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
@@ -25,22 +27,11 @@
#include <sys/wait.h>
#include <unistd.h>
-int main(int argc, char** argv)
+ErrorOr<int> 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";