From 37a053dae99e7efb8858ffcc27b19a7b319136ad Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 23 Oct 2024 19:59:08 -0500 Subject: [PATCH] check xml domain name vs xml filename Signed-off-by: Jeff Carr --- xml.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xml.go b/xml.go index 1654dfa..4035a85 100644 --- a/xml.go +++ b/xml.go @@ -6,7 +6,9 @@ import ( "encoding/xml" "fmt" "os" + "path/filepath" "reflect" + "strings" "go.wit.com/log" "libvirt.org/go/libvirtxml" @@ -76,6 +78,9 @@ func addDefaults(d *libvirtxml.Domain, filename string) { func readXml(filename string) (*libvirtxml.Domain, error) { log.Verbose("parse xml file:", filename) + hostname := filepath.Base(filename) + hostname = strings.TrimSuffix(hostname, ".xml") + pfile, err := os.ReadFile(filename) if err != nil { log.Println("ERROR:", err) @@ -89,6 +94,13 @@ func readXml(filename string) (*libvirtxml.Domain, error) { log.Info("Marshal failed on file", filename, err) return nil, ErrorParseXML } + + if domcfg.Name != hostname { + log.Info("ERROR: domcfg.Name != name", domcfg.Name, hostname) + log.Info("ERROR: xml filenames must match the xml name") + os.Exit(-1) + } + return domcfg, nil }