diff options
author | Thomas Haller <thaller@redhat.com> | 2019-01-13 21:23:02 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-01-22 16:30:23 +0100 |
commit | 08a0f682e192b4288170171bb89727d944555d4c (patch) | |
tree | 6d2125da4508f9a927e11b4751889973885d668e /libnm-core | |
parent | 2210d4514eb9f9dec5ca55415cc8b8dd0f9afefc (diff) | |
download | NetworkManager-08a0f682e192b4288170171bb89727d944555d4c.tar.gz |
libnm: always call clear_secrets() function for all properties
And merge it with the version that uses no flags.
Previously, clear_secrets(_with_flags()) was only implemented
by NMSettingVpn. All other settings would only consider GObject-based
properties.
As we will add secrets that have no GObject property, call the virtual
function always, so that the setting can hook into this (for WireGuard
peers).
Diffstat (limited to 'libnm-core')
-rw-r--r-- | libnm-core/nm-setting-vpn.c | 52 | ||||
-rw-r--r-- | libnm-core/nm-setting.c | 87 | ||||
-rw-r--r-- | libnm-core/nm-setting.h | 10 |
3 files changed, 80 insertions, 69 deletions
diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 581c70d02a..1371140ec4 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -813,29 +813,43 @@ compare_property (const NMSettInfoSetting *sett_info, } static gboolean -clear_secrets_with_flags (NMSetting *setting, - GParamSpec *pspec, - NMSettingClearSecretsWithFlagsFn func, - gpointer user_data) +clear_secrets (const NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, + NMSettingClearSecretsWithFlagsFn func, + gpointer user_data) { NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); + GParamSpec *prop_spec = sett_info->property_infos[property_idx].param_spec; GHashTableIter iter; const char *secret; gboolean changed = TRUE; - if (priv->secrets == NULL) + if ( !prop_spec + || !NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET)) + return FALSE; + + nm_assert (nm_streq (prop_spec->name, NM_SETTING_VPN_SECRETS)); + + if (!priv->secrets) return FALSE; - /* Iterate through secrets hash and check each entry */ g_hash_table_iter_init (&iter, priv->secrets); while (g_hash_table_iter_next (&iter, (gpointer) &secret, NULL)) { - NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - nm_setting_get_secret_flags (setting, secret, &flags, NULL); - if (func (setting, secret, flags, user_data) == TRUE) { - g_hash_table_iter_remove (&iter); - changed = TRUE; - } + if (func) { + NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; + + if (!nm_setting_get_secret_flags (setting, secret, &flags, NULL)) + nm_assert_not_reached (); + + if (!func (setting, secret, flags, user_data)) + continue; + } else + nm_assert (nm_setting_get_secret_flags (setting, secret, NULL, NULL)); + + g_hash_table_iter_remove (&iter); + changed = TRUE; } if (changed) @@ -963,13 +977,13 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->verify = verify; - setting_class->update_one_secret = update_one_secret; - setting_class->get_secret_flags = get_secret_flags; - setting_class->set_secret_flags = set_secret_flags; - setting_class->need_secrets = need_secrets; - setting_class->compare_property = compare_property; - setting_class->clear_secrets_with_flags = clear_secrets_with_flags; + setting_class->verify = verify; + setting_class->update_one_secret = update_one_secret; + setting_class->get_secret_flags = get_secret_flags; + setting_class->set_secret_flags = set_secret_flags; + setting_class->need_secrets = need_secrets; + setting_class->compare_property = compare_property; + setting_class->clear_secrets = clear_secrets; /** * NMSettingVpn:service-type: diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index b00f0ab981..976f7f0085 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1841,34 +1841,42 @@ _nm_setting_aggregate (NMSetting *setting, } static gboolean -clear_secrets_with_flags (NMSetting *setting, - GParamSpec *pspec, - NMSettingClearSecretsWithFlagsFn func, - gpointer user_data) +clear_secrets (const NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, + NMSettingClearSecretsWithFlagsFn func, + gpointer user_data) { NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - gboolean changed = FALSE; + GParamSpec *param_spec = sett_info->property_infos[property_idx].param_spec; - g_return_val_if_fail (!NM_IS_SETTING_VPN (setting), FALSE); + if (!param_spec) + return FALSE; - /* Clear the secret if the user function says to do so */ - if (!nm_setting_get_secret_flags (setting, pspec->name, &flags, NULL)) - g_return_val_if_reached (FALSE); + if (!NM_FLAGS_HAS (param_spec->flags, NM_SETTING_PARAM_SECRET)) + return FALSE; - if (func (setting, pspec->name, flags, user_data) == TRUE) { - GValue value = G_VALUE_INIT; + if (func) { + if (!nm_setting_get_secret_flags (setting, param_spec->name, &flags, NULL)) + nm_assert_not_reached (); + if (!func (setting, param_spec->name, flags, user_data)) + return FALSE; + } else + nm_assert (nm_setting_get_secret_flags (setting, param_spec->name, NULL, NULL)); - g_value_init (&value, pspec->value_type); - g_object_get_property (G_OBJECT (setting), pspec->name, &value); - if (!g_param_value_defaults (pspec, &value)) { - g_param_value_set_default (pspec, &value); - g_object_set_property (G_OBJECT (setting), pspec->name, &value); - changed = TRUE; - } - g_value_unset (&value); + { + nm_auto_unset_gvalue GValue value = G_VALUE_INIT; + + g_value_init (&value, param_spec->value_type); + g_object_get_property (G_OBJECT (setting), param_spec->name, &value); + if (g_param_value_defaults (param_spec, &value)) + return FALSE; + + g_param_value_set_default (param_spec, &value); + g_object_set_property (G_OBJECT (setting), param_spec->name, &value); } - return changed; + return TRUE; } /** @@ -1890,36 +1898,23 @@ _nm_setting_clear_secrets (NMSetting *setting, const NMSettInfoSetting *sett_info; gboolean changed = FALSE; guint i; + gboolean (*my_clear_secrets) (const struct _NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, + NMSettingClearSecretsWithFlagsFn func, + gpointer user_data); g_return_val_if_fail (NM_IS_SETTING (setting), FALSE); + my_clear_secrets = NM_SETTING_GET_CLASS (setting)->clear_secrets; + sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting)); for (i = 0; i < sett_info->property_infos_len; i++) { - GParamSpec *prop_spec = sett_info->property_infos[i].param_spec; - - if (!prop_spec) - continue; - - if (!NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET)) - continue; - - if (func) { - changed |= NM_SETTING_GET_CLASS (setting)->clear_secrets_with_flags (setting, - prop_spec, - func, - user_data); - } else { - GValue value = G_VALUE_INIT; - - g_value_init (&value, prop_spec->value_type); - g_object_get_property (G_OBJECT (setting), prop_spec->name, &value); - if (!g_param_value_defaults (prop_spec, &value)) { - g_param_value_set_default (prop_spec, &value); - g_object_set_property (G_OBJECT (setting), prop_spec->name, &value); - changed = TRUE; - } - g_value_unset (&value); - } + changed |= my_clear_secrets (sett_info, + i, + setting, + func, + user_data); } return changed; } @@ -2575,7 +2570,7 @@ nm_setting_class_init (NMSettingClass *setting_class) setting_class->get_secret_flags = get_secret_flags; setting_class->set_secret_flags = set_secret_flags; setting_class->compare_property = compare_property; - setting_class->clear_secrets_with_flags = clear_secrets_with_flags; + setting_class->clear_secrets = clear_secrets; setting_class->duplicate_copy_properties = duplicate_copy_properties; /** diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index dfdb6cf177..0f0ac8f382 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -200,10 +200,12 @@ typedef struct { NMSettingSecretFlags flags, GError **error); - gboolean (*clear_secrets_with_flags) (NMSetting *setting, - GParamSpec *pspec, - NMSettingClearSecretsWithFlagsFn func, - gpointer user_data); + /*< private >*/ + gboolean (*clear_secrets) (const struct _NMSettInfoSetting *sett_info, + guint property_idx, + NMSetting *setting, + NMSettingClearSecretsWithFlagsFn func, + gpointer user_data); /* compare_property() returns a ternary, where DEFAULT means that the property should not * be compared due to the compare @flags. A TRUE/FALSE result means that the property is |