summaryrefslogtreecommitdiffstats
path: root/ipaserver/plugins
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2009-05-26 18:05:21 +0200
committerRob Crittenden <rcritten@redhat.com>2009-05-26 13:40:46 -0400
commit85bc20b0df9977d0b1d3dd7483c7ebb1893df40b (patch)
tree4f2897448310bab434f586d009fce0c88e35c588 /ipaserver/plugins
parenta92e4402185e518cf26ba3497b43f09251807a05 (diff)
downloadfreeipa-85bc20b0df9977d0b1d3dd7483c7ebb1893df40b.tar.gz
freeipa-85bc20b0df9977d0b1d3dd7483c7ebb1893df40b.tar.xz
freeipa-85bc20b0df9977d0b1d3dd7483c7ebb1893df40b.zip
Make it easier to search for a single entry by attribute value (find_entry_by_attr). Fix minor search filter generation issues.
Diffstat (limited to 'ipaserver/plugins')
-rw-r--r--ipaserver/plugins/ldap2.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py
index 480b817f7..3c3a1a0bc 100644
--- a/ipaserver/plugins/ldap2.py
+++ b/ipaserver/plugins/ldap2.py
@@ -327,9 +327,7 @@ class ldap2(CrudBackend, Encoder):
flt = ''
for f in filters:
if not f.startswith('('):
- f = '(%s' % f
- if not f.endswith(')'):
- f = '%s)' % f
+ f = '(%s)' % f
flt = '%s%s' % (flt, f)
if len(filters) > 1:
flt = '%s)' % flt
@@ -352,9 +350,11 @@ class ldap2(CrudBackend, Encoder):
return self.combine_filters(flts, rules)
elif value is not None:
value = _ldap_filter.escape_filter_chars(value)
- if exact:
- return '(%s=%s)' % (attr, value)
- return '(%s=*%s*)' % (attr, value)
+ if not exact:
+ value = '*%s*' % value
+ if rules == self.MATCH_NONE:
+ return '(!(%s=%s))' % (attr, value)
+ return '(%s=%s)' % (attr, value)
return ''
def make_filter(self, entry_attrs, attrs_list=None, rules='|', exact=True):
@@ -420,6 +420,19 @@ class ldap2(CrudBackend, Encoder):
return res
+ def find_entry_by_attr(self, attr, value, object_class, attrs_list=None,
+ base_dn=''):
+ """
+ Find entry (dn, entry_attrs) by attribute and object class.
+
+ Keyword arguments:
+ attrs_list - list of attributes to return, all if None (default None)
+ base_dn - dn of the entry at which to start the search (default '')
+ """
+ search_kw = {attr: value, 'objectClass': object_class}
+ filter = self.make_filter(search_kw, rules=self.MATCH_ALL)
+ return self.find_entries(filter, attrs_list, base_dn)
+
def get_entry(self, dn, attrs_list=None):
"""
Get entry (dn, entry_attrs) by dn.