NetworkManager r3472 - in trunk: . system-settings/plugins/ifcfg-fedora system-settings/src



Author: dcbw
Date: Tue Mar 18 15:30:50 2008
New Revision: 3472
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3472&view=rev

Log:
2008-03-18  Dan Williams  <dcbw redhat com>

	Adapt system settings service for split 802.1x.

	* system-settings/src/nm-system-config-interface.h
		- clarify return value of get_secrets()

	* system-settings/src/dbus-settings.c
		- (string_to_gvalue, destroy_gvalue, add_one_secret_to_hash): remove
		- (check_for_secrets): check if there actually secrets returned by a
			plugin
		- (exported_connection_get_secrets): just return the plugin-returned
			hash of settings' secrets if it looks valid

	* system-settings/plugins/ifcfg-fedora/plugin.c
		- (get_secrets): add split secrets with correct format to reply hash

	* system-settings/plugins/ifcfg-fedora/parser.c
	  system-settings/plugins/ifcfg-fedora/parser.h
		- (copy_one_cdata_secret, connection_data_copy_secrets,
		   connection_data_free, connection_data_add): keep secrets for
			different settings in different hashes



Modified:
   trunk/ChangeLog
   trunk/system-settings/plugins/ifcfg-fedora/parser.c
   trunk/system-settings/plugins/ifcfg-fedora/parser.h
   trunk/system-settings/plugins/ifcfg-fedora/plugin.c
   trunk/system-settings/src/dbus-settings.c
   trunk/system-settings/src/nm-system-config-interface.h

Modified: trunk/system-settings/plugins/ifcfg-fedora/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/parser.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/parser.c	Tue Mar 18 15:30:50 2008
@@ -63,9 +63,9 @@
 static void
 copy_one_cdata_secret (gpointer key, gpointer data, gpointer user_data)
 {
-	ConnectionData *to = (ConnectionData *) user_data;
+	GHashTable *to = (GHashTable *) user_data;
 
-	g_hash_table_insert (to->secrets, key, g_strdup (data));
+	g_hash_table_insert (to, key, g_strdup (data));
 }
 
 static void
@@ -81,10 +81,17 @@
 	g_return_if_fail (from != NULL);
 	g_return_if_fail (to != NULL);
 
-	g_hash_table_foreach (to->secrets, clear_one_cdata_secret, NULL);
-	g_hash_table_remove_all (to->secrets);
-
-	g_hash_table_foreach (from->secrets, copy_one_cdata_secret, to);
+	g_hash_table_foreach (to->wifi_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_remove_all (to->wifi_secrets);
+	g_hash_table_foreach (from->wifi_secrets, copy_one_cdata_secret, to->wifi_secrets);
+
+	g_hash_table_foreach (to->onex_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_remove_all (to->onex_secrets);
+	g_hash_table_foreach (from->onex_secrets, copy_one_cdata_secret, to->onex_secrets);
+
+	g_hash_table_foreach (to->ppp_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_remove_all (to->ppp_secrets);
+	g_hash_table_foreach (from->ppp_secrets, copy_one_cdata_secret, to->ppp_secrets);
 }
 
 static void
@@ -94,9 +101,16 @@
 
 	g_return_if_fail (cdata != NULL);
 
+	g_hash_table_foreach (cdata->wifi_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_destroy (cdata->wifi_secrets);
+
+	g_hash_table_foreach (cdata->onex_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_destroy (cdata->onex_secrets);
+
+	g_hash_table_foreach (cdata->ppp_secrets, clear_one_cdata_secret, NULL);
+	g_hash_table_destroy (cdata->ppp_secrets);
+
 	g_free (cdata->ifcfg_path);
-	g_hash_table_foreach (cdata->secrets, clear_one_cdata_secret, NULL);
-	g_hash_table_destroy (cdata->secrets);
 	memset (cdata, 0, sizeof (ConnectionData));
 	g_free (cdata);
 }
@@ -108,7 +122,10 @@
 
 	cdata = g_malloc0 (sizeof (ConnectionData));
 	cdata->ifcfg_path = g_strdup (ifcfg_path);
-	cdata->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+
+	cdata->wifi_secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+	cdata->onex_secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+	cdata->ppp_secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
 
 	g_object_set_data_full (G_OBJECT (connection),
 	                        CONNECTION_DATA_TAG, cdata,
@@ -477,7 +494,7 @@
 		if (*error) \
 			goto error; \
 		if (key) { \
-			g_hash_table_insert (cdata->secrets, \
+			g_hash_table_insert (cdata->wifi_secrets, \
 			                     NM_SETTING_WIRELESS_SECURITY_WEP_KEY##idx, \
 			                     key); \
 		} \

Modified: trunk/system-settings/plugins/ifcfg-fedora/parser.h
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/parser.h	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/parser.h	Tue Mar 18 15:30:50 2008
@@ -38,7 +38,9 @@
 	gboolean ignored;
 	gboolean exported;
 
-	GHashTable *secrets;
+	GHashTable *wifi_secrets;
+	GHashTable *onex_secrets;
+	GHashTable *ppp_secrets;
 } ConnectionData;
 
 NMConnection * parser_parse_file (const char *file, GError **error);

Modified: trunk/system-settings/plugins/ifcfg-fedora/plugin.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/plugin.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/plugin.c	Tue Mar 18 15:30:50 2008
@@ -30,6 +30,7 @@
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
 #include <nm-setting-wireless-security.h>
+#include <nm-setting-8021x.h>
 
 #include "plugin.h"
 #include "parser.h"
@@ -363,23 +364,64 @@
 	return list;
 }
 
+static GValue *
+string_to_gvalue (const char *str)
+{
+	GValue *val;
+
+	val = g_slice_new0 (GValue);
+	g_value_init (val, G_TYPE_STRING);
+	g_value_set_string (val, str);
+
+	return val;
+}
+
+static void
+add_one_secret (gpointer key, gpointer data, gpointer user_data)
+{
+	g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), string_to_gvalue (data));	
+}
+
+static void
+destroy_gvalue (gpointer data)
+{
+	GValue *value = (GValue *) data;
+
+	g_value_unset (value);
+	g_slice_free (GValue, value);
+}
+
 static GHashTable *
 get_secrets (NMSystemConfigInterface *config,
              NMConnection *connection,
              NMSetting *setting)
 {
+	GHashTable *settings;
 	ConnectionData *cdata;
-
-	/* wifi security only for now */
-	if (!NM_IS_SETTING_WIRELESS_SECURITY (setting))
-		return NULL;
+	GHashTable *secrets;
 
 	cdata = connection_data_get (connection);
-	if (!cdata || !cdata->secrets)
+	if (!cdata)
 		return NULL;
 
-	g_hash_table_ref (cdata->secrets);
-	return cdata->secrets;
+	settings = g_hash_table_new_full (g_str_hash, g_str_equal,
+	                                  g_free, (GDestroyNotify) g_hash_table_destroy);
+
+	if (cdata->wifi_secrets) {
+		secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+		g_hash_table_foreach (cdata->wifi_secrets, add_one_secret, secrets);
+		g_hash_table_insert (settings, g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME), secrets);
+	}
+
+	if (cdata->onex_secrets) {
+		secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+		g_hash_table_foreach (cdata->onex_secrets, add_one_secret, secrets);
+		g_hash_table_insert (settings, g_strdup (NM_SETTING_802_1X_SETTING_NAME), secrets);
+	}
+
+	/* FIXME: PPP secrets (which are actually split out into GSM/CDMA/etc */
+
+	return settings;
 }
 
 static NMConnection *

Modified: trunk/system-settings/src/dbus-settings.c
==============================================================================
--- trunk/system-settings/src/dbus-settings.c	(original)
+++ trunk/system-settings/src/dbus-settings.c	Tue Mar 18 15:30:50 2008
@@ -41,53 +41,16 @@
 /*
  * NMSysconfigExportedConnection
  */
-static GValue *
-string_to_gvalue (const char *str)
-{
-	GValue *val;
-
-	val = g_slice_new0 (GValue);
-	g_value_init (val, G_TYPE_STRING);
-	g_value_set_string (val, str);
-
-	return val;
-}
-
-static void
-destroy_gvalue (gpointer data)
-{
-	GValue *value = (GValue *) data;
-
-	g_value_unset (value);
-	g_slice_free (GValue, value);
-}
-
-struct AddSecretsData {
-	GHashTable *plugin_secrets;
-	GHashTable *out_secrets;
-};
 
 static void
-add_one_secret_to_hash (NMSetting *setting,
-                        const char *key,
-                        const GValue *value,
-                        gboolean secret,
-                        gpointer user_data)
+check_for_secrets (gpointer key, gpointer data, gpointer user_data)
 {
-	struct AddSecretsData *data = (struct AddSecretsData *) user_data;
-	const char *str_val;
-
-	if (!secret)
-		return;
+	gboolean *have_secrets = (gboolean *) user_data;
 
-	if (!G_VALUE_HOLDS (value, G_TYPE_STRING))
+	if (*have_secrets)
 		return;
 
-	str_val = g_hash_table_lookup (data->plugin_secrets, key);
-	if (!str_val)
-		return;
-
-	g_hash_table_insert (data->out_secrets, g_strdup (key), string_to_gvalue (str_val));
+	*have_secrets = g_hash_table_size ((GHashTable *) data) ? TRUE : FALSE;
 }
 
 static void
@@ -101,8 +64,9 @@
 	GError *error = NULL;
 	NMSettingConnection *s_con;
 	NMSetting *setting;
+	GHashTable *settings = NULL;
 	NMSystemConfigInterface *plugin;
-	struct AddSecretsData sdata;
+	gboolean have_secrets = FALSE;
 
 	connection = nm_exported_connection_get_connection (sys_connection);
 
@@ -136,31 +100,31 @@
 		goto error;
 	}
 
-	sdata.plugin_secrets = nm_system_config_interface_get_secrets (plugin, connection, setting);
-	if (!sdata.plugin_secrets) {
+	settings = nm_system_config_interface_get_secrets (plugin, connection, setting);
+	if (!settings || (g_hash_table_size (settings) == 0)) {
 		g_set_error (&error, NM_SETTINGS_ERROR, 1,
 		             "%s.%d - Connection's plugin did not return a secrets hash.",
 		             __FILE__, __LINE__);
 		goto error;
 	}
 
-	sdata.out_secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
-	nm_setting_enumerate_values (setting, add_one_secret_to_hash, &sdata);
-	g_hash_table_unref (sdata.plugin_secrets);
-
-	if (g_hash_table_size (sdata.out_secrets) == 0) {
+	g_hash_table_foreach (settings, check_for_secrets, &have_secrets);
+	if (!have_secrets) {
 		g_set_error (&error, NM_SETTINGS_ERROR, 1,
 		             "%s.%d - Secrets were found for setting '%s' but none"
 		             " were valid.", __FILE__, __LINE__, setting_name);
 		goto error;
 	} else {
-		dbus_g_method_return (context, sdata.out_secrets);
+		dbus_g_method_return (context, settings);
 	}
 
-	g_hash_table_destroy (sdata.out_secrets);
+	g_hash_table_destroy (settings);
 	return;
 
 error:
+	if (settings)
+		g_hash_table_destroy (settings);
+
 	g_warning (error->message);
 	dbus_g_method_return_error (context, error);
 	g_error_free (error);

Modified: trunk/system-settings/src/nm-system-config-interface.h
==============================================================================
--- trunk/system-settings/src/nm-system-config-interface.h	(original)
+++ trunk/system-settings/src/nm-system-config-interface.h	Tue Mar 18 15:30:50 2008
@@ -79,9 +79,14 @@
 	 */
 	GSList * (*get_connections) (NMSystemConfigInterface *config);
 
-	/* Return the secrets associated with a specific setting of a specific
+	/* Return the secrets associated with settings of a specific
 	 * connection.  The returned hash table is unreffed by the system settings
-	 * service.
+	 * service.  Returned hash table should itself contain string::hashtable
+	 * mappings, each value being a hash table of secrets for a single setting.
+	 *
+	 *  string :: (string :: GValue)
+	 *
+	 * The returned hash table will be freed by the system settings service.
 	 */
 	GHashTable * (*get_secrets) (NMSystemConfigInterface *config, NMConnection *connection, NMSetting *setting);
 



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