@@ -309,32 +309,41 @@ def iter_search_result(self, base_dn, scope, filter_string, attributes):
309
309
connection = self .connection
310
310
search_page_size = self .options ['search_page_size' ]
311
311
312
- lc = ldap .controls .libldap .SimplePagedResultsControl (True , size = search_page_size , cookie = '' )
313
-
314
312
msgid = None
315
313
try :
316
- has_next_page = True
317
- while has_next_page :
318
- response_data = None
319
- result_type = None
320
- if msgid is not None :
321
- result_type , response_data , _rmsgid , serverctrls = connection .result3 (msgid )
322
- msgid = None
323
- pctrls = [c for c in serverctrls
324
- if c .controlType == ldap .controls .libldap .SimplePagedResultsControl .controlType ]
325
- if not pctrls :
326
- self .logger .warn ('Server ignored RFC 2696 control.' )
327
- has_next_page = False
328
- else :
329
- lc .cookie = cookie = pctrls [0 ].cookie
330
- if not cookie :
331
- has_next_page = False
332
- if has_next_page :
333
- msgid = connection .search_ext (base_dn , scope ,
334
- filterstr = filter_string , attrlist = attributes , serverctrls = [lc ])
314
+ if search_page_size == 0 :
315
+ msgid = connection .search (base_dn , scope ,
316
+ filterstr = filter_string , attrlist = attributes )
317
+ result_type , response_data , _rmsgid = connection .result2 (msgid )
318
+ msgid = None
335
319
if result_type in self .expected_result_types and (response_data is not None ):
336
320
for item in response_data :
337
321
yield item
322
+ else :
323
+ lc = ldap .controls .libldap .SimplePagedResultsControl (True , size = search_page_size , cookie = '' )
324
+
325
+ has_next_page = True
326
+ while has_next_page :
327
+ response_data = None
328
+ result_type = None
329
+ if msgid is not None :
330
+ result_type , response_data , _rmsgid , serverctrls = connection .result3 (msgid )
331
+ msgid = None
332
+ pctrls = [c for c in serverctrls
333
+ if c .controlType == ldap .controls .libldap .SimplePagedResultsControl .controlType ]
334
+ if not pctrls :
335
+ self .logger .warn ('Server ignored RFC 2696 control.' )
336
+ has_next_page = False
337
+ else :
338
+ lc .cookie = cookie = pctrls [0 ].cookie
339
+ if not cookie :
340
+ has_next_page = False
341
+ if has_next_page :
342
+ msgid = connection .search_ext (base_dn , scope ,
343
+ filterstr = filter_string , attrlist = attributes , serverctrls = [lc ])
344
+ if result_type in self .expected_result_types and (response_data is not None ):
345
+ for item in response_data :
346
+ yield item
338
347
except GeneratorExit :
339
348
if msgid is not None :
340
349
connection .abandon (msgid )
0 commit comments