Browse Source

Ticket 49544 - Double check pw prompts

Bug Description:  We did not prompt for password change twice.

Fix Description:  Prompt twice when requested to ensure we don't
mess up inputs.

https://pagure.io/389-ds-base/issue/49544

Author: wibrown

Review by: spicugi (Thanks!)
William Brown 7 years ago
parent
commit
e435e96b23

+ 1 - 0
src/lib389/cli/dsidm

@@ -12,6 +12,7 @@ import ldap
 import argparse
 # import argcomplete
 import logging
+import sys
 
 # This has to happen before we import  DirSrv else it tramples our config ... :(
 logging.basicConfig(format='%(message)s')

+ 9 - 2
src/lib389/lib389/cli_base/__init__.py

@@ -11,6 +11,7 @@ import sys
 
 from getpass import getpass
 from lib389 import DirSrv
+from lib389.utils import assert_c
 from lib389.properties import SER_LDAP_URL, SER_ROOT_DN, SER_ROOT_PW
 
 MAJOR, MINOR, _, _, _ = sys.version_info
@@ -23,7 +24,7 @@ def _input(msg):
         return raw_input(msg)
 
 
-def _get_arg(args, msg=None, hidden=False):
+def _get_arg(args, msg=None, hidden=False, confirm=False):
     if args is not None and len(args) > 0:
         if type(args) is list:
             return args[0]
@@ -31,7 +32,13 @@ def _get_arg(args, msg=None, hidden=False):
             return args
     else:
         if hidden:
-            return getpass("%s : " % msg)
+            if confirm:
+                x = getpass("%s : " % msg)
+                y = getpass("CONFIRM - %s : " % msg)
+                assert_c(x == y, "inputs do not match, aborting.")
+                return y
+            else:
+                return getpass("%s : " % msg)
         else:
             return _input("%s : " % msg)
 

+ 1 - 1
src/lib389/lib389/cli_conf/directory_manager.py

@@ -16,7 +16,7 @@ def password_change(inst, basedn, log, args):
     # Due to an issue, we can't use extended op, so we have to
     # submit the password directly to the field.
 
-    password = _get_arg(args.password, msg="Enter new directory manager password", hidden=True)
+    password = _get_arg(args.password, msg="Enter new directory manager password", hidden=True, confirm=True)
     dm = DirectoryManager(inst)
     dm.change_password(password)