[network-manager-applet] editor: remember/restore old password when toggle ask_password in wifi



commit c6ef0298bb096b08bccfc47e215bdfd6295c1fd8
Author: Thomas Haller <thaller redhat com>
Date:   Fri Aug 23 21:33:04 2013 +0200

    editor: remember/restore old password when toggle ask_password in wifi
    
    In the wifi security dialog, when you set the "always ask" checkbox, the
    password will be cleared. Remember the previous password and restore it when
    you uncheck the box again.
    
    This has the effect, that you can toggle this checkbox and don't have to
    reenter the password.
    
    This only works, as long as you don't change the "Security",
    "Authentication" or "Inner authentication" type. This is
    intentionally not to expose the password by accident.
    
    Signed-off-by: Thomas Haller <thaller redhat com>

 src/wireless-security/eap-method-simple.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index 90ae914..60bd11f 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -175,14 +175,37 @@ update_secrets (EAPMethod *parent, NMConnection *connection)
 }
 
 static void
+g_free_str0 (gpointer mem)
+{
+       /* g_free a char pointer and set it to 0 before (for passwords). */
+       if (mem) {
+               char *p = mem;
+               memset (p, 0, strlen (p));
+               g_free (p);
+       }
+}
+
+static void
 password_always_ask_changed (GtkToggleButton *button, EAPMethodSimple *method)
 {
+       char *password;
        gboolean always_ask;
 
        always_ask = gtk_toggle_button_get_active (button);
 
        if (always_ask) {
+               password = g_strdup (gtk_entry_get_text (method->password_entry));
                gtk_entry_set_text (method->password_entry, "");
+               g_object_set_data_full (G_OBJECT (method->password_entry), "password-old", password, 
g_free_str0);
+       } else {
+               password = g_object_get_data (G_OBJECT (method->password_entry), "password-old");
+               gtk_entry_set_text (method->password_entry, password ? password : "");
+               g_object_set_data(G_OBJECT (method->password_entry), "password-old", NULL);
+       }
+
+       if (always_ask) {
+               /* we always clear this button and do not restore it
+                * (because we want to hide the password). */
                gtk_toggle_button_set_active (method->show_password, FALSE);
        }
 
@@ -215,6 +238,9 @@ widgets_unrealized (GtkWidget *widget, EAPMethodSimple *method)
                                        gtk_entry_get_text (method->password_entry),
                                        gtk_toggle_button_get_active (method->always_ask),
                                        gtk_toggle_button_get_active (method->show_password));
+
+       /* clear the remembered password. If the user changes the scheme, it's gone. */
+       g_object_set_data(G_OBJECT (method->password_entry), "password-old", NULL);
 }
 
 static void


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