core: move VPN active connection creation to the manager

Eventually the manager will create both NMActRequest and
NMVPNConnection subclasses directly, instead of leaving
NMVPNConnection creation to the VPN manager.

This also ensures that VPN connections get their user_requested
attribute set correctly, which wasn't happening before in the
case of secondary VPN connections.
This commit is contained in:
Dan Williams 2013-07-25 10:59:28 -05:00
parent 3660a80c29
commit a007292937
5 changed files with 65 additions and 82 deletions

View file

@ -2841,6 +2841,7 @@ static NMActiveConnection *
activate_vpn_connection (NMManager *self,
NMConnection *connection,
const char *specific_object,
gboolean user_requested,
gulong sender_uid,
GError **error)
{
@ -2848,6 +2849,8 @@ activate_vpn_connection (NMManager *self,
NMActiveConnection *parent = NULL;
NMDevice *device = NULL;
GSList *iter;
NMVPNConnection *vpn;
gboolean success = FALSE;
if (specific_object) {
/* Find the specifc connection the client requested we use */
@ -2881,13 +2884,17 @@ activate_vpn_connection (NMManager *self,
return NULL;
}
return nm_vpn_manager_activate_connection (priv->vpn_manager,
connection,
device,
nm_active_connection_get_path (parent),
TRUE,
sender_uid,
error);
vpn = nm_vpn_connection_new (connection,
device,
nm_active_connection_get_path (parent),
user_requested,
sender_uid);
g_assert (vpn);
success = nm_vpn_manager_activate_connection (priv->vpn_manager, vpn, error);
if (!success)
g_object_unref (vpn);
return success ? NM_ACTIVE_CONNECTION (vpn) : NULL;
}
NMActiveConnection *
@ -2928,7 +2935,12 @@ nm_manager_activate_connection (NMManager *manager,
/* VPN ? */
if (nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) {
ac = activate_vpn_connection (manager, connection, specific_object, sender_uid, error);
ac = activate_vpn_connection (manager,
connection,
specific_object,
!!dbus_sender,
sender_uid,
error);
goto activated;
}

View file

@ -78,7 +78,7 @@ get_service_by_namefile (NMVPNManager *self, const char *namefile)
}
static NMVPNConnection *
find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *connection)
find_active_vpn_connection (NMVPNManager *self, NMConnection *connection)
{
NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
@ -104,66 +104,53 @@ find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *conn
return found;
}
NMActiveConnection *
gboolean
nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
NMVPNConnection *vpn,
GError **error)
{
NMSettingVPN *vpn_setting;
NMVPNConnection *existing = NULL;
NMConnection *connection;
NMSettingVPN *s_vpn;
NMVPNService *service;
NMVPNConnection *vpn = NULL;
const char *service_name;
NMDevice *device;
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (*error == NULL, NULL);
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), FALSE);
g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE);
g_return_val_if_fail (error != NULL, FALSE);
g_return_val_if_fail (*error == NULL, FALSE);
device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (vpn));
g_assert (device);
if ( nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED
&& nm_device_get_state (device) != NM_DEVICE_STATE_SECONDARIES) {
g_set_error (error,
NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_DEVICE_NOT_ACTIVE,
"%s", "The base device for the VPN connection was not active.");
return NULL;
g_set_error_literal (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_DEVICE_NOT_ACTIVE,
"The base device for the VPN connection was not active.");
return FALSE;
}
vpn_setting = nm_connection_get_setting_vpn (connection);
if (!vpn_setting) {
g_set_error (error,
NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_CONNECTION_INVALID,
"%s", "The connection was not a VPN connection.");
return NULL;
}
connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (vpn));
g_assert (connection);
s_vpn = nm_connection_get_setting_vpn (connection);
g_assert (s_vpn);
vpn = find_active_vpn_connection_by_connection (manager, connection);
if (vpn) {
nm_vpn_connection_disconnect (vpn, NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED);
vpn = NULL;
}
service_name = nm_setting_vpn_get_service_type (vpn_setting);
service_name = nm_setting_vpn_get_service_type (s_vpn);
g_assert (service_name);
service = g_hash_table_lookup (NM_VPN_MANAGER_GET_PRIVATE (manager)->services, service_name);
if (!service) {
g_set_error (error,
NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_SERVICE_INVALID,
g_set_error (error, NM_VPN_MANAGER_ERROR, NM_VPN_MANAGER_ERROR_SERVICE_INVALID,
"The VPN service '%s' was not installed.",
service_name);
return NULL;
return FALSE;
}
return (NMActiveConnection *) nm_vpn_service_activate (service,
connection,
device,
specific_object,
user_requested,
user_uid,
error);
existing = find_active_vpn_connection (manager,
nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (vpn)));
if (existing)
nm_vpn_connection_disconnect (vpn, NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED);
return nm_vpn_service_activate (service, vpn, error);
}
gboolean

View file

@ -59,13 +59,9 @@ GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_get (void);
NMActiveConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
GError **error);
gboolean nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMVPNConnection *vpn,
GError **error);
gboolean nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
NMVPNConnection *connection,

View file

@ -323,45 +323,37 @@ connection_vpn_state_changed (NMVPNConnection *connection,
}
}
NMVPNConnection *
gboolean
nm_vpn_service_activate (NMVPNService *service,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
NMVPNConnection *vpn,
GError **error)
{
NMVPNConnection *vpn;
NMVPNServicePrivate *priv;
g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (error != NULL, NULL);
g_return_val_if_fail (*error == NULL, NULL);
g_return_val_if_fail (NM_IS_VPN_SERVICE (service), FALSE);
g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), FALSE);
g_return_val_if_fail (error != NULL, FALSE);
g_return_val_if_fail (*error == NULL, FALSE);
priv = NM_VPN_SERVICE_GET_PRIVATE (service);
clear_quit_timeout (service);
vpn = nm_vpn_connection_new (connection, device, specific_object, user_requested, user_uid);
g_signal_connect (vpn, NM_VPN_CONNECTION_INTERNAL_STATE_CHANGED,
G_CALLBACK (connection_vpn_state_changed),
service);
priv->connections = g_slist_prepend (priv->connections, g_object_ref (vpn));
if (nm_dbus_manager_name_has_owner (priv->dbus_mgr, priv->dbus_service)) {
// FIXME: fill in error when errors happen
if (nm_dbus_manager_name_has_owner (priv->dbus_mgr, priv->dbus_service))
nm_vpn_connection_activate (vpn);
} else if (priv->start_timeout == 0) {
else if (priv->start_timeout == 0) {
nm_log_info (LOGD_VPN, "Starting VPN service '%s'...", priv->name);
if (!nm_vpn_service_daemon_exec (service, error))
vpn = NULL;
return FALSE;
}
return vpn;
return TRUE;
}
const GSList *

View file

@ -54,13 +54,9 @@ const char *nm_vpn_service_get_dbus_service (NMVPNService *service);
/* Returns the path of the VPN service's .name file */
const char *nm_vpn_service_get_name_file (NMVPNService *service);
NMVPNConnection * nm_vpn_service_activate (NMVPNService *service,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
GError **error);
gboolean nm_vpn_service_activate (NMVPNService *service,
NMVPNConnection *vpn,
GError **error);
const GSList *nm_vpn_service_get_active_connections (NMVPNService *service);