diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-10 17:55:10 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-10 17:55:10 -0500 |
commit | 58a7cff161d1af1631b67c533d59c39b0adcabda (patch) | |
tree | 80c0401d6226fb57d80360caf2add54f125fd51e | |
parent | 74e5265d3921f18c7d626004e898837adb466d0c (diff) | |
download | UXP-58a7cff161d1af1631b67c533d59c39b0adcabda.tar UXP-58a7cff161d1af1631b67c533d59c39b0adcabda.tar.gz UXP-58a7cff161d1af1631b67c533d59c39b0adcabda.tar.lz UXP-58a7cff161d1af1631b67c533d59c39b0adcabda.tar.xz UXP-58a7cff161d1af1631b67c533d59c39b0adcabda.zip |
Bug 1461106 - Remove SMTP password from cache when deleted from password manager to prevent stale connection attempts.
Tag #1273
-rw-r--r-- | mailnews/build/nsMailModule.cpp | 2 | ||||
-rw-r--r-- | mailnews/compose/src/nsSmtpServer.cpp | 40 | ||||
-rw-r--r-- | mailnews/compose/src/nsSmtpServer.h | 6 |
3 files changed, 46 insertions, 2 deletions
diff --git a/mailnews/build/nsMailModule.cpp b/mailnews/build/nsMailModule.cpp index d0bcabe96..285a0dfc9 100644 --- a/mailnews/build/nsMailModule.cpp +++ b/mailnews/build/nsMailModule.cpp @@ -556,7 +556,7 @@ NS_DEFINE_NAMED_CID(NS_BAYESIANFILTER_CID); // compose factories //////////////////////////////////////////////////////////////////////////////// NS_GENERIC_FACTORY_CONSTRUCTOR(nsSmtpService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsSmtpServer) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSmtpServer, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgCompose) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeParams) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgComposeSendListener) diff --git a/mailnews/compose/src/nsSmtpServer.cpp b/mailnews/compose/src/nsSmtpServer.cpp index 4dc3e1f64..ddbaa4e3c 100644 --- a/mailnews/compose/src/nsSmtpServer.cpp +++ b/mailnews/compose/src/nsSmtpServer.cpp @@ -17,12 +17,14 @@ #include "nsILoginManager.h" #include "nsIArray.h" #include "nsArrayUtils.h" +#include "nsIObserverService.h" NS_IMPL_ADDREF(nsSmtpServer) NS_IMPL_RELEASE(nsSmtpServer) NS_INTERFACE_MAP_BEGIN(nsSmtpServer) NS_INTERFACE_MAP_ENTRY(nsISmtpServer) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISmtpServer) NS_INTERFACE_MAP_END @@ -37,6 +39,44 @@ nsSmtpServer::~nsSmtpServer() { } +nsresult nsSmtpServer::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; +} + +NS_IMETHODIMP +nsSmtpServer::Observe(nsISupports *aSubject, const char* aTopic, + const char16_t *aData) +{ + // 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) + { + m_password.Truncate(); + } + 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 nsSmtpServer::GetKey(char * *aKey) { diff --git a/mailnews/compose/src/nsSmtpServer.h b/mailnews/compose/src/nsSmtpServer.h index cbd7dba67..4473d7af8 100644 --- a/mailnews/compose/src/nsSmtpServer.h +++ b/mailnews/compose/src/nsSmtpServer.h @@ -11,15 +11,19 @@ #include "nsISmtpServer.h" #include "nsIPrefBranch.h" #include "nsWeakReference.h" +#include "nsIObserver.h" class nsSmtpServer : public nsISmtpServer, - public nsSupportsWeakReference + public nsSupportsWeakReference, + public nsIObserver { public: nsSmtpServer(); + nsresult Init(); NS_DECL_ISUPPORTS NS_DECL_NSISMTPSERVER + NS_DECL_NSIOBSERVER private: virtual ~nsSmtpServer(); |