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.

1713 lines
42 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumClusCfgIPAddresses.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumClusCfgIPAddresses
  10. // class.
  11. //
  12. // The class CEnumClusCfgIPAddresses is the enumeration of IP addresses.
  13. // It implements the IEnumClusCfgIPAddresses interface.
  14. //
  15. // Maintained By:
  16. // Galen Barbee (GalenB) 23-MAR-2000
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Include Files
  21. //////////////////////////////////////////////////////////////////////////////
  22. #include "Pch.h"
  23. #include "CEnumClusCfgIPAddresses.h"
  24. #include "CClusCfgIPAddressInfo.h"
  25. #include <ClusRtl.h>
  26. #include <commctrl.h>
  27. //////////////////////////////////////////////////////////////////////////////
  28. // Constant Definitions
  29. //////////////////////////////////////////////////////////////////////////////
  30. DEFINE_THISCLASS( "CEnumClusCfgIPAddresses" );
  31. //*************************************************************************//
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CEnumClusCfgIPAddresses class
  34. /////////////////////////////////////////////////////////////////////////////
  35. //////////////////////////////////////////////////////////////////////////////
  36. //++
  37. //
  38. // CEnumClusCfgIPAddresses::S_HrCreateInstance
  39. //
  40. // Description:
  41. // Create a CEnumClusCfgIPAddresses instance.
  42. //
  43. // Arguments:
  44. // None.
  45. //
  46. // Return Values:
  47. // Pointer to CEnumClusCfgIPAddresses instance.
  48. //
  49. //--
  50. //////////////////////////////////////////////////////////////////////////////
  51. HRESULT
  52. CEnumClusCfgIPAddresses::S_HrCreateInstance( IUnknown ** ppunkOut )
  53. {
  54. TraceFunc( "" );
  55. HRESULT hr = S_OK;
  56. CEnumClusCfgIPAddresses * peccipa = NULL;
  57. if ( ppunkOut == NULL )
  58. {
  59. hr = THR( E_POINTER );
  60. goto Cleanup;
  61. } // if:
  62. peccipa = new CEnumClusCfgIPAddresses();
  63. if ( peccipa == NULL )
  64. {
  65. hr = THR( E_OUTOFMEMORY );
  66. goto Cleanup;
  67. } // if: error allocating object
  68. hr = THR( peccipa->HrInit() );
  69. if ( FAILED( hr ) )
  70. {
  71. goto Cleanup;
  72. } // if: HrInit() failed
  73. hr = THR( peccipa->TypeSafeQI( IUnknown, ppunkOut ) );
  74. if ( FAILED( hr ) )
  75. {
  76. goto Cleanup;
  77. } // if: QI failed
  78. Cleanup:
  79. if ( FAILED( hr ) )
  80. {
  81. LogMsg( L"[SRV] CEnumClusCfgIPAddresses::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  82. } // if:
  83. if ( peccipa != NULL )
  84. {
  85. peccipa->Release();
  86. } // if:
  87. HRETURN( hr );
  88. } //*** CEnumClusCfgIPAddresses::S_HrCreateInstance
  89. //////////////////////////////////////////////////////////////////////////////
  90. //++
  91. //
  92. // CEnumClusCfgIPAddresses::S_HrCreateInstance
  93. //
  94. // Description:
  95. // Create a CEnumClusCfgIPAddresses instance.
  96. //
  97. // Arguments:
  98. // None.
  99. //
  100. // Return Values:
  101. // Pointer to CEnumClusCfgIPAddresses instance.
  102. //
  103. //--
  104. //////////////////////////////////////////////////////////////////////////////
  105. HRESULT
  106. CEnumClusCfgIPAddresses::S_HrCreateInstance(
  107. ULONG ulIPAddressIn
  108. , ULONG ulIPSubnetIn
  109. , IUnknown * punkCallbackIn
  110. , LCID lcidIn
  111. , IWbemServices * pIWbemServicesIn
  112. , IUnknown ** ppunkOut
  113. )
  114. {
  115. TraceFunc( "" );
  116. Assert( ppunkOut != NULL );
  117. Assert( ulIPAddressIn != 0 );
  118. Assert( ulIPSubnetIn != 0 );
  119. HRESULT hr = S_OK;
  120. CEnumClusCfgIPAddresses * peccipa = NULL;
  121. if ( ppunkOut == NULL )
  122. {
  123. hr = THR( E_POINTER );
  124. goto Cleanup;
  125. } // if:
  126. peccipa = new CEnumClusCfgIPAddresses();
  127. if ( peccipa == NULL )
  128. {
  129. hr = THR( E_OUTOFMEMORY );
  130. goto Cleanup;
  131. } // if: error allocating object
  132. hr = THR( peccipa->Initialize( punkCallbackIn, lcidIn ) );
  133. if ( FAILED( hr ) )
  134. {
  135. goto Cleanup;
  136. } // if:
  137. hr = THR( peccipa->SetWbemServices( pIWbemServicesIn ) );
  138. if ( FAILED( hr ) )
  139. {
  140. goto Cleanup;
  141. } // if:
  142. hr = THR( peccipa->HrInit( ulIPAddressIn, ulIPSubnetIn ) );
  143. if ( FAILED( hr ) )
  144. {
  145. goto Cleanup;
  146. } // if: HrInit() failed
  147. hr = THR( peccipa->TypeSafeQI( IUnknown, ppunkOut ) );
  148. Cleanup:
  149. if ( FAILED( hr ) )
  150. {
  151. LogMsg( L"[SRV] CEnumClusCfgIPAddresses::S_HrCreateInstance( ULONG, ULONG ) failed. (hr = %#08x)", hr );
  152. } // if:
  153. if ( peccipa != NULL )
  154. {
  155. peccipa->Release();
  156. } // if:
  157. HRETURN( hr );
  158. } //*** CEnumClusCfgIPAddresses::S_HrCreateInstance
  159. //////////////////////////////////////////////////////////////////////////////
  160. //++
  161. //
  162. // CEnumClusCfgIPAddresses::CEnumClusCfgIPAddresses
  163. //
  164. // Description:
  165. // Constructor of the CEnumClusCfgIPAddresses class. This initializes
  166. // the m_cRef variable to 1 instead of 0 to account of possible
  167. // QueryInterface failure in DllGetClassObject.
  168. //
  169. // Arguments:
  170. // None.
  171. //
  172. // Return Value:
  173. // None.
  174. //
  175. // Remarks:
  176. // None.
  177. //
  178. //--
  179. //////////////////////////////////////////////////////////////////////////////
  180. CEnumClusCfgIPAddresses::CEnumClusCfgIPAddresses( void )
  181. : m_cRef( 1 )
  182. , m_lcid( LOCALE_NEUTRAL )
  183. {
  184. TraceFunc( "" );
  185. Assert( m_idxNext == 0 );
  186. Assert( m_idxEnumNext == 0 );
  187. Assert( m_picccCallback == NULL );
  188. Assert( m_pIWbemServices == NULL );
  189. Assert( m_prgAddresses == NULL );
  190. Assert( m_cAddresses == 0 );
  191. // Increment the count of components in memory so the DLL hosting this
  192. // object cannot be unloaded.
  193. InterlockedIncrement( &g_cObjects );
  194. TraceFuncExit();
  195. } //*** CEnumClusCfgIPAddresses::CEnumClusCfgIPAddresses
  196. //////////////////////////////////////////////////////////////////////////////
  197. //++
  198. //
  199. // CEnumClusCfgIPAddresses::~CEnumClusCfgIPAddresses
  200. //
  201. // Description:
  202. // Desstructor of the CEnumClusCfgIPAddresses class.
  203. //
  204. // Arguments:
  205. // None.
  206. //
  207. // Return Value:
  208. // None.
  209. //
  210. // Remarks:
  211. // None.
  212. //
  213. //--
  214. //////////////////////////////////////////////////////////////////////////////
  215. CEnumClusCfgIPAddresses::~CEnumClusCfgIPAddresses( void )
  216. {
  217. TraceFunc( "" );
  218. ULONG idx;
  219. if ( m_pIWbemServices != NULL )
  220. {
  221. m_pIWbemServices->Release();
  222. } // if:
  223. if ( m_picccCallback != NULL )
  224. {
  225. m_picccCallback->Release();
  226. } // if:
  227. for ( idx = 0; idx < m_idxNext; idx++ )
  228. {
  229. ((*m_prgAddresses)[ idx ])->Release();
  230. } // for:
  231. TraceFree( m_prgAddresses );
  232. // There's going to be one less component in memory. Decrement component count.
  233. InterlockedDecrement( &g_cObjects );
  234. TraceFuncExit();
  235. } //*** CEnumClusCfgIPAddresses::~CEnumClusCfgIPAddresses
  236. //*************************************************************************//
  237. /////////////////////////////////////////////////////////////////////////////
  238. // CEnumClusCfgIPAddresses -- IUknkown interface.
  239. /////////////////////////////////////////////////////////////////////////////
  240. //////////////////////////////////////////////////////////////////////////////
  241. //++
  242. //
  243. // CEnumClusCfgIPAddresses::AddRef
  244. //
  245. // Description:
  246. // Increment the reference count of this object by one.
  247. //
  248. // Arguments:
  249. // None.
  250. //
  251. // Return Value:
  252. // The new reference count.
  253. //
  254. // Remarks:
  255. // None.
  256. //
  257. //--
  258. //////////////////////////////////////////////////////////////////////////////
  259. STDMETHODIMP_( ULONG )
  260. CEnumClusCfgIPAddresses::AddRef( void )
  261. {
  262. TraceFunc( "[IUnknown]" );
  263. InterlockedIncrement( &m_cRef );
  264. CRETURN( m_cRef );
  265. } //*** CEnumClusCfgIPAddresses::AddRef
  266. //////////////////////////////////////////////////////////////////////////////
  267. //++
  268. //
  269. // CEnumClusCfgIPAddresses::Release
  270. //
  271. // Description:
  272. // Decrement the reference count of this object by one.
  273. //
  274. // Arguments:
  275. // None.
  276. //
  277. // Return Value:
  278. // The new reference count.
  279. //
  280. // Remarks:
  281. // None.
  282. //
  283. //--
  284. //////////////////////////////////////////////////////////////////////////////
  285. STDMETHODIMP_( ULONG )
  286. CEnumClusCfgIPAddresses::Release( void )
  287. {
  288. TraceFunc( "[IUnknown]" );
  289. LONG cRef;
  290. cRef = InterlockedDecrement( &m_cRef );
  291. if ( cRef == 0 )
  292. {
  293. TraceDo( delete this );
  294. } // if: reference count equal to zero
  295. CRETURN( cRef );
  296. } //*** CEnumClusCfgIPAddresses::Release
  297. //////////////////////////////////////////////////////////////////////////////
  298. //++
  299. //
  300. // CEnumClusCfgIPAddresses::QueryInterface
  301. //
  302. // Description:
  303. // Query this object for the passed in interface.
  304. //
  305. // Arguments:
  306. // riidIn
  307. // Id of interface requested.
  308. //
  309. // ppvOut
  310. // Pointer to the requested interface.
  311. //
  312. // Return Value:
  313. // S_OK
  314. // If the interface is available on this object.
  315. //
  316. // E_NOINTERFACE
  317. // If the interface is not available.
  318. //
  319. // E_POINTER
  320. // ppvOut was NULL.
  321. //
  322. // Remarks:
  323. // None.
  324. //
  325. //--
  326. //////////////////////////////////////////////////////////////////////////////
  327. STDMETHODIMP
  328. CEnumClusCfgIPAddresses::QueryInterface(
  329. REFIID riidIn
  330. , void ** ppvOut
  331. )
  332. {
  333. TraceQIFunc( riidIn, ppvOut );
  334. HRESULT hr = S_OK;
  335. //
  336. // Validate arguments.
  337. //
  338. Assert( ppvOut != NULL );
  339. if ( ppvOut == NULL )
  340. {
  341. hr = THR( E_POINTER );
  342. goto Cleanup;
  343. }
  344. //
  345. // Handle known interfaces.
  346. //
  347. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  348. {
  349. *ppvOut = static_cast< IEnumClusCfgIPAddresses * >( this );
  350. } // if: IUnknown
  351. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgIPAddresses ) )
  352. {
  353. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgIPAddresses, this, 0 );
  354. } // else if: IEnumClusCfgIPAddresses
  355. else if ( IsEqualIID( riidIn, IID_IClusCfgWbemServices ) )
  356. {
  357. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  358. } // else if: IClusCfgWbemServices
  359. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  360. {
  361. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  362. } // else if: IClusCfgInitialize
  363. else if ( IsEqualIID( riidIn, IID_IClusCfgSetWbemObject ) )
  364. {
  365. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgSetWbemObject, this, 0 );
  366. } // else if: IClusCfgSetWbemObject
  367. else
  368. {
  369. *ppvOut = NULL;
  370. hr = E_NOINTERFACE;
  371. }
  372. //
  373. // Add a reference to the interface if successful.
  374. //
  375. if ( SUCCEEDED( hr ) )
  376. {
  377. ((IUnknown *) *ppvOut)->AddRef();
  378. } // if: success
  379. Cleanup:
  380. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  381. } //*** CEnumClusCfgIPAddresses::QueryInterface
  382. //*************************************************************************//
  383. /////////////////////////////////////////////////////////////////////////////
  384. // CEnumClusCfgIPAddresses -- IClusCfgWbemServices interface.
  385. /////////////////////////////////////////////////////////////////////////////
  386. //////////////////////////////////////////////////////////////////////////////
  387. //++
  388. //
  389. // CEnumClusCfgIPAddresses::SetWbemServices
  390. //
  391. // Description:
  392. // Set the WBEM services provider.
  393. //
  394. // Arguments:
  395. // IN IWbemServices pIWbemServicesIn
  396. //
  397. // Return Value:
  398. // S_OK
  399. // Success
  400. //
  401. // E_POINTER
  402. // The pIWbemServicesIn param is NULL.
  403. //
  404. // Remarks:
  405. // None.
  406. //
  407. //--
  408. //////////////////////////////////////////////////////////////////////////////
  409. STDMETHODIMP
  410. CEnumClusCfgIPAddresses::SetWbemServices( IWbemServices * pIWbemServicesIn )
  411. {
  412. TraceFunc( "[IClusCfgWbemServices]" );
  413. HRESULT hr = S_OK;
  414. if ( pIWbemServicesIn == NULL )
  415. {
  416. hr = THR( E_POINTER );
  417. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Enum_IPAddresses, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  418. goto Cleanup;
  419. } // if:
  420. m_pIWbemServices = pIWbemServicesIn;
  421. m_pIWbemServices->AddRef();
  422. Cleanup:
  423. HRETURN( hr );
  424. } //*** CEnumClusCfgIPAddresses::SetWbemServices
  425. //*************************************************************************//
  426. /////////////////////////////////////////////////////////////////////////////
  427. // CEnumClusCfgIPAddresses -- IClusCfgInitialize interface.
  428. /////////////////////////////////////////////////////////////////////////////
  429. //////////////////////////////////////////////////////////////////////////////
  430. //++
  431. //
  432. // CEnumClusCfgIPAddresses::Initialize
  433. //
  434. // Description:
  435. // Initialize this component.
  436. //
  437. // Arguments:
  438. // IN IUknown * punkCallbackIn
  439. //
  440. // IN LCID lcidIn
  441. //
  442. // Return Value:
  443. // S_OK
  444. // Success
  445. //
  446. // Remarks:
  447. // None.
  448. //
  449. //--
  450. //////////////////////////////////////////////////////////////////////////////
  451. STDMETHODIMP
  452. CEnumClusCfgIPAddresses::Initialize(
  453. IUnknown * punkCallbackIn,
  454. LCID lcidIn
  455. )
  456. {
  457. TraceFunc( "[IClusCfgInitialize]" );
  458. Assert( m_picccCallback == NULL );
  459. HRESULT hr = S_OK;
  460. m_lcid = lcidIn;
  461. if ( punkCallbackIn == NULL )
  462. {
  463. hr = THR( E_POINTER );
  464. goto Cleanup;
  465. } // if:
  466. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  467. Cleanup:
  468. HRETURN( hr );
  469. } //*** CEnumClusCfgIPAddresses::Initialize
  470. //*************************************************************************//
  471. /////////////////////////////////////////////////////////////////////////////
  472. // CEnumClusCfgIPAddresses -- IEnumClusCfgIPAddresses interface.
  473. /////////////////////////////////////////////////////////////////////////////
  474. //////////////////////////////////////////////////////////////////////////////
  475. //++
  476. //
  477. // CEnumClusCfgIPAddresses::Next
  478. //
  479. // Description:
  480. //
  481. // Arguments:
  482. //
  483. // Return Value:
  484. //
  485. // Remarks:
  486. // None.
  487. //
  488. //--
  489. //////////////////////////////////////////////////////////////////////////////
  490. STDMETHODIMP
  491. CEnumClusCfgIPAddresses::Next(
  492. ULONG cNumberRequestedIn,
  493. IClusCfgIPAddressInfo ** rgpIPAddressInfoOut,
  494. ULONG * pcNumberFetchedOut
  495. )
  496. {
  497. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  498. HRESULT hr = S_FALSE;
  499. ULONG cFetched = 0;
  500. ULONG idx;
  501. IClusCfgIPAddressInfo * pccipai;
  502. if ( rgpIPAddressInfoOut == NULL )
  503. {
  504. hr = THR( E_POINTER );
  505. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_IPAddresses, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  506. goto Cleanup;
  507. } // if:
  508. cFetched = min( cNumberRequestedIn, ( m_idxNext - m_idxEnumNext ) );
  509. for ( idx = 0; idx < cFetched; idx++, m_idxEnumNext++ )
  510. {
  511. hr = THR( ((*m_prgAddresses)[ m_idxEnumNext ])->TypeSafeQI( IClusCfgIPAddressInfo, &pccipai ) );
  512. if ( FAILED( hr ) )
  513. {
  514. break;
  515. } // if:
  516. rgpIPAddressInfoOut[ idx ] = pccipai;
  517. } // for:
  518. if ( FAILED( hr ) )
  519. {
  520. ULONG idxStop = idx;
  521. m_idxEnumNext -= idx;
  522. for ( idx = 0; idx < idxStop; idx++ )
  523. {
  524. (rgpIPAddressInfoOut[ idx ])->Release();
  525. } // for:
  526. cFetched = 0;
  527. goto Cleanup;
  528. } // if:
  529. if ( cFetched < cNumberRequestedIn )
  530. {
  531. hr = S_FALSE;
  532. } // if:
  533. Cleanup:
  534. if ( pcNumberFetchedOut != NULL )
  535. {
  536. *pcNumberFetchedOut = cFetched;
  537. } // if:
  538. HRETURN( hr );
  539. } //*** CEnumClusCfgIPAddresses::Next
  540. //////////////////////////////////////////////////////////////////////////////
  541. //++
  542. //
  543. // CEnumClusCfgIPAddresses::Skip
  544. //
  545. // Description:
  546. //
  547. // Arguments:
  548. //
  549. // Return Value:
  550. //
  551. // Remarks:
  552. // None.
  553. //
  554. //--
  555. //////////////////////////////////////////////////////////////////////////////
  556. STDMETHODIMP
  557. CEnumClusCfgIPAddresses::Skip( ULONG cNumberToSkipIn )
  558. {
  559. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  560. HRESULT hr = S_OK;
  561. m_idxEnumNext += cNumberToSkipIn;
  562. if ( m_idxEnumNext >= m_idxNext )
  563. {
  564. m_idxEnumNext = m_idxNext;
  565. hr = STHR( S_FALSE );
  566. } // if:
  567. HRETURN( hr );
  568. } //*** CEnumClusCfgIPAddresses::Skip
  569. //////////////////////////////////////////////////////////////////////////////
  570. //++
  571. //
  572. // CEnumClusCfgIPAddresses::Reset
  573. //
  574. // Description:
  575. //
  576. // Arguments:
  577. //
  578. // Return Value:
  579. //
  580. // Remarks:
  581. // None.
  582. //
  583. //--
  584. //////////////////////////////////////////////////////////////////////////////
  585. STDMETHODIMP
  586. CEnumClusCfgIPAddresses::Reset( void )
  587. {
  588. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  589. HRESULT hr S_OK;
  590. m_idxEnumNext = 0;
  591. HRETURN( hr );
  592. } //*** CEnumClusCfgIPAddresses::Reset
  593. //////////////////////////////////////////////////////////////////////////////
  594. //++
  595. //
  596. // CEnumClusCfgIPAddresses::Clone
  597. //
  598. // Description:
  599. //
  600. // Arguments:
  601. //
  602. // Return Value:
  603. //
  604. // Remarks:
  605. // None.
  606. //
  607. //--
  608. //////////////////////////////////////////////////////////////////////////////
  609. STDMETHODIMP
  610. CEnumClusCfgIPAddresses::Clone(
  611. IEnumClusCfgIPAddresses ** ppEnumClusCfgIPAddressesOut
  612. )
  613. {
  614. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  615. HRESULT hr = S_OK;
  616. if ( ppEnumClusCfgIPAddressesOut == NULL )
  617. {
  618. hr = THR( E_POINTER );
  619. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_IPAddresses, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  620. goto Cleanup;
  621. } // if:
  622. hr = THR( E_NOTIMPL );
  623. Cleanup:
  624. HRETURN( hr );
  625. } //*** CEnumClusCfgIPAddresses::Clone
  626. //////////////////////////////////////////////////////////////////////////////
  627. //++
  628. //
  629. // CEnumClusCfgIPAddresses::Count
  630. //
  631. // Description:
  632. //
  633. // Arguments:
  634. //
  635. // Return Value:
  636. //
  637. // Remarks:
  638. // None.
  639. //
  640. //--
  641. //////////////////////////////////////////////////////////////////////////////
  642. STDMETHODIMP
  643. CEnumClusCfgIPAddresses::Count( DWORD * pnCountOut )
  644. {
  645. TraceFunc( "[IEnumClusCfgIPAddresses]" );
  646. HRESULT hr = S_OK;
  647. if ( pnCountOut == NULL )
  648. {
  649. hr = THR( E_POINTER );
  650. goto Cleanup;
  651. } // if:
  652. *pnCountOut = m_cAddresses;
  653. Cleanup:
  654. HRETURN( hr );
  655. } //*** CEnumClusCfgIPAddress::Count
  656. //*************************************************************************//
  657. /////////////////////////////////////////////////////////////////////////////
  658. // CEnumClusCfgIPAddresses class -- IClusCfgNetworkAdapterInfo Interface
  659. /////////////////////////////////////////////////////////////////////////////
  660. //////////////////////////////////////////////////////////////////////////////
  661. //++
  662. //
  663. // CEnumClusCfgIPAddresses::SetWbemObject
  664. //
  665. // Description:
  666. // Get the configuration from the passed in adapter and load this
  667. // enumerator.
  668. //
  669. // Arguments:
  670. // None.
  671. //
  672. // Return Value:
  673. //
  674. //
  675. // Remarks:
  676. // None.
  677. //
  678. //--
  679. //////////////////////////////////////////////////////////////////////////////
  680. STDMETHODIMP
  681. CEnumClusCfgIPAddresses::SetWbemObject(
  682. IWbemClassObject * pNetworkAdapterIn
  683. , bool * pfRetainObjectOut
  684. )
  685. {
  686. TraceFunc( "[IClusCfgNetworkAdapterInfo]" );
  687. Assert( pfRetainObjectOut != NULL );
  688. HRESULT hr = E_INVALIDARG;
  689. if ( pNetworkAdapterIn != NULL )
  690. {
  691. hr = STHR( HrGetAdapterConfiguration( pNetworkAdapterIn ) );
  692. *pfRetainObjectOut = true;
  693. } // if:
  694. HRETURN( hr );
  695. } //*** CEnumClusCfgIPAddresses::SetWbemObject
  696. //*************************************************************************//
  697. /////////////////////////////////////////////////////////////////////////////
  698. // CEnumClusCfgIPAddresses class -- Private Methods.
  699. /////////////////////////////////////////////////////////////////////////////
  700. //////////////////////////////////////////////////////////////////////////////
  701. //++
  702. //
  703. // CEnumClusCfgIPAddresses::HrInit
  704. //
  705. // Description:
  706. // Initialize this component.
  707. //
  708. // Arguments:
  709. // None.
  710. //
  711. // Return Value:
  712. //
  713. //
  714. // Remarks:
  715. // None.
  716. //
  717. //--
  718. //////////////////////////////////////////////////////////////////////////////
  719. HRESULT
  720. CEnumClusCfgIPAddresses::HrInit( void )
  721. {
  722. TraceFunc( "" );
  723. HRESULT hr = S_OK;
  724. // IUnknown
  725. Assert( m_cRef == 1 );
  726. HRETURN( hr );
  727. } //*** CEnumClusCfgIPAddresses::HrInit
  728. //////////////////////////////////////////////////////////////////////////////
  729. //++
  730. //
  731. // CEnumClusCfgIPAddresses::HrInit
  732. //
  733. // Description:
  734. // Initialize this component.
  735. //
  736. // Arguments:
  737. // ulIPAddressIn
  738. // ulIPSubnetIn
  739. //
  740. // Return Value:
  741. //
  742. //
  743. // Remarks:
  744. // None.
  745. //
  746. //--
  747. //////////////////////////////////////////////////////////////////////////////
  748. HRESULT
  749. CEnumClusCfgIPAddresses::HrInit( ULONG ulIPAddressIn, ULONG ulIPSubnetIn )
  750. {
  751. TraceFunc( "" );
  752. HRESULT hr;
  753. IUnknown * punk = NULL;
  754. // IUnknown
  755. Assert( m_cRef == 1 );
  756. hr = THR( HrCreateIPAddress( ulIPAddressIn, ulIPSubnetIn, &punk ) );
  757. if ( FAILED( hr ) )
  758. {
  759. goto Cleanup;
  760. } // if:
  761. hr = THR( HrAddIPAddressToArray( punk ) );
  762. Cleanup:
  763. if ( punk != NULL )
  764. {
  765. punk->Release();
  766. } // if:
  767. HRETURN( hr );
  768. } //*** CEnumClusCfgIPAddresses::HrInit( ulIPAddressIn, ulIPSubnetIn )
  769. //////////////////////////////////////////////////////////////////////////////
  770. //++
  771. //
  772. // CEnumClusCfgIPAddresses::HrGetAdapterConfiguration
  773. //
  774. // Description:
  775. // Get the configuration of the passed in adapter.
  776. //
  777. // Arguments:
  778. // None.
  779. //
  780. // Return Value:
  781. //
  782. //
  783. // Remarks:
  784. // None.
  785. //
  786. //--
  787. //////////////////////////////////////////////////////////////////////////////
  788. HRESULT
  789. CEnumClusCfgIPAddresses::HrGetAdapterConfiguration(
  790. IWbemClassObject * pNetworkAdapterIn
  791. )
  792. {
  793. TraceFunc( "" );
  794. HRESULT hr = S_OK;
  795. BSTR bstrQuery = NULL;
  796. BSTR bstrWQL = NULL;
  797. VARIANT var;
  798. WCHAR sz[ 256 ];
  799. IEnumWbemClassObject * pConfigurations = NULL;
  800. ULONG ulReturned;
  801. IWbemClassObject * pConfiguration = NULL;
  802. int cFound = 0;
  803. BSTR bstrAdapterName = NULL;
  804. int idx;
  805. HRESULT hrTemp;
  806. CLSID clsidMinorId;
  807. VariantInit( &var );
  808. bstrWQL = TraceSysAllocString( L"WQL" );
  809. if ( bstrWQL == NULL )
  810. {
  811. goto OutOfMemory;
  812. } // if:
  813. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"DeviceID", VT_BSTR, &var ) );
  814. if ( FAILED( hr ) )
  815. {
  816. goto Cleanup;
  817. } // if:
  818. hr = THR( StringCchPrintfW(
  819. sz, ARRAYSIZE( sz )
  820. , L"Associators of {Win32_NetworkAdapter.DeviceID='%ws'} where AssocClass=Win32_NetworkAdapterSetting"
  821. , var.bstrVal
  822. ) );
  823. if ( FAILED( hr ) )
  824. {
  825. goto Cleanup;
  826. } // if:
  827. bstrQuery = TraceSysAllocString( sz );
  828. if ( bstrQuery == NULL )
  829. {
  830. goto OutOfMemory;
  831. } // if:
  832. VariantClear( &var );
  833. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"NetConnectionID", VT_BSTR, &var ) );
  834. if ( FAILED( hr ) )
  835. {
  836. goto Cleanup;
  837. } // if:
  838. bstrAdapterName = TraceSysAllocString( var.bstrVal );
  839. if ( bstrAdapterName == NULL )
  840. {
  841. goto OutOfMemory;
  842. } // if:
  843. hr = THR( m_pIWbemServices->ExecQuery( bstrWQL, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pConfigurations ) );
  844. if ( FAILED( hr ) )
  845. {
  846. STATUS_REPORT_STRING_REF(
  847. TASKID_Major_Find_Devices,
  848. TASKID_Minor_WMI_NetworkAdapterSetting_Qry_Failed,
  849. IDS_ERROR_WMI_NETWORKADAPTERSETTINGS_QRY_FAILED,
  850. bstrAdapterName,
  851. IDS_ERROR_WMI_NETWORKADAPTERSETTINGS_QRY_FAILED_REF,
  852. hr
  853. );
  854. goto Cleanup;
  855. } // if:
  856. for ( idx = 0; ; idx++ )
  857. {
  858. hr = pConfigurations->Next( WBEM_INFINITE, 1, &pConfiguration, &ulReturned );
  859. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  860. {
  861. //
  862. // KB: 25-AUG-2000 GalenB
  863. //
  864. // WMI only supports one configuration per adapter!
  865. //
  866. Assert( idx < 1 );
  867. VariantClear( &var );
  868. hr = THR( HrGetWMIProperty( pConfiguration, L"IPEnabled", VT_BOOL, &var ) );
  869. if ( FAILED( hr ) )
  870. {
  871. goto Cleanup;
  872. } // if:
  873. //
  874. // If this configuration is not for TCP/IP then skip it.
  875. //
  876. if ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) )
  877. {
  878. hr = S_OK; // don't want a yellow bang in the UI
  879. STATUS_REPORT_REF(
  880. TASKID_Major_Find_Devices
  881. , TASKID_Minor_Not_Managed_Networks
  882. , IDS_INFO_NOT_MANAGED_NETWORKS
  883. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  884. , hr
  885. );
  886. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  887. if ( FAILED( hrTemp ) )
  888. {
  889. LogMsg( L"[SRV] Could not create a guid for a network adapter that has a non TCP configuration minor task ID" );
  890. clsidMinorId = IID_NULL;
  891. } // if:
  892. STATUS_REPORT_STRING_REF(
  893. TASKID_Minor_Not_Managed_Networks
  894. , clsidMinorId
  895. , IDS_WARN_NOT_IP_ENABLED
  896. , bstrAdapterName
  897. , IDS_WARN_NOT_IP_ENABLED_REF
  898. , hr
  899. );
  900. continue;
  901. } // if:
  902. hr = STHR( HrSaveIPAddresses( bstrAdapterName, pConfiguration ) );
  903. if ( FAILED( hr ) )
  904. {
  905. goto Cleanup;
  906. } // if:
  907. //
  908. // KB: 24-AUG-2000 GalenB
  909. //
  910. // If any configuration returns S_FALSE then we skip.
  911. //
  912. if ( hr == S_FALSE )
  913. {
  914. pConfiguration->Release();
  915. pConfiguration = NULL;
  916. continue;
  917. } // if:
  918. cFound++;
  919. pConfiguration->Release();
  920. pConfiguration = NULL;
  921. } // if:
  922. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  923. {
  924. hr = S_OK;
  925. break;
  926. } // else if:
  927. else
  928. {
  929. STATUS_REPORT_STRING_REF(
  930. TASKID_Major_Find_Devices
  931. , TASKID_Minor_WQL_Qry_Next_Failed
  932. , IDS_ERROR_WQL_QRY_NEXT_FAILED
  933. , bstrQuery
  934. , IDS_ERROR_WQL_QRY_NEXT_FAILED_REF
  935. , hr
  936. );
  937. goto Cleanup;
  938. } // else:
  939. } // for:
  940. //
  941. // If we didn't find any valid configurations then we should return S_FALSE
  942. // to tell the caller to ingore that adpater.
  943. //
  944. if ( cFound == 0 )
  945. {
  946. hr = S_OK; // don't want a yellow bang in the UI
  947. STATUS_REPORT_REF(
  948. TASKID_Major_Find_Devices
  949. , TASKID_Minor_Not_Managed_Networks
  950. , IDS_INFO_NOT_MANAGED_NETWORKS
  951. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  952. , hr
  953. );
  954. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  955. if ( FAILED( hrTemp ) )
  956. {
  957. LogMsg( L"[SRV] Could not create a guid for a network adapter that doesn't have a valid TCP configuration minor task ID" );
  958. clsidMinorId = IID_NULL;
  959. } // if:
  960. STATUS_REPORT_STRING_REF(
  961. TASKID_Minor_Not_Managed_Networks
  962. , clsidMinorId
  963. , IDS_WARN_NO_VALID_TCP_CONFIGS
  964. , bstrAdapterName
  965. , IDS_WARN_NO_VALID_TCP_CONFIGS_REF
  966. , hr
  967. );
  968. } // if:
  969. goto Cleanup;
  970. OutOfMemory:
  971. hr = THR( E_OUTOFMEMORY );
  972. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrGetAdapterConfiguration, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  973. Cleanup:
  974. VariantClear( &var );
  975. TraceSysFreeString( bstrQuery );
  976. TraceSysFreeString( bstrWQL );
  977. TraceSysFreeString( bstrAdapterName );
  978. if ( pConfiguration != NULL )
  979. {
  980. pConfiguration->Release();
  981. } // if:
  982. if ( pConfigurations != NULL )
  983. {
  984. pConfigurations->Release();
  985. } // if:
  986. HRETURN( hr );
  987. } //*** CEnumClusCfgIPAddresses::HrGetAdapterConfiguration
  988. /////////////////////////////////////////////////////////////////////////////
  989. //++
  990. //
  991. // CEnumClusCfgIPAddresses:HrAddIPAddressToArray
  992. //
  993. // Description:
  994. // Add the passed in address to the array of address.
  995. //
  996. // Arguments:
  997. //
  998. //
  999. // Return Value:
  1000. // S_OK
  1001. // Success
  1002. //
  1003. // E_OUTOFMEMORY
  1004. // Couldn't allocate memeory.
  1005. //
  1006. // Remarks:
  1007. // None.
  1008. //
  1009. //--
  1010. //////////////////////////////////////////////////////////////////////////////
  1011. HRESULT
  1012. CEnumClusCfgIPAddresses::HrAddIPAddressToArray( IUnknown * punkIn )
  1013. {
  1014. TraceFunc( "" );
  1015. HRESULT hr = S_OK;
  1016. IUnknown * ((*prgpunks)[]) = NULL;
  1017. prgpunks = (IUnknown *((*)[])) TraceReAlloc( m_prgAddresses, sizeof( IUnknown * ) * ( m_idxNext + 1 ), HEAP_ZERO_MEMORY );
  1018. if ( prgpunks == NULL )
  1019. {
  1020. hr = THR( E_OUTOFMEMORY );
  1021. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrAddIPAddressToArray, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1022. goto Cleanup;
  1023. } // if:
  1024. m_prgAddresses = prgpunks;
  1025. (*m_prgAddresses)[ m_idxNext++ ] = punkIn;
  1026. punkIn->AddRef();
  1027. m_cAddresses += 1;
  1028. Cleanup:
  1029. HRETURN( hr );
  1030. } //*** CEnumClusCfgIPAddresses::HrAddIPAddressToArray
  1031. //////////////////////////////////////////////////////////////////////////////
  1032. //++
  1033. //
  1034. // CEnumClusCfgIPAddresses::HrMakeDottedQuad
  1035. //
  1036. // Description:
  1037. // Take the passed in IP address and convert it into a dotted quad.
  1038. //
  1039. // Arguments:
  1040. // None.
  1041. //
  1042. // Return Value:
  1043. //
  1044. //
  1045. // Remarks:
  1046. // Internet Addresses
  1047. // Values specified using the ".'' notation take one of the following forms:
  1048. //
  1049. // a.b.c.d a.b.c a.b a
  1050. //
  1051. // When four parts are specified, each is interpreted as a byte of data and
  1052. // assigned, from left to right, to the 4 bytes of an Internet address. When
  1053. // an Internet address is viewed as a 32-bit integer quantity on the
  1054. // Intel architecture, the bytes referred to above appear as "d.c.b.a''.
  1055. // That is, the bytes on an Intel processor are ordered from right to left.
  1056. //
  1057. // The parts that make up an address in "." notation can be decimal, octal
  1058. // or hexadecimal as specified in the C language. Numbers that start
  1059. // with "0x" or "0X" imply hexadecimal. Numbers that start with "0" imply
  1060. // octal. All other numbers are interpreted as decimal.
  1061. //
  1062. //--
  1063. //////////////////////////////////////////////////////////////////////////////
  1064. HRESULT
  1065. CEnumClusCfgIPAddresses::HrMakeDottedQuad(
  1066. BSTR bstrDottedQuadIn,
  1067. ULONG * pulDottedQuadOut
  1068. )
  1069. {
  1070. TraceFunc( "" );
  1071. HRESULT hr = S_OK;
  1072. DWORD sc;
  1073. if ( pulDottedQuadOut == NULL )
  1074. {
  1075. hr = THR( E_POINTER );
  1076. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrMakeDottedQuad, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  1077. goto Cleanup;
  1078. } // if:
  1079. if ( bstrDottedQuadIn == NULL )
  1080. {
  1081. hr = THR( E_INVALIDARG );
  1082. LOG_STATUS_REPORT( L"CEnumClusCfgIPAddresses::HrMakeDottedQuad() was given an invalid argument.", hr );
  1083. goto Cleanup;
  1084. } // if:
  1085. sc = TW32( ClRtlTcpipStringToAddress( bstrDottedQuadIn, pulDottedQuadOut ) );
  1086. if ( sc != ERROR_SUCCESS )
  1087. {
  1088. hr = HRESULT_FROM_WIN32( sc );
  1089. STATUS_REPORT_STRING_REF(
  1090. TASKID_Major_Find_Devices
  1091. , TASKID_Minor_Dotted_Quad_Failed
  1092. , IDS_ERROR_CONVERT_TO_DOTTED_QUAD_FAILED
  1093. , bstrDottedQuadIn
  1094. , IDS_ERROR_CONVERT_TO_DOTTED_QUAD_FAILED_REF
  1095. , hr
  1096. );
  1097. goto Cleanup;
  1098. } // if:
  1099. Cleanup:
  1100. RETURN( hr );
  1101. } //*** CEnumClusCfgIPAddresses::HrMakeDottedQuad
  1102. //////////////////////////////////////////////////////////////////////////////
  1103. //++
  1104. //
  1105. // CEnumClusCfgIPAddresses::HrSaveIPAddresses
  1106. //
  1107. // Description:
  1108. // Add the IP addresses to the array.
  1109. //
  1110. // Arguments:
  1111. //
  1112. //
  1113. // Return Value:
  1114. //
  1115. //
  1116. // Remarks:
  1117. // None.
  1118. //
  1119. //--
  1120. //////////////////////////////////////////////////////////////////////////////
  1121. HRESULT
  1122. CEnumClusCfgIPAddresses::HrSaveIPAddresses(
  1123. BSTR bstrAdapterNameIn,
  1124. IWbemClassObject * pConfigurationIn
  1125. )
  1126. {
  1127. TraceFunc( "" );
  1128. Assert( bstrAdapterNameIn != NULL );
  1129. Assert( pConfigurationIn != NULL );
  1130. HRESULT hr;
  1131. VARIANT varIPAddress;
  1132. VARIANT varIPSubnet;
  1133. long lIPAddressesUpperBound;
  1134. long lIPAddressesLowerBound;
  1135. long lIPSubnetsUpperBound;
  1136. long lIPSubnetsLowerBound;
  1137. long idx;
  1138. ULONG ulIPAddress;
  1139. ULONG ulIPSubnet;
  1140. BSTR bstrIPAddress = NULL;
  1141. BSTR bstrIPSubnet = NULL;
  1142. IUnknown * punk = NULL;
  1143. IClusCfgIPAddressInfo * piccipai = NULL;
  1144. VariantInit( &varIPAddress );
  1145. VariantInit( &varIPSubnet );
  1146. hr = THR( HrGetWMIProperty( pConfigurationIn, L"IPAddress", ( VT_ARRAY | VT_BSTR ), &varIPAddress ) );
  1147. if ( FAILED( hr ) )
  1148. {
  1149. goto Cleanup;
  1150. } // if:
  1151. hr = THR( HrGetWMIProperty( pConfigurationIn, L"IPSubnet", ( VT_ARRAY | VT_BSTR ), &varIPSubnet ) );
  1152. if ( FAILED( hr ) )
  1153. {
  1154. goto Cleanup;
  1155. } // if:
  1156. hr = THR( SafeArrayGetUBound( varIPAddress.parray, 1, &lIPAddressesUpperBound ) );
  1157. if ( FAILED( hr ) )
  1158. {
  1159. goto Cleanup;
  1160. } // if:
  1161. hr = THR( SafeArrayGetUBound( varIPSubnet.parray, 1, &lIPSubnetsUpperBound ) );
  1162. if ( FAILED( hr ) )
  1163. {
  1164. goto Cleanup;
  1165. } // if:
  1166. Assert( lIPAddressesUpperBound == lIPSubnetsUpperBound );
  1167. if ( lIPAddressesUpperBound != lIPSubnetsUpperBound )
  1168. {
  1169. hr = S_FALSE;
  1170. LOG_STATUS_REPORT( L"[SRV] The IP address and IP subnet upper bound counts are not equal", hr );
  1171. goto Cleanup;
  1172. } // if:
  1173. hr = THR( SafeArrayGetLBound( varIPAddress.parray, 1, &lIPAddressesLowerBound ) );
  1174. if ( FAILED( hr ) )
  1175. {
  1176. goto Cleanup;
  1177. } // if:
  1178. hr = THR( SafeArrayGetLBound( varIPSubnet.parray, 1, &lIPSubnetsLowerBound ) );
  1179. if ( FAILED( hr ) )
  1180. {
  1181. goto Cleanup;
  1182. } // if:
  1183. Assert( lIPAddressesLowerBound == lIPSubnetsLowerBound );
  1184. if ( lIPAddressesLowerBound != lIPSubnetsLowerBound )
  1185. {
  1186. hr = S_FALSE;
  1187. LOG_STATUS_REPORT( L"[SRV] The IP address and IP subnet lower bound counts are not equal", hr );
  1188. goto Cleanup;
  1189. } // if:
  1190. //
  1191. // Loop through the IP addresses and store them in our own enumerator
  1192. // so that they can be returned by calls to the Next() method.
  1193. //
  1194. for ( idx = lIPAddressesLowerBound; idx <= lIPAddressesUpperBound; idx++ )
  1195. {
  1196. hr = THR( SafeArrayGetElement( varIPAddress.parray, &idx, &bstrIPAddress ) );
  1197. if ( FAILED( hr ) )
  1198. {
  1199. goto Cleanup;
  1200. } // if:
  1201. TraceMemoryAddBSTR( bstrIPAddress );
  1202. //
  1203. // It is expected that there is at least one IP address.
  1204. //
  1205. if ( *bstrIPAddress == L'\0' )
  1206. {
  1207. HRESULT hrTemp;
  1208. CLSID clsidMinorId;
  1209. STATUS_REPORT_REF(
  1210. TASKID_Major_Find_Devices
  1211. , TASKID_Minor_Not_Managed_Networks
  1212. , IDS_INFO_NOT_MANAGED_NETWORKS
  1213. , IDS_INFO_NOT_MANAGED_NETWORKS_REF
  1214. , S_OK
  1215. );
  1216. hrTemp = THR( CoCreateGuid( &clsidMinorId ) );
  1217. if ( FAILED( hrTemp ) )
  1218. {
  1219. LogMsg( L"[SRV] Could not create a guid for a network adapter with no IP addresses minor task ID" );
  1220. clsidMinorId = IID_NULL;
  1221. } // if:
  1222. STATUS_REPORT_STRING_REF(
  1223. TASKID_Minor_Not_Managed_Networks
  1224. , clsidMinorId
  1225. , IDS_WARN_NO_IP_ADDRESSES
  1226. , bstrAdapterNameIn
  1227. , IDS_WARN_NO_IP_ADDRESSES_REF
  1228. , hr
  1229. );
  1230. goto Cleanup;
  1231. } // end if:
  1232. hr = THR( SafeArrayGetElement( varIPSubnet.parray, &idx, &bstrIPSubnet ) );
  1233. if ( FAILED( hr ) )
  1234. {
  1235. goto Cleanup;
  1236. } // if:
  1237. Assert( bstrIPAddress != NULL );
  1238. Assert( wcslen( bstrIPAddress ) > 0 );
  1239. TraceMemoryAddBSTR( bstrIPSubnet );
  1240. LOG_STATUS_REPORT_STRING2( L"Found IP Address '%1!ws!' with subnet mask '%2!ws!'." , bstrIPAddress, bstrIPSubnet, hr );
  1241. hr = THR( HrMakeDottedQuad( bstrIPAddress, &ulIPAddress ) );
  1242. if ( FAILED( hr ) )
  1243. {
  1244. goto Cleanup;
  1245. } // if:
  1246. hr = THR( HrMakeDottedQuad( bstrIPSubnet, &ulIPSubnet ) );
  1247. if ( FAILED( hr ) )
  1248. {
  1249. goto Cleanup;
  1250. } // if:
  1251. TraceSysFreeString( bstrIPAddress );
  1252. bstrIPAddress = NULL;
  1253. TraceSysFreeString( bstrIPSubnet );
  1254. bstrIPSubnet = NULL;
  1255. hr = THR( HrCreateIPAddress( &punk ) );
  1256. if ( FAILED( hr ) )
  1257. {
  1258. goto Cleanup;
  1259. } // if:
  1260. hr = THR( punk->TypeSafeQI( IClusCfgIPAddressInfo, &piccipai ) );
  1261. if ( FAILED( hr ) )
  1262. {
  1263. goto Cleanup;
  1264. } // if:
  1265. hr = THR( piccipai->SetIPAddress( ulIPAddress ) );
  1266. if ( FAILED( hr ) )
  1267. {
  1268. goto Cleanup;
  1269. } // if:
  1270. hr = THR( piccipai->SetSubnetMask( ulIPSubnet ) );
  1271. if ( FAILED( hr ) )
  1272. {
  1273. goto Cleanup;
  1274. } // if:
  1275. piccipai->Release();
  1276. piccipai = NULL;
  1277. hr = THR( HrAddIPAddressToArray( punk ) );
  1278. if ( FAILED( hr ) )
  1279. {
  1280. goto Cleanup;
  1281. } // if:
  1282. punk->Release();
  1283. punk = NULL;
  1284. } // for: each IP address
  1285. Cleanup:
  1286. if ( piccipai != NULL )
  1287. {
  1288. piccipai->Release();
  1289. } // if:
  1290. if ( punk != NULL )
  1291. {
  1292. punk->Release();
  1293. } // if:
  1294. TraceSysFreeString( bstrIPAddress );
  1295. TraceSysFreeString( bstrIPSubnet );
  1296. VariantClear( &varIPAddress );
  1297. VariantClear( &varIPSubnet );
  1298. HRETURN( hr );
  1299. } //*** CEnumClusCfgIPAddresses::HrSaveIPAddresses
  1300. /////////////////////////////////////////////////////////////////////////////
  1301. //++
  1302. //
  1303. // CEnumClusCfgIPAddresses:HrCreateIPAddress
  1304. //
  1305. // Description:
  1306. //
  1307. //
  1308. // Arguments:
  1309. //
  1310. //
  1311. // Return Value:
  1312. // S_OK
  1313. // Success
  1314. //
  1315. // E_OUTOFMEMORY
  1316. // Couldn't allocate memeory.
  1317. //
  1318. // Remarks:
  1319. // None.
  1320. //
  1321. //--
  1322. //////////////////////////////////////////////////////////////////////////////
  1323. HRESULT
  1324. CEnumClusCfgIPAddresses::HrCreateIPAddress( IUnknown ** ppunkOut )
  1325. {
  1326. TraceFunc( "" );
  1327. Assert( ppunkOut != NULL );
  1328. HRESULT hr;
  1329. IUnknown * punk = NULL;
  1330. hr = THR( CClusCfgIPAddressInfo::S_HrCreateInstance( &punk ) );
  1331. if ( FAILED( hr ) )
  1332. {
  1333. goto Cleanup;
  1334. } // if:
  1335. punk = TraceInterface( L"CClusCfgIPAddressInfo", IUnknown, punk, 1 );
  1336. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1337. if ( FAILED( hr ) )
  1338. {
  1339. goto Cleanup;
  1340. } // if:
  1341. hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1342. if ( FAILED( hr ) )
  1343. {
  1344. goto Cleanup;
  1345. } // if:
  1346. *ppunkOut = punk;
  1347. (*ppunkOut)->AddRef();
  1348. Cleanup:
  1349. if ( punk != NULL )
  1350. {
  1351. punk->Release();
  1352. } // if:
  1353. HRETURN( hr );
  1354. } //*** CEnumClusCfgIPAddresses::HrCreateIPAddress
  1355. /////////////////////////////////////////////////////////////////////////////
  1356. //++
  1357. //
  1358. // CEnumClusCfgIPAddresses:HrCreateIPAddress
  1359. //
  1360. // Description:
  1361. //
  1362. //
  1363. // Arguments:
  1364. //
  1365. //
  1366. // Return Value:
  1367. // S_OK
  1368. // Success
  1369. //
  1370. // E_OUTOFMEMORY
  1371. // Couldn't allocate memeory.
  1372. //
  1373. // Remarks:
  1374. // None.
  1375. //
  1376. //--
  1377. //////////////////////////////////////////////////////////////////////////////
  1378. HRESULT
  1379. CEnumClusCfgIPAddresses::HrCreateIPAddress(
  1380. ULONG ulIPAddressIn
  1381. , ULONG ulIPSubnetIn
  1382. , IUnknown ** ppunkOut
  1383. )
  1384. {
  1385. TraceFunc( "" );
  1386. Assert( ppunkOut != NULL );
  1387. HRESULT hr;
  1388. IUnknown * punk = NULL;
  1389. hr = THR( CClusCfgIPAddressInfo::S_HrCreateInstance( ulIPAddressIn, ulIPSubnetIn, &punk ) );
  1390. if ( FAILED( hr ) )
  1391. {
  1392. goto Cleanup;
  1393. } // if:
  1394. punk = TraceInterface( L"CClusCfgIPAddressInfo", IUnknown, punk, 1 );
  1395. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1396. if ( FAILED( hr ) )
  1397. {
  1398. goto Cleanup;
  1399. } // if:
  1400. hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  1401. if ( FAILED( hr ) )
  1402. {
  1403. goto Cleanup;
  1404. } // if:
  1405. *ppunkOut = punk;
  1406. (*ppunkOut)->AddRef();
  1407. Cleanup:
  1408. if ( punk != NULL )
  1409. {
  1410. punk->Release();
  1411. } // if:
  1412. HRETURN( hr );
  1413. } //*** CEnumClusCfgIPAddresses::HrCreateIPAddress