Changeset View
Changeset View
Standalone View
Standalone View
pykolab/auth/ldap/syncrepl.py
#!/usr/bin/python | #!/usr/bin/python | ||||
try: | try: | ||||
import anydbm | import anydbm | ||||
except: | except ImportError: | ||||
import dbm.ndbm as anydbm | import dbm.ndbm as anydbm | ||||
import ldap | import ldap | ||||
import ldap.syncrepl | import ldap.syncrepl | ||||
import ldapurl | import ldapurl | ||||
import pykolab | import pykolab | ||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.translate import _ | |||||
log = pykolab.getLogger('pykolab.syncrepl') | log = pykolab.getLogger('pykolab.syncrepl') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
class DNSync(ldap.ldapobject.LDAPObject,ldap.syncrepl.SyncreplConsumer): | class DNSync(ldap.ldapobject.LDAPObject, ldap.syncrepl.SyncreplConsumer): | ||||
callback = None | callback = None | ||||
def __init__(self, filename, *args, **kwargs): | def __init__(self, filename, *args, **kwargs): | ||||
if 'callback' in kwargs: | if 'callback' in kwargs: | ||||
self.callback = kwargs['callback'] | self.callback = kwargs['callback'] | ||||
del kwargs['callback'] | del kwargs['callback'] | ||||
ldap.ldapobject.LDAPObject.__init__(self, *args, **kwargs) | ldap.ldapobject.LDAPObject.__init__(self, *args, **kwargs) | ||||
self.__db = anydbm.open(filename, 'c', 0o640) | self.__db = anydbm.open(filename, 'c', 0o640) | ||||
self.__presentUUIDs = {} | self.__presentUUIDs = {} | ||||
def syncrepl_set_cookie(self,cookie): | def syncrepl_set_cookie(self, cookie): | ||||
self.__db['cookie'] = cookie | self.__db['cookie'] = cookie | ||||
def syncrepl_get_cookie(self): | def syncrepl_get_cookie(self): | ||||
if 'cookie' in self.__db: | if 'cookie' in self.__db: | ||||
return self.__db['cookie'] | return self.__db['cookie'] | ||||
def syncrepl_delete(self, uuids): | def syncrepl_delete(self, uuids): | ||||
log.debug("syncrepl_delete uuids: %r" % (uuids), level=8) | log.debug("syncrepl_delete uuids: %r" % uuids, level=8) | ||||
# Get the unique_attribute name to issue along with our | # Get the unique_attribute name to issue along with our | ||||
# callback (if any) | # callback (if any) | ||||
unique_attr = conf.get('ldap', 'unique_attribute') | unique_attr = conf.get('ldap', 'unique_attribute') | ||||
if unique_attr == None: | if unique_attr is None: | ||||
unique_attr = 'entryuuid' | unique_attr = 'entryuuid' | ||||
if unique_attr == 'nsuniqueid': | if unique_attr == 'nsuniqueid': | ||||
log.warning( | log.warning( | ||||
_("The name of the persistent, unique attribute " + \ | _("The name of the persistent, unique attribute " + \ | ||||
"is very probably not compatible with the use of " + \ | "is very probably not compatible with the use of " + \ | ||||
"syncrepl.") | "syncrepl.") | ||||
) | ) | ||||
for uuid in uuids: | for uuid in uuids: | ||||
dn = self.__db[uuid] | dn = self.__db[uuid] | ||||
log.debug("syncrepl_delete dn: %r" % (dn), level=8) | log.debug("syncrepl_delete dn: %r" % dn, level=8) | ||||
if not self.callback == None: | if self.callback is not None: | ||||
self.callback( | self.callback( | ||||
change_type='delete', | change_type='delete', | ||||
previous_dn=None, | previous_dn=None, | ||||
change_number=None, | change_number=None, | ||||
dn=dn, | dn=dn, | ||||
entry={ | entry={ | ||||
unique_attr: uuid | unique_attr: uuid | ||||
} | } | ||||
Show All 16 Lines | def syncrepl_present(self, uuids, refreshDeletes=False): | ||||
self.__presentUUIDs[uuid] = True | self.__presentUUIDs[uuid] = True | ||||
def syncrepl_entry(self, dn, attrs, uuid): | def syncrepl_entry(self, dn, attrs, uuid): | ||||
attrs = utils.normalize(attrs) | attrs = utils.normalize(attrs) | ||||
if uuid in self.__db: | if uuid in self.__db: | ||||
odn = self.__db[uuid] | odn = self.__db[uuid] | ||||
if odn != dn: | if odn != dn: | ||||
if not self.callback == None: | if self.callback is not None: | ||||
self.callback( | self.callback( | ||||
change_type='moddn', | change_type='moddn', | ||||
previous_dn=odn, | previous_dn=odn, | ||||
change_number=None, | change_number=None, | ||||
dn=dn, | dn=dn, | ||||
entry=attrs | entry=attrs | ||||
) | ) | ||||
else: | else: | ||||
if not self.callback == None: | if self.callback is not None: | ||||
self.callback( | self.callback( | ||||
change_type='modify', | change_type='modify', | ||||
previous_dn=None, | previous_dn=None, | ||||
change_number=None, | change_number=None, | ||||
dn=self.__db[uuid], | dn=self.__db[uuid], | ||||
entry=attrs | entry=attrs | ||||
) | ) | ||||
else: | else: | ||||
if not self.callback == None: | if self.callback is not None: | ||||
self.callback( | self.callback( | ||||
change_type='add', | change_type='add', | ||||
previous_dn=None, | previous_dn=None, | ||||
change_number=None, | change_number=None, | ||||
dn=dn, | dn=dn, | ||||
entry=attrs | entry=attrs | ||||
) | ) | ||||
self.__db[uuid] = dn | self.__db[uuid] = dn |