While parsing XML strings from memory, the previous convention in
libvirt was to set the virtual file name to "domain.xml" or something
similar. This could potentialy trick the user into looking for a file
named domain.xml on the disk in an attempt to fix the error.

This patch changes these filenames to something that can't be as easily
confused for a valid filename.
---
For the request for comments:

Shoud we use translation macros around these filename strings? It might be 
possible
to translate these messages in something meaningful in other languages.

Thanks for your comments.

Peter

 src/conf/domain_conf.c        |    2 +-
 src/security/virt-aa-helper.c |    2 +-
 tools/virsh.c                 |   27 ++++++++++++++-------------
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 74f8d6a..bc04732 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7461,7 +7461,7 @@ virDomainDefParse(const char *xmlStr,
     xmlDocPtr xml;
     virDomainDefPtr def = NULL;

-    if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
+    if ((xml = virXMLParse(filename, xmlStr, "DOMAIN_DEFINITION_XML"))) {
         def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
                                     expectedVirtTypes, flags);
         xmlFreeDoc(xml);
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index bb577d3..e460845 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -641,7 +641,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
     xmlDocPtr xml = NULL;
     xmlXPathContextPtr ctxt = NULL;

-    if (!(xml = virXMLParseStringCtxt(xmlStr, "domain.xml", &ctxt))) {
+    if (!(xml = virXMLParseStringCtxt(xmlStr, "DOMAIN_DEFINITION_XML", 
&ctxt))) {
         goto cleanup;
     }

diff --git a/tools/virsh.c b/tools/virsh.c
index 629233f..2da83d0 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1309,7 +1309,7 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
         flags = VIR_DOMAIN_AFFECT_CONFIG;

     /* extract current network device description */
-    xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
+    xml = virXMLParseStringCtxt(desc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(desc);
     if (!xml) {
         vshError(ctl, _("Failed to parse domain description xml"));
@@ -1457,7 +1457,7 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }

-    xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
+    xml = virXMLParseStringCtxt(desc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(desc);
     if (!xml) {
         vshError(ctl, _("Failed to parse domain description xml"));
@@ -1666,7 +1666,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
     if (!xml)
         goto cleanup;

-    xmldoc = virXMLParseStringCtxt(xml, "domain.xml", &ctxt);
+    xmldoc = virXMLParseStringCtxt(xml, "DOMAIN_DEFINITION_XML", &ctxt);
     if (!xmldoc)
         goto cleanup;

@@ -3496,7 +3496,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
             goto cleanup;
         }

-        xml = virXMLParseStringCtxt(cap_xml, "node.xml", &ctxt);
+        xml = virXMLParseStringCtxt(cap_xml, "CAPABILITIES_XML", &ctxt);
         if (!xml) {
             vshError(ctl, "%s", _("unable to get node capabilities"));
             goto cleanup;
@@ -9036,7 +9036,8 @@ cleanup:
 }

 static xmlChar *
-makeCloneXML(const char *origxml, const char *newname) {
+makeCloneXML(const char *origxml, const char *newname)
+{

     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -9044,7 +9045,7 @@ makeCloneXML(const char *origxml, const char *newname) {
     xmlChar *newxml = NULL;
     int size;

-    doc = virXMLParseStringCtxt(origxml, "domain.xml", &ctxt);
+    doc = virXMLParseStringCtxt(origxml, "VOLUME_DEFINITION_XML", &ctxt);
     if (!doc)
         goto cleanup;

@@ -10835,7 +10836,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
     if (!doc)
         goto cleanup;

-    xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+    xml = virXMLParseStringCtxt(doc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(doc);
     if (!xml)
         goto cleanup;
@@ -10903,7 +10904,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
     if (!doc)
         goto cleanup;

-    xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+    xml = virXMLParseStringCtxt(doc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(doc);
     if (!xml)
         goto cleanup;
@@ -11290,7 +11291,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     if (!doc)
         goto cleanup;

-    xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+    xml = virXMLParseStringCtxt(doc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(doc);
     if (!xml) {
         vshError(ctl, "%s", _("Failed to get interface information"));
@@ -11757,7 +11758,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
     if (!doc)
         goto cleanup;

-    xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
+    xml = virXMLParseStringCtxt(doc, "DOMAIN_DEFINITION_XML", &ctxt);
     VIR_FREE(doc);
     if (!xml) {
         vshError(ctl, "%s", _("Failed to get disk information"));
@@ -12908,7 +12909,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
             xmlDocPtr xmldoc = NULL;
             xmlXPathContextPtr ctxt = NULL;

-            xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
+            xmldoc = virXMLParseStringCtxt(xml, "DOMAIN_SNAPSHOT_XML", &ctxt);
             if (!xmldoc)
                 goto cleanup;

@@ -13050,7 +13051,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
             if (!doc)
                 continue;

-            xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
+            xml = virXMLParseStringCtxt(doc, "DOMAIN_SNAPSHOT_XML", &ctxt);
             if (!xml)
                 continue;

@@ -13211,7 +13212,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
     if (!xml)
         goto cleanup;

-    xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
+    xmldoc = virXMLParseStringCtxt(xml, "DOMAIN_SNAPSHOT_XML", &ctxt);
     if (!xmldoc)
         goto cleanup;

-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to