Also return entries in the ldap search result

This commit is contained in:
PCoder 2019-02-24 14:43:24 +01:00
parent 89b535c3d6
commit 017ca767be

View file

@ -74,9 +74,9 @@ class LdapManager:
conn = self.get_admin_conn() conn = self.get_admin_conn()
uidNumber = self._get_max_uid() + 1 uidNumber = self._get_max_uid() + 1
logger.debug("uidNumber={uidNumber}".format(uidNumber=uidNumber)) logger.debug("uidNumber={uidNumber}".format(uidNumber=uidNumber))
results = True user_exists = True
while results: while user_exists:
results = self.check_user_exists( user_exists, _ = self.check_user_exists(
"", "",
True, True,
'(&(objectClass=inetOrgPerson)(objectClass=posixAccount)' '(&(objectClass=inetOrgPerson)(objectClass=posixAccount)'
@ -84,7 +84,7 @@ class LdapManager:
uidNumber=uidNumber uidNumber=uidNumber
) )
) )
if results: if user_exists:
logger.debug( logger.debug(
"{uid} exists. Trying next.".format(uid=uidNumber) "{uid} exists. Trying next.".format(uid=uidNumber)
) )
@ -155,15 +155,17 @@ class LdapManager:
:return: True if the user exists otherwise return False :return: True if the user exists otherwise return False
""" """
conn = self.get_admin_conn() conn = self.get_admin_conn()
entries = []
try: try:
result = conn.search( result = conn.search(
settings.LDAP_CUSTOMER_DN if is_customer else settings.LDAP_USERS_DN, settings.LDAP_CUSTOMER_DN if is_customer else settings.LDAP_USERS_DN,
search_filter=search_filter if len(search_filter)> 0 else search_filter=search_filter if len(search_filter)> 0 else
'(uid={uid})'.format(uid=uid) '(uid={uid})'.format(uid=uid)
) )
entries = conn.entries
finally: finally:
conn.unbind() conn.unbind()
return result return result, entries
def _set_max_uid(self, max_uid): def _set_max_uid(self, max_uid):
""" """