-/* $Id: reg.c,v 1.34 2003/12/13 23:59:45 gvg Exp $
+/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* UPDATE HISTORY:
* Created 01/11/98
* 19990309 EA Stubs
+ * 20050502 Fireball imported some stuff from WINE
*/
/* INCLUDES *****************************************************************/
-#define NTOS_MODE_USER
-#include <ntos.h>
-#include <ddk/ntddk.h>
-#include <rosrtl/string.h>
-#include <ntdll/rtl.h>
-#include <windows.h>
-#include <wchar.h>
-
+#include <advapi32.h>
#define NDEBUG
-#include <debug.h>
+#include <wine/debug.h>
/* DEFINES ******************************************************************/
#define MAX_DEFAULT_HANDLES 6
#define REG_MAX_NAME_SIZE 256
-#define REG_MAX_DATA_SIZE 2048
+#define REG_MAX_DATA_SIZE 2048
+
+/* FIXME: should go into msvcrt.h header? */
+#define offsetof(s,m) (size_t)&(((s*)NULL)->m)
/* GLOBALS ******************************************************************/
-static CRITICAL_SECTION HandleTableCS;
+static RTL_CRITICAL_SECTION HandleTableCS;
static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
static HANDLE ProcessHeap;
+static BOOLEAN DefaultHandlesDisabled = FALSE;
/* PROTOTYPES ***************************************************************/
-static NTSTATUS MapDefaultKey (PHKEY ParentKey, HKEY Key);
+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);
/* FUNCTIONS ****************************************************************/
+/* check if value type needs string conversion (Ansi<->Unicode) */
+inline static int is_string( DWORD type )
+{
+ return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
+}
/************************************************************************
* RegInitDefaultHandles
BOOL
RegInitialize (VOID)
{
- DPRINT("RegInitialize()\n");
+ TRACE("RegInitialize()\n");
ProcessHeap = RtlGetProcessHeap();
RtlZeroMemory (DefaultHandleTable,
BOOL
RegCleanup (VOID)
{
- DPRINT("RegCleanup()\n");
+ TRACE("RegCleanup()\n");
CloseDefaultKeys ();
RtlDeleteCriticalSection (&HandleTableCS);
static NTSTATUS
-MapDefaultKey (PHKEY RealKey,
- HKEY Key)
+MapDefaultKey (OUT PHANDLE RealKey,
+ IN HKEY Key)
{
PHANDLE Handle;
ULONG Index;
+ BOOLEAN DoOpen;
NTSTATUS Status = STATUS_SUCCESS;
- DPRINT("MapDefaultKey (Key %x)\n", Key);
+ TRACE("MapDefaultKey (Key %x)\n", Key);
if (((ULONG)Key & 0xF0000000) != 0x80000000)
{
- *RealKey = Key;
+ *RealKey = (HANDLE)((ULONG_PTR)Key & ~0x1);
return STATUS_SUCCESS;
}
}
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)
break;
default:
- DPRINT("MapDefaultHandle() no handle creator\n");
+ WARN("MapDefaultHandle() no handle creator\n");
Status = STATUS_INVALID_PARAMETER;
+ break;
}
}
- RtlLeaveCriticalSection (&HandleTableCS);
- if (NT_SUCCESS(Status))
- {
- *RealKey = (HKEY)*Handle;
- }
+ if (NT_SUCCESS(Status))
+ {
+ if (!DefaultHandlesDisabled)
+ *RealKey = *Handle;
+ else
+ *(PULONG_PTR)Handle |= 0x1;
+ }
+
+ RtlLeaveCriticalSection (&HandleTableCS);
return Status;
}
OpenClassesRootKey (PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
- UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\Machine\\Software\\CLASSES");
+ UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\CLASSES");
- DPRINT("OpenClassesRootKey()\n");
+ TRACE("OpenClassesRootKey()\n");
InitializeObjectAttributes (&Attributes,
&KeyName,
OpenLocalMachineKey (PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
- UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\Machine");
+ UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine");
+ NTSTATUS Status;
- DPRINT("OpenLocalMachineKey()\n");
+ TRACE("OpenLocalMachineKey()\n");
InitializeObjectAttributes (&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
- return NtOpenKey (KeyHandle,
- MAXIMUM_ALLOWED,
- &Attributes);
+ Status = NtOpenKey (KeyHandle,
+ MAXIMUM_ALLOWED,
+ &Attributes);
+
+ TRACE("NtOpenKey(%wZ) => %08x\n", &KeyName, Status);
+ return Status;
}
OpenUsersKey (PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
- UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\User");
+ UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\User");
- DPRINT("OpenUsersKey()\n");
+ TRACE("OpenUsersKey()\n");
InitializeObjectAttributes (&Attributes,
&KeyName,
NULL,
NULL);
return NtOpenKey (KeyHandle,
- KEY_ALL_ACCESS,
+ MAXIMUM_ALLOWED,
&Attributes);
}
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName =
- ROS_STRING_INITIALIZER(L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current");
+ RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current");
- DPRINT("OpenCurrentConfigKey()\n");
+ TRACE("OpenCurrentConfigKey()\n");
InitializeObjectAttributes (&Attributes,
&KeyName,
}
+/************************************************************************
+ * RegDisablePredefinedCacheEx
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegDisablePredefinedCacheEx(VOID)
+{
+ RtlEnterCriticalSection (&HandleTableCS);
+ DefaultHandlesDisabled = TRUE;
+ RtlLeaveCriticalSection (&HandleTableCS);
+ return ERROR_SUCCESS;
+}
+
+
/************************************************************************
* RegCloseKey
*
LONG STDCALL
RegCloseKey (HKEY hKey)
{
- LONG ErrorCode;
NTSTATUS Status;
/* don't close null handle or a pseudo handle */
Status = NtClose (hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
}
+/************************************************************************
+ * RegCopyTreeW
+ *
+ * @unimplemented
+ */
+LONG STDCALL
+RegCopyTreeW(IN HKEY hKeySrc,
+ IN LPCWSTR lpSubKey OPTIONAL,
+ IN HKEY hKeyDest)
+{
+ HANDLE DestKeyHandle, KeyHandle, CurKey, SubKeyHandle = NULL;
+ NTSTATUS Status;
+
+ Status = MapDefaultKey(&KeyHandle,
+ hKeySrc);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError(Status);
+ }
+
+ Status = MapDefaultKey(&DestKeyHandle,
+ hKeyDest);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Cleanup2;
+ }
+
+ if (lpSubKey != NULL)
+ {
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
+
+ RtlInitUnicodeString(&SubKeyName,
+ (LPWSTR)lpSubKey);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey(&SubKeyHandle,
+ KEY_READ,
+ &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Cleanup;
+ }
+
+ CurKey = SubKeyHandle;
+ }
+ else
+ CurKey = KeyHandle;
+
+ /* FIXME - copy all keys and values recursively */
+ Status = STATUS_NOT_IMPLEMENTED;
+
+ if (SubKeyHandle != NULL)
+ {
+ NtClose(SubKeyHandle);
+ }
+
+Cleanup:
+ CloseDefaultKey(DestKeyHandle);
+Cleanup2:
+ CloseDefaultKey(KeyHandle);
+
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError(Status);
+ }
+
+ return ERROR_SUCCESS;
+}
+
+
+/************************************************************************
+ * RegCopyTreeA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegCopyTreeA(IN HKEY hKeySrc,
+ IN LPCSTR lpSubKey OPTIONAL,
+ IN HKEY hKeyDest)
+{
+ UNICODE_STRING SubKeyName;
+ LONG Ret;
+
+ if (lpSubKey != NULL)
+ {
+ if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
+ (LPSTR)lpSubKey))
+ {
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
+ }
+ else
+ RtlInitUnicodeString(&SubKeyName,
+ NULL);
+
+ Ret = RegCopyTreeW(hKeySrc,
+ SubKeyName.Buffer,
+ hKeyDest);
+
+ RtlFreeUnicodeString(&SubKeyName);
+
+ return Ret;
+}
+
+
/************************************************************************
* RegConnectRegistryW
*
}
+/************************************************************************
+ * CreateNestedKey
+ *
+ * Create key and all necessary intermediate keys
+ */
+static NTSTATUS
+CreateNestedKey(PHKEY KeyHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ PUNICODE_STRING ClassString,
+ DWORD dwOptions,
+ REGSAM samDesired,
+ DWORD *lpdwDisposition)
+{
+ OBJECT_ATTRIBUTES LocalObjectAttributes;
+ UNICODE_STRING LocalKeyName;
+ ULONG Disposition;
+ NTSTATUS Status;
+ ULONG FullNameLength;
+ ULONG Length;
+ PWCHAR Ptr;
+ HANDLE LocalKeyHandle;
+
+ Status = NtCreateKey((PHANDLE) KeyHandle,
+ samDesired,
+ ObjectAttributes,
+ 0,
+ ClassString,
+ dwOptions,
+ (PULONG)lpdwDisposition);
+ TRACE("NtCreateKey(%wZ) called (Status %lx)\n", ObjectAttributes->ObjectName, Status);
+ if (Status != STATUS_OBJECT_NAME_NOT_FOUND)
+ return Status;
+
+ /* Copy object attributes */
+ RtlCopyMemory (&LocalObjectAttributes,
+ ObjectAttributes,
+ sizeof(OBJECT_ATTRIBUTES));
+ RtlCreateUnicodeString (&LocalKeyName,
+ ObjectAttributes->ObjectName->Buffer);
+ LocalObjectAttributes.ObjectName = &LocalKeyName;
+ FullNameLength = LocalKeyName.Length / sizeof(WCHAR);
+
+ /* Remove the last part of the key name and try to create the key again. */
+ while (Status == STATUS_OBJECT_NAME_NOT_FOUND)
+ {
+ Ptr = wcsrchr (LocalKeyName.Buffer, '\\');
+ if (Ptr == NULL || Ptr == LocalKeyName.Buffer)
+ {
+ Status = STATUS_UNSUCCESSFUL;
+ break;
+ }
+ *Ptr = (WCHAR)0;
+ LocalKeyName.Length = wcslen (LocalKeyName.Buffer) * sizeof(WCHAR);
+
+ Status = NtCreateKey (&LocalKeyHandle,
+ KEY_ALL_ACCESS,
+ &LocalObjectAttributes,
+ 0,
+ NULL,
+ 0,
+ &Disposition);
+ TRACE("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status);
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ RtlFreeUnicodeString (&LocalKeyName);
+ return Status;
+ }
+
+ /* Add removed parts of the key name and create them too. */
+ Length = wcslen (LocalKeyName.Buffer);
+ while (TRUE)
+ {
+ NtClose (LocalKeyHandle);
+
+ LocalKeyName.Buffer[Length] = L'\\';
+ Length = wcslen (LocalKeyName.Buffer);
+ LocalKeyName.Length = Length * sizeof(WCHAR);
+
+ if (Length == FullNameLength)
+ {
+ Status = NtCreateKey((PHANDLE) KeyHandle,
+ samDesired,
+ ObjectAttributes,
+ 0,
+ ClassString,
+ dwOptions,
+ (PULONG)lpdwDisposition);
+ break;
+ }
+ Status = NtCreateKey (&LocalKeyHandle,
+ KEY_CREATE_SUB_KEY,
+ &LocalObjectAttributes,
+ 0,
+ NULL,
+ 0,
+ &Disposition);
+ TRACE("NtCreateKey(%wZ) called (Status %lx)\n", &LocalKeyName, Status);
+ if (!NT_SUCCESS(Status))
+ break;
+ }
+
+ RtlFreeUnicodeString (&LocalKeyName);
+
+ return Status;
+}
+
+
/************************************************************************
* RegCreateKeyExA
*
UNICODE_STRING SubKeyString;
UNICODE_STRING ClassString;
OBJECT_ATTRIBUTES Attributes;
- HKEY ParentKey;
- LONG ErrorCode;
+ HANDLE ParentKey;
NTSTATUS Status;
- DPRINT("RegCreateKeyExA() called\n");
+ TRACE("RegCreateKeyExA() called\n");
/* get the real parent key */
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
- DPRINT("ParentKey %x\n", (ULONG)ParentKey);
+ TRACE("ParentKey %x\n", (ULONG)ParentKey);
if (lpClass != NULL)
{
RtlCreateUnicodeStringFromAsciiz (&ClassString,
lpClass);
}
- RtlCreateUnicodeStringFromAsciiz (&SubKeyString,
- (LPSTR)lpSubKey);
+
+ RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
+ (LPSTR)lpSubKey);
InitializeObjectAttributes (&Attributes,
&SubKeyString,
OBJ_CASE_INSENSITIVE,
(HANDLE)ParentKey,
(PSECURITY_DESCRIPTOR)lpSecurityAttributes);
- Status = NtCreateKey (phkResult,
- samDesired,
- &Attributes,
- 0,
- (lpClass == NULL)? NULL : &ClassString,
- dwOptions,
- (PULONG)lpdwDisposition);
+ Status = CreateNestedKey(phkResult,
+ &Attributes,
+ (lpClass == NULL)? NULL : &ClassString,
+ dwOptions,
+ samDesired,
+ lpdwDisposition);
RtlFreeUnicodeString (&SubKeyString);
if (lpClass != NULL)
{
RtlFreeUnicodeString (&ClassString);
}
- DPRINT("Status %x\n", Status);
+
+ CloseDefaultKey(ParentKey);
+
+ TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
* @implemented
*/
LONG STDCALL
-RegCreateKeyExW(HKEY hKey,
- LPCWSTR lpSubKey,
- DWORD Reserved,
- LPWSTR lpClass,
- DWORD dwOptions,
- REGSAM samDesired,
- LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- PHKEY phkResult,
- LPDWORD lpdwDisposition)
+RegCreateKeyExW (HKEY hKey,
+ LPCWSTR lpSubKey,
+ DWORD Reserved,
+ LPWSTR lpClass,
+ DWORD dwOptions,
+ REGSAM samDesired,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ PHKEY phkResult,
+ LPDWORD lpdwDisposition)
{
UNICODE_STRING SubKeyString;
UNICODE_STRING ClassString;
OBJECT_ATTRIBUTES Attributes;
- HKEY ParentKey;
- LONG ErrorCode;
+ HANDLE ParentKey;
NTSTATUS Status;
- DPRINT("RegCreateKeyExW() called\n");
+ TRACE("RegCreateKeyExW() called\n");
/* get the real parent key */
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError(Status);
}
- DPRINT("ParentKey %x\n", (ULONG)ParentKey);
+ TRACE("ParentKey %x\n", (ULONG)ParentKey);
RtlInitUnicodeString (&ClassString,
lpClass);
OBJ_CASE_INSENSITIVE,
(HANDLE)ParentKey,
(PSECURITY_DESCRIPTOR)lpSecurityAttributes);
- Status = NtCreateKey (phkResult,
- samDesired,
- &Attributes,
- 0,
- (lpClass == NULL)? NULL : &ClassString,
- dwOptions,
- (PULONG)lpdwDisposition);
- DPRINT("Status %x\n", Status);
+ Status = CreateNestedKey(phkResult,
+ &Attributes,
+ (lpClass == NULL)? NULL : &ClassString,
+ dwOptions,
+ samDesired,
+ lpdwDisposition);
+
+ CloseDefaultKey(ParentKey);
+
+ TRACE("Status %x\n", Status);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
0,
NULL,
0,
- KEY_ALL_ACCESS,
+ MAXIMUM_ALLOWED,
NULL,
phkResult,
NULL);
0,
NULL,
0,
- KEY_ALL_ACCESS,
+ MAXIMUM_ALLOWED,
NULL,
phkResult,
NULL);
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyName;
- HKEY ParentKey;
+ HANDLE ParentKey;
HANDLE TargetKey;
NTSTATUS Status;
- LONG ErrorCode;
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
RtlCreateUnicodeStringFromAsciiz (&SubKeyName,
InitializeObjectAttributes(&ObjectAttributes,
&SubKeyName,
OBJ_CASE_INSENSITIVE,
- (HANDLE)ParentKey,
+ ParentKey,
NULL);
Status = NtOpenKey (&TargetKey,
RtlFreeUnicodeString (&SubKeyName);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
Status = NtDeleteKey (TargetKey);
NtClose (TargetKey);
+
+Cleanup:
+ CloseDefaultKey(ParentKey);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError(Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError(Status);
}
return ERROR_SUCCESS;
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyName;
- HKEY ParentKey;
+ HANDLE ParentKey;
HANDLE TargetKey;
NTSTATUS Status;
- LONG ErrorCode;
Status = MapDefaultKey (&ParentKey,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
RtlInitUnicodeString (&SubKeyName,
InitializeObjectAttributes (&ObjectAttributes,
&SubKeyName,
OBJ_CASE_INSENSITIVE,
- (HANDLE)ParentKey,
+ ParentKey,
NULL);
Status = NtOpenKey (&TargetKey,
DELETE,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
Status = NtDeleteKey (TargetKey);
NtClose (TargetKey);
+
+Cleanup:
+ CloseDefaultKey(ParentKey);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
/************************************************************************
- * RegDeleteValueA
+ * RegDeleteKeyValueW
*
* @implemented
*/
LONG STDCALL
-RegDeleteValueA (HKEY hKey,
- LPCSTR lpValueName)
+RegDeleteKeyValueW(IN HKEY hKey,
+ IN LPCWSTR lpSubKey OPTIONAL,
+ IN LPCWSTR lpValueName OPTIONAL)
{
- UNICODE_STRING ValueName;
- HKEY KeyHandle;
- LONG ErrorCode;
- NTSTATUS Status;
+ UNICODE_STRING ValueName;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
+ NTSTATUS Status;
- Status = MapDefaultKey (&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError(Status);
}
- RtlCreateUnicodeStringFromAsciiz (&ValueName,
- (LPSTR)lpValueName);
- Status = NtDeleteValueKey (KeyHandle,
- &ValueName);
- RtlFreeUnicodeString (&ValueName);
- if (!NT_SUCCESS(Status))
+ if (lpSubKey != NULL)
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
+
+ RtlInitUnicodeString(&SubKeyName,
+ (LPWSTR)lpSubKey);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey(&SubKeyHandle,
+ KEY_SET_VALUE,
+ &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Cleanup;
+ }
+
+ CurKey = SubKeyHandle;
}
+ else
+ CurKey = KeyHandle;
- return ERROR_SUCCESS;
+ RtlInitUnicodeString(&ValueName,
+ (LPWSTR)lpValueName);
+
+ Status = NtDeleteValueKey(CurKey,
+ &ValueName);
+
+ if (SubKeyHandle != NULL)
+ {
+ NtClose(SubKeyHandle);
+ }
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError(Status);
+ }
+
+ return ERROR_SUCCESS;
}
/************************************************************************
- * RegDeleteValueW
+ * RegDeleteKeyValueA
*
* @implemented
*/
LONG STDCALL
-RegDeleteValueW (HKEY hKey,
- LPCWSTR lpValueName)
+RegDeleteKeyValueA(IN HKEY hKey,
+ IN LPCSTR lpSubKey OPTIONAL,
+ IN LPCSTR lpValueName OPTIONAL)
{
- UNICODE_STRING ValueName;
- NTSTATUS Status;
- LONG ErrorCode;
- HKEY KeyHandle;
-
- Status = MapDefaultKey (&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
+ UNICODE_STRING SubKey, ValueName;
+ LONG Ret;
+
+ if (lpSubKey != NULL)
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ if (!RtlCreateUnicodeStringFromAsciiz(&SubKey,
+ (LPSTR)lpSubKey))
+ {
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
}
+ else
+ RtlInitUnicodeString(&SubKey,
+ NULL);
- RtlInitUnicodeString (&ValueName,
- (LPWSTR)lpValueName);
-
- Status = NtDeleteValueKey (KeyHandle,
- &ValueName);
- if (!NT_SUCCESS(Status))
+ if (lpValueName != NULL)
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ if (!RtlCreateUnicodeStringFromAsciiz(&ValueName,
+ (LPSTR)lpValueName))
+ {
+ RtlFreeUnicodeString(&SubKey);
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
}
+ else
+ RtlInitUnicodeString(&ValueName,
+ NULL);
- return ERROR_SUCCESS;
+ Ret = RegDeleteKeyValueW(hKey,
+ SubKey.Buffer,
+ SubKey.Buffer);
+
+ RtlFreeUnicodeString(&SubKey);
+ RtlFreeUnicodeString(&ValueName);
+
+ return Ret;
}
-/************************************************************************
- * RegEnumKeyA
- *
- * @implemented
- */
-LONG STDCALL
-RegEnumKeyA (HKEY hKey,
- DWORD dwIndex,
- LPSTR lpName,
- DWORD cbName)
+static NTSTATUS
+RegpDeleteTree(IN HKEY hKey)
{
- DWORD dwLength;
-
- dwLength = cbName;
- return RegEnumKeyExA (hKey,
- dwIndex,
- lpName,
- &dwLength,
- NULL,
- NULL,
- NULL,
- NULL);
+ typedef struct
+ {
+ LIST_ENTRY ListEntry;
+ HANDLE KeyHandle;
+ } REGP_DEL_KEYS, *PREG_DEL_KEYS;
+
+ LIST_ENTRY delQueueHead;
+ PREG_DEL_KEYS delKeys = NULL, newDelKeys;
+ HANDLE ProcessHeap;
+ ULONG BufferSize;
+ PKEY_BASIC_INFORMATION BasicInfo;
+ PREG_DEL_KEYS KeyDelRoot;
+ NTSTATUS Status = STATUS_SUCCESS;
+ NTSTATUS Status2 = STATUS_SUCCESS;
+
+ InitializeListHead(&delQueueHead);
+
+ ProcessHeap = RtlGetProcessHeap();
+
+ /* NOTE: no need to allocate enough memory for an additional KEY_BASIC_INFORMATION
+ structure for the root key, we only do that for subkeys as we need to
+ allocate REGP_DEL_KEYS structures anyway! */
+ KeyDelRoot = RtlAllocateHeap(ProcessHeap,
+ 0,
+ sizeof(REGP_DEL_KEYS));
+ if (KeyDelRoot != NULL)
+ {
+ KeyDelRoot->KeyHandle = hKey;
+ InsertTailList(&delQueueHead,
+ &KeyDelRoot->ListEntry);
+
+ do
+ {
+ delKeys = CONTAINING_RECORD(delQueueHead.Flink,
+ REGP_DEL_KEYS,
+ ListEntry);
+
+ BufferSize = 0;
+ BasicInfo = NULL;
+ newDelKeys = NULL;
+
+ReadFirstSubKey:
+ /* check if this key contains subkeys and delete them first by queuing
+ them at the head of the list */
+ Status2 = NtEnumerateKey(delKeys->KeyHandle,
+ 0,
+ KeyBasicInformation,
+ BasicInfo,
+ BufferSize,
+ &BufferSize);
+
+ if (NT_SUCCESS(Status2))
+ {
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
+
+ ASSERT(newDelKeys != NULL);
+ ASSERT(BasicInfo != NULL);
+
+ /* don't use RtlInitUnicodeString as the string is not NULL-terminated! */
+ SubKeyName.Length = BasicInfo->NameLength;
+ SubKeyName.MaximumLength = BasicInfo->NameLength;
+ SubKeyName.Buffer = BasicInfo->Name;
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ delKeys->KeyHandle,
+ NULL);
+
+ /* open the subkey */
+ Status2 = NtOpenKey(&newDelKeys->KeyHandle,
+ DELETE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
+ &ObjectAttributes);
+ if (!NT_SUCCESS(Status2))
+ {
+ goto SubKeyFailure;
+ }
+
+ /* enqueue this key to the head of the deletion queue */
+ InsertHeadList(&delQueueHead,
+ &newDelKeys->ListEntry);
+
+ /* try again from the head of the list */
+ continue;
+ }
+ else
+ {
+ if (Status2 == STATUS_BUFFER_TOO_SMALL)
+ {
+ newDelKeys = RtlAllocateHeap(ProcessHeap,
+ 0,
+ BufferSize + sizeof(REGP_DEL_KEYS));
+ if (newDelKeys != NULL)
+ {
+ BasicInfo = (PKEY_BASIC_INFORMATION)(newDelKeys + 1);
+
+ /* try again */
+ goto ReadFirstSubKey;
+ }
+ else
+ {
+ /* don't break, let's try to delete as many keys as possible */
+ Status2 = STATUS_INSUFFICIENT_RESOURCES;
+ goto SubKeyFailureNoFree;
+ }
+ }
+ else if (Status2 == STATUS_BUFFER_OVERFLOW)
+ {
+ PREG_DEL_KEYS newDelKeys2;
+
+ ASSERT(newDelKeys != NULL);
+
+ /* we need more memory to query the key name */
+ newDelKeys2 = RtlReAllocateHeap(ProcessHeap,
+ 0,
+ newDelKeys,
+ BufferSize + sizeof(REGP_DEL_KEYS));
+ if (newDelKeys2 != NULL)
+ {
+ newDelKeys = newDelKeys2;
+ BasicInfo = (PKEY_BASIC_INFORMATION)(newDelKeys + 1);
+
+ /* try again */
+ goto ReadFirstSubKey;
+ }
+ else
+ {
+ /* don't break, let's try to delete as many keys as possible */
+ Status2 = STATUS_INSUFFICIENT_RESOURCES;
+ }
+ }
+SubKeyFailure:
+ RtlFreeHeap(ProcessHeap,
+ 0,
+ newDelKeys);
+SubKeyFailureNoFree:
+ /* don't break, let's try to delete as many keys as possible */
+ if (Status2 != STATUS_NO_MORE_ENTRIES && NT_SUCCESS(Status))
+ {
+ Status = Status2;
+ }
+ }
+
+ Status2 = NtDeleteKey(delKeys->KeyHandle);
+
+ /* NOTE: do NOT close the handle anymore, it's invalid already! */
+
+ if (!NT_SUCCESS(Status2) && NT_SUCCESS(Status))
+ {
+ /* don't break, let's try to delete as many keys as possible */
+ Status = Status2;
+ }
+
+ /* remove the entry from the list */
+ RemoveEntryList(&delKeys->ListEntry);
+
+ RtlFreeHeap(ProcessHeap,
+ 0,
+ delKeys);
+ } while (!IsListEmpty(&delQueueHead));
+ }
+ else
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+
+ return Status;
}
/************************************************************************
- * RegEnumKeyW
+ * RegDeleteTreeW
*
* @implemented
*/
LONG STDCALL
-RegEnumKeyW (HKEY hKey,
- DWORD dwIndex,
- LPWSTR lpName,
- DWORD cbName)
+RegDeleteTreeW(IN HKEY hKey,
+ IN LPCWSTR lpSubKey OPTIONAL)
{
- DWORD dwLength;
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
+ NTSTATUS Status;
- dwLength = cbName;
- return RegEnumKeyExW (hKey,
- dwIndex,
- lpName,
- &dwLength,
- NULL,
- NULL,
- NULL,
- NULL);
-}
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError(Status);
+ }
+ if (lpSubKey != NULL)
+ {
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
-/************************************************************************
- * RegEnumKeyExA
- *
- * @implemented
- */
-LONG STDCALL
-RegEnumKeyExA (HKEY hKey,
- DWORD dwIndex,
- LPSTR lpName,
- LPDWORD lpcbName,
- LPDWORD lpReserved,
- LPSTR lpClass,
- LPDWORD lpcbClass,
- PFILETIME lpftLastWriteTime)
-{
- union
- {
- KEY_NODE_INFORMATION Node;
- KEY_BASIC_INFORMATION Basic;
- } *KeyInfo;
+ RtlInitUnicodeString(&SubKeyName,
+ (LPWSTR)lpSubKey);
- UNICODE_STRING StringU;
- ANSI_STRING StringA;
- LONG ErrorCode = ERROR_SUCCESS;
- DWORD NameLength;
- DWORD ClassLength;
- DWORD BufferSize;
- DWORD ResultSize;
- HKEY KeyHandle;
- NTSTATUS Status;
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
- DPRINT("RegEnumKeyExA(hKey 0x%x, dwIndex %d, lpName 0x%x, *lpcbName %d, lpClass 0x%x, lpcbClass %d)\n",
- hKey, dwIndex, lpName, *lpcbName, lpClass, lpcbClass ? *lpcbClass : 0);
+ Status = NtOpenKey(&SubKeyHandle,
+ DELETE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
+ &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Cleanup;
+ }
+
+ CurKey = SubKeyHandle;
+ }
+ else
+ CurKey = KeyHandle;
- if ((lpClass) && (!lpcbClass))
+ Status = RegpDeleteTree(CurKey);
+
+ if (SubKeyHandle != NULL)
{
- SetLastError (ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
+ NtClose(SubKeyHandle);
}
- Status = MapDefaultKey(&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError(Status);
}
- if (*lpcbName > 0)
+ return ERROR_SUCCESS;
+}
+
+
+/************************************************************************
+ * RegDeleteTreeA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegDeleteTreeA(IN HKEY hKey,
+ IN LPCSTR lpSubKey OPTIONAL)
+{
+ UNICODE_STRING SubKeyName;
+ LONG Ret;
+
+ if (lpSubKey != NULL)
{
- NameLength = min (*lpcbName - 1 , REG_MAX_NAME_SIZE) * sizeof (WCHAR);
+ if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
+ (LPSTR)lpSubKey))
+ {
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
}
- else
+ else
+ RtlInitUnicodeString(&SubKeyName,
+ NULL);
+
+ Ret = RegDeleteTreeW(hKey,
+ SubKeyName.Buffer);
+
+ RtlFreeUnicodeString(&SubKeyName);
+
+ return Ret;
+}
+
+
+/************************************************************************
+ * RegSetKeyValueW
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegSetKeyValueW(IN HKEY hKey,
+ IN LPCWSTR lpSubKey OPTIONAL,
+ IN LPCWSTR lpValueName OPTIONAL,
+ IN DWORD dwType,
+ IN LPCVOID lpData OPTIONAL,
+ IN DWORD cbData)
+{
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
+ NTSTATUS Status;
+ LONG Ret;
+
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
{
- NameLength = 0;
+ return RtlNtStatusToDosError(Status);
}
- if (lpClass)
+
+ if (lpSubKey != NULL)
{
- if (*lpcbClass > 0)
- {
- ClassLength = min (*lpcbClass -1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
- }
- else
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
+
+ RtlInitUnicodeString(&SubKeyName,
+ (LPWSTR)lpSubKey);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey(&SubKeyHandle,
+ KEY_SET_VALUE,
+ &ObjectAttributes);
+ if (!NT_SUCCESS(Status))
{
- ClassLength = 0;
- }
- /* The class name should start at a dword boundary */
- BufferSize = ((sizeof(KEY_NODE_INFORMATION) + NameLength + 3) & ~3) + ClassLength;
- }
- else
- {
- BufferSize = sizeof(KEY_BASIC_INFORMATION) + NameLength;
+ Ret = RtlNtStatusToDosError(Status);
+ goto Cleanup;
+ }
+
+ CurKey = SubKeyHandle;
}
-
- KeyInfo = RtlAllocateHeap (ProcessHeap,
- 0,
- BufferSize);
-
- if (KeyInfo == NULL)
+ else
+ CurKey = KeyHandle;
+
+ Ret = RegSetValueExW(CurKey,
+ lpValueName,
+ 0,
+ dwType,
+ lpData,
+ cbData);
+
+ if (SubKeyHandle != NULL)
{
- SetLastError (ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
+ NtClose(SubKeyHandle);
}
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
- Status = NtEnumerateKey (KeyHandle,
- (ULONG)dwIndex,
- lpClass == NULL ? KeyBasicInformation : KeyNodeInformation,
- KeyInfo,
- BufferSize,
- &ResultSize);
- DPRINT("NtEnumerateKey() returned status 0x%X\n", Status);
- if (!NT_SUCCESS(Status))
+ return Ret;
+}
+
+
+/************************************************************************
+ * RegSetKeyValueA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegSetKeyValueA(IN HKEY hKey,
+ IN LPCSTR lpSubKey OPTIONAL,
+ IN LPCSTR lpValueName OPTIONAL,
+ IN DWORD dwType,
+ IN LPCVOID lpData OPTIONAL,
+ IN DWORD cbData)
+{
+ HANDLE KeyHandle, CurKey, SubKeyHandle = NULL;
+ NTSTATUS Status;
+ LONG Ret;
+
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
+ return RtlNtStatusToDosError(Status);
}
- else
+
+ if (lpSubKey != NULL)
{
- if (lpClass == NULL)
- {
- if (KeyInfo->Basic.NameLength > NameLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- StringU.Buffer = KeyInfo->Basic.Name;
- StringU.Length = KeyInfo->Basic.NameLength;
- StringU.MaximumLength = KeyInfo->Basic.NameLength;
- }
- }
- else
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyName;
+
+ if (!RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
+ (LPSTR)lpSubKey))
{
- if (KeyInfo->Node.NameLength > NameLength ||
- KeyInfo->Node.ClassLength > ClassLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- StringA.Buffer = lpClass;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbClass;
- StringU.Buffer = (PWCHAR)((ULONG_PTR)KeyInfo->Node.Name + KeyInfo->Node.ClassOffset);
- StringU.Length = KeyInfo->Node.ClassLength;
- StringU.MaximumLength = KeyInfo->Node.ClassLength;
- RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
- lpClass[StringA.Length] = 0;
- *lpcbClass = StringA.Length;
- StringU.Buffer = KeyInfo->Node.Name;
- StringU.Length = KeyInfo->Node.NameLength;
- StringU.MaximumLength = KeyInfo->Node.NameLength;
- }
- }
- if (ErrorCode == ERROR_SUCCESS)
+ Ret = ERROR_NOT_ENOUGH_MEMORY;
+ goto Cleanup;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey(&SubKeyHandle,
+ KEY_SET_VALUE,
+ &ObjectAttributes);
+
+ RtlFreeUnicodeString(&SubKeyName);
+
+ if (!NT_SUCCESS(Status))
{
- StringA.Buffer = lpName;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbName;
- RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
- lpName[StringA.Length] = 0;
- *lpcbName = StringA.Length;
- if (lpftLastWriteTime != NULL)
- {
- if (lpClass == NULL)
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Basic.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Basic.LastWriteTime.u.HighPart;
- }
- else
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Node.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Node.LastWriteTime.u.HighPart;
- }
- }
- }
+ Ret = RtlNtStatusToDosError(Status);
+ goto Cleanup;
+ }
+
+ CurKey = SubKeyHandle;
}
+ else
+ CurKey = KeyHandle;
- DPRINT("Key Namea0 Length %d\n", StringU.Length);
- DPRINT("Key Namea1 Length %d\n", NameLength);
- DPRINT("Key Namea Length %d\n", *lpcbName);
- DPRINT("Key Namea %s\n", lpName);
+ Ret = RegSetValueExA(CurKey,
+ lpValueName,
+ 0,
+ dwType,
+ lpData,
+ cbData);
- RtlFreeHeap (ProcessHeap,
- 0,
- KeyInfo);
-
- if (ErrorCode != ERROR_SUCCESS)
+ if (SubKeyHandle != NULL)
{
- SetLastError(ErrorCode);
+ NtClose(SubKeyHandle);
}
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
- return ErrorCode;
+ return Ret;
}
/************************************************************************
- * RegEnumKeyExW
+ * RegDeleteValueA
*
* @implemented
*/
LONG STDCALL
-RegEnumKeyExW (HKEY hKey,
- DWORD dwIndex,
- LPWSTR lpName,
- LPDWORD lpcbName,
- LPDWORD lpReserved,
- LPWSTR lpClass,
- LPDWORD lpcbClass,
- PFILETIME lpftLastWriteTime)
+RegDeleteValueA (HKEY hKey,
+ LPCSTR lpValueName)
{
- union
- {
- KEY_NODE_INFORMATION Node;
- KEY_BASIC_INFORMATION Basic;
- } *KeyInfo;
-
- ULONG BufferSize;
- ULONG ResultSize;
- ULONG NameLength;
- ULONG ClassLength;
- HKEY KeyHandle;
- LONG ErrorCode = ERROR_SUCCESS;
+ UNICODE_STRING ValueName;
+ HANDLE KeyHandle;
NTSTATUS Status;
- Status = MapDefaultKey(&KeyHandle,
- hKey);
+ Status = MapDefaultKey (&KeyHandle,
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
- if (*lpcbName > 0)
- {
- NameLength = min (*lpcbName - 1, REG_MAX_NAME_SIZE) * sizeof (WCHAR);
- }
- else
- {
- NameLength = 0;
- }
- if (lpClass)
- {
- if (*lpcbClass > 0)
- {
- ClassLength = min (*lpcbClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
- }
- else
- {
- ClassLength = 0;
- }
- BufferSize = ((sizeof(KEY_NODE_INFORMATION) + NameLength + 3) & ~3) + ClassLength;
- }
- else
- {
- BufferSize = sizeof(KEY_BASIC_INFORMATION) + NameLength;
- }
- KeyInfo = RtlAllocateHeap (ProcessHeap,
- 0,
- BufferSize);
- if (KeyInfo == NULL)
- {
- SetLastError (ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
+ return RtlNtStatusToDosError (Status);
}
- Status = NtEnumerateKey (KeyHandle,
- (ULONG)dwIndex,
- lpClass ? KeyNodeInformation : KeyBasicInformation,
- KeyInfo,
- BufferSize,
- &ResultSize);
- DPRINT("NtEnumerateKey() returned status 0x%X\n", Status);
+ RtlCreateUnicodeStringFromAsciiz (&ValueName,
+ (LPSTR)lpValueName);
+ Status = NtDeleteValueKey (KeyHandle,
+ &ValueName);
+ RtlFreeUnicodeString (&ValueName);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- }
- else
- {
- if (lpClass == NULL)
- {
- if (KeyInfo->Basic.NameLength > NameLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- RtlCopyMemory (lpName,
- KeyInfo->Basic.Name,
- KeyInfo->Basic.NameLength);
- *lpcbName = (DWORD)(KeyInfo->Basic.NameLength / sizeof(WCHAR));
- lpName[*lpcbName] = 0;
- }
- }
- else
- {
- if (KeyInfo->Node.NameLength > NameLength ||
- KeyInfo->Node.ClassLength > ClassLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- RtlCopyMemory (lpName,
- KeyInfo->Node.Name,
- KeyInfo->Node.NameLength);
- *lpcbName = KeyInfo->Node.NameLength / sizeof(WCHAR);
- lpName[*lpcbName] = 0;
- RtlCopyMemory (lpClass,
- (PVOID)((ULONG_PTR)KeyInfo->Node.Name + KeyInfo->Node.ClassOffset),
- KeyInfo->Node.ClassLength);
- *lpcbClass = (DWORD)(KeyInfo->Node.ClassLength / sizeof(WCHAR));
- lpClass[*lpcbClass] = 0;
- }
- }
- if (ErrorCode == ERROR_SUCCESS && lpftLastWriteTime != NULL)
- {
- if (lpClass == NULL)
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Basic.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Basic.LastWriteTime.u.HighPart;
- }
- else
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Node.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Node.LastWriteTime.u.HighPart;
- }
- }
+ return RtlNtStatusToDosError (Status);
}
- RtlFreeHeap (ProcessHeap,
- 0,
- KeyInfo);
-
- if (ErrorCode != ERROR_SUCCESS)
- {
- SetLastError(ErrorCode);
- }
- return ErrorCode;
+ return ERROR_SUCCESS;
}
/************************************************************************
- * RegEnumValueA
+ * RegDeleteValueW
*
* @implemented
*/
LONG STDCALL
-RegEnumValueA (HKEY hKey,
- DWORD dwIndex,
- LPSTR lpValueName,
- LPDWORD lpcbValueName,
- LPDWORD lpReserved,
- LPDWORD lpType,
- LPBYTE lpData,
- LPDWORD lpcbData)
+RegDeleteValueW (HKEY hKey,
+ LPCWSTR lpValueName)
{
- union
- {
- KEY_VALUE_FULL_INFORMATION Full;
- KEY_VALUE_BASIC_INFORMATION Basic;
- } *ValueInfo;
-
- ULONG NameLength;
- ULONG BufferSize;
- ULONG DataLength;
- ULONG ResultSize;
- HKEY KeyHandle;
- LONG ErrorCode;
+ UNICODE_STRING ValueName;
NTSTATUS Status;
- UNICODE_STRING StringU;
- ANSI_STRING StringA;
- BOOL IsStringType;
-
- ErrorCode = ERROR_SUCCESS;
+ HANDLE KeyHandle;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
- if (*lpcbValueName > 0)
- {
- NameLength = min (*lpcbValueName - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
- }
- else
- {
- NameLength = 0;
- }
- if (lpData)
- {
- DataLength = min (*lpcbData * sizeof(WCHAR), REG_MAX_DATA_SIZE);
- BufferSize = ((sizeof(KEY_VALUE_FULL_INFORMATION) + NameLength + 3) & ~3) + DataLength;
- }
- else
- {
- BufferSize = sizeof(KEY_VALUE_BASIC_INFORMATION) + NameLength;
- }
+ RtlInitUnicodeString (&ValueName,
+ (LPWSTR)lpValueName);
- ValueInfo = RtlAllocateHeap (ProcessHeap,
- 0,
- BufferSize);
- if (ValueInfo == NULL)
- {
- SetLastError(ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
- }
+ Status = NtDeleteValueKey (KeyHandle,
+ &ValueName);
- Status = NtEnumerateValueKey (KeyHandle,
- (ULONG)dwIndex,
- lpData ? KeyValueFullInformation : KeyValueBasicInformation,
- ValueInfo,
- BufferSize,
- &ResultSize);
+ CloseDefaultKey(KeyHandle);
- DPRINT("NtEnumerateValueKey() returned status 0x%X\n", Status);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
+ return RtlNtStatusToDosError (Status);
}
- else
- {
- if (lpData)
- {
- IsStringType = (ValueInfo->Full.Type == REG_SZ) ||
- (ValueInfo->Full.Type == REG_MULTI_SZ) ||
- (ValueInfo->Full.Type == REG_EXPAND_SZ);
- if (ValueInfo->Full.NameLength > NameLength ||
- (!IsStringType && ValueInfo->Full.DataLength > *lpcbData) ||
- ValueInfo->Full.DataLength > DataLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- if (IsStringType)
- {
- StringU.Buffer = (PWCHAR)((ULONG_PTR)ValueInfo + ValueInfo->Full.DataOffset);
- StringU.Length = ValueInfo->Full.DataLength;
- StringU.MaximumLength = DataLength;
- StringA.Buffer = (PCHAR)lpData;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbData;
- RtlUnicodeStringToAnsiString (&StringA,
- &StringU,
- FALSE);
- *lpcbData = StringA.Length;
+
+ return ERROR_SUCCESS;
+}
+
+
+/************************************************************************
+ * RegEnumKeyA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegEnumKeyA (HKEY hKey,
+ DWORD dwIndex,
+ LPSTR lpName,
+ DWORD cbName)
+{
+ DWORD dwLength;
+
+ dwLength = cbName;
+ return RegEnumKeyExA (hKey,
+ dwIndex,
+ lpName,
+ &dwLength,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+}
+
+
+/************************************************************************
+ * RegEnumKeyW
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegEnumKeyW (HKEY hKey,
+ DWORD dwIndex,
+ LPWSTR lpName,
+ DWORD cbName)
+{
+ DWORD dwLength;
+
+ dwLength = cbName;
+ return RegEnumKeyExW (hKey,
+ dwIndex,
+ lpName,
+ &dwLength,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+}
+
+
+/************************************************************************
+ * RegEnumKeyExA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegEnumKeyExA (HKEY hKey,
+ DWORD dwIndex,
+ LPSTR lpName,
+ LPDWORD lpcbName,
+ LPDWORD lpReserved,
+ LPSTR lpClass,
+ LPDWORD lpcbClass,
+ PFILETIME lpftLastWriteTime)
+{
+ union
+ {
+ KEY_NODE_INFORMATION Node;
+ KEY_BASIC_INFORMATION Basic;
+ } *KeyInfo;
+
+ UNICODE_STRING StringU;
+ ANSI_STRING StringA;
+ LONG ErrorCode = ERROR_SUCCESS;
+ DWORD NameLength;
+ DWORD ClassLength = 0;
+ DWORD BufferSize;
+ DWORD ResultSize;
+ HANDLE KeyHandle;
+ NTSTATUS Status;
+
+ TRACE("RegEnumKeyExA(hKey 0x%x, dwIndex %d, lpName 0x%x, *lpcbName %d, lpClass 0x%x, lpcbClass %d)\n",
+ hKey, dwIndex, lpName, *lpcbName, lpClass, lpcbClass ? *lpcbClass : 0);
+
+ if ((lpClass) && (!lpcbClass))
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ Status = MapDefaultKey(&KeyHandle, hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ if (*lpcbName > 0)
+ {
+ NameLength = min (*lpcbName - 1 , REG_MAX_NAME_SIZE) * sizeof (WCHAR);
+ }
+ else
+ {
+ NameLength = 0;
+ }
+
+ if (lpClass)
+ {
+ if (*lpcbClass > 0)
+ {
+ ClassLength = min (*lpcbClass -1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
}
- else
- {
- RtlCopyMemory(lpData,
- (PVOID)((ULONG_PTR)ValueInfo + ValueInfo->Full.DataOffset),
- ValueInfo->Full.DataLength);
- *lpcbData = ValueInfo->Full.DataLength;
+ else
+ {
+ ClassLength = 0;
}
- StringU.Buffer = ValueInfo->Full.Name;
- StringU.Length = ValueInfo->Full.NameLength;
- StringU.MaximumLength = NameLength;
- }
+
+ /* The class name should start at a dword boundary */
+ BufferSize = ((sizeof(KEY_NODE_INFORMATION) + NameLength + 3) & ~3) + ClassLength;
}
- else
- {
- if (ValueInfo->Basic.NameLength > NameLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- StringU.Buffer = ValueInfo->Basic.Name;
- StringU.Length = ValueInfo->Basic.NameLength;
- StringU.MaximumLength = NameLength;
- }
+ else
+ {
+ BufferSize = sizeof(KEY_BASIC_INFORMATION) + NameLength;
}
- if (ErrorCode == ERROR_SUCCESS)
- {
- StringA.Buffer = (PCHAR)lpValueName;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbValueName;
- RtlUnicodeStringToAnsiString (&StringA,
- &StringU,
- FALSE);
- StringA.Buffer[StringA.Length] = 0;
- *lpcbValueName = StringA.Length;
- if (lpType)
- {
- *lpType = lpData ? ValueInfo->Full.Type : ValueInfo->Basic.Type;
- }
+
+ KeyInfo = RtlAllocateHeap (ProcessHeap, 0, BufferSize);
+ if (KeyInfo == NULL)
+ {
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
- }
- RtlFreeHeap (ProcessHeap,
- 0,
- ValueInfo);
- if (ErrorCode != ERROR_SUCCESS)
- {
- SetLastError(ErrorCode);
- }
- return ErrorCode;
+
+ Status = NtEnumerateKey (KeyHandle,
+ (ULONG)dwIndex,
+ lpClass == NULL ? KeyBasicInformation : KeyNodeInformation,
+ KeyInfo,
+ BufferSize,
+ &ResultSize);
+ TRACE("NtEnumerateKey() returned status 0x%X\n", Status);
+ if (!NT_SUCCESS(Status))
+ {
+ ErrorCode = RtlNtStatusToDosError (Status);
+ }
+ else
+ {
+ if (lpClass == NULL)
+ {
+ if (KeyInfo->Basic.NameLength > NameLength)
+ {
+ ErrorCode = ERROR_BUFFER_OVERFLOW;
+ }
+ else
+ {
+ StringU.Buffer = KeyInfo->Basic.Name;
+ StringU.Length = KeyInfo->Basic.NameLength;
+ StringU.MaximumLength = KeyInfo->Basic.NameLength;
+ }
+ }
+ else
+ {
+ if (KeyInfo->Node.NameLength > NameLength ||
+ KeyInfo->Node.ClassLength > ClassLength)
+ {
+ ErrorCode = ERROR_BUFFER_OVERFLOW;
+ }
+ else
+ {
+ StringA.Buffer = lpClass;
+ StringA.Length = 0;
+ StringA.MaximumLength = *lpcbClass;
+ StringU.Buffer = (PWCHAR)((ULONG_PTR)KeyInfo->Node.Name + KeyInfo->Node.ClassOffset);
+ StringU.Length = KeyInfo->Node.ClassLength;
+ StringU.MaximumLength = KeyInfo->Node.ClassLength;
+ RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
+ lpClass[StringA.Length] = 0;
+ *lpcbClass = StringA.Length;
+ StringU.Buffer = KeyInfo->Node.Name;
+ StringU.Length = KeyInfo->Node.NameLength;
+ StringU.MaximumLength = KeyInfo->Node.NameLength;
+ }
+ }
+
+ if (ErrorCode == ERROR_SUCCESS)
+ {
+ StringA.Buffer = lpName;
+ StringA.Length = 0;
+ StringA.MaximumLength = *lpcbName;
+ RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
+ lpName[StringA.Length] = 0;
+ *lpcbName = StringA.Length;
+ if (lpftLastWriteTime != NULL)
+ {
+ if (lpClass == NULL)
+ {
+ lpftLastWriteTime->dwLowDateTime = KeyInfo->Basic.LastWriteTime.u.LowPart;
+ lpftLastWriteTime->dwHighDateTime = KeyInfo->Basic.LastWriteTime.u.HighPart;
+ }
+ else
+ {
+ lpftLastWriteTime->dwLowDateTime = KeyInfo->Node.LastWriteTime.u.LowPart;
+ lpftLastWriteTime->dwHighDateTime = KeyInfo->Node.LastWriteTime.u.HighPart;
+ }
+ }
+ }
+ }
+
+ TRACE("Key Namea0 Length %d\n", StringU.Length);
+ TRACE("Key Namea1 Length %d\n", NameLength);
+ TRACE("Key Namea Length %d\n", *lpcbName);
+ TRACE("Key Namea %s\n", lpName);
+
+ RtlFreeHeap (ProcessHeap,
+ 0,
+ KeyInfo);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
/************************************************************************
- * RegEnumValueW
+ * RegEnumKeyExW
*
* @implemented
*/
LONG STDCALL
-RegEnumValueW (HKEY hKey,
+RegEnumKeyExW (HKEY hKey,
DWORD dwIndex,
- LPWSTR lpValueName,
- LPDWORD lpcbValueName,
+ LPWSTR lpName,
+ LPDWORD lpcbName,
LPDWORD lpReserved,
- LPDWORD lpType,
- LPBYTE lpData,
- LPDWORD lpcbData)
+ LPWSTR lpClass,
+ LPDWORD lpcbClass,
+ PFILETIME lpftLastWriteTime)
{
union
{
- KEY_VALUE_FULL_INFORMATION Full;
- KEY_VALUE_BASIC_INFORMATION Basic;
- } *ValueInfo;
+ KEY_NODE_INFORMATION Node;
+ KEY_BASIC_INFORMATION Basic;
+ } *KeyInfo;
- ULONG NameLength;
ULONG BufferSize;
- ULONG DataLength;
ULONG ResultSize;
- HKEY KeyHandle;
- LONG ErrorCode;
+ ULONG NameLength;
+ ULONG ClassLength = 0;
+ HANDLE KeyHandle;
+ LONG ErrorCode = ERROR_SUCCESS;
NTSTATUS Status;
-
- ErrorCode = ERROR_SUCCESS;
- Status = MapDefaultKey (&KeyHandle,
- hKey);
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
-
- if (*lpcbValueName > 0)
+
+ if (*lpcbName > 0)
{
- NameLength = min (*lpcbValueName - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
+ NameLength = min (*lpcbName - 1, REG_MAX_NAME_SIZE) * sizeof (WCHAR);
}
else
{
NameLength = 0;
}
- if (lpData)
+
+ if (lpClass)
{
- DataLength = min(*lpcbData, REG_MAX_DATA_SIZE);
- BufferSize = ((sizeof(KEY_VALUE_FULL_INFORMATION) + NameLength + 3) & ~3) + DataLength;
+ if (*lpcbClass > 0)
+ {
+ ClassLength = min (*lpcbClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
+ }
+ else
+ {
+ ClassLength = 0;
+ }
+
+ BufferSize = ((sizeof(KEY_NODE_INFORMATION) + NameLength + 3) & ~3) + ClassLength;
}
else
{
- BufferSize = sizeof(KEY_VALUE_BASIC_INFORMATION) + NameLength;
+ BufferSize = sizeof(KEY_BASIC_INFORMATION) + NameLength;
}
- ValueInfo = RtlAllocateHeap (ProcessHeap,
- 0,
- BufferSize);
- if (ValueInfo == NULL)
+
+ KeyInfo = RtlAllocateHeap (ProcessHeap,
+ 0,
+ BufferSize);
+ if (KeyInfo == NULL)
{
- SetLastError (ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
- Status = NtEnumerateValueKey (KeyHandle,
- (ULONG)dwIndex,
- lpData ? KeyValueFullInformation : KeyValueBasicInformation,
- ValueInfo,
- BufferSize,
- &ResultSize);
- DPRINT("NtEnumerateValueKey() returned status 0x%X\n", Status);
+ Status = NtEnumerateKey (KeyHandle,
+ (ULONG)dwIndex,
+ lpClass ? KeyNodeInformation : KeyBasicInformation,
+ KeyInfo,
+ BufferSize,
+ &ResultSize);
+ TRACE("NtEnumerateKey() returned status 0x%X\n", Status);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError (Status);
}
else
{
- if (lpData)
- {
- if (ValueInfo->Full.DataLength > DataLength ||
- ValueInfo->Full.NameLength > NameLength)
- {
+ if (lpClass == NULL)
+ {
+ if (KeyInfo->Basic.NameLength > NameLength)
+ {
ErrorCode = ERROR_BUFFER_OVERFLOW;
}
- else
+ else
{
- RtlCopyMemory (lpValueName,
- ValueInfo->Full.Name,
- ValueInfo->Full.NameLength);
- *lpcbValueName = (DWORD)(ValueInfo->Full.NameLength / sizeof(WCHAR));
- lpValueName[*lpcbValueName] = 0;
- RtlCopyMemory (lpData,
- (PVOID)((ULONG_PTR)ValueInfo + ValueInfo->Full.DataOffset),
- ValueInfo->Full.DataLength);
- *lpcbData = (DWORD)ValueInfo->Full.DataLength;
+ RtlCopyMemory (lpName,
+ KeyInfo->Basic.Name,
+ KeyInfo->Basic.NameLength);
+ *lpcbName = (DWORD)(KeyInfo->Basic.NameLength / sizeof(WCHAR));
+ lpName[*lpcbName] = 0;
}
}
else
- {
- if (ValueInfo->Basic.NameLength > NameLength)
+ {
+ if (KeyInfo->Node.NameLength > NameLength ||
+ KeyInfo->Node.ClassLength > ClassLength)
{
ErrorCode = ERROR_BUFFER_OVERFLOW;
}
else
{
- RtlCopyMemory (lpValueName,
- ValueInfo->Basic.Name,
- ValueInfo->Basic.NameLength);
- *lpcbValueName = (DWORD)(ValueInfo->Basic.NameLength / sizeof(WCHAR));
- lpValueName[*lpcbValueName] = 0;
+ RtlCopyMemory (lpName,
+ KeyInfo->Node.Name,
+ KeyInfo->Node.NameLength);
+ *lpcbName = KeyInfo->Node.NameLength / sizeof(WCHAR);
+ lpName[*lpcbName] = 0;
+ RtlCopyMemory (lpClass,
+ (PVOID)((ULONG_PTR)KeyInfo->Node.Name + KeyInfo->Node.ClassOffset),
+ KeyInfo->Node.ClassLength);
+ *lpcbClass = (DWORD)(KeyInfo->Node.ClassLength / sizeof(WCHAR));
+ lpClass[*lpcbClass] = 0;
}
}
- if (ErrorCode == ERROR_SUCCESS && lpType != NULL)
+
+ if (ErrorCode == ERROR_SUCCESS && lpftLastWriteTime != NULL)
{
- *lpType = lpData ? ValueInfo->Full.Type : ValueInfo->Basic.Type;
+ if (lpClass == NULL)
+ {
+ lpftLastWriteTime->dwLowDateTime = KeyInfo->Basic.LastWriteTime.u.LowPart;
+ lpftLastWriteTime->dwHighDateTime = KeyInfo->Basic.LastWriteTime.u.HighPart;
+ }
+ else
+ {
+ lpftLastWriteTime->dwLowDateTime = KeyInfo->Node.LastWriteTime.u.LowPart;
+ lpftLastWriteTime->dwHighDateTime = KeyInfo->Node.LastWriteTime.u.HighPart;
+ }
}
}
+
RtlFreeHeap (ProcessHeap,
0,
- ValueInfo);
- if (ErrorCode != ERROR_SUCCESS)
+ KeyInfo);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
+}
+
+/************************************************************************
+ * RegEnumValueA
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegEnumValueA( HKEY hKey, DWORD index, LPSTR value, LPDWORD val_count,
+ LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
+{
+ HANDLE KeyHandle;
+ NTSTATUS status;
+ DWORD total_size;
+ char buffer[256], *buf_ptr = buffer;
+ KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
+ static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
+
+ //TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
+ // hkey, index, value, val_count, reserved, type, data, count );
+
+ /* NT only checks count, not val_count */
+ if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
+ status = MapDefaultKey (&KeyHandle, hKey);
+ if (!NT_SUCCESS(status))
+ {
+ return RtlNtStatusToDosError (status);
+ }
+
+ total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
+ if (data) total_size += *count;
+ total_size = min( sizeof(buffer), total_size );
+
+ status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
+ buffer, total_size, &total_size );
+ if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
+
+ /* we need to fetch the contents for a string type even if not requested,
+ * because we need to compute the length of the ASCII string. */
+ if (value || data || is_string(info->Type))
{
- SetLastError(ErrorCode);
+ /* retry with a dynamically allocated buffer */
+ while (status == STATUS_BUFFER_OVERFLOW)
+ {
+ if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
+ {
+ status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
+ }
+ info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
+ status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
+ buf_ptr, total_size, &total_size );
+ }
+
+ if (status) goto done;
+
+ if (is_string(info->Type))
+ {
+ DWORD len;
+ RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
+ total_size - info->DataOffset );
+ if (data && len)
+ {
+ if (len > *count) status = STATUS_BUFFER_OVERFLOW;
+ else
+ {
+ RtlUnicodeToMultiByteN( (PCHAR)data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
+ total_size - info->DataOffset );
+ /* if the type is REG_SZ and data is not 0-terminated
+ * and there is enough space in the buffer NT appends a \0 */
+ if (len < *count && data[len-1]) data[len] = 0;
+ }
+ }
+ info->DataLength = len;
+ }
+ else if (data)
+ {
+ if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
+ else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
+ }
+
+ if (value && !status)
+ {
+ DWORD len;
+
+ RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
+ if (len >= *val_count)
+ {
+ status = STATUS_BUFFER_OVERFLOW;
+ if (*val_count)
+ {
+ len = *val_count - 1;
+ RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
+ value[len] = 0;
+ }
+ }
+ else
+ {
+ RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
+ value[len] = 0;
+ *val_count = len;
+ }
+ }
}
- return ErrorCode;
+ else status = STATUS_SUCCESS;
+
+ if (type) *type = info->Type;
+ if (count) *count = info->DataLength;
+
+ done:
+ if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ CloseDefaultKey(KeyHandle);
+ return RtlNtStatusToDosError(status);
}
+/******************************************************************************
+ * RegEnumValueW [ADVAPI32.@]
+ * @implemented
+ *
+ * PARAMS
+ * hkey [I] Handle to key to query
+ * index [I] Index of value to query
+ * value [O] Value string
+ * val_count [I/O] Size of value buffer (in wchars)
+ * reserved [I] Reserved
+ * type [O] Type code
+ * data [O] Value data
+ * count [I/O] Size of data buffer (in bytes)
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: nonzero error code from Winerror.h
+ */
+LONG STDCALL
+RegEnumValueW( HKEY hKey, DWORD index, LPWSTR value, PDWORD val_count,
+ PDWORD reserved, PDWORD type, LPBYTE data, PDWORD count )
+{
+ HANDLE KeyHandle;
+ NTSTATUS status;
+ DWORD total_size;
+ char buffer[256], *buf_ptr = buffer;
+ KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
+ static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
+
+ //TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
+ // hkey, index, value, val_count, reserved, type, data, count );
+
+ /* NT only checks count, not val_count */
+ if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
+
+ status = MapDefaultKey (&KeyHandle, hKey);
+ if (!NT_SUCCESS(status))
+ {
+ return RtlNtStatusToDosError (status);
+ }
+
+ total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
+ if (data) total_size += *count;
+ total_size = min( sizeof(buffer), total_size );
+
+ status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
+ buffer, total_size, &total_size );
+ if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
+
+ if (value || data)
+ {
+ /* retry with a dynamically allocated buffer */
+ while (status == STATUS_BUFFER_OVERFLOW)
+ {
+ if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
+ {
+ 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 );
+ }
+
+ if (status) goto done;
+
+ if (value)
+ {
+ if (info->NameLength/sizeof(WCHAR) >= *val_count)
+ {
+ status = STATUS_BUFFER_OVERFLOW;
+ goto overflow;
+ }
+ memcpy( value, info->Name, info->NameLength );
+ *val_count = info->NameLength / sizeof(WCHAR);
+ value[*val_count] = 0;
+ }
+
+ if (data)
+ {
+ if (total_size - info->DataOffset > *count)
+ {
+ status = STATUS_BUFFER_OVERFLOW;
+ goto overflow;
+ }
+ memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
+ if (total_size - info->DataOffset <= *count-sizeof(WCHAR) && is_string(info->Type))
+ {
+ /* if the type is REG_SZ and data is not 0-terminated
+ * and there is enough space in the buffer NT appends a \0 */
+ WCHAR *ptr = (WCHAR *)(data + total_size - info->DataOffset);
+ if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
+ }
+ }
+ }
+ else status = STATUS_SUCCESS;
+
+ overflow:
+ if (type) *type = info->Type;
+ if (count) *count = info->DataLength;
+
+ done:
+ if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
+ CloseDefaultKey(KeyHandle);
+ return RtlNtStatusToDosError(status);
+}
/************************************************************************
* RegFlushKey
LONG STDCALL
RegFlushKey(HKEY hKey)
{
- HKEY KeyHandle;
- LONG ErrorCode;
+ HANDLE KeyHandle;
NTSTATUS Status;
if (hKey == HKEY_PERFORMANCE_DATA)
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
Status = NtFlushKey (KeyHandle);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
/************************************************************************
* RegGetKeySecurity
*
- * @unimplemented
+ * @implemented
*/
LONG STDCALL
-RegGetKeySecurity (HKEY hKey,
- SECURITY_INFORMATION SecurityInformation,
- PSECURITY_DESCRIPTOR pSecurityDescriptor,
- LPDWORD lpcbSecurityDescriptor)
+RegGetKeySecurity(HKEY hKey,
+ SECURITY_INFORMATION SecurityInformation,
+ PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ LPDWORD lpcbSecurityDescriptor)
{
-#if 0
- HKEY KeyHandle;
- LONG ErrorCode;
+ HANDLE KeyHandle;
NTSTATUS Status;
- if (hKey = HKEY_PERFORMANCE_DATA)
+ if (hKey == HKEY_PERFORMANCE_DATA)
{
return ERROR_INVALID_HANDLE;
}
- Status = MapDefaultKey (&KeyHandle,
- hKey);
+ Status = MapDefaultKey(&KeyHandle,
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ TRACE("MapDefaultKey() failed (Status %lx)\n", Status);
+ return RtlNtStatusToDosError (Status);
}
- Status = NtQuerySecurityObject ()
+ Status = NtQuerySecurityObject(KeyHandle,
+ SecurityInformation,
+ pSecurityDescriptor,
+ *lpcbSecurityDescriptor,
+ lpcbSecurityDescriptor);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ WARN("NtQuerySecurityObject() failed (Status %lx)\n", Status);
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
-#endif
-
- UNIMPLEMENTED;
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return ERROR_CALL_NOT_IMPLEMENTED;
}
{
UNICODE_STRING FileName;
UNICODE_STRING KeyName;
- DWORD ErrorCode;
+ LONG ErrorCode;
RtlCreateUnicodeStringFromAsciiz (&KeyName,
(LPSTR)lpSubKey);
UNICODE_STRING FileName;
UNICODE_STRING KeyName;
HANDLE KeyHandle;
- DWORD ErrorCode;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA)
{
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFile,
NULL,
NULL))
{
- SetLastError (ERROR_BAD_PATHNAME);
- return ERROR_BAD_PATHNAME;
+ ErrorCode = ERROR_BAD_PATHNAME;
+ goto Cleanup;
}
InitializeObjectAttributes (&FileObjectAttributes,
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
- return ERROR_SUCCESS;
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
IO_STATUS_BLOCK IoStatusBlock;
HANDLE KeyHandle;
NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
if (hKey == HKEY_PERFORMANCE_DATA)
{
}
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
return RtlNtStatusToDosError (Status);
fAsynchronous);
if (!NT_SUCCESS(Status) && Status != STATUS_TIMEOUT)
{
- return RtlNtStatusToDosError (Status);
+ ErrorCode = RtlNtStatusToDosError (Status);
}
- return ERROR_SUCCESS;
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
+/************************************************************************
+ * RegOpenCurrentUser
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegOpenCurrentUser (IN REGSAM samDesired,
+ OUT PHKEY phkResult)
+{
+ NTSTATUS Status;
+
+ Status = RtlOpenCurrentUser((ACCESS_MASK)samDesired,
+ (PHANDLE)phkResult);
+ if (!NT_SUCCESS(Status))
+ {
+ /* NOTE - don't set the last error code! just return the error! */
+ return RtlNtStatusToDosError(Status);
+ }
+
+ return ERROR_SUCCESS;
+}
+
/************************************************************************
* RegOpenKeyA
*
+ * 20050503 Fireball - imported from WINE
+ *
* @implemented
*/
LONG STDCALL
LPCSTR lpSubKey,
PHKEY phkResult)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
- LONG ErrorCode;
- NTSTATUS Status;
-
- Status = MapDefaultKey (&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ TRACE("RegOpenKeyA hKey 0x%x lpSubKey %s phkResult %p\n", hKey, lpSubKey, phkResult);
- RtlCreateUnicodeStringFromAsciiz (&SubKeyString,
- (LPSTR)lpSubKey);
- InitializeObjectAttributes (&ObjectAttributes,
- &SubKeyString,
- OBJ_CASE_INSENSITIVE,
- KeyHandle,
- NULL);
- Status = NtOpenKey (phkResult,
- MAXIMUM_ALLOWED,
- &ObjectAttributes);
- RtlFreeUnicodeString (&SubKeyString);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ if (!lpSubKey || !*lpSubKey)
+ {
+ *phkResult = hKey;
+ return ERROR_SUCCESS;
+ }
- return ERROR_SUCCESS;
+ return RegOpenKeyExA( hKey, lpSubKey, 0, MAXIMUM_ALLOWED, phkResult);
}
*
* 19981101 Ariadne
* 19990525 EA
+ * 20050503 Fireball - imported from WINE
*
* @implemented
*/
LPCWSTR lpSubKey,
PHKEY phkResult)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
- LONG ErrorCode;
- NTSTATUS Status;
-
- Status = MapDefaultKey (&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
-
- RtlInitUnicodeString (&SubKeyString,
- (LPWSTR)lpSubKey);
- InitializeObjectAttributes (&ObjectAttributes,
- &SubKeyString,
- OBJ_CASE_INSENSITIVE,
- KeyHandle,
- NULL);
- Status = NtOpenKey (phkResult,
- MAXIMUM_ALLOWED,
- &ObjectAttributes);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError(ErrorCode);
- return ErrorCode;
- }
+ TRACE("RegOpenKeyW hKey 0x%x lpSubKey %S phkResult %p\n", hKey, lpSubKey, phkResult);
- return ERROR_SUCCESS;
+ if (!lpSubKey || !*lpSubKey)
+ {
+ *phkResult = hKey;
+ return ERROR_SUCCESS;
+ }
+ return RegOpenKeyExW(hKey, lpSubKey, 0, MAXIMUM_ALLOWED, phkResult);
}
REGSAM samDesired,
PHKEY phkResult)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
- LONG ErrorCode;
- NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING SubKeyString;
+ HANDLE KeyHandle;
+ NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
- Status = MapDefaultKey (&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n",
+ hKey, lpSubKey, ulOptions, samDesired, phkResult);
- RtlCreateUnicodeStringFromAsciiz (&SubKeyString,
- (LPSTR)lpSubKey);
- InitializeObjectAttributes (&ObjectAttributes,
- &SubKeyString,
- OBJ_CASE_INSENSITIVE,
- KeyHandle,
- NULL);
- Status = NtOpenKey (phkResult,
- samDesired,
- &ObjectAttributes);
- RtlFreeUnicodeString (&SubKeyString);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ Status = MapDefaultKey (&KeyHandle, hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
- return ERROR_SUCCESS;
+ RtlCreateUnicodeStringFromAsciiz (&SubKeyString, (LPSTR)lpSubKey);
+ InitializeObjectAttributes (&ObjectAttributes,
+ &SubKeyString,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey ((PHANDLE)phkResult, samDesired, &ObjectAttributes);
+ RtlFreeUnicodeString (&SubKeyString);
+ if (!NT_SUCCESS(Status))
+ {
+ ErrorCode = RtlNtStatusToDosError (Status);
+ }
+
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
REGSAM samDesired,
PHKEY phkResult)
{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ 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);
+
+ Status = MapDefaultKey (&KeyHandle, hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ if (lpSubKey != NULL)
+ RtlInitUnicodeString (&SubKeyString, (LPWSTR)lpSubKey);
+ else
+ RtlInitUnicodeString (&SubKeyString, (LPWSTR)L"");
+
+ InitializeObjectAttributes (&ObjectAttributes,
+ &SubKeyString,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+
+ Status = NtOpenKey ((PHANDLE)phkResult, samDesired, &ObjectAttributes);
+
+ if (!NT_SUCCESS(Status))
+ {
+ ErrorCode = RtlNtStatusToDosError (Status);
+ }
+
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
+}
+
+
+/************************************************************************
+ * RegOpenUserClassesRoot
+ *
+ * @implemented
+ */
+LONG STDCALL
+RegOpenUserClassesRoot (IN HANDLE hToken,
+ IN DWORD dwOptions,
+ IN REGSAM samDesired,
+ OUT PHKEY phkResult)
+{
+ const WCHAR UserClassesKeyPrefix[] = L"\\Registry\\User\\";
+ const WCHAR UserClassesKeySuffix[] = L"_Classes";
+ PTOKEN_USER TokenUserData;
+ ULONG RequiredLength;
+ UNICODE_STRING UserSidString, UserClassesKeyRoot;
OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
- LONG ErrorCode;
NTSTATUS Status;
- Status = MapDefaultKey (&KeyHandle,
- hKey);
+ /* check parameters */
+ if (hToken == NULL || dwOptions != 0 || phkResult == NULL)
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ /*
+ * Get the user sid from the token
+ */
+
+ReadTokenSid:
+ /* determine how much memory we need */
+ Status = NtQueryInformationToken(hToken,
+ TokenUser,
+ NULL,
+ 0,
+ &RequiredLength);
+ if (!NT_SUCCESS(Status) && (Status != STATUS_BUFFER_TOO_SMALL))
+ {
+ /* NOTE - as opposed to all other registry functions windows does indeed
+ change the last error code in case the caller supplied a invalid
+ handle for example! */
+ return RtlNtStatusToDosError (Status);
+ }
+
+ TokenUserData = RtlAllocateHeap(ProcessHeap,
+ 0,
+ RequiredLength);
+ if (TokenUserData == NULL)
+ {
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
+
+ /* attempt to read the information */
+ Status = NtQueryInformationToken(hToken,
+ TokenUser,
+ TokenUserData,
+ RequiredLength,
+ &RequiredLength);
if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ {
+ RtlFreeHeap(ProcessHeap,
+ 0,
+ TokenUserData);
+ if (Status == STATUS_BUFFER_TOO_SMALL)
+ {
+ /* the information appears to have changed?! try again */
+ goto ReadTokenSid;
+ }
+
+ /* NOTE - as opposed to all other registry functions windows does indeed
+ change the last error code in case the caller supplied a invalid
+ handle for example! */
+ return RtlNtStatusToDosError (Status);
+ }
+
+ /*
+ * Build the absolute path for the user's registry in the form
+ * "\Registry\User\<SID>_Classes"
+ */
+ Status = RtlConvertSidToUnicodeString(&UserSidString,
+ TokenUserData->User.Sid,
+ TRUE);
+
+ /* we don't need the user data anymore, free it */
+ RtlFreeHeap(ProcessHeap,
+ 0,
+ TokenUserData);
+
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ /* allocate enough memory for the entire key string */
+ UserClassesKeyRoot.Length = 0;
+ UserClassesKeyRoot.MaximumLength = UserSidString.Length +
+ sizeof(UserClassesKeyPrefix) +
+ sizeof(UserClassesKeySuffix);
+ UserClassesKeyRoot.Buffer = RtlAllocateHeap(ProcessHeap,
+ 0,
+ UserClassesKeyRoot.MaximumLength);
+ if (UserClassesKeyRoot.Buffer == NULL)
+ {
+ RtlFreeUnicodeString(&UserSidString);
+ return RtlNtStatusToDosError (Status);
+ }
+
+ /* build the string */
+ RtlAppendUnicodeToString(&UserClassesKeyRoot,
+ UserClassesKeyPrefix);
+ RtlAppendUnicodeStringToString(&UserClassesKeyRoot,
+ &UserSidString);
+ RtlAppendUnicodeToString(&UserClassesKeyRoot,
+ UserClassesKeySuffix);
+
+ TRACE("RegOpenUserClassesRoot: Absolute path: %wZ\n", &UserClassesKeyRoot);
+
+ /*
+ * Open the key
+ */
- if (lpSubKey != NULL)
- {
- RtlInitUnicodeString (&SubKeyString,
- (LPWSTR)lpSubKey);
- }
- else
- {
- RtlInitUnicodeString (&SubKeyString,
- (LPWSTR)L"");
- }
InitializeObjectAttributes (&ObjectAttributes,
- &SubKeyString,
+ &UserClassesKeyRoot,
OBJ_CASE_INSENSITIVE,
- KeyHandle,
+ NULL,
NULL);
- Status = NtOpenKey (phkResult,
- samDesired,
- &ObjectAttributes);
+
+ Status = NtOpenKey((PHANDLE)phkResult,
+ samDesired,
+ &ObjectAttributes);
+
+ RtlFreeUnicodeString(&UserSidString);
+ RtlFreeUnicodeString(&UserClassesKeyRoot);
+
if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
- }
+ {
+ return RtlNtStatusToDosError (Status);
+ }
return ERROR_SUCCESS;
}
KEY_FULL_INFORMATION FullInfoBuffer;
PKEY_FULL_INFORMATION FullInfo;
ULONG FullInfoSize;
- ULONG ClassLength;
- HKEY KeyHandle;
+ ULONG ClassLength = 0;
+ HANDLE KeyHandle;
NTSTATUS Status;
- LONG ErrorCode = ERROR_SUCCESS;
ULONG Length;
+ LONG ErrorCode = ERROR_SUCCESS;
if ((lpClass) && (!lpcbClass))
{
- SetLastError(ERROR_INVALID_PARAMETER);
return ERROR_INVALID_PARAMETER;
}
hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if (lpClass != NULL)
{
if (*lpcbClass > 0)
- {
- ClassLength = min(*lpcbClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
+ {
+ ClassLength = min(*lpcbClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
}
else
- {
+ {
ClassLength = 0;
}
+
FullInfoSize = sizeof(KEY_FULL_INFORMATION) + ((ClassLength + 3) & ~3);
FullInfo = RtlAllocateHeap (ProcessHeap,
0,
FullInfoSize);
if (FullInfo == NULL)
{
- SetLastError (ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
+
FullInfo->ClassLength = ClassLength;
}
else
FullInfo,
FullInfoSize,
&Length);
- DPRINT("NtQueryKey() returned status 0x%X\n", Status);
+ TRACE("NtQueryKey() returned status 0x%X\n", Status);
if (!NT_SUCCESS(Status))
{
+ if (lpClass != NULL)
+ {
+ RtlFreeHeap (ProcessHeap,
+ 0,
+ FullInfo);
+ }
+
ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
- else
- {
- DPRINT("SubKeys %d\n", FullInfo->SubKeys);
- if (lpcSubKeys != NULL)
- {
- *lpcSubKeys = FullInfo->SubKeys;
- }
-
- DPRINT("MaxNameLen %lu\n", FullInfo->MaxNameLen);
- if (lpcbMaxSubKeyLen != NULL)
- {
- *lpcbMaxSubKeyLen = FullInfo->MaxNameLen / sizeof(WCHAR) + 1;
- }
- DPRINT("MaxClassLen %lu\n", FullInfo->MaxClassLen);
- if (lpcbMaxClassLen != NULL)
- {
- *lpcbMaxClassLen = FullInfo->MaxClassLen / sizeof(WCHAR) + 1;
- }
+ TRACE("SubKeys %d\n", FullInfo->SubKeys);
+ if (lpcSubKeys != NULL)
+ {
+ *lpcSubKeys = FullInfo->SubKeys;
+ }
- DPRINT("Values %lu\n", FullInfo->Values);
- if (lpcValues)
- {
- *lpcValues = FullInfo->Values;
- }
+ TRACE("MaxNameLen %lu\n", FullInfo->MaxNameLen);
+ if (lpcbMaxSubKeyLen != NULL)
+ {
+ *lpcbMaxSubKeyLen = FullInfo->MaxNameLen / sizeof(WCHAR) + 1;
+ }
- DPRINT("MaxValueNameLen %lu\n", FullInfo->MaxValueNameLen);
- if (lpcbMaxValueNameLen)
- {
- *lpcbMaxValueNameLen = FullInfo->MaxValueNameLen / sizeof(WCHAR) + 1;
- }
+ TRACE("MaxClassLen %lu\n", FullInfo->MaxClassLen);
+ if (lpcbMaxClassLen != NULL)
+ {
+ *lpcbMaxClassLen = FullInfo->MaxClassLen / sizeof(WCHAR) + 1;
+ }
- DPRINT("MaxValueDataLen %lu\n", FullInfo->MaxValueDataLen);
- if (lpcbMaxValueLen)
- {
- *lpcbMaxValueLen = FullInfo->MaxValueDataLen;
- }
+ TRACE("Values %lu\n", FullInfo->Values);
+ if (lpcValues != NULL)
+ {
+ *lpcValues = FullInfo->Values;
+ }
- if (lpcbSecurityDescriptor)
- {
- *lpcbSecurityDescriptor = 0;
- /* FIXME */
- }
+ TRACE("MaxValueNameLen %lu\n", FullInfo->MaxValueNameLen);
+ if (lpcbMaxValueNameLen != NULL)
+ {
+ *lpcbMaxValueNameLen = FullInfo->MaxValueNameLen / sizeof(WCHAR) + 1;
+ }
- if (lpftLastWriteTime != NULL)
- {
- lpftLastWriteTime->dwLowDateTime = FullInfo->LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = FullInfo->LastWriteTime.u.HighPart;
- }
+ TRACE("MaxValueDataLen %lu\n", FullInfo->MaxValueDataLen);
+ if (lpcbMaxValueLen != NULL)
+ {
+ *lpcbMaxValueLen = FullInfo->MaxValueDataLen;
+ }
- if (lpClass != NULL)
- {
- if (FullInfo->ClassLength > ClassLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- RtlCopyMemory (lpClass,
- FullInfo->Class,
- FullInfo->ClassLength);
- *lpcbClass = FullInfo->ClassLength / sizeof(WCHAR);
- lpClass[*lpcbClass] = 0;
+ if (lpcbSecurityDescriptor != NULL)
+ {
+ Status = NtQuerySecurityObject(KeyHandle,
+ OWNER_SECURITY_INFORMATION |
+ GROUP_SECURITY_INFORMATION |
+ DACL_SECURITY_INFORMATION,
+ NULL,
+ 0,
+ lpcbSecurityDescriptor);
+ if (!NT_SUCCESS(Status))
+ {
+ if (lpClass != NULL)
+ {
+ RtlFreeHeap(ProcessHeap,
+ 0,
+ FullInfo);
}
+
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
}
}
+
+ if (lpftLastWriteTime != NULL)
+ {
+ lpftLastWriteTime->dwLowDateTime = FullInfo->LastWriteTime.u.LowPart;
+ lpftLastWriteTime->dwHighDateTime = FullInfo->LastWriteTime.u.HighPart;
+ }
+
if (lpClass != NULL)
{
+ if (FullInfo->ClassLength > ClassLength)
+ {
+ ErrorCode = ERROR_BUFFER_OVERFLOW;
+ }
+ else
+ {
+ RtlCopyMemory (lpClass,
+ FullInfo->Class,
+ FullInfo->ClassLength);
+ *lpcbClass = FullInfo->ClassLength / sizeof(WCHAR);
+ lpClass[*lpcbClass] = 0;
+ }
+
RtlFreeHeap (ProcessHeap,
- 0,
+ 0,
FullInfo);
}
- if (ErrorCode != ERROR_SUCCESS)
- {
- SetLastError(ErrorCode);
- }
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
/************************************************************************
* RegQueryMultipleValuesA
*
- * @unimplemented
+ * @implemented
*/
LONG STDCALL
RegQueryMultipleValuesA (HKEY hKey,
LPSTR lpValueBuf,
LPDWORD ldwTotsize)
{
- UNIMPLEMENTED;
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return ERROR_CALL_NOT_IMPLEMENTED;
+ ULONG i;
+ DWORD maxBytes = *ldwTotsize;
+ LPSTR bufptr = (LPSTR)lpValueBuf;
+ LONG ErrorCode;
+
+ if (maxBytes >= (1024*1024))
+ return ERROR_TRANSFER_TOO_LONG;
+
+ *ldwTotsize = 0;
+
+ TRACE("RegQueryMultipleValuesA(%p,%p,%ld,%p,%p=%ld)\n",
+ hKey, val_list, num_vals, lpValueBuf, ldwTotsize, *ldwTotsize);
+
+ for (i = 0; i < num_vals; i++)
+ {
+ val_list[i].ve_valuelen = 0;
+ ErrorCode = RegQueryValueExA (hKey,
+ val_list[i].ve_valuename,
+ NULL,
+ NULL,
+ NULL,
+ &val_list[i].ve_valuelen);
+ if (ErrorCode != ERROR_SUCCESS)
+ {
+ return ErrorCode;
+ }
+
+ if (lpValueBuf != NULL && *ldwTotsize + val_list[i].ve_valuelen <= maxBytes)
+ {
+ ErrorCode = RegQueryValueExA (hKey,
+ val_list[i].ve_valuename,
+ NULL,
+ &val_list[i].ve_type,
+ (LPBYTE)bufptr,
+ &val_list[i].ve_valuelen);
+ if (ErrorCode != ERROR_SUCCESS)
+ {
+ return ErrorCode;
+ }
+
+ val_list[i].ve_valueptr = (DWORD_PTR)bufptr;
+
+ bufptr += val_list[i].ve_valuelen;
+ }
+
+ *ldwTotsize += val_list[i].ve_valuelen;
+ }
+
+ return (lpValueBuf != NULL && *ldwTotsize <= maxBytes) ? ERROR_SUCCESS : ERROR_MORE_DATA;
}
{
ULONG i;
DWORD maxBytes = *ldwTotsize;
- HRESULT status;
LPSTR bufptr = (LPSTR)lpValueBuf;
+ LONG ErrorCode;
- if ( maxBytes >= (1024*1024) )
+ if (maxBytes >= (1024*1024))
return ERROR_TRANSFER_TOO_LONG;
*ldwTotsize = 0;
- //TRACE("(%p,%p,%ld,%p,%p=%ld)\n", hKey, val_list, num_vals, lpValueBuf, ldwTotsize, *ldwTotsize);
+ TRACE ("RegQueryMultipleValuesW(%p,%p,%ld,%p,%p=%ld)\n",
+ hKey, val_list, num_vals, lpValueBuf, ldwTotsize, *ldwTotsize);
- for(i=0; i < num_vals; ++i)
+ for (i = 0; i < num_vals; i++)
{
- val_list[i].ve_valuelen=0;
- status = RegQueryValueExW(hKey, val_list[i].ve_valuename, NULL, NULL, NULL, &val_list[i].ve_valuelen);
- if(status != ERROR_SUCCESS)
+ val_list[i].ve_valuelen = 0;
+ ErrorCode = RegQueryValueExW (hKey,
+ val_list[i].ve_valuename,
+ NULL,
+ NULL,
+ NULL,
+ &val_list[i].ve_valuelen);
+ if (ErrorCode != ERROR_SUCCESS)
{
- return status;
+ return ErrorCode;
}
- if(lpValueBuf != NULL && *ldwTotsize + val_list[i].ve_valuelen <= maxBytes)
+ if (lpValueBuf != NULL && *ldwTotsize + val_list[i].ve_valuelen <= maxBytes)
{
- status = RegQueryValueExW(hKey, val_list[i].ve_valuename, NULL, &val_list[i].ve_type,
- bufptr, &val_list[i].ve_valuelen);
- if(status != ERROR_SUCCESS)
+ ErrorCode = RegQueryValueExW (hKey,
+ val_list[i].ve_valuename,
+ NULL,
+ &val_list[i].ve_type,
+ (LPBYTE)bufptr,
+ &val_list[i].ve_valuelen);
+ if (ErrorCode != ERROR_SUCCESS)
{
- return status;
+ return ErrorCode;
}
val_list[i].ve_valueptr = (DWORD_PTR)bufptr;
*ldwTotsize += val_list[i].ve_valuelen;
}
- return lpValueBuf != NULL && *ldwTotsize <= maxBytes ? ERROR_SUCCESS : ERROR_MORE_DATA;
+
+ return (lpValueBuf != NULL && *ldwTotsize <= maxBytes) ? ERROR_SUCCESS : ERROR_MORE_DATA;
}
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
UNICODE_STRING ValueName;
NTSTATUS Status;
- LONG ErrorCode = ERROR_SUCCESS;
ULONG BufferSize;
ULONG ResultSize;
- HKEY KeyHandle;
+ HANDLE KeyHandle;
+ LONG ErrorCode = ERROR_SUCCESS;
+ ULONG MaxCopy = lpcbData != NULL && lpData != NULL ? *lpcbData : 0;
- DPRINT("hKey 0x%X lpValueName %S lpData 0x%X lpcbData %d\n",
+ TRACE("hKey 0x%X lpValueName %S lpData 0x%X lpcbData %d\n",
hKey, lpValueName, lpData, lpcbData ? *lpcbData : 0);
Status = MapDefaultKey (&KeyHandle,
hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if (lpData != NULL && lpcbData == NULL)
{
- SetLastError (ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
}
RtlInitUnicodeString (&ValueName,
lpValueName);
- BufferSize = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + *lpcbData;
+ BufferSize = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]) + MaxCopy;
ValueInfo = RtlAllocateHeap (ProcessHeap,
0,
BufferSize);
if (ValueInfo == NULL)
{
- SetLastError(ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
+ ErrorCode = ERROR_OUTOFMEMORY;
+ goto Cleanup;
}
- Status = NtQueryValueKey (hKey,
+ Status = NtQueryValueKey (KeyHandle,
&ValueName,
KeyValuePartialInformation,
ValueInfo,
BufferSize,
&ResultSize);
- DPRINT("Status 0x%X\n", Status);
- if (Status == STATUS_BUFFER_TOO_SMALL)
+ TRACE("Status 0x%X\n", Status);
+ if (Status == STATUS_BUFFER_OVERFLOW)
{
/* Return ERROR_SUCCESS and the buffer space needed for a successful call */
- ErrorCode = ERROR_SUCCESS;
+ MaxCopy = 0;
+ ErrorCode = lpData ? ERROR_MORE_DATA : ERROR_SUCCESS;
}
else if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- }
- else
- {
- if (lpType != NULL)
+ MaxCopy = 0;
+ if (lpcbData != NULL)
{
- *lpType = ValueInfo->Type;
+ ResultSize = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]) + *lpcbData;
}
+ }
+
+ if (lpType != NULL)
+ {
+ *lpType = ValueInfo->Type;
+ }
+
+ if (NT_SUCCESS(Status) && lpData != NULL)
+ {
RtlMoveMemory (lpData,
ValueInfo->Data,
- ValueInfo->DataLength);
- if ((ValueInfo->Type == REG_SZ) ||
- (ValueInfo->Type == REG_MULTI_SZ) ||
- (ValueInfo->Type == REG_EXPAND_SZ))
+ min(ValueInfo->DataLength, MaxCopy));
+ }
+
+ if ((ValueInfo->Type == REG_SZ) ||
+ (ValueInfo->Type == REG_MULTI_SZ) ||
+ (ValueInfo->Type == REG_EXPAND_SZ))
+ {
+ if (lpData != NULL && MaxCopy > ValueInfo->DataLength)
{
((PWSTR)lpData)[ValueInfo->DataLength / sizeof(WCHAR)] = 0;
}
- }
- DPRINT("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength);
- if (NULL != lpcbData)
+ if (lpcbData != NULL)
+ {
+ *lpcbData = (ResultSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]));
+ TRACE("(string) Returning Size: %lu\n", *lpcbData);
+ }
+ }
+ else
{
- *lpcbData = (DWORD)ValueInfo->DataLength;
+ if (lpcbData != NULL)
+ {
+ *lpcbData = ResultSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]);
+ TRACE("(other) Returning Size: %lu\n", *lpcbData);
+ }
}
+
+ TRACE("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength);
+
RtlFreeHeap (ProcessHeap,
0,
ValueInfo);
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
*
* @implemented
*/
-LONG
-STDCALL
-RegQueryValueExA(
- HKEY hKey,
- LPCSTR lpValueName,
- LPDWORD lpReserved,
- LPDWORD lpType,
- LPBYTE lpData,
- LPDWORD lpcbData)
+LONG STDCALL
+RegQueryValueExA (HKEY hKey,
+ LPCSTR lpValueName,
+ LPDWORD lpReserved,
+ LPDWORD lpType,
+ LPBYTE lpData,
+ LPDWORD lpcbData)
{
UNICODE_STRING ValueName;
UNICODE_STRING ValueData;
ANSI_STRING AnsiString;
LONG ErrorCode;
+ DWORD Length;
DWORD Type;
- if ((lpData) && (!lpcbData))
+ TRACE("hKey 0x%X lpValueName %s lpData 0x%X lpcbData %d\n",
+ hKey, lpValueName, lpData, lpcbData ? *lpcbData : 0);
+
+ if (lpData != NULL && lpcbData == NULL)
{
- SetLastError(ERROR_INVALID_PARAMETER);
return ERROR_INVALID_PARAMETER;
}
if (lpData)
{
- ValueData.Length = ValueData.MaximumLength = *lpcbData * sizeof(WCHAR);
- ValueData.Buffer = RtlAllocateHeap(
- ProcessHeap,
- 0,
- ValueData.Length);
+ ValueData.Length = 0;
+ ValueData.MaximumLength = (*lpcbData + 1) * sizeof(WCHAR);
+ ValueData.Buffer = RtlAllocateHeap (ProcessHeap,
+ 0,
+ ValueData.MaximumLength);
if (!ValueData.Buffer)
- {
- SetLastError(ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
- }
+ {
+ return ERROR_OUTOFMEMORY;
+ }
}
else
{
ValueData.Buffer = NULL;
+ ValueData.Length = 0;
+ ValueData.MaximumLength = 0;
}
- RtlCreateUnicodeStringFromAsciiz(&ValueName, (LPSTR)lpValueName);
+ RtlCreateUnicodeStringFromAsciiz (&ValueName,
+ (LPSTR)lpValueName);
- ErrorCode = RegQueryValueExW(
- hKey,
- ValueName.Buffer,
- lpReserved,
- &Type,
- (LPBYTE)ValueData.Buffer,
- (LPDWORD)&ValueData.Length);
- if (lpType) *lpType = Type;
+ Length = (lpcbData == NULL) ? 0 : *lpcbData * sizeof(WCHAR);
+ ErrorCode = RegQueryValueExW (hKey,
+ ValueName.Buffer,
+ lpReserved,
+ &Type,
+ (lpData == NULL) ? NULL : (LPBYTE)ValueData.Buffer,
+ &Length);
+ TRACE("ErrorCode %lu\n", ErrorCode);
+ RtlFreeUnicodeString(&ValueName);
- if ((ErrorCode == ERROR_SUCCESS) && (ValueData.Buffer != NULL))
+ if (ErrorCode == ERROR_SUCCESS ||
+ ErrorCode == ERROR_MORE_DATA)
{
+ if (lpType != NULL)
+ {
+ *lpType = Type;
+ }
+
if ((Type == REG_SZ) || (Type == REG_MULTI_SZ) || (Type == REG_EXPAND_SZ))
- {
- RtlInitAnsiString(&AnsiString, NULL);
- AnsiString.Buffer = lpData;
- AnsiString.MaximumLength = *lpcbData;
- RtlUnicodeStringToAnsiString(&AnsiString, &ValueData, FALSE);
- *lpcbData = ValueData.Length / sizeof(WCHAR);
- } else {
- RtlMoveMemory(lpData, ValueData.Buffer, *lpcbData);
- *lpcbData = ValueData.Length;
- }
- }
+ {
+ if (ErrorCode == ERROR_SUCCESS && ValueData.Buffer != NULL)
+ {
+ RtlInitAnsiString(&AnsiString, NULL);
+ AnsiString.Buffer = (LPSTR)lpData;
+ AnsiString.MaximumLength = *lpcbData;
+ ValueData.Length = Length;
+ ValueData.MaximumLength = ValueData.Length + sizeof(WCHAR);
+ RtlUnicodeStringToAnsiString(&AnsiString, &ValueData, FALSE);
+ }
+ Length = Length / sizeof(WCHAR);
+ }
+ else if (ErrorCode == ERROR_SUCCESS && ValueData.Buffer != NULL)
+ {
+ if (*lpcbData < Length)
+ {
+ ErrorCode = ERROR_MORE_DATA;
+ }
+ else
+ {
+ RtlMoveMemory(lpData, ValueData.Buffer, Length);
+ }
+ }
+
+ if (lpcbData != NULL)
+ {
+ *lpcbData = Length;
+ }
+ }
- if (ValueData.Buffer)
+ if (ValueData.Buffer != NULL)
{
RtlFreeHeap(ProcessHeap, 0, ValueData.Buffer);
}
LONG ValueSize;
LONG ErrorCode;
+ TRACE("hKey 0x%X lpSubKey %s lpValue %p lpcbValue %d\n",
+ hKey, lpSubKey, lpValue, lpcbValue ? *lpcbValue : 0);
+
if (lpValue != NULL &&
lpcbValue == NULL)
{
- SetLastError(ERROR_INVALID_PARAMETER);
return ERROR_INVALID_PARAMETER;
}
ValueSize);
if (Value.Buffer == NULL)
{
- SetLastError(ERROR_OUTOFMEMORY);
return ERROR_OUTOFMEMORY;
}
}
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
+ HANDLE KeyHandle;
HANDLE RealKey;
LONG ErrorCode;
BOOL CloseRealKey;
NTSTATUS Status;
+ TRACE("hKey 0x%X lpSubKey %S lpValue %p lpcbValue %d\n",
+ hKey, lpSubKey, lpValue, lpcbValue ? *lpcbValue : 0);
+
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if (lpSubKey != NULL &&
KeyHandle,
NULL);
Status = NtOpenKey (&RealKey,
- KEY_ALL_ACCESS,
+ KEY_QUERY_VALUE,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
CloseRealKey = TRUE;
}
NtClose (RealKey);
}
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
LPCSTR lpNewFile,
LPCSTR lpOldFile)
{
- UNICODE_STRING lpSubKeyW;
- UNICODE_STRING lpNewFileW;
- UNICODE_STRING lpOldFileW;
- LONG ret;
+ UNICODE_STRING SubKey;
+ UNICODE_STRING NewFile;
+ UNICODE_STRING OldFile;
+ LONG ErrorCode;
- RtlCreateUnicodeStringFromAsciiz( &lpSubKeyW, (PCSZ)lpSubKey );
- RtlCreateUnicodeStringFromAsciiz( &lpOldFileW, (PCSZ)lpOldFile );
- RtlCreateUnicodeStringFromAsciiz( &lpNewFileW, (PCSZ)lpNewFile );
- ret = RegReplaceKeyW( hKey, lpSubKeyW.Buffer, lpNewFileW.Buffer, lpOldFileW.Buffer );
- RtlFreeUnicodeString( &lpOldFileW );
- RtlFreeUnicodeString( &lpNewFileW );
- RtlFreeUnicodeString( &lpSubKeyW );
- return ret;
+ RtlCreateUnicodeStringFromAsciiz (&SubKey,
+ (PCSZ)lpSubKey);
+ RtlCreateUnicodeStringFromAsciiz (&OldFile,
+ (PCSZ)lpOldFile);
+ RtlCreateUnicodeStringFromAsciiz (&NewFile,
+ (PCSZ)lpNewFile);
+
+ ErrorCode = RegReplaceKeyW (hKey,
+ SubKey.Buffer,
+ NewFile.Buffer,
+ OldFile.Buffer);
+
+ RtlFreeUnicodeString (&OldFile);
+ RtlFreeUnicodeString (&NewFile);
+ RtlFreeUnicodeString (&SubKey);
+
+ return ErrorCode;
}
LPCWSTR lpNewFile,
LPCWSTR lpOldFile)
{
- UNIMPLEMENTED;
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return ERROR_CALL_NOT_IMPLEMENTED;
+ OBJECT_ATTRIBUTES KeyObjectAttributes;
+ OBJECT_ATTRIBUTES NewObjectAttributes;
+ OBJECT_ATTRIBUTES OldObjectAttributes;
+ UNICODE_STRING SubKeyName;
+ UNICODE_STRING NewFileName;
+ UNICODE_STRING OldFileName;
+ BOOLEAN CloseRealKey;
+ HANDLE RealKeyHandle;
+ HANDLE KeyHandle;
+ NTSTATUS Status;
+ LONG ErrorCode = ERROR_SUCCESS;
+
+ if (hKey == HKEY_PERFORMANCE_DATA)
+ {
+ return ERROR_INVALID_HANDLE;
+ }
+
+ Status = MapDefaultKey (&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ /* Open the real key */
+ if (lpSubKey != NULL && *lpSubKey != (WCHAR)0)
+ {
+ RtlInitUnicodeString (&SubKeyName,
+ (PWSTR)lpSubKey);
+ InitializeObjectAttributes (&KeyObjectAttributes,
+ &SubKeyName,
+ OBJ_CASE_INSENSITIVE,
+ KeyHandle,
+ NULL);
+ Status = NtOpenKey (&RealKeyHandle,
+ MAXIMUM_ALLOWED,
+ &KeyObjectAttributes);
+ if (!NT_SUCCESS(Status))
+ {
+ ErrorCode = RtlNtStatusToDosError (Status);
+ goto Cleanup;
+ }
+ CloseRealKey = TRUE;
+ }
+ else
+ {
+ RealKeyHandle = KeyHandle;
+ CloseRealKey = FALSE;
+ }
+
+ /* Convert new file name */
+ if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewFile,
+ &NewFileName,
+ NULL,
+ NULL))
+ {
+ if (CloseRealKey)
+ {
+ NtClose (RealKeyHandle);
+ }
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
+ }
+
+ InitializeObjectAttributes (&NewObjectAttributes,
+ &NewFileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ /* Convert old file name */
+ if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpOldFile,
+ &OldFileName,
+ NULL,
+ NULL))
+ {
+ RtlFreeUnicodeString (&NewFileName);
+ if (CloseRealKey)
+ {
+ NtClose (RealKeyHandle);
+ }
+ ErrorCode = ERROR_INVALID_PARAMETER;
+ goto Cleanup;
+ }
+
+ InitializeObjectAttributes (&OldObjectAttributes,
+ &OldFileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtReplaceKey (&NewObjectAttributes,
+ RealKeyHandle,
+ &OldObjectAttributes);
+
+ RtlFreeUnicodeString (&OldFileName);
+ RtlFreeUnicodeString (&NewFileName);
+
+ if (CloseRealKey)
+ {
+ NtClose (RealKeyHandle);
+ }
+
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ return ErrorCode;
}
LPCSTR lpFile,
DWORD dwFlags)
{
- UNICODE_STRING lpFileW;
- LONG ret;
+ UNICODE_STRING FileName;
+ LONG ErrorCode;
- RtlCreateUnicodeStringFromAsciiz( &lpFileW, (PCSZ)lpFile );
- ret = RegRestoreKeyW( hKey, lpFileW.Buffer, dwFlags );
- RtlFreeUnicodeString( &lpFileW );
- return ret;
+ RtlCreateUnicodeStringFromAsciiz (&FileName,
+ (PCSZ)lpFile);
+
+ ErrorCode = RegRestoreKeyW (hKey,
+ FileName.Buffer,
+ dwFlags);
+
+ RtlFreeUnicodeString (&FileName);
+
+ return ErrorCode;
}
/************************************************************************
* RegRestoreKeyW
*
- * @unimplemented
+ * @implemented
*/
LONG STDCALL
RegRestoreKeyW (HKEY hKey,
LPCWSTR lpFile,
DWORD dwFlags)
{
- UNIMPLEMENTED;
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return ERROR_CALL_NOT_IMPLEMENTED;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING FileName;
+ HANDLE FileHandle;
+ HANDLE KeyHandle;
+ NTSTATUS Status;
+
+ if (hKey == HKEY_PERFORMANCE_DATA)
+ {
+ return ERROR_INVALID_HANDLE;
+ }
+
+ Status = MapDefaultKey (&KeyHandle,
+ hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFile,
+ &FileName,
+ NULL,
+ NULL))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ goto Cleanup;
+ }
+
+ InitializeObjectAttributes (&ObjectAttributes,
+ &FileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile (&FileHandle,
+ FILE_GENERIC_READ,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ RtlFreeUnicodeString (&FileName);
+ if (!NT_SUCCESS(Status))
+ {
+ goto Cleanup;
+ }
+
+ Status = NtRestoreKey (KeyHandle,
+ FileHandle,
+ (ULONG)dwFlags);
+ NtClose (FileHandle);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
+ if (!NT_SUCCESS(Status))
+ {
+ return RtlNtStatusToDosError (Status);
+ }
+
+ return ERROR_SUCCESS;
}
* @implemented
*/
LONG STDCALL
-RegSaveKeyA(HKEY hKey,
- LPCSTR lpFile,
- LPSECURITY_ATTRIBUTES lpSecurityAttributes)
+RegSaveKeyA (HKEY hKey,
+ LPCSTR lpFile,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
UNICODE_STRING FileName;
LONG ErrorCode;
{
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING NtName;
+ UNICODE_STRING FileName;
IO_STATUS_BLOCK IoStatusBlock;
HANDLE FileHandle;
- HKEY KeyHandle;
+ HANDLE KeyHandle;
NTSTATUS Status;
- LONG ErrorCode;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
- if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFile,
- &NtName,
+ if (!RtlDosPathNameToNtPathName_U ((PWSTR)lpFile,
+ &FileName,
NULL,
NULL))
{
- SetLastError (ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
+ Status = STATUS_INVALID_PARAMETER;
+ goto Cleanup;
}
if (lpSecurityAttributes != NULL)
}
InitializeObjectAttributes (&ObjectAttributes,
- &NtName,
+ &FileName,
OBJ_CASE_INSENSITIVE,
NULL,
SecurityDescriptor);
FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
- RtlFreeUnicodeString (&NtName);
+ RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
Status = NtSaveKey (KeyHandle,
FileHandle);
NtClose (FileHandle);
+
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
SECURITY_INFORMATION SecurityInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor)
{
- HKEY KeyHandle;
+ HANDLE KeyHandle;
NTSTATUS Status;
- LONG ErrorCode;
if (hKey == HKEY_PERFORMANCE_DATA)
- return ERROR_INVALID_HANDLE;
+ {
+ return ERROR_INVALID_HANDLE;
+ }
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
Status = NtSetSecurityObject (KeyHandle,
SecurityInformation,
pSecurityDescriptor);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
LPBYTE pData;
DWORD DataSize;
- if (lpData == NULL)
- {
- SetLastError (ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
- }
-
if (lpValueName != NULL &&
strlen(lpValueName) != 0)
{
RtlCreateUnicodeStringFromAsciiz (&ValueName,
- (LPSTR)lpValueName);
+ (PSTR)lpValueName);
pValueName = (LPWSTR)ValueName.Buffer;
}
else
pValueName = NULL;
}
- if ((dwType == REG_SZ) ||
- (dwType == REG_MULTI_SZ) ||
- (dwType == REG_EXPAND_SZ))
+ if (((dwType == REG_SZ) ||
+ (dwType == REG_MULTI_SZ) ||
+ (dwType == REG_EXPAND_SZ)) &&
+ (cbData != 0))
{
+ /* NT adds one if the caller forgot the NULL-termination character */
+ if (lpData[cbData - 1] != '\0')
+ {
+ cbData++;
+ }
+
RtlInitAnsiString (&AnsiString,
NULL);
- AnsiString.Buffer = (LPSTR)lpData;
- AnsiString.Length = cbData;
+ AnsiString.Buffer = (PSTR)lpData;
+ AnsiString.Length = cbData - 1;
AnsiString.MaximumLength = cbData;
RtlAnsiStringToUnicodeString (&Data,
&AnsiString,
{
UNICODE_STRING ValueName;
PUNICODE_STRING pValueName;
- HKEY KeyHandle;
+ HANDLE KeyHandle;
NTSTATUS Status;
- LONG ErrorCode;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if (lpValueName != NULL)
{
RtlInitUnicodeString (&ValueName,
lpValueName);
- pValueName = &ValueName;
}
else
{
- pValueName = NULL;
+ RtlInitUnicodeString (&ValueName, L"");
+ }
+ pValueName = &ValueName;
+
+ if (((dwType == REG_SZ) ||
+ (dwType == REG_MULTI_SZ) ||
+ (dwType == REG_EXPAND_SZ)) &&
+ (cbData != 0) && (*(((PWCHAR)lpData) + (cbData / sizeof(WCHAR)) - 1) != L'\0'))
+ {
+ /* NT adds one if the caller forgot the NULL-termination character */
+ cbData += sizeof(WCHAR);
}
Status = NtSetValueKey (KeyHandle,
dwType,
(PVOID)lpData,
(ULONG)cbData);
+
+ CloseDefaultKey(KeyHandle);
+
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
LPCSTR lpData,
DWORD cbData)
{
- WCHAR SubKeyNameBuffer[MAX_PATH+1];
- UNICODE_STRING SubKeyName;
- UNICODE_STRING Data;
- ANSI_STRING AnsiString;
- LONG DataSize;
- LONG ErrorCode;
+ LONG ret;
+ HKEY hSubKey;
- if (lpData == NULL)
- {
- SetLastError (ERROR_INVALID_PARAMETER);
- return ERROR_INVALID_PARAMETER;
- }
+ if (dwType != REG_SZ)
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
- RtlInitUnicodeString (&SubKeyName, NULL);
- RtlInitUnicodeString (&Data, NULL);
- if (lpSubKey != NULL && (strlen(lpSubKey) != 0))
- {
- RtlInitAnsiString (&AnsiString, (LPSTR)lpSubKey);
- SubKeyName.Buffer = &SubKeyNameBuffer[0];
- SubKeyName.MaximumLength = sizeof(SubKeyNameBuffer);
- RtlAnsiStringToUnicodeString (&SubKeyName, &AnsiString, FALSE);
- }
+ if (lpSubKey != NULL && lpSubKey[0] != '\0')
+ {
+ ret = RegCreateKeyA(hKey,
+ lpSubKey,
+ &hSubKey);
+
+ if (ret != ERROR_SUCCESS)
+ {
+ return ret;
+ }
+ }
+ else
+ hSubKey = hKey;
- DataSize = cbData * sizeof(WCHAR);
- Data.MaximumLength = DataSize;
- Data.Buffer = RtlAllocateHeap (ProcessHeap,
- 0,
- DataSize);
- if (Data.Buffer == NULL)
- {
- SetLastError (ERROR_OUTOFMEMORY);
- return ERROR_OUTOFMEMORY;
- }
+ ret = RegSetValueExA(hSubKey,
+ NULL,
+ 0,
+ REG_SZ,
+ (CONST BYTE*)lpData,
+ strlen(lpData) + 1);
- ErrorCode = RegSetValueW (hKey,
- (LPCWSTR)SubKeyName.Buffer,
- dwType,
- Data.Buffer,
- DataSize);
- RtlFreeHeap (ProcessHeap,
- 0,
- Data.Buffer);
+ if (hSubKey != hKey)
+ {
+ RegCloseKey(hSubKey);
+ }
- return ErrorCode;
+ return ret;
}
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyString;
- HKEY KeyHandle;
+ HANDLE KeyHandle;
HANDLE RealKey;
- LONG ErrorCode;
BOOL CloseRealKey;
NTSTATUS Status;
+ LONG ErrorCode;
Status = MapDefaultKey (&KeyHandle,
- hKey);
+ hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
if ((lpSubKey) && (wcslen(lpSubKey) != 0))
KeyHandle,
NULL);
Status = NtOpenKey (&RealKey,
- KEY_ALL_ACCESS,
+ KEY_SET_VALUE,
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ goto Cleanup;
}
CloseRealKey = TRUE;
}
NtClose (RealKey);
}
+Cleanup:
+ CloseDefaultKey(KeyHandle);
+
return ErrorCode;
}
* @implemented
*/
LONG STDCALL
-RegUnLoadKeyW (HKEY hKey,
+RegUnLoadKeyW (HKEY hKey,
LPCWSTR lpSubKey)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
HANDLE KeyHandle;
- DWORD ErrorCode;
NTSTATUS Status;
if (hKey == HKEY_PERFORMANCE_DATA)
- return ERROR_INVALID_HANDLE;
+ {
+ return ERROR_INVALID_HANDLE;
+ }
Status = MapDefaultKey (&KeyHandle, hKey);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
RtlInitUnicodeString (&KeyName,
NULL);
Status = NtUnloadKey (&ObjectAttributes);
+
+ CloseDefaultKey(KeyHandle);
if (!NT_SUCCESS(Status))
{
- ErrorCode = RtlNtStatusToDosError (Status);
- SetLastError (ErrorCode);
- return ErrorCode;
+ return RtlNtStatusToDosError (Status);
}
return ERROR_SUCCESS;
}
+
+/************************************************************************
+ * RegLoadMUIStringW
+ *
+ * @unimplemented
+ */
+LONG STDCALL
+RegLoadMUIStringW(IN HKEY hKey,
+ IN LPCWSTR pszValue OPTIONAL,
+ OUT LPWSTR pszOutBuf,
+ IN ULONG cbOutBuf,
+ IN ULONG Reserved,
+ IN LPCWSTR pszDirectory OPTIONAL)
+{
+ DPRINT1("RegLoadMUIStringW(0x%p, 0x%p, 0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
+ hKey, pszValue, pszOutBuf, cbOutBuf, Reserved, pszDirectory);
+ return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+
+/************************************************************************
+ * RegLoadMUIStringA
+ *
+ * @unimplemented
+ */
+LONG STDCALL
+RegLoadMUIStringA(IN HKEY hKey,
+ IN LPCSTR pszValue OPTIONAL,
+ OUT LPSTR pszOutBuf,
+ IN ULONG cbOutBuf,
+ IN ULONG Reserved,
+ IN LPCSTR pszDirectory OPTIONAL)
+{
+ DPRINT1("RegLoadMUIStringA(0x%p, 0x%p, 0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
+ hKey, pszValue, pszOutBuf, cbOutBuf, Reserved, pszDirectory);
+ return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+
/* EOF */