Skip to content

Ability to disable paged results for Enterprise Directory #326

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

Merged
merged 2 commits into from
Jan 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions user_sync/connector/directory_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,32 +294,41 @@ def iter_search_result(self, base_dn, scope, filter_string, attributes):
connection = self.connection
search_page_size = self.options['search_page_size']

lc = ldap.controls.libldap.SimplePagedResultsControl(True, size=search_page_size, cookie='')

msgid = None
try:
has_next_page = True
while has_next_page:
response_data = None
result_type = None
if msgid is not None:
result_type, response_data, _rmsgid, serverctrls = connection.result3(msgid)
msgid = None
pctrls = [c for c in serverctrls
if c.controlType == ldap.controls.libldap.SimplePagedResultsControl.controlType]
if not pctrls:
self.logger.warn('Server ignored RFC 2696 control.')
has_next_page = False
else:
lc.cookie = cookie = pctrls[0].cookie
if not cookie:
has_next_page = False
if has_next_page:
msgid = connection.search_ext(base_dn, scope,
filterstr=filter_string, attrlist=attributes, serverctrls=[lc])
if search_page_size == 0:
msgid = connection.search(base_dn, scope,
filterstr=filter_string, attrlist=attributes)
result_type, response_data, _rmsgid = connection.result2(msgid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to set msgid = None here after retrieving results to avoid problems at GeneratorExit should one be thrown. There's no connection to abandon in this case.

msgid = None
if result_type in self.expected_result_types and (response_data is not None):
for item in response_data:
yield item
else:
lc = ldap.controls.libldap.SimplePagedResultsControl(True, size=search_page_size, cookie='')

has_next_page = True
while has_next_page:
response_data = None
result_type = None
if msgid is not None:
result_type, response_data, _rmsgid, serverctrls = connection.result3(msgid)
msgid = None
pctrls = [c for c in serverctrls
if c.controlType == ldap.controls.libldap.SimplePagedResultsControl.controlType]
if not pctrls:
self.logger.warn('Server ignored RFC 2696 control.')
has_next_page = False
else:
lc.cookie = cookie = pctrls[0].cookie
if not cookie:
has_next_page = False
if has_next_page:
msgid = connection.search_ext(base_dn, scope,
filterstr=filter_string, attrlist=attributes, serverctrls=[lc])
if result_type in self.expected_result_types and (response_data is not None):
for item in response_data:
yield item
except GeneratorExit:
if msgid is not None:
connection.abandon(msgid)
Expand Down