Leaked source code of windows server 2003
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.

422 lines
8.3 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. IN DWORD ObjectSizeInTChars
  96. );
  97. BOOL
  98. CombineObjectStructs (
  99. IN OUT PDATAOBJECT DestObPtr,
  100. IN CPDATAOBJECT SrcObPtr
  101. );
  102. VOID
  103. FreeObjectStruct (
  104. IN OUT PDATAOBJECT SrcObPtr
  105. );
  106. BOOL
  107. TrackedDuplicateObjectStruct (
  108. OUT PDATAOBJECT DestObPtr,
  109. IN CPDATAOBJECT SrcObPtr/* , */
  110. ALLOCATION_TRACKING_DEF
  111. );
  112. #define DuplicateObjectStruct(dest,src) TrackedDuplicateObjectStruct(dest,src /* , */ ALLOCATION_TRACKING_CALL)
  113. //
  114. // The following functions modify the object itself
  115. //
  116. FILTERRETURN
  117. CopyObject (
  118. IN OUT PDATAOBJECT SrcObPtr,
  119. IN CPDATAOBJECT DestObPtr,
  120. IN FILTERFUNCTION FilterFn, OPTIONAL
  121. IN PVOID FilterArg OPTIONAL
  122. );
  123. BOOL
  124. CreateObject (
  125. IN OUT PDATAOBJECT SrcObPtr
  126. );
  127. BOOL
  128. OpenObject (
  129. IN OUT PDATAOBJECT SrcObPtr
  130. );
  131. BOOL
  132. WriteObject (
  133. IN CPDATAOBJECT DestObPtr
  134. );
  135. BOOL
  136. ReadObject (
  137. IN OUT PDATAOBJECT SrcObPtr
  138. );
  139. BOOL
  140. ReadObjectEx (
  141. IN OUT PDATAOBJECT SrcObPtr,
  142. IN BOOL QueryOnly
  143. );
  144. VOID
  145. FreeObjectVal (
  146. IN OUT PDATAOBJECT SrcObPtr
  147. );
  148. VOID
  149. CloseObject (
  150. IN OUT PDATAOBJECT SrcObPtr
  151. );
  152. //
  153. // These functions are private utilities
  154. //
  155. PCTSTR
  156. ConvertKeyToRootString (
  157. HKEY RegRoot
  158. );
  159. HKEY
  160. ConvertRootStringToKey (
  161. PCTSTR RegPath,
  162. PDWORD LengthPtr OPTIONAL
  163. );
  164. //
  165. // Below are the DATAOBJECT flags and macros
  166. //
  167. // Values common to all object types
  168. #define OT_VALUE 0x00000001
  169. #define OT_TREE 0x00000002
  170. #define OT_WIN95 0x00000004 // if not specified, object is NT
  171. #define OT_OPEN 0x00000008
  172. // Values specific to the registry
  173. #define OT_REGISTRY_TYPE 0x00000010
  174. #define OT_REGISTRY_RELATIVE 0x00000100 // used for key renaming
  175. #define OT_REGISTRY_ENUM_KEY 0x00001000
  176. #define OT_REGISTRY_ENUM_VALUENAME 0x00002000
  177. #define OT_REGISTRY_CLASS 0x00010000
  178. #define WIN95OBJECT 1
  179. #define WINNTOBJECT 0
  180. // Flags that indicate which type of object
  181. #define OT_REGISTRY 0x80000000
  182. __inline BOOL DoesObjectHaveRegistryKey (CPDATAOBJECT p) {
  183. if (p->KeyPtr) {
  184. return TRUE;
  185. }
  186. return FALSE;
  187. }
  188. __inline BOOL DoesObjectHaveRegistryValName (CPDATAOBJECT p) {
  189. if (p->ValueName) {
  190. return TRUE;
  191. }
  192. return FALSE;
  193. }
  194. __inline BOOL IsObjectRegistryKeyOnly (CPDATAOBJECT p) {
  195. if (p->KeyPtr && !p->ValueName) {
  196. return TRUE;
  197. }
  198. return FALSE;
  199. }
  200. __inline BOOL IsObjectRegistryKeyAndVal (CPDATAOBJECT p) {
  201. if (p->KeyPtr && p->ValueName) {
  202. return TRUE;
  203. }
  204. return FALSE;
  205. }
  206. __inline BOOL IsObjectRegistryKeyComplete (CPDATAOBJECT p) {
  207. if (p->KeyPtr && p->KeyPtr->OpenKey) {
  208. return TRUE;
  209. }
  210. return FALSE;
  211. }
  212. __inline BOOL DoesObjectHaveValue (CPDATAOBJECT p) {
  213. if (p->ObjectType & OT_VALUE) {
  214. return TRUE;
  215. }
  216. return FALSE;
  217. }
  218. __inline BOOL IsWin95Object (CPDATAOBJECT p) {
  219. if (p->ObjectType & OT_WIN95) {
  220. return TRUE;
  221. }
  222. return FALSE;
  223. }
  224. __inline BOOL IsRegistryKeyOpen (CPDATAOBJECT p) {
  225. if (p->KeyPtr && p->KeyPtr->OpenKey) {
  226. return TRUE;
  227. }
  228. return FALSE;
  229. }
  230. __inline BOOL IsRegistryTypeSpecified (CPDATAOBJECT p) {
  231. if (p->ObjectType & OT_REGISTRY_TYPE) {
  232. return TRUE;
  233. }
  234. return FALSE;
  235. }
  236. BOOL
  237. SetRegistryKey (
  238. PDATAOBJECT p,
  239. PCTSTR Key
  240. );
  241. BOOL
  242. GetRegistryKeyStrFromObject (
  243. IN CPDATAOBJECT InObPtr,
  244. OUT PTSTR RegKey,
  245. IN DWORD RegKeySizeInTchars
  246. );
  247. VOID
  248. FreeRegistryKey (
  249. PDATAOBJECT p
  250. );
  251. VOID
  252. FreeRegistryParentKey (
  253. PDATAOBJECT p
  254. );
  255. BOOL
  256. SetRegistryValueName (
  257. PDATAOBJECT p,
  258. PCTSTR ValueName
  259. );
  260. VOID
  261. FreeRegistryValueName (
  262. PDATAOBJECT p
  263. );
  264. BOOL
  265. SetRegistryClass (
  266. PDATAOBJECT p,
  267. PBYTE Class,
  268. DWORD ClassSize
  269. );
  270. VOID
  271. FreeRegistryClass (
  272. PDATAOBJECT p
  273. );
  274. VOID
  275. SetRegistryType (
  276. PDATAOBJECT p,
  277. DWORD Type
  278. );
  279. BOOL
  280. SetPlatformType (
  281. PDATAOBJECT p,
  282. BOOL Win95Type
  283. );
  284. BOOL
  285. ReadWin95ObjectString (
  286. PCTSTR ObjectStr,
  287. PDATAOBJECT ObPtr
  288. );
  289. BOOL
  290. WriteWinNTObjectString (
  291. PCTSTR ObjectStr,
  292. CPDATAOBJECT SrcObPtr
  293. );
  294. BOOL
  295. ReplaceValue (
  296. PDATAOBJECT ObPtr,
  297. PBYTE NewValue,
  298. DWORD Size
  299. );
  300. BOOL
  301. GetDwordFromObject (
  302. CPDATAOBJECT ObPtr,
  303. PDWORD DwordPtr OPTIONAL
  304. );
  305. PCTSTR
  306. GetStringFromObject (
  307. CPDATAOBJECT ObPtr
  308. );
  309. #define ReplaceValueWithString(x,s) ReplaceValue((x),(PBYTE)(s),SizeOfString(s))
  310. BOOL
  311. DeleteDataObject (
  312. IN PDATAOBJECT ObjectPtr
  313. );
  314. BOOL
  315. DeleteDataObjectValue(
  316. IN CPDATAOBJECT ObPtr
  317. );
  318. BOOL
  319. RenameDataObject (
  320. IN CPDATAOBJECT SrcObPtr,
  321. IN CPDATAOBJECT DestObPtr
  322. );
  323. BOOL
  324. CheckIfNtKeyExists (
  325. IN CPDATAOBJECT SrcObjectPtr
  326. );