NetworkManager/src/nm-activation-request.c

516 lines
16 KiB
C
Raw Normal View History

/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2005 - 2012 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc.
*/
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
2007-09-28 Tambet Ingo <tambet@gmail.com> * src/nm-manager.c: * src/nm-manager.h: Implement device activation through NMManager. Implement "pending device activation" here - If the connection isn't found, we try to wait for up to 5 seconds for the connection to be provided. Add NMConnectionType argument to "connection-added" and "connection-removed" signals. (nm_manager_get): Remove. Finally. * src/nm-activation-request.c: * src/nm-activation-request.h: Remove all the deferred activation code. * src/nm-device.c: Remove all the deferred activation code. Once * the device activation is started, it's started. Update the activation virtual function signature. * src/nm-device-interface.c: * src/nm-device-interface.h: Device activation now takes only NMActRequest argument. Don't expose device activation directly on dbus, it's supposed to go through NMManager now. * src/NetworkManagerPolicy.c (nm_policy_device_change_check): * Make the code a bit more compact. Use the new device activation methods through NMManager. * introspection/nm-manager-client.xml: * introspection/nm-manager.xml: * libnm-glib/nm-client.c: * libnm-glib/nm-client.h: Add device activation method. * libnm-glib/nm-device.c: * libnm-glib/nm-device.h: * introspection/nm-device.xml: Remove device activation method. It's done through NMManager now. * src/vpn-manager/nm-vpn-manager.c (impl_vpn_manager_connect): * Use the shiny new (nm_manager_get_device_by_path) function, get rid of our own )find_device). git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2915 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-01 15:38:39 +00:00
#include <dbus/dbus-glib.h>
2008-03-17 Dan Williams <dcbw@redhat.com> Split the 802.1x bits out of the wireless-security setting so they are generalized enough for wired 802.1x to use too. * introspection/nm-exported-connection.xml - GetSecrets now returns 'a{sa{sv}}' (a hash of settings hashes) instead of just a hash of the secrets for one setting * libnm-util/nm-setting-wireless-security.c libnm-util/nm-setting-wireless-security.h - Remove 802.1x-specific stuff - Added leap-username and leap-password properties for old-school LEAP * src/nm-device.c src/nm-device.h - (connection_secrets_updated_cb): take a list of updated settings names, not just one * src/supplicant-manager/nm-supplicant-config.c src/supplicant-manager/nm-supplicant-config.h - (nm_supplicant_config_add_setting_wireless_security): remove 802.1x specific stuff; fix for updated LEAP bits; punt 802.1x stuff to nm_supplicant_config_add_setting_8021x() - (nm_supplicant_config_add_setting_8021x): add an 802-1x setting to the supplicant config * src/nm-device-802-11-wireless.c - (build_supplicant_config): pass in the 802.1x setting too, if any - (real_connection_secrets_updated): take a list of updated settings names, not just one * src/nm-device-802-3-ethernet.c src/nm-cdma-device.c src/nm-gsm-device.c - (real_connection_secrets_updated_cb): take a list of updated settings names, not just one * src/nm-activation-request.c src/nm-activation-request.h - (nm_act_request_class_init): the 'connection-secrets-updated' signal now passes a list of updated settings names, not just one - (update_one_setting): new function; handle one updated setting - (get_secrets_cb): handle multiple settings returned from the settings service; have to be careful of ordering here as there are some dependencies between settings (ex. wireless-security and 802.1x in some cases) * src/marshallers/nm-marshal.list - new marshaller for connection-secrets-updated signal * libnm-util/nm-setting-8021x.c - Add back the 'pin' and 'psk' settings, for EAP-SIM and EAP-PSK auth methods - (verify): a valid 'eap' property is now required * libnm-util/nm-connection.c - (register_default_settings): add priorities to settings; there are some dependencies between settings, and during the need_secrets calls this priority needs to be respected. For example, only the wireless-security setting knows whether or not the connection is going to use 802.1x or now, so it must be asked for secrets before any existing 802.1x setting is - (nm_connection_lookup_setting_type): expose * libnm-util/nm-setting-wireless.c - (verify): should verify even if all_settings is NULL; otherwise won't catch the case where there is missing security * libnm-util/nm-setting-wireless-security.c - Remove everything to do with 802.1x - Add old-school LEAP specific properties for username and password - (need_secrets): rework LEAP secrets checking - (verify): rework for LEAP and 802.1x verification git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3470 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-17 19:37:23 +00:00
#include "libgsystem.h"
#include "nm-activation-request.h"
#include "nm-logging.h"
2008-03-17 Dan Williams <dcbw@redhat.com> Split the 802.1x bits out of the wireless-security setting so they are generalized enough for wired 802.1x to use too. * introspection/nm-exported-connection.xml - GetSecrets now returns 'a{sa{sv}}' (a hash of settings hashes) instead of just a hash of the secrets for one setting * libnm-util/nm-setting-wireless-security.c libnm-util/nm-setting-wireless-security.h - Remove 802.1x-specific stuff - Added leap-username and leap-password properties for old-school LEAP * src/nm-device.c src/nm-device.h - (connection_secrets_updated_cb): take a list of updated settings names, not just one * src/supplicant-manager/nm-supplicant-config.c src/supplicant-manager/nm-supplicant-config.h - (nm_supplicant_config_add_setting_wireless_security): remove 802.1x specific stuff; fix for updated LEAP bits; punt 802.1x stuff to nm_supplicant_config_add_setting_8021x() - (nm_supplicant_config_add_setting_8021x): add an 802-1x setting to the supplicant config * src/nm-device-802-11-wireless.c - (build_supplicant_config): pass in the 802.1x setting too, if any - (real_connection_secrets_updated): take a list of updated settings names, not just one * src/nm-device-802-3-ethernet.c src/nm-cdma-device.c src/nm-gsm-device.c - (real_connection_secrets_updated_cb): take a list of updated settings names, not just one * src/nm-activation-request.c src/nm-activation-request.h - (nm_act_request_class_init): the 'connection-secrets-updated' signal now passes a list of updated settings names, not just one - (update_one_setting): new function; handle one updated setting - (get_secrets_cb): handle multiple settings returned from the settings service; have to be careful of ordering here as there are some dependencies between settings (ex. wireless-security and 802.1x in some cases) * src/marshallers/nm-marshal.list - new marshaller for connection-secrets-updated signal * libnm-util/nm-setting-8021x.c - Add back the 'pin' and 'psk' settings, for EAP-SIM and EAP-PSK auth methods - (verify): a valid 'eap' property is now required * libnm-util/nm-connection.c - (register_default_settings): add priorities to settings; there are some dependencies between settings, and during the need_secrets calls this priority needs to be respected. For example, only the wireless-security setting knows whether or not the connection is going to use 802.1x or now, so it must be asked for secrets before any existing 802.1x setting is - (nm_connection_lookup_setting_type): expose * libnm-util/nm-setting-wireless.c - (verify): should verify even if all_settings is NULL; otherwise won't catch the case where there is missing security * libnm-util/nm-setting-wireless-security.c - Remove everything to do with 802.1x - Add old-school LEAP specific properties for username and password - (need_secrets): rework LEAP secrets checking - (verify): rework for LEAP and 802.1x verification git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3470 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-17 19:37:23 +00:00
#include "nm-setting-wireless-security.h"
#include "nm-setting-8021x.h"
#include "nm-device.h"
#include "nm-active-connection.h"
#include "nm-settings-connection.h"
#include "nm-posix-signals.h"
2007-09-28 Tambet Ingo <tambet@gmail.com> * src/nm-manager.c: * src/nm-manager.h: Implement device activation through NMManager. Implement "pending device activation" here - If the connection isn't found, we try to wait for up to 5 seconds for the connection to be provided. Add NMConnectionType argument to "connection-added" and "connection-removed" signals. (nm_manager_get): Remove. Finally. * src/nm-activation-request.c: * src/nm-activation-request.h: Remove all the deferred activation code. * src/nm-device.c: Remove all the deferred activation code. Once * the device activation is started, it's started. Update the activation virtual function signature. * src/nm-device-interface.c: * src/nm-device-interface.h: Device activation now takes only NMActRequest argument. Don't expose device activation directly on dbus, it's supposed to go through NMManager now. * src/NetworkManagerPolicy.c (nm_policy_device_change_check): * Make the code a bit more compact. Use the new device activation methods through NMManager. * introspection/nm-manager-client.xml: * introspection/nm-manager.xml: * libnm-glib/nm-client.c: * libnm-glib/nm-client.h: Add device activation method. * libnm-glib/nm-device.c: * libnm-glib/nm-device.h: * introspection/nm-device.xml: Remove device activation method. It's done through NMManager now. * src/vpn-manager/nm-vpn-manager.c (impl_vpn_manager_connect): * Use the shiny new (nm_manager_get_device_by_path) function, get rid of our own )find_device). git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2915 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-01 15:38:39 +00:00
G_DEFINE_TYPE (NMActRequest, nm_act_request, NM_TYPE_ACTIVE_CONNECTION)
#define NM_ACT_REQUEST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_ACT_REQUEST, \
NMActRequestPrivate))
typedef struct {
char *table;
char *rule;
} ShareRule;
2007-09-11 Dan Williams <dcbw@redhat.com> * libnm-util/nm-setting.c libnm-util/nm-setting.h - (nm_setting_update_secrets): new function; add a virtual function that subclasses can implement to update their secrets - (setting_wireless_security_update_secrets): implement that function for the 802-11-wireless-security subclass * libnm-util/nm-connection.c libnm-util/nm-connection.h - (nm_connection_update_secrets): update secrets for a Setting and emit a signal on success * src/nm-manager.c src/nm-manager.h src/nm-marshal.list - (connection_get_settings_cb): enable system settings bits - (nm_manager_get_connection_secrets, get_secrets_cb): add function to request secrets from the settings dbus service and to push those secrets to the NMConnection itself * src/nm-activation-request.c src/nm-activation-request.h - Attach to the 'secrets-updated' signal of the NMConnection that's currently being activated, and proxy that signal to other listeners. Goes through the activation request because the activation request is the thing that manages the lifetime of the NMConnection that's being activated. * src/nm-device-802-11-wireless.c - (real_connection_secrets_updated): implement the connection secrets updated notification and restart activation when secrets are received - (real_act_stage2_config): request secrets from the settings dbus service if secrets are needed * src/nm-device.c src/nm-device.h - (clear_act_request, nm_device_activation_cancel, nm_device_deactivate_quickly, nm_device_dispose): consolidate places where the activation request is cleared - (nm_device_activate, connection_secrets_updated_cb): attach to the updated secrets signal of activation request and add a function that subclasses can override to handle it easily git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2782 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-09-11 18:02:27 +00:00
typedef struct {
GSList *secrets_calls;
gboolean shared;
GSList *share_rules;
} NMActRequestPrivate;
enum {
PROP_0,
PROP_IP4_CONFIG,
PROP_DHCP4_CONFIG,
PROP_IP6_CONFIG,
PROP_DHCP6_CONFIG,
LAST_PROP
};
/*******************************************************************/
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));
}
/*******************************************************************/
typedef struct {
NMActRequest *self;
guint32 call_id;
NMActRequestSecretsFunc callback;
gpointer callback_data;
} GetSecretsInfo;
static void
get_secrets_cb (NMSettingsConnection *connection,
guint32 call_id,
const char *agent_username,
const char *setting_name,
GError *error,
gpointer user_data)
{
GetSecretsInfo *info = user_data;
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (info->self);
g_return_if_fail (info->call_id == call_id);
priv->secrets_calls = g_slist_remove (priv->secrets_calls, info);
info->callback (info->self, call_id, NM_CONNECTION (connection), error, info->callback_data);
g_free (info);
}
guint32
nm_act_request_get_secrets (NMActRequest *self,
const char *setting_name,
NMSettingsGetSecretsFlags flags,
const char *hint,
NMActRequestSecretsFunc callback,
gpointer callback_data)
{
NMActRequestPrivate *priv;
GetSecretsInfo *info;
guint32 call_id;
NMConnection *connection;
const char *hints[2] = { hint, NULL };
g_return_val_if_fail (self, 0);
g_return_val_if_fail (NM_IS_ACT_REQUEST (self), 0);
priv = NM_ACT_REQUEST_GET_PRIVATE (self);
info = g_malloc0 (sizeof (GetSecretsInfo));
info->self = self;
info->callback = callback;
info->callback_data = callback_data;
if (nm_active_connection_get_user_requested (NM_ACTIVE_CONNECTION (self)))
flags |= NM_SETTINGS_GET_SECRETS_FLAG_USER_REQUESTED;
connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (self));
call_id = nm_settings_connection_get_secrets (NM_SETTINGS_CONNECTION (connection),
nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (self)),
setting_name,
flags,
hints,
get_secrets_cb,
info,
NULL);
if (call_id > 0) {
info->call_id = call_id;
priv->secrets_calls = g_slist_append (priv->secrets_calls, info);
} else
g_free (info);
return call_id;
}
void
nm_act_request_cancel_secrets (NMActRequest *self, guint32 call_id)
{
NMActRequestPrivate *priv;
NMConnection *connection;
GSList *iter;
g_return_if_fail (self);
g_return_if_fail (NM_IS_ACT_REQUEST (self));
g_return_if_fail (call_id > 0);
priv = NM_ACT_REQUEST_GET_PRIVATE (self);
connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (self));
for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data;
/* Remove the matching info */
if (info->call_id == call_id) {
priv->secrets_calls = g_slist_remove_link (priv->secrets_calls, iter);
g_slist_free (iter);
nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (connection), call_id);
g_free (info);
break;
}
}
}
/********************************************************************/
static void
clear_share_rules (NMActRequest *req)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (req);
GSList *iter;
for (iter = priv->share_rules; iter; iter = g_slist_next (iter)) {
ShareRule *rule = (ShareRule *) iter->data;
g_free (rule->table);
g_free (rule->rule);
g_free (rule);
}
g_slist_free (priv->share_rules);
priv->share_rules = NULL;
}
static void
share_child_setup (gpointer user_data G_GNUC_UNUSED)
{
/* We are in the child process at this point */
pid_t pid = getpid ();
setpgid (pid, pid);
nm_unblock_posix_signals (NULL);
}
2007-08-28 Dan Williams <dcbw@redhat.com> Remove NMAPSecurity objects, they are replaced with flags on the APs for each AP's capabilities, and by NMConnection/NMSettings objects for user defined connections. * include/NetworkManager.h - Redefine 802.11 security properties. There are now device capabilities and AP flags and AP security flags. It was way to unclear before. * src/Makefile.am src/nm-ap-security-leap.h src/nm-ap-security-leap.c src/nm-ap-security-wpa-eap.c src/nm-ap-security-wpa-eap.h src/nm-ap-security-private.h src/nm-ap-security-wpa-psk.c src/nm-ap-security-wpa-psk.h src/nm-ap-security-wep.c src/nm-ap-security-wep.h src/nm-ap-security.c src/nm-ap-security.h - Removed, to be replaced with NMConnection/NMSettings objects * src/nm-dbus-nmi.c src/nm-dbus-nmi.h - Removed, to be replaced by code that talks to the new info daemon interface and gets NMConnection/NMSettings objects * src/backends/NetworkManagerSuSE.c - Remove usage of NMAPSecurity; should be replaced by a system-level info-daemon that does the same thing but talks the new info-daemon D-Bus interface * src/NetworkManagerAP.h src/NetworkManagerAP.c src/NetworkManagerAPList.c libnm-glib/libnm-glib-test.c - Remove usage of NMAPSecurity objects and adjust to new flags for WPA/RSN * libnm-glib/nm-access-point.c libnm-glib/nm-access-point.h introspection/nm-access-point.xml test/nm-tool.c - Adjust to new flags for AP security * utils/nm-utils.c utils/nm-utils.h src/vpn-manager/nm-dbus-vpn.c - Remove D-Bus pending call stuff from nm-utils and put it in the VPN stuff which is the only place it's used * src/nm-device-interface.c src/nm-device-interface.h introspection/nm-device.xml src/nm-activation-request.c src/nm-activation-request.h src/nm-device.c - Add a new 'specific_object' argument that hints to NM what actual AP or other device-specific thing the connection should apply to. NMConnection objects can apply to more than one actual device/AP. * libnm-util/nm-connection.c * libnm-util/nm-connection.h - Add 'have_secrets" call stubs * libnm-util/cipher.h - Move NM_AUTH_TYPE_* defines here for now * src/nm-device-802-11-wireless.c - Remove usage of NMAPSecurity, to be replaced with NMConnection/ NMSettings objects * src/NetworkManagerDbus.c * src/NetworkManagerPolicy.c - Remove usage of update_allowed_networks, should be pushing data in a different manner git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2738 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-08-28 14:47:31 +00:00
void
nm_act_request_set_shared (NMActRequest *req, gboolean shared)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (req);
GSList *list, *iter;
g_return_if_fail (NM_IS_ACT_REQUEST (req));
NM_ACT_REQUEST_GET_PRIVATE (req)->shared = shared;
/* Tear the rules down in reverse order when sharing is stopped */
list = g_slist_copy (priv->share_rules);
if (!shared)
list = g_slist_reverse (list);
/* Send the rules to iptables */
for (iter = list; iter; iter = g_slist_next (iter)) {
ShareRule *rule = (ShareRule *) iter->data;
char *envp[1] = { NULL };
gs_strfreev char **argv = NULL;
gs_free char *cmd = NULL;
cmd = g_strdup_printf ("%s --table %s %s %s",
IPTABLES_PATH,
rule->table,
shared ? "--insert" : "--delete",
rule->rule);
if (!cmd)
continue;
argv = g_strsplit (cmd, " ", 0);
if (argv && argv[0]) {
int status;
GError *error = NULL;
nm_log_info (LOGD_SHARING, "Executing: %s", cmd);
if (!g_spawn_sync ("/", argv, envp, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
share_child_setup, NULL, NULL, NULL, &status, &error)) {
nm_log_warn (LOGD_SHARING, "Error executing command: (%d) %s",
error ? error->code : -1,
(error && error->message) ? error->message : "(unknown)");
g_clear_error (&error);
} else if (WEXITSTATUS (status)) {
nm_log_warn (LOGD_SHARING, "** Command returned exit status %d.",
WEXITSTATUS (status));
}
}
}
g_slist_free (list);
/* Clear the share rule list when sharing is stopped */
if (!shared)
clear_share_rules (req);
}
gboolean
nm_act_request_get_shared (NMActRequest *req)
{
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
return NM_ACT_REQUEST_GET_PRIVATE (req)->shared;
}
void
nm_act_request_add_share_rule (NMActRequest *req,
const char *table,
const char *table_rule)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (req);
ShareRule *rule;
g_return_if_fail (NM_IS_ACT_REQUEST (req));
g_return_if_fail (table != NULL);
g_return_if_fail (table_rule != NULL);
rule = g_malloc0 (sizeof (ShareRule));
rule->table = g_strdup (table);
rule->rule = g_strdup (table_rule);
priv->share_rules = g_slist_append (priv->share_rules, rule);
}
/********************************************************************/
static void
device_notify (GObject *object,
GParamSpec *pspec,
gpointer self)
{
g_object_notify (self, pspec->name);
}
static void
device_state_changed (NMActiveConnection *active,
NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state)
{
NMActiveConnectionState cur_ac_state = nm_active_connection_get_state (active);
NMActiveConnectionState ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN;
/* Ignore state changes when this activation request is not yet active, but
* handle the DISCONNECTED state correctly. The device clears the
* activation request before sending the state change signal so this
* must be special-cased to ensure the activation request is deactivated.
*/
if (NM_ACTIVE_CONNECTION (nm_device_get_act_request (device)) != active) {
if (new_state != NM_DEVICE_STATE_DISCONNECTED)
return;
if (cur_ac_state < NM_ACTIVE_CONNECTION_STATE_ACTIVATING)
return;
/* Catch device disconnections after this request has been active */
}
/* Set NMActiveConnection state based on the device's state */
switch (new_state) {
case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_IP_CONFIG:
case NM_DEVICE_STATE_IP_CHECK:
case NM_DEVICE_STATE_SECONDARIES:
ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING;
break;
case NM_DEVICE_STATE_ACTIVATED:
ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED;
g_signal_connect (device, "notify::" NM_DEVICE_IP4_CONFIG,
G_CALLBACK (device_notify), active);
g_signal_connect (device, "notify::" NM_DEVICE_DHCP4_CONFIG,
G_CALLBACK (device_notify), active);
g_signal_connect (device, "notify::" NM_DEVICE_IP6_CONFIG,
G_CALLBACK (device_notify), active);
g_signal_connect (device, "notify::" NM_DEVICE_DHCP6_CONFIG,
G_CALLBACK (device_notify), active);
break;
case NM_DEVICE_STATE_DEACTIVATING:
ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING;
break;
case NM_DEVICE_STATE_FAILED:
case NM_DEVICE_STATE_DISCONNECTED:
case NM_DEVICE_STATE_UNMANAGED:
case NM_DEVICE_STATE_UNAVAILABLE:
ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATED;
g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_notify), active);
break;
default:
break;
}
if ( ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
|| ac_state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) {
nm_active_connection_set_default (active, FALSE);
nm_active_connection_set_default6 (active, FALSE);
}
nm_active_connection_set_state (active, ac_state);
}
static void
master_failed (NMActiveConnection *self)
{
NMDevice *device;
NMDeviceState device_state;
/* If the connection has an active device, fail it */
device = nm_active_connection_get_device (self);
if (device) {
device_state = nm_device_get_state (device);
if (nm_device_is_activating (device) || (device_state == NM_DEVICE_STATE_ACTIVATED)) {
nm_device_state_changed (device,
NM_DEVICE_STATE_FAILED,
NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED);
return;
}
}
/* If no device, or the device wasn't active, just move to deactivated state */
nm_active_connection_set_state (self, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED);
}
/********************************************************************/
/**
* nm_act_request_new:
*
* @connection: the connection to activate @device with
* @specific_object: the object path of the specific object (ie, WiFi access point,
* etc) that will be used to activate @connection and @device
* @subject: the #NMAuthSubject representing the requestor of the activation
* @device: the device/interface to configure according to @connection; or %NULL
* if the connection describes a software device which will be created during
* connection activation
*
* Creates a new device-based activation request.
*
* Returns: the new activation request on success, %NULL on error.
*/
NMActRequest *
nm_act_request_new (NMConnection *connection,
const char *specific_object,
NMAuthSubject *subject,
NMDevice *device)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (!device || NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (NM_IS_AUTH_SUBJECT (subject), NULL);
return (NMActRequest *) 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_INT_SUBJECT, subject,
NULL);
}
static void
nm_act_request_init (NMActRequest *req)
{
}
static void
dispose (GObject *object)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
NMConnection *connection;
GSList *iter;
/* Clear any share rules */
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 */
connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object));
for (iter = priv->secrets_calls; connection && iter; iter = g_slist_next (iter)) {
GetSecretsInfo *info = iter->data;
nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (connection), info->call_id);
g_free (info);
}
g_slist_free (priv->secrets_calls);
priv->secrets_calls = NULL;
G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDevice *device;
device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
if (!device) {
g_value_set_boxed (value, "/");
return;
}
switch (prop_id) {
case PROP_IP4_CONFIG:
g_object_get_property (G_OBJECT (device), NM_DEVICE_IP4_CONFIG, value);
break;
case PROP_DHCP4_CONFIG:
g_object_get_property (G_OBJECT (device), NM_DEVICE_DHCP4_CONFIG, value);
break;
case PROP_IP6_CONFIG:
g_object_get_property (G_OBJECT (device), NM_DEVICE_IP6_CONFIG, value);
break;
case PROP_DHCP6_CONFIG:
g_object_get_property (G_OBJECT (device), NM_DEVICE_DHCP6_CONFIG, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_act_request_class_init (NMActRequestClass *req_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (req_class);
NMActiveConnectionClass *active_class = NM_ACTIVE_CONNECTION_CLASS (req_class);
g_type_class_add_private (req_class, sizeof (NMActRequestPrivate));
/* virtual methods */
object_class->dispose = dispose;
object_class->get_property = get_property;
active_class->master_failed = master_failed;
active_class->device_state_changed = device_state_changed;
/* properties */
g_object_class_override_property (object_class, PROP_IP4_CONFIG,
NM_ACTIVE_CONNECTION_IP4_CONFIG);
g_object_class_override_property (object_class, PROP_DHCP4_CONFIG,
NM_ACTIVE_CONNECTION_DHCP4_CONFIG);
g_object_class_override_property (object_class, PROP_IP6_CONFIG,
NM_ACTIVE_CONNECTION_IP6_CONFIG);
g_object_class_override_property (object_class, PROP_DHCP6_CONFIG,
NM_ACTIVE_CONNECTION_DHCP6_CONFIG);
}