Do not ignore the primary group if modifying the list of secondary groups. (#3585)
Fixes #1118
This commit is contained in:
parent
7d9fb08e1a
commit
c952753735
1 changed files with 12 additions and 5 deletions
|
@ -429,7 +429,8 @@ class User(object):
|
||||||
cmd.append(self.group)
|
cmd.append(self.group)
|
||||||
|
|
||||||
if self.groups is not None:
|
if self.groups is not None:
|
||||||
current_groups = self.user_group_membership()
|
# get a list of all groups for the user, including the primary
|
||||||
|
current_groups = self.user_group_membership(exclude_primary=False)
|
||||||
groups_need_mod = False
|
groups_need_mod = False
|
||||||
groups = []
|
groups = []
|
||||||
|
|
||||||
|
@ -459,7 +460,6 @@ class User(object):
|
||||||
cmd.append('-G')
|
cmd.append('-G')
|
||||||
cmd.append(','.join(groups))
|
cmd.append(','.join(groups))
|
||||||
|
|
||||||
|
|
||||||
if self.comment is not None and info[4] != self.comment:
|
if self.comment is not None and info[4] != self.comment:
|
||||||
cmd.append('-c')
|
cmd.append('-c')
|
||||||
cmd.append(self.comment)
|
cmd.append(self.comment)
|
||||||
|
@ -522,12 +522,19 @@ class User(object):
|
||||||
groups.remove(g)
|
groups.remove(g)
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
def user_group_membership(self):
|
def user_group_membership(self, exclude_primary=True):
|
||||||
|
''' Return a list of groups the user belongs to '''
|
||||||
groups = []
|
groups = []
|
||||||
info = self.get_pwd_info()
|
info = self.get_pwd_info()
|
||||||
for group in grp.getgrall():
|
for group in grp.getgrall():
|
||||||
if self.name in group.gr_mem and not info[3] == group.gr_gid:
|
if self.name in group.gr_mem:
|
||||||
|
# Exclude the user's primary group by default
|
||||||
|
if not exclude_primary:
|
||||||
groups.append(group[0])
|
groups.append(group[0])
|
||||||
|
else:
|
||||||
|
if info[3] != group.gr_gid:
|
||||||
|
groups.append(group[0])
|
||||||
|
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
def user_exists(self):
|
def user_exists(self):
|
||||||
|
|
Loading…
Reference in a new issue