]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Inreasing performance of requesting data
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 21 Aug 2023 12:44:23 +0000 (14:44 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 21 Aug 2023 12:44:23 +0000 (14:44 +0200)
lib/pp_admintools/app/check_ldap_pwd_schemes.py

index 6895f654c9e70ee863110d77c4ef9a6f5782cbea..aea4f96ceaa88ea296fea1aa620112dcd1d58892 100644 (file)
@@ -32,7 +32,7 @@ from ..config.ldap import LdapConfiguration
 from ..handler.ldap_password import LdapPasswordHandler
 from ..xlate import XLATOR
 
-__version__ = '0.1.0'
+__version__ = '0.2.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -177,10 +177,51 @@ class CheckLdapPwdSchemesApplication(BaseLdapApplication):
         else:
             ldap_filter = '(&' + self.default_filter + ')'
 
+        get_attributes = self.get_attributes.as_list()
         LOG.debug(_('Used LDAP filter: {!r}.').format(ldap_filter))
 
-        for dn in self.get_all_entry_dns(self.instance, ldap_filter=ldap_filter):
-            self.perform_entry(dn)
+        entries = self.get_all_entries(
+            self.instance, ldap_filter=ldap_filter, attributes=get_attributes)
+
+        for dn in entries:
+
+            attribs = entries[dn]
+            if self.verbose > 3:
+                LOG.debug(_('Got attributes:') + '\n' + pp(attribs.as_dict()))
+
+            if 'userPassword' not in attribs:
+                continue
+
+            used_name = ''
+            if 'cn' in attribs and len(attribs['cn']):
+                used_name = attribs['cn'][0]
+            else:
+                used_name = attribs['uid'][0]
+
+            methods = []
+            show_entry = True
+            if self.filter_schemes:
+                show_entry = False
+            for passwd in attribs['userPassword']:
+                hash_method = self.pwd_handler.get_hashing_schema(passwd)
+                methods.append(hash_method)
+                if self.filter_schemes:
+                    if hash_method in self.filter_schemes:
+                        show_entry = True
+
+            if show_entry and len(methods) > 0:
+                pwdata = {
+                    'name': used_name,
+                    'hashing_methods': methods,
+                }
+                if self.show_details:
+                    pwdata['userPassword'] = attribs['userPassword']
+                self.found_dns.add(dn)
+                self.found_entries[dn] = pwdata
+
+                if self.verbose > 2:
+                    msg = _('Found entry {!r} with data:').format(dn) + '\n' + pp(pwdata)
+                    LOG.debug(msg)
 
         if self.verbose > 3:
             msg = _('Found entry DNs:') + '\n' + pp(self.found_entries.as_dict())
@@ -208,57 +249,6 @@ class CheckLdapPwdSchemesApplication(BaseLdapApplication):
             if self.show_details:
                 print('    dn: ' + dn)
 
-    # -------------------------------------------------------------------------
-    def perform_entry(self, dn):
-        """Get the entry of the given DN and evaluate the password hashing method."""
-        if self.verbose > 1:
-            LOG.debug(_('Checking password hashing method of entry {!r} ...').format(dn))
-
-        get_attributes = self.get_attributes.as_list()
-
-        entry = self.get_entry(dn, self.instance, attributes=get_attributes)
-        attribs = self.normalized_attributes(entry)
-        if self.verbose > 2:
-            LOG.debug(_('Got attributes:') + '\n' + pp(attribs.as_dict()))
-
-        if 'userPassword' not in attribs:
-            return False
-
-        used_name = ''
-        if 'cn' in attribs and len(attribs['cn']):
-            used_name = attribs['cn'][0]
-        else:
-            used_name = attribs['uid'][0]
-
-        methods = []
-        show_entry = True
-        if self.filter_schemes:
-            show_entry = False
-        for passwd in attribs['userPassword']:
-            hash_method = self.pwd_handler.get_hashing_schema(passwd)
-            methods.append(hash_method)
-            if self.filter_schemes:
-                if hash_method in self.filter_schemes:
-                    show_entry = True
-
-        if show_entry and len(methods) > 0:
-            pwdata = {
-                'name': used_name,
-                'hashing_methods': methods,
-            }
-            if self.show_details:
-                pwdata['userPassword'] = attribs['userPassword']
-            self.found_dns.add(dn)
-            self.found_entries[dn] = pwdata
-
-            if self.verbose > 2:
-                msg = _('Found entry {!r} with data:').format(dn) + '\n' + pp(pwdata)
-                LOG.debug(msg)
-
-            return True
-
-        return False
-
 
 # =============================================================================
 if __name__ == '__main__':