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

cmhvlist.c File Reference

#include "cmp.h"

Go to the source code of this file.

Defines

#define HIVE_LIST   L"\\registry\\machine\\system\\currentcontrolset\\control\\hivelist"
#define NAME_BUFFER_SIZE   512

Functions

BOOLEAN CmpGetHiveName (PCMHIVE CmHive, PUNICODE_STRING HiveName)
NTSTATUS CmpAddToHiveFileList (PCMHIVE CmHive)
VOID CmpRemoveFromHiveFileList (PCMHIVE CmHive)

Variables

PCMHIVE CmpMasterHive


Define Documentation

#define HIVE_LIST   L"\\registry\\machine\\system\\currentcontrolset\\control\\hivelist"
 

Definition at line 24 of file cmhvlist.c.

Referenced by CmpAddToHiveFileList(), and CmpRemoveFromHiveFileList().

#define NAME_BUFFER_SIZE   512
 

Referenced by CmpAddToHiveFileList().


Function Documentation

NTSTATUS CmpAddToHiveFileList PCMHIVE  CmHive  ) 
 

Definition at line 42 of file cmhvlist.c.

References Buffer, CML_MAJOR, CMLOG, CmpGetHiveName(), CMS_INIT_ERROR, ExAllocatePool, ExFreePool(), _CMHIVE::FileHandles, HFILE_TYPE_PRIMARY, _CMHIVE::Hive, HIVE_LIST, HIVE_VOLATILE, _HHIVE::HiveFlags, NAME_BUFFER_SIZE, NT_SUCCESS, NtClose(), NTSTATUS(), NULL, ObjectAttributes, PagedPool, RtlInitUnicodeString(), Status, and UnicodeNull.

Referenced by CmInitSystem1(), CmpInitializeHiveList(), and CmpWorker().

00047 : 00048 00049 Add Hive to list of hives and their files in 00050 \registry\machine\system\currentcontrolset\control\hivelist 00051 00052 Arguments: 00053 00054 HivePath - path to root of hive (e.g. \registry\machine\system) 00055 00056 CmHive - pointer to CM_HIVE structure for hive. 00057 00058 Return Value: 00059 00060 ntstatus 00061 00062 --*/ 00063 { 00064 // 00065 // PERFNOTE - allocate small instead of large buffers after 00066 // NtQueryObject is fixec - bryanwi 15may92 00067 // 00068 #define NAME_BUFFER_SIZE 512 00069 OBJECT_ATTRIBUTES ObjectAttributes; 00070 HANDLE KeyHandle; 00071 NTSTATUS Status; 00072 PUCHAR Buffer; 00073 ULONG Length; 00074 PWSTR FilePath; 00075 WCHAR UnicodeNull=UNICODE_NULL; 00076 UNICODE_STRING TempName; 00077 UNICODE_STRING HivePath; 00078 00079 // 00080 // create/open the hive list key 00081 // 00082 RtlInitUnicodeString( 00083 &TempName, 00084 HIVE_LIST 00085 ); 00086 00087 InitializeObjectAttributes( 00088 &ObjectAttributes, 00089 &TempName, 00090 OBJ_CASE_INSENSITIVE, 00091 (HANDLE)NULL, 00092 NULL 00093 ); 00094 00095 Status = ZwCreateKey( 00096 &KeyHandle, 00097 KEY_READ | KEY_WRITE, 00098 &ObjectAttributes, 00099 0, 00100 NULL, 00101 REG_OPTION_VOLATILE, 00102 NULL 00103 ); 00104 00105 if (!NT_SUCCESS(Status)) { 00106 CMLOG(CML_MAJOR, CMS_INIT_ERROR) { 00107 KdPrint(("CmpAddToHiveFileList: ")); 00108 KdPrint(("Create/Open of Hive list failed status = %08lx\n", Status)); 00109 } 00110 return Status; 00111 } 00112 00113 // 00114 // allocate work buffers 00115 // 00116 Buffer = ExAllocatePool(PagedPool, NAME_BUFFER_SIZE); 00117 if (Buffer == NULL) { 00118 NtClose(KeyHandle); 00119 return STATUS_NO_MEMORY; 00120 } 00121 00122 // 00123 // compute name of hive 00124 // 00125 if (! CmpGetHiveName(CmHive, &HivePath)) { 00126 NtClose(KeyHandle); 00127 ExFreePool(Buffer); 00128 return STATUS_NO_MEMORY; 00129 } 00130 00131 00132 // 00133 // get name of file 00134 // 00135 if (!(CmHive->Hive.HiveFlags & HIVE_VOLATILE)) { 00136 Status = ZwQueryObject( 00137 CmHive->FileHandles[HFILE_TYPE_PRIMARY], 00138 ObjectNameInformation, 00139 (PVOID)Buffer, 00140 NAME_BUFFER_SIZE, 00141 &Length 00142 ); 00143 Length -= sizeof(UNICODE_STRING); 00144 if (!NT_SUCCESS(Status)) { 00145 CMLOG(CML_MAJOR, CMS_INIT_ERROR) { 00146 KdPrint(("CmpAddToHiveFileList: ")); 00147 KdPrint(("Query of name2 failed status = %08lx\n", Status)); 00148 } 00149 NtClose(KeyHandle); 00150 ExFreePool(HivePath.Buffer); 00151 ExFreePool(Buffer); 00152 return Status; 00153 } 00154 FilePath = ((POBJECT_NAME_INFORMATION)Buffer)->Name.Buffer; 00155 FilePath[Length/sizeof(WCHAR)] = UNICODE_NULL; 00156 Length+=sizeof(WCHAR); 00157 } else { 00158 FilePath = &UnicodeNull; 00159 Length = sizeof(UnicodeNull); 00160 } 00161 00162 // 00163 // set entry in list 00164 // 00165 Status = ZwSetValueKey( 00166 KeyHandle, 00167 &HivePath, 00168 0, 00169 REG_SZ, 00170 FilePath, 00171 Length 00172 ); 00173 if (!NT_SUCCESS(Status)) { 00174 CMLOG(CML_MAJOR, CMS_INIT_ERROR) { 00175 KdPrint(("CmpAddToHiveFileList: ")); 00176 KdPrint(("Set of entry in Hive list failed status = %08lx\n", Status)); 00177 } 00178 } 00179 00180 NtClose(KeyHandle); 00181 ExFreePool(HivePath.Buffer); 00182 ExFreePool(Buffer); 00183 return Status; 00184 }

BOOLEAN CmpGetHiveName PCMHIVE  CmHive,
PUNICODE_STRING  HiveName
 

Definition at line 251 of file cmhvlist.c.

References _HHIVE::BaseBlock, CmpCopyCompressedName(), CmpHKeyNameLen, CmpMasterHive, ExAllocatePool, FALSE, _CM_KEY_NODE::Flags, HCELL_INDEX, _CMHIVE::Hive, HvGetCell, KEY_COMP_NAME, L, _CM_KEY_NODE::Name, _CM_KEY_NODE::NameLength, NULL, PagedPool, _CM_KEY_NODE::Parent, _HBASE_BLOCK::RootCell, TRUE, and USHORT.

Referenced by CmpAddToHiveFileList(), and CmpRemoveFromHiveFileList().

00257 : 00258 00259 Compute full path to a hive. 00260 00261 Arguments: 00262 00263 CmHive - pointer to CmHive structure 00264 00265 HiveName - supplies pointer to unicode string structure that 00266 will be filled in with pointer to name. 00267 00268 CALL IS EXPECTED TO FREE BUFFER 00269 00270 Return Value: 00271 00272 TRUE = it worked, FALSE = it failed (memory) 00273 00274 --*/ 00275 { 00276 HCELL_INDEX RootCell; 00277 HCELL_INDEX LinkCell; 00278 PCM_KEY_NODE LinkKey; 00279 PCM_KEY_NODE LinkParent; 00280 ULONG size; 00281 ULONG rsize; 00282 ULONG KeySize; 00283 ULONG ParentSize; 00284 PWCHAR p; 00285 PCM_KEY_NODE EntryKey; 00286 00287 // 00288 // First find the link cell. 00289 // 00290 RootCell = CmHive->Hive.BaseBlock->RootCell; 00291 EntryKey = (PCM_KEY_NODE)HvGetCell((PHHIVE)CmHive, RootCell); 00292 LinkCell = EntryKey->Parent; 00293 00294 // 00295 // Compute the value entry name, which is of the form: 00296 // \registry<parent of link node name><link node name> 00297 // 00298 LinkKey = (PCM_KEY_NODE)HvGetCell((PHHIVE)CmpMasterHive, LinkCell); 00299 LinkParent = (PCM_KEY_NODE)HvGetCell( 00300 (PHHIVE)CmpMasterHive, 00301 LinkKey->Parent 00302 ); 00303 rsize = wcslen(L"\\REGISTRY\\"); 00304 00305 KeySize = CmpHKeyNameLen(LinkKey); 00306 ParentSize = CmpHKeyNameLen(LinkParent); 00307 size = KeySize + ParentSize + 00308 (rsize * sizeof(WCHAR)) + sizeof(WCHAR); 00309 00310 HiveName->Buffer = ExAllocatePool(PagedPool, size); 00311 if (HiveName->Buffer == NULL) { 00312 return FALSE; 00313 } 00314 00315 HiveName->Length = (USHORT)size; 00316 HiveName->MaximumLength = (USHORT)size; 00317 p = HiveName->Buffer; 00318 00319 RtlCopyMemory( 00320 (PVOID)p, 00321 (PVOID)L"\\REGISTRY\\", 00322 rsize * sizeof(WCHAR) 00323 ); 00324 p += rsize; 00325 00326 if (LinkParent->Flags & KEY_COMP_NAME) { 00327 CmpCopyCompressedName(p, 00328 ParentSize, 00329 LinkParent->Name, 00330 LinkParent->NameLength); 00331 } else { 00332 RtlMoveMemory( 00333 (PVOID)p, 00334 (PVOID)&(LinkParent->Name[0]), 00335 ParentSize 00336 ); 00337 } 00338 00339 p += ParentSize / sizeof(WCHAR); 00340 00341 *p = OBJ_NAME_PATH_SEPARATOR; 00342 p++; 00343 00344 if (LinkKey->Flags & KEY_COMP_NAME) { 00345 CmpCopyCompressedName(p, 00346 KeySize, 00347 LinkKey->Name, 00348 LinkKey->NameLength); 00349 00350 } else { 00351 RtlMoveMemory( 00352 (PVOID)p, 00353 (PVOID)&(LinkKey->Name[0]), 00354 KeySize 00355 ); 00356 } 00357 00358 return TRUE; 00359 }

VOID CmpRemoveFromHiveFileList PCMHIVE  CmHive  ) 
 

Definition at line 188 of file cmhvlist.c.

References CmpGetHiveName(), ExFreePool(), HIVE_LIST, NT_SUCCESS, NtClose(), NTSTATUS(), NULL, ObjectAttributes, RtlInitUnicodeString(), and Status.

00193 : 00194 00195 Remove hive name from hive file list key 00196 00197 Arguments: 00198 00199 CmHive - pointer to CM_HIVE structure for hive. 00200 00201 Return Value: 00202 00203 ntstatus 00204 00205 --*/ 00206 { 00207 NTSTATUS Status; 00208 UNICODE_STRING EntryName; 00209 UNICODE_STRING TempName; 00210 OBJECT_ATTRIBUTES ObjectAttributes; 00211 HANDLE KeyHandle; 00212 00213 // 00214 // open the hive list key 00215 // 00216 RtlInitUnicodeString( 00217 &TempName, 00218 HIVE_LIST 00219 ); 00220 00221 InitializeObjectAttributes( 00222 &ObjectAttributes, 00223 &TempName, 00224 OBJ_CASE_INSENSITIVE, 00225 (HANDLE)NULL, 00226 NULL 00227 ); 00228 00229 Status = ZwOpenKey( 00230 &KeyHandle, 00231 KEY_READ | KEY_WRITE, 00232 &ObjectAttributes 00233 ); 00234 00235 if (!NT_SUCCESS(Status)) { 00236 return; 00237 } 00238 00239 CmpGetHiveName(CmHive, &EntryName); 00240 00241 ZwDeleteValueKey(KeyHandle, &EntryName); 00242 00243 NtClose(KeyHandle); 00244 ExFreePool(EntryName.Buffer); 00245 00246 return; 00247 }


Variable Documentation

PCMHIVE CmpMasterHive
 

Definition at line 26 of file cmhvlist.c.


Generated on Sat May 15 19:43:08 2004 for test by doxygen 1.3.7