summaryrefslogtreecommitdiff
path: root/xml.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-23 19:59:08 -0500
committerJeff Carr <[email protected]>2024-10-23 19:59:08 -0500
commit37a053dae99e7efb8858ffcc27b19a7b319136ad (patch)
tree4802618507076f969d9ea7f36f0de57a49a8a124 /xml.go
parentd09f4e25c25dced54d688597b5e9a903c456573d (diff)
check xml domain name vs xml filename
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'xml.go')
-rw-r--r--xml.go12
1 files changed, 12 insertions, 0 deletions
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
}