2009-07-24 Priit Laes <plaes@plaes.org>
authorxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jul 2009 12:31:47 +0000 (12:31 +0000)
committerxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jul 2009 12:31:47 +0000 (12:31 +0000)
        Reviewed by Xan Lopez.

        [Gtk] Password is saved into gnome-keyring even if auth. fails
        https://bugs.webkit.org/show_bug.cgi?id=27560

        Check authentication result and save password only when authentication
        succeeds.

        * webkit/webkitsoupauthdialog.c:
        (free_authData):
        (response_callback):
        (save_password_callback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@46350 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/gtk/ChangeLog
WebKit/gtk/webkit/webkitsoupauthdialog.c

index 336183380f909f0b3f1311d5d99cc011bc15890c..74c646484f124d7b1bc3ab42dc723a1e42740995 100644 (file)
@@ -1,3 +1,18 @@
+2009-07-24  Priit Laes  <plaes@plaes.org>
+
+        Reviewed by Xan Lopez.
+
+        [Gtk] Password is saved into gnome-keyring even if auth. fails
+        https://bugs.webkit.org/show_bug.cgi?id=27560
+
+        Check authentication result and save password only when authentication
+        succeeds.
+
+        * webkit/webkitsoupauthdialog.c:
+        (free_authData):
+        (response_callback):
+        (save_password_callback):
+
 2009-07-24  Andrei Popescu  <andreip@google.com>
 
         Reviewed by Anders Carlsson.
index d5ca79cd93066fdb4ba847d15c24f4277a556bfa..2ea72eda80b2730f0c7a94cc49200ab1d79bbae2 100644 (file)
@@ -91,11 +91,15 @@ typedef struct _WebKitAuthData {
 #if USE(GNOMEKEYRING)
     GtkWidget* checkButton;
 #endif
+    char *username;
+    char *password;
 } WebKitAuthData;
 
 static void free_authData(WebKitAuthData* authData)
 {
     g_object_unref(authData->msg);
+    g_free(authData->username);
+    g_free(authData->password);
     g_slice_free(WebKitAuthData, authData);
 }
 
@@ -104,47 +108,49 @@ static void set_password_callback(GnomeKeyringResult result, guint32 val, gpoint
 {
     /* Dummy callback, gnome_keyring_set_network_password does not accept a NULL one */
 }
-#endif
 
-static void response_callback(GtkDialog* dialog, gint response_id, WebKitAuthData* authData)
+static void save_password_callback(SoupMessage* msg, WebKitAuthData* authData)
 {
-    const char* login;
-    const char* password;
-#if USE(GNOMEKEYRING)
-    SoupURI* uri;
-    gboolean storePassword;
+    /* Check only for Success status codes (2xx) */
+    if (msg->status_code >= 200 && msg->status_code < 300) {
+        SoupURI* uri = soup_message_get_uri(authData->msg);
+        gnome_keyring_set_network_password(NULL,
+                                           authData->username,
+                                           soup_auth_get_realm(authData->auth),
+                                           uri->host,
+                                           NULL,
+                                           uri->scheme,
+                                           soup_auth_get_scheme_name(authData->auth),
+                                           uri->port,
+                                           authData->password,
+                                           (GnomeKeyringOperationGetIntCallback)set_password_callback,
+                                           NULL,
+                                           NULL);
+    }
+    free_authData(authData);
+}
 #endif
 
+static void response_callback(GtkDialog* dialog, gint response_id, WebKitAuthData* authData)
+{
     switch(response_id) {
     case GTK_RESPONSE_OK:
-        login = gtk_entry_get_text(GTK_ENTRY(authData->loginEntry));
-        password = gtk_entry_get_text(GTK_ENTRY(authData->passwordEntry));
-        soup_auth_authenticate(authData->auth, login, password);
+        authData->username = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->loginEntry)));
+        authData->password = g_strdup(gtk_entry_get_text(GTK_ENTRY(authData->passwordEntry)));
+        soup_auth_authenticate(authData->auth, authData->username, authData->password);
 
 #if USE(GNOMEKEYRING)
-        storePassword = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(authData->checkButton));
-        if (storePassword) {
-            uri = soup_message_get_uri(authData->msg);
-            gnome_keyring_set_network_password(NULL,
-                                               login,
-                                               soup_auth_get_realm(authData->auth),
-                                               uri->host,
-                                               NULL,
-                                               uri->scheme,
-                                               soup_auth_get_scheme_name(authData->auth),
-                                               uri->port,
-                                               password,
-                                               (GnomeKeyringOperationGetIntCallback)set_password_callback,
-                                               NULL,
-                                               NULL);
-        }
+        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(authData->checkButton)))
+            g_signal_connect(authData->msg, "got-headers", G_CALLBACK(save_password_callback), authData);
 #endif
     default:
         break;
     }
 
     soup_session_unpause_message(authData->session, authData->msg);
+#if !USE(GNOMEKEYRING)
     free_authData(authData);
+#endif
     gtk_widget_destroy(GTK_WIDGET(dialog));
 }