Bug 1018624, part 3: Kill the NNTP legacy credentials migrator, r=Neil.
This commit is contained in:
Родитель
9605d1794a
Коммит
75563f1424
|
@ -15,7 +15,7 @@ interface nsINntpIncomingServer;
|
||||||
|
|
||||||
[ref] native nsMsgKeyArrayRef(nsTArray<nsMsgKey>);
|
[ref] native nsMsgKeyArrayRef(nsTArray<nsMsgKey>);
|
||||||
|
|
||||||
[scriptable, uuid(3bf5c65d-71bd-4560-a337-435797d249a6)]
|
[scriptable, uuid(9a12c3a5-9de5-4c57-ace3-d51802b525a9)]
|
||||||
interface nsIMsgNewsFolder : nsISupports {
|
interface nsIMsgNewsFolder : nsISupports {
|
||||||
readonly attribute AString unicodeName;
|
readonly attribute AString unicodeName;
|
||||||
/**|rawName| is an 8-bit string to represent the name of a newsgroup used by
|
/**|rawName| is an 8-bit string to represent the name of a newsgroup used by
|
||||||
|
@ -80,20 +80,6 @@ interface nsIMsgNewsFolder : nsISupports {
|
||||||
bool getAuthenticationCredentials(in nsIMsgWindow aMsgWindow,
|
bool getAuthenticationCredentials(in nsIMsgWindow aMsgWindow,
|
||||||
in bool mayPrompt, in bool mustPrompt);
|
in bool mayPrompt, in bool mustPrompt);
|
||||||
|
|
||||||
/**
|
|
||||||
* Force migration of credentials from older versions of this codebase.
|
|
||||||
*
|
|
||||||
* This method is normally called during the creation of newsgroup folders,
|
|
||||||
* and it should not be necessary to call this method. This method also
|
|
||||||
* forcibly deletes the old credentials, so that passwords would not be
|
|
||||||
* leaked.
|
|
||||||
*
|
|
||||||
* It is expected that this method will be removed once it is decided that
|
|
||||||
* supporting migration from old versions of Thunderbird and SeaMonkey should
|
|
||||||
* not be supported.
|
|
||||||
*/
|
|
||||||
void migrateLegacyCredentials();
|
|
||||||
|
|
||||||
/// The username that should be used for this group
|
/// The username that should be used for this group
|
||||||
attribute ACString groupUsername;
|
attribute ACString groupUsername;
|
||||||
|
|
||||||
|
|
|
@ -78,56 +78,6 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||||
#define NEWS_SCHEME "news:"
|
#define NEWS_SCHEME "news:"
|
||||||
#define SNEWS_SCHEME "snews:"
|
#define SNEWS_SCHEME "snews:"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
class AsyncAuthMigrator : public nsIMsgAsyncPromptListener {
|
|
||||||
public:
|
|
||||||
AsyncAuthMigrator(nsIMsgNewsFolder *folder) : m_folder(folder) {}
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSIMSGASYNCPROMPTLISTENER
|
|
||||||
|
|
||||||
void EnqueuePrompt();
|
|
||||||
|
|
||||||
private:
|
|
||||||
nsCOMPtr<nsIMsgNewsFolder> m_folder;
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(AsyncAuthMigrator, nsIMsgAsyncPromptListener)
|
|
||||||
|
|
||||||
NS_IMETHODIMP AsyncAuthMigrator::OnPromptStart(bool *retval)
|
|
||||||
{
|
|
||||||
*retval = true;
|
|
||||||
return m_folder->MigrateLegacyCredentials();
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP AsyncAuthMigrator::OnPromptAuthAvailable()
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP AsyncAuthMigrator::OnPromptCanceled()
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsyncAuthMigrator::EnqueuePrompt()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIMsgAsyncPrompter> prompter =
|
|
||||||
do_GetService(NS_MSGASYNCPROMPTER_CONTRACTID);
|
|
||||||
|
|
||||||
// Make up a fake unique key to prevent coalescing of prompts
|
|
||||||
// The address of this object should be sufficient
|
|
||||||
nsAutoCString queueKey;
|
|
||||||
queueKey.AppendInt((int32_t)(uint64_t)this);
|
|
||||||
prompter->QueueAsyncAuthPrompt(queueKey, false, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
nsMsgNewsFolder::nsMsgNewsFolder(void) :
|
nsMsgNewsFolder::nsMsgNewsFolder(void) :
|
||||||
|
@ -235,10 +185,6 @@ nsMsgNewsFolder::AddNewsgroup(const nsACString &name, const nsACString& setStr,
|
||||||
// cache this for when we open the db
|
// cache this for when we open the db
|
||||||
rv = newsFolder->SetReadSetFromStr(setStr);
|
rv = newsFolder->SetReadSetFromStr(setStr);
|
||||||
|
|
||||||
// I don't have a good time to do this, but this is as good as any...
|
|
||||||
nsRefPtr<AsyncAuthMigrator> delayedPrompt(new AsyncAuthMigrator(newsFolder));
|
|
||||||
delayedPrompt->EnqueuePrompt();
|
|
||||||
|
|
||||||
rv = folder->SetParent(this);
|
rv = folder->SetParent(this);
|
||||||
NS_ENSURE_SUCCESS(rv,rv);
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
|
@ -1218,80 +1164,6 @@ nsresult nsMsgNewsFolder::CreateNewsgroupUrlForSignon(const char *ref,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsMsgNewsFolder::MigrateLegacyCredentials()
|
|
||||||
{
|
|
||||||
// The original ways that authentication credentials were stored was rather
|
|
||||||
// complicated and messy. We used separate URLs as the "HTTP realm" field to
|
|
||||||
// permit prompting for username and password as separate dialogs. In this
|
|
||||||
// method, we check for this, and store them in the new unified credentials
|
|
||||||
// dialog.
|
|
||||||
|
|
||||||
// Create the URLs that the login manager needs
|
|
||||||
nsString signonUrl;
|
|
||||||
nsresult rv = CreateNewsgroupUrlForSignon(nullptr, signonUrl);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsString usernameUrl;
|
|
||||||
rv = CreateNewsgroupUrlForSignon("username", usernameUrl);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsString passwordUrl;
|
|
||||||
rv = CreateNewsgroupUrlForSignon("password", passwordUrl);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsCOMPtr<nsILoginManager> loginMgr =
|
|
||||||
do_GetService(NS_LOGINMANAGER_CONTRACTID, &rv);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
// Grab out the saved username
|
|
||||||
uint32_t count = 0;
|
|
||||||
nsILoginInfo **logins = nullptr;
|
|
||||||
rv = loginMgr->FindLogins(&count, signonUrl, EmptyString(), usernameUrl,
|
|
||||||
&logins);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
NS_ASSERTION(count <= 1, "Too many usernames?");
|
|
||||||
|
|
||||||
nsString username;
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
rv = logins[0]->GetPassword(username);
|
|
||||||
// Remove the saved login
|
|
||||||
loginMgr->RemoveLogin(logins[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
// Do the same things for the password
|
|
||||||
rv = loginMgr->FindLogins(&count, signonUrl, EmptyString(), passwordUrl,
|
|
||||||
&logins);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
NS_ASSERTION(count <= 1, "Too many passwords?");
|
|
||||||
|
|
||||||
nsString password;
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
rv = logins[0]->GetPassword(password);
|
|
||||||
loginMgr->RemoveLogin(logins[0]);
|
|
||||||
}
|
|
||||||
NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
// If there is nothing to migrate, then do nothing
|
|
||||||
if (username.IsEmpty() && password.IsEmpty())
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
// Make and add the new logon
|
|
||||||
nsCOMPtr<nsILoginInfo> newLogin = do_CreateInstance(NS_LOGININFO_CONTRACTID);
|
|
||||||
// We need to pass in JS equivalent to "null"; empty ("") isn't good enough
|
|
||||||
nsString voidString;
|
|
||||||
voidString.SetIsVoid(true);
|
|
||||||
newLogin->Init(signonUrl, voidString, signonUrl, username, password,
|
|
||||||
EmptyString(), EmptyString());
|
|
||||||
return loginMgr->AddLogin(newLogin);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMsgNewsFolder::GetAuthenticationCredentials(nsIMsgWindow *aMsgWindow,
|
nsMsgNewsFolder::GetAuthenticationCredentials(nsIMsgWindow *aMsgWindow,
|
||||||
bool mayPrompt, bool mustPrompt, bool *validCredentials)
|
bool mayPrompt, bool mustPrompt, bool *validCredentials)
|
||||||
|
|
|
@ -24,10 +24,6 @@ add_task(function *() {
|
||||||
var incomingServer = MailServices.accounts.createIncomingServer(null, kHostname,
|
var incomingServer = MailServices.accounts.createIncomingServer(null, kHostname,
|
||||||
kProtocol);
|
kProtocol);
|
||||||
|
|
||||||
// Force move to new credentials
|
|
||||||
incomingServer.rootFolder.QueryInterface(Ci.nsIMsgNewsFolder)
|
|
||||||
.migrateLegacyCredentials();
|
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
var count = {};
|
var count = {};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче