From d7a25cdb82ff5326236934dd6e99e1a1b2bef3fe Mon Sep 17 00:00:00 2001 From: brapru Date: Tue, 8 Jun 2021 21:35:50 -0400 Subject: [PATCH] Utilities: Do not allow creating users with existing usernames Previously useradd would not check if a username already existed on the system, and would instead add the user anyway and just increment the uid. useradd should instead return an error when the user attempts to create already existing users. --- Userland/Utilities/useradd.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Utilities/useradd.cpp b/Userland/Utilities/useradd.cpp index 37f8b60a1a..3b6b50db24 100644 --- a/Userland/Utilities/useradd.cpp +++ b/Userland/Utilities/useradd.cpp @@ -64,6 +64,11 @@ int main(int argc, char** argv) return 1; } + if (getpwnam(username)) { + warnln("user {} already exists!", username); + return 1; + } + if (uid < 0) { warnln("invalid uid {}!", uid); return 3;