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);
Handle = &DefaultHandleTable[Index];
if (*Handle == NULL) if (!DefaultHandlesDisabled)
{
Handle = &DefaultHandleTable[Index];
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,14 +161,19 @@ 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))
{ {
*RealKey = *Handle; if (!DefaultHandlesDisabled)
} *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);
@ -549,7 +595,7 @@ RegCreateKeyExA (HKEY hKey,
/* get the real parent key */ /* get the real parent key */
Status = MapDefaultKey (&ParentKey, Status = MapDefaultKey (&ParentKey,
hKey); hKey);
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))
{ {
@ -617,7 +665,7 @@ RegCreateKeyExW (HKEY hKey,
/* get the real parent key */ /* get the real parent key */
Status = MapDefaultKey (&ParentKey, Status = MapDefaultKey (&ParentKey,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError(Status); return RtlNtStatusToDosError(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))
{ {
@ -709,7 +760,7 @@ RegDeleteKeyA (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey (&ParentKey, Status = MapDefaultKey (&ParentKey,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (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);
@ -759,7 +814,7 @@ RegDeleteKeyW (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey (&ParentKey, Status = MapDefaultKey (&ParentKey,
hKey); hKey);
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,22 +890,27 @@ 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)
{ {
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(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,
@ -1060,6 +1132,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,
@ -1131,6 +1210,9 @@ RegSetKeyValueA(IN HKEY hKey,
{ {
NtClose(SubKeyHandle); NtClose(SubKeyHandle);
} }
Cleanup:
CloseDefaultKey(KeyHandle);
return Ret; return Ret;
} }
@ -1150,7 +1232,7 @@ RegDeleteValueA (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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);
@ -1184,7 +1269,7 @@ RegDeleteValueW (HKEY hKey,
HANDLE KeyHandle; HANDLE KeyHandle;
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
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,7 +1505,10 @@ RegEnumKeyExA (HKEY hKey,
0, 0,
KeyInfo); KeyInfo);
return ErrorCode; Cleanup:
CloseDefaultKey(KeyHandle);
return ErrorCode;
} }
@ -1450,7 +1542,7 @@ RegEnumKeyExW (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle, Status = MapDefaultKey(&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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);
} }
@ -1794,13 +1898,16 @@ RegFlushKey(HKEY hKey)
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
} }
Status = NtFlushKey (KeyHandle); Status = NtFlushKey (KeyHandle);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -1830,7 +1937,7 @@ RegGetKeySecurity(HKEY hKey,
} }
Status = MapDefaultKey(&KeyHandle, Status = MapDefaultKey(&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
TRACE("MapDefaultKey() failed (Status %lx)\n", Status); TRACE("MapDefaultKey() failed (Status %lx)\n", 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)
{ {
@ -1905,7 +2016,7 @@ RegLoadKeyW (HKEY hKey,
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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)
{ {
@ -1975,7 +2092,7 @@ RegNotifyChangeKeyValue (HKEY hKey,
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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);
} }
CloseDefaultKey(KeyHandle);
return ERROR_SUCCESS; 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);
} }
CloseDefaultKey(KeyHandle);
return ERROR_SUCCESS; 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;
} }
@ -3013,7 +3149,7 @@ RegQueryValueW (HKEY hKey,
hKey, lpSubKey, lpValue, lpcbValue ? *lpcbValue : 0); hKey, lpSubKey, lpValue, lpcbValue ? *lpcbValue : 0);
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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)
{ {
@ -3123,7 +3264,7 @@ RegReplaceKeyW (HKEY hKey,
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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;
} }
@ -3263,7 +3410,7 @@ RegRestoreKeyW (HKEY hKey,
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return RtlNtStatusToDosError (Status); return RtlNtStatusToDosError (Status);
@ -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);
@ -3351,7 +3503,7 @@ RegSaveKeyW (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
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);
@ -3423,7 +3580,7 @@ RegSetKeySecurity (HKEY hKey,
} }
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
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);
@ -3547,7 +3707,7 @@ RegSetValueExW (HKEY hKey,
NTSTATUS Status; NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
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);
@ -3659,7 +3822,7 @@ RegSetValueW (HKEY hKey,
LONG ErrorCode; LONG ErrorCode;
Status = MapDefaultKey (&KeyHandle, Status = MapDefaultKey (&KeyHandle,
hKey); hKey);
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;
} }
@ -3763,6 +3930,8 @@ RegUnLoadKeyW (HKEY hKey,
NULL); NULL);
Status = NtUnloadKey (&ObjectAttributes); Status = NtUnloadKey (&ObjectAttributes);
CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {