--- trunk/reactos/lib/advapi32/reg/reg.c 2005-08-25 23:54:39 UTC (rev 17553)
+++ trunk/reactos/lib/advapi32/reg/reg.c 2005-08-26 09:40:37 UTC (rev 17554)
@@ -31,11 +31,16 @@
static RTL_CRITICAL_SECTION HandleTableCS;
static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
static HANDLE ProcessHeap;
+static BOOLEAN DefaultHandlesDisabled = FALSE;
/* PROTOTYPES ***************************************************************/
static NTSTATUS MapDefaultKey (PHANDLE ParentKey, HKEY Key);
static VOID CloseDefaultKeys(VOID);
+#define CloseDefaultKey(Handle) \
+ if ((ULONG_PTR)Handle & 0x1) { \
+ NtClose(Handle); \
+ }
static NTSTATUS OpenClassesRootKey(PHANDLE KeyHandle);
static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle);
@@ -83,18 +88,19 @@
static NTSTATUS
-MapDefaultKey (PHANDLE RealKey,
- HKEY Key)
+MapDefaultKey (OUT PHANDLE RealKey,
+ IN HKEY Key)
{
PHANDLE Handle;
ULONG Index;
+ BOOLEAN DoOpen;
NTSTATUS Status = STATUS_SUCCESS;
TRACE("MapDefaultKey (Key %x)\n", Key);
if (((ULONG)Key & 0xF0000000) != 0x80000000)
{
- *RealKey = (HANDLE)Key;
+ *RealKey = (HANDLE)((ULONG_PTR)Key & ~0x1);
return STATUS_SUCCESS;
}
@@ -106,9 +112,20 @@
}
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 */
switch (Index)
{
@@ -144,14 +161,19 @@
default:
WARN("MapDefaultHandle() no handle creator\n");
Status = STATUS_INVALID_PARAMETER;
+ break;
}
}
- RtlLeaveCriticalSection (&HandleTableCS);
- if (NT_SUCCESS(Status))
- {
- *RealKey = *Handle;
- }
+ if (NT_SUCCESS(Status))
+ {
+ if (!DefaultHandlesDisabled)
+ *RealKey = *Handle;
+ else
+ *(PULONG_PTR)Handle |= 0x1;
+ }
+
+ RtlLeaveCriticalSection (&HandleTableCS);
return Status;
}
@@ -257,6 +279,21 @@
/************************************************************************
+ * RegDisablePredefinedCacheEx
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegDisablePredefinedCacheEx(VOID)
+{
+ RtlEnterCriticalSection (&HandleTableCS);
+ DefaultHandlesDisabled = TRUE;
+ RtlLeaveCriticalSection (&HandleTableCS);
+ return ERROR_SUCCESS;
+}
+
+
+/************************************************************************
* RegCloseKey
*
* @implemented
@@ -307,7 +344,7 @@
IN LPCWSTR lpSubKey OPTIONAL,
IN HKEY hKeyDest)
{
- HANDLE DestKeyHandle, KeyHandle, SubKeyHandle = NULL;
+ HANDLE DestKeyHandle, KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
@@ -321,7 +358,7 @@
hKeyDest);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError(Status);
+ goto Cleanup2;
}
if (lpSubKey != NULL)
@@ -343,9 +380,13 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError(Status);
+ goto Cleanup;
}
+
+ CurKey = SubKeyHandle;
}
+ else
+ CurKey = KeyHandle;
/* FIXME - copy all keys and values recursively */
Status = STATUS_NOT_IMPLEMENTED;
@@ -355,6 +396,11 @@
NtClose(SubKeyHandle);
}
+Cleanup:
+ CloseDefaultKey(DestKeyHandle);
+Cleanup2:
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError(Status);
@@ -549,7 +595,7 @@
/* get the real parent key */
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -581,6 +627,8 @@
RtlFreeUnicodeString (&ClassString);
}
+ CloseDefaultKey(ParentKey);
+
TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
@@ -617,7 +665,7 @@
/* get the real parent key */
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError(Status);
@@ -639,6 +687,9 @@
dwOptions,
samDesired,
lpdwDisposition);
+
+ CloseDefaultKey(ParentKey);
+
TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
@@ -709,7 +760,7 @@
NTSTATUS Status;
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -729,11 +780,15 @@
RtlFreeUnicodeString (&SubKeyName);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
Status = NtDeleteKey (TargetKey);
NtClose (TargetKey);
+
+Cleanup:
+ CloseDefaultKey(ParentKey);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError(Status);
@@ -759,7 +814,7 @@
NTSTATUS Status;
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -777,11 +832,15 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
Status = NtDeleteKey (TargetKey);
NtClose (TargetKey);
+
+Cleanup:
+ CloseDefaultKey(ParentKey);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -802,7 +861,7 @@
IN LPCWSTR lpValueName OPTIONAL)
{
UNICODE_STRING ValueName;
- HANDLE KeyHandle, SubKeyHandle = NULL;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
@@ -831,22 +890,27 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError(Status);
+ goto Cleanup;
}
- KeyHandle = SubKeyHandle;
+ CurKey = SubKeyHandle;
}
+ else
+ CurKey = KeyHandle;
RtlInitUnicodeString(&ValueName,
(LPWSTR)lpValueName);
- Status = NtDeleteValueKey(KeyHandle,
+ Status = NtDeleteValueKey(CurKey,
&ValueName);
if (SubKeyHandle != NULL)
{
NtClose(SubKeyHandle);
}
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status))
{
@@ -915,7 +979,7 @@
RegDeleteTreeW(IN HKEY hKey,
IN LPCWSTR lpSubKey OPTIONAL)
{
- HANDLE KeyHandle, SubKeyHandle = NULL;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
@@ -944,11 +1008,13 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError(Status);
+ goto Cleanup;
}
- KeyHandle = SubKeyHandle;
+ CurKey = SubKeyHandle;
}
+ else
+ CurKey = KeyHandle;
/* FIXME - delete all keys recursively */
Status = STATUS_NOT_IMPLEMENTED;
@@ -958,6 +1024,9 @@
NtClose(SubKeyHandle);
}
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError(Status);
@@ -1013,7 +1082,7 @@
IN LPCVOID lpData OPTIONAL,
IN DWORD cbData)
{
- HANDLE KeyHandle, SubKeyHandle = NULL;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
LONG Ret;
@@ -1043,13 +1112,16 @@
&ObjectAttributes);
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,
0,
dwType,
@@ -1060,6 +1132,9 @@
{
NtClose(SubKeyHandle);
}
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
return Ret;
}
@@ -1078,7 +1153,7 @@
IN LPCVOID lpData OPTIONAL,
IN DWORD cbData)
{
- HANDLE KeyHandle, SubKeyHandle = NULL;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
NTSTATUS Status;
LONG Ret;
@@ -1097,7 +1172,8 @@
if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
(LPSTR)lpSubKey))
{
- return ERROR_NOT_ENOUGH_MEMORY;
+ Ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto Cleanup;
}
InitializeObjectAttributes(&ObjectAttributes,
@@ -1114,13 +1190,16 @@
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,
0,
dwType,
@@ -1131,6 +1210,9 @@
{
NtClose(SubKeyHandle);
}
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
return Ret;
}
@@ -1150,7 +1232,7 @@
NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1161,6 +1243,9 @@
Status = NtDeleteValueKey (KeyHandle,
&ValueName);
RtlFreeUnicodeString (&ValueName);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1184,7 +1269,7 @@
HANDLE KeyHandle;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1195,6 +1280,9 @@
Status = NtDeleteValueKey (KeyHandle,
&ValueName);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1330,7 +1418,8 @@
KeyInfo = RtlAllocateHeap (ProcessHeap, 0, BufferSize);
if (KeyInfo == NULL)
{
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
Status = NtEnumerateKey (KeyHandle,
@@ -1416,7 +1505,10 @@
0,
KeyInfo);
- return ErrorCode;
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
@@ -1450,7 +1542,7 @@
NTSTATUS Status;
Status = MapDefaultKey(&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1488,7 +1580,8 @@
BufferSize);
if (KeyInfo == NULL)
{
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
Status = NtEnumerateKey (KeyHandle,
@@ -1560,6 +1653,9 @@
0,
KeyInfo);
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
@@ -1607,7 +1703,10 @@
{
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
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;
status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size );
@@ -1670,6 +1769,7 @@
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ CloseDefaultKey(KeyHandle);
return RtlNtStatusToDosError(status);
}
@@ -1729,7 +1829,10 @@
{
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
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;
status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size );
@@ -1774,6 +1877,7 @@
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ CloseDefaultKey(KeyHandle);
return RtlNtStatusToDosError(status);
}
@@ -1794,13 +1898,16 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
}
Status = NtFlushKey (KeyHandle);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1830,7 +1937,7 @@
}
Status = MapDefaultKey(&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
TRACE("MapDefaultKey() failed (Status %lx)\n", Status);
@@ -1842,6 +1949,9 @@
pSecurityDescriptor,
*lpcbSecurityDescriptor,
lpcbSecurityDescriptor);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
WARN("NtQuerySecurityObject() failed (Status %lx)\n", Status);
@@ -1898,6 +2008,7 @@
UNICODE_STRING KeyName;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA)
{
@@ -1905,7 +2016,7 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1916,7 +2027,8 @@
NULL,
NULL))
{
- return ERROR_BAD_PATHNAME;
+ ErrorCode = ERROR_BAD_PATHNAME;
+ goto Cleanup;
}
InitializeObjectAttributes (&FileObjectAttributes,
@@ -1941,10 +2053,14 @@
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
- return ERROR_SUCCESS;
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
@@ -1963,6 +2079,7 @@
IO_STATUS_BLOCK IoStatusBlock;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA)
{
@@ -1975,7 +2092,7 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -1995,10 +2112,12 @@
fAsynchronous);
if (!NT_SUCCESS(Status) && Status != STATUS_TIMEOUT)
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
}
- return ERROR_SUCCESS;
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
@@ -2090,6 +2209,7 @@
UNICODE_STRING SubKeyString;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult);
@@ -2111,10 +2231,12 @@
RtlFreeUnicodeString (&SubKeyString);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
}
+
+ CloseDefaultKey(KeyHandle);
- return ERROR_SUCCESS;
+ return ErrorCode;
}
@@ -2134,6 +2256,7 @@
UNICODE_STRING SubKeyString;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
TRACE("RegOpenKeyExW hKey 0x%x lpSubKey %S ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult);
@@ -2159,10 +2282,12 @@
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
}
+
+ CloseDefaultKey(KeyHandle);
- return ERROR_SUCCESS;
+ return ErrorCode;
}
@@ -2430,7 +2555,8 @@
FullInfoSize);
if (FullInfo == NULL)
{
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
FullInfo->ClassLength = ClassLength;
@@ -2458,7 +2584,8 @@
FullInfo);
}
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
TRACE("SubKeys %d\n", FullInfo->SubKeys);
@@ -2515,7 +2642,8 @@
FullInfo);
}
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
}
@@ -2545,6 +2673,9 @@
FullInfo);
}
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
@@ -2711,7 +2842,8 @@
if (lpData != NULL && lpcbData == NULL)
{
- return ERROR_INVALID_PARAMETER;
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
}
RtlInitUnicodeString (&ValueName,
@@ -2722,7 +2854,8 @@
BufferSize);
if (ValueInfo == NULL)
{
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
Status = NtQueryValueKey (KeyHandle,
@@ -2790,6 +2923,9 @@
0,
ValueInfo);
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
@@ -3013,7 +3149,7 @@
hKey, lpSubKey, lpValue, lpcbValue ? *lpcbValue : 0);
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3034,7 +3170,8 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
CloseRealKey = TRUE;
}
@@ -3055,6 +3192,9 @@
NtClose (RealKey);
}
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
@@ -3116,6 +3256,7 @@
HANDLE RealKeyHandle;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA)
{
@@ -3123,7 +3264,7 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3144,7 +3285,8 @@
&KeyObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
CloseRealKey = TRUE;
}
@@ -3164,7 +3306,8 @@
{
NtClose (RealKeyHandle);
}
- return ERROR_INVALID_PARAMETER;
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
}
InitializeObjectAttributes (&NewObjectAttributes,
@@ -3184,7 +3327,8 @@
{
NtClose (RealKeyHandle);
}
- return ERROR_INVALID_PARAMETER;
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
}
InitializeObjectAttributes (&OldObjectAttributes,
@@ -3210,7 +3354,10 @@
return RtlNtStatusToDosError (Status);
}
- return ERROR_SUCCESS;
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
@@ -3263,7 +3410,7 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3274,7 +3421,8 @@
NULL,
NULL))
{
- return ERROR_INVALID_PARAMETER;
+ Status = STATUS_INVALID_PARAMETER;
+ goto Cleanup;
}
InitializeObjectAttributes (&ObjectAttributes,
@@ -3292,13 +3440,17 @@
RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
Status = NtRestoreKey (KeyHandle,
FileHandle,
(ULONG)dwFlags);
NtClose (FileHandle);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3351,7 +3503,7 @@
NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3362,7 +3514,8 @@
NULL,
NULL))
{
- return ERROR_INVALID_PARAMETER;
+ Status = STATUS_INVALID_PARAMETER;
+ goto Cleanup;
}
if (lpSecurityAttributes != NULL)
@@ -3389,12 +3542,16 @@
RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
Status = NtSaveKey (KeyHandle,
FileHandle);
NtClose (FileHandle);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3423,7 +3580,7 @@
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3432,6 +3589,9 @@
Status = NtSetSecurityObject (KeyHandle,
SecurityInformation,
pSecurityDescriptor);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3547,7 +3707,7 @@
NTSTATUS Status;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3579,6 +3739,9 @@
dwType,
(PVOID)lpData,
(ULONG)cbData);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3659,7 +3822,7 @@
LONG ErrorCode;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
@@ -3679,7 +3842,8 @@
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
CloseRealKey = TRUE;
[truncated at 1000 lines; 20 more skipped]