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.

954 lines
28 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterResource.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterResource class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ClusterResource.h"
  17. #include "ClusterResource.tmh"
  18. #pragma warning( push )
  19. #pragma warning( disable : 4663 ) // C++ language change: to explicitly specialize class template 'vector' use the following syntax:
  20. #include <vector>
  21. #pragma warning( pop )
  22. //****************************************************************************
  23. //
  24. // CClusterResource
  25. //
  26. //****************************************************************************
  27. //////////////////////////////////////////////////////////////////////////////
  28. //++
  29. //
  30. // CClusterResource::CClusterResource
  31. //
  32. // Description:
  33. // Constructor.
  34. //
  35. // Arguments:
  36. // pwszNameIn -- Class name
  37. // pNamespaceIn -- Namespace
  38. //
  39. // Return Values:
  40. // None.
  41. //
  42. //--
  43. //////////////////////////////////////////////////////////////////////////////
  44. CClusterResource::CClusterResource(
  45. LPCWSTR pwszNameIn,
  46. CWbemServices * pNamespaceIn
  47. )
  48. : CProvBase( pwszNameIn, pNamespaceIn )
  49. {
  50. } //*** CClusterResource::CClusterResource()
  51. //////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // static
  55. // CClusterResource::S_CreateThis
  56. //
  57. // Description:
  58. // Create a resource object
  59. //
  60. // Arguments:
  61. // pwszNameIn -- Class name
  62. // pNamespaceIn -- Namespace
  63. // dwEnumTypeIn -- Type id
  64. //
  65. // Return Values:
  66. // pointer to the CProvBase
  67. //
  68. //--
  69. //////////////////////////////////////////////////////////////////////////////
  70. CProvBase *
  71. CClusterResource::S_CreateThis(
  72. LPCWSTR pwszNameIn,
  73. CWbemServices * pNamespaceIn,
  74. DWORD // dwEnumTypeIn
  75. )
  76. {
  77. return new CClusterResource( pwszNameIn, pNamespaceIn );
  78. } //*** CClusterResource::S_CreateThis()
  79. //////////////////////////////////////////////////////////////////////////////
  80. //++
  81. //
  82. // CClusterResource::EnumInstance
  83. //
  84. // Description:
  85. // Enumerate cluster resource instances.
  86. //
  87. // Arguments:
  88. // lFlagsIn -- WMI flag
  89. // pCtxIn -- WMI context
  90. // pHandlerIn -- WMI sink pointer
  91. //
  92. // Return Values:
  93. // WBEM_S_NO_ERROR
  94. //
  95. //--
  96. //////////////////////////////////////////////////////////////////////////////
  97. SCODE
  98. CClusterResource::EnumInstance(
  99. long lFlagsIn,
  100. IWbemContext * pCtxIn,
  101. IWbemObjectSink * pHandlerIn
  102. )
  103. {
  104. SAFECLUSTER shCluster;
  105. SAFERESOURCE shResource;
  106. LPCWSTR pwszResName = NULL;
  107. shCluster = OpenCluster( NULL );
  108. CClusterEnum cluEnum( shCluster, CLUSTER_ENUM_RESOURCE );
  109. while ( ( pwszResName = cluEnum.GetNext() ) != NULL )
  110. {
  111. shResource = OpenClusterResource( shCluster, pwszResName );
  112. ClusterToWMI( shResource, pHandlerIn );
  113. } // while: more resources
  114. return WBEM_S_NO_ERROR;
  115. } //*** CClusterResource::EnumInstance()
  116. // smart_bstr class to make LoadRegistryCheckpoints func exception safe
  117. struct smart_bstr {
  118. BSTR data;
  119. smart_bstr():data(0){}
  120. ~smart_bstr() { SysFreeString(data); }
  121. };
  122. //////////////////////////////////////////////////////////////////////////////
  123. //++
  124. //
  125. // LoadRegistryCheckpoints
  126. //
  127. // Description:
  128. // Translate a cluster resource objects to WMI object.
  129. //
  130. // Arguments:
  131. // hResourceIn -- Handle to resource
  132. // dwControlCode -- show be one of the following
  133. // CLUSCTL_RESOURCE_GET_REGISTRY_CHECKPOINTS
  134. // CLUSCTL_RESOURCE_GET_CRYPTO_CHECKPOINTS
  135. // propName -- property name to load checkpoints to
  136. // wco -- property container
  137. //
  138. // Return Values:
  139. // none
  140. //--
  141. //////////////////////////////////////////////////////////////////////////////
  142. void
  143. LoadRegistryCheckpoints(
  144. IN HRESOURCE hResourceIn,
  145. IN DWORD dwControlCode,
  146. IN const WCHAR* propName,
  147. IN OUT CWbemClassObject &wco
  148. )
  149. {
  150. DWORD cbReturned = 0;
  151. DWORD dwStatus;
  152. CError er;
  153. dwStatus = ClusterResourceControl(
  154. hResourceIn,
  155. NULL,
  156. dwControlCode,
  157. NULL,
  158. 0,
  159. NULL,
  160. 0,
  161. &cbReturned
  162. );
  163. if (dwStatus != ERROR_MORE_DATA) {
  164. er = dwStatus;
  165. }
  166. if (cbReturned == 0) {
  167. return; // no checkpoints
  168. }
  169. std::vector<WCHAR> checkpoints(cbReturned/sizeof(WCHAR));
  170. er = ClusterResourceControl(
  171. hResourceIn,
  172. NULL,
  173. dwControlCode,
  174. NULL,
  175. 0,
  176. &checkpoints[0],
  177. (DWORD) ( checkpoints.size() * sizeof(WCHAR) ),
  178. &cbReturned
  179. );
  180. int nKeys = 0; // count how many keys are in the string
  181. for(UINT idx = 0; idx < checkpoints.size(); ++idx) {
  182. if (checkpoints[idx] == 0) {
  183. ++nKeys;
  184. if (idx > 0 && checkpoints[idx-1] == 0) {
  185. break; // double null
  186. }
  187. }
  188. }
  189. std::vector<smart_bstr> bstrs(nKeys);
  190. WCHAR* p = &checkpoints[0];
  191. for(int idx = 0; idx < nKeys; ++idx) {
  192. bstrs[idx].data = SysAllocString( p );
  193. p += wcslen(p) + 1;
  194. }
  195. wco.SetProperty(nKeys, &bstrs[0].data, propName);
  196. }
  197. //////////////////////////////////////////////////////////////////////////////
  198. //++
  199. //
  200. // CClusterResource::ClusterToWMI
  201. //
  202. // Description:
  203. // Translate a cluster resource objects to WMI object.
  204. //
  205. // Arguments:
  206. // hResourceIn -- Handle to resource
  207. // pHandlerIn -- Pointer to WMI sink
  208. //
  209. // Return Values:
  210. // WBEM_S_NO_ERROR
  211. // Win32 error
  212. //
  213. //--
  214. //////////////////////////////////////////////////////////////////////////////
  215. void
  216. CClusterResource::ClusterToWMI(
  217. HRESOURCE hResourceIn,
  218. IWbemObjectSink * pHandlerIn
  219. )
  220. {
  221. static SGetControl s_rgControl[] =
  222. {
  223. { CLUSCTL_RESOURCE_GET_RO_COMMON_PROPERTIES, FALSE },
  224. { CLUSCTL_RESOURCE_GET_COMMON_PROPERTIES, FALSE },
  225. { CLUSCTL_RESOURCE_GET_RO_PRIVATE_PROPERTIES, TRUE },
  226. { CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES, TRUE }
  227. };
  228. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  229. CWbemClassObject wco;
  230. CWbemClassObject wcoPrivate;
  231. CWbemClassObject wcoClass;
  232. CError er;
  233. DWORD dwStatus;
  234. UINT idx;
  235. CWstrBuf wsbTypeName ;
  236. DWORD cbTypeName = MAX_PATH;
  237. DWORD cbTypeNameReturned = 0;
  238. //
  239. // get type name and corresponding property class
  240. //
  241. wsbTypeName.SetSize( cbTypeName );
  242. dwStatus = ClusterResourceControl(
  243. hResourceIn,
  244. NULL,
  245. CLUSCTL_RESOURCE_GET_RESOURCE_TYPE,
  246. NULL,
  247. 0,
  248. wsbTypeName,
  249. cbTypeName,
  250. &cbTypeNameReturned
  251. );
  252. if ( dwStatus == ERROR_MORE_DATA )
  253. {
  254. cbTypeName = cbTypeNameReturned;
  255. wsbTypeName.SetSize( cbTypeName );
  256. er = ClusterResourceControl(
  257. hResourceIn,
  258. NULL,
  259. CLUSCTL_RESOURCE_GET_RESOURCE_TYPE,
  260. NULL,
  261. 0,
  262. wsbTypeName,
  263. cbTypeName,
  264. &cbTypeNameReturned
  265. );
  266. }
  267. er = dwStatus;
  268. er = m_pNamespace->GetObject(
  269. g_TypeNameToClass[ static_cast<LPWSTR> ( wsbTypeName ) ],
  270. 0,
  271. 0,
  272. &wcoClass,
  273. NULL
  274. );
  275. er = wcoClass.data()->SpawnInstance( 0, & wcoPrivate );
  276. m_pClass->SpawnInstance( 0, & wco );
  277. //
  278. // get properties from property list
  279. //
  280. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  281. {
  282. CClusPropList pl;
  283. CWbemClassObject wcoTemp;
  284. er = pl.ScGetResourceProperties(
  285. hResourceIn,
  286. s_rgControl[ idx ].dwControl,
  287. NULL,
  288. 0
  289. );
  290. if ( s_rgControl[ idx ].fPrivate )
  291. {
  292. wcoTemp = wcoPrivate;
  293. }
  294. else
  295. {
  296. wcoTemp = wco;
  297. }
  298. CClusterApi::GetObjectProperties(
  299. NULL,
  300. pl,
  301. wcoTemp,
  302. s_rgControl[ idx ].fPrivate
  303. );
  304. } // for: each control code
  305. wco.SetProperty(
  306. wcoPrivate.data(),
  307. PVD_PROP_RES_PRIVATE );
  308. {
  309. DWORD dwState = GetClusterResourceState(
  310. hResourceIn,
  311. NULL,
  312. NULL,
  313. NULL,
  314. NULL
  315. );
  316. wco.SetProperty( dwState, PVD_PROP_RES_STATE );
  317. }
  318. LoadRegistryCheckpoints(hResourceIn,
  319. CLUSCTL_RESOURCE_GET_REGISTRY_CHECKPOINTS, PVD_PROP_RES_CHECKPOINTS, wco);
  320. LoadRegistryCheckpoints(hResourceIn,
  321. CLUSCTL_RESOURCE_GET_CRYPTO_CHECKPOINTS, PVD_PROP_RES_CRYPTO_CHECKPOINTS, wco);
  322. //
  323. // flags and characteristics
  324. //
  325. {
  326. DWORD cbReturned;
  327. DWORD dwOut;
  328. er = ClusterResourceControl(
  329. hResourceIn,
  330. NULL,
  331. CLUSCTL_RESOURCE_GET_CHARACTERISTICS,
  332. NULL,
  333. 0,
  334. &dwOut,
  335. sizeof( DWORD ),
  336. &cbReturned
  337. );
  338. wco.SetProperty( dwOut, PVD_PROP_CHARACTERISTIC );
  339. wco.SetProperty( dwOut & CLUS_CHAR_QUORUM, PVD_PROP_RESTYPE_QUORUM_CAPABLE );
  340. wco.SetProperty( dwOut & CLUS_CHAR_DELETE_REQUIRES_ALL_NODES, PVD_PROP_RESTYPE_DELETE_REQUIRES_ALL_NODES );
  341. wco.SetProperty( dwOut & CLUS_CHAR_LOCAL_QUORUM, PVD_PROP_RESTYPE_LOCALQUORUM_CAPABLE );
  342. er = ClusterResourceControl(
  343. hResourceIn,
  344. NULL,
  345. CLUSCTL_RESOURCE_GET_FLAGS,
  346. NULL,
  347. 0,
  348. &dwOut,
  349. sizeof( DWORD ),
  350. &cbReturned
  351. );
  352. wco.SetProperty( dwOut, PVD_PROP_FLAGS );
  353. wco.SetProperty( dwOut & CLUS_FLAG_CORE, PVD_PROP_RES_CORE_RESOURCE );
  354. }
  355. pHandlerIn->Indicate( 1, & wco );
  356. return;
  357. } //*** CClusterResource::ClusterToWMI()
  358. //////////////////////////////////////////////////////////////////////////////
  359. //++
  360. //
  361. // CClusterResource::GetObject
  362. //
  363. // Description:
  364. // Retrieve cluster resourcee object based on given object path.
  365. //
  366. // Arguments:
  367. // rObjPathIn -- Object path to cluster object
  368. // lFlagsIn -- WMI flag
  369. // pCtxIn -- WMI context
  370. // pHandlerIn -- WMI sink pointer
  371. //
  372. // Return Values:
  373. // WBEM_S_NO_ERROR
  374. // Win32 error
  375. //
  376. //--
  377. //////////////////////////////////////////////////////////////////////////////
  378. SCODE
  379. CClusterResource::GetObject(
  380. CObjPath & rObjPathIn,
  381. long lFlagsIn,
  382. IWbemContext * pCtxIn,
  383. IWbemObjectSink * pHandlerIn
  384. )
  385. {
  386. SAFECLUSTER shCluster;
  387. SAFERESOURCE shRes;
  388. shCluster = OpenCluster( NULL );
  389. shRes = OpenClusterResource(
  390. shCluster,
  391. rObjPathIn.GetStringValueForProperty( CLUSREG_NAME_RES_NAME )
  392. );
  393. ClusterToWMI( shRes, pHandlerIn );
  394. return WBEM_S_NO_ERROR;
  395. } //*** CClusterResource::GetObject()
  396. //////////////////////////////////////////////////////////////////////////////
  397. //++
  398. //
  399. // AddRemoveCheckpoint
  400. //
  401. // Description:
  402. // Adds/Removes regular/crypto checkpoint.
  403. //
  404. // Arguments:
  405. // hResourceIn -- Handle to resource
  406. // dwControlCode -- clusapi control code
  407. // wcoInputParam -- property container
  408. //
  409. // Return Values:
  410. // none
  411. //--
  412. //////////////////////////////////////////////////////////////////////////////
  413. void AddRemoveCheckpoint(
  414. IN HRESOURCE hResourceIn,
  415. IN CWbemClassObject& wcoInputParam,
  416. IN DWORD dwControlCode
  417. )
  418. {
  419. CError er;
  420. _bstr_t keyName;
  421. wcoInputParam.GetProperty( keyName, PVD_MTH_PARM_RES_CHECKPOINT_NAME );
  422. er = ClusterResourceControl(
  423. hResourceIn,
  424. NULL,
  425. dwControlCode,
  426. (wchar_t*)keyName,
  427. SysStringByteLen(keyName) + sizeof(WCHAR),
  428. NULL,
  429. 0,
  430. NULL
  431. );
  432. }
  433. //////////////////////////////////////////////////////////////////////////////
  434. //++
  435. //
  436. // CClusterResource::ExecuteMethod
  437. //
  438. // Description:
  439. // Execute methods defined in the mof for cluster resource.
  440. //
  441. // Arguments:
  442. // rObjPathIn -- Object path to cluster object
  443. // pwszMethodNameIn -- Name of the method to be invoked
  444. // lFlagIn -- WMI flag
  445. // pParamsIn -- Input parameters for the method
  446. // pHandlerIn -- WMI sink pointer
  447. //
  448. // Return Values:
  449. // WBEM_S_NO_ERROR
  450. // WBEM_E_INVALID_PARAMETER
  451. //
  452. //--
  453. //////////////////////////////////////////////////////////////////////////////
  454. SCODE
  455. CClusterResource::ExecuteMethod(
  456. CObjPath & rObjPathIn,
  457. WCHAR * pwszMethodNameIn,
  458. long lFlagIn,
  459. IWbemClassObject * pParamsIn,
  460. IWbemObjectSink * pHandlerIn
  461. )
  462. {
  463. SAFECLUSTER shCluster;
  464. SAFERESOURCE shRes;
  465. CWbemClassObject wcoInputParm( pParamsIn );
  466. shCluster = OpenCluster( NULL );
  467. //
  468. // static method
  469. //
  470. if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_CREATE_RESOURCE ) == 0 )
  471. {
  472. _bstr_t bstrTargetGroup;
  473. _bstr_t bstrResource;
  474. BOOL bSeperateMonitor;
  475. _bstr_t bstrResourceType;
  476. SAFERESOURCE shNewResource;
  477. SAFEGROUP shGroup;
  478. wcoInputParm.GetProperty( bstrTargetGroup, PVD_MTH_PARM_GROUP );
  479. wcoInputParm.GetProperty( bstrResource, PVD_MTH_PARM_RES_NAME );
  480. wcoInputParm.GetProperty( bstrResourceType, PVD_MTH_PARM_RES_TYPE );
  481. wcoInputParm.GetProperty( &bSeperateMonitor, PVD_MTH_PARM_SEP_MONITOR );
  482. shGroup = OpenClusterGroup( shCluster, bstrTargetGroup );
  483. shNewResource = CreateClusterResource(
  484. shGroup,
  485. bstrResource,
  486. bstrResourceType,
  487. bSeperateMonitor
  488. );
  489. } // if: CREATE_RESOURCE
  490. else
  491. {
  492. shRes = OpenClusterResource(
  493. shCluster,
  494. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  495. );
  496. if( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_DELETE_RESOURCE ) == 0 )
  497. {
  498. return DeleteClusterResource( shRes );
  499. }
  500. else if( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_OFFLINE ) == 0 )
  501. {
  502. DWORD dwTimeOut = 0;
  503. wcoInputParm.GetProperty( &dwTimeOut, PVD_MTH_PARM_RES_TIMEOUT );
  504. return HrWrapOfflineClusterResource( shCluster, shRes, dwTimeOut);
  505. } // if: OFFLINE
  506. else if( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_ONLINE ) == 0 )
  507. {
  508. DWORD dwTimeOut = 0;
  509. wcoInputParm.GetProperty( &dwTimeOut, PVD_MTH_PARM_RES_TIMEOUT );
  510. return HrWrapOnlineClusterResource( shCluster, shRes, dwTimeOut);
  511. } // else if: ONLINE
  512. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_CHANGE_GROUP ) == 0 )
  513. {
  514. _bstr_t bstrGroupObjpath;
  515. SAFEGROUP shGroup;
  516. CError er;
  517. wcoInputParm.GetProperty( bstrGroupObjpath, PVD_MTH_PARM_GROUP );
  518. shGroup = OpenClusterGroup( shCluster, bstrGroupObjpath );
  519. er = ChangeClusterResourceGroup( shRes, shGroup );
  520. } // else if: CHANGE_GROUP
  521. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_ADD_DEPENDENCY ) == 0 )
  522. {
  523. _bstr_t bstrDepResource;
  524. SAFERESOURCE shDepResource;
  525. CError er;
  526. wcoInputParm.GetProperty( bstrDepResource, PVD_MTH_PARM_RESOURCE );
  527. shDepResource = OpenClusterResource( shCluster, bstrDepResource );
  528. er = AddClusterResourceDependency( shRes, shDepResource );
  529. } // else if: ADD_DEPENDENCY
  530. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_REMOVE_DEPENDENCY ) == 0 )
  531. {
  532. _bstr_t bstrDepResource;
  533. SAFERESOURCE shDepResource;
  534. CError er;
  535. wcoInputParm.GetProperty( bstrDepResource, PVD_MTH_PARM_RESOURCE );
  536. shDepResource = OpenClusterResource( shCluster, bstrDepResource );
  537. er = RemoveClusterResourceDependency( shRes, shDepResource );
  538. } // else if: REMOVE_DEPENDENCY
  539. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_ADD_REG_CHECKPOINT ) == 0 )
  540. {
  541. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_ADD_REGISTRY_CHECKPOINT);
  542. }
  543. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_DEL_REG_CHECKPOINT ) == 0 )
  544. {
  545. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_DELETE_REGISTRY_CHECKPOINT);
  546. }
  547. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_ADD_CRYPTO_CHECKPOINT ) == 0 )
  548. {
  549. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_ADD_CRYPTO_CHECKPOINT);
  550. }
  551. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_DEL_CRYPTO_CHECKPOINT ) == 0 )
  552. {
  553. AddRemoveCheckpoint(shRes, wcoInputParm, CLUSCTL_RESOURCE_DELETE_CRYPTO_CHECKPOINT);
  554. }
  555. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_FAIL_RESOURCE ) == 0 )
  556. {
  557. CError er;
  558. er = FailClusterResource( shRes );
  559. } // if: FAIL_RESOURCE
  560. else if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_RES_RENAME ) == 0 )
  561. {
  562. _bstr_t bstrName;
  563. CError er;
  564. wcoInputParm.GetProperty( bstrName, PVD_MTH_PARM_NEWNAME );
  565. er = SetClusterResourceName( shRes, bstrName );
  566. } // if: RENAME
  567. else
  568. {
  569. return WBEM_E_INVALID_PARAMETER;
  570. }
  571. } // else: not CREATE_RESOURCE
  572. return WBEM_S_NO_ERROR;
  573. } //*** CClusterResource::ExecuteMethod()
  574. //////////////////////////////////////////////////////////////////////////////
  575. //++
  576. //
  577. // CClusterResource::PutInstance
  578. //
  579. // Description:
  580. // Save this instance.
  581. //
  582. // Arguments:
  583. // rInstToPutIn -- WMI object to be saved
  584. // lFlagIn -- WMI flag
  585. // pCtxIn -- WMI context
  586. // pHandlerIn -- WMI sink pointer
  587. //
  588. // Return Values:
  589. // WBEM_S_NO_ERROR
  590. //
  591. //--
  592. //////////////////////////////////////////////////////////////////////////////
  593. SCODE
  594. CClusterResource::PutInstance(
  595. CWbemClassObject & rInstToPutIn,
  596. long lFlagIn,
  597. IWbemContext * pCtxIn,
  598. IWbemObjectSink * pHandlerIn
  599. )
  600. {
  601. static SGetSetControl s_rgControl[] =
  602. {
  603. {
  604. CLUSCTL_RESOURCE_GET_COMMON_PROPERTIES,
  605. CLUSCTL_RESOURCE_SET_COMMON_PROPERTIES,
  606. FALSE
  607. },
  608. {
  609. CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES,
  610. CLUSCTL_RESOURCE_SET_PRIVATE_PROPERTIES,
  611. TRUE
  612. }
  613. };
  614. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  615. _bstr_t bstrName;
  616. SAFECLUSTER shCluster;
  617. SAFERESOURCE shResource;
  618. CError er;
  619. UINT idx;
  620. TracePrint(( "CClusterResource::PutInstance entry\n" ));
  621. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NAME );
  622. shCluster = OpenCluster( NULL );
  623. shResource = OpenClusterResource( shCluster, bstrName );
  624. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  625. {
  626. CClusPropList plOld;
  627. CClusPropList plNew;
  628. CWbemClassObject wco;
  629. if ( s_rgControl[ idx ].fPrivate )
  630. {
  631. rInstToPutIn.GetProperty( wco, PVD_PROP_RES_PRIVATE );
  632. }
  633. else
  634. {
  635. wco = rInstToPutIn;
  636. }
  637. er = plOld.ScGetResourceProperties(
  638. shResource,
  639. s_rgControl[ idx ].dwGetControl,
  640. NULL,
  641. NULL,
  642. 0
  643. );
  644. CClusterApi::SetObjectProperties(
  645. NULL,
  646. plNew,
  647. plOld,
  648. wco,
  649. s_rgControl[ idx ].fPrivate
  650. );
  651. if ( plNew.Cprops() > 0 )
  652. {
  653. er = ClusterResourceControl(
  654. shResource,
  655. NULL,
  656. s_rgControl[ idx ].dwSetControl,
  657. plNew.PbPropList(),
  658. static_cast< DWORD >( plNew.CbPropList() ),
  659. NULL,
  660. 0,
  661. NULL
  662. );
  663. }
  664. } // for: each control code
  665. return WBEM_S_NO_ERROR;
  666. } //*** CClusterResource::PutInstance()
  667. //////////////////////////////////////////////////////////////////////////////
  668. //++
  669. //
  670. // CClusterResource::DeleteInstance
  671. //
  672. // Description:
  673. // Delete the object specified in rObjPathIn
  674. //
  675. // Arguments:
  676. // rObjPathIn -- ObjPath for the instance to be deleted
  677. // lFlagIn -- WMI flag
  678. // pCtxIn -- WMI context
  679. // pHandlerIn -- WMI sink pointer
  680. //
  681. // Return Values:
  682. // WBEM_S_NO_ERROR
  683. //
  684. //--
  685. //////////////////////////////////////////////////////////////////////////////
  686. SCODE
  687. CClusterResource::DeleteInstance(
  688. CObjPath & rObjPathIn,
  689. long lFlagIn,
  690. IWbemContext * pCtxIn,
  691. IWbemObjectSink * pHandlerIn
  692. )
  693. {
  694. SAFECLUSTER shCluster;
  695. SAFERESOURCE shRes;
  696. CError er;
  697. shCluster = OpenCluster( NULL );
  698. shRes = OpenClusterResource(
  699. shCluster,
  700. rObjPathIn.GetStringValueForProperty( CLUSREG_NAME_RES_NAME )
  701. );
  702. er = HrWrapOfflineClusterResource( shCluster, shRes );
  703. er = DeleteClusterResource( shRes );
  704. return WBEM_S_NO_ERROR;
  705. } //*** CClusterResource::DeleteInstance()
  706. //****************************************************************************
  707. //
  708. // CClusterClusterQuorum
  709. //
  710. //****************************************************************************
  711. //////////////////////////////////////////////////////////////////////////////
  712. //++
  713. //
  714. // CClusterClusterQuorum::CClusterClusterQuorum
  715. //
  716. // Description:
  717. // Constructor.
  718. //
  719. // Arguments:
  720. // pwszNameIn -- Class name
  721. // pNamespaceIn -- Namespace
  722. // dwEnumTypeIn -- Type id
  723. //
  724. // Return Values:
  725. // None.
  726. //
  727. //--
  728. //////////////////////////////////////////////////////////////////////////////
  729. CClusterClusterQuorum::CClusterClusterQuorum(
  730. LPCWSTR pwszNameIn,
  731. CWbemServices * pNamespaceIn,
  732. DWORD dwEnumTypeIn
  733. )
  734. : CClusterObjAssoc( pwszNameIn, pNamespaceIn, dwEnumTypeIn )
  735. {
  736. } //*** CClusterClusterQuorum::CClusterClusterQuorum()
  737. //////////////////////////////////////////////////////////////////////////////
  738. //++
  739. //
  740. // static
  741. // CClusterClusterQuorum::S_CreateThis
  742. //
  743. // Description:
  744. // Create a cluster node object
  745. //
  746. // Arguments:
  747. // pwszNameIn -- Class name
  748. // pNamespaceIn -- Namespace
  749. // dwEnumTypeIn -- Type id
  750. //
  751. // Return Values:
  752. // pointer to the CProvBase
  753. //
  754. //--
  755. //////////////////////////////////////////////////////////////////////////////
  756. CProvBase *
  757. CClusterClusterQuorum::S_CreateThis(
  758. LPCWSTR pwszNameIn,
  759. CWbemServices * pNamespaceIn,
  760. DWORD dwEnumTypeIn
  761. )
  762. {
  763. return new CClusterClusterQuorum(
  764. pwszNameIn,
  765. pNamespaceIn,
  766. dwEnumTypeIn
  767. );
  768. } //*** CClusterClusterQuorum::S_CreateThis()
  769. //////////////////////////////////////////////////////////////////////////////
  770. //++
  771. //
  772. // CClusterClusterQuorum::EnumInstance
  773. //
  774. // Description:
  775. // Enumerate instances of cluster quorum
  776. //
  777. // Arguments:
  778. // lFlagsIn -- WMI flag
  779. // pCtxIn -- WMI context
  780. // pHandlerIn -- WMI sink pointer
  781. //
  782. // Return Values:
  783. // WBEM_S_NO_ERROR
  784. //
  785. //--
  786. //////////////////////////////////////////////////////////////////////////////
  787. SCODE
  788. CClusterClusterQuorum::EnumInstance(
  789. long lFlagsIn,
  790. IWbemContext * pCtxIn,
  791. IWbemObjectSink * pHandlerIn
  792. )
  793. {
  794. SAFECLUSTER shCluster;
  795. SAFERESOURCE shResource;
  796. DWORD cchResName = MAX_PATH;
  797. CWstrBuf wsbResName;
  798. DWORD cchDeviceName = MAX_PATH;
  799. CWstrBuf wsbDeviceName;
  800. DWORD cchClusterName = MAX_PATH;
  801. CWstrBuf wsbClusterName;
  802. DWORD dwLogsize;
  803. CError er;
  804. DWORD dwError;
  805. CWbemClassObject wco;
  806. CWbemClassObject wcoGroup;
  807. CWbemClassObject wcoPart;
  808. _bstr_t bstrGroup;
  809. _bstr_t bstrPart;
  810. wsbResName.SetSize( cchResName );
  811. wsbDeviceName.SetSize( cchDeviceName );
  812. wsbClusterName.SetSize( cchClusterName );
  813. shCluster = OpenCluster( NULL );
  814. m_wcoGroup.SpawnInstance( 0, & wcoGroup );
  815. m_wcoPart.SpawnInstance( 0, & wcoPart );
  816. dwError = GetClusterQuorumResource(
  817. shCluster,
  818. wsbResName,
  819. &cchResName,
  820. wsbDeviceName,
  821. &cchDeviceName,
  822. &dwLogsize
  823. );
  824. if ( dwError == ERROR_MORE_DATA )
  825. {
  826. wsbResName.SetSize( ++cchResName );
  827. wsbDeviceName.SetSize( ++cchDeviceName );
  828. er = GetClusterQuorumResource(
  829. shCluster,
  830. wsbResName,
  831. &cchResName,
  832. wsbDeviceName,
  833. &cchDeviceName,
  834. &dwLogsize
  835. );
  836. } // if: buffer was too small
  837. dwError = GetClusterInformation(
  838. shCluster,
  839. wsbClusterName,
  840. &cchClusterName,
  841. NULL
  842. );
  843. if ( dwError == ERROR_MORE_DATA )
  844. {
  845. wsbClusterName.SetSize( ++cchClusterName );
  846. er = GetClusterInformation(
  847. shCluster,
  848. wsbClusterName,
  849. &cchClusterName,
  850. NULL
  851. );
  852. } // if: buffer was too small
  853. wcoPart.SetProperty( wsbResName, PVD_PROP_NAME );
  854. wcoPart.GetProperty( bstrPart, PVD_WBEM_RELPATH );
  855. wcoGroup.SetProperty( wsbClusterName, PVD_PROP_NAME );
  856. wcoGroup.GetProperty( bstrGroup, PVD_WBEM_RELPATH );
  857. m_pClass->SpawnInstance( 0, &wco );
  858. wco.SetProperty( (LPWSTR) bstrGroup, PVD_PROP_GROUPCOMPONENT );
  859. wco.SetProperty( (LPWSTR) bstrPart, PVD_PROP_PARTCOMPONENT );
  860. pHandlerIn->Indicate( 1, &wco );
  861. return WBEM_S_NO_ERROR;
  862. } //*** ClusterClusterQuorum::EnumInstance()