From f4255c90fb5115cae2a74f0d667d98b25a865545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Mas=C3=A1r?= Date: Wed, 13 Feb 2019 01:33:05 +0100 Subject: [PATCH] LDAP paging support --- python/multicorn/ldapfdw.py | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/python/multicorn/ldapfdw.py b/python/multicorn/ldapfdw.py index df0b4697a..bcfcf3dba 100755 --- a/python/multicorn/ldapfdw.py +++ b/python/multicorn/ldapfdw.py @@ -150,24 +150,32 @@ def execute(self, quals, columns): val = qual.value request = unicode_("(&%s(%s=%s))") % ( request, qual.field_name, val) - self.ldap.search( - self.path, request, self.scope, - attributes=list(self.field_definitions)) - for entry in self.ldap.response: - # Case insensitive lookup for the attributes - litem = dict() - for key, value in entry["attributes"].items(): - if key.lower() in self.field_definitions: - pgcolname = self.field_definitions[key.lower()].column_name - if ldap3.version.__version__ > '2.0.0': - value = value - else: - if pgcolname in self.array_columns: + cookie = None + while True: + self.ldap.search( + self.path, request, self.scope, + attributes=list(self.field_definitions), + paged_size=1000, + paged_cookie=cookie) + for entry in self.ldap.response: + # Case insensitive lookup for the attributes + litem = dict() + for key, value in entry["attributes"].items(): + if key.lower() in self.field_definitions: + pgcolname = self.field_definitions[key.lower()].column_name + if ldap3.version.__version__ > '2.0.0': value = value else: - value = value[0] - litem[pgcolname] = value - yield litem + if pgcolname in self.array_columns: + value = value + else: + value = value[0] + litem[pgcolname] = value + yield litem + # pagedResultsControl, see RFC 2696 + cookie = self.ldap.result['controls']['1.2.840.113556.1.4.319']['value']['cookie'] + if not cookie: + break def parse_scope(self, scope=None): if scope in (None, "", "one"):