[network-manager-applet/danw/askpass: 3/3] wireless-security: remember username/password across pages



commit 3b7bc22f44002078728c9310dfcb0d341f1e27ba
Author: Dan Winship <danw gnome org>
Date:   Tue May 28 15:16:54 2013 -0300

    wireless-security: remember username/password across pages
    
    Several different WPA Enterprise authentication types use username and
    password, but each type has its own set of widgets in the editor, so
    if you switch types, you lose any username/password you typed in
    before. Hack this by having the WirelessSecurity object record the
    last-seen username/password, and having the EAP widgets read from
    that when they're shown, and write to it when they're hidden.

 src/wireless-security/eap-method-leap.c   |   38 ++++++++++++++++++++++++++++
 src/wireless-security/eap-method-simple.c |   39 +++++++++++++++++++++++++++++
 src/wireless-security/wireless-security.c |   27 ++++++++++++++++++++
 src/wireless-security/wireless-security.h |    9 ++++++
 4 files changed, 113 insertions(+), 0 deletions(-)
---
diff --git a/src/wireless-security/eap-method-leap.c b/src/wireless-security/eap-method-leap.c
index 92fcb39..281ff2b 100644
--- a/src/wireless-security/eap-method-leap.c
+++ b/src/wireless-security/eap-method-leap.c
@@ -31,6 +31,8 @@
 struct _EAPMethodLEAP {
        EAPMethod parent;
 
+       WirelessSecurity *ws_parent;
+
        gboolean new_connection;
 
        GtkEntry *username_entry;
@@ -111,6 +113,32 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
                                  (HelperSecretFunc) nm_setting_802_1x_get_password);
 }
 
+static void
+widgets_realized (GtkWidget *widget, EAPMethodLEAP *method)
+{
+       if (method->ws_parent->username)
+               gtk_entry_set_text (method->username_entry, method->ws_parent->username);
+       else
+               gtk_entry_set_text (method->username_entry, "");
+
+       if (method->ws_parent->password && !method->ws_parent->always_ask)
+               gtk_entry_set_text (method->password_entry, method->ws_parent->password);
+       else
+               gtk_entry_set_text (method->password_entry, "");
+
+       gtk_toggle_button_set_active (method->show_password, method->ws_parent->show_password);
+}
+
+static void
+widgets_unrealized (GtkWidget *widget, EAPMethodLEAP *method)
+{
+       wireless_security_set_userpass (method->ws_parent,
+                                       gtk_entry_get_text (method->username_entry),
+                                       gtk_entry_get_text (method->password_entry),
+                                       (gboolean) -1,
+                                       gtk_toggle_button_get_active (method->show_password));
+}
+
 EAPMethodLEAP *
 eap_method_leap_new (WirelessSecurity *ws_parent,
                      NMConnection *connection,
@@ -135,6 +163,16 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
 
        method = (EAPMethodLEAP *) parent;
        method->new_connection = secrets_only ? FALSE : TRUE;
+       method->ws_parent = ws_parent;
+
+       widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_notebook"));
+       g_assert (widget);
+       g_signal_connect (G_OBJECT (widget), "realize",
+                         (GCallback) widgets_realized,
+                         method);
+       g_signal_connect (G_OBJECT (widget), "unrealize",
+                         (GCallback) widgets_unrealized,
+                         method);
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_username_entry"));
        g_assert (widget);
diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index 5cfaca0..02bff33 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -32,6 +32,8 @@
 struct _EAPMethodSimple {
        EAPMethod parent;
 
+       WirelessSecurity *ws_parent;
+
        EAPMethodSimpleType type;
        gboolean is_editor;
        gboolean new_connection;
@@ -188,6 +190,33 @@ password_always_ask_changed (GtkToggleButton *button, EAPMethodSimple *method)
        gtk_widget_set_sensitive (GTK_WIDGET (method->show_password), !always_ask);
 }
 
+static void
+widgets_realized (GtkWidget *widget, EAPMethodSimple *method)
+{
+       if (method->ws_parent->username)
+               gtk_entry_set_text (method->username_entry, method->ws_parent->username);
+       else
+               gtk_entry_set_text (method->username_entry, "");
+
+       if (method->ws_parent->password && !method->ws_parent->always_ask)
+               gtk_entry_set_text (method->password_entry, method->ws_parent->password);
+       else
+               gtk_entry_set_text (method->password_entry, "");
+
+       gtk_toggle_button_set_active (method->always_ask, method->ws_parent->always_ask);
+       gtk_toggle_button_set_active (method->show_password, method->ws_parent->show_password);
+}
+
+static void
+widgets_unrealized (GtkWidget *widget, EAPMethodSimple *method)
+{
+       wireless_security_set_userpass (method->ws_parent,
+                                       gtk_entry_get_text (method->username_entry),
+                                       gtk_entry_get_text (method->password_entry),
+                                       gtk_toggle_button_get_active (method->always_ask),
+                                       gtk_toggle_button_get_active (method->show_password));
+}
+
 EAPMethodSimple *
 eap_method_simple_new (WirelessSecurity *ws_parent,
                        NMConnection *connection,
@@ -219,6 +248,16 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
        method->type = type;
        method->is_editor = is_editor;
        method->new_connection = secrets_only ? FALSE : TRUE;
+       method->ws_parent = ws_parent;
+
+       widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_simple_notebook"));
+       g_assert (widget);
+       g_signal_connect (G_OBJECT (widget), "realize",
+                         (GCallback) widgets_realized,
+                         method);
+       g_signal_connect (G_OBJECT (widget), "unrealize",
+                         (GCallback) widgets_unrealized,
+                         method);
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_simple_username_entry"));
        g_assert (widget);
diff --git a/src/wireless-security/wireless-security.c b/src/wireless-security/wireless-security.c
index fc77777..82de85b 100644
--- a/src/wireless-security/wireless-security.c
+++ b/src/wireless-security/wireless-security.c
@@ -140,6 +140,12 @@ wireless_security_unref (WirelessSecurity *sec)
                if (sec->destroy)
                        sec->destroy (sec);
 
+               g_free (sec->username);
+               if (sec->password) {
+                       memset (sec->password, 0, strlen (sec->password));
+                       g_free (sec->password);
+               }
+
                if (sec->builder)
                        g_object_unref (sec->builder);
                if (sec->ui_widget)
@@ -221,6 +227,27 @@ wireless_security_adhoc_compatible (WirelessSecurity *sec)
 }
 
 void
+wireless_security_set_userpass (WirelessSecurity *sec,
+                                const char *user,
+                                const char *password,
+                                gboolean always_ask,
+                                gboolean show_password)
+{
+       g_free (sec->username);
+       sec->username = g_strdup (user);
+
+       if (sec->password) {
+               memset (sec->password, 0, strlen (sec->password));
+               g_free (sec->password);
+       }
+       sec->password = g_strdup (password);
+
+       if (always_ask != (gboolean) -1)
+               sec->always_ask = always_ask;
+       sec->show_password = show_password;
+}
+
+void
 wireless_security_clear_ciphers (NMConnection *connection)
 {
        NMSettingWirelessSecurity *s_wireless_sec;
diff --git a/src/wireless-security/wireless-security.h b/src/wireless-security/wireless-security.h
index eea98c3..78f4124 100644
--- a/src/wireless-security/wireless-security.h
+++ b/src/wireless-security/wireless-security.h
@@ -49,6 +49,9 @@ struct _WirelessSecurity {
        const char *default_field;
        gboolean adhoc_compatible;
 
+       char *username, *password;
+       gboolean always_ask, show_password;
+
        WSAddToSizeGroupFunc add_to_size_group;
        WSFillConnectionFunc fill_connection;
        WSUpdateSecretsFunc update_secrets;
@@ -81,6 +84,12 @@ GtkWidget * wireless_security_nag_user (WirelessSecurity *sec);
 
 gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec);
 
+void wireless_security_set_userpass (WirelessSecurity *sec,
+                                     const char *user,
+                                     const char *password,
+                                     gboolean always_ask,
+                                     gboolean show_password);
+
 WirelessSecurity *wireless_security_ref (WirelessSecurity *sec);
 
 void wireless_security_unref (WirelessSecurity *sec);


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