Author: ion Date: Tue May 15 00:24:12 2007 New Revision: 26784
URL: http://svn.reactos.org/svn/reactos?rev=26784&view=rev Log: - Re-organize regobj.c so that new APIs are at the bottom. - Make NtDeleteKey delete the key in-line instead of waiting for the Ob callback.
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c trunk/reactos/ntoskrnl/cm/regobj.c
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/ntfunc.c?rev=26... ============================================================================== --- trunk/reactos/ntoskrnl/cm/ntfunc.c (original) +++ trunk/reactos/ntoskrnl/cm/ntfunc.c Tue May 15 00:24:12 2007 @@ -489,9 +489,28 @@ } else { - /* Set the marked for delete bit in the key object */ - KeyObject->Flags |= KO_MARKED_FOR_DELETE; - Status = STATUS_SUCCESS; + PKEY_OBJECT ParentKeyObject = KeyObject->ParentKey; + + if (!NT_SUCCESS(CmiRemoveKeyFromList(KeyObject))) + { + DPRINT1("Key not found in parent list ???\n"); + } + + CmiRemoveSubKey(KeyObject->RegistryHive, + ParentKeyObject, + KeyObject); + + KeQuerySystemTime (&ParentKeyObject->KeyCell->LastWriteTime); + HvMarkCellDirty(&ParentKeyObject->RegistryHive->Hive, + ParentKeyObject->KeyCellOffset); + + if (!IsNoFileHive (KeyObject->RegistryHive) || + !IsNoFileHive (ParentKeyObject->RegistryHive)) + { + CmiSyncHives (); + } + + Status = STATUS_SUCCESS; }
/* Release hive lock */ @@ -521,6 +540,274 @@ * CmpDeleteKeyObject() (in regobj.c) after all key-related structures * have been released. */ + + 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); + } + _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);*/ + + /* Capture all the info */ + DPRINT("Capturing Create Info\n"); + Status = ObpCaptureObjectAttributes(ObjectAttributes, + PreviousMode, + FALSE, + &ObjectCreateInfo, + &ObjectName); + if (!NT_SUCCESS(Status)) + { + DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); + return Status; + } + + if (ObjectName.Buffer && + ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] == '\') + { + ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; + ObjectName.Length -= sizeof(WCHAR); + ObjectName.MaximumLength -= sizeof(WCHAR); + } + + PostOpenKeyInfo.CompleteName = &ObjectName; + PreOpenKeyInfo.CompleteName = &ObjectName; + Status = CmiCallRegisteredCallbacks(RegNtPreOpenKey, &PreOpenKeyInfo); + if (!NT_SUCCESS(Status)) + { + PostOpenKeyInfo.Object = NULL; + PostOpenKeyInfo.Status = Status; + CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); + ObpReleaseCapturedAttributes(&ObjectCreateInfo); + if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); + return Status; + } + + + 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); + + if (Object) + { + ObDereferenceObject(Object); + } + + if (NT_SUCCESS(Status)) + { + _SEH_TRY + { + *KeyHandle = hKey; + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; + } + + return Status; +} + +/* + * NOTE: + * KeyObjectAttributes->RootDirectory specifies the handle to the parent key and + * KeyObjectAttributes->Name specifies the name of the key to load. + * Flags can be 0 or REG_NO_LAZY_FLUSH. + */ +NTSTATUS STDCALL +NtLoadKey2 (IN POBJECT_ATTRIBUTES KeyObjectAttributes, + IN POBJECT_ATTRIBUTES FileObjectAttributes, + IN ULONG Flags) +{ + NTSTATUS Status; + PAGED_CODE(); + DPRINT ("NtLoadKey2() called\n"); + +#if 0 + if (!SeSinglePrivilegeCheck (SeRestorePrivilege, ExGetPreviousMode ())) + return STATUS_PRIVILEGE_NOT_HELD; +#endif + + /* Acquire hive lock */ + KeEnterCriticalRegion(); + ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); + + Status = CmiLoadHive (KeyObjectAttributes, + FileObjectAttributes->ObjectName, + Flags); + if (!NT_SUCCESS (Status)) + { + DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); + } + + /* Release hive lock */ + ExReleaseResourceLite(&CmpRegistryLock); + KeLeaveCriticalRegion(); + + return Status; +} + +NTSTATUS STDCALL +NtInitializeRegistry (IN BOOLEAN SetUpBoot) +{ + NTSTATUS Status; + + PAGED_CODE(); + + if (CmiRegistryInitialized == TRUE) + return STATUS_ACCESS_DENIED; + + /* Save boot log file */ + IopSaveBootLogToFile(); + + Status = CmiInitHives (SetUpBoot); + + CmiRegistryInitialized = TRUE;
return Status; } @@ -636,215 +923,6 @@ 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); - } - _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);*/ - - /* Capture all the info */ - DPRINT("Capturing Create Info\n"); - Status = ObpCaptureObjectAttributes(ObjectAttributes, - PreviousMode, - FALSE, - &ObjectCreateInfo, - &ObjectName); - if (!NT_SUCCESS(Status)) - { - DPRINT("ObpCaptureObjectAttributes() failed (Status %lx)\n", Status); - return Status; - } - - if (ObjectName.Buffer && - ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] == '\') - { - ObjectName.Buffer[(ObjectName.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL; - ObjectName.Length -= sizeof(WCHAR); - ObjectName.MaximumLength -= sizeof(WCHAR); - } - - PostOpenKeyInfo.CompleteName = &ObjectName; - PreOpenKeyInfo.CompleteName = &ObjectName; - Status = CmiCallRegisteredCallbacks(RegNtPreOpenKey, &PreOpenKeyInfo); - if (!NT_SUCCESS(Status)) - { - PostOpenKeyInfo.Object = NULL; - PostOpenKeyInfo.Status = Status; - CmiCallRegisteredCallbacks (RegNtPostOpenKey, &PostOpenKeyInfo); - ObpReleaseCapturedAttributes(&ObjectCreateInfo); - if (ObjectName.Buffer) ObpFreeObjectNameBuffer(&ObjectName); - return Status; - } - - - 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); - - if (Object) - { - ObDereferenceObject(Object); - } - - if (NT_SUCCESS(Status)) - { - _SEH_TRY - { - *KeyHandle = hKey; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - - return Status; -} - NTSTATUS NTAPI NtQueryKey(IN HANDLE KeyHandle, @@ -1050,65 +1128,6 @@ ObDereferenceObject(KeyObject); CmiSyncHives(); return Status; -} - -/* - * NOTE: - * KeyObjectAttributes->RootDirectory specifies the handle to the parent key and - * KeyObjectAttributes->Name specifies the name of the key to load. - * Flags can be 0 or REG_NO_LAZY_FLUSH. - */ -NTSTATUS STDCALL -NtLoadKey2 (IN POBJECT_ATTRIBUTES KeyObjectAttributes, - IN POBJECT_ATTRIBUTES FileObjectAttributes, - IN ULONG Flags) -{ - NTSTATUS Status; - PAGED_CODE(); - DPRINT ("NtLoadKey2() called\n"); - -#if 0 - if (!SeSinglePrivilegeCheck (SeRestorePrivilege, ExGetPreviousMode ())) - return STATUS_PRIVILEGE_NOT_HELD; -#endif - - /* Acquire hive lock */ - KeEnterCriticalRegion(); - ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE); - - Status = CmiLoadHive (KeyObjectAttributes, - FileObjectAttributes->ObjectName, - Flags); - if (!NT_SUCCESS (Status)) - { - DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status); - } - - /* Release hive lock */ - ExReleaseResourceLite(&CmpRegistryLock); - KeLeaveCriticalRegion(); - - return Status; -} - -NTSTATUS STDCALL -NtInitializeRegistry (IN BOOLEAN SetUpBoot) -{ - NTSTATUS Status; - - PAGED_CODE(); - - if (CmiRegistryInitialized == TRUE) - return STATUS_ACCESS_DENIED; - - /* Save boot log file */ - IopSaveBootLogToFile(); - - Status = CmiInitHives (SetUpBoot); - - CmiRegistryInitialized = TRUE; - - return Status; }
NTSTATUS
Modified: trunk/reactos/ntoskrnl/cm/regobj.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/regobj.c?rev=26... ============================================================================== --- trunk/reactos/ntoskrnl/cm/regobj.c (original) +++ trunk/reactos/ntoskrnl/cm/regobj.c Tue May 15 00:24:12 2007 @@ -630,32 +630,16 @@ KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&CmpRegistryLock, TRUE);
- if (!NT_SUCCESS(CmiRemoveKeyFromList(KeyObject))) - { - DPRINT1("Key not found in parent list ???\n"); - } - RemoveEntryList(&KeyObject->ListEntry); RtlFreeUnicodeString(&KeyObject->Name);
- if (KeyObject->Flags & KO_MARKED_FOR_DELETE) - { - DPRINT("delete really key\n"); - - CmiRemoveSubKey(KeyObject->RegistryHive, - ParentKeyObject, - KeyObject); - - KeQuerySystemTime (&ParentKeyObject->KeyCell->LastWriteTime); - HvMarkCellDirty (&ParentKeyObject->RegistryHive->Hive, - ParentKeyObject->KeyCellOffset); - - if (!IsNoFileHive (KeyObject->RegistryHive) || - !IsNoFileHive (ParentKeyObject->RegistryHive)) - { - CmiSyncHives (); - } - } + if (!NT_SUCCESS(CmiRemoveKeyFromList(KeyObject))) + { + DPRINT1("Key not found in parent list ???\n"); + } + + + ASSERT((KeyObject->Flags & KO_MARKED_FOR_DELETE) == FALSE);
ObDereferenceObject (ParentKeyObject);