summaryrefslogtreecommitdiffstats
path: root/ipaserver
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-07-13 14:01:17 +0200
committerMartin Kosek <mkosek@redhat.com>2011-07-13 15:06:13 +0200
commit0cb65fd9f6865d606625ddb16206090779462c1f (patch)
tree6a100a1362a12eba6aa1e0b8cec62f33b6f4accd /ipaserver
parentb93e0b8bbfaa1e9252b3d096ef9251493654dec2 (diff)
downloadfreeipa-0cb65fd9f6865d606625ddb16206090779462c1f.zip
freeipa-0cb65fd9f6865d606625ddb16206090779462c1f.tar.gz
freeipa-0cb65fd9f6865d606625ddb16206090779462c1f.tar.xz
Filter reverse zones in dnszone-find
Implements a new option to filter out reverse zones. This patch also do some clean up in dns plugin - debug prints were accidentally left here in the last dns patch. https://fedorahosted.org/freeipa/ticket/1471
Diffstat (limited to 'ipaserver')
-rw-r--r--ipaserver/plugins/ldap2.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py
index 6f34984..a2e592d 100644
--- a/ipaserver/plugins/ldap2.py
+++ b/ipaserver/plugins/ldap2.py
@@ -457,7 +457,8 @@ class ldap2(CrudBackend, Encoder):
return flt
@encode_args(1, 2)
- def make_filter_from_attr(self, attr, value, rules='|', exact=True):
+ def make_filter_from_attr(self, attr, value, rules='|', exact=True,
+ leading_wildcard=True, trailing_wildcard=True):
"""
Make filter for ldap2.find_entries from attribute.
@@ -465,28 +466,42 @@ class ldap2(CrudBackend, Encoder):
rules -- see ldap2.make_filter
exact -- boolean, True - make filter as (attr=value)
False - make filter as (attr=*value*)
+ leading_wildcard -- boolean, True - allow heading filter wildcard when exact=False
+ False - forbid heading filter wildcard when exact=False
+ trailing_wildcard -- boolean, True - allow trailing filter wildcard when exact=False
+ False - forbid trailing filter wildcard when exact=False
"""
if isinstance(value, (list, tuple)):
flts = []
if rules == self.MATCH_NONE:
for v in value:
flts.append(
- self.make_filter_from_attr(attr, v, exact=exact)
+ self.make_filter_from_attr(attr, v, exact=exact,
+ leading_wildcard=leading_wildcard,
+ trailing_wildcard=trailing_wildcard)
)
return '(!%s)' % self.combine_filters(flts)
for v in value:
- flts.append(self.make_filter_from_attr(attr, v, rules, exact))
+ flts.append(self.make_filter_from_attr(attr, v, rules, exact,
+ leading_wildcard=leading_wildcard,
+ trailing_wildcard=trailing_wildcard))
return self.combine_filters(flts, rules)
elif value is not None:
value = _ldap_filter.escape_filter_chars(value)
if not exact:
- value = '*%s*' % value
+ template = '%s'
+ if leading_wildcard:
+ template = '*' + template
+ if trailing_wildcard:
+ template = template + '*'
+ value = template % 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):
+ def make_filter(self, entry_attrs, attrs_list=None, rules='|', exact=True,
+ leading_wildcard=True, trailing_wildcard=True):
"""
Make filter for ldap2.find_entries from entry attributes.
@@ -495,6 +510,10 @@ class ldap2(CrudBackend, Encoder):
rules -- specifies how to determine a match (default ldap2.MATCH_ANY)
exact -- boolean, True - make filter as (attr=value)
False - make filter as (attr=*value*)
+ leading_wildcard -- boolean, True - allow heading filter wildcard when exact=False
+ False - forbid heading filter wildcard when exact=False
+ trailing_wildcard -- boolean, True - allow trailing filter wildcard when exact=False
+ False - forbid trailing filter wildcard when exact=False
rules can be one of the following:
ldap2.MATCH_NONE - match entries that do not match any attribute
@@ -505,14 +524,16 @@ class ldap2(CrudBackend, Encoder):
if attrs_list is None:
for (k, v) in entry_attrs.iteritems():
flts.append(
- self.make_filter_from_attr(k, v, rules, exact)
+ self.make_filter_from_attr(k, v, rules, exact,
+ leading_wildcard, trailing_wildcard)
)
else:
for a in attrs_list:
value = entry_attrs.get(a, None)
if value is not None:
flts.append(
- self.make_filter_from_attr(a, value, rules, exact)
+ self.make_filter_from_attr(a, value, rules, exact,
+ leading_wildcard, trailing_wildcard)
)
return self.combine_filters(flts, rules)