[PATCH] Saving agent-owned secrets for newly created connections



Hello,

attached is a patch for sending secrets to agents when a new connection is 
created (AddConnection, AddAndActivateConnection).

At present, when a new connection is created, the secrets are not sent to 
agents and thus not saved. One has to edit the connection again. It is easily 
reproducible by adding a VPN connection. When it is opened again in the 
editor, the secrets are not there.

Jirka
From 08614365ba858a090d11cafdf2f506419678b4f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes redhat com>
Date: Wed, 9 Nov 2011 16:48:35 +0100
Subject: [PATCH] settings: send agent-owned secrets also for newly created
 connections
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We have to send agent-owned secrets to agents via SaveSecrets() D-Bus call for
newly created connections, the same way we do for connection updates.
Without that secrets aren't saved for new created VPN connections, for example.
The secrets was only sent after editing the connection afterwards, i.e.
updating it.

Signed-off-by: Jiří Klimeš <jklimes redhat com>
---
 src/nm-manager.c                      |    4 +++
 src/settings/nm-settings-connection.c |   37 +++++++++++++++++++-------------
 src/settings/nm-settings-connection.h |    3 ++
 src/settings/nm-settings.c            |   20 ++++++++++++-----
 src/settings/nm-settings.h            |    1 +
 5 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/nm-manager.c b/src/nm-manager.c
index 475344a..923d511 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -2124,6 +2124,7 @@ activation_add_done (NMSettings *self,
                      NMSettingsConnection *connection,
                      GError *error,
                      DBusGMethodInvocation *context,
+                     gulong caller_uid,
                      gpointer user_data)
 {
 	PendingActivation *pending = user_data;
@@ -2131,6 +2132,9 @@ activation_add_done (NMSettings *self,
 	if (error)
 		pending_activation_destroy (pending, error, NULL);
 	else {
+		/* Send agent-owned secrets to the agents */
+		nm_settings_connection_save_agent_secrets (connection, caller_uid);
+
 		/* Save the new connection's D-Bus path */
 		pending->connection_path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
 
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index cdad832..647d7f8 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -1098,9 +1098,27 @@ impl_settings_connection_get_settings (NMSettingsConnection *self,
 	auth_start (self, context, NULL, get_settings_auth_cb, NULL);
 }
 
+void
+nm_settings_connection_save_agent_secrets (NMSettingsConnection *self,
+                                           gulong caller_uid)
+{
+	NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
+	NMConnection *for_agent;
+
+	/* Dupe the connection so we can clear out non-agent-owned secrets,
+	 * as agent-owned secrets are the only ones we send back be saved.
+	 * Only send secrets to agents of the same UID that called update too.
+	 */
+	for_agent = nm_connection_duplicate (NM_CONNECTION (self));
+	nm_connection_clear_secrets_with_flags (for_agent,
+	                                        secrets_filter_cb,
+	                                        GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
+	nm_agent_manager_save_secrets (priv->agent_mgr, for_agent, TRUE, caller_uid);
+	g_object_unref (for_agent);
+}
+
 typedef struct {
 	DBusGMethodInvocation *context;
-	NMAgentManager *agent_mgr;
 	gulong sender_uid;
 } UpdateInfo;
 
@@ -1110,26 +1128,17 @@ con_update_cb (NMSettingsConnection *self,
                gpointer user_data)
 {
 	UpdateInfo *info = user_data;
-	NMConnection *for_agent;
 
 	if (error)
 		dbus_g_method_return_error (info->context, error);
 	else {
-		/* Dupe the connection so we can clear out non-agent-owned secrets,
-		 * as agent-owned secrets are the only ones we send back be saved.
-		 * Only send secrets to agents of the same UID that called update too.
-		 */
-		for_agent = nm_connection_duplicate (NM_CONNECTION (self));
-		nm_connection_clear_secrets_with_flags (for_agent,
-		                                        secrets_filter_cb,
-		                                        GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
-		nm_agent_manager_save_secrets (info->agent_mgr, for_agent, TRUE, info->sender_uid);
-		g_object_unref (for_agent);
+
+		/* Send agent-owned secrets to the agents */
+		nm_settings_connection_save_agent_secrets (self, info->sender_uid);
 
 		dbus_g_method_return (info->context);
 	}
 
-	g_object_unref (info->agent_mgr);
 	memset (info, 0, sizeof (*info));
 	g_free (info);
 }
@@ -1141,7 +1150,6 @@ update_auth_cb (NMSettingsConnection *self,
                 GError *error,
                 gpointer data)
 {
-	NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
 	NMConnection *new_settings = data;
 	UpdateInfo *info;
 
@@ -1150,7 +1158,6 @@ update_auth_cb (NMSettingsConnection *self,
 	else {
 		info = g_malloc0 (sizeof (*info));
 		info->context = context;
-		info->agent_mgr = g_object_ref (priv->agent_mgr);
 		info->sender_uid = sender_uid;
 
 		/* Cache the new secrets from the agent, as stuff like inotify-triggered
diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
index bc9e3c4..11374cc 100644
--- a/src/settings/nm-settings-connection.h
+++ b/src/settings/nm-settings-connection.h
@@ -113,6 +113,9 @@ guint32 nm_settings_connection_get_secrets (NMSettingsConnection *connection,
 void nm_settings_connection_cancel_secrets (NMSettingsConnection *connection,
                                             guint32 call_id);
 
+void nm_settings_connection_save_agent_secrets (NMSettingsConnection *self,
+                                                gulong caller_uid);
+
 gboolean nm_settings_connection_is_visible (NMSettingsConnection *self);
 
 void nm_settings_connection_recheck_visibility (NMSettingsConnection *self);
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index f0bfc16..1881af2 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -915,6 +915,7 @@ pk_add_cb (NMAuthChain *chain,
 	NMSettingsConnection *added = NULL;
 	NMSettingsAddCallback callback;
 	gpointer callback_data;
+	gulong caller_uid;
 	const char *perm;
 
 	priv->auths = g_slist_remove (priv->auths, chain);
@@ -954,8 +955,9 @@ pk_add_cb (NMAuthChain *chain,
 done:
 	callback = nm_auth_chain_get_data (chain, "callback");
 	callback_data = nm_auth_chain_get_data (chain, "callback-data");
+	caller_uid = nm_auth_chain_get_data_ulong (chain, "caller-uid");
 
-	callback (self, added, error, context, callback_data);
+	callback (self, added, error, context, caller_uid, callback_data);
 
 	g_clear_error (&error);
 	nm_auth_chain_unref (chain);
@@ -966,12 +968,17 @@ add_cb (NMSettings *self,
         NMSettingsConnection *connection,
         GError *error,
         DBusGMethodInvocation *context,
+        gulong caller_uid,
         gpointer user_data)
 {
 	if (error)
 		dbus_g_method_return_error (context, error);
-	else
+	else {
+		/* Send agent-owned secrets to the agents */
+		nm_settings_connection_save_agent_secrets (connection, caller_uid);
+
 		dbus_g_method_return (context, nm_connection_get_path (NM_CONNECTION (connection)));
+	}
 }
 
 void
@@ -996,7 +1003,7 @@ nm_settings_add_connection (NMSettings *self,
 		                     "The connection was invalid: %s",
 		                     tmp_error ? tmp_error->message : "(unknown)");
 		g_error_free (tmp_error);
-		callback (self, NULL, error, context, user_data);
+		callback (self, NULL, error, context, G_MAXULONG, user_data);
 		g_error_free (error);
 		return;
 	}
@@ -1006,7 +1013,7 @@ nm_settings_add_connection (NMSettings *self,
 		error = g_error_new_literal (NM_SETTINGS_ERROR,
 		                             NM_SETTINGS_ERROR_ADD_NOT_SUPPORTED,
 		                             "None of the registered plugins support add.");
-		callback (self, NULL, error, context, user_data);
+		callback (self, NULL, error, context, G_MAXULONG, user_data);
 		g_error_free (error);
 		return;
 	}
@@ -1018,7 +1025,7 @@ nm_settings_add_connection (NMSettings *self,
 		                     "Unable to determine UID of request: %s.",
 		                     error_desc ? error_desc : "(unknown)");
 		g_free (error_desc);
-		callback (self, NULL, error, context, user_data);
+		callback (self, NULL, error, context, G_MAXULONG, user_data);
 		g_error_free (error);
 		return;
 	}
@@ -1032,7 +1039,7 @@ nm_settings_add_connection (NMSettings *self,
 			                             NM_SETTINGS_ERROR_NOT_PRIVILEGED,
 			                             error_desc);
 			g_free (error_desc);
-			callback (self, NULL, error, context, user_data);
+			callback (self, NULL, error, context, caller_uid, user_data);
 			g_error_free (error);
 			return;
 		}
@@ -1060,6 +1067,7 @@ nm_settings_add_connection (NMSettings *self,
 	nm_auth_chain_set_data (chain, "connection", g_object_ref (connection), g_object_unref);
 	nm_auth_chain_set_data (chain, "callback", callback, NULL);
 	nm_auth_chain_set_data (chain, "callback-data", user_data, NULL);
+	nm_auth_chain_set_data_ulong (chain, "caller-uid", caller_uid);
 }
 
 static void
diff --git a/src/settings/nm-settings.h b/src/settings/nm-settings.h
index 77485e1..b22901f 100644
--- a/src/settings/nm-settings.h
+++ b/src/settings/nm-settings.h
@@ -92,6 +92,7 @@ typedef void (*NMSettingsAddCallback) (NMSettings *settings,
                                        NMSettingsConnection *connection,
                                        GError *error,
                                        DBusGMethodInvocation *context,
+                                       gulong caller_uid,
                                        gpointer user_data);
 
 void nm_settings_add_connection (NMSettings *self,
-- 
1.7.6.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]