The branch, master has been updated via 03af1176938 gp_pol: Test multiple values multi_sz roundtrip via d5d96bed02f gp_pol: Allow null data for REG_MULTI_SZ via 9c5a9244281 gp_pol: Test empty multi_sz roundtrip from d1d2a03d73b s3:utils: Initialize the memcache for smbpasswd
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 03af117693852262b3f5ead4aaa62314d6f3ca45 Author: Gabriel Nagy <gabriel.n...@canonical.com> Date: Fri Oct 27 11:21:50 2023 +0300 gp_pol: Test multiple values multi_sz roundtrip Signed-off-by: Gabriel Nagy <gabriel.n...@canonical.com> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: David Mulder <dmul...@samba.org> Autobuild-User(master): David Mulder <dmul...@samba.org> Autobuild-Date(master): Fri Oct 27 14:45:28 UTC 2023 on atb-devel-224 commit d5d96bed02fab78386fad908e4dd18c1adcd4795 Author: Gabriel Nagy <gabriel.n...@canonical.com> Date: Tue Oct 24 12:47:02 2023 +0300 gp_pol: Allow null data for REG_MULTI_SZ The parser is able to convert data from binary to XML (it generates an empty <Value> tag) but not the other way around. This is a common occurrence for empty multitext fields. Signed-off-by: Gabriel Nagy <gabriel.n...@canonical.com> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: David Mulder <dmul...@samba.org> commit 9c5a924428181604e1abc513415037369e79d75b Author: Gabriel Nagy <gabriel.n...@canonical.com> Date: Tue Oct 24 12:26:42 2023 +0300 gp_pol: Test empty multi_sz roundtrip Signed-off-by: Gabriel Nagy <gabriel.n...@canonical.com> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: David Mulder <dmul...@samba.org> ----------------------------------------------------------------------- Summary of changes: python/samba/gp_parse/gp_pol.py | 6 +++- python/samba/tests/gpo.py | 66 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) Changeset truncated at 500 lines: diff --git a/python/samba/gp_parse/gp_pol.py b/python/samba/gp_parse/gp_pol.py index 8a3d5f58ec1..1d5f348176b 100644 --- a/python/samba/gp_parse/gp_pol.py +++ b/python/samba/gp_parse/gp_pol.py @@ -77,7 +77,11 @@ class GPPolParser(GPParser): if misc.REG_MULTI_SZ == entry_type: values = [x.text for x in e.findall('Value')] - entry.data = (u'\x00'.join(values) + u'\x00\x00').encode('utf-16le') + if values == [None]: + data = u'\x00' + else: + data = u'\x00'.join(values) + u'\x00\x00' + entry.data = data.encode('utf-16le') elif (misc.REG_NONE == entry_type): pass elif (misc.REG_SZ == entry_type or diff --git a/python/samba/tests/gpo.py b/python/samba/tests/gpo.py index d68f11233a6..33be897405b 100644 --- a/python/samba/tests/gpo.py +++ b/python/samba/tests/gpo.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import os, grp, pwd +import os, grp, pwd, re import errno from samba import gpo, tests from samba.gp.gpclass import register_gp_extension, list_gp_extensions, \ @@ -5015,6 +5015,32 @@ drive_maps_xml = b"""<?xml version="1.0" encoding="utf-8"?> </Drives> """ +empty_multi_sz_reg_pol = \ +br""" +<?xml version="1.0" encoding="utf-8"?> +<PolFile num_entries="1" signature="PReg" version="1"> + <Entry type="7" type_name="REG_MULTI_SZ"> + <Key>KeyName</Key> + <ValueName>ValueName</ValueName> + <Value/> + </Entry> +</PolFile> +""" + +multiple_values_multi_sz_reg_pol = \ +br""" +<?xml version="1.0" encoding="utf-8"?> +<PolFile num_entries="1" signature="PReg" version="1"> + <Entry type="7" type_name="REG_MULTI_SZ"> + <Key>KeyName</Key> + <ValueName>ValueName</ValueName> + <Value>Value1</Value> + <Value>Value2</Value> + <Value>Value3</Value> + </Entry> +</PolFile> +""" + def days2rel_nttime(val): seconds = 60 minutes = 60 @@ -8015,3 +8041,41 @@ class GPOTests(tests.TestCase): pass else: self.fail('Undefined variable %s caused no error' % undef_var) + + def test_parser_roundtrip_empty_multi_sz(self): + with TemporaryDirectory() as dname: + reg_pol_xml = os.path.join(dname, 'REGISTRY.POL.XML') + + parser = GPPolParser() + try: + parser.load_xml(etree.fromstring(empty_multi_sz_reg_pol.strip())) + except Exception as e: + self.fail(str(e)) + parser.write_xml(reg_pol_xml) + + with open(reg_pol_xml, 'r') as f: + pol_xml_data = f.read() + + # Strip whitespace characters due to indentation differences + expected_xml_data = re.sub(r"\s+", "", empty_multi_sz_reg_pol.decode(), flags=re.UNICODE) + actual_xml_data = re.sub(r"\s+", "", pol_xml_data, flags=re.UNICODE) + self.assertEqual(expected_xml_data, actual_xml_data, 'XML data mismatch') + + def test_parser_roundtrip_multiple_values_multi_sz(self): + with TemporaryDirectory() as dname: + reg_pol_xml = os.path.join(dname, 'REGISTRY.POL.XML') + + parser = GPPolParser() + try: + parser.load_xml(etree.fromstring(multiple_values_multi_sz_reg_pol.strip())) + except Exception as e: + self.fail(str(e)) + parser.write_xml(reg_pol_xml) + + with open(reg_pol_xml, 'r') as f: + pol_xml_data = f.read() + + # Strip whitespace characters due to indentation differences + expected_xml_data = re.sub(r"\s+", "", multiple_values_multi_sz_reg_pol.decode(), flags=re.UNICODE) + actual_xml_data = re.sub(r"\s+", "", pol_xml_data, flags=re.UNICODE) + self.assertEqual(expected_xml_data, actual_xml_data, 'XML data mismatch') -- Samba Shared Repository