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



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3472 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2008-03-18 15:30:50 +00:00
parent 76f418666b
commit e117bad293
6 changed files with 123 additions and 70 deletions

View file

@ -1,3 +1,26 @@
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
2008-03-17 Tambet Ingo <tambet@gmail.com>
Clean up activating device deactivation.

View file

@ -63,9 +63,9 @@ connection_data_get (NMConnection *connection)
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 @@ connection_data_copy_secrets (ConnectionData *from, ConnectionData *to)
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 (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 (from->secrets, copy_one_cdata_secret, to);
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 @@ connection_data_free (gpointer userdata)
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 @@ connection_data_add (NMConnection *connection, const char *ifcfg_path)
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 @@ out:
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); \
} \

View file

@ -38,7 +38,9 @@ typedef struct {
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);

View file

@ -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 @@ get_connections (NMSystemConfigInterface *config)
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 *

View file

@ -41,53 +41,16 @@ G_DEFINE_TYPE (NMSysconfigExportedConnection, nm_sysconfig_exported_connection,
/*
* 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)
check_for_secrets (gpointer key, gpointer data, gpointer user_data)
{
GValue *value = (GValue *) data;
gboolean *have_secrets = (gboolean *) user_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)
{
struct AddSecretsData *data = (struct AddSecretsData *) user_data;
const char *str_val;
if (!secret)
if (*have_secrets)
return;
if (!G_VALUE_HOLDS (value, G_TYPE_STRING))
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 @@ exported_connection_get_secrets (NMExportedConnection *sys_connection,
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 @@ exported_connection_get_secrets (NMExportedConnection *sys_connection,
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);

View file

@ -79,9 +79,14 @@ struct _NMSystemConfigInterface {
*/
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);