summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-02 12:00:51 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-03-02 12:00:51 +0000
commit1f42b362709a09e73e3a93a61dd5c967b0d47098 (patch)
treefe6753410e7ffc7bb4ae362ba4d37d34d4bd87f6
parent9537a8ea971833c8e3a1624ab685f844f3aa8e8e (diff)
downloadpykolab-1f42b362709a09e73e3a93a61dd5c967b0d47098.tar.gz
Remove import not distributed, and only attempt to import the appropriate library after it's been verified the technology is actually used.
Remove unused import for IMAP Simplify initialization
-rw-r--r--pykolab/auth/__init__.py18
-rw-r--r--pykolab/auth/ldap/__init__.py58
2 files changed, 47 insertions, 29 deletions
diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index 5a74675..f744cc1 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -16,10 +16,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
-from pykolab.auth import ldap
-from pykolab.auth import sql
from pykolab.conf import Conf
-from pykolab.imap import IMAP
from pykolab.translate import _
@@ -32,13 +29,9 @@ class Auth(object):
"""
Initialize the authentication class.
"""
- if not conf:
- self.conf = Conf()
- self.conf.finalize_conf()
+ self.conf = conf
+ if hasattr(self.conf, "log"):
self.log = self.conf.log
- else:
- self.conf = conf
- self.log = conf.log
self._auth = None
@@ -47,6 +40,12 @@ class Auth(object):
return
if self.conf.get('kolab', 'auth_mechanism') == 'ldap':
+ try:
+ from pykolab.auth import ldap
+ except:
+ if hasattr(self, "log"):
+ self.log.error(_("Failure to import authentication layer %s," +
+ " please verify module dependencies have been installed") % "ldap")
self._auth = ldap.LDAP(self.conf)
def users(self):
@@ -55,7 +54,6 @@ class Auth(object):
return users
def set_user_attribute(self, user, attribute, value):
- print "Setting attribute %s to %s for user %s" %(attribute, value, user)
self._connect()
self._auth._set_user_attribute(user, attribute, value)
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index aaa3f07..7b5730e 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -17,6 +17,7 @@
#
import ldap
+import time
from pykolab.conf import Conf
from pykolab.constants import *
@@ -56,7 +57,14 @@ class LDAP(object):
self.ldap.simple_bind(bind_dn, bind_pw)
- self.ldap.modify_s(dn, [(ldap.MOD_REPLACE, attribute, value)])
+ try:
+ 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))
+ else:
+ print "LDAP modification of attribute %s to value %s failed" %(attribute,value)
+ self._disconnect()
def _kolab_users(self):
self._connect()
@@ -68,32 +76,44 @@ class LDAP(object):
self.ldap.simple_bind(bind_dn, bind_pw)
- _users = self.ldap.search_s(user_base_dn, ldap.SCOPE_SUBTREE, kolab_user_filter)
-
- self._disconnect()
+ _search = self.ldap.search(user_base_dn, ldap.SCOPE_SUBTREE, kolab_user_filter)
users = []
+ _result_type = None
+
+ while not _result_type == ldap.RES_SEARCH_RESULT:
+ (_result_type, _users) = self.ldap.result(_search, False, 0)
+ if not _users == None:
+ for _user in _users:
+ user_attrs = {}
+
+ (user_dn, _user_attrs) = _user
+ _user_attrs['dn'] = user_dn
+
+ self.conf.log.debug(_("Found user %s") %(user_dn), level=9)
- for _user in _users:
- user_attrs = {}
+ for key in _user_attrs.keys():
+ if type(_user_attrs[key]) == list:
+ if len(_user_attrs[key]) == 1:
+ user_attrs[key.lower()] = ''.join(_user_attrs[key])
+ else:
+ user_attrs[key.lower()] = _user_attrs[key]
+ else:
+ # What the heck?
+ user_attrs[key.lower()] = _user_attrs[key]
- (user_dn, _user_attrs) = _user
- _user_attrs['dn'] = user_dn
- for key in _user_attrs.keys():
- if type(_user_attrs[key]) == list:
- if len(_user_attrs[key]) == 1:
- user_attrs[key.lower()] = ''.join(_user_attrs[key])
- else:
- user_attrs[key.lower()] = _user_attrs[key]
- else:
- # What the heck?
- user_attrs[key.lower()] = _user_attrs[key]
+ 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)
- user_attrs = self.conf.plugins.exec_hook("set_user_attrs", args=(user_attrs))
+# 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)
- users.append(user_attrs)
+ users.append(user_attrs)
return users