Fix UID mismatch bug by directly querying ldapsearch
This commit is contained in:
parent
660e75bff2
commit
c666bbe689
10
adduser
10
adduser
|
@ -13,8 +13,12 @@ def adduser(username, firstname, lastname, email, password):
|
||||||
"""Add a new user"""
|
"""Add a new user"""
|
||||||
|
|
||||||
# Get UID
|
# Get UID
|
||||||
output = str(check_output(['getent', 'passwd']))
|
output = check_output(['ldapsearch', '-x', 'uidNumber']).decode('utf-8')
|
||||||
uid = [u for u in range(1000, 10000) if str(u) not in output][0]
|
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
|
# Construct LDIF
|
||||||
ldif = f'''dn: uid={username},ou=People,dc=exozy,dc=me
|
ldif = f'''dn: uid={username},ou=People,dc=exozy,dc=me
|
||||||
|
@ -49,9 +53,9 @@ gidNumber: {uid}'''
|
||||||
# Add user
|
# Add user
|
||||||
ret = call(['ldapadd', '-D', 'cn=Manager,dc=exozy,dc=me', '-w',
|
ret = call(['ldapadd', '-D', 'cn=Manager,dc=exozy,dc=me', '-w',
|
||||||
open('/etc/ldappass', 'r').read(), '-f', filename])
|
open('/etc/ldappass', 'r').read(), '-f', filename])
|
||||||
remove(filename)
|
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
return
|
return
|
||||||
|
remove(filename)
|
||||||
|
|
||||||
# Configure and set up user
|
# Configure and set up user
|
||||||
# Make home directory
|
# Make home directory
|
||||||
|
|
Loading…
Reference in a new issue