settings: refactor error handling in update_auth_cb()

This commit is contained in:
Thomas Haller
2023-06-22 11:36:55 +02:00
parent 454f8fc7d6
commit 9bc9fde506

View File

@@ -1465,7 +1465,7 @@ update_complete(NMSettingsConnection *self, UpdateInfo *info, GError *error)
g_clear_object(&info->new_settings); g_clear_object(&info->new_settings);
g_free(info->audit_args); g_free(info->audit_args);
g_free(info->plugin_name); g_free(info->plugin_name);
g_slice_free(UpdateInfo, info); nm_g_slice_free(info);
} }
static void static void
@@ -1479,11 +1479,10 @@ update_auth_cb(NMSettingsConnection *self,
UpdateInfo *info = data; UpdateInfo *info = data;
gs_free_error GError *local = NULL; gs_free_error GError *local = NULL;
NMSettingsConnectionPersistMode persist_mode; NMSettingsConnectionPersistMode persist_mode;
gs_unref_object NMConnection *for_agent = NULL;
if (error) { if (error)
update_complete(self, info, error); goto out;
return;
}
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self); priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
@@ -1579,27 +1578,29 @@ update_auth_cb(NMSettingsConnection *self,
"update-from-dbus", "update-from-dbus",
&local); &local);
if (!local) { if (local) {
gs_unref_object NMConnection *for_agent = NULL; error = local;
goto out;
/* Dupe the connection so we can clear out non-agent-owned secrets,
* as agent-owned secrets are the only ones we send back to be saved.
* Only send secrets to agents of the same UID that called update too.
*/
for_agent = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self));
_nm_connection_clear_secrets_by_secret_flags(for_agent, NM_SETTING_SECRET_FLAG_AGENT_OWNED);
nm_agent_manager_save_secrets(info->agent_mgr,
nm_dbus_object_get_path(NM_DBUS_OBJECT(self)),
for_agent,
info->subject);
} }
/* Dupe the connection so we can clear out non-agent-owned secrets,
* as agent-owned secrets are the only ones we send back to be saved.
* Only send secrets to agents of the same UID that called update too.
*/
for_agent = nm_simple_connection_new_clone(nm_settings_connection_get_connection(self));
_nm_connection_clear_secrets_by_secret_flags(for_agent, NM_SETTING_SECRET_FLAG_AGENT_OWNED);
nm_agent_manager_save_secrets(info->agent_mgr,
nm_dbus_object_get_path(NM_DBUS_OBJECT(self)),
for_agent,
info->subject);
/* Reset auto retries back to default since connection was updated */ /* Reset auto retries back to default since connection was updated */
nm_manager_devcon_autoconnect_retries_reset(nm_settings_connection_get_manager(self), nm_manager_devcon_autoconnect_retries_reset(nm_settings_connection_get_manager(self),
NULL, NULL,
self); self);
update_complete(self, info, local); out:
update_complete(self, info, error);
} }
static const char * static const char *
@@ -1679,14 +1680,16 @@ settings_connection_update(NMSettingsConnection *self,
&error)) &error))
goto error; goto error;
info = g_slice_new0(UpdateInfo); info = g_slice_new(UpdateInfo);
info->is_update2 = is_update2; *info = (UpdateInfo){
info->context = context; .is_update2 = is_update2,
info->agent_mgr = g_object_ref(priv->agent_mgr); .context = context,
info->subject = subject; .agent_mgr = g_object_ref(priv->agent_mgr),
info->flags = flags; .subject = subject,
info->new_settings = tmp; .flags = flags,
info->plugin_name = g_strdup(plugin_name); .new_settings = tmp,
.plugin_name = g_strdup(plugin_name),
};
permission = get_update_modify_permission(nm_settings_connection_get_connection(self), permission = get_update_modify_permission(nm_settings_connection_get_connection(self),
tmp ?: nm_settings_connection_get_connection(self)); tmp ?: nm_settings_connection_get_connection(self));