Changeset View
Changeset View
Standalone View
Standalone View
pykolab/auth/ldap/__init__.py
Show First 20 Lines • Show All 452 Lines • ▼ Show 20 Line(s) | |||||
retry_delay = 1.0 | retry_delay = 1.0 | ||||
else: | else: | ||||
retry_max = 200 | retry_max = 200 | ||||
retry_delay = 3.0 | retry_delay = 3.0 | ||||
conn = ldap.ldapobject.ReconnectLDAPObject( | conn = ldap.ldapobject.ReconnectLDAPObject( | ||||
uri, | uri, | ||||
trace_level=trace_level, | trace_level=trace_level, | ||||
trace_file=pykolab.logger.StderrToLogger(log), | |||||
retry_max=retry_max, | retry_max=retry_max, | ||||
retry_delay=retry_delay | retry_delay=retry_delay | ||||
) | ) | ||||
if immediate: | if immediate: | ||||
conn.set_option(ldap.OPT_TIMEOUT, 10) | conn.set_option(ldap.OPT_TIMEOUT, 10) | ||||
conn.protocol_version = 3 | conn.protocol_version = 3 | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
def get_entry_attributes(self, entry_id, attributes): | def get_entry_attributes(self, entry_id, attributes): | ||||
""" | """ | ||||
Get multiple attributes for an entry. | Get multiple attributes for an entry. | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
log.debug(_("Entry ID: %r") % (entry_id), level=9) | log.debug(_("Entry ID: %r") % (entry_id), level=8) | ||||
entry_dn = self.entry_dn(entry_id) | entry_dn = self.entry_dn(entry_id) | ||||
log.debug(_("Entry DN: %r") % (entry_dn), level=9) | log.debug(_("Entry DN: %r") % (entry_dn), level=8) | ||||
log.debug( | log.debug( | ||||
_("ldap search: (%r, %r, filterstr='(objectclass=*)', attrlist=[ 'dn' ] + %r") % ( | _("ldap search: (%r, %r, filterstr='(objectclass=*)', attrlist=[ 'dn' ] + %r") % ( | ||||
entry_dn, | entry_dn, | ||||
ldap.SCOPE_BASE, | ldap.SCOPE_BASE, | ||||
attributes | attributes | ||||
), | ), | ||||
level=9 | level=8 | ||||
) | ) | ||||
_search = self.ldap.search_ext( | _search = self.ldap.search_ext( | ||||
entry_dn, | entry_dn, | ||||
ldap.SCOPE_BASE, | ldap.SCOPE_BASE, | ||||
filterstr='(objectclass=*)', | filterstr='(objectclass=*)', | ||||
attrlist=[ 'dn' ] + attributes | attrlist=[ 'dn' ] + attributes | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Line(s) | |||||
for _result in _results: | for _result in _results: | ||||
(_entry_id, _entry_attrs) = _result | (_entry_id, _entry_attrs) = _result | ||||
_entry_dns.append(_entry_id) | _entry_dns.append(_entry_id) | ||||
return _entry_dns | return _entry_dns | ||||
def get_latest_sync_timestamp(self): | def get_latest_sync_timestamp(self): | ||||
timestamp = cache.last_modify_timestamp(self.domain) | timestamp = cache.last_modify_timestamp(self.domain) | ||||
log.debug(_("Using timestamp %r") % (timestamp), level=9) | log.debug(_("Using timestamp %r") % (timestamp), level=8) | ||||
return timestamp | return timestamp | ||||
def list_secondary_domains(self): | def list_secondary_domains(self): | ||||
""" | """ | ||||
List alias domain name spaces for the current domain name space. | List alias domain name spaces for the current domain name space. | ||||
""" | """ | ||||
if not self.domains == None: | if not self.domains == None: | ||||
return [s for s in self.domains.keys() if not s in self.domains.values()] | return [s for s in self.domains.keys() if not s in self.domains.values()] | ||||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Line(s) | |||||
else: | else: | ||||
secondary_mail_addresses.append(entry[secondary_mail_attribute]) | secondary_mail_addresses.append(entry[secondary_mail_attribute]) | ||||
if not secondary_mail_addresses == None: | if not secondary_mail_addresses == None: | ||||
log.debug( | log.debug( | ||||
_("Secondary mail addresses that we want is not None: %r") % ( | _("Secondary mail addresses that we want is not None: %r") % ( | ||||
secondary_mail_addresses | secondary_mail_addresses | ||||
), | ), | ||||
level=9 | level=8 | ||||
) | ) | ||||
secondary_mail_addresses = list(set(secondary_mail_addresses)) | secondary_mail_addresses = list(set(secondary_mail_addresses)) | ||||
# Avoid duplicates | # Avoid duplicates | ||||
while primary_mail_address in secondary_mail_addresses: | while primary_mail_address in secondary_mail_addresses: | ||||
log.debug( | log.debug( | ||||
_("Avoiding the duplication of the primary mail " + \ | _("Avoiding the duplication of the primary mail " + \ | ||||
"address %r in the list of secondary mail " + \ | "address %r in the list of secondary mail " + \ | ||||
"addresses") % (primary_mail_address), | "addresses") % (primary_mail_address), | ||||
level=9 | level=8 | ||||
) | ) | ||||
secondary_mail_addresses.pop( | secondary_mail_addresses.pop( | ||||
secondary_mail_addresses.index(primary_mail_address) | secondary_mail_addresses.index(primary_mail_address) | ||||
) | ) | ||||
log.debug( | log.debug( | ||||
_("Entry is getting secondary mail addresses: %r") % ( | _("Entry is getting secondary mail addresses: %r") % ( | ||||
secondary_mail_addresses | secondary_mail_addresses | ||||
), | ), | ||||
level=9 | level=8 | ||||
) | ) | ||||
if not entry.has_key(secondary_mail_attribute): | if not entry.has_key(secondary_mail_attribute): | ||||
log.debug( | log.debug( | ||||
_("Entry did not have any secondary mail " + \ | _("Entry did not have any secondary mail " + \ | ||||
"addresses in %r") % (secondary_mail_attribute), | "addresses in %r") % (secondary_mail_attribute), | ||||
level=9 | level=8 | ||||
) | ) | ||||
if not len(secondary_mail_addresses) == 0: | if not len(secondary_mail_addresses) == 0: | ||||
self.set_entry_attribute( | self.set_entry_attribute( | ||||
entry, | entry, | ||||
secondary_mail_attribute, | secondary_mail_attribute, | ||||
secondary_mail_addresses | secondary_mail_addresses | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
filterstr=_filter, | filterstr=_filter, | ||||
attrlist=[ | attrlist=[ | ||||
'*', | '*', | ||||
], | ], | ||||
override_search='_regular_search' | override_search='_regular_search' | ||||
) | ) | ||||
def set_entry_attribute(self, entry_id, attribute, value): | def set_entry_attribute(self, entry_id, attribute, value): | ||||
log.debug(_("Setting entry attribute %r to %r for %r") % (attribute, value, entry_id), level=9) | log.debug(_("Setting entry attribute %r to %r for %r") % (attribute, value, entry_id), level=8) | ||||
self.set_entry_attributes(entry_id, { attribute: value }) | self.set_entry_attributes(entry_id, { attribute: value }) | ||||
def set_entry_attributes(self, entry_id, attributes): | def set_entry_attributes(self, entry_id, attributes): | ||||
self._bind() | self._bind() | ||||
entry_dn = self.entry_dn(entry_id) | entry_dn = self.entry_dn(entry_id) | ||||
entry = self.get_entry_attributes(entry_dn, ['*']) | entry = self.get_entry_attributes(entry_dn, ['*']) | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | |||||
_("About to consider the user quota for %r (used: %r, " + \ | _("About to consider the user quota for %r (used: %r, " + \ | ||||
"imap: %r, ldap: %r, default: %r") % ( | "imap: %r, ldap: %r, default: %r") % ( | ||||
entry_dn, | entry_dn, | ||||
used, | used, | ||||
current_imap_quota, | current_imap_quota, | ||||
current_ldap_quota, | current_ldap_quota, | ||||
default_quota | default_quota | ||||
), | ), | ||||
level=9 | level=8 | ||||
) | ) | ||||
new_quota = conf.plugins.exec_hook("set_user_folder_quota", kw={ | new_quota = conf.plugins.exec_hook("set_user_folder_quota", kw={ | ||||
'used': used, | 'used': used, | ||||
'imap_quota': current_imap_quota, | 'imap_quota': current_imap_quota, | ||||
'ldap_quota': current_ldap_quota, | 'ldap_quota': current_ldap_quota, | ||||
'default_quota': default_quota | 'default_quota': default_quota | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1245 Lines • ▼ Show 20 Line(s) | |||||
supportedControl used to even get the data. | supportedControl used to even get the data. | ||||
""" | """ | ||||
log.debug( | log.debug( | ||||
"auth.ldap.LDAP._synchronize_callback(args %r, kw %r)" % ( | "auth.ldap.LDAP._synchronize_callback(args %r, kw %r)" % ( | ||||
args, | args, | ||||
kw | kw | ||||
), | ), | ||||
level=9 | level=8 | ||||
) | ) | ||||
# Typical for Persistent Change Control EntryChangeNotification | # Typical for Persistent Change Control EntryChangeNotification | ||||
if kw.has_key('change_type'): | if kw.has_key('change_type'): | ||||
change_type = None | change_type = None | ||||
change_dict = { | change_dict = { | ||||
'change_type': kw['change_type'], | 'change_type': kw['change_type'], | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
log.debug(_("Entry type: %s") % (entry['type']), level=8) | log.debug(_("Entry type: %s") % (entry['type']), level=8) | ||||
eval("self._change_none_%s(entry, None)" % (entry['type'])) | eval("self._change_none_%s(entry, None)" % (entry['type'])) | ||||
# result_attribute = conf.get('cyrus-sasl', 'result_attribute') | # result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
# | # | ||||
# rcpt_addrs = self.recipient_policy(entry) | # rcpt_addrs = self.recipient_policy(entry) | ||||
# | # | ||||
# log.debug(_("Recipient Addresses: %r") % (rcpt_addrs), level=9) | # log.debug(_("Recipient Addresses: %r") % (rcpt_addrs), level=8) | ||||
# | # | ||||
# for key in rcpt_addrs.keys(): | # for key in rcpt_addrs.keys(): | ||||
# entry[key] = rcpt_addrs[key] | # entry[key] = rcpt_addrs[key] | ||||
# | # | ||||
# cache.get_entry(self.domain, entry) | # cache.get_entry(self.domain, entry) | ||||
# | # | ||||
# self.imap.connect(domain=self.domain) | # self.imap.connect(domain=self.domain) | ||||
# | # | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | |||||
import syncrepl | import syncrepl | ||||
ldap_url = ldapurl.LDAPUrl(self.config_get('ldap_uri')) | ldap_url = ldapurl.LDAPUrl(self.config_get('ldap_uri')) | ||||
ldap_sync_conn = syncrepl.DNSync( | ldap_sync_conn = syncrepl.DNSync( | ||||
'/var/lib/kolab/syncrepl_%s.db' % (self.domain), | '/var/lib/kolab/syncrepl_%s.db' % (self.domain), | ||||
ldap_url.initializeUrl(), | ldap_url.initializeUrl(), | ||||
trace_level=2, | trace_level=2, | ||||
trace_file=pykolab.logger.StderrToLogger(log), | |||||
callback=self._synchronize_callback | callback=self._synchronize_callback | ||||
) | ) | ||||
bind_dn = self.config_get('bind_dn') | bind_dn = self.config_get('bind_dn') | ||||
bind_pw = self.config_get('bind_pw') | bind_pw = self.config_get('bind_pw') | ||||
ldap_sync_conn.simple_bind_s(bind_dn, bind_pw) | ldap_sync_conn.simple_bind_s(bind_dn, bind_pw) | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |