xref: /reactos/sdk/lib/cmlib/cmlib.h (revision cc63d8f4)
1 /*
2  * PROJECT:     ReactOS Kernel
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Configuration Manager Library - CMLIB header
5  * COPYRIGHT:   Copyright 2001 - 2005 Eric Kohl
6  *              Copyright 2022 George Bișoc <george.bisoc@reactos.org>
7  */
8 
9 #ifndef _CMLIB_H_
10 #define _CMLIB_H_
11 
12 //
13 // Debug support switch
14 //
15 #define _CMLIB_DEBUG_ 1
16 
17 #ifdef CMLIB_HOST
18     #include <typedefs.h>
19     #include <stdio.h>
20     #include <string.h>
21 
22     // NTDDI_xxx versions we allude to in the library (see psdk/sdkddkver.h)
23     #define NTDDI_WS03SP4                       0x05020400
24     #define NTDDI_WIN6                          0x06000000
25     #define NTDDI_LONGHORN                      NTDDI_WIN6
26     #define NTDDI_VISTA                         NTDDI_WIN6
27     #define NTDDI_WIN7                          0x06010000
28 
29     #define NTDDI_VERSION   NTDDI_WS03SP4 // This is the ReactOS NT kernel version
30 
31     /* C_ASSERT Definition */
32     #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
33 
34     #ifdef _WIN32
35     #define strncasecmp _strnicmp
36     #define strcasecmp _stricmp
37     #endif // _WIN32
38 
39     #if (!defined(_MSC_VER) || (_MSC_VER < 1500))
40     #define _In_
41     #define _Out_
42     #define _Inout_
43     #define _In_opt_
44     #define _In_range_(x, y)
45     #endif
46 
47     #define __drv_aliasesMem
48 
49     #ifndef min
50     #define min(a, b)  (((a) < (b)) ? (a) : (b))
51     #endif
52 
53     // #ifndef max
54     // #define max(a, b)  (((a) > (b)) ? (a) : (b))
55     // #endif
56 
57     // Definitions copied from <ntstatus.h>
58     // We only want to include host headers, so we define them manually
59     #define STATUS_SUCCESS                   ((NTSTATUS)0x00000000)
60     #define STATUS_NOT_IMPLEMENTED           ((NTSTATUS)0xC0000002)
61     #define STATUS_NO_MEMORY                 ((NTSTATUS)0xC0000017)
62     #define STATUS_INSUFFICIENT_RESOURCES    ((NTSTATUS)0xC000009A)
63     #define STATUS_INVALID_PARAMETER         ((NTSTATUS)0xC000000D)
64     #define STATUS_REGISTRY_CORRUPT          ((NTSTATUS)0xC000014C)
65     #define STATUS_REGISTRY_IO_FAILED        ((NTSTATUS)0xC000014D)
66     #define STATUS_NOT_REGISTRY_FILE         ((NTSTATUS)0xC000015C)
67     #define STATUS_REGISTRY_RECOVERED        ((NTSTATUS)0x40000009)
68 
69     #define REG_OPTION_VOLATILE              1
70     #define OBJ_CASE_INSENSITIVE             0x00000040L
71     #define USHORT_MAX                       USHRT_MAX
72 
73     #define OBJ_NAME_PATH_SEPARATOR          ((WCHAR)L'\\')
74     #define UNICODE_NULL                     ((WCHAR)0)
75 
76     VOID NTAPI
77     RtlInitUnicodeString(
78         IN OUT PUNICODE_STRING DestinationString,
79         IN PCWSTR SourceString);
80 
81     LONG NTAPI
82     RtlCompareUnicodeString(
83         IN PCUNICODE_STRING String1,
84         IN PCUNICODE_STRING String2,
85         IN BOOLEAN CaseInSensitive);
86 
87     // FIXME: DECLSPEC_NORETURN
88     VOID
89     NTAPI
90     KeBugCheckEx(
91         IN ULONG BugCheckCode,
92         IN ULONG_PTR BugCheckParameter1,
93         IN ULONG_PTR BugCheckParameter2,
94         IN ULONG_PTR BugCheckParameter3,
95         IN ULONG_PTR BugCheckParameter4);
96 
97     VOID NTAPI
98     KeQuerySystemTime(
99         OUT PLARGE_INTEGER CurrentTime);
100 
101     WCHAR NTAPI
102     RtlUpcaseUnicodeChar(
103         IN WCHAR Source);
104 
105     VOID NTAPI
106     RtlInitializeBitMap(
107         IN PRTL_BITMAP BitMapHeader,
108         IN PULONG BitMapBuffer,
109         IN ULONG SizeOfBitMap);
110 
111     ULONG NTAPI
112     RtlFindSetBits(
113         IN PRTL_BITMAP BitMapHeader,
114         IN ULONG NumberToFind,
115         IN ULONG HintIndex);
116 
117     VOID NTAPI
118     RtlSetBits(
119         IN PRTL_BITMAP BitMapHeader,
120         IN ULONG StartingIndex,
121         IN ULONG NumberToSet);
122 
123     VOID NTAPI
124     RtlClearAllBits(
125         IN PRTL_BITMAP BitMapHeader);
126 
127     #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP) / 32]) >> ((BP) % 32)) & 0x1)
128     #define UNREFERENCED_PARAMETER(P) ((void)(P))
129 
130     #define PKTHREAD PVOID
131     #define PKGUARDED_MUTEX PVOID
132     #define PERESOURCE PVOID
133     #define PFILE_OBJECT PVOID
134     #define PKEVENT PVOID
135     #define PWORK_QUEUE_ITEM PVOID
136     #define EX_PUSH_LOCK PULONG_PTR
137 
138     // Definitions copied from <ntifs.h>
139     // We only want to include host headers, so we define them manually
140 
141     typedef USHORT SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
142 
143     typedef struct _SECURITY_DESCRIPTOR_RELATIVE
144     {
145         UCHAR Revision;
146         UCHAR Sbz1;
147         SECURITY_DESCRIPTOR_CONTROL Control;
148         ULONG Owner;
149         ULONG Group;
150         ULONG Sacl;
151         ULONG Dacl;
152     } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
153 
154     #define CMLTRACE(x, ...)
155     #undef PAGED_CODE
156     #define PAGED_CODE()
157     #define REGISTRY_ERROR                   ((ULONG)0x00000051L)
158 
159 #else
160 
161     //
162     // Debug/Tracing support
163     //
164     #if _CMLIB_DEBUG_
165     #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
166     #define CMLTRACE DbgPrintEx
167     #else
168     #define CMLTRACE(x, ...)                                 \
169     if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)
170     #endif
171     #else
172     #define CMLTRACE(x, ...) DPRINT(__VA_ARGS__)
173     #endif
174 
175     #include <ntdef.h>
176     #include <ntifs.h>
177     #include <bugcodes.h>
178 
179     /* Prevent inclusion of Windows headers through <wine/unicode.h> */
180     #define _WINDEF_
181     #define _WINBASE_
182     #define _WINNLS_
183 #endif
184 
185 
186 //
187 // These define the Debug Masks Supported
188 //
189 #define CMLIB_HCELL_DEBUG       0x01
190 
191 #ifndef ROUND_UP
192 #define ROUND_UP(a,b)        ((((a)+(b)-1)/(b))*(b))
193 #define ROUND_DOWN(a,b)      (((a)/(b))*(b))
194 #endif
195 
196 //
197 // PAGE_SIZE definition
198 //
199 #ifndef PAGE_SIZE
200 #if defined(TARGET_i386) || defined(TARGET_amd64) || \
201     defined(TARGET_arm)  || defined(TARGET_arm64)
202 #define PAGE_SIZE 0x1000
203 #else
204 #error Local PAGE_SIZE definition required when built as host
205 #endif
206 #endif
207 
208 #define TAG_CM             '  MC'
209 #define TAG_KCB            'bkMC'
210 #define TAG_CMHIVE         'vHMC'
211 #define TAG_CMSD           'DSMC'
212 #define TAG_REGISTRY_STACK 'sRMC'
213 
214 #define CMAPI NTAPI
215 
216 //
217 // Check Registry status type definition
218 //
219 typedef ULONG CM_CHECK_REGISTRY_STATUS;
220 
221 //
222 // Check Registry flags
223 //
224 #define CM_CHECK_REGISTRY_DONT_PURGE_VOLATILES        0x0
225 #define CM_CHECK_REGISTRY_PURGE_VOLATILES             0x2
226 #define CM_CHECK_REGISTRY_BOOTLOADER_PURGE_VOLATILES  0x4
227 #define CM_CHECK_REGISTRY_VALIDATE_HIVE               0x8
228 #define CM_CHECK_REGISTRY_FIX_HIVE                    0x10
229 
230 //
231 // Check Registry status codes
232 //
233 #define CM_CHECK_REGISTRY_GOOD                         0
234 #define CM_CHECK_REGISTRY_INVALID_PARAMETER            1
235 #define CM_CHECK_REGISTRY_SD_INVALID                   2
236 #define CM_CHECK_REGISTRY_HIVE_CORRUPT_SIGNATURE       3
237 #define CM_CHECK_REGISTRY_BIN_SIZE_OR_OFFSET_CORRUPT   4
238 #define CM_CHECK_REGISTRY_BIN_SIGNATURE_HEADER_CORRUPT 5
239 #define CM_CHECK_REGISTRY_BAD_FREE_CELL                6
240 #define CM_CHECK_REGISTRY_BAD_ALLOC_CELL               7
241 #define CM_CHECK_REGISTRY_ALLOCATE_MEM_STACK_FAIL      8
242 #define CM_CHECK_REGISTRY_ROOT_CELL_NOT_FOUND          9
243 #define CM_CHECK_REGISTRY_BAD_LEXICOGRAPHICAL_ORDER    10
244 #define CM_CHECK_REGISTRY_NODE_NOT_FOUND               11
245 #define CM_CHECK_REGISTRY_SUBKEY_NOT_FOUND             12
246 #define CM_CHECK_REGISTRY_TREE_TOO_MANY_LEVELS         13
247 #define CM_CHECK_REGISTRY_KEY_CELL_NOT_ALLOCATED       14
248 #define CM_CHECK_REGISTRY_CELL_DATA_NOT_FOUND          15
249 #define CM_CHECK_REGISTRY_CELL_SIZE_NOT_SANE           16
250 #define CM_CHECK_REGISTRY_KEY_NAME_LENGTH_ZERO         17
251 #define CM_CHECK_REGISTRY_KEY_TOO_BIG_THAN_CELL        18
252 #define CM_CHECK_REGISTRY_BAD_KEY_NODE_PARENT          19
253 #define CM_CHECK_REGISTRY_BAD_KEY_NODE_SIGNATURE       20
254 #define CM_CHECK_REGISTRY_KEY_CLASS_UNALLOCATED        21
255 #define CM_CHECK_REGISTRY_VALUE_LIST_UNALLOCATED       22
256 #define CM_CHECK_REGISTRY_VALUE_LIST_DATA_NOT_FOUND    23
257 #define CM_CHECK_REGISTRY_VALUE_LIST_SIZE_NOT_SANE     24
258 #define CM_CHECK_REGISTRY_VALUE_CELL_NIL               25
259 #define CM_CHECK_REGISTRY_VALUE_CELL_UNALLOCATED       26
260 #define CM_CHECK_REGISTRY_VALUE_CELL_DATA_NOT_FOUND    27
261 #define CM_CHECK_REGISTRY_VALUE_CELL_SIZE_NOT_SANE     28
262 #define CM_CHECK_REGISTRY_CORRUPT_VALUE_DATA           29
263 #define CM_CHECK_REGISTRY_DATA_CELL_NOT_ALLOCATED      30
264 #define CM_CHECK_REGISTRY_BAD_KEY_VALUE_SIGNATURE      31
265 #define CM_CHECK_REGISTRY_STABLE_KEYS_ON_VOLATILE      32
266 #define CM_CHECK_REGISTRY_SUBKEYS_LIST_UNALLOCATED     33
267 #define CM_CHECK_REGISTRY_CORRUPT_SUBKEYS_INDEX        34
268 #define CM_CHECK_REGISTRY_BAD_SUBKEY_COUNT             35
269 #define CM_CHECK_REGISTRY_KEY_INDEX_CELL_UNALLOCATED   36
270 #define CM_CHECK_REGISTRY_CORRUPT_LEAF_ON_ROOT         37
271 #define CM_CHECK_REGISTRY_CORRUPT_LEAF_SIGNATURE       38
272 #define CM_CHECK_REGISTRY_CORRUPT_KEY_INDEX_SIGNATURE  39
273 
274 //
275 // Check Registry success macro
276 //
277 #define CM_CHECK_REGISTRY_SUCCESS(StatusCode) ((ULONG)(StatusCode) == CM_CHECK_REGISTRY_GOOD)
278 
279 #include <wine/unicode.h>
280 #include <wchar.h>
281 #include "hivedata.h"
282 #include "cmdata.h"
283 
284 /* Forward declarations */
285 typedef struct _CM_KEY_SECURITY_CACHE_ENTRY *PCM_KEY_SECURITY_CACHE_ENTRY;
286 typedef struct _CM_KEY_CONTROL_BLOCK *PCM_KEY_CONTROL_BLOCK;
287 typedef struct _CM_CELL_REMAP_BLOCK *PCM_CELL_REMAP_BLOCK;
288 
289 // See ntoskrnl/include/internal/cm.h
290 #define CMP_SECURITY_HASH_LISTS     64
291 
292 //
293 // Use Count Log and Entry
294 //
295 typedef struct _CM_USE_COUNT_LOG_ENTRY
296 {
297     HCELL_INDEX Cell;
298     PVOID Stack[7];
299 } CM_USE_COUNT_LOG_ENTRY, *PCM_USE_COUNT_LOG_ENTRY;
300 
301 typedef struct _CM_USE_COUNT_LOG
302 {
303     USHORT Next;
304     USHORT Size;
305     CM_USE_COUNT_LOG_ENTRY Log[32];
306 } CM_USE_COUNT_LOG, *PCM_USE_COUNT_LOG;
307 
308 //
309 // Configuration Manager Hive Structure
310 //
311 typedef struct _CMHIVE
312 {
313     HHIVE Hive;
314     HANDLE FileHandles[HFILE_TYPE_MAX];
315     LIST_ENTRY NotifyList;
316     LIST_ENTRY HiveList;
317     EX_PUSH_LOCK HiveLock;
318     PKTHREAD HiveLockOwner;
319     PKGUARDED_MUTEX ViewLock;
320     PKTHREAD ViewLockOwner;
321     EX_PUSH_LOCK WriterLock;
322     PKTHREAD WriterLockOwner;
323     PERESOURCE FlusherLock;
324     EX_PUSH_LOCK SecurityLock;
325     PKTHREAD HiveSecurityLockOwner;
326     LIST_ENTRY LRUViewListHead;
327     LIST_ENTRY PinViewListHead;
328     PFILE_OBJECT FileObject;
329     UNICODE_STRING FileFullPath;
330     UNICODE_STRING FileUserName;
331     USHORT MappedViews;
332     USHORT PinnedViews;
333     ULONG UseCount;
334     ULONG SecurityCount;
335     ULONG SecurityCacheSize;
336     LONG SecurityHitHint;
337     PCM_KEY_SECURITY_CACHE_ENTRY SecurityCache;
338     LIST_ENTRY SecurityHash[CMP_SECURITY_HASH_LISTS];
339     PKEVENT UnloadEvent;
340     PCM_KEY_CONTROL_BLOCK RootKcb;
341     BOOLEAN Frozen;
342     PWORK_QUEUE_ITEM UnloadWorkItem;
343     BOOLEAN GrowOnlyMode;
344     ULONG GrowOffset;
345     LIST_ENTRY KcbConvertListHead;
346     LIST_ENTRY KnodeConvertListHead;
347     PCM_CELL_REMAP_BLOCK CellRemapArray;
348     CM_USE_COUNT_LOG UseCountLog;
349     CM_USE_COUNT_LOG LockHiveLog;
350     ULONG Flags;
351     LIST_ENTRY TrustClassEntry;
352     ULONG FlushCount;
353     BOOLEAN HiveIsLoading;
354     PKTHREAD CreatorOwner;
355 } CMHIVE, *PCMHIVE;
356 
357 typedef struct _HV_HIVE_CELL_PAIR
358 {
359     PHHIVE Hive;
360     HCELL_INDEX Cell;
361 } HV_HIVE_CELL_PAIR, *PHV_HIVE_CELL_PAIR;
362 
363 #define STATIC_CELL_PAIR_COUNT 4
364 typedef struct _HV_TRACK_CELL_REF
365 {
366     USHORT Count;
367     USHORT Max;
368     PHV_HIVE_CELL_PAIR CellArray;
369     HV_HIVE_CELL_PAIR StaticArray[STATIC_CELL_PAIR_COUNT];
370     USHORT StaticCount;
371 } HV_TRACK_CELL_REF, *PHV_TRACK_CELL_REF;
372 
373 extern ULONG CmlibTraceLevel;
374 
375 //
376 // Hack since big keys are not yet supported
377 //
378 #define ASSERT_VALUE_BIG(h, s)  \
379     ASSERTMSG("Big keys not supported!\n", !CmpIsKeyValueBig(h, s));
380 
381 //
382 // Returns whether or not this is a small valued key
383 //
384 static inline
385 BOOLEAN
386 CmpIsKeyValueSmall(OUT PULONG RealLength,
387                    IN ULONG Length)
388 {
389     /* Check if the length has the special size value */
390     if (Length >= CM_KEY_VALUE_SPECIAL_SIZE)
391     {
392         /* It does, so this is a small key: return the real length */
393         *RealLength = Length - CM_KEY_VALUE_SPECIAL_SIZE;
394         return TRUE;
395     }
396 
397     /* This is not a small key, return the length we read */
398     *RealLength = Length;
399     return FALSE;
400 }
401 
402 //
403 // Returns whether or not this is a big valued key
404 //
405 static inline
406 BOOLEAN
407 CmpIsKeyValueBig(IN PHHIVE Hive,
408                  IN ULONG Length)
409 {
410     /* Check if the hive is XP Beta 1 or newer */
411     if (Hive->Version >= HSYS_WHISTLER_BETA1)
412     {
413         /* Check if the key length is valid for a big value key */
414         if ((Length < CM_KEY_VALUE_SPECIAL_SIZE) && (Length > CM_KEY_VALUE_BIG))
415         {
416             /* Yes, this value is big */
417             return TRUE;
418         }
419     }
420 
421     /* Not a big value key */
422     return FALSE;
423 }
424 
425 /*
426  * Public Hive functions.
427  */
428 NTSTATUS CMAPI
429 HvInitialize(
430     PHHIVE RegistryHive,
431     ULONG OperationType,
432     ULONG HiveFlags,
433     ULONG FileType,
434     PVOID HiveData OPTIONAL,
435     PALLOCATE_ROUTINE Allocate,
436     PFREE_ROUTINE Free,
437     PFILE_SET_SIZE_ROUTINE FileSetSize,
438     PFILE_WRITE_ROUTINE FileWrite,
439     PFILE_READ_ROUTINE FileRead,
440     PFILE_FLUSH_ROUTINE FileFlush,
441     ULONG Cluster OPTIONAL,
442     PCUNICODE_STRING FileName OPTIONAL);
443 
444 VOID CMAPI
445 HvFree(
446    PHHIVE RegistryHive);
447 
448 #define HvGetCell(Hive, Cell)   \
449     (Hive)->GetCellRoutine(Hive, Cell)
450 
451 #define HvReleaseCell(Hive, Cell)               \
452 do {                                            \
453     if ((Hive)->ReleaseCellRoutine)             \
454         (Hive)->ReleaseCellRoutine(Hive, Cell); \
455 } while(0)
456 
457 LONG CMAPI
458 HvGetCellSize(
459    PHHIVE RegistryHive,
460    PVOID Cell);
461 
462 HCELL_INDEX CMAPI
463 HvAllocateCell(
464    PHHIVE RegistryHive,
465    ULONG Size,
466    HSTORAGE_TYPE Storage,
467    IN HCELL_INDEX Vicinity);
468 
469 BOOLEAN CMAPI
470 HvIsCellAllocated(
471     IN PHHIVE RegistryHive,
472     IN HCELL_INDEX CellIndex
473 );
474 
475 HCELL_INDEX CMAPI
476 HvReallocateCell(
477    PHHIVE RegistryHive,
478    HCELL_INDEX CellOffset,
479    ULONG Size);
480 
481 VOID CMAPI
482 HvFreeCell(
483    PHHIVE RegistryHive,
484    HCELL_INDEX CellOffset);
485 
486 BOOLEAN CMAPI
487 HvMarkCellDirty(
488    PHHIVE RegistryHive,
489    HCELL_INDEX CellOffset,
490    BOOLEAN HoldingLock);
491 
492 BOOLEAN CMAPI
493 HvIsCellDirty(
494     IN PHHIVE Hive,
495     IN HCELL_INDEX Cell
496 );
497 
498 BOOLEAN
499 CMAPI
500 HvHiveWillShrink(
501     IN PHHIVE RegistryHive
502 );
503 
504 BOOLEAN CMAPI
505 HvSyncHive(
506    PHHIVE RegistryHive);
507 
508 BOOLEAN CMAPI
509 HvWriteHive(
510    PHHIVE RegistryHive);
511 
512 BOOLEAN
513 CMAPI
514 HvSyncHiveFromRecover(
515     _In_ PHHIVE RegistryHive);
516 
517 BOOLEAN
518 CMAPI
519 HvTrackCellRef(
520     IN OUT PHV_TRACK_CELL_REF CellRef,
521     IN PHHIVE Hive,
522     IN HCELL_INDEX Cell
523 );
524 
525 VOID
526 CMAPI
527 HvReleaseFreeCellRefArray(
528     IN OUT PHV_TRACK_CELL_REF CellRef
529 );
530 
531 /*
532  * Private functions.
533  */
534 
535 PCELL_DATA CMAPI
536 HvpGetCellData(
537     _In_ PHHIVE Hive,
538     _In_ HCELL_INDEX CellIndex);
539 
540 PHBIN CMAPI
541 HvpAddBin(
542    PHHIVE RegistryHive,
543    ULONG Size,
544    HSTORAGE_TYPE Storage);
545 
546 NTSTATUS CMAPI
547 HvpCreateHiveFreeCellList(
548    PHHIVE Hive);
549 
550 ULONG CMAPI
551 HvpHiveHeaderChecksum(
552    PHBASE_BLOCK HiveHeader);
553 
554 BOOLEAN CMAPI
555 HvpVerifyHiveHeader(
556     _In_ PHBASE_BLOCK BaseBlock,
557     _In_ ULONG FileType);
558 
559 //
560 // Registry Self-Heal Routines
561 //
562 BOOLEAN
563 CMAPI
564 CmIsSelfHealEnabled(
565     _In_ BOOLEAN FixHive);
566 
567 BOOLEAN
568 CMAPI
569 CmpRepairParentKey(
570     _Inout_ PHHIVE Hive,
571     _In_ HCELL_INDEX TargetKey,
572     _In_ HCELL_INDEX ParentKey,
573     _In_ BOOLEAN FixHive);
574 
575 BOOLEAN
576 CMAPI
577 CmpRepairParentNode(
578     _Inout_ PHHIVE Hive,
579     _In_ HCELL_INDEX DirtyCell,
580     _In_ HCELL_INDEX ParentCell,
581     _Inout_ PCELL_DATA CellData,
582     _In_ BOOLEAN FixHive);
583 
584 BOOLEAN
585 CMAPI
586 CmpRepairKeyNodeSignature(
587     _Inout_ PHHIVE Hive,
588     _In_ HCELL_INDEX DirtyCell,
589     _Inout_ PCELL_DATA CellData,
590     _In_ BOOLEAN FixHive);
591 
592 BOOLEAN
593 CMAPI
594 CmpRepairClassOfNodeKey(
595     _Inout_ PHHIVE Hive,
596     _In_ HCELL_INDEX DirtyCell,
597     _Inout_ PCELL_DATA CellData,
598     _In_ BOOLEAN FixHive);
599 
600 BOOLEAN
601 CMAPI
602 CmpRepairValueList(
603     _Inout_ PHHIVE Hive,
604     _In_ HCELL_INDEX CurrentCell,
605     _In_ BOOLEAN FixHive);
606 
607 BOOLEAN
608 CMAPI
609 CmpRepairValueListCount(
610     _Inout_ PHHIVE Hive,
611     _In_ HCELL_INDEX CurrentCell,
612     _In_ ULONG ListCountIndex,
613     _Inout_ PCELL_DATA ValueListData,
614     _In_ BOOLEAN FixHive);
615 
616 BOOLEAN
617 CMAPI
618 CmpRepairSubKeyCounts(
619     _Inout_ PHHIVE Hive,
620     _In_ HCELL_INDEX CurrentCell,
621     _In_ ULONG Count,
622     _Inout_ PCELL_DATA CellData,
623     _In_ BOOLEAN FixHive);
624 
625 BOOLEAN
626 CMAPI
627 CmpRepairSubKeyList(
628     _Inout_ PHHIVE Hive,
629     _In_ HCELL_INDEX CurrentCell,
630     _Inout_ PCELL_DATA CellData,
631     _In_ BOOLEAN FixHive);
632 
633 /* Old-style Public "Cmlib" functions */
634 
635 BOOLEAN CMAPI
636 CmCreateRootNode(
637    PHHIVE Hive,
638    PCWSTR Name);
639 
640 VOID CMAPI
641 CmPrepareHive(
642    PHHIVE RegistryHive);
643 
644 
645 /* NT-style Public Cm functions */
646 
647 //
648 // Check Registry Routines
649 //
650 CM_CHECK_REGISTRY_STATUS
651 NTAPI
652 HvValidateBin(
653     _In_ PHHIVE Hive,
654     _In_ PHBIN Bin);
655 
656 CM_CHECK_REGISTRY_STATUS
657 NTAPI
658 HvValidateHive(
659     _In_ PHHIVE Hive);
660 
661 CM_CHECK_REGISTRY_STATUS
662 NTAPI
663 CmCheckRegistry(
664     _In_ PCMHIVE RegistryHive,
665     _In_ ULONG Flags);
666 
667 //
668 // Cell Index Routines
669 //
670 HCELL_INDEX
671 NTAPI
672 CmpFindSubKeyByName(
673     IN PHHIVE Hive,
674     IN PCM_KEY_NODE Parent,
675     IN PCUNICODE_STRING SearchName
676 );
677 
678 HCELL_INDEX
679 NTAPI
680 CmpFindSubKeyByNumber(
681     IN PHHIVE Hive,
682     IN PCM_KEY_NODE Node,
683     IN ULONG Number
684 );
685 
686 ULONG
687 NTAPI
688 CmpComputeHashKey(
689     IN ULONG Hash,
690     IN PCUNICODE_STRING Name,
691     IN BOOLEAN AllowSeparators
692 );
693 
694 BOOLEAN
695 NTAPI
696 CmpAddSubKey(
697     IN PHHIVE Hive,
698     IN HCELL_INDEX Parent,
699     IN HCELL_INDEX Child
700 );
701 
702 BOOLEAN
703 NTAPI
704 CmpRemoveSubKey(
705     IN PHHIVE Hive,
706     IN HCELL_INDEX ParentKey,
707     IN HCELL_INDEX TargetKey
708 );
709 
710 BOOLEAN
711 NTAPI
712 CmpMarkIndexDirty(
713     IN PHHIVE Hive,
714     HCELL_INDEX ParentKey,
715     HCELL_INDEX TargetKey
716 );
717 
718 
719 //
720 // Name Functions
721 //
722 LONG
723 NTAPI
724 CmpCompareCompressedName(
725     IN PCUNICODE_STRING SearchName,
726     IN PWCHAR CompressedName,
727     IN ULONG NameLength
728 );
729 
730 USHORT
731 NTAPI
732 CmpNameSize(
733     IN PHHIVE Hive,
734     IN PCUNICODE_STRING Name
735 );
736 
737 USHORT
738 NTAPI
739 CmpCompressedNameSize(
740     IN PWCHAR Name,
741     IN ULONG Length
742 );
743 
744 USHORT
745 NTAPI
746 CmpCopyName(
747     IN PHHIVE Hive,
748     OUT PWCHAR Destination,
749     IN PCUNICODE_STRING Source
750 );
751 
752 VOID
753 NTAPI
754 CmpCopyCompressedName(
755     OUT PWCHAR Destination,
756     IN ULONG DestinationLength,
757     IN PWCHAR Source,
758     IN ULONG SourceLength
759 );
760 
761 BOOLEAN
762 NTAPI
763 CmpFindNameInList(
764     IN PHHIVE Hive,
765     IN PCHILD_LIST ChildList,
766     IN PCUNICODE_STRING Name,
767     OUT PULONG ChildIndex OPTIONAL,
768     OUT PHCELL_INDEX CellIndex
769 );
770 
771 
772 //
773 // Cell Value Routines
774 //
775 HCELL_INDEX
776 NTAPI
777 CmpFindValueByName(
778     IN PHHIVE Hive,
779     IN PCM_KEY_NODE KeyNode,
780     IN PCUNICODE_STRING Name
781 );
782 
783 PCELL_DATA
784 NTAPI
785 CmpValueToData(
786     IN PHHIVE Hive,
787     IN PCM_KEY_VALUE Value,
788     OUT PULONG Length
789 );
790 
791 NTSTATUS
792 NTAPI
793 CmpSetValueDataNew(
794     IN PHHIVE Hive,
795     IN PVOID Data,
796     IN ULONG DataSize,
797     IN HSTORAGE_TYPE StorageType,
798     IN HCELL_INDEX ValueCell,
799     OUT PHCELL_INDEX DataCell
800 );
801 
802 NTSTATUS
803 NTAPI
804 CmpAddValueToList(
805     IN PHHIVE Hive,
806     IN HCELL_INDEX ValueCell,
807     IN ULONG Index,
808     IN HSTORAGE_TYPE StorageType,
809     IN OUT PCHILD_LIST ChildList
810 );
811 
812 BOOLEAN
813 NTAPI
814 CmpFreeValue(
815     IN PHHIVE Hive,
816     IN HCELL_INDEX Cell
817 );
818 
819 BOOLEAN
820 NTAPI
821 CmpMarkValueDataDirty(
822     IN PHHIVE Hive,
823     IN PCM_KEY_VALUE Value
824 );
825 
826 BOOLEAN
827 NTAPI
828 CmpFreeValueData(
829     IN PHHIVE Hive,
830     IN HCELL_INDEX DataCell,
831     IN ULONG DataLength
832 );
833 
834 NTSTATUS
835 NTAPI
836 CmpRemoveValueFromList(
837     IN PHHIVE Hive,
838     IN ULONG Index,
839     IN OUT PCHILD_LIST ChildList
840 );
841 
842 BOOLEAN
843 NTAPI
844 CmpGetValueData(
845     IN PHHIVE Hive,
846     IN PCM_KEY_VALUE Value,
847     OUT PULONG Length,
848     OUT PVOID *Buffer,
849     OUT PBOOLEAN BufferAllocated,
850     OUT PHCELL_INDEX CellToRelease
851 );
852 
853 NTSTATUS
854 NTAPI
855 CmpCopyKeyValueList(
856     IN PHHIVE SourceHive,
857     IN PCHILD_LIST SrcValueList,
858     IN PHHIVE DestinationHive,
859     IN OUT PCHILD_LIST DestValueList,
860     IN HSTORAGE_TYPE StorageType
861 );
862 
863 NTSTATUS
864 NTAPI
865 CmpFreeKeyByCell(
866     IN PHHIVE Hive,
867     IN HCELL_INDEX Cell,
868     IN BOOLEAN Unlink
869 );
870 
871 VOID
872 NTAPI
873 CmpRemoveSecurityCellList(
874     IN PHHIVE Hive,
875     IN HCELL_INDEX SecurityCell
876 );
877 
878 VOID
879 NTAPI
880 CmpFreeSecurityDescriptor(
881     IN PHHIVE Hive,
882     IN HCELL_INDEX Cell
883 );
884 
885 /******************************************************************************/
886 
887 /* To be implemented by the user of this library */
888 PVOID
889 NTAPI
890 CmpAllocate(
891     IN SIZE_T Size,
892     IN BOOLEAN Paged,
893     IN ULONG Tag
894 );
895 
896 VOID
897 NTAPI
898 CmpFree(
899     IN PVOID Ptr,
900     IN ULONG Quota
901 );
902 
903 #endif /* _CMLIB_H_ */
904