render / rpms / qemu

Forked from rpms/qemu 9 months ago
Clone

Blame 0407-Add-SPICE-support-to-add_client-monitor-command.patch

Hans de Goede 56753f
From 9ada192cfea65a92a765c6a2f6b56a08f1b865df Mon Sep 17 00:00:00 2001
Hans de Goede 56753f
From: "Daniel P. Berrange" <berrange@redhat.com>
Hans de Goede 56753f
Date: Mon, 13 Feb 2012 13:43:08 +0000
Hans de Goede 56753f
Subject: [PATCH 407/434] Add SPICE support to add_client monitor command
Hans de Goede 56753f
Hans de Goede 56753f
With the acceptance of some new APIs to libspice-server.so it
Hans de Goede 56753f
is possible to add support for SPICE to the 'add_client'
Hans de Goede 56753f
monitor command, bringing parity with VNC. Since SPICE can
Hans de Goede 56753f
use TLS or plain connections, the command also gains a new
Hans de Goede 56753f
'tls' parameter to specify whether TLS should be attempted
Hans de Goede 56753f
on the injected client sockets.
Hans de Goede 56753f
Hans de Goede 56753f
This new feature is only enabled if building against a
Hans de Goede 56753f
libspice-server >= 0.10.1
Hans de Goede 56753f
Hans de Goede 56753f
* qmp-commands.hx: Add 'tls' parameter & missing doc for
Hans de Goede 56753f
  'skipauth' parameter
Hans de Goede 56753f
* monitor.c: Wire up SPICE for 'add_client' command
Hans de Goede 56753f
* ui/qemu-spice.h, ui/spice-core.c: Add qemu_spice_display_add_client
Hans de Goede 56753f
  API to wire up from monitor
Hans de Goede 56753f
Hans de Goede 56753f
[1] http://cgit.freedesktop.org/spice/spice/commit/server/spice.h?id=d55b68b6b44f2499278fa860fb47ff22f5011faa
Hans de Goede 56753f
    http://cgit.freedesktop.org/spice/spice/commit/server/spice.h?id=bd07dde530d9504e1cfe7ed5837fc00c26f36716
Hans de Goede 56753f
Hans de Goede 56753f
Changes in v3:
Hans de Goede 56753f
 - Added 'optional' flag to new parameters documented
Hans de Goede 56753f
 - Added no-op impl of qemu_spice_display_add_client when
Hans de Goede 56753f
   SPICE is disabled during build
Hans de Goede 56753f
Hans de Goede 56753f
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Hans de Goede 56753f
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Hans de Goede 56753f
---
Hans de Goede 56753f
 monitor.c       |    9 +++++++--
Hans de Goede 56753f
 qmp-commands.hx |    6 ++++--
Hans de Goede 56753f
 ui/qemu-spice.h |    7 +++++++
Hans de Goede 56753f
 ui/spice-core.c |   13 +++++++++++++
Hans de Goede 56753f
 4 files changed, 31 insertions(+), 4 deletions(-)
Hans de Goede 56753f
Hans de Goede 56753f
diff --git a/monitor.c b/monitor.c
Hans de Goede 56753f
index a82fda3..3c23aa4 100644
Hans de Goede 56753f
--- a/monitor.c
Hans de Goede 56753f
+++ b/monitor.c
Hans de Goede 56753f
@@ -998,13 +998,18 @@ static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_d
Hans de Goede 56753f
     CharDriverState *s;
Hans de Goede 56753f
 
Hans de Goede 56753f
     if (strcmp(protocol, "spice") == 0) {
Hans de Goede 56753f
+        int fd = monitor_get_fd(mon, fdname);
Hans de Goede 56753f
+        int skipauth = qdict_get_try_bool(qdict, "skipauth", 0);
Hans de Goede 56753f
+        int tls = qdict_get_try_bool(qdict, "tls", 0);
Hans de Goede 56753f
         if (!using_spice) {
Hans de Goede 56753f
             /* correct one? spice isn't a device ,,, */
Hans de Goede 56753f
             qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
Hans de Goede 56753f
             return -1;
Hans de Goede 56753f
         }
Hans de Goede 56753f
-	qerror_report(QERR_ADD_CLIENT_FAILED);
Hans de Goede 56753f
-	return -1;
Hans de Goede 56753f
+        if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
Hans de Goede 56753f
+            close(fd);
Hans de Goede 56753f
+        }
Hans de Goede 56753f
+        return 0;
Hans de Goede 56753f
 #ifdef CONFIG_VNC
Hans de Goede 56753f
     } else if (strcmp(protocol, "vnc") == 0) {
Hans de Goede 56753f
 	int fd = monitor_get_fd(mon, fdname);
Hans de Goede 56753f
diff --git a/qmp-commands.hx b/qmp-commands.hx
Hans de Goede 56753f
index 97975a5..122b10d 100644
Hans de Goede 56753f
--- a/qmp-commands.hx
Hans de Goede 56753f
+++ b/qmp-commands.hx
Hans de Goede 56753f
@@ -909,8 +909,8 @@ EQMP
Hans de Goede 56753f
 
Hans de Goede 56753f
     {
Hans de Goede 56753f
         .name       = "add_client",
Hans de Goede 56753f
-        .args_type  = "protocol:s,fdname:s,skipauth:b?",
Hans de Goede 56753f
-        .params     = "protocol fdname skipauth",
Hans de Goede 56753f
+        .args_type  = "protocol:s,fdname:s,skipauth:b?,tls:b?",
Hans de Goede 56753f
+        .params     = "protocol fdname skipauth tls",
Hans de Goede 56753f
         .help       = "add a graphics client",
Hans de Goede 56753f
         .user_print = monitor_user_noop,
Hans de Goede 56753f
         .mhandler.cmd_new = add_graphics_client,
Hans de Goede 56753f
@@ -926,6 +926,8 @@ Arguments:
Hans de Goede 56753f
 
Hans de Goede 56753f
 - "protocol": protocol name (json-string)
Hans de Goede 56753f
 - "fdname": file descriptor name (json-string)
Hans de Goede 56753f
+- "skipauth": whether to skip authentication (json-bool, optional)
Hans de Goede 56753f
+- "tls": whether to perform TLS (json-bool, optional)
Hans de Goede 56753f
 
Hans de Goede 56753f
 Example:
Hans de Goede 56753f
 
Hans de Goede 56753f
diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h
Hans de Goede 56753f
index c35b29c..680206a 100644
Hans de Goede 56753f
--- a/ui/qemu-spice.h
Hans de Goede 56753f
+++ b/ui/qemu-spice.h
Hans de Goede 56753f
@@ -33,6 +33,7 @@ void qemu_spice_init(void);
Hans de Goede 56753f
 void qemu_spice_input_init(void);
Hans de Goede 56753f
 void qemu_spice_audio_init(void);
Hans de Goede 56753f
 void qemu_spice_display_init(DisplayState *ds);
Hans de Goede 56753f
+int qemu_spice_display_add_client(int csock, int skipauth, int tls);
Hans de Goede 56753f
 int qemu_spice_add_interface(SpiceBaseInstance *sin);
Hans de Goede 56753f
 int qemu_spice_set_passwd(const char *passwd,
Hans de Goede 56753f
                           bool fail_if_connected, bool disconnect_if_connected);
Hans de Goede 56753f
@@ -68,6 +69,12 @@ static inline int qemu_spice_migrate_info(const char *h, int p, int t,
Hans de Goede 56753f
     return -1;
Hans de Goede 56753f
 }
Hans de Goede 56753f
 
Hans de Goede 56753f
+static inline int qemu_spice_display_add_client(int csock, int skipauth,
Hans de Goede 56753f
+                                                int tls)
Hans de Goede 56753f
+{
Hans de Goede 56753f
+    return -1;
Hans de Goede 56753f
+}
Hans de Goede 56753f
+
Hans de Goede 56753f
 #endif /* CONFIG_SPICE */
Hans de Goede 56753f
 
Hans de Goede 56753f
 #endif /* QEMU_SPICE_H */
Hans de Goede 56753f
diff --git a/ui/spice-core.c b/ui/spice-core.c
Hans de Goede 56753f
index 5639c6f..d98863e 100644
Hans de Goede 56753f
--- a/ui/spice-core.c
Hans de Goede 56753f
+++ b/ui/spice-core.c
Hans de Goede 56753f
@@ -747,6 +747,19 @@ int qemu_spice_set_pw_expire(time_t expires)
Hans de Goede 56753f
     return qemu_spice_set_ticket(false, false);
Hans de Goede 56753f
 }
Hans de Goede 56753f
 
Hans de Goede 56753f
+int qemu_spice_display_add_client(int csock, int skipauth, int tls)
Hans de Goede 56753f
+{
Hans de Goede 56753f
+#if SPICE_SERVER_VERSION >= 0x000a01
Hans de Goede 56753f
+    if (tls) {
Hans de Goede 56753f
+        return spice_server_add_ssl_client(spice_server, csock, skipauth);
Hans de Goede 56753f
+    } else {
Hans de Goede 56753f
+        return spice_server_add_client(spice_server, csock, skipauth);
Hans de Goede 56753f
+    }
Hans de Goede 56753f
+#else
Hans de Goede 56753f
+    return -1;
Hans de Goede 56753f
+#endif
Hans de Goede 56753f
+}
Hans de Goede 56753f
+
Hans de Goede 56753f
 static void spice_register_config(void)
Hans de Goede 56753f
 {
Hans de Goede 56753f
     qemu_add_opts(&qemu_spice_opts);
Hans de Goede 56753f
-- 
Hans de Goede 56753f
1.7.10
Hans de Goede 56753f