From: Garming Sam Date: Tue, 12 Jun 2018 04:19:41 +0000 (+1200) Subject: gpo: Make restore with entities more robust X-Git-Tag: tdb-1.3.17~2149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cedfea1b077a7cb068d884e17f2d9c22e7e97cd5;p=thirdparty%2Fsamba.git gpo: Make restore with entities more robust Sometimes the restore fails for unknown reasons, but rearranging the XML such that the DTD is after the xml header appears to fix it. This might be the case in certain files where no entities are used perhaps. This could probably be made more tolerant using regex, but for the most part we expect the fixed output from the minidom pretty-printed XML. Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index 92526965ccc..1fc25bd6f1b 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -1310,8 +1310,17 @@ class cmd_restore(cmd_create): try: with open(l_name, 'r') as ltemp: data = ltemp.read() - # Load the XML file with the DTD (entity) header - parser.load_xml(ET.fromstring(dtd_header + data)) + xml_head = '' + + if data.startswith(xml_head): + # It appears that sometimes the DTD rejects + # the xml header being after it. + data = data[len(xml_head):] + + # Load the XML file with the DTD (entity) header + parser.load_xml(ET.fromstring(xml_head + dtd_header + data)) + else: + parser.load_xml(ET.fromstring(dtd_header + data)) # Write out the substituted files in the output # location, ready to copy over.