settings: call replace-settings also without new settings

_replace_settings_full() does more then just replace the settings.
It at least also sets some flags, like saved/unsaved depending
on @persist_mode.

_replace_settings_full() also emits the "updated" signal. Note that
previously it would just return without signal if nm_connection_compare()
indicates that there is no difference. But the caller probably cares
about whether the user tries to change the connection at all, not
whether the change actually introduced a real difference in the
settings. Like, policy might re-set the autoconnect blocked flags.
But it should do so on every user-update, regardless of whether
a change was actually made.

It makes sense to call _replace_settings_full() with a @new_connection
of %NULL, to mean: just update the flags, but keep the current connection.

Extend _replace_settings_full() to allow for that.

Also, update update_auth_cb() to always call _replace_settings_full(),
even if no new connection is provided. In this case, only update
the connection flags accordingly.

(cherry picked from commit 9988f9dbbb)
This commit is contained in:
Thomas Haller 2017-11-29 19:35:39 +01:00
parent 359e52651b
commit 2bac3ea550

View file

@ -561,56 +561,60 @@ _replace_settings_full (NMSettingsConnection *self,
GError **error)
{
NMSettingsConnectionPrivate *priv;
gboolean replaced = FALSE;
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (new_connection), FALSE);
g_return_val_if_fail (!new_connection || NM_IS_CONNECTION (new_connection), FALSE);
priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
if ( prepare_new_connection
&& new_connection
&& !nm_settings_connection_replace_settings_prepare (self,
new_connection,
error))
return FALSE;
/* Do nothing if there's nothing to update */
if (nm_connection_compare (NM_CONNECTION (self),
new_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
return TRUE;
}
/* Disconnect the changed signal to ensure we don't set Unsaved when
* it's not required.
*/
g_signal_handlers_block_by_func (self, G_CALLBACK (connection_changed_cb), NULL);
if (log_diff_name)
nm_utils_log_connection_diff (new_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ");
/* Do nothing if there's nothing to update */
if ( new_connection
&& !nm_connection_compare (NM_CONNECTION (self),
new_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
if (log_diff_name)
nm_utils_log_connection_diff (new_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ");
nm_connection_replace_settings_from_connection (NM_CONNECTION (self), new_connection);
nm_connection_replace_settings_from_connection (NM_CONNECTION (self), new_connection);
_LOGD ("replace settings from connection %p (%s)", new_connection, nm_connection_get_id (NM_CONNECTION (self)));
replaced = TRUE;
_LOGD ("replace settings from connection %p (%s)", new_connection, nm_connection_get_id (NM_CONNECTION (self)));
}
nm_settings_connection_set_flags (self,
NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED | NM_SETTINGS_CONNECTION_FLAGS_VOLATILE,
FALSE);
/* Cache the just-updated system secrets in case something calls
* nm_connection_clear_secrets() and clears them.
*/
update_system_secrets_cache (self);
if (replaced) {
/* Cache the just-updated system secrets in case something calls
* nm_connection_clear_secrets() and clears them.
*/
update_system_secrets_cache (self);
/* Add agent and always-ask secrets back; they won't necessarily be
* in the replacement connection data if it was eg reread from disk.
*/
if (priv->agent_secrets) {
GVariant *dict;
/* Add agent and always-ask secrets back; they won't necessarily be
* in the replacement connection data if it was eg reread from disk.
*/
if (priv->agent_secrets) {
GVariant *dict;
dict = nm_connection_to_dbus (priv->agent_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) {
(void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, dict, NULL);
g_variant_unref (dict);
dict = nm_connection_to_dbus (priv->agent_secrets, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
if (dict) {
(void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, dict, NULL);
g_variant_unref (dict);
}
}
}
@ -1740,29 +1744,26 @@ update_auth_cb (NMSettingsConnection *self,
}
if (!info->save_to_disk) {
if (info->new_settings) {
_replace_settings_full (self,
info->new_settings,
FALSE,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY,
"replace-unsaved",
&local);
}
goto out;
_replace_settings_full (self,
info->new_settings,
FALSE,
NM_SETTINGS_CONNECTION_PERSIST_MODE_IN_MEMORY,
"replace-unsaved",
&local);
} else {
commit_reason = NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION;
if ( info->new_settings
&& !nm_streq0 (nm_connection_get_id (NM_CONNECTION (self)),
nm_connection_get_id (info->new_settings)))
commit_reason |= NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED;
_commit_changes_full (self,
info->new_settings,
FALSE,
commit_reason,
&local);
}
commit_reason = NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION;
if ( info->new_settings
&& !nm_streq0 (nm_connection_get_id (NM_CONNECTION (self)),
nm_connection_get_id (info->new_settings)))
commit_reason |= NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED;
_commit_changes_full (self,
info->new_settings,
FALSE,
commit_reason,
&local);
out:
if (!local) {
gs_unref_object NMConnection *for_agent = NULL;