]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Bugfixing
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 26 May 2023 10:46:46 +0000 (12:46 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 26 May 2023 10:46:46 +0000 (12:46 +0200)
lib/pp_admintools/app/barracuda_sync.py

index cc6b80ade17f93aabfd0ed933a41af0900835e71..fe4b0ee23bb9c9857c42e7a7f40aeaa32716bbeb 100644 (file)
@@ -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