Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions lib/ad/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,22 @@ def _fixup_attrs(self, attrs):

def _search_with_paged_results(self, conn, filter, base, scope, attrs):
"""Perform an ldap search operation with paged results."""
ctrl = ldap.controls.SimplePagedResultsControl(
ldap.LDAP_CONTROL_PAGE_OID, True, (self._pagesize, ''))
ctrl = compat.SimplePagedResultsControl(self._pagesize)
result = []
while True:
msgid = conn.search_ext(base, scope, filter, attrs,
serverctrls=[ctrl])
type, data, msgid, ctrls = conn.result3(msgid)
result += data
rctrls = [ c for c in ctrls
if c.controlType == ldap.LDAP_CONTROL_PAGE_OID ]
if c.controlType == compat.LDAP_CONTROL_PAGED_RESULTS ]
if not rctrls:
m = 'Server does not honour paged results.'
raise ADError, m
est, cookie = rctrls[0].controlValue

size = rctrls[0].size
cookie = rctrls[0].cookie

if not cookie:
break
ctrl.controlValue = (self._pagesize, cookie)
Expand Down
42 changes: 42 additions & 0 deletions lib/ad/util/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import ldap
import ldap.dn

from distutils import version

# ldap.str2dn has been removed in python-ldap >= 2.3.6. We now need to use
# the version in ldap.dn.
try:
Expand All @@ -19,3 +21,43 @@
def disable_reverse_dns():
# Possibly add in a Kerberos minimum version check as well...
return hasattr(ldap, 'OPT_X_SASL_NOCANON')

if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__):
LDAP_CONTROL_PAGED_RESULTS = ldap.CONTROL_PAGEDRESULTS
else:
LDAP_CONTROL_PAGED_RESULTS = ldap.LDAP_CONTROL_PAGE_OID


class SimplePagedResultsControl(ldap.controls.SimplePagedResultsControl):
"""
Python LDAP 2.4 and later breaks the API. This is an abstraction class
so that we can handle either.
http://planet.ergo-project.org/blog/jmeeuwen/2011/04/11/python-ldap-module-24-changes
"""

def __init__(self, page_size=0, cookie=''):
if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__):
ldap.controls.SimplePagedResultsControl.__init__(
self,
size=page_size,
cookie=cookie
)
else:
ldap.controls.SimplePagedResultsControl.__init__(
self,
LDAP_CONTROL_PAGED_RESULTS,
critical,
(page_size, '')
)

def cookie(self):
if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__):
return self.cookie
else:
return self.controlValue[1]

def size(self):
if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__):
return self.size
else:
return self.controlValue[0]