Browse Source

- use first free uid in range for system user accounts

- new function for getting the first free uid in a range in getenttools


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@237 a67ec6bc-e5d5-0310-a910-815c51eb3124
master
Jan Dittberner 14 years ago
parent
commit
aaa23c9c5f
  1. 7
      gnuviechadmin/backend/sysuser.py
  2. 12
      gnuviechadmin/util/getenttools.py

7
gnuviechadmin/backend/sysuser.py

@ -74,11 +74,8 @@ class SysuserEntity(BackendEntity):
return config.get('sysuser', 'shellno')
def _get_next_sysuid(self):
uid = int(config.get('sysuser', 'minuid'))
muid = getenttools.get_max_uid(int(config.get('sysuser', 'maxuid')))
if muid >= uid:
uid = muid + 1
return uid
return getenttools.get_next_uid(int(config.get('sysuser', 'minuid')),
int(config.get('sysuser', 'maxuid')))
def _populate_home(self):
templatedir = get_template_dir(config.get('sysuser', 'hometemplate'))

12
gnuviechadmin/util/getenttools.py

@ -77,6 +77,16 @@ def get_group_by_id(gid):
return groups[0]
return None
def get_next_uid(lowerboundary = 10000, upperboundary = 65536):
"""Gets the first available user id in the range between lowerboundary and
upper boundary."""
for uid in range(lowerboundary, upperboundary):
try:
user = pwd.getpwuid(uid)
except KeyError:
return uid
raise Exception("no free uid found in range %d to %d", lowerboundary, upperboundary)
def get_max_uid(boundary = 65536):
"""Gets the highest uid value."""
return max([user.uid for user in parse_users() if user.uid <= boundary])
@ -91,3 +101,5 @@ if __name__ == "__main__":
print "Max GID is %d" % (get_max_gid(40000))
print "User with max UID is %s" % (get_user_by_id(get_max_uid(40000)))
print "Group with max GID is %s" % (get_group_by_id(get_max_gid(40000)))
print "First free UID is %s" % (get_next_uid(10000, 40000))

Loading…
Cancel
Save