diff --git a/CHANGES.rst b/CHANGES.rst index 55cb112..ca4e46b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,10 @@ History 1.0b11 (unreleased) ------------------- +- Return empty search result list when an LDAP error occurs. + Fixes `issue #50 `_. + [maurits] + - Skip objects that were found in LDAP while searching on several attributes but don't contain the required attribute. [fredvd, maurits] diff --git a/src/node/ext/ldap/base.py b/src/node/ext/ldap/base.py index d66a9a7..a002015 100644 --- a/src/node/ext/ldap/base.py +++ b/src/node/ext/ldap/base.py @@ -222,14 +222,18 @@ def _search(baseDN, scope, queryFilter, # in case we do pagination of results if type(attrlist) in (list, tuple): attrlist = [str(_) for _ in attrlist] - msgid = self._con.search_ext( - baseDN, - scope, - queryFilter, - attrlist, - attrsonly, - serverctrls=serverctrls - ) + try: + msgid = self._con.search_ext( + baseDN, + scope, + queryFilter, + attrlist, + attrsonly, + serverctrls=serverctrls + ) + except ldap.LDAPError as e: + logger.warn(str(e)) + return [] rtype, results, rmsgid, rctrls = self._con.result3(msgid) ctype = ldap.controls.libldap.SimplePagedResultsControl.controlType pctrls = [c for c in rctrls if c.controlType == ctype]