Skip to content

Commit

Permalink
Update system/group.py module.
Browse files Browse the repository at this point in the history
Add ability to add system groups with next free system gid (< 500) on macOS.
  • Loading branch information
rqelibari authored and bcoca committed Nov 15, 2016
1 parent f35be48 commit a4cddac
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions system/group.py
Expand Up @@ -269,6 +269,11 @@ def group_add(self, **kwargs):
cmd += [ '-o', 'create' ]
if self.gid is not None:
cmd += [ '-i', self.gid ]
elif 'system' in kwargs and kwargs['system'] == True:
gid = self.get_lowest_available_system_gid()
if gid != False:
self.gid = str(gid)
cmd += [ '-i', self.gid ]
cmd += [ '-L', self.name ]
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
Expand All @@ -291,6 +296,26 @@ def group_mod(self, gid=None):
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
return (None, '', '')

def get_lowest_available_system_gid(self):
# check for lowest available system gid (< 500)
try:
cmd = [self.module.get_bin_path('dscl', True)]
cmd += [ '/Local/Default', '-list', '/Groups', 'PrimaryGroupID']
(rc, out, err) = self.execute_command(cmd)
lines = out.splitlines()
highest = 0
for group_info in lines:
parts = group_info.split(' ')
if len(parts) > 1:
gid = int(parts[-1])
if gid > highest and gid < 500:
highest = gid
if highest == 0 or highest == 499:
return False
return (highest + 1)
except:
return False

class OpenBsdGroup(Group):
"""
Expand Down

0 comments on commit a4cddac

Please sign in to comment.