from ..handler.ldap_password import LdapPasswordHandler
from ..xlate import XLATOR
-__version__ = '0.1.0'
+__version__ = '0.2.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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())
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__':