[patch] second pass at gnome-keyring support.



I went ahead and committed the invariants from the first patch (the
cleanup, the autoconf changes, etc.) that we want whether or not we
merge keyring support now.

And then I cleaned up the patch a bit.  Find a fresh diff off of today's
CVS attached.

	Robert Love

Index: gnome/applet/applet-dbus-info.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-info.c,v
retrieving revision 1.8
diff -u -u -r1.8 applet-dbus-info.c
--- gnome/applet/applet-dbus-info.c	21 Jun 2005 15:07:00 -0000	1.8
+++ gnome/applet/applet-dbus-info.c	23 Jun 2005 20:45:56 -0000
@@ -29,6 +29,8 @@
 #include <dbus/dbus.h>
 #include <gtk/gtk.h>
 #include <glade/glade.h>
+#include <gnome-keyring.h>
+
 #include "NetworkManager.h"
 #include "applet.h"
 #include "applet-dbus.h"
@@ -293,13 +295,14 @@
 	DBusError			 error;
 	NMNetworkType		 type;
 	char				*escaped_network;
-
 	char				*essid = NULL;
 	gint				 timestamp = -1;
-	gint32				i;
+	gint32			 i;
 	char				*key = NULL;
 	NMEncKeyType		 key_type = -1;
 	gboolean			 trusted = FALSE;
+	GList			*found_list = NULL;
+	GnomeKeyringResult	 ret;
 	NMDeviceAuthMethod	 auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN;
 
 	g_return_val_if_fail (applet != NULL, NULL);
@@ -335,16 +338,21 @@
 	}	
 	g_free (gconf_key);
 
-	/* Grab user-key key for our access point from GConf */
-	gconf_key = g_strdup_printf ("%s/%s/key", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
-	if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL)))
-	{
-		key = g_strdup (gconf_value_get_string (value));
-		gconf_value_free (value);
+	/* Get the essid key, if any, from the keyring */
+	ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+								   &found_list,
+								   "essid",
+								   GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+								   essid,
+								   NULL);
+	if (ret == GNOME_KEYRING_RESULT_OK)
+	{
+		GnomeKeyringFound *found = found_list->data;
+		key = g_strdup (found->secret);
+		gnome_keyring_found_list_free (found_list);
 	}
 	else
 		key = g_strdup ("");
-	g_free (gconf_key);
 
 	gconf_key = g_strdup_printf ("%s/%s/key_type", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
 	if ((value = gconf_client_get (applet->gconf_client, gconf_key, NULL)))
Index: gnome/applet/passphrase-dialog.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/passphrase-dialog.c,v
retrieving revision 1.6
diff -u -u -r1.6 passphrase-dialog.c
--- gnome/applet/passphrase-dialog.c	23 Jun 2005 20:34:57 -0000	1.6
+++ gnome/applet/passphrase-dialog.c	23 Jun 2005 20:45:56 -0000
@@ -27,6 +27,7 @@
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 #include <glib.h>
+#include <gnome-keyring.h>
 #include <glib/gi18n.h>
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -236,13 +237,39 @@
 		g_free (key);
 		if (gconf_entry)
 		{
+			GnomeKeyringAttributeList *attributes;
+			GnomeKeyringAttribute attr;
+			GnomeKeyringResult ret;
+			const char *essid, *name;
+			guint32 item_id;
+
+			/* Setup a request to the keyring to save the network passphrase */
+			essid = wireless_network_get_essid (net);
+			name = g_strdup_printf (_("Passphrase for wireless network %s"), essid);
+			attributes = gnome_keyring_attribute_list_new ();
+			attr.name = g_strdup ("essid");	/* FIXME: Do we need to free this ? */
+			attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+			attr.value.string = g_strdup (essid);
+			g_array_append_val (attributes, attr);
+
+			ret = gnome_keyring_item_create_sync (NULL,
+										   GNOME_KEYRING_ITEM_GENERIC_SECRET,
+										   name,
+										   attributes,
+										   passphrase,
+										   TRUE,
+										   &item_id);
+			if (ret != GNOME_KEYRING_RESULT_OK)
+				g_warning ("Error saving passphrase in keyring.  Ret=%d", ret);
+			else
+				gnome_keyring_attribute_list_free (attributes);
+
 			gconf_entry_unref (gconf_entry);
-			key = g_strdup_printf ("%s/%s/key", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
-			gconf_client_set_string (applet->gconf_client, key, passphrase, NULL);
-			g_free (key);
+
 			key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
-			gconf_client_set_string (applet->gconf_client, key, wireless_network_get_essid (net), NULL);
+			gconf_client_set_string (applet->gconf_client, key, essid, NULL);
 			g_free (key);
+
 			key = g_strdup_printf ("%s/%s/key_type", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
 			gconf_client_set_int (applet->gconf_client, key, key_type_return, NULL);
 			g_free (key);


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