Storing proxy password in keyring



	Hi, I'm working in integrate the proxy password stuff with
GNOME keyring. I have a patch for gnome-network-preferences capplet
(attached), but I'm not sure how we should solve one issue.

	When the user change its proxy host or port should we add a new
keyring item for this pair with the old username and password associated
to it? should we update our current item port/port? or just should we
assume that it is a new host/port and reset the authentication suff and
let him click on the deatils button to set authentication?.

	Another issue with this change is if we should import the old
password (stored in gconf) the first time the new http gnome-vfs module
is run or just use a callback to ask for a new password (this will only
happen the first time a GNOME < 2.8 user runs GNOME 2.8).

Salu2


Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/network/Makefile.am,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile.am
--- Makefile.am	16 Dec 2003 21:38:49 -0000	1.3
+++ Makefile.am	25 May 2004 12:39:11 -0000
@@ -2,7 +2,8 @@
 
 gnome_network_preferences_SOURCES = gnome-network-preferences.c
 gnome_network_preferences_LDADD =				\
-	$(GNOMECC_CAPPLETS_LIBS)
+	$(GNOMECC_CAPPLETS_LIBS) \
+	$(NETWORK_CAPPLET_LIBS)
 
 @INTLTOOL_DESKTOP_RULE@
 
@@ -13,6 +14,6 @@
 desktop_in_files = gnome-network-preferences.desktop.in
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
-INCLUDES   = $(GNOMECC_CAPPLETS_CFLAGS)
+INCLUDES   = $(GNOMECC_CAPPLETS_CFLAGS) $(NETWORK_CAPPLET_CFLAGS)
 CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES)
 EXTRA_DIST = $(glade_DATA) $(desktop_in_files)
Index: gnome-network-preferences.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/network/gnome-network-preferences.c,v
retrieving revision 1.16
diff -u -u -r1.16 gnome-network-preferences.c
--- gnome-network-preferences.c	15 Apr 2004 18:32:22 -0000	1.16
+++ gnome-network-preferences.c	25 May 2004 12:39:12 -0000
@@ -29,6 +29,7 @@
 #include <gconf/gconf-client.h>
 #include <glade/glade.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
+#include <gnome-keyring.h>
 
 #include "capplet-util.h"
 #include "gconf-property-editor.h"
@@ -52,7 +53,6 @@
 #define HTTP_PROXY_PORT_KEY  "/system/http_proxy/port"
 #define HTTP_USE_AUTH_KEY    "/system/http_proxy/use_authentication"
 #define HTTP_AUTH_USER_KEY   "/system/http_proxy/authentication_user"
-#define HTTP_AUTH_PASSWD_KEY "/system/http_proxy/authentication_password"
 #define PROXY_MODE_KEY "/system/proxy/mode"
 #define SECURE_PROXY_HOST_KEY  "/system/proxy/secure_host"
 #define SECURE_PROXY_PORT_KEY  "/system/proxy/secure_port"
@@ -65,6 +65,23 @@
 static GtkWidget *details_dialog = NULL;
 
 static void
+cb_set_proxy_password (GnomeKeyringResult result,
+		       guint32            val,
+		       gpointer           data)
+{
+	if (result != GNOME_KEYRING_RESULT_OK) {
+		capplet_error_dialog (GTK_WINDOW (gtk_widget_get_toplevel (details_dialog)),
+				      _("There was an error storing the password in the keyring"),
+				      NULL);
+	}
+	gtk_widget_destroy (GTK_WIDGET (details_dialog));
+	details_dialog = NULL;
+}
+	
+
+
+
+static void
 cb_dialog_response (GtkDialog *dialog, gint response_id)
 {
 	if (response_id == GTK_RESPONSE_HELP)
@@ -76,14 +93,31 @@
 }
 
 static void
-cb_details_dialog_response (GtkDialog *dialog, gint response_id)
+cb_details_dialog_response (GtkDialog *details_dialog, gint response_id,
+			    GladeXML *dialog)
 {
 	if (response_id == GTK_RESPONSE_HELP)
-		capplet_help (GTK_WINDOW (dialog),
+		capplet_help (GTK_WINDOW (details_dialog),
 			      "user-guide.xml",
 			      "goscustdesk-50");
-	else {
-		gtk_widget_destroy (GTK_WIDGET (dialog));
+	else if (response_id == GTK_RESPONSE_CLOSE) {
+		GConfClient *client;
+		const gchar *user, *host, *password;
+		gint port;
+		
+		client = gconf_client_get_default ();
+		if (gconf_client_get_bool (client, HTTP_USE_AUTH_KEY, NULL) == TRUE) {
+			user = gtk_entry_get_text (GTK_ENTRY (WID ("username_entry")));
+			password = gtk_entry_get_text (GTK_ENTRY (WID ("password_entry")));
+			port = gconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL); 
+			host = gconf_client_get_string (client, HTTP_PROXY_HOST_KEY, NULL);
+			gnome_keyring_set_network_password (NULL, user, NULL, host, NULL, "http",
+							    "proxy", port, password, 
+                                	            	    cb_set_proxy_password, NULL, NULL);
+		}
+		g_object_unref (client);
+	} else {
+		gtk_widget_destroy (GTK_WIDGET (details_dialog));
 		details_dialog = NULL;
 	}
 }
@@ -95,6 +129,30 @@
 	gtk_widget_set_sensitive (table, toggle->active);
 }
 
+static char*
+get_http_proxy_password (GConfClient *client)
+{
+	const gchar *user;
+	gchar *host, *password = NULL;
+	gint port;
+	GnomeKeyringResult result;
+	GList *items;
+	GnomeKeyringNetworkPasswordData *item;
+
+	user = gconf_client_get_string (client, HTTP_AUTH_USER_KEY, NULL);
+	port = gconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL); 
+	host = gconf_client_get_string (client, HTTP_PROXY_HOST_KEY, NULL);
+	result = gnome_keyring_find_network_password_sync (user, NULL, host, NULL, "http",
+							   "proxy", port, &items);
+	if (result == GNOME_KEYRING_RESULT_OK && items != NULL) {
+		item = (GnomeKeyringNetworkPasswordData*) items->data;
+		password = g_strdup (item->password);
+		gnome_keyring_network_password_list_free (items);
+	}
+	return password;
+}
+
+
 static void
 cb_http_details_button_clicked (GtkWidget *button,
 			        GtkWidget *parent)
@@ -102,6 +160,7 @@
 	GladeXML  *dialog;
 	GtkWidget *widget;
 	GConfPropertyEditor *peditor;
+	GConfClient *client;
 
 	if (details_dialog != NULL) {
 		gtk_window_present (GTK_WINDOW (details_dialog));
@@ -129,12 +188,17 @@
 	peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
 			NULL, HTTP_AUTH_USER_KEY, WID ("username_entry"),
 			NULL));
-	peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
-			NULL, HTTP_AUTH_PASSWD_KEY, WID ("password_entry"), 
-			NULL));
+
+	client = gconf_client_get_default ();
+	if (gconf_client_get_bool (client, HTTP_USE_AUTH_KEY, NULL) == TRUE) {
+		char *password = get_http_proxy_password (client);
+		gtk_entry_set_text (GTK_ENTRY (WID ("password_entry")), password);
+		g_free (password);
+	}
+	g_object_unref (client);
 
 	g_signal_connect (widget, "response",
-			  G_CALLBACK (cb_details_dialog_response), NULL);
+			  G_CALLBACK (cb_details_dialog_response), dialog);
 	
 	capplet_set_icon (widget, "gnome-network-capplet.png");
 
-- 
Fernando Herrera de las Heras
Onírica: análisis, diseño e implantación de soluciones informáticas
http://www.onirica.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]