]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Get all entries with a mail attribute except for Barracuda
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 12:39:19 +0000 (14:39 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 12:39:19 +0000 (14:39 +0200)
lib/pp_admintools/app/barracuda_sync.py

index ea5cc4be9c013c21b85e163835aba7b4a936aa51..121faae5b4c29561989d89f4d0eb31a778415e8a 100644 (file)
@@ -27,7 +27,7 @@ from ldap3 import BASE
 from .ldap import BaseLdapApplication
 from ..xlate import XLATOR
 
-__version__ = '0.8.2'
+__version__ = '0.8.3'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -108,7 +108,7 @@ class BarracudaSyncApp(BaseLdapApplication):
         self.lookup_table_types = []
         self.existing_aliases = {}
         self.ldap_aliases = []
-        self.ldap_mail_dns = []
+        self.ldap_mail_dns = {}
         self.aliases_to_create = []
         self.aliases_to_remove = []
         self.ignore_aliases_res = []
@@ -453,19 +453,66 @@ class BarracudaSyncApp(BaseLdapApplication):
         base_dn = self.barracuda_base_dn
         result = self.get_all_entries(inst, ldap_filter=ldap_filter, base_dn=base_dn)
 
-        if self.verbose > 1:
+        if self.verbose > 2:
             msg = _('Virtual aliases in LDAP for Barracuda:')
             msg += '\n' + pp(result)
             LOG.debug(msg)
 
         self.ldap_aliases = result
 
+    # -------------------------------------------------------------------------
+    def get_other_ldap_mail_entries(self):
+        """Get all LDAP entries except for Barracuda, where mail attributes are set."""
+        msg = _('Get all LDAP entries except for Barracuda, where mail attributes are set.')
+        LOG.info(msg)
+
+        self.ldap_mail_dns = {}
+
+        inst = self.ldap_instances[0]
+        ldap_filter = '(|(mail=*)(mailAlternateAddress=*)(mailEquivalentAddress=*))'
+        attributes = ['dn', 'mail', 'mailAlternateAddress', 'mailEquivalentAddress']
+        result = self.get_all_entries(inst, ldap_filter=ldap_filter, attributes=attributes)
+
+        for dn in result.keys():
+
+            if dn.endswith(self.barracuda_base_dn):
+                continue
+
+            entry = result[dn]
+
+            if 'mail' in entry:
+                for mail in entry['mail']:
+                    if mail not in self.ldap_mail_dns:
+                        self.ldap_mail_dns[mail] = []
+                    if dn not in self.ldap_mail_dns[mail]:
+                        self.ldap_mail_dns[mail].append(dn)
+
+            if 'mailAlternateAddress' in entry:
+                for mail in entry['mailAlternateAddress']:
+                    if mail not in self.ldap_mail_dns:
+                        self.ldap_mail_dns[mail] = []
+                    if dn not in self.ldap_mail_dns[mail]:
+                        self.ldap_mail_dns[mail].append(dn)
+
+            if 'mailEquivalentAddress' in entry:
+                for mail in entry['mailEquivalentAddress']:
+                    if mail not in self.ldap_mail_dns:
+                        self.ldap_mail_dns[mail] = []
+                    if dn not in self.ldap_mail_dns[mail]:
+                        self.ldap_mail_dns[mail].append(dn)
+
+        if self.verbose > 2:
+            msg = _('LDAP  Barracuda:')
+            msg += '\n' + pp(result)
+            LOG.debug(msg)
+
     # -------------------------------------------------------------------------
     def _run(self):
 
         self.verify_barracuda_container()
         self.read_virtual_alias_mappings()
         self.read_barracuda_ldap_aliases()
+        self.get_other_ldap_mail_entries()
 
 
 # =============================================================================