Fix filter generator in ldapapi. Shouldn't produce invalid filters anymore.

This commit is contained in:
Pavel Zuna 2009-04-21 15:25:48 +02:00 committed by Rob Crittenden
parent 32ad0ab011
commit 5fa7c76f72

View File

@ -386,20 +386,26 @@ class ldap(CrudBackend):
del kw['scope'] del kw['scope']
if exactonly is not None: if exactonly is not None:
del kw['exactonly'] del kw['exactonly']
(exact_match_filter, partial_match_filter) = self._generate_search_filters(**kw) if kw:
(exact_match_filter, partial_match_filter) = self._generate_search_filters(**kw)
else:
(exact_match_filter, partial_match_filter) = ('', '')
if objectclass: if objectclass:
exact_match_filter = "(&(objectClass=%s)%s)" % (objectclass, exact_match_filter) exact_match_filter = '(&(objectClass=%s)%s)' % (objectclass, exact_match_filter)
partial_match_filter = "(&(objectClass=%s)%s)" % (objectclass, partial_match_filter) partial_match_filter = '(&(objectClass=%s)%s)' % (objectclass, partial_match_filter)
else:
exact_match_filter = '(&(objectClass=*)%s)' % exact_match_filter
partial_match_filter = '(&(objectClass=*)%s)' % partial_match_filter
if sfilter: if sfilter:
exact_match_filter = "(%s%s)" % (sfilter, exact_match_filter) exact_match_filter = '(%s%s)' % (sfilter, exact_match_filter)
partial_match_filter = "(%s%s)" % (sfilter, partial_match_filter) partial_match_filter = '(%s%s)' % (sfilter, partial_match_filter)
search_scope = self._get_scope(scope) search_scope = self._get_scope(scope)
if not base: if not base:
base = self.api.env.container_accounts base = self.api.env.container_accounts
search_base = "%s, %s" % (base, self.api.env.basedn) search_base = '%s,%s' % (base, self.api.env.basedn)
try: try:
exact_results = servercore.search(search_base, exact_results = servercore.search(search_base,
exact_match_filter, attributes, scope=search_scope) exact_match_filter, attributes, scope=search_scope)