[virt-tools-list] [PATCH virt-viewer 1/4] Move vnc-specific auth logic to VirtViewerSessionVnc
Jonathon Jongsma
jjongsma at redhat.com
Mon Feb 3 22:14:18 UTC 2014
---
src/virt-viewer-auth.c | 97 -------------------------------------------
src/virt-viewer-auth.h | 6 ---
src/virt-viewer-session-vnc.c | 92 +++++++++++++++++++++++++++++++++++++---
3 files changed, 86 insertions(+), 109 deletions(-)
diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
index 79c8589..a5b6393 100644
--- a/src/virt-viewer-auth.c
+++ b/src/virt-viewer-auth.c
@@ -94,103 +94,6 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
return response == GTK_RESPONSE_OK ? 0 : -1;
}
-#ifdef HAVE_GTK_VNC
-void
-virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
- GtkWindow *window,
- GtkWidget *vnc,
- GValueArray *credList,
- char *vncAddress)
-{
- char *username = NULL, *password = NULL;
- gboolean wantPassword = FALSE, wantUsername = FALSE;
- int i;
-
- DEBUG_LOG("Got VNC credential request for %d credential(s)", credList->n_values);
-
- for (i = 0 ; i < credList->n_values ; i++) {
- GValue *cred = g_value_array_get_nth(credList, i);
- switch (g_value_get_enum(cred)) {
- case VNC_DISPLAY_CREDENTIAL_USERNAME:
- wantUsername = TRUE;
- break;
- case VNC_DISPLAY_CREDENTIAL_PASSWORD:
- wantPassword = TRUE;
- break;
- case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
- break;
- default:
- DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
- vnc_display_close(VNC_DISPLAY(vnc));
- goto cleanup;
- }
- }
-
- VirtViewerFile *file = virt_viewer_session_get_file(session);
- if (file != NULL) {
- if (wantUsername && virt_viewer_file_is_set(file, "username")) {
- username = virt_viewer_file_get_username(file);
- wantUsername = FALSE;
- }
- if (wantPassword && virt_viewer_file_is_set(file, "password")) {
- password = virt_viewer_file_get_password(file);
- wantPassword = FALSE;
- }
- }
-
- if (wantUsername || wantPassword) {
- int ret = virt_viewer_auth_collect_credentials(window,
- "VNC", vncAddress,
- wantUsername ? &username : NULL,
- wantPassword ? &password : NULL);
-
- if (ret < 0) {
- vnc_display_close(VNC_DISPLAY(vnc));
- goto cleanup;
- }
- }
-
- for (i = 0 ; i < credList->n_values ; i++) {
- GValue *cred = g_value_array_get_nth(credList, i);
- switch (g_value_get_enum(cred)) {
- case VNC_DISPLAY_CREDENTIAL_USERNAME:
- if (!username ||
- vnc_display_set_credential(VNC_DISPLAY(vnc),
- g_value_get_enum(cred),
- username)) {
- DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
- vnc_display_close(VNC_DISPLAY(vnc));
- }
- break;
- case VNC_DISPLAY_CREDENTIAL_PASSWORD:
- if (!password ||
- vnc_display_set_credential(VNC_DISPLAY(vnc),
- g_value_get_enum(cred),
- password)) {
- DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
- vnc_display_close(VNC_DISPLAY(vnc));
- }
- break;
- case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
- if (vnc_display_set_credential(VNC_DISPLAY(vnc),
- g_value_get_enum(cred),
- "libvirt")) {
- DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
- vnc_display_close(VNC_DISPLAY(vnc));
- }
- break;
- default:
- DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
- vnc_display_close(VNC_DISPLAY(vnc));
- }
- }
-
- cleanup:
- g_free(username);
- g_free(password);
-}
-#endif
-
/*
* Local variables:
* c-indent-level: 4
diff --git a/src/virt-viewer-auth.h b/src/virt-viewer-auth.h
index 1f102e0..ad932c5 100644
--- a/src/virt-viewer-auth.h
+++ b/src/virt-viewer-auth.h
@@ -32,12 +32,6 @@
#include "virt-viewer-session.h"
#include "virt-viewer-util.h"
-void virt_viewer_auth_vnc_credentials(VirtViewerSession *session,
- GtkWindow *window,
- GtkWidget *vnc,
- GValueArray *credList,
- char *vncAddress);
-
int virt_viewer_auth_collect_credentials(GtkWindow *window,
const char *type,
const char *address,
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index 50fa11f..337cb92 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -254,17 +254,97 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
static void
-virt_viewer_session_vnc_auth_credential(GtkWidget *src,
+virt_viewer_session_vnc_auth_credential(GtkWidget *src G_GNUC_UNUSED,
GValueArray *credList,
VirtViewerSession *session)
{
VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session);
+ char *username = NULL, *password = NULL;
+ gboolean wantPassword = FALSE, wantUsername = FALSE;
+ int i;
+
+ DEBUG_LOG("Got VNC credential request for %d credential(s)", credList->n_values);
+
+ for (i = 0 ; i < credList->n_values ; i++) {
+ GValue *cred = g_value_array_get_nth(credList, i);
+ switch (g_value_get_enum(cred)) {
+ case VNC_DISPLAY_CREDENTIAL_USERNAME:
+ wantUsername = TRUE;
+ break;
+ case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+ wantPassword = TRUE;
+ break;
+ case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
+ break;
+ default:
+ DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
+ vnc_display_close(self->priv->vnc);
+ goto cleanup;
+ }
+ }
+
+ VirtViewerFile *file = virt_viewer_session_get_file(VIRT_VIEWER_SESSION(self));
+ if (file != NULL) {
+ if (wantUsername && virt_viewer_file_is_set(file, "username")) {
+ username = virt_viewer_file_get_username(file);
+ wantUsername = FALSE;
+ }
+ if (wantPassword && virt_viewer_file_is_set(file, "password")) {
+ password = virt_viewer_file_get_password(file);
+ wantPassword = FALSE;
+ }
+ }
+
+ if (wantUsername || wantPassword) {
+ int ret = virt_viewer_auth_collect_credentials(self->priv->main_window,
+ "VNC", NULL,
+ wantUsername ? &username : NULL,
+ wantPassword ? &password : NULL);
+
+ if (ret < 0) {
+ vnc_display_close(self->priv->vnc);
+ goto cleanup;
+ }
+ }
+
+ for (i = 0 ; i < credList->n_values ; i++) {
+ GValue *cred = g_value_array_get_nth(credList, i);
+ switch (g_value_get_enum(cred)) {
+ case VNC_DISPLAY_CREDENTIAL_USERNAME:
+ if (!username ||
+ vnc_display_set_credential(self->priv->vnc,
+ g_value_get_enum(cred),
+ username)) {
+ DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
+ vnc_display_close(self->priv->vnc);
+ }
+ break;
+ case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+ if (!password ||
+ vnc_display_set_credential(self->priv->vnc,
+ g_value_get_enum(cred),
+ password)) {
+ DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
+ vnc_display_close(self->priv->vnc);
+ }
+ break;
+ case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
+ if (vnc_display_set_credential(self->priv->vnc,
+ g_value_get_enum(cred),
+ "libvirt")) {
+ DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
+ vnc_display_close(self->priv->vnc);
+ }
+ break;
+ default:
+ DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
+ vnc_display_close(self->priv->vnc);
+ }
+ }
- virt_viewer_auth_vnc_credentials(session,
- self->priv->main_window,
- src,
- credList,
- NULL);
+ cleanup:
+ g_free(username);
+ g_free(password);
}
--
1.8.5.3
More information about the virt-tools-list
mailing list