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

cmwraper.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 cmwraper.c 00008 00009 Abstract: 00010 00011 Provides wrapper routines to support ntos\config routines called from 00012 user-mode. 00013 00014 Author: 00015 00016 John Vert (jvert) 26-Mar-1992 00017 00018 Revision History: 00019 00020 --*/ 00021 #include "edithive.h" 00022 #include "nturtl.h" 00023 #include "stdlib.h" 00024 #include "stdio.h" 00025 00026 extern ULONG UsedStorage; 00027 00028 CCHAR KiFindFirstSetRight[256] = { 00029 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00030 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00031 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00032 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00033 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00034 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00035 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00036 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00037 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00038 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00039 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00040 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00041 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00042 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00043 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 00044 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}; 00045 00046 00047 ULONG MmSizeOfPagedPoolInBytes = 0xffffffff; // stub out 00048 00049 ULONG 00050 DbgPrint ( 00051 IN PCH Format, 00052 ... 00053 ) 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 } 00069 00070 00071 // 00072 // Structure that describes the mapping of generic access rights to object 00073 // specific access rights for registry key and keyroot objects. 00074 // 00075 00076 GENERIC_MAPPING CmpKeyMapping = { 00077 KEY_READ, 00078 KEY_WRITE, 00079 KEY_EXECUTE, 00080 KEY_ALL_ACCESS 00081 }; 00082 BOOLEAN CmpNoWrite = FALSE; 00083 ULONG CmLogLevel=0; 00084 ULONG CmLogSelect=0; 00085 PCMHIVE CmpMasterHive = NULL; 00086 LIST_ENTRY CmpHiveListHead; // List of CMHIVEs 00087 00088 NTSTATUS 00089 MyCmpInitHiveFromFile( 00090 IN PUNICODE_STRING FileName, 00091 OUT PCMHIVE *CmHive, 00092 OUT PBOOLEAN Allocate 00093 ); 00094 00095 00096 VOID 00097 CmpLazyFlush( 00098 VOID 00099 ) 00100 { 00101 } 00102 00103 00104 VOID 00105 CmpFreeSecurityDescriptor( 00106 IN PHHIVE Hive, 00107 IN HCELL_INDEX Cell 00108 ) 00109 { 00110 return; 00111 } 00112 00113 VOID 00114 CmpReportNotify( 00115 UNICODE_STRING Name, 00116 PHHIVE Hive, 00117 HCELL_INDEX Cell, 00118 ULONG Filter 00119 ) 00120 { 00121 } 00122 00123 VOID 00124 CmpLockRegistry(VOID) 00125 { 00126 return; 00127 } 00128 00129 BOOLEAN 00130 CmpTryLockRegistryExclusive( 00131 IN BOOLEAN CanWait 00132 ) 00133 { 00134 return TRUE; 00135 } 00136 00137 VOID 00138 CmpUnlockRegistry( 00139 ) 00140 { 00141 } 00142 00143 BOOLEAN 00144 CmpTestRegistryLock() 00145 { 00146 return TRUE; 00147 } 00148 00149 BOOLEAN 00150 CmpTestRegistryLockExclusive() 00151 { 00152 return TRUE; 00153 } 00154 LONG 00155 KeReleaseMutex ( 00156 IN PKMUTEX Mutex, 00157 IN BOOLEAN Wait 00158 ) 00159 { 00160 return(0); 00161 } 00162 NTSTATUS 00163 KeWaitForSingleObject ( 00164 IN PVOID Object, 00165 IN KWAIT_REASON WaitReason, 00166 IN KPROCESSOR_MODE WaitMode, 00167 IN BOOLEAN Alertable, 00168 IN PLARGE_INTEGER Timeout OPTIONAL 00169 ) 00170 { 00171 return(STATUS_SUCCESS); 00172 } 00173 00174 BOOLEAN 00175 CmpValidateHiveSecurityDescriptors( 00176 IN PHHIVE Hive 00177 ) 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 } 00216 00217 VOID 00218 KeBugCheck( 00219 IN ULONG BugCheckCode 00220 ) 00221 { 00222 printf("BugCheck: code = %08lx\n", BugCheckCode); 00223 exit(1); 00224 } 00225 00226 VOID 00227 KeBugCheckEx( 00228 IN ULONG BugCheckCode, 00229 IN ULONG Arg1, 00230 IN ULONG Arg2, 00231 IN ULONG Arg3, 00232 IN ULONG Arg4 00233 ) 00234 { 00235 printf("BugCheck: code = %08lx\n", BugCheckCode); 00236 printf("Args =%08lx %08lx %08lx %08lx\n", Arg1, Arg2, Arg3, Arg4); 00237 exit(1); 00238 } 00239 00240 00241 VOID 00242 KeQuerySystemTime( 00243 OUT PLARGE_INTEGER SystemTime 00244 ) 00245 { 00246 NtQuerySystemTime(SystemTime); 00247 } 00248 00249 #ifdef POOL_TAGGING 00250 PVOID 00251 ExAllocatePoolWithTag( 00252 IN POOL_TYPE PoolType, 00253 IN ULONG NumberOfBytes, 00254 IN ULONG Tag 00255 ) 00256 { 00257 PVOID Address = NULL; 00258 ULONG Size; 00259 NTSTATUS status; 00260 00261 Size = ROUND_UP(NumberOfBytes, HBLOCK_SIZE); 00262 status = NtAllocateVirtualMemory( 00263 NtCurrentProcess(), 00264 &Address, 00265 0, 00266 &Size, 00267 MEM_COMMIT, 00268 PAGE_READWRITE 00269 ); 00270 if (!NT_SUCCESS(status)) { 00271 return NULL; 00272 } 00273 return Address; 00274 } 00275 #else 00276 00277 PVOID 00278 ExAllocatePool( 00279 IN POOL_TYPE PoolType, 00280 IN ULONG NumberOfBytes 00281 ) 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 } 00301 #endif 00302 00303 VOID 00304 ExFreePool( 00305 IN PVOID P 00306 ) 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 } 00320 00321 00322 NTSTATUS 00323 CmpWorkerCommand( 00324 IN OUT PREGISTRY_COMMAND Command 00325 ) 00326 00327 /*++ 00328 00329 Routine Description: 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 } 00403 00404 NTSTATUS 00405 MyCmpInitHiveFromFile( 00406 IN PUNICODE_STRING FileName, 00407 OUT PCMHIVE *CmHive, 00408 OUT PBOOLEAN Allocate 00409 ) 00410 00411 /*++ 00412 00413 Routine Description: 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 } 00494 00495 NTSTATUS 00496 CmpLinkHiveToMaster( 00497 PUNICODE_STRING LinkName, 00498 HANDLE RootDirectory, 00499 PCMHIVE CmHive, 00500 BOOLEAN Allocate, 00501 PSECURITY_DESCRIPTOR SecurityDescriptor 00502 ) 00503 { 00504 return( STATUS_SUCCESS ); 00505 } 00506 00507 00508 BOOLEAN 00509 CmpFileSetSize( 00510 PHHIVE Hive, 00511 ULONG FileType, 00512 ULONG FileSize 00513 ) 00514 /*++ 00515 00516 Routine Description: 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 } 00553 

Generated on Sat May 15 19:39:29 2004 for test by doxygen 1.3.7