Automatically remove existing system group if it exists when creating primary groups

This commit is contained in:
Alexandre Aubin 2020-03-27 19:52:24 +01:00
parent 74c1478b74
commit 3b670b6cf9
2 changed files with 6 additions and 1 deletions

View file

@ -221,6 +221,7 @@
"good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters—though it is good practice to use longer password (i.e. a passphrase) and/or to a variation of characters (uppercase, lowercase, digits and special characters).",
"group_already_exist": "Group {group} already exists",
"group_already_exist_on_system": "Group {group} already exists in the system groups",
"group_already_exist_on_system_but_removing_it": "Group {group} already exists in the system groups, but YunoHost will remove it…",
"group_created": "Group '{group}' created",
"group_creation_failed": "Could not create the group '{group}': {error}",
"group_cannot_edit_all_users": "The group 'all_users' cannot be edited manually. It is a special group meant to contain all users registered in YunoHost",

View file

@ -576,6 +576,10 @@ def user_group_create(operation_logger, groupname, gid=None, primary_group=False
# Validate uniqueness of groupname in system group
all_existing_groupnames = {x.gr_name for x in grp.getgrall()}
if groupname in all_existing_groupnames:
if primary_group:
logger.warning('group_already_exist_on_system_but_removing_it', group=groupname)
subprocess.check_call("sed --in-place '/^%s:/d' /etc/group" % groupname, shell=True)
else:
raise YunohostError('group_already_exist_on_system', group=groupname)
if not gid: