From e87ee09b3ee9c09bf9b1f1c37ade06a503d79888 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 23 Jun 2023 02:30:38 +0200 Subject: [PATCH] postinstall: crash early if the username already exists on the system --- src/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tools.py b/src/tools.py index 740f92c9d..488ed516b 100644 --- a/src/tools.py +++ b/src/tools.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # +import pwd import re import os import subprocess @@ -174,6 +175,12 @@ def tools_postinstall( raw_msg=True, ) + # Crash early if the username is already a system user, which is + # a common confusion. We don't want to crash later and end up in an half-configured state. + all_existing_usernames = {x.pw_name for x in pwd.getpwall()} + if username in all_existing_usernames: + raise YunohostValidationError("system_username_exists") + if username in ADMIN_ALIASES: raise YunohostValidationError( f"Unfortunately, {username} cannot be used as a username", raw_msg=True