2007-11-09 Dan Williams <dcbw@redhat.com>

Fix vpn-properties setting update_secrets call for new NMSetting stuff.
	Since the vpn-properties are managed and known by the VPN daemons themselves,
	libnm-util doesn't know what's secret and what's in the setting's 'data'
	member.

	* libnm-util/nm-setting.h
	  libnm-util/nm-setting.c
		- Add the ability for subclasses to override update_one_secret

	* libnm-util/nm-setting-vpn-properties.c
		- Override update_one_secret and just copy the values into the
			internal table



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3078 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2007-11-09 19:41:20 +00:00
parent 65b9233068
commit 5523faaeb8
4 changed files with 73 additions and 16 deletions

View file

@ -1,3 +1,18 @@
2007-11-09 Dan Williams <dcbw@redhat.com>
Fix vpn-properties setting update_secrets call for new NMSetting stuff.
Since the vpn-properties are managed and known by the VPN daemons themselves,
libnm-util doesn't know what's secret and what's in the setting's 'data'
member.
* libnm-util/nm-setting.h
libnm-util/nm-setting.c
- Add the ability for subclasses to override update_one_secret
* libnm-util/nm-setting-vpn-properties.c
- Override update_one_secret and just copy the values into the
internal table
2007-11-09 Dan Williams <dcbw@redhat.com>
* libnm-glib/nm-settings.h

View file

@ -32,6 +32,33 @@ verify (NMSetting *setting, GSList *all_settings)
return TRUE;
}
static void
nm_gvalue_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static void
update_one_secret (NMSetting *setting, const char *key, GValue *value)
{
NMSettingVPNProperties *self = NM_SETTING_VPN_PROPERTIES (setting);
GValue *copy_val;
g_return_if_fail (key != NULL);
g_return_if_fail (value != NULL);
/* Secrets are really only known to the VPNs themselves. */
if (!self->data)
self->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
copy_val = g_slice_new0 (GValue);
g_value_init (copy_val, G_VALUE_TYPE (value));
g_value_copy (value, copy_val);
g_hash_table_insert (self->data, g_strdup (key), copy_val);
}
static void
nm_setting_vpn_properties_init (NMSettingVPNProperties *setting)
{
@ -93,6 +120,7 @@ nm_setting_vpn_properties_class_init (NMSettingVPNPropertiesClass *setting_class
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->update_one_secret = update_one_secret;
/* Properties */
g_object_class_install_property

View file

@ -249,33 +249,41 @@ nm_setting_need_secrets (NMSetting *setting)
}
static void
update_one_secret (gpointer key, gpointer val, gpointer user_data)
update_one_secret (NMSetting *setting, const char *key, GValue *value)
{
char *secret_key = (char *) key;
GValue *secret_value = (GValue *) val;
NMSetting *setting = (NMSetting *) user_data;
GParamSpec *prop_spec;
GValue transformed_value = { 0 };
prop_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), secret_key);
prop_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), key);
if (!prop_spec) {
nm_warning ("Ignoring invalid secret '%s'.", secret_key);
nm_warning ("Ignoring invalid secret '%s'.", key);
return;
}
if (!(prop_spec->flags & NM_SETTING_PARAM_SECRET)) {
nm_warning ("Ignoring secret '%s' as it's not marked as a secret.", secret_key);
nm_warning ("Ignoring secret '%s' as it's not marked as a secret.", key);
return;
}
if (g_value_type_compatible (G_VALUE_TYPE (secret_value), G_PARAM_SPEC_VALUE_TYPE (prop_spec)))
g_object_set_property (G_OBJECT (setting), prop_spec->name, secret_value);
else if (g_value_transform (secret_value, &transformed_value)) {
if (g_value_type_compatible (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (prop_spec)))
g_object_set_property (G_OBJECT (setting), prop_spec->name, value);
else if (g_value_transform (value, &transformed_value)) {
g_object_set_property (G_OBJECT (setting), prop_spec->name, &transformed_value);
g_value_unset (&transformed_value);
} else
} else {
nm_warning ("Ignoring secret property '%s' with invalid type (%s)",
secret_key, G_VALUE_TYPE_NAME (secret_value));
key, G_VALUE_TYPE_NAME (value));
}
}
static void
update_one_cb (gpointer key, gpointer val, gpointer user_data)
{
NMSetting *setting = (NMSetting *) user_data;
const char *secret_key = (const char *) key;
GValue *secret_value = (GValue *) val;
NM_SETTING_GET_CLASS (setting)->update_one_secret (setting, secret_key, secret_value);
}
void
@ -284,7 +292,7 @@ nm_setting_update_secrets (NMSetting *setting, GHashTable *secrets)
g_return_if_fail (NM_IS_SETTING (setting));
g_return_if_fail (secrets != NULL);
g_hash_table_foreach (secrets, update_one_secret, setting);
g_hash_table_foreach (secrets, update_one_cb, setting);
}
char *
@ -426,6 +434,8 @@ nm_setting_class_init (NMSettingClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
setting_class->update_one_secret = update_one_secret;
/* Properties */
g_object_class_install_property
(object_class, PROP_NAME,

View file

@ -31,10 +31,14 @@ typedef struct {
GObjectClass parent;
/* Virtual functions */
gboolean (*verify) (NMSetting *setting,
GSList *all_settings);
gboolean (*verify) (NMSetting *setting,
GSList *all_settings);
GPtrArray *(*need_secrets) (NMSetting *setting);
GPtrArray *(*need_secrets) (NMSetting *setting);
void (*update_one_secret) (NMSetting *setting,
const char *key,
GValue *value);
} NMSettingClass;
typedef void (*NMSettingValueIterFn) (NMSetting *setting,