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.

420 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. object.h
  5. Abstract:
  6. Declares the interface for "objects" that are used in the Win9x
  7. to NT registry merge. The initial goal was to make a single
  8. merge routine work for all objects -- registry data, INI file
  9. data and file data. But this was abandoned because the approach
  10. was complex.
  11. So when you see object, think "registry object."
  12. See w95upgnt\merge\object.c for implementation details.
  13. Author:
  14. Jim Schmidt (jimschm) 14-Jan-1997
  15. Revision History:
  16. <alias> <date> <comments>
  17. --*/
  18. #pragma once
  19. #define MAX_ENCODED_OBJECT (MAX_OBJECT*6)
  20. extern POOLHANDLE g_TempPool;
  21. extern HKEY g_hKeyRootNT;
  22. extern HKEY g_hKeyRoot95;
  23. typedef struct {
  24. WORD UseCount;
  25. WORD OpenCount;
  26. HKEY OpenKey;
  27. BOOL Win95;
  28. TCHAR KeyString[]; // full key path, without root
  29. } KEYPROPS, *PKEYPROPS;
  30. typedef struct {
  31. DWORD Size;
  32. DWORD AllocatedSize;
  33. PBYTE Buffer;
  34. } BINARY_BUFFER, *PBINARY_BUFFER;
  35. typedef struct _tagDATAOBJECT {
  36. DWORD ObjectType;
  37. union {
  38. struct {
  39. INT RootItem;
  40. PKEYPROPS ParentKeyPtr;
  41. PCTSTR ChildKey;
  42. PKEYPROPS KeyPtr;
  43. PCTSTR ValueName;
  44. DWORD Type;
  45. BINARY_BUFFER Class;
  46. DWORD KeyEnum;
  47. DWORD ValNameEnum;
  48. };
  49. };
  50. BINARY_BUFFER Value;
  51. } DATAOBJECT, *PDATAOBJECT;
  52. typedef const PDATAOBJECT CPDATAOBJECT;
  53. #define MAX_CLASS_SIZE 2048
  54. typedef enum { // FILTER_RETURN_HANDLED FILTER_RETURN_CONTINUE
  55. FILTER_KEY_ENUM, // Sub objects not enumerated Sub objects enumerated
  56. FILTER_CREATE_KEY, // Skips empty object creation Creates the dest object
  57. FILTER_PROCESS_VALUES, // Object values not processed Object values processed
  58. FILTER_VALUENAME_ENUM, // Specific value skipped Specific value processed
  59. FILTER_VALUE_COPY // Object read but not written Object copied
  60. } FILTERTYPE;
  61. typedef enum {
  62. FILTER_RETURN_CONTINUE,
  63. FILTER_RETURN_FAIL,
  64. FILTER_RETURN_HANDLED,
  65. FILTER_RETURN_DONE, // return to parent key (if any)
  66. FILTER_RETURN_DELETED // object was deleted -- for object.c internal use only
  67. } FILTERRETURN;
  68. // DestObPtr may be NULL
  69. typedef FILTERRETURN(*FILTERFUNCTION)(CPDATAOBJECT ObjectPtr, CPDATAOBJECT DestObPtr, FILTERTYPE FilterType, PVOID Arg);
  70. #ifdef DEBUG
  71. #define OS_TRACKING_DEF , PCSTR File, UINT Line
  72. #else
  73. #define OS_TRACKING_DEF
  74. #endif
  75. VOID
  76. FixUpUserSpecifiedObject (
  77. PTSTR Object
  78. );
  79. //
  80. // The following functions modify the object structure, but not the
  81. // object itself.
  82. //
  83. BOOL
  84. TrackedCreateObjectStruct (
  85. IN PCTSTR ObjectStr,
  86. OUT PDATAOBJECT OutObPtr,
  87. IN BOOL ObjectType /* , */ // either WIN95OBJECT or WINNTOBJECT
  88. ALLOCATION_TRACKING_DEF
  89. );
  90. #define CreateObjectStruct(os,oop,ot) TrackedCreateObjectStruct(os,oop,ot /* , */ ALLOCATION_TRACKING_CALL)
  91. VOID
  92. CreateObjectString (
  93. IN CPDATAOBJECT InObPtr,
  94. OUT PTSTR ObjectStr
  95. );
  96. BOOL
  97. CombineObjectStructs (
  98. IN OUT PDATAOBJECT DestObPtr,
  99. IN CPDATAOBJECT SrcObPtr
  100. );
  101. VOID
  102. FreeObjectStruct (
  103. IN OUT PDATAOBJECT SrcObPtr
  104. );
  105. BOOL
  106. TrackedDuplicateObjectStruct (
  107. OUT PDATAOBJECT DestObPtr,
  108. IN CPDATAOBJECT SrcObPtr/* , */
  109. ALLOCATION_TRACKING_DEF
  110. );
  111. #define DuplicateObjectStruct(dest,src) TrackedDuplicateObjectStruct(dest,src /* , */ ALLOCATION_TRACKING_CALL)
  112. //
  113. // The following functions modify the object itself
  114. //
  115. FILTERRETURN
  116. CopyObject (
  117. IN OUT PDATAOBJECT SrcObPtr,
  118. IN CPDATAOBJECT DestObPtr,
  119. IN FILTERFUNCTION FilterFn, OPTIONAL
  120. IN PVOID FilterArg OPTIONAL
  121. );
  122. BOOL
  123. CreateObject (
  124. IN OUT PDATAOBJECT SrcObPtr
  125. );
  126. BOOL
  127. OpenObject (
  128. IN OUT PDATAOBJECT SrcObPtr
  129. );
  130. BOOL
  131. WriteObject (
  132. IN CPDATAOBJECT DestObPtr
  133. );
  134. BOOL
  135. ReadObject (
  136. IN OUT PDATAOBJECT SrcObPtr
  137. );
  138. BOOL
  139. ReadObjectEx (
  140. IN OUT PDATAOBJECT SrcObPtr,
  141. IN BOOL QueryOnly
  142. );
  143. VOID
  144. FreeObjectVal (
  145. IN OUT PDATAOBJECT SrcObPtr
  146. );
  147. VOID
  148. CloseObject (
  149. IN OUT PDATAOBJECT SrcObPtr
  150. );
  151. //
  152. // These functions are private utilities
  153. //
  154. PCTSTR
  155. ConvertKeyToRootString (
  156. HKEY RegRoot
  157. );
  158. HKEY
  159. ConvertRootStringToKey (
  160. PCTSTR RegPath,
  161. PDWORD LengthPtr OPTIONAL
  162. );
  163. //
  164. // Below are the DATAOBJECT flags and macros
  165. //
  166. // Values common to all object types
  167. #define OT_VALUE 0x00000001
  168. #define OT_TREE 0x00000002
  169. #define OT_WIN95 0x00000004 // if not specified, object is NT
  170. #define OT_OPEN 0x00000008
  171. // Values specific to the registry
  172. #define OT_REGISTRY_TYPE 0x00000010
  173. #define OT_REGISTRY_RELATIVE 0x00000100 // used for key renaming
  174. #define OT_REGISTRY_ENUM_KEY 0x00001000
  175. #define OT_REGISTRY_ENUM_VALUENAME 0x00002000
  176. #define OT_REGISTRY_CLASS 0x00010000
  177. #define WIN95OBJECT 1
  178. #define WINNTOBJECT 0
  179. // Flags that indicate which type of object
  180. #define OT_REGISTRY 0x80000000
  181. __inline BOOL DoesObjectHaveRegistryKey (CPDATAOBJECT p) {
  182. if (p->KeyPtr) {
  183. return TRUE;
  184. }
  185. return FALSE;
  186. }
  187. __inline BOOL DoesObjectHaveRegistryValName (CPDATAOBJECT p) {
  188. if (p->ValueName) {
  189. return TRUE;
  190. }
  191. return FALSE;
  192. }
  193. __inline BOOL IsObjectRegistryKeyOnly (CPDATAOBJECT p) {
  194. if (p->KeyPtr && !p->ValueName) {
  195. return TRUE;
  196. }
  197. return FALSE;
  198. }
  199. __inline BOOL IsObjectRegistryKeyAndVal (CPDATAOBJECT p) {
  200. if (p->KeyPtr && p->ValueName) {
  201. return TRUE;
  202. }
  203. return FALSE;
  204. }
  205. __inline BOOL IsObjectRegistryKeyComplete (CPDATAOBJECT p) {
  206. if (p->KeyPtr && p->KeyPtr->OpenKey) {
  207. return TRUE;
  208. }
  209. return FALSE;
  210. }
  211. __inline BOOL DoesObjectHaveValue (CPDATAOBJECT p) {
  212. if (p->ObjectType & OT_VALUE) {
  213. return TRUE;
  214. }
  215. return FALSE;
  216. }
  217. __inline BOOL IsWin95Object (CPDATAOBJECT p) {
  218. if (p->ObjectType & OT_WIN95) {
  219. return TRUE;
  220. }
  221. return FALSE;
  222. }
  223. __inline BOOL IsRegistryKeyOpen (CPDATAOBJECT p) {
  224. if (p->KeyPtr && p->KeyPtr->OpenKey) {
  225. return TRUE;
  226. }
  227. return FALSE;
  228. }
  229. __inline BOOL IsRegistryTypeSpecified (CPDATAOBJECT p) {
  230. if (p->ObjectType & OT_REGISTRY_TYPE) {
  231. return TRUE;
  232. }
  233. return FALSE;
  234. }
  235. BOOL
  236. SetRegistryKey (
  237. PDATAOBJECT p,
  238. PCTSTR Key
  239. );
  240. BOOL
  241. GetRegistryKeyStrFromObject (
  242. IN CPDATAOBJECT InObPtr,
  243. OUT PTSTR RegKey
  244. );
  245. VOID
  246. FreeRegistryKey (
  247. PDATAOBJECT p
  248. );
  249. VOID
  250. FreeRegistryParentKey (
  251. PDATAOBJECT p
  252. );
  253. BOOL
  254. SetRegistryValueName (
  255. PDATAOBJECT p,
  256. PCTSTR ValueName
  257. );
  258. VOID
  259. FreeRegistryValueName (
  260. PDATAOBJECT p
  261. );
  262. BOOL
  263. SetRegistryClass (
  264. PDATAOBJECT p,
  265. PBYTE Class,
  266. DWORD ClassSize
  267. );
  268. VOID
  269. FreeRegistryClass (
  270. PDATAOBJECT p
  271. );
  272. VOID
  273. SetRegistryType (
  274. PDATAOBJECT p,
  275. DWORD Type
  276. );
  277. BOOL
  278. SetPlatformType (
  279. PDATAOBJECT p,
  280. BOOL Win95Type
  281. );
  282. BOOL
  283. ReadWin95ObjectString (
  284. PCTSTR ObjectStr,
  285. PDATAOBJECT ObPtr
  286. );
  287. BOOL
  288. WriteWinNTObjectString (
  289. PCTSTR ObjectStr,
  290. CPDATAOBJECT SrcObPtr
  291. );
  292. BOOL
  293. ReplaceValue (
  294. PDATAOBJECT ObPtr,
  295. PBYTE NewValue,
  296. DWORD Size
  297. );
  298. BOOL
  299. GetDwordFromObject (
  300. CPDATAOBJECT ObPtr,
  301. PDWORD DwordPtr OPTIONAL
  302. );
  303. PCTSTR
  304. GetStringFromObject (
  305. CPDATAOBJECT ObPtr
  306. );
  307. #define ReplaceValueWithString(x,s) ReplaceValue((x),(PBYTE)(s),SizeOfString(s))
  308. BOOL
  309. DeleteDataObject (
  310. IN PDATAOBJECT ObjectPtr
  311. );
  312. BOOL
  313. DeleteDataObjectValue(
  314. IN CPDATAOBJECT ObPtr
  315. );
  316. BOOL
  317. RenameDataObject (
  318. IN CPDATAOBJECT SrcObPtr,
  319. IN CPDATAOBJECT DestObPtr
  320. );
  321. BOOL
  322. CheckIfNtKeyExists (
  323. IN CPDATAOBJECT SrcObjectPtr
  324. );