Commit 09d2ca06 authored by Titouan Soulard's avatar Titouan Soulard

format: do not remove user from groups

When an user belonged to a group before running slapformat, the user was previously
removed from that group. This commit avoids it by simply appending SlapOS
additional groups.
parent 9af91a70
...@@ -874,7 +874,6 @@ class User(object): ...@@ -874,7 +874,6 @@ class User(object):
""" """
# XXX: This method shall be no-op in case if all is correctly setup # XXX: This method shall be no-op in case if all is correctly setup
# This method shall check if all is correctly done # This method shall check if all is correctly done
# This method shall not reset groups, just add them
grpname = 'grp_' + self.name if sys.platform == 'cygwin' else self.name grpname = 'grp_' + self.name if sys.platform == 'cygwin' else self.name
try: try:
grp.getgrnam(grpname) grp.getgrnam(grpname)
...@@ -882,17 +881,23 @@ class User(object): ...@@ -882,17 +881,23 @@ class User(object):
callAndRead(['groupadd', grpname]) callAndRead(['groupadd', grpname])
user_parameter_list = ['-d', self.path, '-g', self.name, '-s', self.shell] user_parameter_list = ['-d', self.path, '-g', self.name, '-s', self.shell]
if self.additional_group_list is not None: additional_groups_flag = '-aG'
user_parameter_list.extend(['-G', ','.join(self.additional_group_list)]) command = 'usermod'
user_parameter_list.append(self.name)
try: try:
pwd.getpwnam(self.name) pwd.getpwnam(self.name)
except KeyError: except KeyError:
user_parameter_list.append('-r') user_parameter_list.append('-r')
callAndRead(['useradd'] + user_parameter_list) additional_groups_flag = '-G'
else: command = 'useradd'
# if the user is already created and used we should not fail
callAndRead(['usermod'] + user_parameter_list, raise_on_error=False) if self.additional_group_list is not None:
user_parameter_list.extend([additional_groups_flag, ','.join(self.additional_group_list)])
user_parameter_list.insert(0, command)
user_parameter_list.append(self.name)
callAndRead(user_parameter_list, raise_on_error=False)
# lock the password of user # lock the password of user
callAndRead(['passwd', '-l', self.name]) callAndRead(['passwd', '-l', self.name])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment