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 IN OUT PUNICODE_STRING DestinationString
,
76 IN PCWSTR SourceString
);
79 RtlCompareUnicodeString(
80 IN PCUNICODE_STRING String1
,
81 IN PCUNICODE_STRING String2
,
82 IN BOOLEAN CaseInSensitive
);
87 IN ULONG BugCheckCode
,
88 IN ULONG_PTR BugCheckParameter1
,
89 IN ULONG_PTR BugCheckParameter2
,
90 IN ULONG_PTR BugCheckParameter3
,
91 IN ULONG_PTR BugCheckParameter4
);
95 OUT PLARGE_INTEGER CurrentTime
);
103 IN PRTL_BITMAP BitMapHeader
,
104 IN PULONG BitMapBuffer
,
105 IN ULONG SizeOfBitMap
);
109 IN PRTL_BITMAP BitMapHeader
,
110 IN ULONG NumberToFind
,
115 IN PRTL_BITMAP BitMapHeader
,
116 IN ULONG StartingIndex
,
117 IN ULONG NumberToSet
);
121 IN PRTL_BITMAP BitMapHeader
);
123 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP) / 32]) >> ((BP) % 32)) & 0x1)
124 #define UNREFERENCED_PARAMETER(P) {(P)=(P);}
126 #define PKTHREAD PVOID
127 #define PKGUARDED_MUTEX PVOID
128 #define PERESOURCE PVOID
129 #define PFILE_OBJECT PVOID
130 #define PKEVENT PVOID
131 #define PWORK_QUEUE_ITEM PVOID
132 #define EX_PUSH_LOCK PULONG_PTR
134 // Definitions copied from <ntifs.h>
135 // We only want to include host headers, so we define them manually
137 typedef USHORT SECURITY_DESCRIPTOR_CONTROL
, *PSECURITY_DESCRIPTOR_CONTROL
;
139 typedef struct _SECURITY_DESCRIPTOR_RELATIVE
143 SECURITY_DESCRIPTOR_CONTROL Control
;
148 } SECURITY_DESCRIPTOR_RELATIVE
, *PISECURITY_DESCRIPTOR_RELATIVE
;
150 #define CMLTRACE(x, ...)
153 #define REGISTRY_ERROR ((ULONG)0x00000051L)
156 // Debug/Tracing support
159 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
160 #define CMLTRACE DbgPrintEx
162 #define CMLTRACE(x, ...) \
163 if (x & CmlibTraceLevel) DbgPrint(__VA_ARGS__)
166 #define CMLTRACE(x, ...) DPRINT(__VA_ARGS__)
171 #include <bugcodes.h>
175 /* Prevent inclusion of Windows headers through <wine/unicode.h> */
183 // These define the Debug Masks Supported
185 #define CMLIB_HCELL_DEBUG 0x01
188 #define ROUND_UP(a,b) ((((a)+(b)-1)/(b))*(b))
189 #define ROUND_DOWN(a,b) (((a)/(b))*(b))
193 // PAGE_SIZE definition
196 #if defined(TARGET_i386) || defined(TARGET_amd64) || defined(TARGET_arm)
197 #define PAGE_SIZE 0x1000
199 #error Local PAGE_SIZE definition required when built as host
204 #define TAG_KCB 'bkMC'
205 #define TAG_CMHIVE 'vHMC'
206 #define TAG_CMSD 'DSMC'
210 #include <wine/unicode.h>
212 #include "hivedata.h"
215 #if defined(_TYPEDEFS_HOST_H) || defined(__FREELDR_H) // || defined(_BLDR_)
217 #define PCM_KEY_SECURITY_CACHE_ENTRY PVOID
218 #define PCM_KEY_CONTROL_BLOCK PVOID
219 #define PCM_CELL_REMAP_BLOCK PVOID
221 // See also ntoskrnl/include/internal/cm.h
222 #define CMP_SECURITY_HASH_LISTS 64
224 // #endif // Commented out until one finds a way to properly include
225 // this header in freeldr and in ntoskrnl.
228 // Use Count Log and Entry
230 typedef struct _CM_USE_COUNT_LOG_ENTRY
234 } CM_USE_COUNT_LOG_ENTRY
, *PCM_USE_COUNT_LOG_ENTRY
;
236 typedef struct _CM_USE_COUNT_LOG
240 CM_USE_COUNT_LOG_ENTRY Log
[32];
241 } CM_USE_COUNT_LOG
, *PCM_USE_COUNT_LOG
;
244 // Configuration Manager Hive Structure
246 typedef struct _CMHIVE
249 HANDLE FileHandles
[HFILE_TYPE_MAX
];
250 LIST_ENTRY NotifyList
;
252 EX_PUSH_LOCK HiveLock
;
253 PKTHREAD HiveLockOwner
;
254 PKGUARDED_MUTEX ViewLock
;
255 PKTHREAD ViewLockOwner
;
256 EX_PUSH_LOCK WriterLock
;
257 PKTHREAD WriterLockOwner
;
258 PERESOURCE FlusherLock
;
259 EX_PUSH_LOCK SecurityLock
;
260 PKTHREAD HiveSecurityLockOwner
;
261 LIST_ENTRY LRUViewListHead
;
262 LIST_ENTRY PinViewListHead
;
263 PFILE_OBJECT FileObject
;
264 UNICODE_STRING FileFullPath
;
265 UNICODE_STRING FileUserName
;
270 ULONG SecurityCacheSize
;
271 LONG SecurityHitHint
;
272 PCM_KEY_SECURITY_CACHE_ENTRY SecurityCache
;
273 LIST_ENTRY SecurityHash
[CMP_SECURITY_HASH_LISTS
];
275 PCM_KEY_CONTROL_BLOCK RootKcb
;
277 PWORK_QUEUE_ITEM UnloadWorkItem
;
278 BOOLEAN GrowOnlyMode
;
280 LIST_ENTRY KcbConvertListHead
;
281 LIST_ENTRY KnodeConvertListHead
;
282 PCM_CELL_REMAP_BLOCK CellRemapArray
;
283 CM_USE_COUNT_LOG UseCountLog
;
284 CM_USE_COUNT_LOG LockHiveLog
;
286 LIST_ENTRY TrustClassEntry
;
288 BOOLEAN HiveIsLoading
;
289 PKTHREAD CreatorOwner
;
292 #endif // See comment above
294 typedef struct _HV_HIVE_CELL_PAIR
298 } HV_HIVE_CELL_PAIR
, *PHV_HIVE_CELL_PAIR
;
300 #define STATIC_CELL_PAIR_COUNT 4
301 typedef struct _HV_TRACK_CELL_REF
305 PHV_HIVE_CELL_PAIR CellArray
;
306 HV_HIVE_CELL_PAIR StaticArray
[STATIC_CELL_PAIR_COUNT
];
308 } HV_TRACK_CELL_REF
, *PHV_TRACK_CELL_REF
;
310 extern ULONG CmlibTraceLevel
;
313 // Hack since bigkeys are not yet supported
315 #define ASSERT_VALUE_BIG(h, s) \
316 ASSERTMSG("Big keys not supported!", !CmpIsKeyValueBig(h, s));
319 // Returns whether or not this is a small valued key
323 CmpIsKeyValueSmall(OUT PULONG RealLength
,
326 /* Check if the length has the special size value */
327 if (Length
>= CM_KEY_VALUE_SPECIAL_SIZE
)
329 /* It does, so this is a small key: return the real length */
330 *RealLength
= Length
- CM_KEY_VALUE_SPECIAL_SIZE
;
334 /* This is not a small key, return the length we read */
335 *RealLength
= Length
;
340 // Returns whether or not this is a big valued key
344 CmpIsKeyValueBig(IN PHHIVE Hive
,
347 /* Check if the hive is XP Beta 1 or newer */
348 if (Hive
->Version
>= HSYS_WHISTLER_BETA1
)
350 /* Check if the key length is valid for a big value key */
351 if ((Length
< CM_KEY_VALUE_SPECIAL_SIZE
) && (Length
> CM_KEY_VALUE_BIG
))
353 /* Yes, this value is big */
358 /* Not a big value key */
363 * Public Hive functions.
371 PVOID HiveData OPTIONAL
,
372 PALLOCATE_ROUTINE Allocate
,
374 PFILE_SET_SIZE_ROUTINE FileSetSize
,
375 PFILE_WRITE_ROUTINE FileWrite
,
376 PFILE_READ_ROUTINE FileRead
,
377 PFILE_FLUSH_ROUTINE FileFlush
,
378 ULONG Cluster OPTIONAL
,
379 PCUNICODE_STRING FileName OPTIONAL
);
383 PHHIVE RegistryHive
);
388 HCELL_INDEX CellOffset
);
390 #define HvReleaseCell(h, c) \
392 if ((h)->ReleaseCellRoutine) \
393 (h)->ReleaseCellRoutine(h, c); \
405 HSTORAGE_TYPE Storage
,
406 IN HCELL_INDEX Vicinity
);
410 IN PHHIVE RegistryHive
,
411 IN HCELL_INDEX CellIndex
417 HCELL_INDEX CellOffset
,
423 HCELL_INDEX CellOffset
);
428 HCELL_INDEX CellOffset
,
429 BOOLEAN HoldingLock
);
440 IN PHHIVE RegistryHive
445 PHHIVE RegistryHive
);
449 PHHIVE RegistryHive
);
454 IN OUT PHV_TRACK_CELL_REF CellRef
,
461 HvReleaseFreeCellRefArray(
462 IN OUT PHV_TRACK_CELL_REF CellRef
473 HSTORAGE_TYPE Storage
);
476 HvpCreateHiveFreeCellList(
480 HvpHiveHeaderChecksum(
481 PHBASE_BLOCK HiveHeader
);
484 /* Old-style Public "Cmlib" functions */
493 PHHIVE RegistryHive
);
496 /* NT-style Public Cm functions */
499 // Cell Index Routines
505 IN PCM_KEY_NODE Parent
,
506 IN PCUNICODE_STRING SearchName
511 CmpFindSubKeyByNumber(
513 IN PCM_KEY_NODE Node
,
521 IN PCUNICODE_STRING Name
,
522 IN BOOLEAN AllowSeparators
529 IN HCELL_INDEX Parent
,
537 IN HCELL_INDEX ParentKey
,
538 IN HCELL_INDEX TargetKey
545 HCELL_INDEX ParentKey
,
546 HCELL_INDEX TargetKey
555 CmpCompareCompressedName(
556 IN PCUNICODE_STRING SearchName
,
557 IN PWCHAR CompressedName
,
565 IN PUNICODE_STRING Name
570 CmpCompressedNameSize(
579 OUT PWCHAR Destination
,
580 IN PUNICODE_STRING Source
585 CmpCopyCompressedName(
586 OUT PWCHAR Destination
,
587 IN ULONG DestinationLength
,
589 IN ULONG SourceLength
596 IN PCHILD_LIST ChildList
,
597 IN PUNICODE_STRING Name
,
598 OUT PULONG ChildIndex
,
599 OUT PHCELL_INDEX CellIndex
604 // Cell Value Routines
610 IN PCM_KEY_NODE KeyNode
,
611 IN PUNICODE_STRING Name
618 IN PCM_KEY_VALUE Value
,
628 IN ULONG StorageType
,
629 IN HCELL_INDEX ValueCell
,
630 OUT PHCELL_INDEX DataCell
637 IN HCELL_INDEX ValueCell
,
640 IN OUT PCHILD_LIST ChildList
652 CmpMarkValueDataDirty(
654 IN PCM_KEY_VALUE Value
661 IN HCELL_INDEX DataCell
,
667 CmpRemoveValueFromList(
670 IN OUT PCHILD_LIST ChildList
677 IN PCM_KEY_VALUE Value
,
680 OUT PBOOLEAN BufferAllocated
,
681 OUT PHCELL_INDEX CellToRelease
687 IN PHHIVE SourceHive
,
688 IN PCHILD_LIST SrcValueList
,
689 IN PHHIVE DestinationHive
,
690 IN OUT PCHILD_LIST DestValueList
,
691 IN HSTORAGE_TYPE StorageType
704 CmpRemoveSecurityCellList(
706 IN HCELL_INDEX SecurityCell
711 CmpFreeSecurityDescriptor(
716 /******************************************************************************/
718 /* To be implemented by the user of this library */
734 #endif /* _CMLIB_H_ */