From: David Mulder Date: Thu, 24 Mar 2022 17:05:13 +0000 (+0000) Subject: samba-tool: gpo show/load handle utf-16-le strings X-Git-Tag: tevent-0.14.1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b0d78a3fdcd2df1d6ee63f41e2d56688ccd83f1;p=thirdparty%2Fsamba.git samba-tool: gpo show/load handle utf-16-le strings Signed-off-by: David Mulder Reviewed-by: Andrew Bartlett Tested-by: Kees van Vloten --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index ef4f8393984..b931c149063 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -82,6 +82,7 @@ from samba.netcmd.gpcommon import ( get_gpo_dn ) from samba.policies import RegistryGroupPolicies +from samba.dcerpc.misc import REG_MULTI_SZ def gpo_flags_string(value): @@ -669,7 +670,11 @@ class cmd_show(GPOCommand): defs['data'] = entry.data # Bytes aren't JSON serializable if type(defs['data']) == bytes: - defs['data'] = list(defs['data']) + if entry.type == REG_MULTI_SZ: + data = defs['data'].decode('utf-16-le') + defs['data'] = data.rstrip('\x00').split('\x00') + else: + defs['data'] = list(defs['data']) policy_defs.append(defs) self.outf.write("Policies :\n") json.dump(policy_defs, self.outf, indent=4) diff --git a/python/samba/policies.py b/python/samba/policies.py index d42bac718d7..00ea07e47c9 100644 --- a/python/samba/policies.py +++ b/python/samba/policies.py @@ -39,7 +39,7 @@ from samba.gp_parse.gp_ini import GPTIniParser from samba.common import get_string from samba.dcerpc import security from samba.ntacls import dsacl2fsacl -from samba.dcerpc.misc import GUID +from samba.dcerpc.misc import REG_BINARY, REG_MULTI_SZ, REG_SZ, GUID GPT_EMPTY = \ """ @@ -125,8 +125,13 @@ class RegistryGroupPolicies(object): def __set_data(self, rtype, data): # JSON can't store bytes, and have to be set via an int array - if rtype == 3 and type(data) == list: # REG_BINARY + if rtype == REG_BINARY and type(data) == list: return bytes(data) + elif rtype == REG_MULTI_SZ and type(data) == list: + data = ('\x00').join(data) + '\x00\x00' + return data.encode('utf-16-le') + elif rtype == REG_SZ and type(data) == str: + return data.encode('utf-8') return data def __pol_replace(self, pol_data, entry):