ldap.Auth: Fix half-baked use of jwutils.ldap module

ldap.Auth lost a lot of code when jwutils.ldap was introduced, and
rightfully so, because jwutils.ldap contains most of it. OTOH, it was
used wrongly, fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-09-11 21:35:01 +02:00
commit bc9fa57a2b

View file

@ -6,6 +6,7 @@ import ldap
from ...log import * from ...log import *
from ...ldap import bind from ...ldap import bind
from ...Config import Config
from .. import Access from .. import Access
from .. import Auth as AuthBase from .. import Auth as AuthBase
from .. import Group as GroupBase from .. import Group as GroupBase
@ -69,19 +70,12 @@ class Auth(AuthBase): # export
if self.___users is None: if self.___users is None:
ret: dict[str, User] = {} ret: dict[str, User] = {}
ret_by_email: dict[str, User] = {} ret_by_email: dict[str, User] = {}
ldap_result_id = self.__conn.search( for res in self.__conn.find(
self.__user_base_dn, self.__user_base_dn,
ldap.SCOPE_SUBTREE, ldap.SCOPE_SUBTREE,
"objectClass=inetOrgPerson", "objectClass=inetOrgPerson",
('uid', 'cn', 'uidNumber', 'mail', 'maildrop') ('uid', 'cn', 'uidNumber', 'mail', 'maildrop')
) ):
while True:
result_type, result_data = self.__conn.result(ldap_result_id, 0)
if (result_data == []):
break
if result_type != ldap.RES_SEARCH_ENTRY:
continue
for res in result_data:
try: try:
display_name = None display_name = None
if 'displayName' in res[1]: if 'displayName' in res[1]:
@ -105,6 +99,7 @@ class Auth(AuthBase): # export
ret_by_email[email] = user ret_by_email[email] = user
except Exception as e: except Exception as e:
slog(WARNING, f'Exception {e}') slog(WARNING, f'Exception {e}')
raise
continue continue
for user in self.__dummy.users.values(): for user in self.__dummy.users.values():
ret[user.name] = user ret[user.name] = user