libnm: merge _nm_setting_clear_secrets() and *_with_flags()
This commit is contained in:
@@ -1832,26 +1832,14 @@ nm_connection_need_secrets (NMConnection *connection,
|
|||||||
void
|
void
|
||||||
nm_connection_clear_secrets (NMConnection *connection)
|
nm_connection_clear_secrets (NMConnection *connection)
|
||||||
{
|
{
|
||||||
GHashTableIter iter;
|
return nm_connection_clear_secrets_with_flags (connection, NULL, NULL);
|
||||||
NMSetting *setting;
|
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_CONNECTION (connection));
|
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
|
|
||||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
|
|
||||||
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
|
||||||
_nm_setting_clear_secrets (setting);
|
|
||||||
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_signal_emit (connection, signals[SECRETS_CLEARED], 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_connection_clear_secrets_with_flags:
|
* nm_connection_clear_secrets_with_flags:
|
||||||
* @connection: the #NMConnection
|
* @connection: the #NMConnection
|
||||||
* @func: (scope call): function to be called to determine whether a
|
* @func: (scope call): (allow-none): function to be called to determine whether a
|
||||||
* specific secret should be cleared or not
|
* specific secret should be cleared or not. If %NULL, all secrets are cleared.
|
||||||
* @user_data: caller-supplied data passed to @func
|
* @user_data: caller-supplied data passed to @func
|
||||||
*
|
*
|
||||||
* Clears and frees secrets determined by @func.
|
* Clears and frees secrets determined by @func.
|
||||||
@@ -1869,7 +1857,7 @@ nm_connection_clear_secrets_with_flags (NMConnection *connection,
|
|||||||
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
|
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
|
||||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
|
||||||
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||||
_nm_setting_clear_secrets_with_flags (setting, func, user_data);
|
_nm_setting_clear_secrets (setting, func, user_data);
|
||||||
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,8 +48,7 @@ typedef enum NMSettingUpdateSecretResult {
|
|||||||
NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting,
|
NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting,
|
||||||
GVariant *secrets,
|
GVariant *secrets,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean _nm_setting_clear_secrets (NMSetting *setting);
|
gboolean _nm_setting_clear_secrets (NMSetting *setting,
|
||||||
gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
|
||||||
NMSettingClearSecretsWithFlagsFn func,
|
NMSettingClearSecretsWithFlagsFn func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
@@ -1840,48 +1840,6 @@ _nm_setting_aggregate (NMSetting *setting,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* _nm_setting_clear_secrets:
|
|
||||||
* @setting: the #NMSetting
|
|
||||||
*
|
|
||||||
* Resets and clears any secrets in the setting. Secrets should be added to the
|
|
||||||
* setting only when needed, and cleared immediately after use to prevent
|
|
||||||
* leakage of information.
|
|
||||||
*
|
|
||||||
* Returns: %TRUE if the setting changed at all
|
|
||||||
**/
|
|
||||||
gboolean
|
|
||||||
_nm_setting_clear_secrets (NMSetting *setting)
|
|
||||||
{
|
|
||||||
const NMSettInfoSetting *sett_info;
|
|
||||||
gboolean changed = FALSE;
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
|
||||||
|
|
||||||
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 (prop_spec->flags & NM_SETTING_PARAM_SECRET) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
clear_secrets_with_flags (NMSetting *setting,
|
clear_secrets_with_flags (NMSetting *setting,
|
||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
@@ -1914,7 +1872,7 @@ clear_secrets_with_flags (NMSetting *setting,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _nm_setting_clear_secrets_with_flags:
|
* _nm_setting_clear_secrets:
|
||||||
* @setting: the #NMSetting
|
* @setting: the #NMSetting
|
||||||
* @func: (scope call): function to be called to determine whether a
|
* @func: (scope call): function to be called to determine whether a
|
||||||
* specific secret should be cleared or not
|
* specific secret should be cleared or not
|
||||||
@@ -1925,7 +1883,7 @@ clear_secrets_with_flags (NMSetting *setting,
|
|||||||
* Returns: %TRUE if the setting changed at all
|
* Returns: %TRUE if the setting changed at all
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
_nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
_nm_setting_clear_secrets (NMSetting *setting,
|
||||||
NMSettingClearSecretsWithFlagsFn func,
|
NMSettingClearSecretsWithFlagsFn func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -1934,7 +1892,6 @@ _nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
|||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||||
g_return_val_if_fail (func != NULL, FALSE);
|
|
||||||
|
|
||||||
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
|
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
|
||||||
for (i = 0; i < sett_info->property_infos_len; i++) {
|
for (i = 0; i < sett_info->property_infos_len; i++) {
|
||||||
@@ -1946,10 +1903,23 @@ _nm_setting_clear_secrets_with_flags (NMSetting *setting,
|
|||||||
if (!NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET))
|
if (!NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (func) {
|
||||||
changed |= NM_SETTING_GET_CLASS (setting)->clear_secrets_with_flags (setting,
|
changed |= NM_SETTING_GET_CLASS (setting)->clear_secrets_with_flags (setting,
|
||||||
prop_spec,
|
prop_spec,
|
||||||
func,
|
func,
|
||||||
user_data);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user