Branch 'pykolab-0.4' - 2 commits - pykolab/auth pykolab/Makefile.am
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Thu Sep 13 17:33:28 CEST 2012
pykolab/Makefile.am | 3 -
pykolab/auth/__init__.py | 6 ++
pykolab/auth/ldap/syncrepl.py | 94 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 2 deletions(-)
New commits:
commit 25a46baf5967c6967e29f1669050f3d786ef4aba
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Thu Sep 13 14:07:08 2012 +0100
Include syncrepl module with pykolab
diff --git a/pykolab/Makefile.am b/pykolab/Makefile.am
index bd38824..7f54f53 100644
--- a/pykolab/Makefile.am
+++ b/pykolab/Makefile.am
@@ -8,7 +8,8 @@ pykolab_auth_PYTHON = \
pykolab_auth_ldapdir = $(pythondir)/$(PACKAGE)/auth/ldap
pykolab_auth_ldap_PYTHON = \
auth/ldap/__init__.py \
- auth/ldap/cache.py
+ auth/ldap/cache.py \
+ auth/ldap/syncrepl.py
pykolab_clidir = $(pythondir)/$(PACKAGE)/cli
pykolab_cli_PYTHON = \
diff --git a/pykolab/auth/ldap/syncrepl.py b/pykolab/auth/ldap/syncrepl.py
new file mode 100644
index 0000000..e02e086
--- /dev/null
+++ b/pykolab/auth/ldap/syncrepl.py
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+
+import anydbm
+import ldap
+import ldap.syncrepl
+import ldapurl
+
+from pykolab import utils
+
+class DNSync(ldap.ldapobject.LDAPObject,ldap.syncrepl.SyncreplConsumer):
+
+ callback = None
+
+ def __init__(self, filename, *args, **kwargs):
+ if kwargs.has_key('callback'):
+ self.callback = kwargs['callback']
+ del kwargs['callback']
+
+ ldap.ldapobject.LDAPObject.__init__(self, *args, **kwargs)
+ self.__db = anydbm.open(filename, 'c', 0640)
+ self.__presentUUIDs = {}
+
+ def syncrepl_set_cookie(self,cookie):
+ self.__db['cookie'] = cookie
+
+ def syncrepl_get_cookie(self):
+ if 'cookie' in self.__db:
+ return self.__db['cookie']
+
+ def syncrepl_delete(self, uuids):
+ for uuid in uuids:
+ dn = self.__db[uuid]
+
+ if not self.callback == None:
+ self.callback(
+ change_type='delete',
+ previous_dn=None,
+ change_number=None,
+ dn=dn,
+ entry={}
+ )
+
+ del self.__db[uuid]
+
+ def syncrepl_present(self, uuids, refreshDeletes=False):
+ if uuids is None:
+ if refreshDeletes is False:
+ nonpresent = []
+ for uuid in self.__db.keys():
+ if uuid == 'cookie': continue
+ if uuid in self.__presentUUIDs: continue
+ nonpresent.append(uuid)
+ self.syncrepl_delete(nonpresent)
+ self.__presentUUIDs = {}
+ else:
+ for uuid in uuids:
+ self.__presentUUIDs[uuid] = True
+
+ def syncrepl_entry(self, dn, attrs, uuid):
+ attrs = utils.normalize(attrs)
+
+ if uuid in self.__db:
+ odn = self.__db[uuid]
+ if odn != dn:
+ if not self.callback == None:
+ self.callback(
+ change_type='moddn',
+ previous_dn=odn,
+ change_number=None,
+ dn=dn,
+ entry=attrs
+ )
+
+ else:
+ if not self.callback == None:
+ self.callback(
+ change_type='modify',
+ previous_dn=None,
+ change_number=None,
+ dn=self.__db[uuid],
+ entry=attrs
+ )
+
+ else:
+ if not self.callback == None:
+ self.callback(
+ change_type='add',
+ previous_dn=None,
+ change_number=None,
+ dn=dn,
+ entry=attrs
+ )
+
+ self.__db[uuid] = dn
commit b2fa8d02b0cdfdb0a603fc39fb666c760a027c72
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Thu Sep 13 14:04:07 2012 +0100
Only actually fail listing domains if the primary domain is the domain auth has been instantiated for (#1004)
diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py
index ad8491b..b050069 100644
--- a/pykolab/auth/__init__.py
+++ b/pykolab/auth/__init__.py
@@ -187,7 +187,11 @@ class Auth(pykolab.base.Base):
# Find the domains in the authentication backend.
kolab_primary_domain = conf.get('kolab', 'primary_domain')
- domains = self._auth._list_domains()
+ try:
+ domains = self._auth._list_domains()
+ except:
+ if not self.domain == kolab_primary_domain:
+ return [(self.domain, [])]
# If no domains are found, the primary domain is used.
if len(domains) < 1:
More information about the commits
mailing list