Bug 299017. Fix for firefox 2.0 and firefox 1.5.10, password file.

This commit is contained in:
Jim Norman 2007-08-10 18:18:27 +00:00
parent 93bb0f1046
commit 2943d7a557
7 changed files with 160 additions and 41 deletions

View File

@ -60,6 +60,7 @@ namespace Novell.CASA.DataEngines.FF
{ {
public IntPtr name; public IntPtr name;
public IntPtr value; public IntPtr value;
public IntPtr formUrl;
public int isPassword; public int isPassword;
public IntPtr next; public IntPtr next;
/*public HostElement() /*public HostElement()

View File

@ -38,6 +38,7 @@ struct HostElement
{ {
char *name; char *name;
char *value; char *value;
char *formUrl;
int isPassword; int isPassword;
struct HostElement *next; struct HostElement *next;
}; };

View File

@ -400,6 +400,10 @@ HostElement *t, *temp;
{ {
nh->name = (char*) malloc(strlen(t->name) + 1 ); nh->name = (char*) malloc(strlen(t->name) + 1 );
nh->value = (char*) malloc(strlen(t->value) + 1); nh->value = (char*) malloc(strlen(t->value) + 1);
if (t->formUrl != NULL)
nh->formUrl = (char*) malloc(strlen(t->formUrl) + 1);
else
nh->formUrl = NULL;
} }
if( !nh || !nh->name || !nh->value) if( !nh || !nh->name || !nh->value)
@ -408,6 +412,10 @@ HostElement *t, *temp;
nh->isPassword = t->isPassword; nh->isPassword = t->isPassword;
strcpy(nh->name, t->name); strcpy(nh->name, t->name);
strcpy(nh->value, t->value); strcpy(nh->value, t->value);
if (t->formUrl != NULL)
strcpy(nh->formUrl, t->formUrl);
nh->next = NULL; nh->next = NULL;
if( prev == NULL ) if( prev == NULL )
@ -426,8 +434,9 @@ duplicate_error:
// cleanup partially loaded data // cleanup partially loaded data
for(t=newHost->child; t ; ) for(t=newHost->child; t ; )
{ {
if(t->name) free(t); if(t->name) free(t->name);
if(t->value) free(t); if(t->value) free(t->value);
if(t->formUrl) free(t->formUrl);
temp = t; temp = t;
t = t->next; t = t->next;
@ -461,7 +470,7 @@ void DataManager::PrintAllHosts()
int DataManager::AddHostElement(char *hostName, char *name, char *value, unsigned char isPassword) int DataManager::AddHostElement(char *hostName, char *name, char *value, unsigned char isPassword, char *formUrl)
{ {
Host *host; Host *host;
HostElement *h, *t; HostElement *h, *t;
@ -503,6 +512,14 @@ int DataManager::AddHostElement(char *hostName, char *name, char *value, unsigne
{ {
temp->name = (char*) malloc( strlen(name)+1 ); temp->name = (char*) malloc( strlen(name)+1 );
temp->value = (char*) malloc( strlen( value) + 1 ); temp->value = (char*) malloc( strlen( value) + 1 );
if (formUrl != NULL)
{
temp->formUrl = (char*) malloc( strlen( formUrl) + 1);
}
else
{
temp->formUrl = NULL;
}
} }
if( !temp || !temp->name || !temp->value ) if( !temp || !temp->name || !temp->value )
@ -514,6 +531,11 @@ int DataManager::AddHostElement(char *hostName, char *name, char *value, unsigne
strcpy(temp->name,name); strcpy(temp->name,name);
strcpy(temp->value, value); strcpy(temp->value, value);
temp->isPassword = isPassword; temp->isPassword = isPassword;
// save the formUrl
if (formUrl != NULL)
strcpy(temp->formUrl, formUrl);
temp->next = NULL; temp->next = NULL;
// Now add it to the host... // Now add it to the host...
@ -570,6 +592,10 @@ int DataManager::RemoveHostElement(char *hostName, char *value)
free(h->value); free(h->value);
free(h->name); free(h->name);
if (h->formUrl)
free(h->formUrl);
free(h); free(h);
return FPM_TRUE; return FPM_TRUE;

View File

@ -50,7 +50,7 @@ public:
int RemoveHost(char *hostName); int RemoveHost(char *hostName);
void PrintAllHosts(); void PrintAllHosts();
int AddHostElement(char *hostName, char *name, char *value, unsigned char isPassword); int AddHostElement(char *hostName, char *name, char *value, unsigned char isPassword, char *formUrl);
int RemoveHostElement(char *hostName, char *clearValue); int RemoveHostElement(char *hostName, char *clearValue);
Host* DuplicateHost(Host *host); Host* DuplicateHost(Host *host);

View File

@ -89,9 +89,13 @@
#define Unichar unsigned int #define Unichar unsigned int
#define HEADER_VERSION "#2c" #define HEADER_VERSION "#2c"
// firefox 1.5.10 & greater and firefox 2.0
#define HEADER_VERSION2 "#2d"
#define CRYPT_PREFIX "~" #define CRYPT_PREFIX "~"
#define SIGNON_FILE_NAME "signons.txt" #define SIGNON_FILE_NAME "signons.txt"
#define SIGNON_FILE_NAME2 "signons2.txt"
// Internal structure declaration taken from firefox..... // Internal structure declaration taken from firefox.....
typedef enum SECItemType typedef enum SECItemType

View File

@ -50,7 +50,7 @@ void SignonManager::SetupFunctions(void *funList[])
int SignonManager::OpenSignonFile(char *firefoxProfileDir, char *fileName, char *accessType ) int SignonManager::OpenSignonFile(char *firefoxProfileDir, char *fileName, char *accessType, bool create )
{ {
char *signonFilePath = NULL; char *signonFilePath = NULL;
@ -76,27 +76,36 @@ char *signonFilePath = NULL;
// Open the signon file // Open the signon file
signonFile = fopen(signonFilePath, accessType); signonFile = fopen(signonFilePath, accessType);
if( signonFile == NULL ) if( signonFile == NULL)
{ {
PrintMessage(MESG_DEBUG, "\n SignonManager : Error opening signon file %s", signonFilePath);
PrintMessage(MESG_DEBUG, "\n SignonManager : Creating new signon file %s", signonFilePath);
if((signonFile = fopen(signonFilePath, "a")) == NULL) if (create)
{ {
PrintMessage(MESG_ERROR, "\n SignonManager : Error creating signon file %s", signonFilePath); PrintMessage(MESG_DEBUG, "\n SignonManager : Error opening signon file %s", signonFilePath);
free(signonFilePath); PrintMessage(MESG_DEBUG, "\n SignonManager : Creating new signon file %s", signonFilePath);
return FPM_SIGNON_FILE_NOT_PRESENT;
} if((signonFile = fopen(signonFilePath, "a")) == NULL)
if( WriteLine(HEADER_VERSION) != FPM_TRUE) {
{ PrintMessage(MESG_ERROR, "\n SignonManager : Error creating signon file %s", signonFilePath);
PrintMessage(MESG_ERROR, "\n SignonManager : Error writing header to new signon file %s", signonFilePath); free(signonFilePath);
free(signonFilePath); return FPM_SIGNON_FILE_NOT_PRESENT;
}
if( WriteLine(HEADER_VERSION) != FPM_TRUE)
{
PrintMessage(MESG_ERROR, "\n SignonManager : Error writing header to new signon file %s", signonFilePath);
free(signonFilePath);
fclose(signonFile);
return FPM_SIGNON_FILE_NOT_PRESENT;
}
fclose(signonFile); fclose(signonFile);
signonFile = fopen(signonFilePath, accessType);
}
else
{
free(signonFilePath);
return FPM_SIGNON_FILE_NOT_PRESENT; return FPM_SIGNON_FILE_NOT_PRESENT;
} }
fclose(signonFile);
signonFile = fopen(signonFilePath, accessType);
} }
// cleanup // cleanup
@ -287,12 +296,22 @@ int retValue;
char *clearData = NULL; char *clearData = NULL;
char *newHostName, *uname; char *newHostName, *uname;
int count = 0; int count = 0;
bool isFireFox2 = false;
char formUrl[4096];
// open the signon file // open the signon file, try Firefox2 first
if( (retValue = OpenSignonFile(firefoxProfileDir, SIGNON_FILE_NAME, "r")) != FPM_TRUE ) if( (retValue = OpenSignonFile(firefoxProfileDir, SIGNON_FILE_NAME2, "r", false)) != FPM_TRUE )
{ {
return retValue; if( (retValue = OpenSignonFile(firefoxProfileDir, SIGNON_FILE_NAME, "r", true)) != FPM_TRUE )
{
return retValue;
}
}
else
{
PrintMessage(MESG_DEBUG, "\n SignonManager : New Password file exists");
isFireFox2 = true;
} }
// Clean up any previously loaded data... // Clean up any previously loaded data...
@ -307,11 +326,24 @@ int count = 0;
} }
// check if the format is right... // check if the format is right...
if( strcmp(header, HEADER_VERSION) != 0) if (isFireFox2)
{ {
PrintMessage(MESG_ERROR, "\n SignonManager : Header version information is not proper"); if( strcmp(header, HEADER_VERSION2) != 0)
CloseSignonFile(); {
return FPM_SIGNON_FILE_INVALID_DATA; PrintMessage(MESG_ERROR, "\n SignonManager : Header version information is not proper");
CloseSignonFile();
return FPM_SIGNON_FILE_INVALID_DATA;
}
}
else
{
if( strcmp(header, HEADER_VERSION) != 0)
{
PrintMessage(MESG_ERROR, "\n SignonManager : Header version information is not proper");
CloseSignonFile();
return FPM_SIGNON_FILE_INVALID_DATA;
}
} }
@ -426,13 +458,34 @@ int count = 0;
strncat(newHostName, ")", 1); strncat(newHostName, ")", 1);
dataManager.AddHost(newHostName); dataManager.AddHost(newHostName);
} }
retValue = dataManager.AddHostElement(newHostName, name, clearData, isPassword);
// read formUrl if Firefox 2
if (isFireFox2 && isPassword)
{
retValue = ReadLine(formUrl, bufferLength);
retValue = dataManager.AddHostElement(newHostName, name, clearData, isPassword, formUrl);
}
else
{
retValue = dataManager.AddHostElement(newHostName, name, clearData, isPassword, NULL);
}
if(count%2==0) if(count%2==0)
free(newHostName); free(newHostName);
} }
else else
retValue = dataManager.AddHostElement(hostName, name, clearData, isPassword); {
// read formUrl if Firefox 2
if (isFireFox2 && isPassword)
{
retValue = ReadLine(formUrl, bufferLength);
retValue = dataManager.AddHostElement(hostName, name, clearData, isPassword, formUrl);
}
else
{
retValue = dataManager.AddHostElement(hostName, name, clearData, isPassword, NULL);
}
}
if( retValue != FPM_TRUE ) if( retValue != FPM_TRUE )
{ {
@ -449,8 +502,8 @@ int count = 0;
return retValue; return retValue;
} }
} }
if (count >2) if (count >2)
{ {
newHostName = (char *)malloc((strlen(hostName)+strlen(uname)+4)*sizeof(char)); newHostName = (char *)malloc((strlen(hostName)+strlen(uname)+4)*sizeof(char));
@ -490,6 +543,7 @@ HostElement *h, *temp;
RejectHost *r; RejectHost *r;
char *hn2; char *hn2;
int len; int len;
bool isFireFox2 = false;
// TODO : If signon data has not changed since last write then return... // TODO : If signon data has not changed since last write then return...
/* // There may be requirement to write empty data... /* // There may be requirement to write empty data...
@ -505,7 +559,19 @@ int len;
sprintf(fileName,"signon_fpm_%d.txt", rand()); sprintf(fileName,"signon_fpm_%d.txt", rand());
// Setup the signon and temp filename.. // Setup the signon and temp filename..
signonFilePath = (char*) malloc( strlen(firefoxProfileDir) + strlen(SIGNON_FILE_NAME) + 3);
// Firefox 2 file?
if( (retValue = OpenSignonFile(firefoxProfileDir, SIGNON_FILE_NAME2, "r", false)) = FPM_TRUE )
{
signonFilePath = (char*) malloc( strlen(firefoxProfileDir) + strlen(SIGNON_FILE_NAME2) + 3);
CloseSignonFile();
isFireFox2 = true;
}
else
{
signonFilePath = (char*) malloc( strlen(firefoxProfileDir) + strlen(SIGNON_FILE_NAME) + 3);
}
tempFilePath =(char*) malloc( strlen(firefoxProfileDir) + strlen(fileName) + 3); tempFilePath =(char*) malloc( strlen(firefoxProfileDir) + strlen(fileName) + 3);
if( signonFilePath == NULL || tempFilePath == NULL) if( signonFilePath == NULL || tempFilePath == NULL)
@ -523,7 +589,7 @@ int len;
strcat(tempFilePath, fileName); strcat(tempFilePath, fileName);
// Open signon file // Open signon file
if( (retValue = OpenSignonFile(firefoxProfileDir, fileName, "w")) != FPM_TRUE ) if( (retValue = OpenSignonFile(firefoxProfileDir, fileName, "w", true)) != FPM_TRUE )
{ {
PrintMessage(MESG_ERROR, "\nWriteSignonData : Failed to create temp signon file : %s.", fileName); PrintMessage(MESG_ERROR, "\nWriteSignonData : Failed to create temp signon file : %s.", fileName);
return retValue; return retValue;
@ -531,15 +597,22 @@ int len;
// write out the format revision number // write out the format revision number
if( (retValue = WriteLine(HEADER_VERSION)) != FPM_TRUE) if (isFireFox2)
goto write_signon_error; {
if( (retValue = WriteLine(HEADER_VERSION2)) != FPM_TRUE)
goto write_signon_error;
}
else
{
if( (retValue = WriteLine(HEADER_VERSION)) != FPM_TRUE)
goto write_signon_error;
}
// write out reject host list // write out reject host list
for(r=dataManager.rejectHostList; r ; r=r->next) for(r=dataManager.rejectHostList; r ; r=r->next)
{ {
if( (retValue = WriteLine(r->hostName)) != FPM_TRUE ) if( (retValue = WriteLine(r->hostName)) != FPM_TRUE )
goto write_signon_error; goto write_signon_error;
} }
// End of reject host list // End of reject host list
@ -636,6 +709,21 @@ int len;
PrintMessage(MESG_ERROR, "\n nWriteSignonData : Encryption of value %s failed ", h->value); PrintMessage(MESG_ERROR, "\n nWriteSignonData : Encryption of value %s failed ", h->value);
goto write_signon_error; goto write_signon_error;
} }
// is this a firefox2 password file?
if ( isFireFox2 && h->isPassword)
{
if (h->formUrl != NULL)
{
if( (retValue = WriteLine(h->formUrl)) != FPM_TRUE )
goto write_signon_error;
}
else
{
if( (retValue = WriteLine(t->hostName)) != FPM_TRUE )
goto write_signon_error;
}
}
} }
if( (retValue = WriteLine(".")) != FPM_TRUE ) if( (retValue = WriteLine(".")) != FPM_TRUE )
@ -645,7 +733,6 @@ int len;
// close this temporary file... // close this temporary file...
CloseSignonFile(); CloseSignonFile();
PrintMessage(MESG_DEBUG, "\n WriteSignonData : Removing previous signon file %s ", signonFilePath); PrintMessage(MESG_DEBUG, "\n WriteSignonData : Removing previous signon file %s ", signonFilePath);
// Delete previous signon file // Delete previous signon file

View File

@ -46,7 +46,7 @@ public:
SignonManager(); SignonManager();
virtual ~SignonManager(); virtual ~SignonManager();
int OpenSignonFile(char *firefoxProfileDir, char *fileName, char *accessType ); int OpenSignonFile(char *firefoxProfileDir, char *fileName, char *accessType, bool create);
int CloseSignonFile(); int CloseSignonFile();
int ReadLine(char *buffer, int size); int ReadLine(char *buffer, int size);