[virt-tools-list] [PATCH virt-viewer] spice: ask credentials for proxy

Marc-André Lureau marcandre.lureau at gmail.com
Fri Feb 21 12:02:25 UTC 2014


From: Marc-André Lureau <marcandre.lureau at redhat.com>

If Spice proxy requires authentication, ask credentials and try
connecting again.
---
 configure.ac                    |  3 +--
 src/virt-viewer-session-spice.c | 38 +++++++++++++++++++++++++++++++-------
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7a00bf4..5ee49fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,3 @@
-
 AC_INIT([virt-viewer],[0.6.0])
 AC_CONFIG_SRCDIR(src/virt-viewer-main.c)
 AC_CONFIG_MACRO_DIR([m4])
@@ -19,7 +18,7 @@ GTK2_REQUIRED="2.18.0"
 GTK3_REQUIRED="3.0"
 GTK_VNC1_REQUIRED="0.3.8"
 GTK_VNC2_REQUIRED="0.4.0"
-SPICE_GTK_REQUIRED="0.22"
+SPICE_GTK_REQUIRED="0.23.21"
 SPICE_PROTOCOL_REQUIRED="0.10.1"
 GOVIRT_REQUIRED="0.3.0"
 
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index de5edf7..112f05b 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -29,6 +29,7 @@
 
 #include <spice-option.h>
 #include <spice-util.h>
+#include <spice-uri.h>
 #include <usb-device-widget.h>
 #include "virt-viewer-file.h"
 #include "virt-viewer-util.h"
@@ -471,8 +472,10 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
                                              SpiceChannelEvent event,
                                              VirtViewerSession *session)
 {
+    const GError *error;
     VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session);
-    gchar *password = NULL;
+    gchar *password = NULL, *user = NULL;
+    int ret;
 
     g_return_if_fail(self != NULL);
 
@@ -499,10 +502,10 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
                                   _("invalid password"));
         self->priv->pass_try++;
 
-        int ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
-                                                       "SPICE",
-                                                       NULL,
-                                                       NULL, &password);
+        ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                   "SPICE",
+                                                   NULL,
+                                                   NULL, &password);
         if (ret < 0) {
             g_signal_emit_by_name(session, "session-cancelled");
         } else {
@@ -518,8 +521,28 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
         }
         break;
     case SPICE_CHANNEL_ERROR_CONNECT:
-        DEBUG_LOG("main channel: failed to connect");
-        g_signal_emit_by_name(session, "session-disconnected");
+        error = spice_channel_get_error(channel);
+
+        DEBUG_LOG("main channel: failed to connect %s", error ? error->message : "");
+
+        if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_PROXY_NEED_AUTH) ||
+            g_error_matches(error, G_IO_ERROR, G_IO_ERROR_PROXY_AUTH_FAILED)) {
+            SpiceURI *proxy = spice_session_get_proxy_uri(self->priv->session);
+            g_warn_if_fail(proxy != NULL);
+
+            ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
+                                                       "proxy", NULL,
+                                                       &user, &password);
+            if (ret < 0) {
+                g_signal_emit_by_name(session, "session-cancelled");
+            } else {
+                spice_uri_set_user(proxy, user);
+                spice_uri_set_password(proxy, password);
+                spice_session_connect(self->priv->session);
+            }
+        } else {
+            g_signal_emit_by_name(session, "session-disconnected");
+        }
         break;
     case SPICE_CHANNEL_ERROR_IO:
     case SPICE_CHANNEL_ERROR_LINK:
@@ -532,6 +555,7 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
     }
 
     g_free(password);
+    g_free(user);
 }
 
 static void remove_cb(GtkContainer   *container G_GNUC_UNUSED,
-- 
1.8.5.3




More information about the virt-tools-list mailing list