Skip to content

Commit

Permalink
LDAP paging support
Browse files Browse the repository at this point in the history
  • Loading branch information
helix84 committed Feb 13, 2019
1 parent a77d9be commit f4255c9
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions python/multicorn/ldapfdw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit f4255c9

Please sign in to comment.