diff options
author | Noel Power <noel.power@suse.com> | 2018-11-06 19:58:48 +0000 |
---|---|---|
committer | Noel Power <npower@samba.org> | 2018-12-10 10:38:22 +0100 |
commit | 744acb276c7cfc2e8f859ea960282c6395362602 (patch) | |
tree | fe45bf945ff820f3056e16b0c6133c14a50526f6 /python | |
parent | c99450db4eed3abc3a69833a82b1c906e066e27a (diff) | |
download | samba-744acb276c7cfc2e8f859ea960282c6395362602.tar.gz |
python/samba: PY3 don't call str for bytes (or str)
Note: Fix needed also for gpo.apply
minPwdAge, maxPwdAge, minPwdLength & set_pwdProperties all
have a line like
value = str(value).encode('utf8')
this is a generic type statement I guess to convert int, float etc
to utf8 encoded bytes representing the string value for those.
This worked fine in PY2 but in py3 some routine already are passing
bytes into these methods, in these cases e.g. b'200' will get converted
to "b'200'", this change only performs the conversion above for non
bytes (or str) types by replacing the above with
if not isinstance(value, binary_type):
value = str(value).encode('utf8')
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/samdb.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 415142b2245..1160740a23b 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -33,6 +33,7 @@ from samba.ndr import ndr_unpack, ndr_pack from samba.dcerpc import drsblobs, misc from samba.common import normalise_int32 from samba.compat import text_type +from samba.compat import binary_type from samba.dcerpc import security __docformat__ = "restructuredText" @@ -920,7 +921,8 @@ schemaUpdateNow: 1 return dn def set_minPwdAge(self, value): - value = str(value).encode('utf8') + if not isinstance(value, binary_type): + value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) m["minPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdAge") @@ -936,7 +938,8 @@ schemaUpdateNow: 1 return int(res[0]["minPwdAge"][0]) def set_maxPwdAge(self, value): - value = str(value).encode('utf8') + if not isinstance(value, binary_type): + value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) m["maxPwdAge"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "maxPwdAge") @@ -952,7 +955,8 @@ schemaUpdateNow: 1 return int(res[0]["maxPwdAge"][0]) def set_minPwdLength(self, value): - value = str(value).encode('utf8') + if not isinstance(value, binary_type): + value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) m["minPwdLength"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "minPwdLength") @@ -968,7 +972,8 @@ schemaUpdateNow: 1 return int(res[0]["minPwdLength"][0]) def set_pwdProperties(self, value): - value = str(value).encode('utf8') + if not isinstance(value, binary_type): + value = str(value).encode('utf8') m = ldb.Message() m.dn = ldb.Dn(self, self.domain_dn()) m["pwdProperties"] = ldb.MessageElement(value, ldb.FLAG_MOD_REPLACE, "pwdProperties") |