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.

677 lines
19 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. registry.hxx
  5. Abstract:
  6. This module contains the declarations for the REGISTRY class.
  7. REGISTRY is class that provides methods for an application to
  8. access the registry of a particular machine.
  9. Author:
  10. Jaime Sasson (jaimes) 01-Mar-1992
  11. Environment:
  12. Ulib, User Mode
  13. --*/
  14. #if !defined( _REGISTRY_ )
  15. #define _REGISTRY_
  16. #include "ulib.hxx"
  17. #include "array.hxx"
  18. #include "regkey.hxx"
  19. #include "regvalue.hxx"
  20. #include "sortlit.hxx"
  21. #if !defined( _AUTOCHECK_ )
  22. #include "winreg.h"
  23. #endif
  24. //
  25. // The enumeration below is used to access the array of open handles
  26. // of the registry
  27. //
  28. typedef enum _PREDEFINED_KEY {
  29. PREDEFINED_KEY_CLASSES_ROOT,
  30. PREDEFINED_KEY_CURRENT_USER,
  31. PREDEFINED_KEY_LOCAL_MACHINE,
  32. PREDEFINED_KEY_USERS,
  33. PREDEFINED_KEY_CURRENT_CONFIG
  34. } PREDEFINED_KEY;
  35. #define NUMBER_OF_PREDEFINED_KEYS 5
  36. //
  37. // The enumeration below contains the error codes that the methods in
  38. // the REGISTRY class can return
  39. //
  40. typedef enum _REGISTRY_ERROR {
  41. #if !defined( _AUTOCHECK_ )
  42. REGISTRY_ERROR_BADDB, // Maps ERROR_BADDB
  43. REGISTRY_ERROR_ACCESS_DENIED, // Maps ERROR_ACCESS_DENIED
  44. REGISTRY_ERROR_CANTOPEN, // Maps ERROR_CANT_OPEN
  45. REGISTRY_ERROR_CANTREAD, // Maps ERROR_CANT_READ
  46. REGISTRY_ERROR_INVALID_PARAMETER, // Maps ERROR_INVALID_PARAMETER
  47. REGISTRY_ERROR_OUTOFMEMORY, // Maps ERROR_OUT_OF_MEMORY
  48. #endif
  49. REGISTRY_ERROR_INITIALIZATION_FAILURE,
  50. REGISTRY_ERROR_KEY_DOESNT_EXIST,
  51. REGISTRY_ERROR_VALUE_EXISTS,
  52. REGISTRY_ERROR_VALUE_DOESNT_EXIST,
  53. REGISTRY_ERROR_KEY_INFO_NOT_UPDATED,
  54. REGISTRY_ERROR_UNKNOWN_ERROR,
  55. REGISTRY_ERROR_PRIVILEGE_NOT_HELD, // Maps ERROR_PRIVILEGE_NOT_HELD
  56. REGISTRY_RPC_S_SERVER_UNAVAILABLE, // Maps RPC_S_SERVER_UNAVAILABLE
  57. REGISTRY_ERROR_KEY_DELETED, // Maps ERROR_KEY_DELETED
  58. REGISTRY_ERROR_KEY_NOT_FOUND, // Maps ERROR_FILE_NOT_FOUND
  59. REGISTRY_ERROR_CHILD_MUST_BE_VOLATILE // Maps ERROR_CHILD_MUST_BE_VOLATILE
  60. } REGISTRY_ERROR;
  61. DECLARE_CLASS( REGISTRY );
  62. class REGISTRY : public OBJECT {
  63. public:
  64. DECLARE_CONSTRUCTOR( REGISTRY );
  65. DECLARE_CAST_MEMBER_FUNCTION( REGISTRY );
  66. VIRTUAL
  67. ~REGISTRY(
  68. );
  69. NONVIRTUAL
  70. BOOLEAN
  71. Initialize(
  72. IN PCWSTRING MachineName DEFAULT NULL,
  73. OUT PULONG ErrorCode DEFAULT NULL
  74. );
  75. NONVIRTUAL
  76. BOOLEAN
  77. AddValueEntry(
  78. IN PREDEFINED_KEY Predefinedkey,
  79. IN PCWSTRING ParentKeyName,
  80. IN PCWSTRING KeyName,
  81. IN PCREGISTRY_VALUE_ENTRY Value,
  82. IN BOOLEAN FailIfExists DEFAULT FALSE,
  83. OUT PULONG ErrorCode DEFAULT NULL
  84. );
  85. NONVIRTUAL
  86. BOOLEAN
  87. AddValueEntry(
  88. IN PREDEFINED_KEY Predefinedkey,
  89. IN OUT PREGISTRY_KEY_INFO KeyInfo,
  90. IN PCREGISTRY_VALUE_ENTRY Value,
  91. IN BOOLEAN FailIfExists DEFAULT FALSE,
  92. OUT PULONG ErrorCode DEFAULT NULL
  93. );
  94. #if 0 // NOT_IMPLEMENTED
  95. NONVIRTUAL
  96. BOOLEAN // The key copied will be a subkey
  97. CopyKey( // of ToParentName
  98. IN PREDEFINED_KEY FromPredefinedKey,
  99. IN PCWSTRING FromParentName,
  100. IN PCWSTRING FromKeyName,
  101. IN PREDEFINED_KEY ToPredefinedKey,
  102. IN PCWSTRING ToParentName,
  103. OUT PULONG ErrorCode DEFAULT NULL
  104. );
  105. NONVIRTUAL
  106. BOOLEAN // The key copied will be a subkey
  107. CopyKey( // of ToParentKey
  108. IN PREDEFINED_KEY FromPredefinedKey,
  109. IN PCWSTRING FromParentName,
  110. IN PCWSTRING FromKeyName,
  111. IN PREDEFINED_KEY ToPredefinedKey,
  112. IN OUT PREGISTRY_KEY_INFO ToParentKeyInfo,
  113. OUT PULONG ErrorCode DEFAULT NULL
  114. );
  115. NONVIRTUAL
  116. BOOLEAN
  117. CopyAllValueEntries(
  118. IN PREDEFINED_KEY FromPredefinedKey,
  119. IN PCWSTRING FromParentName,
  120. IN PCWSTRING FromKeyName,
  121. IN PREDEFINED_KEY ToPredefinedKey,
  122. IN PCWSTRING ToParentName,
  123. IN PCWSTRING ToKeyName,
  124. OUT PULONG ErrorCode DEFAULT NULL
  125. );
  126. NONVIRTUAL
  127. BOOLEAN
  128. CopyAllValueEntries(
  129. IN PREDEFINED_KEY FromPredefinedKey,
  130. IN PCWSTRING FromParentName,
  131. IN PCWSTRING FromKeyName,
  132. IN PREDEFINED_KEY ToPredefinedKey,
  133. IN OUT PREGISTRY_KEY_INFO ToKeyInfo,
  134. OUT PULONG ErrorCode DEFAULT NULL
  135. );
  136. NONVIRTUAL
  137. BOOLEAN
  138. CopyOneValueEntry(
  139. IN PREDEFINED_KEY FromPredefinedKey,
  140. IN PCWSTRING FromParentName,
  141. IN PCWSTRING FromKeyName,
  142. IN PCWSTRING FromValueName,
  143. IN PREDEFINED_KEY ToPredefinedKey,
  144. IN PCWSTRING ToParentName,
  145. IN PCWSTRING ToKeyName,
  146. OUT PULONG ErrorCode DEFAULT NULL
  147. );
  148. NONVIRTUAL
  149. BOOLEAN
  150. CopyOneValueEntry(
  151. IN PREDEFINED_KEY FromPredefinedKey,
  152. IN PCWSTRING FromParentName,
  153. IN PCWSTRING FromKeyName,
  154. IN PCWSTRING FromValueName,
  155. IN PREDEFINED_KEY ToPredefinedKey,
  156. IN OUT PREGISTRY_KEY_INFO ToKeyInfo,
  157. OUT PULONG ErrorCode DEFAULT NULL
  158. );
  159. #endif // NOT_IMPLEMENTED
  160. NONVIRTUAL
  161. BOOLEAN
  162. CreateKey(
  163. IN OUT PREGISTRY_KEY_INFO NewSubKeyInfo,
  164. IN PREDEFINED_KEY PredefinedKey,
  165. OUT PULONG ErrorCode DEFAULT NULL,
  166. IN BOOLEAN Volatile DEFAULT FALSE
  167. );
  168. NONVIRTUAL
  169. BOOLEAN
  170. CreateKey(
  171. IN PREDEFINED_KEY Predefinedkey,
  172. IN OUT PREGISTRY_KEY_INFO ParentKeyInfo,
  173. IN OUT PREGISTRY_KEY_INFO NewSubKeyInfo,
  174. OUT PULONG ErrorCode DEFAULT NULL,
  175. IN BOOLEAN Volatile DEFAULT FALSE
  176. );
  177. NONVIRTUAL
  178. BOOLEAN
  179. DeleteKey(
  180. IN PREDEFINED_KEY PredefinedKey,
  181. IN PCWSTRING ParentKeyName,
  182. IN PCWSTRING KeyName,
  183. OUT PULONG ErrorCode DEFAULT NULL
  184. );
  185. NONVIRTUAL
  186. BOOLEAN
  187. DeleteKey(
  188. IN PREDEFINED_KEY PredefinedKey,
  189. IN OUT PREGISTRY_KEY_INFO ParentKeyInfo,
  190. IN PCWSTRING KeyName,
  191. OUT PULONG ErrorCode DEFAULT NULL
  192. );
  193. NONVIRTUAL
  194. BOOLEAN
  195. DeleteValueEntry(
  196. IN PREDEFINED_KEY PredefinedKey,
  197. IN PCWSTRING ParentKeyName,
  198. IN PCWSTRING KeyName,
  199. IN PCWSTRING ValueName,
  200. OUT PULONG ErrorCode DEFAULT NULL
  201. );
  202. NONVIRTUAL
  203. BOOLEAN
  204. DeleteValueEntry(
  205. IN PREDEFINED_KEY PredefinedKey,
  206. IN OUT PREGISTRY_KEY_INFO KeyInfo,
  207. IN PCWSTRING ValueName,
  208. OUT PULONG ErrorCode DEFAULT NULL
  209. );
  210. NONVIRTUAL
  211. BOOLEAN
  212. DoesKeyExist(
  213. IN PREDEFINED_KEY PredefinedKey,
  214. IN PCWSTRING ParentName,
  215. IN PCWSTRING KeyName,
  216. OUT PULONG ErrorCode DEFAULT NULL
  217. );
  218. NONVIRTUAL
  219. BOOLEAN
  220. DoesValueExist(
  221. IN PREDEFINED_KEY PredefinedKey,
  222. IN PCWSTRING ParentName,
  223. IN PCWSTRING KeyName,
  224. IN PCWSTRING ValueName,
  225. OUT PULONG ErrorCode DEFAULT NULL
  226. );
  227. #if !defined( _AUTOCHECK_ )
  228. NONVIRTUAL
  229. BOOLEAN
  230. EnableRootNotification(
  231. IN PREDEFINED_KEY PredefinedKey,
  232. IN HANDLE Event,
  233. IN DWORD Filter,
  234. IN BOOLEAN WatchTree DEFAULT TRUE
  235. );
  236. #endif
  237. NONVIRTUAL
  238. PCWSTRING
  239. GetMachineName(
  240. ) CONST;
  241. NONVIRTUAL
  242. BOOLEAN
  243. IsAccessAllowed(
  244. IN PREDEFINED_KEY PredefinedKey,
  245. IN PREGISTRY_KEY_INFO KeyInfo,
  246. IN REGSAM SamDesired,
  247. OUT PULONG ErrorCode
  248. );
  249. NONVIRTUAL
  250. BOOLEAN
  251. IsRemoteRegistry(
  252. ) CONST;
  253. #if !defined( _AUTOCHECK_ )
  254. NONVIRTUAL
  255. BOOLEAN
  256. LoadHive(
  257. IN PREDEFINED_KEY PredefinedKey,
  258. IN PREGISTRY_KEY_INFO KeyInfo,
  259. IN PCWSTRING FileName,
  260. OUT PULONG ErrorCode DEFAULT NULL
  261. );
  262. #endif
  263. #if 0 // NOT_IMPLEMENTED
  264. NONVIRTUAL // Subkey moved becomes
  265. BOOLEAN // a subkey of ToParentKeyName
  266. MoveKey(
  267. IN PREDEFINED_KEY FromPredefinedKey,
  268. IN PCWSTRING FromParentKeyName,
  269. IN PCWSTRING FromKeyName,
  270. IN PREDEFINED_KEY ToPredefinedKey,
  271. IN PCWSTRING ToParentKeyName,
  272. OUT PULONG ErrorCode DEFAULT NULL
  273. );
  274. NONVIRTUAL
  275. BOOLEAN // Subkey moved becomes
  276. MoveKey( // a subkey of FromParentKey
  277. IN PREDEFINED_KEY FromPredefinedKey,
  278. IN OUT PREGISTRY_KEY_INFO FromParentKeyInfo,
  279. IN PCWSTRING FromKeyName,
  280. IN PREDEFINED_KEY ToPredefinedKey,
  281. IN OUT PREGISTRY_KEY_INFO ToParentKeyInfo,
  282. OUT PULONG ErrorCode DEFAULT NULL
  283. );
  284. NONVIRTUAL
  285. BOOLEAN
  286. MoveAllValueEntries(
  287. IN PREDEFINED_KEY FromPredefinedKey,
  288. IN PCWSTRING FromParentName,
  289. IN PCWSTRING FromKeyName,
  290. IN PREDEFINED_KEY ToPredefinedKey,
  291. IN PCWSTRING ToParentName,
  292. IN PCWSTRING ToKeyName,
  293. OUT PULONG ErrorCode DEFAULT NULL
  294. );
  295. NONVIRTUAL
  296. BOOLEAN
  297. MoveAllValueEntries(
  298. IN PREDEFINED_KEY FromPredefinedKey,
  299. IN OUT PREGISTRY_KEY_INFO FromKeyInfo,
  300. IN PREDEFINED_KEY ToPredefinedKey,
  301. IN OUT PREGISTRY_KEY_INFO ToKeyInfo,
  302. OUT PULONG ErrorCode DEFAULT NULL
  303. );
  304. NONVIRTUAL
  305. BOOLEAN
  306. MoveOneValueEntry(
  307. IN PREDEFINED_KEY FromPredefinedKey,
  308. IN PCWSTRING FromParentName,
  309. IN PCWSTRING FromKeyName,
  310. IN PCWSTRING FromValueName,
  311. IN PREDEFINED_KEY ToPredefinedKey,
  312. IN PCWSTRING ToParentKeyName,
  313. IN PCWSTRING ToKeyName,
  314. OUT PULONG ErrorCode DEFAULT NULL
  315. );
  316. NONVIRTUAL
  317. BOOLEAN
  318. MoveOneValueEntry(
  319. IN PREDEFINED_KEY FromPredefinedKey,
  320. IN OUT PREGISTRY_KEY_INFO FromKeyInfo,
  321. IN PCWSTRING FromValueName,
  322. IN PREDEFINED_KEY ToPredefinedKey,
  323. IN OUT PREGISTRY_KEY_INFO ToKeyInfo,
  324. OUT PULONG ErrorCode DEFAULT NULL
  325. );
  326. #endif // NOT_IMPLEMENTED
  327. NONVIRTUAL
  328. BOOLEAN
  329. QueryKeyInfo(
  330. IN PREDEFINED_KEY PredefinedKey,
  331. IN PCWSTRING ParentKeyName,
  332. IN PCWSTRING KeyName,
  333. OUT PREGISTRY_KEY_INFO KeyInfo,
  334. OUT PULONG ErrorCode DEFAULT NULL
  335. );
  336. NONVIRTUAL
  337. BOOLEAN
  338. QueryKeySecurity(
  339. IN PREDEFINED_KEY PredefinedKey,
  340. IN PCREGISTRY_KEY_INFO KeyInfo,
  341. IN SECURITY_INFORMATION SecurityInformation,
  342. IN PSECURITY_DESCRIPTOR* SecurityDescriptor,
  343. IN PULONG ErrorCode DEFAULT NULL
  344. );
  345. NONVIRTUAL
  346. BOOLEAN
  347. QuerySubKeysInfo(
  348. IN PREDEFINED_KEY PredefinedKey,
  349. IN PCWSTRING ParentKey,
  350. IN PCWSTRING KeyName,
  351. IN OUT PARRAY SubKeysInfo,
  352. OUT PULONG ErrorCode DEFAULT NULL
  353. );
  354. NONVIRTUAL
  355. BOOLEAN
  356. QueryValue(
  357. IN PREDEFINED_KEY PredefinedKey,
  358. IN PCWSTRING ParentKeyName,
  359. IN PCWSTRING KeyName,
  360. IN PCWSTRING ValueName,
  361. IN OUT PREGISTRY_VALUE_ENTRY Values,
  362. OUT PULONG ErrorCode DEFAULT NULL
  363. );
  364. NONVIRTUAL
  365. BOOLEAN
  366. QueryValues(
  367. IN PREDEFINED_KEY PredefinedKey,
  368. IN PCWSTRING ParentKeyName,
  369. IN PCWSTRING KeyName,
  370. IN OUT PARRAY Values,
  371. OUT PULONG ErrorCode DEFAULT NULL
  372. );
  373. NONVIRTUAL
  374. BOOLEAN
  375. SetKeySecurity(
  376. IN PREDEFINED_KEY PredefinedKey,
  377. IN OUT PREGISTRY_KEY_INFO KeyInfo,
  378. IN SECURITY_INFORMATION SecurityInformation,
  379. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  380. IN PULONG ErrorCode DEFAULT NULL,
  381. IN BOOLEAN Recurse DEFAULT FALSE
  382. );
  383. #if !defined( _AUTOCHECK_ )
  384. NONVIRTUAL
  385. BOOLEAN
  386. UnLoadHive(
  387. IN PREDEFINED_KEY PredefinedKey,
  388. IN PREGISTRY_KEY_INFO KeyInfo,
  389. OUT PULONG ErrorCode DEFAULT NULL
  390. );
  391. NONVIRTUAL
  392. BOOLEAN
  393. SaveKeyToFile(
  394. IN PREDEFINED_KEY PredefinedKey,
  395. IN PREGISTRY_KEY_INFO KeyInfo,
  396. IN PCWSTRING FileName,
  397. OUT PULONG ErrorCode DEFAULT NULL
  398. );
  399. NONVIRTUAL
  400. BOOLEAN
  401. RestoreKeyFromFile(
  402. IN PREDEFINED_KEY PredefinedKey,
  403. IN PREGISTRY_KEY_INFO KeyInfo,
  404. IN PCWSTRING FileName,
  405. IN BOOLEAN Volatile DEFAULT FALSE,
  406. OUT PULONG ErrorCode DEFAULT NULL
  407. );
  408. #endif
  409. NONVIRTUAL
  410. BOOLEAN
  411. UpdateKeyInfo(
  412. IN PREDEFINED_KEY PredefinedKey,
  413. IN OUT PREGISTRY_KEY_INFO KeyInfo,
  414. OUT PULONG ErrorCode DEFAULT NULL
  415. );
  416. private:
  417. NONVIRTUAL
  418. VOID
  419. Construct(
  420. );
  421. NONVIRTUAL
  422. VOID
  423. Destroy(
  424. );
  425. NONVIRTUAL
  426. PWSTRING
  427. BuildCompleteName(
  428. IN PCWSTRING ParentName,
  429. IN PCWSTRING KeyName
  430. );
  431. #if !defined( _AUTOCHECK_ )
  432. NONVIRTUAL
  433. ULONG
  434. DeleteTree(
  435. IN HKEY KeyHandle
  436. );
  437. #endif
  438. NONVIRTUAL
  439. BOOLEAN
  440. InitializeMachineName(
  441. IN PCWSTRING MachineName
  442. );
  443. #if !defined( _AUTOCHECK_ )
  444. NONVIRTUAL
  445. BOOLEAN
  446. SetSubKeysSecurity(
  447. IN HKEY KeyHandle,
  448. IN SECURITY_INFORMATION SecurityInformation,
  449. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  450. IN PULONG ErrorCode
  451. );
  452. #endif
  453. #if !defined( _AUTOCHECK_ )
  454. NONVIRTUAL
  455. ULONG
  456. MapWin32RegApiToRegistryError(
  457. IN ULONG ErrorCode
  458. ) CONST;
  459. #endif
  460. #if defined( _AUTOCHECK_ )
  461. NONVIRTUAL
  462. BOOLEAN
  463. OpenKey(
  464. IN PCWSTRING ParentKeyName,
  465. IN PCWSTRING KeyName,
  466. IN ULONG Flags,
  467. OUT PHANDLE Handle,
  468. OUT PULONG ErrorCode
  469. );
  470. #endif
  471. #if !defined( _AUTOCHECK_ )
  472. NONVIRTUAL
  473. BOOLEAN
  474. OpenKey(
  475. IN PREDEFINED_KEY PredefinedKey,
  476. IN PCWSTRING ParentKeyName,
  477. IN PCWSTRING KeyName,
  478. IN DWORD Permission,
  479. OUT PHKEY Key,
  480. OUT PULONG ErrorCode DEFAULT NULL
  481. );
  482. #endif
  483. DSTRING _MachineName;
  484. BOOLEAN _RemoteRegistry;
  485. #if !defined( _AUTOCHECK_ )
  486. HKEY _PredefinedKey[ NUMBER_OF_PREDEFINED_KEYS ];
  487. #endif
  488. STATIC
  489. PWSTRING _Separator;
  490. };
  491. INLINE
  492. PCWSTRING
  493. REGISTRY::GetMachineName(
  494. ) CONST
  495. /*++
  496. Routine Description:
  497. Return the name of the machine associated with this REGISTRY object.
  498. Arguments:
  499. None.
  500. Return Value:
  501. PCWSTRING - Pointer to a WSTRING object that contains the machine name.
  502. --*/
  503. {
  504. return( &_MachineName );
  505. }
  506. INLINE
  507. BOOLEAN
  508. REGISTRY::IsRemoteRegistry(
  509. ) CONST
  510. /*++
  511. Routine Description:
  512. Inform the client whether this object represnts a remote registry.
  513. Arguments:
  514. None.
  515. Return Value:
  516. BOOLEAN - Returns TRUE if this object represents a remote registry.
  517. Returns FALSE otherwise.
  518. --*/
  519. {
  520. return( _RemoteRegistry );
  521. }
  522. #endif // _REGISTRY_