bug 84834, add password to pasword-manager API, r=racham, sr=alecf, a=blizzard

This commit is contained in:
morse%netscape.com 2001-06-13 22:50:22 +00:00
Родитель 7d19a0c13c
Коммит 693dec4df2
6 изменённых файлов: 48 добавлений и 8 удалений

Просмотреть файл

@ -30,6 +30,7 @@
interface nsIPassword : nsISupports {
readonly attribute string host;
readonly attribute wstring user;
readonly attribute wstring password;
};
%{ C++

Просмотреть файл

@ -32,15 +32,17 @@ nsPassword::nsPassword() {
NS_INIT_REFCNT();
}
nsPassword::nsPassword(char * host, PRUnichar * user) {
nsPassword::nsPassword(char * host, PRUnichar * user, PRUnichar * pswd) {
passwordHost = host;
passwordUser = user;
passwordPswd = pswd;
NS_INIT_REFCNT();
}
nsPassword::~nsPassword(void) {
CRTFREEIF(passwordHost);
CRTFREEIF(passwordUser);
CRTFREEIF(passwordPswd);
}
NS_IMETHODIMP nsPassword::GetHost(char * *aHost) {
@ -58,3 +60,11 @@ NS_IMETHODIMP nsPassword::GetUser(PRUnichar * *aUser) {
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsPassword::GetPassword(PRUnichar * *aPswd) {
if (passwordPswd) {
*aPswd = (PRUnichar *) nsMemory::Clone(passwordPswd, 2*(nsCRT::strlen(passwordPswd) + 1));
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}

Просмотреть файл

@ -36,13 +36,14 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPASSWORD
nsPassword(char * host, PRUnichar * user);
nsPassword(char * host, PRUnichar * user, PRUnichar * pswd);
nsPassword();
virtual ~nsPassword(void);
protected:
char * passwordHost;
PRUnichar * passwordUser;
PRUnichar * passwordPswd;
};
#endif /* nsPassword_h__ */

Просмотреть файл

@ -47,7 +47,8 @@ class nsPasswordManagerEnumerator : public nsISimpleEnumerator
{
char * host;
PRUnichar * user;
nsresult rv = SINGSIGN_Enumerate(mHostCount, mUserCount++, &host, &user);
PRUnichar * pswd;
nsresult rv = SINGSIGN_Enumerate(mHostCount, mUserCount++, &host, &user, &pswd);
if (NS_FAILED(rv)) {
return rv;
}
@ -55,8 +56,12 @@ class nsPasswordManagerEnumerator : public nsISimpleEnumerator
mUserCount = 0;
mHostCount++;
}
nsIPassword *password = new nsPassword(host, user);
nsIPassword *password = new nsPassword(host, user, pswd);
// note that memory is handed off to "new nsPassword" in a non-xpcom fashion
if (password == nsnull) {
nsMemory::Free(host);
nsMemory::Free(user);
nsMemory::Free(pswd);
return NS_ERROR_OUT_OF_MEMORY;
}
*result = password;
@ -102,8 +107,9 @@ class nsPasswordManagerRejectEnumerator : public nsISimpleEnumerator
return rv;
}
nsIPassword *password = new nsPassword(host, nsnull); /* second argument is not used */
nsIPassword *password = new nsPassword(host, nsnull, nsnull); /* only first argument used */
if (password == nsnull) {
nsMemory::Free(host);
return NS_ERROR_OUT_OF_MEMORY;
}
*result = password;

Просмотреть файл

@ -2642,7 +2642,8 @@ SINGSIGN_UserCount(PRInt32 host) {
PUBLIC nsresult
SINGSIGN_Enumerate
(PRInt32 hostNumber, PRInt32 userNumber, char **host, PRUnichar ** user) {
(PRInt32 hostNumber, PRInt32 userNumber, char **host,
PRUnichar ** user, PRUnichar ** pswd) {
if (hostNumber > SINGSIGN_HostCount() || userNumber > SINGSIGN_UserCount(hostNumber)) {
return NS_ERROR_FAILURE;
@ -2661,7 +2662,8 @@ SINGSIGN_Enumerate
/* first non-password data item for user is the username */
PRInt32 dataCount = userStruct->signonData_list.Count();
for (PRInt32 k=0; k<dataCount; k++) {
PRInt32 k;
for (k=0; k<dataCount; k++) {
data = NS_STATIC_CAST(si_SignonDataStruct *, userStruct->signonData_list.ElementAt(k));
if (!(data->isPassword)) {
break;
@ -2676,6 +2678,25 @@ SINGSIGN_Enumerate
if (!(*user = userName.ToNewUnicode())) {
return NS_ERROR_OUT_OF_MEMORY;
}
/* first password data item for user is the password */
for (k=0; k<dataCount; k++) {
data = NS_STATIC_CAST(si_SignonDataStruct *, userStruct->signonData_list.ElementAt(k));
if ((data->isPassword)) {
break;
}
}
nsAutoString passWord;
if (NS_FAILED(si_Decrypt(data->value, passWord))) {
/* don't display saved signons if user couldn't unlock the database */
Recycle(*user);
return NS_ERROR_FAILURE;
}
if (!(*pswd = passWord.ToNewUnicode())) {
Recycle(*user);
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}

Просмотреть файл

@ -53,7 +53,8 @@ extern PRInt32
SINGSIGN_RejectCount();
extern nsresult
SINGSIGN_Enumerate(PRInt32 hostNumber, PRInt32 userNumber, char **host, PRUnichar **user);
SINGSIGN_Enumerate
(PRInt32 hostNumber, PRInt32 userNumber, char **host, PRUnichar **user, PRUnichar **pswd);
extern nsresult
SINGSIGN_RejectEnumerate(PRInt32 rejectNumber, char **host);