about summary refs log tree commit diff
path: root/src/nm-active-connection.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-06-04 00:08:31 +0200
committerMichael Biebl <biebl@debian.org>2018-06-04 00:08:31 +0200
commit0dd9df69fdbd475c48a0c8d5b0a1882550fe7321 (patch)
tree249cf25643b1fe408e10679bb61613bc6540e894 /src/nm-active-connection.c
parent2e94a3b93171ab3fb95bf689aab1664d23988809 (diff)
parent04bc9e1cd3544445d883ad29ea108c1645c8e7b7 (diff)
Update upstream source from tag 'upstream/1.11.4'
Update to upstream version '1.11.4'
with Debian dir d0638aa2e32d5bae4e8daa021b9a66b7c4d6647e
Diffstat (limited to 'src/nm-active-connection.c')
-rw-r--r--src/nm-active-connection.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index c6d6645d..aa83d6d5 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -55,7 +55,12 @@ typedef struct _NMActiveConnectionPrivate {
 	bool master_ready:1;
 
 	NMActivationType activation_type:3;
-	NMActivationReason activation_reason:3;
+
+	/* capture the original reason why the connection was activated.
+	 * For example with NM_ACTIVATION_REASON_ASSUME, the connection
+	 * will later change to become fully managed. But the original
+	 * reason never changes. */
+	NMActivationReason activation_reason:4;
 
 	NMAuthSubject *subject;
 	NMActiveConnection *master;
@@ -67,8 +72,7 @@ typedef struct _NMActiveConnectionPrivate {
 		NMAuthManagerCallId *call_id_wifi_shared_permission;
 
 		NMActiveConnectionAuthResultFunc result_func;
-		gpointer user_data1;
-		gpointer user_data2;
+		gpointer user_data;
 	} auth;
 
 } NMActiveConnectionPrivate;
@@ -125,6 +129,8 @@ static void _settings_connection_flags_changed (NMSettingsConnection *settings_c
                                                 NMActiveConnection *self);
 static void _set_activation_type_managed (NMActiveConnection *self);
 
+static void auth_complete (NMActiveConnection *self, gboolean result, const char *message);
+
 /*****************************************************************************/
 
 #define _NMLOG_DOMAIN         LOGD_DEVICE
@@ -236,13 +242,13 @@ nm_active_connection_set_state (NMActiveConnection *self,
 	NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
 	NMActiveConnectionState old_state;
 
+	/* DEACTIVATED is a terminal state */
+	g_return_if_fail (   priv->state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
+	                  || new_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED);
+
 	if (priv->state == new_state)
 		return;
 
-	/* DEACTIVATED is a terminal state */
-	if (priv->state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
-		g_return_if_fail (new_state != NM_ACTIVE_CONNECTION_STATE_DEACTIVATED);
-
 	_LOGD ("set state %s (was %s)",
 	       state_to_string (new_state),
 	       state_to_string (priv->state));
@@ -288,6 +294,10 @@ nm_active_connection_set_state (NMActiveConnection *self,
 	}
 
 	if (priv->state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
+		_nm_unused gs_unref_object NMActiveConnection *self_keep_alive = g_object_ref (self);
+
+		auth_complete (self, FALSE, "Authorization request cancelled");
+
 		/* Device is no longer relevant when deactivated. So remove it and
 		 * emit property change notification so clients re-read the value,
 		 * which will be NULL due to conditions in get_property().
@@ -426,7 +436,7 @@ _set_applied_connection_take (NMActiveConnection *self,
 	if (nm_setting_connection_get_master (s_con))
 		flags_val |= NM_ACTIVATION_STATE_FLAG_IS_SLAVE;
 
-	if (+_nm_connection_type_is_master (nm_setting_connection_get_connection_type (s_con)))
+	if (_nm_connection_type_is_master (nm_setting_connection_get_connection_type (s_con)))
 		flags_val |= NM_ACTIVATION_STATE_FLAG_IS_MASTER;
 
 	nm_active_connection_set_state_flags_full (self,
@@ -986,9 +996,11 @@ nm_active_connection_set_parent (NMActiveConnection *self, NMActiveConnection *p
 /*****************************************************************************/
 
 static void
-auth_cancel (NMActiveConnection *self)
+auth_complete (NMActiveConnection *self, gboolean result, const char *message)
 {
 	NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
+	NMActiveConnectionAuthResultFunc result_func;
+	gpointer user_data;
 
 	if (priv->auth.call_id_network_control)
 		nm_auth_manager_check_authorization_cancel (priv->auth.call_id_network_control);
@@ -998,23 +1010,27 @@ auth_cancel (NMActiveConnection *self)
 		else
 			nm_auth_manager_check_authorization_cancel (priv->auth.call_id_wifi_shared_permission);
 	}
-	priv->auth.result_func = NULL;
-	priv->auth.user_data1 = NULL;
-	priv->auth.user_data2 = NULL;
+
+	nm_assert (!priv->auth.call_id_network_control);
+	nm_assert (!priv->auth.call_id_wifi_shared_permission);
+	if (priv->auth.result_func) {
+		result_func = priv->auth.result_func;
+		priv->auth.result_func = NULL;
+		user_data = g_steal_pointer (&priv->auth.user_data);
+
+		result_func (self,
+		             result,
+		             message,
+		             user_data);
+	}
 }
 
 static void
-auth_complete (NMActiveConnection *self, gboolean result, const char *message)
+auth_complete_keep_alive (NMActiveConnection *self, gboolean result, const char *message)
 {
 	_nm_unused gs_unref_object NMActiveConnection *self_keep_alive = g_object_ref (self);
-	NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
 
-	priv->auth.result_func (self,
-	                        result,
-	                        message,
-	                        priv->auth.user_data1,
-	                        priv->auth.user_data2);
-	auth_cancel (self);
+	auth_complete (self, result, message);
 }
 
 static void
@@ -1048,7 +1064,7 @@ auth_done (NMAuthManager *auth_mgr,
 	if (auth_call_id == priv->auth.call_id_network_control) {
 		priv->auth.call_id_network_control = NULL;
 		if (result != NM_AUTH_CALL_RESULT_YES) {
-			auth_complete (self, FALSE, "Not authorized to control networking.");
+			auth_complete_keep_alive (self, FALSE, "Not authorized to control networking.");
 			return;
 		}
 	} else {
@@ -1068,11 +1084,11 @@ auth_done (NMAuthManager *auth_mgr,
 
 	if (priv->auth.call_id_wifi_shared_permission) {
 		if (priv->auth.call_id_wifi_shared_permission == AUTH_CALL_ID_SHARED_WIFI_PERMISSION_FAILED)
-			auth_complete (self, FALSE, "Not authorized to share connections via wifi.");
+			auth_complete_keep_alive  (self, FALSE, "Not authorized to share connections via wifi.");
 		return;
 	}
 
-	auth_complete (self, TRUE, NULL);
+	auth_complete_keep_alive (self, TRUE, NULL);
 }
 
 /**
@@ -1082,8 +1098,7 @@ auth_done (NMAuthManager *auth_mgr,
  *   is no @settings_connection available when creating the active connection.
  *   Instead pass an alternative connection.
  * @result_func: function to be called on success or error
- * @user_data1: pointer passed to @result_func
- * @user_data2: additional pointer passed to @result_func
+ * @user_data: pointer passed to @result_func
  *
  * Checks whether the subject that initiated the active connection (read from
  * the #NMActiveConnection::subject property) is authorized to complete this
@@ -1093,8 +1108,7 @@ void
 nm_active_connection_authorize (NMActiveConnection *self,
                                 NMConnection *initial_connection,
                                 NMActiveConnectionAuthResultFunc result_func,
-                                gpointer user_data1,
-                                gpointer user_data2)
+                                gpointer user_data)
 {
 	NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
 	const char *wifi_permission = NULL;
@@ -1133,10 +1147,8 @@ nm_active_connection_authorize (NMActiveConnection *self,
 		                                                                                 self);
 	}
 
-	/* Wait for authorization */
 	priv->auth.result_func = result_func;
-	priv->auth.user_data1 = user_data1;
-	priv->auth.user_data2 = user_data2;
+	priv->auth.user_data = user_data;
 }
 
 /*****************************************************************************/
@@ -1416,6 +1428,7 @@ constructed (GObject *object)
 	}
 
 	g_return_if_fail (priv->subject);
+	g_return_if_fail (priv->activation_reason != NM_ACTIVATION_REASON_UNSET);
 }
 
 static void
@@ -1428,7 +1441,7 @@ dispose (GObject *object)
 
 	_LOGD ("disposing");
 
-	auth_cancel (self);
+	auth_complete (self, FALSE, "Authorization aborted");
 
 	nm_clear_g_free (&priv->specific_object);