<div dir="ltr">Howdy!<div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 18, 2014 at 11:51 PM, Jonathon Jongsma <span dir="ltr"><<a href="mailto:jjongsma@redhat.com" target="_blank">jjongsma@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">When the user launches remote-viewer with an ovirt URI of the form<br>
<br>
ovirt://user@host/vmname<br>
<br>
Pre-populate the authentication dialog with the specified username. We<br>
don't support specifying the password on the commandline, since that is<br>
a potential security risk.<br>
<br>
rhbz#1061826<br>
---<br>
src/remote-viewer.c | 20 ++++++++++++++++----<br>
src/virt-viewer-auth.c | 10 +++++++++-<br>
2 files changed, 25 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/remote-viewer.c b/src/remote-viewer.c<br>
index 85a794b..1c1b981 100644<br>
--- a/src/remote-viewer.c<br>
+++ b/src/remote-viewer.c<br>
@@ -626,7 +626,7 @@ remote_viewer_window_added(VirtViewerApp *app G_GNUC_UNUSED,<br>
<br>
#ifdef HAVE_OVIRT<br>
static gboolean<br>
-parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name)<br>
+parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name, char** username)<br></blockquote><div><br></div><div>char **username, here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
{<br>
char *vm_name = NULL;<br>
char *rel_path;<br>
@@ -664,6 +664,9 @@ parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name)<br>
vm_name = path_elements[element_count-1];<br>
path_elements[element_count-1] = NULL;<br>
<br>
+ if (username && uri->user)<br>
+ *username = g_strdup(uri->user);<br>
+<br>
/* build final URI */<br>
rel_path = g_strjoinv("/", path_elements);<br>
/* FIXME: how to decide between http and https? */<br>
@@ -683,10 +686,14 @@ static gboolean<br>
authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,<br>
G_GNUC_UNUSED gboolean retrying, gpointer user_data)<br>
{<br>
- gchar *username;<br>
- gchar *password;<br>
+ gchar *username = NULL;<br>
+ gchar *password = NULL;<br>
VirtViewerWindow *window;<br>
<br>
+ g_object_get(proxy,<br>
+ "username", &username,<br>
+ NULL);<br>
+<br>
window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));<br>
int ret = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),<br>
"oVirt",<br>
@@ -718,6 +725,7 @@ create_ovirt_session(VirtViewerApp *app, const char *uri)<br>
GError *error = NULL;<br>
char *rest_uri = NULL;<br>
char *vm_name = NULL;<br>
+ char* username = NULL;<br></blockquote><div><br></div><div>char *username, here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
gboolean success = FALSE;<br>
guint port;<br>
guint secure_port;<br>
@@ -732,11 +740,15 @@ create_ovirt_session(VirtViewerApp *app, const char *uri)<br>
<br>
g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);<br>
<br>
- if (!parse_ovirt_uri(uri, &rest_uri, &vm_name))<br>
+ if (!parse_ovirt_uri(uri, &rest_uri, &vm_name, &username))</blockquote><div><br></div><div>And if parse_ovirt_uri doesn't fail, username is a new allocated string, right? ...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
goto error;<br>
proxy = ovirt_proxy_new(rest_uri);<br>
if (proxy == NULL)<br>
goto error;<br></blockquote><div><br></div><div>... and you're leaking it here :-)</div><div>Please, free the username in the end of function.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
+ g_object_set(proxy,<br>
+ "username", username,<br>
+ NULL);<br>
ovirt_set_proxy_options(proxy);<br>
g_signal_connect(G_OBJECT(proxy), "authenticate",<br>
G_CALLBACK(authenticate_cb), app);<br>
diff --git a/src/virt-viewer-auth.c b/src/virt-viewer-auth.c<br>
index a5b6393..6745566 100644<br>
--- a/src/virt-viewer-auth.c<br>
+++ b/src/virt-viewer-auth.c<br>
@@ -32,6 +32,10 @@<br>
#include "virt-viewer-auth.h"<br>
<br>
<br>
+/* NOTE: if username is provided, and *username is non-NULL, the user input<br>
+ * field will be pre-filled with this value. The existing string will be freed<br>
+ * before setting the output parameter to the user-entered value.<br>
+ */<br>
int<br>
virt_viewer_auth_collect_credentials(GtkWindow *window,<br>
const char *type,<br>
@@ -60,6 +64,8 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,<br>
promptPassword = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-password"));<br>
<br>
gtk_widget_set_sensitive(credUsername, username != NULL);<br>
+ if (username && *username)<br>
+ gtk_entry_set_text(GTK_ENTRY(credUsername), *username);<br>
gtk_widget_set_sensitive(promptUsername, username != NULL);<br>
gtk_widget_set_sensitive(credPassword, password != NULL);<br>
gtk_widget_set_sensitive(promptPassword, password != NULL);<br>
@@ -82,8 +88,10 @@ virt_viewer_auth_collect_credentials(GtkWindow *window,<br>
gtk_widget_hide(dialog);<br>
<br>
if (response == GTK_RESPONSE_OK) {<br>
- if (username)<br>
+ if (username) {<br>
+ g_free(*username);<br>
*username = g_strdup(gtk_entry_get_text(GTK_ENTRY(credUsername)));<br>
+ }<br>
if (password)<br>
*password = g_strdup(gtk_entry_get_text(GTK_ENTRY(credPassword)));<br>
}<br>
<span class=""><font color="#888888">--<br>
1.9.3<br>
<br>
_______________________________________________<br>
virt-tools-list mailing list<br>
<a href="mailto:virt-tools-list@redhat.com">virt-tools-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/virt-tools-list" target="_blank">https://www.redhat.com/mailman/listinfo/virt-tools-list</a><br>
</font></span></blockquote></div><br><br clear="all"><div>Best Regards,</div>-- <br><div>Fabiano Fidêncio</div>
</div></div>