]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python/samba: PY3 don't call str for bytes (or str)
authorNoel Power <noel.power@suse.com>
Tue, 6 Nov 2018 19:58:48 +0000 (19:58 +0000)
committerNoel Power <npower@samba.org>
Mon, 10 Dec 2018 09:38:22 +0000 (10:38 +0100)
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>
python/samba/samdb.py

index 415142b2245f00161228d2c9b5b30a001e2e08f5..1160740a23ba1264d7a26a9950781a5562a3714f 100644 (file)
@@ -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")