]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Bugfixing
authorFrank Brehm <frank@brehm-online.com>
Fri, 11 Nov 2022 09:51:17 +0000 (10:51 +0100)
committerFrank Brehm <frank@brehm-online.com>
Fri, 11 Nov 2022 09:51:17 +0000 (10:51 +0100)
lib/pp_admintools/app/set_ldap_password.py
lib/pp_admintools/handler/ldap_password.py

index b2aa9e0853408b678e961ab8ae2c562acf0a1f59..f59a0386a939c04e091b189b72c8176674609d58 100644 (file)
@@ -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)
 
index 65132b21289c416065e30521b4822585fe34561a..aab4912ba9d228e17cb736585b830a0e9abab210 100644 (file)
@@ -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