From: Noel Power Date: Mon, 14 May 2018 12:38:20 +0000 (+0100) Subject: python/samba: Fix incorrect encode of password X-Git-Tag: ldb-1.4.0~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7102732b25dfcd5e6815159e3043eed240e918d3;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 424a648446b..abe434c8578 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -589,7 +589,11 @@ member: %s 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') + else: + pw = password + pw = ('"' + pw + '"').encode('utf-16-le') setpw = """ dn: %s changetype: modify