[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] conf: Check migration_host is valid or not during libvirt restarts



if user specified an invalid strings as migration hostname,
like setting: migration_host = "XXXXXXX", libvirt should check
it and return error during lbivirt restart.

Signed-off-by: Chen Fan <chen fan fnst cn fujitsu com>
---
 src/qemu/qemu_conf.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index e2ec54f..450ac5b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include <sys/wait.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 #include "virerror.h"
 #include "qemu_conf.h"
@@ -650,6 +651,45 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
     GET_VALUE_LONG("seccomp_sandbox", cfg->seccompSandbox);
 
     GET_VALUE_STR("migration_host", cfg->migrateHost);
+    if (cfg->migrateHost) {
+        struct addrinfo hints;
+        struct addrinfo *res;
+
+        memset(&hints, 0, sizeof(hints));
+        hints.ai_flags = AI_ADDRCONFIG;
+        hints.ai_family = AF_UNSPEC;
+
+        if (getaddrinfo(cfg->migrateHost, NULL, &hints, &res) != 0) {
+            virReportError(VIR_ERR_CONF_SYNTAX,
+                           _("migration_host: '%s' is not a valid hostname"),
+                           cfg->migrateHost);
+            goto cleanup;
+        }
+
+        if (res == NULL) {
+            virReportError(VIR_ERR_CONF_SYNTAX,
+                           _("No IP address for host '%s' found"),
+                           cfg->migrateHost);
+            goto cleanup;
+        }
+
+        freeaddrinfo(res);
+
+        if (STRPREFIX(cfg->migrateHost, "localhost")) {
+            virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+                           _("setting migration_host to 'localhost' is not allowed"));
+            goto cleanup;
+        }
+
+        if (STREQ(cfg->migrateHost, "127.0.0.1") ||
+            STREQ(cfg->migrateHost, "::1")) {
+            virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+                           _("setting migration_host to '127.0.0.1' or '::1' "
+                             "is not allowed"));
+            goto cleanup;
+        }
+    }
+
     GET_VALUE_STR("migration_address", cfg->migrationAddress);
 
     GET_VALUE_BOOL("log_timestamp", cfg->logTimestamp);
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]