implemented RegDisablePredefinedCacheEx()

svn path=/trunk/; revision=17554
This commit is contained in:
Thomas Bluemel 2005-08-26 09:40:37 +00:00
parent f4668aceae
commit 64d0f61e8a
2 changed files with 248 additions and 78 deletions

View file

@ -483,6 +483,7 @@ RegDeleteTreeW@8
RegDeleteValueA@8 RegDeleteValueA@8
RegDeleteValueW@8 RegDeleteValueW@8
;RegDisablePredefinedCache ;RegDisablePredefinedCache
RegDisablePredefinedCacheEx@0
RegEnumKeyA@16 RegEnumKeyA@16
RegEnumKeyExA@32 RegEnumKeyExA@32
RegEnumKeyExW@32 RegEnumKeyExW@32

View file

@ -31,11 +31,16 @@
static RTL_CRITICAL_SECTION HandleTableCS; static RTL_CRITICAL_SECTION HandleTableCS;
static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES]; static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
static HANDLE ProcessHeap; static HANDLE ProcessHeap;
static BOOLEAN DefaultHandlesDisabled = FALSE;
/* PROTOTYPES ***************************************************************/ /* PROTOTYPES ***************************************************************/
static NTSTATUS MapDefaultKey (PHANDLE ParentKey, HKEY Key); static NTSTATUS MapDefaultKey (PHANDLE ParentKey, HKEY Key);
static VOID CloseDefaultKeys(VOID); static VOID CloseDefaultKeys(VOID);
#define CloseDefaultKey(Handle) \
if ((ULONG_PTR)Handle & 0x1) { \
NtClose(Handle); \
}
static NTSTATUS OpenClassesRootKey(PHANDLE KeyHandle); static NTSTATUS OpenClassesRootKey(PHANDLE KeyHandle);
static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle); static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle);
@ -83,18 +88,19 @@ RegCleanup (VOID)
static NTSTATUS static NTSTATUS
MapDefaultKey (PHANDLE RealKey, MapDefaultKey (OUT PHANDLE RealKey,
HKEY Key) IN HKEY Key)
{ {
PHANDLE Handle; PHANDLE Handle;
ULONG Index; ULONG Index;
BOOLEAN DoOpen;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
TRACE("MapDefaultKey (Key %x)\n", Key); TRACE("MapDefaultKey (Key %x)\n", Key);
if (((ULONG)Key & 0xF0000000) != 0x80000000) if (((ULONG)Key & 0xF0000000) != 0x80000000)
{ {
*RealKey = (HANDLE)Key; *RealKey = (HANDLE)((ULONG_PTR)Key & ~0x1);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -106,8 +112,19 @@ MapDefaultKey (PHANDLE RealKey,
} }
RtlEnterCriticalSection (&HandleTableCS); RtlEnterCriticalSection (&HandleTableCS);
if (!DefaultHandlesDisabled)
{
Handle = &DefaultHandleTable[Index]; Handle = &DefaultHandleTable[Index];
if (*Handle == NULL) DoOpen = (*Handle == NULL);
}
else
{
Handle = RealKey;
DoOpen = TRUE;
}
if (DoOpen)
{ {
/* create/open the default handle */ /* create/open the default handle */
switch (Index) switch (Index)
@ -144,15 +161,20 @@ MapDefaultKey (PHANDLE RealKey,
default: default:
WARN("MapDefaultHandle() no handle creator\n"); WARN("MapDefaultHandle() no handle creator\n");
Status = STATUS_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
break;
} }
} }
RtlLeaveCriticalSection (&HandleTableCS);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
if (!DefaultHandlesDisabled)
*RealKey = *Handle; *RealKey = *Handle;
else
*(PULONG_PTR)Handle |= 0x1;
} }
RtlLeaveCriticalSection (&HandleTableCS);
return Status; return Status;
} }
@ -256,6 +278,21 @@ OpenCurrentConfigKey (PHANDLE KeyHandle)
} }
/************************************************************************
* RegDisablePredefinedCacheEx
*
* @implemented
*/
LONG STDCALL
RegDisablePredefinedCacheEx(VOID)
{
RtlEnterCriticalSection (&HandleTableCS);
DefaultHandlesDisabled = TRUE;
RtlLeaveCriticalSection (&HandleTableCS);
return ERROR_SUCCESS;
}
/************************************************************************ /************************************************************************
* RegCloseKey * RegCloseKey
* *
@ -307,7 +344,7 @@ RegCopyTreeW(IN HKEY hKeySrc,
IN LPCWSTR lpSubKey OPTIONAL, IN LPCWSTR lpSubKey OPTIONAL,
IN HKEY hKeyDest) IN HKEY hKeyDest)
{ {
HANDLE DestKeyHandle, KeyHandle, SubKeyHandle = NULL; HANDLE DestKeyHandle, KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle, Status = MapDefaultKey(&KeyHandle,
@ -321,7 +358,7 @@ RegCopyTreeW(IN HKEY hKeySrc,
hKeyDest); hKeyDest);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); goto Cleanup2;
} }
if (lpSubKey != NULL) if (lpSubKey != NULL)
@ -343,9 +380,13 @@ RegCopyTreeW(IN HKEY hKeySrc,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); goto Cleanup;
} }
CurKey = SubKeyHandle;
} }
else
CurKey = KeyHandle;
/* FIXME - copy all keys and values recursively */ /* FIXME - copy all keys and values recursively */
Status = STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
@ -355,6 +396,11 @@ RegCopyTreeW(IN HKEY hKeySrc,
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(DestKeyHandle);
Cleanup2:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); return RtlNtStatusToDosError(Status);
@ -581,6 +627,8 @@ RegCreateKeyExA (HKEY hKey,
RtlFreeUnicodeString (&ClassString); RtlFreeUnicodeString (&ClassString);
} }
CloseDefaultKey(ParentKey);
TRACE("Status %x\n", Status); TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -639,6 +687,9 @@ RegCreateKeyExW (HKEY hKey,
dwOptions, dwOptions,
samDesired, samDesired,
lpdwDisposition); lpdwDisposition);
CloseDefaultKey(ParentKey);
TRACE("Status %x\n", Status); TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -729,11 +780,15 @@ RegDeleteKeyA (HKEY hKey,
RtlFreeUnicodeString (&SubKeyName); RtlFreeUnicodeString (&SubKeyName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); goto Cleanup;
} }
Status = NtDeleteKey (TargetKey); Status = NtDeleteKey (TargetKey);
NtClose (TargetKey); NtClose (TargetKey);
Cleanup:
CloseDefaultKey(ParentKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); return RtlNtStatusToDosError(Status);
@ -777,11 +832,15 @@ RegDeleteKeyW (HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); goto Cleanup;
} }
Status = NtDeleteKey (TargetKey); Status = NtDeleteKey (TargetKey);
NtClose (TargetKey); NtClose (TargetKey);
Cleanup:
CloseDefaultKey(ParentKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -802,7 +861,7 @@ RegDeleteKeyValueW(IN HKEY hKey,
IN LPCWSTR lpValueName OPTIONAL) IN LPCWSTR lpValueName OPTIONAL)
{ {
UNICODE_STRING ValueName; UNICODE_STRING ValueName;
HANDLE KeyHandle, SubKeyHandle = NULL; HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle, Status = MapDefaultKey(&KeyHandle,
@ -831,16 +890,18 @@ RegDeleteKeyValueW(IN HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); goto Cleanup;
} }
KeyHandle = SubKeyHandle; CurKey = SubKeyHandle;
} }
else
CurKey = KeyHandle;
RtlInitUnicodeString(&ValueName, RtlInitUnicodeString(&ValueName,
(LPWSTR)lpValueName); (LPWSTR)lpValueName);
Status = NtDeleteValueKey(KeyHandle, Status = NtDeleteValueKey(CurKey,
&ValueName); &ValueName);
if (SubKeyHandle != NULL) if (SubKeyHandle != NULL)
@ -848,6 +909,9 @@ RegDeleteKeyValueW(IN HKEY hKey,
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); return RtlNtStatusToDosError(Status);
@ -915,7 +979,7 @@ LONG STDCALL
RegDeleteTreeW(IN HKEY hKey, RegDeleteTreeW(IN HKEY hKey,
IN LPCWSTR lpSubKey OPTIONAL) IN LPCWSTR lpSubKey OPTIONAL)
{ {
HANDLE KeyHandle, SubKeyHandle = NULL; HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle, Status = MapDefaultKey(&KeyHandle,
@ -944,11 +1008,13 @@ RegDeleteTreeW(IN HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); goto Cleanup;
} }
KeyHandle = SubKeyHandle; CurKey = SubKeyHandle;
} }
else
CurKey = KeyHandle;
/* FIXME - delete all keys recursively */ /* FIXME - delete all keys recursively */
Status = STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
@ -958,6 +1024,9 @@ RegDeleteTreeW(IN HKEY hKey,
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); return RtlNtStatusToDosError(Status);
@ -1013,7 +1082,7 @@ RegSetKeyValueW(IN HKEY hKey,
IN LPCVOID lpData OPTIONAL, IN LPCVOID lpData OPTIONAL,
IN DWORD cbData) IN DWORD cbData)
{ {
HANDLE KeyHandle, SubKeyHandle = NULL; HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status; NTSTATUS Status;
LONG Ret; LONG Ret;
@ -1043,13 +1112,16 @@ RegSetKeyValueW(IN HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); Ret = RtlNtStatusToDosError(Status);
goto Cleanup;
} }
KeyHandle = SubKeyHandle; CurKey = SubKeyHandle;
} }
else
CurKey = KeyHandle;
Ret = RegSetValueExW(KeyHandle, Ret = RegSetValueExW(CurKey,
lpValueName, lpValueName,
0, 0,
dwType, dwType,
@ -1061,6 +1133,9 @@ RegSetKeyValueW(IN HKEY hKey,
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return Ret; return Ret;
} }
@ -1078,7 +1153,7 @@ RegSetKeyValueA(IN HKEY hKey,
IN LPCVOID lpData OPTIONAL, IN LPCVOID lpData OPTIONAL,
IN DWORD cbData) IN DWORD cbData)
{ {
HANDLE KeyHandle, SubKeyHandle = NULL; HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status; NTSTATUS Status;
LONG Ret; LONG Ret;
@ -1097,7 +1172,8 @@ RegSetKeyValueA(IN HKEY hKey,
if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName, if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
(LPSTR)lpSubKey)) (LPSTR)lpSubKey))
{ {
return ERROR_NOT_ENOUGH_MEMORY; Ret = ERROR_NOT_ENOUGH_MEMORY;
goto Cleanup;
} }
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
@ -1114,13 +1190,16 @@ RegSetKeyValueA(IN HKEY hKey,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); Ret = RtlNtStatusToDosError(Status);
goto Cleanup;
} }
KeyHandle = SubKeyHandle; CurKey = SubKeyHandle;
} }
else
CurKey = KeyHandle;
Ret = RegSetValueExA(KeyHandle, Ret = RegSetValueExA(CurKey,
lpValueName, lpValueName,
0, 0,
dwType, dwType,
@ -1132,6 +1211,9 @@ RegSetKeyValueA(IN HKEY hKey,
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return Ret; return Ret;
} }
@ -1161,6 +1243,9 @@ RegDeleteValueA (HKEY hKey,
Status = NtDeleteValueKey (KeyHandle, Status = NtDeleteValueKey (KeyHandle,
&ValueName); &ValueName);
RtlFreeUnicodeString (&ValueName); RtlFreeUnicodeString (&ValueName);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -1195,6 +1280,9 @@ RegDeleteValueW (HKEY hKey,
Status = NtDeleteValueKey (KeyHandle, Status = NtDeleteValueKey (KeyHandle,
&ValueName); &ValueName);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -1330,7 +1418,8 @@ RegEnumKeyExA (HKEY hKey,
KeyInfo = RtlAllocateHeap (ProcessHeap, 0, BufferSize); KeyInfo = RtlAllocateHeap (ProcessHeap, 0, BufferSize);
if (KeyInfo == NULL) if (KeyInfo == NULL)
{ {
return ERROR_OUTOFMEMORY; ErrorCode = ERROR_OUTOFMEMORY;
goto Cleanup;
} }
Status = NtEnumerateKey (KeyHandle, Status = NtEnumerateKey (KeyHandle,
@ -1416,6 +1505,9 @@ RegEnumKeyExA (HKEY hKey,
0, 0,
KeyInfo); KeyInfo);
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -1488,7 +1580,8 @@ RegEnumKeyExW (HKEY hKey,
BufferSize); BufferSize);
if (KeyInfo == NULL) if (KeyInfo == NULL)
{ {
return ERROR_OUTOFMEMORY; ErrorCode = ERROR_OUTOFMEMORY;
goto Cleanup;
} }
Status = NtEnumerateKey (KeyHandle, Status = NtEnumerateKey (KeyHandle,
@ -1560,6 +1653,9 @@ RegEnumKeyExW (HKEY hKey,
0, 0,
KeyInfo); KeyInfo);
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -1607,7 +1703,10 @@ RegEnumValueA( HKEY hKey, DWORD index, LPSTR value, LPDWORD val_count,
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY; {
status = STATUS_INSUFFICIENT_RESOURCES;
goto done;
}
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr; info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation, status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size ); buf_ptr, total_size, &total_size );
@ -1670,6 +1769,7 @@ RegEnumValueA( HKEY hKey, DWORD index, LPSTR value, LPDWORD val_count,
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
CloseDefaultKey(KeyHandle);
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -1729,7 +1829,10 @@ RegEnumValueW( HKEY hKey, DWORD index, LPWSTR value, PDWORD val_count,
{ {
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size ))) if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY; {
status = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr; info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation, status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size ); buf_ptr, total_size, &total_size );
@ -1774,6 +1877,7 @@ RegEnumValueW( HKEY hKey, DWORD index, LPWSTR value, PDWORD val_count,
done: done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr ); if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
CloseDefaultKey(KeyHandle);
return RtlNtStatusToDosError(status); return RtlNtStatusToDosError(status);
} }
@ -1801,6 +1905,9 @@ RegFlushKey(HKEY hKey)
} }
Status = NtFlushKey (KeyHandle); Status = NtFlushKey (KeyHandle);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -1842,6 +1949,9 @@ RegGetKeySecurity(HKEY hKey,
pSecurityDescriptor, pSecurityDescriptor,
*lpcbSecurityDescriptor, *lpcbSecurityDescriptor,
lpcbSecurityDescriptor); lpcbSecurityDescriptor);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
WARN("NtQuerySecurityObject() failed (Status %lx)\n", Status); WARN("NtQuerySecurityObject() failed (Status %lx)\n", Status);
@ -1898,6 +2008,7 @@ RegLoadKeyW (HKEY hKey,
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA) if (hKey == HKEY_PERFORMANCE_DATA)
{ {
@ -1916,7 +2027,8 @@ RegLoadKeyW (HKEY hKey,
NULL, NULL,
NULL)) NULL))
{ {
return ERROR_BAD_PATHNAME; ErrorCode = ERROR_BAD_PATHNAME;
goto Cleanup;
} }
InitializeObjectAttributes (&FileObjectAttributes, InitializeObjectAttributes (&FileObjectAttributes,
@ -1941,10 +2053,14 @@ RegLoadKeyW (HKEY hKey,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
return ERROR_SUCCESS; Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -1963,6 +2079,7 @@ RegNotifyChangeKeyValue (HKEY hKey,
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA) if (hKey == HKEY_PERFORMANCE_DATA)
{ {
@ -1995,10 +2112,12 @@ RegNotifyChangeKeyValue (HKEY hKey,
fAsynchronous); fAsynchronous);
if (!NT_SUCCESS(Status) && Status != STATUS_TIMEOUT) if (!NT_SUCCESS(Status) && Status != STATUS_TIMEOUT)
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
} }
return ERROR_SUCCESS; CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -2090,6 +2209,7 @@ RegOpenKeyExA (HKEY hKey,
UNICODE_STRING SubKeyString; UNICODE_STRING SubKeyString;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LONG ErrorCode = ERROR_SUCCESS;
TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n", TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult); hKey, lpSubKey, ulOptions, samDesired, phkResult);
@ -2111,10 +2231,12 @@ RegOpenKeyExA (HKEY hKey,
RtlFreeUnicodeString (&SubKeyString); RtlFreeUnicodeString (&SubKeyString);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
} }
return ERROR_SUCCESS; CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -2134,6 +2256,7 @@ RegOpenKeyExW (HKEY hKey,
UNICODE_STRING SubKeyString; UNICODE_STRING SubKeyString;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LONG ErrorCode = ERROR_SUCCESS;
TRACE("RegOpenKeyExW hKey 0x%x lpSubKey %S ulOptions 0x%x samDesired 0x%x phkResult %p\n", TRACE("RegOpenKeyExW hKey 0x%x lpSubKey %S ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult); hKey, lpSubKey, ulOptions, samDesired, phkResult);
@ -2159,10 +2282,12 @@ RegOpenKeyExW (HKEY hKey,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
} }
return ERROR_SUCCESS; CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -2430,7 +2555,8 @@ RegQueryInfoKeyW (HKEY hKey,
FullInfoSize); FullInfoSize);
if (FullInfo == NULL) if (FullInfo == NULL)
{ {
return ERROR_OUTOFMEMORY; ErrorCode = ERROR_OUTOFMEMORY;
goto Cleanup;
} }
FullInfo->ClassLength = ClassLength; FullInfo->ClassLength = ClassLength;
@ -2458,7 +2584,8 @@ RegQueryInfoKeyW (HKEY hKey,
FullInfo); FullInfo);
} }
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
TRACE("SubKeys %d\n", FullInfo->SubKeys); TRACE("SubKeys %d\n", FullInfo->SubKeys);
@ -2515,7 +2642,8 @@ RegQueryInfoKeyW (HKEY hKey,
FullInfo); FullInfo);
} }
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
} }
@ -2545,6 +2673,9 @@ RegQueryInfoKeyW (HKEY hKey,
FullInfo); FullInfo);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -2711,7 +2842,8 @@ RegQueryValueExW (HKEY hKey,
if (lpData != NULL && lpcbData == NULL) if (lpData != NULL && lpcbData == NULL)
{ {
return ERROR_INVALID_PARAMETER; ErrorCode = ERROR_INVALID_PARAMETER;
goto Cleanup;
} }
RtlInitUnicodeString (&ValueName, RtlInitUnicodeString (&ValueName,
@ -2722,7 +2854,8 @@ RegQueryValueExW (HKEY hKey,
BufferSize); BufferSize);
if (ValueInfo == NULL) if (ValueInfo == NULL)
{ {
return ERROR_OUTOFMEMORY; ErrorCode = ERROR_OUTOFMEMORY;
goto Cleanup;
} }
Status = NtQueryValueKey (KeyHandle, Status = NtQueryValueKey (KeyHandle,
@ -2790,6 +2923,9 @@ RegQueryValueExW (HKEY hKey,
0, 0,
ValueInfo); ValueInfo);
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -3034,7 +3170,8 @@ RegQueryValueW (HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
CloseRealKey = TRUE; CloseRealKey = TRUE;
} }
@ -3055,6 +3192,9 @@ RegQueryValueW (HKEY hKey,
NtClose (RealKey); NtClose (RealKey);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -3116,6 +3256,7 @@ RegReplaceKeyW (HKEY hKey,
HANDLE RealKeyHandle; HANDLE RealKeyHandle;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA) if (hKey == HKEY_PERFORMANCE_DATA)
{ {
@ -3144,7 +3285,8 @@ RegReplaceKeyW (HKEY hKey,
&KeyObjectAttributes); &KeyObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
CloseRealKey = TRUE; CloseRealKey = TRUE;
} }
@ -3164,7 +3306,8 @@ RegReplaceKeyW (HKEY hKey,
{ {
NtClose (RealKeyHandle); NtClose (RealKeyHandle);
} }
return ERROR_INVALID_PARAMETER; ErrorCode = ERROR_INVALID_PARAMETER;
goto Cleanup;
} }
InitializeObjectAttributes (&NewObjectAttributes, InitializeObjectAttributes (&NewObjectAttributes,
@ -3184,7 +3327,8 @@ RegReplaceKeyW (HKEY hKey,
{ {
NtClose (RealKeyHandle); NtClose (RealKeyHandle);
} }
return ERROR_INVALID_PARAMETER; ErrorCode = ERROR_INVALID_PARAMETER;
goto Cleanup;
} }
InitializeObjectAttributes (&OldObjectAttributes, InitializeObjectAttributes (&OldObjectAttributes,
@ -3210,7 +3354,10 @@ RegReplaceKeyW (HKEY hKey,
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
} }
return ERROR_SUCCESS; Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -3274,7 +3421,8 @@ RegRestoreKeyW (HKEY hKey,
NULL, NULL,
NULL)) NULL))
{ {
return ERROR_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
goto Cleanup;
} }
InitializeObjectAttributes (&ObjectAttributes, InitializeObjectAttributes (&ObjectAttributes,
@ -3292,13 +3440,17 @@ RegRestoreKeyW (HKEY hKey,
RtlFreeUnicodeString (&FileName); RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); goto Cleanup;
} }
Status = NtRestoreKey (KeyHandle, Status = NtRestoreKey (KeyHandle,
FileHandle, FileHandle,
(ULONG)dwFlags); (ULONG)dwFlags);
NtClose (FileHandle); NtClose (FileHandle);
Cleanup:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -3362,7 +3514,8 @@ RegSaveKeyW (HKEY hKey,
NULL, NULL,
NULL)) NULL))
{ {
return ERROR_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
goto Cleanup;
} }
if (lpSecurityAttributes != NULL) if (lpSecurityAttributes != NULL)
@ -3389,12 +3542,16 @@ RegSaveKeyW (HKEY hKey,
RtlFreeUnicodeString (&FileName); RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); goto Cleanup;
} }
Status = NtSaveKey (KeyHandle, Status = NtSaveKey (KeyHandle,
FileHandle); FileHandle);
NtClose (FileHandle); NtClose (FileHandle);
Cleanup:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -3432,6 +3589,9 @@ RegSetKeySecurity (HKEY hKey,
Status = NtSetSecurityObject (KeyHandle, Status = NtSetSecurityObject (KeyHandle,
SecurityInformation, SecurityInformation,
pSecurityDescriptor); pSecurityDescriptor);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -3579,6 +3739,9 @@ RegSetValueExW (HKEY hKey,
dwType, dwType,
(PVOID)lpData, (PVOID)lpData,
(ULONG)cbData); (ULONG)cbData);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -3679,7 +3842,8 @@ RegSetValueW (HKEY hKey,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
goto Cleanup;
} }
CloseRealKey = TRUE; CloseRealKey = TRUE;
} }
@ -3700,6 +3864,9 @@ RegSetValueW (HKEY hKey,
NtClose (RealKey); NtClose (RealKey);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode; return ErrorCode;
} }
@ -3764,6 +3931,8 @@ RegUnLoadKeyW (HKEY hKey,
Status = NtUnloadKey (&ObjectAttributes); Status = NtUnloadKey (&ObjectAttributes);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);