Source code of Windows XP (NT5)
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.

1958 lines
44 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgClusterInfo.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CClusCfgClusterInfo
  10. // class.
  11. //
  12. // The class CClusCfgClusterInfo is the representation of a
  13. // cluster. It implements the IClusCfgClusterInfo interface.
  14. //
  15. // Documentation:
  16. //
  17. // Header File:
  18. // CClusCfgClusterInfo.h
  19. //
  20. // Maintained By:
  21. // Galen Barbee (GalenB) 22-FEB-2000
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24. //////////////////////////////////////////////////////////////////////////////
  25. // Include Files
  26. //////////////////////////////////////////////////////////////////////////////
  27. #include "pch.h"
  28. #include <PropList.h>
  29. #include <ClusRtl.h>
  30. #include <windns.h>
  31. #include <commctrl.h>
  32. #include <ClusCfgPrivate.h>
  33. #include <ClusterUtils.h>
  34. #include "CClusCfgClusterInfo.h"
  35. #include "CClusCfgCredentials.h"
  36. //////////////////////////////////////////////////////////////////////////////
  37. // Constant Definitions
  38. //////////////////////////////////////////////////////////////////////////////
  39. DEFINE_THISCLASS( "CClusCfgClusterInfo" );
  40. //*************************************************************************//
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CClusCfgClusterInfo class
  43. /////////////////////////////////////////////////////////////////////////////
  44. //////////////////////////////////////////////////////////////////////////////
  45. //++
  46. //
  47. // CClusCfgClusterInfo::S_HrCreateInstance
  48. //
  49. // Description:
  50. // Create a CClusCfgClusterInfo instance.
  51. //
  52. // Arguments:
  53. // None.
  54. //
  55. // Return Values:
  56. // S_OK
  57. // Success.
  58. //
  59. // E_POINTER
  60. // A passed in argument is NULL.
  61. //
  62. // E_OUTOFMEMORY
  63. // Out of memory.
  64. //
  65. // Other HRESULT error.
  66. //
  67. //--
  68. //////////////////////////////////////////////////////////////////////////////
  69. HRESULT
  70. CClusCfgClusterInfo::S_HrCreateInstance( IUnknown ** ppunkOut )
  71. {
  72. TraceFunc( "" );
  73. HRESULT hr;
  74. CClusCfgClusterInfo * lpccs = NULL;
  75. if ( ppunkOut == NULL )
  76. {
  77. hr = THR( E_POINTER );
  78. goto Cleanup;
  79. } // if:
  80. lpccs = new CClusCfgClusterInfo();
  81. if ( lpccs == NULL )
  82. {
  83. hr = THR( E_OUTOFMEMORY );
  84. goto Cleanup;
  85. } // if: error allocating object
  86. hr = THR( lpccs->HrInit() );
  87. if ( FAILED( hr ) )
  88. {
  89. goto Cleanup;
  90. } // if: HrInit() failed
  91. hr = THR( lpccs->TypeSafeQI( IUnknown, ppunkOut ) );
  92. Cleanup:
  93. if ( lpccs != NULL )
  94. {
  95. lpccs->Release();
  96. } // if:
  97. if ( FAILED( hr ) )
  98. {
  99. LogMsg( L"[SRV] CClusCfgClusterInfo::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  100. } // if:
  101. HRETURN( hr );
  102. } //*** CClusCfgClusterInfo::S_HrCreateInstance
  103. //////////////////////////////////////////////////////////////////////////////
  104. //++
  105. //
  106. // CClusCfgClusterInfo::CClusCfgClusterInfo
  107. //
  108. // Description:
  109. // Constructor of the CClusCfgClusterInfo class. This initializes
  110. // the m_cRef variable to 1 instead of 0 to account of possible
  111. // QueryInterface failure in DllGetClassObject.
  112. //
  113. // Arguments:
  114. // None.
  115. //
  116. // Return Value:
  117. // None.
  118. //
  119. // Remarks:
  120. // None.
  121. //
  122. //--
  123. //////////////////////////////////////////////////////////////////////////////
  124. CClusCfgClusterInfo::CClusCfgClusterInfo( void )
  125. : m_cRef( 1 )
  126. , m_lcid( LOCALE_NEUTRAL )
  127. {
  128. TraceFunc( "" );
  129. // Increment the count of components in memory so the DLL hosting this
  130. // object cannot be unloaded.
  131. InterlockedIncrement( &g_cObjects );
  132. Assert( m_picccCallback == NULL );
  133. Assert( m_bstrName == NULL );
  134. Assert( m_piccniNetwork == NULL );
  135. Assert( m_ulIPDottedQuad == 0 );
  136. Assert( m_ulSubnetDottedQuad == 0 );
  137. Assert( m_punkServiceAccountCredentials == NULL );
  138. Assert( m_pIWbemServices == NULL );
  139. Assert( m_ecmCommitChangesMode == cmUNKNOWN );
  140. Assert( m_bstrBindingString == NULL );
  141. TraceFuncExit();
  142. } //*** CClusCfgClusterInfo::CClusCfgClusterInfo
  143. //////////////////////////////////////////////////////////////////////////////
  144. //++
  145. //
  146. // CClusCfgClusterInfo::~CClusCfgClusterInfo
  147. //
  148. // Description:
  149. // Desstructor of the CClusCfgClusterInfo class.
  150. //
  151. // Arguments:
  152. // None.
  153. //
  154. // Return Value:
  155. // None.
  156. //
  157. // Remarks:
  158. // None.
  159. //
  160. //--
  161. //////////////////////////////////////////////////////////////////////////////
  162. CClusCfgClusterInfo::~CClusCfgClusterInfo( void )
  163. {
  164. TraceFunc( "" );
  165. if ( m_picccCallback != NULL )
  166. {
  167. m_picccCallback->Release();
  168. } // if:
  169. if ( m_piccniNetwork != NULL )
  170. {
  171. m_piccniNetwork->Release();
  172. } // if:
  173. if ( m_punkServiceAccountCredentials != NULL )
  174. {
  175. m_punkServiceAccountCredentials->Release();
  176. } // if:
  177. if ( m_pIWbemServices != NULL )
  178. {
  179. m_pIWbemServices->Release();
  180. } // if:
  181. TraceSysFreeString( m_bstrName );
  182. TraceSysFreeString( m_bstrBindingString );
  183. // There's going to be one less component in memory. Decrement component count.
  184. InterlockedDecrement( &g_cObjects );
  185. TraceFuncExit();
  186. } //*** CClusCfgClusterInfo::~CClusCfgClusterInfo
  187. //*************************************************************************//
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CClusCfgClusterInfo -- IUknkown interface.
  190. /////////////////////////////////////////////////////////////////////////////
  191. //////////////////////////////////////////////////////////////////////////////
  192. //++
  193. //
  194. // STDMETHODIMP_( ULONG )
  195. // CClusCfgClusterInfo:: [IUNKNOWN] AddRef
  196. //
  197. // Description:
  198. // Increment the reference count of this object by one.
  199. //
  200. // Arguments:
  201. // None.
  202. //
  203. // Return Value:
  204. // The new reference count.
  205. //
  206. // Remarks:
  207. // None.
  208. //
  209. //--
  210. //////////////////////////////////////////////////////////////////////////////
  211. STDMETHODIMP_( ULONG )
  212. CClusCfgClusterInfo::AddRef( void )
  213. {
  214. TraceFunc( "[IUnknown]" );
  215. InterlockedIncrement( & m_cRef );
  216. RETURN( m_cRef );
  217. } //*** CClusCfgClusterInfo::AddRef
  218. //////////////////////////////////////////////////////////////////////////////
  219. //++
  220. //
  221. // STDMETHODIMP_( ULONG )
  222. // CClusCfgClusterInfo:: [IUNKNOWN] Release
  223. //
  224. // Description:
  225. // Decrement the reference count of this object by one.
  226. //
  227. // Arguments:
  228. // None.
  229. //
  230. // Return Value:
  231. // The new reference count.
  232. //
  233. // Remarks:
  234. // None.
  235. //
  236. //--
  237. //////////////////////////////////////////////////////////////////////////////
  238. STDMETHODIMP_( ULONG )
  239. CClusCfgClusterInfo::Release( void )
  240. {
  241. TraceFunc( "[IUnknown]" );
  242. LONG cRef;
  243. cRef = InterlockedDecrement( &m_cRef );
  244. if ( cRef == 0 )
  245. {
  246. TraceDo( delete this );
  247. } // if: reference count equal to zero
  248. RETURN( cRef );
  249. } //*** CClusCfgClusterInfo::Release
  250. //////////////////////////////////////////////////////////////////////////////
  251. //++
  252. //
  253. // CClusCfgClusterInfo:: [INKNOWN] QueryInterface
  254. //
  255. // Description:
  256. // Query this object for the passed in interface.
  257. //
  258. // Arguments:
  259. // IN REFIID riid,
  260. // Id of interface requested.
  261. //
  262. // OUT void ** ppv
  263. // Pointer to the requested interface.
  264. //
  265. // Return Value:
  266. // S_OK
  267. // If the interface is available on this object.
  268. //
  269. // E_NOINTERFACE
  270. // If the interface is not available.
  271. //
  272. // Remarks:
  273. // None.
  274. //
  275. //--
  276. //////////////////////////////////////////////////////////////////////////////
  277. STDMETHODIMP
  278. CClusCfgClusterInfo::QueryInterface( REFIID riid, void ** ppv )
  279. {
  280. TraceQIFunc( riid, ppv );
  281. HRESULT hr = E_NOINTERFACE;
  282. if ( IsEqualIID( riid, IID_IUnknown ) )
  283. {
  284. *ppv = static_cast< IClusCfgClusterInfo * >( this );
  285. hr = S_OK;
  286. } // if: IUnknown
  287. else if ( IsEqualIID( riid, IID_IClusCfgClusterInfo ) )
  288. {
  289. *ppv = TraceInterface( __THISCLASS__, IClusCfgClusterInfo, this, 0 );
  290. hr = S_OK;
  291. } // else if:
  292. else if ( IsEqualIID( riid, IID_IClusCfgInitialize ) )
  293. {
  294. *ppv = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  295. hr = S_OK;
  296. } // else if:
  297. else if ( IsEqualIID( riid, IID_IClusCfgSetClusterNodeInfo ) )
  298. {
  299. *ppv = TraceInterface( __THISCLASS__, IClusCfgSetClusterNodeInfo, this, 0 );
  300. hr = S_OK;
  301. } // else if:
  302. else if ( IsEqualIID( riid, IID_IClusCfgWbemServices ) )
  303. {
  304. *ppv = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  305. hr = S_OK;
  306. } // else if:
  307. if ( SUCCEEDED( hr ) )
  308. {
  309. ((IUnknown *) *ppv)->AddRef( );
  310. } // if: success
  311. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  312. } //*** CClusCfgClusterInfo::QueryInterface
  313. //*************************************************************************//
  314. /////////////////////////////////////////////////////////////////////////////
  315. // CClusCfgClusterInfo -- IClusCfgWbemServices interface.
  316. /////////////////////////////////////////////////////////////////////////////
  317. //////////////////////////////////////////////////////////////////////////////
  318. //++
  319. //
  320. // CClusCfgClusterInfo::SetWbemServices
  321. //
  322. // Description:
  323. // Set the WBEM services provider.
  324. //
  325. // Arguments:
  326. // IN IWbemServices pIWbemServicesIn
  327. //
  328. // Return Value:
  329. // S_OK
  330. // Success
  331. //
  332. // E_POINTER
  333. // The pIWbemServicesIn param is NULL.
  334. //
  335. // Remarks:
  336. // None.
  337. //
  338. //--
  339. //////////////////////////////////////////////////////////////////////////////
  340. STDMETHODIMP
  341. CClusCfgClusterInfo::SetWbemServices( IWbemServices * pIWbemServicesIn )
  342. {
  343. TraceFunc( "[IClusCfgWbemServices]" );
  344. HRESULT hr = S_OK;
  345. if ( pIWbemServicesIn == NULL )
  346. {
  347. hr = THR( E_POINTER );
  348. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_SetWbemServices_Cluster, IDS_ERROR_NULL_POINTER, hr );
  349. goto Cleanup;
  350. } // if:
  351. m_pIWbemServices = pIWbemServicesIn;
  352. m_pIWbemServices->AddRef();
  353. Cleanup:
  354. HRETURN( hr );
  355. } //*** CClusCfgClusterInfo::SetWbemServices
  356. //*************************************************************************//
  357. /////////////////////////////////////////////////////////////////////////////
  358. // CClusCfgClusterInfo -- IClusCfgInitialze interface.
  359. /////////////////////////////////////////////////////////////////////////////
  360. //////////////////////////////////////////////////////////////////////////////
  361. //++
  362. //
  363. // CClusCfgClusterInfo::Initialize
  364. //
  365. // Description:
  366. // Initialize this component.
  367. //
  368. // Arguments:
  369. // IN IUknown * punkCallbackIn
  370. //
  371. // IN LCID lcidIn
  372. //
  373. // Return Value:
  374. // S_OK
  375. // Success
  376. //
  377. // Remarks:
  378. // None.
  379. //
  380. //--
  381. //////////////////////////////////////////////////////////////////////////////
  382. STDMETHODIMP
  383. CClusCfgClusterInfo::Initialize(
  384. IUnknown * punkCallbackIn,
  385. LCID lcidIn
  386. )
  387. {
  388. TraceFunc( "[IClusCfgInitialize]" );
  389. HRESULT hr = S_OK;
  390. HRESULT hrTemp = S_OK;
  391. HCLUSTER hCluster = NULL;
  392. DWORD sc;
  393. DWORD dwState;
  394. BSTR bstrDomain = NULL;
  395. BSTR bstrClusterName = NULL;
  396. m_lcid = lcidIn;
  397. Assert( m_picccCallback == NULL );
  398. if ( punkCallbackIn == NULL )
  399. {
  400. hr = THR( E_POINTER );
  401. goto Cleanup;
  402. } // if:
  403. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  404. if ( FAILED( hr ) )
  405. {
  406. goto Cleanup;
  407. } // if:
  408. if ( m_fIsClusterNode )
  409. {
  410. sc = TW32( GetNodeClusterState( NULL, &dwState ) );
  411. if ( sc != ERROR_SUCCESS )
  412. {
  413. hr = HRESULT_FROM_WIN32( sc );
  414. LOG_STATUS_REPORT( L"CClusCfgClusterInfo::Initialize() GetNodeClusterState() failed.", hr );
  415. goto Cleanup;
  416. } // if:
  417. Assert( ( dwState == ClusterStateRunning ) || ( dwState == ClusterStateNotRunning ) );
  418. if ( dwState == ClusterStateNotRunning )
  419. {
  420. //
  421. // Set hrTemp to S_FALSE so a warning is shown in the UI.
  422. //
  423. hrTemp = S_FALSE;
  424. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_Node_Down, IDS_ERROR_NODE_DOWN, hrTemp );
  425. LogMsg( L"[SRV] The cluster service is down in this node." );
  426. //
  427. // Set hrTemp to HR_S_RPC_S_CLUSTER_NODE_DOWN so we can return this later.
  428. //
  429. hrTemp = HR_S_RPC_S_CLUSTER_NODE_DOWN;
  430. goto ClusterNodeDown;
  431. } // if:
  432. hCluster = OpenCluster( NULL );
  433. if ( hCluster == NULL )
  434. {
  435. sc = TW32( GetLastError() );
  436. hr = HRESULT_FROM_WIN32( sc );
  437. LOG_STATUS_REPORT( L"CClusCfgClusterInfo::Initialize() OpenCluster() failed.", hr );
  438. goto Cleanup;
  439. } // if:
  440. hr = THR( HrGetClusterInformation( hCluster, &bstrClusterName, NULL ) );
  441. if ( FAILED( hr ) )
  442. {
  443. goto Cleanup;
  444. } // if:
  445. hr = THR( HrGetComputerName( ComputerNamePhysicalDnsDomain, &bstrDomain ) );
  446. if ( FAILED( hr ) )
  447. {
  448. goto Cleanup;
  449. } // if:
  450. TraceSysFreeString( m_bstrName );
  451. m_bstrName = TraceSysAllocStringLen( NULL, (UINT)( wcslen( bstrClusterName ) + wcslen( bstrDomain ) + 1 ) );
  452. if ( m_bstrName == NULL )
  453. {
  454. hr = THR( E_OUTOFMEMORY );
  455. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_Initialize, IDS_ERROR_OUTOFMEMORY, hr );
  456. goto Cleanup;
  457. } // if:
  458. wcscpy( m_bstrName, bstrClusterName );
  459. wcscat( m_bstrName, L"." );
  460. wcscat( m_bstrName, bstrDomain );
  461. hr = THR( HrLoadNetworkInfo( hCluster ) );
  462. if ( FAILED( hr ) )
  463. {
  464. goto Cleanup;
  465. } // if:
  466. ClusterNodeDown:
  467. hr = THR( HrLoadCredentials() );
  468. if ( SUCCEEDED( hr ) )
  469. {
  470. //
  471. // If successful then use hrTemp since it may contain a more important status code.
  472. //
  473. hr = hrTemp;
  474. LogMsg( L"[SRV] CClusCfgClusterInfo::Initialize() returning (hr=%#08x)", hr );
  475. } // if:
  476. } // if:
  477. Cleanup:
  478. TraceSysFreeString( bstrDomain );
  479. TraceSysFreeString( bstrClusterName );
  480. if ( hCluster != NULL )
  481. {
  482. CloseCluster( hCluster );
  483. } // if:
  484. HRETURN( hr );
  485. } //*** CClusCfgClusterInfo::Initialize
  486. //*************************************************************************//
  487. /////////////////////////////////////////////////////////////////////////////
  488. // CClusCfgClusterInfo -- IClusCfgClusterInfo interface.
  489. /////////////////////////////////////////////////////////////////////////////
  490. //////////////////////////////////////////////////////////////////////////////
  491. //++
  492. //
  493. // CClusCfgClusterInfo::GetCommitMode
  494. //
  495. // Description:
  496. // Get the mode of processing for this node when commit changes is
  497. // called.
  498. //
  499. // Arguments:
  500. //
  501. // Return Value:
  502. // S_OK
  503. // Success.
  504. //
  505. // E_POINTER
  506. // pecmCurrentModeOut is NULL.
  507. //
  508. // Other Win32 error as HRESULT if a failure occurs.
  509. //
  510. // Remarks:
  511. // None.
  512. //
  513. //--
  514. //////////////////////////////////////////////////////////////////////////////
  515. STDMETHODIMP
  516. CClusCfgClusterInfo::GetCommitMode( ECommitMode * pecmCurrentModeOut )
  517. {
  518. TraceFunc( "[IClusCfgClusterInfo]" );
  519. HRESULT hr = S_OK;
  520. if ( pecmCurrentModeOut == NULL )
  521. {
  522. hr = THR( E_POINTER );
  523. goto Cleanup;
  524. } // if:
  525. *pecmCurrentModeOut = m_ecmCommitChangesMode;
  526. Cleanup:
  527. HRETURN( hr );
  528. } //*** CClusCfgClusterInfo::GetCommitMode
  529. //////////////////////////////////////////////////////////////////////////////
  530. //++
  531. //
  532. // CClusCfgClusterInfo::SetCommitMode
  533. //
  534. // Description:
  535. //
  536. // Arguments:
  537. //
  538. // Return Value:
  539. //
  540. // Remarks:
  541. // None.
  542. //
  543. //--
  544. //////////////////////////////////////////////////////////////////////////////
  545. STDMETHODIMP
  546. CClusCfgClusterInfo::SetCommitMode( ECommitMode ecmCurrentModeIn )
  547. {
  548. TraceFunc( "[IClusCfgClusterInfo]" );
  549. HRESULT hr = S_OK;
  550. m_ecmCommitChangesMode = ecmCurrentModeIn;
  551. HRETURN( hr );
  552. } //*** CClusCfgClusterInfo::SetCommitMode
  553. //////////////////////////////////////////////////////////////////////////////
  554. //++
  555. //
  556. // CClusCfgClusterInfo::GetName
  557. //
  558. // Description:
  559. //
  560. // Arguments:
  561. //
  562. // Return Value:
  563. //
  564. // Remarks:
  565. // None.
  566. //
  567. //--
  568. //////////////////////////////////////////////////////////////////////////////
  569. STDMETHODIMP
  570. CClusCfgClusterInfo::GetName( BSTR * pbstrNameOut )
  571. {
  572. TraceFunc( "[IClusCfgClusterInfo]" );
  573. HRESULT hr = S_OK;
  574. if ( pbstrNameOut == NULL )
  575. {
  576. hr = THR( E_POINTER );
  577. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_ClusterInfo_GetName_Pointer, IDS_ERROR_NULL_POINTER, hr );
  578. goto Cleanup;
  579. } // if:
  580. if ( m_bstrName == NULL )
  581. {
  582. hr = S_FALSE;
  583. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Get_Cluster_Name, IDS_ERROR_CLUSTER_NAME_NOT_FOUND, hr );
  584. goto Cleanup;
  585. } // if:
  586. *pbstrNameOut = SysAllocString( m_bstrName );
  587. if ( *pbstrNameOut == NULL )
  588. {
  589. hr = THR( E_OUTOFMEMORY );
  590. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetName_Memory, IDS_ERROR_OUTOFMEMORY, hr );
  591. } // if:
  592. Cleanup:
  593. HRETURN( hr );
  594. } //*** CClusCfgClusterInfo::GetName
  595. //////////////////////////////////////////////////////////////////////////////
  596. //++
  597. //
  598. // CClusCfgClusterInfo::SetName
  599. //
  600. // Description:
  601. //
  602. // Arguments:
  603. //
  604. // Return Value:
  605. //
  606. // Remarks:
  607. // None.
  608. //
  609. //--
  610. //////////////////////////////////////////////////////////////////////////////
  611. STDMETHODIMP
  612. CClusCfgClusterInfo::SetName( LPCWSTR pcszNameIn )
  613. {
  614. TraceFunc1( "[IClusCfgClusterInfo] pcszNameIn = '%ls'", pcszNameIn == NULL ? L"<null>" : pcszNameIn );
  615. HRESULT hr;
  616. if ( pcszNameIn == NULL )
  617. {
  618. hr = THR( E_INVALIDARG );
  619. goto Cleanup;
  620. }
  621. TraceSysFreeString( m_bstrName );
  622. m_bstrName = NULL;
  623. m_bstrName = TraceSysAllocString( pcszNameIn );
  624. if ( m_bstrName == NULL )
  625. {
  626. hr = THR( E_OUTOFMEMORY );
  627. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_SetName_Cluster, IDS_ERROR_OUTOFMEMORY, hr );
  628. goto Cleanup;
  629. } // if:
  630. hr = S_OK;
  631. Cleanup:
  632. HRETURN( hr );
  633. } //*** CClusCfgClusterInfo::SetName
  634. //////////////////////////////////////////////////////////////////////////////
  635. //++
  636. //
  637. // CClusCfgClusterInfo::GetIPAddress
  638. //
  639. // Description:
  640. //
  641. // Arguments:
  642. //
  643. // Return Value:
  644. //
  645. // Remarks:
  646. // None.
  647. //
  648. //--
  649. //////////////////////////////////////////////////////////////////////////////
  650. STDMETHODIMP
  651. CClusCfgClusterInfo::GetIPAddress( ULONG * pulDottedQuadOut )
  652. {
  653. TraceFunc( "[IClusCfgClusterInfo]" );
  654. HRESULT hr = S_OK;
  655. if ( pulDottedQuadOut == NULL )
  656. {
  657. hr = THR( E_POINTER );
  658. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetIPAddress, IDS_ERROR_NULL_POINTER, hr );
  659. goto Cleanup;
  660. } // if:
  661. if ( m_ulIPDottedQuad == 0 )
  662. {
  663. hr = S_FALSE;
  664. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Get_Cluster_IP_Address, IDS_ERROR_CLUSTER_IP_ADDRESS_NOT_FOUND, hr );
  665. goto Cleanup;
  666. } // if:
  667. *pulDottedQuadOut = m_ulIPDottedQuad;
  668. Cleanup:
  669. HRETURN( hr );
  670. } //*** CClusCfgClusterInfo::GetIPAddress
  671. //////////////////////////////////////////////////////////////////////////////
  672. //++
  673. //
  674. // CClusCfgClusterInfo::SetIPAddress
  675. //
  676. // Description:
  677. //
  678. // Arguments:
  679. //
  680. // Return Value:
  681. //
  682. // Remarks:
  683. // None.
  684. //
  685. //--
  686. //////////////////////////////////////////////////////////////////////////////
  687. STDMETHODIMP
  688. CClusCfgClusterInfo::SetIPAddress( ULONG ulDottedQuadIn )
  689. {
  690. TraceFunc( "[IClusCfgClusterInfo]" );
  691. HRESULT hr = S_OK;
  692. m_ulIPDottedQuad = ulDottedQuadIn;
  693. HRETURN( hr );
  694. } //*** CClusCfgClusterInfo::SetIPAddress
  695. //////////////////////////////////////////////////////////////////////////////
  696. //++
  697. //
  698. // CClusCfgClusterInfo::GetSubnetMask
  699. //
  700. // Description:
  701. //
  702. // Arguments:
  703. //
  704. // Return Value:
  705. //
  706. // Remarks:
  707. // None.
  708. //
  709. //--
  710. //////////////////////////////////////////////////////////////////////////////
  711. STDMETHODIMP
  712. CClusCfgClusterInfo::GetSubnetMask( ULONG * pulDottedQuadOut )
  713. {
  714. TraceFunc( "[IClusCfgClusterInfo]" );
  715. HRESULT hr = S_OK;
  716. if ( pulDottedQuadOut == NULL )
  717. {
  718. hr = THR( E_POINTER );
  719. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_ClusterInfo_GetSubnetMask, IDS_ERROR_NULL_POINTER, hr );
  720. goto Cleanup;
  721. } // if:
  722. if ( m_ulSubnetDottedQuad == 0 )
  723. {
  724. hr = S_FALSE;
  725. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Get_Cluster_IP_Subnet, IDS_ERROR_CLUSTER_IP_SUBNET_NOT_FOUND, hr );
  726. goto Cleanup;
  727. } // if:
  728. *pulDottedQuadOut = m_ulSubnetDottedQuad;
  729. Cleanup:
  730. HRETURN( hr );
  731. } //*** CClusCfgClusterInfo::GetSubnetMask
  732. //////////////////////////////////////////////////////////////////////////////
  733. //++
  734. //
  735. // CClusCfgClusterInfo::SetSubnetMask
  736. //
  737. // Description:
  738. //
  739. // Arguments:
  740. //
  741. // Return Value:
  742. //
  743. // Remarks:
  744. // None.
  745. //
  746. //--
  747. //////////////////////////////////////////////////////////////////////////////
  748. STDMETHODIMP
  749. CClusCfgClusterInfo::SetSubnetMask( ULONG ulDottedQuadIn )
  750. {
  751. TraceFunc( "[IClusCfgClusterInfo]" );
  752. HRESULT hr = S_OK;
  753. m_ulSubnetDottedQuad = ulDottedQuadIn;
  754. HRETURN( hr );
  755. } //*** CClusCfgClusterInfo::SetSubnetMask
  756. //////////////////////////////////////////////////////////////////////////////
  757. //++
  758. //
  759. // CClusCfgClusterInfo::GetNetworkInfo
  760. //
  761. // Description:
  762. //
  763. // Arguments:
  764. //
  765. // Return Value:
  766. //
  767. // Remarks:
  768. // None.
  769. //
  770. //--
  771. //////////////////////////////////////////////////////////////////////////////
  772. STDMETHODIMP
  773. CClusCfgClusterInfo::GetNetworkInfo(
  774. IClusCfgNetworkInfo ** ppiccniOut
  775. )
  776. {
  777. TraceFunc( "[IClusCfgClusterInfo]" );
  778. Assert( m_piccniNetwork != NULL );
  779. HRESULT hr = S_OK;
  780. if ( ppiccniOut == NULL )
  781. {
  782. hr = THR( E_POINTER );
  783. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetNetworkInfo, IDS_ERROR_NULL_POINTER, hr );
  784. goto Cleanup;
  785. } // if:
  786. if ( m_piccniNetwork == NULL )
  787. {
  788. hr = S_FALSE;
  789. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Get_Cluster_Networks, IDS_ERROR_CLUSTER_NETWORKS_NOT_FOUND, hr );
  790. goto Cleanup;
  791. } // if:
  792. *ppiccniOut = TraceInterface( L"CClusCfgNetworkInfo", IClusCfgNetworkInfo, m_piccniNetwork, 0 );
  793. (*ppiccniOut)->AddRef();
  794. Cleanup:
  795. HRETURN( hr );
  796. } //*** CClusCfgClusterInfo::GetNetworkInfo
  797. //////////////////////////////////////////////////////////////////////////////
  798. //++
  799. //
  800. // CClusCfgClusterInfo::SetNetworkInfo
  801. //
  802. // Description:
  803. //
  804. // Arguments:
  805. //
  806. // Return Value:
  807. //
  808. // Remarks:
  809. // None.
  810. //
  811. //--
  812. //////////////////////////////////////////////////////////////////////////////
  813. STDMETHODIMP
  814. CClusCfgClusterInfo::SetNetworkInfo(
  815. IClusCfgNetworkInfo * piccniIn
  816. )
  817. {
  818. TraceFunc( "[IClusCfgClusterInfo]" );
  819. HRESULT hr = S_OK;
  820. if ( m_piccniNetwork != NULL )
  821. {
  822. m_piccniNetwork->Release();
  823. } // if:
  824. Assert( piccniIn != NULL );
  825. m_piccniNetwork = piccniIn;
  826. m_piccniNetwork->AddRef();
  827. HRETURN( hr );
  828. } //*** CClusCfgClusterInfo::SetNetworkInfo
  829. //////////////////////////////////////////////////////////////////////////////
  830. //++
  831. //
  832. // CClusCfgClusterInfo::GetClusterServiceAccountCredentials
  833. //
  834. // Description:
  835. //
  836. // Arguments:
  837. //
  838. // Return Value:
  839. //
  840. // Remarks:
  841. // None.
  842. //
  843. //--
  844. //////////////////////////////////////////////////////////////////////////////
  845. STDMETHODIMP
  846. CClusCfgClusterInfo::GetClusterServiceAccountCredentials(
  847. IClusCfgCredentials ** ppicccCredentialsOut
  848. )
  849. {
  850. TraceFunc( "[IClusCfgClusterInfo]" );
  851. HRESULT hr;
  852. if ( ppicccCredentialsOut == NULL )
  853. {
  854. hr = THR( E_POINTER );
  855. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetClusterServiceAccountCredentials, IDS_ERROR_NULL_POINTER, hr );
  856. goto Cleanup;
  857. } // if:
  858. if ( m_punkServiceAccountCredentials != NULL )
  859. {
  860. hr = S_OK;
  861. LOG_STATUS_REPORT( L"CClusCfgClusterInfo::GetClusterServiceAccountCredentials() skipping object creation.", hr );
  862. goto SkipCreate;
  863. } // if:
  864. hr = THR( CClusCfgCredentials::S_HrCreateInstance( &m_punkServiceAccountCredentials ) );
  865. if ( FAILED( hr ) )
  866. {
  867. goto Cleanup;
  868. } // if:
  869. m_punkServiceAccountCredentials = TraceInterface( L"CClusCfgCredentials", IUnknown, m_punkServiceAccountCredentials, 1 );
  870. hr = THR( HrSetInitialize( m_punkServiceAccountCredentials, m_picccCallback, m_lcid ) );
  871. if ( FAILED( hr ) )
  872. {
  873. goto Cleanup;
  874. } // if:
  875. hr = THR( HrSetWbemServices( m_punkServiceAccountCredentials, NULL ) );
  876. SkipCreate:
  877. if ( SUCCEEDED( hr ) )
  878. {
  879. Assert( m_punkServiceAccountCredentials != NULL );
  880. hr = THR( m_punkServiceAccountCredentials->TypeSafeQI( IClusCfgCredentials, ppicccCredentialsOut ) );
  881. } // if:
  882. Cleanup:
  883. HRETURN( hr );
  884. } //*** CClusCfgClusterInfo::GetClusterServiceAccountCredentials
  885. //////////////////////////////////////////////////////////////////////////////
  886. //++
  887. //
  888. // CClusCfgClusterInfo::GetBindingString
  889. //
  890. // Description:
  891. // Get the binding string for this cluster.
  892. //
  893. // Arguments:
  894. //
  895. // Return Value:
  896. //
  897. // Remarks:
  898. // None.
  899. //
  900. //--
  901. //////////////////////////////////////////////////////////////////////////////
  902. STDMETHODIMP
  903. CClusCfgClusterInfo::GetBindingString( BSTR * pbstrBindingStringOut )
  904. {
  905. TraceFunc( "[IClusCfgClusterInfo]" );
  906. HRESULT hr = S_OK;
  907. if ( pbstrBindingStringOut == NULL )
  908. {
  909. hr = THR( E_POINTER );
  910. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_ClusterInfo_GetBindingString_Pointer, IDS_ERROR_NULL_POINTER, hr );
  911. goto Cleanup;
  912. } // if:
  913. if ( m_bstrBindingString == NULL )
  914. {
  915. hr = S_FALSE;
  916. LOG_STATUS_REPORT1(
  917. TASKID_Minor_GetBindingString_Binding_String_NULL
  918. , L"The cluster binding string is empty. If we are adding nodes then this is not correct!"
  919. , hr );
  920. goto Cleanup;
  921. } // if:
  922. *pbstrBindingStringOut = SysAllocString( m_bstrBindingString );
  923. if ( *pbstrBindingStringOut == NULL )
  924. {
  925. hr = THR( E_OUTOFMEMORY );
  926. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetBindingString_Memory, IDS_ERROR_OUTOFMEMORY, hr );
  927. } // if:
  928. Cleanup:
  929. HRETURN( hr );
  930. } //*** CClusCfgClusterInfo::GetBindingString
  931. //////////////////////////////////////////////////////////////////////////////
  932. //++
  933. //
  934. // CClusCfgClusterInfo::SetBindingString
  935. //
  936. // Description:
  937. // Set the binding string of this cluster.
  938. //
  939. // Arguments:
  940. //
  941. // Return Value:
  942. //
  943. // Remarks:
  944. // None.
  945. //
  946. //--
  947. //////////////////////////////////////////////////////////////////////////////
  948. STDMETHODIMP
  949. CClusCfgClusterInfo::SetBindingString( LPCWSTR pcszBindingStringIn )
  950. {
  951. TraceFunc1( "[IClusCfgClusterInfo] pcszBindingStringIn = '%ls'", pcszBindingStringIn == NULL ? L"<null>" : pcszBindingStringIn );
  952. HRESULT hr = S_OK;
  953. BSTR bstr = NULL;
  954. //
  955. // When creating a cluster there is no cluster binding string. Therefore it is reasonable
  956. // to accept a NULL string as the passed in parameter.
  957. //
  958. if ( pcszBindingStringIn == NULL )
  959. {
  960. hr = S_FALSE;
  961. TraceSysFreeString( m_bstrBindingString );
  962. m_bstrBindingString = NULL;
  963. goto Cleanup;
  964. } // if:
  965. bstr = TraceSysAllocString( pcszBindingStringIn );
  966. if ( bstr == NULL )
  967. {
  968. hr = THR( E_OUTOFMEMORY );
  969. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_SetBindingString_Cluster, IDS_ERROR_OUTOFMEMORY, hr );
  970. goto Cleanup;
  971. } // if:
  972. TraceSysFreeString( m_bstrBindingString );
  973. m_bstrBindingString = bstr;
  974. Cleanup:
  975. HRETURN( hr );
  976. } //*** CClusCfgClusterInfo::SetBindingString
  977. //*************************************************************************//
  978. /////////////////////////////////////////////////////////////////////////////
  979. // CClusCfgClusterInfo class -- IClusCfgSetClusterNodeInfo Interfaces.
  980. /////////////////////////////////////////////////////////////////////////////
  981. //////////////////////////////////////////////////////////////////////////////
  982. //++
  983. //
  984. // CClusCfgClusterInfo::SetClusterNodeInfo
  985. //
  986. // Description:
  987. // Suck some info off of the passed in node info object.
  988. //
  989. // Arguments:
  990. // None.
  991. //
  992. // Return Value:
  993. //
  994. //
  995. // Remarks:
  996. // None.
  997. //
  998. //--
  999. //////////////////////////////////////////////////////////////////////////////
  1000. STDMETHODIMP
  1001. CClusCfgClusterInfo::SetClusterNodeInfo( IClusCfgNodeInfo * pNodeInfoIn )
  1002. {
  1003. TraceFunc( "[IClusCfgClusterInfo]" );
  1004. HRESULT hr = S_FALSE;
  1005. hr = STHR( pNodeInfoIn->IsMemberOfCluster() );
  1006. if ( hr == S_OK )
  1007. {
  1008. m_fIsClusterNode = true;
  1009. } // if:
  1010. else if ( hr == S_FALSE )
  1011. {
  1012. m_fIsClusterNode = false;
  1013. hr = S_OK;
  1014. } // else if:
  1015. HRETURN( hr );
  1016. } //*** CClusCfgClusterInfo::SetClusterNodeInfo
  1017. //*************************************************************************//
  1018. /////////////////////////////////////////////////////////////////////////////
  1019. // CClusCfgClusterInfo class -- Private Methods.
  1020. /////////////////////////////////////////////////////////////////////////////
  1021. //////////////////////////////////////////////////////////////////////////////
  1022. //++
  1023. //
  1024. // CClusCfgClusterInfo::HrInit
  1025. //
  1026. // Description:
  1027. // Initialize this component.
  1028. //
  1029. // Arguments:
  1030. // None.
  1031. //
  1032. // Return Value:
  1033. //
  1034. //
  1035. // Remarks:
  1036. // None.
  1037. //
  1038. //--
  1039. //////////////////////////////////////////////////////////////////////////////
  1040. HRESULT
  1041. CClusCfgClusterInfo::HrInit( void )
  1042. {
  1043. TraceFunc( "" );
  1044. HRESULT hr = S_OK;
  1045. m_bstrName = TraceSysAllocString( L"\0" );
  1046. if ( m_bstrName == NULL )
  1047. {
  1048. hr = THR( E_OUTOFMEMORY );
  1049. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrInit, IDS_ERROR_OUTOFMEMORY, hr );
  1050. } // if:
  1051. Cleanup:
  1052. HRETURN( hr );
  1053. } //*** CClusCfgClusterInfo::HrInit
  1054. //////////////////////////////////////////////////////////////////////////////
  1055. //++
  1056. //
  1057. // CClusCfgClusterInfo::HrLoadNetworkInfo
  1058. //
  1059. // Description:
  1060. // Load the cluster network info...
  1061. //
  1062. // Arguments:
  1063. //
  1064. //
  1065. // Return Value:
  1066. //
  1067. //
  1068. // Remarks:
  1069. // None.
  1070. //
  1071. //--
  1072. //////////////////////////////////////////////////////////////////////////////
  1073. HRESULT
  1074. CClusCfgClusterInfo::HrLoadNetworkInfo( HCLUSTER hClusterIn )
  1075. {
  1076. TraceFunc( "" );
  1077. HRESULT hr = S_OK;
  1078. DWORD sc;
  1079. HRESOURCE hIPAddress = NULL;
  1080. sc = TW32( ResUtilGetCoreClusterResources( hClusterIn, NULL, &hIPAddress, NULL ) );
  1081. if ( sc != ERROR_SUCCESS )
  1082. {
  1083. goto Cleanup;
  1084. } // if:
  1085. hr = THR( HrGetIPAddressInfo( hIPAddress ) );
  1086. if ( FAILED( hr ) )
  1087. {
  1088. goto Cleanup;
  1089. } // if:
  1090. Cleanup:
  1091. LOG_STATUS_REPORT1( TASKID_Minor_Server_LoadNetwork_Info, L"LoadNetworkInfo() completed.", hr );
  1092. if ( hIPAddress != NULL )
  1093. {
  1094. CloseClusterResource( hIPAddress );
  1095. } // if:
  1096. HRETURN( hr );
  1097. } //*** CClusCfgClusterInfo::HrLoadNetworkInfo
  1098. //////////////////////////////////////////////////////////////////////////////
  1099. //++
  1100. //
  1101. // CClusCfgClusterInfo::HrGetIPAddressInfo
  1102. //
  1103. // Description:
  1104. //
  1105. //
  1106. // Arguments:
  1107. //
  1108. //
  1109. // Return Value:
  1110. //
  1111. //
  1112. // Remarks:
  1113. // None.
  1114. //
  1115. //--
  1116. //////////////////////////////////////////////////////////////////////////////
  1117. HRESULT
  1118. CClusCfgClusterInfo::HrGetIPAddressInfo(
  1119. HCLUSTER hClusterIn,
  1120. HRESOURCE hResIn
  1121. )
  1122. {
  1123. TraceFunc( "" );
  1124. HRESULT hr = S_FALSE;
  1125. DWORD sc;
  1126. HRESENUM hEnum = NULL;
  1127. DWORD idx;
  1128. WCHAR * psz = NULL;
  1129. DWORD cchpsz = 33;
  1130. DWORD dwType;
  1131. HRESOURCE hRes = NULL;
  1132. hEnum = ClusterResourceOpenEnum( hResIn, CLUSTER_RESOURCE_ENUM_DEPENDS );
  1133. if ( hEnum == NULL )
  1134. {
  1135. sc = TW32( GetLastError() );
  1136. hr = HRESULT_FROM_WIN32( sc );
  1137. goto Cleanup;
  1138. } // if:
  1139. psz = new WCHAR [ cchpsz ];
  1140. if ( psz == NULL )
  1141. {
  1142. goto OutOfMemory;
  1143. } // if:
  1144. for ( idx = 0; ; )
  1145. {
  1146. sc = TW32( ClusterResourceEnum( hEnum, idx, &dwType, psz, &cchpsz ) );
  1147. if ( sc == ERROR_NO_MORE_ITEMS )
  1148. {
  1149. break;
  1150. } // if:
  1151. if ( sc == ERROR_MORE_DATA )
  1152. {
  1153. delete [] psz;
  1154. psz = NULL;
  1155. cchpsz++;
  1156. psz = new WCHAR [ cchpsz ];
  1157. if ( psz == NULL )
  1158. {
  1159. goto OutOfMemory;
  1160. } // if:
  1161. continue;
  1162. } // if:
  1163. if ( sc == ERROR_SUCCESS )
  1164. {
  1165. hRes = OpenClusterResource( hClusterIn, psz );
  1166. if ( hRes == NULL )
  1167. {
  1168. sc = TW32( GetLastError() );
  1169. hr = HRESULT_FROM_WIN32( sc );
  1170. goto Cleanup;
  1171. } // if:
  1172. hr = STHR( HrIsResourceOfType( hRes, L"IP Address" ) );
  1173. if ( FAILED( hr ) )
  1174. {
  1175. goto Cleanup;
  1176. } // if:
  1177. if ( hr == S_OK )
  1178. {
  1179. hr = THR( HrGetIPAddressInfo( hRes ) ); // not recursive!
  1180. break;
  1181. } // if:
  1182. CloseClusterResource( hRes );
  1183. hRes = NULL;
  1184. idx++;
  1185. continue;
  1186. } // if:
  1187. hr = THR( HRESULT_FROM_WIN32( sc ) ); // must be an error!
  1188. goto Cleanup;
  1189. } // for:
  1190. goto Cleanup;
  1191. OutOfMemory:
  1192. hr = THR( E_OUTOFMEMORY );
  1193. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrGetIPAddressInfo, IDS_ERROR_OUTOFMEMORY, hr );
  1194. Cleanup:
  1195. LOG_STATUS_REPORT1( TASKID_Minor_Server_Get_ClusterIPAddress_Info_2, L"GetIPAddressInfo() completed.", hr );
  1196. delete [] psz;
  1197. if ( hRes != NULL )
  1198. {
  1199. CloseClusterResource( hRes );
  1200. } // if:
  1201. if ( hEnum != NULL )
  1202. {
  1203. ClusterResourceCloseEnum( hEnum );
  1204. } // if:
  1205. HRETURN( hr );
  1206. } //*** CClusCfgClusterInfo::HrGetIPAddressInfo
  1207. //////////////////////////////////////////////////////////////////////////////
  1208. //++
  1209. //
  1210. // CClusCfgClusterInfo::HrIsResourceOfType
  1211. //
  1212. // Description:
  1213. // Is the resource of the type passed in?
  1214. //
  1215. // Arguments:
  1216. //
  1217. //
  1218. // Return Value:
  1219. // S_OK
  1220. // The resource is of the type requested.
  1221. //
  1222. // S_FALSE
  1223. // The resource is not of the type requested.
  1224. //
  1225. // Other HRESULT
  1226. // Win32 error as HRESULT.
  1227. //
  1228. // Remarks:
  1229. // None.
  1230. //
  1231. //--
  1232. //////////////////////////////////////////////////////////////////////////////
  1233. HRESULT
  1234. CClusCfgClusterInfo::HrIsResourceOfType(
  1235. HRESOURCE hResIn,
  1236. const WCHAR * pszResourceTypeIn
  1237. )
  1238. {
  1239. TraceFunc( "" );
  1240. HRESULT hr = S_OK;
  1241. DWORD sc;
  1242. WCHAR * psz = NULL;
  1243. DWORD cbpsz = 33;
  1244. DWORD cb;
  1245. int idx;
  1246. psz = new WCHAR [ cbpsz * sizeof( WCHAR ) ];
  1247. if ( psz == NULL )
  1248. {
  1249. goto OutOfMemory;
  1250. } // if:
  1251. for ( idx = 0; ; idx++ )
  1252. {
  1253. Assert( idx < 2 );
  1254. sc = ClusterResourceControl( hResIn, NULL, CLUSCTL_RESOURCE_GET_RESOURCE_TYPE, NULL, 0, psz, cbpsz, &cb );
  1255. if ( sc == ERROR_MORE_DATA )
  1256. {
  1257. delete [] psz;
  1258. psz = NULL;
  1259. cbpsz = cb + 1;
  1260. psz = new WCHAR [ cbpsz * sizeof( WCHAR ) ];
  1261. if ( psz == NULL )
  1262. {
  1263. goto OutOfMemory;
  1264. } // if:
  1265. continue;
  1266. } // if:
  1267. if ( sc != ERROR_SUCCESS )
  1268. {
  1269. hr = HRESULT_FROM_WIN32( sc );
  1270. goto Cleanup;
  1271. } // if:
  1272. break;
  1273. } // for:
  1274. if ( wcscmp( psz, pszResourceTypeIn ) == 0 )
  1275. {
  1276. hr = S_OK;
  1277. } // if:
  1278. else
  1279. {
  1280. hr = S_FALSE;
  1281. } // else:
  1282. goto Cleanup;
  1283. OutOfMemory:
  1284. hr = THR( E_OUTOFMEMORY );
  1285. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrIsResourceOfType, IDS_ERROR_OUTOFMEMORY, hr );
  1286. Cleanup:
  1287. delete [] psz;
  1288. HRETURN( hr );
  1289. } //*** CClusCfgClusterInfo::HrIsResourceOfType
  1290. //////////////////////////////////////////////////////////////////////////////
  1291. //++
  1292. //
  1293. // CClusCfgClusterInfo::HrGetIPAddressInfo
  1294. //
  1295. // Description:
  1296. //
  1297. //
  1298. // Arguments:
  1299. //
  1300. //
  1301. // Return Value:
  1302. //
  1303. //
  1304. // Remarks:
  1305. // None.
  1306. //
  1307. //--
  1308. //////////////////////////////////////////////////////////////////////////////
  1309. HRESULT
  1310. CClusCfgClusterInfo::HrGetIPAddressInfo( HRESOURCE hResIn )
  1311. {
  1312. TraceFunc( "" );
  1313. HRESULT hr = S_OK;
  1314. DWORD sc;
  1315. CClusPropList cpl;
  1316. CLUSPROP_BUFFER_HELPER cpbh;
  1317. ULONG ulNetwork;
  1318. WCHAR * psz = NULL;
  1319. sc = TW32( cpl.ScGetResourceProperties( hResIn, CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES ) );
  1320. if ( sc != ERROR_SUCCESS )
  1321. {
  1322. goto MakeHr;
  1323. } // if:
  1324. sc = TW32( cpl.ScMoveToPropertyByName( L"Address" ) );
  1325. if ( sc != ERROR_SUCCESS )
  1326. {
  1327. goto MakeHr;
  1328. } // if:
  1329. cpbh = cpl.CbhCurrentValue();
  1330. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1331. sc = ClRtlTcpipStringToAddress( cpbh.pStringValue->sz, &m_ulIPDottedQuad );
  1332. if ( sc != ERROR_SUCCESS )
  1333. {
  1334. goto MakeHr;
  1335. } // if:
  1336. m_bstrBindingString = TraceSysAllocString( cpbh.pStringValue->sz );
  1337. if ( m_bstrBindingString == NULL )
  1338. {
  1339. hr = THR( E_OUTOFMEMORY );
  1340. goto Cleanup;
  1341. } // if:
  1342. LOG_STATUS_REPORT_STRING( L"Cluster binding string is '%1!ws!'.", m_bstrBindingString, hr );
  1343. sc = TW32( cpl.ScMoveToPropertyByName( L"SubnetMask" ) );
  1344. if ( sc != ERROR_SUCCESS )
  1345. {
  1346. goto MakeHr;
  1347. } // if:
  1348. cpbh = cpl.CbhCurrentValue();
  1349. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1350. sc = ClRtlTcpipStringToAddress( cpbh.pStringValue->sz, &m_ulSubnetDottedQuad );
  1351. if ( sc != ERROR_SUCCESS )
  1352. {
  1353. goto MakeHr;
  1354. } // if:
  1355. ulNetwork = m_ulIPDottedQuad & m_ulSubnetDottedQuad;
  1356. sc = ClRtlTcpipAddressToString( ulNetwork, &psz ); // KB: Allocates to lpsz using LocalAlloc().
  1357. if ( sc != ERROR_SUCCESS )
  1358. {
  1359. goto MakeHr;
  1360. } // if:
  1361. sc = TW32( cpl.ScMoveToPropertyByName( L"Network" ) );
  1362. if ( sc != ERROR_SUCCESS )
  1363. {
  1364. goto MakeHr;
  1365. } // if:
  1366. cpbh = cpl.CbhCurrentValue();
  1367. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  1368. hr = THR( HrFindNetworkInfo( cpbh.pStringValue->sz, psz ) );
  1369. goto Cleanup;
  1370. MakeHr:
  1371. hr = HRESULT_FROM_WIN32( sc );
  1372. Cleanup:
  1373. LOG_STATUS_REPORT1( TASKID_Minor_Server_Get_ClusterIPAddress_Info, L"GetIPAddressInfo() completed.", hr );
  1374. LocalFree( psz ); // KB: Don't use TraceFree() here!
  1375. HRETURN( hr );
  1376. } //*** CClusCfgClusterInfo::HrGetIPAddressInfo
  1377. //////////////////////////////////////////////////////////////////////////////
  1378. //++
  1379. //
  1380. // CClusCfgClusterInfo::HrFindNetworkInfo
  1381. //
  1382. // Description:
  1383. //
  1384. //
  1385. // Arguments:
  1386. //
  1387. //
  1388. // Return Value:
  1389. //
  1390. //
  1391. // Remarks:
  1392. // None.
  1393. //
  1394. //--
  1395. //////////////////////////////////////////////////////////////////////////////
  1396. HRESULT
  1397. CClusCfgClusterInfo::HrFindNetworkInfo(
  1398. const WCHAR * pszNetworkName,
  1399. const WCHAR * pszNetwork
  1400. )
  1401. {
  1402. TraceFunc( "" );
  1403. HRESULT hr;
  1404. IUnknown * punk = NULL;
  1405. IEnumClusCfgNetworks * pieccn = NULL;
  1406. ULONG cFetched;
  1407. IClusCfgNetworkInfo * piccni = NULL;
  1408. BSTR bstrNetworkName = NULL;
  1409. BSTR bstrNetwork = NULL;
  1410. hr = THR( HrCreateNetworksEnum( m_picccCallback, m_lcid, m_pIWbemServices, &punk ) );
  1411. if ( FAILED( hr ) )
  1412. {
  1413. goto Cleanup;
  1414. } // if:
  1415. hr = THR( punk->TypeSafeQI( IEnumClusCfgNetworks, &pieccn ) );
  1416. if ( FAILED( hr ) )
  1417. {
  1418. goto Cleanup;
  1419. } // if:
  1420. for ( ; ; )
  1421. {
  1422. hr = pieccn->Next( 1, &piccni, &cFetched );
  1423. if ( ( hr == S_OK ) && ( cFetched == 1 ) )
  1424. {
  1425. hr = THR( piccni->GetName( &bstrNetworkName ) );
  1426. if ( FAILED( hr ) )
  1427. {
  1428. goto Cleanup;
  1429. } // if:
  1430. TraceMemoryAddBSTR( bstrNetworkName );
  1431. hr = THR( piccni->GetUID( &bstrNetwork ) );
  1432. if ( FAILED( hr ) )
  1433. {
  1434. goto Cleanup;
  1435. } // if:
  1436. TraceMemoryAddBSTR( bstrNetwork );
  1437. if ( ( wcscmp( pszNetworkName, bstrNetworkName ) == 0 ) && ( _wcsicmp( pszNetwork, bstrNetwork ) == 0 ) )
  1438. {
  1439. if ( m_piccniNetwork != NULL )
  1440. {
  1441. m_piccniNetwork->Release();
  1442. m_piccniNetwork = NULL;
  1443. } // if:
  1444. m_piccniNetwork = piccni;
  1445. m_piccniNetwork->AddRef();
  1446. break;
  1447. } // if:
  1448. piccni->Release();
  1449. piccni = NULL;
  1450. } // if:
  1451. else if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  1452. {
  1453. hr = S_OK;
  1454. break;
  1455. } // else if:
  1456. else
  1457. {
  1458. goto Cleanup;
  1459. } // else:
  1460. } // for:
  1461. //
  1462. // If we didn't find the cluster network in the WMI list of networks then we have a problem.
  1463. //
  1464. Assert( m_piccniNetwork != NULL );
  1465. if ( m_piccniNetwork == NULL )
  1466. {
  1467. hr = THR( ERROR_NETWORK_NOT_AVAILABLE );
  1468. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Cluster_Network_Not_Found, IDS_ERROR_CLUSTER_NETWORK_NOT_FOUND, hr );
  1469. } // if:
  1470. Cleanup:
  1471. if ( piccni != NULL )
  1472. {
  1473. piccni->Release();
  1474. } // if:
  1475. if ( pieccn != NULL )
  1476. {
  1477. pieccn->Release();
  1478. } // if:
  1479. if ( punk != NULL )
  1480. {
  1481. punk->Release();
  1482. } // if:
  1483. TraceSysFreeString( bstrNetworkName );
  1484. TraceSysFreeString( bstrNetwork );
  1485. HRETURN( hr );
  1486. } //*** CClusCfgClusterInfo::HrFindNetworkInfo
  1487. //////////////////////////////////////////////////////////////////////////////
  1488. //++
  1489. //
  1490. // CClusCfgClusterInfo::HrLoadCredentials
  1491. //
  1492. // Description:
  1493. //
  1494. //
  1495. // Arguments:
  1496. //
  1497. //
  1498. // Return Value:
  1499. //
  1500. //
  1501. // Remarks:
  1502. // None.
  1503. //
  1504. //--
  1505. //////////////////////////////////////////////////////////////////////////////
  1506. HRESULT
  1507. CClusCfgClusterInfo::HrLoadCredentials( void )
  1508. {
  1509. TraceFunc( "" );
  1510. HRESULT hr = S_OK;
  1511. SC_HANDLE schSCM = NULL;
  1512. SC_HANDLE schClusSvc = NULL;
  1513. DWORD sc;
  1514. DWORD cbpqsc = 128;
  1515. DWORD cbRequired;
  1516. QUERY_SERVICE_CONFIG * pqsc = NULL;
  1517. IClusCfgCredentials * piccc = NULL;
  1518. IClusCfgSetCredentials * piccsc = NULL;
  1519. schSCM = OpenSCManager( NULL, NULL, GENERIC_READ );
  1520. if ( schSCM == NULL )
  1521. {
  1522. sc = TW32( GetLastError() );
  1523. goto Win32Error;
  1524. } // if:
  1525. schClusSvc = OpenService( schSCM, L"ClusSvc", GENERIC_READ );
  1526. if ( schClusSvc == NULL )
  1527. {
  1528. sc = TW32( GetLastError() );
  1529. goto Win32Error;
  1530. } // if:
  1531. for ( ; ; )
  1532. {
  1533. pqsc = (QUERY_SERVICE_CONFIG *) TraceAlloc( 0, cbpqsc );
  1534. if ( pqsc == NULL )
  1535. {
  1536. hr = THR( E_OUTOFMEMORY );
  1537. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrLoadCredentials, IDS_ERROR_OUTOFMEMORY, hr );
  1538. goto Cleanup;
  1539. } // if:
  1540. if ( !QueryServiceConfig( schClusSvc, pqsc, cbpqsc, &cbRequired ) )
  1541. {
  1542. sc = GetLastError();
  1543. if ( sc == ERROR_INSUFFICIENT_BUFFER )
  1544. {
  1545. TraceFree( pqsc );
  1546. pqsc = NULL;
  1547. cbpqsc = cbRequired;
  1548. continue;
  1549. } // if:
  1550. else
  1551. {
  1552. TW32( sc );
  1553. goto Win32Error;
  1554. } // else:
  1555. } // if:
  1556. else
  1557. {
  1558. break;
  1559. } // else:
  1560. } // for:
  1561. Assert( m_punkServiceAccountCredentials == NULL );
  1562. hr = THR( GetClusterServiceAccountCredentials( &piccc ) );
  1563. if ( FAILED( hr ) )
  1564. {
  1565. goto Cleanup;
  1566. } // if:
  1567. hr = THR( piccc->TypeSafeQI( IClusCfgSetCredentials, &piccsc ) );
  1568. if ( FAILED( hr ) )
  1569. {
  1570. goto Cleanup;
  1571. } // if:
  1572. hr = THR( piccsc->SetDomainCredentials( pqsc->lpServiceStartName ) );
  1573. goto Cleanup;
  1574. Win32Error:
  1575. hr = HRESULT_FROM_WIN32( sc );
  1576. Cleanup:
  1577. if ( schClusSvc != NULL )
  1578. {
  1579. CloseServiceHandle( schClusSvc );
  1580. } // if:
  1581. if ( schSCM != NULL )
  1582. {
  1583. CloseServiceHandle( schSCM );
  1584. } // if:
  1585. if ( pqsc != NULL )
  1586. {
  1587. TraceFree( pqsc );
  1588. } // if:
  1589. if ( piccc != NULL )
  1590. {
  1591. piccc->Release();
  1592. } // if:
  1593. if ( piccsc != NULL )
  1594. {
  1595. piccsc->Release();
  1596. } // if:
  1597. HRETURN( hr );
  1598. } //*** CClusCfgClusterInfo::HrLoadCredentials