libnm: fix setting error for nm_connection_update_secrets()
By convention, a function that indicates failure *MUST* set an error. Also, an error can only be set once.
This commit is contained in:
@@ -1866,7 +1866,8 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMSetting *setting;
|
NMSetting *setting;
|
||||||
gboolean success = TRUE, updated = FALSE;
|
gboolean success = TRUE;
|
||||||
|
gboolean updated = FALSE;
|
||||||
GVariant *setting_dict = NULL;
|
GVariant *setting_dict = NULL;
|
||||||
GVariantIter iter;
|
GVariantIter iter;
|
||||||
const char *key;
|
const char *key;
|
||||||
@@ -1874,13 +1875,13 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||||||
int success_detail;
|
int success_detail;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
|
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
|
||||||
g_return_val_if_fail ( g_variant_is_of_type (secrets, NM_VARIANT_TYPE_SETTING)
|
|
||||||
|| g_variant_is_of_type (secrets, NM_VARIANT_TYPE_CONNECTION), FALSE);
|
|
||||||
if (error)
|
|
||||||
g_return_val_if_fail (*error == NULL, FALSE);
|
|
||||||
|
|
||||||
full_connection = g_variant_is_of_type (secrets, NM_VARIANT_TYPE_CONNECTION);
|
full_connection = g_variant_is_of_type (secrets, NM_VARIANT_TYPE_CONNECTION);
|
||||||
g_return_val_if_fail (setting_name != NULL || full_connection, FALSE);
|
|
||||||
|
g_return_val_if_fail ( full_connection
|
||||||
|
|| g_variant_is_of_type (secrets, NM_VARIANT_TYPE_SETTING), FALSE);
|
||||||
|
g_return_val_if_fail (!error || !*error, FALSE);
|
||||||
|
g_return_val_if_fail (setting_name || full_connection, FALSE);
|
||||||
|
|
||||||
/* Empty @secrets means success */
|
/* Empty @secrets means success */
|
||||||
if (g_variant_n_children (secrets) == 0)
|
if (g_variant_n_children (secrets) == 0)
|
||||||
@@ -1915,8 +1916,10 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||||||
|
|
||||||
g_clear_pointer (&setting_dict, g_variant_unref);
|
g_clear_pointer (&setting_dict, g_variant_unref);
|
||||||
|
|
||||||
if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR)
|
if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR) {
|
||||||
|
nm_assert (!error || *error);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
if (success_detail == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
|
if (success_detail == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
|
||||||
updated = TRUE;
|
updated = TRUE;
|
||||||
} else {
|
} else {
|
||||||
@@ -1936,17 +1939,27 @@ nm_connection_update_secrets (NMConnection *connection,
|
|||||||
/* Update each setting with any secrets from the connection dictionary */
|
/* Update each setting with any secrets from the connection dictionary */
|
||||||
g_variant_iter_init (&iter, secrets);
|
g_variant_iter_init (&iter, secrets);
|
||||||
while (g_variant_iter_next (&iter, "{&s@a{sv}}", &key, &setting_dict)) {
|
while (g_variant_iter_next (&iter, "{&s@a{sv}}", &key, &setting_dict)) {
|
||||||
|
gs_free_error GError *local = NULL;
|
||||||
|
|
||||||
/* Update the secrets for this setting */
|
/* Update the secrets for this setting */
|
||||||
setting = nm_connection_get_setting_by_name (connection, key);
|
setting = nm_connection_get_setting_by_name (connection, key);
|
||||||
|
|
||||||
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
g_signal_handlers_block_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||||
success_detail = _nm_setting_update_secrets (setting, setting_dict, error);
|
success_detail = _nm_setting_update_secrets (setting, setting_dict, error ? &local : NULL);
|
||||||
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
g_signal_handlers_unblock_by_func (setting, (GCallback) setting_changed_cb, connection);
|
||||||
|
|
||||||
g_variant_unref (setting_dict);
|
g_variant_unref (setting_dict);
|
||||||
|
|
||||||
if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR) {
|
if (success_detail == NM_SETTING_UPDATE_SECRET_ERROR) {
|
||||||
|
if (success) {
|
||||||
|
if (error) {
|
||||||
|
nm_assert (local);
|
||||||
|
g_propagate_error (error, g_steal_pointer (&local));
|
||||||
|
error = NULL;
|
||||||
|
} else
|
||||||
|
nm_assert (!local);
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (success_detail == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
|
if (success_detail == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
|
||||||
|
@@ -648,7 +648,7 @@ test_update_secrets_null_setting_name_with_setting_hash (void)
|
|||||||
|
|
||||||
secrets = build_wep_secrets (wepkey);
|
secrets = build_wep_secrets (wepkey);
|
||||||
|
|
||||||
NMTST_EXPECT_LIBNM_CRITICAL (NMTST_G_RETURN_MSG (setting_name != NULL || full_connection));
|
NMTST_EXPECT_LIBNM_CRITICAL (NMTST_G_RETURN_MSG (setting_name || full_connection));
|
||||||
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
|
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
|
||||||
g_test_assert_expected_messages ();
|
g_test_assert_expected_messages ();
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
Reference in New Issue
Block a user