reactos/lib/ntdll/rtl
diff -u -r1.27 -r1.28
--- registry.c 17 Nov 2003 02:12:50 -0000 1.27
+++ registry.c 20 Mar 2004 15:56:00 -0000 1.28
@@ -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
* PROJECT: ReactOS kernel
@@ -13,15 +13,12 @@
* TODO:
* - finish RtlQueryRegistryValues()
* - support RTL_QUERY_REGISTRY_DELETE
- *
- * - finish RtlFormatCurrentUserKeyPath()
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
-#include <rosrtl/string.h>
#include <ntos/minmax.h>
#define NDEBUG
@@ -36,6 +33,7 @@
BOOLEAN Create,
PHANDLE KeyHandle)
{
+ UNICODE_STRING KeyPath;
UNICODE_STRING KeyName;
WCHAR KeyBuffer[MAX_PATH];
OBJECT_ATTRIBUTES ObjectAttributes;
@@ -94,9 +92,14 @@
break;
case RTL_REGISTRY_USER:
- Status = RtlFormatCurrentUserKeyPath(&KeyName);
+ Status = RtlFormatCurrentUserKeyPath (&KeyPath);
if (!NT_SUCCESS(Status))
return(Status);
+ RtlAppendUnicodeStringToString (&KeyName,
+ &KeyPath);
+ RtlFreeUnicodeString (&KeyPath);
+ RtlAppendUnicodeToString (&KeyName,
+ L"\\");
break;
/* ReactOS specific */
@@ -222,17 +225,88 @@
/*
- * @unimplemented
+ * @implemented
*/
NTSTATUS STDCALL
-RtlFormatCurrentUserKeyPath(PUNICODE_STRING KeyPath)
+RtlFormatCurrentUserKeyPath (OUT PUNICODE_STRING KeyPath)
{
- /* FIXME: !!! */
-#if 0
- RtlCreateUnicodeString(KeyPath,
- L"\\Registry\\User\\.Default");
-#endif
- return(STATUS_SUCCESS);
+ HANDLE TokenHandle;
+ UCHAR Buffer[256];
+ PSID_AND_ATTRIBUTES SidBuffer;
+ ULONG Length;
+ UNICODE_STRING SidString;
+ 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 @@
OUT PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING KeyPath;
NTSTATUS Status;
- UNICODE_STRING KeyPath = ROS_STRING_INITIALIZER(L"\\Registry\\User\\.Default");
Status = RtlFormatCurrentUserKeyPath(&KeyPath);
if (NT_SUCCESS(Status))
@@ -258,11 +332,15 @@
Status = NtOpenKey(KeyHandle,
DesiredAccess,
&ObjectAttributes);
- if (NT_SUCCESS(Status)) {
- RtlFreeUnicodeString(&KeyPath);
- return(STATUS_SUCCESS);
- }
+ RtlFreeUnicodeString(&KeyPath);
+ if (NT_SUCCESS(Status))
+ {
+ return STATUS_SUCCESS;
+ }
}
+
+ RtlInitUnicodeString (&KeyPath,
+ L"\\Registry\\User\\.Default");
InitializeObjectAttributes(&ObjectAttributes,
&KeyPath,
OBJ_CASE_INSENSITIVE,
@@ -271,8 +349,8 @@
Status = NtOpenKey(KeyHandle,
DesiredAccess,
&ObjectAttributes);
- RtlFreeUnicodeString(&KeyPath);
- return(Status);
+
+ return Status;
}
@@ -656,7 +734,7 @@
FullValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferSize);
- if (FullValueInfo == NULL)
+ if (FullValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
@@ -670,7 +748,7 @@
Status = STATUS_NO_MEMORY;
break;
}
- Index = 0;
+ Index = 0;
while (TRUE)
{
Status = NtEnumerateValueKey(CurrentKeyHandle,
@@ -701,9 +779,9 @@
0,
ValueName);
ValueNameSize = FullValueInfo->NameLength + sizeof(WCHAR);
- ValueName = RtlAllocateHeap(RtlGetProcessHeap(),
- 0,
- ValueNameSize);
+ ValueName = RtlAllocateHeap(RtlGetProcessHeap(),
+ 0,
+ ValueNameSize);
if (ValueName == NULL)
{
Status = STATUS_NO_MEMORY;
@@ -712,7 +790,7 @@
}
memcpy(ValueName,
- FullValueInfo->Name,
+ FullValueInfo->Name,
FullValueInfo->NameLength);
ValueName[FullValueInfo->NameLength / sizeof(WCHAR)] = 0;