[gnome-control-center/benzea/fix-password-validation: 14/14] network: Accept empty passwords if it is not saved




commit 1decf825c1c3f945aa2ba3c0534258947e25c9a4
Author: Benjamin Berg <bberg redhat com>
Date:   Thu Jan 14 17:17:42 2021 +0100

    network: Accept empty passwords if it is not saved
    
    In that case, NM will use gnome-shell to prompt for the password. As
    such, the form should validate no matter what password is set.

 panels/network/wireless-security/eap-method-leap.c | 7 +++++++
 panels/network/wireless-security/eap-method-tls.c  | 4 ++++
 panels/network/wireless-security/ws-leap.c         | 7 +++++++
 panels/network/wireless-security/ws-sae.c          | 8 ++++++++
 panels/network/wireless-security/ws-wep-key.c      | 7 +++++++
 panels/network/wireless-security/ws-wpa-psk.c      | 7 +++++++
 6 files changed, 40 insertions(+)
---
diff --git a/panels/network/wireless-security/eap-method-leap.c 
b/panels/network/wireless-security/eap-method-leap.c
index f7b69b4d8..d218ade19 100644
--- a/panels/network/wireless-security/eap-method-leap.c
+++ b/panels/network/wireless-security/eap-method-leap.c
@@ -55,6 +55,7 @@ static gboolean
 validate (EAPMethod *parent, GError **error)
 {
        EAPMethodLEAP *self = (EAPMethodLEAP *)parent;
+       NMSettingSecretFlags secret_flags;
        const char *text;
        gboolean ret = TRUE;
 
@@ -66,6 +67,12 @@ validate (EAPMethod *parent, GError **error)
        } else
                widget_unset_error (GTK_WIDGET (self->username_entry));
 
+       secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
+       if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) {
+               widget_unset_error (GTK_WIDGET (self->password_entry));
+               return TRUE;
+       }
+
        text = gtk_entry_get_text (self->password_entry);
        if (!text || !strlen (text)) {
                widget_set_error (GTK_WIDGET (self->password_entry));
diff --git a/panels/network/wireless-security/eap-method-tls.c 
b/panels/network/wireless-security/eap-method-tls.c
index 1e0d6f377..fb039d740 100644
--- a/panels/network/wireless-security/eap-method-tls.c
+++ b/panels/network/wireless-security/eap-method-tls.c
@@ -79,6 +79,7 @@ validate (EAPMethod *method, GError **error)
 {
        EAPMethodTLS *self = EAP_METHOD_TLS (method);
        NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
+       NMSettingSecretFlags secret_flags;
        const char *password, *identity;
        g_autoptr(GError) ca_cert_error = NULL;
        g_autoptr(GError) private_key_error = NULL;
@@ -115,6 +116,9 @@ validate (EAPMethod *method, GError **error)
        }
 
        password = gtk_entry_get_text (self->private_key_password_entry);
+       secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->private_key_password_entry));
+       if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
+               password = NULL;
 
        if (!eap_method_validate_filepicker (GTK_FILE_CHOOSER (self->private_key_button),
                                             TYPE_PRIVATE_KEY,
diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c
index a3391ec5e..464f92831 100644
--- a/panels/network/wireless-security/ws-leap.c
+++ b/panels/network/wireless-security/ws-leap.c
@@ -56,6 +56,7 @@ static gboolean
 validate (WirelessSecurity *security, GError **error)
 {
        WirelessSecurityLEAP *self = WS_LEAP (security);
+       NMSettingSecretFlags secret_flags;
        const char *text;
        gboolean ret = TRUE;
 
@@ -67,6 +68,12 @@ validate (WirelessSecurity *security, GError **error)
        } else
                widget_unset_error (GTK_WIDGET (self->username_entry));
 
+       secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
+       if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) {
+               widget_unset_error (GTK_WIDGET (self->password_entry));
+               return TRUE;
+       }
+
        text = gtk_entry_get_text (self->password_entry);
        if (!text || !strlen (text)) {
                widget_set_error (GTK_WIDGET (self->password_entry));
diff --git a/panels/network/wireless-security/ws-sae.c b/panels/network/wireless-security/ws-sae.c
index 6f451cdba..89017ad6a 100644
--- a/panels/network/wireless-security/ws-sae.c
+++ b/panels/network/wireless-security/ws-sae.c
@@ -59,8 +59,16 @@ static gboolean
 validate (WirelessSecurity *security, GError **error)
 {
   WirelessSecuritySAE *self = WS_SAE (security);
+  NMSettingSecretFlags secret_flags;
   const char *key;
 
+  secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
+  if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
+    {
+      widget_unset_error (GTK_WIDGET (self->password_entry));
+      return TRUE;
+  }
+
   key = gtk_entry_get_text (self->password_entry);
 
   if (key == NULL || key[0] == '\0')
diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c
index ba09a689d..006ecedae 100644
--- a/panels/network/wireless-security/ws-wep-key.c
+++ b/panels/network/wireless-security/ws-wep-key.c
@@ -98,9 +98,16 @@ static gboolean
 validate (WirelessSecurity *security, GError **error)
 {
        WirelessSecurityWEPKey *self = WS_WEP_KEY (security);
+       NMSettingSecretFlags secret_flags;
        const char *key;
        int i;
 
+       secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->key_entry));
+       if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) {
+               widget_unset_error (GTK_WIDGET (self->key_entry));
+               return TRUE;
+       }
+
        key = gtk_entry_get_text (self->key_entry);
        if (!key) {
                widget_set_error (GTK_WIDGET (self->key_entry));
diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c
index 653b5ffc7..978488b7e 100644
--- a/panels/network/wireless-security/ws-wpa-psk.c
+++ b/panels/network/wireless-security/ws-wpa-psk.c
@@ -59,10 +59,17 @@ static gboolean
 validate (WirelessSecurity *security, GError **error)
 {
        WirelessSecurityWPAPSK *self = WS_WPA_PSK (security);
+       NMSettingSecretFlags secret_flags;
        const char *key;
        gsize len;
        int i;
 
+       secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
+       if (secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED) {
+               widget_unset_error (GTK_WIDGET (self->password_entry));
+               return TRUE;
+       }
+
        key = gtk_entry_get_text (self->password_entry);
        len = key ? strlen (key) : 0;
        if ((len < 8) || (len > 64)) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]