This diff was made against pykolab-0.7.27 branch
--- pykolab/auth/__init__.py | 4 ++-- pykolab/auth/ldap/__init__.py | 14 ++++++++++---- pykolab/cli/cmd_sync_mailhost_attrs.py | 5 +++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pykolab/auth/__init__.py b/pykolab/auth/__init__.py index 2ffd8d3..6b5af9a 100644 --- a/pykolab/auth/__init__.py +++ b/pykolab/auth/__init__.py @@ -193,7 +193,7 @@ class Auth(pykolab.base.Base): else: return result - def find_recipient(self, address, domain=None): + def find_recipient(self, address, domain=None, respect_base_filter=False): """ Find one or more entries corresponding to the recipient address. """ @@ -203,7 +203,7 @@ class Auth(pykolab.base.Base): if not self._auth or self._auth == None: self.connect(domain=domain) - result = self._auth.find_recipient(address) + result = self._auth.find_recipient(address, respect_base_filter=respect_base_filter) if isinstance(result, list) and len(result) == 1: return result[0] diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py index 9a65a9c..a74fb68 100644 --- a/pykolab/auth/ldap/__init__.py +++ b/pykolab/auth/ldap/__init__.py @@ -541,7 +541,7 @@ class LDAP(pykolab.base.Base): return _entry_dns - def find_recipient(self, address="*", exclude_entry_id=None): + def find_recipient(self, address="*", exclude_entry_id=None, respect_base_filter=False): """ Given an address string or list of addresses, find one or more valid recipients. @@ -576,6 +576,7 @@ class LDAP(pykolab.base.Base): result_attributes.append(self.config_get('unique_attribute')) + _filter = "(|" for recipient_address_attr in recipient_address_attrs: @@ -586,9 +587,14 @@ class LDAP(pykolab.base.Base): _filter += "(%s=%s)" % (recipient_address_attr, _address) _filter += ")" - - _filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) - + if respect_base_filter: + # If this option is set we add an additional filter so that we only search for entries + # that actually should be kolabUsers as defined by "kolab_user_filter"... + # tbh: I have no idea why this isn't already happening... + log.debug(_("Adding kolab_user_filter..."), level=8) + _filter = "(&%s%s)" % (self.config_get('kolab_user_filter'), _filter) + + filter = "%s%s%s" % (__filter_prefix,_filter,__filter_suffix) log.debug(_("Finding recipient with filter %r") % (_filter), level=8) if len(_filter) <= 6: diff --git a/pykolab/cli/cmd_sync_mailhost_attrs.py b/pykolab/cli/cmd_sync_mailhost_attrs.py index fe7f6b2..8e42055 100644 --- a/pykolab/cli/cmd_sync_mailhost_attrs.py +++ b/pykolab/cli/cmd_sync_mailhost_attrs.py @@ -140,10 +140,11 @@ def execute(*args, **kw): recipient = auth.find_folder_resource(folder) else: r_folder = '/'.join(folder.split('/')[1:]) - recipient = auth.find_recipient(r_folder) + recipient = auth.find_recipient(r_folder, respect_base_filter=True) if (isinstance(recipient, list)): if len(recipient) > 1: + print recipient log.warning(_("Multiple recipients for '%s'!") % (r_folder)) continue elif len(recipient) == 0: @@ -188,6 +189,6 @@ def execute(*args, **kw): if folder.startswith('shared/'): recipient = auth.find_folder_resource(folder) else: - recipient = auth.find_recipient('/'.join(folder.split('/')[1:])) + recipient = auth.find_recipient('/'.join(folder.split('/')[1:]), respect_base_filter=True) print folder, server, recipient -- 2.7.4