From 3b371056484782df1bd40dabe710d111bdd29667 Mon Sep 17 00:00:00 2001 From: Robert Love Date: Thu, 23 Jun 2005 21:02:40 +0000 Subject: [PATCH] 2005-06-23 Robert Love * gnome/applet/applet-dbus-info.c: gnome keyring support! * gnome/applet/passphrase-dialog.c: more of that keyring! git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@745 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 5 +++++ gnome/applet/applet-dbus-info.c | 24 ++++++++++++++-------- gnome/applet/passphrase-dialog.c | 35 ++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e47a1012fa..7374130206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-23 Robert Love + + * gnome/applet/applet-dbus-info.c: gnome keyring support! + * gnome/applet/passphrase-dialog.c: more of that keyring! + 2005-06-23 Robert Love * configure.in: remove extraneous GNOMEKEYRING directives. diff --git a/gnome/applet/applet-dbus-info.c b/gnome/applet/applet-dbus-info.c index 7a6f34a3e8..732b7402d4 100644 --- a/gnome/applet/applet-dbus-info.c +++ b/gnome/applet/applet-dbus-info.c @@ -29,6 +29,8 @@ #include #include #include +#include + #include "NetworkManager.h" #include "applet.h" #include "applet-dbus.h" @@ -293,13 +295,14 @@ static DBusMessage *nmi_dbus_get_network_properties (NMWirelessApplet *applet, D 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 @@ static DBusMessage *nmi_dbus_get_network_properties (NMWirelessApplet *applet, D } 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))) + /* 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) { - key = g_strdup (gconf_value_get_string (value)); - gconf_value_free (value); + 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))) diff --git a/gnome/applet/passphrase-dialog.c b/gnome/applet/passphrase-dialog.c index a2455afe7f..0bfaaa7112 100644 --- a/gnome/applet/passphrase-dialog.c +++ b/gnome/applet/passphrase-dialog.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -236,13 +237,39 @@ static void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer use 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);