From 5fbeb226612095ec734cb2dce4494b5f6bd7be83 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 26 May 2023 12:46:46 +0200 Subject: [PATCH] Bugfixing --- lib/pp_admintools/app/barracuda_sync.py | 40 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index cc6b80a..fe4b0ee 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -31,7 +31,7 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.9.6' +__version__ = '0.9.7' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -563,17 +563,27 @@ class BarracudaSyncApp(BaseLdapApplication): for dn in self.ldap_aliases: entry = self.ldap_aliases[dn] + ldap_cn = entry['cn'][0] do_delete = False entry_in_local_aliases = False for mail in entry['mail']: if mail in self.ldap_mail_dns: do_delete = True + if self.verbose > 2: + msg = _( + 'Removing {!r}, because there are mail attributes somewhere ' + 'else.').format(dn) + LOG,debug(msg) break - for cn in self.existing_aliases.keys(): - local_alias = self.existing_aliases[cn] - if mail.lower() == local_alias['alias'].lower(): + for local_cn in self.existing_aliases.keys(): + if ldap_cn.lower() == local_cn.lower(): entry_in_local_aliases = True - if not entry_in_local_aliases: + if not entry_in_local_aliases and not do_delete: + if self.verbose > 2: + msg = _( + 'Removing {dn!r}, because there is no key {cn!r} in virtual aliases' + 'table.').format(dn=dn, cn=local_cn) + LOG,debug(msg) do_delete = True if do_delete: self.aliases_to_remove.append(dn) @@ -601,8 +611,8 @@ class BarracudaSyncApp(BaseLdapApplication): self.aliases_to_create = [] - for cn in self.existing_aliases.keys(): - local_alias = self.existing_aliases[cn] + for local_cn in self.existing_aliases.keys(): + local_alias = self.existing_aliases[local_cn] mail = local_alias['alias'] if mail in self.ldap_mail_dns: @@ -614,11 +624,12 @@ class BarracudaSyncApp(BaseLdapApplication): do_create = True for dn in self.ldap_aliases: entry = self.ldap_aliases[dn] - if mail in entry['mail']: + ldap_cn = entry['cn'][0] + if local_cn.lower() == ldap_cn.lower(): do_create = False break if do_create: - self.aliases_to_create.append(cn) + self.aliases_to_create.append(local_cn) self.aliases_to_create.sort(key=str.lower) @@ -642,12 +653,12 @@ class BarracudaSyncApp(BaseLdapApplication): self.aliases_to_modify = {} - for cn in self.existing_aliases.keys(): - local_alias = self.existing_aliases[cn] + for local_cn in self.existing_aliases.keys(): + local_alias = self.existing_aliases[local_cn] mail = local_alias['alias'] if self.verbose > 3: - LOG.debug('Evaluating CN {!r} for modifications ...'.format(cn)) + LOG.debug('Evaluating CN {!r} for modifications ...'.format(local_cn)) if mail in self.ldap_mail_dns: if self.verbose > 2: @@ -658,10 +669,11 @@ class BarracudaSyncApp(BaseLdapApplication): modify_data = None for dn in self.ldap_aliases: entry = self.ldap_aliases[dn] - if mail in entry['mail']: + ldap_cn = entry['cn'][0] + if ldap_cn.lower() == local_cn.lower(): if self.verbose > 3: LOG.debug('Evaluating DN {!r} for modifications ...'.format(dn)) - modify_data = self._create_modify_alias_data(cn, entry) + modify_data = self._create_modify_alias_data(local_cn, entry) if modify_data: self.aliases_to_modify[dn] = modify_data break -- 2.39.5