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.

673 lines
18 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusterNetwork.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterNetwork class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ClusterNetwork.h"
  17. //****************************************************************************
  18. //
  19. // CClusterNetwork
  20. //
  21. //****************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // CClusterNetwork::CClusterNetwork
  26. //
  27. // Description:
  28. // Constructor.
  29. //
  30. // Arguments:
  31. // pwszNameIn -- Class name
  32. // pNamespaceIn -- Namespace
  33. //
  34. // Return Values:
  35. // None.
  36. //
  37. //--
  38. //////////////////////////////////////////////////////////////////////////////
  39. CClusterNetwork::CClusterNetwork(
  40. LPCWSTR pwszNameIn,
  41. CWbemServices * pNamespaceIn
  42. )
  43. :CProvBase( pwszNameIn, pNamespaceIn )
  44. {
  45. } //*** CClusterNetwork::CClusterNetwork()
  46. //////////////////////////////////////////////////////////////////////////////
  47. //++
  48. //
  49. // static
  50. // CClusterNetwork::S_CreateThis
  51. //
  52. // Description:
  53. // Create a cluster node object.
  54. //
  55. // Arguments:
  56. // pwszNameIn -- Class name
  57. // pNamespaceIn -- Namespace
  58. // dwEnumTypeIn -- Type id
  59. //
  60. // Return Values:
  61. // pointer to the CProvBase
  62. //
  63. //--
  64. //////////////////////////////////////////////////////////////////////////////
  65. CProvBase *
  66. CClusterNetwork::S_CreateThis(
  67. LPCWSTR pwszNameIn,
  68. CWbemServices * pNamespaceIn,
  69. DWORD // dwEnumTypeIn
  70. )
  71. {
  72. return new CClusterNetwork( pwszNameIn, pNamespaceIn );
  73. } //*** CClusterNetwork::S_CreateThis()
  74. //////////////////////////////////////////////////////////////////////////////
  75. //++
  76. //
  77. // CClusterNetwork::RgGetPropMap
  78. //
  79. // Description:
  80. // Retrieve the property maping table of the cluster network.
  81. //
  82. // Arguments:
  83. // None.
  84. //
  85. // Return Values:
  86. // Reference to the array of property maping table.
  87. //
  88. //--
  89. //////////////////////////////////////////////////////////////////////////////
  90. const SPropMapEntryArray *
  91. CClusterNetwork::RgGetPropMap( void )
  92. {
  93. static SPropMapEntry s_rgpm[] =
  94. {
  95. {
  96. NULL,
  97. CLUSREG_NAME_NET_PRIORITY,
  98. SZ_TYPE,
  99. READONLY
  100. }
  101. ,
  102. {
  103. NULL,
  104. CLUSREG_NAME_NET_TRANSPORT,
  105. DWORD_TYPE,
  106. READWRITE
  107. }
  108. };
  109. static SPropMapEntryArray s_pmea(
  110. sizeof( s_rgpm ) /sizeof( SPropMapEntry ),
  111. s_rgpm
  112. );
  113. return & s_pmea;
  114. } //*** CClusterNetwork::RgGetPropMap()
  115. //////////////////////////////////////////////////////////////////////////////
  116. //++
  117. //
  118. // CClusterNetwork::EnumInstance
  119. //
  120. // Description:
  121. // enum cluster instance
  122. //
  123. // Arguments:
  124. // lFlagsIn -- WMI flag
  125. // pCtxIn -- WMI context
  126. // pHandlerIn -- WMI sink pointer
  127. //
  128. // Return Values:
  129. // WBEM_S_NO_ERROR
  130. //
  131. //--
  132. //////////////////////////////////////////////////////////////////////////////
  133. SCODE
  134. CClusterNetwork::EnumInstance(
  135. long lFlagsIn,
  136. IWbemContext * pCtxIn,
  137. IWbemObjectSink * pHandlerIn
  138. )
  139. {
  140. SAFECLUSTER shCluster;
  141. SAFENETWORK shNetwork;
  142. LPCWSTR pwszName;
  143. shCluster = OpenCluster( NULL );
  144. CClusterEnum cluEnum( shCluster, CLUSTER_ENUM_NETWORK );
  145. while ( ( pwszName = cluEnum.GetNext() ) != NULL )
  146. {
  147. shNetwork = OpenClusterNetwork( shCluster, pwszName );
  148. ClusterToWMI( shNetwork, pHandlerIn );
  149. } // while: more networks
  150. return WBEM_S_NO_ERROR;
  151. } //*** CClusterNetwork::EnumInstance()
  152. //////////////////////////////////////////////////////////////////////////////
  153. //++
  154. //
  155. // CClusterResource::ClusterToWMI
  156. //
  157. // Description:
  158. // Translate a cluster resource objects to WMI object.
  159. //
  160. // Arguments:
  161. // hResourceIn -- handle to resource
  162. // pHandlerIn -- Pointer to WMI sink
  163. //
  164. // Return Values:
  165. // WBEM_S_NO_ERROR
  166. // win32 error
  167. //
  168. //--
  169. //////////////////////////////////////////////////////////////////////////////
  170. void
  171. CClusterNetwork::ClusterToWMI(
  172. HNETWORK hNetworkIn,
  173. IWbemObjectSink * pHandlerIn
  174. )
  175. {
  176. static SGetControl s_rgControl[] =
  177. {
  178. { CLUSCTL_NETWORK_GET_RO_COMMON_PROPERTIES, FALSE },
  179. { CLUSCTL_NETWORK_GET_COMMON_PROPERTIES, FALSE },
  180. { CLUSCTL_NETWORK_GET_RO_PRIVATE_PROPERTIES, TRUE },
  181. { CLUSCTL_NETWORK_GET_PRIVATE_PROPERTIES, TRUE }
  182. };
  183. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  184. CWbemClassObject wco;
  185. CError er;
  186. UINT idx;
  187. m_pClass->SpawnInstance( 0, & wco );
  188. for ( idx = 0 ; idx < s_cControl ; idx ++ )
  189. {
  190. CClusPropList pl;
  191. er = pl.ScGetNetworkProperties(
  192. hNetworkIn,
  193. s_rgControl[ idx ].dwControl,
  194. NULL,
  195. 0
  196. );
  197. CClusterApi::GetObjectProperties(
  198. RgGetPropMap(),
  199. pl,
  200. wco,
  201. s_rgControl[ idx ].fPrivate
  202. );
  203. } // for: each control code
  204. {
  205. DWORD dwState = GetClusterNetworkState( hNetworkIn );
  206. wco.SetProperty( dwState, PVD_PROP_NETWORK_STATE );
  207. }
  208. //
  209. // flags and characteristics
  210. //
  211. {
  212. DWORD cbReturned;
  213. DWORD dwOut;
  214. er = ClusterNetworkControl(
  215. hNetworkIn,
  216. NULL,
  217. CLUSCTL_NETWORK_GET_CHARACTERISTICS, // this control code
  218. NULL, // input buffer (not used)
  219. 0, // input buffer size (not used)
  220. & dwOut,
  221. sizeof( DWORD ),
  222. & cbReturned
  223. );
  224. wco.SetProperty(
  225. dwOut,
  226. PVD_PROP_CHARACTERISTIC
  227. );
  228. }
  229. pHandlerIn->Indicate( 1, & wco );
  230. return;
  231. } //*** CClusterResource::ClusterToWMI()
  232. //////////////////////////////////////////////////////////////////////////////
  233. //++
  234. //
  235. // CClusterNetwork::GetObject
  236. //
  237. // Description:
  238. // Retrieve cluster node object based given object path.
  239. //
  240. // Arguments:
  241. // rObjPathIn -- Object path to cluster object
  242. // lFlagsIn -- WMI flag
  243. // pCtxIn -- WMI context
  244. // pHandlerIn -- WMI sink pointer
  245. //
  246. // Return Values:
  247. // WBEM_S_NO_ERROR
  248. // win32 error
  249. //
  250. //--
  251. //////////////////////////////////////////////////////////////////////////////
  252. SCODE
  253. CClusterNetwork::GetObject(
  254. CObjPath & rObjPathIn,
  255. long lFlagsIn,
  256. IWbemContext * pCtxIn,
  257. IWbemObjectSink * pHandlerIn
  258. )
  259. {
  260. SAFECLUSTER shCluster;
  261. SAFENETWORK shNetwork;
  262. shCluster = OpenCluster( NULL );
  263. shNetwork = OpenClusterNetwork(
  264. shCluster,
  265. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  266. );
  267. ClusterToWMI( shNetwork, pHandlerIn );
  268. return WBEM_S_NO_ERROR;
  269. } //*** CClusterNetwork::GetObject()
  270. //////////////////////////////////////////////////////////////////////////////
  271. //++
  272. //
  273. // CClusterNetwork::ExecuteMethod
  274. //
  275. // Description:
  276. // Execute methods defined in the mof for cluster network.
  277. //
  278. // Arguments:
  279. // rObjPathIn -- Object path to cluster object
  280. // pwszMethodNameIn -- Name of the method to be invoked
  281. // lFlagIn -- WMI flag
  282. // pParamsIn -- Input parameters for the method
  283. // pHandlerIn -- WMI sink pointer
  284. //
  285. // Return Values:
  286. // WBEM_S_NO_ERROR
  287. //
  288. //--
  289. //////////////////////////////////////////////////////////////////////////////
  290. SCODE
  291. CClusterNetwork::ExecuteMethod(
  292. CObjPath & rObjPathIn,
  293. WCHAR * pwszMethodNameIn,
  294. long lFlagIn,
  295. IWbemClassObject * pParamsIn,
  296. IWbemObjectSink * pHandlerIn
  297. )
  298. {
  299. SAFECLUSTER shCluster;
  300. CWbemClassObject wcoInArgs( pParamsIn );
  301. CError er;
  302. shCluster = OpenCluster( NULL );
  303. if ( ClRtlStrICmp( pwszMethodNameIn, PVD_MTH_NETWORK_RENAME ) == 0 )
  304. {
  305. _bstr_t bstrName;
  306. SAFENETWORK shNetwork;
  307. wcoInArgs.GetProperty( bstrName, PVD_MTH_NETWORK_PARM_NEWNAME );
  308. shNetwork = OpenClusterNetwork(
  309. shCluster,
  310. rObjPathIn.GetStringValueForProperty( PVD_PROP_NAME )
  311. );
  312. er = SetClusterNetworkName( shNetwork, bstrName );
  313. } // if: RENAME
  314. else
  315. {
  316. er = static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER );
  317. }
  318. return WBEM_S_NO_ERROR;
  319. } //*** CClusterNetwork::ExecuteMethod()
  320. //////////////////////////////////////////////////////////////////////////////
  321. //++
  322. //
  323. // CClusterNetwork::PutInstance
  324. //
  325. // Description:
  326. // Save this instance.
  327. //
  328. // Arguments:
  329. // rInstToPutIn -- WMI object to be saved
  330. // lFlagIn -- WMI flag
  331. // pCtxIn -- WMI context
  332. // pHandlerIn -- WMI sink pointer
  333. //
  334. // Return Values:
  335. // WBEM_S_NO_ERROR
  336. //
  337. //--
  338. //////////////////////////////////////////////////////////////////////////////
  339. SCODE
  340. CClusterNetwork::PutInstance(
  341. CWbemClassObject & rInstToPutIn,
  342. long lFlagIn,
  343. IWbemContext * pCtxIn,
  344. IWbemObjectSink * pHandlerIn
  345. )
  346. {
  347. static SGetSetControl s_rgControl[] =
  348. {
  349. {
  350. CLUSCTL_NETWORK_GET_COMMON_PROPERTIES,
  351. CLUSCTL_NETWORK_SET_COMMON_PROPERTIES,
  352. FALSE
  353. },
  354. {
  355. CLUSCTL_NETWORK_GET_PRIVATE_PROPERTIES,
  356. CLUSCTL_NETWORK_SET_PRIVATE_PROPERTIES,
  357. TRUE
  358. }
  359. };
  360. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetSetControl );
  361. _bstr_t bstrName;
  362. SAFECLUSTER shCluster;
  363. SAFENETWORK shNetwork;
  364. CError er;
  365. UINT idx;
  366. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NAME );
  367. shCluster = OpenCluster( NULL );
  368. shNetwork = OpenClusterNetwork( shCluster, bstrName );
  369. for ( idx = 0 ; idx < s_cControl; idx ++ )
  370. {
  371. CClusPropList plOld;
  372. CClusPropList plNew;
  373. er = plOld.ScGetNetworkProperties(
  374. shNetwork,
  375. s_rgControl[ idx ].dwGetControl,
  376. NULL,
  377. NULL,
  378. 0
  379. );
  380. CClusterApi::SetObjectProperties(
  381. RgGetPropMap(),
  382. plNew,
  383. plOld,
  384. rInstToPutIn,
  385. s_rgControl[ idx ].fPrivate
  386. );
  387. if ( plNew.Cprops() > 0 )
  388. {
  389. er = ClusterNetworkControl(
  390. shNetwork,
  391. NULL,
  392. s_rgControl[ idx ].dwSetControl,
  393. plNew.PbPropList(),
  394. static_cast< DWORD >( plNew.CbPropList() ),
  395. NULL,
  396. 0,
  397. NULL
  398. );
  399. }
  400. } // for: each control code
  401. return WBEM_S_NO_ERROR;
  402. } //*** CClusterNetwork::PutInstance()
  403. //////////////////////////////////////////////////////////////////////////////
  404. //++
  405. //
  406. // CClusterNetwork::DeleteInstance
  407. //
  408. // Description:
  409. // Delete the object specified in rObjPathIn.
  410. //
  411. // Arguments:
  412. // rObjPathIn -- ObjPath for the instance to be deleted
  413. // lFlagIn -- WMI flag
  414. // pCtxIn -- WMI context
  415. // pHandlerIn -- WMI sink pointer
  416. //
  417. // Return Values:
  418. // WBEM_E_NOT_SUPPORTED
  419. //
  420. //--
  421. //////////////////////////////////////////////////////////////////////////////
  422. SCODE
  423. CClusterNetwork::DeleteInstance(
  424. CObjPath & rObjPathIn,
  425. long lFlagIn,
  426. IWbemContext * pCtxIn,
  427. IWbemObjectSink * pHandlerIn
  428. )
  429. {
  430. return WBEM_E_NOT_SUPPORTED;
  431. } //*** CClusterNetwork::DeleteInstance()
  432. //****************************************************************************
  433. //
  434. // CClusterNetNetInterface
  435. //
  436. //****************************************************************************
  437. //////////////////////////////////////////////////////////////////////////////
  438. //++
  439. //
  440. // ClusterNetNetInterface::CClusterNetNetInterface
  441. //
  442. // Description:
  443. // Constructor.
  444. //
  445. // Arguments:
  446. // pwszNameIn -- Class name
  447. // pNamespaceIn -- Namespace
  448. // dwEnumTypeIn -- Type id
  449. //
  450. // Return Values:
  451. // None.
  452. //
  453. //--
  454. //////////////////////////////////////////////////////////////////////////////
  455. CClusterNetNetInterface::CClusterNetNetInterface(
  456. const WCHAR * pwszNameIn,
  457. CWbemServices * pNamespaceIn,
  458. DWORD dwEnumTypeIn
  459. )
  460. : CClusterObjAssoc( pwszNameIn, pNamespaceIn, dwEnumTypeIn )
  461. {
  462. } //*** ClusterNetNetInterface::ClusterNetNetInterface()
  463. //////////////////////////////////////////////////////////////////////////////
  464. //++
  465. //
  466. // static
  467. // ClusterNetNetInterface::S_CreateThis
  468. //
  469. // Description:
  470. // Create a cluster node object
  471. //
  472. // Arguments:
  473. // pwszNameIn -- Class name
  474. // pNamespaceIn -- Namespace
  475. // dwEnumTypeIn -- Type id
  476. //
  477. // Return Values:
  478. // Pointer to the CProvBase
  479. //
  480. //--
  481. //////////////////////////////////////////////////////////////////////////////
  482. CProvBase *
  483. CClusterNetNetInterface::S_CreateThis(
  484. LPCWSTR pwszNameIn,
  485. CWbemServices * pNamespaceIn,
  486. DWORD dwEnumTypeIn
  487. )
  488. {
  489. return new CClusterNetNetInterface(
  490. pwszNameIn,
  491. pNamespaceIn,
  492. dwEnumTypeIn
  493. );
  494. } //*** ClusterNetNetInterface::S_CreateThis()
  495. //////////////////////////////////////////////////////////////////////////////
  496. //++
  497. //
  498. // ClusterNetNetInterface::GetPropMap
  499. //
  500. // Description:
  501. // Retrieve the property maping table of the cluster network net interface.
  502. //
  503. // Arguments:
  504. // lFlagsIn --
  505. // pCtxIn --
  506. // pHandlerIn --
  507. //
  508. // Return Values:
  509. // Reference to the array of property maping table
  510. //
  511. //--
  512. //////////////////////////////////////////////////////////////////////////////
  513. SCODE
  514. CClusterNetNetInterface::EnumInstance(
  515. long lFlagsIn,
  516. IWbemContext * pCtxIn,
  517. IWbemObjectSink * pHandlerIn
  518. )
  519. {
  520. SAFECLUSTER shCluster;
  521. CError er;
  522. DWORD dwError;
  523. CWbemClassObject wcoGroup;
  524. _bstr_t bstrGroup;
  525. _bstr_t bstrPart;
  526. DWORD cbNetworkName = MAX_PATH;
  527. CWstrBuf wsbNetworkName;
  528. HRESULT hr;
  529. CComPtr< IEnumWbemClassObject > pEnum;
  530. shCluster = OpenCluster( NULL );
  531. CClusterEnum clusEnum( shCluster, m_dwEnumType );
  532. m_wcoGroup.SpawnInstance( 0, & wcoGroup );
  533. //
  534. // network interface objects
  535. //
  536. er = m_pNamespace->CreateInstanceEnum(
  537. _bstr_t( PVD_CLASS_NETWORKINTERFACE ),
  538. 0,
  539. NULL,
  540. & pEnum
  541. );
  542. wsbNetworkName.SetSize( cbNetworkName );
  543. for ( ; ; )
  544. {
  545. CWbemClassObject wcoNetInterface;
  546. DWORD cWco;
  547. hr = pEnum->Next(
  548. 5000,
  549. 1,
  550. & wcoNetInterface,
  551. & cWco
  552. );
  553. if ( hr == WBEM_S_NO_ERROR )
  554. {
  555. SAFENETINTERFACE shNetInterface;
  556. DWORD cbReturn;
  557. CWbemClassObject wco;
  558. wcoNetInterface.GetProperty( bstrPart, PVD_WBEM_PROP_DEVICEID );
  559. shNetInterface = OpenClusterNetInterface( shCluster, bstrPart );
  560. dwError = ClusterNetInterfaceControl(
  561. shNetInterface,
  562. NULL,
  563. CLUSCTL_NETINTERFACE_GET_NETWORK,
  564. NULL,
  565. 0,
  566. wsbNetworkName,
  567. cbNetworkName,
  568. & cbReturn
  569. );
  570. if ( dwError == ERROR_MORE_DATA )
  571. {
  572. cbNetworkName = cbReturn;
  573. wsbNetworkName.SetSize( cbNetworkName );
  574. er = ClusterNetInterfaceControl(
  575. shNetInterface,
  576. NULL,
  577. CLUSCTL_NETINTERFACE_GET_NETWORK,
  578. NULL,
  579. 0,
  580. wsbNetworkName,
  581. cbNetworkName,
  582. & cbReturn
  583. );
  584. } // if: buffer is too small
  585. wcoGroup.SetProperty( wsbNetworkName, CLUSREG_NAME_NET_NAME );
  586. wcoGroup.GetProperty( bstrGroup, PVD_WBEM_RELPATH );
  587. wcoNetInterface.GetProperty( bstrPart, PVD_WBEM_RELPATH );
  588. m_pClass->SpawnInstance( 0, & wco );
  589. wco.SetProperty( (LPWSTR) bstrGroup, PVD_PROP_GROUPCOMPONENT );
  590. wco.SetProperty( (LPWSTR ) bstrPart, PVD_PROP_PARTCOMPONENT );
  591. pHandlerIn->Indicate( 1, & wco );
  592. } // if: no error
  593. else
  594. {
  595. break;
  596. } // else S_FALSE, or error
  597. } // forever
  598. if ( FAILED ( hr ) )
  599. {
  600. er = hr;
  601. }
  602. return WBEM_S_NO_ERROR;
  603. } //*** ClusterNetNetInterface::EnumInstance()