fixed some bugs

This commit is contained in:
downhill 2018-10-26 11:59:26 +00:00
parent ea4c0ec178
commit 39f08c7939
1 changed files with 24 additions and 5 deletions

View File

@ -56,6 +56,18 @@ def user_or_customer(uid):
conn.unbind()
return False
# Get the objectclasses
def objclasses(rdn, uid, connection):
# search for objectClasses
connection.search(rdn, '(%s)' % uid, attributes=['objectClass'])
objclass = []
# get the relevant data
tmp = conn.entries[0]['objectClass']
# This one sets up the array
for y in tmp:
objclass.append(y)
# return the array containing the objectClasses, like ['inetOrgPerson', 'posixAccount', 'ldapPublicKey']
return objclass
# checks if a user already exists in the LDAP
class UserLookUp(object):
@ -100,11 +112,12 @@ class CreateUser(object):
if not conn.bind():
self.dispatch('ldap', '%s [Error CreateUser] Could not connect to LDAPserver\n' % datetime.now() )
return "Could not connect to LDAP Server."
# set objectClasses for the new user
obj_new_user = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn)
obj_new_user = ObjectDef(['inetOrgPerson', 'posixAccount', 'ldapPublicKey'], conn)
w = Writer(conn, obj_new_user)
# newly created users get put into ou=customers
dn = 'uid=%s,ou=customers,dc=ungleich,dc=ch' % user
dn = 'uid=%s,ou=users,dc=ungleich,dc=ch' % user
w.new(dn)
# Filling in some of the data
# required attributes are sn, cn, homeDirectory, uid (already handled by dn), uidNumber, gidNumber
@ -160,7 +173,9 @@ class GetUserData(object):
conn.unbind()
self.dispatch('ldap', '%s [Info GetUserData] Could not find user %s\n' % (datetime.now(), LDAP_UID) )
return ("error", "Could not find the user.", "", "")
obj = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn)
# Workaround because not all users have the same objectClasses
objclass = objclasses(rdn, LDAP_UID, conn)
obj = ObjectDef(objclass, conn)
# The Reader gets the data for the user
r = Reader(conn, obj, rdn)
r.search()
@ -205,8 +220,10 @@ class ChangeUserData(object):
conn.unbind()
self.dispatch('ldap', '%s [Info ChangeUserData] User with %s not found.\n' % (datetime.now(), LDAP_UID) )
return "Could not find user."
# Fix because not every user has the same objectClasses
objclass = objclasses(rdn, LDAP_UID, conn)
# Set up a reader for the user
obj = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn)
obj = ObjectDef(objclass, conn)
r = Reader(conn, obj, rdn)
r.search()
# Again, user_or_customer() should prevent it from throwing an exception because it's a confirmed user
@ -253,8 +270,10 @@ class ChangePassword(object):
conn.unbind()
self.dispatch('ldap', '%s [Error ChangePassword] Could not find user %s\n' % (datetime.now(), LDAP_UID) )
return "Could not find the user."
# Plus not everyone has the same objectClasses, so workaround
objclass = objclasses(rdn, LDAP_UID, conn)
obj = ObjectDef(objclass, conn)
# Set up a Reader for the DN
obj = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn)
r = Reader(conn, obj, rdn)
r.search()
# Shouldn't throw an exception, since the user is confirmed to be there