summaryrefslogtreecommitdiff
path: root/pykolab/auth/ldap/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'pykolab/auth/ldap/__init__.py')
-rw-r--r--pykolab/auth/ldap/__init__.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 8b224ee..76c130f 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -313,6 +313,62 @@ class LDAP(object):
return _user_dn
+ def _find_recipient(self, attr, value, domain=None, additional_filter=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, 'base_dn'):
+ section = domain
+ else:
+ section = 'ldap'
+
+ base_dn = conf.get_raw(
+ section,
+ '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 the recipient with search filter: %s") %(
+ search_filter
+ ),
+ level=8
+ )
+
+ _results = self.ldap.search_s(
+ base_dn,
+ scope=ldap.SCOPE_SUBTREE,
+ filterstr=search_filter,
+ attrlist=[ 'dn' ]
+ )
+
+ if len(_results) == 1:
+ (_recipient_dn, _recipient_attrs) = _results[0]
+ else:
+ return False
+
+ return _recipient_dn
+
def _persistent_search(self,
base_dn,
scope=ldap.SCOPE_SUBTREE,