network-manager-applet r432 - in branches/network-manager-applet-0-6: . po src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r432 - in branches/network-manager-applet-0-6: . po src
- Date: Mon, 7 Jan 2008 22:09:05 +0000 (GMT)
Author: dcbw
Date: Mon Jan 7 22:09:04 2008
New Revision: 432
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=432&view=rev
Log:
2008-01-07 Dan Williams <dcbw redhat com>
Fix gnome.org #359541, rh #220913, rh #220915
* src/applet.c
- (nma_get_instance): call compat functions to fix up WPA-EAP password
entries
* src/applet-compat.c
- (copy_one_wpa_private_key_password): new function; copy the WPA
private key password to the new keyring item
- (copy_one_wpa_password): new function; copy the WPA user password
from GConf to the keyring and delete the GConf entry
- (nma_compat_move_wpa_eap_passwords): new function; move the WPA
password from GConf (where it's unobfuscated) to the Gnome Keyring
* src/nm-gconf-wso.h
src/nm-gconf-wso.c
- (nm_gconf_wso_read_secrets, real_read_secrets): new function; let
subclasses handle reading their own secrets, but provide a default
implementation that gets the default key
- (nm_gconf_wso_write_secrets, real_write_secrets): new function; let
subclasses handle writing their own secrets to the keyring, but
provide a default implementation that writes the default key
* src/nm-gconf-wso-wpa-eap.c
- (nm_gconf_wso_wpa_eap_new_deserialize_dbus, real_serialize_dbus): the
default secret should be the WPA password, not the private key
password
- (nm_gconf_wso_wpa_eap_new_deserialize_gconf): don't read the WPA
password out of GConf
- (real_serialize_gconf): don't write the WPA password to GConf
- (real_read_secrets): read both the WPA password and the private key
password from the keyring
- (real_write_secrets): write both the WPA password and the private key
password to the keyring
- (nm_gconf_wso_wpa_eap_class_init): override the superclass' secret
read/write functions
* src/applet-dbus-info.c
- (free_network_key_cb_data, nmi_dbus_get_network_key_callback):
removed
- (nmi_dbus_get_key_for_network): let the NMGConfWSO object handle
reading its own secrets
- (nmi_save_network_info): let the NMGConfWSO object handle writing
its own secrets
Modified:
branches/network-manager-applet-0-6/ChangeLog
branches/network-manager-applet-0-6/po/POTFILES.in
branches/network-manager-applet-0-6/src/applet-compat.c
branches/network-manager-applet-0-6/src/applet-dbus-info.c
branches/network-manager-applet-0-6/src/applet.c
branches/network-manager-applet-0-6/src/nm-gconf-wso-wpa-eap.c
branches/network-manager-applet-0-6/src/nm-gconf-wso.c
branches/network-manager-applet-0-6/src/nm-gconf-wso.h
Modified: branches/network-manager-applet-0-6/po/POTFILES.in
==============================================================================
--- branches/network-manager-applet-0-6/po/POTFILES.in (original)
+++ branches/network-manager-applet-0-6/po/POTFILES.in Mon Jan 7 22:09:04 2008
@@ -9,6 +9,8 @@
src/applet.glade
src/eggtrayicon.c
src/menu-items.c
+src/nm-gconf-wso.c
+src/nm-gconf-wso-wpa-eap.c
src/other-network-dialog.c
src/passphrase-dialog.c
src/vpn-password-dialog.c
Modified: branches/network-manager-applet-0-6/src/applet-compat.c
==============================================================================
--- branches/network-manager-applet-0-6/src/applet-compat.c (original)
+++ branches/network-manager-applet-0-6/src/applet-compat.c Mon Jan 7 22:09:04 2008
@@ -397,3 +397,180 @@
g_slist_free (dir_list);
}
+
+#define WPA_EAP_PREFIX "wpa_eap_"
+
+static void
+copy_one_wpa_private_key_password (GConfClient *client,
+ const char *ssid,
+ const char *escaped_network)
+{
+ char *private_key_passwd = NULL;
+ GnomeKeyringResult ret;
+ GnomeKeyringAttributeList *attrs;
+ char *display_name = NULL;
+ GList *found_list = NULL;
+ char *temp = NULL;
+ guint32 item_id = 0;
+
+ nm_gconf_get_string_helper (client,
+ GCONF_PATH_WIRELESS_NETWORKS,
+ WPA_EAP_PREFIX"private_key_file",
+ escaped_network,
+ &temp);
+ /* Nothing to do if a private key file wasn't specified */
+ if (!temp)
+ goto out;
+
+ /* Read private_key_passwd from keyring */
+ ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ &found_list,
+ "essid",
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ ssid,
+ NULL);
+ if ((ret == GNOME_KEYRING_RESULT_OK) && g_list_length (found_list)) {
+ GnomeKeyringFound *found = (GnomeKeyringFound *) found_list->data;
+
+ private_key_passwd = g_strdup (found->secret);
+ /* Delete old private_key_password keyring item */
+ gnome_keyring_item_delete_sync (NULL, found->item_id);
+ }
+ gnome_keyring_found_list_free (found_list);
+
+ if (!private_key_passwd)
+ goto out;
+
+ /* Save private_key_passwd to keyring */
+ display_name = g_strdup_printf (_("Private key password for wireless network %s"), ssid);
+
+ attrs = gnome_keyring_attribute_list_new ();
+ gnome_keyring_attribute_list_append_string (attrs, "private-key-passwd", ssid);
+ ret = gnome_keyring_item_create_sync (NULL,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ display_name,
+ attrs,
+ private_key_passwd,
+ TRUE,
+ &item_id);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ nm_warning ("Error saving secret for wireless network '%s' in keyring: %d", ssid, ret);
+
+ g_free (display_name);
+ gnome_keyring_attribute_list_free (attrs);
+
+out:
+ g_free (private_key_passwd);
+ g_free (temp);
+}
+
+static void
+copy_one_wpa_password (GConfClient *client,
+ const char *ssid,
+ const char *dir,
+ const char *escaped_network)
+{
+ char *gconf_key = NULL;
+ char *passwd = NULL;
+ char *display_name = NULL;
+ GnomeKeyringResult ret;
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attr;
+ guint32 item_id = 0;
+
+ nm_gconf_get_string_helper (client,
+ GCONF_PATH_WIRELESS_NETWORKS,
+ WPA_EAP_PREFIX"passwd",
+ escaped_network,
+ &passwd);
+ /* Nothing to do if a passwd wasn't specified */
+ if (!passwd)
+ return;
+
+ display_name = g_strdup_printf (_("Passphrase for wireless network %s"), ssid);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ attr.name = g_strdup ("essid");
+ attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attr.value.string = g_strdup (ssid);
+ g_array_append_val (attributes, attr);
+
+ ret = gnome_keyring_item_create_sync (NULL,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ display_name,
+ attributes,
+ passwd,
+ TRUE,
+ &item_id);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ nm_warning ("Error saving secret for wireless network '%s' in keyring: %d", ssid, ret);
+
+ g_free (display_name);
+ gnome_keyring_attribute_list_free (attributes);
+
+ /* Remove passwd value from GConf */
+ gconf_key = g_strdup_printf ("%s/%spasswd", dir, WPA_EAP_PREFIX);
+ if (gconf_key) {
+ gconf_client_unset (client, gconf_key, NULL);
+ g_free (gconf_key);
+ }
+
+ g_free (passwd);
+}
+
+void
+nma_compat_move_wpa_eap_passwords (GConfClient *client)
+{
+ GSList *dir_list = NULL;
+ GSList *elt;
+
+ g_return_if_fail (client != NULL);
+
+ if (!(dir_list = gconf_client_all_dirs (client, GCONF_PATH_WIRELESS_NETWORKS, NULL)))
+ return;
+
+ for (elt = dir_list; elt; elt = g_slist_next (elt)) {
+ char key[100];
+ GConfValue *value;
+ char *dir = (char *) (elt->data);
+
+ g_snprintf (&key[0], 99, "%s/essid", dir);
+ if ((value = gconf_client_get (client, key, NULL))) {
+ const char *ssid;
+ char *escaped_network = NULL;
+ int we_cipher = -1;
+
+ if (value->type != GCONF_VALUE_STRING)
+ goto next;
+
+ ssid = gconf_value_get_string (value);
+ escaped_network = gconf_escape_key (ssid, strlen (ssid));
+ if (!escaped_network || strlen (escaped_network) == 0) {
+ nm_warning ("%s:%d (%s): couldn't unescape network name '%s'.",
+ __FILE__, __LINE__, __func__, ssid);
+ goto next;
+ }
+
+ /* Ignore any entry that looks like it doesn't need conversion */
+ if (!nm_gconf_get_int_helper (client,
+ GCONF_PATH_WIRELESS_NETWORKS,
+ "we_cipher",
+ escaped_network,
+ &we_cipher))
+ goto next;
+
+ if (we_cipher != NM_AUTH_TYPE_WPA_EAP)
+ goto next;
+
+ copy_one_wpa_private_key_password (client, ssid, escaped_network);
+ copy_one_wpa_password (client, ssid, dir, escaped_network);
+
+next:
+ g_free (escaped_network);
+ gconf_value_free (value);
+ }
+ g_free (dir);
+ }
+ g_slist_free (dir_list);
+}
+
Modified: branches/network-manager-applet-0-6/src/applet-dbus-info.c
==============================================================================
--- branches/network-manager-applet-0-6/src/applet-dbus-info.c (original)
+++ branches/network-manager-applet-0-6/src/applet-dbus-info.c Mon Jan 7 22:09:04 2008
@@ -29,7 +29,6 @@
#include <dbus/dbus.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
-#include <gnome-keyring.h>
#include <iwlib.h>
#include "NetworkManager.h"
@@ -69,67 +68,6 @@
}
-typedef struct NMGetNetworkKeyCBData
-{
- NMApplet *applet;
- DBusMessage *message;
- NetworkDevice *dev;
- char *net_path;
- char *essid;
-} NMGetNetworkKeyCBData;
-
-static void free_network_key_cb_data (NMGetNetworkKeyCBData *cb_data)
-{
- if (cb_data)
- {
- dbus_message_unref (cb_data->message);
- network_device_unref (cb_data->dev);
- g_free (cb_data->net_path);
- g_free (cb_data->essid);
- memset (cb_data, 0, sizeof (NMGetNetworkKeyCBData));
- g_free (cb_data);
- }
-}
-
-
-static void nmi_dbus_get_network_key_callback (GnomeKeyringResult result,
- GList *found_list,
- gpointer data)
-{
- NMGetNetworkKeyCBData * cb_data = (NMGetNetworkKeyCBData*) data;
- NMApplet * applet = cb_data->applet;
- DBusMessage * message = cb_data->message;
- NetworkDevice * dev = cb_data->dev;
- char * net_path = cb_data->net_path;
- char * essid = cb_data->essid;
-
- if (result == GNOME_KEYRING_RESULT_OK && found_list)
- {
- gchar * escaped_network;
- GnomeKeyringFound * found;
- NMGConfWSO * gconf_wso;
-
- escaped_network = gconf_escape_key (essid, strlen (essid));
- gconf_wso = nm_gconf_wso_new_deserialize_gconf (applet->gconf_client, escaped_network);
- g_free (escaped_network);
-
- found = found_list->data;
- nm_gconf_wso_set_key (gconf_wso, found->secret, strlen (found->secret));
- nmi_dbus_return_user_key (applet->connection, message, gconf_wso);
- }
- else
- {
- WirelessNetwork *net;
-
- nmi_passphrase_dialog_destroy (applet);
- if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
- applet->passphrase_dialog = nmi_passphrase_dialog_new (applet, 0, dev, net, message);
- }
-
- free_network_key_cb_data (cb_data);
-}
-
-
/*
* nmi_dbus_get_key_for_network
*
@@ -152,8 +90,6 @@
char * temp = NULL;
char * escaped_network;
int we_cipher = -1;
- char * private_key_file = NULL;
- gboolean have_priv_key_file = FALSE;
g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
@@ -184,45 +120,10 @@
|| !temp)
new_key = TRUE;
- nm_gconf_get_string_helper (applet->gconf_client,
- GCONF_PATH_WIRELESS_NETWORKS,
- "wpa_eap_private_key_file", escaped_network, &private_key_file);
- if (private_key_file) {
- have_priv_key_file = TRUE;
- g_free (private_key_file);
- }
-
- /* Hack: 802.1x passwords are not stored in the keyring */
- if (!new_key && (we_cipher == NM_AUTH_TYPE_WPA_EAP && !have_priv_key_file))
- {
- NMGConfWSO *gconf_wso;
- gconf_wso = nm_gconf_wso_new_deserialize_gconf (applet->gconf_client,
- escaped_network);
- if (gconf_wso)
- {
- nmi_dbus_return_user_key(connection, message, gconf_wso);
- g_object_unref (G_OBJECT (gconf_wso));
- g_free (escaped_network);
- return NULL;
- }
- else
- new_key = TRUE;
- }
- g_free (escaped_network);
-
/* It's not a new key, so try to get the key from the keyring. */
if (!new_key)
{
- NMGetNetworkKeyCBData *cb_data;
-
- cb_data = g_malloc0 (sizeof (NMGetNetworkKeyCBData));
- cb_data->applet = applet;
- cb_data->essid = g_strdup (essid);
- cb_data->message = message;
- dbus_message_ref (message);
- cb_data->dev = dev;
- network_device_ref (dev);
- cb_data->net_path = g_strdup (net_path);
+ NMGConfWSO *gconf_wso;
/* If the menu happens to be showing when we pop up the
* keyring dialog, we get an X server deadlock. So deactivate
@@ -231,18 +132,23 @@
if (applet->dropdown_menu && GTK_WIDGET_VISIBLE (GTK_WIDGET (applet->dropdown_menu)))
gtk_menu_shell_deactivate (GTK_MENU_SHELL (applet->dropdown_menu));
- /* Get the essid key, if any, from the keyring */
- gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- (GnomeKeyringOperationGetListCallback) nmi_dbus_get_network_key_callback,
- cb_data,
- NULL,
- "essid",
- GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- essid,
- NULL);
+ gconf_wso = nm_gconf_wso_new_deserialize_gconf (applet->gconf_client, escaped_network);
+ if (!gconf_wso) {
+ new_key = TRUE;
+ goto new_key;
+ }
+
+ /* Grab secrets from the keyring, if any */
+ if (!nm_gconf_wso_read_secrets (gconf_wso, essid)) {
+ new_key = TRUE;
+ goto new_key;
+ }
+
+ nmi_dbus_return_user_key (applet->connection, message, gconf_wso);
}
- else
- {
+
+new_key:
+ if (new_key) {
/* We only ask the user for a new key when we know about the network from NM,
* since throwing up a dialog with a random essid from somewhere is a security issue.
*/
@@ -253,6 +159,7 @@
}
}
+ g_free (escaped_network);
return NULL;
}
@@ -935,35 +842,7 @@
}
/* Stuff the encryption key into the keyring */
- if (nm_gconf_wso_get_we_cipher (gconf_wso) != IW_AUTH_CIPHER_NONE)
- {
- GnomeKeyringAttributeList * attributes;
- GnomeKeyringAttribute attr;
- char * display_name;
- GnomeKeyringResult ret;
- guint32 item_id;
-
- display_name = g_strdup_printf (_("Passphrase for wireless network %s"), essid);
-
- attributes = gnome_keyring_attribute_list_new ();
- attr.name = g_strdup ("essid");
- 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,
- display_name,
- attributes,
- nm_gconf_wso_get_key (gconf_wso),
- TRUE,
- &item_id);
- if (ret != GNOME_KEYRING_RESULT_OK)
- nm_warning ("Error saving secret for wireless network '%s' in keyring: %d", essid, ret);
-
- g_free (display_name);
- gnome_keyring_attribute_list_free (attributes);
- }
+ nm_gconf_wso_write_secrets (gconf_wso, essid);
out:
g_free (escaped_network);
Modified: branches/network-manager-applet-0-6/src/applet.c
==============================================================================
--- branches/network-manager-applet-0-6/src/applet.c (original)
+++ branches/network-manager-applet-0-6/src/applet.c Mon Jan 7 22:09:04 2008
@@ -2564,6 +2564,7 @@
* synchronous calls against gnome-keyring.
*/
nma_compat_convert_oldformat_entries (applet->gconf_client);
+ nma_compat_move_wpa_eap_passwords (applet->gconf_client);
/* Load pixmaps and create applet widgets */
nma_setup_widgets (applet);
Modified: branches/network-manager-applet-0-6/src/nm-gconf-wso-wpa-eap.c
==============================================================================
--- branches/network-manager-applet-0-6/src/nm-gconf-wso-wpa-eap.c (original)
+++ branches/network-manager-applet-0-6/src/nm-gconf-wso-wpa-eap.c Mon Jan 7 22:09:04 2008
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <dbus/dbus.h>
#include <iwlib.h>
+#include <gnome-keyring.h>
#include "applet.h"
#include "nm-gconf-wso.h"
@@ -31,6 +32,7 @@
#include "nm-gconf-wso-private.h"
#include "dbus-helpers.h"
#include "gconf-helpers.h"
+#include "nm-utils.h"
#define WPA_EAP_PREFIX "wpa_eap_"
@@ -38,17 +40,17 @@
struct _NMGConfWSOWPA_EAPPrivate
{
- int eap_method;
- int key_type;
- int phase2_type;
- int wpa_version;
- int key_mgmt;
- const char * identity;
- const char * passwd;
- const char * anon_identity;
- const char * private_key_file;
- const char * client_cert_file;
- const char * ca_cert_file;
+ int eap_method;
+ int key_type;
+ int phase2_type;
+ int wpa_version;
+ int key_mgmt;
+ char * identity;
+ char * anon_identity;
+ char * private_key_file;
+ char * private_key_passwd;
+ char * client_cert_file;
+ char * ca_cert_file;
};
@@ -78,15 +80,15 @@
/* Success, build up our security object */
security = g_object_new (NM_TYPE_GCONF_WSO_WPA_EAP, NULL);
nm_gconf_wso_set_we_cipher (NM_GCONF_WSO (security), we_cipher);
- if (private_key_passwd && strlen (private_key_passwd) > 0)
- nm_gconf_wso_set_key (NM_GCONF_WSO (security), private_key_passwd, strlen (private_key_passwd));
+ nm_gconf_wso_set_key (NM_GCONF_WSO (security), passwd, strlen (passwd));
security->priv->wpa_version = wpa_version;
security->priv->key_type = key_type;
security->priv->eap_method = NM_EAP_TO_EAP_METHOD (eap_method);
security->priv->phase2_type = NM_EAP_TO_PHASE2_METHOD (eap_method);
security->priv->key_mgmt = IW_AUTH_KEY_MGMT_802_1X;
security->priv->identity = g_strdup (identity);
- security->priv->passwd = g_strdup (passwd);
+ if (private_key_passwd && strlen (private_key_passwd) > 0)
+ security->priv->private_key_passwd = g_strdup (private_key_passwd);
security->priv->anon_identity = g_strdup (anon_identity);
security->priv->private_key_file = g_strdup (private_key_file);
security->priv->client_cert_file = g_strdup (client_cert_file);
@@ -102,7 +104,6 @@
{
NMGConfWSOWPA_EAP * security = NULL;
char * identity = NULL;
- char * passwd = NULL;
char * anon_identity = NULL;
char * private_key_file = NULL;
char * client_cert_file = NULL;
@@ -155,12 +156,6 @@
nm_gconf_get_string_helper (client,
GCONF_PATH_WIRELESS_NETWORKS,
- WPA_EAP_PREFIX"passwd",
- network,
- &passwd);
-
- nm_gconf_get_string_helper (client,
- GCONF_PATH_WIRELESS_NETWORKS,
WPA_EAP_PREFIX"anon_identity",
network,
&anon_identity);
@@ -192,14 +187,12 @@
security->priv->phase2_type = phase2_type;
security->priv->key_mgmt = IW_AUTH_KEY_MGMT_802_1X;
security->priv->identity = g_strdup (identity);
- security->priv->passwd = g_strdup (passwd);
security->priv->anon_identity = g_strdup (anon_identity);
security->priv->private_key_file = g_strdup (private_key_file);
security->priv->client_cert_file = g_strdup (client_cert_file);
security->priv->ca_cert_file = g_strdup (ca_cert_file);
g_free (identity);
- g_free (passwd);
g_free (anon_identity);
g_free (private_key_file);
g_free (client_cert_file);
@@ -218,9 +211,9 @@
self->priv->eap_method | self->priv->phase2_type,
self->priv->key_type,
self->priv->identity ? : "",
- self->priv->passwd ? : "",
- self->priv->anon_identity ? : "",
nm_gconf_wso_get_key (instance) ? : "",
+ self->priv->anon_identity ? : "",
+ self->priv->private_key_passwd ? : "",
self->priv->private_key_file ? : "",
self->priv->client_cert_file ? : "",
self->priv->ca_cert_file ? : "",
@@ -262,13 +255,6 @@
g_free (key);
}
- if (self->priv->passwd && strlen (self->priv->passwd) > 0)
- {
- key = g_strdup_printf ("%s/%s/%spasswd", GCONF_PATH_WIRELESS_NETWORKS, network, WPA_EAP_PREFIX);
- gconf_client_set_string (client, key, self->priv->passwd, NULL);
- g_free (key);
- }
-
if (self->priv->anon_identity && strlen (self->priv->anon_identity) > 0)
{
key = g_strdup_printf ("%s/%s/%sanon_identity", GCONF_PATH_WIRELESS_NETWORKS, network, WPA_EAP_PREFIX);
@@ -300,6 +286,72 @@
return TRUE;
}
+static gboolean
+real_read_secrets (NMGConfWSO *instance,
+ const char *ssid)
+{
+ NMGConfWSOWPA_EAP *self = NM_GCONF_WSO_WPA_EAP (instance);
+ GList *found_list = NULL;
+ GnomeKeyringResult ret;
+ GnomeKeyringFound *found;
+
+ NM_GCONF_WSO_CLASS (g_type_class_peek (NM_TYPE_GCONF_WSO))->read_secrets_func (instance, ssid);
+
+ ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ &found_list,
+ "private-key-passwd",
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ ssid,
+ NULL);
+ if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0)) {
+ nm_info ("No keyring secrets found for network %s", ssid);
+ return FALSE;
+ }
+
+ found = (GnomeKeyringFound *) found_list->data;
+ self->priv->private_key_passwd = g_strdup (found->secret);
+ gnome_keyring_found_list_free (found_list);
+
+ return TRUE;
+}
+
+static void
+real_write_secrets (NMGConfWSO *instance,
+ const char *ssid)
+{
+ NMGConfWSOWPA_EAP *self = NM_GCONF_WSO_WPA_EAP (instance);
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attr;
+ char *display_name;
+ GnomeKeyringResult ret;
+ guint32 item_id;
+
+ NM_GCONF_WSO_CLASS (g_type_class_peek (NM_TYPE_GCONF_WSO))->write_secrets_func (instance, ssid);
+
+ if (!self->priv->private_key_passwd)
+ return;
+
+ display_name = g_strdup_printf (_("Private key password for wireless network %s"), ssid);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ attr.name = g_strdup ("private-key-passwd");
+ attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attr.value.string = g_strdup (ssid);
+ g_array_append_val (attributes, attr);
+
+ ret = gnome_keyring_item_create_sync (NULL,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ display_name,
+ attributes,
+ self->priv->private_key_passwd,
+ TRUE,
+ &item_id);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ nm_warning ("Error saving secret for wireless network '%s' in keyring: %d", ssid, ret);
+
+ g_free (display_name);
+ gnome_keyring_attribute_list_free (attributes);
+}
static void
nm_gconf_wso_wpa_eap_init (NMGConfWSOWPA_EAP *self)
@@ -318,6 +370,8 @@
par_class->serialize_dbus_func = real_serialize_dbus;
par_class->serialize_gconf_func = real_serialize_gconf;
+ par_class->read_secrets_func = real_read_secrets;
+ par_class->write_secrets_func = real_write_secrets;
g_type_class_add_private (object_class, sizeof (NMGConfWSOWPA_EAPPrivate));
}
Modified: branches/network-manager-applet-0-6/src/nm-gconf-wso.c
==============================================================================
--- branches/network-manager-applet-0-6/src/nm-gconf-wso.c (original)
+++ branches/network-manager-applet-0-6/src/nm-gconf-wso.c Mon Jan 7 22:09:04 2008
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
#include <dbus/dbus.h>
#include <gconf/gconf-client.h>
+#include <gnome-keyring.h>
#include <iwlib.h>
#include "applet.h"
@@ -34,6 +35,7 @@
#include "nm-gconf-wso-leap.h"
#include "gconf-helpers.h"
#include "wireless-security-option.h"
+#include "nm-utils.h"
#define NM_GCONF_WSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_GCONF_WSO, NMGConfWSOPrivate))
@@ -296,6 +298,81 @@
return NM_GCONF_WSO_GET_CLASS (self)->serialize_gconf_func (self, client, network);
}
+gboolean
+nm_gconf_wso_read_secrets (NMGConfWSO *self,
+ const char *ssid)
+{
+ return NM_GCONF_WSO_GET_CLASS (self)->read_secrets_func (self, ssid);
+}
+
+static gboolean
+real_read_secrets (NMGConfWSO *self,
+ const char *ssid)
+{
+ GList *found_list = NULL;
+ GnomeKeyringResult ret;
+ GnomeKeyringFound *found;
+
+ ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ &found_list,
+ "essid",
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ ssid,
+ NULL);
+ if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0)) {
+ nm_info ("No keyring secrets found for network %s", ssid);
+ return FALSE;
+ }
+
+ found = (GnomeKeyringFound *) found_list->data;
+ nm_gconf_wso_set_key (self, found->secret, strlen (found->secret));
+ gnome_keyring_found_list_free (found_list);
+
+ return TRUE;
+}
+
+void
+nm_gconf_wso_write_secrets (NMGConfWSO *self,
+ const char *ssid)
+{
+ NM_GCONF_WSO_GET_CLASS (self)->write_secrets_func (self, ssid);
+}
+
+static void
+real_write_secrets (NMGConfWSO *self,
+ const char *ssid)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attr;
+ char *display_name;
+ GnomeKeyringResult ret;
+ guint32 item_id;
+
+ if (nm_gconf_wso_get_we_cipher (self) == IW_AUTH_CIPHER_NONE)
+ return;
+
+ display_name = g_strdup_printf (_("Passphrase for wireless network %s"), ssid);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ attr.name = g_strdup ("essid");
+ attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attr.value.string = g_strdup (ssid);
+ g_array_append_val (attributes, attr);
+
+ ret = gnome_keyring_item_create_sync (NULL,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ display_name,
+ attributes,
+ nm_gconf_wso_get_key (self),
+ TRUE,
+ &item_id);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ nm_warning ("Error saving secret for wireless network '%s' in keyring: %d", ssid, ret);
+
+ g_free (display_name);
+ gnome_keyring_attribute_list_free (attributes);
+}
+
static void
nm_gconf_wso_init (NMGConfWSO * self)
{
@@ -359,6 +436,8 @@
klass->serialize_dbus_func = real_serialize_dbus;
klass->serialize_gconf_func = real_serialize_gconf;
+ klass->read_secrets_func = real_read_secrets;
+ klass->write_secrets_func = real_write_secrets;
g_type_class_add_private (object_class, sizeof (NMGConfWSOPrivate));
}
Modified: branches/network-manager-applet-0-6/src/nm-gconf-wso.h
==============================================================================
--- branches/network-manager-applet-0-6/src/nm-gconf-wso.h (original)
+++ branches/network-manager-applet-0-6/src/nm-gconf-wso.h Mon Jan 7 22:09:04 2008
@@ -57,6 +57,10 @@
gboolean (*serialize_dbus_func) (NMGConfWSO *self, DBusMessageIter *iter);
gboolean (*serialize_gconf_func) (NMGConfWSO *self, GConfClient *client, const char *network);
+
+ gboolean (*read_secrets_func) (NMGConfWSO *self, const char *ssid);
+
+ void (*write_secrets_func) (NMGConfWSO *self, const char *ssid);
};
@@ -78,4 +82,8 @@
gboolean nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network);
+gboolean nm_gconf_wso_read_secrets (NMGConfWSO *self, const char *ssid);
+
+void nm_gconf_wso_write_secrets (NMGConfWSO *self, const char *ssid);
+
#endif /* NM_GCONF_WSO_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]