Update system/group.py module.

Add ability to add system groups with next free system gid (< 500) on macOS.
This commit is contained in:
Rezart Qelibari 2016-11-15 01:52:25 +01:00 committed by Matt Clay
parent 5945b19ad3
commit d7e9fbe631

View file

@ -269,6 +269,11 @@ class DarwinGroup(Group):
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)
@ -292,6 +297,26 @@ class DarwinGroup(Group):
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):
"""
This is a OpenBSD Group manipulation class.