-IsStoreAvailable() Functionality
This commit is contained in:
parent
8d6c6a44b9
commit
b84d53afb8
@ -9,6 +9,25 @@ ProfileManager profileManager[MAX_PROFILE_COUNT];
|
||||
int profileCount = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if firefox is there on the system
|
||||
*
|
||||
* @return 1 if firefox libraries are present
|
||||
* 0 otherwise
|
||||
*
|
||||
* It loads the libraries from the firefox library path and if they are loaded
|
||||
* successfully then that indicates that firefox is present.
|
||||
*
|
||||
*/
|
||||
extern "C" APIEXPORT int FPM_IsStoreAvailable()
|
||||
{
|
||||
ProfileManager pm;
|
||||
return pm.IsStoreAvailable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Gets the list of profile names...
|
||||
*
|
||||
@ -213,8 +232,26 @@ extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int *profileFl
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the firefox library with the specified profile
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @return 1 on success
|
||||
* <=0 on error
|
||||
*
|
||||
* It initializes the firefox library with the specified profile. This must be called before
|
||||
* invoking any operation on the specified profile.
|
||||
* It performs following tasks
|
||||
* * Determine firefox profile directory
|
||||
* * Loads the firefox security libraries.
|
||||
* * Initializes the firefox security library for the profile.
|
||||
*
|
||||
* If the mentioned profile is not found then FPM_PROFILE_NOT_PRESENT will be returned. If there is
|
||||
* an error in loading or initializing the firefox library then FPM_LIBRARY_LOAD_FAILED or FPM_LIBRARY_INIT_FAILED
|
||||
* is returned. If user has not enabled "remember passwords" then certain files (key3.db, cert8.db) required for
|
||||
* initialization will not be present in the profile directory. This can cause FPM_LIBRARY_INIT_FAILED error.
|
||||
*
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileInit(char *profileName)
|
||||
{
|
||||
@ -228,7 +265,7 @@ int profileIndex = -1;
|
||||
{
|
||||
if( STRCMPI(profileManager[i].profileName, profileName) == 0 )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n FirefoxProfileInit : Object for specified profile %s exist ", profileName);
|
||||
PrintMessage(MESG_DEBUG, "\n FirefoxProfileInit : Object for specified profile %s exist ", profileName);
|
||||
profileIndex = i;
|
||||
|
||||
break;
|
||||
@ -252,7 +289,7 @@ int profileIndex = -1;
|
||||
// check if the profile is already initialized...
|
||||
if( profileManager[profileIndex].isInitialized == FPM_TRUE )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n FirefoxProfileInit : Specified profile %s is already initialized", profileName);
|
||||
PrintMessage(MESG_DEBUG, "\n FirefoxProfileInit : Specified profile %s is already initialized", profileName);
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
@ -270,6 +307,18 @@ int profileIndex = -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Uninitializes the specified profile.
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @return 1 on success
|
||||
* <=0 on error
|
||||
*
|
||||
* Uninitializes the specified profile and unloads the firefox security library.
|
||||
* It also cleans up internal data structure.
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName)
|
||||
{
|
||||
// Find the profile...
|
||||
@ -303,6 +352,18 @@ extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies if master passsword is set for the specified profile
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @return 1 if master password is set
|
||||
* 0 if master password not set
|
||||
*
|
||||
* Checks if the master password is set or not for the specified profile. The application can
|
||||
* use this function to determine if the user has set the master password. If so it can prompt
|
||||
* the user to enter the master password.
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_IsMasterPasswordSet(char *profileName)
|
||||
{
|
||||
|
||||
@ -335,6 +396,21 @@ extern "C" APIEXPORT int FPM_IsMasterPasswordSet(char *profileName)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the master password is correct for the specified profile.
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @param masterPassword Master password to be checked.
|
||||
* @return 1 if the specified master password is correct
|
||||
* 0 if the master password is wrong.
|
||||
*
|
||||
*
|
||||
* Check if the specified master password is correct or not. If it is
|
||||
* correct then password is stored to the internal store for later use.
|
||||
* If it is wrong then nothing is stored and 0 will be returned.
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_CheckMasterPassword(char *profileName, char *masterPassword)
|
||||
{
|
||||
|
||||
@ -367,6 +443,28 @@ extern "C" APIEXPORT int FPM_CheckMasterPassword(char *profileName, char *master
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the signon data from the firefox signon file for specified profile
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @param struct Host** pointer to list of signon host structure
|
||||
* @param doRefresh signon data to be refreshed or not
|
||||
* @return 1 success
|
||||
* <= 0 If an error has occurred.
|
||||
*
|
||||
* Returns the pointer to the internal signon data store which contains list of hosts
|
||||
* and associated name/value pairs. If doRefresh value is positive then fresh signon
|
||||
* data is loaded from the signon file. Otherwise current signon data is returned.
|
||||
*
|
||||
* If the master password is set and its not specified or wrong password is specified
|
||||
* then error code FPM_MASTERPASSWORD_WRONG will be returned. In this case use
|
||||
* CheckMasterPassword function to set the correct master password and then call this
|
||||
* function again.
|
||||
*
|
||||
* In case of error in reading signon information FPM_SIGNON_FILE_READ_ERROR or
|
||||
* FPM_SIGNON_FILE_NOT_PRESENT will be returned.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
extern "C" APIEXPORT int FPM_GetSignonData(char *profileName,struct Host **host, int doRefresh)
|
||||
@ -400,7 +498,26 @@ extern "C" APIEXPORT int FPM_GetSignonData(char *profileName,struct Host **host,
|
||||
return FPM_PROFILE_NOT_PRESENT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the firefox signon file with new signon data.
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @return 1 If signon data written to the disk successfully
|
||||
* <=0 If an error has occurred.
|
||||
*
|
||||
* Writes the signon data from the internal signon data store to the disk. If an
|
||||
* error occurs then proper error code will be returned. If the master password is set
|
||||
* and its not specified or wrong password is specified then error code FPM_MASTERPASSWORD_WRONG
|
||||
* will be returned. In this case use CheckMasterPassword function to set the correct
|
||||
* master password and then call this function again.
|
||||
*
|
||||
* In case of write error, error code FPM_SIGNON_FILE_WRITE_ERROR will be returned.
|
||||
*
|
||||
* If the signon file is locked then error code FPM_SIGNON_FILE_LOCKED will be
|
||||
* returned. In this case application should ask the user to close the firefox
|
||||
* application and then it should call this function again.
|
||||
*
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_WriteSignonData(char *profileName)
|
||||
{
|
||||
@ -434,6 +551,22 @@ extern "C" APIEXPORT int FPM_WriteSignonData(char *profileName)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds signon data for new host...
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @param struct Host* pointer to host structure to be added
|
||||
* @param doUpdate signon data to be written to the file or not
|
||||
* @return 1 success
|
||||
* <=0 error
|
||||
*
|
||||
* Adds the specified host information to the internal signon data store. If the
|
||||
* value of doUpdate is positive then the entire signon data is written to the file.
|
||||
* Otherwise changes are done only in the internal data store.
|
||||
*
|
||||
* If doUpdate is positive then error code may be from FPM_WriteSignonData function.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
extern "C" APIEXPORT int FPM_AddHost(char *profileName, struct Host *host, int doUpdate)
|
||||
@ -468,7 +601,25 @@ extern "C" APIEXPORT int FPM_AddHost(char *profileName, struct Host *host, int d
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modifies the credentials for the specified host url for specified profile.
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @param struct Host* pointer to host structure to be modified.
|
||||
* @param doUpdate signon data to be written to the file or not
|
||||
* @return 1 success
|
||||
* <=0 error
|
||||
*
|
||||
* Modifes the values of the specified host with new values. If the value
|
||||
* of doUpdate is positive then the entire signon data is written to the file.
|
||||
* Otherwise changes are done only in the internal data store. If any of
|
||||
* the names ( name/value pairs ) is not matched with the existing name in the
|
||||
* Host's username/password list then error FPM_NAME_NOT_PRESENT is returned.
|
||||
*
|
||||
* If doUpdate is positive then error code may be from FPM_WriteSignonData function.
|
||||
*
|
||||
*/
|
||||
|
||||
extern "C" APIEXPORT int FPM_ModifyHost(char *profileName, struct Host *host, int doUpdate)
|
||||
{
|
||||
// Find the profile...
|
||||
@ -501,7 +652,24 @@ extern "C" APIEXPORT int FPM_ModifyHost(char *profileName, struct Host *host, in
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the signon credentials for specified host
|
||||
*
|
||||
* @param profileName name of the profile
|
||||
* @param hostName complete URL of the host name
|
||||
* @param doUpdate signon data to be written to the file or not
|
||||
*
|
||||
* @return 1 on success
|
||||
* <=0 on error
|
||||
*
|
||||
* Removes the specified host from the internal signon data store. All
|
||||
* name-value pairs associated with specified host will also be removed.
|
||||
* If the value of doUpdate is positive then the entire signon data is
|
||||
* written to the file. Otherwise changes are done only in the internal data store.
|
||||
*
|
||||
* If doUpdate is positive then error code may be from FPM_WriteSignonData function.
|
||||
*
|
||||
*/
|
||||
extern "C" APIEXPORT int FPM_RemoveHost(char *profileName, char *hostName, int doUpdate)
|
||||
{
|
||||
// Find the profile...
|
||||
@ -532,60 +700,6 @@ extern "C" APIEXPORT int FPM_RemoveHost(char *profileName, char *hostName, int d
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char **profileList;
|
||||
int *profileFlag;
|
||||
int profCount;
|
||||
|
||||
profCount = FPM_GetProfileList(&profileList, &profileFlag);
|
||||
|
||||
if( profCount > 0)
|
||||
{
|
||||
printf("\n Profile names are as follows...");
|
||||
for(int i=0; i< profCount; i++)
|
||||
{
|
||||
printf("\n %d => [%s] [%d]", i+1, profileList[i], profileFlag[i]);
|
||||
|
||||
// Load the default profile...
|
||||
if( profileFlag[i] == 1 )
|
||||
{
|
||||
ProfileManager *pm = new ProfileManager();
|
||||
printf("\n ***************************************");
|
||||
|
||||
if( pm->ProfileInit(profileList[i]) == 1)
|
||||
{
|
||||
pm->CheckMasterPassword("test123", 1);
|
||||
struct Host *hostInfo;
|
||||
pm->GetSignonData(&hostInfo, 1);
|
||||
|
||||
// Print all the data
|
||||
PrintMessage(MESG_PRINT, "\n\n List of hosts ");
|
||||
|
||||
for(Host *t=hostInfo; t ; t=t->next)
|
||||
{
|
||||
PrintMessage(MESG_PRINT, "\n\n %s", t->hostName);
|
||||
for(HostElement *h=t->child; h ; h= h->next)
|
||||
{
|
||||
PrintMessage(MESG_PRINT, "\n %s : %s ", h->name, h->value);
|
||||
}
|
||||
}
|
||||
|
||||
pm->WriteSignonData();
|
||||
|
||||
pm->ProfileExit();
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n ***************************************");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -141,6 +141,7 @@ void StrLwr(char *str);
|
||||
|
||||
|
||||
// Profile initiliazation functions
|
||||
extern "C" APIEXPORT int FPM_IsStoreAvailable();
|
||||
extern "C" APIEXPORT int FPM_GetProfileList(char **profileList[], int **profileFlag);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileInit(char *profileName);
|
||||
extern "C" APIEXPORT int FPM_FirefoxProfileExit(char *profileName);
|
||||
|
@ -391,6 +391,75 @@ HMODULE libtmp = NULL;
|
||||
return libtmp;
|
||||
}
|
||||
|
||||
//
|
||||
// Checks if store is available...
|
||||
//
|
||||
int ProfileManager::IsStoreAvailable()
|
||||
{
|
||||
|
||||
PrintMessage(MESG_DEBUG, "\n IsStoreAvailable : Checking if firefox and its libraries are present ");
|
||||
|
||||
|
||||
libraryPath = GetFirefoxLibPath();
|
||||
|
||||
if( !libraryPath )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsStoreAvailable : Failed to find firefox profile or library path ");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// First try to load from the library path then try to load from default lib path
|
||||
|
||||
// Here we have to first load all dependent libraries and then
|
||||
// load main library , otherwise face the problems...:)
|
||||
if( PMLoadLibrary(libraryPath, NSPR_LIBRARY_NAME) )
|
||||
{
|
||||
if((libplc=PMLoadLibrary(libraryPath, PLC_LIBRARY_NAME)) )
|
||||
{
|
||||
if( PMLoadLibrary(libraryPath, PLDS_LIBRARY_NAME) )
|
||||
{
|
||||
if( PMLoadLibrary(libraryPath, SOFTN_LIBRARY_NAME) )
|
||||
libnss=PMLoadLibrary(libraryPath, NSS_LIBRARY_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // try to load library from default library path
|
||||
{
|
||||
if( PMLoadLibrary(NULL, NSPR_LIBRARY_NAME) )
|
||||
{
|
||||
if((libplc=PMLoadLibrary(NULL, PLC_LIBRARY_NAME)) )
|
||||
{
|
||||
if( PMLoadLibrary(NULL, PLDS_LIBRARY_NAME) )
|
||||
{
|
||||
if( PMLoadLibrary(NULL, SOFTN_LIBRARY_NAME) )
|
||||
libnss=PMLoadLibrary(NULL, NSS_LIBRARY_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !libnss || !libplc )
|
||||
{
|
||||
PrintMessage(MESG_ERROR, "\n IsStoreAvailable : Failed to load the required firefox library");
|
||||
return FPM_FALSE;
|
||||
}
|
||||
|
||||
// Free the library
|
||||
if( libnss != NULL )
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n IsStoreAvailable : Freeing library libnss.dll");
|
||||
FREELIBRARY(libnss);
|
||||
}
|
||||
|
||||
if( libplc != NULL )
|
||||
{
|
||||
PrintMessage(MESG_DEBUG, "\n IsStoreAvailable : Freeing library libplc.dll");
|
||||
FREELIBRARY(libplc);
|
||||
}
|
||||
|
||||
return FPM_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
ProfileManager();
|
||||
|
||||
int IsStoreAvailable();
|
||||
int ProfileInit(char *profileName);
|
||||
void ProfileExit();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user