From cfe5c28deb1bb98fb07502da863149e76b3ab21d Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 11 Nov 2022 10:51:17 +0100 Subject: [PATCH] Bugfixing --- lib/pp_admintools/app/set_ldap_password.py | 14 +++++--------- lib/pp_admintools/handler/ldap_password.py | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/pp_admintools/app/set_ldap_password.py b/lib/pp_admintools/app/set_ldap_password.py index b2aa9e0..f59a038 100644 --- a/lib/pp_admintools/app/set_ldap_password.py +++ b/lib/pp_admintools/app/set_ldap_password.py @@ -33,7 +33,7 @@ from ..handler.ldap_password import WrongPwdSchemaError from ..handler.ldap_password import LdapPasswordHandler from ..handler.ldap_password import HAS_CRACKLIB -__version__ = '0.7.1' +__version__ = '0.7.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -110,9 +110,6 @@ class SetLdapPasswordApplication(BaseLdapApplication): res = super(SetLdapPasswordApplication, self).as_dict(short=short) - res['available_schemes'] = self.available_schemes - res['default_schema'] = self.passlib_context.default_scheme() - res['schema_ids'] = self.schema_ids if self.current_password and self.verbose < 5: res['current_password'] = '******' if self.new_password and self.verbose < 5: @@ -450,10 +447,9 @@ class SetLdapPasswordApplication(BaseLdapApplication): def do_set_password(self): print() - msg = _("Setting password of {dn!r} with hashing schema {schema!r}.").format( - dn=self.user_dn, schema=self.schema_id) msg = _("Setting password of '{dn}' with hashing schema '{schema}' ...").format( - dn=self.colored(self.user_dn, 'CYAN'), schema=self.colored(self.schema_id, 'CYAN')) + dn=self.colored(self.user_dn, 'CYAN'), + schema=self.colored(self.pwd_handler.schema_id, 'CYAN')) print(msg) if self.current_password_hash: @@ -464,8 +460,8 @@ class SetLdapPasswordApplication(BaseLdapApplication): self.colored(self.user_dn, 'CYAN')) print(msg) - LOG.debug(_("Used schema: {!r}.").format(self.schema)) - hashed_passwd = self.pwd_handler.get_hash(self.new_password, self.schema) + LOG.debug(_("Used schema: {!r}.").format(self.pwd_handler.schema)) + hashed_passwd = self.pwd_handler.get_hash(self.new_password, self.pwd_handler.schema) msg = _("New password hash: '{}'.").format(self.colored(hashed_passwd, 'CYAN')) print(msg) diff --git a/lib/pp_admintools/handler/ldap_password.py b/lib/pp_admintools/handler/ldap_password.py index 65132b2..aab4912 100644 --- a/lib/pp_admintools/handler/ldap_password.py +++ b/lib/pp_admintools/handler/ldap_password.py @@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.2.1' +__version__ = '0.2.2' # ============================================================================= @@ -158,6 +158,22 @@ class LdapPasswordHandler(HandlingObject): if initialized: self.initialized = True + # ------------------------------------------------------------------------- + @property + def salt_len(self): + """Gives the valid length of a salt string in dependency to the current schema.""" + if hasattr(self, 'schema') and self.schema == 'ldap_des_crypt': + return 2 + return 8 + + # ------------------------------------------------------------------------- + @property + def salt(self): + """The salt of the current schema.""" + if not hasattr(self.__class__, 'passlib_context'): + return None + return self.passlib_context.salt() + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -173,7 +189,10 @@ class LdapPasswordHandler(HandlingObject): res = super(LdapPasswordHandler, self).as_dict(short=short) res['available_schemes'] = self.available_schemes + res['passlib_context'] = self.passlib_context.to_dict(True) res['default_schema'] = self.passlib_context.default_scheme() + # res['salt'] = self.salt + res['salt_len'] = self.salt_len res['schema_ids'] = self.schema_ids return res -- 2.39.5