diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-10 17:53:59 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-10 17:53:59 -0500 |
commit | 74e5265d3921f18c7d626004e898837adb466d0c (patch) | |
tree | 5bc34e298dd24e389781d2a1fce6132aed8b0819 /mailnews/base/util | |
parent | bbf10b90975bc11e5ea2ac70196615a041b00f6f (diff) | |
download | UXP-74e5265d3921f18c7d626004e898837adb466d0c.tar UXP-74e5265d3921f18c7d626004e898837adb466d0c.tar.gz UXP-74e5265d3921f18c7d626004e898837adb466d0c.tar.lz UXP-74e5265d3921f18c7d626004e898837adb466d0c.tar.xz UXP-74e5265d3921f18c7d626004e898837adb466d0c.zip |
Bug 516464 - Remove passwords from cache when password manager contents are changed to prevent stale password attempts.
Tag #1273
Diffstat (limited to 'mailnews/base/util')
-rw-r--r-- | mailnews/base/util/nsMsgIncomingServer.cpp | 42 | ||||
-rw-r--r-- | mailnews/base/util/nsMsgIncomingServer.h | 6 |
2 files changed, 46 insertions, 2 deletions
diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index a1e897f12..2677e149a 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -49,6 +49,7 @@ #include "nsIMsgFilter.h" #include "nsIArray.h" #include "nsArrayUtils.h" +#include "nsIObserverService.h" #define PORT_NOT_SET -1 @@ -64,12 +65,51 @@ nsMsgIncomingServer::nsMsgIncomingServer(): { } +nsresult nsMsgIncomingServer::Init() +{ + // We need to know when the password manager changes. + nsCOMPtr<nsIObserverService> observerService = + mozilla::services::GetObserverService(); + NS_ENSURE_TRUE(observerService, NS_ERROR_UNEXPECTED); + + observerService->AddObserver(this, "passwordmgr-storage-changed", false); + observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); + return NS_OK; +} + nsMsgIncomingServer::~nsMsgIncomingServer() { } NS_IMPL_ISUPPORTS(nsMsgIncomingServer, nsIMsgIncomingServer, - nsISupportsWeakReference) + nsISupportsWeakReference, nsIObserver) + +NS_IMETHODIMP +nsMsgIncomingServer::Observe(nsISupports *aSubject, const char* aTopic, + const char16_t *aData) +{ + nsresult rv; + + // When the state of the password manager changes we need to clear the + // password from the cache in case the user just removed it. + if (strcmp(aTopic, "passwordmgr-storage-changed") == 0) + { + rv = ForgetSessionPassword(); + NS_ENSURE_SUCCESS(rv,rv); + } + else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) + { + // Now remove ourselves from the observer service as well. + nsCOMPtr<nsIObserverService> observerService = + mozilla::services::GetObserverService(); + NS_ENSURE_TRUE(observerService, NS_ERROR_UNEXPECTED); + + observerService->RemoveObserver(this, "passwordmgr-storage-changed"); + observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); + } + + return NS_OK; +} NS_IMETHODIMP nsMsgIncomingServer::SetServerBusy(bool aServerBusy) diff --git a/mailnews/base/util/nsMsgIncomingServer.h b/mailnews/base/util/nsMsgIncomingServer.h index 0c4219cd2..d19bdc930 100644 --- a/mailnews/base/util/nsMsgIncomingServer.h +++ b/mailnews/base/util/nsMsgIncomingServer.h @@ -21,6 +21,7 @@ #include "nsIMsgFilterPlugin.h" #include "nsDataHashtable.h" #include "nsIMsgPluggableStore.h" +#include "nsIObserver.h" class nsIMsgFolderCache; class nsIMsgProtocolInfo; @@ -36,13 +37,16 @@ class nsIMsgProtocolInfo; #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT class NS_MSG_BASE nsMsgIncomingServer : public nsIMsgIncomingServer, - public nsSupportsWeakReference + public nsSupportsWeakReference, + public nsIObserver { public: nsMsgIncomingServer(); + nsresult Init(); NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIMSGINCOMINGSERVER + NS_DECL_NSIOBSERVER protected: virtual ~nsMsgIncomingServer(); |