mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-09 04:05:56 +00:00
2008-10-30 Dan Williams <dcbw@redhat.com>
* libnm-util/libnm-util.ver libnm-util/nm-setting-wireless-security.c libnm-util/nm-setting-wireless-security.h - Make properties private and add accessor functions * libnm-util/nm-setting-wireless.c src/NetworkManagerAP.c src/nm-device-wifi.c src/supplicant-manager/nm-supplicant-config.c system-settings/plugins/ifcfg-fedora/reader.c system-settings/plugins/ifcfg-suse/parser.c - Use wireless security accessors git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4237 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
4129798d51
commit
0d7b805152
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2008-10-30 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* libnm-util/libnm-util.ver
|
||||
libnm-util/nm-setting-wireless-security.c
|
||||
libnm-util/nm-setting-wireless-security.h
|
||||
- Make properties private and add accessor functions
|
||||
|
||||
* libnm-util/nm-setting-wireless.c
|
||||
src/NetworkManagerAP.c
|
||||
src/nm-device-wifi.c
|
||||
src/supplicant-manager/nm-supplicant-config.c
|
||||
system-settings/plugins/ifcfg-fedora/reader.c
|
||||
system-settings/plugins/ifcfg-suse/parser.c
|
||||
- Use wireless security accessors
|
||||
|
||||
2008-10-30 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/nm-device-ethernet.c
|
||||
|
|
|
@ -193,10 +193,33 @@ global:
|
|||
nm_setting_wireless_add_seen_bssid;
|
||||
nm_setting_wireless_get_num_seen_bssids;
|
||||
nm_setting_wireless_get_seen_bssid;
|
||||
nm_setting_wireless_security_add_proto;
|
||||
nm_setting_wireless_security_add_pairwise;
|
||||
nm_setting_wireless_security_add_group;
|
||||
nm_setting_wireless_security_clear_groups;
|
||||
nm_setting_wireless_security_clear_pairwise;
|
||||
nm_setting_wireless_security_clear_protos;
|
||||
nm_setting_wireless_security_error_get_type;
|
||||
nm_setting_wireless_security_error_quark;
|
||||
nm_setting_wireless_security_get_auth_alg;
|
||||
nm_setting_wireless_security_get_group;
|
||||
nm_setting_wireless_security_get_key_mgmt;
|
||||
nm_setting_wireless_security_get_leap_username;
|
||||
nm_setting_wireless_security_get_leap_password;
|
||||
nm_setting_wireless_security_get_num_groups;
|
||||
nm_setting_wireless_security_get_num_pairwise;
|
||||
nm_setting_wireless_security_get_num_protos;
|
||||
nm_setting_wireless_security_get_pairwise;
|
||||
nm_setting_wireless_security_get_proto;
|
||||
nm_setting_wireless_security_get_psk;
|
||||
nm_setting_wireless_security_get_type;
|
||||
nm_setting_wireless_security_get_wep_key;
|
||||
nm_setting_wireless_security_get_wep_tx_keyidx;
|
||||
nm_setting_wireless_security_new;
|
||||
nm_setting_wireless_security_remove_group;
|
||||
nm_setting_wireless_security_remove_pairwise;
|
||||
nm_setting_wireless_security_remove_proto;
|
||||
nm_setting_wireless_security_set_wep_key;
|
||||
nm_utils_deinit;
|
||||
nm_utils_escape_ssid;
|
||||
nm_utils_gvalue_hash_dup;
|
||||
|
|
|
@ -76,6 +76,24 @@ nm_setting_wireless_security_error_get_type (void)
|
|||
|
||||
G_DEFINE_TYPE (NMSettingWirelessSecurity, nm_setting_wireless_security, NM_TYPE_SETTING)
|
||||
|
||||
#define NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *key_mgmt;
|
||||
guint32 wep_tx_keyidx;
|
||||
char *auth_alg;
|
||||
GSList *proto; /* GSList of strings */
|
||||
GSList *pairwise; /* GSList of strings */
|
||||
GSList *group; /* GSList of strings */
|
||||
char *leap_username;
|
||||
char *wep_key0;
|
||||
char *wep_key1;
|
||||
char *wep_key2;
|
||||
char *wep_key3;
|
||||
char *psk;
|
||||
char *leap_password;
|
||||
} NMSettingWirelessSecurityPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_KEY_MGMT,
|
||||
|
@ -101,6 +119,311 @@ nm_setting_wireless_security_new (void)
|
|||
return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS_SECURITY, NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_key_mgmt (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->key_mgmt;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_setting_wireless_security_get_num_protos (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
|
||||
|
||||
return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->proto);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_proto (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (i <= g_slist_length (priv->proto), NULL);
|
||||
|
||||
return (const char *) g_slist_nth_data (priv->proto, i);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_setting_wireless_security_add_proto (NMSettingWirelessSecurity *setting, const char *proto)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
|
||||
g_return_val_if_fail (proto != NULL, FALSE);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
for (iter = priv->proto; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp (proto, (char *) iter->data))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv->proto = g_slist_append (priv->proto, g_ascii_strdown (proto, -1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_remove_proto (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *elt;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
elt = g_slist_nth (priv->proto, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
g_free (elt->data);
|
||||
priv->proto = g_slist_delete_link (priv->proto, elt);
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_clear_protos (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
nm_utils_slist_free (priv->proto, g_free);
|
||||
priv->proto = NULL;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_setting_wireless_security_get_num_pairwise (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
|
||||
|
||||
return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->pairwise);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_pairwise (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (i <= g_slist_length (priv->pairwise), NULL);
|
||||
|
||||
return (const char *) g_slist_nth_data (priv->pairwise, i);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_setting_wireless_security_add_pairwise (NMSettingWirelessSecurity *setting, const char *pairwise)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
|
||||
g_return_val_if_fail (pairwise != NULL, FALSE);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp (pairwise, (char *) iter->data))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv->pairwise = g_slist_append (priv->pairwise, g_ascii_strdown (pairwise, -1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_remove_pairwise (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *elt;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
elt = g_slist_nth (priv->pairwise, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
g_free (elt->data);
|
||||
priv->pairwise = g_slist_delete_link (priv->pairwise, elt);
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_clear_pairwise (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
nm_utils_slist_free (priv->pairwise, g_free);
|
||||
priv->pairwise = NULL;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_setting_wireless_security_get_num_groups (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
|
||||
|
||||
return g_slist_length (NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->group);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_group (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
g_return_val_if_fail (i <= g_slist_length (priv->group), NULL);
|
||||
|
||||
return (const char *) g_slist_nth_data (priv->group, i);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_setting_wireless_security_add_group (NMSettingWirelessSecurity *setting, const char *group)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE);
|
||||
g_return_val_if_fail (group != NULL, FALSE);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
for (iter = priv->group; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp (group, (char *) iter->data))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv->group = g_slist_append (priv->group, g_ascii_strdown (group, -1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_remove_group (NMSettingWirelessSecurity *setting, guint32 i)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
GSList *elt;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
elt = g_slist_nth (priv->group, i);
|
||||
g_return_if_fail (elt != NULL);
|
||||
|
||||
g_free (elt->data);
|
||||
priv->group = g_slist_delete_link (priv->group, elt);
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
nm_utils_slist_free (priv->group, g_free);
|
||||
priv->group = NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->psk;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_username;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->leap_password;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
g_return_val_if_fail (idx < 4, NULL);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
if (idx == 0)
|
||||
return priv->wep_key0;
|
||||
else if (idx == 1)
|
||||
return priv->wep_key1;
|
||||
else if (idx == 2)
|
||||
return priv->wep_key2;
|
||||
else if (idx == 3)
|
||||
return priv->wep_key3;
|
||||
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, guint32 idx, const char *key)
|
||||
{
|
||||
NMSettingWirelessSecurityPrivate *priv;
|
||||
|
||||
g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting));
|
||||
g_return_if_fail (idx < 4);
|
||||
|
||||
priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
switch (idx) {
|
||||
case 0:
|
||||
g_free (priv->wep_key0);
|
||||
priv->wep_key0 = g_strdup (key);
|
||||
break;
|
||||
case 1:
|
||||
g_free (priv->wep_key1);
|
||||
priv->wep_key1 = g_strdup (key);
|
||||
break;
|
||||
case 2:
|
||||
g_free (priv->wep_key2);
|
||||
priv->wep_key2 = g_strdup (key);
|
||||
break;
|
||||
case 3:
|
||||
g_free (priv->wep_key3);
|
||||
priv->wep_key3 = g_strdup (key);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_setting_wireless_security_get_wep_tx_keyidx (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), 0);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->wep_tx_keyidx;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting)
|
||||
{
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), NULL);
|
||||
|
||||
return NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting)->auth_alg;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
verify_wep_key (const char *key)
|
||||
{
|
||||
|
@ -146,6 +469,7 @@ static GPtrArray *
|
|||
need_secrets (NMSetting *setting)
|
||||
{
|
||||
NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
|
||||
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
|
||||
GPtrArray *secrets;
|
||||
|
||||
secrets = g_ptr_array_sized_new (4);
|
||||
|
@ -154,23 +478,23 @@ need_secrets (NMSetting *setting)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
g_assert (self->key_mgmt);
|
||||
g_assert (priv->key_mgmt);
|
||||
|
||||
/* Static WEP */
|
||||
if (strcmp (self->key_mgmt, "none") == 0) {
|
||||
if ((self->wep_tx_keyidx == 0) && !verify_wep_key (self->wep_key0)) {
|
||||
if (strcmp (priv->key_mgmt, "none") == 0) {
|
||||
if ((priv->wep_tx_keyidx == 0) && !verify_wep_key (priv->wep_key0)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
return secrets;
|
||||
}
|
||||
if ((self->wep_tx_keyidx == 1) && !verify_wep_key (self->wep_key1)) {
|
||||
if ((priv->wep_tx_keyidx == 1) && !verify_wep_key (priv->wep_key1)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
|
||||
return secrets;
|
||||
}
|
||||
if ((self->wep_tx_keyidx == 2) && !verify_wep_key (self->wep_key2)) {
|
||||
if ((priv->wep_tx_keyidx == 2) && !verify_wep_key (priv->wep_key2)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
|
||||
return secrets;
|
||||
}
|
||||
if ((self->wep_tx_keyidx == 3) && !verify_wep_key (self->wep_key3)) {
|
||||
if ((priv->wep_tx_keyidx == 3) && !verify_wep_key (priv->wep_key3)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
|
||||
return secrets;
|
||||
}
|
||||
|
@ -178,9 +502,9 @@ need_secrets (NMSetting *setting)
|
|||
}
|
||||
|
||||
/* WPA-PSK infrastructure and adhoc */
|
||||
if ( (strcmp (self->key_mgmt, "wpa-none") == 0)
|
||||
|| (strcmp (self->key_mgmt, "wpa-psk") == 0)) {
|
||||
if (!verify_wpa_psk (self->psk)) {
|
||||
if ( (strcmp (priv->key_mgmt, "wpa-none") == 0)
|
||||
|| (strcmp (priv->key_mgmt, "wpa-psk") == 0)) {
|
||||
if (!verify_wpa_psk (priv->psk)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_PSK);
|
||||
return secrets;
|
||||
}
|
||||
|
@ -188,18 +512,18 @@ need_secrets (NMSetting *setting)
|
|||
}
|
||||
|
||||
/* LEAP */
|
||||
if ( self->auth_alg
|
||||
&& !strcmp (self->auth_alg, "leap")
|
||||
&& !strcmp (self->key_mgmt, "ieee8021x")) {
|
||||
if (!self->leap_password || !strlen (self->leap_password)) {
|
||||
if ( priv->auth_alg
|
||||
&& !strcmp (priv->auth_alg, "leap")
|
||||
&& !strcmp (priv->key_mgmt, "ieee8021x")) {
|
||||
if (!priv->leap_password || !strlen (priv->leap_password)) {
|
||||
g_ptr_array_add (secrets, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
|
||||
return secrets;
|
||||
}
|
||||
goto no_secrets;
|
||||
}
|
||||
|
||||
if ( (strcmp (self->key_mgmt, "ieee8021x") == 0)
|
||||
|| (strcmp (self->key_mgmt, "wpa-eap") == 0)) {
|
||||
if ( (strcmp (priv->key_mgmt, "ieee8021x") == 0)
|
||||
|| (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
|
||||
/* Let caller check the 802.1x setting for secrets */
|
||||
goto no_secrets;
|
||||
}
|
||||
|
@ -226,13 +550,14 @@ static gboolean
|
|||
verify (NMSetting *setting, GSList *all_settings, GError **error)
|
||||
{
|
||||
NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (setting);
|
||||
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
|
||||
const char *valid_key_mgmt[] = { "none", "ieee8021x", "wpa-none", "wpa-psk", "wpa-eap", NULL };
|
||||
const char *valid_auth_algs[] = { "open", "shared", "leap", NULL };
|
||||
const char *valid_protos[] = { "wpa", "rsn", NULL };
|
||||
const char *valid_pairwise[] = { "wep40", "wep104", "tkip", "ccmp", NULL };
|
||||
const char *valid_groups[] = { "wep40", "wep104", "tkip", "ccmp", NULL };
|
||||
|
||||
if (!self->key_mgmt) {
|
||||
if (!priv->key_mgmt) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_PROPERTY,
|
||||
|
@ -240,7 +565,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!nm_utils_string_in_list (self->key_mgmt, valid_key_mgmt)) {
|
||||
if (!nm_utils_string_in_list (priv->key_mgmt, valid_key_mgmt)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -248,16 +573,16 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->auth_alg && !strcmp (self->auth_alg, "leap")) {
|
||||
if (priv->auth_alg && !strcmp (priv->auth_alg, "leap")) {
|
||||
/* LEAP must use ieee8021x key management */
|
||||
if (strcmp (self->key_mgmt, "ieee8021x")) {
|
||||
if (strcmp (priv->key_mgmt, "ieee8021x")) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X,
|
||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG);
|
||||
return FALSE;
|
||||
}
|
||||
if (!self->leap_username) {
|
||||
if (!priv->leap_username) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME,
|
||||
|
@ -265,8 +590,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if ( (strcmp (self->key_mgmt, "ieee8021x") == 0)
|
||||
|| (strcmp (self->key_mgmt, "wpa-eap") == 0)) {
|
||||
if ( (strcmp (priv->key_mgmt, "ieee8021x") == 0)
|
||||
|| (strcmp (priv->key_mgmt, "wpa-eap") == 0)) {
|
||||
/* Need an 802.1x setting too */
|
||||
if (!g_slist_find_custom (all_settings, NM_SETTING_802_1X_SETTING_NAME, find_setting_by_name)) {
|
||||
g_set_error (error,
|
||||
|
@ -278,7 +603,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
if (self->leap_username && !strlen (self->leap_username)) {
|
||||
if (priv->leap_username && !strlen (priv->leap_username)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -286,7 +611,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->wep_tx_keyidx > 3) {
|
||||
if (priv->wep_tx_keyidx > 3) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -294,28 +619,28 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->wep_key0 && !strlen (self->wep_key0)) {
|
||||
if (priv->wep_key0 && !strlen (priv->wep_key0)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
return FALSE;
|
||||
}
|
||||
if (self->wep_key1 && !strlen (self->wep_key1)) {
|
||||
if (priv->wep_key1 && !strlen (priv->wep_key1)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
|
||||
return FALSE;
|
||||
}
|
||||
if (self->wep_key2 && !strlen (self->wep_key2)) {
|
||||
if (priv->wep_key2 && !strlen (priv->wep_key2)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
|
||||
return FALSE;
|
||||
}
|
||||
if (self->wep_key3 && !strlen (self->wep_key3)) {
|
||||
if (priv->wep_key3 && !strlen (priv->wep_key3)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -323,7 +648,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->auth_alg && !nm_utils_string_in_list (self->auth_alg, valid_auth_algs)) {
|
||||
if (priv->auth_alg && !nm_utils_string_in_list (priv->auth_alg, valid_auth_algs)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -331,7 +656,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->proto && !nm_utils_string_slist_validate (self->proto, valid_protos)) {
|
||||
if (priv->proto && !nm_utils_string_slist_validate (priv->proto, valid_protos)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -339,15 +664,15 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->pairwise) {
|
||||
if (priv->pairwise) {
|
||||
const char *wpa_none[] = { "wpa-none", NULL };
|
||||
|
||||
/* For ad-hoc connections, pairwise must be "none" */
|
||||
if (nm_utils_string_in_list (self->key_mgmt, wpa_none)) {
|
||||
if (nm_utils_string_in_list (priv->key_mgmt, wpa_none)) {
|
||||
GSList *iter;
|
||||
gboolean found = FALSE;
|
||||
|
||||
for (iter = self->pairwise; iter; iter = g_slist_next (iter)) {
|
||||
for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp ((char *) iter->data, "none")) {
|
||||
found = TRUE;
|
||||
break;
|
||||
|
@ -364,7 +689,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
NM_SETTING_WIRELESS_SECURITY_PAIRWISE);
|
||||
return FALSE;
|
||||
}
|
||||
} else if (!nm_utils_string_slist_validate (self->pairwise, valid_pairwise)) {
|
||||
} else if (!nm_utils_string_slist_validate (priv->pairwise, valid_pairwise)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -373,7 +698,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
}
|
||||
|
||||
if (self->group && !nm_utils_string_slist_validate (self->group, valid_groups)) {
|
||||
if (priv->group && !nm_utils_string_slist_validate (priv->group, valid_groups)) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY,
|
||||
|
@ -382,8 +707,8 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
|
|||
}
|
||||
|
||||
/* Shared Key auth can only be used with WEP */
|
||||
if (self->auth_alg && !strcmp (self->auth_alg, "shared")) {
|
||||
if (self->key_mgmt && strcmp (self->key_mgmt, "none")) {
|
||||
if (priv->auth_alg && !strcmp (priv->auth_alg, "shared")) {
|
||||
if (priv->key_mgmt && strcmp (priv->key_mgmt, "none")) {
|
||||
g_set_error (error,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR,
|
||||
NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP,
|
||||
|
@ -405,22 +730,23 @@ static void
|
|||
finalize (GObject *object)
|
||||
{
|
||||
NMSettingWirelessSecurity *self = NM_SETTING_WIRELESS_SECURITY (object);
|
||||
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (self);
|
||||
|
||||
/* Strings first. g_free() already checks for NULLs so we don't have to */
|
||||
|
||||
g_free (self->key_mgmt);
|
||||
g_free (self->auth_alg);
|
||||
g_free (self->leap_username);
|
||||
g_free (self->wep_key0);
|
||||
g_free (self->wep_key1);
|
||||
g_free (self->wep_key2);
|
||||
g_free (self->wep_key3);
|
||||
g_free (self->psk);
|
||||
g_free (self->leap_password);
|
||||
g_free (priv->key_mgmt);
|
||||
g_free (priv->auth_alg);
|
||||
g_free (priv->leap_username);
|
||||
g_free (priv->wep_key0);
|
||||
g_free (priv->wep_key1);
|
||||
g_free (priv->wep_key2);
|
||||
g_free (priv->wep_key3);
|
||||
g_free (priv->psk);
|
||||
g_free (priv->leap_password);
|
||||
|
||||
nm_utils_slist_free (self->proto, g_free);
|
||||
nm_utils_slist_free (self->pairwise, g_free);
|
||||
nm_utils_slist_free (self->group, g_free);
|
||||
nm_utils_slist_free (priv->proto, g_free);
|
||||
nm_utils_slist_free (priv->pairwise, g_free);
|
||||
nm_utils_slist_free (priv->group, g_free);
|
||||
|
||||
G_OBJECT_CLASS (nm_setting_wireless_security_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -430,58 +756,59 @@ set_property (GObject *object, guint prop_id,
|
|||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY (object);
|
||||
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
const char *str;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_KEY_MGMT:
|
||||
g_free (setting->key_mgmt);
|
||||
setting->key_mgmt = g_value_dup_string (value);
|
||||
g_free (priv->key_mgmt);
|
||||
str = g_value_get_string (value);
|
||||
priv->key_mgmt = str ? g_ascii_strdown (str, -1) : NULL;
|
||||
break;
|
||||
case PROP_WEP_TX_KEYIDX:
|
||||
setting->wep_tx_keyidx = g_value_get_uint (value);
|
||||
priv->wep_tx_keyidx = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_AUTH_ALG:
|
||||
g_free (setting->auth_alg);
|
||||
setting->auth_alg = g_value_dup_string (value);
|
||||
g_free (priv->auth_alg);
|
||||
str = g_value_get_string (value);
|
||||
priv->auth_alg = str ? g_ascii_strdown (str, -1) : NULL;
|
||||
break;
|
||||
case PROP_PROTO:
|
||||
nm_utils_slist_free (setting->proto, g_free);
|
||||
setting->proto = g_value_dup_boxed (value);
|
||||
nm_utils_slist_free (priv->proto, g_free);
|
||||
priv->proto = g_value_dup_boxed (value);
|
||||
break;
|
||||
case PROP_PAIRWISE:
|
||||
nm_utils_slist_free (setting->pairwise, g_free);
|
||||
setting->pairwise = g_value_dup_boxed (value);
|
||||
nm_utils_slist_free (priv->pairwise, g_free);
|
||||
priv->pairwise = g_value_dup_boxed (value);
|
||||
break;
|
||||
case PROP_GROUP:
|
||||
nm_utils_slist_free (setting->group, g_free);
|
||||
setting->group = g_value_dup_boxed (value);
|
||||
nm_utils_slist_free (priv->group, g_free);
|
||||
priv->group = g_value_dup_boxed (value);
|
||||
break;
|
||||
case PROP_LEAP_USERNAME:
|
||||
g_free (setting->leap_username);
|
||||
setting->leap_username = g_value_dup_string (value);
|
||||
g_free (priv->leap_username);
|
||||
str = g_value_get_string (value);
|
||||
priv->leap_username = str ? g_ascii_strdown (str, -1) : NULL;
|
||||
break;
|
||||
case PROP_WEP_KEY0:
|
||||
g_free (setting->wep_key0);
|
||||
setting->wep_key0 = g_value_dup_string (value);
|
||||
nm_setting_wireless_security_set_wep_key (setting, 0, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_WEP_KEY1:
|
||||
g_free (setting->wep_key1);
|
||||
setting->wep_key1 = g_value_dup_string (value);
|
||||
nm_setting_wireless_security_set_wep_key (setting, 1, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_WEP_KEY2:
|
||||
g_free (setting->wep_key2);
|
||||
setting->wep_key2 = g_value_dup_string (value);
|
||||
nm_setting_wireless_security_set_wep_key (setting, 2, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_WEP_KEY3:
|
||||
g_free (setting->wep_key3);
|
||||
setting->wep_key3 = g_value_dup_string (value);
|
||||
nm_setting_wireless_security_set_wep_key (setting, 3, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_PSK:
|
||||
g_free (setting->psk);
|
||||
setting->psk = g_value_dup_string (value);
|
||||
g_free (priv->psk);
|
||||
priv->psk = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_LEAP_PASSWORD:
|
||||
g_free (setting->leap_password);
|
||||
setting->leap_password = g_value_dup_string (value);
|
||||
g_free (priv->leap_password);
|
||||
priv->leap_password = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
@ -494,46 +821,47 @@ get_property (GObject *object, guint prop_id,
|
|||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMSettingWirelessSecurity *setting = NM_SETTING_WIRELESS_SECURITY (object);
|
||||
NMSettingWirelessSecurityPrivate *priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_KEY_MGMT:
|
||||
g_value_set_string (value, setting->key_mgmt);
|
||||
g_value_set_string (value, priv->key_mgmt);
|
||||
break;
|
||||
case PROP_WEP_TX_KEYIDX:
|
||||
g_value_set_uint (value, setting->wep_tx_keyidx);
|
||||
g_value_set_uint (value, priv->wep_tx_keyidx);
|
||||
break;
|
||||
case PROP_AUTH_ALG:
|
||||
g_value_set_string (value, setting->auth_alg);
|
||||
g_value_set_string (value, priv->auth_alg);
|
||||
break;
|
||||
case PROP_PROTO:
|
||||
g_value_set_boxed (value, setting->proto);
|
||||
g_value_set_boxed (value, priv->proto);
|
||||
break;
|
||||
case PROP_PAIRWISE:
|
||||
g_value_set_boxed (value, setting->pairwise);
|
||||
g_value_set_boxed (value, priv->pairwise);
|
||||
break;
|
||||
case PROP_GROUP:
|
||||
g_value_set_boxed (value, setting->group);
|
||||
g_value_set_boxed (value, priv->group);
|
||||
break;
|
||||
case PROP_LEAP_USERNAME:
|
||||
g_value_set_string (value, setting->leap_username);
|
||||
g_value_set_string (value, priv->leap_username);
|
||||
break;
|
||||
case PROP_WEP_KEY0:
|
||||
g_value_set_string (value, setting->wep_key0);
|
||||
g_value_set_string (value, priv->wep_key0);
|
||||
break;
|
||||
case PROP_WEP_KEY1:
|
||||
g_value_set_string (value, setting->wep_key1);
|
||||
g_value_set_string (value, priv->wep_key1);
|
||||
break;
|
||||
case PROP_WEP_KEY2:
|
||||
g_value_set_string (value, setting->wep_key2);
|
||||
g_value_set_string (value, priv->wep_key2);
|
||||
break;
|
||||
case PROP_WEP_KEY3:
|
||||
g_value_set_string (value, setting->wep_key3);
|
||||
g_value_set_string (value, priv->wep_key3);
|
||||
break;
|
||||
case PROP_PSK:
|
||||
g_value_set_string (value, setting->psk);
|
||||
g_value_set_string (value, priv->psk);
|
||||
break;
|
||||
case PROP_LEAP_PASSWORD:
|
||||
g_value_set_string (value, setting->leap_password);
|
||||
g_value_set_string (value, priv->leap_password);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
|
@ -547,6 +875,8 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting
|
|||
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
|
||||
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
|
||||
|
||||
g_type_class_add_private (setting_class, sizeof (NMSettingWirelessSecurityPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
|
|
|
@ -72,20 +72,6 @@ GQuark nm_setting_wireless_security_error_quark (void);
|
|||
|
||||
typedef struct {
|
||||
NMSetting parent;
|
||||
|
||||
char *key_mgmt;
|
||||
guint32 wep_tx_keyidx;
|
||||
char *auth_alg;
|
||||
GSList *proto; /* GSList of strings */
|
||||
GSList *pairwise; /* GSList of strings */
|
||||
GSList *group; /* GSList of strings */
|
||||
char *leap_username;
|
||||
char *wep_key0;
|
||||
char *wep_key1;
|
||||
char *wep_key2;
|
||||
char *wep_key3;
|
||||
char *psk;
|
||||
char *leap_password;
|
||||
} NMSettingWirelessSecurity;
|
||||
|
||||
typedef struct {
|
||||
|
@ -94,7 +80,37 @@ typedef struct {
|
|||
|
||||
GType nm_setting_wireless_security_get_type (void);
|
||||
|
||||
NMSetting *nm_setting_wireless_security_new (void);
|
||||
NMSetting * nm_setting_wireless_security_new (void);
|
||||
|
||||
const char *nm_setting_wireless_security_get_key_mgmt (NMSettingWirelessSecurity *setting);
|
||||
|
||||
guint32 nm_setting_wireless_security_get_num_protos (NMSettingWirelessSecurity *setting);
|
||||
const char *nm_setting_wireless_security_get_proto (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
gboolean nm_setting_wireless_security_add_proto (NMSettingWirelessSecurity *setting, const char *proto);
|
||||
void nm_setting_wireless_security_remove_proto (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
void nm_setting_wireless_security_clear_protos (NMSettingWirelessSecurity *setting);
|
||||
|
||||
guint32 nm_setting_wireless_security_get_num_pairwise (NMSettingWirelessSecurity *setting);
|
||||
const char *nm_setting_wireless_security_get_pairwise (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
gboolean nm_setting_wireless_security_add_pairwise (NMSettingWirelessSecurity *setting, const char *pairwise);
|
||||
void nm_setting_wireless_security_remove_pairwise (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
void nm_setting_wireless_security_clear_pairwise (NMSettingWirelessSecurity *setting);
|
||||
|
||||
guint32 nm_setting_wireless_security_get_num_groups (NMSettingWirelessSecurity *setting);
|
||||
const char *nm_setting_wireless_security_get_group (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
gboolean nm_setting_wireless_security_add_group (NMSettingWirelessSecurity *setting, const char *group);
|
||||
void nm_setting_wireless_security_remove_group (NMSettingWirelessSecurity *setting, guint32 i);
|
||||
void nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting);
|
||||
|
||||
const char *nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting);
|
||||
|
||||
const char *nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting);
|
||||
const char *nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setting);
|
||||
|
||||
const char *nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx);
|
||||
void nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, guint32 idx, const char *key);
|
||||
guint32 nm_setting_wireless_security_get_wep_tx_keyidx (NMSettingWirelessSecurity *setting);
|
||||
const char *nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -132,6 +132,9 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
guint32 ap_mode)
|
||||
{
|
||||
NMSettingWirelessPrivate *priv;
|
||||
const char *key_mgmt = NULL, *cipher;
|
||||
guint32 num, i;
|
||||
gboolean found = FALSE;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
|
||||
|
||||
|
@ -148,11 +151,14 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
if (strcmp (priv->security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) != 0)
|
||||
return FALSE;
|
||||
|
||||
if (s_wireless_sec == NULL || !s_wireless_sec->key_mgmt)
|
||||
if (s_wireless_sec)
|
||||
key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
|
||||
|
||||
if (s_wireless_sec == NULL || !key_mgmt)
|
||||
return FALSE;
|
||||
|
||||
/* Static WEP */
|
||||
if (!strcmp (s_wireless_sec->key_mgmt, "none")) {
|
||||
if (!strcmp (key_mgmt, "none")) {
|
||||
if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
|
||||
|| (ap_wpa != NM_802_11_AP_SEC_NONE)
|
||||
|| (ap_rsn != NM_802_11_AP_SEC_NONE))
|
||||
|
@ -161,7 +167,7 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
}
|
||||
|
||||
/* Adhoc WPA */
|
||||
if (!strcmp (s_wireless_sec->key_mgmt, "wpa-none")) {
|
||||
if (!strcmp (key_mgmt, "wpa-none")) {
|
||||
if (ap_mode != NM_802_11_MODE_ADHOC)
|
||||
return FALSE;
|
||||
// FIXME: validate ciphers if the BSSID actually puts WPA/RSN IE in
|
||||
|
@ -174,15 +180,12 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
return FALSE;
|
||||
|
||||
/* Dynamic WEP or LEAP */
|
||||
if (!strcmp (s_wireless_sec->key_mgmt, "ieee8021x")) {
|
||||
if (!strcmp (key_mgmt, "ieee8021x")) {
|
||||
if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
|
||||
return FALSE;
|
||||
|
||||
/* If the AP is advertising a WPA IE, make sure it supports WEP ciphers */
|
||||
if (ap_wpa != NM_802_11_AP_SEC_NONE) {
|
||||
gboolean found = FALSE;
|
||||
GSList *iter;
|
||||
|
||||
if (!(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
|
||||
return FALSE;
|
||||
|
||||
|
@ -196,48 +199,46 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
/* Match at least one pairwise cipher with AP's capability if the
|
||||
* wireless-security setting explicitly lists pairwise ciphers
|
||||
*/
|
||||
if (s_wireless_sec->pairwise) {
|
||||
for (iter = s_wireless_sec->pairwise; iter; iter = g_slist_next (iter)) {
|
||||
if ((found = match_cipher (iter->data, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (iter->data, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
return FALSE;
|
||||
num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
|
||||
for (i = 0, found = FALSE; i < num; i++) {
|
||||
cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
|
||||
if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
|
||||
break;
|
||||
}
|
||||
if (!found && num)
|
||||
return FALSE;
|
||||
|
||||
/* Match at least one group cipher with AP's capability if the
|
||||
* wireless-security setting explicitly lists group ciphers
|
||||
*/
|
||||
if (s_wireless_sec->group) {
|
||||
for (iter = s_wireless_sec->group; iter; iter = g_slist_next (iter)) {
|
||||
if ((found = match_cipher (iter->data, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (iter->data, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
return FALSE;
|
||||
num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
|
||||
for (i = 0, found = FALSE; i < num; i++) {
|
||||
cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
|
||||
if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
|
||||
break;
|
||||
}
|
||||
if (!found && num)
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* WPA[2]-PSK and WPA[2] Enterprise */
|
||||
if ( !strcmp (s_wireless_sec->key_mgmt, "wpa-psk")
|
||||
|| !strcmp (s_wireless_sec->key_mgmt, "wpa-eap")) {
|
||||
GSList * elt;
|
||||
gboolean found = FALSE;
|
||||
if ( !strcmp (key_mgmt, "wpa-psk")
|
||||
|| !strcmp (key_mgmt, "wpa-eap")) {
|
||||
|
||||
if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp (s_wireless_sec->key_mgmt, "wpa-psk")) {
|
||||
if (!strcmp (key_mgmt, "wpa-psk")) {
|
||||
if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_PSK)
|
||||
&& !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
|
||||
return FALSE;
|
||||
} else if (!strcmp (s_wireless_sec->key_mgmt, "wpa-eap")) {
|
||||
} else if (!strcmp (key_mgmt, "wpa-eap")) {
|
||||
if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
|
||||
&& !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
|
||||
return FALSE;
|
||||
|
@ -250,34 +251,35 @@ nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
|
|||
/* Match at least one pairwise cipher with AP's capability if the
|
||||
* wireless-security setting explicitly lists pairwise ciphers
|
||||
*/
|
||||
if (s_wireless_sec->pairwise) {
|
||||
for (elt = s_wireless_sec->pairwise; elt; elt = g_slist_next (elt)) {
|
||||
if ((found = match_cipher (elt->data, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_TKIP)))
|
||||
break;
|
||||
if ((found = match_cipher (elt->data, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
return FALSE;
|
||||
num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
|
||||
for (i = 0, found = FALSE; i < num; i++) {
|
||||
cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
|
||||
if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_TKIP)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
|
||||
break;
|
||||
}
|
||||
if (!found && num)
|
||||
return FALSE;
|
||||
|
||||
/* Match at least one group cipher with AP's capability if the
|
||||
* wireless-security setting explicitly lists group ciphers
|
||||
*/
|
||||
if (s_wireless_sec->group) {
|
||||
for (elt = s_wireless_sec->group; elt; elt = g_slist_next (elt)) {
|
||||
if ((found = match_cipher (elt->data, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (elt->data, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
|
||||
break;
|
||||
if ((found = match_cipher (elt->data, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
|
||||
break;
|
||||
if ((found = match_cipher (elt->data, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
return FALSE;
|
||||
num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
|
||||
for (i = 0, found = FALSE; i < num; i++) {
|
||||
cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
|
||||
|
||||
if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
|
||||
break;
|
||||
if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
|
||||
break;
|
||||
}
|
||||
if (!found && num)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -489,11 +489,12 @@ nm_ap_new_from_properties (GHashTable *properties)
|
|||
static gboolean
|
||||
has_proto (NMSettingWirelessSecurity *sec, const char *proto)
|
||||
{
|
||||
GSList *iter;
|
||||
guint32 i;
|
||||
|
||||
for (iter = sec->proto; iter; iter = g_slist_next (iter))
|
||||
if (!strcmp (iter->data, proto))
|
||||
for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) {
|
||||
if (!strcmp (nm_setting_wireless_security_get_proto (sec, i), proto))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -512,20 +513,26 @@ has_proto_rsn (NMSettingWirelessSecurity *sec)
|
|||
static void
|
||||
add_ciphers (NMAccessPoint *ap, NMSettingWirelessSecurity *sec, gboolean group)
|
||||
{
|
||||
GSList *iter;
|
||||
GSList *ciphers = group ? sec->group : sec->pairwise;
|
||||
guint32 i, num;
|
||||
|
||||
for (iter = ciphers; iter; iter = g_slist_next (iter)) {
|
||||
num = group ? nm_setting_wireless_security_get_num_groups (sec) :
|
||||
nm_setting_wireless_security_get_num_pairwise (sec);
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
const char *cipher;
|
||||
guint32 flags = NM_802_11_AP_SEC_NONE;
|
||||
guint32 orig_flags;
|
||||
|
||||
if (!strcmp (iter->data, "wep40"))
|
||||
cipher = group ? nm_setting_wireless_security_get_group (sec, i) :
|
||||
nm_setting_wireless_security_get_pairwise (sec, i);
|
||||
|
||||
if (!strcmp (cipher, "wep40"))
|
||||
flags |= group ? NM_802_11_AP_SEC_GROUP_WEP40 : NM_802_11_AP_SEC_PAIR_WEP40;
|
||||
else if (!strcmp (iter->data, "wep104"))
|
||||
else if (!strcmp (cipher, "wep104"))
|
||||
flags |= group ? NM_802_11_AP_SEC_GROUP_WEP104 : NM_802_11_AP_SEC_PAIR_WEP104;
|
||||
else if (!strcmp (iter->data, "tkip"))
|
||||
else if (!strcmp (cipher, "tkip"))
|
||||
flags |= group ? NM_802_11_AP_SEC_GROUP_TKIP : NM_802_11_AP_SEC_PAIR_TKIP;
|
||||
else if (!strcmp (iter->data, "ccmp"))
|
||||
else if (!strcmp (cipher, "ccmp"))
|
||||
flags |= group ? NM_802_11_AP_SEC_GROUP_CCMP : NM_802_11_AP_SEC_PAIR_CCMP;
|
||||
|
||||
if (has_proto_wpa (sec)) {
|
||||
|
@ -546,8 +553,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
|
|||
NMSettingWireless *s_wireless;
|
||||
NMSettingWirelessSecurity *s_wireless_sec;
|
||||
const GByteArray *ssid;
|
||||
const char *mode;
|
||||
const char *band;
|
||||
const char *mode, *band, *key_mgmt;
|
||||
guint32 channel;
|
||||
guint32 flags;
|
||||
|
||||
|
@ -597,13 +603,15 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
|
|||
|
||||
flags = nm_ap_get_flags (ap);
|
||||
|
||||
key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
|
||||
|
||||
/* Static WEP or no security */
|
||||
if (!strcmp (s_wireless_sec->key_mgmt, "none")) {
|
||||
if (!strcmp (key_mgmt, "none")) {
|
||||
/* static wep? */
|
||||
if ( s_wireless_sec->wep_key0
|
||||
|| s_wireless_sec->wep_key1
|
||||
|| s_wireless_sec->wep_key2
|
||||
|| s_wireless_sec->wep_key3)
|
||||
if ( nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)
|
||||
|| nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)
|
||||
|| nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)
|
||||
|| nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3))
|
||||
nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
|
||||
|
||||
goto done;
|
||||
|
@ -611,8 +619,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
|
|||
|
||||
nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
|
||||
|
||||
if ( !strcmp (s_wireless_sec->key_mgmt, "wpa-psk")
|
||||
|| !strcmp (s_wireless_sec->key_mgmt, "wpa-none")) {
|
||||
if (!strcmp (key_mgmt, "wpa-psk") || !strcmp (key_mgmt, "wpa-none")) {
|
||||
if (has_proto_wpa (s_wireless_sec)) {
|
||||
flags = nm_ap_get_wpa_flags (ap);
|
||||
nm_ap_set_wpa_flags (ap, flags | NM_802_11_AP_SEC_KEY_MGMT_PSK);
|
||||
|
@ -624,8 +631,7 @@ nm_ap_new_fake_from_connection (NMConnection *connection)
|
|||
}
|
||||
}
|
||||
|
||||
if ( !strcmp (s_wireless_sec->key_mgmt, "ieee8021x")
|
||||
|| !strcmp (s_wireless_sec->key_mgmt, "wpa-eap")) {
|
||||
if (!strcmp (key_mgmt, "ieee8021x") || !strcmp (key_mgmt, "wpa-eap")) {
|
||||
if (has_proto_wpa (s_wireless_sec)) {
|
||||
flags = nm_ap_get_wpa_flags (ap);
|
||||
nm_ap_set_wpa_flags (ap, flags | NM_802_11_AP_SEC_KEY_MGMT_802_1X);
|
||||
|
|
|
@ -1815,16 +1815,18 @@ ap_auth_enforced (NMConnection *connection,
|
|||
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
|
||||
&& (rsn_flags == NM_802_11_AP_SEC_NONE)) {
|
||||
NMSettingWirelessSecurity *s_wireless_sec;
|
||||
const char *auth_alg;
|
||||
|
||||
/* No way to tell if the key is wrong with Open System
|
||||
* auth mode in WEP. Auth is not enforced like Shared Key.
|
||||
*/
|
||||
s_wireless_sec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection,
|
||||
NM_TYPE_SETTING_WIRELESS_SECURITY);
|
||||
if (s_wireless_sec &&
|
||||
(!s_wireless_sec->auth_alg ||
|
||||
!strcmp (s_wireless_sec->auth_alg, "open")))
|
||||
goto out;
|
||||
if (s_wireless_sec) {
|
||||
auth_alg = nm_setting_wireless_security_get_auth_alg (s_wireless_sec);
|
||||
if (!auth_alg || !strcmp (auth_alg, "open"))
|
||||
goto out;
|
||||
}
|
||||
|
||||
enforced = TRUE;
|
||||
} else if (wpa_flags != NM_802_11_AP_SEC_NONE) { /* WPA */
|
||||
|
|
|
@ -426,16 +426,17 @@ nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
|
|||
} \
|
||||
}
|
||||
|
||||
#define ADD_STRING_LIST_VAL(field, name, ucase, secret) \
|
||||
if (field) { \
|
||||
GSList *elt; \
|
||||
#define ADD_STRING_LIST_VAL(setting, field, field_plural, name, ucase, secret) \
|
||||
if (nm_setting_wireless_security_get_num_##field_plural (setting)) { \
|
||||
guint32 k; \
|
||||
GString *str = g_string_new (NULL); \
|
||||
for (elt = field; elt; elt = g_slist_next (elt)) { \
|
||||
for (k = 0; k < nm_setting_wireless_security_get_num_##field_plural (setting); k++) { \
|
||||
const char *item = nm_setting_wireless_security_get_##field (setting, k); \
|
||||
if (!str->len) { \
|
||||
g_string_append (str, elt->data); \
|
||||
g_string_append (str, item); \
|
||||
} else { \
|
||||
g_string_append_c (str, ' '); \
|
||||
g_string_append (str, elt->data); \
|
||||
g_string_append (str, item); \
|
||||
} \
|
||||
} \
|
||||
if (ucase) \
|
||||
|
@ -481,8 +482,9 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
|
|||
const char *connection_uid)
|
||||
{
|
||||
NMSupplicantConfigPrivate *priv;
|
||||
char * value;
|
||||
char *value;
|
||||
gboolean success;
|
||||
const char *key_mgmt, *auth_alg;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE);
|
||||
g_return_val_if_fail (setting != NULL, FALSE);
|
||||
|
@ -490,28 +492,37 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
|
|||
|
||||
priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
ADD_STRING_VAL (setting->key_mgmt, "key_mgmt", TRUE, FALSE, FALSE);
|
||||
ADD_STRING_VAL (setting->auth_alg, "auth_alg", TRUE, FALSE, FALSE);
|
||||
ADD_STRING_VAL (setting->psk, "psk", FALSE, TRUE, TRUE);
|
||||
key_mgmt = nm_setting_wireless_security_get_key_mgmt (setting);
|
||||
ADD_STRING_VAL (key_mgmt, "key_mgmt", TRUE, FALSE, FALSE);
|
||||
|
||||
auth_alg = nm_setting_wireless_security_get_auth_alg (setting);
|
||||
ADD_STRING_VAL (auth_alg, "auth_alg", TRUE, FALSE, FALSE);
|
||||
|
||||
ADD_STRING_VAL (nm_setting_wireless_security_get_psk (setting), "psk", FALSE, TRUE, TRUE);
|
||||
|
||||
/* Only WPA-specific things when using WPA */
|
||||
if ( !strcmp (setting->key_mgmt, "wpa-none")
|
||||
|| !strcmp (setting->key_mgmt, "wpa-psk")
|
||||
|| !strcmp (setting->key_mgmt, "wpa-eap")) {
|
||||
ADD_STRING_LIST_VAL (setting->proto, "proto", TRUE, FALSE);
|
||||
ADD_STRING_LIST_VAL (setting->pairwise, "pairwise", TRUE, FALSE);
|
||||
ADD_STRING_LIST_VAL (setting->group, "group", TRUE, FALSE);
|
||||
if ( !strcmp (key_mgmt, "wpa-none")
|
||||
|| !strcmp (key_mgmt, "wpa-psk")
|
||||
|| !strcmp (key_mgmt, "wpa-eap")) {
|
||||
ADD_STRING_LIST_VAL (setting, proto, protos, "proto", TRUE, FALSE);
|
||||
ADD_STRING_LIST_VAL (setting, pairwise, pairwise, "pairwise", TRUE, FALSE);
|
||||
ADD_STRING_LIST_VAL (setting, group, groups, "group", TRUE, FALSE);
|
||||
}
|
||||
|
||||
/* WEP keys if required */
|
||||
if (!strcmp (setting->key_mgmt, "none")) {
|
||||
ADD_STRING_VAL (setting->wep_key0, "wep_key0", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (setting->wep_key1, "wep_key1", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (setting->wep_key2, "wep_key2", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (setting->wep_key3, "wep_key3", FALSE, TRUE, TRUE);
|
||||
if (!strcmp (key_mgmt, "none")) {
|
||||
const char *wep0 = nm_setting_wireless_security_get_wep_key (setting, 0);
|
||||
const char *wep1 = nm_setting_wireless_security_get_wep_key (setting, 1);
|
||||
const char *wep2 = nm_setting_wireless_security_get_wep_key (setting, 2);
|
||||
const char *wep3 = nm_setting_wireless_security_get_wep_key (setting, 3);
|
||||
|
||||
if (setting->wep_key0 || setting->wep_key1 || setting->wep_key2 || setting->wep_key3) {
|
||||
value = g_strdup_printf ("%d", setting->wep_tx_keyidx);
|
||||
ADD_STRING_VAL (wep0, "wep_key0", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (wep1, "wep_key1", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (wep2, "wep_key2", FALSE, TRUE, TRUE);
|
||||
ADD_STRING_VAL (wep3, "wep_key3", FALSE, TRUE, TRUE);
|
||||
|
||||
if (wep0 || wep1 || wep2 || wep3) {
|
||||
value = g_strdup_printf ("%d", nm_setting_wireless_security_get_wep_tx_keyidx (setting));
|
||||
success = nm_supplicant_config_add_option (self, "wep_tx_keyidx", value, -1, FALSE);
|
||||
g_free (value);
|
||||
if (!success) {
|
||||
|
@ -521,19 +532,18 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
|
|||
}
|
||||
}
|
||||
|
||||
if (setting->auth_alg && !strcmp (setting->auth_alg, "leap")) {
|
||||
if (auth_alg && !strcmp (auth_alg, "leap")) {
|
||||
/* LEAP */
|
||||
if (!strcmp (setting->key_mgmt, "ieee8021x")) {
|
||||
ADD_STRING_VAL (setting->leap_username, "identity", FALSE, FALSE, FALSE);
|
||||
ADD_STRING_VAL (setting->leap_password, "password", FALSE, FALSE, TRUE);
|
||||
if (!strcmp (key_mgmt, "ieee8021x")) {
|
||||
ADD_STRING_VAL (nm_setting_wireless_security_get_leap_username (setting), "identity", FALSE, FALSE, FALSE);
|
||||
ADD_STRING_VAL (nm_setting_wireless_security_get_leap_password (setting), "password", FALSE, FALSE, TRUE);
|
||||
ADD_STRING_VAL ("leap", "eap", TRUE, FALSE, FALSE);
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
/* 802.1x for Dynamic WEP and WPA-Enterprise */
|
||||
if ( !strcmp (setting->key_mgmt, "ieee8021x")
|
||||
|| !strcmp (setting->key_mgmt, "wpa-eap")) {
|
||||
if (!strcmp (key_mgmt, "ieee8021x") || !strcmp (key_mgmt, "wpa-eap")) {
|
||||
if (!setting_8021x)
|
||||
return FALSE;
|
||||
if (!nm_supplicant_config_add_setting_8021x (self, setting_8021x, connection_uid, FALSE))
|
||||
|
@ -578,7 +588,31 @@ nm_supplicant_config_add_setting_8021x (NMSupplicantConfig *self,
|
|||
* all over the drive.
|
||||
*/
|
||||
|
||||
ADD_STRING_LIST_VAL (setting->eap, "eap", TRUE, FALSE);
|
||||
/* FIXME: go back to using ADD_STRING_LIST_VAL when 802.1x setting is
|
||||
* converted to accessors */
|
||||
if (setting->eap) {
|
||||
GSList *elt;
|
||||
GString *str = g_string_new (NULL);
|
||||
|
||||
for (elt = setting->eap; elt; elt = g_slist_next (elt)) {
|
||||
if (!str->len) {
|
||||
g_string_append (str, elt->data);
|
||||
} else {
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append (str, elt->data);
|
||||
}
|
||||
}
|
||||
g_string_ascii_up (str);
|
||||
if (str->len)
|
||||
success = nm_supplicant_config_add_option (self, "eap", str->str, -1, FALSE);
|
||||
else
|
||||
success = TRUE;
|
||||
g_string_free (str, TRUE);
|
||||
if (!success) {
|
||||
nm_warning ("Error adding %s to supplicant config.", "eap");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Drop the fragment size a bit for better compatibility */
|
||||
if (!nm_supplicant_config_add_option (self, "fragment_size", "1300", -1, FALSE))
|
||||
|
|
|
@ -462,16 +462,7 @@ add_one_wep_key (shvarFile *ifcfg,
|
|||
}
|
||||
|
||||
if (key) {
|
||||
if (key_idx == 0)
|
||||
s_wsec->wep_key0 = key;
|
||||
else if (key_idx == 1)
|
||||
s_wsec->wep_key1 = key;
|
||||
else if (key_idx == 2)
|
||||
s_wsec->wep_key2 = key;
|
||||
else if (key_idx == 3)
|
||||
s_wsec->wep_key3 = key;
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, key_idx, key);
|
||||
success = TRUE;
|
||||
}
|
||||
|
||||
|
@ -557,7 +548,7 @@ make_wireless_security_setting (shvarFile *ifcfg,
|
|||
success = get_int (value, &default_key_idx);
|
||||
if (success && (default_key_idx >= 1) && (default_key_idx <= 4)) {
|
||||
default_key_idx--; /* convert to [0...3] */
|
||||
s_wireless_sec->wep_tx_keyidx = default_key_idx;
|
||||
g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, default_key_idx, NULL);
|
||||
} else {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Invalid default WEP key '%s'", value);
|
||||
|
@ -582,15 +573,15 @@ make_wireless_security_setting (shvarFile *ifcfg,
|
|||
}
|
||||
|
||||
/* If there's a default key, ensure that key exists */
|
||||
if ((default_key_idx == 1) && !s_wireless_sec->wep_key1) {
|
||||
if ((default_key_idx == 1) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Default WEP key index was 2, but no valid KEY2 exists.");
|
||||
goto error;
|
||||
} else if ((default_key_idx == 2) && !s_wireless_sec->wep_key2) {
|
||||
} else if ((default_key_idx == 2) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Default WEP key index was 3, but no valid KEY3 exists.");
|
||||
goto error;
|
||||
} else if ((default_key_idx == 3) && !s_wireless_sec->wep_key3) {
|
||||
} else if ((default_key_idx == 3) && !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Default WEP key index was 4, but no valid KEY4 exists.");
|
||||
goto error;
|
||||
|
@ -604,9 +595,9 @@ make_wireless_security_setting (shvarFile *ifcfg,
|
|||
g_free (value);
|
||||
|
||||
if (!strcmp (lcase, "open")) {
|
||||
s_wireless_sec->auth_alg = g_strdup ("open");
|
||||
g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL);
|
||||
} else if (!strcmp (lcase, "restricted")) {
|
||||
s_wireless_sec->auth_alg = g_strdup ("shared");
|
||||
g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL);
|
||||
} else {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Invalid WEP authentication algoritm '%s'",
|
||||
|
@ -617,12 +608,15 @@ make_wireless_security_setting (shvarFile *ifcfg,
|
|||
g_free (lcase);
|
||||
}
|
||||
|
||||
if ( !s_wireless_sec->wep_key0
|
||||
&& !s_wireless_sec->wep_key1
|
||||
&& !s_wireless_sec->wep_key2
|
||||
&& !s_wireless_sec->wep_key3
|
||||
&& !s_wireless_sec->wep_tx_keyidx) {
|
||||
if (s_wireless_sec->auth_alg && !strcmp (s_wireless_sec->auth_alg, "shared")) {
|
||||
if ( !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 0)
|
||||
&& !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 1)
|
||||
&& !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 2)
|
||||
&& !nm_setting_wireless_security_get_wep_key (s_wireless_sec, 3)
|
||||
&& !nm_setting_wireless_security_get_wep_tx_keyidx (s_wireless_sec)) {
|
||||
const char *auth_alg;
|
||||
|
||||
auth_alg = nm_setting_wireless_security_get_auth_alg (s_wireless_sec);
|
||||
if (auth_alg && !strcmp (auth_alg, "shared")) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"WEP Shared Key authentication is invalid for "
|
||||
"unencrypted connections.");
|
||||
|
@ -634,7 +628,7 @@ make_wireless_security_setting (shvarFile *ifcfg,
|
|||
s_wireless_sec = NULL;
|
||||
} else {
|
||||
// FIXME: WEP-only for now
|
||||
s_wireless_sec->key_mgmt = g_strdup ("none");
|
||||
g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL);
|
||||
}
|
||||
|
||||
return (NMSetting *) s_wireless_sec;
|
||||
|
|
|
@ -339,7 +339,7 @@ read_wep_settings (shvarFile *ifcfg, NMSettingWirelessSecurity *security)
|
|||
READ_WEP_KEY(3)
|
||||
|
||||
if (have_key)
|
||||
security->key_mgmt = g_strdup ("none");
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL);
|
||||
|
||||
value = svGetValue (ifcfg, "WIRELESS_DEFAULT_KEY");
|
||||
if (value) {
|
||||
|
@ -348,7 +348,7 @@ read_wep_settings (shvarFile *ifcfg, NMSettingWirelessSecurity *security)
|
|||
|
||||
success = get_int (value, &key_idx);
|
||||
if (success && (key_idx >= 0) && (key_idx <= 3))
|
||||
security->wep_tx_keyidx = key_idx;
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, key_idx, NULL);
|
||||
else
|
||||
g_warning ("Invalid default WEP key: '%s'", value);
|
||||
|
||||
|
@ -362,25 +362,6 @@ error:
|
|||
}
|
||||
}
|
||||
|
||||
/* Copied from applet/src/wireless-secuirty/wireless-security.c */
|
||||
static void
|
||||
ws_wpa_fill_default_ciphers (NMSettingWirelessSecurity *s_wireless_sec)
|
||||
{
|
||||
// FIXME: allow protocol selection and filter on device capabilities
|
||||
s_wireless_sec->proto = g_slist_append (s_wireless_sec->proto, g_strdup ("wpa"));
|
||||
s_wireless_sec->proto = g_slist_append (s_wireless_sec->proto, g_strdup ("rsn"));
|
||||
|
||||
// FIXME: allow pairwise cipher selection and filter on device capabilities
|
||||
s_wireless_sec->pairwise = g_slist_append (s_wireless_sec->pairwise, g_strdup ("tkip"));
|
||||
s_wireless_sec->pairwise = g_slist_append (s_wireless_sec->pairwise, g_strdup ("ccmp"));
|
||||
|
||||
// FIXME: allow group cipher selection and filter on device capabilities
|
||||
s_wireless_sec->group = g_slist_append (s_wireless_sec->group, g_strdup ("wep40"));
|
||||
s_wireless_sec->group = g_slist_append (s_wireless_sec->group, g_strdup ("wep104"));
|
||||
s_wireless_sec->group = g_slist_append (s_wireless_sec->group, g_strdup ("tkip"));
|
||||
s_wireless_sec->group = g_slist_append (s_wireless_sec->group, g_strdup ("ccmp"));
|
||||
}
|
||||
|
||||
/*
|
||||
* utils_bin2hexstr
|
||||
*
|
||||
|
@ -425,20 +406,20 @@ read_wpa_psk_settings (shvarFile *ifcfg,
|
|||
if (value) {
|
||||
if (strlen (value) == 64) {
|
||||
/* Hex PSK */
|
||||
security->psk = g_strdup (value);
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_PSK, value, NULL);
|
||||
} else {
|
||||
/* passphrase */
|
||||
const GByteArray *ssid = nm_setting_wireless_get_mac_address (s_wireless);
|
||||
unsigned char *buf = g_malloc0 (WPA_PMK_LEN * 2);
|
||||
char *tmp;
|
||||
|
||||
pbkdf2_sha1 (value, (char *) ssid->data, ssid->len, 4096, buf, WPA_PMK_LEN);
|
||||
security->psk = utils_bin2hexstr ((const char *) buf, WPA_PMK_LEN, WPA_PMK_LEN * 2);
|
||||
tmp = utils_bin2hexstr ((const char *) buf, WPA_PMK_LEN, WPA_PMK_LEN * 2);
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_PSK, tmp, NULL);
|
||||
g_free (tmp);
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
g_free (value);
|
||||
|
||||
ws_wpa_fill_default_ciphers (security);
|
||||
} else
|
||||
g_warning ("Missing WPA-PSK key");
|
||||
}
|
||||
|
@ -533,13 +514,13 @@ make_wireless_security_setting (shvarFile *ifcfg, NMSettingWireless *s_wireless)
|
|||
security = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
|
||||
|
||||
if (!g_ascii_strcasecmp (str, "open")) {
|
||||
security->auth_alg = g_strdup ("open");
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL);
|
||||
read_wep_settings (ifcfg, security);
|
||||
} else if (!g_ascii_strcasecmp (str, "sharedkey")) {
|
||||
security->auth_alg = g_strdup ("shared");
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared", NULL);
|
||||
read_wep_settings (ifcfg, security);
|
||||
} else if (!g_ascii_strcasecmp (str, "psk")) {
|
||||
security->key_mgmt = g_strdup ("wpa-psk");
|
||||
g_object_set (security, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
|
||||
read_wpa_psk_settings (ifcfg, security, s_wireless);
|
||||
} else
|
||||
g_warning ("Invalid authentication algorithm: '%s'", str);
|
||||
|
|
Loading…
Reference in New Issue
Block a user