2007-11-02 23:12:22 +00:00
|
|
|
/*
|
2023-09-06 12:53:53 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Configuration Manager - Internal Registry APIs
|
|
|
|
* PROGRAMMERS: Alex Ionescu <alex.ionescu@reactos.org>
|
2007-11-02 23:12:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include "ntoskrnl.h"
|
2023-09-06 12:53:53 +00:00
|
|
|
#define NDEBUG
|
2007-11-02 23:12:22 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
|
|
|
KTIMER CmpLazyFlushTimer;
|
|
|
|
KDPC CmpLazyFlushDpc;
|
|
|
|
WORK_QUEUE_ITEM CmpLazyWorkItem;
|
|
|
|
KTIMER CmpEnableLazyFlushTimer;
|
|
|
|
KDPC CmpEnableLazyFlushDpc;
|
|
|
|
BOOLEAN CmpLazyFlushPending;
|
|
|
|
BOOLEAN CmpForceForceFlush;
|
|
|
|
BOOLEAN CmpHoldLazyFlush = TRUE;
|
|
|
|
ULONG CmpLazyFlushIntervalInSeconds = 5;
|
2024-08-11 14:39:28 +00:00
|
|
|
ULONG CmpLazyFlushHiveCount = 7;
|
2007-11-02 23:12:22 +00:00
|
|
|
ULONG CmpLazyFlushCount = 1;
|
|
|
|
LONG CmpFlushStarveWriters;
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2014-01-23 21:06:48 +00:00
|
|
|
CmpDoFlushNextHive(_In_ BOOLEAN ForceFlush,
|
|
|
|
_Out_ PBOOLEAN Error,
|
|
|
|
_Out_ PULONG DirtyCount)
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PLIST_ENTRY NextEntry;
|
|
|
|
PCMHIVE CmHive;
|
2012-12-19 23:49:13 +00:00
|
|
|
BOOLEAN Result;
|
2007-11-02 23:12:22 +00:00
|
|
|
ULONG HiveCount = CmpLazyFlushHiveCount;
|
|
|
|
|
|
|
|
/* Set Defaults */
|
|
|
|
*Error = FALSE;
|
|
|
|
*DirtyCount = 0;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Don't do anything if we're not supposed to */
|
|
|
|
if (CmpNoWrite) return TRUE;
|
|
|
|
|
|
|
|
/* Make sure we have to flush at least one hive */
|
|
|
|
if (!HiveCount) HiveCount = 1;
|
|
|
|
|
|
|
|
/* Acquire the list lock and loop */
|
|
|
|
ExAcquirePushLockShared(&CmpHiveListHeadLock);
|
|
|
|
NextEntry = CmpHiveListHead.Flink;
|
2014-01-23 21:06:48 +00:00
|
|
|
while ((NextEntry != &CmpHiveListHead) && HiveCount)
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
/* Get the hive and check if we should flush it */
|
|
|
|
CmHive = CONTAINING_RECORD(NextEntry, CMHIVE, HiveList);
|
|
|
|
if (!(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH) &&
|
|
|
|
(CmHive->FlushCount != CmpLazyFlushCount))
|
|
|
|
{
|
2024-08-11 14:39:28 +00:00
|
|
|
/* Great success! */
|
2007-11-02 23:12:22 +00:00
|
|
|
Result = TRUE;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2014-01-23 21:06:48 +00:00
|
|
|
/* One less to flush */
|
|
|
|
HiveCount--;
|
|
|
|
|
|
|
|
/* Ignore clean or volatile hives */
|
|
|
|
if ((!CmHive->Hive.DirtyCount && !ForceFlush) ||
|
2007-11-02 23:12:22 +00:00
|
|
|
(CmHive->Hive.HiveFlags & HIVE_VOLATILE))
|
|
|
|
{
|
|
|
|
/* Don't do anything but do update the count */
|
|
|
|
CmHive->FlushCount = CmpLazyFlushCount;
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("Hive %wZ is clean.\n", &CmHive->FileFullPath);
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do the sync */
|
2014-11-02 18:58:09 +00:00
|
|
|
DPRINT("Flushing: %wZ\n", &CmHive->FileFullPath);
|
|
|
|
DPRINT("Handle: %p\n", CmHive->FileHandles[HFILE_TYPE_PRIMARY]);
|
2007-11-02 23:12:22 +00:00
|
|
|
Status = HvSyncHive(&CmHive->Hive);
|
2024-08-11 14:39:28 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
/* Let them know we failed */
|
2014-11-02 18:58:09 +00:00
|
|
|
DPRINT1("Failed to flush %wZ on handle %p (status 0x%08lx)\n",
|
|
|
|
&CmHive->FileFullPath, CmHive->FileHandles[HFILE_TYPE_PRIMARY], Status);
|
2007-11-02 23:12:22 +00:00
|
|
|
*Error = TRUE;
|
|
|
|
Result = FALSE;
|
2014-01-23 21:06:48 +00:00
|
|
|
break;
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
2014-01-23 21:06:48 +00:00
|
|
|
CmHive->FlushCount = CmpLazyFlushCount;
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-20 19:28:13 +00:00
|
|
|
else if (CmHive->Hive.DirtyCount &&
|
|
|
|
!(CmHive->Hive.HiveFlags & HIVE_VOLATILE) &&
|
|
|
|
!(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH))
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
/* Use another lazy flusher for this hive */
|
|
|
|
ASSERT(CmHive->FlushCount == CmpLazyFlushCount);
|
|
|
|
*DirtyCount += CmHive->Hive.DirtyCount;
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("CmHive %wZ already uptodate.\n", &CmHive->FileFullPath);
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try the next one */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Check if we've flushed everything */
|
|
|
|
if (NextEntry == &CmpHiveListHead)
|
|
|
|
{
|
|
|
|
/* We have, tell the caller we're done */
|
|
|
|
Result = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We need to be called again */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Unlock the list and return the result */
|
|
|
|
ExReleasePushLock(&CmpHiveListHeadLock);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(KDEFERRED_ROUTINE)
|
2007-11-02 23:12:22 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpEnableLazyFlushDpcRoutine(IN PKDPC Dpc,
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Don't stop lazy flushing from happening anymore */
|
|
|
|
CmpHoldLazyFlush = FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(KDEFERRED_ROUTINE)
|
2007-11-02 23:12:22 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpLazyFlushDpcRoutine(IN PKDPC Dpc,
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Check if we should queue the lazy flush worker */
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("Flush pending: %s, Holding lazy flush: %s.\n", CmpLazyFlushPending ? "yes" : "no", CmpHoldLazyFlush ? "yes" : "no");
|
2023-12-20 19:28:13 +00:00
|
|
|
if (!CmpLazyFlushPending && !CmpHoldLazyFlush)
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
CmpLazyFlushPending = TRUE;
|
|
|
|
ExQueueWorkItem(&CmpLazyWorkItem, DelayedWorkQueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpLazyFlush(VOID)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER DueTime;
|
|
|
|
PAGED_CODE();
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Check if we should set the lazy flush timer */
|
2023-12-20 19:28:13 +00:00
|
|
|
if (!CmpNoWrite && !CmpHoldLazyFlush)
|
2007-11-02 23:12:22 +00:00
|
|
|
{
|
|
|
|
/* Do it */
|
|
|
|
DueTime.QuadPart = Int32x32To64(CmpLazyFlushIntervalInSeconds,
|
|
|
|
-10 * 1000 * 1000);
|
|
|
|
KeSetTimer(&CmpLazyFlushTimer, DueTime, &CmpLazyFlushDpc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(WORKER_THREAD_ROUTINE)
|
2007-11-02 23:12:22 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpLazyFlushWorker(IN PVOID Parameter)
|
|
|
|
{
|
|
|
|
BOOLEAN ForceFlush, Result, MoreWork = FALSE;
|
|
|
|
ULONG DirtyCount = 0;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Don't do anything if lazy flushing isn't enabled yet */
|
2014-01-23 21:06:48 +00:00
|
|
|
if (CmpHoldLazyFlush)
|
|
|
|
{
|
|
|
|
DPRINT1("Lazy flush held. Bye bye.\n");
|
|
|
|
CmpLazyFlushPending = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Check if we are forcing a flush */
|
|
|
|
ForceFlush = CmpForceForceFlush;
|
|
|
|
if (ForceFlush)
|
|
|
|
{
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("Forcing flush.\n");
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Lock the registry exclusively */
|
|
|
|
CmpLockRegistryExclusive();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("Not forcing flush.\n");
|
|
|
|
/* Starve writers before locking */
|
2007-11-02 23:12:22 +00:00
|
|
|
InterlockedIncrement(&CmpFlushStarveWriters);
|
2014-01-23 21:06:48 +00:00
|
|
|
CmpLockRegistry();
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Flush the next hive */
|
2007-12-25 12:35:15 +00:00
|
|
|
MoreWork = CmpDoFlushNextHive(ForceFlush, &Result, &DirtyCount);
|
2007-11-02 23:12:22 +00:00
|
|
|
if (!MoreWork)
|
|
|
|
{
|
|
|
|
/* We're done */
|
|
|
|
InterlockedIncrement((PLONG)&CmpLazyFlushCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have starved writers */
|
2014-01-23 21:06:48 +00:00
|
|
|
if (!ForceFlush)
|
|
|
|
InterlockedDecrement(&CmpFlushStarveWriters);
|
2007-11-02 23:12:22 +00:00
|
|
|
|
|
|
|
/* Not pending anymore, release the registry lock */
|
|
|
|
CmpLazyFlushPending = FALSE;
|
|
|
|
CmpUnlockRegistry();
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2014-01-23 21:06:48 +00:00
|
|
|
DPRINT("Lazy flush done. More work to be done: %s. Entries still dirty: %u.\n",
|
|
|
|
MoreWork ? "Yes" : "No", DirtyCount);
|
|
|
|
|
|
|
|
if (MoreWork)
|
|
|
|
{
|
|
|
|
/* Relaunch the flush timer, so the remaining hives get flushed */
|
|
|
|
CmpLazyFlush();
|
|
|
|
}
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpCmdInit(IN BOOLEAN SetupBoot)
|
|
|
|
{
|
2012-12-19 23:49:13 +00:00
|
|
|
LARGE_INTEGER DueTime;
|
2007-11-02 23:12:22 +00:00
|
|
|
PAGED_CODE();
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Setup the lazy DPC */
|
|
|
|
KeInitializeDpc(&CmpLazyFlushDpc, CmpLazyFlushDpcRoutine, NULL);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Setup the lazy timer */
|
|
|
|
KeInitializeTimer(&CmpLazyFlushTimer);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Setup the lazy worker */
|
|
|
|
ExInitializeWorkItem(&CmpLazyWorkItem, CmpLazyFlushWorker, NULL);
|
|
|
|
|
|
|
|
/* Setup the forced-lazy DPC and timer */
|
|
|
|
KeInitializeDpc(&CmpEnableLazyFlushDpc,
|
|
|
|
CmpEnableLazyFlushDpcRoutine,
|
|
|
|
NULL);
|
|
|
|
KeInitializeTimer(&CmpEnableLazyFlushTimer);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Enable lazy flushing after 10 minutes */
|
|
|
|
DueTime.QuadPart = Int32x32To64(600, -10 * 1000 * 1000);
|
|
|
|
KeSetTimer(&CmpEnableLazyFlushTimer, DueTime, &CmpEnableLazyFlushDpc);
|
|
|
|
|
|
|
|
/* Setup flush variables */
|
2007-12-25 12:35:15 +00:00
|
|
|
CmpNoWrite = CmpMiniNTBoot;
|
2007-11-02 23:12:22 +00:00
|
|
|
CmpWasSetupBoot = SetupBoot;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* Testing: Force Lazy Flushing */
|
|
|
|
CmpHoldLazyFlush = FALSE;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2023-12-14 21:02:58 +00:00
|
|
|
/* Setup the system hives list if this is not a Setup boot */
|
2017-06-02 15:47:52 +00:00
|
|
|
if (!SetupBoot)
|
|
|
|
CmpInitializeHiveList();
|
2023-12-14 21:02:58 +00:00
|
|
|
|
|
|
|
/* Now that the system hives are loaded, if we are in PE mode,
|
|
|
|
* all other hives will be loaded with full access */
|
|
|
|
if (CmpMiniNTBoot)
|
|
|
|
CmpShareSystemHives = FALSE;
|
2007-11-22 18:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CmpCmdHiveOpen(IN POBJECT_ATTRIBUTES FileAttributes,
|
|
|
|
IN PSECURITY_CLIENT_CONTEXT ImpersonationContext,
|
|
|
|
IN OUT PBOOLEAN Allocate,
|
|
|
|
OUT PCMHIVE *NewHive,
|
|
|
|
IN ULONG CheckFlags)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2018-10-21 22:39:50 +00:00
|
|
|
UNICODE_STRING FileName;
|
|
|
|
PWCHAR FilePath;
|
2019-04-17 07:37:37 +00:00
|
|
|
ULONG Length;
|
2019-05-07 11:51:06 +00:00
|
|
|
OBJECT_NAME_INFORMATION DummyNameInfo;
|
2019-04-17 07:37:37 +00:00
|
|
|
POBJECT_NAME_INFORMATION FileNameInfo;
|
2018-10-21 22:39:50 +00:00
|
|
|
|
2007-11-22 18:38:32 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2018-10-21 22:39:50 +00:00
|
|
|
if (FileAttributes->RootDirectory)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Validity check: The ObjectName is relative to RootDirectory,
|
|
|
|
* therefore it must not start with a path separator.
|
|
|
|
*/
|
|
|
|
if (FileAttributes->ObjectName && FileAttributes->ObjectName->Buffer &&
|
|
|
|
FileAttributes->ObjectName->Length >= sizeof(WCHAR) &&
|
|
|
|
*FileAttributes->ObjectName->Buffer == OBJ_NAME_PATH_SEPARATOR)
|
|
|
|
{
|
|
|
|
return STATUS_OBJECT_PATH_SYNTAX_BAD;
|
|
|
|
}
|
|
|
|
|
2019-04-17 07:37:37 +00:00
|
|
|
/* Determine the right buffer size and allocate */
|
|
|
|
Status = ZwQueryObject(FileAttributes->RootDirectory,
|
|
|
|
ObjectNameInformation,
|
2019-05-07 11:51:06 +00:00
|
|
|
&DummyNameInfo,
|
|
|
|
sizeof(DummyNameInfo),
|
2019-04-17 07:37:37 +00:00
|
|
|
&Length);
|
2019-05-07 11:51:06 +00:00
|
|
|
if (Status != STATUS_BUFFER_OVERFLOW)
|
2019-04-17 07:37:37 +00:00
|
|
|
{
|
|
|
|
DPRINT1("CmpCmdHiveOpen(): Root directory handle object name size query failed, Status = 0x%08lx\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileNameInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
Length + sizeof(UNICODE_NULL),
|
|
|
|
TAG_CM);
|
|
|
|
if (FileNameInfo == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("CmpCmdHiveOpen(): Unable to allocate memory\n");
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2018-10-21 22:39:50 +00:00
|
|
|
/* Try to get the value */
|
|
|
|
Status = ZwQueryObject(FileAttributes->RootDirectory,
|
|
|
|
ObjectNameInformation,
|
|
|
|
FileNameInfo,
|
|
|
|
Length,
|
|
|
|
&Length);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
DPRINT1("CmpCmdHiveOpen(): Root directory handle object name query failed, Status = 0x%08lx\n", Status);
|
2019-04-17 07:37:37 +00:00
|
|
|
ExFreePoolWithTag(FileNameInfo, TAG_CM);
|
2018-10-21 22:39:50 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Null-terminate and add the length of the terminator */
|
|
|
|
Length -= sizeof(OBJECT_NAME_INFORMATION);
|
|
|
|
FilePath = FileNameInfo->Name.Buffer;
|
|
|
|
FilePath[Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
Length += sizeof(UNICODE_NULL);
|
|
|
|
|
|
|
|
/* Compute the size of the full path; Length already counts the terminating NULL */
|
|
|
|
Length = Length + sizeof(WCHAR) + FileAttributes->ObjectName->Length;
|
|
|
|
if (Length > MAXUSHORT)
|
|
|
|
{
|
|
|
|
/* Name size too long, bail out */
|
2019-04-17 07:37:37 +00:00
|
|
|
ExFreePoolWithTag(FileNameInfo, TAG_CM);
|
2018-10-21 22:39:50 +00:00
|
|
|
return STATUS_OBJECT_PATH_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the full path */
|
|
|
|
RtlInitEmptyUnicodeString(&FileName, NULL, 0);
|
|
|
|
FileName.Buffer = ExAllocatePoolWithTag(PagedPool, Length, TAG_CM);
|
|
|
|
if (!FileName.Buffer)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
DPRINT1("CmpCmdHiveOpen(): Unable to allocate memory\n");
|
2019-04-17 07:37:37 +00:00
|
|
|
ExFreePoolWithTag(FileNameInfo, TAG_CM);
|
2018-10-21 22:39:50 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
FileName.MaximumLength = Length;
|
|
|
|
RtlCopyUnicodeString(&FileName, &FileNameInfo->Name);
|
2019-04-17 07:37:37 +00:00
|
|
|
ExFreePoolWithTag(FileNameInfo, TAG_CM);
|
2018-10-21 22:39:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a path terminator if needed (we have already accounted
|
|
|
|
* for a possible extra one when allocating the buffer).
|
|
|
|
*/
|
|
|
|
if (/* FileAttributes->ObjectName->Buffer[0] != OBJ_NAME_PATH_SEPARATOR && */ // We excluded ObjectName starting with a path separator above.
|
|
|
|
FileName.Length > 0 && FileName.Buffer[FileName.Length / sizeof(WCHAR) - 1] != OBJ_NAME_PATH_SEPARATOR)
|
|
|
|
{
|
|
|
|
/* ObjectName does not start with '\' and PathBuffer does not end with '\' */
|
|
|
|
FileName.Buffer[FileName.Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR;
|
|
|
|
FileName.Length += sizeof(WCHAR);
|
|
|
|
FileName.Buffer[FileName.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append the object name */
|
|
|
|
Status = RtlAppendUnicodeStringToString(&FileName, FileAttributes->ObjectName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
DPRINT1("CmpCmdHiveOpen(): RtlAppendUnicodeStringToString() failed, Status = 0x%08lx\n", Status);
|
|
|
|
ExFreePoolWithTag(FileName.Buffer, TAG_CM);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileName = *FileAttributes->ObjectName;
|
|
|
|
}
|
|
|
|
|
2007-11-22 18:38:32 +00:00
|
|
|
/* Open the file in the current security context */
|
2018-10-21 22:39:50 +00:00
|
|
|
Status = CmpInitHiveFromFile(&FileName,
|
2007-11-22 18:38:32 +00:00
|
|
|
0,
|
|
|
|
NewHive,
|
|
|
|
Allocate,
|
2007-12-25 12:35:15 +00:00
|
|
|
CheckFlags);
|
2007-11-22 18:38:32 +00:00
|
|
|
if (((Status == STATUS_ACCESS_DENIED) ||
|
|
|
|
(Status == STATUS_NO_SUCH_USER) ||
|
|
|
|
(Status == STATUS_WRONG_PASSWORD) ||
|
|
|
|
(Status == STATUS_ACCOUNT_EXPIRED) ||
|
|
|
|
(Status == STATUS_ACCOUNT_DISABLED) ||
|
|
|
|
(Status == STATUS_ACCOUNT_RESTRICTION)) &&
|
2023-12-20 19:28:13 +00:00
|
|
|
ImpersonationContext)
|
2007-11-22 18:38:32 +00:00
|
|
|
{
|
|
|
|
/* We failed due to an account/security error, impersonate SYSTEM */
|
|
|
|
Status = SeImpersonateClientEx(ImpersonationContext, NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Now try again */
|
2018-10-21 22:39:50 +00:00
|
|
|
Status = CmpInitHiveFromFile(&FileName,
|
2007-11-22 18:38:32 +00:00
|
|
|
0,
|
|
|
|
NewHive,
|
|
|
|
Allocate,
|
2007-12-25 12:35:15 +00:00
|
|
|
CheckFlags);
|
|
|
|
|
2007-11-22 18:38:32 +00:00
|
|
|
/* Restore impersonation token */
|
|
|
|
PsRevertToSelf();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 22:39:50 +00:00
|
|
|
if (FileAttributes->RootDirectory)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(FileName.Buffer, TAG_CM);
|
|
|
|
}
|
|
|
|
|
2007-11-22 18:38:32 +00:00
|
|
|
/* Return status of open attempt */
|
|
|
|
return Status;
|
2007-11-02 23:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpShutdownWorkers(VOID)
|
|
|
|
{
|
|
|
|
/* Stop lazy flushing */
|
|
|
|
PAGED_CODE();
|
|
|
|
KeCancelTimer(&CmpLazyFlushTimer);
|
|
|
|
}
|
|
|
|
|
2010-03-08 20:37:24 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmSetLazyFlushState(IN BOOLEAN Enable)
|
|
|
|
{
|
|
|
|
/* Set state for lazy flusher */
|
|
|
|
CmpHoldLazyFlush = !Enable;
|
|
|
|
}
|
|
|
|
|
2007-11-02 23:12:22 +00:00
|
|
|
/* EOF */
|