From a22b039c11353d4ba1764cd86ce2ab8917bf1765 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 16 Dec 2005 15:04:40 +0000 Subject: [PATCH] 2005-12-16 Dan Williams * Kill auth_method for access points, since that's now done by NMAPSecurity objects * Add a copy-constructor of sorts to NMAPSecurity (how do you do this properly in glib???) git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1200 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 8 +++++ src/NetworkManagerAP.c | 55 ++++------------------------ src/NetworkManagerAP.h | 5 --- src/NetworkManagerAPList.c | 2 -- src/NetworkManagerDbus.c | 1 + src/NetworkManagerDevice.c | 70 +++++++++--------------------------- src/NetworkManagerPolicy.c | 4 --- src/nm-ap-security-private.h | 2 ++ src/nm-ap-security-wep.c | 12 +++++++ src/nm-ap-security-wpa-psk.c | 13 +++++++ src/nm-ap-security.c | 31 ++++++++++++++++ src/nm-ap-security.h | 4 +++ 12 files changed, 95 insertions(+), 112 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c0c9518d..271dbcc71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-12-16 Dan Williams + + * Kill auth_method for access points, since that's now done + by NMAPSecurity objects + + * Add a copy-constructor of sorts to NMAPSecurity + (how do you do this properly in glib???) + 2005-12-15 Dan Williams * Exorcise encryption key hashing on APs diff --git a/src/NetworkManagerAP.c b/src/NetworkManagerAP.c index f0da86dac..b397d83d1 100644 --- a/src/NetworkManagerAP.c +++ b/src/NetworkManagerAP.c @@ -55,11 +55,6 @@ struct NMAccessPoint NMAPSecurity * security; GTimeVal timestamp; GSList * user_addresses; - - /* Soon to be banished */ - char * enc_key; - NMEncKeyType enc_type; - int auth_method; /* from wireless.h; -1 is unknown, zero is none */ }; /* This is a controlled list. Want to add to it? Stop. Ask first. */ @@ -90,7 +85,6 @@ NMAccessPoint * nm_ap_new (void) } ap->mode = IW_MODE_INFRA; - ap->auth_method = -1; ap->refcount = 1; return (ap); @@ -133,10 +127,10 @@ NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap) new_ap->rate = src_ap->rate; new_ap->capabilities = src_ap->capabilities; - if (src_ap->enc_key && (strlen (src_ap->enc_key) > 0)) - new_ap->enc_key = g_strdup (src_ap->enc_key); + if (src_ap->security) + new_ap->security = nm_ap_security_new_copy (src_ap->security); - return (new_ap); + return new_ap; } @@ -159,7 +153,6 @@ void nm_ap_unref (NMAccessPoint *ap) { g_free (ap->essid); g_free (ap->address); - g_free (ap->enc_key); g_slist_foreach (ap->user_addresses, (GFunc)g_free, NULL); g_slist_free (ap->user_addresses); @@ -167,7 +160,6 @@ void nm_ap_unref (NMAccessPoint *ap) g_object_unref (G_OBJECT (ap->security)); ap->essid = NULL; - ap->enc_key = NULL; g_free (ap); memset (ap, 0, sizeof (NMAccessPoint)); @@ -229,7 +221,9 @@ gboolean nm_ap_get_encrypted (const NMAccessPoint *ap) { g_return_val_if_fail (ap != NULL, FALSE); - return (ap->capabilities & NM_802_11_CAP_PROTO_WEP); + return ((ap->capabilities & NM_802_11_CAP_PROTO_WEP) + || (ap->capabilities & NM_802_11_CAP_PROTO_WPA) + || (ap->capabilities & NM_802_11_CAP_PROTO_WPA2)); } void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy) @@ -242,38 +236,6 @@ void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy) ap->capabilities &= ~NM_802_11_CAP_PROTO_WEP; } - -/* - * Return the encryption method the user specified for this access point. - * - */ -NMEncKeyType nm_ap_get_enc_type (const NMAccessPoint *ap) -{ - g_return_val_if_fail (ap != NULL, TRUE); - - return (ap->enc_type); -} - - -/* - * Get/set functions for auth_method - * - */ -int nm_ap_get_auth_method (const NMAccessPoint *ap) -{ - g_return_val_if_fail (ap != NULL, -1); - - return (ap->auth_method); -} - -void nm_ap_set_auth_method (NMAccessPoint *ap, int auth_method) -{ - g_return_if_fail (ap != NULL); - - ap->auth_method = auth_method; -} - - /* * Accessorts for AP security info * @@ -296,10 +258,7 @@ void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security) } if (security) - { - g_object_ref (G_OBJECT (security)); - ap->security = security; - } + ap->security = nm_ap_security_new_copy (security); } diff --git a/src/NetworkManagerAP.h b/src/NetworkManagerAP.h index daea7cdd0..9db33f027 100644 --- a/src/NetworkManagerAP.h +++ b/src/NetworkManagerAP.h @@ -43,11 +43,6 @@ void nm_ap_set_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp); char * nm_ap_get_essid (const NMAccessPoint *ap); void nm_ap_set_essid (NMAccessPoint *ap, const char *essid); -NMEncKeyType nm_ap_get_enc_type (const NMAccessPoint *ap); - -int nm_ap_get_auth_method (const NMAccessPoint *ap); -void nm_ap_set_auth_method (NMAccessPoint *ap, int auth_method); - gboolean nm_ap_get_encrypted (const NMAccessPoint *ap); void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy); diff --git a/src/NetworkManagerAPList.c b/src/NetworkManagerAPList.c index e2e8652d3..d47d18930 100644 --- a/src/NetworkManagerAPList.c +++ b/src/NetworkManagerAPList.c @@ -458,7 +458,6 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap); nm_ap_set_encrypted (list_ap_addr, nm_ap_get_encrypted (merge_ap)); - nm_ap_set_auth_method (list_ap_addr, nm_ap_get_auth_method (merge_ap)); if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap_addr)) { nm_ap_set_strength (list_ap_addr, nm_ap_get_strength (merge_ap)); @@ -482,7 +481,6 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me const GTimeVal *list_ap_essid_seen = nm_ap_get_last_seen (list_ap_essid); nm_ap_set_encrypted (list_ap_essid, nm_ap_get_encrypted (merge_ap)); - nm_ap_set_auth_method (list_ap_essid, nm_ap_get_auth_method (merge_ap)); if (!((list_ap_essid_seen->tv_sec == merge_ap_seen->tv_sec) && (nm_ap_get_strength (list_ap_essid) >= nm_ap_get_strength (merge_ap)))) diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index 95ed9101b..02383eb8d 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -826,6 +826,7 @@ static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data ap = nm_ap_new (); nm_ap_set_essid (ap, essid); nm_ap_set_security (ap, security); + g_object_unref (G_OBJECT (security)); /* set_security copies the object */ timestamp = g_malloc0 (sizeof (GTimeVal)); timestamp->tv_sec = timestamp_secs; diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 9e944dd5a..49ddd1251 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -310,14 +310,7 @@ void nm_device_copy_allowed_to_dev_list (NMDevice *dev, NMAccessPointList *allow dev_list = nm_device_ap_list_get (dev); while ((src_ap = nm_ap_list_iter_next (iter))) { - NMAccessPoint *dst_ap = nm_ap_new_from_ap (src_ap); - - /* Assume that if the allowed list AP has a saved encryption - * key that the AP is encrypted. - */ - if ( (nm_ap_get_auth_method (src_ap) == IW_AUTH_ALG_OPEN_SYSTEM) - || (nm_ap_get_auth_method (src_ap) == IW_AUTH_ALG_SHARED_KEY)) - nm_ap_set_encrypted (dst_ap, TRUE); + NMAccessPoint * dst_ap = nm_ap_new_from_ap (src_ap); nm_ap_list_append_ap (dev_list, dst_ap); nm_ap_unref (dst_ap); @@ -1475,11 +1468,11 @@ void nm_device_get_ap_address (NMDevice *dev, struct ether_addr *addr) */ void nm_device_set_enc_key (NMDevice *dev, const char *key, int auth_method) { - NMSock *sk; - struct iwreq wreq; - int keylen; - unsigned char safe_key[IW_ENCODING_TOKEN_MAX + 1]; - gboolean set_key = FALSE; + NMSock * sk; + struct iwreq wreq; + int keylen; + unsigned char safe_key[IW_ENCODING_TOKEN_MAX + 1]; + gboolean set_key = FALSE; g_return_if_fail (dev != NULL); g_return_if_fail (nm_device_is_802_11_wireless (dev)); @@ -2582,30 +2575,10 @@ static void nm_device_wireless_configure (NMActRequest *req) if (!link) { - if (nm_ap_get_auth_method (ap) == IW_AUTH_ALG_OPEN_SYSTEM) - { - nm_debug ("Activation (%s/wireless): no hardware link to '%s' in Open System mode, trying Shared Key.", - nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); - /* Back down to Shared Key mode */ - nm_ap_set_auth_method (ap, IW_AUTH_ALG_SHARED_KEY); - success = FALSE; - continue; - } - else if (nm_ap_get_auth_method (ap) == IW_AUTH_ALG_SHARED_KEY) - { - /* Didn't work in Shared Key either. */ - nm_debug ("Activation (%s/wireless): no hardware link to '%s' in Shared Key mode, need correct key?", - nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); - nm_dbus_get_user_key_for_network (data->dbus_connection, req, TRUE); - break; - } - else - { - nm_debug ("Activation (%s/wireless): no hardware link to '%s' in non-encrypted mode.", - nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); - nm_policy_schedule_activation_failed (req); - break; - } + nm_debug ("Activation (%s/wireless): no hardware link to '%s'.", + nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); + nm_policy_schedule_activation_failed (req); + break; } } @@ -2972,25 +2945,17 @@ static gboolean nm_device_activate_stage4_ip_config_timeout (NMActRequest *req) else if (nm_device_is_802_11_wireless (dev)) { NMAccessPoint *ap = nm_act_request_get_ap (req); + NMAPSecurity * security; g_assert (ap); - /* For those broken cards that report successful hardware link even when WEP key is wrong, - * and also for Open System mode (where you cannot know WEP key is wrong ever), we try to - * do DHCP and if that fails, fall back to next auth mode and try again. - */ - if (nm_ap_get_auth_method (ap) == IW_AUTH_ALG_OPEN_SYSTEM) + security = nm_ap_get_security (ap); + + /* FIXME: should we only ask for a new key if the activation request is user-requested? */ + if (ap && (nm_ap_security_get_we_cipher (security) != IW_AUTH_CIPHER_NONE)) { - /* Back down to Shared Key mode */ - nm_debug ("Activation (%s/wireless): could not get IP configuration info for '%s' in Open System mode, trying Shared Key.", - nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); - nm_ap_set_auth_method (ap, IW_AUTH_ALG_SHARED_KEY); - nm_device_activate_schedule_stage2_device_config (req); - } - else if ((nm_ap_get_auth_method (ap) == IW_AUTH_ALG_SHARED_KEY)) - { - /* Shared Key mode failed, we must have bad WEP key */ - nm_debug ("Activation (%s/wireless): could not get IP configuration info for '%s' in Shared Key mode, asking for new key.", + /* Activation failed, we must have bad WEP key */ + nm_debug ("Activation (%s/wireless): could not get IP configuration info for '%s', asking for new key.", nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)"); nm_dbus_get_user_key_for_network (data->dbus_connection, req, TRUE); } @@ -4519,7 +4484,6 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin /* New AP with some defaults */ ap = nm_ap_new (); nm_ap_set_address (ap, (const struct ether_addr *)(iwe->u.ap_addr.sa_data)); - nm_ap_set_auth_method (ap, IW_AUTH_ALG_OPEN_SYSTEM); nm_ap_set_mode (ap, IW_MODE_INFRA); break; case SIOCGIWMODE: diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index a16758d3c..7d7fb2a31 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -67,10 +67,6 @@ static gboolean nm_policy_activation_finish (NMActRequest *req) /* Cache details in the info-daemon since the connect was successful */ nm_dbus_update_network_info (data->dbus_connection, ap, nm_act_request_get_user_requested (req)); - /* Cache the correct auth method in our AP list too */ - if ((tmp_ap = nm_ap_list_get_ap_by_essid (data->allowed_ap_list, nm_ap_get_essid (ap)))) - nm_ap_set_auth_method (tmp_ap, nm_ap_get_auth_method (ap)); - nm_device_get_ap_address (dev, &addr); if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap))) nm_ap_set_address (ap, &addr); diff --git a/src/nm-ap-security-private.h b/src/nm-ap-security-private.h index b675fb7a6..13b1d7084 100644 --- a/src/nm-ap-security-private.h +++ b/src/nm-ap-security-private.h @@ -30,4 +30,6 @@ 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 index 069eea86d..87d936fa0 100644 --- a/src/nm-ap-security-wep.c +++ b/src/nm-ap-security-wep.c @@ -97,6 +97,17 @@ real_device_setup (NMAPSecurity *instance, NMDevice * dev) return 0; } +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) { @@ -111,6 +122,7 @@ 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_wpa_supplicant_config_func = real_write_wpa_supplicant_config; par_class->device_setup_func = real_device_setup; diff --git a/src/nm-ap-security-wpa-psk.c b/src/nm-ap-security-wpa-psk.c index 8401be6dd..d9a8983d0 100644 --- a/src/nm-ap-security-wpa-psk.c +++ b/src/nm-ap-security-wpa-psk.c @@ -97,6 +97,18 @@ real_device_setup (NMAPSecurity *self, NMDevice * dev) return 0; } +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) { @@ -112,6 +124,7 @@ 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->write_wpa_supplicant_config_func = real_write_wpa_supplicant_config; par_class->device_setup_func = real_device_setup; diff --git a/src/nm-ap-security.c b/src/nm-ap-security.c index b75138fe8..8fa3a1918 100644 --- a/src/nm-ap-security.c +++ b/src/nm-ap-security.c @@ -138,6 +138,15 @@ nm_ap_security_set_key (NMAPSecurity *self, const char *key, int key_len) memcpy (self->priv->key, key, key_len); } +static NMAPSecurity * +real_copy_constructor (NMAPSecurity *self) +{ + NMAPSecurity * dst = nm_ap_security_new (self->priv->we_cipher); + + nm_ap_security_copy_properties (self, dst); + return dst; +} + static int real_serialize (NMAPSecurity *self, DBusMessageIter *iter) { @@ -221,6 +230,27 @@ nm_ap_security_serialize (NMAPSecurity *self, DBusMessageIter *iter) 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) +{ + int key_len; + + 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); + 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) @@ -276,6 +306,7 @@ nm_ap_security_class_init (NMAPSecurityClass *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_wpa_supplicant_config_func = real_write_wpa_supplicant_config; klass->device_setup_func = real_device_setup; diff --git a/src/nm-ap-security.h b/src/nm-ap-security.h index 001879a41..5ecf03ba9 100644 --- a/src/nm-ap-security.h +++ b/src/nm-ap-security.h @@ -51,6 +51,8 @@ struct _NMAPSecurityClass GObjectClass parent; /* class members */ + NMAPSecurity * (*copy_constructor_func) (NMAPSecurity *self); + int (*serialize_func) (NMAPSecurity *self, DBusMessageIter *iter); void (*write_wpa_supplicant_config_func)(NMAPSecurity *self, int fd); @@ -61,6 +63,8 @@ struct _NMAPSecurityClass GType nm_ap_security_get_type (void); +NMAPSecurity * nm_ap_security_new_copy (NMAPSecurity *self); + NMAPSecurity * nm_ap_security_new_deserialize (DBusMessageIter *iter); int nm_ap_security_get_we_cipher (NMAPSecurity *self);