diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-09 12:22:39 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-03-20 13:02:04 +0100 |
commit | 628f47285dbefe2d57ba42e64db6c8843bdbf742 (patch) | |
tree | caba375f630aef638e83df862b29dfbb7f73c707 | |
parent | dbbedce21f0dbb2849ed48bd2cee3b98e1ad2135 (diff) | |
download | NetworkManager-628f47285dbefe2d57ba42e64db6c8843bdbf742.tar.gz |
libnm: accept unknown WEP key type in nm_utils_wep_key_valid()
libnm-core treated the UNKNOWN WEP key type as KEY. Relax that
and try to guess the correct type based on the key.
This is for example important if you have a valid connection with
wep-key-type=0 (unknown)
If you request passwords for such a connection, the user cannot
enter them in password format -- but there is no UI indication
that the password must be KEY.
-rw-r--r-- | libnm-core/nm-utils.c | 9 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/writer.c | 11 | ||||
-rw-r--r-- | src/supplicant-manager/nm-supplicant-config.c | 7 |
3 files changed, 22 insertions, 5 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 7e0c6d9217..d3557f578a 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -999,9 +999,13 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type) if (!key) return FALSE; + if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + return nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY) || + nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE); + } + keylen = strlen (key); - if ( wep_type == NM_WEP_KEY_TYPE_KEY - || wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (wep_type == NM_WEP_KEY_TYPE_KEY) { if (keylen == 10 || keylen == 26) { /* Hex key */ for (i = 0; i < keylen; i++) { @@ -1016,7 +1020,6 @@ nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type) } } else return FALSE; - } else if (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE) { if (!keylen || keylen > 64) return FALSE; diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 5fe88746a3..75547641b1 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -696,9 +696,15 @@ write_wireless_security_setting (NMConnection *connection, * keys. */ key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec); + if (key_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) + key_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) + key_type = NM_WEP_KEY_TYPE_PASSPHRASE; + } if (key_type == NM_WEP_KEY_TYPE_PASSPHRASE) tmp = g_strdup_printf ("KEY_PASSPHRASE%d", i + 1); - else { + else if (key_type == NM_WEP_KEY_TYPE_KEY) { tmp = g_strdup_printf ("KEY%d", i + 1); /* Add 's:' prefix for ASCII keys */ @@ -706,7 +712,8 @@ write_wireless_security_setting (NMConnection *connection, ascii_key = g_strdup_printf ("s:%s", key); key = ascii_key; } - } + } else + key = NULL; set_secret (ifcfg, tmp, diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c index d976bd703f..5df7b1e760 100644 --- a/src/supplicant-manager/nm-supplicant-config.c +++ b/src/supplicant-manager/nm-supplicant-config.c @@ -526,6 +526,13 @@ add_wep_key (NMSupplicantConfig *self, if (!key || !key_len) return TRUE; + if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) { + if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_KEY)) + wep_type = NM_WEP_KEY_TYPE_KEY; + else if (nm_utils_wep_key_valid (key, NM_WEP_KEY_TYPE_PASSPHRASE)) + wep_type = NM_WEP_KEY_TYPE_PASSPHRASE; + } + if ( (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) || (wep_type == NM_WEP_KEY_TYPE_KEY)) { if ((key_len == 10) || (key_len == 26)) { |