network-manager-applet r1041 - in trunk: . src/gconf-helpers



Author: dcbw
Date: Thu Nov 20 23:20:20 2008
New Revision: 1041
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=1041&view=rev

Log:
2008-11-20  Dan Williams  <dcbw redhat com>

	* src/gconf-helpers/gconf-upgrade.c
		- (get_06_keyring_secret): get an NM 0.6 secret from the keyring
		- (nm_gconf_read_0_6_wep_settings, nm_gconf_read_0_6_wpa_settings,
		   nm_gconf_read_0_6_eap_settings, nm_gconf_read_0_6_leap_settings,
		   nm_gconf_read_0_6_wireless_connection): attempt to convert NM 0.6
			secrets to NM 0.7 format



Modified:
   trunk/ChangeLog
   trunk/src/gconf-helpers/gconf-upgrade.c

Modified: trunk/src/gconf-helpers/gconf-upgrade.c
==============================================================================
--- trunk/src/gconf-helpers/gconf-upgrade.c	(original)
+++ trunk/src/gconf-helpers/gconf-upgrade.c	Thu Nov 20 23:20:20 2008
@@ -153,6 +153,38 @@
 	return TRUE;
 }
 
+static char *
+get_06_keyring_secret (const char *network, const char *attr_name)
+{
+	GnomeKeyringResult result;
+	GList *found_list = NULL;
+	char *secret = NULL;
+
+	/* Get the PSK out of the keyring */
+	result = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+	                                         &found_list,
+	                                         attr_name ? attr_name : "essid",
+	                                         GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+	                                         network,
+	                                         NULL);
+	if ((result == GNOME_KEYRING_RESULT_OK) && (g_list_length (found_list) > 0)) {
+		GnomeKeyringFound *found = (GnomeKeyringFound *) found_list->data;
+
+		secret = g_strdup (found->secret);
+		gnome_keyring_found_list_free (found_list);
+	}
+	return secret;
+}
+
+static void
+clear_06_keyring_secret (char *secret)
+{
+	if (secret) {
+		memset (secret, 0, strlen (secret));
+		g_free (secret);
+	}
+}
+
 static const struct flagnames wep_auth_algorithms[] = {
 	{ "open",   IW_AUTH_ALG_OPEN_SYSTEM },
 	{ "shared", IW_AUTH_ALG_SHARED_KEY },
@@ -161,10 +193,13 @@
 
 static NMSettingWirelessSecurity *
 nm_gconf_read_0_6_wep_settings (GConfClient *client,
-						  const char *path, const char *network)
+                                const char *path,
+                                const char *network,
+                                const char *uuid,
+                                const char *id)
 {
 	NMSettingWirelessSecurity *s_wireless_sec;
-	char *auth_alg;
+	char *auth_alg, *secret = NULL;
 
 	if (!get_enum_helper (client, path, "wep_auth_algorithm", network, wep_auth_algorithms, &auth_alg))
 		return NULL;
@@ -177,6 +212,15 @@
 	              NULL);
 	g_free (auth_alg);
 
+	secret = get_06_keyring_secret (network, NULL);
+	if (secret) {
+		nm_gconf_add_keyring_item (uuid, id,
+		                           NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+		                           NM_SETTING_WIRELESS_SECURITY_WEP_KEY0,
+		                           secret);
+		clear_06_keyring_secret (secret);
+	}
+
 	return s_wireless_sec;
 }
 
@@ -188,15 +232,28 @@
 
 static NMSettingWirelessSecurity *
 nm_gconf_read_0_6_wpa_settings (GConfClient *client,
-						  const char *path, const char *network)
+                                const char *path,
+                                const char *network,
+                                const char *uuid,
+                                const char *id)
 {
 	NMSettingWirelessSecurity *s_wireless_sec = NULL;
+	char *secret = NULL;
 
 	s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
 	g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
 	nm_setting_wireless_security_add_proto (s_wireless_sec, "wpa");
 	nm_setting_wireless_security_add_proto (s_wireless_sec, "rsn");
 
+	secret = get_06_keyring_secret (network, NULL);
+	if (secret) {
+		nm_gconf_add_keyring_item (uuid, id,
+		                           NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+		                           NM_SETTING_WIRELESS_SECURITY_PSK,
+		                           secret);
+		clear_06_keyring_secret (secret);
+	}
+
 	return s_wireless_sec;
 }
 
@@ -232,11 +289,13 @@
 nm_gconf_read_0_6_eap_settings (GConfClient *client,
                                 const char *path,
                                 const char *network,
+                                const char *uuid,
+                                const char *id,
                                 NMSetting8021x **s_8021x)
 {
 	NMSettingWirelessSecurity *wsec = NULL;
 	GSList *eaps = NULL, *ciphers = NULL, *iter;
-	char *phase2 = NULL, *identity = NULL, *anon_identity = NULL;
+	char *phase2 = NULL, *identity = NULL, *anon_identity = NULL, *secret = NULL;
 	const char *eap = NULL;
 	gboolean wep_ciphers = FALSE, wpa_ciphers = FALSE;
 
@@ -283,6 +342,15 @@
 	              NULL);
 	nm_setting_802_1x_add_eap_method (*s_8021x, eap);
 
+	secret = get_06_keyring_secret (network, NULL);
+	if (secret) {
+		nm_gconf_add_keyring_item (uuid, id,
+		                           NM_SETTING_802_1X_SETTING_NAME,
+		                           NM_SETTING_802_1X_PASSWORD,
+		                           secret);
+		clear_06_keyring_secret (secret);
+	}
+
 	/* Add phase2 if the eap method uses inner auth */
 	if (!strcmp (eap, "ttls") || !strcmp (eap, "peap")) {
 		/* If the method is actually unsupported in NM 0.7, default to mschapv2 */
@@ -293,6 +361,24 @@
 			phase2 = g_strdup ("mschapv2");
 		}
 		g_object_set (*s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, phase2, NULL);
+
+		secret = get_06_keyring_secret (network, "private-key-passwd");
+		if (secret) {
+			nm_gconf_add_keyring_item (uuid, id,
+			                           NM_SETTING_802_1X_SETTING_NAME,
+			                           NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD,
+			                           secret);
+			clear_06_keyring_secret (secret);
+		}
+	} else if (!strcmp (eap, "tls")) {
+		secret = get_06_keyring_secret (network, "private-key-passwd");
+		if (secret) {
+			nm_gconf_add_keyring_item (uuid, id,
+			                           NM_SETTING_802_1X_SETTING_NAME,
+			                           NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD,
+			                           secret);
+			clear_06_keyring_secret (secret);
+		}
 	}
 
 out:
@@ -308,10 +394,12 @@
 nm_gconf_read_0_6_leap_settings (GConfClient *client,
                                  const char *path,
                                  const char *network,
+                                 const char *uuid,
+                                 const char *id,
                                  NMSetting8021x **s_8021x)
 {
 	NMSettingWirelessSecurity *s_wireless_sec = NULL;
-	char *username = NULL, *key_mgmt = NULL;
+	char *username = NULL, *key_mgmt = NULL, *secret = NULL;
 
 	if (!get_mandatory_string_helper (client, path, "leap_key_mgmt", network, &key_mgmt))
 		goto out;
@@ -320,12 +408,21 @@
 
 	s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
 
+	secret = get_06_keyring_secret (network, NULL);
+
 	if (!strcmp (key_mgmt, "WPA-EAP")) {
 		g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
 
 		*s_8021x = NM_SETTING_802_1X (nm_setting_802_1x_new ());
 		nm_setting_802_1x_add_eap_method (*s_8021x, "leap");
 		g_object_set (*s_8021x, NM_SETTING_802_1X_IDENTITY, username, NULL);
+
+		if (secret) {
+			nm_gconf_add_keyring_item (uuid, id,
+			                           NM_SETTING_802_1X_SETTING_NAME,
+			                           NM_SETTING_802_1X_PASSWORD,
+			                           secret);
+		}
 	} else {
 		/* Traditional LEAP */
 		g_object_set (s_wireless_sec,
@@ -333,7 +430,15 @@
 		              NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
 		              NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, username,
 		              NULL);
+
+		if (secret) {
+			nm_gconf_add_keyring_item (uuid, id,
+			                           NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+			                           NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
+			                           secret);
+		}
 	}
+	clear_06_keyring_secret (secret);
 
 out:
 	g_free (username);
@@ -352,7 +457,7 @@
 	NMSetting8021x *s_8021x = NULL;
 	GByteArray *ssid;
 	char *path, *network, *essid = NULL;
-	char *s;
+	char *uuid, *id;
 	int timestamp, we_cipher;
 	GSList *iter;
 	GSList *bssids = NULL;
@@ -381,13 +486,11 @@
 				  NM_SETTING_CONNECTION_TIMESTAMP, timestamp >= 0 ? (guint64) timestamp : 0,
 				  NULL);
 
-	s = g_strdup_printf ("Auto %s", essid);
-	g_object_set (s_con, NM_SETTING_CONNECTION_ID, s, NULL);
-	g_free (s);
-
-	s = nm_utils_uuid_generate ();
-	g_object_set (s_con, NM_SETTING_CONNECTION_UUID, s, NULL);
-	g_free (s);
+	id = g_strdup_printf ("Auto %s", essid);
+	g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
+
+	uuid = nm_utils_uuid_generate ();
+	g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
 
 	s_wireless = (NMSettingWireless *)nm_setting_wireless_new ();
 
@@ -410,18 +513,18 @@
 		switch (we_cipher) {
 		case NM_AUTH_TYPE_WEP40:
 		case NM_AUTH_TYPE_WEP104:
-			s_wireless_sec = nm_gconf_read_0_6_wep_settings (client, path, network);
+			s_wireless_sec = nm_gconf_read_0_6_wep_settings (client, path, network, uuid, id);
 			break;
 		case NM_AUTH_TYPE_WPA_PSK_AUTO:
 		case NM_AUTH_TYPE_WPA_PSK_TKIP:
 		case NM_AUTH_TYPE_WPA_PSK_CCMP:
-			s_wireless_sec = nm_gconf_read_0_6_wpa_settings (client, path, network);
+			s_wireless_sec = nm_gconf_read_0_6_wpa_settings (client, path, network, uuid, id);
 			break;
 		case NM_AUTH_TYPE_WPA_EAP:
-			s_wireless_sec = nm_gconf_read_0_6_eap_settings (client, path, network, &s_8021x);
+			s_wireless_sec = nm_gconf_read_0_6_eap_settings (client, path, network, uuid, id, &s_8021x);
 			break;
 		case NM_AUTH_TYPE_LEAP:
-			s_wireless_sec = nm_gconf_read_0_6_leap_settings (client, path, network, &s_8021x);
+			s_wireless_sec = nm_gconf_read_0_6_leap_settings (client, path, network, uuid, id, &s_8021x);
 			break;
 		default:
 			g_warning ("Unknown NM 0.6 auth type %d on connection %s", we_cipher, dir);
@@ -459,6 +562,8 @@
 
 	g_free (path);
 	g_free (network);
+	g_free (uuid);
+	g_free (id);
 
 	return connection;
 }



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