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:
Dan Williams 2009-11-16 16:14:50 -08:00
parent b135fa3265
commit 0bbdc6b0fc
7 changed files with 19 additions and 23 deletions

View file

@ -57,6 +57,7 @@ ignore_cb (NMSettingsConnectionInterface *connection,
gboolean
nm_sysconfig_connection_update (NMSysconfigConnection *self,
NMConnection *new,
gboolean signal_update,
GError **error)
{
GHashTable *new_settings;
@ -71,9 +72,11 @@ nm_sysconfig_connection_update (NMSysconfigConnection *self,
new_settings = nm_connection_to_hash (new);
g_assert (new_settings);
if (nm_connection_replace_settings (NM_CONNECTION (self), new_settings, error)) {
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
ignore_cb,
NULL);
if (signal_update) {
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (self),
ignore_cb,
NULL);
}
success = TRUE;
}
g_hash_table_destroy (new_settings);
@ -282,7 +285,6 @@ pk_update_cb (GObject *object, GAsyncResult *result, gpointer user_data)
NMSysconfigConnectionPrivate *priv;
PolkitAuthorizationResult *pk_result;
GError *error = NULL;
GHashTable *settings;
/* If our NMSysconfigConnection is already gone, do nothing */
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
* 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_connection_replace_settings (NM_CONNECTION (self), settings, &error)) {
if (!nm_sysconfig_connection_update (self, call->connection, FALSE, &error)) {
/* Shouldn't really happen since we've already validated the settings */
dbus_g_method_return_error (call->context, error);
g_error_free (error);
polkit_call_free (call);
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),
con_update_cb,
call);

View file

@ -43,11 +43,12 @@ typedef struct {
GType nm_sysconfig_connection_get_type (void);
/* Called by a system-settings plugin to update a connection when the
* connection's backing storage has changed.
/* Called by a system-settings plugin to update a connection is out of sync
* with it's backing storage.
*/
gboolean nm_sysconfig_connection_update (NMSysconfigConnection *self,
NMConnection *new_settings,
gboolean signal_update,
GError **error);
G_END_DECLS

View file

@ -108,7 +108,6 @@ nm_ifcfg_connection_new (const char *filename,
char *unmanaged = NULL;
char *keyfile = NULL;
NMInotifyHelper *ih;
GHashTable *settings;
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 */
settings = nm_connection_to_hash (tmp);
nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL);
g_hash_table_destroy (settings);
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
g_object_unref (tmp);
priv = NM_IFCFG_CONNECTION_GET_PRIVATE (object);

View file

@ -283,6 +283,7 @@ connection_changed_handler (SCPluginIfcfg *plugin,
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (connection),
NM_CONNECTION (new),
TRUE,
&error)) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " error updating: %s",
(error && error->message) ? error->message : "(unknown)");

View file

@ -59,6 +59,7 @@ file_changed (GFileMonitor *monitor,
if (new) {
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (self),
NM_CONNECTION (new),
TRUE,
&error)) {
g_warning ("%s: '%s' / '%s' invalid: %d",
__func__,
@ -87,7 +88,6 @@ nm_suse_connection_new (const char *iface, NMDeviceType dev_type)
GFileMonitor *monitor;
NMSuseConnection *exported;
NMSuseConnectionPrivate *priv;
GHashTable *settings;
NMSettingConnection *s_con;
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 */
settings = nm_connection_to_hash (tmp);
nm_connection_replace_settings (NM_CONNECTION (exported), settings, NULL);
g_hash_table_destroy (settings);
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (exported), tmp, FALSE, NULL);
g_object_unref (tmp);
priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported);

View file

@ -131,7 +131,6 @@ constructor (GType type,
NMKeyfileConnectionPrivate *priv;
NMSettingConnection *s_con;
NMConnection *tmp;
GHashTable *settings;
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;
}
settings = nm_connection_to_hash (tmp);
nm_connection_replace_settings (NM_CONNECTION (object), settings, NULL);
g_hash_table_destroy (settings);
nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (object), tmp, FALSE, NULL);
g_object_unref (tmp);
/* if for some reason the connection didn't have a UUID, add one */

View file

@ -130,6 +130,7 @@ update_connection_settings (NMKeyfileConnection *orig,
if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (orig),
NM_CONNECTION (new),
TRUE,
&error)) {
g_warning ("%s: '%s' / '%s' invalid: %d",
__func__,