Compare commits
No commits in common. "31eeff367c50b0c3481e9bfa465cbe411cc866b6" and "6adcc1eeed187893cbf4ff2eb1492a26e3b8b234" have entirely different histories.
31eeff367c
...
6adcc1eeed
1 changed files with 8 additions and 32 deletions
|
@ -116,7 +116,7 @@ class LdapServer:
|
|||
return ldap.SCOPE_SUBTREE # pylint: disable=no-member
|
||||
raise Exception(f'Unknown LDAP scope "{scope}"')
|
||||
|
||||
def search(self, basedn, filterstr=None, attrs=None, sizelimit=None, scope=None):
|
||||
def search(self, basedn, filterstr=None, attrs=None, sizelimit=0, scope=None):
|
||||
""" Run a search on LDAP server """
|
||||
assert self.con or self.connect()
|
||||
res_id = self.con.search(
|
||||
|
@ -141,18 +141,10 @@ class LdapServer:
|
|||
result = self.search(dn, filterstr=filterstr, scope='base', attrs=attrs)
|
||||
return result[dn] if dn in result else None
|
||||
|
||||
def paged_search(self, basedn, filterstr=None, attrs=None, scope=None, pagesize=None,
|
||||
sizelimit=None):
|
||||
def paged_search(self, basedn, filterstr, attrs, scope='sub', pagesize=500):
|
||||
""" Run a paged search on LDAP server """
|
||||
assert not self.v2, "Paged search is not available on LDAP version 2"
|
||||
assert self.con or self.connect()
|
||||
|
||||
# Set parameters default values (if not defined)
|
||||
filterstr = filterstr if filterstr else '(objectClass=*)'
|
||||
attrs = attrs if attrs else []
|
||||
scope = scope if scope else 'sub'
|
||||
pagesize = pagesize if pagesize else 500
|
||||
|
||||
# Initialize SimplePagedResultsControl object
|
||||
page_control = SimplePagedResultsControl(
|
||||
True,
|
||||
|
@ -216,13 +208,6 @@ class LdapServer:
|
|||
# Store results of this page
|
||||
for obj_dn, obj_attrs in rdata:
|
||||
ret[obj_dn] = obj_attrs
|
||||
# If sizelimit reached, stop
|
||||
if sizelimit and len(ret) >= sizelimit:
|
||||
break
|
||||
|
||||
# If sizelimit reached, stop
|
||||
if sizelimit and len(ret) >= sizelimit:
|
||||
break
|
||||
|
||||
# If no cookie returned, we are done
|
||||
if not result_page_control.cookie:
|
||||
|
@ -538,8 +523,7 @@ class LdapClient:
|
|||
return vals if all_values else vals[0]
|
||||
return default if default or not all_values else []
|
||||
|
||||
def get_objects(self, name, filterstr, basedn, attrs, key_attr=None, warn=True,
|
||||
paged_search=False, pagesize=None):
|
||||
def get_objects(self, name, filterstr, basedn, attrs, key_attr=None, warn=True):
|
||||
"""
|
||||
Retrieve objects from LDAP
|
||||
|
||||
|
@ -552,25 +536,17 @@ class LdapClient:
|
|||
:param warn: If True, a warning message will be logged if no object is found
|
||||
in LDAP directory (otherwise, it will be just a debug message)
|
||||
(optional, default: True)
|
||||
:param paged_search: If True, use paged search to list objects from LDAP directory
|
||||
(optional, default: False)
|
||||
:param pagesize: When using paged search, the page size
|
||||
(optional, default: see LdapServer.paged_search)
|
||||
"""
|
||||
if name in self._cached_objects:
|
||||
log.debug('Retreived %s objects from cache', name)
|
||||
else:
|
||||
assert self._conn or self.initialize()
|
||||
log.debug('Looking for LDAP %s with (filter="%s" / basedn="%s")', name, filterstr, basedn)
|
||||
if paged_search:
|
||||
ldap_data = self._conn.paged_search(
|
||||
basedn=basedn, filterstr=filterstr, attrs=attrs,
|
||||
pagesize=pagesize
|
||||
)
|
||||
else:
|
||||
ldap_data = self._conn.search(
|
||||
basedn=basedn, filterstr=filterstr, attrs=attrs,
|
||||
)
|
||||
ldap_data = self._conn.search(
|
||||
basedn=basedn,
|
||||
filterstr=filterstr,
|
||||
attrs=attrs
|
||||
)
|
||||
|
||||
if not ldap_data:
|
||||
if warn:
|
||||
|
|
Loading…
Reference in a new issue