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.

706 lines
17 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. fmprop.c
  5. Abstract:
  6. Implements the management of group properties.
  7. Author:
  8. Rod Gamache (rodga) 7-Jan-1996
  9. Revision History:
  10. --*/
  11. #include "fmp.h"
  12. //#include "stdio.h"
  13. #define MAX_DWORD ((DWORD)-1)
  14. //
  15. // Group Common properties.
  16. //
  17. //
  18. // Read-Write Common Properties.
  19. //
  20. RESUTIL_PROPERTY_ITEM
  21. FmpGroupCommonProperties[] = {
  22. { CLUSREG_NAME_GRP_DESC, NULL, CLUSPROP_FORMAT_SZ, 0, 0, 0, 0 },
  23. { CLUSREG_NAME_GRP_PERSISTENT_STATE, NULL, CLUSPROP_FORMAT_DWORD, 0, 0, 1, 0 },
  24. { CLUSREG_NAME_GRP_FAILOVER_THRESHOLD, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_FAILOVER_THRESHOLD, 0, MAX_DWORD, 0 },
  25. { CLUSREG_NAME_GRP_FAILOVER_PERIOD, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_FAILOVER_PERIOD, 0, CLUSTER_GROUP_MAXIMUM_FAILOVER_PERIOD, 0 },
  26. { CLUSREG_NAME_GRP_FAILBACK_TYPE, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_AUTO_FAILBACK_TYPE, 0, CLUSTER_GROUP_MAXIMUM_AUTO_FAILBACK_TYPE, 0 },
  27. { CLUSREG_NAME_GRP_FAILBACK_WIN_START, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_FAILBACK_WINDOW_START, CLUSTER_GROUP_MINIMUM_FAILBACK_WINDOW_START, CLUSTER_GROUP_MAXIMUM_FAILBACK_WINDOW_START, RESUTIL_PROPITEM_SIGNED },
  28. { CLUSREG_NAME_GRP_FAILBACK_WIN_END, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_FAILBACK_WINDOW_END, CLUSTER_GROUP_MINIMUM_FAILBACK_WINDOW_END, CLUSTER_GROUP_MAXIMUM_FAILBACK_WINDOW_END, RESUTIL_PROPITEM_SIGNED },
  29. { CLUSREG_NAME_GRP_LOADBAL_STATE, NULL, CLUSPROP_FORMAT_DWORD, CLUSTER_GROUP_DEFAULT_LOADBAL_STATE, 0, 1, 0 },
  30. { CLUSREG_NAME_GRP_ANTI_AFFINITY_CLASS_NAME, NULL, CLUSPROP_FORMAT_MULTI_SZ, 0, 0, 0, 0 },
  31. { 0 }
  32. };
  33. //
  34. // Read-Only Common Properties.
  35. //
  36. RESUTIL_PROPERTY_ITEM
  37. FmpGroupROCommonProperties[] = {
  38. { CLUSREG_NAME_GRP_NAME, NULL, CLUSPROP_FORMAT_SZ,
  39. 0, 0, 0,
  40. RESUTIL_PROPITEM_READ_ONLY,
  41. 0
  42. },
  43. // { CLUSREG_NAME_GRP_CONTAINS, NULL, CLUSPROP_FORMAT_MULTI_SZ, 0, 0, 0, RESUTIL_PROPITEM_READ_ONLY, 0 },
  44. // { CLUSREG_NAME_GRP_PREFERRED_OWNERS, NULL, CLUSPROP_FORMAT_MULTI_SZ, 0, 0, 0, RESUTIL_PROPITEM_READ_ONLY, 0 },
  45. { 0 }
  46. };
  47. //
  48. // Cluster registry API function pointers.
  49. //
  50. CLUSTER_REG_APIS
  51. FmpClusterRegApis = {
  52. (PFNCLRTLCREATEKEY) DmRtlCreateKey,
  53. (PFNCLRTLOPENKEY) DmRtlOpenKey,
  54. (PFNCLRTLCLOSEKEY) DmCloseKey,
  55. (PFNCLRTLSETVALUE) DmSetValue,
  56. (PFNCLRTLQUERYVALUE) DmQueryValue,
  57. (PFNCLRTLENUMVALUE) DmEnumValue,
  58. (PFNCLRTLDELETEVALUE) DmDeleteValue,
  59. NULL,
  60. NULL,
  61. NULL
  62. };
  63. DWORD
  64. FmpGroupEnumCommonProperties(
  65. OUT PVOID OutBuffer,
  66. IN DWORD OutBufferSize,
  67. OUT LPDWORD BytesReturned,
  68. OUT LPDWORD Required
  69. )
  70. /*++
  71. Routine Description:
  72. Enumerates the common property names for a given group.
  73. Arguments:
  74. OutBuffer - Supplies the output buffer.
  75. OutBufferSize - Supplies the size of the output buffer.
  76. BytesReturned - The number of bytes returned in OutBuffer.
  77. Required - The required number of bytes if OutBuffer is too small.
  78. Return Value:
  79. ERROR_SUCCESS if successful.
  80. A Win32 error code on failure.
  81. --*/
  82. {
  83. DWORD status;
  84. //
  85. // Enumerate the common properties.
  86. //
  87. status = ClRtlEnumProperties( FmpGroupCommonProperties,
  88. OutBuffer,
  89. OutBufferSize,
  90. BytesReturned,
  91. Required );
  92. return(status);
  93. } // FmpGroupEnumCommonProperties
  94. DWORD
  95. FmpGroupGetCommonProperties(
  96. IN PFM_GROUP Group,
  97. IN BOOL ReadOnly,
  98. OUT PVOID OutBuffer,
  99. IN DWORD OutBufferSize,
  100. OUT LPDWORD BytesReturned,
  101. OUT LPDWORD Required
  102. )
  103. /*++
  104. Routine Description:
  105. Gets the common properties for a given group.
  106. Arguments:
  107. Group - Supplies the group.
  108. ReadOnly - TRUE if the read-only properties should be read. FALSE otherwise.
  109. OutBuffer - Supplies the output buffer.
  110. OutBufferSize - Supplies the size of the output buffer.
  111. BytesReturned - The number of bytes returned in OutBuffer.
  112. Required - The required number of bytes if OutBuffer is too small.
  113. Return Value:
  114. ERROR_SUCCESS if successful.
  115. A Win32 error code on failure.
  116. --*/
  117. {
  118. DWORD status;
  119. DWORD outBufferSize = OutBufferSize;
  120. //
  121. // Clear the output buffer
  122. //
  123. ZeroMemory( OutBuffer, OutBufferSize );
  124. //
  125. // Get the common properties.
  126. //
  127. if ( ReadOnly ) {
  128. //
  129. // We have to be particularly careful about the group name.
  130. // If a remote node owns the group, and changes the name, then
  131. // the registry field is updated after the name is set into OM.
  132. // Therefore, we must read the OM info, rather than the registry
  133. // which could be stale.
  134. //
  135. status = ClRtlPropertyListFromParameterBlock(
  136. FmpGroupROCommonProperties,
  137. OutBuffer,
  138. &outBufferSize,
  139. (LPBYTE) &OmObjectName(Group),
  140. BytesReturned,
  141. Required );
  142. } else {
  143. status = ClRtlGetProperties(
  144. Group->RegistryKey,
  145. &FmpClusterRegApis,
  146. FmpGroupCommonProperties,
  147. OutBuffer,
  148. OutBufferSize,
  149. BytesReturned,
  150. Required );
  151. }
  152. return(status);
  153. } // FmpGroupGetCommonProperties
  154. DWORD
  155. FmpGroupValidateCommonProperties(
  156. IN PFM_GROUP Group,
  157. IN PVOID InBuffer,
  158. IN DWORD InBufferSize
  159. )
  160. /*++
  161. Routine Description:
  162. Validates the common properties for a given group.
  163. Arguments:
  164. Group - Supplies the group.
  165. InBuffer - Supplies the input buffer.
  166. InBufferSize - Supplies the size of the input buffer.
  167. Return Value:
  168. ERROR_SUCCESS if successful.
  169. A Win32 error code on failure.
  170. --*/
  171. {
  172. DWORD status;
  173. //
  174. // Validate the property list.
  175. //
  176. status = ClRtlVerifyPropertyTable( FmpGroupCommonProperties,
  177. NULL, // Reserved
  178. FALSE, // Don't allow uknowns
  179. InBuffer,
  180. InBufferSize,
  181. NULL );
  182. if ( status != ERROR_SUCCESS ) {
  183. ClRtlLogPrint( LOG_ERROR,
  184. "[FM] ValidateCommonProperties, error in verify routine.\n");
  185. }
  186. return(status);
  187. } // FmpGroupValidateCommonProperties
  188. DWORD
  189. FmpGroupSetCommonProperties(
  190. IN PFM_GROUP Group,
  191. IN PVOID InBuffer,
  192. IN DWORD InBufferSize
  193. )
  194. /*++
  195. Routine Description:
  196. Sets the common properties for a given group.
  197. Arguments:
  198. Group - Supplies the group.
  199. InBuffer - Supplies the input buffer.
  200. InBufferSize - Supplies the size of the input buffer.
  201. Return Value:
  202. ERROR_SUCCESS if successful.
  203. A Win32 error code on failure.
  204. --*/
  205. {
  206. DWORD status;
  207. //
  208. // Validate the property list.
  209. //
  210. status = ClRtlVerifyPropertyTable( FmpGroupCommonProperties,
  211. NULL, // Reserved
  212. FALSE, // Don't allow uknowns
  213. InBuffer,
  214. InBufferSize,
  215. NULL );
  216. if ( status == ERROR_SUCCESS ) {
  217. status = ClRtlSetPropertyTable( NULL,
  218. Group->RegistryKey,
  219. &FmpClusterRegApis,
  220. FmpGroupCommonProperties,
  221. NULL, // Reserved
  222. FALSE, // Don't allow unknowns
  223. InBuffer,
  224. InBufferSize,
  225. FALSE, // bForceWrite
  226. NULL );
  227. if ( status != ERROR_SUCCESS ) {
  228. ClRtlLogPrint( LOG_ERROR,
  229. "[FM] SetCommonProperties, error in set routine.\n");
  230. }
  231. } else {
  232. ClRtlLogPrint( LOG_ERROR,
  233. "[FM] SetCommonProperties, error in verify routine.\n");
  234. }
  235. return(status);
  236. } // FmpGroupSetCommonProperties
  237. DWORD
  238. FmpGroupEnumPrivateProperties(
  239. PFM_GROUP Group,
  240. OUT PVOID OutBuffer,
  241. IN DWORD OutBufferSize,
  242. OUT LPDWORD BytesReturned,
  243. OUT LPDWORD Required
  244. )
  245. /*++
  246. Routine Description:
  247. Enumerates the private property names for a given group.
  248. Arguments:
  249. OutBuffer - Supplies the output buffer.
  250. OutBufferSize - Supplies the size of the output buffer.
  251. BytesReturned - The number of bytes returned in OutBuffer.
  252. Required - The required number of bytes if OutBuffer is too small.
  253. Return Value:
  254. ERROR_SUCCESS if successful.
  255. A Win32 error code on failure.
  256. --*/
  257. {
  258. DWORD status;
  259. HDMKEY groupKey;
  260. DWORD totalBufferSize = 0;
  261. *BytesReturned = 0;
  262. *Required = 0;
  263. //
  264. // Clear the output buffer
  265. //
  266. ZeroMemory( OutBuffer, OutBufferSize );
  267. //
  268. // Open the cluster group parameters key.
  269. //
  270. groupKey = DmOpenKey( Group->RegistryKey,
  271. CLUSREG_KEYNAME_PARAMETERS,
  272. MAXIMUM_ALLOWED );
  273. if ( groupKey == NULL ) {
  274. status = GetLastError();
  275. if ( status == ERROR_FILE_NOT_FOUND ) {
  276. status = ERROR_SUCCESS;
  277. }
  278. return(status);
  279. }
  280. //
  281. // Enumerate the private properties.
  282. //
  283. status = ClRtlEnumPrivateProperties( groupKey,
  284. &FmpClusterRegApis,
  285. OutBuffer,
  286. OutBufferSize,
  287. BytesReturned,
  288. Required );
  289. DmCloseKey( groupKey );
  290. return(status);
  291. } // FmpGroupEnumPrivateProperties
  292. DWORD
  293. FmpGroupGetPrivateProperties(
  294. IN PFM_GROUP Group,
  295. OUT PVOID OutBuffer,
  296. IN DWORD OutBufferSize,
  297. OUT LPDWORD BytesReturned,
  298. OUT LPDWORD Required
  299. )
  300. /*++
  301. Routine Description:
  302. Gets the private properties for a given group.
  303. Arguments:
  304. Group - Supplies the group.
  305. OutBuffer - Supplies the output buffer.
  306. OutBufferSize - Supplies the size of the output buffer.
  307. BytesReturned - The number of bytes returned in OutBuffer.
  308. Required - The required number of bytes if OutBuffer is too small.
  309. Return Value:
  310. ERROR_SUCCESS if successful.
  311. A Win32 error code on failure.
  312. --*/
  313. {
  314. DWORD status;
  315. HDMKEY groupKey;
  316. DWORD totalBufferSize = 0;
  317. *BytesReturned = 0;
  318. *Required = 0;
  319. //
  320. // Clear the output buffer
  321. //
  322. ZeroMemory( OutBuffer, OutBufferSize );
  323. //
  324. // Open the cluster group parameters key.
  325. //
  326. groupKey = DmOpenKey( Group->RegistryKey,
  327. CLUSREG_KEYNAME_PARAMETERS,
  328. MAXIMUM_ALLOWED );
  329. if ( groupKey == NULL ) {
  330. status = GetLastError();
  331. if ( status == ERROR_FILE_NOT_FOUND ) {
  332. //
  333. // If we don't have a parameters key, then return an
  334. // item count of 0 and an endmark.
  335. //
  336. totalBufferSize = sizeof(DWORD) + sizeof(CLUSPROP_SYNTAX);
  337. if ( OutBufferSize < totalBufferSize ) {
  338. *Required = totalBufferSize;
  339. status = ERROR_MORE_DATA;
  340. } else {
  341. // This is somewhat redundant since we zero the
  342. // buffer above, but it's here for clarity.
  343. CLUSPROP_BUFFER_HELPER buf;
  344. buf.pb = OutBuffer;
  345. buf.pList->nPropertyCount = 0;
  346. buf.pdw++;
  347. buf.pSyntax->dw = CLUSPROP_SYNTAX_ENDMARK;
  348. *BytesReturned = totalBufferSize;
  349. status = ERROR_SUCCESS;
  350. }
  351. }
  352. return(status);
  353. }
  354. //
  355. // Get private properties for the group.
  356. //
  357. status = ClRtlGetPrivateProperties( groupKey,
  358. &FmpClusterRegApis,
  359. OutBuffer,
  360. OutBufferSize,
  361. BytesReturned,
  362. Required );
  363. DmCloseKey( groupKey );
  364. return(status);
  365. } // FmpGroupGetPrivateProperties
  366. DWORD
  367. FmpGroupValidatePrivateProperties(
  368. IN PFM_GROUP Group,
  369. IN PVOID InBuffer,
  370. IN DWORD InBufferSize
  371. )
  372. /*++
  373. Routine Description:
  374. Validates the private properties for a given group.
  375. Arguments:
  376. Group - Supplies the group.
  377. InBuffer - Supplies the input buffer.
  378. InBufferSize - Supplies the size of the input buffer.
  379. Return Value:
  380. ERROR_SUCCESS if successful.
  381. A Win32 error code on failure.
  382. --*/
  383. {
  384. DWORD status;
  385. //
  386. // Validate the property list.
  387. //
  388. status = ClRtlVerifyPrivatePropertyList( InBuffer,
  389. InBufferSize );
  390. return(status);
  391. } // FmpGroupValidatePrivateProperties
  392. DWORD
  393. FmpGroupSetPrivateProperties(
  394. IN PFM_GROUP Group,
  395. IN PVOID InBuffer,
  396. IN DWORD InBufferSize
  397. )
  398. /*++
  399. Routine Description:
  400. Sets the private properties for a given group.
  401. Arguments:
  402. Group - Supplies the group.
  403. InBuffer - Supplies the input buffer.
  404. InBufferSize - Supplies the size of the input buffer.
  405. Return Value:
  406. ERROR_SUCCESS if successful.
  407. A Win32 error code on failure.
  408. --*/
  409. {
  410. DWORD status;
  411. HDMKEY groupKey;
  412. DWORD disposition;
  413. //
  414. // Validate the property list.
  415. //
  416. status = ClRtlVerifyPrivatePropertyList( InBuffer,
  417. InBufferSize );
  418. if ( status == ERROR_SUCCESS ) {
  419. //
  420. // Open the cluster group\parameters key
  421. //
  422. groupKey = DmOpenKey( Group->RegistryKey,
  423. CLUSREG_KEYNAME_PARAMETERS,
  424. MAXIMUM_ALLOWED );
  425. if ( groupKey == NULL ) {
  426. status = GetLastError();
  427. if ( status == ERROR_FILE_NOT_FOUND ) {
  428. //
  429. // Try to create the parameters key.
  430. //
  431. groupKey = DmCreateKey( Group->RegistryKey,
  432. CLUSREG_KEYNAME_PARAMETERS,
  433. 0,
  434. KEY_READ | KEY_WRITE,
  435. NULL,
  436. &disposition );
  437. if ( groupKey == NULL ) {
  438. status = GetLastError();
  439. return(status);
  440. }
  441. }
  442. }
  443. status = ClRtlSetPrivatePropertyList( NULL, // IN HANDLE hXsaction
  444. groupKey,
  445. &FmpClusterRegApis,
  446. InBuffer,
  447. InBufferSize );
  448. DmCloseKey( groupKey );
  449. }
  450. return(status);
  451. } // FmpGroupSetPrivateProperties
  452. DWORD
  453. FmpGroupGetFlags(
  454. IN PFM_GROUP Group,
  455. OUT PVOID OutBuffer,
  456. IN DWORD OutBufferSize,
  457. OUT LPDWORD BytesReturned,
  458. OUT LPDWORD Required
  459. )
  460. /*++
  461. Routine Description:
  462. Gets the flags for a given group.
  463. Arguments:
  464. Group - Supplies the group.
  465. OutBuffer - Supplies the output buffer.
  466. OutBufferSize - Supplies the size of the output buffer.
  467. BytesReturned - The number of bytes returned in OutBuffer.
  468. Required - The required number of bytes if OutBuffer is too small.
  469. Return Value:
  470. ERROR_SUCCESS if successful.
  471. A Win32 error code on failure.
  472. --*/
  473. {
  474. DWORD status;
  475. *BytesReturned = 0;
  476. if ( OutBufferSize < sizeof(DWORD) ) {
  477. *Required = sizeof(DWORD);
  478. if ( OutBuffer == NULL ) {
  479. status = ERROR_SUCCESS;
  480. } else {
  481. status = ERROR_MORE_DATA;
  482. }
  483. } else {
  484. DWORD valueType;
  485. //
  486. // Read the Flags value for the group.
  487. //
  488. *BytesReturned = OutBufferSize;
  489. status = DmQueryValue( Group->RegistryKey,
  490. CLUSREG_NAME_FLAGS,
  491. &valueType,
  492. OutBuffer,
  493. BytesReturned );
  494. if ( status == ERROR_FILE_NOT_FOUND ) {
  495. *BytesReturned = sizeof(DWORD);
  496. *(LPDWORD)OutBuffer = 0;
  497. status = ERROR_SUCCESS;
  498. }
  499. }
  500. return(status);
  501. } // FmpGroupGetFlags