From 486a9d1b951141a2d688bc392e775e273000e5b8 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 11 Jan 2014 23:13:48 +0000 Subject: [PATCH] [NTOSKRNL] Implement CmpLinkKeyToHive and create missing HKLM\Security\SAM -> HKLM\SAM\SAM and HKU\S-1-5-18 -> HKU\.Default links. svn path=/trunk/; revision=61591 --- reactos/ntoskrnl/config/cmsysini.c | 73 +++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index aa69546a6cd..3d97640dc21 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -36,6 +36,71 @@ extern BOOLEAN CmFirstTime; /* FUNCTIONS ******************************************************************/ +BOOLEAN +NTAPI +CmpLinkKeyToHive( + _In_z_ PWSTR LinkKeyName, + _In_z_ PWSTR TargetKeyName) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING LinkKeyName_U; + HANDLE TargetKeyHandle; + ULONG Disposition; + NTSTATUS Status; + PAGED_CODE(); + + /* Initialize the object attributes */ + RtlInitUnicodeString(&LinkKeyName_U, LinkKeyName); + InitializeObjectAttributes(&ObjectAttributes, + &LinkKeyName_U, + OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, + NULL, + NULL); + + /* Create the link key */ + Status = ZwCreateKey(&TargetKeyHandle, + KEY_CREATE_LINK, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, + &Disposition); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CM: CmpLinkKeyToHive: couldn't create %S Status = 0x%lx\n", + LinkKeyName, Status); + return FALSE; + } + + /* Check if the new key was actually created */ + if (Disposition != REG_CREATED_NEW_KEY) + { + DPRINT1("CM: CmpLinkKeyToHive: %S already exists!\n", LinkKeyName); + ZwClose(TargetKeyHandle); + return FALSE; + } + + /* Set the target key name as link target */ + Status = ZwSetValueKey(TargetKeyHandle, + &CmSymbolicLinkValueName, + 0, + REG_LINK, + TargetKeyName, + wcslen(TargetKeyName) * sizeof(WCHAR)); + + /* Close the link key handle */ + ObCloseHandle(TargetKeyHandle, KernelMode); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("CM: CmpLinkKeyToHive: couldn't create symbolic link for %S\n", + TargetKeyName); + return FALSE; + } + + return TRUE; +} + VOID NTAPI CmpDeleteKeyObject(PVOID DeletedObject) @@ -1389,9 +1454,13 @@ CmpInitializeHiveList(IN USHORT Flag) /* Get rid of the SD */ ExFreePoolWithTag(SecurityDescriptor, TAG_CM); - /* FIXME: Link SECURITY to SAM */ + /* Link SECURITY to SAM */ + CmpLinkKeyToHive(L"\\Registry\\Machine\\Security\\SAM", + L"\\Registry\\Machine\\SAM\\SAM"); - /* FIXME: Link S-1-5-18 to .Default */ + /* Link S-1-5-18 to .Default */ + CmpLinkKeyToHive(L"\\Registry\\User\\S-1-5-18", + L"\\Registry\\User\\.Default"); } BOOLEAN