Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection.search() returns True even if there are no matches #1024

Open
lightspot21 opened this issue Mar 2, 2022 · 0 comments
Open

Connection.search() returns True even if there are no matches #1024

lightspot21 opened this issue Mar 2, 2022 · 0 comments

Comments

@lightspot21
Copy link

lightspot21 commented Mar 2, 2022

I am not certain if this is a bug, since I couldn't find in the docs whether search()'s return value is supposed to signal the existence of matches or something else, but still:

On Active Directory, calling search() deliberately for something with no results returns True, while the same search (again searching for something that doesn't exist) returns False on OpenLDAP. The cause seems to be this (core/connection.py:856-863):

if isinstance(response, int):  # asynchronous strategy
    return_value = response
    if log_enabled(PROTOCOL):
        log(PROTOCOL, 'async SEARCH response id <%s> received via <%s>', return_value, self)
    else:
        return_value = True if self.result['type'] == 'searchResDone' and len(response) > 0 else False
        if not return_value and self.result['result'] not in [RESULT_SUCCESS] and not self.last_error:
            self.last_error = self.result['description']

On line 861 return_value = True if self.result['type'] == 'searchResDone' and len(response) > 0 else False the return value is determined by the result type and the length of response. On OpenLDAP when nothing is found len(response) = 0, but Active Directory returns searchResRef objects even if no results are found, thus making len(response) > 0 --> return_value = True instead of False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant