Blame SOURCES/0084-Move-vnc-specific-auth-logic-to-VirtViewerSessionVnc.patch

4ab194
From 25ef080ac79f31002259a050944079bb9672f5ea Mon Sep 17 00:00:00 2001
4ab194
From: Jonathon Jongsma <jjongsma@redhat.com>
4ab194
Date: Fri, 31 Jan 2014 11:31:33 -0600
4ab194
Subject: [PATCH] Move vnc-specific auth logic to VirtViewerSessionVnc
4ab194
4ab194
Conflicts:
4ab194
	src/virt-viewer-auth.c
4ab194
(cherry picked from commit dce19b379ad65a0d0edef6dfce19f1177eb082c6)
4ab194
---
4ab194
 src/virt-viewer-auth.c        | 97 -------------------------------------------
4ab194
 src/virt-viewer-auth.h        |  6 ---
4ab194
 src/virt-viewer-session-vnc.c | 92 +++++++++++++++++++++++++++++++++++++---
4ab194
 3 files changed, 86 insertions(+), 109 deletions(-)
4ab194
4ab194
diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
4ab194
index bb03516..a796619 100644
4ab194
--- a/src/virt-viewer-auth.c
4ab194
+++ b/src/virt-viewer-auth.c
4ab194
@@ -105,103 +105,6 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
4ab194
     return response == GTK_RESPONSE_OK ? 0 : -1;
4ab194
 }
4ab194
 
4ab194
-#ifdef HAVE_GTK_VNC
4ab194
-void
4ab194
-virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
4ab194
-                                 GtkWindow *window,
4ab194
-                                 GtkWidget *vnc,
4ab194
-                                 GValueArray *credList,
4ab194
-                                 char *vncAddress)
4ab194
-{
4ab194
-    char *username = NULL, *password = NULL;
4ab194
-    gboolean wantPassword = FALSE, wantUsername = FALSE;
4ab194
-    int i;
4ab194
-
4ab194
-    g_debug("Got VNC credential request for %d credential(s)", credList->n_values);
4ab194
-
4ab194
-    for (i = 0 ; i < credList->n_values ; i++) {
4ab194
-        GValue *cred = g_value_array_get_nth(credList, i);
4ab194
-        switch (g_value_get_enum(cred)) {
4ab194
-        case VNC_DISPLAY_CREDENTIAL_USERNAME:
4ab194
-            wantUsername = TRUE;
4ab194
-            break;
4ab194
-        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
4ab194
-            wantPassword = TRUE;
4ab194
-            break;
4ab194
-        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
4ab194
-            break;
4ab194
-        default:
4ab194
-            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
4ab194
-            vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-            goto cleanup;
4ab194
-        }
4ab194
-    }
4ab194
-
4ab194
-    VirtViewerFile *file = virt_viewer_session_get_file(session);
4ab194
-    if (file != NULL) {
4ab194
-        if (wantUsername && virt_viewer_file_is_set(file, "username")) {
4ab194
-            username = virt_viewer_file_get_username(file);
4ab194
-            wantUsername = FALSE;
4ab194
-        }
4ab194
-        if (wantPassword && virt_viewer_file_is_set(file, "password")) {
4ab194
-            password = virt_viewer_file_get_password(file);
4ab194
-            wantPassword = FALSE;
4ab194
-        }
4ab194
-    }
4ab194
-
4ab194
-    if (wantUsername || wantPassword) {
4ab194
-        int ret = virt_viewer_auth_collect_credentials(window,
4ab194
-                                                       "VNC", vncAddress,
4ab194
-                                                       wantUsername ? &username : NULL,
4ab194
-                                                       wantPassword ? &password : NULL);
4ab194
-
4ab194
-        if (ret < 0) {
4ab194
-            vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-            goto cleanup;
4ab194
-        }
4ab194
-    }
4ab194
-
4ab194
-    for (i = 0 ; i < credList->n_values ; i++) {
4ab194
-        GValue *cred = g_value_array_get_nth(credList, i);
4ab194
-        switch (g_value_get_enum(cred)) {
4ab194
-        case VNC_DISPLAY_CREDENTIAL_USERNAME:
4ab194
-            if (!username ||
4ab194
-                vnc_display_set_credential(VNC_DISPLAY(vnc),
4ab194
-                                           g_value_get_enum(cred),
4ab194
-                                           username)) {
4ab194
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
-                vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-            }
4ab194
-            break;
4ab194
-        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
4ab194
-            if (!password ||
4ab194
-                vnc_display_set_credential(VNC_DISPLAY(vnc),
4ab194
-                                           g_value_get_enum(cred),
4ab194
-                                           password)) {
4ab194
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
-                vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-            }
4ab194
-            break;
4ab194
-        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
4ab194
-            if (vnc_display_set_credential(VNC_DISPLAY(vnc),
4ab194
-                                           g_value_get_enum(cred),
4ab194
-                                           "libvirt")) {
4ab194
-                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
-                vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-            }
4ab194
-            break;
4ab194
-        default:
4ab194
-            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
4ab194
-            vnc_display_close(VNC_DISPLAY(vnc));
4ab194
-        }
4ab194
-    }
4ab194
-
4ab194
- cleanup:
4ab194
-    g_free(username);
4ab194
-    g_free(password);
4ab194
-}
4ab194
-#endif
4ab194
-
4ab194
 /*
4ab194
  * Local variables:
4ab194
  *  c-indent-level: 4
4ab194
diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
4ab194
index 1f102e0..ad932c5 100644
4ab194
--- a/src/virt-viewer-auth.h
4ab194
+++ b/src/virt-viewer-auth.h
4ab194
@@ -32,12 +32,6 @@
4ab194
 #include "virt-viewer-session.h"
4ab194
 #include "virt-viewer-util.h"
4ab194
 
4ab194
-void virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
4ab194
-                                      GtkWindow *window,
4ab194
-                                      GtkWidget *vnc,
4ab194
-                                      GValueArray *credList,
4ab194
-                                      char *vncAddress);
4ab194
-
4ab194
 int virt_viewer_auth_collect_credentials(GtkWindow *window,
4ab194
                                          const char *type,
4ab194
                                          const char *address,
4ab194
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
4ab194
index 1e82fbb..3f4c90d 100644
4ab194
--- a/src/virt-viewer-session-vnc.c
4ab194
+++ b/src/virt-viewer-session-vnc.c
4ab194
@@ -254,17 +254,97 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
4ab194
 
4ab194
 
4ab194
 static void
4ab194
-virt_viewer_session_vnc_auth_credential(GtkWidget *src,
4ab194
+virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
4ab194
                                         GValueArray *credList,
4ab194
                                         VirtViewerSession *session)
4ab194
 {
4ab194
     VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session);
4ab194
+    char *username = NULL, *password = NULL;
4ab194
+    gboolean wantPassword = FALSE, wantUsername = FALSE;
4ab194
+    int i;
4ab194
+
4ab194
+    g_debug("Got VNC credential request for %d credential(s)", credList->n_values);
4ab194
+
4ab194
+    for (i = 0 ; i < credList->n_values ; i++) {
4ab194
+        GValue *cred = g_value_array_get_nth(credList, i);
4ab194
+        switch (g_value_get_enum(cred)) {
4ab194
+        case VNC_DISPLAY_CREDENTIAL_USERNAME:
4ab194
+            wantUsername = TRUE;
4ab194
+            break;
4ab194
+        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
4ab194
+            wantPassword = TRUE;
4ab194
+            break;
4ab194
+        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
4ab194
+            break;
4ab194
+        default:
4ab194
+            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
4ab194
+            vnc_display_close(self->priv->vnc);
4ab194
+            goto cleanup;
4ab194
+        }
4ab194
+    }
4ab194
+
4ab194
+    VirtViewerFile *file = virt_viewer_session_get_file(VIRT_VIEWER_SESSION(self));
4ab194
+    if (file != NULL) {
4ab194
+        if (wantUsername && virt_viewer_file_is_set(file, "username")) {
4ab194
+            username = virt_viewer_file_get_username(file);
4ab194
+            wantUsername = FALSE;
4ab194
+        }
4ab194
+        if (wantPassword && virt_viewer_file_is_set(file, "password")) {
4ab194
+            password = virt_viewer_file_get_password(file);
4ab194
+            wantPassword = FALSE;
4ab194
+        }
4ab194
+    }
4ab194
+
4ab194
+    if (wantUsername || wantPassword) {
4ab194
+        int ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
4ab194
+                                                       "VNC", NULL,
4ab194
+                                                       wantUsername ? &username : NULL,
4ab194
+                                                       wantPassword ? &password : NULL);
4ab194
+
4ab194
+        if (ret < 0) {
4ab194
+            vnc_display_close(self->priv->vnc);
4ab194
+            goto cleanup;
4ab194
+        }
4ab194
+    }
4ab194
+
4ab194
+    for (i = 0 ; i < credList->n_values ; i++) {
4ab194
+        GValue *cred = g_value_array_get_nth(credList, i);
4ab194
+        switch (g_value_get_enum(cred)) {
4ab194
+        case VNC_DISPLAY_CREDENTIAL_USERNAME:
4ab194
+            if (!username ||
4ab194
+                vnc_display_set_credential(self->priv->vnc,
4ab194
+                                           g_value_get_enum(cred),
4ab194
+                                           username)) {
4ab194
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
+                vnc_display_close(self->priv->vnc);
4ab194
+            }
4ab194
+            break;
4ab194
+        case VNC_DISPLAY_CREDENTIAL_PASSWORD:
4ab194
+            if (!password ||
4ab194
+                vnc_display_set_credential(self->priv->vnc,
4ab194
+                                           g_value_get_enum(cred),
4ab194
+                                           password)) {
4ab194
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
+                vnc_display_close(self->priv->vnc);
4ab194
+            }
4ab194
+            break;
4ab194
+        case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
4ab194
+            if (vnc_display_set_credential(self->priv->vnc,
4ab194
+                                           g_value_get_enum(cred),
4ab194
+                                           "libvirt")) {
4ab194
+                g_debug("Failed to set credential type %d", g_value_get_enum(cred));
4ab194
+                vnc_display_close(self->priv->vnc);
4ab194
+            }
4ab194
+            break;
4ab194
+        default:
4ab194
+            g_debug("Unsupported credential type %d", g_value_get_enum(cred));
4ab194
+            vnc_display_close(self->priv->vnc);
4ab194
+        }
4ab194
+    }
4ab194
 
4ab194
-    virt_viewer_auth_vnc_credentials(session,
4ab194
-                                     self->priv->main_window,
4ab194
-                                     src,
4ab194
-                                     credList,
4ab194
-                                     NULL);
4ab194
+ cleanup:
4ab194
+    g_free(username);
4ab194
+    g_free(password);
4ab194
 }
4ab194
 
4ab194