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.

2110 lines
49 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgNetworkInfo.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CClusCfgNetworkInfo
  10. // class.
  11. //
  12. // The class CClusCfgNetworkInfo represents a cluster manageable
  13. // network. It implements the IClusCfgNetworkInfo interface.
  14. //
  15. // Maintained By:
  16. // Galen Barbee (GalenB) 23-FEB-2000
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Include Files
  21. //////////////////////////////////////////////////////////////////////////////
  22. #include "Pch.h"
  23. #include <PropList.h>
  24. #include <ClusRtl.h>
  25. #include "CClusCfgNetworkInfo.h"
  26. #include "CEnumClusCfgIPAddresses.h"
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Constant Definitions
  29. //////////////////////////////////////////////////////////////////////////////
  30. DEFINE_THISCLASS( "CClusCfgNetworkInfo" );
  31. //*************************************************************************//
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CClusCfgNetworkInfo class
  34. /////////////////////////////////////////////////////////////////////////////
  35. //////////////////////////////////////////////////////////////////////////////
  36. //++
  37. //
  38. // CClusCfgNetworkInfo::S_HrCreateInstance
  39. //
  40. // Description:
  41. // Create a CClusCfgNetworkInfo instance.
  42. //
  43. // Arguments:
  44. // None.
  45. //
  46. // Return Values:
  47. // Pointer to CClusCfgNetworkInfo instance.
  48. //
  49. //--
  50. //////////////////////////////////////////////////////////////////////////////
  51. HRESULT
  52. CClusCfgNetworkInfo::S_HrCreateInstance(
  53. IUnknown ** ppunkOut
  54. )
  55. {
  56. TraceFunc( "" );
  57. HRESULT hr = S_OK;
  58. CClusCfgNetworkInfo * pccni = NULL;
  59. if ( ppunkOut == NULL )
  60. {
  61. hr = THR( E_POINTER );
  62. goto Cleanup;
  63. } // if:
  64. pccni = new CClusCfgNetworkInfo();
  65. if ( pccni == NULL )
  66. {
  67. hr = THR( E_OUTOFMEMORY );
  68. goto Cleanup;
  69. } // if: error allocating object
  70. hr = THR( pccni->HrInit() );
  71. if ( FAILED( hr ) )
  72. {
  73. goto Cleanup;
  74. } // if: HrInit() failed
  75. hr = THR( pccni->TypeSafeQI( IUnknown, ppunkOut ) );
  76. if ( FAILED( hr ) )
  77. {
  78. goto Cleanup;
  79. } // if: QI failed
  80. Cleanup:
  81. if ( FAILED( hr ) )
  82. {
  83. LogMsg( L"[SRV] CClusCfgNetworkInfo::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  84. } // if:
  85. if ( pccni != NULL )
  86. {
  87. pccni->Release();
  88. } // if:
  89. HRETURN( hr );
  90. } //*** CClusCfgNetworkInfo::S_HrCreateInstance
  91. //////////////////////////////////////////////////////////////////////////////
  92. //++
  93. //
  94. // CClusCfgNetworkInfo::S_HrCreateInstance
  95. //
  96. // Description:
  97. // Create a CClusCfgNetworkInfo instance.
  98. //
  99. // Arguments:
  100. //
  101. //
  102. // Return Values:
  103. // Pointer to CClusCfgNetworkInfo instance.
  104. //
  105. //--
  106. //////////////////////////////////////////////////////////////////////////////
  107. HRESULT
  108. CClusCfgNetworkInfo::S_HrCreateInstance(
  109. HNETWORK hNetworkIn
  110. , HNETINTERFACE hNetInterfaceIn
  111. , IUnknown * punkCallbackIn
  112. , LCID lcidIn
  113. , IWbemServices * pIWbemServicesIn
  114. , IUnknown ** ppunkOut
  115. )
  116. {
  117. TraceFunc( "" );
  118. Assert( hNetworkIn != NULL );
  119. Assert( ppunkOut != NULL );
  120. HRESULT hr = S_OK;
  121. CClusCfgNetworkInfo * pccni = NULL;
  122. if ( ppunkOut == NULL )
  123. {
  124. hr = THR( E_POINTER );
  125. goto Cleanup;
  126. } // if:
  127. LogMsg( L"[SRV] Creating NetworkInfo object from a cluster network." );
  128. pccni = new CClusCfgNetworkInfo();
  129. if ( pccni == NULL )
  130. {
  131. hr = THR( E_OUTOFMEMORY );
  132. goto Cleanup;
  133. } // if: error allocating object
  134. hr = THR( pccni->Initialize( punkCallbackIn, lcidIn ) );
  135. if ( FAILED( hr ) )
  136. {
  137. goto Cleanup;
  138. } // if:
  139. hr = THR( pccni->SetWbemServices( pIWbemServicesIn ) );
  140. if ( FAILED( hr ) )
  141. {
  142. goto Cleanup;
  143. } // if:
  144. hr = THR( pccni->HrInit( hNetworkIn, hNetInterfaceIn ) );
  145. if ( FAILED( hr ) )
  146. {
  147. goto Cleanup;
  148. } // if: HrInit() failed
  149. hr = THR( pccni->TypeSafeQI( IUnknown, ppunkOut ) );
  150. if ( FAILED( hr ) )
  151. {
  152. goto Cleanup;
  153. } // if: QI succeeded
  154. Cleanup:
  155. if ( FAILED( hr ) )
  156. {
  157. LogMsg( L"[SRV] CClusCfgNetworkInfo::S_HrCreateInstance( HRESOURCE ) failed. (hr = %#08x)", hr );
  158. } // if:
  159. if ( pccni != NULL )
  160. {
  161. pccni->Release();
  162. } // if:
  163. HRETURN( hr );
  164. } //*** CClusCfgNetworkInfo::S_HrCreateInstance
  165. //////////////////////////////////////////////////////////////////////////////
  166. //++
  167. //
  168. // CClusCfgNetworkInfo::CClusCfgNetworkInfo
  169. //
  170. // Description:
  171. // Constructor of the CClusCfgNetworkInfo class. This initializes
  172. // the m_cRef variable to 1 instead of 0 to account of possible
  173. // QueryInterface failure in DllGetClassObject.
  174. //
  175. // Arguments:
  176. // None.
  177. //
  178. // Return Value:
  179. // None.
  180. //
  181. // Remarks:
  182. // None.
  183. //
  184. //--
  185. //////////////////////////////////////////////////////////////////////////////
  186. CClusCfgNetworkInfo::CClusCfgNetworkInfo( void )
  187. : m_cRef( 1 )
  188. {
  189. TraceFunc( "" );
  190. // Increment the count of components in memory so the DLL hosting this
  191. // object cannot be unloaded.
  192. InterlockedIncrement( &g_cObjects );
  193. Assert( m_pIWbemServices == NULL );
  194. Assert( m_dwFlags == 0 );
  195. Assert( m_bstrName == NULL );
  196. Assert( m_bstrDescription == NULL );
  197. Assert( m_bstrDeviceID == NULL );
  198. Assert( m_punkAddresses == NULL );
  199. Assert( m_bstrConnectionName == NULL );
  200. Assert( m_picccCallback == NULL );
  201. Assert( !m_fIsClusterNetwork );
  202. TraceFuncExit();
  203. } //*** CClusCfgNetworkInfo::CClusCfgNetworkInfo
  204. //////////////////////////////////////////////////////////////////////////////
  205. //++
  206. //
  207. // CClusCfgNetworkInfo::~CClusCfgNetworkInfo
  208. //
  209. // Description:
  210. // Desstructor of the CClusCfgNetworkInfo class.
  211. //
  212. // Arguments:
  213. // None.
  214. //
  215. // Return Value:
  216. // None.
  217. //
  218. // Remarks:
  219. // None.
  220. //
  221. //--
  222. //////////////////////////////////////////////////////////////////////////////
  223. CClusCfgNetworkInfo::~CClusCfgNetworkInfo( void )
  224. {
  225. TraceFunc( "" );
  226. if ( m_pIWbemServices != NULL )
  227. {
  228. m_pIWbemServices->Release();
  229. } // if:
  230. if ( m_punkAddresses != NULL )
  231. {
  232. m_punkAddresses->Release();
  233. } // if:
  234. if ( m_picccCallback != NULL )
  235. {
  236. m_picccCallback->Release();
  237. } // if:
  238. TraceSysFreeString( m_bstrName );
  239. TraceSysFreeString( m_bstrDescription );
  240. TraceSysFreeString( m_bstrDeviceID );
  241. TraceSysFreeString( m_bstrConnectionName );
  242. // There's going to be one less component in memory. Decrement component count.
  243. InterlockedDecrement( &g_cObjects );
  244. TraceFuncExit();
  245. } //*** CClusCfgNetworkInfo::~CClusCfgNetworkInfo
  246. //*************************************************************************//
  247. /////////////////////////////////////////////////////////////////////////////
  248. // CClusCfgNetworkInfo -- IUknkown interface.
  249. /////////////////////////////////////////////////////////////////////////////
  250. //////////////////////////////////////////////////////////////////////////////
  251. //++
  252. //
  253. // CClusCfgNetworkInfo::AddRef
  254. //
  255. // Description:
  256. // Increment the reference count of this object by one.
  257. //
  258. // Arguments:
  259. // None.
  260. //
  261. // Return Value:
  262. // The new reference count.
  263. //
  264. // Remarks:
  265. // None.
  266. //
  267. //--
  268. //////////////////////////////////////////////////////////////////////////////
  269. STDMETHODIMP_( ULONG )
  270. CClusCfgNetworkInfo::AddRef( void )
  271. {
  272. TraceFunc( "[IUnknown]" );
  273. InterlockedIncrement( & m_cRef );
  274. CRETURN( m_cRef );
  275. } //*** CClusCfgNetworkInfo::AddRef
  276. //////////////////////////////////////////////////////////////////////////////
  277. //++
  278. //
  279. // CClusCfgNetworkInfo::Release
  280. //
  281. // Description:
  282. // Decrement the reference count of this object by one.
  283. //
  284. // Arguments:
  285. // None.
  286. //
  287. // Return Value:
  288. // The new reference count.
  289. //
  290. // Remarks:
  291. // None.
  292. //
  293. //--
  294. //////////////////////////////////////////////////////////////////////////////
  295. STDMETHODIMP_( ULONG )
  296. CClusCfgNetworkInfo::Release( void )
  297. {
  298. TraceFunc( "[IUnknown]" );
  299. LONG cRef;
  300. cRef = InterlockedDecrement( &m_cRef );
  301. if ( cRef == 0 )
  302. {
  303. TraceDo( delete this );
  304. } // if: reference count equal to zero
  305. CRETURN( cRef );
  306. } //*** CClusCfgNetworkInfo::Release
  307. //////////////////////////////////////////////////////////////////////////////
  308. //++
  309. //
  310. // CClusCfgNetworkInfo::QueryInterface
  311. //
  312. // Description:
  313. // Query this object for the passed in interface.
  314. //
  315. // Arguments:
  316. // riidIn
  317. // Id of interface requested.
  318. //
  319. // ppvOut
  320. // Pointer to the requested interface.
  321. //
  322. // Return Value:
  323. // S_OK
  324. // If the interface is available on this object.
  325. //
  326. // E_NOINTERFACE
  327. // If the interface is not available.
  328. //
  329. // E_POINTER
  330. // ppvOut was NULL.
  331. //
  332. // Remarks:
  333. // None.
  334. //
  335. //--
  336. //////////////////////////////////////////////////////////////////////////////
  337. STDMETHODIMP
  338. CClusCfgNetworkInfo::QueryInterface(
  339. REFIID riidIn
  340. , void ** ppvOut
  341. )
  342. {
  343. TraceQIFunc( riidIn, ppvOut );
  344. HRESULT hr = S_OK;
  345. //
  346. // Validate arguments.
  347. //
  348. Assert( ppvOut != NULL );
  349. if ( ppvOut == NULL )
  350. {
  351. hr = THR( E_POINTER );
  352. goto Cleanup;
  353. }
  354. //
  355. // Handle known interfaces.
  356. //
  357. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  358. {
  359. *ppvOut = static_cast< IClusCfgNetworkInfo * >( this );
  360. } // if: IUnknown
  361. else if ( IsEqualIID( riidIn, IID_IClusCfgNetworkInfo ) )
  362. {
  363. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgNetworkInfo, this, 0 );
  364. } // else if: IClusCfgNetworkInfo
  365. else if ( IsEqualIID( riidIn, IID_IClusCfgWbemServices ) )
  366. {
  367. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  368. } // else if: IClusCfgWbemServices
  369. else if ( IsEqualIID( riidIn, IID_IClusCfgSetWbemObject ) )
  370. {
  371. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgSetWbemObject, this, 0 );
  372. } // else if: IClusCfgSetWbemObject
  373. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgIPAddresses ) )
  374. {
  375. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgIPAddresses, this, 0 );
  376. } // else if: IEnumClusCfgIPAddresses
  377. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  378. {
  379. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  380. } // else if: IClusCfgInitialize
  381. else if ( IsEqualIID( riidIn, IID_IClusCfgClusterNetworkInfo ) )
  382. {
  383. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgClusterNetworkInfo, this, 0 );
  384. } // else if: IClusCfgClusterNetworkInfo
  385. else
  386. {
  387. *ppvOut = NULL;
  388. hr = E_NOINTERFACE;
  389. }
  390. //
  391. // Add a reference to the interface if successful.
  392. //
  393. if ( SUCCEEDED( hr ) )
  394. {
  395. ((IUnknown *) *ppvOut)->AddRef();
  396. } // if: success
  397. Cleanup:
  398. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  399. } //*** CClusCfgNetworkInfo::QueryInterface
  400. //*************************************************************************//
  401. /////////////////////////////////////////////////////////////////////////////
  402. // CPhysicalDisk -- IClusCfgWbemServices interface.
  403. /////////////////////////////////////////////////////////////////////////////
  404. //////////////////////////////////////////////////////////////////////////////
  405. //++
  406. //
  407. // CClusCfgNetworkInfo::SetWbemServices
  408. //
  409. // Description:
  410. // Set the WBEM services provider.
  411. //
  412. // Arguments:
  413. // IN IWbemServices pIWbemServicesIn
  414. //
  415. // Return Value:
  416. // S_OK
  417. // Success
  418. //
  419. // E_POINTER
  420. // The pIWbemServicesIn param is NULL.
  421. //
  422. // Remarks:
  423. // None.
  424. //
  425. //--
  426. //////////////////////////////////////////////////////////////////////////////
  427. STDMETHODIMP
  428. CClusCfgNetworkInfo::SetWbemServices( IWbemServices * pIWbemServicesIn )
  429. {
  430. TraceFunc( "[IClusCfgWbemServices]" );
  431. HRESULT hr = S_OK;
  432. if ( pIWbemServicesIn == NULL )
  433. {
  434. hr = THR( E_POINTER );
  435. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Network, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  436. goto Cleanup;
  437. } // if:
  438. m_pIWbemServices = pIWbemServicesIn;
  439. m_pIWbemServices->AddRef();
  440. Cleanup:
  441. HRETURN( hr );
  442. } //*** CClusCfgNetworkInfo::SetWbemServices
  443. //*************************************************************************//
  444. /////////////////////////////////////////////////////////////////////////////
  445. // CClusCfgNetworkInfo -- IClusCfgInitialize interface.
  446. /////////////////////////////////////////////////////////////////////////////
  447. //////////////////////////////////////////////////////////////////////////////
  448. //++
  449. //
  450. // CClusCfgNetworkInfo::Initialize
  451. //
  452. // Description:
  453. // Initialize this component.
  454. //
  455. // Arguments:
  456. // IN IUknown * punkCallbackIn
  457. //
  458. // IN LCID lcidIn
  459. //
  460. // Return Value:
  461. // S_OK
  462. // Success
  463. //
  464. // Remarks:
  465. // None.
  466. //
  467. //--
  468. //////////////////////////////////////////////////////////////////////////////
  469. STDMETHODIMP
  470. CClusCfgNetworkInfo::Initialize(
  471. IUnknown * punkCallbackIn,
  472. LCID lcidIn
  473. )
  474. {
  475. TraceFunc( "[IClusCfgInitialize]" );
  476. Assert( m_picccCallback == NULL );
  477. HRESULT hr = S_OK;
  478. m_lcid = lcidIn;
  479. if ( punkCallbackIn == NULL )
  480. {
  481. hr = THR( E_POINTER );
  482. goto Cleanup;
  483. } // if:
  484. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  485. Cleanup:
  486. HRETURN( hr );
  487. } //*** CClusCfgNetworkInfo::Initialize
  488. //*************************************************************************//
  489. /////////////////////////////////////////////////////////////////////////////
  490. // CClusCfgNetworkInfo -- IClusCfgSetWbemObject interface.
  491. /////////////////////////////////////////////////////////////////////////////
  492. //////////////////////////////////////////////////////////////////////////////
  493. //++
  494. //
  495. // CClusCfgNetworkInfo::SetWbemObject
  496. //
  497. // Description:
  498. //
  499. // Arguments:
  500. //
  501. // Return Value:
  502. //
  503. // Remarks:
  504. // None.
  505. //
  506. //--
  507. //////////////////////////////////////////////////////////////////////////////
  508. STDMETHODIMP
  509. CClusCfgNetworkInfo::SetWbemObject(
  510. IWbemClassObject * pNetworkAdapterIn
  511. , bool * pfRetainObjectOut
  512. )
  513. {
  514. TraceFunc( "[IClusCfgSetWbemObject]" );
  515. Assert( pNetworkAdapterIn != NULL );
  516. Assert( pfRetainObjectOut != NULL );
  517. HRESULT hr = S_OK;
  518. VARIANT var;
  519. VariantInit( &var );
  520. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"Description", VT_BSTR, &var ) );
  521. if ( FAILED( hr ) )
  522. {
  523. goto Cleanup;
  524. } // if:
  525. m_bstrDescription = TraceSysAllocString( var.bstrVal );
  526. if ( m_bstrDescription == NULL )
  527. {
  528. goto OutOfMemory;
  529. } // if:
  530. VariantClear( &var );
  531. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"Name", VT_BSTR, &var ) );
  532. if ( FAILED( hr ) )
  533. {
  534. goto Cleanup;
  535. } // if:
  536. m_bstrName = TraceSysAllocString( var.bstrVal );
  537. if ( m_bstrName == NULL )
  538. {
  539. goto OutOfMemory;
  540. } // if:
  541. VariantClear( &var );
  542. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"DeviceID", VT_BSTR, &var ) );
  543. if ( FAILED( hr ) )
  544. {
  545. goto Cleanup;
  546. } // if:
  547. m_bstrDeviceID = TraceSysAllocString( var.bstrVal );
  548. if ( m_bstrDeviceID == NULL )
  549. {
  550. goto OutOfMemory;
  551. } // if:
  552. VariantClear( &var );
  553. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"NetConnectionID", VT_BSTR, &var ) );
  554. if ( FAILED( hr ) )
  555. {
  556. goto Cleanup;
  557. } // if:
  558. m_bstrConnectionName = TraceSysAllocString( var.bstrVal );
  559. if ( m_bstrConnectionName == NULL )
  560. {
  561. goto OutOfMemory;
  562. } // if:
  563. hr = STHR( HrLoadEnum( pNetworkAdapterIn, pfRetainObjectOut ) );
  564. if ( FAILED( hr ) )
  565. {
  566. goto Cleanup;
  567. } // if:
  568. goto Cleanup;
  569. OutOfMemory:
  570. hr = THR( E_OUTOFMEMORY );
  571. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemObject_Network, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  572. Cleanup:
  573. LOG_STATUS_REPORT_STRING( L"Created network adapter '%1!ws!'", ( m_bstrConnectionName != NULL ) ? m_bstrConnectionName : L"<Unknown>", hr );
  574. VariantClear( &var );
  575. HRETURN( hr );
  576. } //*** CClusCfgNetworkInfo::SetWbemObject
  577. //*************************************************************************//
  578. /////////////////////////////////////////////////////////////////////////////
  579. // CClusCfgNetworkInfo -- IClusCfgNetworkInfo interface.
  580. /////////////////////////////////////////////////////////////////////////////
  581. //////////////////////////////////////////////////////////////////////////////
  582. //++
  583. //
  584. // CClusCfgNetworkInfo::GetUID
  585. //
  586. // Description:
  587. //
  588. // Arguments:
  589. //
  590. // Return Value:
  591. //
  592. // Remarks:
  593. // None.
  594. //
  595. //--
  596. //////////////////////////////////////////////////////////////////////////////
  597. STDMETHODIMP
  598. CClusCfgNetworkInfo::GetUID(
  599. BSTR * pbstrUIDOut
  600. )
  601. {
  602. TraceFunc( "[IClusCfgNetworkInfo]" );
  603. Assert( m_punkAddresses != NULL );
  604. HRESULT hr;
  605. IClusCfgIPAddressInfo * piccipi = NULL;
  606. if ( pbstrUIDOut == NULL )
  607. {
  608. hr = THR( E_POINTER );
  609. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetUID, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  610. goto Cleanup;
  611. } // if:
  612. hr = STHR( GetPrimaryNetworkAddress( &piccipi ) );
  613. if ( FAILED( hr ) )
  614. {
  615. goto Cleanup;
  616. } // if:
  617. //
  618. // When there is not a primary network address, we goto cleanup
  619. //
  620. if ( ( piccipi == NULL ) && ( hr == S_FALSE ) )
  621. {
  622. goto Cleanup;
  623. } // if:
  624. hr = THR( piccipi->GetUID( pbstrUIDOut ) );
  625. Cleanup:
  626. if ( piccipi != NULL )
  627. {
  628. piccipi->Release();
  629. } // if:
  630. HRETURN( hr );
  631. } //*** CClusCfgNetworkInfo::GetUID
  632. //////////////////////////////////////////////////////////////////////////////
  633. //++
  634. //
  635. // CClusCfgNetworkInfo::GetName
  636. //
  637. // Description:
  638. //
  639. // Arguments:
  640. //
  641. // Return Value:
  642. //
  643. // Remarks:
  644. // None.
  645. //
  646. //--
  647. //////////////////////////////////////////////////////////////////////////////
  648. STDMETHODIMP
  649. CClusCfgNetworkInfo::GetName( BSTR * pbstrNameOut )
  650. {
  651. TraceFunc( "[IClusCfgNetworkInfo]" );
  652. Assert( m_bstrConnectionName != NULL );
  653. HRESULT hr = S_OK;
  654. if ( pbstrNameOut == NULL )
  655. {
  656. hr = THR( E_POINTER );
  657. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_NetworkInfo_GetName_Pointer, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  658. goto Cleanup;
  659. } // if:
  660. *pbstrNameOut = SysAllocString( m_bstrConnectionName );
  661. if ( *pbstrNameOut == NULL )
  662. {
  663. hr = THR( E_OUTOFMEMORY );
  664. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetName_Memory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  665. } // if:
  666. Cleanup:
  667. HRETURN( hr );
  668. } //*** CClusCfgNetworkInfo::GetName
  669. //////////////////////////////////////////////////////////////////////////////
  670. //++
  671. //
  672. // CClusCfgNetworkInfo::SetName
  673. //
  674. // Description:
  675. //
  676. // Arguments:
  677. //
  678. // Return Value:
  679. //
  680. // Remarks:
  681. // None.
  682. //
  683. //--
  684. //////////////////////////////////////////////////////////////////////////////
  685. STDMETHODIMP
  686. CClusCfgNetworkInfo::SetName( LPCWSTR pcszNameIn )
  687. {
  688. TraceFunc1( "[IClusCfgNetworkInfo] pcszNameIn = '%ls'", pcszNameIn == NULL ? L"<null>" : pcszNameIn );
  689. HRESULT hr = S_FALSE;
  690. HRETURN( hr );
  691. } //*** CClusCfgNetworkInfo::SetName
  692. //////////////////////////////////////////////////////////////////////////////
  693. //++
  694. //
  695. // CClusCfgNetworkInfo::GetDescription
  696. //
  697. // Description:
  698. //
  699. // Arguments:
  700. //
  701. // Return Value:
  702. //
  703. // Remarks:
  704. // None.
  705. //
  706. //--
  707. //////////////////////////////////////////////////////////////////////////////
  708. STDMETHODIMP
  709. CClusCfgNetworkInfo::GetDescription( BSTR * pbstrDescriptionOut )
  710. {
  711. TraceFunc( "[IClusCfgNetworkInfo]" );
  712. Assert( m_bstrDescription != NULL );
  713. HRESULT hr = S_OK;
  714. if ( pbstrDescriptionOut == NULL )
  715. {
  716. hr = THR( E_POINTER );
  717. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_NetworkInfo_GetDescription_Pointer, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  718. goto Cleanup;
  719. } // if:
  720. *pbstrDescriptionOut = SysAllocString( m_bstrDescription );
  721. if ( *pbstrDescriptionOut == NULL )
  722. {
  723. hr = THR( E_OUTOFMEMORY );
  724. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_NetworkInfo_GetDescription_Memory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  725. } // if:
  726. Cleanup:
  727. HRETURN( hr );
  728. } //*** CClusCfgNetworkInfo::GetDescription
  729. //////////////////////////////////////////////////////////////////////////////
  730. //++
  731. //
  732. // CClusCfgNetworkInfo::SetDescription
  733. //
  734. // Description:
  735. //
  736. // Arguments:
  737. //
  738. // Return Value:
  739. //
  740. // Remarks:
  741. // None.
  742. //
  743. //--
  744. //////////////////////////////////////////////////////////////////////////////
  745. STDMETHODIMP
  746. CClusCfgNetworkInfo::SetDescription( LPCWSTR pcszDescriptionIn )
  747. {
  748. TraceFunc1( "[IClusCfgNetworkInfo] pcszDescriptionIn = '%ls'", pcszDescriptionIn == NULL ? L"<null>" : pcszDescriptionIn );
  749. HRESULT hr = S_FALSE;
  750. HRETURN( hr );
  751. } //*** CClusCfgNetworkInfo::SetDescription
  752. //////////////////////////////////////////////////////////////////////////////
  753. //++
  754. //
  755. // CClusCfgNetworkInfo::GetPrimaryNetworkAddress
  756. //
  757. // Description:
  758. //
  759. // Arguments:
  760. //
  761. // Return Value:
  762. //
  763. // Remarks:
  764. // None.
  765. //
  766. //--
  767. //////////////////////////////////////////////////////////////////////////////
  768. STDMETHODIMP
  769. CClusCfgNetworkInfo::GetPrimaryNetworkAddress(
  770. IClusCfgIPAddressInfo ** ppIPAddressOut
  771. )
  772. {
  773. TraceFunc( "[IClusCfgNetworkInfo]" );
  774. Assert( m_punkAddresses != NULL );
  775. HRESULT hr;
  776. ULONG cFetched;
  777. hr = STHR( HrGetPrimaryNetworkAddress( ppIPAddressOut, &cFetched ) );
  778. if ( FAILED( hr ) )
  779. {
  780. goto Cleanup;
  781. } // if:
  782. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  783. {
  784. STATUS_REPORT_STRING_REF(
  785. TASKID_Major_Find_Devices
  786. , TASKID_Minor_Primary_IP_Address
  787. , IDS_ERROR_PRIMARY_IP_NOT_FOUND
  788. , m_bstrConnectionName
  789. , IDS_ERROR_PRIMARY_IP_NOT_FOUND_REF
  790. , hr
  791. );
  792. } // if:
  793. Cleanup:
  794. HRETURN( hr );
  795. } //*** CClusCfgNetworkInfo::GetPrimaryNetworkAddress
  796. //////////////////////////////////////////////////////////////////////////////
  797. //++
  798. //
  799. // CClusCfgNetworkInfo::SetPrimaryNetworkAddress
  800. //
  801. // Description:
  802. //
  803. // Arguments:
  804. //
  805. // Return Value:
  806. //
  807. // Remarks:
  808. // None.
  809. //
  810. //--
  811. //////////////////////////////////////////////////////////////////////////////
  812. STDMETHODIMP
  813. CClusCfgNetworkInfo::SetPrimaryNetworkAddress(
  814. IClusCfgIPAddressInfo * pIPAddressIn
  815. )
  816. {
  817. TraceFunc( "[IClusCfgNetworkInfo]" );
  818. HRESULT hr = THR( E_NOTIMPL );
  819. HRETURN( hr );
  820. } //*** CClusCfgNetworkInfo::SetPrimaryNetworkAddress
  821. //////////////////////////////////////////////////////////////////////////////
  822. //++
  823. //
  824. // CClusCfgNetworkInfo::IsPublic
  825. //
  826. // Description:
  827. //
  828. // Arguments:
  829. //
  830. // Return Value:
  831. // S_OK
  832. // The network is public -- client traffic only.
  833. //
  834. // S_FALSE
  835. // The network is not public -- has cluster and client traffic.
  836. //
  837. // Win32 error as HRESULT when an error occurs.
  838. //
  839. // Remarks:
  840. // None.
  841. //
  842. //--
  843. //////////////////////////////////////////////////////////////////////////////
  844. STDMETHODIMP
  845. CClusCfgNetworkInfo::IsPublic( void )
  846. {
  847. TraceFunc( "[IClusCfgNetworkInfo]" );
  848. HRESULT hr = S_FALSE;
  849. if ( m_dwFlags & eIsPublic )
  850. {
  851. hr = S_OK;
  852. } // if:
  853. HRETURN( hr );
  854. } //*** CClusCfgNetworkInfo::IsPublic
  855. //////////////////////////////////////////////////////////////////////////////
  856. //++
  857. //
  858. // CClusCfgNetworkInfo::SetPublic
  859. //
  860. // Description:
  861. //
  862. // Arguments:
  863. //
  864. // Return Value:
  865. //
  866. // Remarks:
  867. // None.
  868. //
  869. //--
  870. //////////////////////////////////////////////////////////////////////////////
  871. STDMETHODIMP
  872. CClusCfgNetworkInfo::SetPublic( BOOL fIsPublicIn )
  873. {
  874. TraceFunc( "[IClusCfgNetworkInfo]" );
  875. HRESULT hr = S_OK;
  876. if ( fIsPublicIn )
  877. {
  878. m_dwFlags |= eIsPublic;
  879. } // if:
  880. else
  881. {
  882. m_dwFlags &= ~eIsPublic;
  883. } // else:
  884. HRETURN( hr );
  885. } //*** CClusCfgNetworkInfo::SetPublic
  886. //////////////////////////////////////////////////////////////////////////////
  887. //++
  888. //
  889. // CClusCfgNetworkInfo::IsPrivate
  890. //
  891. // Description:
  892. //
  893. // Arguments:
  894. //
  895. // Return Value:
  896. // S_OK
  897. // The network is private -- no client traffic.
  898. //
  899. // S_FALSE
  900. // The network is not private -- has client traffic.
  901. //
  902. // Win32 error as HRESULT when an error occurs.
  903. //
  904. // Remarks:
  905. // None.
  906. //
  907. //--
  908. //////////////////////////////////////////////////////////////////////////////
  909. STDMETHODIMP
  910. CClusCfgNetworkInfo::IsPrivate( void )
  911. {
  912. TraceFunc( "[IClusCfgNetworkInfo]" );
  913. HRESULT hr = S_FALSE;
  914. if ( m_dwFlags & eIsPrivate )
  915. {
  916. hr = S_OK;
  917. } // if:
  918. HRETURN( hr );
  919. } //*** CClusCfgNetworkInfo::IsPrivate
  920. //////////////////////////////////////////////////////////////////////////////
  921. //++
  922. //
  923. // CClusCfgNetworkInfo::SetPrivate
  924. //
  925. // Description:
  926. //
  927. // Arguments:
  928. //
  929. // Return Value:
  930. //
  931. // Remarks:
  932. // None.
  933. //
  934. //--
  935. //////////////////////////////////////////////////////////////////////////////
  936. STDMETHODIMP
  937. CClusCfgNetworkInfo::SetPrivate( BOOL fIsPrivateIn )
  938. {
  939. TraceFunc( "[IClusCfgNetworkInfo]" );
  940. HRESULT hr = S_OK;
  941. if ( fIsPrivateIn )
  942. {
  943. m_dwFlags |= eIsPrivate;
  944. } // if:
  945. else
  946. {
  947. m_dwFlags &= ~eIsPrivate;
  948. } // else:
  949. HRETURN( hr );
  950. } //*** CClusCfgNetworkInfo::SetPrivate
  951. //*************************************************************************//
  952. /////////////////////////////////////////////////////////////////////////////
  953. // CClusCfgNetworkInfo -- IEnumClusCfgIPAddresses interface.
  954. /////////////////////////////////////////////////////////////////////////////
  955. //////////////////////////////////////////////////////////////////////////////
  956. //++
  957. //
  958. // CClusCfgNetworkInfo::Next
  959. //
  960. // Description:
  961. //
  962. // Arguments:
  963. //
  964. // Return Value:
  965. //
  966. // Remarks:
  967. // None.
  968. //
  969. //--
  970. //////////////////////////////////////////////////////////////////////////////
  971. STDMETHODIMP
  972. CClusCfgNetworkInfo::Next(
  973. ULONG cNumberRequestedIn,
  974. IClusCfgIPAddressInfo ** rgpIPAddresseInfoOut,
  975. ULONG * pcNumberFetchedOut
  976. )
  977. {
  978. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  979. Assert( m_punkAddresses != NULL );
  980. HRESULT hr;
  981. IEnumClusCfgIPAddresses * pccipa;
  982. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pccipa ) );
  983. if ( SUCCEEDED( hr ) )
  984. {
  985. hr = STHR( pccipa->Next( cNumberRequestedIn, rgpIPAddresseInfoOut, pcNumberFetchedOut ) );
  986. pccipa->Release();
  987. } // if:
  988. HRETURN( hr );
  989. } //*** CClusCfgNetworkInfo::Next
  990. //////////////////////////////////////////////////////////////////////////////
  991. //++
  992. //
  993. // CClusCfgNetworkInfo::Skip
  994. //
  995. // Description:
  996. //
  997. // Arguments:
  998. //
  999. // Return Value:
  1000. //
  1001. // Remarks:
  1002. // None.
  1003. //
  1004. //--
  1005. //////////////////////////////////////////////////////////////////////////////
  1006. STDMETHODIMP
  1007. CClusCfgNetworkInfo::Skip( ULONG cNumberToSkipIn )
  1008. {
  1009. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  1010. Assert( m_punkAddresses != NULL );
  1011. HRESULT hr;
  1012. IEnumClusCfgIPAddresses * pccipa;
  1013. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pccipa ) );
  1014. if ( SUCCEEDED( hr ) )
  1015. {
  1016. hr = THR( pccipa->Skip( cNumberToSkipIn ) );
  1017. pccipa->Release();
  1018. } // if:
  1019. HRETURN( hr );
  1020. } //*** CClusCfgNetworkInfo::Skip
  1021. //////////////////////////////////////////////////////////////////////////////
  1022. //++
  1023. //
  1024. // CClusCfgNetworkInfo::Reset
  1025. //
  1026. // Description:
  1027. //
  1028. // Arguments:
  1029. //
  1030. // Return Value:
  1031. //
  1032. // Remarks:
  1033. // None.
  1034. //
  1035. //--
  1036. //////////////////////////////////////////////////////////////////////////////
  1037. STDMETHODIMP
  1038. CClusCfgNetworkInfo::Reset( void )
  1039. {
  1040. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  1041. Assert( m_punkAddresses != NULL );
  1042. HRESULT hr;
  1043. IEnumClusCfgIPAddresses * pccipa;
  1044. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pccipa ) );
  1045. if ( SUCCEEDED( hr ) )
  1046. {
  1047. hr = THR( pccipa->Reset() );
  1048. pccipa->Release();
  1049. } // if:
  1050. HRETURN( hr );
  1051. } //*** CClusCfgNetworkInfo::Reset
  1052. //////////////////////////////////////////////////////////////////////////////
  1053. //++
  1054. //
  1055. // CClusCfgNetworkInfo::Clone
  1056. //
  1057. // Description:
  1058. //
  1059. // Arguments:
  1060. //
  1061. // Return Value:
  1062. //
  1063. // Remarks:
  1064. // None.
  1065. //
  1066. //--
  1067. //////////////////////////////////////////////////////////////////////////////
  1068. STDMETHODIMP
  1069. CClusCfgNetworkInfo::Clone(
  1070. IEnumClusCfgIPAddresses ** ppEnumClusCfgIPAddressesOut
  1071. )
  1072. {
  1073. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  1074. Assert( m_punkAddresses != NULL );
  1075. HRESULT hr;
  1076. IEnumClusCfgIPAddresses * pccipa;
  1077. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pccipa ) );
  1078. if ( SUCCEEDED( hr ) )
  1079. {
  1080. hr = THR( pccipa->Clone( ppEnumClusCfgIPAddressesOut ) );
  1081. pccipa->Release();
  1082. } // if:
  1083. HRETURN( hr );
  1084. } //*** CClusCfgNetworkInfo::Clone
  1085. //////////////////////////////////////////////////////////////////////////////
  1086. //++
  1087. //
  1088. // CClusCfgNetworkInfo::Count
  1089. //
  1090. // Description:
  1091. //
  1092. // Arguments:
  1093. //
  1094. // Return Value:
  1095. //
  1096. // Remarks:
  1097. // None.
  1098. //
  1099. //--
  1100. //////////////////////////////////////////////////////////////////////////////
  1101. STDMETHODIMP
  1102. CClusCfgNetworkInfo::Count( DWORD * pnCountOut )
  1103. {
  1104. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  1105. Assert( m_punkAddresses != NULL );
  1106. HRESULT hr = S_OK;
  1107. IEnumClusCfgIPAddresses * pccipa = NULL;
  1108. if ( pnCountOut == NULL )
  1109. {
  1110. hr = THR( E_POINTER );
  1111. goto Cleanup;
  1112. } // if:
  1113. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pccipa ) );
  1114. if ( FAILED( hr ) )
  1115. {
  1116. goto Cleanup;
  1117. } // if:
  1118. hr = THR( pccipa->Count( pnCountOut ) );
  1119. Cleanup:
  1120. if ( pccipa != NULL )
  1121. {
  1122. pccipa->Release();
  1123. }
  1124. HRETURN( hr );
  1125. } //** CClusCfgNetworkInfo::Count
  1126. //*************************************************************************//
  1127. /////////////////////////////////////////////////////////////////////////////
  1128. // CClusCfgNetworkInfo class -- IClusCfgClusterNetworkInfo interface.
  1129. /////////////////////////////////////////////////////////////////////////////
  1130. //////////////////////////////////////////////////////////////////////////////
  1131. //++
  1132. //
  1133. // CClusCfgNetworkInfo::HrIsClusterNetwork
  1134. //
  1135. // Description:
  1136. // Is this network already a cluster network.
  1137. //
  1138. // Arguments:
  1139. // None.
  1140. //
  1141. // Return Value:
  1142. // S_OK
  1143. // This network is already a cluster network.
  1144. //
  1145. // S_FALSE
  1146. // This network is not already a cluster network.
  1147. //
  1148. // Remarks:
  1149. // None.
  1150. //
  1151. //--
  1152. //////////////////////////////////////////////////////////////////////////////
  1153. HRESULT
  1154. CClusCfgNetworkInfo::HrIsClusterNetwork( void )
  1155. {
  1156. TraceFunc( "" );
  1157. HRESULT hr = S_FALSE;
  1158. if ( m_fIsClusterNetwork )
  1159. {
  1160. hr = S_OK;
  1161. } // if:
  1162. HRETURN( hr );
  1163. } //*** CClusCfgNetworkInfo::HrIsClusterNetwork
  1164. //////////////////////////////////////////////////////////////////////////////
  1165. //++
  1166. //
  1167. // CClusCfgNetworkInfo::HrGetNetUID
  1168. //
  1169. // Description:
  1170. //
  1171. // Arguments:
  1172. //
  1173. // Return Value:
  1174. //
  1175. // Remarks:
  1176. // None.
  1177. //
  1178. //--
  1179. //////////////////////////////////////////////////////////////////////////////
  1180. HRESULT
  1181. CClusCfgNetworkInfo::HrGetNetUID(
  1182. BSTR * pbstrUIDOut
  1183. , const CLSID * pclsidMajorIdIn
  1184. , LPCWSTR pwszNetworkNameIn
  1185. )
  1186. {
  1187. TraceFunc( "[IClusCfgNetworkInfo]" );
  1188. Assert( m_punkAddresses != NULL );
  1189. Assert( pclsidMajorIdIn != NULL );
  1190. Assert( pwszNetworkNameIn != NULL );
  1191. HRESULT hr;
  1192. IClusCfgIPAddressInfo * piccipi = NULL;
  1193. if ( pbstrUIDOut == NULL )
  1194. {
  1195. hr = THR( E_POINTER );
  1196. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetUID, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  1197. goto Cleanup;
  1198. } // if:
  1199. hr = STHR( HrGetPrimaryNetAddress( &piccipi, pclsidMajorIdIn, pwszNetworkNameIn ) );
  1200. if ( FAILED( hr ) )
  1201. {
  1202. goto Cleanup;
  1203. } // if:
  1204. //
  1205. // When there is not a primary network address, we goto cleanup
  1206. //
  1207. if ( ( piccipi == NULL ) && ( hr == S_FALSE ) )
  1208. {
  1209. goto Cleanup;
  1210. } // if:
  1211. hr = THR( piccipi->GetUID( pbstrUIDOut ) );
  1212. Cleanup:
  1213. if ( piccipi != NULL )
  1214. {
  1215. piccipi->Release();
  1216. } // if:
  1217. HRETURN( hr );
  1218. } //*** CClusCfgNetworkInfo::HrGetNetUID
  1219. //////////////////////////////////////////////////////////////////////////////
  1220. //++
  1221. //
  1222. // CClusCfgNetworkInfo::HrGetPrimaryNetAddress
  1223. //
  1224. // Description:
  1225. //
  1226. // Arguments:
  1227. // pwszNetworkNameIn
  1228. // Need to pass this in because m_bstrConnectionName doesn't reflect
  1229. // the correct connection.
  1230. //
  1231. // Return Value:
  1232. //
  1233. // Remarks:
  1234. // None.
  1235. //
  1236. //--
  1237. //////////////////////////////////////////////////////////////////////////////
  1238. HRESULT
  1239. CClusCfgNetworkInfo::HrGetPrimaryNetAddress(
  1240. IClusCfgIPAddressInfo ** ppIPAddressOut
  1241. , const CLSID * pclsidMajorIdIn
  1242. , LPCWSTR pwszNetworkNameIn
  1243. )
  1244. {
  1245. TraceFunc( "[IClusCfgNetworkInfo]" );
  1246. Assert( m_punkAddresses != NULL );
  1247. Assert( pclsidMajorIdIn != NULL );
  1248. Assert( pwszNetworkNameIn != NULL );
  1249. HRESULT hr;
  1250. ULONG cFetched;
  1251. hr = STHR( HrGetPrimaryNetworkAddress( ppIPAddressOut, &cFetched ) );
  1252. if ( FAILED( hr ) )
  1253. {
  1254. goto Cleanup;
  1255. } // if:
  1256. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  1257. {
  1258. STATUS_REPORT_STRING(
  1259. TASKID_Major_Find_Devices
  1260. , *pclsidMajorIdIn
  1261. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  1262. , pwszNetworkNameIn
  1263. , hr
  1264. );
  1265. STATUS_REPORT_STRING_REF(
  1266. *pclsidMajorIdIn
  1267. , TASKID_Minor_Primary_IP_Address
  1268. , IDS_ERROR_PRIMARY_IP_NOT_FOUND
  1269. , pwszNetworkNameIn
  1270. , IDS_ERROR_PRIMARY_IP_NOT_FOUND_REF
  1271. , hr
  1272. );
  1273. } // if:
  1274. Cleanup:
  1275. HRETURN( hr );
  1276. } //*** CClusCfgNetworkInfo::HrGetPrimaryNetAddress
  1277. //*************************************************************************//
  1278. /////////////////////////////////////////////////////////////////////////////
  1279. // CClusCfgNetworkInfo class -- Private Methods.
  1280. /////////////////////////////////////////////////////////////////////////////
  1281. //////////////////////////////////////////////////////////////////////////////
  1282. //++
  1283. //
  1284. // CClusCfgNetworkInfo::HrInit
  1285. //
  1286. // Description:
  1287. // Initialize this component.
  1288. //
  1289. // Arguments:
  1290. // None.
  1291. //
  1292. // Return Value:
  1293. //
  1294. //
  1295. // Remarks:
  1296. // None.
  1297. //
  1298. //--
  1299. //////////////////////////////////////////////////////////////////////////////
  1300. HRESULT
  1301. CClusCfgNetworkInfo::HrInit( void )
  1302. {
  1303. TraceFunc( "" );
  1304. HRESULT hr = S_OK;
  1305. // IUnknown
  1306. Assert( m_cRef == 1 );
  1307. m_dwFlags = ( eIsPrivate | eIsPublic );
  1308. HRETURN( hr );
  1309. } //*** CClusCfgNetworkInfo::HrInit
  1310. //////////////////////////////////////////////////////////////////////////////
  1311. //++
  1312. //
  1313. // CClusCfgNetworkInfo::HrInit
  1314. //
  1315. // Description:
  1316. // Initialize this component.
  1317. //
  1318. // Arguments:
  1319. // hNetworkIn
  1320. // hNetInterfaceIn
  1321. //
  1322. // Return Value:
  1323. //
  1324. //
  1325. // Remarks:
  1326. // None.
  1327. //
  1328. //--
  1329. //////////////////////////////////////////////////////////////////////////////
  1330. HRESULT
  1331. CClusCfgNetworkInfo::HrInit(
  1332. HNETWORK hNetworkIn
  1333. , HNETINTERFACE hNetInterfaceIn
  1334. )
  1335. {
  1336. TraceFunc( "[HNETWORK]" );
  1337. HRESULT hr = S_OK;
  1338. DWORD sc;
  1339. CClusPropList cplNetworkCommon;
  1340. CClusPropList cplNetworkROCommon;
  1341. CClusPropList cplNetInterfaceROCommon;
  1342. CLUSPROP_BUFFER_HELPER cpbh;
  1343. ULONG ulIPAddress;
  1344. ULONG ulSubnetMask;
  1345. // IUnknown
  1346. Assert( m_cRef == 1 );
  1347. //
  1348. // Get the network common read only properties
  1349. //
  1350. sc = TW32( cplNetworkROCommon.ScGetNetworkProperties( hNetworkIn, CLUSCTL_NETWORK_GET_RO_COMMON_PROPERTIES ) );
  1351. if ( sc != ERROR_SUCCESS )
  1352. {
  1353. goto MakeHr;
  1354. } // if:
  1355. //
  1356. // Get the network common properties
  1357. //
  1358. sc = TW32( cplNetworkCommon.ScGetNetworkProperties( hNetworkIn, CLUSCTL_NETWORK_GET_COMMON_PROPERTIES ) );
  1359. if ( sc != ERROR_SUCCESS )
  1360. {
  1361. goto MakeHr;
  1362. } // if:
  1363. //
  1364. // Get the netinterface common read only properties
  1365. //
  1366. sc = TW32( cplNetInterfaceROCommon.ScGetNetInterfaceProperties( hNetInterfaceIn, CLUSCTL_NETINTERFACE_GET_RO_COMMON_PROPERTIES ) );
  1367. if ( sc != ERROR_SUCCESS )
  1368. {
  1369. goto MakeHr;
  1370. } // if:
  1371. //
  1372. // Find the RO property "name" and save it.
  1373. //
  1374. sc = TW32( cplNetworkROCommon.ScMoveToPropertyByName( L"Name" ) );
  1375. if ( sc != ERROR_SUCCESS )
  1376. {
  1377. goto MakeHr;
  1378. } // if:
  1379. cpbh = cplNetworkROCommon.CbhCurrentValue();
  1380. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1381. //
  1382. // If the name is empty tell the user and leave.
  1383. //
  1384. if ( ( cpbh.pStringValue->sz != NULL ) && ( cpbh.pStringValue->sz[ 0 ] != L'\0' ) )
  1385. {
  1386. m_bstrConnectionName = TraceSysAllocString( cpbh.pStringValue->sz );
  1387. if ( m_bstrConnectionName == NULL )
  1388. {
  1389. goto OutOfMemory;
  1390. } // if:
  1391. } // if:
  1392. else
  1393. {
  1394. hr = HRESULT_FROM_WIN32( TW32( ERROR_INVALID_DATA ) );
  1395. LOG_STATUS_REPORT_MINOR(
  1396. TASKID_Minor_HrInit_No_Network_Name
  1397. , L"[SRV] A network name was not found in the common read-only properties."
  1398. , hr
  1399. );
  1400. goto Cleanup;
  1401. } // else:
  1402. //
  1403. // Find the property "description" and save it.
  1404. //
  1405. sc = TW32( cplNetworkCommon.ScMoveToPropertyByName( L"Description" ) );
  1406. if ( sc != ERROR_SUCCESS )
  1407. {
  1408. goto MakeHr;
  1409. } // if:
  1410. cpbh = cplNetworkCommon.CbhCurrentValue();
  1411. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1412. //
  1413. // If the description is empty then alloc a space and continue.
  1414. //
  1415. if ( ( cpbh.pStringValue->sz != NULL ) && ( cpbh.pStringValue->sz[ 0 ] != L'\0' ) )
  1416. {
  1417. m_bstrDescription = TraceSysAllocString( cpbh.pStringValue->sz );
  1418. if ( m_bstrDescription == NULL )
  1419. {
  1420. goto OutOfMemory;
  1421. } // if:
  1422. } // if:
  1423. else
  1424. {
  1425. m_bstrDescription = TraceSysAllocString( L" " );
  1426. if ( m_bstrDescription == NULL )
  1427. {
  1428. goto OutOfMemory;
  1429. } // if:
  1430. } // else:
  1431. //
  1432. // Find the property "role".
  1433. //
  1434. sc = TW32( cplNetworkCommon.ScMoveToPropertyByName( L"Role" ) );
  1435. if ( sc != ERROR_SUCCESS )
  1436. {
  1437. goto MakeHr;
  1438. } // if:
  1439. cpbh = cplNetworkCommon.CbhCurrentValue();
  1440. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_DWORD );
  1441. //
  1442. // Switch on the role value and set the "private" or "public" bits.
  1443. //
  1444. switch ( cpbh.pDwordValue->dw )
  1445. {
  1446. case ClusterNetworkRoleNone :
  1447. m_dwFlags = 0;
  1448. break;
  1449. case ClusterNetworkRoleInternalUse :
  1450. m_dwFlags = eIsPrivate;
  1451. break;
  1452. case ClusterNetworkRoleClientAccess :
  1453. m_dwFlags = eIsPublic;
  1454. break;
  1455. case ClusterNetworkRoleInternalAndClient :
  1456. m_dwFlags = ( eIsPrivate | eIsPublic );
  1457. break;
  1458. //
  1459. // Should never get here!
  1460. //
  1461. default:
  1462. hr = HRESULT_FROM_WIN32( TW32( ERROR_INVALID_DATA ) );
  1463. LOG_STATUS_REPORT_STRING_MINOR2(
  1464. TASKID_Minor_HrInit_Unknown_Network_Role
  1465. , L"[SRV] The Role property on the network '%1!ws!' is set to %d which is unrecognized."
  1466. , m_bstrConnectionName
  1467. , cpbh.pDwordValue->dw
  1468. , hr
  1469. );
  1470. goto Cleanup;
  1471. } // switch:
  1472. //
  1473. // Find the RO property address and save it.
  1474. //
  1475. sc = TW32( cplNetInterfaceROCommon.ScMoveToPropertyByName( L"Address" ) );
  1476. if ( sc != ERROR_SUCCESS )
  1477. {
  1478. goto MakeHr;
  1479. } // if:
  1480. cpbh = cplNetInterfaceROCommon.CbhCurrentValue();
  1481. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1482. sc = TW32( ClRtlTcpipStringToAddress( cpbh.pStringValue->sz, &ulIPAddress ) );
  1483. if ( sc != ERROR_SUCCESS )
  1484. {
  1485. goto MakeHr;
  1486. } // if:
  1487. //
  1488. // Find the RO property AddressMask and save it.
  1489. //
  1490. sc = TW32( cplNetworkROCommon.ScMoveToPropertyByName( L"AddressMask" ) );
  1491. if ( sc != ERROR_SUCCESS )
  1492. {
  1493. goto MakeHr;
  1494. } // if:
  1495. cpbh = cplNetworkROCommon.CbhCurrentValue();
  1496. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1497. sc = TW32( ClRtlTcpipStringToAddress( cpbh.pStringValue->sz, &ulSubnetMask ) );
  1498. if ( sc != ERROR_SUCCESS )
  1499. {
  1500. goto MakeHr;
  1501. } // if:
  1502. hr = THR( HrCreateEnumAndAddIPAddress( ulIPAddress, ulSubnetMask ) );
  1503. if ( FAILED( hr ) )
  1504. {
  1505. goto Cleanup;
  1506. } // if:
  1507. m_fIsClusterNetwork = TRUE;
  1508. goto Cleanup;
  1509. MakeHr:
  1510. hr = HRESULT_FROM_WIN32( sc );
  1511. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrInit_Win32Error, IDS_ERROR_WIN32, IDS_ERROR_WIN32_REF, hr );
  1512. goto Cleanup;
  1513. OutOfMemory:
  1514. hr = THR( E_OUTOFMEMORY );
  1515. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrInit_OutOfMemory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1516. Cleanup:
  1517. HRETURN( hr );
  1518. } //*** CClusCfgNetworkInfo::HrInit( hNetworkIn, hNetInterfaceIn )
  1519. //////////////////////////////////////////////////////////////////////////////
  1520. //++
  1521. //
  1522. // CClusCfgNetworkInfo::HrLoadEnum
  1523. //
  1524. // Description:
  1525. // Load the contained enumerator
  1526. //
  1527. // Arguments:
  1528. // None.
  1529. //
  1530. // Return Value:
  1531. //
  1532. //
  1533. // Remarks:
  1534. // None.
  1535. //
  1536. //--
  1537. //////////////////////////////////////////////////////////////////////////////
  1538. HRESULT
  1539. CClusCfgNetworkInfo::HrLoadEnum(
  1540. IWbemClassObject * pNetworkAdapterIn
  1541. , bool * pfRetainObjectOut
  1542. )
  1543. {
  1544. TraceFunc( "" );
  1545. HRESULT hr;
  1546. IClusCfgSetWbemObject * piccswo = NULL;
  1547. hr = THR( HrCreateEnum() );
  1548. if ( FAILED( hr ) )
  1549. {
  1550. goto Cleanup;
  1551. } // if:
  1552. hr = THR( m_punkAddresses->TypeSafeQI( IClusCfgSetWbemObject, &piccswo ) );
  1553. if ( FAILED( hr ) )
  1554. {
  1555. goto Cleanup;
  1556. } // if:
  1557. hr = STHR( piccswo->SetWbemObject( pNetworkAdapterIn, pfRetainObjectOut ) );
  1558. Cleanup:
  1559. if ( piccswo != NULL )
  1560. {
  1561. piccswo->Release();
  1562. } // if:
  1563. HRETURN( hr );
  1564. } //*** CClusCfgNetworkInfo::HrLoadEnum
  1565. //////////////////////////////////////////////////////////////////////////////
  1566. //++
  1567. //
  1568. // CClusCfgNetworkInfo::HrCreateEnum
  1569. //
  1570. // Description:
  1571. // Create the contained enumerator
  1572. //
  1573. // Arguments:
  1574. // None.
  1575. //
  1576. // Return Value:
  1577. //
  1578. //
  1579. // Remarks:
  1580. // None.
  1581. //
  1582. //--
  1583. //////////////////////////////////////////////////////////////////////////////
  1584. HRESULT
  1585. CClusCfgNetworkInfo::HrCreateEnum( void )
  1586. {
  1587. TraceFunc( "" );
  1588. Assert( m_punkAddresses == NULL );
  1589. HRESULT hr;
  1590. IUnknown * punk = NULL;
  1591. hr = THR( CEnumClusCfgIPAddresses::S_HrCreateInstance( &punk ) );
  1592. if ( FAILED( hr ) )
  1593. {
  1594. goto Cleanup;
  1595. } // if:
  1596. punk = TraceInterface( L"CEnumClusCfgIPAddresses", IUnknown, punk, 1 );
  1597. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1598. if ( FAILED( hr ))
  1599. {
  1600. goto Cleanup;
  1601. } // if:
  1602. hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1603. if ( FAILED( hr ) )
  1604. {
  1605. goto Cleanup;
  1606. } // if:
  1607. m_punkAddresses = punk;
  1608. m_punkAddresses->AddRef();
  1609. Cleanup:
  1610. if ( punk != NULL )
  1611. {
  1612. punk->Release();
  1613. } // if:
  1614. HRETURN( hr );
  1615. } //*** CClusCfgNetworkInfo::HrCreateEnum
  1616. //////////////////////////////////////////////////////////////////////////////
  1617. //++
  1618. //
  1619. // CClusCfgNetworkInfo::HrCreateEnumAndAddIPAddress
  1620. //
  1621. // Description:
  1622. // Add an IPAddress to the contained enumerator.
  1623. //
  1624. // Arguments:
  1625. // None.
  1626. //
  1627. // Return Value:
  1628. //
  1629. //
  1630. // Remarks:
  1631. // None.
  1632. //
  1633. //--
  1634. //////////////////////////////////////////////////////////////////////////////
  1635. HRESULT
  1636. CClusCfgNetworkInfo::HrCreateEnumAndAddIPAddress(
  1637. ULONG ulIPAddressIn
  1638. , ULONG ulSubnetMaskIn
  1639. )
  1640. {
  1641. TraceFunc( "" );
  1642. Assert( m_punkAddresses == NULL );
  1643. HRESULT hr;
  1644. IUnknown * punk = NULL;
  1645. IUnknown * punkCallback = NULL;
  1646. hr = THR( m_picccCallback->TypeSafeQI( IUnknown, &punkCallback ) );
  1647. if ( FAILED( hr ) )
  1648. {
  1649. goto Cleanup;
  1650. } // if:
  1651. //
  1652. // Have to pass the Initialize interface arguments since new objects will
  1653. // be created when this call is made.
  1654. //
  1655. hr = THR( CEnumClusCfgIPAddresses::S_HrCreateInstance( ulIPAddressIn, ulSubnetMaskIn, punkCallback, m_lcid, m_pIWbemServices, &punk ) );
  1656. if ( FAILED( hr ) )
  1657. {
  1658. goto Cleanup;
  1659. } // if:
  1660. punk = TraceInterface( L"CEnumClusCfgIPAddresses", IUnknown, punk, 1 );
  1661. //
  1662. // This is special -- do not initialize this again.
  1663. //
  1664. //hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1665. //if ( FAILED( hr ))
  1666. //{
  1667. // goto Cleanup;
  1668. //} // if:
  1669. //hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1670. //if ( FAILED( hr ) )
  1671. //{
  1672. // goto Cleanup;
  1673. //} // if:
  1674. m_punkAddresses = punk;
  1675. m_punkAddresses->AddRef();
  1676. Cleanup:
  1677. if ( punkCallback != NULL )
  1678. {
  1679. punkCallback->Release();
  1680. } // if:
  1681. if ( punk != NULL )
  1682. {
  1683. punk->Release();
  1684. } // if:
  1685. HRETURN( hr );
  1686. } //*** CClusCfgNetworkInfo::HrCreateEnumAndAddIPAddress
  1687. //////////////////////////////////////////////////////////////////////////////
  1688. //++
  1689. //
  1690. // CClusCfgNetworkInfo::HrGetPrimaryNetworkAddress
  1691. //
  1692. // Description:
  1693. //
  1694. // Arguments:
  1695. //
  1696. // Return Value:
  1697. //
  1698. // Remarks:
  1699. // None.
  1700. //
  1701. //--
  1702. //////////////////////////////////////////////////////////////////////////////
  1703. HRESULT
  1704. CClusCfgNetworkInfo::HrGetPrimaryNetworkAddress(
  1705. IClusCfgIPAddressInfo ** ppIPAddressOut
  1706. , ULONG * pcFetched
  1707. )
  1708. {
  1709. TraceFunc( "[IClusCfgNetworkInfo]" );
  1710. Assert( m_punkAddresses != NULL );
  1711. HRESULT hr;
  1712. IEnumClusCfgIPAddresses * pieccipa = NULL;
  1713. if ( ppIPAddressOut == NULL )
  1714. {
  1715. hr = THR( E_POINTER );
  1716. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetPrimaryNetworkAddress, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  1717. goto Cleanup;
  1718. } // if:
  1719. hr = THR( m_punkAddresses->TypeSafeQI( IEnumClusCfgIPAddresses, &pieccipa ) );
  1720. if ( FAILED( hr ) )
  1721. {
  1722. goto Cleanup;
  1723. } // if:
  1724. hr = THR( pieccipa->Reset() );
  1725. if ( FAILED( hr ) )
  1726. {
  1727. goto Cleanup;
  1728. } // if:
  1729. hr = STHR( pieccipa->Next( 1, ppIPAddressOut, pcFetched ) );
  1730. if ( FAILED( hr ) )
  1731. {
  1732. goto Cleanup;
  1733. } // if:
  1734. Cleanup:
  1735. if ( pieccipa != NULL )
  1736. {
  1737. pieccipa->Release();
  1738. } // if:
  1739. HRETURN( hr );
  1740. } //*** CClusCfgNetworkInfo::HrGetPrimaryNetworkAddress