From: Andreas Hasenack Date: Tue, 18 Feb 2025 15:43:46 +0000 (-0300) Subject: python:netcmd:gpo: fix crash when updating an MOTD GPO X-Git-Tag: samba-4.22.1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f76df8a6f02497c3f04622c694f9e2761a84797;p=thirdparty%2Fsamba.git python:netcmd:gpo: fix crash when updating an MOTD GPO When the policy exists already, there is no exception and the code tries to use the "data" variable, but it doesn't exist because it was only defined in the exception handling. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15774 Signed-off-by: Andreas Hasenack Reviewed-by: Douglas Bagnall Reviewed-by: Jennifer Sutton (cherry picked from commit e87e20c04d90292e3a5caac8ea3105b16f948ed3) --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 96fce917f0f..d4f6bad67af 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -3808,7 +3808,9 @@ samba-tool gpo manage motd set {31B2F340-016D-11D2-945F-00C04FB984F9} "Message f return try: - xml_data = ET.fromstring(conn.loadfile(vgp_xml)) + xml_data = ET.ElementTree(ET.fromstring(conn.loadfile(vgp_xml))) + policysetting = xml_data.getroot().find('policysetting') + data = policysetting.find('data') except NTSTATUSError as e: if e.args[0] in [NT_STATUS_OBJECT_NAME_INVALID, NT_STATUS_OBJECT_NAME_NOT_FOUND, @@ -3834,7 +3836,9 @@ samba-tool gpo manage motd set {31B2F340-016D-11D2-945F-00C04FB984F9} "Message f else: raise - text = ET.SubElement(data, 'text') + text = data.find('text') + if text is None: + text = ET.SubElement(data, 'text') text.text = value out = BytesIO() diff --git a/selftest/knownfail.d/samba-tool-gpo b/selftest/knownfail.d/samba-tool-gpo deleted file mode 100644 index e8ab4690fa8..00000000000 --- a/selftest/knownfail.d/samba-tool-gpo +++ /dev/null @@ -1 +0,0 @@ -^samba.tests.samba_tool.gpo.+GpoCmdTestCase.test_vgp_motd_set_thrice