diff options
40 files changed, 645 insertions, 3452 deletions
@@ -1,3 +1,82 @@ +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 + 2007-08-27 Tambet Ingo <tambet@gmail.com> * src/nm-manager.c (impl_manager_get_devices): Duplicate the device path, diff --git a/include/NetworkManager.h b/include/NetworkManager.h index 2992f3b690..cc2c101d0d 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -79,47 +79,42 @@ typedef enum NMDeviceType #define NM_DEVICE_CAP_CARRIER_DETECT 0x00000002 -/* 802.11 wireless-specific device capability bits */ -#define NM_802_11_CAP_NONE 0x00000000 -#define NM_802_11_CAP_PROTO_NONE 0x00000001 -#define NM_802_11_CAP_PROTO_WEP 0x00000002 -#define NM_802_11_CAP_PROTO_WPA 0x00000004 -#define NM_802_11_CAP_PROTO_WPA2 0x00000008 -#define NM_802_11_CAP_RESERVED1 0x00000010 -#define NM_802_11_CAP_RESERVED2 0x00000020 -#define NM_802_11_CAP_KEY_MGMT_PSK 0x00000040 -#define NM_802_11_CAP_KEY_MGMT_802_1X 0x00000080 -#define NM_802_11_CAP_RESERVED3 0x00000100 -#define NM_802_11_CAP_RESERVED4 0x00000200 -#define NM_802_11_CAP_RESERVED5 0x00000400 -#define NM_802_11_CAP_RESERVED6 0x00000800 -#define NM_802_11_CAP_CIPHER_WEP40 0x00001000 -#define NM_802_11_CAP_CIPHER_WEP104 0x00002000 -#define NM_802_11_CAP_CIPHER_TKIP 0x00004000 -#define NM_802_11_CAP_CIPHER_CCMP 0x00008000 +/* 802.11 wireless device-specific capabilities */ +#define NM_802_11_DEVICE_CAP_NONE 0x00000000 +#define NM_802_11_DEVICE_CAP_CIPHER_WEP40 0x00000001 +#define NM_802_11_DEVICE_CAP_CIPHER_WEP104 0x00000002 +#define NM_802_11_DEVICE_CAP_CIPHER_TKIP 0x00000004 +#define NM_802_11_DEVICE_CAP_CIPHER_CCMP 0x00000008 +#define NM_802_11_DEVICE_CAP_WPA 0x00000010 +#define NM_802_11_DEVICE_CAP_RSN 0x00000020 + /* - * NM-supported Authentication Methods + * 802.11 Access Point flags + * */ -#define NM_AUTH_TYPE_WPA_PSK_AUTO 0x00000000 -#define NM_AUTH_TYPE_NONE 0x00000001 -#define NM_AUTH_TYPE_WEP40 0x00000002 -#define NM_AUTH_TYPE_WPA_PSK_TKIP 0x00000004 -#define NM_AUTH_TYPE_WPA_PSK_CCMP 0x00000008 -#define NM_AUTH_TYPE_WEP104 0x00000010 -#define NM_AUTH_TYPE_WPA_EAP 0x00000020 -#define NM_AUTH_TYPE_LEAP 0x00000040 +#define NM_802_11_AP_FLAGS_NONE 0x00000000 +#define NM_802_11_AP_FLAGS_PRIVACY 0x00000001 /* - * EAP Methods + * 802.11 Access Point security flags + * + * These describe the current security requirements of the BSSID as extracted + * from various pieces of beacon information, like beacon flags and various + * information elements. */ -#define NM_EAP_METHOD_MD5 0x00000001 /* EAP-MD5 */ -#define NM_EAP_METHOD_MSCHAP 0x00000002 /* EAP-MSCHAPv2 */ -#define NM_EAP_METHOD_OTP 0x00000004 /* EAP-OTP */ -#define NM_EAP_METHOD_GTC 0x00000008 /* EAP-GTC */ -#define NM_EAP_METHOD_PEAP 0x00000010 /* EAP-PEAP */ -#define NM_EAP_METHOD_TLS 0x00000020 /* EAP-TLS */ -#define NM_EAP_METHOD_TTLS 0x00000040 /* EAP-TTLS */ +#define NM_802_11_AP_SEC_NONE 0x00000000 +#define NM_802_11_AP_SEC_PAIR_WEP40 0x00000001 +#define NM_802_11_AP_SEC_PAIR_WEP104 0x00000002 +#define NM_802_11_AP_SEC_PAIR_TKIP 0x00000004 +#define NM_802_11_AP_SEC_PAIR_CCMP 0x00000008 +#define NM_802_11_AP_SEC_GROUP_WEP40 0x00000010 +#define NM_802_11_AP_SEC_GROUP_WEP104 0x00000020 +#define NM_802_11_AP_SEC_GROUP_TKIP 0x00000040 +#define NM_802_11_AP_SEC_GROUP_CCMP 0x00000080 +#define NM_802_11_AP_SEC_KEY_MGMT_PSK 0x00000100 +#define NM_802_11_AP_SEC_KEY_MGMT_802_1X 0x00000200 + /* * Wireless network types diff --git a/introspection/nm-access-point.xml b/introspection/nm-access-point.xml index 9608a457fc..a3cba5d5fb 100644 --- a/introspection/nm-access-point.xml +++ b/introspection/nm-access-point.xml @@ -2,8 +2,9 @@ <node name="/"> <interface name="org.freedesktop.NetworkManager.AccessPoint"> - <property name="Capabilities" type="u" access="read"/> - <property name="Encrypted" type="b" access="read"/> + <property name="Flags" type="u" access="read"/> + <property name="WPAFlags" type="u" access="read"/> + <property name="RSNFlags" type="u" access="read"/> <property name="Ssid" type="ay" access="read"/> <property name="Frequency" type="d" access="read"/> <property name="HwAddress" type="s" access="read"/> diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 53da6e0ed4..03b6649dfc 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -4,7 +4,7 @@ <interface name="org.freedesktop.NetworkManager.Device"> <method name="Activate"> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_activate"/> - <arg name="connection" type="a{sa{sv}}" direction="in"/> + <arg name="connection" type="a{sa{sv}}o" direction="in"/> </method> <method name="Deactivate"> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_deactivate"/> diff --git a/libnm-glib/libnm-glib-test.c b/libnm-glib/libnm-glib-test.c index 5740b6321b..d56a6345b0 100644 --- a/libnm-glib/libnm-glib-test.c +++ b/libnm-glib/libnm-glib-test.c @@ -177,8 +177,9 @@ dump_access_point (NMAccessPoint *ap) g_print ("\tMAC Address: %s\n", str); g_free (str); - g_print ("\tCapabilities: %d\n", nm_access_point_get_capabilities (ap)); - g_print ("\tEncrypted: %d\n", nm_access_point_is_encrypted (ap)); + g_print ("\tFlags: 0x%X\n", nm_access_point_get_flags (ap)); + g_print ("\tWPA Flags: 0x%X\n", nm_access_point_get_wpa_flags (ap)); + g_print ("\tRSN Flags: 0x%X\n", nm_access_point_get_rsn_flags (ap)); g_print ("\tFrequency: %f\n", nm_access_point_get_frequency (ap)); g_print ("\tMode: %d\n", nm_access_point_get_mode (ap)); diff --git a/libnm-glib/nm-access-point.c b/libnm-glib/nm-access-point.c index 2465cc5c8f..e9bc75f248 100644 --- a/libnm-glib/nm-access-point.c +++ b/libnm-glib/nm-access-point.c @@ -102,19 +102,27 @@ strength_changed_proxy (NMAccessPoint *ap, guchar strength) } guint32 -nm_access_point_get_capabilities (NMAccessPoint *ap) +nm_access_point_get_flags (NMAccessPoint *ap) { - g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0); + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_FLAGS_NONE); - return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Capabilities"); + return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Flags"); } -gboolean -nm_access_point_is_encrypted (NMAccessPoint *ap) +guint32 +nm_access_point_get_wpa_flags (NMAccessPoint *ap) +{ + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE); + + return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "WPAFlags"); +} + +guint32 +nm_access_point_get_rsn_flags (NMAccessPoint *ap) { - g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), FALSE); + g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE); - return nm_object_get_boolean_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Encrypted"); + return nm_object_get_uint_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "RSNFlags"); } GByteArray * diff --git a/libnm-glib/nm-access-point.h b/libnm-glib/nm-access-point.h index 0d4bf7dfee..3300175945 100644 --- a/libnm-glib/nm-access-point.h +++ b/libnm-glib/nm-access-point.h @@ -29,8 +29,9 @@ GType nm_access_point_get_type (void); NMAccessPoint *nm_access_point_new (DBusGConnection *connection, const char *path); -guint32 nm_access_point_get_capabilities (NMAccessPoint *ap); -gboolean nm_access_point_is_encrypted (NMAccessPoint *ap); +guint32 nm_access_point_get_flags (NMAccessPoint *ap); +guint32 nm_access_point_get_wpa_flags (NMAccessPoint *ap); +guint32 nm_access_point_get_rsn_flags (NMAccessPoint *ap); GByteArray * nm_access_point_get_ssid (NMAccessPoint *ap); gdouble nm_access_point_get_frequency (NMAccessPoint *ap); char * nm_access_point_get_hw_address (NMAccessPoint *ap); diff --git a/libnm-util/cipher.h b/libnm-util/cipher.h index 4b30d7fbba..ddb955b974 100644 --- a/libnm-util/cipher.h +++ b/libnm-util/cipher.h @@ -28,6 +28,30 @@ extern "C" { #endif +/* + * NM-supported Authentication Methods + */ +#define NM_AUTH_TYPE_WPA_PSK_AUTO 0x00000000 +#define NM_AUTH_TYPE_NONE 0x00000001 +#define NM_AUTH_TYPE_WEP40 0x00000002 +#define NM_AUTH_TYPE_WPA_PSK_TKIP 0x00000004 +#define NM_AUTH_TYPE_WPA_PSK_CCMP 0x00000008 +#define NM_AUTH_TYPE_WEP104 0x00000010 +#define NM_AUTH_TYPE_WPA_EAP 0x00000020 +#define NM_AUTH_TYPE_LEAP 0x00000040 + +/* + * EAP Methods + */ +#define NM_EAP_METHOD_MD5 0x00000001 /* EAP-MD5 */ +#define NM_EAP_METHOD_MSCHAP 0x00000002 /* EAP-MSCHAPv2 */ +#define NM_EAP_METHOD_OTP 0x00000004 /* EAP-OTP */ +#define NM_EAP_METHOD_GTC 0x00000008 /* EAP-GTC */ +#define NM_EAP_METHOD_PEAP 0x00000010 /* EAP-PEAP */ +#define NM_EAP_METHOD_TLS 0x00000020 /* EAP-TLS */ +#define NM_EAP_METHOD_TTLS 0x00000040 /* EAP-TTLS */ + + typedef struct IEEE_802_11_Cipher IEEE_802_11_Cipher; void ieee_802_11_cipher_ref (IEEE_802_11_Cipher *cipher); diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index 6ec30f0e63..035eaf6d08 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -137,6 +137,15 @@ nm_connection_compare (NMConnection *connection, NMConnection *other) return FALSE; } +gboolean +nm_connection_have_secrets (NMConnection *connection) +{ + /* FIXME: go through Settings objects and determine if there are any + * secrets required. + */ + return FALSE; +} + static void add_one_setting_to_hash (gpointer key, gpointer data, gpointer user_data) { diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h index 58335f6156..7e08526279 100644 --- a/libnm-util/nm-connection.h +++ b/libnm-util/nm-connection.h @@ -21,6 +21,8 @@ NMSetting *nm_connection_get_setting (NMConnection *connection, gboolean nm_connection_compare (NMConnection *connection, NMConnection *other); +gboolean nm_connection_have_secrets (NMConnection *connection); + GHashTable *nm_connection_to_hash (NMConnection *connection); void nm_connection_dump (NMConnection *connection); void nm_connection_destroy (NMConnection *connection); diff --git a/src/Makefile.am b/src/Makefile.am index ae9ebe9318..5f0e4b7d40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,8 +34,6 @@ NetworkManager_SOURCES = \ NetworkManagerDbusUtils.h \ nm-dbus-manager.h \ nm-dbus-manager.c \ - nm-dbus-nmi.c \ - nm-dbus-nmi.h \ nm-hal-manager.c \ nm-hal-manager.h \ nm-ip4-config.c \ @@ -58,17 +56,6 @@ NetworkManager_SOURCES = \ nm-activation-request.h \ autoip.c \ autoip.h \ - nm-ap-security.c \ - nm-ap-security.h \ - nm-ap-security-private.h \ - nm-ap-security-wep.c \ - nm-ap-security-wep.h \ - nm-ap-security-wpa-eap.c \ - nm-ap-security-wpa-eap.h \ - nm-ap-security-wpa-psk.c \ - nm-ap-security-wpa-psk.h \ - nm-ap-security-leap.c \ - nm-ap-security-leap.h \ nm-marshal-main.c \ kernel-types.h \ wpa.c \ diff --git a/src/NetworkManagerAP.c b/src/NetworkManagerAP.c index 8b58134b6e..7968e88dee 100644 --- a/src/NetworkManagerAP.c +++ b/src/NetworkManagerAP.c @@ -22,7 +22,6 @@ #include "NetworkManagerAP.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" -#include "nm-ap-security.h" #include "nm-dbus-manager.h" #include <wireless.h> #include "wpa.h" @@ -55,7 +54,10 @@ typedef struct gint8 strength; double freq; guint16 rate; - guint32 capabilities; + + guint32 flags; /* General flags */ + guint32 wpa_flags; /* WPA-related flags */ + guint32 rsn_flags; /* RSN (WPA2) -related flags */ /* Non-scanned attributes */ gboolean invalid; @@ -71,7 +73,6 @@ typedef struct /* Things from user prefs/NetworkManagerInfo */ gboolean fallback; - NMAPSecurity * security; GTimeVal timestamp; GSList * user_addresses; } NMAccessPointPrivate; @@ -90,8 +91,9 @@ static guint signals[LAST_SIGNAL] = { 0 }; enum { PROP_0, - PROP_CAPABILITIES, - PROP_ENCRYPTED, + PROP_FLAGS, + PROP_WPA_FLAGS, + PROP_RSN_FLAGS, PROP_SSID, PROP_FREQUENCY, PROP_HW_ADDRESS, @@ -110,7 +112,9 @@ nm_ap_init (NMAccessPoint *ap) priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++); priv->mode = IW_MODE_INFRA; - priv->capabilities = NM_802_11_CAP_PROTO_NONE; + priv->flags = NM_802_11_AP_FLAGS_NONE; + priv->wpa_flags = NM_802_11_AP_SEC_NONE; + priv->rsn_flags = NM_802_11_AP_SEC_NONE; priv->broadcast = TRUE; } @@ -125,9 +129,6 @@ finalize (GObject *object) g_slist_foreach (priv->user_addresses, (GFunc)g_free, NULL); g_slist_free (priv->user_addresses); - if (priv->security) - g_object_unref (G_OBJECT (priv->security)); - G_OBJECT_CLASS (nm_ap_parent_class)->finalize (object); } @@ -140,8 +141,14 @@ set_property (GObject *object, guint prop_id, int mode; switch (prop_id) { - case PROP_CAPABILITIES: - priv->capabilities = g_value_get_uint (value); + case PROP_FLAGS: + priv->flags = g_value_get_uint (value); + break; + case PROP_WPA_FLAGS: + priv->wpa_flags = g_value_get_uint (value); + break; + case PROP_RSN_FLAGS: + priv->rsn_flags = g_value_get_uint (value); break; case PROP_SSID: ssid = g_value_get_boxed (value); @@ -193,11 +200,14 @@ get_property (GObject *object, guint prop_id, int i; switch (prop_id) { - case PROP_CAPABILITIES: - g_value_set_uint (value, priv->capabilities); + case PROP_FLAGS: + g_value_set_uint (value, priv->flags); + break; + case PROP_WPA_FLAGS: + g_value_set_uint (value, priv->wpa_flags); break; - case PROP_ENCRYPTED: - g_value_set_boolean (value, !(priv->capabilities & NM_802_11_CAP_PROTO_NONE)); + case PROP_RSN_FLAGS: + g_value_set_uint (value, priv->rsn_flags); break; case PROP_SSID: len = priv->ssid ? priv->ssid->len : 0; @@ -234,7 +244,7 @@ static void nm_ap_class_init (NMAccessPointClass *ap_class) { GObjectClass *object_class = G_OBJECT_CLASS (ap_class); - guint32 all_caps; + guint32 all_sec_flags; g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate)); @@ -245,39 +255,47 @@ nm_ap_class_init (NMAccessPointClass *ap_class) /* properties */ - all_caps = NM_802_11_CAP_NONE - | NM_802_11_CAP_PROTO_NONE - | NM_802_11_CAP_PROTO_WEP - | NM_802_11_CAP_PROTO_WPA - | NM_802_11_CAP_PROTO_WPA2 - | NM_802_11_CAP_RESERVED1 - | NM_802_11_CAP_RESERVED2 - | NM_802_11_CAP_KEY_MGMT_PSK - | NM_802_11_CAP_KEY_MGMT_802_1X - | NM_802_11_CAP_RESERVED3 - | NM_802_11_CAP_RESERVED4 - | NM_802_11_CAP_RESERVED5 - | NM_802_11_CAP_RESERVED6 - | NM_802_11_CAP_CIPHER_WEP40 - | NM_802_11_CAP_CIPHER_WEP104 - | NM_802_11_CAP_CIPHER_TKIP - | NM_802_11_CAP_CIPHER_CCMP; + all_sec_flags = NM_802_11_AP_SEC_NONE + | NM_802_11_AP_SEC_PAIR_WEP40 + | NM_802_11_AP_SEC_PAIR_WEP104 + | NM_802_11_AP_SEC_PAIR_TKIP + | NM_802_11_AP_SEC_PAIR_CCMP + | NM_802_11_AP_SEC_GROUP_WEP40 + | NM_802_11_AP_SEC_GROUP_WEP104 + | NM_802_11_AP_SEC_GROUP_TKIP + | NM_802_11_AP_SEC_GROUP_CCMP + | NM_802_11_AP_SEC_KEY_MGMT_PSK + | NM_802_11_AP_SEC_KEY_MGMT_802_1X; g_object_class_install_property - (object_class, PROP_CAPABILITIES, - g_param_spec_uint (NM_AP_CAPABILITIES, - "Capabilities", - "Capabilities", - NM_802_11_CAP_NONE, all_caps, NM_802_11_CAP_PROTO_NONE, + (object_class, PROP_FLAGS, + g_param_spec_uint (NM_AP_FLAGS, + "Flags", + "Flags", + NM_802_11_AP_FLAGS_NONE, + NM_802_11_AP_FLAGS_PRIVACY, + NM_802_11_AP_FLAGS_NONE, G_PARAM_READWRITE)); g_object_class_install_property - (object_class, PROP_ENCRYPTED, - g_param_spec_boolean (NM_AP_ENCRYPTED, - "Encrypted", - "Is encrypted", - FALSE, - G_PARAM_READABLE)); + (object_class, PROP_WPA_FLAGS, + g_param_spec_uint (NM_AP_WPA_FLAGS, + "WPA Flags", + "WPA Flags", + NM_802_11_AP_SEC_NONE, + all_sec_flags, + NM_802_11_AP_SEC_NONE, + G_PARAM_READWRITE)); + + g_object_class_install_property + (object_class, PROP_RSN_FLAGS, + g_param_spec_uint (NM_AP_RSN_FLAGS, + "RSN Flags", + "RSN Flags", + NM_802_11_AP_SEC_NONE, + all_sec_flags, + NM_802_11_AP_SEC_NONE, + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_SSID, @@ -399,12 +417,11 @@ nm_ap_new_from_ap (NMAccessPoint *src_ap) new_priv->strength = src_priv->strength; new_priv->freq = src_priv->freq; new_priv->rate = src_priv->rate; - new_priv->capabilities = src_priv->capabilities; new_priv->artificial = src_priv->artificial; new_priv->broadcast = src_priv->broadcast; - - if (src_priv->security) - new_priv->security = nm_ap_security_new_copy (src_priv->security); + new_priv->flags = src_priv->flags; + new_priv->wpa_flags = src_priv->wpa_flags; + new_priv->rsn_flags = src_priv->rsn_flags; return new_ap; } @@ -446,14 +463,20 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data) nm_ap_set_address (ap, &addr); } else if (!strcmp (key, "wpaie")) { guint8 * ie = (guint8 *) array->data; + guint32 flags = nm_ap_get_wpa_flags (ap); + if (array->len <= 0 || array->len > WPA_MAX_IE_LEN) return; - nm_ap_add_capabilities_from_ie (ap, ie, array->len); + flags = nm_ap_add_security_from_ie (flags, ie, array->len); + nm_ap_set_wpa_flags (ap, flags); } else if (!strcmp (key, "rsnie")) { guint8 * ie = (guint8 *) array->data; + guint32 flags = nm_ap_get_rsn_flags (ap); + if (array->len <= 0 || array->len > WPA_MAX_IE_LEN) return; - nm_ap_add_capabilities_from_ie (ap, ie, array->len); + flags = nm_ap_add_security_from_ie (flags, ie, array->len); + nm_ap_set_rsn_flags (ap, flags); } } else if (G_VALUE_HOLDS_INT (variant)) { gint32 int_val = g_value_get_int (variant); @@ -475,11 +498,8 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data) } if (val & IEEE80211_CAP_PRIVACY) { - guint cur_caps; - - cur_caps = nm_ap_get_capabilities (ap); - if (cur_caps == NM_802_11_CAP_NONE || cur_caps & NM_802_11_CAP_PROTO_NONE) - nm_ap_add_capabilities_for_wep (ap); + guint32 flags = nm_ap_get_flags (ap); + nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY); } } } @@ -531,13 +551,16 @@ nm_ap_print_self (NMAccessPoint *ap, priv = NM_AP_GET_PRIVATE (ap); - nm_info ("%s'%s' (%p) stamp=%ld caps=0x%X bssid=" MAC_FMT " strength=%d " - "freq=[%f/%d] rate=%d inval=%d mode=%d seen=%ld", + nm_info ("%s'%s' (%p) stamp=%ld flags=0x%X wpa-flags=0x%X rsn-flags=0x%x " + "bssid=" MAC_FMT " strength=%d freq=[%f/%d] rate=%d inval=%d " + "mode=%d seen=%ld", prefix, priv->ssid ? nm_utils_escape_ssid (priv->ssid->data, priv->ssid->len) : "(none)", ap, priv->timestamp.tv_sec, - priv->capabilities, + priv->flags, + priv->wpa_flags, + priv->rsn_flags, MAC_ARG (priv->address.ether_addr_octet), priv->strength, (priv->freq > 20) ? priv->freq : 0, @@ -606,72 +629,69 @@ void nm_ap_set_ssid (NMAccessPoint *ap, const GByteArray * ssid) } -guint32 nm_ap_get_capabilities (NMAccessPoint *ap) +guint32 +nm_ap_get_flags (NMAccessPoint *ap) { - guint32 caps; + guint32 flags; - g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_CAP_NONE); + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_FLAGS_NONE); - g_object_get (ap, NM_AP_CAPABILITIES, &caps, NULL); + g_object_get (ap, NM_AP_FLAGS, &flags, NULL); - return caps; + return flags; } -void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities) +void +nm_ap_set_flags (NMAccessPoint *ap, guint32 flags) { g_return_if_fail (NM_IS_AP (ap)); - g_object_set (ap, NM_AP_CAPABILITIES, capabilities, NULL); + g_object_set (ap, NM_AP_FLAGS, flags, NULL); } - -/* - * Accessor function for encrypted flag - * - */ -gboolean nm_ap_get_encrypted (NMAccessPoint *ap) +guint32 +nm_ap_get_wpa_flags (NMAccessPoint *ap) { - gboolean encrypted; + guint32 flags; - g_return_val_if_fail (NM_IS_AP (ap), FALSE); + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - g_object_get (ap, NM_AP_ENCRYPTED, &encrypted, NULL); + g_object_get (ap, NM_AP_WPA_FLAGS, &flags, NULL); - return encrypted; + return flags; } -/* - * Accessors for AP security info - * - */ -NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap) +void +nm_ap_set_wpa_flags (NMAccessPoint *ap, guint32 flags) { - g_return_val_if_fail (NM_IS_AP (ap), NULL); + g_return_if_fail (NM_IS_AP (ap)); - return NM_AP_GET_PRIVATE (ap)->security; + g_object_set (ap, NM_AP_WPA_FLAGS, flags, NULL); } -void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security) +guint32 +nm_ap_get_rsn_flags (NMAccessPoint *ap) { - NMAccessPointPrivate *priv; + guint32 flags; - g_return_if_fail (NM_IS_AP (ap)); + g_return_val_if_fail (NM_IS_AP (ap), NM_802_11_AP_SEC_NONE); - priv = NM_AP_GET_PRIVATE (ap); + g_object_get (ap, NM_AP_RSN_FLAGS, &flags, NULL); - if (priv->security) - { - g_object_unref (G_OBJECT (priv->security)); - priv->security = NULL; - } - - if (security) - priv->security = nm_ap_security_new_copy (security); + return flags; } +void +nm_ap_set_rsn_flags (NMAccessPoint *ap, guint32 flags) +{ + g_return_if_fail (NM_IS_AP (ap)); + + g_object_set (ap, NM_AP_RSN_FLAGS, flags, NULL); +} + /* * Get/set functions for address * @@ -984,117 +1004,42 @@ gboolean nm_ap_has_manufacturer_default_ssid (NMAccessPoint *ap) return FALSE; } - -static guint32 add_capabilities_from_cipher (guint32 caps, int cipher) +guint32 +nm_ap_add_security_from_ie (guint32 flags, + const guint8 *wpa_ie, + guint32 length) { - if (cipher & IW_AUTH_CIPHER_WEP40) - { - caps |= NM_802_11_CAP_PROTO_WEP; - caps |= NM_802_11_CAP_CIPHER_WEP40; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - if (cipher & IW_AUTH_CIPHER_WEP104) - { - caps |= NM_802_11_CAP_PROTO_WEP; - caps |= NM_802_11_CAP_CIPHER_WEP104; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - if (cipher & IW_AUTH_CIPHER_TKIP) - { - caps |= NM_802_11_CAP_CIPHER_TKIP; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - if (cipher & IW_AUTH_CIPHER_CCMP) - { - caps |= NM_802_11_CAP_CIPHER_CCMP; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - - if (cipher == NM_AUTH_TYPE_WPA_PSK_AUTO) - { - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - - if (cipher == NM_AUTH_TYPE_WPA_EAP) - { - caps |= NM_802_11_CAP_KEY_MGMT_802_1X; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - if (cipher == NM_AUTH_TYPE_LEAP) - { - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - return caps; -} - -/* - * nm_ap_add_capabilities_from_cipher - * - * Update a given AP's capabilities via a wireless extension cipher integer - * - */ -void nm_ap_add_capabilities_from_security (NMAccessPoint *ap, NMAPSecurity *security) -{ - guint32 caps; - int cipher; - - g_return_if_fail (NM_IS_AP (ap)); - g_return_if_fail (security != NULL); - - cipher = nm_ap_security_get_we_cipher (security); - caps = nm_ap_get_capabilities (ap); - caps = add_capabilities_from_cipher (caps, cipher); - nm_ap_set_capabilities (ap, caps); -} - -void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length) -{ - wpa_ie_data * cap_data; - guint32 caps; - - g_return_if_fail (NM_IS_AP (ap)); + wpa_ie_data * cap_data; if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length))) - return; - - caps = nm_ap_get_capabilities (ap); - - /* Mark WEP as unsupported, if it's supported it will be added below */ - caps &= ~NM_802_11_CAP_PROTO_WEP; - - if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA) - { - caps |= NM_802_11_CAP_PROTO_WPA; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA2) - { - caps |= NM_802_11_CAP_PROTO_WPA2; - caps &= ~NM_802_11_CAP_PROTO_NONE; - } - - caps = add_capabilities_from_cipher (caps, cap_data->pairwise_cipher); - caps = add_capabilities_from_cipher (caps, cap_data->group_cipher); + return NM_802_11_AP_SEC_NONE; + + /* Pairwise cipher flags */ + if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_WEP40) + flags |= NM_802_11_AP_SEC_PAIR_WEP40; + if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_WEP104) + flags |= NM_802_11_AP_SEC_PAIR_WEP104; + if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_TKIP) + flags |= NM_802_11_AP_SEC_PAIR_TKIP; + if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_CCMP) + flags |= NM_802_11_AP_SEC_PAIR_CCMP; + + /* Group cipher flags */ + if (cap_data->group_cipher & IW_AUTH_CIPHER_WEP40) + flags |= NM_802_11_AP_SEC_GROUP_WEP40; + if (cap_data->group_cipher & IW_AUTH_CIPHER_WEP104) + flags |= NM_802_11_AP_SEC_GROUP_WEP104; + if (cap_data->group_cipher & IW_AUTH_CIPHER_TKIP) + flags |= NM_802_11_AP_SEC_GROUP_TKIP; + if (cap_data->group_cipher & IW_AUTH_CIPHER_CCMP) + flags |= NM_802_11_AP_SEC_GROUP_CCMP; if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_802_1X) - caps |= NM_802_11_CAP_KEY_MGMT_802_1X; + flags |= NM_802_11_AP_SEC_KEY_MGMT_802_1X; if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_PSK) - caps |= NM_802_11_CAP_KEY_MGMT_PSK; - - nm_ap_set_capabilities (ap, caps); + flags |= NM_802_11_AP_SEC_KEY_MGMT_PSK; g_slice_free (wpa_ie_data, cap_data); + return flags; } - -void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap) -{ - NMAccessPointPrivate *priv; - - g_return_if_fail (NM_IS_AP (ap)); - - priv = NM_AP_GET_PRIVATE (ap); - - priv->capabilities |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104); - priv->capabilities &= ~NM_802_11_CAP_PROTO_NONE; -} diff --git a/src/NetworkManagerAP.h b/src/NetworkManagerAP.h index 64fda566ff..10ce1fcb0d 100644 --- a/src/NetworkManagerAP.h +++ b/src/NetworkManagerAP.h @@ -27,7 +27,6 @@ #include <glib-object.h> #include <time.h> #include "NetworkManager.h" -#include "nm-ap-security.h" #define NM_TYPE_AP (nm_ap_get_type ()) #define NM_AP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP, NMAccessPoint)) @@ -36,8 +35,9 @@ #define NM_IS_AP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_AP)) #define NM_AP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP, NMAccessPointClass)) -#define NM_AP_CAPABILITIES "capabilities" -#define NM_AP_ENCRYPTED "encrypted" +#define NM_AP_FLAGS "flags" +#define NM_AP_WPA_FLAGS "wpa-flags" +#define NM_AP_RSN_FLAGS "rsn-flags" #define NM_AP_SSID "ssid" #define NM_AP_FREQUENCY "frequency" #define NM_AP_HW_ADDRESS "hw-address" @@ -70,13 +70,14 @@ void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *ti const GByteArray * nm_ap_get_ssid (const NMAccessPoint * ap); void nm_ap_set_ssid (NMAccessPoint * ap, const GByteArray * ssid); -guint32 nm_ap_get_capabilities (NMAccessPoint *ap); -void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities); +guint32 nm_ap_get_flags (NMAccessPoint *ap); +void nm_ap_set_flags (NMAccessPoint *ap, guint32 flags); -gboolean nm_ap_get_encrypted (NMAccessPoint *ap); +guint32 nm_ap_get_wpa_flags (NMAccessPoint *ap); +void nm_ap_set_wpa_flags (NMAccessPoint *ap, guint32 flags); -NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap); -void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security); +guint32 nm_ap_get_rsn_flags (NMAccessPoint *ap); +void nm_ap_set_rsn_flags (NMAccessPoint *ap, guint32 flags); const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap); void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); @@ -114,9 +115,9 @@ void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created); GSList * nm_ap_get_user_addresses (const NMAccessPoint *ap); void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list); -void nm_ap_add_capabilities_from_security (NMAccessPoint *ap, NMAPSecurity *security); -void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length); -void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap); +guint32 nm_ap_add_security_from_ie (guint32 flags, + const guint8 *wpa_ie, + guint32 length); void nm_ap_print_self (NMAccessPoint *ap, const char * prefix); diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index 8e431022b8..08b580ed2c 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -366,7 +366,9 @@ void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *sou if ((src_ap = nm_ap_list_get_ap_by_ssid (source, nm_ap_get_ssid (dest_ap)))) { nm_ap_set_invalid (dest_ap, nm_ap_get_invalid (src_ap)); - nm_ap_set_security (dest_ap, nm_ap_get_security (src_ap)); + nm_ap_set_flags (dest_ap, nm_ap_get_flags (src_ap)); + nm_ap_set_wpa_flags (dest_ap, nm_ap_get_wpa_flags (src_ap)); + nm_ap_set_rsn_flags (dest_ap, nm_ap_get_rsn_flags (src_ap)); nm_ap_set_timestamp_via_timestamp (dest_ap, nm_ap_get_timestamp (src_ap)); } } diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index ea409d0dd9..acb3642841 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -36,7 +36,6 @@ #include "NetworkManagerAP.h" #include "NetworkManagerAPList.h" #include "NetworkManagerPolicy.h" -#include "nm-dbus-nmi.h" #include "nm-utils.h" #include "nm-dhcp-manager.h" #include "nm-dbus-manager.h" @@ -111,8 +110,7 @@ nm_dbus_nmi_signal_handler (DBusConnection *connection, DBUS_TYPE_INVALID)) { /* Update a single wireless network's data */ nm_debug ("NetworkManagerInfo triggered update of wireless network '%s'", network); - nm_dbus_update_one_allowed_network (network, - (NMData *) g_object_get_data (G_OBJECT (manager), "NM_DATA_HACK")); + // FIXME: convert to connection update signal handled = TRUE; } } else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "UserInterfaceActivated")) { diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index bee8b19cef..ceafede873 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -35,11 +35,11 @@ #include "NetworkManagerDbus.h" #include "nm-activation-request.h" #include "nm-utils.h" -#include "nm-dbus-nmi.h" #include "nm-device-interface.h" #include "nm-device-802-11-wireless.h" #include "nm-device-802-3-ethernet.h" #include "nm-dbus-manager.h" +#include "nm-setting.h" struct NMPolicy { NMManager *manager; @@ -367,7 +367,7 @@ nm_policy_device_change_check (gpointer user_data) connection = create_connection (new_dev, ap); if (connection) nm_device_interface_activate (NM_DEVICE_INTERFACE (new_dev), - connection, FALSE); + connection, NULL, FALSE); } } @@ -399,11 +399,8 @@ nm_policy_allowed_ap_list_update (gpointer user_data) nm_info ("Updating allowed wireless network lists."); - /* Query info daemon for network lists if its now running */ - if (data->allowed_ap_list) - nm_ap_list_unref (data->allowed_ap_list); - if ((data->allowed_ap_list = nm_ap_list_new (NETWORK_TYPE_ALLOWED))) - nm_dbus_update_allowed_networks (data->allowed_ap_list, data); + // FIXME: convert to getting connections instead + return FALSE; } diff --git a/src/backends/NetworkManagerSuSE.c b/src/backends/NetworkManagerSuSE.c index 4f518a10b0..9423e6908a 100644 --- a/src/backends/NetworkManagerSuSE.c +++ b/src/backends/NetworkManagerSuSE.c @@ -38,17 +38,8 @@ #include "NetworkManagerUtils.h" #include "NetworkManagerMain.h" #include "nm-device.h" -#include "nm-ap-security.h" -#include "nm-ap-security-private.h" -#include "nm-ap-security-wep.h" -#include "nm-ap-security-wpa-psk.h" #include "NetworkManagerAPList.h" #include "NetworkManagerPolicy.h" -#include "cipher.h" -#include "cipher-wep-ascii.h" -#include "cipher-wep-hex.h" -#include "cipher-wep-passphrase.h" -#include "cipher-wpa-psk-passphrase.h" #include "nm-device-802-3-ethernet.h" #include "nm-device-802-11-wireless.h" #include "NetworkManagerDialup.h" @@ -387,144 +378,6 @@ found: free (buf); } - if ((buf = svGetValue (file, "WIRELESS_ESSID")) && strlen (buf) > 1) - { - NMAccessPoint * ap; - NMAccessPoint * list_ap; - char * key; - char * mode; - GByteArray * ssid; - - ap = nm_ap_new (); - - ssid = g_byte_array_sized_new (strlen (buf)); - g_byte_array_append (ssid, buf, strlen (buf)); - nm_ap_set_ssid (ap, ssid); - - nm_ap_set_timestamp (ap, time (NULL), 0); - nm_ap_set_fallback (ap, TRUE); - - if ((mode = svGetValue (file, "WIRELESS_AUTH_MODE")) && !strcmp (mode, "psk")) - { - if ((key = svGetValue (file, "WIRELESS_WPA_PSK"))) - { - IEEE_802_11_Cipher * cipher; - NMAPSecurityWPA_PSK * security; - char * hash; - - cipher = cipher_wpa_psk_passphrase_new (); - nm_ap_set_capabilities (ap, NM_802_11_CAP_PROTO_WPA); - security = nm_ap_security_wpa_psk_new (NM_802_11_CAP_PROTO_WPA, - NM_AUTH_TYPE_WPA_PSK_AUTO); - hash = ieee_802_11_cipher_hash (cipher, buf, key); - if (hash) - { - nm_ap_security_set_key (NM_AP_SECURITY (security), hash, strlen (hash)); - nm_ap_set_security (ap, NM_AP_SECURITY (security)); - } - - ieee_802_11_cipher_unref (cipher); - g_object_unref (G_OBJECT (security)); - } - } - else if ((key = svGetValue (file, "WIRELESS_KEY_0")) && strlen (key) > 3) - { - IEEE_802_11_Cipher * cipher; - NMAPSecurityWEP * security; - char * key_type; - char * hash; - char * real_key; - - key_type = svGetValue (file, "WIRELESS_KEY_LENGTH"); - if (key_type && strcmp (key_type, "128") != 0) - { - if (key[0] == 'h' && key[1] == ':') - { - cipher = cipher_wep64_passphrase_new (); - real_key = key + 2; - } - else if (key[0] == 's' && key[1] == ':') - { - cipher = cipher_wep64_ascii_new (); - real_key = key + 2; - } - else - { - cipher = cipher_wep64_hex_new (); - real_key = key; - } - security = nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP40); - } - else - { - if (key[0] == 'h' && key[1] == ':') - { - cipher = cipher_wep128_passphrase_new (); - real_key = key + 2; - } - else if (key[0] == 's' && key[1] == ':') - { - cipher = cipher_wep128_ascii_new (); - real_key = key + 2; - } - else - { - char **keyv; - - cipher = cipher_wep128_hex_new (); - - keyv = g_strsplit (key, "-", 0); - real_key = g_strjoinv (NULL, keyv); - g_strfreev (keyv); - } - security = nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP104); - } - hash = ieee_802_11_cipher_hash (cipher, buf, real_key); - if (hash) - { - nm_ap_security_set_key (NM_AP_SECURITY (security), hash, strlen (hash)); - nm_ap_set_security (ap, NM_AP_SECURITY (security)); - } - - ieee_802_11_cipher_unref (cipher); - g_object_unref (G_OBJECT (security)); - - free (key_type); - } - else - { - NMAPSecurity * security; - - security = nm_ap_security_new (NM_DEVICE_CAP_NONE, FALSE); - nm_ap_set_security (ap, security); - g_object_unref (G_OBJECT (security)); - } - - if ((list_ap = nm_ap_list_get_ap_by_ssid (app_data->allowed_ap_list, ssid))) - { - nm_ap_set_ssid (list_ap, nm_ap_get_ssid (ap)); - nm_ap_set_timestamp_via_timestamp (list_ap, nm_ap_get_timestamp (ap)); - nm_ap_set_fallback (list_ap, TRUE); - nm_ap_set_security (list_ap, nm_ap_get_security (ap)); - } - else - { - /* New AP, just add it to the list */ - nm_ap_list_append_ap (app_data->allowed_ap_list, ap); - } - g_byte_array_free (ssid, TRUE); - g_object_unref (ap); - - nm_debug ("Adding '%s' to the list of trusted networks", buf); - - /* Ensure all devices get new information copied into their device lists */ - nm_policy_schedule_device_ap_lists_update_from_allowed (app_data); - - free (key); - free (mode); - free (buf); - } - sys_data->config = nm_ip4_config_new (); if (!sys_data->use_dhcp || sys_data->system_disabled) diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index 70989e5922..fe996e426b 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -28,6 +28,7 @@ G_DEFINE_TYPE (NMActRequest, nm_act_request, G_TYPE_OBJECT) typedef struct { NMConnection *connection; + char *specific_object; gboolean user_requested; } NMActRequestPrivate; @@ -43,6 +44,8 @@ finalize (GObject *object) nm_connection_destroy (priv->connection); + g_free (priv->specific_object); + G_OBJECT_CLASS (nm_act_request_parent_class)->finalize (object); } @@ -57,7 +60,9 @@ nm_act_request_class_init (NMActRequestClass *req_class) } NMActRequest * -nm_act_request_new (NMConnection *connection, gboolean user_requested) +nm_act_request_new (NMConnection *connection, + const char *specific_object, + gboolean user_requested) { GObject *obj; NMActRequestPrivate *priv; @@ -72,6 +77,8 @@ nm_act_request_new (NMConnection *connection, gboolean user_requested) priv->connection = connection; priv->user_requested = user_requested; + if (specific_object) + priv->specific_object = g_strdup (specific_object); return NM_ACT_REQUEST (obj); } @@ -84,6 +91,14 @@ nm_act_request_get_connection (NMActRequest *req) return NM_ACT_REQUEST_GET_PRIVATE (req)->connection; } +const char * +nm_act_request_get_specific_object (NMActRequest *req) +{ + g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL); + + return NM_ACT_REQUEST_GET_PRIVATE (req)->specific_object; +} + gboolean nm_act_request_get_user_requested (NMActRequest *req) { diff --git a/src/nm-activation-request.h b/src/nm-activation-request.h index 06d36fb191..6c498b88b7 100644 --- a/src/nm-activation-request.h +++ b/src/nm-activation-request.h @@ -44,9 +44,11 @@ typedef struct { GType nm_act_request_get_type (void); NMActRequest *nm_act_request_new (NMConnection *connection, - gboolean user_requested); + const char *specific_object, + gboolean user_requested); NMConnection *nm_act_request_get_connection (NMActRequest *req); +const char * nm_act_request_get_specific_object(NMActRequest *req); gboolean nm_act_request_get_user_requested (NMActRequest *req); #endif /* NM_ACTIVATION_REQUEST_H */ diff --git a/src/nm-ap-security-leap.c b/src/nm-ap-security-leap.c deleted file mode 100644 index f9636381b2..0000000000 --- a/src/nm-ap-security-leap.c +++ /dev/null @@ -1,212 +0,0 @@ -/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2006 Thiago Jung Bauermann <thiago.bauermann@gmail.com> - */ - -/* This file is heavily based on nm-ap-security-wpa-eap.c */ - -#include <glib.h> -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <iwlib.h> - -#include "nm-ap-security.h" -#include "nm-ap-security-leap.h" -#include "nm-ap-security-private.h" -#include "dbus-helpers.h" -#include "nm-device-802-11-wireless.h" -#include "nm-supplicant-config.h" - -#define NM_AP_SECURITY_LEAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAPPrivate)) - -struct _NMAPSecurityLEAPPrivate -{ - char * username; - char * key_mgmt; -}; - - -NMAPSecurityLEAP * -nm_ap_security_leap_new_deserialize (DBusMessageIter *iter) -{ - NMAPSecurityLEAP * security = NULL; - char * username = NULL; - char * password = NULL; - char * key_mgmt = NULL; - - g_return_val_if_fail (iter != NULL, NULL); - - if (!nmu_security_deserialize_leap (iter, &username, &password, &key_mgmt)) - goto out; - - /* Success, build up our security object */ - security = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_LEAP); - if (password) - nm_ap_security_set_key (NM_AP_SECURITY (security), password, strlen(password)); - if (username) - security->priv->username = g_strdup (username); - if (key_mgmt) - security->priv->key_mgmt = g_strdup (key_mgmt); - - nm_ap_security_set_description (NM_AP_SECURITY (security), _("LEAP")); - -out: - return security; -} - - -NMAPSecurityLEAP * -nm_ap_security_leap_new (void) -{ - NMAPSecurityLEAP *security; - - security = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_LEAP); - nm_ap_security_set_description (NM_AP_SECURITY (security), _("LEAP")); - - return security; -} - - -static int -real_serialize (NMAPSecurity *instance, DBusMessageIter *iter) -{ - NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance); - - if (!nmu_security_serialize_leap (iter, self->priv->username, - nm_ap_security_get_key(instance), self->priv->key_mgmt)) - return -1; - return 0; -} - -static gboolean -real_write_supplicant_config (NMAPSecurity *instance, - NMSupplicantConfig * config, - gboolean user_created) -{ - NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance); - gboolean success = FALSE; - const char * password = nm_ap_security_get_key (instance); - - g_return_val_if_fail (nm_ap_security_get_we_cipher (instance) == NM_AUTH_TYPE_LEAP, FALSE); - - if (!nm_supplicant_config_add_option (config, "proto", "WPA", -1)) - goto out; - - if (!nm_supplicant_config_add_option (config, "key_mgmt", self->priv->key_mgmt, -1)) - goto out; - - if (!nm_supplicant_config_add_option (config, "eap", "LEAP", -1)) - goto out; - - if (self->priv->username && strlen (self->priv->username) > 0) { - if (!nm_supplicant_config_add_option (config, "identity", self->priv->username, -1)) - goto out; - } - - if (password && strlen (password) > 0) { - if (!nm_supplicant_config_add_option (config, "password", password, -1)) - goto out; - } - - success = TRUE; - -out: - return success; -} - -static guint32 -real_get_default_capabilities (NMAPSecurity *instance) -{ - guint32 caps = NM_802_11_CAP_NONE; - - caps |= NM_802_11_CAP_KEY_MGMT_802_1X; - - return caps; -} - -static gboolean -real_get_authentication_required (NMAPSecurity *instance) -{ - /* LEAP always requires authentication. */ - return TRUE; -} - -static NMAPSecurity * -real_copy_constructor (NMAPSecurity *instance) -{ - NMAPSecurityLEAP * dst = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL); - NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance); - - dst->priv->username = self->priv->username; - dst->priv->key_mgmt = self->priv->key_mgmt; - - nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst)); - - return NM_AP_SECURITY (dst); -} - - -static void -nm_ap_security_leap_init (NMAPSecurityLEAP * self) -{ - self->priv = NM_AP_SECURITY_LEAP_GET_PRIVATE (self); - self->priv->username = NULL; - self->priv->key_mgmt = NULL; -} - - -static void -nm_ap_security_leap_class_init (NMAPSecurityLEAPClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass); - - par_class->copy_constructor_func = real_copy_constructor; - par_class->serialize_func = real_serialize; - par_class->write_supplicant_config_func = real_write_supplicant_config; - par_class->get_default_capabilities_func = real_get_default_capabilities; - par_class->get_authentication_required_func = real_get_authentication_required; - - g_type_class_add_private (object_class, sizeof (NMAPSecurityLEAPPrivate)); -} - - -GType -nm_ap_security_leap_get_type (void) -{ - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (NMAPSecurityLEAPClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) nm_ap_security_leap_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (NMAPSecurityLEAP), - 0, /* n_preallocs */ - (GInstanceInitFunc) nm_ap_security_leap_init, - NULL /* value_table */ - }; - type = g_type_register_static (NM_TYPE_AP_SECURITY, - "NMAPSecurityLEAP", - &info, 0); - } - return type; -} diff --git a/src/nm-ap-security-leap.h b/src/nm-ap-security-leap.h deleted file mode 100644 index 4e5ebd12fa..0000000000 --- a/src/nm-ap-security-leap.h +++ /dev/null @@ -1,59 +0,0 @@ -/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2006 Thiago Jung Bauermann <thiago.bauermann@gmail.com> - */ - -/* This file is heavily based on nm-ap-security-wpa-eap.h */ - -#ifndef NM_AP_SECURITY_LEAP_H -#define NM_AP_SECURITY_LEAP_H - -#include <glib-object.h> -#include <dbus/dbus.h> -#include "nm-ap-security.h" - -#define NM_TYPE_AP_SECURITY_LEAP (nm_ap_security_leap_get_type ()) -#define NM_AP_SECURITY_LEAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAP)) -#define NM_AP_SECURITY_LEAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAPClass)) -#define NM_IS_AP_SECURITY_LEAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP_SECURITY_LEAP)) -#define NM_IS_AP_SECURITY_LEAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_AP_SECURITY_LEAP)) -#define NM_AP_SECURITY_LEAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAPClass)) - -typedef struct _NMAPSecurityLEAP NMAPSecurityLEAP; -typedef struct _NMAPSecurityLEAPClass NMAPSecurityLEAPClass; -typedef struct _NMAPSecurityLEAPPrivate NMAPSecurityLEAPPrivate; - -struct _NMAPSecurityLEAP -{ - NMAPSecurity parent; - - /*< private >*/ - NMAPSecurityLEAPPrivate *priv; -}; - -struct _NMAPSecurityLEAPClass -{ - NMAPSecurityClass parent; -}; - - -GType nm_ap_security_leap_get_type (void); - -NMAPSecurityLEAP * nm_ap_security_leap_new_deserialize (DBusMessageIter *iter); -NMAPSecurityLEAP * nm_ap_security_leap_new (void); - -#endif /* NM_AP_SECURITY_LEAP_H */ diff --git a/src/nm-ap-security-private.h b/src/nm-ap-security-private.h deleted file mode 100644 index 13b1d70840..0000000000 --- a/src/nm-ap-security-private.h +++ /dev/null @@ -1,35 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_AP_SECURITY_PRIVATE_H -#define NM_AP_SECURITY_PRIVATE_H - -#include "nm-ap-security.h" - -void nm_ap_security_set_we_cipher (NMAPSecurity *self, int we_cipher); - -void nm_ap_security_set_key (NMAPSecurity *self, const char *key, int key_len); - -void nm_ap_security_set_description (NMAPSecurity *self, const char *desc); - -void nm_ap_security_copy_properties (NMAPSecurity *self, NMAPSecurity *dst); - -#endif /* NM_AP_SECURITY_PRIVATE_H */ diff --git a/src/nm-ap-security-wep.c b/src/nm-ap-security-wep.c deleted file mode 100644 index 30f5a0385b..0000000000 --- a/src/nm-ap-security-wep.c +++ /dev/null @@ -1,237 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include <glib.h> -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <iwlib.h> - -#include "nm-ap-security.h" -#include "nm-ap-security-wep.h" -#include "nm-ap-security-private.h" -#include "dbus-helpers.h" -#include "nm-device-802-11-wireless.h" -#include "nm-utils.h" -#include "nm-supplicant-config.h" - -#define NM_AP_SECURITY_WEP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPPrivate)) - -struct _NMAPSecurityWEPPrivate -{ - int auth_algorithm; -}; - -static int get_auth_algorithm (NMAPSecurityWEP *security) -{ - return security->priv->auth_algorithm; -} - -static void set_description (NMAPSecurityWEP *security) -{ - NMAPSecurity * parent = NM_AP_SECURITY (security); - - if (nm_ap_security_get_we_cipher (parent) == IW_AUTH_CIPHER_WEP40) - nm_ap_security_set_description (parent, _("40-bit WEP")); - else - nm_ap_security_set_description (parent, _("104-bit WEP")); - -} - -NMAPSecurityWEP * -nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher) -{ - NMAPSecurityWEP * security = NULL; - char * key = NULL; - int key_len; - int auth_algorithm; - - g_return_val_if_fail (iter != NULL, NULL); - g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL); - - if (!nmu_security_deserialize_wep (iter, &key, &key_len, &auth_algorithm)) - goto out; - - /* Success, build up our security object */ - security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher); - if (key) - nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len); - security->priv->auth_algorithm = auth_algorithm; - - set_description (security); - -out: - return security; -} - -NMAPSecurityWEP * -nm_ap_security_wep_new (int we_cipher) -{ - NMAPSecurityWEP *security; - - g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL); - - security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher); - security->priv->auth_algorithm = IW_AUTH_ALG_OPEN_SYSTEM; - - set_description (security); - - return security; -} - -static int -real_serialize (NMAPSecurity *instance, DBusMessageIter *iter) -{ - NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance); - - if (!nmu_security_serialize_wep (iter, - nm_ap_security_get_key (instance), - self->priv->auth_algorithm)) - return -1; - return 0; -} - -static gboolean -real_write_supplicant_config (NMAPSecurity *instance, - NMSupplicantConfig * config, - gboolean adhoc) -{ - gboolean success = FALSE; - const char * key = nm_ap_security_get_key (instance); - char * bin_key = NULL; - - /* WEP network setup */ - if (!nm_supplicant_config_add_option (config, "key_mgmt", "NONE", -1)) - goto out; - - /* - * If the user selected "Shared" (aka restricted) key, set it explicitly. Otherwise, - * let wpa_supplicant default to the right thing, which is an open key. - */ - if (get_auth_algorithm (NM_AP_SECURITY_WEP (instance)) == IW_AUTH_ALG_SHARED_KEY) { - if (!nm_supplicant_config_add_option (config, "auth_alg", "SHARED", -1)) - goto out; - } - - bin_key = cipher_hexstr2bin(key, strlen (key)); - if (bin_key == NULL) { - nm_warning ("Not enough memory to convert key."); - goto out; - } - - if (!nm_supplicant_config_add_option (config, "wep_key0", bin_key, -1)) { - g_free (bin_key); - goto out; - } - g_free (bin_key); - - if (!nm_supplicant_config_add_option (config, "wep_tx_keyidx", "0", -1)) - goto out; - - success = TRUE; - -out: - return success; -} - -static guint32 -real_get_default_capabilities (NMAPSecurity *instance) -{ - guint32 caps = NM_802_11_CAP_NONE; - - switch (nm_ap_security_get_we_cipher (instance)) - { - case IW_AUTH_CIPHER_WEP40: - caps |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40); - break; - case IW_AUTH_CIPHER_WEP104: - caps |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104); - break; - default: - break; - } - return caps; -} - -static gboolean -real_get_authentication_required (NMAPSecurity *instance) -{ - /* WEP really requires authentication in Shared mode only */ - return (get_auth_algorithm (NM_AP_SECURITY_WEP (instance)) == IW_AUTH_ALG_SHARED_KEY); -} - -static NMAPSecurity * -real_copy_constructor (NMAPSecurity *instance) -{ - NMAPSecurityWEP * dst = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL); - NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance); - - dst->priv->auth_algorithm = self->priv->auth_algorithm; - nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst)); - return NM_AP_SECURITY (dst); -} - -static void -nm_ap_security_wep_init (NMAPSecurityWEP * self) -{ - self->priv = NM_AP_SECURITY_WEP_GET_PRIVATE (self); - self->priv->auth_algorithm = IW_AUTH_ALG_OPEN_SYSTEM; -} - -static void -nm_ap_security_wep_class_init (NMAPSecurityWEPClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass); - - par_class->copy_constructor_func = real_copy_constructor; - par_class->serialize_func = real_serialize; - par_class->write_supplicant_config_func = real_write_supplicant_config; - par_class->get_default_capabilities_func = real_get_default_capabilities; - par_class->get_authentication_required_func = real_get_authentication_required; - - g_type_class_add_private (object_class, sizeof (NMAPSecurityWEPPrivate)); -} - -GType -nm_ap_security_wep_get_type (void) -{ - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (NMAPSecurityWEPClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) nm_ap_security_wep_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (NMAPSecurityWEP), - 0, /* n_preallocs */ - (GInstanceInitFunc) nm_ap_security_wep_init, - NULL /* value_table */ - }; - type = g_type_register_static (NM_TYPE_AP_SECURITY, - "NMAPSecurityWEP", - &info, 0); - } - return type; -} diff --git a/src/nm-ap-security-wep.h b/src/nm-ap-security-wep.h deleted file mode 100644 index a0b103a799..0000000000 --- a/src/nm-ap-security-wep.h +++ /dev/null @@ -1,59 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_AP_SECURITY_WEP_H -#define NM_AP_SECURITY_WEP_H - -#include <glib-object.h> -#include <dbus/dbus.h> -#include "nm-ap-security.h" - -#define NM_TYPE_AP_SECURITY_WEP (nm_ap_security_wep_get_type ()) -#define NM_AP_SECURITY_WEP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEP)) -#define NM_AP_SECURITY_WEP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPClass)) -#define NM_IS_AP_SECURITY_WEP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP_SECURITY_WEP)) -#define NM_IS_AP_SECURITY_WEP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_AP_SECURITY_WEP)) -#define NM_AP_SECURITY_WEP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPClass)) - -typedef struct _NMAPSecurityWEP NMAPSecurityWEP; -typedef struct _NMAPSecurityWEPClass NMAPSecurityWEPClass; -typedef struct _NMAPSecurityWEPPrivate NMAPSecurityWEPPrivate; - -struct _NMAPSecurityWEP -{ - NMAPSecurity parent; - - /*< private >*/ - NMAPSecurityWEPPrivate *priv; -}; - -struct _NMAPSecurityWEPClass -{ - NMAPSecurityClass parent; -}; - - -GType nm_ap_security_wep_get_type (void); - -NMAPSecurityWEP * nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher); -NMAPSecurityWEP * nm_ap_security_wep_new (int we_cipher); - -#endif /* NM_AP_SECURITY_WEP_H */ diff --git a/src/nm-ap-security-wpa-eap.c b/src/nm-ap-security-wpa-eap.c deleted file mode 100644 index 2d5174ff2f..0000000000 --- a/src/nm-ap-security-wpa-eap.c +++ /dev/null @@ -1,385 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - * (C) Copyright 2006 Novell, Inc. - */ - -#include <glib.h> -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <iwlib.h> - -#include "nm-ap-security.h" -#include "nm-ap-security-wpa-eap.h" -#include "nm-ap-security-private.h" -#include "dbus-helpers.h" -#include "nm-device-802-11-wireless.h" -#include "nm-supplicant-config.h" - -#define NM_AP_SECURITY_WPA_EAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WPA_EAP, NMAPSecurityWPA_EAPPrivate)) - -struct _NMAPSecurityWPA_EAPPrivate -{ - int eap_method; - int key_type; - int wpa_version; - int key_mgmt; - char * identity; - char * passwd; - char * anon_identity; - char * private_key_passwd; - char * private_key_file; - char * client_cert_file; - char * ca_cert_file; -}; - - -NMAPSecurityWPA_EAP * -nm_ap_security_wpa_eap_new_deserialize (DBusMessageIter *iter) -{ - NMAPSecurityWPA_EAP * security = NULL; - int eap_method; - int key_type; - int wpa_version; - char * identity = NULL; - char * passwd = NULL; - char * anon_identity = NULL; - char * private_key_passwd = NULL; - char * private_key_file = NULL; - char * client_cert_file = NULL; - char * ca_cert_file = NULL; - - g_return_val_if_fail (iter != NULL, NULL); - - if (!nmu_security_deserialize_wpa_eap (iter, &eap_method, &key_type, &identity, &passwd, - &anon_identity, &private_key_passwd, &private_key_file, - &client_cert_file, &ca_cert_file, &wpa_version)) - goto out; - - /* Success, build up our security object */ - security = g_object_new (NM_TYPE_AP_SECURITY_WPA_EAP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_WPA_EAP); - if ((private_key_passwd && strlen (private_key_passwd) > 0) || (passwd && strlen (passwd) > 0)) - nm_ap_security_set_key (NM_AP_SECURITY (security), "FIXME", 5); - security->priv->eap_method = eap_method; - security->priv->key_type = key_type; - security->priv->wpa_version = wpa_version; - security->priv->key_mgmt = IW_AUTH_KEY_MGMT_802_1X; - security->priv->identity = g_strdup (identity); - security->priv->passwd = g_strdup (passwd); - security->priv->anon_identity = g_strdup (anon_identity); - security->priv->private_key_passwd = g_strdup (private_key_passwd); - security->priv->private_key_file = g_strdup (private_key_file); - security->priv->client_cert_file = g_strdup (client_cert_file); - security->priv->ca_cert_file = g_strdup (ca_cert_file); - - if (wpa_version == IW_AUTH_WPA_VERSION_WPA2) - nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA2 Enterprise")); - else - nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA Enterprise")); - -out: - return security; -} - - -NMAPSecurityWPA_EAP * -nm_ap_security_wpa_eap_new (guint32 capabilities) -{ - NMAPSecurityWPA_EAP *security; - - security = g_object_new (NM_TYPE_AP_SECURITY_WPA_EAP, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_WPA_EAP); - - if (capabilities & NM_802_11_CAP_PROTO_WPA2) { - security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA2; - nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA2 Enterprise")); - } else { - security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; - nm_ap_security_set_description (NM_AP_SECURITY (security), _("WPA Enterprise")); - } - - return security; -} - - -static int -real_serialize (NMAPSecurity *instance, DBusMessageIter *iter) -{ - NMAPSecurityWPA_EAP * self = NM_AP_SECURITY_WPA_EAP (instance); - - if (!nmu_security_serialize_wpa_eap (iter, - self->priv->eap_method, - self->priv->key_type, - self->priv->identity ? : "", - self->priv->passwd ? : "", - self->priv->anon_identity ? : "", - self->priv->private_key_passwd ? : "", - self->priv->private_key_file ? : "", - self->priv->client_cert_file ? : "", - self->priv->ca_cert_file ? : "", - self->priv->wpa_version)) - return -1; - return 0; -} - - -static const char * -get_eap_method (int eap_method) -{ - switch (eap_method) - { - case NM_EAP_METHOD_PEAP: - return "PEAP"; - case NM_EAP_METHOD_TLS: - return "TLS"; - case NM_EAP_METHOD_TTLS: - return "TTLS"; - default: - g_warning ("Unmatched eap_method=%d!", eap_method); - return "TLS"; - } -} - - -static gboolean -real_write_supplicant_config (NMAPSecurity *instance, - NMSupplicantConfig * config, - gboolean adhoc) -{ - NMAPSecurityWPA_EAP * self = NM_AP_SECURITY_WPA_EAP (instance); - gboolean success = FALSE; - const char * identity = self->priv->identity; - const char * anon_identity = self->priv->anon_identity; - const char * passwd = self->priv->passwd; - const char * private_key_passwd = self->priv->private_key_passwd; - const char * private_key_file = self->priv->private_key_file; - const char * ca_cert_file = self->priv->ca_cert_file; - const char * client_cert_file = self->priv->client_cert_file; - int wpa_version = self->priv->wpa_version; - int key_mgmt = self->priv->key_mgmt; - int eap_method = self->priv->eap_method; - int key_type = self->priv->key_type; - - g_return_val_if_fail (nm_ap_security_get_we_cipher (instance) == NM_AUTH_TYPE_WPA_EAP, FALSE); - g_return_val_if_fail (key_mgmt == IW_AUTH_KEY_MGMT_802_1X, FALSE); - g_return_val_if_fail (wpa_version == IW_AUTH_WPA_VERSION_WPA - || wpa_version == IW_AUTH_WPA_VERSION_WPA2, FALSE); - g_return_val_if_fail (eap_method == NM_EAP_METHOD_MD5 - || eap_method == NM_EAP_METHOD_MSCHAP - || eap_method == NM_EAP_METHOD_OTP - || eap_method == NM_EAP_METHOD_GTC - || eap_method == NM_EAP_METHOD_PEAP - || eap_method == NM_EAP_METHOD_TLS - || eap_method == NM_EAP_METHOD_TTLS, FALSE); - g_return_val_if_fail ((key_type == NM_AUTH_TYPE_WPA_PSK_AUTO) - || (key_type == IW_AUTH_CIPHER_CCMP) - || (key_type == IW_AUTH_CIPHER_TKIP) - || (key_type == IW_AUTH_CIPHER_WEP104), FALSE); - - /* WPA-EAP network setup */ - - if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA) { - if (!nm_supplicant_config_add_option (config, "proto", "WPA", -1)) - goto out; - } else { - if (!nm_supplicant_config_add_option (config, "proto", "WPA2", -1)) - goto out; - } - - if (key_type != IW_AUTH_CIPHER_WEP104) { - if (!nm_supplicant_config_add_option (config, "key_mgmt", "WPA-EAP", -1)) - goto out; - } else { - /* So-called Dynamic WEP */ - if (!nm_supplicant_config_add_option (config, "key_mgmt", "IEEE8021X", -1)) - goto out; - } - - if (!nm_supplicant_config_add_option (config, "eap", get_eap_method (eap_method), -1)) - goto out; - - if (identity && strlen (identity) > 0) { - if (!nm_supplicant_config_add_option (config, "identity", identity, -1)) - goto out; - } - - if (passwd && strlen (passwd) > 0) { - if (!nm_supplicant_config_add_option (config, "password", passwd, -1)) - goto out; - } - - if (anon_identity && strlen (anon_identity) > 0) { - if (!nm_supplicant_config_add_option (config, "anonymous_identity", anon_identity, -1)) - goto out; - } - - if (private_key_file && strlen (private_key_file) > 0) { - if (!nm_supplicant_config_add_option (config, "private_key", private_key_file, -1)) - goto out; - } - - if (private_key_passwd && strlen (private_key_passwd) > 0) { - if (!nm_supplicant_config_add_option (config, "private_key_passwd", private_key_passwd, -1)) - goto out; - } - - if (client_cert_file && strlen (client_cert_file) > 0) { - if (!nm_supplicant_config_add_option (config, "client_cert", client_cert_file, -1)) - goto out; - } - - if (ca_cert_file && strlen (ca_cert_file) > 0) { - if (!nm_supplicant_config_add_option (config, "ca_cert", ca_cert_file, -1)) - goto out; - } - - /* - * Set the pairwise and group cipher, if the user provided one. If user selected "Automatic", we - * let wpa_supplicant sort it out. Likewise, if the user selected "Dynamic WEP", we do nothing. - */ - if (key_type != NM_AUTH_TYPE_WPA_PSK_AUTO && key_type != IW_AUTH_CIPHER_WEP104) { - const char *cipher; - - /* - * FIXME: Technically, the pairwise cipher does not need to be the same as - * the group cipher. Fixing this requires changes in the UI. - */ - if (key_type == IW_AUTH_CIPHER_TKIP) - cipher = "TKIP"; - else /* IW_AUTH_CIPHER_CCMP */ - cipher = "CCMP"; - - if (!nm_supplicant_config_add_option (config, "pairwise", cipher, -1)) - goto out; - - if (!nm_supplicant_config_add_option (config, "group", cipher, -1)) - goto out; - } - - success = TRUE; - -out: - return success; -} - -static guint32 -real_get_default_capabilities (NMAPSecurity *instance) -{ - NMAPSecurityWPA_EAP *self = NM_AP_SECURITY_WPA_EAP (instance); - guint32 caps = NM_802_11_CAP_NONE; - - if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA) - caps |= NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_TKIP; - else if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA2) - caps |= NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_CCMP; - - if (self->priv->key_mgmt == IW_AUTH_KEY_MGMT_802_1X) - caps |= NM_802_11_CAP_KEY_MGMT_802_1X; - - return caps; -} - -static gboolean -real_get_authentication_required (NMAPSecurity *instance) -{ - /* WPA Enterprise is all about strong security */ - return TRUE; -} - -static NMAPSecurity * -real_copy_constructor (NMAPSecurity *instance) -{ - NMAPSecurityWPA_EAP * dst = g_object_new (NM_TYPE_AP_SECURITY_WPA_EAP, NULL); - NMAPSecurityWPA_EAP * self = NM_AP_SECURITY_WPA_EAP (instance); - - dst->priv->eap_method = self->priv->eap_method; - dst->priv->key_type = self->priv->key_type; - dst->priv->wpa_version = self->priv->wpa_version; - dst->priv->key_mgmt = self->priv->key_mgmt; - dst->priv->identity = g_strdup (self->priv->identity); - dst->priv->passwd = g_strdup (self->priv->passwd); - dst->priv->anon_identity = g_strdup (self->priv->anon_identity); - dst->priv->private_key_passwd = g_strdup (self->priv->private_key_passwd); - dst->priv->private_key_file = g_strdup (self->priv->private_key_file); - dst->priv->client_cert_file = g_strdup (self->priv->client_cert_file); - dst->priv->ca_cert_file = g_strdup (self->priv->ca_cert_file); - - nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst)); - - return NM_AP_SECURITY (dst); -} - - -static void -nm_ap_security_wpa_eap_init (NMAPSecurityWPA_EAP * self) -{ - self->priv = NM_AP_SECURITY_WPA_EAP_GET_PRIVATE (self); - self->priv->eap_method = NM_EAP_METHOD_TLS; - self->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; - self->priv->key_mgmt = IW_AUTH_KEY_MGMT_802_1X; - self->priv->identity = NULL; - self->priv->passwd = NULL; - self->priv->anon_identity = NULL; - self->priv->private_key_passwd = NULL; - self->priv->private_key_file = NULL; - self->priv->client_cert_file = NULL; - self->priv->ca_cert_file = NULL; -} - - -static void -nm_ap_security_wpa_eap_class_init (NMAPSecurityWPA_EAPClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass); - - par_class->copy_constructor_func = real_copy_constructor; - par_class->serialize_func = real_serialize; - par_class->write_supplicant_config_func = real_write_supplicant_config; - par_class->get_default_capabilities_func = real_get_default_capabilities; - par_class->get_authentication_required_func = real_get_authentication_required; - - g_type_class_add_private (object_class, sizeof (NMAPSecurityWPA_EAPPrivate)); -} - - -GType -nm_ap_security_wpa_eap_get_type (void) -{ - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (NMAPSecurityWPA_EAPClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) nm_ap_security_wpa_eap_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (NMAPSecurityWPA_EAP), - 0, /* n_preallocs */ - (GInstanceInitFunc) nm_ap_security_wpa_eap_init, - NULL /* value_table */ - }; - type = g_type_register_static (NM_TYPE_AP_SECURITY, - "NMAPSecurityWPA_EAP", - &info, 0); - } - return type; -} diff --git a/src/nm-ap-security-wpa-eap.h b/src/nm-ap-security-wpa-eap.h deleted file mode 100644 index 8b8606f3ec..0000000000 --- a/src/nm-ap-security-wpa-eap.h +++ /dev/null @@ -1,60 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - * (C) Copyright 2006 Novell, Inc. - */ - -#ifndef NM_AP_SECURITY_WPA_EAP_H -#define NM_AP_SECURITY_WPA_EAP_H - -#include <glib-object.h> -#include <dbus/dbus.h> -#include "nm-ap-security.h" - -#define NM_TYPE_AP_SECURITY_WPA_EAP (nm_ap_security_wpa_eap_get_type ()) -#define NM_AP_SECURITY_WPA_EAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP_SECURITY_WPA_EAP, NMAPSecurityWPA_EAP)) -#define NM_AP_SECURITY_WPA_EAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP_SECURITY_WPA_EAP, NMAPSecurityWPA_EAPClass)) -#define NM_IS_AP_SECURITY_WPA_EAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP_SECURITY_WPA_EAP)) -#define NM_IS_AP_SECURITY_WPA_EAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_AP_SECURITY_WPA_EAP)) -#define NM_AP_SECURITY_WPA_EAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP_SECURITY_WPA_EAP, NMAPSecurityWPA_EAPClass)) - -typedef struct _NMAPSecurityWPA_EAP NMAPSecurityWPA_EAP; -typedef struct _NMAPSecurityWPA_EAPClass NMAPSecurityWPA_EAPClass; -typedef struct _NMAPSecurityWPA_EAPPrivate NMAPSecurityWPA_EAPPrivate; - -struct _NMAPSecurityWPA_EAP -{ - NMAPSecurity parent; - - /*< private >*/ - NMAPSecurityWPA_EAPPrivate *priv; -}; - -struct _NMAPSecurityWPA_EAPClass -{ - NMAPSecurityClass parent; -}; - - -GType nm_ap_security_wpa_eap_get_type (void); - -NMAPSecurityWPA_EAP * nm_ap_security_wpa_eap_new_deserialize (DBusMessageIter *iter); -NMAPSecurityWPA_EAP * nm_ap_security_wpa_eap_new (guint32 capabilities); - -#endif /* NM_AP_SECURITY_WPA_EAP_H */ diff --git a/src/nm-ap-security-wpa-psk.c b/src/nm-ap-security-wpa-psk.c deleted file mode 100644 index 1c6e5092bc..0000000000 --- a/src/nm-ap-security-wpa-psk.c +++ /dev/null @@ -1,292 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include <glib.h> -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <iwlib.h> - -#include "nm-ap-security.h" -#include "nm-ap-security-wpa-psk.h" -#include "nm-ap-security-private.h" -#include "dbus-helpers.h" -#include "nm-device-802-11-wireless.h" -#include "nm-supplicant-config.h" -#include "nm-utils.h" - -#define NM_AP_SECURITY_WPA_PSK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSKPrivate)) - -struct _NMAPSecurityWPA_PSKPrivate -{ - int wpa_version; - int key_mgt; -}; - -static void set_description (NMAPSecurityWPA_PSK *security) -{ - NMAPSecurity * parent = NM_AP_SECURITY (security); - int we_cipher = nm_ap_security_get_we_cipher (parent); - - if (security->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA) - { - if (we_cipher == IW_AUTH_CIPHER_TKIP) - nm_ap_security_set_description (parent, _("WPA TKIP")); - else if (we_cipher == IW_AUTH_CIPHER_CCMP) - nm_ap_security_set_description (parent, _("WPA CCMP")); - else - nm_ap_security_set_description (parent, _("WPA Automatic")); - } - else if (security->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA2) - { - if (we_cipher == IW_AUTH_CIPHER_TKIP) - nm_ap_security_set_description (parent, _("WPA2 TKIP")); - else if (we_cipher == IW_AUTH_CIPHER_CCMP) - nm_ap_security_set_description (parent, _("WPA2 CCMP")); - else - nm_ap_security_set_description (parent, _("WPA2 Automatic")); - } -} - -NMAPSecurityWPA_PSK * -nm_ap_security_wpa_psk_new_deserialize (DBusMessageIter *iter, int we_cipher) -{ - NMAPSecurityWPA_PSK * security = NULL; - char * key = NULL; - int key_len; - int wpa_version; - int key_mgt; - - g_return_val_if_fail (iter != NULL, NULL); - g_return_val_if_fail (we_cipher == NM_AUTH_TYPE_WPA_PSK_AUTO || we_cipher == IW_AUTH_CIPHER_TKIP || we_cipher == IW_AUTH_CIPHER_CCMP, NULL); - - if (!nmu_security_deserialize_wpa_psk (iter, &key, &key_len, &wpa_version, &key_mgt)) - goto out; - - /* Success, build up our security object */ - security = g_object_new (NM_TYPE_AP_SECURITY_WPA_PSK, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher); - if (key) - nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len); - security->priv->wpa_version = wpa_version; - security->priv->key_mgt = key_mgt; - - set_description (security); - -out: - return security; -} - -NMAPSecurityWPA_PSK * -nm_ap_security_wpa_psk_new (guint32 capabilities, int we_cipher) -{ - NMAPSecurityWPA_PSK *security; - - g_return_val_if_fail (we_cipher == NM_AUTH_TYPE_WPA_PSK_AUTO || we_cipher == IW_AUTH_CIPHER_TKIP || (we_cipher == IW_AUTH_CIPHER_CCMP), NULL); - - security = g_object_new (NM_TYPE_AP_SECURITY_WPA_PSK, NULL); - nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher); - - if (capabilities & NM_802_11_CAP_PROTO_WPA2) - security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA2; - else if (capabilities & NM_802_11_CAP_PROTO_WPA) - security->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; - security->priv->key_mgt = IW_AUTH_KEY_MGMT_PSK; - - set_description (security); - - return security; -} - -static int -real_serialize (NMAPSecurity *instance, DBusMessageIter *iter) -{ - NMAPSecurityWPA_PSK * self = NM_AP_SECURITY_WPA_PSK (instance); - - if (!nmu_security_serialize_wpa_psk (iter, - nm_ap_security_get_key (instance), - self->priv->wpa_version, - self->priv->key_mgt)) - return -1; - return 0; -} - -static gboolean -real_write_supplicant_config (NMAPSecurity *instance, - NMSupplicantConfig * config, - gboolean adhoc) -{ - NMAPSecurityWPA_PSK * self = NM_AP_SECURITY_WPA_PSK (instance); - gboolean success = FALSE; - const char * key = nm_ap_security_get_key (instance); - int cipher = nm_ap_security_get_we_cipher (instance); - char * key_mgmt = "WPA-PSK"; - char * pairwise_cipher = NULL; - char * group_cipher = NULL; - char * bin_key = NULL; - - /* WPA-PSK network setup */ - - if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA) { - if (!nm_supplicant_config_add_option (config, "proto", "WPA", -1)) - goto out; - } else if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA2) { - if (!nm_supplicant_config_add_option (config, "proto", "WPA2", -1)) - goto out; - } - - /* Ad-Hoc has to be WPA-NONE */ - if (adhoc) - key_mgmt = "WPA-NONE"; - - if (!nm_supplicant_config_add_option (config, "key_mgmt", key_mgmt, -1)) - goto out; - - bin_key = cipher_hexstr2bin(key, strlen (key)); - if (bin_key == NULL) { - nm_warning ("Not enough memory to convert key."); - goto out; - } - - if (!nm_supplicant_config_add_option (config, "psk", bin_key, strlen (key) / 2)) { - g_free (bin_key); - goto out; - } - g_free (bin_key); - - /* - * FIXME: Technically, the pairwise cipher does not need to be the same as - * the group cipher. Fixing this requires changes in the UI. - */ - if (cipher == IW_AUTH_CIPHER_TKIP) - pairwise_cipher = group_cipher = "TKIP"; - else if (cipher == IW_AUTH_CIPHER_CCMP) - pairwise_cipher = group_cipher = "CCMP"; - else if (cipher == IW_AUTH_CIPHER_NONE) - pairwise_cipher = group_cipher = "NONE"; - - /* Ad-Hoc requires pairwise cipher of NONE */ - if (adhoc) - pairwise_cipher = "NONE"; - - /* If user selected "Automatic", we let wpa_supplicant sort it out */ - if (cipher != NM_AUTH_TYPE_WPA_PSK_AUTO) { - if (!nm_supplicant_config_add_option (config, "pairwise", pairwise_cipher, -1)) - goto out; - - if (!nm_supplicant_config_add_option (config, "group", group_cipher, -1)) - goto out; - } - - success = TRUE; - -out: - return success; -} - -static guint32 -real_get_default_capabilities (NMAPSecurity *instance) -{ - NMAPSecurityWPA_PSK * self = NM_AP_SECURITY_WPA_PSK (instance); - guint32 caps = NM_802_11_CAP_NONE; - int we_cipher = nm_ap_security_get_we_cipher (instance); - - if (we_cipher == IW_AUTH_CIPHER_TKIP) - caps |= NM_802_11_CAP_CIPHER_TKIP; - else if (we_cipher == IW_AUTH_CIPHER_CCMP) - caps |= NM_802_11_CAP_CIPHER_CCMP; - else if (we_cipher == NM_AUTH_TYPE_WPA_PSK_AUTO) - caps |= (NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_CIPHER_CCMP); - - if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA) - caps |= NM_802_11_CAP_PROTO_WPA; - else if (self->priv->wpa_version == IW_AUTH_WPA_VERSION_WPA2) - caps |= NM_802_11_CAP_PROTO_WPA2; - - if (self->priv->key_mgt == IW_AUTH_KEY_MGMT_PSK) - caps |= NM_802_11_CAP_KEY_MGMT_PSK; - return caps; -} - -static gboolean -real_get_authentication_required (NMAPSecurity *instance) -{ - /* WPA Personal always requires authentication in the infrastructure mode. */ - return TRUE; -} - -static NMAPSecurity * -real_copy_constructor (NMAPSecurity *instance) -{ - NMAPSecurityWPA_PSK * dst = g_object_new (NM_TYPE_AP_SECURITY_WPA_PSK, NULL); - NMAPSecurityWPA_PSK * self = NM_AP_SECURITY_WPA_PSK (instance); - - dst->priv->wpa_version = self->priv->wpa_version; - dst->priv->key_mgt = self->priv->key_mgt; - nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst)); - return NM_AP_SECURITY (dst); -} - -static void -nm_ap_security_wpa_psk_init (NMAPSecurityWPA_PSK * self) -{ - self->priv = NM_AP_SECURITY_WPA_PSK_GET_PRIVATE (self); - self->priv->wpa_version = IW_AUTH_WPA_VERSION_WPA; - self->priv->key_mgt = IW_AUTH_KEY_MGMT_PSK; -} - -static void -nm_ap_security_wpa_psk_class_init (NMAPSecurityWPA_PSKClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass); - - par_class->copy_constructor_func = real_copy_constructor; - par_class->serialize_func = real_serialize; - par_class->write_supplicant_config_func = real_write_supplicant_config; - par_class->get_default_capabilities_func = real_get_default_capabilities; - par_class->get_authentication_required_func = real_get_authentication_required; - - g_type_class_add_private (object_class, sizeof (NMAPSecurityWPA_PSKPrivate)); -} - -GType -nm_ap_security_wpa_psk_get_type (void) -{ - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (NMAPSecurityWPA_PSKClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) nm_ap_security_wpa_psk_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (NMAPSecurityWPA_PSK), - 0, /* n_preallocs */ - (GInstanceInitFunc) nm_ap_security_wpa_psk_init, - NULL /* value_table */ - }; - type = g_type_register_static (NM_TYPE_AP_SECURITY, - "NMAPSecurityWPA_PSK", - &info, 0); - } - return type; -} diff --git a/src/nm-ap-security-wpa-psk.h b/src/nm-ap-security-wpa-psk.h deleted file mode 100644 index 95aa5f13cb..0000000000 --- a/src/nm-ap-security-wpa-psk.h +++ /dev/null @@ -1,59 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_AP_SECURITY_WPA_PSK_H -#define NM_AP_SECURITY_WPA_PSK_H - -#include <glib-object.h> -#include <dbus/dbus.h> -#include "nm-ap-security.h" - -#define NM_TYPE_AP_SECURITY_WPA_PSK (nm_ap_security_wpa_psk_get_type ()) -#define NM_AP_SECURITY_WPA_PSK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSK)) -#define NM_AP_SECURITY_WPA_PSK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSKClass)) -#define NM_IS_AP_SECURITY_WPA_PSK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP_SECURITY_WPA_PSK)) -#define NM_IS_AP_SECURITY_WPA_PSK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_AP_SECURITY_WPA_PSK)) -#define NM_AP_SECURITY_WPA_PSK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSKClass)) - -typedef struct _NMAPSecurityWPA_PSK NMAPSecurityWPA_PSK; -typedef struct _NMAPSecurityWPA_PSKClass NMAPSecurityWPA_PSKClass; -typedef struct _NMAPSecurityWPA_PSKPrivate NMAPSecurityWPA_PSKPrivate; - -struct _NMAPSecurityWPA_PSK -{ - NMAPSecurity parent; - - /*< private >*/ - NMAPSecurityWPA_PSKPrivate *priv; -}; - -struct _NMAPSecurityWPA_PSKClass -{ - NMAPSecurityClass parent; -}; - - -GType nm_ap_security_wpa_psk_get_type (void); - -NMAPSecurityWPA_PSK * nm_ap_security_wpa_psk_new_deserialize (DBusMessageIter *iter, int we_cipher); -NMAPSecurityWPA_PSK * nm_ap_security_wpa_psk_new (guint32 capabilities, int we_cipher); - -#endif /* NM_AP_SECURITY_WPA_PSK_H */ diff --git a/src/nm-ap-security.c b/src/nm-ap-security.c deleted file mode 100644 index 2fc21d514b..0000000000 --- a/src/nm-ap-security.c +++ /dev/null @@ -1,412 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include <glib.h> -#include <glib/gi18n.h> -#include <dbus/dbus.h> -#include <iwlib.h> - -#include "nm-ap-security.h" -#include "nm-ap-security-private.h" -#include "nm-ap-security-wep.h" -#include "nm-ap-security-wpa-psk.h" -#include "nm-ap-security-wpa-eap.h" -#include "nm-ap-security-leap.h" -#include "nm-device-802-11-wireless.h" -#include "nm-supplicant-config.h" -#include "nm-utils.h" - -#define NM_AP_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY, NMAPSecurityPrivate)) - -struct _NMAPSecurityPrivate -{ - int we_cipher; - char * key; - char * description; - - gboolean dispose_has_run; -}; - -#define WPA2_CCMP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA2_TKIP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA2_EAP (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_KEY_MGMT_802_1X) -#define WPA_CCMP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA_TKIP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK) -#define WPA_EAP (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_KEY_MGMT_802_1X) -#define WEP_WEP104 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104) -#define WEP_WEP40 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40) -#define LEAP (NM_802_11_CAP_KEY_MGMT_802_1X) - -NMAPSecurity * -nm_ap_security_new (guint32 capabilities, gboolean encrypted) -{ - NMAPSecurity *security; - - /* Deteremine best encryption algorithm to use */ - if (((capabilities & WPA_CCMP_PSK) == WPA_CCMP_PSK) || ((capabilities & WPA2_CCMP_PSK) == WPA2_CCMP_PSK)) - security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new (capabilities, IW_AUTH_CIPHER_CCMP)); - else if (((capabilities & WPA_TKIP_PSK) == WPA_TKIP_PSK) || ((capabilities & WPA2_TKIP_PSK) == WPA2_TKIP_PSK)) - security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new (capabilities, IW_AUTH_CIPHER_TKIP)); - else if (((capabilities & WPA_EAP) == WPA_EAP) || ((capabilities & WPA2_EAP) == WPA2_EAP)) - security = NM_AP_SECURITY (nm_ap_security_wpa_eap_new (capabilities)); - else if ((capabilities & WEP_WEP104) == WEP_WEP104) - security = NM_AP_SECURITY (nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP104)); - else if ((capabilities & WEP_WEP40) == WEP_WEP40) - security = NM_AP_SECURITY (nm_ap_security_wep_new (IW_AUTH_CIPHER_WEP40)); - else if ((capabilities & LEAP) == LEAP) - security = NM_AP_SECURITY (nm_ap_security_leap_new ()); - else if (!encrypted) { - security = g_object_new (NM_TYPE_AP_SECURITY, NULL); - security->priv->we_cipher = IW_AUTH_CIPHER_NONE; - security->priv->key = NULL; - } - - return security; -} - - -NMAPSecurity * -nm_ap_security_new_deserialize (DBusMessageIter *iter) -{ - NMAPSecurity * security = NULL; - int we_cipher; - - g_return_val_if_fail (iter != NULL, NULL); - - /* We require the WE cipher (an INT32) first */ - g_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_INT32, NULL); - - /* Get and validate WE cipher */ - dbus_message_iter_get_basic (iter, &we_cipher); - - if (we_cipher == IW_AUTH_CIPHER_NONE) - security = nm_ap_security_new (NM_DEVICE_CAP_NONE, FALSE); - else - { - /* Advance to start of cipher-dependent options */ - if (!dbus_message_iter_next (iter)) - goto out; - - switch (we_cipher) - { - case IW_AUTH_CIPHER_WEP40: - case IW_AUTH_CIPHER_WEP104: - security = NM_AP_SECURITY (nm_ap_security_wep_new_deserialize (iter, we_cipher)); - break; - - case NM_AUTH_TYPE_WPA_PSK_AUTO: - case IW_AUTH_CIPHER_TKIP: - case IW_AUTH_CIPHER_CCMP: - security = NM_AP_SECURITY (nm_ap_security_wpa_psk_new_deserialize (iter, we_cipher)); - break; - - case NM_AUTH_TYPE_WPA_EAP: - security = NM_AP_SECURITY (nm_ap_security_wpa_eap_new_deserialize (iter)); - break; - - case NM_AUTH_TYPE_LEAP: - security = NM_AP_SECURITY (nm_ap_security_leap_new_deserialize (iter)); - break; - - default: - nm_warning ("Unmatched cipher %d", we_cipher); - break; - } - } - -out: - return security; -} - - -guint32 -nm_ap_security_get_default_capabilities (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, NM_802_11_CAP_PROTO_NONE); - - return NM_AP_SECURITY_GET_CLASS (self)->get_default_capabilities_func (self); -} - -gboolean -nm_ap_security_get_authentication_required (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, FALSE); - - return NM_AP_SECURITY_GET_CLASS (self)->get_authentication_required_func (self); -} - - -gboolean -nm_ap_security_write_supplicant_config (NMAPSecurity *self, - NMSupplicantConfig * config, - gboolean adhoc) -{ - NMAPSecurityClass * class = NM_AP_SECURITY_GET_CLASS (self); - - g_return_val_if_fail (self != NULL, FALSE); - g_return_val_if_fail (config != NULL, FALSE); - - if (self->priv->dispose_has_run) - return FALSE; - - return class->write_supplicant_config_func (self, config, adhoc); -} - -void -nm_ap_security_set_we_cipher (NMAPSecurity *self, int we_cipher) -{ - g_return_if_fail (self != NULL); - - /* Ensure that the cipher is valid */ - g_return_if_fail ( - (we_cipher == NM_AUTH_TYPE_WPA_PSK_AUTO) - || (we_cipher == IW_AUTH_CIPHER_NONE) - || (we_cipher == IW_AUTH_CIPHER_WEP40) - || (we_cipher == IW_AUTH_CIPHER_WEP104) - || (we_cipher == IW_AUTH_CIPHER_TKIP) - || (we_cipher == IW_AUTH_CIPHER_CCMP) - || (we_cipher == NM_AUTH_TYPE_WPA_EAP) - || (we_cipher == NM_AUTH_TYPE_LEAP)); - - self->priv->we_cipher = we_cipher; -} - -/* - * nm_ap_security_set_key - set the encryption key for a given AP - * - */ -void -nm_ap_security_set_key (NMAPSecurity *self, const char *key, int key_len) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (key_len > 0); - - if (self->priv->key) - g_free (self->priv->key); - self->priv->key = g_malloc0 (key_len + 1); - memcpy (self->priv->key, key, key_len); -} - -static NMAPSecurity * -real_copy_constructor (NMAPSecurity *self) -{ - NMAPSecurity *dst; - - dst = g_object_new (NM_TYPE_AP_SECURITY, NULL); - dst->priv->we_cipher = self->priv->we_cipher; - dst->priv->key = NULL; - - nm_ap_security_copy_properties (self, dst); - return dst; -} - -static int -real_serialize (NMAPSecurity *self, DBusMessageIter *iter) -{ - /* Nothing to do */ - return 0; -} - -static gboolean -real_write_supplicant_config (NMAPSecurity *self, - NMSupplicantConfig * config, - gboolean adhoc) -{ - /* Unencrypted network */ - if (!nm_supplicant_config_add_option (config, "key_mgmt", "NONE", -1)) - return FALSE; - - return TRUE; -} - -static guint32 -real_get_default_capabilities (NMAPSecurity *self) -{ - return NM_802_11_CAP_PROTO_NONE; -} - -int -nm_ap_security_get_we_cipher (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, NM_AUTH_TYPE_WPA_PSK_AUTO); - - return self->priv->we_cipher; -} - -const char * -nm_ap_security_get_key (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, NULL); - - return self->priv->key; -} - -const char * -nm_ap_security_get_description (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, NULL); - - return self->priv->description; -} - -void -nm_ap_security_set_description (NMAPSecurity *self, const char *desc) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (desc != NULL); - - self->priv->description = (char *) desc; -} - -int -nm_ap_security_serialize (NMAPSecurity *self, DBusMessageIter *iter) -{ - dbus_int32_t dbus_we_cipher; - - g_return_val_if_fail (self != NULL, -1); - g_return_val_if_fail (iter != NULL, -1); - - if (self->priv->dispose_has_run) - return -1; - - /* First arg: WE cipher (INT32) */ - dbus_we_cipher = (dbus_int32_t) self->priv->we_cipher; - dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &dbus_we_cipher); - - return NM_AP_SECURITY_GET_CLASS (self)->serialize_func (self, iter); -} - -NMAPSecurity * -nm_ap_security_new_copy (NMAPSecurity *self) -{ - g_return_val_if_fail (self != NULL, NULL); - - return NM_AP_SECURITY_GET_CLASS (self)->copy_constructor_func (self); -} - -void -nm_ap_security_copy_properties (NMAPSecurity *self, NMAPSecurity *dst) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (dst != NULL); - g_return_if_fail (self != dst); - - nm_ap_security_set_we_cipher (dst, self->priv->we_cipher); - if (self->priv->key) - nm_ap_security_set_key (dst, self->priv->key, strlen (self->priv->key)); - nm_ap_security_set_description (dst, self->priv->description); -} - -static void -nm_ap_security_init (NMAPSecurity * self) -{ - self->priv = NM_AP_SECURITY_GET_PRIVATE (self); - self->priv->dispose_has_run = FALSE; - self->priv->we_cipher = IW_AUTH_CIPHER_NONE; - self->priv->key = NULL; - self->priv->description = _("none"); -} - -static void -nm_ap_security_dispose (GObject *object) -{ - NMAPSecurity * self = NM_AP_SECURITY (object); - NMAPSecurityClass * klass; - GObjectClass * parent_class; - - if (self->priv->dispose_has_run) - /* If dispose did already run, return. */ - return; - - /* Make sure dispose does not run twice. */ - self->priv->dispose_has_run = TRUE; - - /* - * In dispose, you are supposed to free all types referenced from this - * object which might themselves hold a reference to self. Generally, - * the most simple solution is to unref all members on which you own a - * reference. - */ - - /* Chain up to the parent class */ - klass = NM_AP_SECURITY_CLASS (g_type_class_peek (NM_TYPE_AP_SECURITY)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - parent_class->dispose (object); -} - -static void -nm_ap_security_finalize (GObject *object) -{ - NMAPSecurity * self = NM_AP_SECURITY (object); - NMAPSecurityClass * klass; - GObjectClass * parent_class; - - /* Complete object destruction */ - g_free (self->priv->key); - - /* Chain up to the parent class */ - klass = NM_AP_SECURITY_CLASS (g_type_class_peek (NM_TYPE_AP_SECURITY)); - parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - parent_class->finalize (object); -} - - -static void -nm_ap_security_class_init (NMAPSecurityClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = nm_ap_security_dispose; - object_class->finalize = nm_ap_security_finalize; - - klass->copy_constructor_func = real_copy_constructor; - klass->serialize_func = real_serialize; - klass->write_supplicant_config_func = real_write_supplicant_config; - klass->get_default_capabilities_func = real_get_default_capabilities; - - g_type_class_add_private (object_class, sizeof (NMAPSecurityPrivate)); -} - -GType -nm_ap_security_get_type (void) -{ - static GType type = 0; - if (type == 0) { - static const GTypeInfo info = { - sizeof (NMAPSecurityClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) nm_ap_security_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (NMAPSecurity), - 0, /* n_preallocs */ - (GInstanceInitFunc) nm_ap_security_init, - NULL /* value_table */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "NMAPSecurity", - &info, 0); - } - return type; -} diff --git a/src/nm-ap-security.h b/src/nm-ap-security.h deleted file mode 100644 index 7ff9ee82f4..0000000000 --- a/src/nm-ap-security.h +++ /dev/null @@ -1,103 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_AP_SECURITY_H -#define NM_AP_SECURITY_H - -#include <glib-object.h> -#include <dbus/dbus.h> - -#include "supplicant-manager/nm-supplicant-types.h" - -/* Grr */ -#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED -#define NM_DEVICE_802_11_WIRELESS_DEFINED -typedef struct _NMDevice80211Wireless NMDevice80211Wireless; -#endif - -G_BEGIN_DECLS - -#define NM_TYPE_AP_SECURITY (nm_ap_security_get_type ()) -#define NM_AP_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AP_SECURITY, NMAPSecurity)) -#define NM_AP_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_AP_SECURITY, NMAPSecurityClass)) -#define NM_IS_AP_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_AP_SECURITY)) -#define NM_IS_AP_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_AP_SECURITY)) -#define NM_AP_SECURITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AP_SECURITY, NMAPSecurityClass)) - -typedef struct _NMAPSecurity NMAPSecurity; -typedef struct _NMAPSecurityClass NMAPSecurityClass; -typedef struct _NMAPSecurityPrivate NMAPSecurityPrivate; - -struct _NMAPSecurity -{ - GObject parent; - - /*< private >*/ - NMAPSecurityPrivate *priv; -}; - -struct _NMAPSecurityClass -{ - GObjectClass parent; - - /* class members */ - NMAPSecurity * (*copy_constructor_func) (NMAPSecurity *self); - - int (*serialize_func) (NMAPSecurity *self, - DBusMessageIter *iter); - - gboolean (*write_supplicant_config_func) (NMAPSecurity *self, - NMSupplicantConfig * config, - gboolean adhoc); - - guint32 (*get_default_capabilities_func) (NMAPSecurity *self); - gboolean (*get_authentication_required_func) (NMAPSecurity *self); -}; - - -GType nm_ap_security_get_type (void); - -NMAPSecurity * nm_ap_security_new_copy (NMAPSecurity *self); - -NMAPSecurity * nm_ap_security_new (guint32 capabilities, gboolean encrypted); - -NMAPSecurity * nm_ap_security_new_deserialize (DBusMessageIter *iter); - -int nm_ap_security_get_we_cipher (NMAPSecurity *self); - -const char * nm_ap_security_get_key (NMAPSecurity *self); - -int nm_ap_security_serialize (NMAPSecurity *self, - DBusMessageIter *iter); - -gboolean nm_ap_security_write_supplicant_config (NMAPSecurity *self, - NMSupplicantConfig * config, - gboolean adhoc); - -const char * nm_ap_security_get_description (NMAPSecurity *self); - -guint32 nm_ap_security_get_default_capabilities (NMAPSecurity *self); - -gboolean nm_ap_security_get_authentication_required (NMAPSecurity *self); - -G_END_DECLS - -#endif /* NM_AP_SECURITY_H */ diff --git a/src/nm-dbus-nmi.c b/src/nm-dbus-nmi.c deleted file mode 100644 index 4d952273dc..0000000000 --- a/src/nm-dbus-nmi.c +++ /dev/null @@ -1,764 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#include "NetworkManager.h" -#include "nm-device-interface.h" -#include "nm-device.h" -#include "nm-activation-request.h" -#include "NetworkManagerAPList.h" -#include "NetworkManagerPolicy.h" -#include "NetworkManagerUtils.h" -#include "nm-dbus-nmi.h" -#include "nm-utils.h" -#include "nm-dbus-manager.h" - -#define NM_ACT_REQUEST_PENDING_CALL "nm-act-request-pending-call" - -typedef struct { - NMDevice *device; - NMActRequest *req; -} UserKeyInfo; - -static void -user_key_info_destroy (gpointer data) -{ - UserKeyInfo *info = (UserKeyInfo *) data; - - g_object_set_data (G_OBJECT (info->req), NM_ACT_REQUEST_PENDING_CALL, NULL); - - g_object_unref (info->device); - g_object_unref (info->req); - - g_slice_free (UserKeyInfo, info); -} - -/* - * nm_dbus_get_user_key_for_network_cb - * - * Callback from nm_dbus_get_user_key_for_network when NetworkManagerInfo returns - * the new user key. - * - */ -static void -nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, - UserKeyInfo *info) -{ - DBusMessage * reply = NULL; - NMData * data; - NMDevice * dev; - NMActRequest *req; - NMAccessPoint * ap; - NMAPSecurity * security; - DBusMessageIter iter; - const GByteArray * ssid; - - g_return_if_fail (pcall != NULL); - g_return_if_fail (info != NULL); - - dev = info->device; - req = info->req; - - data = nm_device_get_app_data (dev); - g_assert (data); - - ap = nm_device_802_11_wireless_get_activation_ap (NM_DEVICE_802_11_WIRELESS (dev)); - g_assert (ap); - ssid = nm_ap_get_ssid (ap); - - nm_dbus_send_with_callback_replied (pcall, __func__); - - if (!(reply = dbus_pending_call_steal_reply (pcall))) - goto out; - - if (message_is_error (reply)) { - DBusError err; - - dbus_error_init (&err); - dbus_set_error_from_message (&err, reply); - - /* Check for cancelled error */ - if (strcmp (err.name, NMI_DBUS_USER_KEY_CANCELED_ERROR) == 0) { - nm_info ("Activation (%s) New wireless user key request for network" - " '%s' was canceled.", - nm_device_get_iface (dev), - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); - } else { - nm_warning ("dbus returned an error.\n (%s) %s\n", - err.name, - err.message); - } - - dbus_error_free (&err); - - /* FIXME: since we're not marking the device as invalid, its a fair bet - * that NM will just try to reactivate the device again, and may fail - * to get the user key in exactly the same way, which ends up right back - * here... ad nauseum. Figure out how to deal with a failure here. - */ - nm_ap_list_append_ap (data->invalid_ap_list, ap); - nm_device_interface_deactivate (NM_DEVICE_INTERFACE (dev)); - - goto out; - } - - nm_info ("Activation (%s) New wireless user key for network '%s' received.", - nm_device_get_iface (dev), - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); - - dbus_message_iter_init (reply, &iter); - if ((security = nm_ap_security_new_deserialize (&iter))) { - nm_ap_set_security (ap, security); - nm_device_activate_schedule_stage2_device_config (dev); - } - -out: - if (reply) - dbus_message_unref (reply); - dbus_pending_call_unref (pcall); -} - - -/* - * nm_dbus_get_user_key_for_network - * - * Asks the info-daemon for a user-entered WEP key. - * - */ -void -nm_dbus_get_user_key_for_network (NMDevice *dev, - NMActRequest *req, - const gboolean new_key) -{ - NMDBusManager * dbus_mgr = NULL; - DBusConnection *dbus_connection; - DBusMessage * message; - DBusPendingCall * pcall; - UserKeyInfo *info; - NMAccessPoint * ap; - gint32 attempt = 1; - const char * dev_path; - const char * net_path; - const GByteArray * ssid; - - g_return_if_fail (NM_IS_DEVICE (dev)); - g_return_if_fail (req != NULL); - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("could not get the dbus connection."); - goto out; - } - - ap = nm_device_802_11_wireless_get_activation_ap (NM_DEVICE_802_11_WIRELESS (dev)); - g_assert (ap); - - ssid = nm_ap_get_ssid (ap); - nm_info ("Activation (%s) New wireless user key requested for network '%s'.", - nm_device_get_iface (dev), - ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); - - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "getKeyForNetwork"); - if (!message) { - nm_warning ("couldn't allocate the dbus message"); - goto out; - } - - dev_path = nm_device_get_dbus_path (dev); - net_path = nm_ap_get_dbus_path (ap); - if (dev_path && strlen (dev_path) && net_path && strlen (net_path)) { - char buf[IW_ESSID_MAX_SIZE + 1]; - char * ptr = &buf[0]; - - memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid->data, MIN (ssid->len, sizeof (buf) - 1)); - dbus_message_append_args (message, DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_OBJECT_PATH, &net_path, - DBUS_TYPE_STRING, &ptr, - DBUS_TYPE_INT32, &attempt, - DBUS_TYPE_BOOLEAN, &new_key, - DBUS_TYPE_INVALID); - - info = g_slice_new (UserKeyInfo); - info->device = g_object_ref (dev); - info->req = g_object_ref (req); - - pcall = nm_dbus_send_with_callback (dbus_connection, - message, - (DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb, - info, - user_key_info_destroy, - __func__); - if (pcall) - g_object_set_data (G_OBJECT (req), NM_ACT_REQUEST_PENDING_CALL, pcall); - } else { - nm_warning ("bad object path data"); - } - - /* FIXME: figure out how to deal with a failure here, otherwise - * we just hang in the activation process and nothing happens - * until the user cancels stuff. - */ - - dbus_message_unref (message); - -out: - g_object_unref (dbus_mgr); -} - - -/* - * nm_dbus_cancel_get_user_key_for_network - * - * Sends a user-key cancellation message to NetworkManagerInfo - * - */ -void -nm_dbus_cancel_get_user_key_for_network (NMActRequest *req) -{ - DBusMessage * message; - DBusPendingCall * pcall; - NMDBusManager * dbus_mgr; - DBusConnection * dbus_connection; - - g_return_if_fail (req != NULL); - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("could not get the dbus connection."); - goto out; - } - - pcall = (DBusPendingCall *) g_object_get_data (G_OBJECT (req), NM_ACT_REQUEST_PENDING_CALL); - if (pcall) - dbus_pending_call_cancel (pcall); - - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "cancelGetKeyForNetwork"); - if (!message) { - nm_warning ("couldn't allocate the dbus message"); - goto out; - } - - dbus_connection_send (dbus_connection, message, NULL); - dbus_message_unref (message); - -out: - g_object_unref (dbus_mgr); -} - - -/* - * nm_dbus_update_network_info - * - * Tell NetworkManagerInfo the updated info of the AP - * - */ -void -nm_dbus_update_network_info (NMAccessPoint *ap, - const gboolean automatic) -{ - NMDBusManager * dbus_mgr = NULL; - DBusConnection * dbus_connection; - DBusMessage * message; - gboolean fallback; - const GByteArray * ssid; - gchar * char_bssid; - NMAPSecurity * security; - const struct ether_addr *addr; - DBusMessageIter iter; - char buf[IW_ESSID_MAX_SIZE + 1]; - char * ptr = &buf[0]; - - g_return_if_fail (ap != NULL); - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("could not get the dbus connection."); - goto out; - } - - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "updateNetworkInfo"); - if (!message) { - nm_warning ("couldn't allocate the dbus message"); - goto out; - } - - dbus_message_iter_init_append (message, &iter); - - /* First argument: ESSID (STRING) */ - ssid = nm_ap_get_ssid (ap); - memset (buf, 0, sizeof (buf)); - memcpy (buf, ssid->data, MIN (ssid->len, IW_ESSID_MAX_SIZE)); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &ptr); - - /* Second argument: Automatic or user-driven connection? (BOOLEAN) */ - dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &automatic); - - /* Third argument: Fallback? (BOOLEAN) */ - fallback = nm_ap_get_fallback (ap); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &fallback); - - /* Fourth argument: Access point's BSSID */ - addr = nm_ap_get_address (ap); - if ((nm_ap_get_mode (ap) == IW_MODE_INFRA) && nm_ethernet_address_is_valid (addr)) - { - char_bssid = g_new0 (gchar, 20); - iw_ether_ntop (addr, char_bssid); - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &char_bssid); - g_free (char_bssid); - } - else - { - /* Use an invalid BSSID for non-infrastructure networks, since - * the BSSID is usually randomly constructed by the driver and - * changed every time you activate the network. - */ - char_bssid = " "; - dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &char_bssid); - } - - /* Serialize the AP's security info into the message */ - security = nm_ap_get_security (ap); - g_assert (security); - if (nm_ap_security_serialize (security, &iter) == 0) - dbus_connection_send (dbus_connection, message, NULL); - dbus_message_unref (message); - -out: - g_object_unref (dbus_mgr); - return; -} - - -typedef struct GetOneNetworkCBData -{ - NMData * data; - char * network; - NMAccessPointList * list; -} GetOneNetworkCBData; - - -static void free_get_one_network_cb_data (GetOneNetworkCBData *data) -{ - if (data) - { - nm_ap_list_unref (data->list); - g_free (data->network); - data->list = NULL; - data->network = NULL; - data->data = NULL; - g_slice_free (GetOneNetworkCBData, data); - } -} - -typedef struct GetNetworksCBData -{ - NMData * data; - NMAccessPointList * list; -} GetNetworksCBData; - - -static void free_get_networks_cb_data (GetNetworksCBData *data) -{ - if (data) - { - nm_ap_list_unref (data->list); - data->data = NULL; - data->list = NULL; - g_slice_free (GetNetworksCBData, data); - } -} - -/* - * nm_dbus_get_network_data_cb - * - * Add a new NMAccessPoint to the allowed list with the correct properties - * - */ -static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data) -{ - GetOneNetworkCBData * cb_data = (GetOneNetworkCBData *)user_data; - DBusMessage * reply = NULL; - DBusMessageIter iter; - DBusMessageIter subiter; - const char * tmp_ssid = NULL; - guint32 tmp_ssid_len; - gint timestamp_secs = -1; - gboolean fallback = FALSE; - GSList * addr_list = NULL; - NMAPSecurity * security; - NMAccessPoint * ap; - NMAccessPoint * list_ap; - GByteArray * ssid; - - g_return_if_fail (pcall != NULL); - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->data != NULL); - g_return_if_fail (cb_data->network != NULL); - g_return_if_fail (cb_data->list != NULL); - - nm_dbus_send_with_callback_replied (pcall, __func__); - - dbus_pending_call_ref (pcall); - - if (!(reply = dbus_pending_call_steal_reply (pcall))) - goto out; - - if (dbus_message_is_error (reply, "BadNetworkData")) { - guint32 rmv_len = strlen (cb_data->network); - GByteArray * rmv_ssid; - - rmv_ssid = g_byte_array_sized_new (rmv_len); - g_byte_array_append (rmv_ssid, cb_data->network, rmv_len); - nm_ap_list_remove_ap_by_ssid (cb_data->list, rmv_ssid); - g_byte_array_free (rmv_ssid, TRUE); - goto out; - } - - if (message_is_error (reply)) { - DBusError err; - - dbus_error_init (&err); - dbus_set_error_from_message (&err, reply); - nm_warning ("dbus returned an error.\n (%s) %s\n", err.name, err.message); - dbus_error_free (&err); - goto out; - } - - dbus_message_iter_init (reply, &iter); - - /* First arg: ESSID (STRING) */ - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - { - nm_warning ("a message argument (SSID) was invalid."); - goto out; - } - dbus_message_iter_get_basic (&iter, &tmp_ssid); - - /* Second arg: Timestamp (INT32) */ - if (!dbus_message_iter_next (&iter) - || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)) - { - nm_warning ("a message argument (timestamp) was invalid."); - goto out; - } - dbus_message_iter_get_basic (&iter, ×tamp_secs); - - /* Third arg: Fallback? (BOOLEAN) */ - if (!dbus_message_iter_next (&iter) - || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN)) - { - nm_warning ("a message argument (fallback) was invalid."); - goto out; - } - dbus_message_iter_get_basic (&iter, &fallback); - - /* Fourth arg: BSSID addresses (ARRAY, STRING) */ - if (!dbus_message_iter_next (&iter) - || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) - || (dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_STRING)) - { - nm_warning ("a message argument (addresses) was invalid."); - goto out; - } - dbus_message_iter_recurse (&iter, &subiter); - while (dbus_message_iter_get_arg_type (&subiter) == DBUS_TYPE_STRING) - { - char *address; - dbus_message_iter_get_basic (&subiter, &address); - if (address && strlen (address) >= 11) - addr_list = g_slist_append (addr_list, address); - dbus_message_iter_next (&subiter); - } - - /* Unserialize access point security info */ - if (!dbus_message_iter_has_next (&iter)) - { - nm_warning ("a message argument (security info) was invalid."); - goto out; - } - dbus_message_iter_next (&iter); - - if (!(security = nm_ap_security_new_deserialize (&iter))) - { - nm_warning ("message arguments were invalid (could not deserialize " - "wireless network security information."); - goto out; - } - - /* Construct the new access point */ - ap = nm_ap_new (); - - tmp_ssid_len = MIN (strlen (tmp_ssid), IW_ESSID_MAX_SIZE); - ssid = g_byte_array_sized_new (tmp_ssid_len); - g_byte_array_append (ssid, tmp_ssid, tmp_ssid_len); - nm_ap_set_ssid (ap, ssid); - - nm_ap_set_security (ap, security); - nm_ap_add_capabilities_from_security (ap, security); - g_object_unref (G_OBJECT (security)); /* set_security copies the object */ - - nm_ap_set_timestamp (ap, timestamp_secs, 0); - - nm_ap_set_fallback (ap, fallback); - nm_ap_set_user_addresses (ap, addr_list); - - if ((list_ap = nm_ap_list_get_ap_by_ssid (cb_data->list, ssid))) - { - nm_ap_set_ssid (list_ap, nm_ap_get_ssid (ap)); - nm_ap_set_timestamp_via_timestamp (list_ap, nm_ap_get_timestamp (ap)); - nm_ap_set_fallback (list_ap, nm_ap_get_fallback (ap)); - nm_ap_set_security (list_ap, nm_ap_get_security (ap)); - nm_ap_set_user_addresses (list_ap, nm_ap_get_user_addresses (ap)); - } - else - { - /* New AP, just add it to the list */ - nm_ap_list_append_ap (cb_data->list, ap); - } - g_byte_array_free (ssid, TRUE); - g_object_unref (ap); - - /* Ensure all devices get new information copied into their device lists */ - nm_policy_schedule_device_ap_lists_update_from_allowed (cb_data->data); - -out: - if (addr_list) - g_slist_free (addr_list); - if (reply) - dbus_message_unref (reply); - dbus_pending_call_unref (pcall); -} - - -/* - * nm_dbus_get_networks_cb - * - * Async callback from nm_dbus_get_networks - * - */ -static void -nm_dbus_get_networks_cb (DBusPendingCall *pcall, - void *user_data) -{ - DBusMessage * reply; - DBusMessageIter iter, array_iter; - GetNetworksCBData * cb_data = (GetNetworksCBData *)user_data; - NMDBusManager * dbus_mgr = NULL; - DBusConnection *dbus_connection; - - g_return_if_fail (pcall); - g_return_if_fail (cb_data != NULL); - g_return_if_fail (cb_data->list != NULL); - g_return_if_fail (cb_data->data != NULL); - - nm_dbus_send_with_callback_replied (pcall, __func__); - - dbus_pending_call_ref (pcall); - - if (!(reply = dbus_pending_call_steal_reply (pcall))) - goto out; - - if (message_is_error (reply)) { - DBusError err; - - dbus_error_init (&err); - dbus_set_error_from_message (&err, reply); - nm_warning ("error received: %s - %s.", err.name, err.message); - goto out; - } - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("couldn't get dbus connection."); - goto out; - } - - dbus_message_iter_init (reply, &iter); - dbus_message_iter_recurse (&iter, &array_iter); - while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) { - const char * value; - DBusMessage * message; - - dbus_message_iter_get_basic (&array_iter, &value); - - /* Get properties on each network */ - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "getNetworkProperties"); - if (message) { - dbus_int32_t type_as_int32 = nm_ap_list_get_type (cb_data->list); - GetOneNetworkCBData * net_cb_data = g_slice_new0 (GetOneNetworkCBData); - - net_cb_data->data = cb_data->data; - net_cb_data->network = g_strdup (value); - nm_ap_list_ref (cb_data->list); - net_cb_data->list = cb_data->list; - - dbus_message_append_args (message, - DBUS_TYPE_STRING, &value, - DBUS_TYPE_INT32, &type_as_int32, - DBUS_TYPE_INVALID); - nm_dbus_send_with_callback (dbus_connection, - message, - (DBusPendingCallNotifyFunction) nm_dbus_get_network_data_cb, - net_cb_data, - (DBusFreeFunction) free_get_one_network_cb_data, - __func__); - dbus_message_unref (message); - } - dbus_message_iter_next(&array_iter); - } - dbus_message_unref (reply); - -out: - if (dbus_mgr) - g_object_unref (dbus_mgr); - dbus_pending_call_unref (pcall); -} - - -/* - * nm_dbus_update_allowed_networks - * - * Update all allowed networks from NetworkManagerInfo - * - */ -void -nm_dbus_update_allowed_networks (NMAccessPointList *list, - NMData *data) -{ - NMDBusManager * dbus_mgr = NULL; - DBusConnection * dbus_connection; - DBusMessage * message; - dbus_int32_t type_as_int32 = nm_ap_list_get_type (list); - GetNetworksCBData * cb_data; - - g_return_if_fail (list != NULL); - g_return_if_fail (data != NULL); - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("could not get the dbus connection."); - goto out; - } - - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "getNetworks"); - if (!message) { - nm_warning ("could not allocate the dbus message."); - goto out; - } - - dbus_message_append_args (message, - DBUS_TYPE_INT32, &type_as_int32, - DBUS_TYPE_INVALID); - - cb_data = g_slice_new0 (GetNetworksCBData); - cb_data->data = data; - nm_ap_list_ref (list); - cb_data->list = list; - - nm_dbus_send_with_callback (dbus_connection, - message, - (DBusPendingCallNotifyFunction) nm_dbus_get_networks_cb, - cb_data, - (DBusFreeFunction) free_get_networks_cb_data, - __func__); - dbus_message_unref (message); - -out: - g_object_unref (dbus_mgr); -} - - -/* - * nm_dbus_update_one_allowed_network - * - * Update all networks of a specific type from NetworkManagerInfo - * - */ -void -nm_dbus_update_one_allowed_network (const char *network, - NMData *data) -{ - NMDBusManager * dbus_mgr = NULL; - DBusConnection * dbus_connection; - DBusMessage * message; - dbus_int32_t type_as_int32 = NETWORK_TYPE_ALLOWED; - GetOneNetworkCBData * cb_data = NULL; - - g_return_if_fail (data != NULL); - - dbus_mgr = nm_dbus_manager_get (); - dbus_connection = nm_dbus_manager_get_dbus_connection (dbus_mgr); - if (!dbus_connection) { - nm_warning ("could not get the dbus connection."); - goto out; - } - - message = dbus_message_new_method_call (NMI_DBUS_SERVICE, - NMI_DBUS_PATH, - NMI_DBUS_INTERFACE, - "getNetworkProperties"); - if (!message) { - nm_warning ("couldn't allocate the dbus message."); - goto out; - } - - cb_data = g_slice_new0 (GetOneNetworkCBData); - cb_data->data = data; - cb_data->network = g_strdup (network); - cb_data->list = data->allowed_ap_list; - - dbus_message_append_args (message, - DBUS_TYPE_STRING, &network, - DBUS_TYPE_INT32, &type_as_int32, - DBUS_TYPE_INVALID); - nm_dbus_send_with_callback (dbus_connection, - message, - (DBusPendingCallNotifyFunction) nm_dbus_get_network_data_cb, - cb_data, - (DBusFreeFunction) free_get_one_network_cb_data, - __func__); - dbus_message_unref (message); - -out: - g_object_unref (dbus_mgr); -} - - diff --git a/src/nm-dbus-nmi.h b/src/nm-dbus-nmi.h deleted file mode 100644 index 32d67760fb..0000000000 --- a/src/nm-dbus-nmi.h +++ /dev/null @@ -1,41 +0,0 @@ -/* NetworkManager -- Network link manager - * - * Dan Williams <dcbw@redhat.com> - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * (C) Copyright 2005 Red Hat, Inc. - */ - -#ifndef NM_DBUS_NMI_H -#define NM_DBUS_NMI_H - -#include "NetworkManager.h" -#include "NetworkManagerAP.h" - -void nm_dbus_get_user_key_for_network (NMDevice *dev, - NMActRequest *req, - const gboolean new_key); - -void nm_dbus_cancel_get_user_key_for_network (NMActRequest *req); - -void nm_dbus_update_network_info (NMAccessPoint *ap, const gboolean user_requested); - -void nm_dbus_update_one_allowed_network (const char *network, NMData *data); - -void nm_dbus_update_allowed_networks (NMAccessPointList *list, NMData *data); - - -#endif /* NM_DBUS_NMI_H */ diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index 0d06355a63..c867f78a18 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -41,7 +41,6 @@ #include "NetworkManagerUtils.h" #include "NetworkManagerPolicy.h" #include "nm-activation-request.h" -#include "nm-dbus-nmi.h" #include "nm-supplicant-manager.h" #include "nm-supplicant-interface.h" #include "nm-supplicant-config.h" @@ -244,7 +243,7 @@ nm_device_802_11_wireless_update_bssid (NMDevice80211Wireless *self, nm_ap_set_address (ap, &new_bssid); automatic = !nm_act_request_get_user_requested (nm_device_get_act_request (NM_DEVICE (self))); - nm_dbus_update_network_info (ap, automatic); + // FIXME: push new BSSID to the info-daemon } } @@ -333,43 +332,54 @@ out: return caps; } +#define WPA_CAPS (NM_802_11_DEVICE_CAP_CIPHER_TKIP | \ + NM_802_11_DEVICE_CAP_CIPHER_CCMP | \ + NM_802_11_DEVICE_CAP_WPA | \ + NM_802_11_DEVICE_CAP_RSN) + static guint32 get_wireless_capabilities (NMDevice80211Wireless *self, iwrange * range, guint32 data_len) { guint32 minlen; - guint32 caps = NM_802_11_CAP_NONE; + guint32 caps = NM_802_11_DEVICE_CAP_NONE; - g_return_val_if_fail (self != NULL, NM_802_11_CAP_NONE); - g_return_val_if_fail (range != NULL, NM_802_11_CAP_NONE); + g_return_val_if_fail (self != NULL, NM_802_11_DEVICE_CAP_NONE); + g_return_val_if_fail (range != NULL, NM_802_11_DEVICE_CAP_NONE); minlen = ((char *) &range->enc_capa) - (char *) range + sizeof (range->enc_capa); /* All drivers should support WEP by default */ - caps |= (NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104); - /* All drivers should support no encryption by default */ - caps |= (NM_802_11_CAP_PROTO_NONE | NM_802_11_CAP_PROTO_WEP); + caps |= NM_802_11_DEVICE_CAP_CIPHER_WEP40 | NM_802_11_DEVICE_CAP_CIPHER_WEP104; + + if ((data_len >= minlen) && range->we_version_compiled >= 18) { + if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP) + caps |= NM_802_11_DEVICE_CAP_CIPHER_TKIP; + + if (range->enc_capa & IW_ENC_CAPA_CIPHER_CCMP) + caps |= NM_802_11_DEVICE_CAP_CIPHER_CCMP; - if ((data_len >= minlen) && range->we_version_compiled >= 18) - { if (range->enc_capa & IW_ENC_CAPA_WPA) - { - caps |= (NM_802_11_CAP_PROTO_WPA - | NM_802_11_CAP_KEY_MGMT_PSK - | NM_802_11_CAP_KEY_MGMT_802_1X); - } + caps |= NM_802_11_DEVICE_CAP_WPA; + if (range->enc_capa & IW_ENC_CAPA_WPA2) - { - caps |= (NM_802_11_CAP_PROTO_WPA2 - | NM_802_11_CAP_KEY_MGMT_PSK - | NM_802_11_CAP_KEY_MGMT_802_1X); + caps |= NM_802_11_DEVICE_CAP_RSN; + + /* Check for cipher support but not WPA support */ + if ( (caps & (NM_802_11_DEVICE_CAP_CIPHER_TKIP | NM_802_11_DEVICE_CAP_CIPHER_CCMP)) + && !(caps & (NM_802_11_DEVICE_CAP_WPA | NM_802_11_DEVICE_CAP_RSN))) { + nm_warning ("%s: device supports WPA ciphers but not WPA protocol; " + "WPA unavailable."); + caps &= ~WPA_CAPS; } - if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP) - caps |= NM_802_11_CAP_CIPHER_TKIP; - if (range->enc_capa & IW_ENC_CAPA_CIPHER_CCMP) - caps |= NM_802_11_CAP_CIPHER_CCMP; + /* Check for WPA support but not cipher support */ + if ( (caps & (NM_802_11_DEVICE_CAP_WPA | NM_802_11_DEVICE_CAP_RSN)) + && !(caps & (NM_802_11_DEVICE_CAP_CIPHER_TKIP | NM_802_11_DEVICE_CAP_CIPHER_CCMP))) + nm_warning ("%s: device supports WPA protocol but not WPA ciphers; " + "WPA unavailable."); + caps &= ~WPA_CAPS; } return caps; @@ -923,7 +933,6 @@ nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *self) if (!blacklisted && (curtime->tv_sec > best_timestamp.tv_sec)) { best_timestamp = *nm_ap_get_timestamp (tmp_ap); best_ap = scan_ap; - nm_ap_set_security (best_ap, nm_ap_get_security (tmp_ap)); } } } @@ -937,6 +946,7 @@ nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *self) return best_ap; } +#if 0 static gboolean nm_device_802_11_wireless_set_activation_ap (NMDevice80211Wireless *self, GByteArray *ssid, @@ -1009,7 +1019,7 @@ nm_device_802_11_wireless_set_activation_ap (NMDevice80211Wireless *self, return TRUE; } - +#endif /* * nm_device_802_11_wireless_ap_list_clear @@ -1757,66 +1767,50 @@ out: static gboolean -ap_need_key (NMDevice80211Wireless *self, - NMAccessPoint *ap, - gboolean *ask_user) +ap_need_secrets (NMDevice80211Wireless *self, + NMAccessPoint *ap, + NMConnection *connection, + gboolean *ask_user) { - const GByteArray * ssid; - gboolean need_key = FALSE; - NMAPSecurity * security; - const char * iface; - int we_cipher; - const char * esc_ssid = NULL; + const GByteArray * ssid; + gboolean need_key = FALSE; + const char * iface; + const char * esc_ssid; + guint32 flags, wpa_flags, rsn_flags; + g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (ap != NULL, FALSE); + g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (ask_user != NULL, FALSE); - ssid = nm_ap_get_ssid (ap); - if (ssid) - esc_ssid = nm_utils_escape_ssid (ssid->data, ssid->len); - - security = nm_ap_get_security (ap); - g_assert (security); - we_cipher = nm_ap_security_get_we_cipher (security); - iface = nm_device_get_iface (NM_DEVICE (self)); - if (!nm_ap_get_encrypted (ap)) - { - nm_info ("Activation (%s/wireless): access point '%s' is unencrypted, no key needed.", - iface, esc_ssid ? esc_ssid : "(null)"); - - /* If the user-specified security info doesn't overlap the - * scanned access point's info, create new info from the scanned - * characteristics of the access point. Can happen if the AP's - * settings were changed. - */ - if (we_cipher != IW_AUTH_CIPHER_NONE) - nm_ap_set_security (ap, nm_ap_security_new (nm_ap_get_capabilities (ap), - nm_ap_get_encrypted (ap))); - } - else - { - if ( !nm_ap_security_get_key (security) - || (we_cipher == IW_AUTH_CIPHER_NONE)) - { - nm_info ("Activation (%s/wireless): access point '%s' " - "is encrypted, but NO valid key exists. New key needed.", - iface, esc_ssid ? esc_ssid : "(null)"); + ssid = nm_ap_get_ssid (ap); + esc_ssid = ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(null)"; + + flags = nm_ap_get_flags (ap); + wpa_flags = nm_ap_get_wpa_flags (ap); + rsn_flags = nm_ap_get_rsn_flags (ap); + if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags == NM_802_11_AP_SEC_NONE) + && (rsn_flags == NM_802_11_AP_SEC_NONE)) { + nm_info ("Activation (%s/wireless): access point '%s' has no security, " + "no key needed.", + iface, esc_ssid); + } else { + if (nm_connection_have_secrets (connection)) { + nm_info ("Activation (%s/wireless): access point '%s' has security" + ", and secrets exist. No new secrets needed.", + iface, esc_ssid ? esc_ssid : "(null)"); + } else { + nm_info ("Activation (%s/wireless): access point '%s' has security," + " but secrets are required.", + iface, esc_ssid); need_key = TRUE; - /* If the user-specified security info doesn't overlap the - * scanned access point's info, ask the user for a completely - * new key. + /* FIXME: how to determine when to explicitly ask the user for + * secrets... */ - if (we_cipher == IW_AUTH_CIPHER_NONE) - *ask_user = TRUE; - } - else - { - nm_info ("Activation (%s/wireless): access point '%s' " - "is encrypted, and a key exists. No new key needed.", - iface, esc_ssid ? esc_ssid : "(null)"); } } @@ -1825,7 +1819,7 @@ ap_need_key (NMDevice80211Wireless *self, /* - * ap_is_auth_required + * ap_auth_enforced * * Checks whether or not there is an encryption key present for * this connection, and whether or not the authentication method @@ -1835,48 +1829,31 @@ ap_need_key (NMDevice80211Wireless *self, * Similarly, Open System WEP access points don't reject a station * when the key is wrong. Shared Key WEP access points will. * - * Theory of operation here is that if: - * (a) the NMAPSecurity object specifies that authentication is - * required, and the AP rejects our authentication attempt during - * connection (which shows up as a wpa_supplicant disconnection - * event); or - * (b) the NMAPSecurity object specifies that no authentiation is - * required, and either DHCP times out or wpa_supplicant times out; - * - * then we need a new key from the user because our currenty key - * and/or authentication method is likely wrong. - * */ static gboolean -ap_is_auth_required (NMAccessPoint *ap, gboolean *has_key) +ap_auth_enforced (NMAccessPoint *ap) { - NMAPSecurity *security; - int we_cipher; - gboolean auth_required = FALSE; + guint32 flags, wpa_flags, rsn_flags; g_return_val_if_fail (ap != NULL, FALSE); - g_return_val_if_fail (has_key != NULL, FALSE); - - *has_key = FALSE; - /* Ad Hoc mode doesn't have any master station to validate - * security credentials, so no auth can possibly be required. - */ - if (nm_ap_get_mode(ap) == IW_MODE_ADHOC) + if (nm_ap_get_mode (ap) == IW_MODE_ADHOC) return FALSE; - /* No encryption obviously means no possiblity of auth - * rejection due to a wrong encryption key. - */ - security = nm_ap_get_security (ap); - we_cipher = nm_ap_security_get_we_cipher (security); - if (we_cipher == IW_AUTH_CIPHER_NONE) - return FALSE; + flags = nm_ap_get_flags (ap); + wpa_flags = nm_ap_get_wpa_flags (ap); + rsn_flags = nm_ap_get_rsn_flags (ap); + + if (flags & NM_802_11_AP_FLAGS_PRIVACY) + return TRUE; + + if (wpa_flags != NM_802_11_AP_SEC_NONE) + return TRUE; - auth_required = nm_ap_security_get_authentication_required (security); - *has_key = TRUE; + if (rsn_flags != NM_802_11_AP_SEC_NONE) + return TRUE; - return auth_required; + return FALSE; } @@ -1952,11 +1929,12 @@ merge_scanned_ap (NMDevice80211Wireless *dev, nm_ap_list_iter_free (iter); if (found_ap) { - nm_ap_set_capabilities (found_ap, nm_ap_get_capabilities (merge_ap)); + nm_ap_set_flags (found_ap, nm_ap_get_flags (merge_ap)); + nm_ap_set_wpa_flags (found_ap, nm_ap_get_wpa_flags (merge_ap)); + nm_ap_set_rsn_flags (found_ap, nm_ap_get_rsn_flags (merge_ap)); nm_ap_set_strength (found_ap, nm_ap_get_strength (merge_ap)); nm_ap_set_last_seen (found_ap, nm_ap_get_last_seen (merge_ap)); nm_ap_set_broadcast (found_ap, nm_ap_get_broadcast (merge_ap)); - nm_ap_set_capabilities (found_ap, nm_ap_get_capabilities (merge_ap)); /* If the AP is noticed in a scan, it's automatically no longer * artificial, since it clearly exists somewhere. @@ -2178,13 +2156,13 @@ link_timeout_cb (gpointer user_data) * another one. */ if ((nm_device_get_state (dev) == NM_DEVICE_STATE_CONFIG) - && (ap_is_auth_required (ap, &has_key) && has_key)) { + && ap_auth_enforced (ap)) { /* Association/authentication failed, we must have bad encryption key */ nm_info ("Activation (%s/wireless): disconnected during association," " asking for new key.", nm_device_get_iface (dev)); cleanup_association_attempt (self, TRUE); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); - nm_dbus_get_user_key_for_network (dev, req, TRUE); + // FIXME: get secrets from the info-daemon } else { nm_info ("%s: link timed out.", nm_device_get_iface (dev)); nm_device_set_active_link (dev, FALSE); @@ -2546,27 +2524,28 @@ supplicant_connection_timeout_cb (gpointer user_data) cleanup_association_attempt (self, TRUE); - /* Timed out waiting for authentication success; if the security method - * in use does not require access point side authentication (Open System + /* Timed out waiting for authentication success; if the security in use + * does not require access point side authentication (Open System * WEP, for example) then we are likely using the wrong authentication * algorithm or key. Request new one from the user. */ - if (!ap_is_auth_required (ap, &has_key) && has_key) { - /* Activation failed, we must have bad encryption key */ - nm_info ("Activation (%s/wireless): association took too long, " - "asking for new key.", - nm_device_get_iface (dev)); - - nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); - nm_dbus_get_user_key_for_network (dev, nm_device_get_act_request (dev), TRUE); - } else { + if (ap_auth_enforced (ap)) { if (nm_device_is_activating (dev)) { + /* Kicked off by the authenticator most likely */ nm_info ("Activation (%s/wireless): association took too long, " "failing activation.", nm_device_get_iface (dev)); nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED); } + } else { + /* Activation failed, encryption key is probably bad */ + nm_info ("Activation (%s/wireless): association took too long, " + "asking for new key.", + nm_device_get_iface (dev)); + + nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); + // FIXME: get secrets from the info-daemon } return FALSE; @@ -2650,10 +2629,14 @@ build_supplicant_config (NMDevice80211Wireless *self) goto error; } +#if 0 + // FIXME: send nm-802-11-wireless & nm-802-11-wireless-security + // settings objects to the supplicant if (!nm_ap_security_write_supplicant_config (nm_ap_get_security (ap), config, is_adhoc)) goto error; +#endif out: return config; @@ -2700,7 +2683,11 @@ real_act_stage1_prepare (NMDevice *dev) setting = (NMSettingWireless *) nm_connection_get_setting (nm_act_request_get_connection (req), "802-11-wireless"); g_assert (setting); +#if 0 success = nm_device_802_11_wireless_set_activation_ap (self, setting->ssid, NULL); +#endif + /* FIXME: match up 802-11-wireless and 802-11-wireless-security to an AP */ + success = NM_ACT_STAGE_RETURN_SUCCESS; return success ? NM_ACT_STAGE_RETURN_SUCCESS : NM_ACT_STAGE_RETURN_FAILURE; } @@ -2710,21 +2697,30 @@ static NMActStageReturn real_act_stage2_config (NMDevice *dev) { NMDevice80211Wireless * self = NM_DEVICE_802_11_WIRELESS (dev); - NMAccessPoint * ap = nm_device_802_11_wireless_get_activation_ap (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; const char * iface = nm_device_get_iface (dev); gboolean ask_user = FALSE; + NMAccessPoint * ap; NMSupplicantConfig * config = NULL; gulong id = 0; + NMActRequest * req; + NMConnection * connection; + + remove_supplicant_timeouts (self); + ap = nm_device_802_11_wireless_get_activation_ap (self); g_assert (ap); - remove_supplicant_timeouts (self); + req = nm_device_get_act_request (dev); + g_assert (req); - /* If we need an encryption key, get one */ - if (ap_need_key (self, ap, &ask_user)) { + connection = nm_act_request_get_connection (req); + g_assert (connection); + + /* If we need secrets, get them */ + if (ap_need_secrets (self, ap, connection, &ask_user)) { nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); - nm_dbus_get_user_key_for_network (dev, nm_device_get_act_request (dev), ask_user); + // FIXME: get secrets from info-daemon return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -2840,7 +2836,6 @@ real_act_stage4_ip_config_timeout (NMDevice *dev, NMAccessPoint * ap = nm_device_802_11_wireless_get_activation_ap (self); NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; NMIP4Config * real_config = NULL; - NMAPSecurity * security; gboolean has_key; g_return_val_if_fail (config != NULL, NM_ACT_STAGE_RETURN_FAILURE); @@ -2848,15 +2843,11 @@ real_act_stage4_ip_config_timeout (NMDevice *dev, g_assert (ap); - security = nm_ap_get_security (ap); - g_assert (security); - - /* If the security credentials' validity was not checked by any - * peer during authentication process, and DHCP times out, then + /* If nothing checks the security authentication information (as in + * Open System WEP for example), and DHCP times out, then * the encryption key is likely wrong. Ask the user for a new one. */ - if (!ap_is_auth_required (ap, &has_key) && has_key) - { + if (!ap_auth_enforced (ap)) { const GByteArray * ssid = nm_ap_get_ssid (ap); /* Activation failed, we must have bad encryption key */ @@ -2864,11 +2855,9 @@ real_act_stage4_ip_config_timeout (NMDevice *dev, nm_device_get_iface (dev), ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)"); nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH); - nm_dbus_get_user_key_for_network (dev, nm_device_get_act_request (dev), TRUE); + // FIXME: request new secrets from info-daemon ret = NM_ACT_STAGE_RETURN_POSTPONE; - } - else if (nm_ap_get_mode (ap) == IW_MODE_ADHOC) - { + } else if (nm_ap_get_mode (ap) == IW_MODE_ADHOC) { NMDevice80211WirelessClass * klass; NMDeviceClass * parent_class; @@ -2876,9 +2865,7 @@ real_act_stage4_ip_config_timeout (NMDevice *dev, klass = NM_DEVICE_802_11_WIRELESS_GET_CLASS (self); parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass)); ret = parent_class->act_stage4_ip_config_timeout (dev, &real_config); - } - else - { + } else { /* Non-encrypted network and IP configure failed. Alert the user. */ ret = NM_ACT_STAGE_RETURN_FAILURE; } @@ -2914,7 +2901,7 @@ activation_success_handler (NMDevice *dev) if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap))) nm_ap_set_address (ap, &addr); - nm_dbus_update_network_info (ap, automatic); + // FIXME: send connection + new BSSID to info-daemon } @@ -2970,9 +2957,6 @@ real_activation_cancel_handler (NMDevice *dev) parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass)); parent_class->activation_cancel_handler (dev); - if (nm_device_get_state (dev) == NM_DEVICE_STATE_NEED_AUTH) - nm_dbus_cancel_get_user_key_for_network (nm_device_get_act_request (dev)); - cleanup_association_attempt (self, TRUE); } @@ -3119,7 +3103,7 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass) g_param_spec_uint (NM_DEVICE_802_11_WIRELESS_CAPABILITIES, "Wireless Capabilities", "Wireless Capabilities", - 0, G_MAXUINT32, NM_802_11_CAP_NONE, + 0, G_MAXUINT32, NM_802_11_DEVICE_CAP_NONE, G_PARAM_READABLE)); /* Signals */ diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c index 7eaa7bbd2d..2177ddec9b 100644 --- a/src/nm-device-interface.c +++ b/src/nm-device-interface.c @@ -4,6 +4,7 @@ static gboolean impl_device_activate (NMDeviceInterface *device, GHashTable *connection_hash, + const char *specific_object, GError **err); static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err); @@ -156,17 +157,22 @@ nm_device_interface_get_type (void) void nm_device_interface_activate (NMDeviceInterface *device, NMConnection *connection, + const char *specific_object, gboolean user_requested) { g_return_if_fail (NM_IS_DEVICE_INTERFACE (device)); g_return_if_fail (connection != NULL); - NM_DEVICE_INTERFACE_GET_INTERFACE (device)->activate (device, connection, user_requested); + NM_DEVICE_INTERFACE_GET_INTERFACE (device)->activate (device, + connection, + specific_object, + user_requested); } static gboolean impl_device_activate (NMDeviceInterface *device, GHashTable *connection_hash, + const char *specific_object, GError **err) { NMConnection *connection; @@ -174,7 +180,7 @@ impl_device_activate (NMDeviceInterface *device, connection = nm_connection_new_from_hash (connection_hash); nm_connection_dump (connection); - nm_device_interface_activate (device, connection, TRUE); + nm_device_interface_activate (device, connection, specific_object, TRUE); return TRUE; } diff --git a/src/nm-device-interface.h b/src/nm-device-interface.h index 5b1d3ad0a1..4b368cd14d 100644 --- a/src/nm-device-interface.h +++ b/src/nm-device-interface.h @@ -45,7 +45,10 @@ struct _NMDeviceInterface { GTypeInterface g_iface; /* Methods */ - void (*activate) (NMDeviceInterface *device, NMConnection *connection, gboolean user_requested); + void (*activate) (NMDeviceInterface *device, + NMConnection *connection, + const char *specific_object, + gboolean user_requested); void (*deactivate) (NMDeviceInterface *device); /* Signals */ @@ -57,6 +60,7 @@ GType nm_device_interface_get_type (void); void nm_device_interface_activate (NMDeviceInterface *device, NMConnection *connection, + const char *specific_object, gboolean user_requested); void nm_device_interface_deactivate (NMDeviceInterface *device); diff --git a/src/nm-device.c b/src/nm-device.c index 9156a5ab62..4c538cb3e5 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -34,7 +34,6 @@ #include "NetworkManagerSystem.h" #include "nm-dhcp-manager.h" #include "nm-dbus-manager.h" -#include "nm-dbus-nmi.h" #include "nm-utils.h" #include "autoip.h" #include "nm-netlink.h" @@ -83,6 +82,7 @@ struct _NMDevicePrivate static void nm_device_activate (NMDeviceInterface *device, NMConnection *connection, + const char *specific_object, gboolean user_requested); static void nm_device_activate_schedule_stage5_ip_config_commit (NMDevice *self); @@ -1059,6 +1059,7 @@ nm_device_deactivate (NMDeviceInterface *device) static void nm_device_activate (NMDeviceInterface *device, NMConnection *connection, + const char *specific_object, gboolean user_requested) { NMDevice *self = NM_DEVICE (device); @@ -1081,7 +1082,7 @@ nm_device_activate (NMDeviceInterface *device, } nm_info ("Activating device %s", nm_device_get_iface (self)); - priv->act_request = nm_act_request_new (connection, user_requested); + priv->act_request = nm_act_request_new (connection, specific_object, user_requested); nm_device_activate_schedule_stage1_device_prepare (self); } diff --git a/src/vpn-manager/nm-dbus-vpn.c b/src/vpn-manager/nm-dbus-vpn.c index 157d7c4ca3..86850729c2 100644 --- a/src/vpn-manager/nm-dbus-vpn.c +++ b/src/vpn-manager/nm-dbus-vpn.c @@ -34,6 +34,133 @@ #include "nm-utils.h" #include "nm-dbus-manager.h" +/* + * Pending Call Debug stuff + * + */ +typedef struct PCallInfo +{ + DBusPendingCall * pcall; + char * caller; + guint32 id; + GTimeVal start; +} PCallInfo; + +static GStaticMutex pcall_mutex = G_STATIC_MUTEX_INIT; +static GHashTable * pcall_table = NULL; +static guint32 pcall_gid = 0; +static guint32 pcall_pending = 0; + + +DBusPendingCall * +nm_dbus_send_with_callback (DBusConnection *connection, + DBusMessage *msg, + DBusPendingCallNotifyFunction func, + gpointer data, + DBusFreeFunction free_func, + const char *caller) +{ + PCallInfo * info = NULL; + DBusPendingCall * pcall = NULL; + + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (msg != NULL, NULL); + g_return_val_if_fail (func != NULL, NULL); + g_return_val_if_fail (caller != NULL, NULL); + + if (!(info = g_malloc0 (sizeof (PCallInfo)))) + { + g_warning ("Error: '%s' couldn't allocate memory for tracking PCall.", caller); + if (free_func) + (*free_func)(data); + return NULL; + } + + dbus_connection_send_with_reply (connection, msg, &pcall, -1); + if (!pcall) + { + g_warning ("Error: '%s' couldn't send dbus message.", caller); + if (free_func) + (*free_func)(data); + g_free (info); + return NULL; + } + dbus_pending_call_set_notify (pcall, func, data, free_func); + + info->caller = g_strdup (caller); + info->pcall = pcall; + g_get_current_time (&info->start); + dbus_pending_call_ref (pcall); + + g_static_mutex_lock (&pcall_mutex); + info->id = pcall_gid++; + pcall_pending++; + + if (!pcall_table) + pcall_table = g_hash_table_new (g_direct_hash, g_direct_equal); + g_hash_table_insert (pcall_table, pcall, info); + +#ifdef DBUS_PENDING_CALL_DEBUG + nm_info ("PCall Debug: new id %d (%p), from '%s' (%s), " + "%d pending.", info->id, pcall, info->caller, + dbus_message_get_member (msg), pcall_pending); +#endif + + g_static_mutex_unlock (&pcall_mutex); + + return pcall; +} + +void +nm_dbus_send_with_callback_replied (DBusPendingCall *pcall, + const char *caller) +{ + PCallInfo * info; +#ifdef DBUS_PENDING_CALL_DEBUG + GTimeVal now; + long elapsed_ms = 0; +#endif + + g_return_if_fail (pcall != NULL); + g_return_if_fail (caller != NULL); + + g_static_mutex_lock (&pcall_mutex); + if (!(info = g_hash_table_lookup (pcall_table, pcall))) + { + nm_warning ("Error: couldn't find pending call %p in tracking" + " table.", pcall); + goto out; + } + + pcall_pending--; +#ifdef DBUS_PENDING_CALL_DEBUG + g_get_current_time (&now); + if (info->start.tv_usec > now.tv_usec) + { + now.tv_sec--; + now.tv_usec = G_USEC_PER_SEC - (info->start.tv_usec - now.tv_usec); + } + else + now.tv_usec -= info->start.tv_usec; + now.tv_sec -= info->start.tv_sec; + elapsed_ms = now.tv_sec * G_USEC_PER_SEC + now.tv_usec; + elapsed_ms /= 1000; + + nm_info ("PCall Debug: unregistered ID %d (%p), %s -> %s," + " %lums elapsed. Total pending: %d", info->id, info->pcall, info->caller, + caller, elapsed_ms, pcall_pending); +#endif + + g_hash_table_remove (pcall_table, pcall); + g_free (info->caller); + dbus_pending_call_unref (info->pcall); + g_free (info); + +out: + g_static_mutex_unlock (&pcall_mutex); +} + + static DBusMessage * new_invalid_vpn_connection_error (DBusMessage *replyto) diff --git a/test/nm-tool.c b/test/nm-tool.c index 1c749fc4be..45167c896c 100644 --- a/test/nm-tool.c +++ b/test/nm-tool.c @@ -147,11 +147,13 @@ detail_network (gpointer data, gpointer user_data) const char *active_bssid = (const char *) user_data; GString *str; gboolean active = FALSE; - guint32 capabilities; + guint32 flags, wpa_flags, rsn_flags; GByteArray * ssid; char *tmp; - capabilities = nm_access_point_get_capabilities (ap); + flags = nm_access_point_get_flags (ap); + wpa_flags = nm_access_point_get_wpa_flags (ap); + rsn_flags = nm_access_point_get_rsn_flags (ap); if (active_bssid) { char *current_bssid = nm_access_point_get_hw_address (ap); @@ -169,16 +171,21 @@ detail_network (gpointer data, gpointer user_data) nm_access_point_get_rate (ap) / 1024, nm_access_point_get_strength (ap)); - if (nm_access_point_is_encrypted (ap)) + if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags != NM_802_11_AP_SEC_NONE) + && (rsn_flags != NM_802_11_AP_SEC_NONE)) g_string_append (str, ", Encrypted: "); - if (capabilities & NM_802_11_CAP_PROTO_WEP) + if ( (flags & NM_802_11_AP_FLAGS_PRIVACY) + && (wpa_flags == NM_802_11_AP_SEC_NONE) + && (rsn_flags == NM_802_11_AP_SEC_NONE)) g_string_append (str, " WEP"); - if (capabilities & NM_802_11_CAP_PROTO_WPA) + if (wpa_flags != NM_802_11_AP_SEC_NONE) g_string_append (str, " WPA"); - if (capabilities & NM_802_11_CAP_PROTO_WPA2) + if (rsn_flags != NM_802_11_AP_SEC_NONE) g_string_append (str, " WPA2"); - if (capabilities & NM_802_11_CAP_KEY_MGMT_802_1X) + if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + || (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) g_string_append (str, " Enterprise"); /* FIXME: broadcast/hidden */ @@ -277,20 +284,20 @@ detail_device (gpointer data, gpointer user_data) /* Wireless specific information */ if ((NM_IS_DEVICE_802_11_WIRELESS (device))) { - guint32 wireless_caps; + guint32 wcaps; NMAccessPoint *active_ap = NULL; char *active_bssid = NULL; GSList *networks; printf ("\n Wireless Settings\n"); - wireless_caps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (device)); + wcaps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (device)); - if (wireless_caps & NM_802_11_CAP_PROTO_WEP) + if (wcaps & (NM_802_11_DEVICE_CAP_CIPHER_WEP40 | NM_802_11_DEVICE_CAP_CIPHER_WEP104)) print_string (" WEP Encryption", "yes"); - if (wireless_caps & NM_802_11_CAP_PROTO_WPA) + if (wcaps & NM_802_11_DEVICE_CAP_WPA) print_string (" WPA Encryption", "yes"); - if (wireless_caps & NM_802_11_CAP_PROTO_WPA2) + if (wcaps & NM_802_11_DEVICE_CAP_RSN) print_string (" WPA2 Encryption", "yes"); if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { diff --git a/utils/nm-utils.c b/utils/nm-utils.c index 98b6bbb626..acd8204cb6 100644 --- a/utils/nm-utils.c +++ b/utils/nm-utils.c @@ -351,130 +351,3 @@ out: } -/* - * Pending Call Debug stuff - * - */ -typedef struct PCallInfo -{ - DBusPendingCall * pcall; - char * caller; - guint32 id; - GTimeVal start; -} PCallInfo; - -static GStaticMutex pcall_mutex = G_STATIC_MUTEX_INIT; -static GHashTable * pcall_table = NULL; -static guint32 pcall_gid = 0; -static guint32 pcall_pending = 0; - - -DBusPendingCall * -nm_dbus_send_with_callback (DBusConnection *connection, - DBusMessage *msg, - DBusPendingCallNotifyFunction func, - gpointer data, - DBusFreeFunction free_func, - const char *caller) -{ - PCallInfo * info = NULL; - DBusPendingCall * pcall = NULL; - - g_return_val_if_fail (connection != NULL, NULL); - g_return_val_if_fail (msg != NULL, NULL); - g_return_val_if_fail (func != NULL, NULL); - g_return_val_if_fail (caller != NULL, NULL); - - if (!(info = g_malloc0 (sizeof (PCallInfo)))) - { - g_warning ("Error: '%s' couldn't allocate memory for tracking PCall.", caller); - if (free_func) - (*free_func)(data); - return NULL; - } - - dbus_connection_send_with_reply (connection, msg, &pcall, -1); - if (!pcall) - { - g_warning ("Error: '%s' couldn't send dbus message.", caller); - if (free_func) - (*free_func)(data); - g_free (info); - return NULL; - } - dbus_pending_call_set_notify (pcall, func, data, free_func); - - info->caller = g_strdup (caller); - info->pcall = pcall; - g_get_current_time (&info->start); - dbus_pending_call_ref (pcall); - - g_static_mutex_lock (&pcall_mutex); - info->id = pcall_gid++; - pcall_pending++; - - if (!pcall_table) - pcall_table = g_hash_table_new (g_direct_hash, g_direct_equal); - g_hash_table_insert (pcall_table, pcall, info); - -#ifdef DBUS_PENDING_CALL_DEBUG - nm_info ("PCall Debug: new id %d (%p), from '%s' (%s), " - "%d pending.", info->id, pcall, info->caller, - dbus_message_get_member (msg), pcall_pending); -#endif - - g_static_mutex_unlock (&pcall_mutex); - - return pcall; -} - -void -nm_dbus_send_with_callback_replied (DBusPendingCall *pcall, - const char *caller) -{ - PCallInfo * info; -#ifdef DBUS_PENDING_CALL_DEBUG - GTimeVal now; - long elapsed_ms = 0; -#endif - - g_return_if_fail (pcall != NULL); - g_return_if_fail (caller != NULL); - - g_static_mutex_lock (&pcall_mutex); - if (!(info = g_hash_table_lookup (pcall_table, pcall))) - { - nm_warning ("Error: couldn't find pending call %p in tracking" - " table.", pcall); - goto out; - } - - pcall_pending--; -#ifdef DBUS_PENDING_CALL_DEBUG - g_get_current_time (&now); - if (info->start.tv_usec > now.tv_usec) - { - now.tv_sec--; - now.tv_usec = G_USEC_PER_SEC - (info->start.tv_usec - now.tv_usec); - } - else - now.tv_usec -= info->start.tv_usec; - now.tv_sec -= info->start.tv_sec; - elapsed_ms = now.tv_sec * G_USEC_PER_SEC + now.tv_usec; - elapsed_ms /= 1000; - - nm_info ("PCall Debug: unregistered ID %d (%p), %s -> %s," - " %lums elapsed. Total pending: %d", info->id, info->pcall, info->caller, - caller, elapsed_ms, pcall_pending); -#endif - - g_hash_table_remove (pcall_table, pcall); - g_free (info->caller); - dbus_pending_call_unref (info->pcall); - g_free (info); - -out: - g_static_mutex_unlock (&pcall_mutex); -} - - diff --git a/utils/nm-utils.h b/utils/nm-utils.h index d43526c752..19e90c4a87 100644 --- a/utils/nm-utils.h +++ b/utils/nm-utils.h @@ -131,15 +131,4 @@ gchar *nm_dbus_unescape_object_path (const gchar *object_path); char *nm_utils_ssid_to_utf8 (const char *ssid, guint32 len); -/* #define DBUS_PENDING_CALL_DEBUG */ - -DBusPendingCall * nm_dbus_send_with_callback (DBusConnection *connection, - DBusMessage *msg, - DBusPendingCallNotifyFunction func, - gpointer data, - DBusFreeFunction free_func, - const char *caller); -void nm_dbus_send_with_callback_replied (DBusPendingCall *pcall, - const char *caller); - #endif /* NM_UTILS_H */ |