]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
gpo: Properly decode utf-8/16 inf files from bytes
authorDavid Mulder <dmulder@suse.com>
Mon, 6 Jul 2020 14:13:57 +0000 (08:13 -0600)
committerDavid Mulder <dmulder@samba.org>
Thu, 6 Aug 2020 16:38:36 +0000 (16:38 +0000)
This code was python 2 specific (string handling
has changed dramatically in python 3), and didn't
correctly decode utf-16 in python3. We should
instead read the file as bytes, then attempt a
utf-8 decode (the default), and try utf-16 if
encountering a decode failure.
The existing code actually throws an exception on
the initial file read when the data is utf-16,
since it tries to decode the bytes to a utf-8
string.

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/gpclass.py
selftest/knownfail.d/gpo [deleted file]

index cc574e12a425266577ba13282b48f173ef9bcb56..1831e6e1ebc056727d57bd449aa667d84ac2af03 100644 (file)
@@ -351,12 +351,12 @@ class gp_ext_setter(object):
 
 class gp_inf_ext(gp_ext):
     def read(self, data_file):
-        policy = open(data_file, 'r').read()
+        policy = open(data_file, 'rb').read()
         inf_conf = ConfigParser()
         inf_conf.optionxform = str
         try:
-            inf_conf.readfp(StringIO(policy))
-        except:
+            inf_conf.readfp(StringIO(policy.decode()))
+        except UnicodeDecodeError:
             inf_conf.readfp(StringIO(policy.decode('utf-16')))
         return inf_conf
 
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
deleted file mode 100644 (file)
index d2e80b6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_inf_ext_utf