python/samba/netcmd: net.change_password should be passed string
authorNoel Power <noel.power@suse.com>
Wed, 16 May 2018 15:51:34 +0000 (16:51 +0100)
committerNoel Power <npower@samba.org>
Thu, 17 May 2018 09:31:29 +0000 (11:31 +0200)
password param which in python2 (is str) is incorrectly encoded
before passing to net.change_password.

python2 - password is either unicode or str, if str we should
          decode to get unicode (and then pass to net.change_password).
python3 - password is either str or bytes, if bytes then decode
          (and pass as 'str' to net.change_password).
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/user.py

index 4009d6304bfc1ef3b97e74eafefadd1a9ad15709..f211b5158ced255430cb4f3d0057f12b52c25e67 100644 (file)
@@ -54,7 +54,7 @@ from samba.netcmd import (
     SuperCommand,
     Option,
     )
-
+from samba.compat import text_type
 
 try:
     import io
@@ -713,7 +713,9 @@ class cmd_user_password(Command):
                 self.outf.write("Sorry, passwords do not match.\n")
 
         try:
-            net.change_password(password.encode('utf-8'))
+            if not isinstance(password, text_type):
+                password = password.decode('utf8')
+            net.change_password(password)
         except Exception as msg:
             # FIXME: catch more specific exception
             raise CommandError("Failed to change password : %s" % msg)