From: Stefan Leichter Subject: [Patch 3/6, v2] ntdll: implement RtlCreateRegistryKey Message-Id: <7f0b27c4-945e-2d46-1a39-311e7ca6e562@gmx.de> Date: Mon, 12 Mar 2018 00:15:27 +0100 Signed-off-by: Stefan Leichter --- dlls/ntdll/ntdll.spec | 2 +- dlls/ntdll/reg.c | 71 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index b63e335e25..4ad7a6065d 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -509,7 +509,7 @@ @ stdcall RtlCreateProcessParameters(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) @ stub RtlCreatePropertySet @ stdcall RtlCreateQueryDebugBuffer(long long) -@ stub RtlCreateRegistryKey +@ stdcall RtlCreateRegistryKey(long wstr) @ stdcall RtlCreateSecurityDescriptor(ptr long) # @ stub RtlCreateSystemVolumeInformationFolder @ stub RtlCreateTagHeap diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c index 658628f3ac..ba5a4f6ad3 100644 --- a/dlls/ntdll/reg.c +++ b/dlls/ntdll/reg.c @@ -1133,13 +1133,10 @@ static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo, } -static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle) +static NTSTATUS RTL_KeyHandleCreateObject(ULONG RelativeTo, PCWSTR Path, POBJECT_ATTRIBUTES regkey, PUNICODE_STRING KeyString) { - UNICODE_STRING KeyString; - OBJECT_ATTRIBUTES regkey; PCWSTR base; INT len; - NTSTATUS status; static const WCHAR empty[] = {0}; static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e', @@ -1191,17 +1188,33 @@ static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle) } len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR); - KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len); - if (KeyString.Buffer == NULL) + KeyString->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len); + if (KeyString->Buffer == NULL) return STATUS_NO_MEMORY; - strcpyW(KeyString.Buffer, base); - strcatW(KeyString.Buffer, Path); - KeyString.Length = len - sizeof(WCHAR); - KeyString.MaximumLength = len; - InitializeObjectAttributes(®key, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL); + strcpyW(KeyString->Buffer, base); + strcatW(KeyString->Buffer, Path); + KeyString->Length = len - sizeof(WCHAR); + KeyString->MaximumLength = len; + InitializeObjectAttributes(regkey, KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL); + TRACE("Resulting key: %s\n", debugstr_us(regkey->ObjectName)); + return STATUS_SUCCESS; +} + +static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle) +{ + OBJECT_ATTRIBUTES regkey; + UNICODE_STRING KeyString; + NTSTATUS status; + + + status = RTL_KeyHandleCreateObject(RelativeTo, Path, ®key, &KeyString); + if(status != STATUS_SUCCESS) + return status; + status = NtOpenKey(handle, KEY_ALL_ACCESS, ®key); RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer); + return status; } @@ -1415,6 +1428,42 @@ NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path) } /************************************************************************* + * RtlCreateRegistryKey [NTDLL.@] + * + * Add a key to the registry given by absolute or relative path + * + * PARAMS + * RelativeTo [I] Registry path that Path refers to + * Path [I] Path to key + * + * RETURNS + * STATUS_SUCCESS or an appropriate NTSTATUS error code. + */ +NTSTATUS WINAPI RtlCreateRegistryKey(IN ULONG RelativeTo, IN PWSTR Path) +{ + OBJECT_ATTRIBUTES regkey; + UNICODE_STRING KeyString; + HANDLE handle; + NTSTATUS status; + + RelativeTo &= ~RTL_REGISTRY_OPTIONAL; + + if((!RelativeTo) && ((Path == NULL) || (Path[0] == 0))) + return STATUS_OBJECT_PATH_SYNTAX_BAD; + if((RelativeTo <= RTL_REGISTRY_USER) && ((Path == NULL) || (Path[0] == 0))) + return STATUS_SUCCESS; + status = RTL_KeyHandleCreateObject(RelativeTo, Path, ®key, &KeyString); + if(status != STATUS_SUCCESS) + return status; + + status = NtCreateKey(&handle, KEY_ALL_ACCESS, ®key, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); + if(handle) NtClose(handle); + RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer); + + return status; +} + +/************************************************************************* * RtlDeleteRegistryValue [NTDLL.@] * * Query multiple registry values with a single call.