Changeset View
Changeset View
Standalone View
Standalone View
pykolab/auth/ldap/__init__.py
Show First 20 Lines • Show All 496 Lines • ▼ Show 20 Lines | def entry_dn(self, entry_id): | ||||
config_base_dn = self.config_get('base_dn') | config_base_dn = self.config_get('base_dn') | ||||
ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ||||
if not ldap_base_dn == None and not ldap_base_dn == config_base_dn: | if not ldap_base_dn == None and not ldap_base_dn == config_base_dn: | ||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
_filter = "(%s=%s)" % (unique_attribute, ldap.filter.escape_filter_chars(entry_id)) | |||||
_search = self.ldap.search_ext( | _search = self.ldap.search_ext( | ||||
base_dn, | base_dn, | ||||
ldap.SCOPE_SUBTREE, | ldap.SCOPE_SUBTREE, | ||||
'(%s=%s)' % (unique_attribute, entry_id), | _filter, | ||||
['entrydn'] | ['entrydn'] | ||||
) | ) | ||||
( | ( | ||||
_result_type, | _result_type, | ||||
_result_data, | _result_data, | ||||
_result_msgid, | _result_msgid, | ||||
_result_controls | _result_controls | ||||
▲ Show 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | def find_recipient(self, address="*", exclude_entry_id=None, search_attrs=None): | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
if not exclude_entry_id == None: | if not exclude_entry_id == None: | ||||
__filter_prefix = "(&" | __filter_prefix = "(&" | ||||
__filter_suffix = "(!(%s=%s)))" % ( | __filter_suffix = "(!(%s=%s)))" % ( | ||||
self.config_get('unique_attribute'), | self.config_get('unique_attribute'), | ||||
exclude_entry_id | ldap.filter.escape_filter_chars(exclude_entry_id) | ||||
) | ) | ||||
else: | else: | ||||
__filter_prefix = "" | __filter_prefix = "" | ||||
__filter_suffix = "" | __filter_suffix = "" | ||||
kolab_filter = self._kolab_filter() | kolab_filter = self._kolab_filter() | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def find_resource(self, address="*", exclude_entry_id=None): | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
if not exclude_entry_id == None: | if not exclude_entry_id == None: | ||||
__filter_prefix = "(&" | __filter_prefix = "(&" | ||||
__filter_suffix = "(!(%s=%s)))" % ( | __filter_suffix = "(!(%s=%s)))" % ( | ||||
self.config_get('unique_attribute'), | self.config_get('unique_attribute'), | ||||
exclude_entry_id | ldap.filter.escape_filter_chars(exclude_entry_id) | ||||
) | ) | ||||
else: | else: | ||||
__filter_prefix = "" | __filter_prefix = "" | ||||
__filter_suffix = "" | __filter_suffix = "" | ||||
resource_filter = self.config_get('resource_filter') | resource_filter = self.config_get('resource_filter') | ||||
if not resource_filter == None: | if not resource_filter == None: | ||||
Show All 38 Lines | def find_resource(self, address="*", exclude_entry_id=None): | ||||
attrlist=result_attributes, | attrlist=result_attributes, | ||||
attrsonly=True | attrsonly=True | ||||
) | ) | ||||
_entry_dns = [] | _entry_dns = [] | ||||
for _result in _results: | for _result in _results: | ||||
(_entry_id, _entry_attrs) = _result | (_entry_id, _entry_attrs) = _result | ||||
# Prevent Active Directory referrals | |||||
if not _entry_id == None: | |||||
_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=8) | log.debug(_("Using timestamp %r") % (timestamp), level=8) | ||||
return timestamp | return timestamp | ||||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | def search_entry_by_attribute(self, attr, value, **kw): | ||||
config_base_dn = self.config_get('base_dn') | config_base_dn = self.config_get('base_dn') | ||||
ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ||||
if not ldap_base_dn == None and not ldap_base_dn == config_base_dn: | if not ldap_base_dn == None and not ldap_base_dn == config_base_dn: | ||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
return self._search( | _results = self._search( | ||||
base_dn, | base_dn, | ||||
filterstr=_filter, | filterstr=_filter, | ||||
attrlist=[ | attrlist=[ | ||||
'*', | '*', | ||||
], | ], | ||||
override_search='_regular_search' | override_search='_regular_search' | ||||
) | ) | ||||
_entry_dns = [] | |||||
for _result in _results: | |||||
(_entry_dn, _entry_attrs) = _result | |||||
# Prevent Active Directory referrals | |||||
if not _entry_dn == None: | |||||
_entry_dns.append(_entry_id) | |||||
machniak: s/_entry_id/_entry_dn/, but... | |||||
return _entry_dns | |||||
Not Done Inline Actions... but, didn't you change the returned value format? Maybe you meant _entry_dns.append(_result) in the loop above? machniak: ... but, didn't you change the returned value format? Maybe you meant _entry_dns.append… | |||||
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=8) | 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) | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def synchronize(self, mode=0, callback=None): | ||||
modifytimestamp_format = "%Y%m%d%H%M%SZ" | modifytimestamp_format = "%Y%m%d%H%M%SZ" | ||||
modified_after = datetime.datetime(1900, 01, 01, 00, 00, 00).strftime(modifytimestamp_format) | modified_after = datetime.datetime(1900, 01, 01, 00, 00, 00).strftime(modifytimestamp_format) | ||||
else: | else: | ||||
modified_after = self.get_latest_sync_timestamp() | modified_after = self.get_latest_sync_timestamp() | ||||
_filter = "(&%s(modifytimestamp>=%s))" % (_filter,modified_after) | _filter = "(&%s(modifytimestamp>=%s))" % (_filter,modified_after) | ||||
log.debug(_("Using filter %r") % (_filter), level=8) | log.debug(_("Synchronization is using filter %r") % (_filter), level=8) | ||||
if not mode == 0: | if not mode == 0: | ||||
override_search = mode | override_search = mode | ||||
else: | else: | ||||
override_search = False | override_search = False | ||||
config_base_dn = self.config_get('base_dn') | config_base_dn = self.config_get('base_dn') | ||||
ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ldap_base_dn = self._kolab_domain_root_dn(self.domain) | ||||
▲ Show 20 Lines • Show All 981 Lines • ▼ Show 20 Lines | def _disconnect(self): | ||||
self.bind = None | self.bind = None | ||||
def _domain_naming_context(self, domain): | def _domain_naming_context(self, domain): | ||||
self._bind() | self._bind() | ||||
# The list of naming contexts in the LDAP server | # The list of naming contexts in the LDAP server | ||||
attrs = self.get_entry_attributes("", ['namingContexts']) | attrs = self.get_entry_attributes("", ['namingContexts']) | ||||
naming_contexts = attrs['namingcontexts'] | # Lower case of naming contexts - primarily for AD | ||||
naming_contexts = utils.normalize(attrs['namingcontexts']) | |||||
if isinstance(naming_contexts, basestring): | if isinstance(naming_contexts, basestring): | ||||
naming_contexts = [ naming_contexts ] | naming_contexts = [ naming_contexts ] | ||||
log.debug( | log.debug( | ||||
_("Naming contexts found: %r") % (naming_contexts), | _("Naming contexts found: %r") % (naming_contexts), | ||||
level=8 | level=8 | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | def _synchronize_callback(self, *args, **kw): | ||||
args, | args, | ||||
kw | kw | ||||
), | ), | ||||
level=8 | 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'): | ||||
log.debug(_("change_type defined, typical for Persistent Change Control EntryChangeNotification"), level=5) | |||||
change_type = None | change_type = None | ||||
change_dict = { | change_dict = { | ||||
'change_type': kw['change_type'], | 'change_type': kw['change_type'], | ||||
'previous_dn': kw['previous_dn'], | 'previous_dn': kw['previous_dn'], | ||||
'change_number': kw['change_number'], | 'change_number': kw['change_number'], | ||||
'dn': kw['dn'] | 'dn': kw['dn'] | ||||
} | } | ||||
Show All 34 Lines | def _synchronize_callback(self, *args, **kw): | ||||
"self._change_%s_%s(entry, change_dict)" % ( | "self._change_%s_%s(entry, change_dict)" % ( | ||||
change, | change, | ||||
entry['type'] | entry['type'] | ||||
) | ) | ||||
) | ) | ||||
# Typical for Paged Results Control | # Typical for Paged Results Control | ||||
elif kw.has_key('entry') and isinstance(kw['entry'], list): | elif kw.has_key('entry') and isinstance(kw['entry'], list): | ||||
log.debug(_("No change_type, typical for Paged Results Control"), level=5) | |||||
for entry_dn,entry_attrs in kw['entry']: | for entry_dn,entry_attrs in kw['entry']: | ||||
# This is a referral | # This is a referral | ||||
if entry_dn == None: | if entry_dn == None: | ||||
continue | continue | ||||
entry = { 'dn': entry_dn } | entry = { 'dn': entry_dn } | ||||
entry_attrs = utils.normalize(entry_attrs) | entry_attrs = utils.normalize(entry_attrs) | ||||
for attr in entry_attrs.keys(): | for attr in entry_attrs.keys(): | ||||
entry[attr.lower()] = entry_attrs[attr] | entry[attr.lower()] = entry_attrs[attr] | ||||
unique_attr = self.config_get('unique_attribute') | unique_attr = self.config_get('unique_attribute').lower() | ||||
entry['id'] = entry[unique_attr] | entry['id'] = entry[unique_attr] | ||||
try: | try: | ||||
entry['type'] = self._entry_type(entry) | entry['type'] = self._entry_type(entry) | ||||
except: | except: | ||||
entry['type'] = "unknown" | entry['type'] = "unknown" | ||||
log.debug(_("Entry type: %s") % (entry['type']), level=8) | log.debug(_("Entry type for dn: %s is: %s") % (entry['dn'], 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=8) | # log.debug(_("Recipient Addresses: %r") % (rcpt_addrs), level=8) | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | def _paged_search(self, | ||||
except ldap.NO_SUCH_OBJECT, e: | except ldap.NO_SUCH_OBJECT, e: | ||||
log.warning( | log.warning( | ||||
_("Object %s searched no longer exists") % (base_dn) | _("Object %s searched no longer exists") % (base_dn) | ||||
) | ) | ||||
break | break | ||||
# Remove referrals | |||||
_result_data = [_e for _e in _result_data if _e[0] is not None] | |||||
if callback: | if callback: | ||||
callback(entry=_result_data) | callback(entry=_result_data) | ||||
_results.extend(_result_data) | _results.extend(_result_data) | ||||
if (pages % 2) == 0: | if (pages % 2) == 0: | ||||
log.debug(_("%d results...") % (len(_results))) | log.debug(_("%d results...") % (len(_results))) | ||||
pctrls = [ | pctrls = [ | ||||
▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines |
s/_entry_id/_entry_dn/, but...