2
* Virt Viewer: A virtual machine console viewer
4
* Copyright (C) 2007-2009 Red Hat,
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* Author: Daniel P. Berrange <berrange@redhat.com>
25
#include <vncdisplay.h>
27
#include <glade/glade.h>
34
viewer_auth_collect_credentials(const char *type,
39
GtkWidget *dialog = NULL;
40
GladeXML *creds = viewer_load_glade("auth.glade", "auth");
41
GtkWidget *credUsername;
42
GtkWidget *credPassword;
43
GtkWidget *promptUsername;
44
GtkWidget *promptPassword;
45
GtkWidget *labelMessage;
49
dialog = glade_xml_get_widget(creds, "auth");
50
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
52
labelMessage = glade_xml_get_widget(creds, "message");
53
credUsername = glade_xml_get_widget(creds, "cred-username");
54
promptUsername = glade_xml_get_widget(creds, "prompt-username");
55
credPassword = glade_xml_get_widget(creds, "cred-password");
56
promptPassword = glade_xml_get_widget(creds, "prompt-password");
58
gtk_widget_set_sensitive(credUsername, username != NULL);
59
gtk_widget_set_sensitive(promptUsername, username != NULL);
60
gtk_widget_set_sensitive(credPassword, password != NULL);
61
gtk_widget_set_sensitive(promptPassword, password != NULL);
63
message = g_strdup_printf("Authentication is required for the %s connection to:\n\n"
66
address ? address : "<unknown>");
68
gtk_label_set_markup(GTK_LABEL(labelMessage), message);
71
gtk_widget_show_all(dialog);
72
response = gtk_dialog_run(GTK_DIALOG(dialog));
73
gtk_widget_hide(dialog);
75
if (response == GTK_RESPONSE_OK) {
77
*username = g_strdup(gtk_entry_get_text(GTK_ENTRY(credUsername)));
79
*password = g_strdup(gtk_entry_get_text(GTK_ENTRY(credPassword)));
82
gtk_widget_destroy(GTK_WIDGET(dialog));
84
return response == GTK_RESPONSE_OK ? 0 : -1;
87
void viewer_auth_vnc_credentials(GtkWidget *vnc, GValueArray *credList, char **vncAddress)
89
char *username = NULL, *password = NULL;
90
gboolean wantPassword = FALSE, wantUsername = FALSE;
93
DEBUG_LOG("Got VNC credential request for %d credential(s)", credList->n_values);
95
for (i = 0 ; i < credList->n_values ; i++) {
96
GValue *cred = g_value_array_get_nth(credList, i);
97
switch (g_value_get_enum(cred)) {
98
case VNC_DISPLAY_CREDENTIAL_USERNAME:
101
case VNC_DISPLAY_CREDENTIAL_PASSWORD:
104
case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
107
DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
108
vnc_display_close(VNC_DISPLAY(vnc));
113
if (wantUsername || wantPassword) {
114
int ret = viewer_auth_collect_credentials("VNC", vncAddress ? *vncAddress : NULL,
115
wantUsername ? &username : NULL,
116
wantPassword ? &password : NULL);
119
vnc_display_close(VNC_DISPLAY(vnc));
124
for (i = 0 ; i < credList->n_values ; i++) {
125
GValue *cred = g_value_array_get_nth(credList, i);
126
switch (g_value_get_enum(cred)) {
127
case VNC_DISPLAY_CREDENTIAL_USERNAME:
129
vnc_display_set_credential(VNC_DISPLAY(vnc),
130
g_value_get_enum(cred),
132
DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
133
vnc_display_close(VNC_DISPLAY(vnc));
136
case VNC_DISPLAY_CREDENTIAL_PASSWORD:
138
vnc_display_set_credential(VNC_DISPLAY(vnc),
139
g_value_get_enum(cred),
141
DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
142
vnc_display_close(VNC_DISPLAY(vnc));
145
case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
146
if (vnc_display_set_credential(VNC_DISPLAY(vnc),
147
g_value_get_enum(cred),
149
DEBUG_LOG("Failed to set credential type %d", g_value_get_enum(cred));
150
vnc_display_close(VNC_DISPLAY(vnc));
154
DEBUG_LOG("Unsupported credential type %d", g_value_get_enum(cred));
155
vnc_display_close(VNC_DISPLAY(vnc));
167
viewer_auth_libvirt_credentials(virConnectCredentialPtr cred,
171
char **username = NULL, **password = NULL;
172
const char *uri = cbdata;
176
DEBUG_LOG("Got libvirt credential request for %d credential(s)", ncred);
178
for (i = 0 ; i < ncred ; i++) {
179
switch (cred[i].type) {
180
case VIR_CRED_USERNAME:
181
case VIR_CRED_AUTHNAME:
182
username = &cred[i].result;
184
case VIR_CRED_PASSPHRASE:
185
password = &cred[i].result;
188
DEBUG_LOG("Unsupported libvirt credential %d", cred[i].type);
193
if (username || password) {
194
ret = viewer_auth_collect_credentials("libvirt", uri,
202
for (i = 0 ; i < ncred ; i++) {
203
switch (cred[i].type) {
204
case VIR_CRED_AUTHNAME:
205
case VIR_CRED_USERNAME:
206
case VIR_CRED_PASSPHRASE:
208
cred[i].resultlen = strlen(cred[i].result);
210
cred[i].resultlen = 0;
211
DEBUG_LOG("Got '%s' %d %d", cred[i].result, cred[i].resultlen, cred[i].type);
217
DEBUG_LOG("Return %d", ret);