Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

410 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. memdb.h
  5. Abstract:
  6. Declares interfaces for memdb, the memory database. MemDb is
  7. used throughout the Win9x upgrade project to record OS state
  8. and to track operations on files and the registry.
  9. See common\memdb for implementation details.
  10. Author:
  11. Jim Schmidt (jimschm) 15-Nov-1996
  12. Revision History:
  13. jimschm 05-Apr-1999 MemDbGetStoredEndPatternValue
  14. jimschm 18-Jan-1999 Version APIs
  15. jimschm 23-Sep-1998 Proxy node capability
  16. jimschm 24-Jun-1998 MemDbMove capability
  17. jimschm 30-Oct-1997 Temporary hive capability
  18. jimschm 31-Jul-1997 Hashing for faster access
  19. jimschm 19-Mar-1997 Binary node capability
  20. jimschm 28-Feb-1997 Offset access capabilities
  21. jimschm 20-Dec-1996 Ex routines
  22. --*/
  23. #pragma once
  24. #define INVALID_OFFSET 0xffffffff
  25. #include "memdbdef.h"
  26. #define MEMDB_MAX 2048
  27. //
  28. // My net share flag, used to distinguish user-level security and
  29. // password-level security. When it is specified, user-level
  30. // security is enabled, and NetShares\<share>\ACL\<list> exists.
  31. //
  32. #define SHI50F_ACLS 0x1000
  33. typedef BYTE const * PCBYTE;
  34. //
  35. // Enumerator struct
  36. //
  37. #define MAX_ENUM_POS (MEMDB_MAX/2)
  38. typedef struct {
  39. // Outbound key and value
  40. WCHAR szName[MEMDB_MAX];
  41. BOOL bEndpoint;
  42. BOOL bBinary;
  43. BOOL bProxy;
  44. DWORD UserFlags;
  45. // if !bBinary
  46. DWORD dwValue;
  47. // if bBinary
  48. PCBYTE BinaryPtr;
  49. DWORD BinarySize;
  50. DWORD Offset;
  51. // Internally maintained members
  52. WCHAR PatternStr[MEMDB_MAX];
  53. PWSTR PatPos;
  54. DWORD LastPos[MAX_ENUM_POS];
  55. int PosCount;
  56. int Depth;
  57. int Start;
  58. DWORD Flags;
  59. } MEMDB_ENUMW, *PMEMDB_ENUMW;
  60. typedef struct {
  61. // Outbound key and value
  62. CHAR szName[MEMDB_MAX * sizeof (WCHAR)];
  63. BOOL bEndpoint;
  64. BOOL bBinary;
  65. BOOL bProxy;
  66. DWORD UserFlags;
  67. // if !bBinary
  68. DWORD dwValue;
  69. // if bBinary
  70. PCBYTE BinaryPtr;
  71. DWORD BinarySize;
  72. DWORD Offset;
  73. // Internally maintained members
  74. WCHAR PatternStr[MEMDB_MAX];
  75. PWSTR PatPos;
  76. DWORD LastPos[MAX_ENUM_POS];
  77. int PosCount;
  78. int Depth;
  79. int Start;
  80. DWORD Flags;
  81. } MEMDB_ENUMA, *PMEMDB_ENUMA;
  82. // enumeration flags
  83. #define NO_FLAGS 0x00000000
  84. #define MEMDB_ALL_MATCHES 0
  85. #define MEMDB_ENDPOINTS_ONLY 1
  86. #define MEMDB_BINARY_NODES_ONLY 2
  87. #define MEMDB_PROXY_NODES_ONLY 3
  88. #define MEMDB_ALL_BUT_PROXY 4
  89. // enumeration level
  90. #define MEMDB_ALL_SUBLEVELS 0
  91. #define MEMDB_THIS_LEVEL_ONLY 1
  92. typedef struct {
  93. BOOL Valid;
  94. BOOL Debug;
  95. UINT Version;
  96. BOOL CurrentVersion;
  97. } MEMDB_VERSION, *PMEMDB_VERSION;
  98. //
  99. // Function prototypes
  100. //
  101. BOOL MemDbSetValueA (PCSTR szKeyName, DWORD dwValue);
  102. BOOL MemDbSetValueW (PCWSTR szKeyName, DWORD dwValue);
  103. BOOL MemDbSetValueAndFlagsA (PCSTR szKeyName, DWORD dwValue, DWORD SetFlags, DWORD ClearFlags);
  104. BOOL MemDbSetValueAndFlagsW (PCWSTR szKeyName, DWORD dwValue, DWORD SetFlags, DWORD ClearFlags);
  105. BOOL MemDbSetBinaryValueA (PCSTR szKeyName, PCBYTE Data, DWORD DataSize);
  106. BOOL MemDbSetBinaryValueW (PCWSTR szKeyName, PCBYTE Data, DWORD DataSize);
  107. BOOL MemDbGetValueA (PCSTR szKeyName, PDWORD lpdwValue);
  108. BOOL MemDbGetValueW (PCWSTR szKeyName, PDWORD lpdwValue);
  109. BOOL MemDbGetValueAndFlagsA (PCSTR szKeyName, PDWORD lpdwValue, PDWORD UserFlagsPtr);
  110. BOOL MemDbGetValueAndFlagsW (PCWSTR szKeyName, PDWORD lpdwValue, PDWORD UserFlagsPtr);
  111. PCBYTE MemDbGetBinaryValueA (PCSTR szKeyName, PDWORD DataSize);
  112. PCBYTE MemDbGetBinaryValueW (PCWSTR szKeyName, PDWORD DataSize);
  113. BOOL MemDbGetPatternValueA (PCSTR szKey, PDWORD lpdwValue);
  114. BOOL MemDbGetPatternValueW (PCWSTR szKey, PDWORD lpdwValue);
  115. BOOL MemDbGetStoredEndPatternValueA (PCSTR Key, PDWORD Value);
  116. BOOL MemDbGetStoredEndPatternValueW (PCWSTR Key, PDWORD Value);
  117. BOOL MemDbGetValueWithPatternA (PCSTR szKeyPattern, PDWORD lpdwValue);
  118. BOOL MemDbGetValueWithPatternW (PCWSTR szKeyPattern, PDWORD lpdwValue);
  119. BOOL MemDbGetPatternValueWithPatternA (PCSTR szKeyPattern, PDWORD lpdwValue);
  120. BOOL MemDbGetPatternValueWithPatternW (PCWSTR szKeyPattern, PDWORD lpdwValue);
  121. void MemDbDeleteValueA (PCSTR szKey);
  122. void MemDbDeleteValueW (PCWSTR szKey);
  123. void MemDbDeleteTreeA (PCSTR szKey);
  124. void MemDbDeleteTreeW (PCWSTR szKey);
  125. BOOL MemDbEnumFirstValueA (PMEMDB_ENUMA pEnum, PCSTR szPattern, int Depth, DWORD Flags);
  126. BOOL MemDbEnumFirstValueW (PMEMDB_ENUMW pEnum, PCWSTR szPattern, int Depth, DWORD Flags);
  127. BOOL MemDbEnumNextValueA (PMEMDB_ENUMA pEnum);
  128. BOOL MemDbEnumNextValueW (PMEMDB_ENUMW pEnum);
  129. BOOL MemDbSaveA (PCSTR szFile);
  130. BOOL MemDbSaveW (PCWSTR szFile);
  131. BOOL MemDbLoadA (PCSTR szFile);
  132. BOOL MemDbLoadW (PCWSTR szFile);
  133. VOID MemDbBuildKeyA (PSTR Buffer, PCSTR Category, PCSTR Item, PCSTR Field, PCSTR Data);
  134. VOID MemDbBuildKeyW (PWSTR Buffer, PCWSTR Category, PCWSTR Item, PCWSTR Field, PCWSTR Data);
  135. BOOL MemDbSetValueExA (PCSTR Category, PCSTR Item, PCSTR Field,
  136. PCSTR Data, DWORD Val, PDWORD Offset);
  137. BOOL MemDbSetValueExW (PCWSTR Category, PCWSTR Item, PCWSTR Field,
  138. PCWSTR Data, DWORD Val, PDWORD Offset);
  139. BOOL MemDbSetBinaryValueExA (PCSTR Category, PCSTR Item, PCSTR Field,
  140. PCBYTE Data, DWORD DataSize, PDWORD Offset);
  141. BOOL MemDbSetBinaryValueExW (PCWSTR Category, PCWSTR Item, PCWSTR Field,
  142. PCBYTE Data, DWORD DataSize, PDWORD Offset);
  143. BOOL MemDbBuildKeyFromOffsetA (DWORD Offset, PSTR Buffer, DWORD StartLevel, PDWORD Val);
  144. BOOL MemDbBuildKeyFromOffsetW (DWORD Offset, PWSTR Buffer, DWORD StartLevel, PDWORD Val);
  145. BOOL MemDbBuildKeyFromOffsetExA (DWORD Offset, PSTR Buffer, PDWORD BufferLen, DWORD StartLevel, PDWORD Val, PDWORD UserFlags);
  146. BOOL MemDbBuildKeyFromOffsetExW (DWORD Offset, PWSTR Buffer, PDWORD BufferLen, DWORD StartLevel, PDWORD Val, PDWORD UserFlags);
  147. BOOL MemDbGetOffsetA(PCSTR Key,PDWORD Offset);
  148. BOOL MemDbGetOffsetW(PCWSTR Key,PDWORD Offset);
  149. BOOL MemDbGetOffsetExA(PCSTR Category, PCSTR Item, PCSTR Field, PCSTR Data, PDWORD Offset);
  150. BOOL MemDbGetOffsetExW(PCWSTR Category, PCWSTR Item, PCWSTR Field, PCWSTR Data, PDWORD Offset);
  151. BOOL MemDbEnumItemsA (PMEMDB_ENUMA pEnum, PCSTR Category);
  152. BOOL MemDbEnumItemsW (PMEMDB_ENUMW pEnum, PCWSTR Category);
  153. BOOL MemDbEnumFieldsA (PMEMDB_ENUMA pEnum, PCSTR Category, PCSTR Item);
  154. BOOL MemDbEnumFieldsW (PMEMDB_ENUMW pEnum, PCWSTR Category, PCWSTR Item);
  155. BOOL MemDbGetValueExA (PMEMDB_ENUMA pEnum, PCSTR Category, PCSTR Item, PCSTR Field);
  156. BOOL MemDbGetValueExW (PMEMDB_ENUMW pEnum, PCWSTR Category, PCWSTR Item, PCWSTR Field);
  157. BOOL MemDbGetEndpointValueA (PCSTR Pattern, PCSTR Item, PSTR Buffer);
  158. BOOL MemDbGetEndpointValueW (PCWSTR Pattern, PCWSTR Item, PWSTR Buffer);
  159. BOOL MemDbGetEndpointValueExA (PCSTR Category, PCSTR Item, PCSTR Field, PSTR Buffer);
  160. BOOL MemDbGetEndpointValueExW (PCWSTR Category, PCWSTR Item, PCWSTR Field, PWSTR Buffer);
  161. BOOL MemDbValidateDatabase (VOID);
  162. BOOL MemDbQueryVersionA (PCSTR FileName, PMEMDB_VERSION Version);
  163. BOOL MemDbQueryVersionW (PCWSTR FileName, PMEMDB_VERSION Version);
  164. BOOL MemDbCreateTemporaryKeyA (PCSTR KeyName);
  165. BOOL MemDbCreateTemporaryKeyW (PCWSTR KeyName);
  166. BOOL
  167. MemDbMoveTreeA (
  168. IN PCSTR RootNode,
  169. IN PCSTR NewRoot
  170. );
  171. BOOL
  172. MemDbMoveTreeW (
  173. IN PCWSTR RootNode,
  174. IN PCWSTR NewRoot
  175. );
  176. BOOL
  177. MemDbExportA (
  178. IN PCSTR RootTree,
  179. IN PCSTR FileName,
  180. IN BOOL AnsiFormat
  181. );
  182. BOOL
  183. MemDbExportW (
  184. IN PCWSTR RootTree,
  185. IN PCWSTR FileName,
  186. IN BOOL AnsiFormat
  187. );
  188. BOOL
  189. MemDbImportA (
  190. IN PCSTR FileName
  191. );
  192. BOOL
  193. MemDbImportW (
  194. IN PCWSTR FileName
  195. );
  196. #define MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1 0x0001
  197. #define MEMDB_CONVERT_WILD_STAR_TO_ASCII_2 0x0002
  198. #define MEMDB_CONVERT_WILD_QMARK_TO_ASCII_3 0x0002
  199. // other conversion to be implemented when needed
  200. VOID MemDbMakeNonPrintableKeyA (PSTR KeyName, DWORD Flags);
  201. VOID MemDbMakeNonPrintableKeyW (PWSTR KeyName, DWORD Flags);
  202. VOID MemDbMakePrintableKeyA (PSTR KeyName, DWORD Flags);
  203. VOID MemDbMakePrintableKeyW (PWSTR KeyName, DWORD Flags);
  204. VOID GetFixedUserNameA (PSTR UserName);
  205. VOID GetFixedUserNameW (PWSTR UserName);
  206. //
  207. // Internal routines for memdbt
  208. //
  209. typedef struct {
  210. UINT NextItem : 28;
  211. UINT Hive : 4;
  212. } HASHINFO;
  213. typedef struct _tagHASHSTRUCT {
  214. DWORD Offset;
  215. HASHINFO Info;
  216. } BUCKETSTRUCT, *PBUCKETSTRUCT;
  217. typedef struct {
  218. PBUCKETSTRUCT BucketPtr;
  219. PBUCKETSTRUCT PrevBucketPtr;
  220. UINT Bucket;
  221. DWORD LastOffset;
  222. } HASHENUM, *PHASHENUM;
  223. BOOL
  224. EnumFirstHashEntry (
  225. OUT PHASHENUM HashEnum
  226. );
  227. BOOL
  228. EnumNextHashEntry (
  229. IN OUT PHASHENUM HashEnum
  230. );
  231. //
  232. // A & W
  233. //
  234. #ifdef UNICODE
  235. #define MEMDB_ENUM MEMDB_ENUMW
  236. #define PMEMDB_ENUM PMEMDB_ENUMW
  237. #define MemDbSetValue MemDbSetValueW
  238. #define MemDbSetValueAndFlags MemDbSetValueAndFlagsW
  239. #define MemDbSetBinaryValue MemDbSetBinaryValueW
  240. #define MemDbGetValue MemDbGetValueW
  241. #define MemDbGetValueAndFlags MemDbGetValueAndFlagsW
  242. #define MemDbGetBinaryValue MemDbGetBinaryValueW
  243. #define MemDbGetPatternValue MemDbGetPatternValueW
  244. #define MemDbGetValueWithPattern MemDbGetValueWithPatternW
  245. #define MemDbGetPatternValueWithPattern MemDbGetPatternValueWithPatternW
  246. #define MemDbGetStoredEndPatternValue MemDbGetStoredEndPatternValueW
  247. #define MemDbDeleteValue MemDbDeleteValueW
  248. #define MemDbDeleteTree MemDbDeleteTreeW
  249. #define MemDbEnumFirstValue MemDbEnumFirstValueW
  250. #define MemDbEnumNextValue MemDbEnumNextValueW
  251. #define MemDbSave MemDbSaveW
  252. #define MemDbLoad MemDbLoadW
  253. #define MemDbBuildKey MemDbBuildKeyW
  254. #define MemDbSetValueEx MemDbSetValueExW
  255. #define MemDbSetBinaryValueEx MemDbSetBinaryValueExW
  256. #define MemDbBuildKeyFromOffset MemDbBuildKeyFromOffsetW
  257. #define MemDbBuildKeyFromOffsetEx MemDbBuildKeyFromOffsetExW
  258. #define MemDbGetOffset MemDbGetOffsetW
  259. #define MemDbGetOffsetEx MemDbGetOffsetExW
  260. #define MemDbEnumItems MemDbEnumItemsW
  261. #define MemDbEnumFields MemDbEnumFieldsW
  262. #define MemDbGetValueEx MemDbGetValueExW
  263. #define MemDbGetEndpointValue MemDbGetEndpointValueW
  264. #define MemDbGetEndpointValueEx MemDbGetEndpointValueExW
  265. #define MemDbQueryVersion MemDbQueryVersionW
  266. #define MemDbCreateTemporaryKey MemDbCreateTemporaryKeyW
  267. #define MemDbMoveTree MemDbMoveTreeW
  268. #define MemDbExport MemDbExportW
  269. #define MemDbImport MemDbImportW
  270. #define MemDbMakeNonPrintableKey MemDbMakeNonPrintableKeyW
  271. #define MemDbMakePrintableKey MemDbMakePrintableKeyW
  272. #define GetFixedUserName GetFixedUserNameW
  273. #else
  274. #define MEMDB_ENUM MEMDB_ENUMA
  275. #define PMEMDB_ENUM PMEMDB_ENUMA
  276. #define MemDbSetValue MemDbSetValueA
  277. #define MemDbSetValueAndFlags MemDbSetValueAndFlagsA
  278. #define MemDbSetBinaryValue MemDbSetBinaryValueA
  279. #define MemDbGetValue MemDbGetValueA
  280. #define MemDbGetValueAndFlags MemDbGetValueAndFlagsA
  281. #define MemDbGetBinaryValue MemDbGetBinaryValueA
  282. #define MemDbGetPatternValue MemDbGetPatternValueA
  283. #define MemDbGetValueWithPattern MemDbGetValueWithPatternA
  284. #define MemDbGetPatternValueWithPattern MemDbGetPatternValueWithPatternA
  285. #define MemDbGetStoredEndPatternValue MemDbGetStoredEndPatternValueA
  286. #define MemDbDeleteValue MemDbDeleteValueA
  287. #define MemDbDeleteTree MemDbDeleteTreeA
  288. #define MemDbEnumFirstValue MemDbEnumFirstValueA
  289. #define MemDbEnumNextValue MemDbEnumNextValueA
  290. #define MemDbSave MemDbSaveA
  291. #define MemDbLoad MemDbLoadA
  292. #define MemDbBuildKey MemDbBuildKeyA
  293. #define MemDbSetValueEx MemDbSetValueExA
  294. #define MemDbSetBinaryValueEx MemDbSetBinaryValueExA
  295. #define MemDbBuildKeyFromOffset MemDbBuildKeyFromOffsetA
  296. #define MemDbBuildKeyFromOffsetEx MemDbBuildKeyFromOffsetExA
  297. #define MemDbGetOffset MemDbGetOffsetA
  298. #define MemDbGetOffsetEx MemDbGetOffsetExA
  299. #define MemDbEnumItems MemDbEnumItemsA
  300. #define MemDbEnumFields MemDbEnumFieldsA
  301. #define MemDbGetValueEx MemDbGetValueExA
  302. #define MemDbGetEndpointValue MemDbGetEndpointValueA
  303. #define MemDbGetEndpointValueEx MemDbGetEndpointValueExA
  304. #define MemDbQueryVersion MemDbQueryVersionA
  305. #define MemDbCreateTemporaryKey MemDbCreateTemporaryKeyA
  306. #define MemDbMoveTree MemDbMoveTreeA
  307. #define MemDbExport MemDbExportA
  308. #define MemDbImport MemDbImportA
  309. #define MemDbMakeNonPrintableKey MemDbMakeNonPrintableKeyA
  310. #define MemDbMakePrintableKey MemDbMakePrintableKeyA
  311. #define GetFixedUserName GetFixedUserNameA
  312. #endif