1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-23 00:23:53 +03:00

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 <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Garming Sam
2018-06-12 16:19:41 +12:00
committed by Andrew Bartlett
parent 9977b4bc7c
commit cedfea1b07

View File

@@ -1310,8 +1310,17 @@ class cmd_restore(cmd_create):
try: try:
with open(l_name, 'r') as ltemp: with open(l_name, 'r') as ltemp:
data = ltemp.read() data = ltemp.read()
# Load the XML file with the DTD (entity) header xml_head = '<?xml version="1.0" encoding="utf-8"?>'
parser.load_xml(ET.fromstring(dtd_header + data))
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 # Write out the substituted files in the output
# location, ready to copy over. # location, ready to copy over.