Skip to content
Open
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
58 changes: 33 additions & 25 deletions python/multicorn/ldapfdw.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@
);

CREATE FOREIGN TABLE ldapexample (
mail character varying,
cn character varying,
description character varying
mail character varying,
cn character varying,
description character varying
) server ldap_srv options (
uri 'ldap://localhost',
path 'dc=lab,dc=example,dc=com',
scope 'sub',
binddn 'cn=Admin,dc=example,dc=com',
bindpwd 'admin',
objectClass '*'
uri 'ldap://localhost',
path 'dc=lab,dc=example,dc=com',
scope 'sub',
binddn 'cn=Admin,dc=example,dc=com',
bindpwd 'admin',
objectClass '*'
);

select * from ldapexample;
Expand Down 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