NetworkManager/0005-fix-saving-agent-owned...

78 lines
3.2 KiB
Diff

From 886493a8f0640d6de8dbc7014df419316eae5784 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Wed, 5 Dec 2018 11:46:45 +0100
Subject: [PATCH 1/2] settings: apply agent-owned secrets from the new
connection on update
When updating a connection passing agent-owned secret, they are lost
from @reread_connection after the settings-plugin persists the
connection. Therefore we need to cache and reapply them separately to
the connection so that they can be saved to secret agents later.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/82
(cherry picked from commit a3383726dce09255b5413a6230be580856ab212c)
(cherry picked from commit 95d9fd387bcdd22e11cca98b540bb68fbd8744a0)
(cherry picked from commit 5420456cf1104a792938089aefcd4f043217edb5)
---
src/settings/nm-settings-connection.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index c09f68040..ccdaddb50 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -611,7 +611,9 @@ nm_settings_connection_update (NMSettingsConnection *self,
gboolean replaced = FALSE;
gs_free char *logmsg_change = NULL;
GError *local = NULL;
+ gs_unref_object NMConnection *simple = NULL;
gs_unref_variant GVariant *con_agent_secrets = NULL;
+ gs_unref_variant GVariant *new_agent_secrets = NULL;
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), FALSE);
@@ -652,6 +654,16 @@ nm_settings_connection_update (NMSettingsConnection *self,
replace_connection = reread_connection ?: new_connection;
+ /* Save agent-owned secrets from the new connection for later use */
+ if (new_connection) {
+ simple = nm_simple_connection_new_clone (new_connection);
+ nm_connection_clear_secrets_with_flags (simple,
+ secrets_filter_cb,
+ GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
+ new_agent_secrets = nm_connection_to_dbus (simple, NM_CONNECTION_SERIALIZE_ONLY_SECRETS);
+ g_clear_object (&simple);
+ }
+
/* Disconnect the changed signal to ensure we don't set Unsaved when
* it's not required.
*/
@@ -662,7 +674,6 @@ nm_settings_connection_update (NMSettingsConnection *self,
&& !nm_connection_compare (NM_CONNECTION (self),
replace_connection,
NM_SETTING_COMPARE_FLAG_EXACT)) {
- gs_unref_object NMConnection *simple = NULL;
if (log_diff_name) {
nm_utils_log_connection_diff (replace_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ",
@@ -709,6 +720,15 @@ nm_settings_connection_update (NMSettingsConnection *self,
(void) nm_connection_update_secrets (NM_CONNECTION (self), NULL, con_agent_secrets, NULL);
}
+ /* Apply agent-owned secrets from the new connection so that
+ * they can be sent to agents */
+ if (new_agent_secrets) {
+ (void) nm_connection_update_secrets (NM_CONNECTION (self),
+ NULL,
+ new_agent_secrets,
+ NULL);
+ }
+
nm_settings_connection_recheck_visibility (self);
if ( replaced
--
2.20.1