From 99f763cab37e39d520b53b3a6e31c5a7a240c7e9 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 16 Jun 2023 18:08:40 +0100 Subject: [PATCH] usermod: Simplify uid validation --- Userland/Utilities/usermod.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Userland/Utilities/usermod.cpp b/Userland/Utilities/usermod.cpp index e2a40f7e59..0a422de4b9 100644 --- a/Userland/Utilities/usermod.cpp +++ b/Userland/Utilities/usermod.cpp @@ -27,7 +27,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio wpath rpath cpath fattr tty")); TRY(Core::System::unveil("/etc", "rwc")); - int uid = 0; + uid_t uid = 0; int gid = 0; bool lock = false; bool unlock = false; @@ -75,12 +75,7 @@ ErrorOr serenity_main(Main::Arguments arguments) unveil(nullptr, nullptr); if (uid) { - if (uid < 0) { - warnln("invalid uid {}", uid); - return 1; - } - - if (getpwuid(static_cast(uid))) { + if (getpwuid(uid)) { warnln("uid {} already exists", uid); return 1; }