]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding removing no more used aliases in LDAP
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 May 2023 16:12:32 +0000 (18:12 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 May 2023 16:12:32 +0000 (18:12 +0200)
lib/pp_admintools/app/barracuda_sync.py

index 6f0d206d7f2a59c6ee901432e5dcdce67945baf5..adb1d41026d06b83ad8df532bf98b64642770928 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.3'
+__version__ = '0.9.4'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -836,6 +836,25 @@ class BarracudaSyncApp(BaseLdapApplication):
 
         return (oclasses, attributes)
 
+    # -------------------------------------------------------------------------
+    def remove_old_alias_entries(self):
+        """Remove all no more used alias entries."""
+        self.empty_line()
+        LOG.info(_('Removing all no more used alias entries …'))
+        inst = self.ldap_instances[0]
+
+        if not len(self.aliases_to_remove):
+            msg = _('No aliases found to remove in LDAP.')
+            LOG.info(msg)
+            if self.wait_interval:
+                time.sleep(self.wait_interval * 10)
+            return
+
+        for dn in self.aliases_to_remove:
+            self.delete_entry(inst, dn)
+            if self.wait_interval:
+                time.sleep(self.wait_interval)
+
     # -------------------------------------------------------------------------
     def add_failing_ldap_entries(self):
         """Create failing LDAP entries."""
@@ -843,6 +862,13 @@ class BarracudaSyncApp(BaseLdapApplication):
         LOG.info(_('Adding failing LDAP aliases ...'))
         inst = self.ldap_instances[0]
 
+        if not len(self.aliases_to_create):
+            msg = _('No aliases found to create in LDAP.')
+            LOG.info(msg)
+            if self.wait_interval:
+                time.sleep(self.wait_interval * 10)
+            return
+
         for cn in self.aliases_to_create:
             dn = 'cn=' + cn + ',' + self.barracuda_base_dn
             (oclasses, attributes) = self._create_ldap_entry_for_create(cn)
@@ -859,6 +885,7 @@ class BarracudaSyncApp(BaseLdapApplication):
         self.read_barracuda_ldap_aliases()
         self.get_other_ldap_mail_entries()
         self.eval_diffs()
+        self.remove_old_alias_entries()
         self.add_failing_ldap_entries()