1
0
Fork 0

- 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
This commit is contained in:
Jan Dittberner 2007-07-26 13:21:36 +00:00
parent d5ace903bf
commit aaa23c9c5f
2 changed files with 14 additions and 5 deletions

View file

@ -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'))

View file

@ -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))