summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-02 13:49:33 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-02 13:49:33 +0000
commitfa08b287713bc6b34133fc28d4cdaf97021631a0 (patch)
tree75a853d7b05d52eff06709bdb69eeffc0730fe82
parent18da9a49afe99a432c377b7e9b238adf33a5b3cc (diff)
downloadpykolab-fa08b287713bc6b34133fc28d4cdaf97021631a0.tar.gz
Enable alternative email addresses to also be inserted back into LDAP
-rw-r--r--pykolab/auth/ldap/__init__.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 7b5730e..ee635d1 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -40,7 +40,7 @@ class LDAP(object):
if not self.ldap == None:
return
- self.log.debug(_("Connecting to LDAP..."), 9)
+ self.log.debug(_("Connecting to LDAP..."), level=9)
uri = self.conf.get('ldap', 'uri')
self.ldap = ldap.initialize(uri)
@@ -61,9 +61,12 @@ class LDAP(object):
self.ldap.modify(dn, [(ldap.MOD_REPLACE, attribute, value)])
except:
if hasattr(self.conf, "log"):
- self.conf.log.warning(_("LDAP modification of attribute %s to value %s failed") %(attribute,value))
+ self.conf.log.warning(_("LDAP modification of attribute %s" + \
+ " to value %s failed") %(attribute,value))
else:
- print "LDAP modification of attribute %s to value %s failed" %(attribute,value)
+ # Cannot but print in case someone's interested
+ print "LDAP modification of attribute %s to value %s" + \
+ " failed" %(attribute,value)
self._disconnect()
def _kolab_users(self):
@@ -76,7 +79,11 @@ class LDAP(object):
self.ldap.simple_bind(bind_dn, bind_pw)
- _search = self.ldap.search(user_base_dn, ldap.SCOPE_SUBTREE, kolab_user_filter)
+ _search = self.ldap.search(
+ user_base_dn,
+ ldap.SCOPE_SUBTREE,
+ kolab_user_filter
+ )
users = []
_result_type = None
@@ -102,16 +109,21 @@ class LDAP(object):
# What the heck?
user_attrs[key.lower()] = _user_attrs[key]
-
+ # Execute plugin hooks that may change the value(s) of the
+ # user attributes we are going to be using.
mail = self.conf.plugins.exec_hook("set_user_attrs_mail", args=(user_attrs))
alternative_mail = self.conf.plugins.exec_hook("set_user_attrs_alternative_mail", args=(user_attrs))
if not mail == user_attrs['mail']:
self._set_user_attribute(user_attrs['dn'], "mail", mail)
-# if not user_attrs.has_key('mailAlternateAddress'):
-# # Also make sure the required object class is available.
-# self._set_user_attribute(user_attrs['dn'], 'mailAlternateAddress', alternative_mail)
+ if len(alternative_mail) > 0:
+ # Also make sure the required object class is available.
+ if not "mailrecipient" in user_attrs['objectclass']:
+ user_attrs['objectclass'].append('mailrecipient')
+ self._set_user_attribute(user_attrs['dn'], 'objectclass', user_attrs['objectclass'])
+
+ self._set_user_attribute(user_attrs['dn'], 'mailalternateaddress', alternative_mail)
users.append(user_attrs)