Skip to content

Commit 89f8677

Browse files
author
Marco Martinez
committed
LDAP requires a filter string, (objectClass=*) if not available
1 parent b743548 commit 89f8677

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

src/who_ldap/__init__.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def __init__(self,
263263

264264
self.name = name
265265
self.attributes = \
266-
list(attributes_map.keys()) if attributes_map else None
266+
list(attributes_map.keys()) if attributes_map else ALL_ATTRIBUTES
267267
self._attributes_map = attributes_map
268268
self.filterstr = filterstr
269269
self.flatten = str(flatten)[0].lower() == 't'
@@ -279,26 +279,25 @@ def add_metadata(self, environ, identity):
279279
logger.error('Cannot establish connection')
280280
return
281281

282-
dn = extract_userdata(identity)
283-
284-
if not dn:
285-
logger.error('Malformed userdata')
286-
return
287-
282+
# Behave like search if filterstr is specified, otherwise use base
288283
if self.filterstr:
289-
status = conn.search('',
290-
self.filterstr.format(identity=identity),
291-
SEARCH_SCOPE_WHOLE_SUBTREE,
292-
attributes=(ALL_ATTRIBUTES
293-
if self.attributes is None
294-
else self.attributes))
284+
search_scope = SEARCH_SCOPE_WHOLE_SUBTREE
285+
filterstr = self.filterstr.format(identity=identity)
286+
# XXX This might need to be a setting?
287+
base_dn = ''
295288
else:
296-
status = conn.search(dn,
297-
self.filterstr,
298-
SEARCH_SCOPE_BASE_OBJECT,
299-
attributes=(ALL_ATTRIBUTES
300-
if self.attributes is None
301-
else self.attributes))
289+
search_scope = SEARCH_SCOPE_BASE_OBJECT
290+
filterstr = '(objectClass=*)' # ldap requires a filter string
291+
base_dn = extract_userdata(identity)
292+
if not base_dn:
293+
logger.error('Malformed userdata')
294+
return
295+
296+
status = conn.search(
297+
base_dn,
298+
filterstr,
299+
search_scope,
300+
attributes=self.attributes)
302301

303302
if not status:
304303
logger.error(

0 commit comments

Comments
 (0)