diff --git a/adduser b/adduser index 6a4caad..7b8d006 100755 --- a/adduser +++ b/adduser @@ -13,8 +13,12 @@ def adduser(username, firstname, lastname, email, password): """Add a new user""" # Get UID - output = str(check_output(['getent', 'passwd'])) - uid = [u for u in range(1000, 10000) if str(u) not in output][0] + output = check_output(['ldapsearch', '-x', 'uidNumber']).decode('utf-8') + used = set() + for line in output.split('\n'): + if line.startswith('uidNumber'): + used.add(int(line.split()[1])) + uid = [u for u in range(1001, 10000) if u not in used][0] # Construct LDIF ldif = f'''dn: uid={username},ou=People,dc=exozy,dc=me @@ -49,9 +53,9 @@ gidNumber: {uid}''' # Add user ret = call(['ldapadd', '-D', 'cn=Manager,dc=exozy,dc=me', '-w', open('/etc/ldappass', 'r').read(), '-f', filename]) - remove(filename) if ret != 0: return + remove(filename) # Configure and set up user # Make home directory