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: tevent-0.17.0~515 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e87e20c04d90292e3a5caac8ea3105b16f948ed3;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 --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index dbb948d9889..9c22b03a39e 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -3811,7 +3811,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, @@ -3837,7 +3839,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