From f35f35d1c99c45445c9cbfd4af03c2bf5c898e6f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 25 May 2023 18:12:32 +0200 Subject: [PATCH] Adding removing no more used aliases in LDAP --- lib/pp_admintools/app/barracuda_sync.py | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index 6f0d206..adb1d41 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.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() -- 2.39.5