core: move most activation request logic to the active connection class

We'll want to use NMActiveConnection more in the manager and also fold
the PendingActivation functionality into it.  All this functionality
applies to the VPN connections too, so it makes sense to have it all
in the base class instead of both NMActRequest and NMVPNConnection.
This commit is contained in:
Dan Williams
2012-08-22 09:38:01 -05:00
parent 7a3c53e8ff
commit 84603c2380
7 changed files with 297 additions and 242 deletions

View File

@@ -28,11 +28,9 @@
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include "nm-activation-request.h" #include "nm-activation-request.h"
#include "nm-marshal.h"
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-setting-wireless-security.h" #include "nm-setting-wireless-security.h"
#include "nm-setting-8021x.h" #include "nm-setting-8021x.h"
#include "nm-dbus-manager.h"
#include "nm-device.h" #include "nm-device.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-settings-connection.h" #include "nm-settings-connection.h"
@@ -51,28 +49,32 @@ typedef struct {
} ShareRule; } ShareRule;
typedef struct { typedef struct {
gboolean disposed;
NMConnection *connection; NMConnection *connection;
GSList *secrets_calls;
NMDevice *device; NMDevice *device;
gboolean user_requested; guint device_state_id;
gulong user_uid;
char *dbus_sender; char *dbus_sender;
GSList *secrets_calls;
NMDevice *master;
gboolean shared; gboolean shared;
GSList *share_rules; GSList *share_rules;
gboolean assumed;
} NMActRequestPrivate; } NMActRequestPrivate;
enum { /*******************************************************************/
PROP_MASTER = 2000,
}; NMConnection *
nm_act_request_get_connection (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
return nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (req));
}
const char *
nm_act_request_get_dbus_sender (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
return NM_ACT_REQUEST_GET_PRIVATE (req)->dbus_sender;
}
/*******************************************************************/ /*******************************************************************/
@@ -112,6 +114,8 @@ nm_act_request_get_secrets (NMActRequest *self,
NMActRequestPrivate *priv; NMActRequestPrivate *priv;
GetSecretsInfo *info; GetSecretsInfo *info;
guint32 call_id; guint32 call_id;
NMConnection *connection;
gboolean user_requested;
g_return_val_if_fail (self, 0); g_return_val_if_fail (self, 0);
g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0); g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0);
@@ -123,12 +127,14 @@ nm_act_request_get_secrets (NMActRequest *self,
info->callback = callback; info->callback = callback;
info->callback_data = callback_data; info->callback_data = callback_data;
if (priv->user_requested) user_requested = nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self));
if (user_requested)
flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED; flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED;
call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection), connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (self));
priv->user_requested, call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (connection),
priv->user_uid, user_requested,
nm_active_connection_get_user_uid (NM_ACTIVE_CONNECTION (self)),
setting_name, setting_name,
flags, flags,
hint, hint,
@@ -171,62 +177,6 @@ nm_act_request_cancel_secrets (NMActRequest *self, guint32 call_id)
} }
} }
/*******************************************************************/
NMConnection *
nm_act_request_get_connection (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
return NM_ACT_REQUEST_GET_PRIVATE (req)->connection;
}
gboolean
nm_act_request_get_user_requested (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
return NM_ACT_REQUEST_GET_PRIVATE (req)->user_requested;
}
gulong
nm_act_request_get_user_uid (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), 0);
return NM_ACT_REQUEST_GET_PRIVATE (req)->user_uid;
}
const char *
nm_act_request_get_dbus_sender (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
return NM_ACT_REQUEST_GET_PRIVATE (req)->dbus_sender;
}
GObject *
nm_act_request_get_device (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL);
return G_OBJECT (NM_ACT_REQUEST_GET_PRIVATE (req)->device);
}
gboolean
nm_act_request_get_assumed (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
return NM_ACT_REQUEST_GET_PRIVATE (req)->assumed;
}
GObject *
nm_act_request_get_master (NMActRequest *req)
{
return (GObject *) NM_ACT_REQUEST_GET_PRIVATE (req)->master;
}
/********************************************************************/ /********************************************************************/
static void static void
@@ -345,17 +295,12 @@ nm_act_request_add_share_rule (NMActRequest *req,
/********************************************************************/ /********************************************************************/
static void static void
device_state_changed (NMDevice *device, device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self)
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
{ {
NMActRequest *self = NM_ACT_REQUEST (user_data);
NMActiveConnectionState new_ac_state; NMActiveConnectionState new_ac_state;
/* Set NMActiveConnection state based on the device's state */ /* Set NMActiveConnection state based on the device's state */
switch (new_state) { switch (nm_device_get_state (device)) {
case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_NEED_AUTH:
@@ -411,45 +356,26 @@ nm_act_request_new (NMConnection *connection,
gulong user_uid, gulong user_uid,
const char *dbus_sender, const char *dbus_sender,
gboolean assumed, gboolean assumed,
gpointer *device, NMDevice *device,
gpointer *master) NMDevice *master)
{ {
GObject *object; GObject *object;
NMActRequestPrivate *priv;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_DEVICE (device), NULL); g_return_val_if_fail (NM_DEVICE (device), NULL);
object = g_object_new (NM_TYPE_ACT_REQUEST, object = g_object_new (NM_TYPE_ACT_REQUEST,
NM_ACTIVE_CONNECTION_INT_CONNECTION, connection,
NM_ACTIVE_CONNECTION_INT_DEVICE, device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
NM_ACTIVE_CONNECTION_INT_USER_REQUESTED, user_requested,
NM_ACTIVE_CONNECTION_INT_USER_UID, user_uid,
NM_ACTIVE_CONNECTION_INT_ASSUMED, assumed,
NM_ACTIVE_CONNECTION_INT_MASTER, master,
NULL); NULL);
if (!object) if (object) {
return NULL; nm_active_connection_export (NM_ACTIVE_CONNECTION (object));
NM_ACT_REQUEST_GET_PRIVATE (object)->dbus_sender = g_strdup (dbus_sender);
priv = NM_ACT_REQUEST_GET_PRIVATE (object);
priv->connection = g_object_ref (connection);
priv->device = NM_DEVICE (device);
g_signal_connect (device, "state-changed",
G_CALLBACK (device_state_changed),
NM_ACT_REQUEST (object));
priv->user_uid = user_uid;
priv->user_requested = user_requested;
priv->dbus_sender = g_strdup (dbus_sender);
priv->assumed = assumed;
if (master) {
g_assert (NM_IS_DEVICE (master));
g_assert (NM_DEVICE (master) != NM_DEVICE (device));
priv->master = g_object_ref (master);
}
if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (object),
connection,
nm_device_get_path (NM_DEVICE (device)))) {
g_object_unref (object);
object = NULL;
} }
return (NMActRequest *) object; return (NMActRequest *) object;
@@ -461,18 +387,24 @@ nm_act_request_init (NMActRequest *req)
} }
static void static void
get_property (GObject *object, guint prop_id, constructed (GObject *object)
GValue *value, GParamSpec *pspec)
{ {
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
NMConnection *connection;
NMDevice *device;
switch (prop_id) { G_OBJECT_CLASS (nm_act_request_parent_class)->constructed (object);
case PROP_MASTER:
g_value_set_boxed (value, priv->master ? nm_device_get_path (priv->master) : "/"); connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object));
break; priv->connection = g_object_ref (connection);
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
break; if (device) {
priv->device = g_object_ref (device);
priv->device_state_id = g_signal_connect (priv->device,
"notify::" NM_DEVICE_STATE,
G_CALLBACK (device_state_changed),
NM_ACT_REQUEST (object));
} }
} }
@@ -482,46 +414,37 @@ dispose (GObject *object)
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
GSList *iter; GSList *iter;
if (priv->disposed) { if (priv->device && priv->device_state_id) {
G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); g_signal_handler_disconnect (priv->device, priv->device_state_id);
return; priv->device_state_id = 0;
} }
priv->disposed = TRUE;
g_signal_handlers_disconnect_by_func (G_OBJECT (priv->device),
G_CALLBACK (device_state_changed),
NM_ACT_REQUEST (object));
/* Clear any share rules */ /* Clear any share rules */
nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE); if (priv->share_rules) {
nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE);
clear_share_rules (NM_ACT_REQUEST (object));
}
/* Kill any in-progress secrets requests */ /* Kill any in-progress secrets requests */
g_assert (priv->connection);
for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) { for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data; GetSecretsInfo *info = iter->data;
g_assert (priv->connection);
nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id); nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id);
g_free (info); g_free (info);
} }
g_slist_free (priv->secrets_calls); g_slist_free (priv->secrets_calls);
priv->secrets_calls = NULL;
g_object_unref (priv->connection);
g_free (priv->dbus_sender); g_free (priv->dbus_sender);
priv->dbus_sender = NULL;
g_clear_object (&priv->master); g_clear_object (&priv->device);
g_clear_object (&priv->connection);
G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object);
} }
static void
finalize (GObject *object)
{
clear_share_rules (NM_ACT_REQUEST (object));
G_OBJECT_CLASS (nm_act_request_parent_class)->finalize (object);
}
static void static void
nm_act_request_class_init (NMActRequestClass *req_class) nm_act_request_class_init (NMActRequestClass *req_class)
{ {
@@ -530,10 +453,7 @@ nm_act_request_class_init (NMActRequestClass *req_class)
g_type_class_add_private (req_class, sizeof (NMActRequestPrivate)); g_type_class_add_private (req_class, sizeof (NMActRequestPrivate));
/* virtual methods */ /* virtual methods */
object_class->get_property = get_property; object_class->constructed = constructed;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize;
g_object_class_override_property (object_class, PROP_MASTER, NM_ACTIVE_CONNECTION_MASTER);
} }

View File

@@ -23,6 +23,7 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include "nm-types.h"
#include "nm-connection.h" #include "nm-connection.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "nm-settings-flags.h" #include "nm-settings-flags.h"
@@ -35,11 +36,11 @@
#define NM_ACT_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACT_REQUEST, NMActRequestClass)) #define NM_ACT_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACT_REQUEST, NMActRequestClass))
typedef struct { typedef struct {
GObject parent; NMActiveConnection parent;
} NMActRequest; } NMActRequest;
typedef struct { typedef struct {
GObjectClass parent; NMActiveConnectionClass parent;
/* Signals */ /* Signals */
void (*properties_changed) (NMActRequest *req, GHashTable *properties); void (*properties_changed) (NMActRequest *req, GHashTable *properties);
@@ -53,12 +54,10 @@ NMActRequest *nm_act_request_new (NMConnection *connection,
gulong user_uid, gulong user_uid,
const char *dbus_sender, const char *dbus_sender,
gboolean assumed, gboolean assumed,
gpointer *device, /* An NMDevice */ NMDevice *device,
gpointer *master); /* An NMDevice */ NMDevice *master);
NMConnection *nm_act_request_get_connection (NMActRequest *req); NMConnection *nm_act_request_get_connection (NMActRequest *req);
gboolean nm_act_request_get_user_requested (NMActRequest *req);
gulong nm_act_request_get_user_uid (NMActRequest *req); gulong nm_act_request_get_user_uid (NMActRequest *req);
@@ -72,12 +71,6 @@ void nm_act_request_add_share_rule (NMActRequest *req,
const char *table, const char *table,
const char *rule); const char *rule);
GObject * nm_act_request_get_device (NMActRequest *req);
gboolean nm_act_request_get_assumed (NMActRequest *req);
GObject * nm_act_request_get_master (NMActRequest *req);
/* Secrets handling */ /* Secrets handling */
typedef void (*NMActRequestSecretsFunc) (NMActRequest *req, typedef void (*NMActRequestSecretsFunc) (NMActRequest *req,

View File

@@ -19,12 +19,14 @@
*/ */
#include <glib.h> #include <glib.h>
#include "nm-types.h"
#include "nm-active-connection.h" #include "nm-active-connection.h"
#include "NetworkManager.h" #include "NetworkManager.h"
#include "nm-logging.h" #include "nm-logging.h"
#include "nm-dbus-glib-types.h" #include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h" #include "nm-dbus-manager.h"
#include "nm-properties-changed-signal.h" #include "nm-properties-changed-signal.h"
#include "nm-device.h"
#include "nm-active-connection-glue.h" #include "nm-active-connection-glue.h"
@@ -36,16 +38,20 @@ G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT)
NMActiveConnectionPrivate)) NMActiveConnectionPrivate))
typedef struct { typedef struct {
gboolean disposed;
NMConnection *connection; NMConnection *connection;
char *path; char *path;
char *specific_object; char *specific_object;
char *device_path; NMDevice *device;
gboolean is_default; gboolean is_default;
gboolean is_default6; gboolean is_default6;
NMActiveConnectionState state; NMActiveConnectionState state;
gboolean vpn; gboolean vpn;
gboolean user_requested;
gulong user_uid;
gboolean assumed;
NMDevice *master;
} NMActiveConnectionPrivate; } NMActiveConnectionPrivate;
enum { enum {
@@ -60,6 +66,13 @@ enum {
PROP_VPN, PROP_VPN,
PROP_MASTER, PROP_MASTER,
PROP_INT_CONNECTION,
PROP_INT_DEVICE,
PROP_INT_USER_REQUESTED,
PROP_INT_USER_UID,
PROP_INT_ASSUMED,
PROP_INT_MASTER,
LAST_PROP LAST_PROP
}; };
@@ -175,27 +188,58 @@ nm_active_connection_get_default6 (NMActiveConnection *self)
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default6; return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default6;
} }
gboolean void
nm_active_connection_export (NMActiveConnection *self, nm_active_connection_export (NMActiveConnection *self)
NMConnection *connection,
const char *devpath)
{ {
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
NMDBusManager *dbus_mgr; NMDBusManager *dbus_mgr;
static guint32 counter = 0; static guint32 counter = 0;
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (devpath != NULL, FALSE);
priv->connection = g_object_ref (connection);
priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++); priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++);
priv->device_path = g_strdup (devpath);
dbus_mgr = nm_dbus_manager_get (); dbus_mgr = nm_dbus_manager_get ();
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr),
priv->path, G_OBJECT (self)); priv->path, G_OBJECT (self));
g_object_unref (dbus_mgr); g_object_unref (dbus_mgr);
return TRUE; }
gboolean
nm_active_connection_get_user_requested (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->user_requested;
}
gulong
nm_active_connection_get_user_uid (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), G_MAXULONG);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->user_uid;
}
gboolean
nm_active_connection_get_assumed (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->assumed;
}
NMDevice *
nm_active_connection_get_device (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->device;
}
NMDevice *
nm_active_connection_get_master (NMActiveConnection *self)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->master;
} }
/****************************************************************/ /****************************************************************/
@@ -205,23 +249,6 @@ nm_active_connection_init (NMActiveConnection *self)
{ {
} }
static void
dispose (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
if (!priv->disposed) {
priv->disposed = TRUE;
g_free (priv->path);
g_free (priv->specific_object);
g_free (priv->device_path);
g_object_unref (priv->connection);
}
G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
}
static void static void
set_property (GObject *object, guint prop_id, set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec) const GValue *value, GParamSpec *pspec)
@@ -229,6 +256,31 @@ set_property (GObject *object, guint prop_id,
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
switch (prop_id) { switch (prop_id) {
case PROP_INT_CONNECTION:
g_warn_if_fail (priv->connection == NULL);
priv->connection = g_value_dup_object (value);
break;
case PROP_INT_DEVICE:
g_warn_if_fail (priv->device == NULL);
priv->device = g_value_dup_object (value);
if (priv->device)
g_warn_if_fail (priv->device != priv->master);
break;
case PROP_INT_USER_REQUESTED:
priv->user_requested = g_value_get_boolean (value);
break;
case PROP_INT_USER_UID:
priv->user_uid = g_value_get_ulong (value);
break;
case PROP_INT_ASSUMED:
priv->assumed = g_value_get_boolean (value);
break;
case PROP_INT_MASTER:
g_warn_if_fail (priv->master == NULL);
priv->master = g_value_dup_object (value);
if (priv->master)
g_warn_if_fail (priv->master != priv->device);
break;
case PROP_SPECIFIC_OBJECT: case PROP_SPECIFIC_OBJECT:
priv->specific_object = g_value_dup_boxed (value); priv->specific_object = g_value_dup_boxed (value);
break; break;
@@ -241,6 +293,8 @@ set_property (GObject *object, guint prop_id,
case PROP_VPN: case PROP_VPN:
priv->vpn = g_value_get_boolean (value); priv->vpn = g_value_get_boolean (value);
break; break;
case PROP_MASTER:
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -266,7 +320,8 @@ get_property (GObject *object, guint prop_id,
break; break;
case PROP_DEVICES: case PROP_DEVICES:
devices = g_ptr_array_sized_new (1); devices = g_ptr_array_sized_new (1);
g_ptr_array_add (devices, g_strdup (priv->device_path)); if (priv->device)
g_ptr_array_add (devices, g_strdup (nm_device_get_path (priv->device)));
g_value_take_boxed (value, devices); g_value_take_boxed (value, devices);
break; break;
case PROP_STATE: case PROP_STATE:
@@ -282,6 +337,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->vpn); g_value_set_boolean (value, priv->vpn);
break; break;
case PROP_MASTER: case PROP_MASTER:
g_value_set_boxed (value, priv->master ? nm_device_get_path (priv->master) : "/");
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -289,6 +345,23 @@ get_property (GObject *object, guint prop_id,
} }
} }
static void
dispose (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
g_free (priv->path);
priv->path = NULL;
g_free (priv->specific_object);
priv->specific_object = NULL;
g_clear_object (&priv->connection);
g_clear_object (&priv->device);
g_clear_object (&priv->master);
G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
}
static void static void
nm_active_connection_class_init (NMActiveConnectionClass *vpn_class) nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
{ {
@@ -301,7 +374,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->dispose = dispose; object_class->dispose = dispose;
/* properties */ /* D-Bus exported properties */
g_object_class_install_property (object_class, PROP_CONNECTION, g_object_class_install_property (object_class, PROP_CONNECTION,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION, g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION,
"Connection", "Connection",
@@ -367,6 +440,49 @@ nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE)); G_PARAM_READABLE));
/* Internal properties */
g_object_class_install_property (object_class, PROP_INT_CONNECTION,
g_param_spec_object (NM_ACTIVE_CONNECTION_INT_CONNECTION,
"Internal Connection",
"Internal connection",
NM_TYPE_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
g_object_class_install_property (object_class, PROP_INT_DEVICE,
g_param_spec_object (NM_ACTIVE_CONNECTION_INT_DEVICE,
"Internal device",
"Internal device",
NM_TYPE_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
g_object_class_install_property (object_class, PROP_INT_USER_REQUESTED,
g_param_spec_boolean (NM_ACTIVE_CONNECTION_INT_USER_REQUESTED,
"User requested",
"User requested",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
g_object_class_install_property (object_class, PROP_INT_USER_UID,
g_param_spec_ulong (NM_ACTIVE_CONNECTION_INT_USER_UID,
"User UID",
"User UID (if user requested)",
0, G_MAXULONG, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
g_object_class_install_property (object_class, PROP_INT_ASSUMED,
g_param_spec_boolean (NM_ACTIVE_CONNECTION_INT_ASSUMED,
"Assumed",
"Assumed",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
g_object_class_install_property (object_class, PROP_INT_MASTER,
g_param_spec_object (NM_ACTIVE_CONNECTION_INT_MASTER,
"Internal master device",
"Internal device",
NM_TYPE_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
/* Signals */ /* Signals */
signals[PROPERTIES_CHANGED] = signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class, nm_properties_changed_signal_new (object_class,

View File

@@ -22,6 +22,7 @@
#define NM_ACTIVE_CONNECTION_H #define NM_ACTIVE_CONNECTION_H
#include <glib-object.h> #include <glib-object.h>
#include "nm-types.h"
#include "nm-connection.h" #include "nm-connection.h"
#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ()) #define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ())
@@ -31,7 +32,7 @@
#define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ACTIVE_CONNECTION)) #define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ACTIVE_CONNECTION))
#define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass)) #define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
/* Properties */ /* D-Bus Exported Properties */
#define NM_ACTIVE_CONNECTION_CONNECTION "connection" #define NM_ACTIVE_CONNECTION_CONNECTION "connection"
#define NM_ACTIVE_CONNECTION_UUID "uuid" #define NM_ACTIVE_CONNECTION_UUID "uuid"
#define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object" #define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object"
@@ -42,6 +43,15 @@
#define NM_ACTIVE_CONNECTION_VPN "vpn" #define NM_ACTIVE_CONNECTION_VPN "vpn"
#define NM_ACTIVE_CONNECTION_MASTER "master" #define NM_ACTIVE_CONNECTION_MASTER "master"
/* Internal non-exported construct-time properties */
#define NM_ACTIVE_CONNECTION_INT_CONNECTION "int-connection"
#define NM_ACTIVE_CONNECTION_INT_DEVICE "int-device"
#define NM_ACTIVE_CONNECTION_INT_USER_REQUESTED "int-user-requested"
#define NM_ACTIVE_CONNECTION_INT_USER_UID "int-user-uid"
#define NM_ACTIVE_CONNECTION_INT_ASSUMED "int-assumed"
#define NM_ACTIVE_CONNECTION_INT_MASTER "int-master"
typedef struct { typedef struct {
GObject parent; GObject parent;
} NMActiveConnection; } NMActiveConnection;
@@ -50,14 +60,12 @@ typedef struct {
GObjectClass parent; GObjectClass parent;
/* Signals */ /* Signals */
void (*properties_changed) (NMActiveConnection *req, GHashTable *properties); void (*properties_changed) (NMActiveConnection *active, GHashTable *properties);
} NMActiveConnectionClass; } NMActiveConnectionClass;
GType nm_active_connection_get_type (void); GType nm_active_connection_get_type (void);
gboolean nm_active_connection_export (NMActiveConnection *self, void nm_active_connection_export (NMActiveConnection *self);
NMConnection *connection,
const char *devpath);
NMConnection *nm_active_connection_get_connection (NMActiveConnection *self); NMConnection *nm_active_connection_get_connection (NMActiveConnection *self);
const char * nm_active_connection_get_name (NMActiveConnection *self); const char * nm_active_connection_get_name (NMActiveConnection *self);
@@ -84,4 +92,14 @@ NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *self
void nm_active_connection_set_state (NMActiveConnection *self, void nm_active_connection_set_state (NMActiveConnection *self,
NMActiveConnectionState state); NMActiveConnectionState state);
NMDevice * nm_active_connection_get_device (NMActiveConnection *self);
gboolean nm_active_connection_get_user_requested (NMActiveConnection *self);
gulong nm_active_connection_get_user_uid (NMActiveConnection *self);
gboolean nm_active_connection_get_assumed (NMActiveConnection *self);
NMDevice * nm_active_connection_get_master (NMActiveConnection *self);
#endif /* NM_ACTIVE_CONNECTION_H */ #endif /* NM_ACTIVE_CONNECTION_H */

View File

@@ -2761,7 +2761,7 @@ nm_device_activate_stage3_ip_config_start (gpointer user_data)
* in which case we postpone activation here until the master enslaves us, * in which case we postpone activation here until the master enslaves us,
* which calls nm_device_slave_notify_enslaved(). * which calls nm_device_slave_notify_enslaved().
*/ */
master = (NMDevice *) nm_act_request_get_master (priv->act_request); master = nm_active_connection_get_master (NM_ACTIVE_CONNECTION (priv->act_request));
if (master) { if (master) {
if (priv->enslaved == FALSE) { if (priv->enslaved == FALSE) {
nm_log_info (LOGD_DEVICE, "Activation (%s) connection '%s' waiting on master '%s'", nm_log_info (LOGD_DEVICE, "Activation (%s) connection '%s' waiting on master '%s'",
@@ -2824,7 +2824,7 @@ nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self)
g_return_if_fail (priv->act_request); g_return_if_fail (priv->act_request);
state = nm_device_get_state (self); state = nm_device_get_state (self);
if (nm_act_request_get_assumed (priv->act_request) == FALSE) if (nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request)) == FALSE)
g_warn_if_fail (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_NEED_AUTH); g_warn_if_fail (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_NEED_AUTH);
/* Add the interface to the specified firewall zone */ /* Add the interface to the specified firewall zone */
@@ -3176,7 +3176,7 @@ nm_device_activate_ip4_config_commit (gpointer user_data)
/* Merge with user overrides */ /* Merge with user overrides */
nm_utils_merge_ip4_config (config, nm_connection_get_setting_ip4_config (connection)); nm_utils_merge_ip4_config (config, nm_connection_get_setting_ip4_config (connection));
assumed = nm_act_request_get_assumed (priv->act_request); assumed = nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request));
if (!nm_device_set_ip4_config (self, config, assumed, &reason)) { if (!nm_device_set_ip4_config (self, config, assumed, &reason)) {
nm_log_info (LOGD_DEVICE | LOGD_IP4, nm_log_info (LOGD_DEVICE | LOGD_IP4,
"Activation (%s) Stage 5 of 5 (IPv4 Commit) failed", "Activation (%s) Stage 5 of 5 (IPv4 Commit) failed",
@@ -3653,7 +3653,7 @@ nm_device_activate (NMDevice *self, NMActRequest *req)
priv->act_request = g_object_ref (req); priv->act_request = g_object_ref (req);
g_object_notify (G_OBJECT (self), NM_DEVICE_ACTIVE_CONNECTION); g_object_notify (G_OBJECT (self), NM_DEVICE_ACTIVE_CONNECTION);
if (nm_act_request_get_assumed (req)) { if (nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (req))) {
/* If it's an assumed connection, let the device subclass short-circuit /* If it's an assumed connection, let the device subclass short-circuit
* the normal connection process and just copy its IP configs from the * the normal connection process and just copy its IP configs from the
* interface. * interface.
@@ -3671,7 +3671,7 @@ nm_device_activate (NMDevice *self, NMActRequest *req)
nm_device_state_changed (self, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE); nm_device_state_changed (self, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE);
/* Handle any dependencies this connection might have */ /* Handle any dependencies this connection might have */
master = (NMDevice *) nm_act_request_get_master (req); master = nm_active_connection_get_master (NM_ACTIVE_CONNECTION (req));
if (master) { if (master) {
/* Master should at least already be activating */ /* Master should at least already be activating */
g_assert (nm_device_get_state (master) > NM_DEVICE_STATE_DISCONNECTED); g_assert (nm_device_get_state (master) > NM_DEVICE_STATE_DISCONNECTED);

View File

@@ -2309,7 +2309,7 @@ internal_activate_device (NMManager *manager,
} }
if (master) if (master)
master_device = (NMDevice *) nm_act_request_get_device (NM_ACT_REQUEST (master)); master_device = nm_active_connection_get_device (master);
req = nm_act_request_new (connection, req = nm_act_request_new (connection,
specific_object, specific_object,
@@ -2317,8 +2317,8 @@ internal_activate_device (NMManager *manager,
sender_uid, sender_uid,
dbus_sender, dbus_sender,
assumed, assumed,
(gpointer) device, device,
(gpointer) master_device); master_device);
nm_device_activate (device, req); nm_device_activate (device, req);
g_object_unref (req); g_object_unref (req);

View File

@@ -69,8 +69,6 @@ typedef struct {
NMConnection *connection; NMConnection *connection;
gboolean user_requested;
gulong user_uid;
guint32 secrets_id; guint32 secrets_id;
SecretsReq secrets_idx; SecretsReq secrets_idx;
char *username; char *username;
@@ -347,42 +345,20 @@ nm_vpn_connection_new (NMConnection *connection,
gulong user_uid) gulong user_uid)
{ {
NMVPNConnection *self; NMVPNConnection *self;
NMVPNConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (parent_device), NULL); g_return_val_if_fail (NM_IS_DEVICE (parent_device), NULL);
self = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION, self = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION,
NM_ACTIVE_CONNECTION_INT_CONNECTION, connection,
NM_ACTIVE_CONNECTION_INT_DEVICE, parent_device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
NM_ACTIVE_CONNECTION_INT_USER_REQUESTED, user_requested,
NM_ACTIVE_CONNECTION_INT_USER_UID, user_uid,
NM_ACTIVE_CONNECTION_VPN, TRUE, NM_ACTIVE_CONNECTION_VPN, TRUE,
NULL); NULL);
if (!self) if (self)
return NULL; nm_active_connection_export (NM_ACTIVE_CONNECTION (self));
priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
priv->user_requested = user_requested;
priv->user_uid = user_uid;
priv->connection = g_object_ref (connection);
priv->parent_dev = g_object_ref (parent_device);
priv->device_monitor = g_signal_connect (parent_device, "state-changed",
G_CALLBACK (device_state_changed),
self);
priv->device_ip4 = g_signal_connect (parent_device, "notify::" NM_DEVICE_IP4_CONFIG,
G_CALLBACK (device_ip4_config_changed),
self);
priv->device_ip6 = g_signal_connect (parent_device, "notify::" NM_DEVICE_IP6_CONFIG,
G_CALLBACK (device_ip6_config_changed),
self);
if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (self),
connection,
nm_device_get_path (parent_device))) {
g_object_unref (self);
self = NULL;
}
return self; return self;
} }
@@ -1436,11 +1412,13 @@ get_secrets (NMVPNConnection *self, SecretsReq secrets_idx)
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_NONE; NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_NONE;
GError *error = NULL; GError *error = NULL;
gboolean filter_by_uid = priv->user_requested; gboolean filter_by_uid;
g_return_if_fail (secrets_idx < SECRETS_REQ_LAST); g_return_if_fail (secrets_idx < SECRETS_REQ_LAST);
priv->secrets_idx = secrets_idx; priv->secrets_idx = secrets_idx;
filter_by_uid = nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self));
nm_log_dbg (LOGD_VPN, "(%s/%s) requesting VPN secrets pass #%d", nm_log_dbg (LOGD_VPN, "(%s/%s) requesting VPN secrets pass #%d",
nm_connection_get_uuid (priv->connection), nm_connection_get_uuid (priv->connection),
nm_connection_get_id (priv->connection), nm_connection_get_id (priv->connection),
@@ -1461,12 +1439,12 @@ get_secrets (NMVPNConnection *self, SecretsReq secrets_idx)
g_assert_not_reached (); g_assert_not_reached ();
} }
if (priv->user_requested) if (nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self)))
flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED; flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED;
priv->secrets_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection), priv->secrets_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (priv->connection),
filter_by_uid, filter_by_uid,
priv->user_uid, nm_active_connection_get_user_uid (NM_ACTIVE_CONNECTION (self)),
NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME,
flags, flags,
NULL, NULL,
@@ -1491,6 +1469,35 @@ nm_vpn_connection_init (NMVPNConnection *self)
NM_VPN_CONNECTION_GET_PRIVATE (self)->vpn_state = NM_VPN_CONNECTION_STATE_PREPARE; NM_VPN_CONNECTION_GET_PRIVATE (self)->vpn_state = NM_VPN_CONNECTION_STATE_PREPARE;
} }
static void
constructed (GObject *object)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
NMConnection *connection;
NMDevice *device;
G_OBJECT_CLASS (nm_vpn_connection_parent_class)->constructed (object);
connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object));
priv->connection = g_object_ref (connection);
device = (NMDevice *) nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
g_assert (device);
priv->parent_dev = g_object_ref (device);
priv->device_monitor = g_signal_connect (device, "state-changed",
G_CALLBACK (device_state_changed),
object);
priv->device_ip4 = g_signal_connect (device, "notify::" NM_DEVICE_IP4_CONFIG,
G_CALLBACK (device_ip4_config_changed),
object);
priv->device_ip6 = g_signal_connect (device, "notify::" NM_DEVICE_IP6_CONFIG,
G_CALLBACK (device_ip6_config_changed),
object);
}
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
@@ -1517,7 +1524,7 @@ dispose (GObject *object)
if (priv->device_monitor) if (priv->device_monitor)
g_signal_handler_disconnect (priv->parent_dev, priv->device_monitor); g_signal_handler_disconnect (priv->parent_dev, priv->device_monitor);
g_object_unref (priv->parent_dev); g_clear_object (&priv->parent_dev);
if (priv->ip4_config) if (priv->ip4_config)
g_object_unref (priv->ip4_config); g_object_unref (priv->ip4_config);
@@ -1535,7 +1542,7 @@ dispose (GObject *object)
priv->secrets_id); priv->secrets_id);
} }
g_object_unref (priv->connection); g_clear_object (&priv->connection);
g_free (priv->username); g_free (priv->username);
G_OBJECT_CLASS (nm_vpn_connection_parent_class)->dispose (object); G_OBJECT_CLASS (nm_vpn_connection_parent_class)->dispose (object);
@@ -1583,6 +1590,7 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class)
/* virtual methods */ /* virtual methods */
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->constructed = constructed;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;