[PATCH 4/4] qemu: Add support for change-vnc-password

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

 



Rather than use the to be deprecated "change" command, use the
change-vnc-password command to perform VNC password changes instead
of the set_password command. Since changing VNC password only
accepts "keep" for connect and that's the default, no sense in
vectoring through "set_password" as we've already checked that the
XML 'connected' was set to "keep" in virDomainGraphicsAuthDefParseXML.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c      | 10 +++++++++-
 src/qemu/qemu_monitor.c      | 15 +++++++++++++++
 src/qemu/qemu_monitor.h      |  2 ++
 src/qemu/qemu_monitor_json.c | 28 ++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  2 ++
 tests/qemumonitorjsontest.c  |  2 ++
 6 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0ee9b2bfc..a012b3dcd 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -5333,7 +5333,15 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         goto cleanup;
-    ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
+
+    /* The connected parameter can only be keep for VNC, thus QMP command
+     * set_password makes the same call hence if available just use the
+     * newer change-vnc-password command. */
+    if (type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
+        virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CHANGE_VNC_PASSWORD))
+        ret = qemuMonitorSetVNCPassword(priv->mon, password);
+    else
+        ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
 
     if (ret == -2) {
         if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 56c8345d5..c88634a38 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2387,6 +2387,21 @@ qemuMonitorSetVNCPasswordLegacy(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
+                          const char *password)
+{
+    VIR_DEBUG("password=%p", password);
+
+    QEMU_CHECK_MONITOR_JSON(mon);
+
+    if (!password)
+        password = "";
+
+    return qemuMonitorJSONSetVNCPassword(mon, password);
+}
+
+
 static const char *
 qemuMonitorTypeToProtocol(int type)
 {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index cf9ab7cb3..eeae72928 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -597,6 +597,8 @@ int qemuMonitorBlockResize(qemuMonitorPtr mon,
                            unsigned long long size);
 int qemuMonitorSetVNCPasswordLegacy(qemuMonitorPtr mon,
                                     const char *password);
+int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
+                              const char *password);
 int qemuMonitorSetPassword(qemuMonitorPtr mon,
                            int type,
                            const char *password,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index ad81b70db..f8131ac4d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2384,6 +2384,34 @@ qemuMonitorJSONSetVNCPasswordLegacy(qemuMonitorPtr mon,
     return ret;
 }
 
+
+int
+qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
+                              const char *password)
+{
+    int ret = -1;
+    virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("change-vnc-password",
+                                                     "s:password", password,
+                                                     NULL);
+    virJSONValuePtr reply = NULL;
+
+    if (!cmd)
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 /* Returns -1 on error, -2 if not supported */
 int qemuMonitorJSONSetPassword(qemuMonitorPtr mon,
                                const char *protocol,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index dec7a5cf9..b3254ac05 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -94,6 +94,8 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSetVNCPasswordLegacy(qemuMonitorPtr mon,
                                         const char *password);
+int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
+                                  const char *password);
 int qemuMonitorJSONSetPassword(qemuMonitorPtr mon,
                                const char *protocol,
                                const char *password,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index f9c59f2f0..6d33333a0 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1317,6 +1317,7 @@ cleanup: \
 GEN_TEST_FUNC(qemuMonitorJSONSetLink, "vnet0", VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
 GEN_TEST_FUNC(qemuMonitorJSONBlockResize, "vda", 123456)
 GEN_TEST_FUNC(qemuMonitorJSONSetVNCPasswordLegacy, "secret_password")
+GEN_TEST_FUNC(qemuMonitorJSONSetVNCPassword, "secret_password")
 GEN_TEST_FUNC(qemuMonitorJSONSetPassword, "spice", "secret_password", "disconnect")
 GEN_TEST_FUNC(qemuMonitorJSONExpirePassword, "spice", "123456")
 GEN_TEST_FUNC(qemuMonitorJSONSetBalloon, 1024)
@@ -2906,6 +2907,7 @@ mymain(void)
     DO_TEST_GEN(qemuMonitorJSONSetLink);
     DO_TEST_GEN(qemuMonitorJSONBlockResize);
     DO_TEST_GEN(qemuMonitorJSONSetVNCPasswordLegacy);
+    DO_TEST_GEN(qemuMonitorJSONSetVNCPassword);
     DO_TEST_GEN(qemuMonitorJSONSetPassword);
     DO_TEST_GEN(qemuMonitorJSONExpirePassword);
     DO_TEST_GEN(qemuMonitorJSONSetBalloon);
-- 
2.13.6

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux