Commit 3cc1e4c7 authored by Lubomir Rintel's avatar Lubomir Rintel
Browse files

wireless-security: fix validation of "always ask" passwords

The entry never contains a value in such cases. Don't fail the validation.
parent 9a1863d5
Pipeline #16386 passed with stages
in 30 minutes and 39 seconds
......@@ -52,6 +52,7 @@ static gboolean
validate (WirelessSecurity *parent, GError **error)
{
GtkWidget *entry;
NMSettingSecretFlags secret_flags;
const char *text;
gboolean ret = TRUE;
......@@ -67,15 +68,21 @@ validate (WirelessSecurity *parent, GError **error)
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry"));
g_assert (entry);
secret_flags = nma_utils_menu_to_secret_flags (entry);
text = gtk_entry_get_text (GTK_ENTRY (entry));
if (!text || !strlen (text)) {
if ( secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED
|| secret_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED
|| (text && strlen (text))) {
widget_unset_error (entry);
} else {
widget_set_error (entry);
if (ret) {
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-password"));
ret = FALSE;
}
} else
widget_unset_error (entry);
}
return ret;
}
......
......@@ -94,6 +94,7 @@ static gboolean
validate (WirelessSecurity *parent, GError **error)
{
WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent;
NMSettingSecretFlags secret_flags;
GtkWidget *entry;
const char *key;
int i;
......@@ -101,14 +102,17 @@ validate (WirelessSecurity *parent, GError **error)
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wep_key_entry"));
g_assert (entry);
secret_flags = nma_utils_menu_to_secret_flags (entry);
key = gtk_entry_get_text (GTK_ENTRY (entry));
if (!key) {
if ( secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED
|| secret_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) {
/* All good. */
} else if (!key) {
widget_set_error (entry);
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing wep-key"));
return FALSE;
}
if (sec->type == NM_WEP_KEY_TYPE_KEY) {
} else if (sec->type == NM_WEP_KEY_TYPE_KEY) {
if ((strlen (key) == 10) || (strlen (key) == 26)) {
for (i = 0; i < strlen (key); i++) {
if (!g_ascii_isxdigit (key[i])) {
......
......@@ -56,6 +56,7 @@ static gboolean
validate (WirelessSecurity *parent, GError **error)
{
GtkWidget *entry;
NMSettingSecretFlags secret_flags;
const char *key;
gsize len;
int i;
......@@ -63,15 +64,18 @@ validate (WirelessSecurity *parent, GError **error)
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wpa_psk_entry"));
g_assert (entry);
secret_flags = nma_utils_menu_to_secret_flags (entry);
key = gtk_entry_get_text (GTK_ENTRY (entry));
len = key ? strlen (key) : 0;
if ((len < 8) || (len > 64)) {
if ( secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED
|| secret_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED) {
/* All good. */
} else if ((len < 8) || (len > 64)) {
widget_set_error (entry);
g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wpa-psk: invalid key-length %zu. Must be [8,63] bytes or 64 hex digits"), len);
return FALSE;
}
if (len == 64) {
} else if (len == 64) {
/* Hex PSK */
for (i = 0; i < len; i++) {
if (!isxdigit (key[i])) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment