summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2014-07-18 16:51:05 -0500
committerChristophe Fergeau <cfergeau@redhat.com>2014-08-18 13:20:42 +0200
commit49abd71dae12d2b284aee7d6c9c8213b22738b19 (patch)
treec10b359d2d9372d43ff6097ae6c22b53cff56b7f
parent8b7f5db57356d3adca864585efe672a830ce5b87 (diff)
downloadvirt-viewer-49abd71dae12d2b284aee7d6c9c8213b22738b19.tar.gz
virt-viewer-49abd71dae12d2b284aee7d6c9c8213b22738b19.tar.xz
virt-viewer-49abd71dae12d2b284aee7d6c9c8213b22738b19.zip
remote-viewer: allow username in ovirt URIs
When the user launches remote-viewer with an ovirt URI of the form ovirt://user@host/vmname Pre-populate the authentication dialog with the specified username. We don't support specifying the password on the commandline, since that is a potential security risk. rhbz#1061826
-rw-r--r--src/remote-viewer.c20
-rw-r--r--src/virt-viewer-auth.c10
2 files changed, 25 insertions, 5 deletions
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 3a0a71e..a27a165 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -624,7 +624,7 @@ remote_viewer_window_added(VirtViewerApp *app,
#ifdef HAVE_OVIRT
static gboolean
-parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name)
+parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name, char** username)
{
char *vm_name = NULL;
char *rel_path;
@@ -662,6 +662,9 @@ parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name)
vm_name = path_elements[element_count-1];
path_elements[element_count-1] = NULL;
+ if (username && uri->user)
+ *username = g_strdup(uri->user);
+
/* build final URI */
rel_path = g_strjoinv("/", path_elements);
/* FIXME: how to decide between http and https? */
@@ -681,10 +684,14 @@ static gboolean
authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
G_GNUC_UNUSED gboolean retrying, gpointer user_data)
{
- gchar *username;
- gchar *password;
+ gchar *username = NULL;
+ gchar *password = NULL;
VirtViewerWindow *window;
+ g_object_get(proxy,
+ "username", &username,
+ NULL);
+
window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
int ret = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
"oVirt",
@@ -716,6 +723,7 @@ create_ovirt_session(VirtViewerApp *app, const char *uri)
GError *error = NULL;
char *rest_uri = NULL;
char *vm_name = NULL;
+ char* username = NULL;
gboolean success = FALSE;
guint port;
guint secure_port;
@@ -730,11 +738,15 @@ create_ovirt_session(VirtViewerApp *app, const char *uri)
g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
- if (!parse_ovirt_uri(uri, &rest_uri, &vm_name))
+ if (!parse_ovirt_uri(uri, &rest_uri, &vm_name, &username))
goto error;
proxy = ovirt_proxy_new(rest_uri);
if (proxy == NULL)
goto error;
+
+ g_object_set(proxy,
+ "username", username,
+ NULL);
ovirt_set_proxy_options(proxy);
g_signal_connect(G_OBJECT(proxy), "authenticate",
G_CALLBACK(authenticate_cb), app);
diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c
index a5b6393..6745566 100644
--- a/src/virt-viewer-auth.c
+++ b/src/virt-viewer-auth.c
@@ -32,6 +32,10 @@
#include "virt-viewer-auth.h"
+/* NOTE: if username is provided, and *username is non-NULL, the user input
+ * field will be pre-filled with this value. The existing string will be freed
+ * before setting the output parameter to the user-entered value.
+ */
int
virt_viewer_auth_collect_credentials(GtkWindow *window,
const char *type,
@@ -60,6 +64,8 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
promptPassword = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-password"));
gtk_widget_set_sensitive(credUsername, username != NULL);
+ if (username && *username)
+ gtk_entry_set_text(GTK_ENTRY(credUsername), *username);
gtk_widget_set_sensitive(promptUsername, username != NULL);
gtk_widget_set_sensitive(credPassword, password != NULL);
gtk_widget_set_sensitive(promptPassword, password != NULL);
@@ -82,8 +88,10 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,
gtk_widget_hide(dialog);
if (response == GTK_RESPONSE_OK) {
- if (username)
+ if (username) {
+ g_free(*username);
*username = g_strdup(gtk_entry_get_text(GTK_ENTRY(credUsername)));
+ }
if (password)
*password = g_strdup(gtk_entry_get_text(GTK_ENTRY(credPassword)));
}