From e3e1edf7b9afe9eec5aa8cdf87321904b1d9710e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 14 May 2018 13:48:18 +0100 Subject: [PATCH 1/2] s4/setup/tests: Add test for non ascii password setting samba-tool Bug: https://bugzilla.samba.org/show_bug.cgi?id=13435 Signed-off-by: Noel Power --- source4/setup/tests/blackbox_setpassword.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source4/setup/tests/blackbox_setpassword.sh b/source4/setup/tests/blackbox_setpassword.sh index 8055740f101..ccc94c3f05d 100755 --- a/source4/setup/tests/blackbox_setpassword.sh +++ b/source4/setup/tests/blackbox_setpassword.sh @@ -25,6 +25,8 @@ testit "setpassword" $samba_tool user setpassword --configfile=$PREFIX/simple-dc testit "setpassword" $samba_tool user setpassword --configfile=$PREFIX/simple-dc/etc/smb.conf testuser --newpassword=testp@ssw0Rd --must-change-at-next-login +testit "setpassword" $samba_tool user setpassword --configfile=$PREFIX/simple-dc/etc/smb.conf testuser --newpassword=Täst123 --must-change-at-next-login + testit "passwordsettings" $samba_tool domain passwordsettings set --quiet --configfile=$PREFIX/simple-dc/etc/smb.conf --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default --store-plaintext=on exit $failed From 52e4d5ab1014fccdc0954966c720a35551198b83 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 14 May 2018 13:38:20 +0100 Subject: [PATCH 2/2] python/samba: Fix incorrect encode of password In python2 you can encode a 'str' type which doesn't really make sense since it is already bytes (as such). In python3 this isn't possible you can't encode bytes or decode strings. Also because you can call encode on 'str' in python2 it tries to to what you wanted and it implicity calls decode('ascii') before performing the encode. This is why we get mention of ascii codec in the error. This patch should future proof for python3 also. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13435 Signed-off-by: Noel Power --- python/samba/samdb.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 424a648446b..e2c53c91e6a 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -589,7 +589,9 @@ def setpassword(self, search_filter, password, if len(res) > 1: raise Exception('Matched %u multiple users with filter "%s"' % (len(res), search_filter)) user_dn = res[0].dn - pw = text_type(b'"' + password.encode('utf-8') + b'"', 'utf-8').encode('utf-16-le') + if not isinstance(password, text_type): + pw = password.decode('utf-8') + pw = ('"' + pw + '"').encode('utf-16-le') setpw = """ dn: %s changetype: modify