From: Frank Brehm Date: Mon, 21 Aug 2023 12:44:23 +0000 (+0200) Subject: Inreasing performance of requesting data X-Git-Tag: 0.11.0~3^2~10 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=00f2462ff7b009f6b7e15e38afed84f8ac383869;p=pixelpark%2Fpp-admin-tools.git Inreasing performance of requesting data --- diff --git a/lib/pp_admintools/app/check_ldap_pwd_schemes.py b/lib/pp_admintools/app/check_ldap_pwd_schemes.py index 6895f65..aea4f96 100644 --- a/lib/pp_admintools/app/check_ldap_pwd_schemes.py +++ b/lib/pp_admintools/app/check_ldap_pwd_schemes.py @@ -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__':