Changes to reflect the transition from Windows to Netscape Registry

This commit is contained in:
racham%netscape.com 1998-09-03 21:00:52 +00:00
Родитель 747631900d
Коммит 91d9580a12
2 изменённых файлов: 317 добавлений и 148 удалений

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

@ -31,6 +31,7 @@ INCS= \
-I. -I..\include \
-I$(DEPTH)\dist\public\java \
-I$(DEPTH)\dist\public\nspr \
-I$(DEPTH)\dist\public\libreg \
!ifdef MOZ_PRIV
-I$(PRIVDIR) \
-I$(PRIVDIR)\..\..\shiva \
@ -123,6 +124,8 @@ DLL_LIBS=mapi32.lib \
comdlg32.lib \
uuid.lib \
ole32.lib \
$(LIBNSPR) \
$(DEPTH)\dist\$(OBJDIR)\lib\libreg32.lib \
$(DLL_LIBS)
!endif

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

@ -19,6 +19,11 @@
#include <npapi.h>
#include "plugin.h"
// Netscape Registry header file
#include "NSReg.h"
#include "xp_mem.h"
// resource include
#ifdef WIN32 // **************************** WIN32 *****************************
#include "resource.h"
@ -35,6 +40,8 @@
#define INI_CURRUSER_KEY "CurrentUser"
#endif // !WIN32
#define MAX_PATH_LENGTH 256
// java includes
#include "netscape_npasw_SetupPlugin.h"
#include "java_lang_String.h"
@ -43,6 +50,8 @@ extern const char *GetStringPlatformChars(JRIEnv *env, struct java_lang_String *
void GetProfileDirectory(char *profilePath);
REGERR CopyNetscapeRegKey(HREG hReg, RKEY key, const char *path, RKEY newKey, char *newPath);
REGERR DeleteKeyTree(HREG hReg, RKEY key, const char *path);
//********************************************************************************
@ -56,50 +65,68 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fGetCurrentProfileDirectory(JRIEnv*
struct netscape_npasw_SetupPlugin* self)
{
struct java_lang_String *profilePath = NULL;
char buf[_MAX_PATH];
DWORD bufsize = sizeof(buf);
char buf[MAX_PATH_LENGTH];
buf[0] = '\0';
#ifdef WIN32 // ***************************** WIN32 ********************************
HKEY hKey;
HREG reg;
RKEY rKey1, rKey2;
char *keyPath = (char *)malloc(sizeof(char) * 512);
assert(keyPath);
if (!keyPath)
return NULL;
strcpy(keyPath, "SOFTWARE\\Netscape\\Netscape Navigator\\Users");
// finds the user profile path in registry
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyPath, NULL, KEY_ALL_ACCESS, &hKey))
strcpy(keyPath, "Netscape/ProfileManager");
// Open Netscape Registry
if (REGERR_OK == NR_RegOpen(NULL, &reg))
{
// Get the handle to the common information
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, keyPath, &rKey1))
{
//Get the current user profile
if (REGERR_OK == NR_RegGetEntryString(reg, rKey1, "LastNetscapeUser", buf, MAX_PATH_LENGTH))
{
//Get the handle to the current profile
if( REGERR_OK == NR_RegGetKey(reg, ROOTKEY_USERS, buf, &rKey2))
{
// Get the current profile location
if (REGERR_OK == NR_RegGetEntryString(reg, rKey2, "ProfileLocation", (char *)buf, MAX_PATH_LENGTH))
{
// make sure we append the last '\' in the profile dir path
strcat(buf, "\\");
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "CurrentUser", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize)) {
RegCloseKey(hKey);
strcat(keyPath, "\\");
strcat(keyPath, buf);
buf[0]='\0';
bufsize = sizeof(buf); // bufsize got reset from the last RegQueryValueEx
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyPath, NULL, KEY_ALL_ACCESS, &hKey)) {
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "DirRoot", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize)) {
// make sure we append the last '\' in the profile dir path
strcat(buf, "\\");
int len = strlen(buf);
profilePath = JRI_NewStringPlatform(env, buf, len, NULL, 0);
RegCloseKey(hKey);
profilePath = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0);
NR_RegClose(reg);
}
else
{
trace("profile.cpp : GetCurrentProfileDirectiory : Error in obtaining Current User profile location");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_USERS");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Error in obtaining Current User profile");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_COMMON");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not open Netscape Registry");
}
free(keyPath);
#else // ***************************** WIN16 ********************************
@ -124,28 +151,43 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fGetCurrentProfileName(JRIEnv* env,
struct netscape_npasw_SetupPlugin* self)
{
struct java_lang_String *profileName = NULL;
char buf[_MAX_PATH];
DWORD bufsize = sizeof(buf);
char buf[MAX_PATH_LENGTH];
buf[0] = '\0';
#ifdef WIN32 // ***************************** WIN32 ********************************
HKEY hKey;
HREG reg;
RKEY rKey;
// finds the user profile path in registry
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Netscape\\Netscape Navigator\\Users",
NULL,
KEY_ALL_ACCESS,
&hKey))
// Open Netscape Registry
if (REGERR_OK == NR_RegOpen(NULL, &reg))
{
// finds the user profile path in registry
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, "Netscape/ProfileManager", &rKey))
{
//Get the current user profile
if (REGERR_OK == NR_RegGetEntryString(reg, rKey, "LastNetscapeUser", buf, MAX_PATH_LENGTH))
{
profileName = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0);
RegQueryValueEx(hKey, "CurrentUser", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize);
profileName = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0);
RegCloseKey(hKey);
NR_RegClose(reg);
}
else
{
trace("profile.cpp : GetCurrentProfileName : Error in obtaining Current User profile location");
}
}
else
{
trace("profile.cpp : GetCurrentProfileName : Could not obtain handle to ROOTKEY_COMMON");
}
}
else
{
trace("profile.cpp : GetCurrentProfileName : Could not open Netscape Registry");
}
#else // ***************************** WIN16 ********************************
// get current profile name
@ -316,103 +358,101 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fSetCurrentProfileName(JRIEnv* env,
#ifdef WIN32 // ***************************** WIN32 ********************************
char *newPath;
char *oldPath;
char *Path = "SOFTWARE\\Netscape\\Netscape Navigator\\Users";
char buf[_MAX_PATH];
DWORD bufsize = sizeof(buf);
char *newProfName;
char *oldProfName;
char buf[MAX_PATH_LENGTH];
char *keyPath = (char *)malloc(sizeof(char) * 512);
HKEY hKeyUsers;
HKEY hKeyNewName;
HKEY hKeyOldName;
assert(keyPath);
if (!keyPath)
return;
strcpy(keyPath, "Netscape/ProfileManager");
HREG reg;
RKEY rKey1, rKey2;
DWORD dwDisposition;
BOOL Err = FALSE;
if (JSprofileName != NULL)
newProfileName = GetStringPlatformChars(env, JSprofileName);
oldPath = (char *)malloc(sizeof(char) * 260);
newPath = (char *)malloc(sizeof(char) * 260);
oldProfName = (char *)malloc(sizeof(char) * 260);
newProfName = (char *)malloc(sizeof(char) * 260);
if ((!oldPath) && (!newPath))
if ((!oldProfName) && (!newProfName))
return;
// finds the user profile path in registry
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, Path, NULL, KEY_ALL_ACCESS, &hKeyUsers)) {
// Open Netscape Registry
if (REGERR_OK == NR_RegOpen(NULL, &reg))
{
// Get the handle to the common information
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, keyPath, &rKey1))
{
//Get the current user profile
if (REGERR_OK == NR_RegGetEntryString(reg, rKey1, "LastNetscapeUser", buf, MAX_PATH_LENGTH))
{
// old user profile key path
strcat (oldProfName, buf);
// finds out the value of CurrentUser (the default user)
if (ERROR_SUCCESS == RegQueryValueEx(hKeyUsers, "CurrentUser", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize)) {
// new user profile key path
strcat (newProfName, newProfileName);
// old user profile key path
strcpy (oldPath, Path);
strcat (oldPath, "\\");
strcat (oldPath, buf);
// new user profile key path
strcpy (newPath, Path);
strcat (newPath, "\\");
strcat (newPath, newProfileName);
// check if the new ProfileName is same as old ProfileName, if it is, we don't
// need to do anything.
if (strcmp(oldPath, newPath) == 0) {
RegCloseKey(hKeyUsers);
free(newPath);
free(oldPath);
return;
}
// create a new key for our new profile name
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, newPath, NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &hKeyNewName, &dwDisposition)) {
// now... we enumerate old profile key contents and copy everything into new profile key
// first, gets the hkey for the old profile path
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldPath, NULL, KEY_ALL_ACCESS, &hKeyOldName)) {
DWORD subKeys;
DWORD maxSubKeyLen;
DWORD maxClassLen;
DWORD values;
DWORD maxValueNameLen;
DWORD maxValueLen;
DWORD securityDescriptor;
FILETIME lastWriteTime;
// get some information about this old profile key
if (ERROR_SUCCESS == RegQueryInfoKey(hKeyOldName, NULL, NULL, NULL, &subKeys, &maxSubKeyLen, &maxClassLen, &values, &maxValueNameLen, &maxValueLen, &securityDescriptor, &lastWriteTime)) {
// copy the values
BOOL NoErr = CopyRegKeys(hKeyOldName, hKeyNewName, subKeys, maxSubKeyLen, maxClassLen, values, maxValueNameLen, maxValueLen, oldPath, newPath);
// delete the old Key, if everything went well
if (NoErr) {
if (ERROR_SUCCESS != RegDeleteKey(hKeyUsers, buf)) {
// unknown err happened, can't delete key
Err = TRUE;
}
// also, resets the CurrentUser key to point to the newly renamed key
if (hKeyUsers) {
char *CurrentUserkey = "CurrentUser";
long ret = RegSetValueEx(hKeyUsers, CurrentUserkey, 0, REG_SZ, (unsigned char *)newProfileName, strlen(newProfileName) + 1);
}
}
}
// check if the new ProfileName is same as old ProfileName, if it is, we don't
// need to do anything.
if (strcmp(oldProfName, newProfName) == 0) {
NR_RegClose(reg);
free(newProfName);
free(oldProfName);
return;
}
RegCloseKey(hKeyUsers);
RegCloseKey(hKeyNewName);
RegCloseKey(hKeyOldName);
free(oldPath);
// Get the handle to the user profile to be modified
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_USERS, oldProfName, &rKey2))
{
if (REGERR_OK == CopyNetscapeRegKey (reg, ROOTKEY_USERS, (char *)oldProfName, ROOTKEY_USERS, (char *) newProfName))
{
DeleteKeyTree(reg, ROOTKEY_USERS, (char *)oldProfName);
}
else
{
trace("profile.cpp : SetCurrentProfile : Error in copying keys");
}
}
else
{
trace("profile.cpp : SetCurrentProfile : Error in obtaining a handle to ROOTKEY_USERS");
}
}
free(newPath);
else
{
trace("profile.cpp : SetCurrentProfile : Error in obtaining current profile value");
}
}
else
{
trace("profile.cpp : SetCurrentProfile : Error in obtaining a handle to ROOTKEY_COMMON");
}
}
else
{
trace("profile.cpp : SetCurrentProfile : Error opening Netscape registry");
}
if (REGERR_OK == NR_RegSetUsername(newProfName))
{
trace("profile.cpp : SetCurrentProfile : New profile name is the current user name");
}
else
{
trace("profile.cpp : SetCurrentProfile : Error in setting the new profile name to be the current profile name");
}
NR_RegClose(reg);
free(oldProfName);
free(newProfName);
#else // ***************************** WIN16 ********************************
@ -463,48 +503,70 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fSetCurrentProfileName(JRIEnv* env,
//********************************************************************************
void GetProfileDirectory(char *profilePath)
{
char buf[_MAX_PATH];
DWORD bufsize = sizeof(buf);
char buf[MAX_PATH_LENGTH];
buf[0] = '\0';
#ifdef WIN32
HKEY hKey;
HREG reg;
RKEY rKey1, rKey2;
char *keyPath = (char *)malloc(sizeof(char) * 512);
assert(keyPath);
if (!keyPath)
return;
strcpy(keyPath, "SOFTWARE\\Netscape\\Netscape Navigator\\Users");
// finds the user profile path in registry
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyPath, NULL, KEY_ALL_ACCESS, &hKey))
strcpy(keyPath, "Netscape/ProfileManager");
// Open Netscape Registry
if (REGERR_OK == NR_RegOpen(NULL, &reg))
{
// Get the handle to the common information
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, keyPath, &rKey1))
{
//Get the current user profile
if (REGERR_OK == NR_RegGetEntryString(reg, rKey1, "LastNetscapeUser", buf, MAX_PATH_LENGTH))
{
//Get the handle to the current profile
if( REGERR_OK == NR_RegGetKey(reg, ROOTKEY_USERS, buf, &rKey2))
{
// Get the current profile location
if (REGERR_OK == NR_RegGetEntryString(reg, rKey2, "ProfileLocation", (char *)buf, MAX_PATH_LENGTH))
{
// make sure we append the last '\' in the profile dir path
strcat(buf, "\\");
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "CurrentUser", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize)) {
RegCloseKey(hKey);
strcat(keyPath, "\\");
strcat(keyPath, buf);
buf[0]='\0';
bufsize = sizeof(buf); // bufsize got reset from the last RegQueryValueEx
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyPath, NULL, KEY_ALL_ACCESS, &hKey)) {
if (ERROR_SUCCESS == RegQueryValueEx(hKey, "DirRoot", NULL, NULL, (LPBYTE)buf, (LPDWORD)&bufsize)) {
// make sure we append the last '\' in the profile dir path
strcat(buf, "\\");
RegCloseKey(hKey);
NR_RegClose(reg);
}
else
{
trace("profile.cpp : GetCurrentProfileDirectiory : Error in obtaining Current User profile location");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_USERS");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Error in obtaining Current User profile");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_COMMON");
}
}
else
{
trace("profile.cpp : GetCurrentProfileDirectory : Could not open Netscape Registry");
}
free(keyPath);
#else // WIN16
#else // ***************************** WIN16 ********************************
char keyPath[_MAX_PATH];
// get current user profile
@ -528,3 +590,107 @@ void GetProfileDirectory(char *profilePath)
}
REGERR
CopyNetscapeRegKey(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
const char *path, /* relative path of subkey to find */
RKEY newKey, /* new root key */
char *newPath /* new path */
)
{
char keyName[MAX_PATH_LENGTH];
REGERR err;
REGENUM keyState = NULL, entryState = NULL;
REGINFO regInfo;
RKEY sourceKey, destKey;
err = NR_RegGetKey(hReg, key, (char *) path, &sourceKey);
if (err == REGERR_OK) {
err = NR_RegAddKey(hReg, newKey, newPath, &destKey);
}
if (err == REGERR_OK) {
char entryName[MAX_PATH_LENGTH];
uint32 dataSize;
unsigned char smallBuffer[256];
void *pData;
regInfo.size = sizeof(REGINFO);
entryState = NULL;
while (err == REGERR_OK) {
err = NR_RegEnumEntries(hReg, sourceKey, &entryState, entryName, MAX_PATH_LENGTH, &regInfo);
if (err == REGERR_OK) {
if (regInfo.entryLength < 256) {
pData = (void *) smallBuffer;
dataSize = 256;
} else {
pData = (void *) XP_ALLOC(regInfo.entryLength);
dataSize = regInfo.entryLength;
}
err = NR_RegGetEntry(hReg, sourceKey, entryName, pData, &dataSize);
if (err == REGERR_OK) {
err = NR_RegSetEntry(hReg, destKey, entryName, regInfo.entryType, pData, dataSize);
}
if (pData != smallBuffer) {
XP_FREEIF(pData);
}
}
}
if (err == REGERR_NOMORE) {
err = REGERR_OK;
}
while (err == REGERR_OK) {
err = NR_RegEnumSubkeys(hReg, sourceKey, &keyState, keyName, MAX_PATH_LENGTH, 0);
if (err == REGERR_OK) {
err = CopyNetscapeRegKey(hReg, sourceKey, keyName, destKey, keyName);
}
}
if (err == REGERR_NOMORE) {
err = REGERR_OK;
}
} /* if (destKey) */
return err;
}
REGERR
DeleteKeyTree(
HREG hReg, /* handle of open registry */
RKEY key, /* root key */
const char *path /* relative path of subkey to find */
)
{
char keyName[MAX_PATH_LENGTH];
REGERR err;
REGENUM keyState = NULL;
RKEY keyToDelete;
err = NR_RegGetKey(hReg, key, (char *) path, &keyToDelete);
while (err == REGERR_OK) {
err = NR_RegEnumSubkeys(hReg, keyToDelete, &keyState, keyName, MAX_PATH_LENGTH, REGENUM_DEPTH_FIRST);
if (err == REGERR_OK) {
NR_RegDeleteKey(hReg, keyToDelete, keyName);
}
}
err = NR_RegDeleteKey(hReg, key, (char *) path);
return err;
}