mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
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:
parent
d1c83c0515
commit
bc9fa57a2b
1 changed files with 29 additions and 34 deletions
|
|
@ -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,45 +70,39 @@ 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:
|
try:
|
||||||
result_type, result_data = self.__conn.result(ldap_result_id, 0)
|
display_name = None
|
||||||
if (result_data == []):
|
if 'displayName' in res[1]:
|
||||||
break
|
cn = res[1]['displayName'][0].decode('utf-8')
|
||||||
if result_type != ldap.RES_SEARCH_ENTRY:
|
else:
|
||||||
continue
|
cn = res[1]['cn'][0].decode('utf-8')
|
||||||
for res in result_data:
|
uid = res[1]['uid'][0].decode('utf-8')
|
||||||
try:
|
uidNumber = res[1]['uidNumber'][0].decode('utf-8')
|
||||||
display_name = None
|
emails = []
|
||||||
if 'displayName' in res[1]:
|
#for attr in ['mail', 'maildrop']:
|
||||||
cn = res[1]['displayName'][0].decode('utf-8')
|
for attr in ['mail']:
|
||||||
else:
|
if attr in res[1]:
|
||||||
cn = res[1]['cn'][0].decode('utf-8')
|
for entry in res[1][attr]:
|
||||||
uid = res[1]['uid'][0].decode('utf-8')
|
emails.append(entry.decode('utf-8'))
|
||||||
uidNumber = res[1]['uidNumber'][0].decode('utf-8')
|
if not emails:
|
||||||
emails = []
|
slog(DEBUG, f'No email for user "{uid}", skipping')
|
||||||
#for attr in ['mail', 'maildrop']:
|
|
||||||
for attr in ['mail']:
|
|
||||||
if attr in res[1]:
|
|
||||||
for entry in res[1][attr]:
|
|
||||||
emails.append(entry.decode('utf-8'))
|
|
||||||
if not emails:
|
|
||||||
slog(DEBUG, f'No email for user "{uid}", skipping')
|
|
||||||
continue
|
|
||||||
user = User(self, name=uid, cn=cn, email=emails[0])
|
|
||||||
ret[uid] = user
|
|
||||||
for email in emails:
|
|
||||||
ret_by_email[email] = user
|
|
||||||
except Exception as e:
|
|
||||||
slog(WARNING, f'Exception {e}')
|
|
||||||
continue
|
continue
|
||||||
for user in self.__dummy.users.values():
|
user = User(self, name=uid, cn=cn, email=emails[0])
|
||||||
ret[user.name] = user
|
ret[uid] = user
|
||||||
|
for email in emails:
|
||||||
|
ret_by_email[email] = user
|
||||||
|
except Exception as e:
|
||||||
|
slog(WARNING, f'Exception {e}')
|
||||||
|
raise
|
||||||
|
continue
|
||||||
|
for user in self.__dummy.users.values():
|
||||||
|
ret[user.name] = user
|
||||||
self.___users = ret
|
self.___users = ret
|
||||||
self.___user_by_email = ret_by_email
|
self.___user_by_email = ret_by_email
|
||||||
return self.___users
|
return self.___users
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue