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.

477 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 Microsoft Corporation
  4. //
  5. // Module Name: CClusterNetInterface.cpp
  6. //
  7. // Description:
  8. // Implementation of CClusterNetInterface class
  9. //
  10. // Author:
  11. // Henry Wang (HenryWa) 24-AUG-1999
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #include "Pch.h"
  15. #include "ClusterNetInterface.h"
  16. #include "ClusterNetInterface.tmh"
  17. //****************************************************************************
  18. //
  19. // CClusterNetInterface
  20. //
  21. //****************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // CClusterNetInterface::CClusterNetInterface
  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. CClusterNetInterface::CClusterNetInterface(
  40. LPCWSTR pwszNameIn,
  41. CWbemServices * pNamespaceIn
  42. )
  43. : CProvBase( pwszNameIn, pNamespaceIn )
  44. {
  45. } //*** CClusterNetInterface::CClusterNetInterface()
  46. //////////////////////////////////////////////////////////////////////////////
  47. //++
  48. //
  49. // static
  50. // CClusterNetInterface::S_CreateThis
  51. //
  52. // Description:
  53. // Create a cluster network interface 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. CClusterNetInterface::S_CreateThis(
  67. LPCWSTR pwszNameIn,
  68. CWbemServices * pNamespaceIn,
  69. DWORD // dwEnumTypeIn
  70. )
  71. {
  72. return new CClusterNetInterface( pwszNameIn, pNamespaceIn );
  73. } // CClusterNetInterface::S_CreateThis
  74. //////////////////////////////////////////////////////////////////////////////
  75. //++
  76. //
  77. // CClusterNetInterface::RgGetPropMap
  78. //
  79. // Description:
  80. // Retrieve the property maping table of the cluster node.
  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. CClusterNetInterface::RgGetPropMap( void )
  92. {
  93. static SPropMapEntry s_rgpm[] =
  94. {
  95. {
  96. PVD_PROP_NETINTERFACE_DEVICEID,
  97. CLUSREG_NAME_NETIFACE_NAME,
  98. SZ_TYPE,
  99. READONLY
  100. },
  101. {
  102. PVD_PROP_NETINTERFACE_SYSTEMNAME,
  103. CLUSREG_NAME_NETIFACE_NODE,
  104. DWORD_TYPE,
  105. READWRITE
  106. },
  107. {
  108. NULL,
  109. CLUSREG_NAME_NETIFACE_ADAPTER_ID,
  110. DWORD_TYPE,
  111. READWRITE
  112. },
  113. {
  114. NULL,
  115. CLUSREG_NAME_NETIFACE_ENDPOINT,
  116. DWORD_TYPE,
  117. READWRITE
  118. }
  119. };
  120. static SPropMapEntryArray s_pmea(
  121. sizeof( s_rgpm ) /sizeof( SPropMapEntry ),
  122. s_rgpm
  123. );
  124. return &s_pmea;
  125. } //*** CClusterNetInterface::RgGetPropMap()
  126. //////////////////////////////////////////////////////////////////////////////
  127. //++
  128. //
  129. // CClusterNetInterface::EnumInstance
  130. //
  131. // Description:
  132. // Enum cluster instance
  133. //
  134. // Arguments:
  135. // lFlagsIn -- WMI flag
  136. // pCtxIn -- WMI context
  137. // pHandlerIn -- WMI sink pointer
  138. //
  139. // Return Values:
  140. // WBEM_S_NO_ERROR
  141. //
  142. //--
  143. //////////////////////////////////////////////////////////////////////////////
  144. SCODE
  145. CClusterNetInterface::EnumInstance(
  146. long lFlagsIn,
  147. IWbemContext * pCtxIn,
  148. IWbemObjectSink * pHandlerIn
  149. )
  150. {
  151. SAFECLUSTER shCluster;
  152. SAFENETINTERFACE shNetInterface;
  153. LPCWSTR pwszName;
  154. shCluster = OpenCluster( NULL );
  155. CClusterEnum cluEnum(
  156. shCluster,
  157. CLUSTER_ENUM_NETINTERFACE );
  158. while ( ( pwszName = cluEnum.GetNext() ) != NULL )
  159. {
  160. shNetInterface = OpenClusterNetInterface( shCluster, pwszName );
  161. ClusterToWMI( shNetInterface, pHandlerIn, pwszName );
  162. }
  163. return WBEM_S_NO_ERROR;
  164. } //*** CClusterNetInterface::EnumInstance()
  165. //////////////////////////////////////////////////////////////////////////////
  166. //++
  167. //
  168. // CClusterResource::ClusterToWMI
  169. //
  170. // Description:
  171. // Translate a cluster network interface object to WMI object.
  172. //
  173. // Arguments:
  174. // hNetInterfaceIn -- handle to network interface
  175. // pHandlerIn -- Pointer to WMI sink
  176. // pwszNameIn -- Name of the network interface
  177. //
  178. // Return Values:
  179. // WBEM_S_NO_ERROR
  180. // win32 error
  181. //
  182. //--
  183. //////////////////////////////////////////////////////////////////////////////
  184. void
  185. CClusterNetInterface::ClusterToWMI(
  186. HNETINTERFACE hNetInterfaceIn,
  187. IWbemObjectSink * pHandlerIn,
  188. LPCWSTR pwszNameIn
  189. )
  190. {
  191. static SGetControl s_rgControl[] =
  192. {
  193. { CLUSCTL_NETINTERFACE_GET_RO_COMMON_PROPERTIES, FALSE },
  194. { CLUSCTL_NETINTERFACE_GET_COMMON_PROPERTIES, FALSE },
  195. { CLUSCTL_NETINTERFACE_GET_RO_PRIVATE_PROPERTIES, TRUE },
  196. { CLUSCTL_NETINTERFACE_GET_PRIVATE_PROPERTIES, TRUE }
  197. };
  198. static DWORD s_cControl = sizeof( s_rgControl ) / sizeof( SGetControl );
  199. CWbemClassObject wco;
  200. CError er;
  201. UINT idx;
  202. m_pClass->SpawnInstance( 0, & wco);
  203. for( idx = 0 ; idx < s_cControl ; idx++ )
  204. {
  205. CClusPropList pl;
  206. er = pl.ScGetNetInterfaceProperties(
  207. hNetInterfaceIn,
  208. s_rgControl[ idx ].dwControl,
  209. NULL,
  210. 0 );
  211. CClusterApi::GetObjectProperties(
  212. RgGetPropMap(),
  213. pl,
  214. wco,
  215. s_rgControl[ idx ].fPrivate
  216. );
  217. } // for: each control code
  218. //
  219. // Set the network interface name
  220. //
  221. wco.SetProperty(
  222. pwszNameIn,
  223. PVD_PROP_NETINTERFACE_NAME
  224. );
  225. wco.SetProperty(
  226. GetClusterNetInterfaceState( hNetInterfaceIn),
  227. PVD_PROP_NETINTERFACE_STATE
  228. );
  229. //
  230. // flags and characteristics
  231. //
  232. {
  233. DWORD cbReturned;
  234. DWORD dwOut;
  235. er = ClusterNetInterfaceControl(
  236. hNetInterfaceIn,
  237. NULL,
  238. CLUSCTL_NETINTERFACE_GET_CHARACTERISTICS, // this control code
  239. NULL, // input buffer (not used)
  240. 0, // input buffer size (not used)
  241. & dwOut,
  242. sizeof( DWORD ),
  243. & cbReturned
  244. );
  245. wco.SetProperty(
  246. dwOut,
  247. PVD_PROP_CHARACTERISTIC
  248. );
  249. }
  250. pHandlerIn->Indicate( 1, & wco );
  251. return;
  252. } //*** CClusterResource::ClusterToWMI()
  253. //////////////////////////////////////////////////////////////////////////////
  254. //++
  255. //
  256. // CClusterNetInterface::GetObject
  257. //
  258. // Description:
  259. // Retrieve cluster network interface object based given object path.
  260. //
  261. // Arguments:
  262. // rObjPathIn -- Object path to cluster object
  263. // lFlagsIn -- WMI flag
  264. // pCtxIn -- WMI context
  265. // pHandlerIn -- WMI sink pointer
  266. //
  267. // Return Values:
  268. // WBEM_S_NO_ERROR
  269. // Win32 error
  270. //
  271. //--
  272. //////////////////////////////////////////////////////////////////////////////
  273. SCODE
  274. CClusterNetInterface::GetObject(
  275. CObjPath & rObjPathIn,
  276. long lFlagsIn,
  277. IWbemContext * pCtxIn,
  278. IWbemObjectSink * pHandlerIn
  279. )
  280. {
  281. SAFECLUSTER shCluster;
  282. SAFENETINTERFACE shNetInterface;
  283. LPCWSTR pwszName = rObjPathIn.GetStringValueForProperty( PVD_PROP_NETINTERFACE_DEVICEID );
  284. shCluster = OpenCluster( NULL ) ;
  285. shNetInterface = OpenClusterNetInterface( shCluster, pwszName );
  286. ClusterToWMI( shNetInterface, pHandlerIn, pwszName );
  287. return WBEM_S_NO_ERROR;
  288. } //*** CClusterNetInterface::GetObject()
  289. //////////////////////////////////////////////////////////////////////////////
  290. //++
  291. //
  292. // CClusterNetInterface::ExecuteMethod
  293. //
  294. // Description:
  295. // Execute methods defined in the mof for cluster network interface.
  296. //
  297. // Arguments:
  298. // rObjPathIn -- Object path to cluster object
  299. // pwszMethodNameIn -- Name of the method to be invoked
  300. // lFlagIn -- WMI flag
  301. // pParamsIn -- Input parameters for the method
  302. // pHandlerIn -- WMI sink pointer
  303. //
  304. // Return Values:
  305. // WBEM_E_NOT_SUPPORTED
  306. //
  307. //--
  308. //////////////////////////////////////////////////////////////////////////////
  309. SCODE
  310. CClusterNetInterface::ExecuteMethod(
  311. CObjPath & rObjPathIn,
  312. WCHAR * pwszMethodNameIn,
  313. long lFlagIn,
  314. IWbemClassObject * pParamsIn,
  315. IWbemObjectSink * pHandlerIn
  316. )
  317. {
  318. return WBEM_E_NOT_SUPPORTED;
  319. } //*** CClusterNetInterface::ExecuteMethod()
  320. //////////////////////////////////////////////////////////////////////////////
  321. //++
  322. //
  323. // CClusterNetInterface::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_E_NOT_SUPPORTED
  336. //
  337. //--
  338. //////////////////////////////////////////////////////////////////////////////
  339. SCODE
  340. CClusterNetInterface::PutInstance(
  341. CWbemClassObject & rInstToPutIn,
  342. long lFlagIn,
  343. IWbemContext * pCtxIn,
  344. IWbemObjectSink * pHandlerIn
  345. )
  346. {
  347. static SGetSetControl s_rgControl[] =
  348. {
  349. {
  350. CLUSCTL_NETINTERFACE_GET_COMMON_PROPERTIES,
  351. CLUSCTL_NETINTERFACE_SET_COMMON_PROPERTIES,
  352. FALSE
  353. },
  354. {
  355. CLUSCTL_NETINTERFACE_GET_PRIVATE_PROPERTIES,
  356. CLUSCTL_NETINTERFACE_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. SAFENETINTERFACE shNetwork;
  364. CError er;
  365. UINT idx;
  366. rInstToPutIn.GetProperty( bstrName, PVD_PROP_NETINTERFACE_DEVICEID );
  367. shCluster = OpenCluster( NULL );
  368. shNetwork = OpenClusterNetInterface( shCluster, bstrName );
  369. for ( idx = 0 ; idx < s_cControl; idx ++ )
  370. {
  371. CClusPropList plOld;
  372. CClusPropList plNew;
  373. er = plOld.ScGetNetInterfaceProperties(
  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 = ClusterNetInterfaceControl(
  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. } //*** CClusterNetInterface::PutInstance()
  403. //////////////////////////////////////////////////////////////////////////////
  404. //++
  405. //
  406. // CClusterNetInterface::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. CClusterNetInterface::DeleteInstance(
  424. CObjPath & rObjPathIn,
  425. long lFlagIn,
  426. IWbemContext * pCtxIn,
  427. IWbemObjectSink * pHandlerIn
  428. )
  429. {
  430. return WBEM_E_NOT_SUPPORTED;
  431. } //*** CClusterNetInterface::DeleteInstance()