mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
baseldap: Handle missing parent objects properly in *-find commands
The find_entries function in ipaldap does not differentiate between a LDAP search that returns error code 32 (No such object) and LDAP search returning error code 0 (Success), but returning no results. In both cases errors.NotFound is raised. In turn, LDAPSearch commands interpret NotFound exception as no results. To differentiate between the cases, a new error EmptyResult was added, which inherits from NotFound to preserve the compatibility with the new code. This error is raised by ipaldap.find_entries in case it is performing a search with and the target dn does not exist. https://fedorahosted.org/freeipa/ticket/4659 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
parent
640a4b30c2
commit
44134460b6
@ -1329,6 +1329,21 @@ class PosixGroupViolation(ExecutionError):
|
||||
errno = 4030
|
||||
format = _('This is already a posix group and cannot be converted to external one')
|
||||
|
||||
class EmptyResult(NotFound):
|
||||
"""
|
||||
**4031** Raised when a LDAP search returned no results.
|
||||
|
||||
For example:
|
||||
|
||||
>>> raise EmptyResult(reason='no matching entry found')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
EmptyResult: no matching entry found
|
||||
|
||||
"""
|
||||
|
||||
errno = 4031
|
||||
|
||||
class BuiltinError(ExecutionError):
|
||||
"""
|
||||
**4100** Base class for builtin execution errors (*4100 - 4199*).
|
||||
|
@ -1995,8 +1995,10 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
|
||||
time_limit=options.get('timelimit', None),
|
||||
size_limit=options.get('sizelimit', None)
|
||||
)
|
||||
except errors.NotFound:
|
||||
except errors.EmptyResult:
|
||||
(entries, truncated) = ([], False)
|
||||
except errors.NotFound:
|
||||
self.api.Object[self.obj.parent_object].handle_not_found(*args[:-1])
|
||||
|
||||
for callback in self.get_callbacks('post'):
|
||||
truncated = callback(self, ldap, entries, truncated, *args, **options)
|
||||
|
@ -1527,7 +1527,7 @@ class LDAPClient(object):
|
||||
break
|
||||
|
||||
if not res and not truncated:
|
||||
raise errors.NotFound(reason='no such entry')
|
||||
raise errors.EmptyResult(reason='no matching entry found')
|
||||
|
||||
return (res, truncated)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user