summaryrefslogtreecommitdiffstats
path: root/pykolab/auth/ldap/__init__.py
diff options
context:
space:
mode:
authorPaul Boddie <paul@boddie.org.uk>2013-12-05 17:13:22 +0100
committerPaul Boddie <paul@boddie.org.uk>2013-12-05 17:13:22 +0100
commit280b09d0e3232e6c4dacd287ce39edcb2c9187ed (patch)
treef380a4d0023ec1615162f9d69f0fa1ca587970b3 /pykolab/auth/ldap/__init__.py
parent265063a09a2a77470c2cefd95b4667f86567126d (diff)
downloadpykolab-280b09d0e3232e6c4dacd287ce39edcb2c9187ed.tar.gz
Merged some search operations, simplified some conditional logic.
Diffstat (limited to 'pykolab/auth/ldap/__init__.py')
-rw-r--r--pykolab/auth/ldap/__init__.py50
1 files changed, 13 insertions, 37 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 952af86..8e65005 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -192,22 +192,7 @@ class LDAP(pykolab.base.Base):
pass
if entry_dn is None:
- _search = self.ldap.search_ext(
- base_dn,
- ldap.SCOPE_SUBTREE,
- _filter,
- ['entrydn']
- )
-
- (
- _result_type,
- _result_data,
- _result_msgid,
- _result_controls
- ) = self.ldap.result3(_search)
-
- if len(_result_data) >= 1:
- (entry_dn, entry_attrs) = _result_data[0]
+ entry_dn = self.entry_dn_using_filter(_filter, base_dn)
try:
log.debug(_("Binding with user_dn %s and password %s")
@@ -304,10 +289,17 @@ class LDAP(pykolab.base.Base):
unique_attribute = self.config_get('unique_attribute')
base_dn = self.config_get('base_dn')
+ return self.entry_dn_using_filter('(%s=%s)' % (unique_attribute, entry_id), base_dn)
+
+ def entry_dn_using_filter(self, _filter, base_dn):
+ """
+ Return results from a search with the given filter and base dn.
+ """
+
_search = self.ldap.search_ext(
base_dn,
ldap.SCOPE_SUBTREE,
- '(%s=%s)' % (unique_attribute, entry_id),
+ _filter,
['entrydn']
)
@@ -1392,21 +1384,7 @@ class LDAP(pykolab.base.Base):
# See if we have to trigger the recipient policy. Only really applies to
# situations in which the result_attribute is used in the old or in the
# new DN.
- trigger_recipient_policy = False
-
- if old_rdn == result_attribute:
- if new_rdn == result_attribute:
- if new_rdn == old_rdn:
- trigger_recipient_policy = True
- else:
- if new_rdn != old_rdn:
- trigger_recipient_policy = True
- else:
- if new_rdn == result_attribute:
- if new_rdn != old_rdn:
- trigger_recipient_policy = True
-
- if trigger_recipient_policy:
+ if result_attribute in (old_rdn, new_rdn):
entry_changes = self.recipient_policy(entry)
for key in entry_changes.keys():
@@ -1596,9 +1574,7 @@ class LDAP(pykolab.base.Base):
self.imap.connect(domain=self.domain)
- if entry.has_key(result_attribute) and \
- entry.has_key(result_attribute) is not None:
-
+ if entry.get(result_attribute):
if not self.imap.user_mailbox_exists(entry[result_attribute]):
folder = self.imap.user_mailbox_create(entry[result_attribute])
server = self.imap.user_mailbox_server(folder)
@@ -1995,8 +1971,8 @@ class LDAP(pykolab.base.Base):
entry = { 'dn': entry_dn }
entry_attrs = utils.normalize(entry_attrs)
- for attr in entry_attrs.keys():
- entry[attr.lower()] = entry_attrs[attr]
+ for attr, value in entry_attrs.items():
+ entry[attr.lower()] = value
unique_attr = self.config_get('unique_attribute')
entry['id'] = entry[unique_attr]