test: cmwraper.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# cmwraper.c File Reference

`#include "edithive.h"`
`#include "nturtl.h"`
`#include "stdlib.h"`
`#include "stdio.h"`

Go to the source code of this file.

## Functions

ULONG | DbgPrint (IN PCH Format,...)
NTSTATUS | MyCmpInitHiveFromFile (IN PUNICODE_STRING FileName, OUT PCMHIVE *CmHive, OUT PBOOLEAN Allocate)
VOID | CmpLazyFlush (VOID)
VOID | CmpFreeSecurityDescriptor (IN PHHIVE Hive, IN HCELL_INDEX Cell)
VOID | CmpReportNotify (UNICODE_STRING Name, PHHIVE Hive, HCELL_INDEX Cell, ULONG Filter)
VOID | CmpLockRegistry (VOID)
BOOLEAN | CmpTryLockRegistryExclusive (IN BOOLEAN CanWait)
VOID | CmpUnlockRegistry ()
BOOLEAN | CmpTestRegistryLock ()
BOOLEAN | CmpTestRegistryLockExclusive ()
LONG | KeReleaseMutex (IN PKMUTEX Mutex, IN BOOLEAN Wait)
NTSTATUS | KeWaitForSingleObject (IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
BOOLEAN | CmpValidateHiveSecurityDescriptors (IN PHHIVE Hive)
VOID | KeBugCheck (IN ULONG BugCheckCode)
VOID | KeBugCheckEx (IN ULONG BugCheckCode, IN ULONG Arg1, IN ULONG Arg2, IN ULONG Arg3, IN ULONG Arg4)
VOID | KeQuerySystemTime (OUT PLARGE_INTEGER SystemTime)
PVOID | ExAllocatePool (IN POOL_TYPE PoolType, IN ULONG NumberOfBytes)
VOID | ExFreePool (IN PVOID P)
NTSTATUS | CmpWorkerCommand (IN OUT PREGISTRY_COMMAND Command)
NTSTATUS | CmpLinkHiveToMaster (PUNICODE_STRING LinkName, HANDLE RootDirectory, PCMHIVE CmHive, BOOLEAN Allocate, PSECURITY_DESCRIPTOR SecurityDescriptor)
BOOLEAN | CmpFileSetSize (PHHIVE Hive, ULONG FileType, ULONG FileSize)

## Variables

ULONG | UsedStorage
CCHAR | KiFindFirstSetRight [256]
ULONG | MmSizeOfPagedPoolInBytes = 0xffffffff
GENERIC_MAPPING | CmpKeyMapping
BOOLEAN | CmpNoWrite = FALSE
ULONG | CmLogLevel = 0
ULONG | CmLogSelect = 0
PCMHIVE | CmpMasterHive = NULL
LIST_ENTRY | CmpHiveListHead

## Function Documentation

BOOLEAN CmpFileSetSize | ( | PHHIVE | Hive,
|  | ULONG | FileType,
|  | ULONG | FileSize
| ) |

Definition at line 509 of file cmwraper.c.

References CML_MAJOR, CMLOG, CmpDoFileSetSize(), CMS_IO_ERROR, FALSE, Hive, NT_SUCCESS, NTSTATUS(), and TRUE.

Referenced by CmpInitializeHive(), and CmpInitializeHiveList().

    00516                    :
    00517
    00518     This routine sets the size of a file.  It must not return until
    00519     the size is guaranteed, therefore, it does a flush.
    00520
    00521     It is environment specific.
    00522
    00523     This routine will force execution to the correct thread context.
    00524
    00525 Arguments:
    00526
    00527     Hive - Hive we are doing I/O for
    00528
    00529     FileType - which supporting file to use
    00530
    00531     FileSize - 32 bit value to set the file's size to
    00532
    00533 Return Value:
    00534
    00535     FALSE if failure
    00536     TRUE if success
    00537
    00538 --*/
    00539 {
    00540     NTSTATUS    status;
    00541
    00542     status = CmpDoFileSetSize(Hive, FileType, FileSize);
    00543     if (!NT_SUCCESS(status)) {
    00544         CMLOG(CML_MAJOR, CMS_IO_ERROR) {
    00545             KdPrint(("CmpFileSetSize:\n\t"));
    00546             KdPrint(("Failure: status = %08lx ", status));
    00547         }
    00548         return FALSE;
    00549     }
    00550
    00551     return TRUE;
    00552 }
    }

VOID CmpFreeSecurityDescriptor | ( | IN PHHIVE | Hive,
|  | IN HCELL_INDEX | Cell
| ) |

Definition at line 105 of file cmwraper.c.

Referenced by CmpFreeKeyByCell(), and CmpFreeKeyValues().

    00109 {
    00110     return;
    00111 }

VOID CmpLazyFlush | ( | VOID |  | ) |

Definition at line 97 of file cmwraper.c.

Referenced by CmpInitializeHiveList(), CmpLazyFlushWorker(), and HvMarkDirty().

    00100 {
    00101 }

NTSTATUS CmpLinkHiveToMaster | ( | PUNICODE_STRING | LinkName,
|  | HANDLE | RootDirectory,
|  | PCMHIVE | CmHive,
|  | BOOLEAN | Allocate,
|  | PSECURITY_DESCRIPTOR | SecurityDescriptor
| ) |

Definition at line 496 of file cmwraper.c.

Referenced by CmInitSystem1(), CmLoadKey(), CmpInitializeHiveList(), CmpInitializeSystemHive(), and CmpLoadHiveVolatile().

    00503 {
    00504     return( STATUS_SUCCESS );
    00505 }

VOID CmpLockRegistry | ( | VOID |  | ) |

Definition at line 124 of file cmwraper.c.

Referenced by CmEnumerateKey(), CmEnumerateValueKey(), CmpCloseKeyObject(), CmpDeleteKeyObject(), CmpLazyFlushWorker(), CmpQueryKeyName(), CmpSecurityMethod(), CmQueryKey(), CmQueryMultipleValueKey(), CmQueryValueKey(), CmSetValueKey(), NtFlushKey(), NtNotifyChangeMultipleKeys(), and NtOpenKey().

    00125 {
    00126     return;
    00127 }

VOID CmpReportNotify | ( | UNICODE_STRING | Name,
|  | PHHIVE | Hive,
|  | HCELL_INDEX | Cell,
|  | ULONG | Filter
| ) |

Definition at line 114 of file cmwraper.c.

Referenced by CmDeleteKey(), CmDeleteValueKey(), CmpDoCreateChild(), CmpLinkHiveToMaster(), CmpSecurityMethod(), CmRestoreKey(), CmSetValueKey(), and NtUnloadKey().

    00120 {
    00121 }

BOOLEAN CmpTestRegistryLock | ( |  | ) |

Definition at line 144 of file cmwraper.c.

References TRUE.

    00145 {
    00146     return TRUE;
    00147 }

BOOLEAN CmpTestRegistryLockExclusive | ( |  | ) |

Definition at line 150 of file cmwraper.c.

References TRUE.

    00151 {
    00152     return TRUE;
    00153 }

BOOLEAN CmpTryLockRegistryExclusive | ( | IN BOOLEAN | CanWait | ) |

Definition at line 130 of file cmwraper.c.

References TRUE.

    00133 {
    00134     return TRUE;
    00135 }

VOID CmpUnlockRegistry | ( |  | ) |

Definition at line 138 of file cmwraper.c.

Referenced by CmDeleteKey(), CmDeleteValueKey(), CmEnumerateKey(), CmEnumerateValueKey(), CmGetSystemDriverList(), CmInitSystem1(), CmLoadKey(), CmNotifyRunDown(), CmpCloneControlSet(), CmpCloneHwProfile(), CmpCloseKeyObject(), CmpDeleteKeyObject(), CmpFileSetSize(), CmpLazyFlushWorker(), CmpLoadHiveVolatile(), CmpQueryKeyName(), CmpRefreshHive(), CmpSaveBootControlSet(), CmpSaveKeyByFileCopy(), CmpSecurityMethod(), CmQueryKey(), CmQueryMultipleValueKey(), CmQueryValueKey(), CmReplaceKey(), CmRestoreKey(), CmSaveKey(), CmSaveMergedKeys(), CmSetLastWriteTimeKey(), CmSetValueKey(), CmShutdownSystem(), CmUnloadKey(), NtCreateKey(), NtFlushKey(), NtInitializeRegistry(), NtNotifyChangeMultipleKeys(), NtOpenKey(), NtQueryOpenSubKeys(), and NtUnloadKey().

    00140 {
    00141 }

BOOLEAN CmpValidateHiveSecurityDescriptors | ( | IN PHHIVE | Hive | ) |

Definition at line 175 of file cmwraper.c.

References _HHIVE::BaseBlock, _CM_KEY_SECURITY::Blink, CML_FLOW, CML_MAJOR, CML_MINOR, CMLOG, CmpDumpSecurityDescriptor, CMS_SEC, _CM_KEY_SECURITY::Descriptor, _CM_KEY_SECURITY::DescriptorLength, FALSE, _CM_KEY_SECURITY::Flink, HCELL_INDEX, Hive, HvGetCell, HvIsCellAllocated(), PCM_KEY_SECURITY, _CM_KEY_SECURITY::ReferenceCount, _HBASE_BLOCK::RootCell, _CM_KEY_NODE::Security, SetUsed, SeValidSecurityDescriptor(), and TRUE.

Referenced by CmCheckRegistry().

    00178 {
    00179     PCM_KEY_NODE RootNode;
    00180     PCM_KEY_SECURITY SecurityCell;
    00181     HCELL_INDEX ListAnchor;
    00182     HCELL_INDEX NextCell;
    00183     HCELL_INDEX LastCell;
    00184     BOOLEAN ValidHive = TRUE;
    00185
    00186     CMLOG(CML_FLOW, CMS_SEC) {
    00187         KdPrint(("CmpValidateHiveSecurityDescriptor: Hive = %lx\n",(ULONG)Hive));
    00188     }
    00189     RootNode = (PCM_KEY_NODE) HvGetCell(Hive, Hive->BaseBlock->RootCell);
    00190     ListAnchor = NextCell = RootNode->u1.s1.Security;
    00191
    00192     do {
    00193         SecurityCell = (PCM_KEY_SECURITY) HvGetCell(Hive, NextCell);
    00194         if (NextCell != ListAnchor) {
    00195             //
    00196             // Check to make sure that our Blink points to where we just
    00197             // came from.
    00198             //
    00199             if (SecurityCell->Blink != LastCell) {
    00200                 CMLOG(CML_MAJOR, CMS_SEC) {
    00201                     KdPrint(("  Invalid Blink (%ld) on security cell %ld\n",SecurityCell->Blink, NextCell));
    00202                     KdPrint(("  should point to %ld\n", LastCell));
    00203                 }
    00204                 ValidHive = FALSE;
    00205             }
    00206         }
    00207         CMLOG(CML_MINOR, CMS_SEC) {
    00208             KdPrint(("CmpValidSD:  SD shared by %d nodes\n",SecurityCell->ReferenceCount));
    00209         }
    00210 //        SetUsed(Hive, NextCell);
    00211         LastCell = NextCell;
    00212         NextCell = SecurityCell->Flink;
    00213     } while ( NextCell != ListAnchor );
    00214     return(TRUE);
    00215 }

NTSTATUS CmpWorkerCommand | ( | IN OUT PREGISTRY_COMMAND | Command | ) |

Definition at line 323 of file cmwraper.c.

References CmFlushKey(), CmpDoFileSetSize(), _CMHIVE::FileHandles, FileName, HFILE_TYPE_MAX, MyCmpInitHiveFromFile(), NtClose(), NULL, REG_CMD_FILE_SET_SIZE, REG_CMD_FLUSH_KEY, REG_CMD_HIVE_CLOSE, REG_CMD_HIVE_OPEN, and REG_CMD_SHUTDOWN.

    00329                    :
    00330
    00331     This routine just encapsulates all the necessary synchronization for
    00332     sending a command to the worker thread.
    00333
    00334 Arguments:
    00335
    00336     Command - Supplies a pointer to an initialized REGISTRY_COMMAND structure
    00337             which will be copied into the global communication structure.
    00338
    00339 Return Value:
    00340
    00341     NTSTATUS = Command.Status
    00342
    00343 --*/
    00344
    00345 {
    00346     PCMHIVE CmHive;
    00347     PUNICODE_STRING FileName;
    00348     ULONG i;
    00349
    00350     switch (Command->Command) {
    00351
    00352         case REG_CMD_FLUSH_KEY:
    00353             return CmFlushKey(Command->Hive, Command->Cell);
    00354             break;
    00355
    00356         case REG_CMD_FILE_SET_SIZE:
    00357             return CmpDoFileSetSize(
    00358                       Command->Hive,
    00359                       Command->FileType,
    00360                       Command->FileSize
    00361                       );
    00362             break;
    00363
    00364         case REG_CMD_HIVE_OPEN:
    00365
    00366             //
    00367             // Open the file.
    00368             //
    00369             FileName = Command->FileAttributes->ObjectName;
    00370
    00371             return MyCmpInitHiveFromFile(FileName,
    00372                                          &Command->CmHive,
    00373                                          &Command->Allocate);
    00374
    00375             break;
    00376
    00377         case REG_CMD_HIVE_CLOSE:
    00378
    00379             //
    00380             // Close the files associated with this hive.
    00381             //
    00382             CmHive = Command->CmHive;
    00383
    00384             for (i=0; i<HFILE_TYPE_MAX; i++) {
    00385                 if (CmHive->FileHandles[i] != NULL) {
    00386                     NtClose(CmHive->FileHandles[i]);
    00387                 }
    00388             }
    00389             return STATUS_SUCCESS;
    00390             break;
    00391
    00392         case REG_CMD_SHUTDOWN:
    00393
    00394             //
    00395             // shut down the registry
    00396             //
    00397             break;
    00398
    00399         default:
    00400             return STATUS_INVALID_PARAMETER;
    00401     }
    00402 }

ULONG DbgPrint | ( | IN PCH | Format,
|  |  | ...
| ) |

Definition at line 50 of file cmwraper.c.

References Buffer.

    00054 {
    00055     va_list arglist;
    00056     UCHAR Buffer[512];
    00057     STRING Output;
    00058
    00059     //
    00060     // Format the output into a buffer and then print it.
    00061     //
    00062
    00063     va_start(arglist, Format);
    00064     Output.Length = _vsnprintf(Buffer, sizeof(Buffer), Format, arglist);
    00065     Output.Buffer = Buffer;
    00066     printf("%s", Buffer);
    00067     return 0;
    00068 }

PVOID ExAllocatePool | ( | IN POOL_TYPE | PoolType,
|  | IN ULONG | NumberOfBytes
| ) |

Definition at line 278 of file cmwraper.c.

References HBLOCK_SIZE, NT_SUCCESS, NtAllocateVirtualMemory(), NTSTATUS(), NULL, ROUND_UP, and Size.

    00282 {
    00283     PVOID   Address = NULL;
    00284     ULONG   Size;
    00285     NTSTATUS    status;
    00286
    00287     Size = ROUND_UP(NumberOfBytes, HBLOCK_SIZE);
    00288     status = NtAllocateVirtualMemory(
    00289                 NtCurrentProcess(),
    00290                 &Address,
    00291                 0,
    00292                 &Size,
    00293                 MEM_COMMIT,
    00294                 PAGE_READWRITE
    00295                 );
    00296     if (!NT_SUCCESS(status)) {
    00297         return NULL;
    00298     }
    00299     return Address;
    00300 }

VOID ExFreePool | ( | IN PVOID | P | ) |

Definition at line 304 of file cmwraper.c.

Referenced by ExInitializeNPagedLookasideList(), and ExInitializePagedLookasideList().

    00307 {
    00308     ULONG   size;
    00309     size = HBLOCK_SIZE;
    00310
    00311     // if it was really more than 1 page, well, too bad
    00312     NtFreeVirtualMemory(
    00313         NtCurrentProcess(),
    00314         &P,
    00315         &size,
    00316         MEM_DECOMMIT
    00317         );
    00318     return;
    00319 }

VOID KeBugCheck | ( | IN ULONG | BugCheckCode | ) |

Definition at line 218 of file cmwraper.c.

Referenced by KiInitializeKernel().

    00221 {
    00222     printf("BugCheck: code = %08lx\n", BugCheckCode);
    00223     exit(1);
    00224 }

VOID KeBugCheckEx | ( | IN ULONG | BugCheckCode,
|  | IN ULONG | Arg1,
|  | IN ULONG | Arg2,
|  | IN ULONG | Arg3,
|  | IN ULONG | Arg4
| ) |

Definition at line 227 of file cmwraper.c.

References exit.

    00234 {
    00235     printf("BugCheck: code = %08lx\n", BugCheckCode);
    00236     printf("Args =%08lx %08lx %08lx %08lx\n", Arg1, Arg2, Arg3, Arg4);
    00237     exit(1);
    00238 }

VOID KeQuerySystemTime | ( | OUT PLARGE_INTEGER | SystemTime | ) |

Definition at line 242 of file cmwraper.c.

    00245 {
    00246     NtQuerySystemTime(SystemTime);
    00247 }

LONG KeReleaseMutex | ( | IN PKMUTEX | Mutex,
|  | IN BOOLEAN | Wait
| ) |

Definition at line 155 of file cmwraper.c.

References PKMUTEX.

    00159 {
    00160     return(0);
    00161 }

NTSTATUS KeWaitForSingleObject | ( | IN PVOID | Object,
|  | IN KWAIT_REASON | WaitReason,
|  | IN KPROCESSOR_MODE | WaitMode,
|  | IN BOOLEAN | Alertable,
|  | IN PLARGE_INTEGER Timeout | OPTIONAL
| ) |

Definition at line 163 of file cmwraper.c.

    00170 {
    00171     return(STATUS_SUCCESS);
    00172 }

NTSTATUS MyCmpInitHiveFromFile | ( | IN PUNICODE_STRING | FileName,
|  | OUT PCMHIVE * | CmHive,
|  | OUT PBOOLEAN | Allocate
| ) |

Definition at line 405 of file cmwraper.c.

References CmpInitializeHive(), CmpOpenHiveFiles(), FALSE, FileName, HFILE_TYPE_LOG, HFILE_TYPE_PRIMARY, HINIT_CREATE, HINIT_FILE, L, NT_SUCCESS, NtClose(), NTSTATUS(), NULL, Status, and TRUE.

Referenced by CmpWorkerCommand().

    00413                    :
    00414
    00415     This routine opens a file and log, allocates a CMHIVE, and initializes
    00416     it.
    00417
    00418 Arguments:
    00419
    00420     FileName - Supplies name of file to be loaded.
    00421
    00422     CmHive   - Returns pointer to initialized hive (if successful)
    00423
    00424     Allocate - Returns whether the hive was allocated or existing.
    00425
    00426 Return Value:
    00427
    00428     NTSTATUS
    00429
    00430 --*/
    00431
    00432 {
    00433     PCMHIVE NewHive;
    00434     ULONG Disposition;
    00435     ULONG SecondaryDisposition;
    00436     HANDLE PrimaryHandle;
    00437     HANDLE LogHandle;
    00438     NTSTATUS Status;
    00439     ULONG FileType;
    00440     ULONG Operation;
    00441
    00442     BOOLEAN Success;
    00443
    00444     *CmHive = NULL;
    00445
    00446     Status = CmpOpenHiveFiles(FileName,
    00447                               L".log",
    00448                               &PrimaryHandle,
    00449                               &LogHandle,
    00450                               &Disposition,
    00451                               &SecondaryDisposition,
    00452                               TRUE,
    00453                               NULL
    00454                               );
    00455     if (!NT_SUCCESS(Status)) {
    00456         return(Status);
    00457     }
    00458
    00459     if (LogHandle == NULL) {
    00460         FileType = HFILE_TYPE_PRIMARY;
    00461     } else {
    00462         FileType = HFILE_TYPE_LOG;
    00463     }
    00464
    00465     if (Disposition == FILE_CREATED) {
    00466         Operation = HINIT_CREATE;
    00467         *Allocate = TRUE;
    00468     } else {
    00469         Operation = HINIT_FILE;
    00470         *Allocate = FALSE;
    00471     }
    00472
    00473     Success = CmpInitializeHive(&NewHive,
    00474                                 Operation,
    00475                                 FALSE,
    00476                                 FileType,
    00477                                 NULL,
    00478                                 PrimaryHandle,
    00479                                 NULL,
    00480                                 LogHandle,
    00481                                 NULL,
    00482                                 NULL);
    00483     if (!Success) {
    00484         NtClose(PrimaryHandle);
    00485         if (LogHandle != NULL) {
    00486             NtClose(LogHandle);
    00487         }
    00488         return(STATUS_REGISTRY_CORRUPT);
    00489     } else {
    00490         *CmHive = NewHive;
    00491         return(STATUS_SUCCESS);
    00492     }
    00493 }

## Variable Documentation

ULONG CmLogLevel = 0

| Definition at line 83 of file cmwraper.c.

ULONG CmLogSelect = 0

| Definition at line 84 of file cmwraper.c.

LIST_ENTRY CmpHiveListHead

| Definition at line 86 of file cmwraper.c.

GENERIC_MAPPING CmpKeyMapping

Initial value:

     {
        KEY_READ,
        KEY_WRITE,
        KEY_EXECUTE,
        KEY_ALL_ACCESS
    }

Definition at line 76 of file cmwraper.c.

Referenced by CmpCreateObjectTypes(), and EhpAttachSecurity().

PCMHIVE CmpMasterHive = NULL

| Definition at line 85 of file cmwraper.c.

BOOLEAN CmpNoWrite = FALSE

| Definition at line 82 of file cmwraper.c.

CCHAR KiFindFirstSetRight[256]

Initial value:

     {
            0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
            4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}

Definition at line 28 of file cmwraper.c.

ULONG MmSizeOfPagedPoolInBytes = 0xffffffff

| Definition at line 47 of file cmwraper.c.

ULONG UsedStorage

| Definition at line 26 of file cmwraper.c. Referenced by CmCheckRegistry().