summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-06 09:28:29 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-06 09:28:29 +0000
commit708a3703149943febe0b086281c7e16d97c681a3 (patch)
tree0d64886a4732e2f24c944fdf1f834cea96e6eb4c
parent91102c4fd11e4f4f4539bb1522d32d306e1cd904 (diff)
downloadpykolab-708a3703149943febe0b086281c7e16d97c681a3.tar.gz
Allow overriding the base_dn for find_user()
Add search_user()
-rw-r--r--pykolab/auth/ldap/__init__.py73
1 files changed, 68 insertions, 5 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index c52bd55..e0ffa95 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -302,7 +302,7 @@ class LDAP(object):
return _user_dn
- def _find_user(self, attr, value, domain=None, additional_filter=None):
+ def _find_user(self, attr, value, domain=None, additional_filter=None, base_dn=None):
self._connect()
self._bind()
@@ -316,10 +316,13 @@ class LDAP(object):
else:
section = 'ldap'
- user_base_dn = conf.get_raw(
- section,
- 'user_base_dn'
- ) %({'base_dn': domain_root_dn})
+ if base_dn == None:
+ user_base_dn = conf.get_raw(
+ section,
+ 'user_base_dn'
+ ) %({'base_dn': domain_root_dn})
+ else:
+ user_base_dn = base_dn
if type(attr) == str:
search_filter = "(%s=%s)" %(
@@ -358,6 +361,66 @@ class LDAP(object):
return _user_dn
+ def _search_users(self, attr, value, domain=None, additional_filter=None, base_dn=None):
+ self._connect()
+ self._bind()
+
+ if domain == None:
+ domain = conf.get('kolab', 'primary_domain')
+
+ domain_root_dn = self._kolab_domain_root_dn(domain)
+
+ if conf.has_option(domain, 'user_base_dn'):
+ section = domain
+ else:
+ section = 'ldap'
+
+ if base_dn == None:
+ user_base_dn = conf.get_raw(
+ section,
+ 'user_base_dn'
+ ) %({'base_dn': domain_root_dn})
+ else:
+ user_base_dn = base_dn
+
+ if type(attr) == str:
+ search_filter = "(%s=%s)" %(
+ attr,
+ value
+ )
+ elif type(attr) == list:
+ search_filter = "(|"
+ for _attr in attr:
+ search_filter = "%s(%s=%s)" %(search_filter, _attr, value)
+ search_filter = "%s)" %(search_filter)
+
+ if additional_filter:
+ search_filter = additional_filter % {
+ 'search_filter': search_filter
+ }
+
+ log.debug(
+ _("Attempting to find entries with search filter: %s") %(
+ search_filter
+ ),
+ level=8
+ )
+
+ _results = self.ldap.search_s(
+ user_base_dn,
+ scope=ldap.SCOPE_SUBTREE,
+ filterstr=search_filter,
+ attrlist=[ 'dn' ]
+ )
+
+ _user_dns = []
+
+ for _result in _results:
+ (_user_dn, _user_attrs) = _result
+ _user_dns.append(_user_dn)
+
+ return _user_dns
+
def _persistent_search(self,
base_dn,
scope=ldap.SCOPE_SUBTREE,