samba-tool: gpo show/load handle utf-16-le strings
authorDavid Mulder <dmulder@suse.com>
Thu, 24 Mar 2022 17:05:13 +0000 (17:05 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 30 Jan 2023 09:00:39 +0000 (09:00 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Tested-by: Kees van Vloten <keesvanvloten@gmail.com>
python/samba/netcmd/gpo.py
python/samba/policies.py

index ef4f83939840d5a0d5e8df3aaf46bd7fafe21657..b931c149063e516136d062041beff68688d3451e 100644 (file)
@@ -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)
index d42bac718d7c9706990f8dc411f58c4ffbd58979..00ea07e47c9c411f334a0eca427a20739c58adf9 100644 (file)
@@ -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):