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.

2458 lines
66 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumClusCfgNetworks.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumClusCfgNetworks
  10. // class.
  11. //
  12. // The class CEnumClusCfgNetworks is the enumeration of cluster
  13. // networks. It implements the IEnumClusCfgNetworks 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 "CEnumClusCfgNetworks.h"
  25. #include "CClusCfgNetworkInfo.h"
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Constant Definitions
  28. //////////////////////////////////////////////////////////////////////////////
  29. DEFINE_THISCLASS( "CEnumClusCfgNetworks" );
  30. //*************************************************************************//
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CEnumClusCfgNetworks class
  33. /////////////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////////
  35. //++
  36. //
  37. // CEnumClusCfgNetworks::S_HrCreateInstance
  38. //
  39. // Description:
  40. // Create a CEnumClusCfgNetworks instance.
  41. //
  42. // Arguments:
  43. // None.
  44. //
  45. // Return Values:
  46. // Pointer to CEnumClusCfgNetworks instance.
  47. //
  48. //--
  49. //////////////////////////////////////////////////////////////////////////////
  50. HRESULT
  51. CEnumClusCfgNetworks::S_HrCreateInstance( IUnknown ** ppunkOut )
  52. {
  53. TraceFunc( "" );
  54. HRESULT hr = S_OK;
  55. CEnumClusCfgNetworks * peccn = NULL;
  56. if ( ppunkOut == NULL )
  57. {
  58. hr = THR( E_POINTER );
  59. goto Cleanup;
  60. } // if:
  61. peccn = new CEnumClusCfgNetworks();
  62. if ( peccn == NULL )
  63. {
  64. hr = THR( E_OUTOFMEMORY );
  65. goto Cleanup;
  66. } // if: error allocating object
  67. hr = THR( peccn->HrInit() );
  68. if ( FAILED( hr ) )
  69. {
  70. goto Cleanup;
  71. } // if: HrInit() failed
  72. hr = THR( peccn->TypeSafeQI( IUnknown, ppunkOut ) );
  73. if ( FAILED( hr ) )
  74. {
  75. goto Cleanup;
  76. } // if: QI failed
  77. Cleanup:
  78. if ( FAILED( hr ) )
  79. {
  80. LogMsg( L"[SRV] CEnumClusCfgNetworks::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  81. } // if:
  82. if ( peccn != NULL )
  83. {
  84. peccn->Release();
  85. } // if:
  86. HRETURN( hr );
  87. } //*** CEnumClusCfgNetworks::S_HrCreateInstance
  88. //////////////////////////////////////////////////////////////////////////////
  89. //++
  90. //
  91. // CEnumClusCfgNetworks::CEnumClusCfgNetworks
  92. //
  93. // Description:
  94. // Constructor of the CEnumClusCfgNetworks class. This initializes
  95. // the m_cRef variable to 1 instead of 0 to account of possible
  96. // QueryInterface failure in DllGetClassObject.
  97. //
  98. // Arguments:
  99. // None.
  100. //
  101. // Return Value:
  102. // None.
  103. //
  104. // Remarks:
  105. // None.
  106. //
  107. //--
  108. //////////////////////////////////////////////////////////////////////////////
  109. CEnumClusCfgNetworks::CEnumClusCfgNetworks( void )
  110. : m_cRef( 1 )
  111. , m_lcid( LOCALE_NEUTRAL )
  112. , m_fLoadedNetworks( false )
  113. {
  114. TraceFunc( "" );
  115. // Increment the count of components in memory so the DLL hosting this
  116. // object cannot be unloaded.
  117. InterlockedIncrement( &g_cObjects );
  118. Assert( m_picccCallback == NULL );
  119. Assert( m_pIWbemServices == NULL );
  120. Assert( m_prgNetworks == NULL );
  121. Assert( m_idxNext == 0 );
  122. Assert( m_idxEnumNext == 0 );
  123. Assert( m_bstrNodeName == NULL );
  124. Assert( m_cNetworks == 0 );
  125. TraceFuncExit();
  126. } //*** CEnumClusCfgNetworks::CEnumClusCfgNetworks
  127. //////////////////////////////////////////////////////////////////////////////
  128. //++
  129. //
  130. // CEnumClusCfgNetworks::~CEnumClusCfgNetworks
  131. //
  132. // Description:
  133. // Desstructor of the CEnumClusCfgNetworks class.
  134. //
  135. // Arguments:
  136. // None.
  137. //
  138. // Return Value:
  139. // None.
  140. //
  141. // Remarks:
  142. // None.
  143. //
  144. //--
  145. //////////////////////////////////////////////////////////////////////////////
  146. CEnumClusCfgNetworks::~CEnumClusCfgNetworks( void )
  147. {
  148. TraceFunc( "" );
  149. ULONG idx;
  150. if ( m_pIWbemServices != NULL )
  151. {
  152. m_pIWbemServices->Release();
  153. } // if:
  154. if ( m_picccCallback != NULL )
  155. {
  156. m_picccCallback->Release();
  157. } // if:
  158. for ( idx = 0; idx < m_idxNext; idx++ )
  159. {
  160. ((*m_prgNetworks)[ idx ])->Release();
  161. } // for:
  162. TraceFree( m_prgNetworks );
  163. TraceSysFreeString( m_bstrNodeName );
  164. // There's going to be one less component in memory. Decrement component count.
  165. InterlockedDecrement( &g_cObjects );
  166. TraceFuncExit();
  167. } //*** CEnumClusCfgNetworks::~CEnumClusCfgNetworks
  168. //*************************************************************************//
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CEnumClusCfgNetworks -- IUknkown interface.
  171. /////////////////////////////////////////////////////////////////////////////
  172. //////////////////////////////////////////////////////////////////////////////
  173. //++
  174. //
  175. // CEnumClusCfgNetworks::AddRef
  176. //
  177. // Description:
  178. // Increment the reference count of this object by one.
  179. //
  180. // Arguments:
  181. // None.
  182. //
  183. // Return Value:
  184. // The new reference count.
  185. //
  186. // Remarks:
  187. // None.
  188. //
  189. //--
  190. //////////////////////////////////////////////////////////////////////////////
  191. STDMETHODIMP_( ULONG )
  192. CEnumClusCfgNetworks::AddRef( void )
  193. {
  194. TraceFunc( "[IUnknown]" );
  195. InterlockedIncrement( &m_cRef );
  196. CRETURN( m_cRef );
  197. } //*** CEnumClusCfgNetworks::AddRef
  198. //////////////////////////////////////////////////////////////////////////////
  199. //++
  200. //
  201. // CEnumClusCfgNetworks::Release
  202. //
  203. // Description:
  204. // Decrement the reference count of this object by one.
  205. //
  206. // Arguments:
  207. // None.
  208. //
  209. // Return Value:
  210. // The new reference count.
  211. //
  212. // Remarks:
  213. // None.
  214. //
  215. //--
  216. //////////////////////////////////////////////////////////////////////////////
  217. STDMETHODIMP_( ULONG )
  218. CEnumClusCfgNetworks::Release( void )
  219. {
  220. TraceFunc( "[IUnknown]" );
  221. LONG cRef;
  222. cRef = InterlockedDecrement( &m_cRef );
  223. if ( cRef == 0 )
  224. {
  225. TraceDo( delete this );
  226. } // if: reference count equal to zero
  227. CRETURN( cRef );
  228. } //*** CEnumClusCfgNetworks::Release
  229. //////////////////////////////////////////////////////////////////////////////
  230. //++
  231. //
  232. // CEnumClusCfgNetworks::QueryInterface
  233. //
  234. // Description:
  235. // Query this object for the passed in interface.
  236. //
  237. // Arguments:
  238. // riidIn
  239. // Id of interface requested.
  240. //
  241. // ppvOut
  242. // Pointer to the requested interface.
  243. //
  244. // Return Value:
  245. // S_OK
  246. // If the interface is available on this object.
  247. //
  248. // E_NOINTERFACE
  249. // If the interface is not available.
  250. //
  251. // E_POINTER
  252. // ppvOut was NULL.
  253. //
  254. // Remarks:
  255. // None.
  256. //
  257. //--
  258. //////////////////////////////////////////////////////////////////////////////
  259. STDMETHODIMP
  260. CEnumClusCfgNetworks::QueryInterface(
  261. REFIID riidIn
  262. , void ** ppvOut
  263. )
  264. {
  265. TraceQIFunc( riidIn, ppvOut );
  266. HRESULT hr = S_OK;
  267. //
  268. // Validate arguments.
  269. //
  270. Assert( ppvOut != NULL );
  271. if ( ppvOut == NULL )
  272. {
  273. hr = THR( E_POINTER );
  274. goto Cleanup;
  275. }
  276. //
  277. // Handle known interfaces.
  278. //
  279. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  280. {
  281. *ppvOut = static_cast< IEnumClusCfgNetworks * >( this );
  282. } // if: IUnknown
  283. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgNetworks ) )
  284. {
  285. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgNetworks, this, 0 );
  286. } // else if: IEnumClusCfgNetworks
  287. else if ( IsEqualIID( riidIn, IID_IClusCfgWbemServices ) )
  288. {
  289. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  290. } // else if: IClusCfgWbemServices
  291. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  292. {
  293. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  294. } // else if: IClusCfgInitialize
  295. else
  296. {
  297. *ppvOut = NULL;
  298. hr = E_NOINTERFACE;
  299. }
  300. //
  301. // Add a reference to the interface if successful.
  302. //
  303. if ( SUCCEEDED( hr ) )
  304. {
  305. ((IUnknown *) *ppvOut)->AddRef();
  306. } // if: success
  307. Cleanup:
  308. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  309. } //*** CEnumClusCfgNetworks::QueryInterface
  310. //*************************************************************************//
  311. /////////////////////////////////////////////////////////////////////////////
  312. // CEnumClusCfgNetworks -- IClusCfgWbemServices interface.
  313. /////////////////////////////////////////////////////////////////////////////
  314. //////////////////////////////////////////////////////////////////////////////
  315. //++
  316. //
  317. // CEnumClusCfgNetworks::SetWbemServices
  318. //
  319. // Description:
  320. // Set the WBEM services provider.
  321. //
  322. // Arguments:
  323. // IN IWbemServices pIWbemServicesIn
  324. //
  325. // Return Value:
  326. // S_OK
  327. // Success
  328. //
  329. // E_POINTER
  330. // The pIWbemServicesIn param is NULL.
  331. //
  332. // Remarks:
  333. // None.
  334. //
  335. //--
  336. //////////////////////////////////////////////////////////////////////////////
  337. STDMETHODIMP
  338. CEnumClusCfgNetworks::SetWbemServices( IWbemServices * pIWbemServicesIn )
  339. {
  340. TraceFunc( "[IClusCfgWbemServices]" );
  341. HRESULT hr = S_OK;
  342. if ( pIWbemServicesIn == NULL )
  343. {
  344. hr = THR( E_POINTER );
  345. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Enum_Networks, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  346. goto Cleanup;
  347. } // if:
  348. m_pIWbemServices = pIWbemServicesIn;
  349. m_pIWbemServices->AddRef();
  350. Cleanup:
  351. HRETURN( hr );
  352. } //*** CEnumClusCfgNetworks::SetWbemServices
  353. //*************************************************************************//
  354. /////////////////////////////////////////////////////////////////////////////
  355. // CEnumClusCfgNetworks -- IClusCfgInitialize interface.
  356. /////////////////////////////////////////////////////////////////////////////
  357. //////////////////////////////////////////////////////////////////////////////
  358. //++
  359. //
  360. // CEnumClusCfgNetworks::Initialize
  361. //
  362. // Description:
  363. // Initialize this component.
  364. //
  365. // Arguments:
  366. // punkCallbackIn
  367. // lcidIn
  368. //
  369. // Return Value:
  370. // S_OK - Success.
  371. // Other HRESULTs.
  372. //
  373. //--
  374. //////////////////////////////////////////////////////////////////////////////
  375. STDMETHODIMP
  376. CEnumClusCfgNetworks::Initialize(
  377. IUnknown * punkCallbackIn
  378. , LCID lcidIn
  379. )
  380. {
  381. TraceFunc( "[IClusCfgInitialize]" );
  382. Assert( m_picccCallback == NULL );
  383. HRESULT hr = S_OK;
  384. m_lcid = lcidIn;
  385. if ( punkCallbackIn == NULL )
  386. {
  387. hr = THR( E_POINTER );
  388. goto Cleanup;
  389. } // if:
  390. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  391. if ( FAILED( hr ) )
  392. {
  393. goto Cleanup;
  394. } // if:
  395. hr = THR( HrGetComputerName(
  396. ComputerNameDnsHostname
  397. , &m_bstrNodeName
  398. , TRUE // fBestEffortIn
  399. ) );
  400. if ( FAILED( hr ) )
  401. {
  402. goto Cleanup;
  403. } // if:
  404. Cleanup:
  405. HRETURN( hr );
  406. } //*** CEnumClusCfgNetworks::Initialize
  407. //*************************************************************************//
  408. /////////////////////////////////////////////////////////////////////////////
  409. // CEnumClusCfgNetworks -- IEnumClusCfgNetworks interface.
  410. /////////////////////////////////////////////////////////////////////////////
  411. //////////////////////////////////////////////////////////////////////////////
  412. //++
  413. //
  414. // CEnumClusCfgNetworks::Next
  415. //
  416. // Description:
  417. //
  418. // Arguments:
  419. //
  420. // Return Value:
  421. //
  422. // Remarks:
  423. // None.
  424. //
  425. //--
  426. //////////////////////////////////////////////////////////////////////////////
  427. STDMETHODIMP
  428. CEnumClusCfgNetworks::Next(
  429. ULONG cNumberRequestedIn,
  430. IClusCfgNetworkInfo ** rgpNetworkInfoOut,
  431. ULONG * pcNumberFetchedOut
  432. )
  433. {
  434. TraceFunc( "[IEnumClusCfgNetworks]" );
  435. HRESULT hr = S_FALSE;
  436. ULONG cFetched = 0;
  437. ULONG idx;
  438. IClusCfgNetworkInfo * pccni;
  439. if ( rgpNetworkInfoOut == NULL )
  440. {
  441. hr = THR( E_POINTER );
  442. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_Networks, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  443. goto Cleanup;
  444. } // if:
  445. if ( m_fLoadedNetworks == FALSE )
  446. {
  447. hr = THR( HrGetNetworks() );
  448. if ( FAILED( hr ) )
  449. {
  450. goto Cleanup;
  451. } // if:
  452. } // if:
  453. Assert( m_prgNetworks != NULL );
  454. Assert( m_idxNext > 0 );
  455. cFetched = min( cNumberRequestedIn, ( m_idxNext - m_idxEnumNext ) );
  456. //
  457. // Copy the interfaces to the caller's array.
  458. //
  459. for ( idx = 0; idx < cFetched; idx++, m_idxEnumNext++ )
  460. {
  461. hr = THR( ((*m_prgNetworks)[ m_idxEnumNext ])->TypeSafeQI( IClusCfgNetworkInfo, &pccni ) );
  462. if ( FAILED( hr ) )
  463. {
  464. break;
  465. } // if:
  466. rgpNetworkInfoOut[ idx ] = pccni;
  467. } // for:
  468. //
  469. // If a failure occured, release all the interfaces copied to the caller's
  470. // array and log the error.
  471. //
  472. if ( FAILED( hr ) )
  473. {
  474. ULONG idxStop = idx;
  475. ULONG idxError = m_idxEnumNext;
  476. m_idxEnumNext -= idx;
  477. for ( idx = 0; idx < idxStop; idx++ )
  478. {
  479. (rgpNetworkInfoOut[ idx ])->Release();
  480. } // for:
  481. cFetched = 0;
  482. LOG_STATUS_REPORT_STRING_MINOR(
  483. TASKID_Minor_Next_Failed
  484. , L"[SRV] Error QI'ing for IClusCfgNetworkInfo on network object at index %d when filling output array."
  485. , idxError
  486. , hr
  487. );
  488. goto Cleanup;
  489. } // if:
  490. if ( cFetched < cNumberRequestedIn )
  491. {
  492. hr = S_FALSE;
  493. } // if:
  494. Cleanup:
  495. if ( pcNumberFetchedOut != NULL )
  496. {
  497. *pcNumberFetchedOut = cFetched;
  498. } // if:
  499. HRETURN( hr );
  500. } //*** CEnumClusCfgNetworks::Next
  501. //////////////////////////////////////////////////////////////////////////////
  502. //++
  503. //
  504. // CEnumClusCfgNetworks::Skip
  505. //
  506. // Description:
  507. //
  508. // Arguments:
  509. //
  510. // Return Value:
  511. //
  512. // Remarks:
  513. // None.
  514. //
  515. //--
  516. //////////////////////////////////////////////////////////////////////////////
  517. STDMETHODIMP
  518. CEnumClusCfgNetworks::Skip( ULONG cNumberToSkipIn )
  519. {
  520. TraceFunc( "[IEnumClusCfgNetworks]" );
  521. HRESULT hr = S_OK;
  522. m_idxEnumNext += cNumberToSkipIn;
  523. if ( m_idxEnumNext >= m_idxNext )
  524. {
  525. m_idxEnumNext = m_idxNext;
  526. hr = STHR( S_FALSE );
  527. } // if:
  528. HRETURN( hr );
  529. } //*** CEnumClusCfgNetworks::Skip
  530. //////////////////////////////////////////////////////////////////////////////
  531. //++
  532. //
  533. // CEnumClusCfgNetworks::Reset
  534. //
  535. // Description:
  536. //
  537. // Arguments:
  538. //
  539. // Return Value:
  540. //
  541. // Remarks:
  542. // None.
  543. //
  544. //--
  545. //////////////////////////////////////////////////////////////////////////////
  546. STDMETHODIMP
  547. CEnumClusCfgNetworks::Reset( void )
  548. {
  549. TraceFunc( "[IEnumClusCfgNetworks]" );
  550. HRESULT hr = S_OK;
  551. m_idxEnumNext = 0;
  552. HRETURN( hr );
  553. } //*** CEnumClusCfgNetworks::Reset
  554. //////////////////////////////////////////////////////////////////////////////
  555. //++
  556. //
  557. // CEnumClusCfgNetworks::Clone
  558. //
  559. // Description:
  560. //
  561. // Arguments:
  562. //
  563. // Return Value:
  564. //
  565. // Remarks:
  566. // None.
  567. //
  568. //--
  569. //////////////////////////////////////////////////////////////////////////////
  570. STDMETHODIMP
  571. CEnumClusCfgNetworks::Clone(
  572. IEnumClusCfgNetworks ** ppEnumNetworksOut
  573. )
  574. {
  575. TraceFunc( "[IEnumClusCfgNetworks]" );
  576. HRESULT hr = S_OK;
  577. if ( ppEnumNetworksOut == NULL )
  578. {
  579. hr = THR( E_POINTER );
  580. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_Networks, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  581. goto Cleanup;
  582. } // if:
  583. hr = THR( E_NOTIMPL );
  584. Cleanup:
  585. HRETURN( hr );
  586. } //*** CEnumClusCfgNetworks::Clone
  587. //////////////////////////////////////////////////////////////////////////////
  588. //++
  589. //
  590. // CEnumClusCfgNetworks::Count
  591. //
  592. // Description:
  593. //
  594. // Arguments:
  595. //
  596. // Return Value:
  597. //
  598. // Remarks:
  599. // None.
  600. //
  601. //--
  602. //////////////////////////////////////////////////////////////////////////////
  603. STDMETHODIMP
  604. CEnumClusCfgNetworks::Count( DWORD * pnCountOut )
  605. {
  606. TraceFunc( "[IEnumClusCfgNetworks]" );
  607. HRESULT hr = S_OK;
  608. if ( pnCountOut == NULL )
  609. {
  610. hr = THR( E_POINTER );
  611. goto Cleanup;
  612. } // if:
  613. if ( !m_fLoadedNetworks )
  614. {
  615. hr = THR( HrGetNetworks() );
  616. if ( FAILED( hr ) )
  617. {
  618. goto Cleanup;
  619. } // if:
  620. } // if:
  621. *pnCountOut = m_cNetworks;
  622. Cleanup:
  623. HRETURN( hr );
  624. } //*** CEnumClusCfgNetworks::Count
  625. //*************************************************************************//
  626. /////////////////////////////////////////////////////////////////////////////
  627. // CEnumClusCfgNetworks class -- Private Methods.
  628. /////////////////////////////////////////////////////////////////////////////
  629. //////////////////////////////////////////////////////////////////////////////
  630. //++
  631. //
  632. // CEnumClusCfgNetworks::HrInit
  633. //
  634. // Description:
  635. // Initialize this component.
  636. //
  637. // Arguments:
  638. // None.
  639. //
  640. // Return Value:
  641. //
  642. //
  643. // Remarks:
  644. // None.
  645. //
  646. //--
  647. //////////////////////////////////////////////////////////////////////////////
  648. HRESULT
  649. CEnumClusCfgNetworks::HrInit( void )
  650. {
  651. TraceFunc( "" );
  652. HRESULT hr = S_OK;
  653. // IUnknown
  654. Assert( m_cRef == 1 );
  655. HRETURN( hr );
  656. } //*** CEnumClusCfgNetworks::HrInit
  657. /////////////////////////////////////////////////////////////////////////////
  658. //++
  659. //
  660. // CEnumClusCfgNetworks::HrGetNetworks
  661. //
  662. // Description:
  663. //
  664. // Arguments:
  665. //
  666. //
  667. // Return Value:
  668. //
  669. //
  670. // Remarks:
  671. // None.
  672. //
  673. //--
  674. //////////////////////////////////////////////////////////////////////////////
  675. HRESULT
  676. CEnumClusCfgNetworks::HrGetNetworks( void )
  677. {
  678. TraceFunc( "" );
  679. HRESULT hr = S_FALSE;
  680. BSTR bstrQuery = NULL;
  681. BSTR bstrAdapterQuery = NULL;
  682. IWbemClassObject * piwcoNetwork = NULL;
  683. IWbemClassObject * pAdapterInfo = NULL;
  684. IEnumWbemClassObject * piewcoNetworks = NULL;
  685. INetConnectionManager * pNetConManager = NULL;
  686. IEnumNetConnection * pEnumNetCon = NULL;
  687. INetConnection * pNetConnection = NULL;
  688. NETCON_PROPERTIES * pProps = NULL;
  689. ULONG cRecordsReturned;
  690. VARIANT varConnectionStatus;
  691. VARIANT varConnectionID;
  692. VARIANT varIndex;
  693. VARIANT varDHCPEnabled;
  694. DWORD sc;
  695. DWORD dwState;
  696. DWORD cNumConnectionsReturned;
  697. HRESULT hrTemp;
  698. CLSID clsidMajorId;
  699. CLSID clsidMinorId;
  700. BSTR bstrWQL = NULL;
  701. bstrWQL = TraceSysAllocString( L"WQL" );
  702. if ( bstrWQL == NULL )
  703. {
  704. hr = THR( E_OUTOFMEMORY );
  705. goto Cleanup;
  706. } // if:
  707. sc = TW32( GetNodeClusterState( NULL, &dwState ) );
  708. if ( sc != ERROR_SUCCESS )
  709. {
  710. hr = HRESULT_FROM_WIN32( sc );
  711. goto Cleanup;
  712. } // if:
  713. if ( dwState == ClusterStateRunning )
  714. {
  715. hr = THR( HrLoadClusterNetworks() );
  716. if ( FAILED( hr ) )
  717. {
  718. goto Cleanup;
  719. } // if:
  720. } // if:
  721. VariantInit( &varConnectionStatus );
  722. VariantInit( &varConnectionID );
  723. VariantInit( &varIndex );
  724. VariantInit( &varDHCPEnabled );
  725. //
  726. // Instantiate a connection manager object to enum the connections
  727. //
  728. hr = THR ( CoCreateInstance(
  729. CLSID_ConnectionManager
  730. , NULL
  731. , CLSCTX_ALL
  732. , IID_INetConnectionManager
  733. , reinterpret_cast< LPVOID * >( &pNetConManager )
  734. )
  735. );
  736. if ( FAILED( hr ) || ( pNetConManager == NULL ) )
  737. {
  738. STATUS_REPORT_REF(
  739. TASKID_Major_Find_Devices
  740. , TASKID_Minor_CoCreate_NetConnection_Manager_Failed
  741. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED
  742. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED_REF
  743. , hr
  744. );
  745. goto Cleanup;
  746. }
  747. //
  748. // Enumerate the network connections
  749. //
  750. hr = THR( pNetConManager->EnumConnections( NCME_DEFAULT, &pEnumNetCon ) );
  751. if ( ( FAILED( hr ) ) || ( pEnumNetCon == NULL ) )
  752. {
  753. STATUS_REPORT_REF(
  754. TASKID_Major_Find_Devices
  755. , TASKID_Minor_Enumerate_Network_Connections_Failed
  756. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED
  757. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED_REF
  758. , hr
  759. );
  760. goto Cleanup;
  761. } // if:
  762. hr = pEnumNetCon->Reset();
  763. if ( FAILED( hr ) )
  764. {
  765. STATUS_REPORT_REF(
  766. TASKID_Major_Find_Devices
  767. , TASKID_Minor_Reset_Network_Connections_Enum_Failed
  768. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED
  769. , IDS_ERROR_ENUM_NETWORK_CONNECTIONS_FAILED_REF
  770. , hr
  771. );
  772. goto Cleanup;
  773. }
  774. //
  775. // Loop through the networks and skip inappropriate networks and form the network array
  776. //
  777. for ( ; ; )
  778. {
  779. //
  780. // There are several "continue"s in this loop, so lets make sure we clean up before we start a new loop
  781. //
  782. if ( pNetConnection != NULL )
  783. {
  784. pNetConnection->Release();
  785. pNetConnection = NULL;
  786. } // if:
  787. if ( piewcoNetworks != NULL )
  788. {
  789. piewcoNetworks->Release();
  790. piewcoNetworks = NULL;
  791. } // if:
  792. if ( piwcoNetwork != NULL )
  793. {
  794. piwcoNetwork->Release();
  795. piwcoNetwork = NULL;
  796. } // if:
  797. if ( pAdapterInfo != NULL )
  798. {
  799. pAdapterInfo->Release();
  800. pAdapterInfo = NULL;
  801. } // if:
  802. //
  803. // Free network connection properties
  804. //
  805. NcFreeNetconProperties( pProps );
  806. pProps = NULL;
  807. hr = STHR( pEnumNetCon->Next( 1, &pNetConnection, &cNumConnectionsReturned ) );
  808. if ( FAILED( hr ) )
  809. {
  810. goto Cleanup;
  811. } // if:
  812. else if ( ( hr == S_FALSE ) && ( cNumConnectionsReturned == 0 ) )
  813. {
  814. hr = S_OK;
  815. break;
  816. } // else if:
  817. Assert( pNetConnection != NULL );
  818. hr = THR( pNetConnection->GetProperties( &pProps ) );
  819. if ( ( FAILED( hr ) ) || ( pProps == NULL ) )
  820. {
  821. goto Cleanup;
  822. } // if:
  823. //
  824. // Create an ID for this particular network connection. We will use this ID later if there are issues with
  825. // this network connection.
  826. //
  827. hrTemp = THR( CoCreateGuid( &clsidMajorId ) );
  828. if ( FAILED( hrTemp ) )
  829. {
  830. LogMsg( L"[SRV] Could not create a guid for a network connection." );
  831. clsidMajorId = IID_NULL;
  832. } // if:
  833. //
  834. // Get the NetworkAdapter WMI object with the specified NetConnectionID
  835. //
  836. hr = HrFormatStringIntoBSTR( L"Select * from Win32_NetworkAdapter where NetConnectionID='%1!ws!'", &bstrQuery, pProps->pszwName );
  837. if ( FAILED( hr ) )
  838. {
  839. goto Cleanup;
  840. } // if:
  841. //
  842. // We are executing a query which we assume will find 1 matching record since NetConnectionID is a unique value
  843. //
  844. hr = THR( m_pIWbemServices->ExecQuery( bstrWQL, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &piewcoNetworks ) );
  845. if ( FAILED( hr ) )
  846. {
  847. STATUS_REPORT_STRING(
  848. TASKID_Major_Find_Devices
  849. , clsidMajorId
  850. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  851. , pProps->pszwName
  852. , hr
  853. );
  854. STATUS_REPORT_STRING_REF(
  855. clsidMajorId
  856. , TASKID_Minor_WMI_NetworkAdapter_Qry_Failed
  857. , IDS_ERROR_WMI_NETWORKADAPTER_QRY_FAILED
  858. , pProps->pszwName
  859. , IDS_ERROR_WMI_NETWORKADAPTER_QRY_FAILED_REF
  860. , hr
  861. );
  862. goto Cleanup;
  863. } // if:
  864. //
  865. // Get the network returned into piwcoNetwork
  866. //
  867. hr = THR( piewcoNetworks->Next( WBEM_INFINITE, 1, &piwcoNetwork, &cRecordsReturned ) );
  868. if ( FAILED( hr ) )
  869. {
  870. STATUS_REPORT_STRING(
  871. TASKID_Major_Find_Devices
  872. , clsidMajorId
  873. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  874. , pProps->pszwName
  875. , hr
  876. );
  877. STATUS_REPORT_STRING_REF(
  878. clsidMajorId
  879. , TASKID_Minor_WQL_Network_Qry_Next_Failed
  880. , IDS_ERROR_WQL_QRY_NEXT_FAILED
  881. , bstrQuery
  882. , IDS_ERROR_WQL_QRY_NEXT_FAILED_REF
  883. , hr
  884. );
  885. goto Cleanup;
  886. } // if:
  887. else if ( hr == S_FALSE )
  888. {
  889. TraceSysFreeString( bstrQuery );
  890. bstrQuery = NULL;
  891. hr = S_OK;
  892. continue;
  893. }
  894. TraceSysFreeString( bstrQuery );
  895. bstrQuery = NULL;
  896. //
  897. // Get the NetConnectionID. Only "real" hardware adapters will have this as a non-NULL property.
  898. //
  899. // TODO: 31-OCT-2001 Ozano & GalenB
  900. //
  901. // Do we really need this piece of code after we start looping using INetConnection
  902. //
  903. hr = HrGetWMIProperty( piwcoNetwork, L"NetConnectionID", VT_BSTR, &varConnectionID );
  904. if ( ( hr == E_PROPTYPEMISMATCH ) && ( varConnectionID.vt == VT_NULL ) )
  905. {
  906. hr = S_OK; // don't want a yellow bang in the UI
  907. STATUS_REPORT_REF(
  908. TASKID_Major_Find_Devices
  909. , TASKID_Minor_Not_Managed_Networks
  910. , IDS_INFO_NOT_MANAGED_NETWORKS
  911. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  912. , hr
  913. );
  914. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  915. if ( FAILED( hrTemp ) )
  916. {
  917. LogMsg( L"[SRV] Could not create a guid for a not connected network minor task ID" );
  918. clsidMinorId = IID_NULL;
  919. } // if:
  920. STATUS_REPORT_STRING_REF(
  921. TASKID_Minor_Not_Managed_Networks
  922. , clsidMinorId
  923. , IDS_WARN_NETWORK_SKIPPED
  924. , pProps->pszwName
  925. , IDS_WARN_NETWORK_SKIPPED_REF
  926. , hr
  927. );
  928. continue; // skip this adapter
  929. } // if:
  930. else if ( FAILED( hr ) )
  931. {
  932. THR( hr );
  933. goto Cleanup;
  934. } // else if:
  935. //
  936. // Check the connection status of this adapter and skip it if it is not connected.
  937. //
  938. hr = THR( HrGetWMIProperty( piwcoNetwork, L"NetConnectionStatus", VT_I4, &varConnectionStatus ) );
  939. if ( FAILED( hr ) )
  940. {
  941. goto Cleanup;
  942. } // if:
  943. //
  944. // If the network adapter is not connected then skip it.
  945. //
  946. if ( varConnectionStatus.iVal != STATUS_CONNECTED )
  947. {
  948. hr = S_OK; // don't want a yellow bang in the UI
  949. STATUS_REPORT_REF(
  950. TASKID_Major_Find_Devices
  951. , TASKID_Minor_Not_Managed_Networks
  952. , IDS_INFO_NOT_MANAGED_NETWORKS
  953. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  954. , hr
  955. );
  956. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  957. if ( FAILED( hrTemp ) )
  958. {
  959. LogMsg( L"[SRV] Could not create a guid for a not connected network minor task ID" );
  960. clsidMinorId = IID_NULL;
  961. } // if:
  962. STATUS_REPORT_STRING2_REF(
  963. TASKID_Minor_Not_Managed_Networks
  964. , clsidMinorId
  965. , IDS_WARN_NETWORK_NOT_CONNECTED
  966. , varConnectionID.bstrVal
  967. , varConnectionStatus.iVal
  968. , IDS_WARN_NETWORK_NOT_CONNECTED_REF
  969. , hr
  970. );
  971. continue;
  972. } // if:
  973. //
  974. // If it is a bridged network connection, display a warning
  975. //
  976. if ( pProps->MediaType == NCM_BRIDGE )
  977. {
  978. // This is the virtual bridged network connection
  979. STATUS_REPORT_STRING(
  980. TASKID_Major_Find_Devices
  981. , clsidMajorId
  982. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  983. , pProps->pszwName
  984. , hr
  985. );
  986. hrTemp = S_FALSE;
  987. STATUS_REPORT_STRING_REF(
  988. clsidMajorId
  989. , TASKID_Minor_Bridged_Network
  990. , IDS_WARN_NETWORK_BRIDGE_ENABLED
  991. , pProps->pszwName
  992. , IDS_WARN_NETWORK_BRIDGE_ENABLED_REF
  993. , hrTemp
  994. );
  995. } // if: ( pProps->MediaType == NCM_BRIDGE )
  996. else if ( ( pProps->dwCharacter & NCCF_BRIDGED ) == NCCF_BRIDGED )
  997. {
  998. // This is one of the end points of a bridged network connection
  999. STATUS_REPORT_STRING(
  1000. TASKID_Major_Find_Devices
  1001. , clsidMajorId
  1002. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  1003. , pProps->pszwName
  1004. , hr
  1005. );
  1006. hrTemp = S_FALSE;
  1007. STATUS_REPORT_STRING_REF(
  1008. clsidMajorId
  1009. , TASKID_Minor_Bridged_Network
  1010. , IDS_WARN_NETWORK_BRIDGE_ENDPOINT
  1011. , pProps->pszwName
  1012. , IDS_WARN_NETWORK_BRIDGE_ENDPOINT_REF
  1013. , hrTemp
  1014. );
  1015. continue; // skip end point connections since they do not have an IP address
  1016. } // else if: ( ( pProps->dwCharacter & NCCF_BRIDGED ) == NCCF_BRIDGED )
  1017. //
  1018. // If it is a firewall enabled network connection, display a warning
  1019. //
  1020. if ( ( pProps->dwCharacter & NCCF_FIREWALLED ) == NCCF_FIREWALLED )
  1021. {
  1022. STATUS_REPORT_STRING(
  1023. TASKID_Major_Find_Devices
  1024. , clsidMajorId
  1025. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  1026. , pProps->pszwName
  1027. , hr
  1028. );
  1029. hrTemp = S_FALSE;
  1030. STATUS_REPORT_STRING_REF(
  1031. clsidMajorId
  1032. , TASKID_Minor_Network_Firewall_Enabled
  1033. , IDS_WARN_NETWORK_FIREWALL_ENABLED
  1034. , pProps->pszwName
  1035. , IDS_WARN_NETWORK_FIREWALL_ENABLED_REF
  1036. , hrTemp
  1037. );
  1038. } // if: ( ( pProps->dwCharacter & NCCF_FIREWALLED ) == NCCF_FIREWALLED )
  1039. //
  1040. // At this stage we should only have real LAN adapters.
  1041. //
  1042. Assert( pProps->MediaType == NCM_LAN );
  1043. //
  1044. // Get the Index No. of this adapter
  1045. //
  1046. hr = THR( HrGetWMIProperty( piwcoNetwork, L"Index", VT_I4, &varIndex ) );
  1047. if ( FAILED( hr ) )
  1048. {
  1049. goto Cleanup;
  1050. } // if:
  1051. //
  1052. // Get the associated NetworkAdapterConfiguration WMI object. First, format the Query string
  1053. //
  1054. hr = HrFormatStringIntoBSTR( L"Win32_NetworkAdapterConfiguration.Index=%1!u!", &bstrAdapterQuery, varIndex.iVal );
  1055. if ( FAILED( hr ) )
  1056. {
  1057. goto Cleanup;
  1058. } // if:
  1059. //
  1060. // Then, get the Object
  1061. //
  1062. hr = THR( m_pIWbemServices->GetObject(
  1063. bstrAdapterQuery
  1064. , WBEM_FLAG_RETURN_WBEM_COMPLETE
  1065. , NULL
  1066. , &pAdapterInfo
  1067. , NULL
  1068. ) );
  1069. if ( FAILED ( hr ) )
  1070. {
  1071. goto Cleanup;
  1072. } // if:
  1073. TraceSysFreeString( bstrAdapterQuery );
  1074. bstrAdapterQuery = NULL;
  1075. //
  1076. // Find out if this adapter is DHCP enabled. If it is, send out a warning.
  1077. //
  1078. hr = THR( HrGetWMIProperty( pAdapterInfo, L"DHCPEnabled", VT_BOOL, &varDHCPEnabled ) );
  1079. if ( FAILED ( hr ) )
  1080. {
  1081. goto Cleanup;
  1082. } // if:
  1083. if ( ( varDHCPEnabled.vt == VT_BOOL ) && ( varDHCPEnabled.boolVal == VARIANT_TRUE ) )
  1084. {
  1085. STATUS_REPORT_STRING(
  1086. TASKID_Major_Find_Devices
  1087. , clsidMajorId
  1088. , IDS_INFO_NETWORK_CONNECTION_CONCERN
  1089. , pProps->pszwName
  1090. , hr
  1091. );
  1092. hr = S_FALSE;
  1093. STATUS_REPORT_STRING_REF(
  1094. clsidMajorId
  1095. , TASKID_Minor_HrGetNetworks_DHCP_Enabled
  1096. , IDS_WARN_DHCP_ENABLED
  1097. , varConnectionID.bstrVal
  1098. , IDS_WARN_DHCP_ENABLED_REF
  1099. , hr
  1100. );
  1101. if ( FAILED ( hr ) )
  1102. {
  1103. goto Cleanup;
  1104. }
  1105. } // if:
  1106. hr = STHR( HrCreateAndAddNetworkToArray( piwcoNetwork, &clsidMajorId, pProps->pszwName ) );
  1107. if ( FAILED( hr ) )
  1108. {
  1109. goto Cleanup;
  1110. } // if:
  1111. } // for:
  1112. //
  1113. // Check for any NLB network adapters and if there is one then send a warning status report.
  1114. //
  1115. hr = THR( HrCheckForNLBS() );
  1116. if ( FAILED( hr ) )
  1117. {
  1118. goto Cleanup;
  1119. } // if:
  1120. m_idxEnumNext = 0;
  1121. m_fLoadedNetworks = TRUE;
  1122. goto Cleanup;
  1123. Cleanup:
  1124. VariantClear( &varConnectionStatus );
  1125. VariantClear( &varConnectionID );
  1126. VariantClear( &varIndex );
  1127. VariantClear( &varDHCPEnabled );
  1128. TraceSysFreeString( bstrWQL );
  1129. TraceSysFreeString( bstrQuery );
  1130. TraceSysFreeString( bstrAdapterQuery );
  1131. NcFreeNetconProperties( pProps );
  1132. if ( piwcoNetwork != NULL )
  1133. {
  1134. piwcoNetwork->Release();
  1135. } // if:
  1136. if ( piewcoNetworks != NULL )
  1137. {
  1138. piewcoNetworks->Release();
  1139. } // if:
  1140. if ( pAdapterInfo != NULL )
  1141. {
  1142. pAdapterInfo->Release();
  1143. } // if:
  1144. if ( pNetConnection != NULL )
  1145. {
  1146. pNetConnection->Release();
  1147. } // if:
  1148. if ( pNetConManager != NULL )
  1149. {
  1150. pNetConManager->Release();
  1151. } // if:
  1152. if ( pEnumNetCon != NULL )
  1153. {
  1154. pEnumNetCon->Release();
  1155. } // if:
  1156. HRETURN( hr );
  1157. } //*** CEnumClusCfgNetworks::HrGetNetworks
  1158. /////////////////////////////////////////////////////////////////////////////
  1159. //++
  1160. //
  1161. // CEnumClusCfgNetworks:HrAddNetworkToArray
  1162. //
  1163. // Description:
  1164. // Add the passed in Network to the array of punks that holds the Networks.
  1165. //
  1166. // Arguments:
  1167. //
  1168. //
  1169. // Return Value:
  1170. // S_OK
  1171. // Success
  1172. //
  1173. // E_OUTOFMEMORY
  1174. // Couldn't allocate memeory.
  1175. //
  1176. // Remarks:
  1177. // None.
  1178. //
  1179. //--
  1180. //////////////////////////////////////////////////////////////////////////////
  1181. HRESULT
  1182. CEnumClusCfgNetworks::HrAddNetworkToArray( IUnknown * punkIn )
  1183. {
  1184. TraceFunc( "" );
  1185. HRESULT hr = S_OK;
  1186. IUnknown * ((*prgpunks)[]) = NULL;
  1187. prgpunks = (IUnknown *((*)[])) TraceReAlloc( m_prgNetworks, sizeof( IUnknown * ) * ( m_idxNext + 1 ), HEAP_ZERO_MEMORY );
  1188. if ( prgpunks == NULL )
  1189. {
  1190. hr = THR( E_OUTOFMEMORY );
  1191. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrAddNetworkToArray, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1192. goto Cleanup;
  1193. } // if:
  1194. m_prgNetworks = prgpunks;
  1195. (*m_prgNetworks)[ m_idxNext++ ] = punkIn;
  1196. punkIn->AddRef();
  1197. m_cNetworks += 1;
  1198. Cleanup:
  1199. HRETURN( hr );
  1200. } //*** CEnumClusCfgNetworks::HrAddNetworkToArray
  1201. /////////////////////////////////////////////////////////////////////////////
  1202. //++
  1203. //
  1204. // CEnumClusCfgNetworks::HrCreateAndAddNetworkToArray
  1205. //
  1206. // Description:
  1207. // Create a IClusCfgStorageDevice object and add the passed in Network to
  1208. // the array of punks that holds the Networks.
  1209. //
  1210. // Arguments:
  1211. //
  1212. //
  1213. // Return Value:
  1214. // S_OK
  1215. // Success
  1216. //
  1217. // E_OUTOFMEMORY
  1218. // Couldn't allocate memory.
  1219. //
  1220. // Remarks:
  1221. // None.
  1222. //
  1223. //--
  1224. //////////////////////////////////////////////////////////////////////////////
  1225. HRESULT
  1226. CEnumClusCfgNetworks::HrCreateAndAddNetworkToArray(
  1227. IWbemClassObject * pNetworkIn
  1228. , const CLSID * pclsidMajorIdIn
  1229. , LPCWSTR pwszNetworkNameIn
  1230. )
  1231. {
  1232. TraceFunc( "" );
  1233. Assert( pNetworkIn != NULL );
  1234. Assert( pclsidMajorIdIn != NULL );
  1235. Assert( pwszNetworkNameIn != NULL );
  1236. HRESULT hr = S_FALSE;
  1237. IUnknown * punk = NULL;
  1238. IClusCfgSetWbemObject * piccswo = NULL;
  1239. bool fRetainObject = true;
  1240. hr = THR( CClusCfgNetworkInfo::S_HrCreateInstance( &punk ) );
  1241. if ( FAILED( hr ) )
  1242. {
  1243. goto Cleanup;
  1244. } // if:
  1245. punk = TraceInterface( L"CClusCfgNetworkInfo", IUnknown, punk, 1 );
  1246. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1247. if ( FAILED( hr ))
  1248. {
  1249. goto Cleanup;
  1250. } // if:
  1251. hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1252. if ( FAILED( hr ) )
  1253. {
  1254. goto Cleanup;
  1255. } // if:
  1256. hr = THR( punk->TypeSafeQI( IClusCfgSetWbemObject, &piccswo ) );
  1257. if ( FAILED( hr ) )
  1258. {
  1259. goto Cleanup;
  1260. } // if:
  1261. hr = STHR( piccswo->SetWbemObject( pNetworkIn, &fRetainObject ) );
  1262. if ( FAILED( hr ) )
  1263. {
  1264. goto Cleanup;
  1265. } // if:
  1266. if ( ( hr == S_OK ) && ( fRetainObject ) )
  1267. {
  1268. hr = STHR( HrIsThisNetworkUnique( punk, pNetworkIn, pclsidMajorIdIn, pwszNetworkNameIn ) );
  1269. if ( hr == S_OK )
  1270. {
  1271. hr = THR( HrAddNetworkToArray( punk ) );
  1272. } // if:
  1273. } // if:
  1274. Cleanup:
  1275. if ( piccswo != NULL )
  1276. {
  1277. piccswo->Release();
  1278. } // if:
  1279. if ( punk != NULL )
  1280. {
  1281. punk->Release();
  1282. } // if:
  1283. HRETURN( hr );
  1284. } //*** CEnumClusCfgNetworks::HrCreateAndAddNetworkToArray
  1285. /////////////////////////////////////////////////////////////////////////////
  1286. //++
  1287. //
  1288. // CEnumClusCfgNetworks:HrIsThisNetworkUnique
  1289. //
  1290. // Description:
  1291. // Does a network for this IP Address and subnet already exist?
  1292. //
  1293. // Arguments:
  1294. //
  1295. //
  1296. // Return Value:
  1297. // S_OK
  1298. // Success
  1299. //
  1300. // S_FALSE
  1301. // This network is a duplicate.
  1302. //
  1303. // Remarks:
  1304. // None.
  1305. //
  1306. //--
  1307. //////////////////////////////////////////////////////////////////////////////
  1308. HRESULT
  1309. CEnumClusCfgNetworks::HrIsThisNetworkUnique(
  1310. IUnknown * punkIn
  1311. , IWbemClassObject * pNetworkIn
  1312. , const CLSID * pclsidMajorIdIn
  1313. , LPCWSTR pwszNetworkNameIn
  1314. )
  1315. {
  1316. TraceFunc( "" );
  1317. Assert( punkIn != NULL );
  1318. Assert( pNetworkIn != NULL );
  1319. Assert( pclsidMajorIdIn != NULL );
  1320. Assert( pwszNetworkNameIn != NULL );
  1321. HRESULT hr = S_OK;
  1322. ULONG idx;
  1323. IClusCfgNetworkInfo * piccni = NULL;
  1324. IClusCfgNetworkInfo * piccniSource = NULL;
  1325. BSTR bstr = NULL;
  1326. BSTR bstrSource = NULL;
  1327. BSTR bstrAdapterName = NULL;
  1328. BSTR bstrConnectionName = NULL;
  1329. BSTR bstrMessage = NULL;
  1330. VARIANT var;
  1331. IClusCfgClusterNetworkInfo * picccni = NULL;
  1332. IClusCfgClusterNetworkInfo * picccniSource = NULL;
  1333. VariantInit( &var );
  1334. hr = THR( punkIn->TypeSafeQI( IClusCfgNetworkInfo, &piccniSource ) );
  1335. if ( FAILED( hr ) )
  1336. {
  1337. goto Cleanup;
  1338. } // if:
  1339. hr = THR( piccniSource->TypeSafeQI( IClusCfgClusterNetworkInfo, &picccniSource ) );
  1340. if ( FAILED( hr ) )
  1341. {
  1342. goto Cleanup;
  1343. } // if:
  1344. hr = STHR( picccniSource->HrGetNetUID( &bstrSource, pclsidMajorIdIn, pwszNetworkNameIn ) );
  1345. if ( FAILED( hr ) )
  1346. {
  1347. goto Cleanup;
  1348. } // if:
  1349. if ( ( hr == S_FALSE ) && ( bstrSource == NULL ) )
  1350. {
  1351. LOG_STATUS_REPORT_STRING( L"Unable to get a UID for '%1!ws!'.", pwszNetworkNameIn, hr );
  1352. goto Cleanup;
  1353. } // if:
  1354. TraceMemoryAddBSTR( bstrSource );
  1355. for ( idx = 0; idx < m_idxNext; idx++ )
  1356. {
  1357. hr = THR( ((*m_prgNetworks)[ idx ])->TypeSafeQI( IClusCfgNetworkInfo, &piccni ) );
  1358. if ( FAILED( hr ) )
  1359. {
  1360. goto Cleanup;
  1361. } // if:
  1362. hr = THR( piccni->GetUID( &bstr ) );
  1363. if ( FAILED( hr ) )
  1364. {
  1365. goto Cleanup;
  1366. } // if:
  1367. if ( ( hr == S_FALSE ) && ( bstr != NULL ) )
  1368. {
  1369. BSTR bstrTemp = NULL;
  1370. THR( piccni->GetName( &bstrTemp ) );
  1371. LOG_STATUS_REPORT_STRING( L" Unable to get a UID for '%1!ws!'.", ( bstrTemp != NULL ) ? bstrTemp : L"<unknown>", hr );
  1372. SysFreeString( bstrTemp );
  1373. goto Cleanup;
  1374. } // if:
  1375. TraceMemoryAddBSTR( bstr );
  1376. if ( NBSTRCompareCase( bstr, bstrSource ) == 0 )
  1377. {
  1378. hr = THR( piccni->TypeSafeQI( IClusCfgClusterNetworkInfo, &picccni ) );
  1379. if ( FAILED( hr ) )
  1380. {
  1381. goto Cleanup;
  1382. } // if:
  1383. hr = STHR( picccni->HrIsClusterNetwork() );
  1384. picccni->Release();
  1385. picccni = NULL;
  1386. //
  1387. // If the network in the enum was already a cluster network then we do not need
  1388. // to warn the user.
  1389. //
  1390. if ( hr == S_OK )
  1391. {
  1392. hr = S_FALSE; // tell the caller that this is a duplicate network
  1393. } // if:
  1394. else if ( hr == S_FALSE ) // warn the user
  1395. {
  1396. HRESULT hrTemp;
  1397. CLSID clsidMinorId;
  1398. hr = THR( HrGetWMIProperty( pNetworkIn, L"Name", VT_BSTR, &var ) );
  1399. if ( FAILED( hr ) )
  1400. {
  1401. bstrAdapterName = NULL;
  1402. } // if:
  1403. else
  1404. {
  1405. bstrAdapterName = TraceSysAllocString( var.bstrVal );
  1406. } // else:
  1407. VariantClear( &var );
  1408. hr = THR( HrGetWMIProperty( pNetworkIn, L"NetConnectionID", VT_BSTR, &var ) );
  1409. if ( FAILED( hr ) )
  1410. {
  1411. bstrConnectionName = NULL;
  1412. } // if:
  1413. else
  1414. {
  1415. bstrConnectionName = TraceSysAllocString( var.bstrVal );
  1416. } // else:
  1417. hr = S_OK; // don't want a yellow bang in the UI
  1418. STATUS_REPORT_REF(
  1419. TASKID_Major_Find_Devices
  1420. , TASKID_Minor_Not_Managed_Networks
  1421. , IDS_INFO_NOT_MANAGED_NETWORKS
  1422. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  1423. , hr
  1424. );
  1425. hr = THR( HrFormatMessageIntoBSTR(
  1426. g_hInstance
  1427. , IDS_ERROR_WMI_NETWORKADAPTER_DUPE_FOUND
  1428. , &bstrMessage
  1429. , bstrAdapterName != NULL ? bstrAdapterName : L"Unknown"
  1430. , bstrConnectionName != NULL ? bstrConnectionName : L"Unknown"
  1431. ) );
  1432. if ( FAILED( hr ) )
  1433. {
  1434. bstrMessage = NULL;
  1435. hr = S_OK;
  1436. } // if:
  1437. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  1438. if ( FAILED( hrTemp ) )
  1439. {
  1440. LogMsg( L"[SRV] Could not create a guid for a duplicate network minor task ID" );
  1441. clsidMinorId = IID_NULL;
  1442. } // if:
  1443. hrTemp = THR( HrSendStatusReport(
  1444. m_picccCallback
  1445. , TASKID_Minor_Not_Managed_Networks
  1446. , clsidMinorId
  1447. , 0
  1448. , 1
  1449. , 1
  1450. , hr
  1451. , bstrMessage != NULL ? bstrMessage : L"An adapter with a duplicate IP address and subnet was found."
  1452. , IDS_ERROR_WMI_NETWORKADAPTER_DUPE_FOUND_REF
  1453. ) );
  1454. if ( FAILED( hrTemp ) )
  1455. {
  1456. hr = hrTemp;
  1457. goto Cleanup;
  1458. } // if:
  1459. // Indicate to the caller that this network is not unique.
  1460. hr = S_FALSE;
  1461. } // else if:
  1462. break;
  1463. } // if: ( NBSTRCompareCase( bstr, bstrSource ) == 0 )
  1464. piccni->Release();
  1465. piccni = NULL;
  1466. TraceSysFreeString( bstr );
  1467. bstr = NULL;
  1468. } // for:
  1469. Cleanup:
  1470. if ( picccniSource != NULL )
  1471. {
  1472. picccniSource->Release();
  1473. } // if:
  1474. if ( piccniSource != NULL )
  1475. {
  1476. piccniSource->Release();
  1477. } // if:
  1478. if ( picccni != NULL )
  1479. {
  1480. picccni->Release();
  1481. } // if:
  1482. if ( piccni != NULL )
  1483. {
  1484. piccni->Release();
  1485. } // if:
  1486. VariantClear( &var );
  1487. TraceSysFreeString( bstrAdapterName );
  1488. TraceSysFreeString( bstrConnectionName );
  1489. TraceSysFreeString( bstrMessage );
  1490. TraceSysFreeString( bstrSource );
  1491. TraceSysFreeString( bstr );
  1492. HRETURN( hr );
  1493. } //*** CEnumClusCfgNetworks::HrIsThisNetworkUnique
  1494. //////////////////////////////////////////////////////////////////////////////
  1495. //++
  1496. //
  1497. // CEnumClusCfgNetworks:HrCheckForNLBS
  1498. //
  1499. // Description:
  1500. // Are there any soft NLBS adapters? If there is then send a warning status report.
  1501. //
  1502. // Arguments:
  1503. // None.
  1504. //
  1505. // Return Value:
  1506. // S_OK - The operation completed successfully.
  1507. // Other HRESULTs.
  1508. //
  1509. //--
  1510. //////////////////////////////////////////////////////////////////////////////
  1511. HRESULT
  1512. CEnumClusCfgNetworks::HrCheckForNLBS( void )
  1513. {
  1514. TraceFunc( "" );
  1515. HRESULT hr = S_OK;
  1516. IWbemClassObject * piwcoNetwork = NULL;
  1517. IEnumWbemClassObject * piewcoNetworks = NULL;
  1518. BSTR bstrAdapterName = NULL;
  1519. BSTR bstrWQL = NULL;
  1520. BSTR bstrQuery = NULL;
  1521. ULONG cRecordsReturned;
  1522. bstrWQL = TraceSysAllocString( L"WQL" );
  1523. if ( bstrWQL == NULL )
  1524. {
  1525. hr = THR( E_OUTOFMEMORY );
  1526. goto Cleanup;
  1527. } // if:
  1528. //
  1529. // Load the NLBS Soft adapter name.
  1530. //
  1531. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_NLBS_SOFT_ADAPTER_NAME, &bstrAdapterName ) );
  1532. if ( FAILED( hr ) )
  1533. {
  1534. goto Cleanup;
  1535. } // if:
  1536. //
  1537. // Form the WMI query string.
  1538. //
  1539. hr = HrFormatStringIntoBSTR( L"Select * from Win32_NetworkAdapter where Name='%1!ws!'", &bstrQuery, bstrAdapterName );
  1540. if ( FAILED( hr ) )
  1541. {
  1542. goto Cleanup;
  1543. } // if:
  1544. //
  1545. // Execute this query and see if there are any NLB network adapters.
  1546. //
  1547. hr = THR( m_pIWbemServices->ExecQuery( bstrWQL, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &piewcoNetworks ) );
  1548. if ( FAILED( hr ) )
  1549. {
  1550. STATUS_REPORT_STRING_REF(
  1551. TASKID_Major_Find_Devices
  1552. , TASKID_Minor_WMI_NetworkAdapter_Qry_Failed
  1553. , IDS_ERROR_WMI_NETWORKADAPTER_QRY_FAILED
  1554. , bstrQuery
  1555. , IDS_ERROR_WMI_NETWORKADAPTER_QRY_FAILED_REF
  1556. , hr
  1557. );
  1558. goto Cleanup;
  1559. } // if:
  1560. //
  1561. // Loop through the adapters returned. Actually we break out of the loop after the first pass.
  1562. // The "for" loop is for future use in case we ever want to loop through every individual record returned.
  1563. //
  1564. for ( ; ; )
  1565. {
  1566. hr = piewcoNetworks->Next( WBEM_INFINITE, 1, &piwcoNetwork, &cRecordsReturned );
  1567. if ( ( hr == S_OK ) && ( cRecordsReturned == 1 ) )
  1568. {
  1569. //
  1570. // NLB network adapter was found.
  1571. // Send a warning status report and break out of the loop.
  1572. //
  1573. STATUS_REPORT_REF(
  1574. TASKID_Major_Find_Devices
  1575. , TASKID_Minor_Warning_NLBS_Detected
  1576. , IDS_WARN_NLBS_DETECTED
  1577. , IDS_WARN_NLBS_DETECTED_REF
  1578. , S_FALSE // Display warning in UI
  1579. );
  1580. break;
  1581. } // if: NLB adapter found
  1582. else if ( ( hr == S_FALSE ) && ( cRecordsReturned == 0 ) )
  1583. {
  1584. //
  1585. // There were no NLB adapters found.
  1586. //
  1587. hr = S_OK;
  1588. break;
  1589. } // else if: no NLB adapters found
  1590. else
  1591. {
  1592. //
  1593. // An error occurred.
  1594. //
  1595. STATUS_REPORT_STRING_REF(
  1596. TASKID_Major_Find_Devices
  1597. , TASKID_Minor_WQL_Network_Qry_Next_Failed
  1598. , IDS_ERROR_WQL_QRY_NEXT_FAILED
  1599. , bstrQuery
  1600. , IDS_ERROR_WQL_QRY_NEXT_FAILED_REF
  1601. , hr
  1602. );
  1603. goto Cleanup;
  1604. } // else:
  1605. } // for ever
  1606. Cleanup:
  1607. TraceSysFreeString( bstrAdapterName );
  1608. TraceSysFreeString( bstrWQL );
  1609. TraceSysFreeString( bstrQuery );
  1610. if ( piwcoNetwork != NULL )
  1611. {
  1612. piwcoNetwork->Release();
  1613. } // if:
  1614. if ( piewcoNetworks != NULL )
  1615. {
  1616. piewcoNetworks->Release();
  1617. } // if:
  1618. HRETURN( hr );
  1619. } //*** CEnumClusCfgNetworks::HrCheckForNLBS
  1620. //////////////////////////////////////////////////////////////////////////////
  1621. //++
  1622. //
  1623. // CEnumClusCfgNetworks:HrLoadClusterNetworks
  1624. //
  1625. // Description:
  1626. // Load the cluster networks.
  1627. //
  1628. // Arguments:
  1629. //
  1630. //
  1631. // Return Value:
  1632. // S_OK
  1633. // Success.
  1634. //
  1635. // Other HRESULT errors.
  1636. //
  1637. // Remarks:
  1638. // None.
  1639. //
  1640. //--
  1641. //////////////////////////////////////////////////////////////////////////////
  1642. HRESULT
  1643. CEnumClusCfgNetworks::HrLoadClusterNetworks( void )
  1644. {
  1645. TraceFunc( "" );
  1646. HRESULT hr = S_OK;
  1647. HCLUSTER hCluster = NULL;
  1648. HCLUSENUM hEnum = NULL;
  1649. DWORD sc;
  1650. DWORD idx;
  1651. DWORD cchNetworkName = 64;
  1652. DWORD cchNetInterfaceName = 64;
  1653. WCHAR * pszNetworkName = NULL;
  1654. WCHAR * pszNetInterfaceName = NULL;
  1655. BSTR bstrNetInterfaceName = NULL;
  1656. DWORD dwType;
  1657. HNETWORK hNetwork = NULL;
  1658. HNETINTERFACE hNetInterface = NULL;
  1659. BSTR bstrLocalNetBIOSName = NULL;
  1660. //
  1661. // Get netbios name for the GetClusterNetInterface clusapi call.
  1662. //
  1663. hr = THR( HrGetComputerName( ComputerNameNetBIOS, &bstrLocalNetBIOSName, TRUE ) );
  1664. if ( FAILED( hr ) )
  1665. {
  1666. LOG_STATUS_REPORT( L"[SRV] Failed to get the local computer net bios name.", hr );
  1667. goto Cleanup;
  1668. } // if:
  1669. hCluster = OpenCluster( NULL );
  1670. if ( hCluster == NULL )
  1671. {
  1672. sc = TW32( GetLastError() );
  1673. goto MakeHr;
  1674. } // if:
  1675. hEnum = ClusterOpenEnum( hCluster, CLUSTER_ENUM_NETWORK );
  1676. if ( hEnum == NULL )
  1677. {
  1678. sc = TW32( GetLastError() );
  1679. goto MakeHr;
  1680. } // if:
  1681. pszNetworkName = new WCHAR [ cchNetworkName ];
  1682. if ( pszNetworkName == NULL )
  1683. {
  1684. hr = THR( E_OUTOFMEMORY );
  1685. goto Cleanup;
  1686. } // if:
  1687. pszNetInterfaceName = new WCHAR [ cchNetInterfaceName ];
  1688. if ( pszNetInterfaceName == NULL )
  1689. {
  1690. hr = THR( E_OUTOFMEMORY );
  1691. goto Cleanup;
  1692. } // if:
  1693. //
  1694. // Enumerate all the network connections on this node.
  1695. //
  1696. for ( idx = 0; ; )
  1697. {
  1698. //
  1699. // Get the next network name.
  1700. //
  1701. sc = ClusterEnum( hEnum, idx, &dwType, pszNetworkName, &cchNetworkName );
  1702. if ( sc == ERROR_NO_MORE_ITEMS )
  1703. {
  1704. break;
  1705. } // if:
  1706. if ( sc == ERROR_MORE_DATA )
  1707. {
  1708. delete [] pszNetworkName;
  1709. pszNetworkName = NULL;
  1710. cchNetworkName++;
  1711. pszNetworkName = new WCHAR [ cchNetworkName ];
  1712. if ( pszNetworkName == NULL )
  1713. {
  1714. hr = THR( E_OUTOFMEMORY );
  1715. goto Cleanup;
  1716. } // if:
  1717. sc = ClusterEnum( hEnum, idx, &dwType, pszNetworkName, &cchNetworkName );
  1718. } // if:
  1719. if ( sc != ERROR_SUCCESS )
  1720. {
  1721. TW32( sc );
  1722. goto MakeHr;
  1723. } // if: ClusterEnum() failed.
  1724. //
  1725. // Get the network handle using the network name.
  1726. //
  1727. hNetwork = OpenClusterNetwork( hCluster, pszNetworkName );
  1728. if ( hNetwork == NULL )
  1729. {
  1730. sc = TW32( GetLastError() );
  1731. hr = HRESULT_FROM_WIN32( sc );
  1732. LOG_STATUS_REPORT_STRING( L"[SRV] Cannot open cluster network \"%1!ws!\".", pszNetworkName, hr );
  1733. goto Cleanup;
  1734. } // if: OpenClusterNetwork() failed.
  1735. //
  1736. // Get the network interface name on this node for the
  1737. // current network name.
  1738. //
  1739. sc = GetClusterNetInterface(
  1740. hCluster
  1741. , bstrLocalNetBIOSName
  1742. , pszNetworkName
  1743. , pszNetInterfaceName
  1744. , &cchNetInterfaceName
  1745. );
  1746. if ( sc == ERROR_MORE_DATA )
  1747. {
  1748. delete [] pszNetInterfaceName;
  1749. pszNetInterfaceName = NULL;
  1750. cchNetInterfaceName++;
  1751. pszNetInterfaceName = new WCHAR [ cchNetInterfaceName ];
  1752. if ( pszNetInterfaceName == NULL )
  1753. {
  1754. hr = THR( E_OUTOFMEMORY );
  1755. goto Cleanup;
  1756. } // if:
  1757. sc = GetClusterNetInterface(
  1758. hCluster
  1759. , bstrLocalNetBIOSName
  1760. , pszNetworkName
  1761. , pszNetInterfaceName
  1762. , &cchNetInterfaceName
  1763. );
  1764. } // if: ( sc == ERROR_MORE_DATA )
  1765. if ( ( sc != ERROR_SUCCESS ) && ( sc != ERROR_CLUSTER_NETINTERFACE_NOT_FOUND ) )
  1766. {
  1767. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  1768. LOG_STATUS_REPORT_STRING( L"[SRV] Error locating a network interface for cluster network \"%1!ws!\".", pszNetworkName, hr );
  1769. goto Cleanup;
  1770. } // if: GetClusterNetInterface() failed.
  1771. if ( sc == ERROR_CLUSTER_NETINTERFACE_NOT_FOUND )
  1772. {
  1773. //
  1774. // If we get ERROR_CLUSTER_NETINTERFACE_NOT_FOUND for
  1775. // any reason then display a warning regarding this network
  1776. // interface on this node and find a valid (=enabled, working)
  1777. // network interface on another node.
  1778. //
  1779. hr = S_FALSE;
  1780. STATUS_REPORT_STRING2_REF(
  1781. TASKID_Major_Find_Devices
  1782. , TASKID_Minor_Network_Interface_Not_Found
  1783. , IDS_WARN_NETWORK_INTERFACE_NOT_FOUND
  1784. , pszNetworkName
  1785. , bstrLocalNetBIOSName
  1786. , IDS_WARN_NETWORK_INTERFACE_NOT_FOUND_REF
  1787. , hr
  1788. );
  1789. //
  1790. // Find a valid network interface name of another node on this network.
  1791. //
  1792. hr = THR( HrFindNetInterface( hNetwork, &bstrNetInterfaceName ) );
  1793. if ( FAILED( hr ) )
  1794. {
  1795. LOG_STATUS_REPORT_STRING( L"[SRV] Can not find a network interface for cluster network \"%1!ws!\".", pszNetworkName, hr );
  1796. goto Cleanup;
  1797. } // if: HrFindNetInterface failed.
  1798. } // if: sc == ERROR_CLUSTER_NETINTERFACE_NOT_FOUND
  1799. else
  1800. {
  1801. //
  1802. // We have a network interface name on this node
  1803. //
  1804. bstrNetInterfaceName = TraceSysAllocString ( pszNetInterfaceName );
  1805. if ( bstrNetInterfaceName == NULL )
  1806. {
  1807. hr = THR( E_OUTOFMEMORY );
  1808. goto Cleanup;
  1809. } // if:
  1810. } // else: sc == ERROR_SUCCESS
  1811. Assert( bstrNetInterfaceName != NULL );
  1812. //
  1813. // Open the network interface handle using the network interface
  1814. // name.
  1815. //
  1816. hNetInterface = OpenClusterNetInterface( hCluster, bstrNetInterfaceName );
  1817. if ( hNetInterface == NULL )
  1818. {
  1819. //
  1820. // If we don't have network interface handle by now
  1821. // we'll log an error and goto cleanup.
  1822. //
  1823. sc = TW32( GetLastError() );
  1824. hr = HRESULT_FROM_WIN32( sc );
  1825. LOG_STATUS_REPORT_STRING2(
  1826. L"[SRV] Can not open the cluster network interface \"%1!ws!\" for cluster network \"%2!ws!\" on this node."
  1827. , pszNetInterfaceName
  1828. , pszNetworkName
  1829. , hr
  1830. );
  1831. goto Cleanup;
  1832. } // if: Could not open the network interface.
  1833. else
  1834. {
  1835. hr = THR( HrLoadClusterNetwork( hNetwork, hNetInterface ) );
  1836. if ( FAILED( hr ) )
  1837. {
  1838. LOG_STATUS_REPORT_STRING( L"[SRV] Can not load information for cluster network \"%1!ws!\".", pszNetworkName, hr );
  1839. goto Cleanup;
  1840. } // if:
  1841. CloseClusterNetInterface( hNetInterface );
  1842. hNetInterface = NULL;
  1843. } // else: Could open the network interface.
  1844. CloseClusterNetwork( hNetwork );
  1845. hNetwork = NULL;
  1846. idx++;
  1847. } // for:
  1848. Assert( hr == S_OK );
  1849. goto Cleanup;
  1850. MakeHr:
  1851. hr = HRESULT_FROM_WIN32( sc );
  1852. goto Cleanup;
  1853. Cleanup:
  1854. LOG_STATUS_REPORT( L"[SRV] Completed loading the cluster networks.", hr );
  1855. if ( hNetInterface != NULL )
  1856. {
  1857. CloseClusterNetInterface( hNetInterface );
  1858. } // if:
  1859. if ( hNetwork != NULL )
  1860. {
  1861. CloseClusterNetwork( hNetwork );
  1862. } // if:
  1863. if ( hEnum != NULL )
  1864. {
  1865. ClusterCloseEnum( hEnum );
  1866. } // if:
  1867. if ( hCluster != NULL )
  1868. {
  1869. CloseCluster( hCluster );
  1870. } // if:
  1871. delete [] pszNetworkName;
  1872. delete [] pszNetInterfaceName;
  1873. TraceSysFreeString( bstrNetInterfaceName );
  1874. TraceSysFreeString( bstrLocalNetBIOSName );
  1875. HRETURN( hr );
  1876. } //*** CEnumClusCfgNetworks::HrLoadClusterNetworks
  1877. //////////////////////////////////////////////////////////////////////////////
  1878. //++
  1879. //
  1880. // CEnumClusCfgNetworks:HrLoadClusterNetwork
  1881. //
  1882. // Description:
  1883. // Load the cluster network and put it into the array of networks.
  1884. //
  1885. // Arguments:
  1886. // hNetworkIn
  1887. // hNetInterfaceIn
  1888. //
  1889. // Return Value:
  1890. // S_OK
  1891. // Success.
  1892. //
  1893. // Other HRESULT errors.
  1894. //
  1895. // Remarks:
  1896. // None.
  1897. //
  1898. //--
  1899. //////////////////////////////////////////////////////////////////////////////
  1900. HRESULT
  1901. CEnumClusCfgNetworks::HrLoadClusterNetwork(
  1902. HNETWORK hNetworkIn
  1903. , HNETINTERFACE hNetInterfaceIn
  1904. )
  1905. {
  1906. TraceFunc( "" );
  1907. Assert( hNetworkIn != NULL );
  1908. Assert( hNetInterfaceIn != NULL );
  1909. HRESULT hr;
  1910. IUnknown * punk = NULL;
  1911. IUnknown * punkCallback = NULL;
  1912. hr = THR( m_picccCallback->TypeSafeQI( IUnknown, &punkCallback ) );
  1913. if ( FAILED( hr ) )
  1914. {
  1915. goto Cleanup;
  1916. } // if:
  1917. //
  1918. // Have to pass the Initialize interface arguments since new objects will
  1919. // be created when this call is made.
  1920. //
  1921. hr = THR( CClusCfgNetworkInfo::S_HrCreateInstance( hNetworkIn, hNetInterfaceIn, punkCallback, m_lcid, m_pIWbemServices, &punk ) );
  1922. if ( FAILED( hr ) )
  1923. {
  1924. goto Cleanup;
  1925. } // if:
  1926. //
  1927. // This is special -- do not initialize this again.
  1928. //
  1929. //hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1930. //if ( FAILED( hr ))
  1931. //{
  1932. // goto Cleanup;
  1933. //} // if:
  1934. //hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1935. //if ( FAILED( hr ) )
  1936. //{
  1937. // goto Cleanup;
  1938. //} // if:
  1939. hr = THR( HrAddNetworkToArray( punk ) );
  1940. goto Cleanup;
  1941. Cleanup:
  1942. if ( punkCallback != NULL )
  1943. {
  1944. punkCallback->Release();
  1945. } // if:
  1946. if ( punk != NULL )
  1947. {
  1948. punk->Release();
  1949. } // if:
  1950. HRETURN( hr );
  1951. } //*** CEnumClusCfgNetworks::HrLoadClusterNetwork
  1952. //////////////////////////////////////////////////////////////////////////////
  1953. //++
  1954. //
  1955. // CEnumClusCfgNetworks::HrFindNetInterface
  1956. //
  1957. // Description:
  1958. // Finds the first network interface name for the passed in network.
  1959. //
  1960. // Arguments:
  1961. //
  1962. //
  1963. // Return Value:
  1964. // S_OK
  1965. // Success.
  1966. //
  1967. // HRESULT version of error ERROR_CLUSTER_NETINTERFACE_NOT_FOUND
  1968. // or other HRESULTS
  1969. // Failure.
  1970. //
  1971. // Remarks:
  1972. // None.
  1973. //
  1974. //--
  1975. //////////////////////////////////////////////////////////////////////////////
  1976. HRESULT
  1977. CEnumClusCfgNetworks::HrFindNetInterface(
  1978. HNETWORK hNetworkIn
  1979. , BSTR * pbstrNetInterfaceNameOut
  1980. )
  1981. {
  1982. TraceFunc( "" );
  1983. Assert( hNetworkIn != NULL );
  1984. Assert( pbstrNetInterfaceNameOut != NULL );
  1985. HRESULT hr = S_OK;
  1986. DWORD sc;
  1987. HNETWORKENUM hEnum = NULL;
  1988. WCHAR * pszNetInterfaceName = NULL;
  1989. DWORD cchNetInterfaceName = 64;
  1990. DWORD idx;
  1991. DWORD dwType;
  1992. *pbstrNetInterfaceNameOut = NULL;
  1993. //
  1994. // Create a netinterface enum for the passed in network.
  1995. //
  1996. hEnum = ClusterNetworkOpenEnum( hNetworkIn, CLUSTER_NETWORK_ENUM_NETINTERFACES );
  1997. if ( hEnum == NULL )
  1998. {
  1999. sc = TW32( GetLastError() );
  2000. hr = HRESULT_FROM_WIN32( sc );
  2001. LOG_STATUS_REPORT( L"[SRV] Can not open Cluster Network enumeration.", hr );
  2002. goto Cleanup;
  2003. } // if:
  2004. pszNetInterfaceName = new WCHAR [ cchNetInterfaceName ];
  2005. if ( pszNetInterfaceName == NULL )
  2006. {
  2007. hr = THR( E_OUTOFMEMORY );
  2008. goto Cleanup;
  2009. } // if:
  2010. for ( idx = 0; ; )
  2011. {
  2012. sc = ClusterNetworkEnum( hEnum, idx, &dwType, pszNetInterfaceName, &cchNetInterfaceName );
  2013. if ( sc == ERROR_NO_MORE_ITEMS )
  2014. {
  2015. break;
  2016. } // if:
  2017. if ( sc == ERROR_MORE_DATA )
  2018. {
  2019. delete [] pszNetInterfaceName;
  2020. pszNetInterfaceName = NULL;
  2021. cchNetInterfaceName++;
  2022. pszNetInterfaceName = new WCHAR [ cchNetInterfaceName ];
  2023. if ( pszNetInterfaceName == NULL )
  2024. {
  2025. hr = THR( E_OUTOFMEMORY );
  2026. goto Cleanup;
  2027. } // if:
  2028. sc = ClusterNetworkEnum( hEnum, idx, &dwType, pszNetInterfaceName, &cchNetInterfaceName );
  2029. } // if:
  2030. if ( sc != ERROR_SUCCESS )
  2031. {
  2032. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  2033. LOG_STATUS_REPORT_STRING( L"[SRV] Failed to enumerate Network Interface \"%1!ws!\".", pszNetInterfaceName != NULL ? pszNetInterfaceName : L"<unknown>", hr );
  2034. goto Cleanup;
  2035. } // if: ( sc != ERROR_SUCCESS )
  2036. //
  2037. // Get the first enabled network interface for this network
  2038. // and break out of the for loop.
  2039. //
  2040. *pbstrNetInterfaceNameOut = TraceSysAllocString( pszNetInterfaceName );
  2041. if ( *pbstrNetInterfaceNameOut == NULL )
  2042. {
  2043. hr = THR( E_OUTOFMEMORY );
  2044. goto Cleanup;
  2045. } // if:
  2046. break;
  2047. } // for:
  2048. //
  2049. // This function will either return S_OK or HRESULT version of error
  2050. // ERROR_CLUSTER_NETINTERFACE_NOT_FOUND at this point.
  2051. //
  2052. if ( *pbstrNetInterfaceNameOut == NULL )
  2053. {
  2054. hr = HRESULT_FROM_WIN32( TW32( ERROR_CLUSTER_NETINTERFACE_NOT_FOUND ) );
  2055. } // if:
  2056. else
  2057. {
  2058. hr = S_OK;
  2059. } // else:
  2060. goto Cleanup;
  2061. Cleanup:
  2062. LOG_STATUS_REPORT_STRING( L"[SRV] Completed searching for NetInterface \"%1!ws!\".", pszNetInterfaceName != NULL ? pszNetInterfaceName : L"<unknown>", hr );
  2063. if ( hEnum != NULL )
  2064. {
  2065. ClusterNetworkCloseEnum( hEnum );
  2066. } // if:
  2067. delete [] pszNetInterfaceName;
  2068. HRETURN( hr );
  2069. } //*** CEnumClusCfgNetworks::HrFindNetInterface