From 24956867f0d600a4166cf87bea05ca936ae15a70 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Fri, 21 Jul 2023 18:26:42 +0200 Subject: [PATCH] mainusers only in newservers --- orchestra/contrib/systemusers/backends.py | 51 ++++++++++++----------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/orchestra/contrib/systemusers/backends.py b/orchestra/contrib/systemusers/backends.py index c63d6ba3..08e7033d 100644 --- a/orchestra/contrib/systemusers/backends.py +++ b/orchestra/contrib/systemusers/backends.py @@ -538,37 +538,38 @@ class UNIXUserControllerNewServers(ServiceController): """) % context ) - for member in settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS: - context['member'] = member - self.append('usermod -a -G %(user)s %(member)s || exit_code=$?' % context) - if not user.is_main: - self.append('usermod -a -G %(user)s %(mainuser)s || exit_code=$?' % context) + for member in settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS: + context['member'] = member + self.append('usermod -a -G %(user)s %(member)s || exit_code=$?' % context) + def delete(self, user): context = self.get_context(user) if not context['user']: return - self.append(textwrap.dedent(""" - # Delete %(user)s user - nohup bash -c 'sleep 2 && killall -u %(user)s -s KILL' &> /dev/null & - killall -u %(user)s || true - userdel %(user)s || exit_code=$? - groupdel %(group)s || exit_code=$?\ - """) % context - ) - if context['deleted_home']: + if user.is_main: self.append(textwrap.dedent("""\ - # Move home into SYSTEMUSERS_MOVE_ON_DELETE_PATH, nesting if exists. - deleted_home="%(deleted_home)s" - while [[ -e "$deleted_home" ]]; do - deleted_home="${deleted_home}/$(basename ${deleted_home})" - done - mv '%(base_home)s' "$deleted_home" || exit_code=$? + # Delete %(user)s user + nohup bash -c 'sleep 2 && killall -u %(user)s -s KILL' &> /dev/null & + killall -u %(user)s || true + userdel %(user)s || exit_code=$? + groupdel %(group)s || exit_code=$? """) % context ) - else: - self.append("rm -fr -- '%(base_home)s'" % context) + if context['deleted_home']: + self.append(textwrap.dedent("""\ + # Move home into SYSTEMUSERS_MOVE_ON_DELETE_PATH, nesting if exists. + deleted_home="%(deleted_home)s" + while [[ -e "$deleted_home" ]]; do + deleted_home="${deleted_home}/$(basename ${deleted_home})" + done + mv '%(base_home)s' "$deleted_home" || exit_code=$? + """) % context + ) + else: + self.append("rm -fr -- '%(base_home)s'" % context) + # TODO: comprovar funciones que no se suelen utilizar def grant_permissions(self, user, context): context['perms'] = user.set_perm_perms # Capital X adds execution permissions for directories, not files @@ -680,12 +681,12 @@ class UNIXUserControllerNewServers(ServiceController): ) def get_groups(self, user): + groups = [] if user.is_main: groups = list(user.account.systemusers.exclude(username=user.username).values_list('username', flat=True)) groups.append("main-systemusers") - return groups - groups = list(user.groups.values_list('username', flat=True)) - groups.append("webapp-systemusers") + # groups = list(user.groups.values_list('username', flat=True)) + # groups.append("webapp-systemusers") return groups def get_context(self, user):