From 8b12884393ce81c2a1b1e4f17d65397528f4f6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 9 Jul 2007 23:22:43 +0000 Subject: [PATCH] [FORMATTING] Fix formatting, to have an indentation of 4 spaces No code change svn path=/trunk/; revision=27553 --- reactos/ntoskrnl/cm/ntfunc.c | 939 +++++++++++++++++---------------- reactos/ntoskrnl/cm/regfile.c | 605 +++++++++++---------- reactos/ntoskrnl/cm/registry.c | 836 +++++++++++++++-------------- reactos/ntoskrnl/cm/regobj.c | 747 +++++++++++++------------- 4 files changed, 1560 insertions(+), 1567 deletions(-) diff --git a/reactos/ntoskrnl/cm/ntfunc.c b/reactos/ntoskrnl/cm/ntfunc.c index bfb2108e47d..2df1d94414e 100644 --- a/reactos/ntoskrnl/cm/ntfunc.c +++ b/reactos/ntoskrnl/cm/ntfunc.c @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * PROJECT: ReactOS Kernel * COPYRIGHT: GPL - See COPYING in the top level directory * FILE: ntoskrnl/cm/ntfunc.c @@ -128,524 +127,526 @@ CmpCreateHandle(PVOID ObjectBody, return STATUS_UNSUCCESSFUL; } -NTSTATUS STDCALL +NTSTATUS +NTAPI NtCreateKey(OUT PHANDLE KeyHandle, - IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes, - IN ULONG TitleIndex, - IN PUNICODE_STRING Class, - IN ULONG CreateOptions, - OUT PULONG Disposition) + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ULONG TitleIndex, + IN PUNICODE_STRING Class, + IN ULONG CreateOptions, + OUT PULONG Disposition) { - UNICODE_STRING RemainingPath = {0}; - BOOLEAN FreeRemainingPath = TRUE; - ULONG LocalDisposition; - PKEY_OBJECT KeyObject; - NTSTATUS Status = STATUS_SUCCESS; - PVOID Object = NULL; - PWSTR Start; - UNICODE_STRING ObjectName; - OBJECT_CREATE_INFORMATION ObjectCreateInfo; - unsigned i; - REG_PRE_CREATE_KEY_INFORMATION PreCreateKeyInfo; - REG_POST_CREATE_KEY_INFORMATION PostCreateKeyInfo; - KPROCESSOR_MODE PreviousMode; - UNICODE_STRING CapturedClass = {0}; - HANDLE hKey; + UNICODE_STRING RemainingPath = {0}; + BOOLEAN FreeRemainingPath = TRUE; + ULONG LocalDisposition; + PKEY_OBJECT KeyObject; + NTSTATUS Status = STATUS_SUCCESS; + PVOID Object = NULL; + PWSTR Start; + UNICODE_STRING ObjectName; + OBJECT_CREATE_INFORMATION ObjectCreateInfo; + unsigned int i; + REG_PRE_CREATE_KEY_INFORMATION PreCreateKeyInfo; + REG_POST_CREATE_KEY_INFORMATION PostCreateKeyInfo; + KPROCESSOR_MODE PreviousMode; + UNICODE_STRING CapturedClass = {0}; + HANDLE hKey; - PAGED_CODE(); + PAGED_CODE(); - DPRINT("NtCreateKey(TI 0x%x, DA 0x%x, Class '%wZ', OA 0x%p, OA->ON '%wZ'\n", - TitleIndex, DesiredAccess, Class, ObjectAttributes, - ObjectAttributes ? ObjectAttributes->ObjectName : NULL); + DPRINT("NtCreateKey(TI 0x%x, DA 0x%x, Class '%wZ', OA 0x%p, OA->ON '%wZ'\n", + TitleIndex, DesiredAccess, Class, ObjectAttributes, + ObjectAttributes ? ObjectAttributes->ObjectName : NULL); - PreviousMode = ExGetPreviousMode(); + PreviousMode = ExGetPreviousMode(); - if (PreviousMode != KernelMode) - { - _SEH_TRY - { - ProbeAndZeroHandle(KeyHandle); - if (Disposition != NULL) - { - ProbeForWriteUlong(Disposition); - } - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - if (!NT_SUCCESS(Status)) - { - return Status; - } - } - - if (Class != NULL) - { - Status = ProbeAndCaptureUnicodeString(&CapturedClass, - PreviousMode, - Class); - if (!NT_SUCCESS(Status)) - { - return Status; - } - } - - /* Capture all the info */ - DPRINT("Capturing Create Info\n"); - Status = ObpCaptureObjectAttributes(ObjectAttributes, - PreviousMode, - FALSE, - &ObjectCreateInfo, - &ObjectName); - if (!NT_SUCCESS(Status)) + if (PreviousMode != KernelMode) { - DPRINT1("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); - return Status; - } - - PostCreateKeyInfo.CompleteName = &ObjectName; - PreCreateKeyInfo.CompleteName = &ObjectName; - Status = CmiCallRegisteredCallbacks(RegNtPreCreateKey, &PreCreateKeyInfo); - if (!NT_SUCCESS(Status)) - { - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - goto Cleanup; - } - - Status = CmFindObject(&ObjectCreateInfo, - &ObjectName, - (PVOID*)&Object, - &RemainingPath, - CmpKeyObjectType, - NULL, - NULL); - if (!NT_SUCCESS(Status)) - { - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - DPRINT1("CmpFindObject failed, Status: 0x%x\n", Status); - goto Cleanup; - } - - DPRINT("RemainingPath %wZ\n", &RemainingPath); - - if (RemainingPath.Length == 0) - { - /* Fail if the key has been deleted */ - if (((PKEY_OBJECT) Object)->Flags & KO_MARKED_FOR_DELETE) - { - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = STATUS_UNSUCCESSFUL; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - DPRINT1("Object marked for delete!\n"); - Status = STATUS_UNSUCCESSFUL; - goto Cleanup; - } - - Status = CmpCreateHandle(Object, - DesiredAccess, - ObjectCreateInfo.Attributes, - &hKey); - - if (!NT_SUCCESS(Status)) - DPRINT1("CmpCreateHandle failed Status 0x%x\n", Status); - - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - LocalDisposition = REG_OPENED_EXISTING_KEY; - goto SuccessReturn; - } - - /* If RemainingPath contains \ we must return error - because NtCreateKey doesn't create trees */ - Start = RemainingPath.Buffer; - if (*Start == L'\\') - { - Start++; - //RemainingPath.Length -= sizeof(WCHAR); - //RemainingPath.MaximumLength -= sizeof(WCHAR); - //RemainingPath.Buffer++; - //DPRINT1("String: %wZ\n", &RemainingPath); - } - - if (RemainingPath.Buffer[(RemainingPath.Length / sizeof(WCHAR)) - 1] == '\\') - { - RemainingPath.Buffer[(RemainingPath.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; - RemainingPath.Length -= sizeof(WCHAR); - RemainingPath.MaximumLength -= sizeof(WCHAR); - } - - for (i = 1; i < RemainingPath.Length / sizeof(WCHAR); i++) - { - if (L'\\' == RemainingPath.Buffer[i]) + _SEH_TRY { - DPRINT("NtCreateKey() doesn't create trees! (found \'\\\' in remaining path: \"%wZ\"!)\n", &RemainingPath); + ProbeAndZeroHandle(KeyHandle); + if (Disposition != NULL) + { + ProbeForWriteUlong(Disposition); + } + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = STATUS_OBJECT_NAME_NOT_FOUND; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - Status = STATUS_OBJECT_NAME_NOT_FOUND; - goto Cleanup; + if (!NT_SUCCESS(Status)) + { + return Status; } } - DPRINT("RemainingPath %S ParentObject 0x%p\n", RemainingPath.Buffer, Object); - - Status = ObCreateObject(PreviousMode, - CmpKeyObjectType, - NULL, - PreviousMode, - NULL, - sizeof(KEY_OBJECT), - 0, - 0, - (PVOID*)&KeyObject); - if (!NT_SUCCESS(Status)) + if (Class != NULL) { - DPRINT1("ObCreateObject() failed!\n"); - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - goto Cleanup; + Status = ProbeAndCaptureUnicodeString(&CapturedClass, + PreviousMode, + Class); + if (!NT_SUCCESS(Status)) + { + return Status; + } } - Status = ObInsertObject((PVOID)KeyObject, - NULL, - DesiredAccess, - 0, - NULL, - &hKey); - if (!NT_SUCCESS(Status)) + /* Capture all the info */ + DPRINT("Capturing Create Info\n"); + Status = ObpCaptureObjectAttributes(ObjectAttributes, + PreviousMode, + FALSE, + &ObjectCreateInfo, + &ObjectName); + if (!NT_SUCCESS(Status)) { - ObDereferenceObject(KeyObject); - DPRINT1("ObInsertObject() failed!\n"); - - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - - goto Cleanup; + DPRINT1("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); + return Status; } - KeyObject->ParentKey = Object; - KeyObject->RegistryHive = KeyObject->ParentKey->RegistryHive; - KeyObject->Flags = 0; - KeyObject->SubKeyCounts = 0; - KeyObject->SizeOfSubKeys = 0; - KeyObject->SubKeys = NULL; + PostCreateKeyInfo.CompleteName = &ObjectName; + PreCreateKeyInfo.CompleteName = &ObjectName; + Status = CmiCallRegisteredCallbacks(RegNtPreCreateKey, &PreCreateKeyInfo); + if (!NT_SUCCESS(Status)) + { + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + goto Cleanup; + } - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + Status = CmFindObject(&ObjectCreateInfo, + &ObjectName, + (PVOID*)&Object, + &RemainingPath, + CmpKeyObjectType, + NULL, + NULL); + if (!NT_SUCCESS(Status)) + { + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - InsertTailList(&CmiKeyObjectListHead, &KeyObject->ListEntry); + DPRINT1("CmpFindObject failed, Status: 0x%x\n", Status); + goto Cleanup; + } + + DPRINT("RemainingPath %wZ\n", &RemainingPath); + + if (RemainingPath.Length == 0) + { + /* Fail if the key has been deleted */ + if (((PKEY_OBJECT) Object)->Flags & KO_MARKED_FOR_DELETE) + { + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = STATUS_UNSUCCESSFUL; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + DPRINT1("Object marked for delete!\n"); + Status = STATUS_UNSUCCESSFUL; + goto Cleanup; + } + + Status = CmpCreateHandle(Object, + DesiredAccess, + ObjectCreateInfo.Attributes, + &hKey); + + if (!NT_SUCCESS(Status)) + DPRINT1("CmpCreateHandle failed Status 0x%x\n", Status); + + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + LocalDisposition = REG_OPENED_EXISTING_KEY; + goto SuccessReturn; + } + + /* If RemainingPath contains \ we must return error + because NtCreateKey doesn't create trees */ + Start = RemainingPath.Buffer; + if (*Start == L'\\') + { + Start++; + //RemainingPath.Length -= sizeof(WCHAR); + //RemainingPath.MaximumLength -= sizeof(WCHAR); + //RemainingPath.Buffer++; + //DPRINT1("String: %wZ\n", &RemainingPath); + } + + if (RemainingPath.Buffer[(RemainingPath.Length / sizeof(WCHAR)) - 1] == '\\') + { + RemainingPath.Buffer[(RemainingPath.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; + RemainingPath.Length -= sizeof(WCHAR); + RemainingPath.MaximumLength -= sizeof(WCHAR); + } + + for (i = 1; i < RemainingPath.Length / sizeof(WCHAR); i++) + { + if (L'\\' == RemainingPath.Buffer[i]) + { + DPRINT("NtCreateKey() doesn't create trees! (found \'\\\' in remaining path: \"%wZ\"!)\n", &RemainingPath); + + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = STATUS_OBJECT_NAME_NOT_FOUND; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + Status = STATUS_OBJECT_NAME_NOT_FOUND; + goto Cleanup; + } + } + + DPRINT("RemainingPath %S ParentObject 0x%p\n", RemainingPath.Buffer, Object); + + Status = ObCreateObject(PreviousMode, + CmpKeyObjectType, + NULL, + PreviousMode, + NULL, + sizeof(KEY_OBJECT), + 0, + 0, + (PVOID*)&KeyObject); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ObCreateObject() failed!\n"); + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + goto Cleanup; + } + + Status = ObInsertObject((PVOID)KeyObject, + NULL, + DesiredAccess, + 0, + NULL, + &hKey); + if (!NT_SUCCESS(Status)) + { + ObDereferenceObject(KeyObject); + DPRINT1("ObInsertObject() failed!\n"); + + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + + goto Cleanup; + } + + KeyObject->ParentKey = Object; + KeyObject->RegistryHive = KeyObject->ParentKey->RegistryHive; + KeyObject->Flags = 0; + KeyObject->SubKeyCounts = 0; + KeyObject->SizeOfSubKeys = 0; + KeyObject->SubKeys = NULL; + + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + + InsertTailList(&CmiKeyObjectListHead, &KeyObject->ListEntry); /* add key to subkeys of parent if needed */ - Status = CmiAddSubKey(KeyObject->RegistryHive, - KeyObject->ParentKey, - KeyObject, - &RemainingPath, - TitleIndex, - &CapturedClass, - CreateOptions); - if (!NT_SUCCESS(Status)) + Status = CmiAddSubKey(KeyObject->RegistryHive, + KeyObject->ParentKey, + KeyObject, + &RemainingPath, + TitleIndex, + &CapturedClass, + CreateOptions); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiAddSubKey() failed (Status %lx)\n", Status); - /* Release hive lock */ - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - ObDereferenceObject(KeyObject); + DPRINT1("CmiAddSubKey() failed (Status %lx)\n", Status); + /* Release hive lock */ + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + ObDereferenceObject(KeyObject); - PostCreateKeyInfo.Object = NULL; - PostCreateKeyInfo.Status = STATUS_UNSUCCESSFUL; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + PostCreateKeyInfo.Object = NULL; + PostCreateKeyInfo.Status = STATUS_UNSUCCESSFUL; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - Status = STATUS_UNSUCCESSFUL; - goto Cleanup; + Status = STATUS_UNSUCCESSFUL; + goto Cleanup; } - if (Start == RemainingPath.Buffer) + if (Start == RemainingPath.Buffer) { - KeyObject->Name = RemainingPath; - FreeRemainingPath = FALSE; + KeyObject->Name = RemainingPath; + FreeRemainingPath = FALSE; } - else + else { - RtlpCreateUnicodeString(&KeyObject->Name, Start, NonPagedPool); + RtlpCreateUnicodeString(&KeyObject->Name, Start, NonPagedPool); } - KeyObject->KeyCell->Parent = KeyObject->ParentKey->KeyCellOffset; - KeyObject->KeyCell->SecurityKeyOffset = KeyObject->ParentKey->KeyCell->SecurityKeyOffset; - KeyObject->ValueCache.ValueList = KeyObject->KeyCell->ValueList.List; - KeyObject->ValueCache.Count = KeyObject->KeyCell->ValueList.Count; + KeyObject->KeyCell->Parent = KeyObject->ParentKey->KeyCellOffset; + KeyObject->KeyCell->SecurityKeyOffset = KeyObject->ParentKey->KeyCell->SecurityKeyOffset; + KeyObject->ValueCache.ValueList = KeyObject->KeyCell->ValueList.List; + KeyObject->ValueCache.Count = KeyObject->KeyCell->ValueList.Count; - DPRINT("RemainingPath: %wZ\n", &RemainingPath); + DPRINT("RemainingPath: %wZ\n", &RemainingPath); - CmiAddKeyToList(KeyObject->ParentKey, KeyObject); + CmiAddKeyToList(KeyObject->ParentKey, KeyObject); - VERIFY_KEY_OBJECT(KeyObject); + VERIFY_KEY_OBJECT(KeyObject); - /* Release hive lock */ - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); + /* Release hive lock */ + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); - PostCreateKeyInfo.Object = KeyObject; - PostCreateKeyInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); + PostCreateKeyInfo.Object = KeyObject; + PostCreateKeyInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostCreateKey, &PostCreateKeyInfo); - CmiSyncHives(); - - LocalDisposition = REG_CREATED_NEW_KEY; + CmiSyncHives(); + + LocalDisposition = REG_CREATED_NEW_KEY; SuccessReturn: - _SEH_TRY - { - *KeyHandle = hKey; - if (Disposition != NULL) - { - *Disposition = LocalDisposition; - } - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - -Cleanup: - ObpReleaseCapturedAttributes(&ObjectCreateInfo); - if (Class != NULL) - { - ReleaseCapturedUnicodeString(&CapturedClass, - PreviousMode); - } - if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); - if (FreeRemainingPath) RtlFreeUnicodeString(&RemainingPath); - if (Object != NULL) ObDereferenceObject(Object); - - return Status; -} - -NTSTATUS STDCALL -NtFlushKey(IN HANDLE KeyHandle) -{ - NTSTATUS Status; - PKEY_OBJECT KeyObject; - PEREGISTRY_HIVE RegistryHive; - KPROCESSOR_MODE PreviousMode; - - PAGED_CODE(); - - DPRINT("NtFlushKey (KeyHandle %lx) called\n", KeyHandle); - - PreviousMode = ExGetPreviousMode(); - - /* Verify that the handle is valid and is a registry key */ - Status = ObReferenceObjectByHandle(KeyHandle, - 0, - CmpKeyObjectType, - PreviousMode, - (PVOID *)&KeyObject, - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - VERIFY_KEY_OBJECT(KeyObject); - - RegistryHive = KeyObject->RegistryHive; - - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - - if (IsNoFileHive(RegistryHive)) - { - Status = STATUS_SUCCESS; - } - else - { - /* Flush non-volatile hive */ - Status = CmiFlushRegistryHive(RegistryHive); - } - - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - - ObDereferenceObject(KeyObject); - - return STATUS_SUCCESS; -} - - -NTSTATUS STDCALL -NtOpenKey(OUT PHANDLE KeyHandle, - IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes) -{ - UNICODE_STRING RemainingPath; - KPROCESSOR_MODE PreviousMode; - PVOID Object = NULL; - HANDLE hKey = NULL; - NTSTATUS Status = STATUS_SUCCESS; - UNICODE_STRING ObjectName; - OBJECT_CREATE_INFORMATION ObjectCreateInfo; - REG_PRE_OPEN_KEY_INFORMATION PreOpenKeyInfo; - REG_POST_OPEN_KEY_INFORMATION PostOpenKeyInfo; - - PAGED_CODE(); - - DPRINT("NtOpenKey(KH 0x%p DA %x OA 0x%p OA->ON '%wZ'\n", - KeyHandle, - DesiredAccess, - ObjectAttributes, - ObjectAttributes ? ObjectAttributes->ObjectName : NULL); - - /* Check place for result handle, if it's null - return immediately */ - if (KeyHandle == NULL) - return(STATUS_INVALID_PARAMETER); - - PreviousMode = ExGetPreviousMode(); - - if(PreviousMode != KernelMode) - { _SEH_TRY { - ProbeAndZeroHandle(KeyHandle); + *KeyHandle = hKey; + if (Disposition != NULL) + { + *Disposition = LocalDisposition; + } } _SEH_HANDLE { - Status = _SEH_GetExceptionCode(); + Status = _SEH_GetExceptionCode(); } _SEH_END; - if(!NT_SUCCESS(Status)) +Cleanup: + ObpReleaseCapturedAttributes(&ObjectCreateInfo); + if (Class != NULL) { - return Status; + ReleaseCapturedUnicodeString(&CapturedClass, + PreviousMode); } - } + if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); + if (FreeRemainingPath) RtlFreeUnicodeString(&RemainingPath); + if (Object != NULL) ObDereferenceObject(Object); - /* WINE checks for the length also */ - /*if (ObjectAttributes->ObjectName->Length > MAX_NAME_LENGTH) - return(STATUS_BUFFER_OVERFLOW);*/ + return Status; +} - /* Capture all the info */ - DPRINT("Capturing Create Info\n"); - Status = ObpCaptureObjectAttributes(ObjectAttributes, +NTSTATUS +NTAPI +NtFlushKey(IN HANDLE KeyHandle) +{ + NTSTATUS Status; + PKEY_OBJECT KeyObject; + PEREGISTRY_HIVE RegistryHive; + KPROCESSOR_MODE PreviousMode; + + PAGED_CODE(); + + DPRINT("NtFlushKey (KeyHandle %lx) called\n", KeyHandle); + + PreviousMode = ExGetPreviousMode(); + + /* Verify that the handle is valid and is a registry key */ + Status = ObReferenceObjectByHandle(KeyHandle, + 0, + CmpKeyObjectType, PreviousMode, - FALSE, - &ObjectCreateInfo, - &ObjectName); - if (!NT_SUCCESS(Status)) + (PVOID *)&KeyObject, + NULL); + if (!NT_SUCCESS(Status)) { - DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); - return Status; + return(Status); } - if (ObjectName.Buffer && - ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] == '\\') + VERIFY_KEY_OBJECT(KeyObject); + + RegistryHive = KeyObject->RegistryHive; + + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + + if (IsNoFileHive(RegistryHive)) { - ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; - ObjectName.Length -= sizeof(WCHAR); - ObjectName.MaximumLength -= sizeof(WCHAR); + Status = STATUS_SUCCESS; + } + else + { + /* Flush non-volatile hive */ + Status = CmiFlushRegistryHive(RegistryHive); } - PostOpenKeyInfo.CompleteName = &ObjectName; - PreOpenKeyInfo.CompleteName = &ObjectName; - Status = CmiCallRegisteredCallbacks(RegNtPreOpenKey, &PreOpenKeyInfo); - if (!NT_SUCCESS(Status)) + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + + ObDereferenceObject(KeyObject); + + return STATUS_SUCCESS; +} + + +NTSTATUS +NTAPI +NtOpenKey(OUT PHANDLE KeyHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes) +{ + UNICODE_STRING RemainingPath; + KPROCESSOR_MODE PreviousMode; + PVOID Object = NULL; + HANDLE hKey = NULL; + NTSTATUS Status = STATUS_SUCCESS; + UNICODE_STRING ObjectName; + OBJECT_CREATE_INFORMATION ObjectCreateInfo; + REG_PRE_OPEN_KEY_INFORMATION PreOpenKeyInfo; + REG_POST_OPEN_KEY_INFORMATION PostOpenKeyInfo; + + PAGED_CODE(); + + DPRINT("NtOpenKey(KH 0x%p DA %x OA 0x%p OA->ON '%wZ'\n", + KeyHandle, + DesiredAccess, + ObjectAttributes, + ObjectAttributes ? ObjectAttributes->ObjectName : NULL); + + /* Check place for result handle, if it's null - return immediately */ + if (KeyHandle == NULL) + return(STATUS_INVALID_PARAMETER); + + PreviousMode = ExGetPreviousMode(); + + if(PreviousMode != KernelMode) { - PostOpenKeyInfo.Object = NULL; - PostOpenKeyInfo.Status = Status; - CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); - ObpReleaseCapturedAttributes(&ObjectCreateInfo); - if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); - return Status; + _SEH_TRY + { + ProbeAndZeroHandle(KeyHandle); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + + if(!NT_SUCCESS(Status)) + { + return Status; + } } + /* WINE checks for the length also */ + /*if (ObjectAttributes->ObjectName->Length > MAX_NAME_LENGTH) + return(STATUS_BUFFER_OVERFLOW);*/ - RemainingPath.Buffer = NULL; - - Status = CmFindObject(&ObjectCreateInfo, - &ObjectName, - (PVOID*)&Object, - &RemainingPath, - CmpKeyObjectType, - NULL, - NULL); - if (!NT_SUCCESS(Status)) + /* Capture all the info */ + DPRINT("Capturing Create Info\n"); + Status = ObpCaptureObjectAttributes(ObjectAttributes, + PreviousMode, + FALSE, + &ObjectCreateInfo, + &ObjectName); + if (!NT_SUCCESS(Status)) { - DPRINT("CmpFindObject() returned 0x%08lx\n", Status); - Status = STATUS_INVALID_HANDLE; /* Because ObFindObject returns STATUS_UNSUCCESSFUL */ - goto openkey_cleanup; + DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); + return Status; } - VERIFY_KEY_OBJECT((PKEY_OBJECT) Object); - - DPRINT("RemainingPath '%wZ'\n", &RemainingPath); - - if ((RemainingPath.Buffer != NULL) && (RemainingPath.Buffer[0] != 0)) + if (ObjectName.Buffer && + ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] == '\\') { - RtlFreeUnicodeString(&RemainingPath); - Status = STATUS_OBJECT_NAME_NOT_FOUND; - goto openkey_cleanup; + ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; + ObjectName.Length -= sizeof(WCHAR); + ObjectName.MaximumLength -= sizeof(WCHAR); } - RtlFreeUnicodeString(&RemainingPath); - - /* Fail if the key has been deleted */ - if (((PKEY_OBJECT)Object)->Flags & KO_MARKED_FOR_DELETE) + PostOpenKeyInfo.CompleteName = &ObjectName; + PreOpenKeyInfo.CompleteName = &ObjectName; + Status = CmiCallRegisteredCallbacks(RegNtPreOpenKey, &PreOpenKeyInfo); + if (!NT_SUCCESS(Status)) { - Status = STATUS_UNSUCCESSFUL; - goto openkey_cleanup; + PostOpenKeyInfo.Object = NULL; + PostOpenKeyInfo.Status = Status; + CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); + ObpReleaseCapturedAttributes(&ObjectCreateInfo); + if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); + return Status; } - Status = CmpCreateHandle(Object, - DesiredAccess, - ObjectCreateInfo.Attributes, - &hKey); + RemainingPath.Buffer = NULL; + + Status = CmFindObject(&ObjectCreateInfo, + &ObjectName, + (PVOID*)&Object, + &RemainingPath, + CmpKeyObjectType, + NULL, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT("CmpFindObject() returned 0x%08lx\n", Status); + Status = STATUS_INVALID_HANDLE; /* Because ObFindObject returns STATUS_UNSUCCESSFUL */ + goto openkey_cleanup; + } + + VERIFY_KEY_OBJECT((PKEY_OBJECT) Object); + + DPRINT("RemainingPath '%wZ'\n", &RemainingPath); + + if ((RemainingPath.Buffer != NULL) && (RemainingPath.Buffer[0] != 0)) + { + RtlFreeUnicodeString(&RemainingPath); + Status = STATUS_OBJECT_NAME_NOT_FOUND; + goto openkey_cleanup; + } + + RtlFreeUnicodeString(&RemainingPath); + + /* Fail if the key has been deleted */ + if (((PKEY_OBJECT)Object)->Flags & KO_MARKED_FOR_DELETE) + { + Status = STATUS_UNSUCCESSFUL; + goto openkey_cleanup; + } + + Status = CmpCreateHandle(Object, + DesiredAccess, + ObjectCreateInfo.Attributes, + &hKey); openkey_cleanup: - ObpReleaseCapturedAttributes(&ObjectCreateInfo); - PostOpenKeyInfo.Object = NT_SUCCESS(Status) ? (PVOID)Object : NULL; - PostOpenKeyInfo.Status = Status; - CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); - if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); + ObpReleaseCapturedAttributes(&ObjectCreateInfo); + PostOpenKeyInfo.Object = NT_SUCCESS(Status) ? (PVOID)Object : NULL; + PostOpenKeyInfo.Status = Status; + CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); + if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); - if (Object) + if (Object) { - ObDereferenceObject(Object); + ObDereferenceObject(Object); } - if (NT_SUCCESS(Status)) - { - _SEH_TRY + if (NT_SUCCESS(Status)) { - *KeyHandle = hKey; + _SEH_TRY + { + *KeyHandle = hKey; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - return Status; + return Status; } /* @@ -654,57 +655,59 @@ openkey_cleanup: * KeyObjectAttributes->Name specifies the name of the key to load. * Flags can be 0 or REG_NO_LAZY_FLUSH. */ -NTSTATUS STDCALL +NTSTATUS +NTAPI NtLoadKey2 (IN POBJECT_ATTRIBUTES KeyObjectAttributes, - IN POBJECT_ATTRIBUTES FileObjectAttributes, - IN ULONG Flags) + IN POBJECT_ATTRIBUTES FileObjectAttributes, + IN ULONG Flags) { - NTSTATUS Status; - PAGED_CODE(); - DPRINT ("NtLoadKey2() called\n"); + NTSTATUS Status; + PAGED_CODE(); + DPRINT ("NtLoadKey2() called\n"); #if 0 - if (!SeSinglePrivilegeCheck (SeRestorePrivilege, ExGetPreviousMode ())) - return STATUS_PRIVILEGE_NOT_HELD; + if (!SeSinglePrivilegeCheck (SeRestorePrivilege, ExGetPreviousMode ())) + return STATUS_PRIVILEGE_NOT_HELD; #endif - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - Status = CmiLoadHive (KeyObjectAttributes, - FileObjectAttributes->ObjectName, - Flags); - if (!NT_SUCCESS (Status)) + Status = CmiLoadHive (KeyObjectAttributes, + FileObjectAttributes->ObjectName, + Flags); + if (!NT_SUCCESS (Status)) { - DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); + DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); } - /* Release hive lock */ - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); + /* Release hive lock */ + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); - return Status; + return Status; } -NTSTATUS STDCALL +NTSTATUS +NTAPI NtInitializeRegistry (IN BOOLEAN SetUpBoot) { - NTSTATUS Status; + NTSTATUS Status; - PAGED_CODE(); + PAGED_CODE(); - if (CmiRegistryInitialized == TRUE) - return STATUS_ACCESS_DENIED; + if (CmiRegistryInitialized == TRUE) + return STATUS_ACCESS_DENIED; - /* Save boot log file */ - IopSaveBootLogToFile(); + /* Save boot log file */ + IopSaveBootLogToFile(); - Status = CmiInitHives (SetUpBoot); + Status = CmiInitHives (SetUpBoot); - CmiRegistryInitialized = TRUE; + CmiRegistryInitialized = TRUE; - return Status; + return Status; } NTSTATUS diff --git a/reactos/ntoskrnl/cm/regfile.c b/reactos/ntoskrnl/cm/regfile.c index ef4c21b3d61..b26dd3c23d2 100644 --- a/reactos/ntoskrnl/cm/regfile.c +++ b/reactos/ntoskrnl/cm/regfile.c @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * PROJECT: ReactOS Kernel * COPYRIGHT: GPL - See COPYING in the top level directory * FILE: ntoskrnl/cm/regfile.c @@ -62,195 +61,195 @@ CmiLoadHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, VOID CmCloseHiveFiles(PEREGISTRY_HIVE RegistryHive) { - ZwClose(RegistryHive->HiveHandle); - ZwClose(RegistryHive->LogHandle); + ZwClose(RegistryHive->HiveHandle); + ZwClose(RegistryHive->LogHandle); } NTSTATUS CmiFlushRegistryHive(PEREGISTRY_HIVE RegistryHive) { - BOOLEAN Success; - NTSTATUS Status; - ULONG Disposition; + BOOLEAN Success; + NTSTATUS Status; + ULONG Disposition; - ASSERT(!IsNoFileHive(RegistryHive)); + ASSERT(!IsNoFileHive(RegistryHive)); - if (RtlFindSetBits(&RegistryHive->Hive.DirtyVector, 1, 0) == ~0) + if (RtlFindSetBits(&RegistryHive->Hive.DirtyVector, 1, 0) == ~0) { - return(STATUS_SUCCESS); + return(STATUS_SUCCESS); } - Status = CmpOpenHiveFiles(&RegistryHive->HiveFileName, - L".LOG", - &RegistryHive->HiveHandle, - &RegistryHive->LogHandle, - &Disposition, - &Disposition, - FALSE, - FALSE, - TRUE, - NULL); - if (!NT_SUCCESS(Status)) + Status = CmpOpenHiveFiles(&RegistryHive->HiveFileName, + L".LOG", + &RegistryHive->HiveHandle, + &RegistryHive->LogHandle, + &Disposition, + &Disposition, + FALSE, + FALSE, + TRUE, + NULL); + if (!NT_SUCCESS(Status)) { - return Status; + return Status; } - Success = HvSyncHive(&RegistryHive->Hive); + Success = HvSyncHive(&RegistryHive->Hive); - CmCloseHiveFiles(RegistryHive); + CmCloseHiveFiles(RegistryHive); - return Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; + return Success ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; } ULONG CmiGetMaxNameLength(PHHIVE Hive, PCM_KEY_NODE KeyCell) { - PHASH_TABLE_CELL HashBlock; - PCM_KEY_NODE CurSubKeyCell; - ULONG MaxName; - ULONG NameSize; - ULONG i; - ULONG Storage; + PHASH_TABLE_CELL HashBlock; + PCM_KEY_NODE CurSubKeyCell; + ULONG MaxName; + ULONG NameSize; + ULONG i; + ULONG Storage; - MaxName = 0; - for (Storage = HvStable; Storage < HvMaxStorageType; Storage++) + MaxName = 0; + for (Storage = HvStable; Storage < HvMaxStorageType; Storage++) { - if (KeyCell->SubKeyLists[Storage] != HCELL_NULL) + if (KeyCell->SubKeyLists[Storage] != HCELL_NULL) { - HashBlock = HvGetCell (Hive, KeyCell->SubKeyLists[Storage]); - ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); + HashBlock = HvGetCell (Hive, KeyCell->SubKeyLists[Storage]); + ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); - for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) + for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) { - CurSubKeyCell = HvGetCell (Hive, - HashBlock->Table[i].KeyOffset); - NameSize = CurSubKeyCell->NameSize; - if (CurSubKeyCell->Flags & REG_KEY_NAME_PACKED) - NameSize *= sizeof(WCHAR); - if (NameSize > MaxName) - MaxName = NameSize; + CurSubKeyCell = HvGetCell (Hive, + HashBlock->Table[i].KeyOffset); + NameSize = CurSubKeyCell->NameSize; + if (CurSubKeyCell->Flags & REG_KEY_NAME_PACKED) + NameSize *= sizeof(WCHAR); + if (NameSize > MaxName) + MaxName = NameSize; } } } - DPRINT ("MaxName %lu\n", MaxName); + DPRINT ("MaxName %lu\n", MaxName); - return MaxName; + return MaxName; } ULONG CmiGetMaxClassLength(PHHIVE Hive, PCM_KEY_NODE KeyCell) { - PHASH_TABLE_CELL HashBlock; - PCM_KEY_NODE CurSubKeyCell; - ULONG MaxClass; - ULONG i; - ULONG Storage; + PHASH_TABLE_CELL HashBlock; + PCM_KEY_NODE CurSubKeyCell; + ULONG MaxClass; + ULONG i; + ULONG Storage; - MaxClass = 0; - for (Storage = HvStable; Storage < HvMaxStorageType; Storage++) + MaxClass = 0; + for (Storage = HvStable; Storage < HvMaxStorageType; Storage++) { - if (KeyCell->SubKeyLists[Storage] != HCELL_NULL) + if (KeyCell->SubKeyLists[Storage] != HCELL_NULL) { - HashBlock = HvGetCell (Hive, - KeyCell->SubKeyLists[Storage]); - ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); + HashBlock = HvGetCell (Hive, + KeyCell->SubKeyLists[Storage]); + ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); - for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) + for (i = 0; i < KeyCell->SubKeyCounts[Storage]; i++) { - CurSubKeyCell = HvGetCell (Hive, - HashBlock->Table[i].KeyOffset); + CurSubKeyCell = HvGetCell (Hive, + HashBlock->Table[i].KeyOffset); - if (MaxClass < CurSubKeyCell->ClassSize) + if (MaxClass < CurSubKeyCell->ClassSize) { - MaxClass = CurSubKeyCell->ClassSize; + MaxClass = CurSubKeyCell->ClassSize; } } } } - return MaxClass; + return MaxClass; } ULONG CmiGetMaxValueNameLength(PHHIVE Hive, - PCM_KEY_NODE KeyCell) + PCM_KEY_NODE KeyCell) { - PVALUE_LIST_CELL ValueListCell; - PCM_KEY_VALUE CurValueCell; - ULONG MaxValueName; - ULONG Size; - ULONG i; + PVALUE_LIST_CELL ValueListCell; + PCM_KEY_VALUE CurValueCell; + ULONG MaxValueName; + ULONG Size; + ULONG i; - VERIFY_KEY_CELL(KeyCell); + VERIFY_KEY_CELL(KeyCell); - if (KeyCell->ValueList.List == HCELL_NULL) + if (KeyCell->ValueList.List == HCELL_NULL) { - return 0; + return 0; } - MaxValueName = 0; - ValueListCell = HvGetCell (Hive, - KeyCell->ValueList.List); + MaxValueName = 0; + ValueListCell = HvGetCell (Hive, + KeyCell->ValueList.List); - for (i = 0; i < KeyCell->ValueList.Count; i++) + for (i = 0; i < KeyCell->ValueList.Count; i++) { - CurValueCell = HvGetCell (Hive, - ValueListCell->ValueOffset[i]); - if (CurValueCell == NULL) - { - DPRINT("CmiGetBlock() failed\n"); - } + CurValueCell = HvGetCell (Hive, + ValueListCell->ValueOffset[i]); + if (CurValueCell == NULL) + { + DPRINT("CmiGetBlock() failed\n"); + } - if (CurValueCell != NULL) - { - Size = CurValueCell->NameSize; - if (CurValueCell->Flags & REG_VALUE_NAME_PACKED) - { - Size *= sizeof(WCHAR); - } - if (MaxValueName < Size) - { - MaxValueName = Size; - } + if (CurValueCell != NULL) + { + Size = CurValueCell->NameSize; + if (CurValueCell->Flags & REG_VALUE_NAME_PACKED) + { + Size *= sizeof(WCHAR); + } + if (MaxValueName < Size) + { + MaxValueName = Size; + } } } - return MaxValueName; + return MaxValueName; } ULONG CmiGetMaxValueDataLength(PHHIVE Hive, - PCM_KEY_NODE KeyCell) + PCM_KEY_NODE KeyCell) { - PVALUE_LIST_CELL ValueListCell; - PCM_KEY_VALUE CurValueCell; - LONG MaxValueData; - ULONG i; + PVALUE_LIST_CELL ValueListCell; + PCM_KEY_VALUE CurValueCell; + LONG MaxValueData; + ULONG i; - VERIFY_KEY_CELL(KeyCell); + VERIFY_KEY_CELL(KeyCell); - if (KeyCell->ValueList.List == HCELL_NULL) + if (KeyCell->ValueList.List == HCELL_NULL) { - return 0; + return 0; } - MaxValueData = 0; - ValueListCell = HvGetCell (Hive, KeyCell->ValueList.List); + MaxValueData = 0; + ValueListCell = HvGetCell (Hive, KeyCell->ValueList.List); - for (i = 0; i < KeyCell->ValueList.Count; i++) + for (i = 0; i < KeyCell->ValueList.Count; i++) { - CurValueCell = HvGetCell (Hive, - ValueListCell->ValueOffset[i]); - if ((MaxValueData < (LONG)(CurValueCell->DataSize & REG_DATA_SIZE_MASK))) + CurValueCell = HvGetCell (Hive, + ValueListCell->ValueOffset[i]); + if ((MaxValueData < (LONG)(CurValueCell->DataSize & REG_DATA_SIZE_MASK))) { - MaxValueData = CurValueCell->DataSize & REG_DATA_SIZE_MASK; + MaxValueData = CurValueCell->DataSize & REG_DATA_SIZE_MASK; } } - return MaxValueData; + return MaxValueData; } NTSTATUS @@ -302,250 +301,250 @@ CmiScanForSubKey(IN PEREGISTRY_HIVE RegistryHive, NTSTATUS CmiAddSubKey(PEREGISTRY_HIVE RegistryHive, - PKEY_OBJECT ParentKey, - PKEY_OBJECT SubKey, - PUNICODE_STRING SubKeyName, - ULONG TitleIndex, - PUNICODE_STRING Class, - ULONG CreateOptions) + PKEY_OBJECT ParentKey, + PKEY_OBJECT SubKey, + PUNICODE_STRING SubKeyName, + ULONG TitleIndex, + PUNICODE_STRING Class, + ULONG CreateOptions) { - PHASH_TABLE_CELL HashBlock; - HCELL_INDEX NKBOffset; - PCM_KEY_NODE NewKeyCell; - ULONG NewBlockSize; - PCM_KEY_NODE ParentKeyCell; - PVOID ClassCell; - NTSTATUS Status; - USHORT NameSize; - PWSTR NamePtr; - BOOLEAN Packable; - HV_STORAGE_TYPE Storage; - ULONG i; + PHASH_TABLE_CELL HashBlock; + HCELL_INDEX NKBOffset; + PCM_KEY_NODE NewKeyCell; + ULONG NewBlockSize; + PCM_KEY_NODE ParentKeyCell; + PVOID ClassCell; + NTSTATUS Status; + USHORT NameSize; + PWSTR NamePtr; + BOOLEAN Packable; + HV_STORAGE_TYPE Storage; + ULONG i; - ParentKeyCell = ParentKey->KeyCell; + ParentKeyCell = ParentKey->KeyCell; - VERIFY_KEY_CELL(ParentKeyCell); + VERIFY_KEY_CELL(ParentKeyCell); - /* Skip leading backslash */ - if (SubKeyName->Buffer[0] == L'\\') + /* Skip leading backslash */ + if (SubKeyName->Buffer[0] == L'\\') { - NamePtr = &SubKeyName->Buffer[1]; - NameSize = SubKeyName->Length - sizeof(WCHAR); + NamePtr = &SubKeyName->Buffer[1]; + NameSize = SubKeyName->Length - sizeof(WCHAR); } - else + else { - NamePtr = SubKeyName->Buffer; - NameSize = SubKeyName->Length; + NamePtr = SubKeyName->Buffer; + NameSize = SubKeyName->Length; } - /* Check whether key name can be packed */ - Packable = TRUE; - for (i = 0; i < NameSize / sizeof(WCHAR); i++) + /* Check whether key name can be packed */ + Packable = TRUE; + for (i = 0; i < NameSize / sizeof(WCHAR); i++) { - if (NamePtr[i] & 0xFF00) - { - Packable = FALSE; - break; - } - } - - /* Adjust name size */ - if (Packable) - { - NameSize = NameSize / sizeof(WCHAR); - } - - DPRINT("Key %S Length %lu %s\n", NamePtr, NameSize, (Packable)?"True":"False"); - - Status = STATUS_SUCCESS; - - Storage = (CreateOptions & REG_OPTION_VOLATILE) ? HvVolatile : HvStable; - NewBlockSize = sizeof(CM_KEY_NODE) + NameSize; - NKBOffset = HvAllocateCell (&RegistryHive->Hive, NewBlockSize, Storage); - if (NKBOffset == HCELL_NULL) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - else - { - NewKeyCell = HvGetCell (&RegistryHive->Hive, NKBOffset); - NewKeyCell->Id = REG_KEY_CELL_ID; - if (CreateOptions & REG_OPTION_VOLATILE) + if (NamePtr[i] & 0xFF00) { - NewKeyCell->Flags = REG_KEY_VOLATILE_CELL; + Packable = FALSE; + break; } - else - { - NewKeyCell->Flags = 0; - } - KeQuerySystemTime(&NewKeyCell->LastWriteTime); - NewKeyCell->Parent = HCELL_NULL; - NewKeyCell->SubKeyCounts[HvStable] = 0; - NewKeyCell->SubKeyCounts[HvVolatile] = 0; - NewKeyCell->SubKeyLists[HvStable] = HCELL_NULL; - NewKeyCell->SubKeyLists[HvVolatile] = HCELL_NULL; - NewKeyCell->ValueList.Count = 0; - NewKeyCell->ValueList.List = HCELL_NULL; - NewKeyCell->SecurityKeyOffset = HCELL_NULL; - NewKeyCell->ClassNameOffset = HCELL_NULL; - - /* Pack the key name */ - NewKeyCell->NameSize = NameSize; - if (Packable) - { - NewKeyCell->Flags |= REG_KEY_NAME_PACKED; - for (i = 0; i < NameSize; i++) - { - NewKeyCell->Name[i] = (CHAR)(NamePtr[i] & 0x00FF); - } - } - else - { - RtlCopyMemory(NewKeyCell->Name, - NamePtr, - NameSize); - } - - VERIFY_KEY_CELL(NewKeyCell); - - if (Class != NULL && Class->Length) - { - NewKeyCell->ClassSize = Class->Length; - NewKeyCell->ClassNameOffset = HvAllocateCell( - &RegistryHive->Hive, NewKeyCell->ClassSize, HvStable); - ASSERT(NewKeyCell->ClassNameOffset != HCELL_NULL); /* FIXME */ - - ClassCell = HvGetCell(&RegistryHive->Hive, NewKeyCell->ClassNameOffset); - RtlCopyMemory (ClassCell, - Class->Buffer, - Class->Length); - } } - if (!NT_SUCCESS(Status)) + /* Adjust name size */ + if (Packable) + { + NameSize = NameSize / sizeof(WCHAR); + } + + DPRINT("Key %S Length %lu %s\n", NamePtr, NameSize, (Packable)?"True":"False"); + + Status = STATUS_SUCCESS; + + Storage = (CreateOptions & REG_OPTION_VOLATILE) ? HvVolatile : HvStable; + NewBlockSize = sizeof(CM_KEY_NODE) + NameSize; + NKBOffset = HvAllocateCell (&RegistryHive->Hive, NewBlockSize, Storage); + if (NKBOffset == HCELL_NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + NewKeyCell = HvGetCell (&RegistryHive->Hive, NKBOffset); + NewKeyCell->Id = REG_KEY_CELL_ID; + if (CreateOptions & REG_OPTION_VOLATILE) + { + NewKeyCell->Flags = REG_KEY_VOLATILE_CELL; + } + else + { + NewKeyCell->Flags = 0; + } + KeQuerySystemTime(&NewKeyCell->LastWriteTime); + NewKeyCell->Parent = HCELL_NULL; + NewKeyCell->SubKeyCounts[HvStable] = 0; + NewKeyCell->SubKeyCounts[HvVolatile] = 0; + NewKeyCell->SubKeyLists[HvStable] = HCELL_NULL; + NewKeyCell->SubKeyLists[HvVolatile] = HCELL_NULL; + NewKeyCell->ValueList.Count = 0; + NewKeyCell->ValueList.List = HCELL_NULL; + NewKeyCell->SecurityKeyOffset = HCELL_NULL; + NewKeyCell->ClassNameOffset = HCELL_NULL; + + /* Pack the key name */ + NewKeyCell->NameSize = NameSize; + if (Packable) + { + NewKeyCell->Flags |= REG_KEY_NAME_PACKED; + for (i = 0; i < NameSize; i++) + { + NewKeyCell->Name[i] = (CHAR)(NamePtr[i] & 0x00FF); + } + } + else + { + RtlCopyMemory(NewKeyCell->Name, + NamePtr, + NameSize); + } + + VERIFY_KEY_CELL(NewKeyCell); + + if (Class != NULL && Class->Length) + { + NewKeyCell->ClassSize = Class->Length; + NewKeyCell->ClassNameOffset = HvAllocateCell( + &RegistryHive->Hive, NewKeyCell->ClassSize, HvStable); + ASSERT(NewKeyCell->ClassNameOffset != HCELL_NULL); /* FIXME */ + + ClassCell = HvGetCell(&RegistryHive->Hive, NewKeyCell->ClassNameOffset); + RtlCopyMemory (ClassCell, + Class->Buffer, + Class->Length); + } + } + + if (!NT_SUCCESS(Status)) { return Status; } - SubKey->KeyCell = NewKeyCell; - SubKey->KeyCellOffset = NKBOffset; + SubKey->KeyCell = NewKeyCell; + SubKey->KeyCellOffset = NKBOffset; - if (ParentKeyCell->SubKeyLists[Storage] == HCELL_NULL) + if (ParentKeyCell->SubKeyLists[Storage] == HCELL_NULL) { - Status = CmiAllocateHashTableCell (RegistryHive, - &HashBlock, - &ParentKeyCell->SubKeyLists[Storage], - REG_INIT_HASH_TABLE_SIZE, - Storage); - if (!NT_SUCCESS(Status)) - { - return(Status); - } + Status = CmiAllocateHashTableCell (RegistryHive, + &HashBlock, + &ParentKeyCell->SubKeyLists[Storage], + REG_INIT_HASH_TABLE_SIZE, + Storage); + if (!NT_SUCCESS(Status)) + { + return(Status); + } } - else + else { - HashBlock = HvGetCell (&RegistryHive->Hive, - ParentKeyCell->SubKeyLists[Storage]); - ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); + HashBlock = HvGetCell (&RegistryHive->Hive, + ParentKeyCell->SubKeyLists[Storage]); + ASSERT(HashBlock->Id == REG_HASH_TABLE_CELL_ID); - if (((ParentKeyCell->SubKeyCounts[Storage] + 1) >= HashBlock->HashTableSize)) - { - PHASH_TABLE_CELL NewHashBlock; - HCELL_INDEX HTOffset; + if (((ParentKeyCell->SubKeyCounts[Storage] + 1) >= HashBlock->HashTableSize)) + { + PHASH_TABLE_CELL NewHashBlock; + HCELL_INDEX HTOffset; - /* Reallocate the hash table cell */ - Status = CmiAllocateHashTableCell (RegistryHive, - &NewHashBlock, - &HTOffset, - HashBlock->HashTableSize + - REG_EXTEND_HASH_TABLE_SIZE, - Storage); - if (!NT_SUCCESS(Status)) - { - return Status; - } + /* Reallocate the hash table cell */ + Status = CmiAllocateHashTableCell (RegistryHive, + &NewHashBlock, + &HTOffset, + HashBlock->HashTableSize + + REG_EXTEND_HASH_TABLE_SIZE, + Storage); + if (!NT_SUCCESS(Status)) + { + return Status; + } - RtlZeroMemory(&NewHashBlock->Table[0], - sizeof(NewHashBlock->Table[0]) * NewHashBlock->HashTableSize); - RtlCopyMemory(&NewHashBlock->Table[0], - &HashBlock->Table[0], - sizeof(NewHashBlock->Table[0]) * HashBlock->HashTableSize); - HvFreeCell (&RegistryHive->Hive, ParentKeyCell->SubKeyLists[Storage]); - ParentKeyCell->SubKeyLists[Storage] = HTOffset; - HashBlock = NewHashBlock; - } + RtlZeroMemory(&NewHashBlock->Table[0], + sizeof(NewHashBlock->Table[0]) * NewHashBlock->HashTableSize); + RtlCopyMemory(&NewHashBlock->Table[0], + &HashBlock->Table[0], + sizeof(NewHashBlock->Table[0]) * HashBlock->HashTableSize); + HvFreeCell (&RegistryHive->Hive, ParentKeyCell->SubKeyLists[Storage]); + ParentKeyCell->SubKeyLists[Storage] = HTOffset; + HashBlock = NewHashBlock; + } } - Status = CmiAddKeyToHashTable(RegistryHive, - HashBlock, - ParentKeyCell, - Storage, - NewKeyCell, - NKBOffset); - if (NT_SUCCESS(Status)) + Status = CmiAddKeyToHashTable(RegistryHive, + HashBlock, + ParentKeyCell, + Storage, + NewKeyCell, + NKBOffset); + if (NT_SUCCESS(Status)) { - ParentKeyCell->SubKeyCounts[Storage]++; + ParentKeyCell->SubKeyCounts[Storage]++; } - KeQuerySystemTime (&ParentKeyCell->LastWriteTime); - HvMarkCellDirty (&RegistryHive->Hive, ParentKey->KeyCellOffset); + KeQuerySystemTime (&ParentKeyCell->LastWriteTime); + HvMarkCellDirty (&RegistryHive->Hive, ParentKey->KeyCellOffset); - return(Status); + return(Status); } NTSTATUS CmiAllocateHashTableCell (IN PEREGISTRY_HIVE RegistryHive, - OUT PHASH_TABLE_CELL *HashBlock, - OUT HCELL_INDEX *HBOffset, - IN ULONG SubKeyCount, - IN HV_STORAGE_TYPE Storage) + OUT PHASH_TABLE_CELL *HashBlock, + OUT HCELL_INDEX *HBOffset, + IN ULONG SubKeyCount, + IN HV_STORAGE_TYPE Storage) { - PHASH_TABLE_CELL NewHashBlock; - ULONG NewHashSize; - NTSTATUS Status; + PHASH_TABLE_CELL NewHashBlock; + ULONG NewHashSize; + NTSTATUS Status; - Status = STATUS_SUCCESS; - *HashBlock = NULL; - NewHashSize = sizeof(HASH_TABLE_CELL) + - (SubKeyCount * sizeof(HASH_RECORD)); - *HBOffset = HvAllocateCell (&RegistryHive->Hive, NewHashSize, Storage); + Status = STATUS_SUCCESS; + *HashBlock = NULL; + NewHashSize = sizeof(HASH_TABLE_CELL) + + (SubKeyCount * sizeof(HASH_RECORD)); + *HBOffset = HvAllocateCell (&RegistryHive->Hive, NewHashSize, Storage); - if (*HBOffset == HCELL_NULL) + if (*HBOffset == HCELL_NULL) { - Status = STATUS_INSUFFICIENT_RESOURCES; + Status = STATUS_INSUFFICIENT_RESOURCES; } - else + else { - ASSERT(SubKeyCount <= 0xffff); /* should really be USHORT_MAX or similar */ - NewHashBlock = HvGetCell (&RegistryHive->Hive, *HBOffset); - NewHashBlock->Id = REG_HASH_TABLE_CELL_ID; - NewHashBlock->HashTableSize = (USHORT)SubKeyCount; - *HashBlock = NewHashBlock; + ASSERT(SubKeyCount <= 0xffff); /* should really be USHORT_MAX or similar */ + NewHashBlock = HvGetCell (&RegistryHive->Hive, *HBOffset); + NewHashBlock->Id = REG_HASH_TABLE_CELL_ID; + NewHashBlock->HashTableSize = (USHORT)SubKeyCount; + *HashBlock = NewHashBlock; } - return Status; + return Status; } NTSTATUS CmiAddKeyToHashTable(PEREGISTRY_HIVE RegistryHive, - PHASH_TABLE_CELL HashCell, - PCM_KEY_NODE KeyCell, - HV_STORAGE_TYPE StorageType, - PCM_KEY_NODE NewKeyCell, - HCELL_INDEX NKBOffset) + PHASH_TABLE_CELL HashCell, + PCM_KEY_NODE KeyCell, + HV_STORAGE_TYPE StorageType, + PCM_KEY_NODE NewKeyCell, + HCELL_INDEX NKBOffset) { - ULONG i = KeyCell->SubKeyCounts[StorageType]; + ULONG i = KeyCell->SubKeyCounts[StorageType]; - HashCell->Table[i].KeyOffset = NKBOffset; - HashCell->Table[i].HashValue = 0; - if (NewKeyCell->Flags & REG_KEY_NAME_PACKED) + HashCell->Table[i].KeyOffset = NKBOffset; + HashCell->Table[i].HashValue = 0; + if (NewKeyCell->Flags & REG_KEY_NAME_PACKED) { - RtlCopyMemory(&HashCell->Table[i].HashValue, - NewKeyCell->Name, - min(NewKeyCell->NameSize, sizeof(ULONG))); + RtlCopyMemory(&HashCell->Table[i].HashValue, + NewKeyCell->Name, + min(NewKeyCell->NameSize, sizeof(ULONG))); } - HvMarkCellDirty(&RegistryHive->Hive, KeyCell->SubKeyLists[StorageType]); - return STATUS_SUCCESS; + HvMarkCellDirty(&RegistryHive->Hive, KeyCell->SubKeyLists[StorageType]); + return STATUS_SUCCESS; } /* EOF */ diff --git a/reactos/ntoskrnl/cm/registry.c b/reactos/ntoskrnl/cm/registry.c index b7972df6698..e5d0ac796a2 100644 --- a/reactos/ntoskrnl/cm/registry.c +++ b/reactos/ntoskrnl/cm/registry.c @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * PROJECT: ReactOS Kernel * COPYRIGHT: GPL - See COPYING in the top level directory * FILE: ntoskrnl/cm/registry.c @@ -46,78 +45,79 @@ volatile BOOLEAN CmiHiveSyncPending = FALSE; KDPC CmiHiveSyncDpc; KTIMER CmiHiveSyncTimer; -static VOID STDCALL +static VOID +NTAPI CmiHiveSyncDpcRoutine(PKDPC Dpc, - PVOID DeferredContext, - PVOID SystemArgument1, - PVOID SystemArgument2); + PVOID DeferredContext, + PVOID SystemArgument1, + PVOID SystemArgument2); extern LIST_ENTRY CmiCallbackHead; extern FAST_MUTEX CmiCallbackLock; extern UNICODE_STRING CmpSystemStartOptions; extern UNICODE_STRING CmpLoadOptions; + /* FUNCTIONS ****************************************************************/ -VOID STDCALL +VOID +NTAPI CmiWorkerThread(PVOID Param) { - NTSTATUS Status; - PLIST_ENTRY CurrentEntry; - PKEY_OBJECT CurrentKey; - ULONG Count; + NTSTATUS Status; + PLIST_ENTRY CurrentEntry; + PKEY_OBJECT CurrentKey; + ULONG Count; - - while (1) - { - Status = KeWaitForSingleObject(&CmiWorkerTimer, - Executive, - KernelMode, - FALSE, - NULL); - if (Status == STATUS_SUCCESS) + while (1) { - DPRINT("CmiWorkerThread\n"); + Status = KeWaitForSingleObject(&CmiWorkerTimer, + Executive, + KernelMode, + FALSE, + NULL); + if (Status == STATUS_SUCCESS) + { + DPRINT("CmiWorkerThread\n"); - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - CmiTimer++; + CmiTimer++; - Count = 0; - CurrentEntry = CmiKeyObjectListHead.Blink; - while (CurrentEntry != &CmiKeyObjectListHead) - { - CurrentKey = CONTAINING_RECORD(CurrentEntry, KEY_OBJECT, ListEntry); - if (CurrentKey->TimeStamp + 120 > CmiTimer) - { - /* The object was accessed in the last 10min */ - break; - } - if (1 == ObGetObjectPointerCount(CurrentKey) && - !(CurrentKey->Flags & KO_MARKED_FOR_DELETE)) - { - ObDereferenceObject(CurrentKey); + Count = 0; CurrentEntry = CmiKeyObjectListHead.Blink; - Count++; - } - else - { - CurrentEntry = CurrentEntry->Blink; - } - } - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - - DPRINT("Removed %d key objects\n", Count); + while (CurrentEntry != &CmiKeyObjectListHead) + { + CurrentKey = CONTAINING_RECORD(CurrentEntry, KEY_OBJECT, ListEntry); + if (CurrentKey->TimeStamp + 120 > CmiTimer) + { + /* The object was accessed in the last 10min */ + break; + } + if (1 == ObGetObjectPointerCount(CurrentKey) && + !(CurrentKey->Flags & KO_MARKED_FOR_DELETE)) + { + ObDereferenceObject(CurrentKey); + CurrentEntry = CmiKeyObjectListHead.Blink; + Count++; + } + else + { + CurrentEntry = CurrentEntry->Blink; + } + } + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + DPRINT("Removed %d key objects\n", Count); + } + else + { + KEBUGCHECK(0); + } } - else - { - KEBUGCHECK(0); - } - } } PVOID @@ -194,7 +194,7 @@ CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName, NTSTATUS CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, - IN PEREGISTRY_HIVE RegistryHive) + IN PEREGISTRY_HIVE RegistryHive) { UNICODE_STRING RemainingPath; PKEY_OBJECT ParentKey; @@ -205,81 +205,82 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, OBJECT_CREATE_INFORMATION ObjectCreateInfo; DPRINT("CmiConnectHive(%p, %p) called.\n", - KeyObjectAttributes, RegistryHive); + KeyObjectAttributes, RegistryHive); /* Capture all the info */ DPRINT("Capturing Create Info\n"); Status = ObpCaptureObjectAttributes(KeyObjectAttributes, - KernelMode, - FALSE, - &ObjectCreateInfo, - &ObjectName); + KernelMode, + FALSE, + &ObjectCreateInfo, + &ObjectName); if (!NT_SUCCESS(Status)) - { - DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); - return Status; - } + { + DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); + return Status; + } Status = CmFindObject(&ObjectCreateInfo, - &ObjectName, - (PVOID*)&ParentKey, - &RemainingPath, - CmpKeyObjectType, - NULL, - NULL); + &ObjectName, + (PVOID*)&ParentKey, + &RemainingPath, + CmpKeyObjectType, + NULL, + NULL); /* Yields a new reference */ ObpReleaseCapturedAttributes(&ObjectCreateInfo); if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); if (!NT_SUCCESS(Status)) - { - return Status; - } + { + return Status; + } DPRINT ("RemainingPath %wZ\n", &RemainingPath); if ((RemainingPath.Buffer == NULL) || (RemainingPath.Buffer[0] == 0)) - { - ObDereferenceObject (ParentKey); - RtlFreeUnicodeString(&RemainingPath); - return STATUS_OBJECT_NAME_COLLISION; - } + { + ObDereferenceObject (ParentKey); + RtlFreeUnicodeString(&RemainingPath); + return STATUS_OBJECT_NAME_COLLISION; + } /* Ignore leading backslash */ SubName = RemainingPath.Buffer; if (*SubName == L'\\') - SubName++; + SubName++; /* If RemainingPath contains \ we must return error because CmiConnectHive() can not create trees */ if (wcschr (SubName, L'\\') != NULL) - { - ObDereferenceObject (ParentKey); - RtlFreeUnicodeString(&RemainingPath); - return STATUS_OBJECT_NAME_NOT_FOUND; - } + { + ObDereferenceObject (ParentKey); + RtlFreeUnicodeString(&RemainingPath); + return STATUS_OBJECT_NAME_NOT_FOUND; + } DPRINT("RemainingPath %wZ ParentKey %p\n", - &RemainingPath, ParentKey); + &RemainingPath, ParentKey); Status = ObCreateObject(KernelMode, - CmpKeyObjectType, - NULL, - KernelMode, - NULL, - sizeof(KEY_OBJECT), - 0, - 0, - (PVOID*)&NewKey); - + CmpKeyObjectType, + NULL, + KernelMode, + NULL, + sizeof(KEY_OBJECT), + 0, + 0, + (PVOID*)&NewKey); + if (!NT_SUCCESS(Status)) - { - DPRINT1 ("ObCreateObject() failed (Status %lx)\n", Status); - ObDereferenceObject (ParentKey); - RtlFreeUnicodeString(&RemainingPath); - return Status; - } + { + DPRINT1 ("ObCreateObject() failed (Status %lx)\n", Status); + ObDereferenceObject (ParentKey); + RtlFreeUnicodeString(&RemainingPath); + return Status; + } + #if 0 DPRINT("Inserting Key into Object Tree\n"); Status = ObInsertObject((PVOID)NewKey, @@ -288,55 +289,55 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, 0, NULL, NULL); - DPRINT("Status %x\n", Status); + DPRINT("Status %x\n", Status); #else /* Free the create information */ ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo); OBJECT_TO_OBJECT_HEADER(NewKey)->ObjectCreateInfo = NULL; #endif - NewKey->Flags = 0; - NewKey->SubKeyCounts = 0; - NewKey->SubKeys = NULL; - NewKey->SizeOfSubKeys = 0; - InsertTailList(&CmiKeyObjectListHead, &NewKey->ListEntry); + NewKey->Flags = 0; + NewKey->SubKeyCounts = 0; + NewKey->SubKeys = NULL; + NewKey->SizeOfSubKeys = 0; + InsertTailList(&CmiKeyObjectListHead, &NewKey->ListEntry); - DPRINT ("SubName %S\n", SubName); + DPRINT ("SubName %S\n", SubName); - Status = CmiAddSubKey(ParentKey->RegistryHive, - ParentKey, - NewKey, - &RemainingPath, - 0, - NULL, - REG_OPTION_VOLATILE); - if (!NT_SUCCESS(Status)) + Status = CmiAddSubKey(ParentKey->RegistryHive, + ParentKey, + NewKey, + &RemainingPath, + 0, + NULL, + REG_OPTION_VOLATILE); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiAddSubKey() failed (Status %lx)\n", Status); - ObDereferenceObject (NewKey); - ObDereferenceObject (ParentKey); - return STATUS_INSUFFICIENT_RESOURCES; + DPRINT1("CmiAddSubKey() failed (Status %lx)\n", Status); + ObDereferenceObject (NewKey); + ObDereferenceObject (ParentKey); + return STATUS_INSUFFICIENT_RESOURCES; } - NewKey->KeyCellOffset = RegistryHive->Hive.HiveHeader->RootCell; - NewKey->KeyCell = HvGetCell (&RegistryHive->Hive, NewKey->KeyCellOffset); - NewKey->RegistryHive = RegistryHive; + NewKey->KeyCellOffset = RegistryHive->Hive.HiveHeader->RootCell; + NewKey->KeyCell = HvGetCell (&RegistryHive->Hive, NewKey->KeyCellOffset); + NewKey->RegistryHive = RegistryHive; - Status = RtlpCreateUnicodeString(&NewKey->Name, - SubName, NonPagedPool); - RtlFreeUnicodeString(&RemainingPath); - if (!NT_SUCCESS(Status)) + Status = RtlpCreateUnicodeString(&NewKey->Name, + SubName, NonPagedPool); + RtlFreeUnicodeString(&RemainingPath); + if (!NT_SUCCESS(Status)) { - DPRINT1("RtlpCreateUnicodeString() failed (Status %lx)\n", Status); - ObDereferenceObject (NewKey); - ObDereferenceObject (ParentKey); - return STATUS_INSUFFICIENT_RESOURCES; + DPRINT1("RtlpCreateUnicodeString() failed (Status %lx)\n", Status); + ObDereferenceObject (NewKey); + ObDereferenceObject (ParentKey); + return STATUS_INSUFFICIENT_RESOURCES; } - /* FN1 */ - ObReferenceObject (NewKey); + /* FN1 */ + ObReferenceObject (NewKey); - CmiAddKeyToList (ParentKey, NewKey); - ObDereferenceObject (ParentKey); + CmiAddKeyToList (ParentKey, NewKey); + ObDereferenceObject (ParentKey); VERIFY_KEY_OBJECT(NewKey); @@ -350,406 +351,401 @@ CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes, static NTSTATUS CmiInitControlSetLink (VOID) { - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING ControlSetKeyName = RTL_CONSTANT_STRING( - L"\\Registry\\Machine\\SYSTEM\\ControlSet001"); - UNICODE_STRING ControlSetLinkName = RTL_CONSTANT_STRING( - L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet"); - UNICODE_STRING ControlSetValueName = RTL_CONSTANT_STRING(L"SymbolicLinkValue"); - HANDLE KeyHandle; - NTSTATUS Status; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING ControlSetKeyName = RTL_CONSTANT_STRING( + L"\\Registry\\Machine\\SYSTEM\\ControlSet001"); + UNICODE_STRING ControlSetLinkName = RTL_CONSTANT_STRING( + L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet"); + UNICODE_STRING ControlSetValueName = RTL_CONSTANT_STRING(L"SymbolicLinkValue"); + HANDLE KeyHandle; + NTSTATUS Status; - /* Create 'ControlSet001' key */ - InitializeObjectAttributes (&ObjectAttributes, - &ControlSetKeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = ZwCreateKey (&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - if (!NT_SUCCESS(Status)) + /* Create 'ControlSet001' key */ + InitializeObjectAttributes (&ObjectAttributes, + &ControlSetKeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = ZwCreateKey (&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + if (!NT_SUCCESS(Status)) { - DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status); - return Status; + DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status); + return Status; } - ZwClose (KeyHandle); + ZwClose (KeyHandle); - /* Link 'CurrentControlSet' to 'ControlSet001' key */ - InitializeObjectAttributes (&ObjectAttributes, - &ControlSetLinkName, - OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_OPENLINK, - NULL, - NULL); - Status = ZwCreateKey (&KeyHandle, - KEY_ALL_ACCESS | KEY_CREATE_LINK, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, - NULL); - if (!NT_SUCCESS(Status)) + /* Link 'CurrentControlSet' to 'ControlSet001' key */ + InitializeObjectAttributes (&ObjectAttributes, + &ControlSetLinkName, + OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_OPENLINK, + NULL, + NULL); + Status = ZwCreateKey (&KeyHandle, + KEY_ALL_ACCESS | KEY_CREATE_LINK, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, + NULL); + if (!NT_SUCCESS(Status)) { - DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status); - return Status; + DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status); + return Status; } - Status = ZwSetValueKey (KeyHandle, - &ControlSetValueName, - 0, - REG_LINK, - (PVOID)ControlSetKeyName.Buffer, - ControlSetKeyName.Length); - if (!NT_SUCCESS(Status)) + Status = ZwSetValueKey (KeyHandle, + &ControlSetValueName, + 0, + REG_LINK, + (PVOID)ControlSetKeyName.Buffer, + ControlSetKeyName.Length); + if (!NT_SUCCESS(Status)) { - DPRINT1 ("ZwSetValueKey() failed (Status %lx)\n", Status); + DPRINT1 ("ZwSetValueKey() failed (Status %lx)\n", Status); } - ZwClose (KeyHandle); + ZwClose (KeyHandle); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } - NTSTATUS CmiInitHives(BOOLEAN SetupBoot) { - PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; - OBJECT_ATTRIBUTES ObjectAttributes; - UNICODE_STRING FileName; - UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE"); - UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath"); - HANDLE KeyHandle; + PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING FileName; + UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE"); + UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath"); + HANDLE KeyHandle; - NTSTATUS Status; + NTSTATUS Status; - WCHAR ConfigPath[MAX_PATH]; + WCHAR ConfigPath[MAX_PATH]; - ULONG BufferSize; - ULONG ResultSize; - PWSTR EndPtr; + ULONG BufferSize; + ULONG ResultSize; + PWSTR EndPtr; + DPRINT("CmiInitHives() called\n"); - DPRINT("CmiInitHives() called\n"); - - if (SetupBoot == TRUE) + if (SetupBoot == TRUE) { - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = ZwOpenKey(&KeyHandle, - KEY_ALL_ACCESS, - &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status); - return(Status); - } + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = ZwOpenKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status); + return(Status); + } - BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096; - ValueInfo = ExAllocatePool(PagedPool, - BufferSize); - if (ValueInfo == NULL) - { - ZwClose(KeyHandle); - return(STATUS_INSUFFICIENT_RESOURCES); - } + BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096; + ValueInfo = ExAllocatePool(PagedPool, BufferSize); + if (ValueInfo == NULL) + { + ZwClose(KeyHandle); + return(STATUS_INSUFFICIENT_RESOURCES); + } - Status = ZwQueryValueKey(KeyHandle, - &ValueName, - KeyValuePartialInformation, - ValueInfo, - BufferSize, - &ResultSize); - ZwClose(KeyHandle); - if (!NT_SUCCESS(Status)) - { - ExFreePool(ValueInfo); - return(Status); - } + Status = ZwQueryValueKey(KeyHandle, + &ValueName, + KeyValuePartialInformation, + ValueInfo, + BufferSize, + &ResultSize); + ZwClose(KeyHandle); + if (!NT_SUCCESS(Status)) + { + ExFreePool(ValueInfo); + return(Status); + } - RtlCopyMemory(ConfigPath, - ValueInfo->Data, - ValueInfo->DataLength); - ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = (WCHAR)0; - ExFreePool(ValueInfo); + RtlCopyMemory(ConfigPath, + ValueInfo->Data, + ValueInfo->DataLength); + ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = (WCHAR)0; + ExFreePool(ValueInfo); } - else + else { - wcscpy(ConfigPath, L"\\SystemRoot"); + wcscpy(ConfigPath, L"\\SystemRoot"); } - wcscat(ConfigPath, L"\\system32\\config"); + wcscat(ConfigPath, L"\\system32\\config"); - DPRINT("ConfigPath: %S\n", ConfigPath); + DPRINT("ConfigPath: %S\n", ConfigPath); - EndPtr = ConfigPath + wcslen(ConfigPath); + EndPtr = ConfigPath + wcslen(ConfigPath); - /* FIXME: Save boot log */ + /* FIXME: Save boot log */ - /* Connect the SYSTEM hive only if it has been created */ - if (SetupBoot == TRUE) + /* Connect the SYSTEM hive only if it has been created */ + if (SetupBoot == TRUE) { - wcscpy(EndPtr, REG_SYSTEM_FILE_NAME); - DPRINT ("ConfigPath: %S\n", ConfigPath); + wcscpy(EndPtr, REG_SYSTEM_FILE_NAME); + DPRINT ("ConfigPath: %S\n", ConfigPath); - RtlInitUnicodeString (&KeyName, - REG_SYSTEM_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); + RtlInitUnicodeString (&KeyName, + REG_SYSTEM_KEY_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - RtlInitUnicodeString (&FileName, - ConfigPath); - Status = CmiLoadHive (&ObjectAttributes, - &FileName, - 0); - if (!NT_SUCCESS(Status)) - { - DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); - return Status; - } + RtlInitUnicodeString (&FileName, + ConfigPath); + Status = CmiLoadHive (&ObjectAttributes, + &FileName, + 0); + if (!NT_SUCCESS(Status)) + { + DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); + return Status; + } - Status = CmiInitControlSetLink (); - if (!NT_SUCCESS(Status)) - { - DPRINT1("CmiInitControlSetLink() failed (Status %lx)\n", Status); - return(Status); - } + Status = CmiInitControlSetLink (); + if (!NT_SUCCESS(Status)) + { + DPRINT1("CmiInitControlSetLink() failed (Status %lx)\n", Status); + return(Status); + } } - /* Connect the SOFTWARE hive */ - wcscpy(EndPtr, REG_SOFTWARE_FILE_NAME); - RtlInitUnicodeString (&FileName, - ConfigPath); - DPRINT ("ConfigPath: %S\n", ConfigPath); + /* Connect the SOFTWARE hive */ + wcscpy(EndPtr, REG_SOFTWARE_FILE_NAME); + RtlInitUnicodeString (&FileName, + ConfigPath); + DPRINT ("ConfigPath: %S\n", ConfigPath); - RtlInitUnicodeString (&KeyName, - REG_SOFTWARE_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); + RtlInitUnicodeString (&KeyName, + REG_SOFTWARE_KEY_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); - Status = CmiLoadHive (&ObjectAttributes, - &FileName, - 0); - if (!NT_SUCCESS(Status)) + Status = CmiLoadHive (&ObjectAttributes, + &FileName, + 0); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); - return(Status); + DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); + return(Status); } - /* Connect the SAM hive */ - wcscpy(EndPtr, REG_SAM_FILE_NAME); - RtlInitUnicodeString (&FileName, - ConfigPath); - DPRINT ("ConfigPath: %S\n", ConfigPath); + /* Connect the SAM hive */ + wcscpy(EndPtr, REG_SAM_FILE_NAME); + RtlInitUnicodeString (&FileName, + ConfigPath); + DPRINT ("ConfigPath: %S\n", ConfigPath); - RtlInitUnicodeString (&KeyName, - REG_SAM_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = CmiLoadHive (&ObjectAttributes, - &FileName, - 0); - if (!NT_SUCCESS(Status)) + RtlInitUnicodeString (&KeyName, + REG_SAM_KEY_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = CmiLoadHive (&ObjectAttributes, + &FileName, + 0); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); - return(Status); + DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); + return(Status); } - /* Connect the SECURITY hive */ - wcscpy(EndPtr, REG_SEC_FILE_NAME); - RtlInitUnicodeString (&FileName, - ConfigPath); - DPRINT ("ConfigPath: %S\n", ConfigPath); + /* Connect the SECURITY hive */ + wcscpy(EndPtr, REG_SEC_FILE_NAME); + RtlInitUnicodeString (&FileName, + ConfigPath); + DPRINT ("ConfigPath: %S\n", ConfigPath); - RtlInitUnicodeString (&KeyName, - REG_SEC_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = CmiLoadHive (&ObjectAttributes, - &FileName, - 0); - if (!NT_SUCCESS(Status)) + RtlInitUnicodeString (&KeyName, + REG_SEC_KEY_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = CmiLoadHive (&ObjectAttributes, + &FileName, + 0); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); - return(Status); + DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); + return(Status); } - /* Connect the DEFAULT hive */ - wcscpy(EndPtr, REG_DEFAULT_USER_FILE_NAME); - RtlInitUnicodeString (&FileName, - ConfigPath); - DPRINT ("ConfigPath: %S\n", ConfigPath); + /* Connect the DEFAULT hive */ + wcscpy(EndPtr, REG_DEFAULT_USER_FILE_NAME); + RtlInitUnicodeString (&FileName, + ConfigPath); + DPRINT ("ConfigPath: %S\n", ConfigPath); - RtlInitUnicodeString (&KeyName, - REG_DEFAULT_USER_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = CmiLoadHive (&ObjectAttributes, - &FileName, - 0); - if (!NT_SUCCESS(Status)) + RtlInitUnicodeString (&KeyName, + REG_DEFAULT_USER_KEY_NAME); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = CmiLoadHive (&ObjectAttributes, + &FileName, + 0); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); - return(Status); + DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); + return(Status); } -// CmiCheckRegistry(TRUE); + //CmiCheckRegistry(TRUE); - /* Start automatic hive synchronization */ - KeInitializeDpc(&CmiHiveSyncDpc, - CmiHiveSyncDpcRoutine, - NULL); - KeInitializeTimer(&CmiHiveSyncTimer); - CmiHiveSyncEnabled = TRUE; + /* Start automatic hive synchronization */ + KeInitializeDpc(&CmiHiveSyncDpc, + CmiHiveSyncDpcRoutine, + NULL); + KeInitializeTimer(&CmiHiveSyncTimer); + CmiHiveSyncEnabled = TRUE; - DPRINT("CmiInitHives() done\n"); + DPRINT("CmiInitHives() done\n"); - return(STATUS_SUCCESS); + return(STATUS_SUCCESS); } - VOID CmShutdownRegistry(VOID) { - PEREGISTRY_HIVE Hive; - PLIST_ENTRY Entry; + PEREGISTRY_HIVE Hive; + PLIST_ENTRY Entry; - DPRINT("CmShutdownRegistry() called\n"); + DPRINT("CmShutdownRegistry() called\n"); - /* Stop automatic hive synchronization */ - CmiHiveSyncEnabled = FALSE; + /* Stop automatic hive synchronization */ + CmiHiveSyncEnabled = FALSE; - /* Cancel pending hive synchronization */ - if (CmiHiveSyncPending == TRUE) + /* Cancel pending hive synchronization */ + if (CmiHiveSyncPending == TRUE) { - KeCancelTimer(&CmiHiveSyncTimer); - CmiHiveSyncPending = FALSE; + KeCancelTimer(&CmiHiveSyncTimer); + CmiHiveSyncPending = FALSE; } - /* Lock the hive list */ + /* Lock the hive list */ ExAcquirePushLockExclusive(&CmpHiveListHeadLock); - Entry = CmpHiveListHead.Flink; - while (Entry != &CmpHiveListHead) + Entry = CmpHiveListHead.Flink; + while (Entry != &CmpHiveListHead) { - Hive = CONTAINING_RECORD(Entry, EREGISTRY_HIVE, HiveList); + Hive = CONTAINING_RECORD(Entry, EREGISTRY_HIVE, HiveList); - if (!(IsNoFileHive(Hive) || IsNoSynchHive(Hive))) - { - /* Flush non-volatile hive */ - CmiFlushRegistryHive(Hive); - } + if (!(IsNoFileHive(Hive) || IsNoSynchHive(Hive))) + { + /* Flush non-volatile hive */ + CmiFlushRegistryHive(Hive); + } - Entry = Entry->Flink; + Entry = Entry->Flink; } /* Release the lock */ ExReleasePushLock(&CmpHiveListHeadLock); - DPRINT("CmShutdownRegistry() done\n"); + DPRINT("CmShutdownRegistry() done\n"); } - -VOID STDCALL +VOID +NTAPI CmiHiveSyncRoutine(PVOID DeferredContext) { - PEREGISTRY_HIVE Hive; - PLIST_ENTRY Entry; + PEREGISTRY_HIVE Hive; + PLIST_ENTRY Entry; - DPRINT("CmiHiveSyncRoutine() called\n"); + DPRINT("CmiHiveSyncRoutine() called\n"); - CmiHiveSyncPending = FALSE; + CmiHiveSyncPending = FALSE; - /* Lock the hive list */ + /* Lock the hive list */ ExAcquirePushLockExclusive(&CmpHiveListHeadLock); - Entry = CmpHiveListHead.Flink; - while (Entry != &CmpHiveListHead) + Entry = CmpHiveListHead.Flink; + while (Entry != &CmpHiveListHead) { - Hive = CONTAINING_RECORD(Entry, EREGISTRY_HIVE, HiveList); + Hive = CONTAINING_RECORD(Entry, EREGISTRY_HIVE, HiveList); - if (!(IsNoFileHive(Hive) || IsNoSynchHive(Hive))) - { - /* Flush non-volatile hive */ - CmiFlushRegistryHive(Hive); - } + if (!(IsNoFileHive(Hive) || IsNoSynchHive(Hive))) + { + /* Flush non-volatile hive */ + CmiFlushRegistryHive(Hive); + } - Entry = Entry->Flink; + Entry = Entry->Flink; } /* Release the lock */ ExReleasePushLock(&CmpHiveListHeadLock); - DPRINT("DeferredContext 0x%p\n", DeferredContext); - ExFreePool(DeferredContext); + DPRINT("DeferredContext 0x%p\n", DeferredContext); + ExFreePool(DeferredContext); - DPRINT("CmiHiveSyncRoutine() done\n"); + DPRINT("CmiHiveSyncRoutine() done\n"); } - -static VOID STDCALL +static VOID +NTAPI CmiHiveSyncDpcRoutine(PKDPC Dpc, - PVOID DeferredContext, - PVOID SystemArgument1, - PVOID SystemArgument2) + PVOID DeferredContext, + PVOID SystemArgument1, + PVOID SystemArgument2) { - PWORK_QUEUE_ITEM WorkQueueItem; + PWORK_QUEUE_ITEM WorkQueueItem; - WorkQueueItem = ExAllocatePool(NonPagedPool, - sizeof(WORK_QUEUE_ITEM)); - if (WorkQueueItem == NULL) + WorkQueueItem = ExAllocatePool(NonPagedPool, + sizeof(WORK_QUEUE_ITEM)); + if (WorkQueueItem == NULL) { - DbgPrint("Failed to allocate work item\n"); - return; + DPRINT1("Failed to allocate work item\n"); + return; } - ExInitializeWorkItem(WorkQueueItem, - CmiHiveSyncRoutine, - WorkQueueItem); + ExInitializeWorkItem(WorkQueueItem, + CmiHiveSyncRoutine, + WorkQueueItem); - DPRINT("DeferredContext 0x%p\n", WorkQueueItem); - ExQueueWorkItem(WorkQueueItem, - CriticalWorkQueue); + DPRINT("DeferredContext 0x%p\n", WorkQueueItem); + ExQueueWorkItem(WorkQueueItem, + CriticalWorkQueue); } - VOID CmiSyncHives(VOID) { - LARGE_INTEGER Timeout; + LARGE_INTEGER Timeout; - DPRINT("CmiSyncHives() called\n"); + DPRINT("CmiSyncHives() called\n"); if (CmiHiveSyncEnabled == FALSE || - CmiHiveSyncPending == TRUE) - return; + CmiHiveSyncPending == TRUE) + return; - CmiHiveSyncPending = TRUE; + CmiHiveSyncPending = TRUE; - Timeout.QuadPart = (LONGLONG)-50000000; - KeSetTimer(&CmiHiveSyncTimer, - Timeout, - &CmiHiveSyncDpc); + Timeout.QuadPart = (LONGLONG)-50000000; + KeSetTimer(&CmiHiveSyncTimer, + Timeout, + &CmiHiveSyncDpc); } /* EOF */ diff --git a/reactos/ntoskrnl/cm/regobj.c b/reactos/ntoskrnl/cm/regobj.c index 879cc7d336c..68e2374552a 100644 --- a/reactos/ntoskrnl/cm/regobj.c +++ b/reactos/ntoskrnl/cm/regobj.c @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * PROJECT: ReactOS Kernel * COPYRIGHT: GPL - See COPYING in the top level directory * FILE: ntoskrnl/cm/regobj.c @@ -23,8 +22,8 @@ extern ULONG CmiTimer; static NTSTATUS CmiGetLinkTarget(PEREGISTRY_HIVE RegistryHive, - PCM_KEY_NODE KeyCell, - PUNICODE_STRING TargetPath); + PCM_KEY_NODE KeyCell, + PUNICODE_STRING TargetPath); /* FUNCTONS *****************************************************************/ @@ -341,7 +340,8 @@ Next: return STATUS_SUCCESS; } -NTSTATUS STDCALL +NTSTATUS +NTAPI CmpParseKey(IN PVOID ParsedObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, @@ -353,524 +353,519 @@ CmpParseKey(IN PVOID ParsedObject, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *NextObject) { - HCELL_INDEX BlockOffset; - PKEY_OBJECT FoundObject; - PKEY_OBJECT ParsedKey; - PCM_KEY_NODE SubKeyCell; - NTSTATUS Status; - PWSTR StartPtr; - PWSTR EndPtr; - ULONG Length; - UNICODE_STRING LinkPath; - UNICODE_STRING TargetPath; - UNICODE_STRING KeyName; - PWSTR *Path = &RemainingName->Buffer; + HCELL_INDEX BlockOffset; + PKEY_OBJECT FoundObject; + PKEY_OBJECT ParsedKey; + PCM_KEY_NODE SubKeyCell; + NTSTATUS Status; + PWSTR StartPtr; + PWSTR EndPtr; + ULONG Length; + UNICODE_STRING LinkPath; + UNICODE_STRING TargetPath; + UNICODE_STRING KeyName; + PWSTR *Path = &RemainingName->Buffer; - ParsedKey = ParsedObject; + ParsedKey = ParsedObject; - VERIFY_KEY_OBJECT(ParsedKey); + VERIFY_KEY_OBJECT(ParsedKey); - *NextObject = NULL; + *NextObject = NULL; - if ((*Path) == NULL) + if ((*Path) == NULL) { - DPRINT("*Path is NULL\n"); - return STATUS_UNSUCCESSFUL; + DPRINT("*Path is NULL\n"); + return STATUS_UNSUCCESSFUL; } - DPRINT("Path '%S'\n", *Path); + DPRINT("Path '%S'\n", *Path); - /* Extract relevant path name */ - StartPtr = *Path; - if (*StartPtr == L'\\') - StartPtr++; + /* Extract relevant path name */ + StartPtr = *Path; + if (*StartPtr == L'\\') + StartPtr++; - EndPtr = wcschr(StartPtr, L'\\'); - if (EndPtr != NULL) - Length = ((PCHAR)EndPtr - (PCHAR)StartPtr) / sizeof(WCHAR); - else - Length = wcslen(StartPtr); + EndPtr = wcschr(StartPtr, L'\\'); + if (EndPtr != NULL) + Length = ((PCHAR)EndPtr - (PCHAR)StartPtr) / sizeof(WCHAR); + else + Length = wcslen(StartPtr); + KeyName.Length = (USHORT)Length * sizeof(WCHAR); + KeyName.MaximumLength = (USHORT)KeyName.Length + sizeof(WCHAR); + KeyName.Buffer = ExAllocatePool(NonPagedPool, + KeyName.MaximumLength); + RtlCopyMemory(KeyName.Buffer, + StartPtr, + KeyName.Length); + KeyName.Buffer[KeyName.Length / sizeof(WCHAR)] = 0; - KeyName.Length = (USHORT)Length * sizeof(WCHAR); - KeyName.MaximumLength = (USHORT)KeyName.Length + sizeof(WCHAR); - KeyName.Buffer = ExAllocatePool(NonPagedPool, - KeyName.MaximumLength); - RtlCopyMemory(KeyName.Buffer, - StartPtr, - KeyName.Length); - KeyName.Buffer[KeyName.Length / sizeof(WCHAR)] = 0; + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - - Status = CmiScanKeyList(ParsedKey, - &KeyName, - Attributes, - &FoundObject); - if (!NT_SUCCESS(Status)) - { - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - RtlFreeUnicodeString(&KeyName); - return Status; - } - if (FoundObject == NULL) + Status = CmiScanKeyList(ParsedKey, + &KeyName, + Attributes, + &FoundObject); + if (!NT_SUCCESS(Status)) { - Status = CmiScanForSubKey(ParsedKey->RegistryHive, - ParsedKey->KeyCell, - &SubKeyCell, - &BlockOffset, - &KeyName, - 0, - Attributes); - if (!NT_SUCCESS(Status)) + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + RtlFreeUnicodeString(&KeyName); + return Status; + } + if (FoundObject == NULL) + { + Status = CmiScanForSubKey(ParsedKey->RegistryHive, + ParsedKey->KeyCell, + &SubKeyCell, + &BlockOffset, + &KeyName, + 0, + Attributes); + if (!NT_SUCCESS(Status)) { - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - RtlFreeUnicodeString(&KeyName); - return(STATUS_UNSUCCESSFUL); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + RtlFreeUnicodeString(&KeyName); + return(STATUS_UNSUCCESSFUL); } - if ((SubKeyCell->Flags & REG_KEY_LINK_CELL) && - !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL))) + if ((SubKeyCell->Flags & REG_KEY_LINK_CELL) && + !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL))) { - RtlInitUnicodeString(&LinkPath, NULL); - Status = CmiGetLinkTarget(ParsedKey->RegistryHive, - SubKeyCell, - &LinkPath); - if (NT_SUCCESS(Status)) + RtlInitUnicodeString(&LinkPath, NULL); + Status = CmiGetLinkTarget(ParsedKey->RegistryHive, + SubKeyCell, + &LinkPath); + if (NT_SUCCESS(Status)) { - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); - DPRINT("LinkPath '%wZ'\n", &LinkPath); + DPRINT("LinkPath '%wZ'\n", &LinkPath); - /* build new FullPath for reparsing */ - TargetPath.MaximumLength = LinkPath.MaximumLength; - if (EndPtr != NULL) + /* build new FullPath for reparsing */ + TargetPath.MaximumLength = LinkPath.MaximumLength; + if (EndPtr != NULL) { - TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR)); + TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR)); } - TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); - TargetPath.Buffer = ExAllocatePool(NonPagedPool, - TargetPath.MaximumLength); - wcscpy(TargetPath.Buffer, LinkPath.Buffer); - if (EndPtr != NULL) + TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); + TargetPath.Buffer = ExAllocatePool(NonPagedPool, + TargetPath.MaximumLength); + wcscpy(TargetPath.Buffer, LinkPath.Buffer); + if (EndPtr != NULL) { - wcscat(TargetPath.Buffer, EndPtr); + wcscat(TargetPath.Buffer, EndPtr); } - RtlFreeUnicodeString(FullPath); - RtlFreeUnicodeString(&LinkPath); - FullPath->Length = TargetPath.Length; - FullPath->MaximumLength = TargetPath.MaximumLength; - FullPath->Buffer = TargetPath.Buffer; + RtlFreeUnicodeString(FullPath); + RtlFreeUnicodeString(&LinkPath); + FullPath->Length = TargetPath.Length; + FullPath->MaximumLength = TargetPath.MaximumLength; + FullPath->Buffer = TargetPath.Buffer; - DPRINT("FullPath '%wZ'\n", FullPath); + DPRINT("FullPath '%wZ'\n", FullPath); - /* reinitialize Path for reparsing */ - *Path = FullPath->Buffer; + /* reinitialize Path for reparsing */ + *Path = FullPath->Buffer; - *NextObject = NULL; + *NextObject = NULL; - RtlFreeUnicodeString(&KeyName); - return(STATUS_REPARSE); - } + RtlFreeUnicodeString(&KeyName); + return(STATUS_REPARSE); + } } - /* Create new key object and put into linked list */ - DPRINT("CmpParseKey: %S\n", *Path); - Status = ObCreateObject(KernelMode, - CmpKeyObjectType, - NULL, - KernelMode, - NULL, - sizeof(KEY_OBJECT), - 0, - 0, - (PVOID*)&FoundObject); - if (!NT_SUCCESS(Status)) + /* Create new key object and put into linked list */ + DPRINT("CmpParseKey: %S\n", *Path); + Status = ObCreateObject(KernelMode, + CmpKeyObjectType, + NULL, + KernelMode, + NULL, + sizeof(KEY_OBJECT), + 0, + 0, + (PVOID*)&FoundObject); + if (!NT_SUCCESS(Status)) { - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - RtlFreeUnicodeString(&KeyName); - return(Status); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + RtlFreeUnicodeString(&KeyName); + return(Status); } #if 0 - DPRINT("Inserting Key into Object Tree\n"); - Status = ObInsertObject((PVOID)FoundObject, - NULL, - KEY_ALL_ACCESS, - 0, - NULL, - NULL); - DPRINT("Status %x\n", Status); + DPRINT("Inserting Key into Object Tree\n"); + Status = ObInsertObject((PVOID)FoundObject, + NULL, + KEY_ALL_ACCESS, + 0, + NULL, + NULL); + DPRINT("Status %x\n", Status); #else -/* Free the create information */ -ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo); -OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo = NULL; + /* Free the create information */ + ObpFreeAndReleaseCapturedAttributes(OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo); + OBJECT_TO_OBJECT_HEADER(FoundObject)->ObjectCreateInfo = NULL; #endif - /* Add the keep-alive reference */ - ObReferenceObject(FoundObject); + /* Add the keep-alive reference */ + ObReferenceObject(FoundObject); - FoundObject->Flags = 0; - FoundObject->KeyCell = SubKeyCell; - FoundObject->KeyCellOffset = BlockOffset; - FoundObject->RegistryHive = ParsedKey->RegistryHive; - InsertTailList(&CmiKeyObjectListHead, &FoundObject->ListEntry); - RtlpCreateUnicodeString(&FoundObject->Name, KeyName.Buffer, NonPagedPool); - CmiAddKeyToList(ParsedKey, FoundObject); - DPRINT("Created object 0x%p\n", FoundObject); + FoundObject->Flags = 0; + FoundObject->KeyCell = SubKeyCell; + FoundObject->KeyCellOffset = BlockOffset; + FoundObject->RegistryHive = ParsedKey->RegistryHive; + InsertTailList(&CmiKeyObjectListHead, &FoundObject->ListEntry); + RtlpCreateUnicodeString(&FoundObject->Name, KeyName.Buffer, NonPagedPool); + CmiAddKeyToList(ParsedKey, FoundObject); + DPRINT("Created object 0x%p\n", FoundObject); } - else + else { - if ((FoundObject->KeyCell->Flags & REG_KEY_LINK_CELL) && - !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL))) - { - DPRINT("Found link\n"); + if ((FoundObject->KeyCell->Flags & REG_KEY_LINK_CELL) && + !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL))) + { + DPRINT("Found link\n"); - RtlInitUnicodeString(&LinkPath, NULL); - Status = CmiGetLinkTarget(FoundObject->RegistryHive, - FoundObject->KeyCell, - &LinkPath); - if (NT_SUCCESS(Status)) - { - DPRINT("LinkPath '%wZ'\n", &LinkPath); + RtlInitUnicodeString(&LinkPath, NULL); + Status = CmiGetLinkTarget(FoundObject->RegistryHive, + FoundObject->KeyCell, + &LinkPath); + if (NT_SUCCESS(Status)) + { + DPRINT("LinkPath '%wZ'\n", &LinkPath); - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); - ObDereferenceObject(FoundObject); + ObDereferenceObject(FoundObject); - /* build new FullPath for reparsing */ - TargetPath.MaximumLength = LinkPath.MaximumLength; - if (EndPtr != NULL) - { - TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR)); - } - TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); - TargetPath.Buffer = ExAllocatePool(NonPagedPool, - TargetPath.MaximumLength); - wcscpy(TargetPath.Buffer, LinkPath.Buffer); - if (EndPtr != NULL) - { - wcscat(TargetPath.Buffer, EndPtr); - } + /* build new FullPath for reparsing */ + TargetPath.MaximumLength = LinkPath.MaximumLength; + if (EndPtr != NULL) + { + TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR)); + } + TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); + TargetPath.Buffer = ExAllocatePool(NonPagedPool, + TargetPath.MaximumLength); + wcscpy(TargetPath.Buffer, LinkPath.Buffer); + if (EndPtr != NULL) + { + wcscat(TargetPath.Buffer, EndPtr); + } - RtlFreeUnicodeString(FullPath); - RtlFreeUnicodeString(&LinkPath); - FullPath->Length = TargetPath.Length; - FullPath->MaximumLength = TargetPath.MaximumLength; - FullPath->Buffer = TargetPath.Buffer; + RtlFreeUnicodeString(FullPath); + RtlFreeUnicodeString(&LinkPath); + FullPath->Length = TargetPath.Length; + FullPath->MaximumLength = TargetPath.MaximumLength; + FullPath->Buffer = TargetPath.Buffer; - DPRINT("FullPath '%wZ'\n", FullPath); + DPRINT("FullPath '%wZ'\n", FullPath); - /* reinitialize Path for reparsing */ - *Path = FullPath->Buffer; + /* reinitialize Path for reparsing */ + *Path = FullPath->Buffer; - *NextObject = NULL; + *NextObject = NULL; - RtlFreeUnicodeString(&KeyName); - return(STATUS_REPARSE); - } - } + RtlFreeUnicodeString(&KeyName); + return(STATUS_REPARSE); + } + } } - RemoveEntryList(&FoundObject->ListEntry); - InsertHeadList(&CmiKeyObjectListHead, &FoundObject->ListEntry); - FoundObject->TimeStamp = CmiTimer; + RemoveEntryList(&FoundObject->ListEntry); + InsertHeadList(&CmiKeyObjectListHead, &FoundObject->ListEntry); + FoundObject->TimeStamp = CmiTimer; - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); - DPRINT("CmpParseKey: %wZ\n", &FoundObject->Name); + DPRINT("CmpParseKey: %wZ\n", &FoundObject->Name); - *Path = EndPtr; + *Path = EndPtr; - VERIFY_KEY_OBJECT(FoundObject); + VERIFY_KEY_OBJECT(FoundObject); - *NextObject = FoundObject; + *NextObject = FoundObject; - RtlFreeUnicodeString(&KeyName); + RtlFreeUnicodeString(&KeyName); - return(STATUS_SUCCESS); + return(STATUS_SUCCESS); } -VOID STDCALL +VOID +NTAPI CmpDeleteKeyObject(PVOID DeletedObject) { - PKEY_OBJECT ParentKeyObject; - PKEY_OBJECT KeyObject; - REG_KEY_HANDLE_CLOSE_INFORMATION KeyHandleCloseInfo; - REG_POST_OPERATION_INFORMATION PostOperationInfo; - NTSTATUS Status; + PKEY_OBJECT ParentKeyObject; + PKEY_OBJECT KeyObject; + REG_KEY_HANDLE_CLOSE_INFORMATION KeyHandleCloseInfo; + REG_POST_OPERATION_INFORMATION PostOperationInfo; + NTSTATUS Status; - DPRINT("Delete key object (%p)\n", DeletedObject); + DPRINT("Delete key object (%p)\n", DeletedObject); - KeyObject = (PKEY_OBJECT) DeletedObject; - ParentKeyObject = KeyObject->ParentKey; + KeyObject = (PKEY_OBJECT) DeletedObject; + ParentKeyObject = KeyObject->ParentKey; - ObReferenceObject (ParentKeyObject); + ObReferenceObject (ParentKeyObject); - PostOperationInfo.Object = (PVOID)KeyObject; - KeyHandleCloseInfo.Object = (PVOID)KeyObject; - Status = CmiCallRegisteredCallbacks(RegNtPreKeyHandleClose, &KeyHandleCloseInfo); - if (!NT_SUCCESS(Status)) + PostOperationInfo.Object = (PVOID)KeyObject; + KeyHandleCloseInfo.Object = (PVOID)KeyObject; + Status = CmiCallRegisteredCallbacks(RegNtPreKeyHandleClose, &KeyHandleCloseInfo); + if (!NT_SUCCESS(Status)) { - PostOperationInfo.Status = Status; - CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose, &PostOperationInfo); - ObDereferenceObject (ParentKeyObject); - return; + PostOperationInfo.Status = Status; + CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose, &PostOperationInfo); + ObDereferenceObject (ParentKeyObject); + return; } - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - RemoveEntryList(&KeyObject->ListEntry); - RtlFreeUnicodeString(&KeyObject->Name); + RemoveEntryList(&KeyObject->ListEntry); + RtlFreeUnicodeString(&KeyObject->Name); - ASSERT((KeyObject->Flags & KO_MARKED_FOR_DELETE) == FALSE); + ASSERT((KeyObject->Flags & KO_MARKED_FOR_DELETE) == FALSE); - ObDereferenceObject (ParentKeyObject); + ObDereferenceObject (ParentKeyObject); - if (KeyObject->SizeOfSubKeys) + if (KeyObject->SizeOfSubKeys) { - ExFreePool(KeyObject->SubKeys); + ExFreePool(KeyObject->SubKeys); } - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - PostOperationInfo.Status = STATUS_SUCCESS; - CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose, &PostOperationInfo); + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + PostOperationInfo.Status = STATUS_SUCCESS; + CmiCallRegisteredCallbacks(RegNtPostKeyHandleClose, &PostOperationInfo); } -NTSTATUS STDCALL -CmpQueryKeyName (PVOID ObjectBody, - IN BOOLEAN HasName, - POBJECT_NAME_INFORMATION ObjectNameInfo, - ULONG Length, - PULONG ReturnLength, - IN KPROCESSOR_MODE PreviousMode) +NTSTATUS +NTAPI +CmpQueryKeyName(PVOID ObjectBody, + IN BOOLEAN HasName, + POBJECT_NAME_INFORMATION ObjectNameInfo, + ULONG Length, + PULONG ReturnLength, + IN KPROCESSOR_MODE PreviousMode) { - PKEY_OBJECT KeyObject; - NTSTATUS Status; + PKEY_OBJECT KeyObject; + NTSTATUS Status; - DPRINT ("CmpQueryKeyName() called\n"); + DPRINT ("CmpQueryKeyName() called\n"); - KeyObject = (PKEY_OBJECT)ObjectBody; + KeyObject = (PKEY_OBJECT)ObjectBody; - if (KeyObject->ParentKey != KeyObject) + if (KeyObject->ParentKey != KeyObject) { - Status = ObQueryNameString (KeyObject->ParentKey, - ObjectNameInfo, - Length, - ReturnLength); + Status = ObQueryNameString (KeyObject->ParentKey, + ObjectNameInfo, + Length, + ReturnLength); } - else + else { - /* KeyObject is the root key */ - Status = ObQueryNameString (OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(KeyObject))->Directory, - ObjectNameInfo, - Length, - ReturnLength); + /* KeyObject is the root key */ + Status = ObQueryNameString (OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(KeyObject))->Directory, + ObjectNameInfo, + Length, + ReturnLength); } - if (!NT_SUCCESS(Status) && Status != STATUS_INFO_LENGTH_MISMATCH) + if (!NT_SUCCESS(Status) && Status != STATUS_INFO_LENGTH_MISMATCH) { - return Status; + return Status; } - (*ReturnLength) += sizeof(WCHAR) + KeyObject->Name.Length; + (*ReturnLength) += sizeof(WCHAR) + KeyObject->Name.Length; - if (Status == STATUS_INFO_LENGTH_MISMATCH || *ReturnLength > Length) + if (Status == STATUS_INFO_LENGTH_MISMATCH || *ReturnLength > Length) { - return STATUS_INFO_LENGTH_MISMATCH; + return STATUS_INFO_LENGTH_MISMATCH; } - if (ObjectNameInfo->Name.Buffer == NULL) + if (ObjectNameInfo->Name.Buffer == NULL) { - ObjectNameInfo->Name.Buffer = (PWCHAR)(ObjectNameInfo + 1); - ObjectNameInfo->Name.Length = 0; - ObjectNameInfo->Name.MaximumLength = (USHORT)Length - sizeof(OBJECT_NAME_INFORMATION); + ObjectNameInfo->Name.Buffer = (PWCHAR)(ObjectNameInfo + 1); + ObjectNameInfo->Name.Length = 0; + ObjectNameInfo->Name.MaximumLength = (USHORT)Length - sizeof(OBJECT_NAME_INFORMATION); } + DPRINT ("Parent path: %wZ\n", ObjectNameInfo->Name); - DPRINT ("Parent path: %wZ\n", ObjectNameInfo->Name); + Status = RtlAppendUnicodeToString (&ObjectNameInfo->Name, + L"\\"); + if (!NT_SUCCESS (Status)) + return Status; + + Status = RtlAppendUnicodeStringToString (&ObjectNameInfo->Name, + &KeyObject->Name); + if (NT_SUCCESS (Status)) + { + DPRINT ("Total path: %wZ\n", &ObjectNameInfo->Name); + } - Status = RtlAppendUnicodeToString (&ObjectNameInfo->Name, - L"\\"); - if (!NT_SUCCESS (Status)) return Status; - - Status = RtlAppendUnicodeStringToString (&ObjectNameInfo->Name, - &KeyObject->Name); - if (NT_SUCCESS (Status)) - { - DPRINT ("Total path: %wZ\n", &ObjectNameInfo->Name); - } - - return Status; } - - VOID CmiAddKeyToList(PKEY_OBJECT ParentKey, - PKEY_OBJECT NewKey) + PKEY_OBJECT NewKey) { + DPRINT("ParentKey %.08x\n", ParentKey); - DPRINT("ParentKey %.08x\n", ParentKey); - - - if (ParentKey->SizeOfSubKeys <= ParentKey->SubKeyCounts) + if (ParentKey->SizeOfSubKeys <= ParentKey->SubKeyCounts) { - PKEY_OBJECT *tmpSubKeys = ExAllocatePool(NonPagedPool, - (ParentKey->SubKeyCounts + 1) * sizeof(ULONG)); + PKEY_OBJECT *tmpSubKeys = ExAllocatePool(NonPagedPool, + (ParentKey->SubKeyCounts + 1) * sizeof(ULONG)); - if (ParentKey->SubKeyCounts > 0) - { - RtlCopyMemory (tmpSubKeys, - ParentKey->SubKeys, - ParentKey->SubKeyCounts * sizeof(ULONG)); - } + if (ParentKey->SubKeyCounts > 0) + { + RtlCopyMemory (tmpSubKeys, + ParentKey->SubKeys, + ParentKey->SubKeyCounts * sizeof(ULONG)); + } - if (ParentKey->SubKeys) - ExFreePool(ParentKey->SubKeys); + if (ParentKey->SubKeys) + ExFreePool(ParentKey->SubKeys); - ParentKey->SubKeys = tmpSubKeys; - ParentKey->SizeOfSubKeys = ParentKey->SubKeyCounts + 1; + ParentKey->SubKeys = tmpSubKeys; + ParentKey->SizeOfSubKeys = ParentKey->SubKeyCounts + 1; } - /* FIXME: Please maintain the list in alphabetic order */ - /* to allow a dichotomic search */ - ParentKey->SubKeys[ParentKey->SubKeyCounts++] = NewKey; + /* FIXME: Please maintain the list in alphabetic order */ + /* to allow a dichotomic search */ + ParentKey->SubKeys[ParentKey->SubKeyCounts++] = NewKey; - DPRINT("Reference parent key: 0x%p\n", ParentKey); + DPRINT("Reference parent key: 0x%p\n", ParentKey); - ObReferenceObjectByPointer(ParentKey, - STANDARD_RIGHTS_REQUIRED, - CmpKeyObjectType, - KernelMode); - NewKey->ParentKey = ParentKey; + ObReferenceObjectByPointer(ParentKey, + STANDARD_RIGHTS_REQUIRED, + CmpKeyObjectType, + KernelMode); + NewKey->ParentKey = ParentKey; } NTSTATUS CmiScanKeyList(PKEY_OBJECT Parent, - PUNICODE_STRING KeyName, - ULONG Attributes, - PKEY_OBJECT* ReturnedObject) + PUNICODE_STRING KeyName, + ULONG Attributes, + PKEY_OBJECT* ReturnedObject) { - PKEY_OBJECT CurKey = NULL; - ULONG Index; + PKEY_OBJECT CurKey = NULL; + ULONG Index; - DPRINT("Scanning key list for: %wZ (Parent: %wZ)\n", - KeyName, &Parent->Name); + DPRINT("Scanning key list for: %wZ (Parent: %wZ)\n", + KeyName, &Parent->Name); - /* FIXME: if list maintained in alphabetic order, use dichotomic search */ - for (Index=0; Index < Parent->SubKeyCounts; Index++) + /* FIXME: if list maintained in alphabetic order, use dichotomic search */ + for (Index=0; Index < Parent->SubKeyCounts; Index++) { - CurKey = Parent->SubKeys[Index]; - if (Attributes & OBJ_CASE_INSENSITIVE) - { - DPRINT("Comparing %wZ and %wZ\n", KeyName, &CurKey->Name); - if ((KeyName->Length == CurKey->Name.Length) - && (_wcsicmp(KeyName->Buffer, CurKey->Name.Buffer) == 0)) - { - break; - } - } - else - { - if ((KeyName->Length == CurKey->Name.Length) - && (wcscmp(KeyName->Buffer, CurKey->Name.Buffer) == 0)) - { - break; - } - } + CurKey = Parent->SubKeys[Index]; + if (Attributes & OBJ_CASE_INSENSITIVE) + { + DPRINT("Comparing %wZ and %wZ\n", KeyName, &CurKey->Name); + if ((KeyName->Length == CurKey->Name.Length) + && (_wcsicmp(KeyName->Buffer, CurKey->Name.Buffer) == 0)) + { + break; + } + } + else + { + if ((KeyName->Length == CurKey->Name.Length) + && (wcscmp(KeyName->Buffer, CurKey->Name.Buffer) == 0)) + { + break; + } + } } - if (Index < Parent->SubKeyCounts) - { - if (CurKey->Flags & KO_MARKED_FOR_DELETE) - { - CHECKPOINT; + if (Index < Parent->SubKeyCounts) + { + if (CurKey->Flags & KO_MARKED_FOR_DELETE) + { + CHECKPOINT; + *ReturnedObject = NULL; + return STATUS_UNSUCCESSFUL; + } + ObReferenceObject(CurKey); + *ReturnedObject = CurKey; + } + else + { *ReturnedObject = NULL; - return STATUS_UNSUCCESSFUL; - } - ObReferenceObject(CurKey); - *ReturnedObject = CurKey; - } - else - { - *ReturnedObject = NULL; - } - return STATUS_SUCCESS; + } + return STATUS_SUCCESS; } - static NTSTATUS CmiGetLinkTarget(PEREGISTRY_HIVE RegistryHive, - PCM_KEY_NODE KeyCell, - PUNICODE_STRING TargetPath) + PCM_KEY_NODE KeyCell, + PUNICODE_STRING TargetPath) { - UNICODE_STRING LinkName = RTL_CONSTANT_STRING(L"SymbolicLinkValue"); - PCM_KEY_VALUE ValueCell; - PVOID DataCell; - NTSTATUS Status; + UNICODE_STRING LinkName = RTL_CONSTANT_STRING(L"SymbolicLinkValue"); + PCM_KEY_VALUE ValueCell; + PVOID DataCell; + NTSTATUS Status; - DPRINT("CmiGetLinkTarget() called\n"); + DPRINT("CmiGetLinkTarget() called\n"); - /* Get Value block of interest */ - Status = CmiScanKeyForValue(RegistryHive, - KeyCell, - &LinkName, - &ValueCell, - NULL); - if (!NT_SUCCESS(Status)) + /* Get Value block of interest */ + Status = CmiScanKeyForValue(RegistryHive, + KeyCell, + &LinkName, + &ValueCell, + NULL); + if (!NT_SUCCESS(Status)) { - DPRINT1("CmiScanKeyForValue() failed (Status %lx)\n", Status); - return(Status); + DPRINT1("CmiScanKeyForValue() failed (Status %lx)\n", Status); + return(Status); } - if (ValueCell->DataType != REG_LINK) + if (ValueCell->DataType != REG_LINK) { - DPRINT1("Type != REG_LINK\n!"); - return(STATUS_UNSUCCESSFUL); + DPRINT1("Type != REG_LINK\n!"); + return(STATUS_UNSUCCESSFUL); } - if (TargetPath->Buffer == NULL && TargetPath->MaximumLength == 0) + if (TargetPath->Buffer == NULL && TargetPath->MaximumLength == 0) { - TargetPath->Length = 0; - TargetPath->MaximumLength = (USHORT)ValueCell->DataSize + sizeof(WCHAR); - TargetPath->Buffer = ExAllocatePool(NonPagedPool, - TargetPath->MaximumLength); + TargetPath->Length = 0; + TargetPath->MaximumLength = (USHORT)ValueCell->DataSize + sizeof(WCHAR); + TargetPath->Buffer = ExAllocatePool(NonPagedPool, + TargetPath->MaximumLength); } - TargetPath->Length = min((USHORT)TargetPath->MaximumLength - sizeof(WCHAR), - (USHORT)ValueCell->DataSize); + TargetPath->Length = min((USHORT)TargetPath->MaximumLength - sizeof(WCHAR), + (USHORT)ValueCell->DataSize); - if (ValueCell->DataSize > 0) + if (ValueCell->DataSize > 0) { - DataCell = HvGetCell (&RegistryHive->Hive, ValueCell->DataOffset); - RtlCopyMemory(TargetPath->Buffer, - DataCell, - TargetPath->Length); - TargetPath->Buffer[TargetPath->Length / sizeof(WCHAR)] = 0; + DataCell = HvGetCell (&RegistryHive->Hive, ValueCell->DataOffset); + RtlCopyMemory(TargetPath->Buffer, + DataCell, + TargetPath->Length); + TargetPath->Buffer[TargetPath->Length / sizeof(WCHAR)] = 0; } - else + else { - RtlCopyMemory(TargetPath->Buffer, - &ValueCell->DataOffset, - TargetPath->Length); - TargetPath->Buffer[TargetPath->Length / sizeof(WCHAR)] = 0; + RtlCopyMemory(TargetPath->Buffer, + &ValueCell->DataOffset, + TargetPath->Length); + TargetPath->Buffer[TargetPath->Length / sizeof(WCHAR)] = 0; } - DPRINT("TargetPath '%wZ'\n", TargetPath); + DPRINT("TargetPath '%wZ'\n", TargetPath); - return(STATUS_SUCCESS); + return(STATUS_SUCCESS); } /* EOF */