Changeset View
Standalone View
pykolab/auth/ldap/__init__.py
Show All 31 Lines | |||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.constants import * | from pykolab.constants import * | ||||
from pykolab.errors import * | from pykolab.errors import * | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
log = pykolab.getLogger('pykolab.auth') | log = pykolab.getLogger('pykolab.auth') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
import auth_cache | import auth_cache | ||||
Lint: PEP8 E402: module level import not at top of file | |||||
import cache | import cache | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
# Catch python-ldap-2.4 changes | # Catch python-ldap-2.4 changes | ||||
from distutils import version | from distutils import version | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__): | if version.StrictVersion('2.4.0') <= version.StrictVersion(ldap.__version__): | ||||
LDAP_CONTROL_PAGED_RESULTS = ldap.CONTROL_PAGEDRESULTS | LDAP_CONTROL_PAGED_RESULTS = ldap.CONTROL_PAGEDRESULTS | ||||
else: | else: | ||||
LDAP_CONTROL_PAGED_RESULTS = ldap.LDAP_CONTROL_PAGE_OID | LDAP_CONTROL_PAGED_RESULTS = ldap.LDAP_CONTROL_PAGE_OID | ||||
try: | try: | ||||
from ldap.controls import psearch | from ldap.controls import psearch | ||||
except: | except: | ||||
log.warning(_("Python LDAP library does not support persistent search")) | log.warning(_("Python LDAP library does not support persistent search")) | ||||
class SimplePagedResultsControl(ldap.controls.SimplePagedResultsControl): | class SimplePagedResultsControl(ldap.controls.SimplePagedResultsControl): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
""" | """ | ||||
Python LDAP 2.4 and later breaks the API. This is an abstraction class | Python LDAP 2.4 and later breaks the API. This is an abstraction class | ||||
so that we can handle either. | so that we can handle either. | ||||
""" | """ | ||||
def __init__(self, page_size=0, cookie=''): | def __init__(self, page_size=0, cookie=''): | ||||
if version.StrictVersion( | if version.StrictVersion( | ||||
Show All 32 Lines | def size(self): | ||||
) <= version.StrictVersion( | ) <= version.StrictVersion( | ||||
ldap.__version__ | ldap.__version__ | ||||
): | ): | ||||
return self.size | return self.size | ||||
else: | else: | ||||
return self.controlValue[0] | return self.controlValue[0] | ||||
class LDAP(pykolab.base.Base): | class LDAP(pykolab.base.Base): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
""" | """ | ||||
Abstraction layer for the LDAP authentication / authorization backend, | Abstraction layer for the LDAP authentication / authorization backend, | ||||
for use with Kolab. | for use with Kolab. | ||||
""" | """ | ||||
def __init__(self, domain=None): | def __init__(self, domain=None): | ||||
""" | """ | ||||
Initialize the LDAP object for domain. If no domain is specified, | Initialize the LDAP object for domain. If no domain is specified, | ||||
domain name space configured as 'kolab'.'primary_domain' is used. | domain name space configured as 'kolab'.'primary_domain' is used. | ||||
""" | """ | ||||
pykolab.base.Base.__init__(self, domain=domain) | pykolab.base.Base.__init__(self, domain=domain) | ||||
self.ldap = None | self.ldap = None | ||||
self.bind = None | self.bind = None | ||||
if domain == None: | if domain == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.domain = conf.get('kolab', 'primary_domain') | self.domain = conf.get('kolab', 'primary_domain') | ||||
else: | else: | ||||
self.domain = domain | self.domain = domain | ||||
def authenticate(self, login, realm): | def authenticate(self, login, realm): | ||||
""" | """ | ||||
Find the entry corresponding to login, and attempt a bind. | Find the entry corresponding to login, and attempt a bind. | ||||
login is a tuple with 4 values. In order of appearance; | login is a tuple with 4 values. In order of appearance; | ||||
[0] - the login username. | [0] - the login username. | ||||
[1] - the password | [1] - the password | ||||
[2] - the service (optional) | [2] - the service (optional) | ||||
[3] - the realm | [3] - the realm | ||||
Called from pykolab.auth.Auth, the realm parameter is derived, while | Called from pykolab.auth.Auth, the realm parameter is derived, while | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
login[3] preserves the originally specified realm. | login[3] preserves the originally specified realm. | ||||
""" | """ | ||||
try: | try: | ||||
log.debug( | log.debug( | ||||
_("Attempting to authenticate user %s in realm %s") % ( | _("Attempting to authenticate user %s in realm %s") % ( | ||||
login[0], | login[0], | ||||
realm | realm | ||||
Show All 9 Lines | def authenticate(self, login, realm): | ||||
# See if we know a base_dn for the domain | # See if we know a base_dn for the domain | ||||
base_dn = None | base_dn = None | ||||
try: | try: | ||||
base_dn = auth_cache.get_entry(self.domain) | base_dn = auth_cache.get_entry(self.domain) | ||||
except: | except: | ||||
pass | pass | ||||
if base_dn == None: | if base_dn == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
try: | try: | ||||
auth_cache.set_entry(self.domain, base_dn) | auth_cache.set_entry(self.domain, base_dn) | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.error(_("Authentication cache failed: %r") % (errmsg)) | log.error(_("Authentication cache failed: %r") % (errmsg)) | ||||
pass | pass | ||||
try: | try: | ||||
user_filter = self.config_get_raw('user_filter') % ({'base_dn':base_dn}) | user_filter = self.config_get_raw('user_filter') % ({'base_dn':base_dn}) | ||||
Lint: PEP8 E231 missing whitespace after ':' Lint: PEP8 E231: missing whitespace after ':' | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
except TypeError, errmsg: | except TypeError, errmsg: | ||||
user_filter = self.config_get_raw('user_filter') | user_filter = self.config_get_raw('user_filter') | ||||
_filter = '(&(|' | _filter = '(&(|' | ||||
auth_attrs = self.config_get_list('auth_attributes') | auth_attrs = self.config_get_list('auth_attributes') | ||||
for attr in auth_attrs: | for attr in auth_attrs: | ||||
_filter += "(%s=%s)" % (attr, login[0]) | _filter += "(%s=%s)" % (attr, login[0]) | ||||
_filter += "(%s=%s@%s)" % (attr, login[0], realm) | _filter += "(%s=%s@%s)" % (attr, login[0], realm) | ||||
_filter += ')%s)' % (user_filter) | _filter += ')%s)' % (user_filter) | ||||
entry_dn = None | entry_dn = None | ||||
try: | try: | ||||
entry_dn = auth_cache.get_entry(_filter) | entry_dn = auth_cache.get_entry(_filter) | ||||
except: | except: | ||||
pass | pass | ||||
if entry_dn == None: | if entry_dn == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
_search = self.ldap.search_ext( | _search = self.ldap.search_ext( | ||||
base_dn, | base_dn, | ||||
ldap.SCOPE_SUBTREE, | ldap.SCOPE_SUBTREE, | ||||
_filter, | _filter, | ||||
['entrydn'] | ['entrydn'] | ||||
) | ) | ||||
try: | try: | ||||
Show All 10 Lines | def authenticate(self, login, realm): | ||||
self._disconnect() | self._disconnect() | ||||
return False | return False | ||||
if len(_result_data) >= 1: | if len(_result_data) >= 1: | ||||
(entry_dn, entry_attrs) = _result_data[0] | (entry_dn, entry_attrs) = _result_data[0] | ||||
try: | try: | ||||
log.debug(_("Binding with user_dn %s and password %s") | log.debug(_("Binding with user_dn %s and password %s") | ||||
% (entry_dn, '*' * len(login[1]))) | % (entry_dn, '*' * len(login[1]))) | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
# Needs to be synchronous or succeeds and continues setting retval | # Needs to be synchronous or succeeds and continues setting retval | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
# to True!! | # to True!! | ||||
retval = self._bind(entry_dn, login[1]) | retval = self._bind(entry_dn, login[1]) | ||||
try: | try: | ||||
auth_cache.set_entry(_filter, entry_dn) | auth_cache.set_entry(_filter, entry_dn) | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.error(_("Authentication cache failed: %r") % (errmsg)) | log.error(_("Authentication cache failed: %r") % (errmsg)) | ||||
pass | pass | ||||
except ldap.SERVER_DOWN, errmsg: | except ldap.SERVER_DOWN, errmsg: | ||||
log.error(_("Authentication failed, LDAP server unavailable")) | log.error(_("Authentication failed, LDAP server unavailable")) | ||||
self._disconnect() | self._disconnect() | ||||
pass | pass | ||||
except: | except: | ||||
try: | try: | ||||
log.debug( | log.debug( | ||||
_("Failed to authenticate as user %s") % (login[0]), | _("Failed to authenticate as user %s") % (login[0]), | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
level=8 | level=8 | ||||
) | ) | ||||
except: | except: | ||||
pass | pass | ||||
retval = False | retval = False | ||||
else: | else: | ||||
try: | try: | ||||
log.debug(_("Binding with user_dn %s and password %s") | log.debug(_("Binding with user_dn %s and password %s") | ||||
% (entry_dn, '*' * len(login[1]))) | % (entry_dn, '*' * len(login[1]))) | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
# Needs to be synchronous or succeeds and continues setting retval | # Needs to be synchronous or succeeds and continues setting retval | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
# to True!! | # to True!! | ||||
retval = self._bind(entry_dn, login[1]) | retval = self._bind(entry_dn, login[1]) | ||||
auth_cache.set_entry(_filter, entry_dn) | auth_cache.set_entry(_filter, entry_dn) | ||||
except ldap.NO_SUCH_OBJECT, errmsg: | except ldap.NO_SUCH_OBJECT, errmsg: | ||||
log.debug(_("Error occured, there is no such object: %r") % (errmsg), level=8) | log.debug(_("Error occured, there is no such object: %r") % (errmsg), level=8) | ||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
self.bind = None | self.bind = None | ||||
try: | try: | ||||
auth_cache.del_entry(_filter) | auth_cache.del_entry(_filter) | ||||
except: | except: | ||||
log.error(_("Authentication cache failed to clear entry")) | log.error(_("Authentication cache failed to clear entry")) | ||||
pass | pass | ||||
return self.authenticate(login, realm) | return self.authenticate(login, realm) | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.debug(_("Exception occured: %r") %(errmsg)) | log.debug(_("Exception occured: %r") %(errmsg)) | ||||
Lint: PEP8 E225 missing whitespace around operator Lint: PEP8 E225: missing whitespace around operator | |||||
try: | try: | ||||
log.debug( | log.debug( | ||||
_("Failed to authenticate as user %s") % (login[0]), | _("Failed to authenticate as user %s") % (login[0]), | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
level=8 | level=8 | ||||
) | ) | ||||
except: | except: | ||||
pass | pass | ||||
retval = False | retval = False | ||||
return retval | return retval | ||||
def connect(self): | def connect(self): | ||||
""" | """ | ||||
Connect to the LDAP server through the uri configured. | Connect to the LDAP server through the uri configured. | ||||
""" | """ | ||||
if not self.ldap == None: | if not self.ldap == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return | return | ||||
log.debug(_("Connecting to LDAP..."), level=8) | log.debug(_("Connecting to LDAP..."), level=8) | ||||
uri = self.config_get('ldap_uri') | uri = self.config_get('ldap_uri') | ||||
log.debug(_("Attempting to use LDAP URI %s") % (uri), level=8) | log.debug(_("Attempting to use LDAP URI %s") % (uri), level=8) | ||||
Show All 30 Lines | def entry_dn(self, entry_id): | ||||
if self._entry_dict(entry_id): | if self._entry_dict(entry_id): | ||||
return entry_id['dn'] | return entry_id['dn'] | ||||
unique_attribute = self.config_get('unique_attribute') | unique_attribute = self.config_get('unique_attribute') | ||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
_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), | '(%s=%s)' % (unique_attribute, entry_id), | ||||
Show All 35 Lines | def get_entry_attributes(self, entry_id, attributes): | ||||
self._bind() | self._bind() | ||||
log.debug(_("Entry ID: %r") % (entry_id), level=9) | log.debug(_("Entry ID: %r") % (entry_id), level=9) | ||||
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=9) | ||||
log.debug( | log.debug( | ||||
_("ldap search: (%r, %r, filterstr='(objectclass=*)', attrlist=[ 'dn' ] + %r") % ( | _("ldap search: (%r, %r, filterstr='(objectclass=*)', attrlist=[ 'dn' ] + %r") % ( | ||||
Lint: PEP8 E501 line too long (98 > 79 characters) Lint: PEP8 E501: line too long (98 > 79 characters) | |||||
entry_dn, | entry_dn, | ||||
ldap.SCOPE_BASE, | ldap.SCOPE_BASE, | ||||
attributes | attributes | ||||
), | ), | ||||
level=9 | level=9 | ||||
) | ) | ||||
_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 | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
) | ) | ||||
( | ( | ||||
_result_type, | _result_type, | ||||
_result_data, | _result_data, | ||||
_result_msgid, | _result_msgid, | ||||
_result_controls | _result_controls | ||||
) = self.ldap.result3(_search) | ) = self.ldap.result3(_search) | ||||
if len(_result_data) >= 1: | if len(_result_data) >= 1: | ||||
(_entry_dn, _entry_attrs) = _result_data[0] | (_entry_dn, _entry_attrs) = _result_data[0] | ||||
else: | else: | ||||
return None | return None | ||||
return utils.normalize(_entry_attrs) | return utils.normalize(_entry_attrs) | ||||
def list_recipient_addresses(self, entry_id): | def list_recipient_addresses(self, entry_id): | ||||
""" | """ | ||||
Give a list of all valid recipient addresses for an LDAP entry | Give a list of all valid recipient addresses for an LDAP entry | ||||
identified by its ID. | identified by its ID. | ||||
""" | """ | ||||
mail_attributes = conf.get_list('ldap', 'mail_attributes') | mail_attributes = conf.get_list('ldap', 'mail_attributes') | ||||
entry = self.get_entry_attributes(entry_id, mail_attributes) | entry = self.get_entry_attributes(entry_id, mail_attributes) | ||||
return self.extract_recipient_addresses(entry) if entry is not None else [] | return self.extract_recipient_addresses(entry) if entry is not None else [] | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
def extract_recipient_addresses(self, entry): | def extract_recipient_addresses(self, entry): | ||||
""" | """ | ||||
Extact a list of all valid recipient addresses for the given LDAP entry. | Extact a list of all valid recipient addresses for the given LDAP entry. | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
This includes all attributes configured for ldap.mail_attributes | This includes all attributes configured for ldap.mail_attributes | ||||
""" | """ | ||||
recipient_addresses = [] | recipient_addresses = [] | ||||
mail_attributes = conf.get_list('ldap', 'mail_attributes') | mail_attributes = conf.get_list('ldap', 'mail_attributes') | ||||
for attr in mail_attributes: | for attr in mail_attributes: | ||||
if entry.has_key(attr): | if entry.has_key(attr): | ||||
if isinstance(entry[attr], list): | if isinstance(entry[attr], list): | ||||
recipient_addresses.extend(entry[attr]) | recipient_addresses.extend(entry[attr]) | ||||
elif isinstance(entry[attr], basestring): | elif isinstance(entry[attr], basestring): | ||||
recipient_addresses.append(entry[attr]) | recipient_addresses.append(entry[attr]) | ||||
return recipient_addresses | return recipient_addresses | ||||
def list_delegators(self, entry_id): | def list_delegators(self, entry_id): | ||||
""" | """ | ||||
Get a list of user records the given user is set to be a delegatee | Get a list of user records the given user is set to be a delegatee | ||||
""" | """ | ||||
delegators = [] | delegators = [] | ||||
mailbox_attribute = conf.get('cyrus-sasl', 'result_attribute') | mailbox_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if mailbox_attribute == None: | if mailbox_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
mailbox_attribute = 'mail' | mailbox_attribute = 'mail' | ||||
for __delegator in self.search_entry_by_attribute('kolabDelegate', entry_id): | for __delegator in self.search_entry_by_attribute('kolabDelegate', entry_id): | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
(_dn, _delegator) = __delegator | (_dn, _delegator) = __delegator | ||||
_delegator['dn'] = _dn; | _delegator['dn'] = _dn; | ||||
Lint: PEP8 E703 statement ends with a semicolon Lint: PEP8 E703: statement ends with a semicolon | |||||
_delegator['_mailbox_basename'] = _delegator[mailbox_attribute] if _delegator.has_key(mailbox_attribute) else None | _delegator['_mailbox_basename'] = _delegator[mailbox_attribute] if _delegator.has_key(mailbox_attribute) else None | ||||
Lint: PEP8 E501 line too long (126 > 79 characters) Lint: PEP8 E501: line too long (126 > 79 characters) | |||||
if isinstance(_delegator['_mailbox_basename'], list): | if isinstance(_delegator['_mailbox_basename'], list): | ||||
_delegator['_mailbox_basename'] = _delegator['_mailbox_basename'][0] | _delegator['_mailbox_basename'] = _delegator['_mailbox_basename'][0] | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
delegators.append(_delegator) | delegators.append(_delegator) | ||||
return delegators | return delegators | ||||
def find_recipient(self, address="*", exclude_entry_id=None): | def find_recipient(self, address="*", exclude_entry_id=None): | ||||
""" | """ | ||||
Given an address string or list of addresses, find one or more valid | Given an address string or list of addresses, find one or more valid | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
recipients. | recipients. | ||||
Use this function only to detect whether an address is already in | Use this function only to detect whether an address is already in | ||||
use by any entry in the tree. | use by any entry in the tree. | ||||
Specify an additional entry_id to exclude to exclude matches against | Specify an additional entry_id to exclude to exclude matches against | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
the current entry. | the current entry. | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
if not exclude_entry_id == None: | if not exclude_entry_id == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is 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 | exclude_entry_id | ||||
) | ) | ||||
else: | else: | ||||
__filter_prefix = "" | __filter_prefix = "" | ||||
Show All 15 Lines | def find_recipient(self, address="*", exclude_entry_id=None): | ||||
if isinstance(address, basestring): | if isinstance(address, basestring): | ||||
_filter += "(%s=%s)" % (recipient_address_attr, address) | _filter += "(%s=%s)" % (recipient_address_attr, address) | ||||
else: | else: | ||||
for _address in address: | for _address in address: | ||||
_filter += "(%s=%s)" % (recipient_address_attr, _address) | _filter += "(%s=%s)" % (recipient_address_attr, _address) | ||||
_filter += ")" | _filter += ")" | ||||
_filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) | _filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
log.debug(_("Finding recipient with filter %r") % (_filter), level=8) | log.debug(_("Finding recipient with filter %r") % (_filter), level=8) | ||||
if len(_filter) <= 6: | if len(_filter) <= 6: | ||||
return None | return None | ||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
_results = self.ldap.search_s( | _results = self.ldap.search_s( | ||||
base_dn, | base_dn, | ||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
filterstr=_filter, | filterstr=_filter, | ||||
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 | # Prevent Active Directory referrals | ||||
if not _entry_id == None: | if not _entry_id == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
_entry_dns.append(_entry_id) | _entry_dns.append(_entry_id) | ||||
return _entry_dns | return _entry_dns | ||||
def find_resource(self, address="*", exclude_entry_id=None): | def find_resource(self, address="*", exclude_entry_id=None): | ||||
""" | """ | ||||
Given an address string or list of addresses, find one or more valid | Given an address string or list of addresses, find one or more valid | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
resources. | resources. | ||||
Specify an additional entry_id to exclude to exclude matches. | Specify an additional entry_id to exclude to exclude matches. | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
if not exclude_entry_id == None: | if not exclude_entry_id == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is 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 | 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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
__filter_prefix = "(&%s" % resource_filter | __filter_prefix = "(&%s" % resource_filter | ||||
__filter_suffix = ")" | __filter_suffix = ")" | ||||
recipient_address_attrs = self.config_get_list("mail_attributes") | recipient_address_attrs = self.config_get_list("mail_attributes") | ||||
result_attributes = recipient_address_attrs | result_attributes = recipient_address_attrs | ||||
result_attributes.append(self.config_get('unique_attribute')) | result_attributes.append(self.config_get('unique_attribute')) | ||||
_filter = "(|" | _filter = "(|" | ||||
for recipient_address_attr in recipient_address_attrs: | for recipient_address_attr in recipient_address_attrs: | ||||
if isinstance(address, basestring): | if isinstance(address, basestring): | ||||
_filter += "(%s=%s)" % (recipient_address_attr, address) | _filter += "(%s=%s)" % (recipient_address_attr, address) | ||||
else: | else: | ||||
for _address in address: | for _address in address: | ||||
_filter += "(%s=%s)" % (recipient_address_attr, _address) | _filter += "(%s=%s)" % (recipient_address_attr, _address) | ||||
_filter += ")" | _filter += ")" | ||||
_filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) | _filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
log.debug(_("Finding resource with filter %r") % (_filter), level=8) | log.debug(_("Finding resource with filter %r") % (_filter), level=8) | ||||
if len(_filter) <= 6: | if len(_filter) <= 6: | ||||
return None | return None | ||||
config_base_dn = self.config_get('resource_base_dn') | config_base_dn = self.config_get('resource_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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
resource_base_dn = ldap_base_dn | resource_base_dn = ldap_base_dn | ||||
else: | else: | ||||
resource_base_dn = config_base_dn | resource_base_dn = config_base_dn | ||||
_results = self.ldap.search_s( | _results = self.ldap.search_s( | ||||
resource_base_dn, | resource_base_dn, | ||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
filterstr=_filter, | filterstr=_filter, | ||||
Show All 13 Lines | 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=9) | ||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is 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()] | ||||
Lint: PEP8 E713 test for membership should be 'not in' Lint: PEP8 E713: test for membership should be 'not in' | |||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
else: | else: | ||||
return [] | return [] | ||||
def recipient_policy(self, entry): | def recipient_policy(self, entry): | ||||
""" | """ | ||||
Apply a recipient policy, if configured. | Apply a recipient policy, if configured. | ||||
Given an entry, returns the entry's attribute values to be set. | Given an entry, returns the entry's attribute values to be set. | ||||
Show All 9 Lines | def recipient_policy(self, entry): | ||||
if len(mail_attributes) >= 1: | if len(mail_attributes) >= 1: | ||||
primary_mail_attribute = mail_attributes[0] | primary_mail_attribute = mail_attributes[0] | ||||
if len(mail_attributes) >= 2: | if len(mail_attributes) >= 2: | ||||
secondary_mail_attribute = mail_attributes[1] | secondary_mail_attribute = mail_attributes[1] | ||||
daemon_rcpt_policy = self.config_get('daemon_rcpt_policy') | daemon_rcpt_policy = self.config_get('daemon_rcpt_policy') | ||||
if not utils.true_or_false(daemon_rcpt_policy) and not daemon_rcpt_policy == None: | if not utils.true_or_false(daemon_rcpt_policy) and not daemon_rcpt_policy == None: | ||||
Lint: PEP8 E501 line too long (90 > 79 characters) Lint: PEP8 E501: line too long (90 > 79 characters) | |||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
log.debug( | log.debug( | ||||
_( | _( | ||||
"Not applying recipient policy for %s " + \ | "Not applying recipient policy for %s " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"(disabled through configuration)" | "(disabled through configuration)" | ||||
) % (entry_dn), | ) % (entry_dn), | ||||
level=1 | level=1 | ||||
) | ) | ||||
return entry_modifications | return entry_modifications | ||||
want_attrs = [] | want_attrs = [] | ||||
log.debug(_("Applying recipient policy to %r") % (entry_dn), level=8) | log.debug(_("Applying recipient policy to %r") % (entry_dn), level=8) | ||||
# See which mail attributes we would want to control. | # See which mail attributes we would want to control. | ||||
# | # | ||||
# 'mail' is considered for primary_mail, | # 'mail' is considered for primary_mail, | ||||
# 'alias' and 'mailalternateaddress' are considered for secondary mail. | # 'alias' and 'mailalternateaddress' are considered for secondary mail. | ||||
# | # | ||||
primary_mail = self.config_get_raw('%s_primary_mail' % (entry_type)) | primary_mail = self.config_get_raw('%s_primary_mail' % (entry_type)) | ||||
if primary_mail == None and entry_type == 'user': | if primary_mail == None and entry_type == 'user': | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
primary_mail = self.config_get_raw('primary_mail') | primary_mail = self.config_get_raw('primary_mail') | ||||
if not secondary_mail_attribute == None: | if not secondary_mail_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
secondary_mail = self.config_get_raw('%s_secondary_mail' % (entry_type)) | secondary_mail = self.config_get_raw('%s_secondary_mail' % (entry_type)) | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
if secondary_mail == None and entry_type == 'user': | if secondary_mail == None and entry_type == 'user': | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
secondary_mail = self.config_get_raw('secondary_mail') | secondary_mail = self.config_get_raw('secondary_mail') | ||||
log.debug( | log.debug( | ||||
_("Using mail attributes: %r, with primary %r and " + \ | _("Using mail attributes: %r, with primary %r and " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"secondary %r") % ( | "secondary %r") % ( | ||||
Lint: PEP8 E127 continuation line over-indented for visual indent Lint: PEP8 E127: continuation line over-indented for visual indent | |||||
mail_attributes, | mail_attributes, | ||||
primary_mail_attribute, | primary_mail_attribute, | ||||
secondary_mail_attribute | secondary_mail_attribute | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
for _mail_attr in mail_attributes: | for _mail_attr in mail_attributes: | ||||
if not entry.has_key(_mail_attr): | if not entry.has_key(_mail_attr): | ||||
log.debug(_("key %r not in entry") % (_mail_attr), level=8) | log.debug(_("key %r not in entry") % (_mail_attr), level=8) | ||||
if _mail_attr == primary_mail_attribute: | if _mail_attr == primary_mail_attribute: | ||||
log.debug(_("key %r is the prim. mail attr.") % (_mail_attr), level=8) | log.debug(_("key %r is the prim. mail attr.") % (_mail_attr), level=8) | ||||
Lint: PEP8 E501 line too long (90 > 79 characters) Lint: PEP8 E501: line too long (90 > 79 characters) | |||||
if not primary_mail == None: | if not primary_mail == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
log.debug(_("prim. mail pol. is not empty"), level=8) | log.debug(_("prim. mail pol. is not empty"), level=8) | ||||
want_attrs.append(_mail_attr) | want_attrs.append(_mail_attr) | ||||
elif _mail_attr == secondary_mail_attribute: | elif _mail_attr == secondary_mail_attribute: | ||||
log.debug(_("key %r is the sec. mail attr.") % (_mail_attr), level=8) | log.debug(_("key %r is the sec. mail attr.") % (_mail_attr), level=8) | ||||
Lint: PEP8 E501 line too long (89 > 79 characters) Lint: PEP8 E501: line too long (89 > 79 characters) | |||||
if not secondary_mail == None: | if not secondary_mail == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
log.debug(_("sec. mail pol. is not empty"), level=8) | log.debug(_("sec. mail pol. is not empty"), level=8) | ||||
want_attrs.append(_mail_attr) | want_attrs.append(_mail_attr) | ||||
if len(want_attrs) > 0: | if len(want_attrs) > 0: | ||||
log.debug(_("Attributes %r are not yet available for entry %r") % ( | log.debug(_("Attributes %r are not yet available for entry %r") % ( | ||||
want_attrs, | want_attrs, | ||||
entry_dn | entry_dn | ||||
), | ), | ||||
Show All 17 Lines | def recipient_policy(self, entry): | ||||
for attribute in attributes.keys(): | for attribute in attributes.keys(): | ||||
entry[attribute] = attributes[attribute] | entry[attribute] = attributes[attribute] | ||||
if not entry.has_key('preferredlanguage'): | if not entry.has_key('preferredlanguage'): | ||||
entry['preferredlanguage'] = conf.get('kolab', 'default_locale') | entry['preferredlanguage'] = conf.get('kolab', 'default_locale') | ||||
# Primary mail address | # Primary mail address | ||||
if not primary_mail == None: | if not primary_mail == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
primary_mail_address = conf.plugins.exec_hook( | primary_mail_address = conf.plugins.exec_hook( | ||||
"set_primary_mail", | "set_primary_mail", | ||||
kw={ | kw={ | ||||
'primary_mail': primary_mail, | 'primary_mail': primary_mail, | ||||
'entry': entry, | 'entry': entry, | ||||
'primary_domain': self.domain | 'primary_domain': self.domain | ||||
} | } | ||||
) | ) | ||||
if primary_mail_address == None: | if primary_mail_address == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return entry_modifications | return entry_modifications | ||||
i = 1 | i = 1 | ||||
_primary_mail = primary_mail_address | _primary_mail = primary_mail_address | ||||
done = False | done = False | ||||
while not done: | while not done: | ||||
results = self.find_recipient(_primary_mail, entry['id']) | results = self.find_recipient(_primary_mail, entry['id']) | ||||
Show All 18 Lines | def recipient_policy(self, entry): | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
almost_done = True | almost_done = True | ||||
for result in results: | for result in results: | ||||
if not result == entry_dn: | if not result == entry_dn: | ||||
log.debug( | log.debug( | ||||
_("Too bad, primary email address %s " + \ | _("Too bad, primary email address %s " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"already in use for %s (we are %s)") % ( | "already in use for %s (we are %s)") % ( | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
_primary_mail, | _primary_mail, | ||||
result, | result, | ||||
entry_dn | entry_dn | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
almost_done = False | almost_done = False | ||||
Show All 9 Lines | def recipient_policy(self, entry): | ||||
primary_mail_address.split('@')[0], | primary_mail_address.split('@')[0], | ||||
i, | i, | ||||
primary_mail_address.split('@')[1] | primary_mail_address.split('@')[1] | ||||
) | ) | ||||
primary_mail_address = _primary_mail | primary_mail_address = _primary_mail | ||||
### | ### | ||||
### FIXME | ### FIXME | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
if not primary_mail_address == None: | if not primary_mail_address == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not entry.has_key(primary_mail_attribute): | if not entry.has_key(primary_mail_attribute): | ||||
self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | ||||
Lint: PEP8 E501 line too long (97 > 79 characters) Lint: PEP8 E501: line too long (97 > 79 characters) | |||||
entry_modifications[primary_mail_attribute] = primary_mail_address | entry_modifications[primary_mail_attribute] = primary_mail_address | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
else: | else: | ||||
if not primary_mail_address == entry[primary_mail_attribute]: | if not primary_mail_address == entry[primary_mail_attribute]: | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | self.set_entry_attribute(entry, primary_mail_attribute, primary_mail_address) | ||||
Lint: PEP8 E501 line too long (101 > 79 characters) Lint: PEP8 E501: line too long (101 > 79 characters) | |||||
entry_modifications[primary_mail_attribute] = primary_mail_address | entry_modifications[primary_mail_attribute] = primary_mail_address | ||||
Lint: PEP8 E501 line too long (90 > 79 characters) Lint: PEP8 E501: line too long (90 > 79 characters) | |||||
if not secondary_mail == None: | if not secondary_mail == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
# Execute the plugin hook | # Execute the plugin hook | ||||
suggested_secondary_mail = conf.plugins.exec_hook( | suggested_secondary_mail = conf.plugins.exec_hook( | ||||
"set_secondary_mail", | "set_secondary_mail", | ||||
kw={ | kw={ | ||||
'secondary_mail': secondary_mail, | 'secondary_mail': secondary_mail, | ||||
'entry': entry, | 'entry': entry, | ||||
'domain': self.domain, | 'domain': self.domain, | ||||
'primary_domain': self.domain, | 'primary_domain': self.domain, | ||||
'secondary_domains': self.list_secondary_domains() | 'secondary_domains': self.list_secondary_domains() | ||||
} | } | ||||
) # end of conf.plugins.exec_hook() call | ) # end of conf.plugins.exec_hook() call | ||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
secondary_mail_addresses = [] | secondary_mail_addresses = [] | ||||
for _secondary_mail in suggested_secondary_mail: | for _secondary_mail in suggested_secondary_mail: | ||||
i = 1 | i = 1 | ||||
__secondary_mail = _secondary_mail | __secondary_mail = _secondary_mail | ||||
done = False | done = False | ||||
while not done: | while not done: | ||||
results = self.find_recipient(__secondary_mail, entry['id']) | results = self.find_recipient(__secondary_mail, entry['id']) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
# Length of results should be 0 (no entry found) | # Length of results should be 0 (no entry found) | ||||
# or 1 (which should be the entry we're looking at here) | # or 1 (which should be the entry we're looking at here) | ||||
if len(results) == 0: | if len(results) == 0: | ||||
log.debug( | log.debug( | ||||
_("No results for address %s found") % ( | _("No results for address %s found") % ( | ||||
__secondary_mail | __secondary_mail | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
done = True | done = True | ||||
continue | continue | ||||
if len(results) == 1: | if len(results) == 1: | ||||
log.debug( | log.debug( | ||||
_("1 result for address %s found, " + \ | _("1 result for address %s found, " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"verifying...") % ( | "verifying...") % ( | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
__secondary_mail | __secondary_mail | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
almost_done = True | almost_done = True | ||||
for result in results: | for result in results: | ||||
if not result == entry_dn: | if not result == entry_dn: | ||||
log.debug( | log.debug( | ||||
_("Too bad, secondary email " + \ | _("Too bad, secondary email " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"address %s already in use for " + \ | "address %s already in use for " + \ | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"%s (we are %s)") % ( | "%s (we are %s)") % ( | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
__secondary_mail, | __secondary_mail, | ||||
result, | result, | ||||
entry_dn | entry_dn | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
almost_done = False | almost_done = False | ||||
else: | else: | ||||
log.debug(_("Address assigned to us"), level=8) | log.debug(_("Address assigned to us"), level=8) | ||||
if almost_done: | if almost_done: | ||||
done = True | done = True | ||||
continue | continue | ||||
i += 1 | i += 1 | ||||
__secondary_mail = "%s%d@%s" % ( | __secondary_mail = "%s%d@%s" % ( | ||||
_secondary_mail.split('@')[0], | _secondary_mail.split('@')[0], | ||||
i, | i, | ||||
_secondary_mail.split('@')[1] | _secondary_mail.split('@')[1] | ||||
) | ) | ||||
secondary_mail_addresses.append(__secondary_mail) | secondary_mail_addresses.append(__secondary_mail) | ||||
log.debug(_("Recipient policy composed the following set of secondary " + \ | log.debug(_("Recipient policy composed the following set of secondary " + \ | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"email addresses: %r") % (secondary_mail_addresses), level=8) | "email addresses: %r") % (secondary_mail_addresses), level=8) | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
if entry.has_key(secondary_mail_attribute): | if entry.has_key(secondary_mail_attribute): | ||||
if isinstance(entry[secondary_mail_attribute], list): | if isinstance(entry[secondary_mail_attribute], list): | ||||
secondary_mail_addresses.extend(entry[secondary_mail_attribute]) | secondary_mail_addresses.extend(entry[secondary_mail_attribute]) | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
else: | else: | ||||
secondary_mail_addresses.append(entry[secondary_mail_attribute]) | secondary_mail_addresses.append(entry[secondary_mail_attribute]) | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
if not secondary_mail_addresses == None: | if not secondary_mail_addresses == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is 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") % ( | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
secondary_mail_addresses | secondary_mail_addresses | ||||
), | ), | ||||
level=9 | level=9 | ||||
) | ) | ||||
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 " + \ | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"address %r in the list of secondary mail " + \ | "address %r in the list of secondary mail " + \ | ||||
Lint: PEP8 E127 continuation line over-indented for visual indent Lint: PEP8 E127: continuation line over-indented for visual indent | |||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"addresses") % (primary_mail_address), | "addresses") % (primary_mail_address), | ||||
level=9 | level=9 | ||||
) | ) | ||||
secondary_mail_addresses.pop( | secondary_mail_addresses.pop( | ||||
secondary_mail_addresses.index(primary_mail_address) | secondary_mail_addresses.index(primary_mail_address) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
) | ) | ||||
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=9 | ||||
) | ) | ||||
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 " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"addresses in %r") % (secondary_mail_attribute), | "addresses in %r") % (secondary_mail_attribute), | ||||
Lint: PEP8 E127 continuation line over-indented for visual indent Lint: PEP8 E127: continuation line over-indented for visual indent | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
level=9 | level=9 | ||||
) | ) | ||||
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 | ||||
) | ) | ||||
entry_modifications[secondary_mail_attribute] = secondary_mail_addresses | entry_modifications[secondary_mail_attribute] = secondary_mail_addresses | ||||
Lint: PEP8 E501 line too long (96 > 79 characters) Lint: PEP8 E501: line too long (96 > 79 characters) | |||||
else: | else: | ||||
if isinstance(entry[secondary_mail_attribute], basestring): | if isinstance(entry[secondary_mail_attribute], basestring): | ||||
entry[secondary_mail_attribute] = [entry[secondary_mail_attribute]] | entry[secondary_mail_attribute] = [entry[secondary_mail_attribute]] | ||||
Lint: PEP8 E501 line too long (91 > 79 characters) Lint: PEP8 E501: line too long (91 > 79 characters) | |||||
log.debug(_("secondary_mail_addresses: %r") % (secondary_mail_addresses), level=8) | log.debug(_("secondary_mail_addresses: %r") % (secondary_mail_addresses), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
log.debug(_("entry[%s]: %r") % (secondary_mail_attribute,entry[secondary_mail_attribute]), level=8) | log.debug(_("entry[%s]: %r") % (secondary_mail_attribute,entry[secondary_mail_attribute]), level=8) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E501 line too long (119 > 79 characters) Lint: PEP8 E501: line too long (119 > 79 characters) | |||||
secondary_mail_addresses.sort() | secondary_mail_addresses.sort() | ||||
entry[secondary_mail_attribute].sort() | entry[secondary_mail_attribute].sort() | ||||
log.debug(_("secondary_mail_addresses: %r") % (secondary_mail_addresses), level=8) | log.debug(_("secondary_mail_addresses: %r") % (secondary_mail_addresses), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
log.debug(_("entry[%s]: %r") % (secondary_mail_attribute,entry[secondary_mail_attribute]), level=8) | log.debug(_("entry[%s]: %r") % (secondary_mail_attribute,entry[secondary_mail_attribute]), level=8) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E501 line too long (119 > 79 characters) Lint: PEP8 E501: line too long (119 > 79 characters) | |||||
if not list(set(secondary_mail_addresses)) == list(set(entry[secondary_mail_attribute])): | if not list(set(secondary_mail_addresses)) == list(set(entry[secondary_mail_attribute])): | ||||
Lint: PEP8 E501 line too long (109 > 79 characters) Lint: PEP8 E501: line too long (109 > 79 characters) | |||||
self.set_entry_attribute( | self.set_entry_attribute( | ||||
entry, | entry, | ||||
secondary_mail_attribute, | secondary_mail_attribute, | ||||
list(set(secondary_mail_addresses)) | list(set(secondary_mail_addresses)) | ||||
) | ) | ||||
entry_modifications[secondary_mail_attribute] = list(set(secondary_mail_addresses)) | entry_modifications[secondary_mail_attribute] = list(set(secondary_mail_addresses)) | ||||
Lint: PEP8 E501 line too long (107 > 79 characters) Lint: PEP8 E501: line too long (107 > 79 characters) | |||||
log.debug(_("Entry modifications list: %r") % (entry_modifications), level=8) | log.debug(_("Entry modifications list: %r") % (entry_modifications), level=8) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
return entry_modifications | return entry_modifications | ||||
def reconnect(self): | def reconnect(self): | ||||
bind = self.bind | bind = self.bind | ||||
self._disconnect() | self._disconnect() | ||||
self.connect() | self.connect() | ||||
if bind is not None: | if bind is not None: | ||||
self._bind(bind['dn'], bind['pw']) | self._bind(bind['dn'], bind['pw']) | ||||
def search_entry_by_attribute(self, attr, value, **kw): | def search_entry_by_attribute(self, attr, value, **kw): | ||||
self._bind() | self._bind() | ||||
_filter = "(%s=%s)" % (attr, ldap.filter.escape_filter_chars(value)) | _filter = "(%s=%s)" % (attr, ldap.filter.escape_filter_chars(value)) | ||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
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( | return self._search( | ||||
base_dn, | base_dn, | ||||
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): | ||||
Lint: PEP8 E303 too many blank lines (2) Lint: PEP8 E303: too many blank lines (2) | |||||
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=9) | ||||
Lint: PEP8 E501 line too long (103 > 79 characters) Lint: PEP8 E501: line too long (103 > 79 characters) | |||||
self.set_entry_attributes(entry_id, { attribute: value }) | self.set_entry_attributes(entry_id, { attribute: value }) | ||||
Lint: PEP8 E201 whitespace after '{' Lint: PEP8 E201: whitespace after '{' | |||||
Lint: PEP8 E202 whitespace before '}' Lint: PEP8 E202: whitespace before '}' | |||||
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, ['*']) | ||||
attrs = {} | attrs = {} | ||||
for attribute in attributes.keys(): | for attribute in attributes.keys(): | ||||
attrs[attribute.lower()] = attributes[attribute] | attrs[attribute.lower()] = attributes[attribute] | ||||
modlist = [] | modlist = [] | ||||
for attribute in attrs.keys(): | for attribute in attrs.keys(): | ||||
if not entry.has_key(attribute): | if not entry.has_key(attribute): | ||||
entry[attribute] = self.get_entry_attribute(entry_id, attribute) | entry[attribute] = self.get_entry_attribute(entry_id, attribute) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
for attribute in attrs.keys(): | for attribute in attrs.keys(): | ||||
if entry.has_key(attribute) and entry[attribute] == None: | if entry.has_key(attribute) and entry[attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
modlist.append((ldap.MOD_ADD, attribute, attrs[attribute])) | modlist.append((ldap.MOD_ADD, attribute, attrs[attribute])) | ||||
elif entry.has_key(attribute) and not entry[attribute] == None: | elif entry.has_key(attribute) and not entry[attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if attrs[attribute] == None: | if attrs[attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
modlist.append((ldap.MOD_DELETE, attribute, entry[attribute])) | modlist.append((ldap.MOD_DELETE, attribute, entry[attribute])) | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
else: | else: | ||||
modlist.append((ldap.MOD_REPLACE, attribute, attrs[attribute])) | modlist.append((ldap.MOD_REPLACE, attribute, attrs[attribute])) | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
dn = entry_dn | dn = entry_dn | ||||
if len(modlist) > 0: | if len(modlist) > 0: | ||||
try: | try: | ||||
self.ldap.modify_s(dn, modlist) | self.ldap.modify_s(dn, modlist) | ||||
except: | except: | ||||
log.error(_("Could not update dn %r:\n%r") % (dn, modlist)) | log.error(_("Could not update dn %r:\n%r") % (dn, modlist)) | ||||
def synchronize(self, mode=0, callback=None): | def synchronize(self, mode=0, callback=None): | ||||
""" | """ | ||||
Synchronize with LDAP | Synchronize with LDAP | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
_filter = self._kolab_filter() | _filter = self._kolab_filter() | ||||
modified_after = None | modified_after = None | ||||
if hasattr(conf, 'resync'): | if hasattr(conf, 'resync'): | ||||
if not conf.resync: | if not conf.resync: | ||||
modified_after = self.get_latest_sync_timestamp() | modified_after = self.get_latest_sync_timestamp() | ||||
else: | else: | ||||
modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format') | modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format') | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if modifytimestamp_format == None: | if modifytimestamp_format == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is 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) | ||||
Lint: PEP8 E501 line too long (109 > 79 characters) Lint: PEP8 E501: line too long (109 > 79 characters) | |||||
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) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
log.debug(_("Using filter %r") % (_filter), level=8) | log.debug(_("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) | ||||
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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
log.debug(_("Synchronization is searching against base DN: %s") % (base_dn), level=8) | log.debug(_("Synchronization is searching against base DN: %s") % (base_dn), level=8) | ||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
if callback == None: | if callback == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
callback = self._synchronize_callback | callback = self._synchronize_callback | ||||
try: | try: | ||||
self._search( | self._search( | ||||
base_dn, | base_dn, | ||||
filterstr=_filter, | filterstr=_filter, | ||||
attrlist=[ | attrlist=[ | ||||
'*', | '*', | ||||
self.config_get('unique_attribute'), | self.config_get('unique_attribute'), | ||||
conf.get('cyrus-sasl', 'result_attribute'), | conf.get('cyrus-sasl', 'result_attribute'), | ||||
'modifytimestamp' | 'modifytimestamp' | ||||
], | ], | ||||
override_search=override_search, | override_search=override_search, | ||||
callback=callback, | callback=callback, | ||||
) | ) | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.error("An error occurred: %r" % (errmsg)) | log.error("An error occurred: %r" % (errmsg)) | ||||
log.error(_("%s") % (traceback.format_exc())) | log.error(_("%s") % (traceback.format_exc())) | ||||
def user_quota(self, entry_id, folder): | def user_quota(self, entry_id, folder): | ||||
default_quota = self.config_get('default_quota') | default_quota = self.config_get('default_quota') | ||||
quota_attribute = self.config_get('quota_attribute') | quota_attribute = self.config_get('quota_attribute') | ||||
if quota_attribute == None: | if quota_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return | return | ||||
# The default quota may be None, but LDAP quota could still be set | # The default quota may be None, but LDAP quota could still be set | ||||
if default_quota == None: | if default_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
default_quota = 0 | default_quota = 0 | ||||
self._bind() | self._bind() | ||||
entry_dn = self.entry_dn(entry_id) | entry_dn = self.entry_dn(entry_id) | ||||
current_ldap_quota = self.get_entry_attribute(entry_dn, quota_attribute) | current_ldap_quota = self.get_entry_attribute(entry_dn, quota_attribute) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
_imap_quota = self.imap.get_quota(folder) | _imap_quota = self.imap.get_quota(folder) | ||||
if _imap_quota == None: | if _imap_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
used = None | used = None | ||||
current_imap_quota = None | current_imap_quota = None | ||||
else: | else: | ||||
(used, current_imap_quota) = _imap_quota | (used, current_imap_quota) = _imap_quota | ||||
log.debug( | log.debug( | ||||
_("About to consider the user quota for %r (used: %r, " + \ | _("About to consider the user quota for %r (used: %r, " + \ | ||||
Lint: PEP8 E502 the backslash is redundant between brackets Lint: PEP8 E502: the backslash is redundant between brackets | |||||
"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=9 | ||||
) | ) | ||||
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 | ||||
} | } | ||||
) | ) | ||||
try: | try: | ||||
current_ldap_quota = (int)(current_ldap_quota) | current_ldap_quota = (int)(current_ldap_quota) | ||||
except: | except: | ||||
current_ldap_quota = None | current_ldap_quota = None | ||||
if not current_ldap_quota == None: | if not current_ldap_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not new_quota == (int)(current_ldap_quota): | if not new_quota == (int)(current_ldap_quota): | ||||
self.set_entry_attribute( | self.set_entry_attribute( | ||||
entry_dn, | entry_dn, | ||||
quota_attribute, | quota_attribute, | ||||
"%s" % (new_quota) | "%s" % (new_quota) | ||||
) | ) | ||||
else: | else: | ||||
if not new_quota == None: | if not new_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.set_entry_attribute( | self.set_entry_attribute( | ||||
entry_dn, | entry_dn, | ||||
quota_attribute, | quota_attribute, | ||||
"%s" % (new_quota) | "%s" % (new_quota) | ||||
) | ) | ||||
if not current_imap_quota == None: | if not current_imap_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not new_quota == current_imap_quota: | if not new_quota == current_imap_quota: | ||||
self.imap.set_quota(folder, new_quota) | self.imap.set_quota(folder, new_quota) | ||||
else: | else: | ||||
if not new_quota == None: | if not new_quota == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.set_quota(folder, new_quota) | self.imap.set_quota(folder, new_quota) | ||||
### | ### | ||||
### API depth level increasing! | ### API depth level increasing! | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
def _bind(self, bind_dn=None, bind_pw=None): | def _bind(self, bind_dn=None, bind_pw=None): | ||||
if self.ldap == None: | if self.ldap == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.connect() | self.connect() | ||||
if self.bind is None or bind_dn is None: | if self.bind is None or bind_dn is None: | ||||
if bind_dn is None: | if bind_dn is None: | ||||
bind_dn = self.config_get('bind_dn') | bind_dn = self.config_get('bind_dn') | ||||
if bind_pw is None: | if bind_pw is None: | ||||
bind_pw = self.config_get('bind_pw') | bind_pw = self.config_get('bind_pw') | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def _change_add_sharedfolder(self, entry, change): | ||||
server = None | server = None | ||||
# Get some configuration values | # Get some configuration values | ||||
mailserver_attribute = self.config_get('mailserver_attribute') | mailserver_attribute = self.config_get('mailserver_attribute') | ||||
if entry.has_key(mailserver_attribute): | if entry.has_key(mailserver_attribute): | ||||
server = entry[mailserver_attribute] | server = entry[mailserver_attribute] | ||||
foldertype_attribute = self.config_get('sharedfolder_type_attribute') | foldertype_attribute = self.config_get('sharedfolder_type_attribute') | ||||
if not foldertype_attribute == None: | if not foldertype_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not entry.has_key(foldertype_attribute): | if not entry.has_key(foldertype_attribute): | ||||
entry[foldertype_attribute] = self.get_entry_attribute( | entry[foldertype_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
foldertype_attribute | foldertype_attribute | ||||
) | ) | ||||
if not entry[foldertype_attribute] == None: | if not entry[foldertype_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
entry['kolabfoldertype'] = entry[foldertype_attribute] | entry['kolabfoldertype'] = entry[foldertype_attribute] | ||||
if not entry.has_key('kolabfoldertype'): | if not entry.has_key('kolabfoldertype'): | ||||
entry['kolabfoldertype'] = self.get_entry_attribute( | entry['kolabfoldertype'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
'kolabfoldertype' | 'kolabfoldertype' | ||||
) | ) | ||||
# A delivery address is postuser+targetfolder | # A delivery address is postuser+targetfolder | ||||
delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
if delivery_address_attribute == None: | if delivery_address_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
delivery_address_attribute = 'mail' | delivery_address_attribute = 'mail' | ||||
if not entry.has_key(delivery_address_attribute): | if not entry.has_key(delivery_address_attribute): | ||||
entry[delivery_address_attribute] = self.get_entry_attribute( | entry[delivery_address_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
delivery_address_attribute | delivery_address_attribute | ||||
) | ) | ||||
if not entry[delivery_address_attribute] == None: | if not entry[delivery_address_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if len(entry[delivery_address_attribute].split('+')) > 1: | if len(entry[delivery_address_attribute].split('+')) > 1: | ||||
entry['kolabtargetfolder'] = entry[delivery_address_attribute].split('+')[1] | entry['kolabtargetfolder'] = entry[delivery_address_attribute].split('+')[1] | ||||
Lint: PEP8 E501 line too long (92 > 79 characters) Lint: PEP8 E501: line too long (92 > 79 characters) | |||||
if not entry.has_key('kolabtargetfolder'): | if not entry.has_key('kolabtargetfolder'): | ||||
entry['kolabtargetfolder'] = self.get_entry_attribute( | entry['kolabtargetfolder'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
'kolabtargetfolder' | 'kolabtargetfolder' | ||||
) | ) | ||||
if entry.has_key('kolabtargetfolder') and \ | if entry.has_key('kolabtargetfolder') and \ | ||||
not entry['kolabtargetfolder'] == None: | not entry['kolabtargetfolder'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folder_path = entry['kolabtargetfolder'] | folder_path = entry['kolabtargetfolder'] | ||||
else: | else: | ||||
# TODO: What is *the* way to see if we need to create an @domain | # TODO: What is *the* way to see if we need to create an @domain | ||||
# shared mailbox? | # shared mailbox? | ||||
# TODO^2: self.domain, really? Presumes any mail attribute is | # TODO^2: self.domain, really? Presumes any mail attribute is | ||||
# set to the primary domain name space... | # set to the primary domain name space... | ||||
# TODO^3: Test if the cn is already something@domain | # TODO^3: Test if the cn is already something@domain | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute in ['mail']: | if result_attribute in ['mail']: | ||||
folder_path = "%s@%s" % (entry['cn'], self.domain) | folder_path = "%s@%s" % (entry['cn'], self.domain) | ||||
else: | else: | ||||
folder_path = entry['cn'] | folder_path = entry['cn'] | ||||
if not folder_path.startswith('shared/'): | if not folder_path.startswith('shared/'): | ||||
folder_path = "shared/%s" % folder_path | folder_path = "shared/%s" % folder_path | ||||
folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute') | folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute') | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if folderacl_entry_attribute == None: | if folderacl_entry_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folderacl_entry_attribute = 'acl' | folderacl_entry_attribute = 'acl' | ||||
if not entry.has_key(folderacl_entry_attribute): | if not entry.has_key(folderacl_entry_attribute): | ||||
entry[folderacl_entry_attribute] = self.get_entry_attribute( | entry[folderacl_entry_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
folderacl_entry_attribute | folderacl_entry_attribute | ||||
) | ) | ||||
if not entry[folderacl_entry_attribute] == None: | if not entry[folderacl_entry_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
# Parse it before assigning it | # Parse it before assigning it | ||||
entry['kolabfolderaclentry'] = [] | entry['kolabfolderaclentry'] = [] | ||||
if not isinstance(entry[folderacl_entry_attribute], list): | if not isinstance(entry[folderacl_entry_attribute], list): | ||||
entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ] | entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
for acl_entry in entry[folderacl_entry_attribute]: | for acl_entry in entry[folderacl_entry_attribute]: | ||||
acl_access = acl_entry.split()[-1] | acl_access = acl_entry.split()[-1] | ||||
if len(acl_entry.split(', ')) > 1: | if len(acl_entry.split(', ')) > 1: | ||||
aci_subject = ', '.join(acl_entry.split(', ')[:-1]) | aci_subject = ', '.join(acl_entry.split(', ')[:-1]) | ||||
else: | else: | ||||
aci_subject = acl_entry.split()[0] | aci_subject = acl_entry.split()[0] | ||||
log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
access_lookup_dict = { | access_lookup_dict = { | ||||
'all': 'lrsedntxakcpiw', | 'all': 'lrsedntxakcpiw', | ||||
'append': 'wip', | 'append': 'wip', | ||||
'full': 'lrswipkxtecdn', | 'full': 'lrswipkxtecdn', | ||||
'read': 'lrs', | 'read': 'lrs', | ||||
'read-only': 'lrs', | 'read-only': 'lrs', | ||||
'read-write': 'lrswitedn', | 'read-write': 'lrswitedn', | ||||
'post': 'p', | 'post': 'p', | ||||
'semi-full': 'lrswit', | 'semi-full': 'lrswit', | ||||
'write': 'lrswite', | 'write': 'lrswite', | ||||
} | } | ||||
if access_lookup_dict.has_key(acl_access): | if access_lookup_dict.has_key(acl_access): | ||||
acl_access = access_lookup_dict[acl_access] | acl_access = access_lookup_dict[acl_access] | ||||
log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access)) | entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access)) | ||||
Lint: PEP8 E501 line too long (108 > 79 characters) Lint: PEP8 E501: line too long (108 > 79 characters) | |||||
if not self.imap.shared_folder_exists(folder_path): | if not self.imap.shared_folder_exists(folder_path): | ||||
self.imap.shared_folder_create(folder_path, server) | self.imap.shared_folder_create(folder_path, server) | ||||
self.imap.set_acl(folder_path, 'anyone', '') | self.imap.set_acl(folder_path, 'anyone', '') | ||||
if entry.has_key('kolabfoldertype') and \ | if entry.has_key('kolabfoldertype') and \ | ||||
not entry['kolabfoldertype'] == None: | not entry['kolabfoldertype'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.shared_folder_set_type( | self.imap.shared_folder_set_type( | ||||
folder_path, | folder_path, | ||||
entry['kolabfoldertype'] | entry['kolabfoldertype'] | ||||
) | ) | ||||
if entry.has_key('kolabfolderaclentry') and \ | if entry.has_key('kolabfolderaclentry') and \ | ||||
not entry['kolabfolderaclentry'] == None: | not entry['kolabfolderaclentry'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap._set_kolab_mailfolder_acls( | self.imap._set_kolab_mailfolder_acls( | ||||
entry['kolabfolderaclentry'] | entry['kolabfolderaclentry'] | ||||
) | ) | ||||
if entry.has_key(delivery_address_attribute) and \ | if entry.has_key(delivery_address_attribute) and \ | ||||
not entry[delivery_address_attribute] == None: | not entry[delivery_address_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.set_acl(folder_path, 'anyone', '+p') | self.imap.set_acl(folder_path, 'anyone', '+p') | ||||
#if server == None: | #if server == None: | ||||
Lint: PEP8 E265 block comment should start with '# ' Lint: PEP8 E265: block comment should start with '# ' | |||||
#self.entry_set_attribute(mailserver_attribute, server) | #self.entry_set_attribute(mailserver_attribute, server) | ||||
Lint: PEP8 E265 block comment should start with '# ' Lint: PEP8 E265: block comment should start with '# ' | |||||
def _change_add_unknown(self, entry, change): | def _change_add_unknown(self, entry, change): | ||||
""" | """ | ||||
An entry has been add, and we do not know of what object type | An entry has been add, and we do not know of what object type | ||||
the entry was - user, group, role or sharedfolder. | the entry was - user, group, role or sharedfolder. | ||||
""" | """ | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return None | return None | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return None | return None | ||||
for _type in ['user','group','role','sharedfolder']: | for _type in ['user','group','role','sharedfolder']: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
try: | try: | ||||
eval("self._change_add_%s(entry, change)" % (_type)) | eval("self._change_add_%s(entry, change)" % (_type)) | ||||
success = True | success = True | ||||
except: | except: | ||||
success = False | success = False | ||||
if success: | if success: | ||||
break | break | ||||
def _change_add_user(self, entry, change): | def _change_add_user(self, entry, change): | ||||
""" | """ | ||||
An entry of type user was added. | An entry of type user was added. | ||||
""" | """ | ||||
mailserver_attribute = self.config_get('mailserver_attribute') | mailserver_attribute = self.config_get('mailserver_attribute') | ||||
if mailserver_attribute == None: | if mailserver_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
mailserver_attribute = 'mailhost' | mailserver_attribute = 'mailhost' | ||||
mailserver_attribute = mailserver_attribute.lower() | mailserver_attribute = mailserver_attribute.lower() | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute == None: | if result_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
result_attribute = 'mail' | result_attribute = 'mail' | ||||
result_attribute = result_attribute.lower() | result_attribute = result_attribute.lower() | ||||
if not entry.has_key(mailserver_attribute): | if not entry.has_key(mailserver_attribute): | ||||
entry[mailserver_attribute] = \ | entry[mailserver_attribute] = \ | ||||
self.get_entry_attribute(entry, mailserver_attribute) | self.get_entry_attribute(entry, mailserver_attribute) | ||||
rcpt_addrs = self.recipient_policy(entry) | rcpt_addrs = self.recipient_policy(entry) | ||||
for key in rcpt_addrs: | for key in rcpt_addrs: | ||||
entry[key] = rcpt_addrs[key] | entry[key] = rcpt_addrs[key] | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return | return | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return | return | ||||
if entry[result_attribute] == '': | if entry[result_attribute] == '': | ||||
return | return | ||||
cache.get_entry(self.domain, entry) | cache.get_entry(self.domain, entry) | ||||
self.imap.connect(domain=self.domain) | self.imap.connect(domain=self.domain) | ||||
if not self.imap.user_mailbox_exists(entry[result_attribute].lower()): | if not self.imap.user_mailbox_exists(entry[result_attribute].lower()): | ||||
folder = self.imap.user_mailbox_create( | folder = self.imap.user_mailbox_create( | ||||
entry[result_attribute], | entry[result_attribute], | ||||
entry[mailserver_attribute] | entry[mailserver_attribute] | ||||
) | ) | ||||
else: | else: | ||||
folder = "user%s%s" % (self.imap.get_separator(),entry[result_attribute].lower()) | folder = "user%s%s" % (self.imap.get_separator(),entry[result_attribute].lower()) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
server = self.imap.user_mailbox_server(folder) | server = self.imap.user_mailbox_server(folder) | ||||
log.debug( | log.debug( | ||||
_("Entry %s attribute value: %r") % ( | _("Entry %s attribute value: %r") % ( | ||||
mailserver_attribute, | mailserver_attribute, | ||||
entry[mailserver_attribute] | entry[mailserver_attribute] | ||||
), | ), | ||||
Show All 18 Lines | def _change_delete_group(self, entry, change): | ||||
An entry of type group was deleted. | An entry of type group was deleted. | ||||
""" | """ | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return None | return None | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return None | return None | ||||
self.imap.cleanup_acls(entry[result_attribute]) | self.imap.cleanup_acls(entry[result_attribute]) | ||||
def _change_delete_None(self, entry, change): | def _change_delete_None(self, entry, change): | ||||
Lint: PEP8 E303 too many blank lines (2) Lint: PEP8 E303: too many blank lines (2) | |||||
""" | """ | ||||
Redirect to _change_delete_unknown | Redirect to _change_delete_unknown | ||||
""" | """ | ||||
self._change_delete_unknown(entry, change) | self._change_delete_unknown(entry, change) | ||||
def _change_delete_resource(self, entry, change): | def _change_delete_resource(self, entry, change): | ||||
pass | pass | ||||
def _change_delete_role(self, entry, change): | def _change_delete_role(self, entry, change): | ||||
pass | pass | ||||
def _change_delete_sharedfolder(self, entry, change): | def _change_delete_sharedfolder(self, entry, change): | ||||
pass | pass | ||||
def _change_delete_unknown(self, entry, change): | def _change_delete_unknown(self, entry, change): | ||||
""" | """ | ||||
An entry has been deleted, and we do not know of what object type | An entry has been deleted, and we do not know of what object type | ||||
the entry was - user, group, resource, role or sharedfolder. | the entry was - user, group, resource, role or sharedfolder. | ||||
""" | """ | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return None | return None | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return None | return None | ||||
success = True | success = True | ||||
for _type in ['user','group','resource','role','sharedfolder']: | for _type in ['user','group','resource','role','sharedfolder']: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
try: | try: | ||||
success = eval("self._change_delete_%s(entry, change)" % (_type)) | success = eval("self._change_delete_%s(entry, change)" % (_type)) | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
except Exception, errmsg: | except Exception, errmsg: | ||||
log.error(_("An error occured: %r") % (errmsg)) | log.error(_("An error occured: %r") % (errmsg)) | ||||
log.error(_("%s") % (traceback.format_exc())) | log.error(_("%s") % (traceback.format_exc())) | ||||
success = False | success = False | ||||
if success: | if success: | ||||
break | break | ||||
def _change_delete_user(self, entry, change): | def _change_delete_user(self, entry, change): | ||||
""" | """ | ||||
An entry of type user was deleted. | An entry of type user was deleted. | ||||
""" | """ | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return None | return None | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return None | return None | ||||
cache.delete_entry(self.domain, entry) | cache.delete_entry(self.domain, entry) | ||||
self.imap.user_mailbox_delete(entry[result_attribute]) | self.imap.user_mailbox_delete(entry[result_attribute]) | ||||
self.imap.cleanup_acls(entry[result_attribute]) | self.imap.cleanup_acls(entry[result_attribute]) | ||||
# let plugins act upon this deletion | # let plugins act upon this deletion | ||||
conf.plugins.exec_hook( | conf.plugins.exec_hook( | ||||
'user_delete', | 'user_delete', | ||||
kw = { | kw = { | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
'user': entry, | 'user': entry, | ||||
'domain': self.domain | 'domain': self.domain | ||||
} | } | ||||
) | ) | ||||
def _change_moddn_group(self, entry, change): | def _change_moddn_group(self, entry, change): | ||||
# TODO: If the rdn attribute is the same as the result attribute... | # TODO: If the rdn attribute is the same as the result attribute... | ||||
pass | pass | ||||
Show All 9 Lines | def _change_moddn_user(self, entry, change): | ||||
old_rdn = ldap.dn.explode_dn(old_dn)[0].split('=')[0] | old_rdn = ldap.dn.explode_dn(old_dn)[0].split('=')[0] | ||||
new_rdn = ldap.dn.explode_dn(new_dn)[0].split('=')[0] | new_rdn = ldap.dn.explode_dn(new_dn)[0].split('=')[0] | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
old_canon_attr = None | old_canon_attr = None | ||||
cache_entry = cache.get_entry(self.domain, entry) | cache_entry = cache.get_entry(self.domain, entry) | ||||
if not cache_entry == None: | if not cache_entry == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
old_canon_attr = cache_entry.result_attribute | old_canon_attr = cache_entry.result_attribute | ||||
# See if we have to trigger the recipient policy. Only really applies to | # See if we have to trigger the recipient policy. Only really applies to | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
# situations in which the result_attribute is used in the old or in the | # situations in which the result_attribute is used in the old or in the | ||||
# new DN. | # new DN. | ||||
trigger_recipient_policy = False | trigger_recipient_policy = False | ||||
if old_rdn == result_attribute: | if old_rdn == result_attribute: | ||||
if new_rdn == result_attribute: | if new_rdn == result_attribute: | ||||
if new_rdn == old_rdn: | if new_rdn == old_rdn: | ||||
trigger_recipient_policy = True | trigger_recipient_policy = True | ||||
Show All 9 Lines | def _change_moddn_user(self, entry, change): | ||||
entry_changes = self.recipient_policy(entry) | entry_changes = self.recipient_policy(entry) | ||||
for key in entry_changes.keys(): | for key in entry_changes.keys(): | ||||
entry[key] = entry_changes[key] | entry[key] = entry_changes[key] | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
return | return | ||||
if entry[result_attribute] == None: | if entry[result_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return | return | ||||
if entry[result_attribute] == '': | if entry[result_attribute] == '': | ||||
return | return | ||||
# Now look at entry_changes and old_canon_attr, and see if they're | # Now look at entry_changes and old_canon_attr, and see if they're | ||||
# the same value. | # the same value. | ||||
if entry_changes.has_key(result_attribute): | if entry_changes.has_key(result_attribute): | ||||
if not old_canon_attr == None: | if not old_canon_attr == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.user_mailbox_create( | self.imap.user_mailbox_create( | ||||
entry_changes[result_attribute] | entry_changes[result_attribute] | ||||
) | ) | ||||
elif not entry_changes[result_attribute] == old_canon_attr: | elif not entry_changes[result_attribute] == old_canon_attr: | ||||
self.imap.user_mailbox_rename( | self.imap.user_mailbox_rename( | ||||
old_canon_attr, | old_canon_attr, | ||||
entry_changes[result_attribute] | entry_changes[result_attribute] | ||||
Show All 22 Lines | def _change_modify_sharedfolder(self, entry, change): | ||||
server = None | server = None | ||||
# Get some configuration values | # Get some configuration values | ||||
mailserver_attribute = self.config_get('mailserver_attribute') | mailserver_attribute = self.config_get('mailserver_attribute') | ||||
if entry.has_key(mailserver_attribute): | if entry.has_key(mailserver_attribute): | ||||
server = entry[mailserver_attribute] | server = entry[mailserver_attribute] | ||||
foldertype_attribute = self.config_get('sharedfolder_type_attribute') | foldertype_attribute = self.config_get('sharedfolder_type_attribute') | ||||
if not foldertype_attribute == None: | if not foldertype_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not entry.has_key(foldertype_attribute): | if not entry.has_key(foldertype_attribute): | ||||
entry[foldertype_attribute] = self.get_entry_attribute( | entry[foldertype_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
foldertype_attribute | foldertype_attribute | ||||
) | ) | ||||
if not entry[foldertype_attribute] == None: | if not entry[foldertype_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
entry['kolabfoldertype'] = entry[foldertype_attribute] | entry['kolabfoldertype'] = entry[foldertype_attribute] | ||||
if not entry.has_key('kolabfoldertype'): | if not entry.has_key('kolabfoldertype'): | ||||
entry['kolabfoldertype'] = self.get_entry_attribute( | entry['kolabfoldertype'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
'kolabfoldertype' | 'kolabfoldertype' | ||||
) | ) | ||||
# A delivery address is postuser+targetfolder | # A delivery address is postuser+targetfolder | ||||
delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
if not delivery_address_attribute == None: | if not delivery_address_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not entry.has_key(delivery_address_attribute): | if not entry.has_key(delivery_address_attribute): | ||||
entry[delivery_address_attribute] = self.get_entry_attribute( | entry[delivery_address_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
delivery_address_attribute | delivery_address_attribute | ||||
) | ) | ||||
if not entry[delivery_address_attribute] == None: | if not entry[delivery_address_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if len(entry[delivery_address_attribute].split('+')) > 1: | if len(entry[delivery_address_attribute].split('+')) > 1: | ||||
entry['kolabtargetfolder'] = entry[delivery_address_attribute].split('+')[1] | entry['kolabtargetfolder'] = entry[delivery_address_attribute].split('+')[1] | ||||
Lint: PEP8 E501 line too long (96 > 79 characters) Lint: PEP8 E501: line too long (96 > 79 characters) | |||||
if not entry.has_key('kolabtargetfolder'): | if not entry.has_key('kolabtargetfolder'): | ||||
entry['kolabtargetfolder'] = self.get_entry_attribute( | entry['kolabtargetfolder'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
'kolabtargetfolder' | 'kolabtargetfolder' | ||||
) | ) | ||||
if entry.has_key('kolabtargetfolder') and \ | if entry.has_key('kolabtargetfolder') and \ | ||||
not entry['kolabtargetfolder'] == None: | not entry['kolabtargetfolder'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folder_path = entry['kolabtargetfolder'] | folder_path = entry['kolabtargetfolder'] | ||||
else: | else: | ||||
# TODO: What is *the* way to see if we need to create an @domain | # TODO: What is *the* way to see if we need to create an @domain | ||||
# shared mailbox? | # shared mailbox? | ||||
# TODO^2: self.domain, really? Presumes any mail attribute is | # TODO^2: self.domain, really? Presumes any mail attribute is | ||||
# set to the primary domain name space... | # set to the primary domain name space... | ||||
# TODO^3: Test if the cn is already something@domain | # TODO^3: Test if the cn is already something@domain | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute in ['mail']: | if result_attribute in ['mail']: | ||||
folder_path = "%s@%s" % (entry['cn'], self.domain) | folder_path = "%s@%s" % (entry['cn'], self.domain) | ||||
else: | else: | ||||
folder_path = entry['cn'] | folder_path = entry['cn'] | ||||
if not folder_path.startswith('shared/'): | if not folder_path.startswith('shared/'): | ||||
folder_path = "shared/%s" % folder_path | folder_path = "shared/%s" % folder_path | ||||
folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute') | folderacl_entry_attribute = self.config_get('sharedfolder_acl_entry_attribute') | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if folderacl_entry_attribute == None: | if folderacl_entry_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folderacl_entry_attribute = 'acl' | folderacl_entry_attribute = 'acl' | ||||
if not entry.has_key(folderacl_entry_attribute): | if not entry.has_key(folderacl_entry_attribute): | ||||
entry[folderacl_entry_attribute] = self.get_entry_attribute( | entry[folderacl_entry_attribute] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
folderacl_entry_attribute | folderacl_entry_attribute | ||||
) | ) | ||||
if not entry[folderacl_entry_attribute] == None: | if not entry[folderacl_entry_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
# Parse it before assigning it | # Parse it before assigning it | ||||
entry['kolabfolderaclentry'] = [] | entry['kolabfolderaclentry'] = [] | ||||
if not isinstance(entry[folderacl_entry_attribute], list): | if not isinstance(entry[folderacl_entry_attribute], list): | ||||
entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ] | entry[folderacl_entry_attribute] = [ entry[folderacl_entry_attribute] ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
for acl_entry in entry[folderacl_entry_attribute]: | for acl_entry in entry[folderacl_entry_attribute]: | ||||
acl_access = acl_entry.split()[-1] | acl_access = acl_entry.split()[-1] | ||||
if len(acl_entry.split(', ')) > 1: | if len(acl_entry.split(', ')) > 1: | ||||
aci_subject = ', '.join(acl_entry.split(', ')[:-1]) | aci_subject = ', '.join(acl_entry.split(', ')[:-1]) | ||||
else: | else: | ||||
aci_subject = acl_entry.split()[0] | aci_subject = acl_entry.split()[0] | ||||
log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
access_lookup_dict = { | access_lookup_dict = { | ||||
'all': 'lrsedntxakcpiw', | 'all': 'lrsedntxakcpiw', | ||||
'append': 'wip', | 'append': 'wip', | ||||
'full': 'lrswipkxtecdn', | 'full': 'lrswipkxtecdn', | ||||
'read': 'lrs', | 'read': 'lrs', | ||||
'read-only': 'lrs', | 'read-only': 'lrs', | ||||
'read-write': 'lrswitedn', | 'read-write': 'lrswitedn', | ||||
'post': 'p', | 'post': 'p', | ||||
'semi-full': 'lrswit', | 'semi-full': 'lrswit', | ||||
'write': 'lrswite', | 'write': 'lrswite', | ||||
} | } | ||||
if access_lookup_dict.has_key(acl_access): | if access_lookup_dict.has_key(acl_access): | ||||
acl_access = access_lookup_dict[acl_access] | acl_access = access_lookup_dict[acl_access] | ||||
log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | log.debug(_("Found a subject %r with access %r") % (aci_subject, acl_access), level=8) | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access)) | entry['kolabfolderaclentry'].append("(%r, %r, %r)" % (folder_path, aci_subject, acl_access)) | ||||
Lint: PEP8 E501 line too long (108 > 79 characters) Lint: PEP8 E501: line too long (108 > 79 characters) | |||||
if not self.imap.shared_folder_exists(folder_path): | if not self.imap.shared_folder_exists(folder_path): | ||||
self.imap.shared_folder_create(folder_path, server) | self.imap.shared_folder_create(folder_path, server) | ||||
self.imap.set_acl(folder_path, 'anyone', '') | self.imap.set_acl(folder_path, 'anyone', '') | ||||
if entry.has_key('kolabfoldertype') and \ | if entry.has_key('kolabfoldertype') and \ | ||||
not entry['kolabfoldertype'] == None: | not entry['kolabfoldertype'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.shared_folder_set_type( | self.imap.shared_folder_set_type( | ||||
folder_path, | folder_path, | ||||
entry['kolabfoldertype'] | entry['kolabfoldertype'] | ||||
) | ) | ||||
if entry.has_key('kolabfolderaclentry') and \ | if entry.has_key('kolabfolderaclentry') and \ | ||||
not entry['kolabfolderaclentry'] == None: | not entry['kolabfolderaclentry'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap._set_kolab_mailfolder_acls( | self.imap._set_kolab_mailfolder_acls( | ||||
entry['kolabfolderaclentry'] | entry['kolabfolderaclentry'] | ||||
) | ) | ||||
if entry.has_key(delivery_address_attribute) and \ | if entry.has_key(delivery_address_attribute) and \ | ||||
not entry[delivery_address_attribute] == None: | not entry[delivery_address_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.set_acl(folder_path, 'anyone', '+p') | self.imap.set_acl(folder_path, 'anyone', '+p') | ||||
def _change_modify_user(self, entry, change): | def _change_modify_user(self, entry, change): | ||||
""" | """ | ||||
Handle the changes for an object of type user. | Handle the changes for an object of type user. | ||||
Expects the new entry. | Expects the new entry. | ||||
""" | """ | ||||
# Initialize old_canon_attr (#1701) | # Initialize old_canon_attr (#1701) | ||||
old_canon_attr = None | old_canon_attr = None | ||||
result_attribute = conf.get('cyrus-sasl','result_attribute') | result_attribute = conf.get('cyrus-sasl','result_attribute') | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
_entry = cache.get_entry(self.domain, entry, update=False) | _entry = cache.get_entry(self.domain, entry, update=False) | ||||
# We do not necessarily have a synchronisation cache entry (#1701) | # We do not necessarily have a synchronisation cache entry (#1701) | ||||
if not _entry == None: | if not _entry == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if _entry.__dict__.has_key('result_attribute') and not _entry.result_attribute == '': | if _entry.__dict__.has_key('result_attribute') and not _entry.result_attribute == '': | ||||
Lint: PEP8 E501 line too long (97 > 79 characters) Lint: PEP8 E501: line too long (97 > 79 characters) | |||||
old_canon_attr = _entry.result_attribute | old_canon_attr = _entry.result_attribute | ||||
entry_changes = self.recipient_policy(entry) | entry_changes = self.recipient_policy(entry) | ||||
log.debug( | log.debug( | ||||
_("Result from recipient policy: %r") % (entry_changes), | _("Result from recipient policy: %r") % (entry_changes), | ||||
level=8 | level=8 | ||||
) | ) | ||||
if entry_changes.has_key(result_attribute): | if entry_changes.has_key(result_attribute): | ||||
if not entry_changes[result_attribute] == old_canon_attr: | if not entry_changes[result_attribute] == old_canon_attr: | ||||
if old_canon_attr == None: | if old_canon_attr == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.user_mailbox_create( | self.imap.user_mailbox_create( | ||||
entry_changes[result_attribute] | entry_changes[result_attribute] | ||||
) | ) | ||||
else: | else: | ||||
self.imap.user_mailbox_rename( | self.imap.user_mailbox_rename( | ||||
old_canon_attr, | old_canon_attr, | ||||
entry_changes[result_attribute] | entry_changes[result_attribute] | ||||
) | ) | ||||
entry[result_attribute] = entry_changes[result_attribute] | entry[result_attribute] = entry_changes[result_attribute] | ||||
cache.get_entry(self.domain, entry) | cache.get_entry(self.domain, entry) | ||||
elif entry.has_key(result_attribute): | elif entry.has_key(result_attribute): | ||||
if not entry[result_attribute] == old_canon_attr: | if not entry[result_attribute] == old_canon_attr: | ||||
if old_canon_attr == None: | if old_canon_attr == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.user_mailbox_create( | self.imap.user_mailbox_create( | ||||
entry[result_attribute] | entry[result_attribute] | ||||
) | ) | ||||
else: | else: | ||||
self.imap.user_mailbox_rename( | self.imap.user_mailbox_rename( | ||||
old_canon_attr, | old_canon_attr, | ||||
entry[result_attribute] | entry[result_attribute] | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | def _change_none_sharedfolder(self, entry, change): | ||||
) | ) | ||||
if not entry.has_key('kolabfoldertype'): | if not entry.has_key('kolabfoldertype'): | ||||
entry['kolabfoldertype'] = self.get_entry_attribute( | entry['kolabfoldertype'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
'kolabfoldertype' | 'kolabfoldertype' | ||||
) | ) | ||||
folderacl_entry_attribute = conf.get('ldap', 'sharedfolder_acl_entry_attribute') | folderacl_entry_attribute = conf.get('ldap', 'sharedfolder_acl_entry_attribute') | ||||
Lint: PEP8 E501 line too long (88 > 79 characters) Lint: PEP8 E501: line too long (88 > 79 characters) | |||||
if folderacl_entry_attribute == None: | if folderacl_entry_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folderacl_entry_attribute = 'acl' | folderacl_entry_attribute = 'acl' | ||||
if not entry.has_key(folderacl_entry_attribute): | if not entry.has_key(folderacl_entry_attribute): | ||||
entry['kolabfolderaclentry'] = self.get_entry_attribute( | entry['kolabfolderaclentry'] = self.get_entry_attribute( | ||||
entry['id'], | entry['id'], | ||||
folderacl_entry_attribute | folderacl_entry_attribute | ||||
) | ) | ||||
else: | else: | ||||
entry['kolabfolderaclentry'] = entry[folderacl_entry_attribute] | entry['kolabfolderaclentry'] = entry[folderacl_entry_attribute] | ||||
del entry[folderacl_entry_attribute] | del entry[folderacl_entry_attribute] | ||||
if entry.has_key('kolabtargetfolder') and \ | if entry.has_key('kolabtargetfolder') and \ | ||||
not entry['kolabtargetfolder'] == None: | not entry['kolabtargetfolder'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
folder_path = entry['kolabtargetfolder'] | folder_path = entry['kolabtargetfolder'] | ||||
else: | else: | ||||
# TODO: What is *the* way to see if we need to create an @domain | # TODO: What is *the* way to see if we need to create an @domain | ||||
# shared mailbox? | # shared mailbox? | ||||
# TODO^2: self.domain, really? Presumes any mail attribute is | # TODO^2: self.domain, really? Presumes any mail attribute is | ||||
# set to the primary domain name space... | # set to the primary domain name space... | ||||
# TODO^3: Test if the cn is already something@domain | # TODO^3: Test if the cn is already something@domain | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute in ['mail']: | if result_attribute in ['mail']: | ||||
folder_path = "%s@%s" % (entry['cn'], self.domain) | folder_path = "%s@%s" % (entry['cn'], self.domain) | ||||
else: | else: | ||||
folder_path = entry['cn'] | folder_path = entry['cn'] | ||||
if not folder_path.startswith('shared/'): | if not folder_path.startswith('shared/'): | ||||
folder_path = "shared/%s" % folder_path | folder_path = "shared/%s" % folder_path | ||||
if not self.imap.shared_folder_exists(folder_path): | if not self.imap.shared_folder_exists(folder_path): | ||||
self.imap.shared_folder_create(folder_path, server) | self.imap.shared_folder_create(folder_path, server) | ||||
if entry.has_key('kolabfoldertype') and \ | if entry.has_key('kolabfoldertype') and \ | ||||
not entry['kolabfoldertype'] == None: | not entry['kolabfoldertype'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.shared_folder_set_type( | self.imap.shared_folder_set_type( | ||||
folder_path, | folder_path, | ||||
entry['kolabfoldertype'] | entry['kolabfoldertype'] | ||||
) | ) | ||||
if entry.has_key('kolabfolderaclentry') and \ | if entry.has_key('kolabfolderaclentry') and \ | ||||
not entry['kolabfolderaclentry'] == None: | not entry['kolabfolderaclentry'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if isinstance(entry['kolabfolderaclentry'], basestring): | if isinstance(entry['kolabfolderaclentry'], basestring): | ||||
entry['kolabfolderaclentry'] = [ entry['kolabfolderaclentry'] ] | entry['kolabfolderaclentry'] = [ entry['kolabfolderaclentry'] ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
import copy | import copy | ||||
_acls = copy.deepcopy(entry['kolabfolderaclentry']) | _acls = copy.deepcopy(entry['kolabfolderaclentry']) | ||||
entry['kolabfolderaclentry'] = [] | entry['kolabfolderaclentry'] = [] | ||||
for _entry in _acls: | for _entry in _acls: | ||||
if _entry[0] == "(": | if _entry[0] == "(": | ||||
entry['kolabfolderaclentry'].append(_entry) | entry['kolabfolderaclentry'].append(_entry) | ||||
continue | continue | ||||
s,r = [x.strip() for x in _entry.split(',')] | s,r = [x.strip() for x in _entry.split(',')] | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
entry['kolabfolderaclentry'].append("('%s', '%s', '%s')" % (folder_path, s, r)) | entry['kolabfolderaclentry'].append("('%s', '%s', '%s')" % (folder_path, s, r)) | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
self.imap._set_kolab_mailfolder_acls( | self.imap._set_kolab_mailfolder_acls( | ||||
entry['kolabfolderaclentry'] | entry['kolabfolderaclentry'] | ||||
) | ) | ||||
elif entry['kolabfolderaclentry'] in [None,[]]: | elif entry['kolabfolderaclentry'] in [None,[]]: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
for ace in self.imap.list_acls(folder_path): | for ace in self.imap.list_acls(folder_path): | ||||
aci_subject = ace.split()[0] | aci_subject = ace.split()[0] | ||||
self.imap.set_acl(folder_path, aci_subject, '') | self.imap.set_acl(folder_path, aci_subject, '') | ||||
delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | delivery_address_attribute = self.config_get('sharedfolder_delivery_address_attribute') | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
if entry.has_key(delivery_address_attribute) and \ | if entry.has_key(delivery_address_attribute) and \ | ||||
not entry[delivery_address_attribute] == None: | not entry[delivery_address_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
self.imap.set_acl(folder_path, 'anyone', '+p') | self.imap.set_acl(folder_path, 'anyone', '+p') | ||||
#if server == None: | #if server == None: | ||||
Lint: PEP8 E265 block comment should start with '# ' Lint: PEP8 E265: block comment should start with '# ' | |||||
#self.entry_set_attribute(mailserver_attribute, server) | #self.entry_set_attribute(mailserver_attribute, server) | ||||
Lint: PEP8 E265 block comment should start with '# ' Lint: PEP8 E265: block comment should start with '# ' | |||||
def _change_none_user(self, entry, change): | def _change_none_user(self, entry, change): | ||||
""" | """ | ||||
A user entry as part of the initial search result set. | A user entry as part of the initial search result set. | ||||
""" | """ | ||||
mailserver_attribute = self.config_get('mailserver_attribute') | mailserver_attribute = self.config_get('mailserver_attribute') | ||||
if mailserver_attribute == None: | if mailserver_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
mailserver_attribute = 'mailhost' | mailserver_attribute = 'mailhost' | ||||
mailserver_attribute = mailserver_attribute.lower() | mailserver_attribute = mailserver_attribute.lower() | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute == None: | if result_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
result_attribute = 'mail' | result_attribute = 'mail' | ||||
result_attribute = result_attribute.lower() | result_attribute = result_attribute.lower() | ||||
old_canon_attr = None | old_canon_attr = None | ||||
_entry = cache.get_entry(self.domain, entry, update=False) | _entry = cache.get_entry(self.domain, entry, update=False) | ||||
if not _entry == None and _entry.__dict__.has_key('result_attribute') and not _entry.result_attribute == '': | if not _entry == None and _entry.__dict__.has_key('result_attribute') and not _entry.result_attribute == '': | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
Lint: PEP8 E501 line too long (116 > 79 characters) Lint: PEP8 E501: line too long (116 > 79 characters) | |||||
old_canon_attr = _entry.result_attribute | old_canon_attr = _entry.result_attribute | ||||
entry_changes = self.recipient_policy(entry) | entry_changes = self.recipient_policy(entry) | ||||
if entry.has_key(result_attribute) and entry_changes.has_key(result_attribute): | if entry.has_key(result_attribute) and entry_changes.has_key(result_attribute): | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if not entry[result_attribute] == entry_changes[result_attribute]: | if not entry[result_attribute] == entry_changes[result_attribute]: | ||||
old_canon_attr = entry[result_attribute] | old_canon_attr = entry[result_attribute] | ||||
log.debug( | log.debug( | ||||
_("Result from recipient policy: %r") % (entry_changes), | _("Result from recipient policy: %r") % (entry_changes), | ||||
level=8 | level=8 | ||||
) | ) | ||||
if entry_changes.has_key(result_attribute) and not old_canon_attr == None: | if entry_changes.has_key(result_attribute) and not old_canon_attr == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
if not entry_changes[result_attribute] == old_canon_attr: | if not entry_changes[result_attribute] == old_canon_attr: | ||||
self.imap.user_mailbox_rename( | self.imap.user_mailbox_rename( | ||||
old_canon_attr, | old_canon_attr, | ||||
entry_changes[result_attribute] | entry_changes[result_attribute] | ||||
) | ) | ||||
for key in entry_changes.keys(): | for key in entry_changes.keys(): | ||||
entry[key] = entry_changes[key] | entry[key] = entry_changes[key] | ||||
self.set_entry_attribute(entry, key, entry[key]) | self.set_entry_attribute(entry, key, entry[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) | ||||
server = None | server = None | ||||
if not entry.has_key(mailserver_attribute): | if not entry.has_key(mailserver_attribute): | ||||
entry[mailserver_attribute] = self.get_entry_attribute(entry, mailserver_attribute) | entry[mailserver_attribute] = self.get_entry_attribute(entry, mailserver_attribute) | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
if entry[mailserver_attribute] == "" or entry[mailserver_attribute] == None: | if entry[mailserver_attribute] == "" or entry[mailserver_attribute] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
server = None | server = None | ||||
else: | else: | ||||
server = entry[mailserver_attribute].lower() | server = entry[mailserver_attribute].lower() | ||||
if entry.has_key(result_attribute) and \ | if entry.has_key(result_attribute) and \ | ||||
not entry.has_key(result_attribute) == None: | not entry.has_key(result_attribute) == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not self.imap.user_mailbox_exists(entry[result_attribute]): | if not self.imap.user_mailbox_exists(entry[result_attribute]): | ||||
folder = self.imap.user_mailbox_create(entry[result_attribute], server=server) | folder = self.imap.user_mailbox_create(entry[result_attribute], server=server) | ||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
server = self.imap.user_mailbox_server(folder) | server = self.imap.user_mailbox_server(folder) | ||||
else: | else: | ||||
folder = "user%s%s" % ( | folder = "user%s%s" % ( | ||||
self.imap.get_separator(), | self.imap.get_separator(), | ||||
entry[result_attribute] | entry[result_attribute] | ||||
) | ) | ||||
server = self.imap.user_mailbox_server(folder) | server = self.imap.user_mailbox_server(folder) | ||||
Show All 26 Lines | 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'] | naming_contexts = attrs['namingcontexts'] | ||||
if isinstance(naming_contexts, basestring): | if isinstance(naming_contexts, basestring): | ||||
naming_contexts = [ naming_contexts ] | naming_contexts = [ naming_contexts ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
log.debug( | log.debug( | ||||
_("Naming contexts found: %r") % (naming_contexts), | _("Naming contexts found: %r") % (naming_contexts), | ||||
level=8 | level=8 | ||||
) | ) | ||||
self._kolab_domain_root_dn(domain) | self._kolab_domain_root_dn(domain) | ||||
log.debug( | log.debug( | ||||
_("Domains/Root DNs found: %r") % ( | _("Domains/Root DNs found: %r") % ( | ||||
self.domain_rootdns | self.domain_rootdns | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
# If we have a 1:1 match, continue as planned | # If we have a 1:1 match, continue as planned | ||||
for naming_context in naming_contexts: | for naming_context in naming_contexts: | ||||
if domain in self.domain_rootdns: | |||||
if self.domain_rootdns[domain].endswith(naming_context): | if self.domain_rootdns[domain].endswith(naming_context): | ||||
return naming_context | return naming_context | ||||
def _primary_domain_for_naming_context(self, naming_context): | def _primary_domain_for_naming_context(self, naming_context): | ||||
self._bind() | self._bind() | ||||
_domain = '.'.join(naming_context.split(',dc='))[3:] | _domain = '.'.join(naming_context.split(',dc='))[3:] | ||||
_naming_context = self._kolab_domain_root_dn(_domain) | _naming_context = self._kolab_domain_root_dn(_domain) | ||||
Show All 39 Lines | def _entry_type(self, entry_id): | ||||
""" | """ | ||||
self._bind() | self._bind() | ||||
entry_dn = self.entry_dn(entry_id) | entry_dn = self.entry_dn(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: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
base_dn = ldap_base_dn | base_dn = ldap_base_dn | ||||
else: | else: | ||||
base_dn = config_base_dn | base_dn = config_base_dn | ||||
for _type in ['user', 'group', 'sharedfolder']: | for _type in ['user', 'group', 'sharedfolder']: | ||||
__filter = self.config_get('kolab_%s_filter' % (_type)) | __filter = self.config_get('kolab_%s_filter' % (_type)) | ||||
if __filter == None: | if __filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
__filter = self.config_get('%s_filter' % (_type)) | __filter = self.config_get('%s_filter' % (_type)) | ||||
if not __filter == None: | if not __filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
try: | try: | ||||
result = self._regular_search(entry_dn, filterstr=__filter) | result = self._regular_search(entry_dn, filterstr=__filter) | ||||
except: | except: | ||||
result = self._regular_search( | result = self._regular_search( | ||||
base_dn, | base_dn, | ||||
filterstr="(%s=%s)" %( | filterstr="(%s=%s)" %( | ||||
Lint: PEP8 E225 missing whitespace around operator Lint: PEP8 E225: missing whitespace around operator | |||||
self.config_get('unique_attribute'), | self.config_get('unique_attribute'), | ||||
entry_id['id']) | entry_id['id']) | ||||
) | ) | ||||
if not result: | if not result: | ||||
continue | continue | ||||
else: | else: | ||||
return _type | return _type | ||||
def _find_user_dn(self, login, kolabuser=False): | def _find_user_dn(self, login, kolabuser=False): | ||||
""" | """ | ||||
Find the distinguished name (DN) for a (Kolab) user entry in LDAP. | Find the distinguished name (DN) for a (Kolab) user entry in LDAP. | ||||
""" | """ | ||||
conf_prefix = 'kolab_' if kolabuser else '' | conf_prefix = 'kolab_' if kolabuser else '' | ||||
domain_root_dn = self._kolab_domain_root_dn(self.domain) | domain_root_dn = self._kolab_domain_root_dn(self.domain) | ||||
user_base_dn = self.config_get(conf_prefix + 'user_base_dn') | user_base_dn = self.config_get(conf_prefix + 'user_base_dn') | ||||
if user_base_dn == None: | if user_base_dn == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
user_base_dn = self.config_get('base_dn') | user_base_dn = self.config_get('base_dn') | ||||
auth_attrs = self.config_get_list('auth_attributes') | auth_attrs = self.config_get_list('auth_attributes') | ||||
auth_search_filter = [ '(|' ] | auth_search_filter = [ '(|' ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
for auth_attr in auth_attrs: | for auth_attr in auth_attrs: | ||||
auth_search_filter.append('(%s=%s)' % (auth_attr,login)) | auth_search_filter.append('(%s=%s)' % (auth_attr,login)) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
if not '@' in login: | if not '@' in login: | ||||
Lint: PEP8 E713 test for membership should be 'not in' Lint: PEP8 E713: test for membership should be 'not in' | |||||
auth_search_filter.append( | auth_search_filter.append( | ||||
'(%s=%s@%s)' % ( | '(%s=%s@%s)' % ( | ||||
auth_attr, | auth_attr, | ||||
login, | login, | ||||
self.domain | self.domain | ||||
) | ) | ||||
) | ) | ||||
auth_search_filter.append(')') | auth_search_filter.append(')') | ||||
auth_search_filter = ''.join(auth_search_filter) | auth_search_filter = ''.join(auth_search_filter) | ||||
user_filter = self.config_get(conf_prefix + 'user_filter') | user_filter = self.config_get(conf_prefix + 'user_filter') | ||||
search_filter = "(&%s%s)" % ( | search_filter = "(&%s%s)" % ( | ||||
auth_search_filter, | auth_search_filter, | ||||
user_filter | user_filter | ||||
) | ) | ||||
_results = self._search( | _results = self._search( | ||||
user_base_dn, | user_base_dn, | ||||
filterstr=search_filter, | filterstr=search_filter, | ||||
attrlist=[ 'dn' ], | attrlist=[ 'dn' ], | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
override_search='_regular_search' | override_search='_regular_search' | ||||
) | ) | ||||
if len(_results) == 1: | if len(_results) == 1: | ||||
(_user_dn, _user_attrs) = _results[0] | (_user_dn, _user_attrs) = _results[0] | ||||
else: | else: | ||||
# Retry to find the user_dn with just uid=%s against the root_dn, | # Retry to find the user_dn with just uid=%s against the root_dn, | ||||
# if the login is not fully qualified | # if the login is not fully qualified | ||||
if len(login.split('@')) < 2: | if len(login.split('@')) < 2: | ||||
search_filter = "(uid=%s)" % (login) | search_filter = "(uid=%s)" % (login) | ||||
_results = self._search( | _results = self._search( | ||||
domain, | domain, | ||||
filterstr=search_filter, | filterstr=search_filter, | ||||
attrlist=[ 'dn' ] | attrlist=[ 'dn' ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
) | ) | ||||
if len(_results) == 1: | if len(_results) == 1: | ||||
(_user_dn, _user_attrs) = _results[0] | (_user_dn, _user_attrs) = _results[0] | ||||
else: | else: | ||||
# Overall fail | # Overall fail | ||||
return False | return False | ||||
else: | else: | ||||
return False | return False | ||||
return _user_dn | return _user_dn | ||||
def _kolab_domain_root_dn(self, domain): | def _kolab_domain_root_dn(self, domain): | ||||
log.debug(_("Searching root dn for domain %r") % (domain), level=8) | log.debug(_("Searching root dn for domain %r") % (domain), level=8) | ||||
if not hasattr(self, 'domain_rootdns'): | if not hasattr(self, 'domain_rootdns'): | ||||
self.domain_rootdns = {} | self.domain_rootdns = {} | ||||
if self.domain_rootdns.has_key(domain): | if self.domain_rootdns.has_key(domain): | ||||
log.debug(_("Returning from cache: %r") % (self.domain_rootdns[domain]), level=8) | log.debug(_("Returning from cache: %r") % (self.domain_rootdns[domain]), level=8) | ||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
return self.domain_rootdns[domain] | return self.domain_rootdns[domain] | ||||
self._bind() | self._bind() | ||||
log.debug(_("Finding domain root dn for domain %s") % (domain), level=8) | log.debug(_("Finding domain root dn for domain %s") % (domain), level=8) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
domain_base_dn = conf.get('ldap', 'domain_base_dn', quiet=True) | domain_base_dn = conf.get('ldap', 'domain_base_dn', quiet=True) | ||||
domain_filter = conf.get('ldap', 'domain_filter') | domain_filter = conf.get('ldap', 'domain_filter') | ||||
if not domain_filter == None: | if not domain_filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
if not domain == None: | if not domain == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
domain_filter = domain_filter.replace('*', domain) | domain_filter = domain_filter.replace('*', domain) | ||||
if not domain_base_dn == "": | if not domain_base_dn == "": | ||||
_results = self._search( | _results = self._search( | ||||
domain_base_dn, | domain_base_dn, | ||||
ldap.SCOPE_SUBTREE, | ldap.SCOPE_SUBTREE, | ||||
domain_filter, | domain_filter, | ||||
override_search='_regular_search' | override_search='_regular_search' | ||||
) | ) | ||||
domains = [] | domains = [] | ||||
for _domain in _results: | for _domain in _results: | ||||
(domain_dn, _domain_attrs) = _domain | (domain_dn, _domain_attrs) = _domain | ||||
domain_rootdn_attribute = conf.get( | domain_rootdn_attribute = conf.get( | ||||
'ldap', | 'ldap', | ||||
'domain_rootdn_attribute' | 'domain_rootdn_attribute' | ||||
) | ) | ||||
_domain_attrs = utils.normalize(_domain_attrs) | _domain_attrs = utils.normalize(_domain_attrs) | ||||
if _domain_attrs.has_key(domain_rootdn_attribute): | if _domain_attrs.has_key(domain_rootdn_attribute): | ||||
log.debug(_("Setting domain root dn from LDAP for domain %r: %r") % (domain, _domain_attrs[domain_rootdn_attribute]), level=8) | log.debug(_("Setting domain root dn from LDAP for domain %r: %r") % (domain, _domain_attrs[domain_rootdn_attribute]), level=8) | ||||
Lint: PEP8 E501 line too long (150 > 79 characters) Lint: PEP8 E501: line too long (150 > 79 characters) | |||||
self.domain_rootdns[domain] = _domain_attrs[domain_rootdn_attribute] | self.domain_rootdns[domain] = _domain_attrs[domain_rootdn_attribute] | ||||
Lint: PEP8 E501 line too long (92 > 79 characters) Lint: PEP8 E501: line too long (92 > 79 characters) | |||||
return _domain_attrs[domain_rootdn_attribute] | return _domain_attrs[domain_rootdn_attribute] | ||||
else: | else: | ||||
domain_name_attribute = self.config_get('domain_name_attribute') | domain_name_attribute = self.config_get('domain_name_attribute') | ||||
Lint: PEP8 E501 line too long (88 > 79 characters) Lint: PEP8 E501: line too long (88 > 79 characters) | |||||
if domain_name_attribute == None: | if domain_name_attribute == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
domain_name_attribute = 'associateddomain' | domain_name_attribute = 'associateddomain' | ||||
if isinstance(_domain_attrs[domain_name_attribute], list): | if isinstance(_domain_attrs[domain_name_attribute], list): | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
domain = _domain_attrs[domain_name_attribute][0] | domain = _domain_attrs[domain_name_attribute][0] | ||||
else: | else: | ||||
domain = _domain_attrs[domain_name_attribute] | domain = _domain_attrs[domain_name_attribute] | ||||
else: | else: | ||||
if conf.has_option('ldap', 'base_dn'): | if conf.has_option('ldap', 'base_dn'): | ||||
return conf.get('ldap', 'base_dn') | return conf.get('ldap', 'base_dn') | ||||
self.domain_rootdns[domain] = utils.standard_root_dn(domain) | self.domain_rootdns[domain] = utils.standard_root_dn(domain) | ||||
return self.domain_rootdns[domain] | return self.domain_rootdns[domain] | ||||
def _kolab_filter(self): | def _kolab_filter(self): | ||||
""" | """ | ||||
Compose a filter using the relevant settings from configuration. | Compose a filter using the relevant settings from configuration. | ||||
""" | """ | ||||
_filter = "(|" | _filter = "(|" | ||||
for _type in ['user', 'group', 'resource', 'sharedfolder']: | for _type in ['user', 'group', 'resource', 'sharedfolder']: | ||||
__filter = self.config_get('kolab_%s_filter' % (_type)) | __filter = self.config_get('kolab_%s_filter' % (_type)) | ||||
if __filter == None: | if __filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
__filter = self.config_get('%s_filter' % (_type)) | __filter = self.config_get('%s_filter' % (_type)) | ||||
if not __filter == None: | if not __filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
_filter = "%s%s" % (_filter,__filter) | _filter = "%s%s" % (_filter,__filter) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
_filter = "%s)" % (_filter) | _filter = "%s)" % (_filter) | ||||
return _filter | return _filter | ||||
def _list_domains(self, domain=None): | def _list_domains(self, domain=None): | ||||
""" | """ | ||||
Find the domains related to this Kolab setup, and return a list of | Find the domains related to this Kolab setup, and return a list of | ||||
DNS domain names. | DNS domain names. | ||||
Returns a list of tuples, each tuple containing the primary domain | Returns a list of tuples, each tuple containing the primary domain | ||||
name and a list of secondary domain names. | name and a list of secondary domain names. | ||||
This function should only be called by the primary instance of Auth. | This function should only be called by the primary instance of Auth. | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
""" | """ | ||||
log.debug(_("Listing domains..."), level=8) | log.debug(_("Listing domains..."), level=8) | ||||
self.connect() | self.connect() | ||||
self._bind() | self._bind() | ||||
domain_base_dn = conf.get('ldap', 'domain_base_dn', quiet=True) | domain_base_dn = conf.get('ldap', 'domain_base_dn', quiet=True) | ||||
if domain_base_dn == "": | if domain_base_dn == "": | ||||
# No domains are to be found in LDAP, return an empty list. | # No domains are to be found in LDAP, return an empty list. | ||||
# Note that the Auth() base itself handles this case. | # Note that the Auth() base itself handles this case. | ||||
return [] | return [] | ||||
# If we haven't returned already, let's continue searching | # If we haven't returned already, let's continue searching | ||||
domain_filter = conf.get('ldap', 'domain_filter') | domain_filter = conf.get('ldap', 'domain_filter') | ||||
if not domain == None: | if not domain == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
domain_filter = domain_filter.replace('*', domain) | domain_filter = domain_filter.replace('*', domain) | ||||
if domain_base_dn == None or domain_filter == None: | if domain_base_dn == None or domain_filter == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
return [] | return [] | ||||
dna = self.config_get('domain_name_attribute') | dna = self.config_get('domain_name_attribute') | ||||
if dna == None: | if dna == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
dna = 'associateddomain' | dna = 'associateddomain' | ||||
try: | try: | ||||
_search = self._search( | _search = self._search( | ||||
domain_base_dn, | domain_base_dn, | ||||
ldap.SCOPE_SUBTREE, | ldap.SCOPE_SUBTREE, | ||||
domain_filter, | domain_filter, | ||||
# TODO: Where we use associateddomain is actually | # TODO: Where we use associateddomain is actually | ||||
# configurable | # configurable | ||||
[ dna ], | [ dna ], | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
override_search='_regular_search' | override_search='_regular_search' | ||||
) | ) | ||||
except: | except: | ||||
return [] | return [] | ||||
domains = [] | domains = [] | ||||
for domain_dn, domain_attrs in _search: | for domain_dn, domain_attrs in _search: | ||||
primary_domain = None | primary_domain = None | ||||
secondary_domains = [] | secondary_domains = [] | ||||
domain_attrs = utils.normalize(domain_attrs) | domain_attrs = utils.normalize(domain_attrs) | ||||
# TODO: Where we use associateddomain is actually configurable | # TODO: Where we use associateddomain is actually configurable | ||||
if type(domain_attrs[dna]) == list: | if type(domain_attrs[dna]) == list: | ||||
primary_domain = domain_attrs[dna].pop(0).lower() | primary_domain = domain_attrs[dna].pop(0).lower() | ||||
secondary_domains = [x.lower() for x in domain_attrs[dna]] | secondary_domains = [x.lower() for x in domain_attrs[dna]] | ||||
else: | else: | ||||
primary_domain = domain_attrs[dna].lower() | primary_domain = domain_attrs[dna].lower() | ||||
domains.append((primary_domain,secondary_domains)) | domains.append((primary_domain,secondary_domains)) | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
return domains | return domains | ||||
def _synchronize_callback(self, *args, **kw): | def _synchronize_callback(self, *args, **kw): | ||||
""" | """ | ||||
Determine the characteristics of the callback being placed, and | Determine the characteristics of the callback being placed, and | ||||
what data is contained within *args and **kw exactly. | what data is contained within *args and **kw exactly. | ||||
Show All 28 Lines | def _synchronize_callback(self, *args, **kw): | ||||
try: | try: | ||||
entry['type'] = self._entry_type(entry) | entry['type'] = self._entry_type(entry) | ||||
except: | except: | ||||
entry['type'] = None | entry['type'] = None | ||||
log.debug(_("Entry type: %s") % (entry['type']), level=8) | log.debug(_("Entry type: %s") % (entry['type']), level=8) | ||||
if change_dict['change_type'] == None: | if change_dict['change_type'] == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
# This entry was in the start result set | # This entry was in the start result set | ||||
eval("self._change_none_%s(entry, change_dict)" % (entry['type'])) | eval("self._change_none_%s(entry, change_dict)" % (entry['type'])) | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
else: | else: | ||||
if isinstance(change_dict['change_type'], int): | if isinstance(change_dict['change_type'], int): | ||||
change = psearch.CHANGE_TYPES_STR[change_dict['change_type']] | change = psearch.CHANGE_TYPES_STR[change_dict['change_type']] | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
change = change.lower() | change = change.lower() | ||||
else: | else: | ||||
change = change_dict['change_type'] | change = change_dict['change_type'] | ||||
# See if we can find the cache entry - this way we can get to | # See if we can find the cache entry - this way we can get to | ||||
# the value of a (former, on a deleted entry) result_attribute | # the value of a (former, on a deleted entry) result_attribute | ||||
result_attribute = conf.get('cyrus-sasl', 'result_attribute') | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if not entry.has_key(result_attribute): | if not entry.has_key(result_attribute): | ||||
cache_entry = cache.get_entry(self.domain, entry, update=False) | cache_entry = cache.get_entry(self.domain, entry, update=False) | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
if hasattr(cache_entry, 'result_attribute') and change == 'delete': | if hasattr(cache_entry, 'result_attribute') and change == 'delete': | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
entry[result_attribute] = cache_entry.result_attribute | entry[result_attribute] = cache_entry.result_attribute | ||||
eval( | eval( | ||||
"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): | ||||
for entry_dn,entry_attrs in kw['entry']: | for entry_dn,entry_attrs in kw['entry']: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
# This is a referral | # This is a referral | ||||
if entry_dn == None: | if entry_dn == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
continue | continue | ||||
entry = { 'dn': entry_dn } | entry = { 'dn': entry_dn } | ||||
Lint: PEP8 E201 whitespace after '{' Lint: PEP8 E201: whitespace after '{' | |||||
Lint: PEP8 E202 whitespace before '}' Lint: PEP8 E202: whitespace before '}' | |||||
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') | ||||
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: %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=9) | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
# | # | ||||
# 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) | ||||
# | # | ||||
# if not self.imap.user_mailbox_exists(entry[result_attribute]): | # if not self.imap.user_mailbox_exists(entry[result_attribute]): | ||||
# folder = self.imap.user_mailbox_create( | # folder = self.imap.user_mailbox_create( | ||||
# entry[result_attribute] | # entry[result_attribute] | ||||
# ) | # ) | ||||
# | # | ||||
# server = self.imap.user_mailbox_server(folder) | # server = self.imap.user_mailbox_server(folder) | ||||
def _unbind(self): | def _unbind(self): | ||||
""" | """ | ||||
Discard the current set of bind credentials. | Discard the current set of bind credentials. | ||||
Virtually disconnects the LDAP connection, and should be followed by | Virtually disconnects the LDAP connection, and should be followed by | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
a call to _bind() afterwards. | a call to _bind() afterwards. | ||||
""" | """ | ||||
self.ldap.unbind() | self.ldap.unbind() | ||||
self.bind = None | self.bind = None | ||||
### | ### | ||||
### Backend search functions | ### Backend search functions | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### | ### | ||||
def _persistent_search(self, | def _persistent_search(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
_results = [] | _results = [] | ||||
psearch_server_controls = [] | psearch_server_controls = [] | ||||
psearch_server_controls.append(psearch.PersistentSearchControl( | psearch_server_controls.append(psearch.PersistentSearchControl( | ||||
criticality=True, | criticality=True, | ||||
changeTypes=[ 'add', 'delete', 'modify', 'modDN' ], | changeTypes=[ 'add', 'delete', 'modify', 'modDN' ], | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
changesOnly=False, | changesOnly=False, | ||||
returnECs=True | returnECs=True | ||||
) | ) | ||||
) | ) | ||||
_search = self.ldap.search_ext( | _search = self.ldap.search_ext( | ||||
base_dn, | base_dn, | ||||
scope=scope, | scope=scope, | ||||
filterstr=filterstr, | filterstr=filterstr, | ||||
attrlist=attrlist, | attrlist=attrlist, | ||||
attrsonly=attrsonly, | attrsonly=attrsonly, | ||||
timeout=timeout, | timeout=timeout, | ||||
serverctrls=psearch_server_controls | serverctrls=psearch_server_controls | ||||
) | ) | ||||
ecnc = psearch.EntryChangeNotificationControl | ecnc = psearch.EntryChangeNotificationControl | ||||
while True: | while True: | ||||
res_type,res_data,res_msgid,_None,_None,_None = self.ldap.result4( | res_type,res_data,res_msgid,_None,_None,_None = self.ldap.result4( | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
_search, | _search, | ||||
all=0, | all=0, | ||||
add_ctrls=1, | add_ctrls=1, | ||||
add_intermediates=1, | add_intermediates=1, | ||||
resp_ctrl_classes={ecnc.controlType:ecnc} | resp_ctrl_classes={ecnc.controlType:ecnc} | ||||
Lint: PEP8 E231 missing whitespace after ':' Lint: PEP8 E231: missing whitespace after ':' | |||||
) | ) | ||||
change_type = None | change_type = None | ||||
previous_dn = None | previous_dn = None | ||||
change_number = None | change_number = None | ||||
for dn,entry,srv_ctrls in res_data: | for dn,entry,srv_ctrls in res_data: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
log.debug(_("LDAP Search Result Data Entry:"), level=8) | log.debug(_("LDAP Search Result Data Entry:"), level=8) | ||||
log.debug(" DN: %r" % (dn), level=8) | log.debug(" DN: %r" % (dn), level=8) | ||||
log.debug(" Entry: %r" % (entry), level=8) | log.debug(" Entry: %r" % (entry), level=8) | ||||
ecn_ctrls = [ | ecn_ctrls = [ | ||||
c for c in srv_ctrls | c for c in srv_ctrls | ||||
if c.controlType == ecnc.controlType | if c.controlType == ecnc.controlType | ||||
] | ] | ||||
Show All 29 Lines | def _persistent_search(self, | ||||
previous_dn=previous_dn, | previous_dn=previous_dn, | ||||
change_type=change_type, | change_type=change_type, | ||||
change_number=change_number, | change_number=change_number, | ||||
primary_domain=primary_domain, | primary_domain=primary_domain, | ||||
secondary_domains=secondary_domains | secondary_domains=secondary_domains | ||||
) | ) | ||||
def _paged_search(self, | def _paged_search(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
page_size = 500 | page_size = 500 | ||||
critical = True | critical = True | ||||
_results = [] | _results = [] | ||||
server_page_control = SimplePagedResultsControl(page_size=page_size) | server_page_control = SimplePagedResultsControl(page_size=page_size) | ||||
_search = self.ldap.search_ext( | _search = self.ldap.search_ext( | ||||
Show All 27 Lines | def _paged_search(self, | ||||
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 = [ | ||||
c for c in _result_controls | c for c in _result_controls | ||||
if c.controlType == LDAP_CONTROL_PAGED_RESULTS | if c.controlType == LDAP_CONTROL_PAGED_RESULTS | ||||
Lint: PEP8 E131 continuation line unaligned for hanging indent Lint: PEP8 E131: continuation line unaligned for hanging indent | |||||
] | ] | ||||
if pctrls: | if pctrls: | ||||
if hasattr(pctrls[0], 'size'): | if hasattr(pctrls[0], 'size'): | ||||
size = pctrls[0].size | size = pctrls[0].size | ||||
cookie = pctrls[0].cookie | cookie = pctrls[0].cookie | ||||
else: | else: | ||||
size, cookie = pctrls[0].controlValue | size, cookie = pctrls[0].controlValue | ||||
Show All 14 Lines | def _paged_search(self, | ||||
else: | else: | ||||
# TODO: Error out more verbose | # TODO: Error out more verbose | ||||
print "Warning: Server ignores RFC 2696 control." | print "Warning: Server ignores RFC 2696 control." | ||||
break | break | ||||
return _results | return _results | ||||
def _vlv_search(self, | def _vlv_search(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
pass | pass | ||||
def _sync_repl(self, | def _sync_repl(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
import ldapurl | import ldapurl | ||||
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), | ||||
Show All 18 Lines | def _sync_repl(self, | ||||
try: | try: | ||||
# Here's where returns need to be taken into account... | # Here's where returns need to be taken into account... | ||||
while ldap_sync_conn.syncrepl_poll(all=1, msgid=msgid): | while ldap_sync_conn.syncrepl_poll(all=1, msgid=msgid): | ||||
pass | pass | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
pass | pass | ||||
def _regular_search(self, | def _regular_search(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
log.debug(_("Searching with filter %r") % (filterstr), level=8) | log.debug(_("Searching with filter %r") % (filterstr), level=8) | ||||
_search = self.ldap.search( | _search = self.ldap.search( | ||||
base_dn, | base_dn, | ||||
scope=scope, | scope=scope, | ||||
filterstr=filterstr, | filterstr=filterstr, | ||||
attrlist=attrlist, | attrlist=attrlist, | ||||
attrsonly=attrsonly | attrsonly=attrsonly | ||||
) | ) | ||||
_results = [] | _results = [] | ||||
_result_type = None | _result_type = None | ||||
while not _result_type == ldap.RES_SEARCH_RESULT: | while not _result_type == ldap.RES_SEARCH_RESULT: | ||||
(_result_type, _result) = self.ldap.result(_search, False, 0) | (_result_type, _result) = self.ldap.result(_search, False, 0) | ||||
if not _result == None: | if not _result == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
for result in _result: | for result in _result: | ||||
_results.append(result) | _results.append(result) | ||||
return _results | return _results | ||||
def _search(self, | def _search(self, | ||||
base_dn, | base_dn, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
scope=ldap.SCOPE_SUBTREE, | scope=ldap.SCOPE_SUBTREE, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
filterstr="(objectClass=*)", | filterstr="(objectClass=*)", | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrlist=None, | attrlist=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
attrsonly=0, | attrsonly=0, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
timeout=-1, | timeout=-1, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
override_search=False, | override_search=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
callback=False, | callback=False, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
primary_domain=None, | primary_domain=None, | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
secondary_domains=[] | secondary_domains=[] | ||||
Lint: PEP8 E128 continuation line under-indented for visual indent Lint: PEP8 E128: continuation line under-indented for visual indent | |||||
): | ): | ||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
Lint: PEP8 E125 continuation line with same indent as next logical line Lint: PEP8 E125: continuation line with same indent as next logical line | |||||
""" | """ | ||||
Search LDAP. | Search LDAP. | ||||
Use the priority ordered SUPPORTED_LDAP_CONTROLS and use | Use the priority ordered SUPPORTED_LDAP_CONTROLS and use | ||||
the first one supported. | the first one supported. | ||||
""" | """ | ||||
supported_controls = conf.get_list('ldap', 'supported_controls') | supported_controls = conf.get_list('ldap', 'supported_controls') | ||||
if not supported_controls == None and not len(supported_controls) < 1: | if not supported_controls == None and not len(supported_controls) < 1: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
for control_num in [(int)(x) for x in supported_controls]: | for control_num in [(int)(x) for x in supported_controls]: | ||||
self.ldap.supported_controls.append( | self.ldap.supported_controls.append( | ||||
SUPPORTED_LDAP_CONTROLS[control_num]['func'] | SUPPORTED_LDAP_CONTROLS[control_num]['func'] | ||||
) | ) | ||||
if len(self.ldap.supported_controls) < 1: | if len(self.ldap.supported_controls) < 1: | ||||
for control_num in SUPPORTED_LDAP_CONTROLS.keys(): | for control_num in SUPPORTED_LDAP_CONTROLS.keys(): | ||||
log.debug( | log.debug( | ||||
_("Checking for support for %s on %s") % ( | _("Checking for support for %s on %s") % ( | ||||
SUPPORTED_LDAP_CONTROLS[control_num]['desc'], | SUPPORTED_LDAP_CONTROLS[control_num]['desc'], | ||||
self.domain | self.domain | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
_search = self.ldap.search_s( | _search = self.ldap.search_s( | ||||
'', | '', | ||||
scope=ldap.SCOPE_BASE, | scope=ldap.SCOPE_BASE, | ||||
attrlist=['supportedControl'] | attrlist=['supportedControl'] | ||||
) | ) | ||||
for (_result,_supported_controls) in _search: | for (_result,_supported_controls) in _search: | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
supported_controls = _supported_controls.values()[0] | supported_controls = _supported_controls.values()[0] | ||||
for control_num in SUPPORTED_LDAP_CONTROLS.keys(): | for control_num in SUPPORTED_LDAP_CONTROLS.keys(): | ||||
if SUPPORTED_LDAP_CONTROLS[control_num]['oid'] in \ | if SUPPORTED_LDAP_CONTROLS[control_num]['oid'] in \ | ||||
supported_controls: | supported_controls: | ||||
log.debug(_("Found support for %s") % ( | log.debug(_("Found support for %s") % ( | ||||
SUPPORTED_LDAP_CONTROLS[control_num]['desc'], | SUPPORTED_LDAP_CONTROLS[control_num]['desc'], | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
self.ldap.supported_controls.append( | self.ldap.supported_controls.append( | ||||
SUPPORTED_LDAP_CONTROLS[control_num]['func'] | SUPPORTED_LDAP_CONTROLS[control_num]['func'] | ||||
) | ) | ||||
_results = [] | _results = [] | ||||
if not override_search == False: | if not override_search == False: | ||||
Lint: PEP8 E712 comparison to False should be 'if cond is False:' or 'if not cond:' Lint: PEP8 E712: comparison to False should be 'if cond is False:' or 'if not cond:' | |||||
_use_ldap_controls = [ override_search ] | _use_ldap_controls = [ override_search ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
else: | else: | ||||
_use_ldap_controls = self.ldap.supported_controls | _use_ldap_controls = self.ldap.supported_controls | ||||
for supported_control in _use_ldap_controls: | for supported_control in _use_ldap_controls: | ||||
# Repeat the same supported control until | # Repeat the same supported control until | ||||
# a failure (Exception) occurs that been | # a failure (Exception) occurs that been | ||||
# recognized as not an error related to the | # recognized as not an error related to the | ||||
# supported control (such as ldap.SERVER_DOWN). | # supported control (such as ldap.SERVER_DOWN). | ||||
Show All 17 Lines | def _search(self, | ||||
scope, | scope, | ||||
filterstr, | filterstr, | ||||
attrlist, | attrlist, | ||||
attrsonly, | attrsonly, | ||||
timeout, | timeout, | ||||
primary_domain, | primary_domain, | ||||
secondary_domains | secondary_domains | ||||
) | ) | ||||
) | ) | ||||
Lint: PEP8 E124 closing bracket does not match visual indentation Lint: PEP8 E124: closing bracket does not match visual indentation | |||||
break | break | ||||
except ldap.SERVER_DOWN, errmsg: | except ldap.SERVER_DOWN, errmsg: | ||||
log.error(_("LDAP server unavailable: %r") % (errmsg)) | log.error(_("LDAP server unavailable: %r") % (errmsg)) | ||||
log.error(_("%s") % (traceback.format_exc())) | log.error(_("%s") % (traceback.format_exc())) | ||||
log.error(_("-- reconnecting in 10 seconds.")) | log.error(_("-- reconnecting in 10 seconds.")) | ||||
time.sleep(10) | time.sleep(10) | ||||
self.reconnect() | self.reconnect() | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
failed_ok = True | failed_ok = True | ||||
log.error(_("An error occured using %s: %r") % (supported_control, errmsg)) | log.error(_("An error occured using %s: %r") % (supported_control, errmsg)) | ||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
log.error(_("%s") % (traceback.format_exc())) | log.error(_("%s") % (traceback.format_exc())) | ||||
continue | continue | ||||
return _results | return _results |
module level import not at top of file