2 * PROJECT: Registry manipulation library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
5 * Copyright 2001 - 2005 Eric Kohl
12 // Debug support switch
14 #define _CMLIB_DEBUG_ 1
21 // NTDDI_xxx versions we allude to in the library (see psdk/sdkddkver.h)
22 #define NTDDI_WS03SP4 0x05020400
23 #define NTDDI_WIN6 0x06000000
24 #define NTDDI_LONGHORN NTDDI_WIN6
25 #define NTDDI_VISTA NTDDI_WIN6
26 #define NTDDI_WIN7 0x06010000
28 #define NTDDI_VERSION NTDDI_WS03SP4 // This is the ReactOS NT kernel version
30 /* C_ASSERT Definition */
31 #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
34 #define strncasecmp _strnicmp
35 #define strcasecmp _stricmp
38 #if (!defined(_MSC_VER) || (_MSC_VER < 1500))
43 #define _In_range_(x, y)
46 #define __drv_aliasesMem
49 #define min(a, b) (((a) < (b)) ? (a) : (b))
53 // #define max(a, b) (((a) > (b)) ? (a) : (b))
56 // Definitions copied from <ntstatus.h>
57 // We only want to include host headers, so we define them manually
58 #define STATUS_SUCCESS ((NTSTATUS)0x00000000)
59 #define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002)
60 #define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
61 #define STATUS_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC000009A)
62 #define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)
63 #define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
64 #define STATUS_REGISTRY_RECOVERED ((NTSTATUS)0x40000009)
66 #define REG_OPTION_VOLATILE 1
67 #define OBJ_CASE_INSENSITIVE 0x00000040L
68 #define USHORT_MAX USHRT_MAX
70 #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
71 #define UNICODE_NULL ((WCHAR)0)
75 OUT PLARGE_INTEGER CurrentTime
);
83 IN PRTL_BITMAP BitMapHeader
,
84 IN PULONG BitMapBuffer
,
85 IN ULONG SizeOfBitMap
);
89 IN PRTL_BITMAP BitMapHeader
,
90 IN ULONG NumberToFind
,
95 IN PRTL_BITMAP BitMapHeader
,
96 IN ULONG StartingIndex
,
97 IN ULONG NumberToSet
);
101 IN PRTL_BITMAP BitMapHeader
);
103 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP) / 32]) >> ((BP) % 32)) & 0x1)
104 #define UNREFERENCED_PARAMETER(P) {(P)=(P);}
106 #define PKTHREAD PVOID
107 #define PKGUARDED_MUTEX PVOID
108 #define PERESOURCE PVOID
109 #define PFILE_OBJECT PVOID
110 #define PKEVENT PVOID
111 #define PWORK_QUEUE_ITEM PVOID
112 #define EX_PUSH_LOCK PULONG_PTR
114 // Definitions copied from <ntifs.h>
115 // We only want to include host headers, so we define them manually
117 typedef USHORT SECURITY_DESCRIPTOR_CONTROL
, *PSECURITY_DESCRIPTOR_CONTROL
;
119 typedef struct _SECURITY_DESCRIPTOR_RELATIVE
123 SECURITY_DESCRIPTOR_CONTROL Control
;
128 } SECURITY_DESCRIPTOR_RELATIVE
, *PISECURITY_DESCRIPTOR_RELATIVE
;
130 #define CMLTRACE(x, ...)
133 #define REGISTRY_ERROR ((ULONG)0x00000051L)
136 // Debug/Tracing support
139 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
140 #define CMLTRACE DbgPrintEx
142 #define CMLTRACE(x, ...) \
143 if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)
146 #define CMLTRACE(x, ...) DPRINT(__VA_ARGS__)
151 #include <bugcodes.h>
155 /* Prevent inclusion of Windows headers through <wine/unicode.h> */
163 // These define the Debug Masks Supported
165 #define CMLIB_HCELL_DEBUG 0x01
168 #define ROUND_UP(a,b) ((((a)+(b)-1)/(b))*(b))
169 #define ROUND_DOWN(a,b) (((a)/(b))*(b))
173 // PAGE_SIZE definition
176 #if defined(TARGET_i386) || defined(TARGET_amd64) || defined(TARGET_arm)
177 #define PAGE_SIZE 0x1000
179 #error Local PAGE_SIZE definition required when built as host
184 #define TAG_KCB 'bkMC'
185 #define TAG_CMHIVE 'vHMC'
186 #define TAG_CMSD 'DSMC'
190 #include <wine/unicode.h>
192 #include "hivedata.h"
195 #if defined(_TYPEDEFS_HOST_H) || defined(__FREELDR_H) // || defined(_BLDR_)
197 #define PCM_KEY_SECURITY_CACHE_ENTRY PVOID
198 #define PCM_KEY_CONTROL_BLOCK PVOID
199 #define PCM_CELL_REMAP_BLOCK PVOID
201 // See also ntoskrnl/include/internal/cm.h
202 #define CMP_SECURITY_HASH_LISTS 64
204 // #endif // Commented out until one finds a way to properly include
205 // this header in freeldr and in ntoskrnl.
208 // Use Count Log and Entry
210 typedef struct _CM_USE_COUNT_LOG_ENTRY
214 } CM_USE_COUNT_LOG_ENTRY
, *PCM_USE_COUNT_LOG_ENTRY
;
216 typedef struct _CM_USE_COUNT_LOG
220 CM_USE_COUNT_LOG_ENTRY Log
[32];
221 } CM_USE_COUNT_LOG
, *PCM_USE_COUNT_LOG
;
224 // Configuration Manager Hive Structure
226 typedef struct _CMHIVE
229 HANDLE FileHandles
[HFILE_TYPE_MAX
];
230 LIST_ENTRY NotifyList
;
232 EX_PUSH_LOCK HiveLock
;
233 PKTHREAD HiveLockOwner
;
234 PKGUARDED_MUTEX ViewLock
;
235 PKTHREAD ViewLockOwner
;
236 EX_PUSH_LOCK WriterLock
;
237 PKTHREAD WriterLockOwner
;
238 PERESOURCE FlusherLock
;
239 EX_PUSH_LOCK SecurityLock
;
240 PKTHREAD HiveSecurityLockOwner
;
241 LIST_ENTRY LRUViewListHead
;
242 LIST_ENTRY PinViewListHead
;
243 PFILE_OBJECT FileObject
;
244 UNICODE_STRING FileFullPath
;
245 UNICODE_STRING FileUserName
;
250 ULONG SecurityCacheSize
;
251 LONG SecurityHitHint
;
252 PCM_KEY_SECURITY_CACHE_ENTRY SecurityCache
;
253 LIST_ENTRY SecurityHash
[CMP_SECURITY_HASH_LISTS
];
255 PCM_KEY_CONTROL_BLOCK RootKcb
;
257 PWORK_QUEUE_ITEM UnloadWorkItem
;
258 BOOLEAN GrowOnlyMode
;
260 LIST_ENTRY KcbConvertListHead
;
261 LIST_ENTRY KnodeConvertListHead
;
262 PCM_CELL_REMAP_BLOCK CellRemapArray
;
263 CM_USE_COUNT_LOG UseCountLog
;
264 CM_USE_COUNT_LOG LockHiveLog
;
266 LIST_ENTRY TrustClassEntry
;
268 BOOLEAN HiveIsLoading
;
269 PKTHREAD CreatorOwner
;
272 #endif // See comment above
274 typedef struct _HV_HIVE_CELL_PAIR
278 } HV_HIVE_CELL_PAIR
, *PHV_HIVE_CELL_PAIR
;
280 #define STATIC_CELL_PAIR_COUNT 4
281 typedef struct _HV_TRACK_CELL_REF
285 PHV_HIVE_CELL_PAIR CellArray
;
286 HV_HIVE_CELL_PAIR StaticArray
[STATIC_CELL_PAIR_COUNT
];
288 } HV_TRACK_CELL_REF
, *PHV_TRACK_CELL_REF
;
290 extern ULONG CmlibTraceLevel
;
293 // Hack since bigkeys are not yet supported
295 #define ASSERT_VALUE_BIG(h, s) \
296 ASSERTMSG("Big keys not supported!", !CmpIsKeyValueBig(h, s));
299 // Returns whether or not this is a small valued key
303 CmpIsKeyValueSmall(OUT PULONG RealLength
,
306 /* Check if the length has the special size value */
307 if (Length
>= CM_KEY_VALUE_SPECIAL_SIZE
)
309 /* It does, so this is a small key: return the real length */
310 *RealLength
= Length
- CM_KEY_VALUE_SPECIAL_SIZE
;
314 /* This is not a small key, return the length we read */
315 *RealLength
= Length
;
320 // Returns whether or not this is a big valued key
324 CmpIsKeyValueBig(IN PHHIVE Hive
,
327 /* Check if the hive is XP Beta 1 or newer */
328 if (Hive
->Version
>= HSYS_WHISTLER_BETA1
)
330 /* Check if the key length is valid for a big value key */
331 if ((Length
< CM_KEY_VALUE_SPECIAL_SIZE
) && (Length
> CM_KEY_VALUE_BIG
))
333 /* Yes, this value is big */
338 /* Not a big value key */
343 * Public Hive functions.
351 PVOID HiveData OPTIONAL
,
352 PALLOCATE_ROUTINE Allocate
,
354 PFILE_SET_SIZE_ROUTINE FileSetSize
,
355 PFILE_WRITE_ROUTINE FileWrite
,
356 PFILE_READ_ROUTINE FileRead
,
357 PFILE_FLUSH_ROUTINE FileFlush
,
358 ULONG Cluster OPTIONAL
,
359 PCUNICODE_STRING FileName OPTIONAL
);
363 PHHIVE RegistryHive
);
368 HCELL_INDEX CellOffset
);
370 #define HvReleaseCell(h, c) \
372 if ((h)->ReleaseCellRoutine) \
373 (h)->ReleaseCellRoutine(h, c); \
385 HSTORAGE_TYPE Storage
,
386 IN HCELL_INDEX Vicinity
);
390 IN PHHIVE RegistryHive
,
391 IN HCELL_INDEX CellIndex
397 HCELL_INDEX CellOffset
,
403 HCELL_INDEX CellOffset
);
408 HCELL_INDEX CellOffset
,
409 BOOLEAN HoldingLock
);
420 IN PHHIVE RegistryHive
425 PHHIVE RegistryHive
);
429 PHHIVE RegistryHive
);
434 PHV_TRACK_CELL_REF CellRef
,
441 HvReleaseFreeCellRefArray(
442 PHV_TRACK_CELL_REF CellRef
453 HSTORAGE_TYPE Storage
);
456 HvpCreateHiveFreeCellList(
460 HvpHiveHeaderChecksum(
461 PHBASE_BLOCK HiveHeader
);
464 /* Old-style Public "Cmlib" functions */
473 PHHIVE RegistryHive
);
476 /* NT-style Public Cm functions */
479 // Cell Index Routines
485 IN PCM_KEY_NODE Parent
,
486 IN PCUNICODE_STRING SearchName
491 CmpFindSubKeyByNumber(
493 IN PCM_KEY_NODE Node
,
501 IN PCUNICODE_STRING Name
,
502 IN BOOLEAN AllowSeparators
509 IN HCELL_INDEX Parent
,
517 IN HCELL_INDEX ParentKey
,
518 IN HCELL_INDEX TargetKey
525 HCELL_INDEX ParentKey
,
526 HCELL_INDEX TargetKey
535 CmpCompareCompressedName(
536 IN PCUNICODE_STRING SearchName
,
537 IN PWCHAR CompressedName
,
545 IN PUNICODE_STRING Name
550 CmpCompressedNameSize(
559 IN PWCHAR Destination
,
560 IN PUNICODE_STRING Source
565 CmpCopyCompressedName(
566 IN PWCHAR Destination
,
567 IN ULONG DestinationLength
,
569 IN ULONG SourceLength
576 IN PCHILD_LIST ChildList
,
577 IN PUNICODE_STRING Name
,
578 OUT PULONG ChildIndex
,
579 OUT PHCELL_INDEX CellIndex
584 // Cell Value Routines
590 IN PCM_KEY_NODE KeyNode
,
591 IN PUNICODE_STRING Name
598 IN PCM_KEY_VALUE Value
,
608 IN ULONG StorageType
,
609 IN HCELL_INDEX ValueCell
,
610 OUT PHCELL_INDEX DataCell
617 IN HCELL_INDEX ValueCell
,
620 IN OUT PCHILD_LIST ChildList
632 CmpMarkValueDataDirty(
634 IN PCM_KEY_VALUE Value
641 IN HCELL_INDEX DataCell
,
647 CmpRemoveValueFromList(
650 IN OUT PCHILD_LIST ChildList
657 IN PCM_KEY_VALUE Value
,
660 OUT PBOOLEAN BufferAllocated
,
661 OUT PHCELL_INDEX CellToRelease
667 IN PHHIVE SourceHive
,
668 IN PCHILD_LIST SrcValueList
,
669 IN PHHIVE DestinationHive
,
670 IN OUT PCHILD_LIST DestValueList
,
671 IN HSTORAGE_TYPE StorageType
684 CmpRemoveSecurityCellList(
686 IN HCELL_INDEX SecurityCell
691 CmpFreeSecurityDescriptor(
696 /******************************************************************************/
698 /* To be implemented by the user of this library */
714 #endif /* _CMLIB_H_ */