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