Fixed some bugs in the registry

Improved registry test app

svn path=/trunk/; revision=1343
This commit is contained in:
Eric Kohl 2000-09-06 19:59:54 +00:00
parent e7365f8b00
commit d7d755265d
5 changed files with 238 additions and 105 deletions

View file

@ -22,22 +22,78 @@ int main(int argc, char* argv[])
{
HKEY hKey = NULL;
DWORD dwDisposition;
DWORD dwError;
AllocConsole();
InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
dprintf ("RegCreateKeyExW:\n");
RegCreateKeyExW (HKEY_LOCAL_MACHINE,
L"Test",
0,
L"",
REG_OPTION_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
L"Test",
0,
L"",
REG_OPTION_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
dprintf ("dwError %x\n", dwError);
if (dwError != ERROR_SUCCESS)
return 0;
dprintf ("dwDisposition %x\n", dwDisposition);
dprintf ("RegSetValueExW:\n");
dwError = RegSetValueExW (hKey,
L"TestValue",
0,
REG_SZ,
L"TestString",
20);
dprintf ("dwError %x\n", dwError);
if (dwError != ERROR_SUCCESS)
return 0;
dprintf ("RegCloseKey:\n");
dwError = RegCloseKey (hKey);
dprintf ("dwError %x\n", dwError);
if (dwError != ERROR_SUCCESS)
return 0;
dprintf ("\n\n");
hKey = NULL;
dprintf ("RegCreateKeyExW:\n");
dwError = RegCreateKeyExW (HKEY_LOCAL_MACHINE,
L"Test",
0,
L"",
REG_OPTION_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
dprintf ("dwError %x\n", dwError);
if (dwError != ERROR_SUCCESS)
return 0;
dprintf ("dwDisposition %x\n", dwDisposition);
#if 0
dprintf ("RegQueryKeyExW:\n");
#endif
dprintf ("RegCloseKey:\n");
dwError = RegCloseKey (hKey);
dprintf ("dwError %x\n", dwError);
if (dwError != ERROR_SUCCESS)
return 0;
dprintf ("\nTests done...\n");

View file

@ -211,7 +211,7 @@ typedef char *PTSTR;
/*
typedef PWSTR;
*/
typedef PVOID REGSAM;
typedef DWORD REGSAM;
typedef short RETCODE;

View file

@ -1,4 +1,4 @@
; $Id: advapi32.edf,v 1.8 2000/04/06 02:29:43 ekohl Exp $
; $Id: advapi32.edf,v 1.9 2000/09/06 19:57:58 ekohl Exp $
;
; advapi32.def
;
@ -297,7 +297,7 @@ RegCreateKeyW=RegCreateKeyW@12
RegDeleteKeyA=RegDeleteKeyA@8
RegDeleteKeyW=RegDeleteKeyW@8
RegDeleteValueA=RegDeleteValueA@8
;RegDeleteValueW=RegDeleteValueW@8
RegDeleteValueW=RegDeleteValueW@8
RegEnumKeyA=RegEnumKeyA@16
RegEnumKeyExA=RegEnumKeyExA@32
;RegEnumKeyExW=RegEnumKeyExW@32
@ -330,8 +330,8 @@ RegSaveKeyA=RegSaveKeyA@12
;RegSetKeySecurity=RegSetKeySecurity@12
RegSetValueA=RegSetValueA@20
RegSetValueExA=RegSetValueExA@24
;RegSetValueExW=RegSetValueExW@24
;RegSetValueW=RegSetValueW@20
RegSetValueExW=RegSetValueExW@24
RegSetValueW=RegSetValueW@20
RegUnLoadKeyA=RegUnLoadKeyA@8
;RegUnLoadKeyW=RegUnLoadKeyW@8
;RegisterEventSourceA=RegisterEventSourceA@8

View file

@ -1,4 +1,4 @@
/* $Id: reg.c,v 1.8 2000/09/05 23:00:27 ekohl Exp $
/* $Id: reg.c,v 1.9 2000/09/06 19:58:47 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -28,7 +28,7 @@ static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
/* PROTOTYPES ****************************************************************/
static NTSTATUS MapDefaultKey (PHKEY ParentKey, HKEY Key);
static VOID CloseDefaultHandles(VOID);
static VOID CloseDefaultKeys(VOID);
static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle);
@ -60,7 +60,7 @@ RegCleanup(VOID)
{
DPRINT1("RegCleanup()\n");
CloseDefaultHandles();
CloseDefaultKeys();
RtlDeleteCriticalSection(&HandleTableCS);
return TRUE;
}
@ -120,7 +120,7 @@ DPRINT1("Status %x\n", Status);
}
static VOID CloseDefaultHandles(VOID)
static VOID CloseDefaultKeys (VOID)
{
ULONG i;
@ -130,7 +130,7 @@ static VOID CloseDefaultHandles(VOID)
{
if (DefaultHandleTable[i] != NULL)
{
// NtClose (DefaultHandleTable[i]);
NtClose (DefaultHandleTable[i]);
DefaultHandleTable[i] = NULL;
}
}
@ -156,7 +156,9 @@ OpenLocalMachineKey (PHANDLE KeyHandle)
NULL,
NULL);
return (NtOpenKey (KeyHandle, 0x200000, &Attributes));
return (NtOpenKey (KeyHandle,
KEY_ALL_ACCESS,
&Attributes));
}
@ -169,11 +171,22 @@ RegCloseKey(
HKEY hKey
)
{
if (!hKey)
NTSTATUS Status;
/* don't close null handle or a pseudo handle */
if ((!hKey) || (((ULONG)hKey & 0xF0000000) == 0x80000000))
return ERROR_INVALID_HANDLE;
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED;
Status = NtClose (hKey);
if (!NT_SUCCESS(Status))
{
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return ErrorCode;
}
return ERROR_SUCCESS;
}
@ -290,8 +303,10 @@ RegCreateKeyExW(
Status = MapDefaultKey (&ParentKey, hKey);
if (!NT_SUCCESS(Status))
{
SetLastError (RtlNtStatusToDosError(Status));
return (RtlNtStatusToDosError(Status));
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return ErrorCode;
}
DPRINT1("ParentKey %x\n", (ULONG)ParentKey);
@ -315,8 +330,10 @@ RegCreateKeyExW(
DPRINT1("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
SetLastError (RtlNtStatusToDosError(Status));
return (RtlNtStatusToDosError(Status));
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return ErrorCode;
}
DPRINT1("Returned handle %x\n", (ULONG)*phkResult);
@ -369,6 +386,21 @@ RegDeleteValueA(
}
/************************************************************************
* RegDeleteValueW
*/
LONG
STDCALL
RegDeleteValueW(
HKEY hKey,
LPCWSTR lpValueName
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED;
}
/************************************************************************
* RegEnumKeyA
*/
@ -831,6 +863,62 @@ RegSetValueExA(
}
/************************************************************************
* RegSetValueExW
*/
LONG
STDCALL
RegSetValueExW(
HKEY hKey,
LPCWSTR lpValueName,
DWORD Reserved,
DWORD dwType,
CONST BYTE *lpData,
DWORD cbData
)
{
UNICODE_STRING ValueName;
NTSTATUS Status;
RtlInitUnicodeString (&ValueName,
lpValueName);
Status = NtSetValueKey (hKey,
&ValueName,
0,
dwType,
(PVOID)lpData,
(ULONG)cbData);
if (!NT_SUCCESS(Status))
{
LONG ErrorCode = RtlNtStatusToDosError(Status);
SetLastError (ErrorCode);
return ErrorCode;
}
return ERROR_SUCCESS;
}
/************************************************************************
* RegSetValueW
*/
LONG
STDCALL
RegSetValueW(
HKEY hKey,
LPCWSTR lpSubKey,
DWORD dwType,
LPCWSTR lpData,
DWORD cbData
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return ERROR_CALL_NOT_IMPLEMENTED;
}
/************************************************************************
* RegUnLoadKeyA
*/

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.27 2000/09/05 23:03:09 ekohl Exp $
/* $Id: registry.c,v 1.28 2000/09/06 19:59:54 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -408,7 +408,6 @@ NtCreateKey (
Status = CmiBuildKeyPath(&KeyNameBuf, ObjectAttributes);
if (!NT_SUCCESS(Status))
{
CHECKPOINT1;
return Status;
}
@ -429,8 +428,11 @@ CHECKPOINT1;
FALSE,
KeyHandle);
ExFreePool(KeyNameBuf);
CHECKPOINT1;
if (NT_SUCCESS(Status))
{
*Disposition = REG_OPENED_EXISTING_KEY;
}
DPRINT1("KeyHandle (opened) %x\n", *KeyHandle);
return Status;
}
@ -447,7 +449,6 @@ CHECKPOINT1;
{
ExFreePool(KeyNameBuf);
CHECKPOINT1;
return Status;
}
@ -458,7 +459,6 @@ CHECKPOINT1;
CmiKeyType);
if (NewKey == NULL)
{
CHECKPOINT1;
return STATUS_UNSUCCESSFUL;
}
NewKey->Flags = 0;
@ -467,12 +467,17 @@ CHECKPOINT1;
NewKey->RegistryFile = FileToUse;
CmiAddKeyToList(NewKey);
Status = ObCreateHandle(PsGetCurrentProcess(),
CurKey,
NewKey,
DesiredAccess,
FALSE,
KeyHandle);
CHECKPOINT1;
DPRINT1("Status %x KeyHandle (created) %x\n", Status, *KeyHandle);
if (NT_SUCCESS(Status))
{
*Disposition = REG_CREATED_NEW_KEY;
}
return Status;
#else
UNIMPLEMENTED;
@ -745,11 +750,12 @@ NtOpenKey (
KeyHandle);
ExFreePool(KeyNameBuf);
DPRINT1("Status %x KeyHandle (opened) %x\n", Status, *KeyHandle);
return Status;
}
/* Open the key in the registry file */
CHECKPOINT1;
FileToUse = CmiSystemFile;
Status = CmiFindKey(FileToUse,
KeyNameBuf,
@ -757,10 +763,8 @@ CHECKPOINT1;
DesiredAccess,
0,
NULL);
CHECKPOINT1;
if (!NT_SUCCESS(Status))
{
CHECKPOINT1;
FileToUse = CmiVolatileFile;
Status = CmiFindKey(FileToUse,
KeyNameBuf,
@ -768,16 +772,13 @@ CHECKPOINT1;
DesiredAccess,
0,
NULL);
CHECKPOINT1;
if (!NT_SUCCESS(Status))
{
CHECKPOINT1;
ExFreePool(KeyNameBuf);
return Status;
}
}
CHECKPOINT1;
/* Create new key object and put into linked list */
NewKey = ObCreateObject(KeyHandle,
@ -793,12 +794,15 @@ CHECKPOINT1;
NewKey->RegistryFile = FileToUse;
NewKey->KeyBlock = KeyBlock;
CmiAddKeyToList(NewKey);
DPRINT1("KeyHandle (created) %x\n", *KeyHandle);
Status = ObCreateHandle(PsGetCurrentProcess(),
CurKey,
NewKey,
DesiredAccess,
FALSE,
KeyHandle);
DPRINT1("Status %x KeyHandle (created) %x\n", Status, *KeyHandle);
return Status;
#else
UNIMPLEMENTED;
@ -1097,7 +1101,7 @@ NtSetValueKey (
/* Verify that the handle is valid and is a registry key */
Status = ObReferenceObjectByHandle(KeyHandle,
KEY_QUERY_VALUE,
KEY_SET_VALUE,
CmiKeyType,
UserMode,
(PVOID *)&KeyObject,
@ -1106,7 +1110,6 @@ NtSetValueKey (
{
return Status;
}
/* Get pointer to KeyBlock */
KeyBlock = KeyObject->KeyBlock;
RegistryFile = KeyObject->RegistryFile;
@ -1116,6 +1119,7 @@ NtSetValueKey (
&ValueBlock);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject (KeyObject);
return Status;
}
if (ValueBlock == NULL)
@ -1135,6 +1139,7 @@ NtSetValueKey (
Data,
DataSize);
}
ObDereferenceObject (KeyObject);
return Status;
#else
@ -1515,7 +1520,7 @@ DbgPrint ("KeyName %wZ\n", ObjectAttributes->ObjectName);
Status = ObReferenceObjectByHandle(ObjectAttributes->RootDirectory,
KEY_READ,
NULL,
UserMode,
KernelMode,
(PVOID *)&ObjectBody,
NULL);
if (!NT_SUCCESS(Status))
@ -1760,13 +1765,11 @@ CmiCreateKey(IN PREGISTRY_FILE RegistryFile,
/* FIXME: Should handle search by Class/TitleIndex */
CHECKPOINT;
/* Loop through each key level and find or build the needed subkey */
Status = STATUS_SUCCESS;
/* FIXME: this access of RootKeyBlock should be guarded by spinlock */
CurKeyBlock = CmiGetKeyBlock(RegistryFile,
RegistryFile->HeaderBlock->RootKeyBlock);
CHECKPOINT;
Remainder = KeyNameBuf;
while (NT_SUCCESS(Status) &&
(NextSlash = wcschr(Remainder, L'\\')) != NULL)
@ -1867,12 +1870,8 @@ CmiFindKey(IN PREGISTRY_FILE RegistryFile,
PWSTR Remainder, NextSlash;
PKEY_BLOCK CurKeyBlock, SubKeyBlock;
DbgPrint("KeyNameBuf %S\n", KeyNameBuf);
CHECKPOINT1;
if (RegistryFile == NULL)
return STATUS_UNSUCCESSFUL;
CHECKPOINT1;
/* FIXME: Should handle search by Class/TitleIndex */
@ -1888,7 +1887,6 @@ CHECKPOINT1;
/* Copy just the current subkey name to a buffer */
wcsncpy(CurKeyName, Remainder, NextSlash - Remainder);
CurKeyName[NextSlash - Remainder] = 0;
DbgPrint("CurKeyName %S\n", CurKeyName);
/* Verify existance of CurKeyName */
Status = CmiScanForSubKey(RegistryFile,
@ -1902,7 +1900,6 @@ DbgPrint("CurKeyName %S\n", CurKeyName);
}
if (SubKeyBlock == NULL)
{
CHECKPOINT1;
Status = STATUS_UNSUCCESSFUL;
continue;
}
@ -1913,7 +1910,6 @@ CHECKPOINT1;
}
if (NT_SUCCESS(Status))
{
DbgPrint("CurKeyName %S\n", CurKeyName);
Status = CmiScanForSubKey(RegistryFile,
CurKeyBlock,
&SubKeyBlock,
@ -1923,7 +1919,6 @@ DbgPrint("CurKeyName %S\n", CurKeyName);
{
if (SubKeyBlock == NULL)
{
CHECKPOINT1;
Status = STATUS_UNSUCCESSFUL;
}
else
@ -1933,7 +1928,6 @@ CHECKPOINT1;
}
}
CmiReleaseBlock(RegistryFile, CurKeyBlock);
CHECKPOINT1;
return Status;
}
@ -2079,27 +2073,21 @@ CmiScanForSubKey(IN PREGISTRY_FILE RegistryFile,
PHASH_TABLE_BLOCK HashBlock;
PKEY_BLOCK CurSubKeyBlock;
CHECKPOINT1;
HashBlock = CmiGetHashTableBlock(RegistryFile, KeyBlock->HashTableOffset);
*SubKeyBlock = NULL;
if (HashBlock == 0)
{
CHECKPOINT1;
return STATUS_SUCCESS;
}
CHECKPOINT1;
for (Idx = 0; Idx < HashBlock->HashTableSize; Idx++)
{
DbgPrint ("KeyName %S HashValue %x\n", KeyName, HashBlock->Table[Idx].HashValue);
if (HashBlock->Table[Idx].KeyOffset != 0 &&
!wcsncmp(KeyName, (PWSTR) &HashBlock->Table[Idx].HashValue, 2))
// !wcsncmp(KeyName, (PWSTR) &HashBlock->Table[Idx].HashValue, 4))
{
CurSubKeyBlock = CmiGetKeyBlock(RegistryFile,
HashBlock->Table[Idx].KeyOffset);
if (!wcscmp(KeyName, CurSubKeyBlock->Name))
{
CHECKPOINT1;
*SubKeyBlock = CurSubKeyBlock;
break;
}
@ -2283,8 +2271,8 @@ CmiAddValueToKey(IN PREGISTRY_FILE RegistryFile,
ValueListBlock->Values[KeyBlock->NumberOfValues] =
CmiGetBlockOffset(RegistryFile, ValueBlock);
KeyBlock->NumberOfValues++;
CmiReleaseBlock(RegistryFile, ValueBlock);
CmiReleaseBlock(RegistryFile, ValueListBlock);
CmiReleaseBlock(RegistryFile, ValueBlock);
return STATUS_SUCCESS;
}
@ -2579,7 +2567,7 @@ CmiAllocateValueBlock(PREGISTRY_FILE RegistryFile,
/* Handle volatile files first */
if (RegistryFile->Filename == NULL)
{
NewValueSize = sizeof(VALUE_BLOCK) + wcslen(ValueNameBuf);
NewValueSize = sizeof(VALUE_BLOCK) + wcslen(ValueNameBuf)* sizeof(WCHAR);
NewValueBlock = ExAllocatePool(NonPagedPool, NewValueSize);
if (NewValueBlock == NULL)
{
@ -2664,6 +2652,7 @@ CmiDestroyValueBlock(PREGISTRY_FILE RegistryFile,
{
NTSTATUS Status;
CHECKPOINT1;
Status = CmiDestroyBlock(RegistryFile,
CmiGetBlock(RegistryFile,
ValueBlock->DataOffset));