mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 15:48:06 +02:00
system-settings: generalize nm_sysconfig_connection_update() a bit
So that it can be the sole location where secrets caching happens.
This commit is contained in:
parent
b135fa3265
commit
0bbdc6b0fc
7 changed files with 19 additions and 23 deletions
|
|
@ -57,6 +57,7 @@ ignore_cb (NMSettingsConnectionInterface *connection,
|
||||||
gboolean
|
gboolean
|
||||||
nm_sysconfig_connection_update (NMSysconfigConnection *self,
|
nm_sysconfig_connection_update (NMSysconfigConnection *self,
|
||||||
NMConnection *new,
|
NMConnection *new,
|
||||||
|
gboolean signal_update,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GHashTable *new_settings;
|
GHashTable *new_settings;
|
||||||
|
|
@ -71,9 +72,11 @@ nm_sysconfig_connection_update (NMSysconfigConnection *self,
|
||||||
new_settings = nm_connection_to_hash (new);
|
new_settings = nm_connection_to_hash (new);
|
||||||
g_assert (new_settings);
|
g_assert (new_settings);
|
||||||
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) {
|
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) {
|
||||||
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
|
if (signal_update) {
|
||||||
ignore_cb,
|
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
|
||||||
NULL);
|
ignore_cb,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
}
|
}
|
||||||
g_hash_table_destroy (new_settings);
|
g_hash_table_destroy (new_settings);
|
||||||
|
|
@ -282,7 +285,6 @@ pk_update_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||||
NMSysconfigConnectionPrivate *priv;
|
NMSysconfigConnectionPrivate *priv;
|
||||||
PolkitAuthorizationResult *pk_result;
|
PolkitAuthorizationResult *pk_result;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GHashTable *settings;
|
|
||||||
|
|
||||||
/* If our NMSysconfigConnection is already gone, do nothing */
|
/* If our NMSysconfigConnection is already gone, do nothing */
|
||||||
if (call->disposed) {
|
if (call->disposed) {
|
||||||
|
|
@ -322,19 +324,18 @@ pk_update_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update our settings internally so the update() call will save the new
|
/* Update our settings internally so the update() call will save the new
|
||||||
* ones.
|
* ones. We don't let nm_sysconfig_connection_update() handle the update
|
||||||
|
* signal since we need our own callback after the update is done.
|
||||||
*/
|
*/
|
||||||
settings = nm_connection_to_hash (call->connection);
|
if (!nm_sysconfig_connection_update (self, call->connection, FALSE, &error)) {
|
||||||
if (!nm_connection_replace_settings (NM_CONNECTION (self), settings, &error)) {
|
|
||||||
/* Shouldn't really happen since we've already validated the settings */
|
/* Shouldn't really happen since we've already validated the settings */
|
||||||
dbus_g_method_return_error (call->context, error);
|
dbus_g_method_return_error (call->context, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
polkit_call_free (call);
|
polkit_call_free (call);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
g_hash_table_destroy (settings);
|
|
||||||
|
|
||||||
/* Caller is authenticated, now we can finally try to update */
|
/* Caller is authenticated, now we can finally try to commit the update */
|
||||||
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
|
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
|
||||||
con_update_cb,
|
con_update_cb,
|
||||||
call);
|
call);
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,12 @@ typedef struct {
|
||||||
|
|
||||||
GType nm_sysconfig_connection_get_type (void);
|
GType nm_sysconfig_connection_get_type (void);
|
||||||
|
|
||||||
/* Called by a system-settings plugin to update a connection when the
|
/* Called by a system-settings plugin to update a connection is out of sync
|
||||||
* connection's backing storage has changed.
|
* with it's backing storage.
|
||||||
*/
|
*/
|
||||||
gboolean nm_sysconfig_connection_update (NMSysconfigConnection *self,
|
gboolean nm_sysconfig_connection_update (NMSysconfigConnection *self,
|
||||||
NMConnection *new_settings,
|
NMConnection *new_settings,
|
||||||
|
gboolean signal_update,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ nm_ifcfg_connection_new (const char *filename,
|
||||||
char *unmanaged = NULL;
|
char *unmanaged = NULL;
|
||||||
char *keyfile = NULL;
|
char *keyfile = NULL;
|
||||||
NMInotifyHelper *ih;
|
NMInotifyHelper *ih;
|
||||||
GHashTable *settings;
|
|
||||||
|
|
||||||
g_return_val_if_fail (filename != NULL, NULL);
|
g_return_val_if_fail (filename != NULL, NULL);
|
||||||
|
|
||||||
|
|
@ -126,9 +125,7 @@ nm_ifcfg_connection_new (const char *filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update our settings with what was read from the file */
|
/* Update our settings with what was read from the file */
|
||||||
settings = nm_connection_to_hash (tmp);
|
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
|
||||||
nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL);
|
|
||||||
g_hash_table_destroy (settings);
|
|
||||||
g_object_unref (tmp);
|
g_object_unref (tmp);
|
||||||
|
|
||||||
priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object);
|
priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object);
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,7 @@ connection_changed_handler (SCPluginIfcfg *plugin,
|
||||||
|
|
||||||
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (connection),
|
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (connection),
|
||||||
NM_CONNECTION (new),
|
NM_CONNECTION (new),
|
||||||
|
TRUE,
|
||||||
&error)) {
|
&error)) {
|
||||||
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " error updating: %s",
|
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " error updating: %s",
|
||||||
(error && error->message) ? error->message : "(unknown)");
|
(error && error->message) ? error->message : "(unknown)");
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ file_changed (GFileMonitor *monitor,
|
||||||
if (new) {
|
if (new) {
|
||||||
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (self),
|
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (self),
|
||||||
NM_CONNECTION (new),
|
NM_CONNECTION (new),
|
||||||
|
TRUE,
|
||||||
&error)) {
|
&error)) {
|
||||||
g_warning ("%s: '%s' / '%s' invalid: %d",
|
g_warning ("%s: '%s' / '%s' invalid: %d",
|
||||||
__func__,
|
__func__,
|
||||||
|
|
@ -87,7 +88,6 @@ nm_suse_connection_new (const char *iface, NMDeviceType dev_type)
|
||||||
GFileMonitor *monitor;
|
GFileMonitor *monitor;
|
||||||
NMSuseConnection *exported;
|
NMSuseConnection *exported;
|
||||||
NMSuseConnectionPrivate *priv;
|
NMSuseConnectionPrivate *priv;
|
||||||
GHashTable *settings;
|
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
|
|
||||||
g_return_val_if_fail (iface != NULL, NULL);
|
g_return_val_if_fail (iface != NULL, NULL);
|
||||||
|
|
@ -112,9 +112,7 @@ nm_suse_connection_new (const char *iface, NMDeviceType dev_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update our settings with what was read from the file */
|
/* Update our settings with what was read from the file */
|
||||||
settings = nm_connection_to_hash (tmp);
|
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (exported), tmp, FALSE, NULL);
|
||||||
nm_connection_replace_settings (NM_CONNECTION (exported), settings, NULL);
|
|
||||||
g_hash_table_destroy (settings);
|
|
||||||
g_object_unref (tmp);
|
g_object_unref (tmp);
|
||||||
|
|
||||||
priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported);
|
priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported);
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,6 @@ constructor (GType type,
|
||||||
NMKeyfileConnectionPrivate *priv;
|
NMKeyfileConnectionPrivate *priv;
|
||||||
NMSettingConnection *s_con;
|
NMSettingConnection *s_con;
|
||||||
NMConnection *tmp;
|
NMConnection *tmp;
|
||||||
GHashTable *settings;
|
|
||||||
|
|
||||||
object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
object = G_OBJECT_CLASS (nm_keyfile_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||||
|
|
||||||
|
|
@ -148,9 +147,7 @@ constructor (GType type,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
settings = nm_connection_to_hash (tmp);
|
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
|
||||||
nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL);
|
|
||||||
g_hash_table_destroy (settings);
|
|
||||||
g_object_unref (tmp);
|
g_object_unref (tmp);
|
||||||
|
|
||||||
/* if for some reason the connection didn't have a UUID, add one */
|
/* if for some reason the connection didn't have a UUID, add one */
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,7 @@ update_connection_settings (NMKeyfileConnection *orig,
|
||||||
|
|
||||||
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (orig),
|
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (orig),
|
||||||
NM_CONNECTION (new),
|
NM_CONNECTION (new),
|
||||||
|
TRUE,
|
||||||
&error)) {
|
&error)) {
|
||||||
g_warning ("%s: '%s' / '%s' invalid: %d",
|
g_warning ("%s: '%s' / '%s' invalid: %d",
|
||||||
__func__,
|
__func__,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue