Bug 379997: don't delete logins if authentication fails, patch by Justin Dolske <dolske@mozilla.com>, r+sr=biesi
authorgavin@gavinsharp.com
Mon, 14 May 2007 11:39:34 -0700
changeset 1425 38db3a0657b8e035778ef05c9a4e30c5e45f7c3a
parent 1424 15d17b301778b9f0cf607a23e02e6be0062fa94f
child 1426 a94492db2633c4d418f00b6a545a042a4d74747d
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
bugs379997
milestone1.9a5pre
Bug 379997: don't delete logins if authentication fails, patch by Justin Dolske <dolske@mozilla.com>, r+sr=biesi
netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp
netwerk/protocol/http/src/nsHttpChannel.cpp
netwerk/protocol/http/src/nsHttpChannel.h
--- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp
+++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp
@@ -60,17 +60,16 @@
 #include "nsStreamUtils.h"
 #include "nsICacheService.h"
 #include "nsIURL.h"
 #include "nsISocketTransport.h"
 #include "nsIStreamListenerTee.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIStringBundle.h"
-#include "nsCPasswordManager.h"
 #include "nsAuthInformationHolder.h"
 
 #if defined(PR_LOGGING)
 extern PRLogModuleInfo* gFTPLog;
 #endif
 #define LOG(args)         PR_LOG(gFTPLog, PR_LOG_DEBUG, args)
 #define LOG_ALWAYS(args)  PR_LOG(gFTPLog, PR_LOG_ALWAYS, args)
 
@@ -797,31 +796,16 @@ nsFtpState::R_pass() {
         // start over w/ the user command.
         // note: the password was successful, and it's stored in mPassword
         mRetryPass = PR_FALSE;
         return FTP_S_USER;
     }
     if (mResponseCode/100 == 5 || mResponseCode==421) {
         // There is no difference between a too-many-users error,
         // a wrong-password error, or any other sort of error
-        // So we need to tell wallet to forget the password if we had one,
-        // and error out. That will then show the error message, and the
-        // user can retry if they want to
-
-        if (!mPassword.IsEmpty()) {
-            nsCOMPtr<nsIPasswordManager> pm =
-                    do_GetService(NS_PASSWORDMANAGER_CONTRACTID);
-            if (pm) {
-                nsCAutoString prePath;
-                nsresult rv = mChannel->URI()->GetPrePath(prePath);
-                NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get prepath");
-                if (NS_SUCCEEDED(rv))
-                    pm->RemoveUser(prePath, EmptyString());
-            }
-        }
 
         // If the login was anonymous, and it failed, try again with a username
         if (mAnonymous) {
             mAnonymous = PR_FALSE;
             return FTP_S_USER;
         }
 
         mRetryPass = PR_TRUE;
--- a/netwerk/protocol/http/src/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/src/nsHttpChannel.cpp
@@ -52,17 +52,16 @@
 #include "nsIAuthPromptProvider.h"
 #include "nsIStringBundle.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIURL.h"
 #include "nsIIDNService.h"
 #include "nsIStreamListenerTee.h"
 #include "nsISeekableStream.h"
-#include "nsCPasswordManager.h"
 #include "nsMimeTypes.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsAutoPtr.h"
 #include "plstr.h"
@@ -2739,17 +2738,16 @@ nsHttpChannel::GetCredentialsForChalleng
     LOG(("  identity invalid = %d\n", identityInvalid));
 
     if (identityInvalid) {
         if (entry) {
             if (ident->Equals(entry->Identity())) {
                 LOG(("  clearing bad auth cache entry\n"));
                 // ok, we've already tried this user identity, so clear the
                 // corresponding entry from the auth cache.
-                ClearPasswordManagerEntry(scheme.get(), host, port, realm.get(), entry->User());
                 authCache->ClearAuthEntry(scheme.get(), host, port, realm.get());
                 entry = nsnull;
                 ident->Clear();
             }
             else if (!identFromURI || nsCRT::strcmp(ident->User(), entry->Identity().User()) == 0) {
                 LOG(("  taking identity from auth cache\n"));
                 // the password from the auth cache is more likely to be
                 // correct than the one in the URL.  at least, we know that it
@@ -4628,41 +4626,16 @@ nsHttpChannel::OnCacheEntryAvailable(nsI
     if (NS_FAILED(rv)) {
         CloseCacheEntry();
         AsyncAbort(rv);
     }
 
     return NS_OK;
 }
 
-void
-nsHttpChannel::ClearPasswordManagerEntry(const char      *scheme,
-                                         const char      *host,
-                                         PRInt32          port,
-                                         const char      *realm,
-                                         const PRUnichar *user)
-{
-    // XXX scheme is currently unused.  see comments in PromptForIdentity
-
-    nsresult rv;
-    nsCOMPtr<nsIPasswordManager> passWordManager = do_GetService(NS_PASSWORDMANAGER_CONTRACTID, &rv);
-    if (passWordManager) {
-        nsCAutoString domain;
-        domain.Assign(host);
-        domain.Append(':');
-        domain.AppendInt(port);
-
-        domain.AppendLiteral(" (");
-        domain.Append(realm);
-        domain.Append(')');
-
-        passWordManager->RemoveUser(domain, nsDependentString(user));
-    }
-} 
-
 nsresult
 nsHttpChannel::DoAuthRetry(nsAHttpConnection *conn)
 {
     LOG(("nsHttpChannel::DoAuthRetry [this=%x]\n", this));
 
     NS_ASSERTION(!mTransaction, "should not have a transaction");
     nsresult rv;
 
--- a/netwerk/protocol/http/src/nsHttpChannel.h
+++ b/netwerk/protocol/http/src/nsHttpChannel.h
@@ -203,17 +203,16 @@ private:
     void     ParseRealm(const char *challenge, nsACString &realm);
     void     GetIdentityFromURI(PRUint32 authFlags, nsHttpAuthIdentity&);
     nsresult PromptForIdentity(PRUint32 level, PRBool proxyAuth, const char *realm, const char *authType, PRUint32 authFlags, nsHttpAuthIdentity &);
     PRBool   ConfirmAuth(const nsString &bundleKey, PRBool doYesNoPrompt);
     void     CheckForSuperfluousAuth();
     void     SetAuthorizationHeader(nsHttpAuthCache *, nsHttpAtom header, const char *scheme, const char *host, PRInt32 port, const char *path, nsHttpAuthIdentity &ident);
     void     AddAuthorizationHeaders();
     nsresult GetCurrentPath(nsACString &);
-    void     ClearPasswordManagerEntry(const char *scheme, const char *host, PRInt32 port, const char *realm, const PRUnichar *user);
     nsresult DoAuthRetry(nsAHttpConnection *);
 
 private:
     nsCOMPtr<nsIURI>                  mOriginalURI;
     nsCOMPtr<nsIURI>                  mURI;
     nsCOMPtr<nsIURI>                  mDocumentURI;
     nsCOMPtr<nsIStreamListener>       mListener;
     nsCOMPtr<nsISupports>             mListenerContext;