fixed some bugs

This commit is contained in:
downhill 2018-10-26 11:59:26 +00:00
parent ea4c0ec178
commit 39f08c7939

View file

@ -56,6 +56,18 @@ def user_or_customer(uid):
conn.unbind() conn.unbind()
return False 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 # checks if a user already exists in the LDAP
class UserLookUp(object): class UserLookUp(object):
@ -100,11 +112,12 @@ class CreateUser(object):
if not conn.bind(): if not conn.bind():
self.dispatch('ldap', '%s [Error CreateUser] Could not connect to LDAPserver\n' % datetime.now() ) self.dispatch('ldap', '%s [Error CreateUser] Could not connect to LDAPserver\n' % datetime.now() )
return "Could not connect to LDAP Server." return "Could not connect to LDAP Server."
# set objectClasses for the new user # 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) w = Writer(conn, obj_new_user)
# newly created users get put into ou=customers # 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) w.new(dn)
# Filling in some of the data # Filling in some of the data
# required attributes are sn, cn, homeDirectory, uid (already handled by dn), uidNumber, gidNumber # required attributes are sn, cn, homeDirectory, uid (already handled by dn), uidNumber, gidNumber
@ -160,7 +173,9 @@ class GetUserData(object):
conn.unbind() conn.unbind()
self.dispatch('ldap', '%s [Info GetUserData] Could not find user %s\n' % (datetime.now(), LDAP_UID) ) self.dispatch('ldap', '%s [Info GetUserData] Could not find user %s\n' % (datetime.now(), LDAP_UID) )
return ("error", "Could not find the user.", "", "") 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 # The Reader gets the data for the user
r = Reader(conn, obj, rdn) r = Reader(conn, obj, rdn)
r.search() r.search()
@ -205,8 +220,10 @@ class ChangeUserData(object):
conn.unbind() conn.unbind()
self.dispatch('ldap', '%s [Info ChangeUserData] User with %s not found.\n' % (datetime.now(), LDAP_UID) ) self.dispatch('ldap', '%s [Info ChangeUserData] User with %s not found.\n' % (datetime.now(), LDAP_UID) )
return "Could not find user." 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 # Set up a reader for the user
obj = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn) obj = ObjectDef(objclass, conn)
r = Reader(conn, obj, rdn) r = Reader(conn, obj, rdn)
r.search() r.search()
# Again, user_or_customer() should prevent it from throwing an exception because it's a confirmed user # 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() conn.unbind()
self.dispatch('ldap', '%s [Error ChangePassword] Could not find user %s\n' % (datetime.now(), LDAP_UID) ) self.dispatch('ldap', '%s [Error ChangePassword] Could not find user %s\n' % (datetime.now(), LDAP_UID) )
return "Could not find the user." 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 # Set up a Reader for the DN
obj = ObjectDef(['inetOrgPerson', 'posixAccount', 'shadowAccount'], conn)
r = Reader(conn, obj, rdn) r = Reader(conn, obj, rdn)
r.search() r.search()
# Shouldn't throw an exception, since the user is confirmed to be there # Shouldn't throw an exception, since the user is confirmed to be there