mirror of
https://github.com/samba-team/samba.git
synced 2025-03-22 02:50:28 +03:00
gpo: Properly decode utf-8/16 inf files from bytes
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>
This commit is contained in:
parent
70a38eb548
commit
0f3066abbb
@ -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
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_inf_ext_utf
|
Loading…
x
Reference in New Issue
Block a user