mirror of
https://github.com/reactos/reactos.git
synced 2024-08-30 23:28:58 +00:00
Fully implement RtlFormatCurrentUserKeyPath().
svn path=/trunk/; revision=8813
This commit is contained in:
parent
0f69a9471a
commit
baaf29305f
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: registry.c,v 1.27 2003/11/17 02:12:50 hyperion Exp $
|
/* $Id: registry.c,v 1.28 2004/03/20 15:56:00 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -13,15 +13,12 @@
|
||||||
* TODO:
|
* TODO:
|
||||||
* - finish RtlQueryRegistryValues()
|
* - finish RtlQueryRegistryValues()
|
||||||
* - support RTL_QUERY_REGISTRY_DELETE
|
* - support RTL_QUERY_REGISTRY_DELETE
|
||||||
*
|
|
||||||
* - finish RtlFormatCurrentUserKeyPath()
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES ****************************************************************/
|
/* INCLUDES ****************************************************************/
|
||||||
|
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
#include <ntdll/rtl.h>
|
#include <ntdll/rtl.h>
|
||||||
#include <rosrtl/string.h>
|
|
||||||
#include <ntos/minmax.h>
|
#include <ntos/minmax.h>
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
|
@ -36,6 +33,7 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
|
||||||
BOOLEAN Create,
|
BOOLEAN Create,
|
||||||
PHANDLE KeyHandle)
|
PHANDLE KeyHandle)
|
||||||
{
|
{
|
||||||
|
UNICODE_STRING KeyPath;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
WCHAR KeyBuffer[MAX_PATH];
|
WCHAR KeyBuffer[MAX_PATH];
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
@ -94,9 +92,14 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RTL_REGISTRY_USER:
|
case RTL_REGISTRY_USER:
|
||||||
Status = RtlFormatCurrentUserKeyPath(&KeyName);
|
Status = RtlFormatCurrentUserKeyPath (&KeyPath);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return(Status);
|
return(Status);
|
||||||
|
RtlAppendUnicodeStringToString (&KeyName,
|
||||||
|
&KeyPath);
|
||||||
|
RtlFreeUnicodeString (&KeyPath);
|
||||||
|
RtlAppendUnicodeToString (&KeyName,
|
||||||
|
L"\\");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* ReactOS specific */
|
/* ReactOS specific */
|
||||||
|
@ -222,17 +225,88 @@ RtlDeleteRegistryValue(IN ULONG RelativeTo,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @unimplemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
RtlFormatCurrentUserKeyPath(PUNICODE_STRING KeyPath)
|
RtlFormatCurrentUserKeyPath (OUT PUNICODE_STRING KeyPath)
|
||||||
{
|
{
|
||||||
/* FIXME: !!! */
|
HANDLE TokenHandle;
|
||||||
#if 0
|
UCHAR Buffer[256];
|
||||||
RtlCreateUnicodeString(KeyPath,
|
PSID_AND_ATTRIBUTES SidBuffer;
|
||||||
L"\\Registry\\User\\.Default");
|
ULONG Length;
|
||||||
#endif
|
UNICODE_STRING SidString;
|
||||||
return(STATUS_SUCCESS);
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
DPRINT ("RtlFormatCurrentUserKeyPath() called\n");
|
||||||
|
|
||||||
|
Status = NtOpenThreadToken (NtCurrentThread (),
|
||||||
|
TOKEN_READ,
|
||||||
|
TRUE,
|
||||||
|
&TokenHandle);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
if (Status != STATUS_NO_TOKEN)
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtOpenThreadToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = NtOpenProcessToken (NtCurrentProcess (),
|
||||||
|
TOKEN_READ,
|
||||||
|
&TokenHandle);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtOpenProcessToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SidBuffer = (PSID_AND_ATTRIBUTES)Buffer;
|
||||||
|
Status = NtQueryInformationToken (TokenHandle,
|
||||||
|
TokenUser,
|
||||||
|
(PVOID)SidBuffer,
|
||||||
|
256,
|
||||||
|
&Length);
|
||||||
|
NtClose (TokenHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtQueryInformationToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = RtlConvertSidToUnicodeString (&SidString,
|
||||||
|
SidBuffer[0].Sid,
|
||||||
|
TRUE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("RtlConvertSidToUnicodeString() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT ("SidString: '%wZ'\n", &SidString);
|
||||||
|
|
||||||
|
Length = SidString.Length + sizeof(L"\\Registry\\User\\");
|
||||||
|
DPRINT ("Length: %lu\n", Length);
|
||||||
|
|
||||||
|
KeyPath->Length = 0;
|
||||||
|
KeyPath->MaximumLength = Length;
|
||||||
|
KeyPath->Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||||
|
0,
|
||||||
|
KeyPath->MaximumLength);
|
||||||
|
if (KeyPath->Buffer == NULL)
|
||||||
|
{
|
||||||
|
DPRINT1 ("RtlAllocateHeap() failed\n");
|
||||||
|
RtlFreeUnicodeString (&SidString);
|
||||||
|
return STATUS_NO_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlAppendUnicodeToString (KeyPath,
|
||||||
|
L"\\Registry\\User\\");
|
||||||
|
RtlAppendUnicodeStringToString (KeyPath,
|
||||||
|
&SidString);
|
||||||
|
RtlFreeUnicodeString (&SidString);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,8 +318,8 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
|
||||||
OUT PHANDLE KeyHandle)
|
OUT PHANDLE KeyHandle)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
UNICODE_STRING KeyPath;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING KeyPath = ROS_STRING_INITIALIZER(L"\\Registry\\User\\.Default");
|
|
||||||
|
|
||||||
Status = RtlFormatCurrentUserKeyPath(&KeyPath);
|
Status = RtlFormatCurrentUserKeyPath(&KeyPath);
|
||||||
if (NT_SUCCESS(Status))
|
if (NT_SUCCESS(Status))
|
||||||
|
@ -258,11 +332,15 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
|
||||||
Status = NtOpenKey(KeyHandle,
|
Status = NtOpenKey(KeyHandle,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
&ObjectAttributes);
|
&ObjectAttributes);
|
||||||
if (NT_SUCCESS(Status)) {
|
|
||||||
RtlFreeUnicodeString(&KeyPath);
|
RtlFreeUnicodeString(&KeyPath);
|
||||||
return(STATUS_SUCCESS);
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString (&KeyPath,
|
||||||
|
L"\\Registry\\User\\.Default");
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&KeyPath,
|
&KeyPath,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
@ -271,8 +349,8 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
|
||||||
Status = NtOpenKey(KeyHandle,
|
Status = NtOpenKey(KeyHandle,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
&ObjectAttributes);
|
&ObjectAttributes);
|
||||||
RtlFreeUnicodeString(&KeyPath);
|
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
|
||||||
BOOLEAN Create,
|
BOOLEAN Create,
|
||||||
PHANDLE KeyHandle)
|
PHANDLE KeyHandle)
|
||||||
{
|
{
|
||||||
|
UNICODE_STRING KeyPath;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
WCHAR KeyBuffer[MAX_PATH];
|
WCHAR KeyBuffer[MAX_PATH];
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
@ -80,10 +81,14 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RTL_REGISTRY_USER:
|
case RTL_REGISTRY_USER:
|
||||||
Status = RtlFormatCurrentUserKeyPath(&KeyName);
|
Status = RtlFormatCurrentUserKeyPath (&KeyPath);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return(Status);
|
return(Status);
|
||||||
RtlAppendUnicodeToString(&KeyName, L"\\");
|
RtlAppendUnicodeStringToString (&KeyName,
|
||||||
|
&KeyPath);
|
||||||
|
RtlFreeUnicodeString (&KeyPath);
|
||||||
|
RtlAppendUnicodeToString (&KeyName,
|
||||||
|
L"\\");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* ReactOS specific */
|
/* ReactOS specific */
|
||||||
|
@ -207,16 +212,87 @@ RtlDeleteRegistryValue(IN ULONG RelativeTo,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @unimplemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
RtlFormatCurrentUserKeyPath(IN OUT PUNICODE_STRING KeyPath)
|
RtlFormatCurrentUserKeyPath (OUT PUNICODE_STRING KeyPath)
|
||||||
{
|
{
|
||||||
/* FIXME: !!! */
|
HANDLE TokenHandle;
|
||||||
KeyPath->Length = 0;
|
UCHAR Buffer[256];
|
||||||
RtlAppendUnicodeToString(KeyPath, L"\\Registry\\User\\.Default");
|
PSID_AND_ATTRIBUTES SidBuffer;
|
||||||
|
ULONG Length;
|
||||||
|
UNICODE_STRING SidString;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
DPRINT ("RtlFormatCurrentUserKeyPath() called\n");
|
||||||
|
|
||||||
|
Status = NtOpenThreadToken (NtCurrentThread (),
|
||||||
|
TOKEN_READ,
|
||||||
|
TRUE,
|
||||||
|
&TokenHandle);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
if (Status != STATUS_NO_TOKEN)
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtOpenThreadToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = NtOpenProcessToken (NtCurrentProcess (),
|
||||||
|
TOKEN_READ,
|
||||||
|
&TokenHandle);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtOpenProcessToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SidBuffer = (PSID_AND_ATTRIBUTES)Buffer;
|
||||||
|
Status = NtQueryInformationToken (TokenHandle,
|
||||||
|
TokenUser,
|
||||||
|
(PVOID)SidBuffer,
|
||||||
|
256,
|
||||||
|
&Length);
|
||||||
|
NtClose (TokenHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("NtQueryInformationToken() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = RtlConvertSidToUnicodeString (&SidString,
|
||||||
|
SidBuffer[0].Sid,
|
||||||
|
TRUE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1 ("RtlConvertSidToUnicodeString() failed (Status %lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT ("SidString: '%wZ'\n", &SidString);
|
||||||
|
|
||||||
|
Length = SidString.Length + sizeof(L"\\Registry\\User\\");
|
||||||
|
DPRINT ("Length: %lu\n", Length);
|
||||||
|
|
||||||
|
KeyPath->Length = 0;
|
||||||
|
KeyPath->MaximumLength = Length;
|
||||||
|
KeyPath->Buffer = ExAllocatePool (NonPagedPool,
|
||||||
|
KeyPath->MaximumLength);
|
||||||
|
if (KeyPath->Buffer == NULL)
|
||||||
|
{
|
||||||
|
DPRINT1 ("RtlAllocateHeap() failed\n");
|
||||||
|
RtlFreeUnicodeString (&SidString);
|
||||||
|
return STATUS_NO_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlAppendUnicodeToString (KeyPath,
|
||||||
|
L"\\Registry\\User\\");
|
||||||
|
RtlAppendUnicodeStringToString (KeyPath,
|
||||||
|
&SidString);
|
||||||
|
RtlFreeUnicodeString (&SidString);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,7 +301,7 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
|
||||||
OUT PHANDLE KeyHandle)
|
OUT PHANDLE KeyHandle)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
UNICODE_STRING KeyPath = ROS_STRING_INITIALIZER(L"\\Registry\\User\\.Default");
|
UNICODE_STRING KeyPath;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
Status = RtlFormatCurrentUserKeyPath(&KeyPath);
|
Status = RtlFormatCurrentUserKeyPath(&KeyPath);
|
||||||
|
@ -244,6 +320,8 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString (&KeyPath,
|
||||||
|
L"\\Registry\\User\\.Default");
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&KeyPath,
|
&KeyPath,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
|
Loading…
Reference in a new issue