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.

2800 lines
74 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgServer.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CClusCfgServer class.
  10. //
  11. // The class CClusCfgServer is the implementations of the
  12. // IClusCfgServer interface.
  13. //
  14. // Documentation:
  15. //
  16. // Header File:
  17. // CClusCfgServer.h
  18. //
  19. // Maintained By:
  20. // Galen Barbee (GalenB) 03-FEB-2000
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. //////////////////////////////////////////////////////////////////////////////
  24. // Include Files
  25. //////////////////////////////////////////////////////////////////////////////
  26. #include "pch.h"
  27. #include "CClusCfgServer.h"
  28. #include "PrivateInterfaces.h"
  29. #include "CClusCfgNodeInfo.h"
  30. #include "CEnumClusCfgManagedResources.h"
  31. #include "CClusCfgCallback.h"
  32. #include "EventName.h"
  33. #include <ClusRtl.h>
  34. #include <windns.h>
  35. #include <ClusterUtils.h>
  36. #include <clusudef.h>
  37. //////////////////////////////////////////////////////////////////////////////
  38. // Constant Definitions
  39. //////////////////////////////////////////////////////////////////////////////
  40. DEFINE_THISCLASS( "CClusCfgServer" );
  41. #define CLEANUP_LOCK_NAME L"Global\\Microsoft Cluster Configuration Cleanup Lock"
  42. //*************************************************************************//
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CClusCfgServer class
  45. /////////////////////////////////////////////////////////////////////////////
  46. //////////////////////////////////////////////////////////////////////////////
  47. //++
  48. //
  49. // CClusCfgServer::S_HrCreateInstance
  50. //
  51. // Description:
  52. // Create a CClusCfgServer instance.
  53. //
  54. // Arguments:
  55. // ppunkOut -
  56. //
  57. // Return Values:
  58. // Pointer to CClusCfgServer instance.
  59. //
  60. //--
  61. //////////////////////////////////////////////////////////////////////////////
  62. HRESULT
  63. CClusCfgServer::S_HrCreateInstance( IUnknown ** ppunkOut )
  64. {
  65. TraceFunc( "" );
  66. HRESULT hr;
  67. CClusCfgServer * pccs = NULL;
  68. if ( ppunkOut == NULL )
  69. {
  70. hr = THR( E_POINTER );
  71. goto Cleanup;
  72. } // if:
  73. //
  74. // KB: Since this is usually the start of the "server" thread,
  75. // we will cause it to read its thread settings here.
  76. //
  77. TraceInitializeThread( L"ServerThread" );
  78. pccs = new CClusCfgServer();
  79. if ( pccs == NULL )
  80. {
  81. hr = THR( E_OUTOFMEMORY );
  82. goto Cleanup;
  83. } // if: error allocating object
  84. hr = THR( pccs->HrInit() );
  85. if ( FAILED( hr ) )
  86. {
  87. goto Cleanup;
  88. } // if: HrInit() failed
  89. hr = THR( pccs->TypeSafeQI( IUnknown, ppunkOut ) );
  90. Cleanup:
  91. if ( FAILED( hr ) )
  92. {
  93. LogMsg( L"[SRV] CClusCfgServer::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  94. } // if:
  95. if ( pccs != NULL )
  96. {
  97. pccs->Release();
  98. } // if:
  99. HRETURN( hr );
  100. } //*** CClusCfgServer::S_HrCreateInstance
  101. //////////////////////////////////////////////////////////////////////////////
  102. //++
  103. //
  104. // CClusCfgServer::CClusCfgServer
  105. //
  106. // Description:
  107. // Constructor of the CClusCfgServer class. This initializes
  108. // the m_cRef variable to 1 instead of 0 to account of possible
  109. // QueryInterface failure in DllGetClassObject.
  110. //
  111. // Arguments:
  112. // None.
  113. //
  114. // Return Value:
  115. // None.
  116. //
  117. // Remarks:
  118. // None.
  119. //
  120. //--
  121. //////////////////////////////////////////////////////////////////////////////
  122. CClusCfgServer::CClusCfgServer( void )
  123. : m_cRef( 1 )
  124. , m_pIWbemServices( NULL )
  125. , m_lcid( LOCALE_NEUTRAL )
  126. , m_fCanBeClustered( TRUE )
  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_punkNodeInfo == NULL );
  134. Assert( m_punkEnumResources == NULL );
  135. Assert( m_punkNetworksEnum == NULL );
  136. Assert( m_bstrNodeName == NULL );
  137. Assert( !m_fUsePolling );
  138. Assert( m_bstrBindingString == NULL );
  139. TraceFuncExit();
  140. } //*** CClusCfgServer::CClusCfgServer
  141. //////////////////////////////////////////////////////////////////////////////
  142. //++
  143. //
  144. // CClusCfgServer::~CClusCfgServer
  145. //
  146. // Description:
  147. // Destructor of the CClusCfgServer class.
  148. //
  149. // Arguments:
  150. // None.
  151. //
  152. // Return Value:
  153. // None.
  154. //
  155. // Remarks:
  156. // None.
  157. //
  158. //--
  159. //////////////////////////////////////////////////////////////////////////////
  160. CClusCfgServer::~CClusCfgServer( void )
  161. {
  162. TraceFunc( "" );
  163. TraceSysFreeString( m_bstrNodeName );
  164. TraceSysFreeString( m_bstrBindingString );
  165. if ( m_pIWbemServices != NULL )
  166. {
  167. m_pIWbemServices->Release();
  168. } // if:
  169. if ( m_punkNodeInfo != NULL )
  170. {
  171. m_punkNodeInfo->Release();
  172. } // if:
  173. if ( m_punkEnumResources != NULL )
  174. {
  175. m_punkEnumResources->Release();
  176. } // if:
  177. if ( m_punkNetworksEnum != NULL )
  178. {
  179. m_punkNetworksEnum->Release();
  180. } // if:
  181. if ( m_picccCallback != NULL )
  182. {
  183. m_picccCallback->Release();
  184. } // if:
  185. // There's going to be one less component in memory. Decrement component count.
  186. InterlockedDecrement( &g_cObjects );
  187. TraceFuncExit();
  188. } //*** CClusCfgServer::~CClusCfgServer
  189. //*************************************************************************//
  190. /////////////////////////////////////////////////////////////////////////////
  191. // CClusCfgServer -- IUknkown interface.
  192. /////////////////////////////////////////////////////////////////////////////
  193. //////////////////////////////////////////////////////////////////////////////
  194. //++
  195. //
  196. // STDMETHODIMP_( ULONG )
  197. // CClusCfgServer:: [IUNKNOWN] AddRef
  198. //
  199. // Description:
  200. // Increment the reference count of this object by one.
  201. //
  202. // Arguments:
  203. // None.
  204. //
  205. // Return Value:
  206. // The new reference count.
  207. //
  208. // Remarks:
  209. // None.
  210. //
  211. //--
  212. //////////////////////////////////////////////////////////////////////////////
  213. STDMETHODIMP_( ULONG )
  214. CClusCfgServer::AddRef( void )
  215. {
  216. TraceFunc( "[IUnknown]" );
  217. InterlockedIncrement( & m_cRef );
  218. RETURN( m_cRef );
  219. } //*** CClusCfgServer::AddRef
  220. //////////////////////////////////////////////////////////////////////////////
  221. //++
  222. //
  223. // STDMETHODIMP_( ULONG )
  224. // CClusCfgServer:: [IUNKNOWN] Release
  225. //
  226. // Description:
  227. // Decrement the reference count of this object by one.
  228. //
  229. // Arguments:
  230. // None.
  231. //
  232. // Return Value:
  233. // The new reference count.
  234. //
  235. // Remarks:
  236. // None.
  237. //
  238. //--
  239. //////////////////////////////////////////////////////////////////////////////
  240. STDMETHODIMP_( ULONG )
  241. CClusCfgServer::Release( void )
  242. {
  243. TraceFunc( "[IUnknown]" );
  244. LONG cRef;
  245. cRef = InterlockedDecrement( &m_cRef );
  246. if ( cRef == 0 )
  247. {
  248. TraceDo( delete this );
  249. } // if: reference count equal to zero
  250. RETURN( cRef );
  251. } //*** CClusCfgServer::Release
  252. //////////////////////////////////////////////////////////////////////////////
  253. //++
  254. //
  255. // CClusCfgServer:: [INKNOWN] QueryInterface
  256. //
  257. // Description:
  258. // Query this object for the passed in interface.
  259. //
  260. // Arguments:
  261. // IN REFIID riid,
  262. // Id of interface requested.
  263. //
  264. // OUT void ** ppv
  265. // Pointer to the requested interface.
  266. //
  267. // Return Value:
  268. // S_OK
  269. // If the interface is available on this object.
  270. //
  271. // E_NOINTERFACE
  272. // If the interface is not available.
  273. //
  274. // Remarks:
  275. // None.
  276. //
  277. //--
  278. //////////////////////////////////////////////////////////////////////////////
  279. STDMETHODIMP
  280. CClusCfgServer::QueryInterface( REFIID riid, void ** ppv )
  281. {
  282. TraceQIFunc( riid, ppv );
  283. HRESULT hr = E_NOINTERFACE;
  284. if ( IsEqualIID( riid, IID_IUnknown ) )
  285. {
  286. *ppv = static_cast< IClusCfgServer * >( this );
  287. hr = S_OK;
  288. } // if: IUnknown
  289. else if ( IsEqualIID( riid, IID_IClusCfgServer ) )
  290. {
  291. *ppv = TraceInterface( __THISCLASS__, IClusCfgServer, this, 0 );
  292. hr = S_OK;
  293. } // else if:
  294. else if ( IsEqualIID( riid, IID_IClusCfgInitialize ) )
  295. {
  296. *ppv = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  297. hr = S_OK;
  298. } // else if:
  299. else if ( IsEqualIID( riid, IID_IClusCfgCapabilities ) )
  300. {
  301. *ppv = TraceInterface( __THISCLASS__, IClusCfgCapabilities, this, 0 );
  302. hr = S_OK;
  303. } // else if:
  304. else if ( IsEqualIID( riid, IID_IClusCfgPollingCallbackInfo ) )
  305. {
  306. *ppv = TraceInterface( __THISCLASS__, IClusCfgPollingCallbackInfo, this, 0 );
  307. hr = S_OK;
  308. } // else if:
  309. else if ( IsEqualIID( riid, IID_IClusCfgVerify ) )
  310. {
  311. *ppv = TraceInterface( __THISCLASS__, IClusCfgVerify, this, 0 );
  312. hr = S_OK;
  313. } // else if:
  314. if ( SUCCEEDED( hr ) )
  315. {
  316. ((IUnknown *) *ppv)->AddRef( );
  317. } // if: success
  318. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  319. } //*** CClusCfgServer::QueryInterface
  320. //*************************************************************************//
  321. /////////////////////////////////////////////////////////////////////////////
  322. // CClusCfgServer -- IClusCfgInitialize interface.
  323. /////////////////////////////////////////////////////////////////////////////
  324. //////////////////////////////////////////////////////////////////////////////
  325. //++
  326. //
  327. // CClusCfgServer::Initialize
  328. //
  329. // Description:
  330. // Initialize this component.
  331. //
  332. // Arguments:
  333. // IN IUknown * punkCallbackIn
  334. //
  335. // IN LCID lcidIn
  336. //
  337. // Return Value:
  338. // S_OK
  339. // Success
  340. //
  341. // E_POINTER
  342. // The punkCallbackIn param is NULL.
  343. //
  344. // Remarks:
  345. // None.
  346. //
  347. //--
  348. //////////////////////////////////////////////////////////////////////////////
  349. STDMETHODIMP
  350. CClusCfgServer::Initialize(
  351. IUnknown * punkCallbackIn,
  352. LCID lcidIn
  353. )
  354. {
  355. TraceFunc( "[IClusCfgInitialize]" );
  356. Assert( m_picccCallback != NULL );
  357. TraceInitializeThread( L"ClusCfgServerFlags" );
  358. HRESULT hr = S_OK;
  359. IUnknown * punk = NULL;
  360. IClusCfgCallback * piccc = NULL; // this is NULL when we are polling callback
  361. IClusCfgNodeInfo * piccni = NULL;
  362. IClusCfgClusterInfo * piccci = NULL;
  363. // hr = STHR( HrCheckSecurity() );
  364. // if ( FAILED( hr ) )
  365. // {
  366. // goto Cleanup;
  367. // } // if:
  368. m_lcid = lcidIn;
  369. //
  370. // If we are passed a callback object then we need to get its IClusCfgCallback
  371. // interface so we can pass it into our callback object when it's initialized
  372. // below.
  373. //
  374. if ( punkCallbackIn != NULL )
  375. {
  376. Assert( !m_fUsePolling );
  377. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &piccc ) );
  378. if ( FAILED( hr ) )
  379. {
  380. goto Cleanup;
  381. } // if:
  382. } // if:
  383. else
  384. {
  385. Assert( m_fUsePolling );
  386. if ( m_fUsePolling == FALSE )
  387. {
  388. hr = THR( E_INVALIDARG );
  389. goto Cleanup;
  390. } // if:
  391. } // else:
  392. //
  393. // Initialize our internal callback object passing it either the passed in
  394. // callback object's callback interface or NULL if we are polling.
  395. //
  396. hr = THR( m_picccCallback->TypeSafeQI( IUnknown, &punk ) );
  397. if ( FAILED( hr ) )
  398. {
  399. goto Cleanup;
  400. } // if:
  401. hr = THR( HrSetInitialize( punk, piccc, m_lcid ) );
  402. if ( FAILED( hr ) )
  403. {
  404. goto Cleanup;
  405. } // if:
  406. //
  407. // KB: 24-JUL-2000 GalenB
  408. //
  409. // If we are being initialized on this interface then we are going to run this server local
  410. // to the node.
  411. //
  412. hr = THR( HrInitializeForLocalServer() );
  413. if ( FAILED( hr ) )
  414. {
  415. goto Cleanup;
  416. } // if:
  417. //
  418. // Precreate the node info so we can get the cluster info object and determine if the cluster service
  419. // is running on this node or not.
  420. //
  421. hr = THR( HrCreateClusterNodeInfo() );
  422. if ( FAILED( hr ) )
  423. {
  424. goto Cleanup;
  425. } // if:
  426. hr = THR( m_punkNodeInfo->TypeSafeQI( IClusCfgNodeInfo, &piccni ) );
  427. if ( FAILED( hr ) )
  428. {
  429. goto Cleanup;
  430. } // if:
  431. //
  432. // This could return HRESUTL_FROM_WIN32( ERROR_CLUSTER_NODE_DOWN ) and that
  433. // tells us that the cluster service is not running on this node. The
  434. // middletier needs to know this so it doesn't call us on this node
  435. // anymore.
  436. //
  437. hr = THR( piccni->GetClusterConfigInfo( &piccci ) );
  438. Cleanup:
  439. if ( m_picccCallback != NULL )
  440. {
  441. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_Server_Initialized, IDS_NOTIFY_SERVER_INITIALIZED, hr );
  442. } // if:
  443. if ( piccci != NULL )
  444. {
  445. piccci->Release();
  446. } // if:
  447. if ( piccni != NULL )
  448. {
  449. piccni->Release();
  450. } // if:
  451. if ( piccc != NULL )
  452. {
  453. piccc->Release();
  454. } // if:
  455. if ( punk != NULL )
  456. {
  457. punk->Release();
  458. } // if:
  459. HRETURN( hr );
  460. } //*** CClusCfgServer::Initialize
  461. //*************************************************************************//
  462. /////////////////////////////////////////////////////////////////////////////
  463. // CClusCfgServer -- IClusCfgServer interface.
  464. /////////////////////////////////////////////////////////////////////////////
  465. //////////////////////////////////////////////////////////////////////////////
  466. //++
  467. //
  468. // CClusCfgServer::GetClusterNodeInfo
  469. //
  470. // Description:
  471. // Get information about the computer on which this object is present.
  472. //
  473. // Arguments:
  474. // OUT IClusCfgNodeInfo ** ppClusterNodeInfoOut
  475. // Catches the node info object.
  476. //
  477. // Return Value:
  478. // S_OK
  479. // Success
  480. //
  481. // E_POINTER
  482. // The out param was NULL.
  483. //
  484. // E_OUTOFMEMORY
  485. // The IClusCfgNodeInfo object could not be allocated.
  486. //
  487. // Remarks:
  488. // None.
  489. //
  490. //--
  491. //////////////////////////////////////////////////////////////////////////////
  492. STDMETHODIMP
  493. CClusCfgServer::GetClusterNodeInfo(
  494. IClusCfgNodeInfo ** ppClusterNodeInfoOut
  495. )
  496. {
  497. TraceFunc( "[IClusCfgServer]" );
  498. HRESULT hr = S_OK;
  499. if ( ppClusterNodeInfoOut == NULL )
  500. {
  501. hr = THR( E_POINTER );
  502. STATUS_REPORT( TASKID_Major_Check_Node_Feasibility, TASKID_Minor_GetClusterNodeInfo, IDS_ERROR_NULL_POINTER, hr );
  503. goto Cleanup;
  504. } // if:
  505. if ( m_punkNodeInfo != NULL )
  506. {
  507. hr = S_OK;
  508. goto SkipCreate;
  509. } // if:
  510. hr = THR( HrCreateClusterNodeInfo() );
  511. SkipCreate:
  512. if ( SUCCEEDED( hr ) )
  513. {
  514. Assert( m_punkNodeInfo != NULL );
  515. hr = THR( m_punkNodeInfo->TypeSafeQI( IClusCfgNodeInfo, ppClusterNodeInfoOut ) );
  516. } // if:
  517. Cleanup:
  518. if ( FAILED( hr ) )
  519. {
  520. STATUS_REPORT( TASKID_Major_Check_Node_Feasibility, TASKID_Minor_Server_GetClusterNodeInfo, IDS_ERROR_NODE_INFO_CREATE, hr );
  521. } // if:
  522. else
  523. {
  524. STATUS_REPORT( TASKID_Major_Check_Node_Feasibility, TASKID_Minor_Server_GetClusterNodeInfo, IDS_NODE_INFO_CREATE, hr );
  525. } // else:
  526. HRETURN( hr );
  527. } //*** CClusCfgServer::GetClusterNodeInfo
  528. //////////////////////////////////////////////////////////////////////////////
  529. //++
  530. //
  531. // CClusCfgServer::GetManagedResourcesEnum
  532. //
  533. // Description:
  534. // Get an enumeration of the devices on this computer that can be
  535. // managed by the cluster service.
  536. //
  537. // Arguments:
  538. // OUT IEnumClusCfgManagedResources ** ppEnumManagedResourcesOut
  539. // Catches the CEnumClusCfgManagedResources object.
  540. //
  541. // Return Value:
  542. // S_OK
  543. // Success
  544. //
  545. // E_POINTER
  546. // The out param was NULL.
  547. //
  548. // E_OUTOFMEMORY
  549. // The CEnumClusCfgManagedResources object could not be allocated.
  550. //
  551. // Remarks:
  552. // None.
  553. //
  554. //--
  555. //////////////////////////////////////////////////////////////////////////////
  556. STDMETHODIMP
  557. CClusCfgServer::GetManagedResourcesEnum(
  558. IEnumClusCfgManagedResources ** ppEnumManagedResourcesOut
  559. )
  560. {
  561. TraceFunc( "[IClusCfgServer]" );
  562. HRESULT hr = S_OK;
  563. if ( ppEnumManagedResourcesOut == NULL )
  564. {
  565. hr = THR( E_POINTER );
  566. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetManagedResourcesEnum, IDS_ERROR_NULL_POINTER, hr );
  567. goto Cleanup;
  568. } // if:
  569. if ( m_punkEnumResources != NULL )
  570. {
  571. m_punkEnumResources->Release();
  572. m_punkEnumResources = NULL;
  573. } // if:
  574. hr = THR( CEnumClusCfgManagedResources::S_HrCreateInstance( &m_punkEnumResources ) );
  575. if ( FAILED( hr ) )
  576. {
  577. goto Cleanup;
  578. } // if:
  579. m_punkEnumResources = TraceInterface( L"CEnumClusCfgManagedResources", IUnknown, m_punkEnumResources, 1 );
  580. hr = THR( HrSetInitialize( m_punkEnumResources, m_picccCallback, m_lcid ) );
  581. if ( FAILED( hr ) )
  582. {
  583. goto Cleanup;
  584. } // if:
  585. hr = THR( HrSetWbemServices( m_punkEnumResources, m_pIWbemServices ) );
  586. if ( FAILED( hr ) )
  587. {
  588. goto Cleanup;
  589. } // if:
  590. hr = THR( m_punkEnumResources->TypeSafeQI( IEnumClusCfgManagedResources, ppEnumManagedResourcesOut ) );
  591. Cleanup:
  592. if ( FAILED( hr ) )
  593. {
  594. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetManagedResourcesEnum, IDS_ERROR_MANAGED_RESOURCE_ENUM_CREATE, hr );
  595. } // if:
  596. else
  597. {
  598. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetManagedResourcesEnum, IDS_MANAGED_RESOURCE_ENUM_CREATE, hr );
  599. } // else:
  600. HRETURN( hr );
  601. } //*** CClusCfgServer::GetManagedResourcesEnum
  602. //////////////////////////////////////////////////////////////////////////////
  603. //++
  604. //
  605. // CClusCfgServer::GetNetworksEnum
  606. //
  607. // Description:
  608. // Get an enumeration of all the networks on this computer.
  609. //
  610. // Arguments:
  611. // OUT IEnumClusCfgNetworks ** ppEnumNetworksOut
  612. // Catches the CEnumClusCfgNetworks object.
  613. //
  614. // Return Value:
  615. // S_OK
  616. // Success
  617. //
  618. // E_POINTER
  619. // The out param was NULL.
  620. //
  621. // E_OUTOFMEMORY
  622. // The CEnumClusCfgNetworks object could not be allocated.
  623. //
  624. // Remarks:
  625. // None.
  626. //
  627. //--
  628. //////////////////////////////////////////////////////////////////////////////
  629. STDMETHODIMP
  630. CClusCfgServer::GetNetworksEnum(
  631. IEnumClusCfgNetworks ** ppEnumNetworksOut
  632. )
  633. {
  634. TraceFunc( "[IClusCfgServer]" );
  635. HRESULT hr = S_OK;
  636. if ( ppEnumNetworksOut == NULL )
  637. {
  638. hr = THR( E_POINTER );
  639. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetNetworksEnum, IDS_ERROR_NULL_POINTER, hr );
  640. goto Cleanup;
  641. } // if:
  642. if ( m_punkNetworksEnum != NULL )
  643. {
  644. m_punkNetworksEnum->Release();
  645. m_punkNetworksEnum = NULL;
  646. } // if:
  647. hr = THR( HrCreateNetworksEnum( m_picccCallback, m_lcid, m_pIWbemServices, &m_punkNetworksEnum ) );
  648. if ( FAILED( hr ) )
  649. {
  650. goto Cleanup;
  651. } // if:
  652. hr = THR( m_punkNetworksEnum->TypeSafeQI( IEnumClusCfgNetworks, ppEnumNetworksOut ) );
  653. Cleanup:
  654. if ( FAILED( hr ) )
  655. {
  656. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetNetworksEnum, IDS_ERROR_NETWORKS_ENUM_CREATE, hr );
  657. } // if:
  658. else
  659. {
  660. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetNetworksEnum, IDS_NETWORKS_ENUM_CREATE, hr );
  661. } // else:
  662. HRETURN( hr );
  663. } //*** CClusCfgServer::GetNetworksEnum
  664. //////////////////////////////////////////////////////////////////////////////
  665. //++
  666. //
  667. // CClusCfgServer::CommitChanges
  668. //
  669. // Description:
  670. // Commit the changes to the node.
  671. //
  672. // Arguments:
  673. //
  674. //
  675. // Return Value:
  676. // S_OK
  677. // Success
  678. //
  679. // Remarks:
  680. // None.
  681. //
  682. //--
  683. //////////////////////////////////////////////////////////////////////////////
  684. STDMETHODIMP
  685. CClusCfgServer::CommitChanges( void )
  686. {
  687. TraceFunc( "[IClusCfgServer]" );
  688. HRESULT hr = S_OK;
  689. HRESULT hrTemp = S_OK;
  690. IClusCfgInitialize * pcci = NULL;
  691. IClusCfgClusterInfo * pClusCfgClusterInfo = NULL;
  692. ECommitMode ecmCommitChangesMode = cmUNKNOWN;
  693. IClusCfgNodeInfo * piccni = NULL;
  694. IPostCfgManager * ppcm = NULL;
  695. IUnknown * punkCallback = NULL;
  696. HANDLE heventPostCfgCompletion = NULL;
  697. IEnumClusCfgManagedResources * peccmr = NULL;
  698. MULTI_QI mqiInterfaces[] =
  699. {
  700. { &IID_IClusCfgBaseCluster, NULL, S_OK },
  701. { &IID_IClusCfgInitialize, NULL, S_OK }
  702. };
  703. hr = THR( m_picccCallback->TypeSafeQI( IUnknown, &punkCallback ) );
  704. if ( FAILED( hr ) )
  705. {
  706. goto Cleanup;
  707. } // if:
  708. //
  709. // KB: First, get a pointer to the IClusCfgNodeInfo interface. Use this to get
  710. // a pointer to the IClusCfgClusterInfo interface to see what action needs
  711. // to be committed.
  712. //
  713. if ( m_punkNodeInfo == NULL )
  714. {
  715. hr = THR( GetClusterNodeInfo( &piccni ) );
  716. if ( FAILED( hr ) )
  717. {
  718. goto Cleanup;
  719. } // if:
  720. } // if:
  721. else
  722. {
  723. hr = THR( m_punkNodeInfo->TypeSafeQI( IClusCfgNodeInfo, &piccni ) );
  724. if ( FAILED( hr ) )
  725. {
  726. goto Cleanup;
  727. } // if: we could not get the pointer to the IClusCfgNodeInfo interface
  728. } // else:
  729. hr = THR( piccni->GetClusterConfigInfo( &pClusCfgClusterInfo ) );
  730. if ( FAILED( hr ) )
  731. {
  732. goto Cleanup;
  733. } // if: we could not get the pointer to the IClusCfgClusterInfo interface
  734. hr = STHR( pClusCfgClusterInfo->GetCommitMode( &ecmCommitChangesMode ) );
  735. if ( FAILED( hr ) )
  736. {
  737. goto Cleanup;
  738. } // if:
  739. Assert( ecmCommitChangesMode != cmUNKNOWN );
  740. //
  741. // Create and initialize the BaseClusterAction component
  742. //
  743. hr = THR( CoCreateInstanceEx( CLSID_ClusCfgBaseCluster, NULL, CLSCTX_SERVER, NULL, ARRAYSIZE( mqiInterfaces ), mqiInterfaces ) );
  744. if ( FAILED( hr ) && ( hr != CO_S_NOTALLINTERFACES ) )
  745. {
  746. LOG_STATUS_REPORT( L"Failed to CoCreate Base Cluster Actions", hr );
  747. goto Cleanup;
  748. } // if: CoCreateInstanceEx() failed
  749. hr = THR( mqiInterfaces[ 0 ].hr );
  750. if ( FAILED( hr ) )
  751. {
  752. goto Cleanup;
  753. } // if: we could not get a pointer to the IClusCfgBaseCluster interface
  754. //
  755. // Check if we got a pointer to the IClusCfgInitialize interface
  756. hr = mqiInterfaces[ 1 ].hr;
  757. if ( hr == S_OK )
  758. {
  759. hr = THR( ((IClusCfgInitialize *) mqiInterfaces[ 1 ].pItf)->Initialize( punkCallback, m_lcid ) );
  760. if ( FAILED( hr ) )
  761. {
  762. goto Cleanup;
  763. } // if: something went wrong during initialization
  764. } // if: we got a pointer to the IClusCfgInitialize interface
  765. else
  766. {
  767. if ( hr != E_NOINTERFACE )
  768. {
  769. goto Cleanup;
  770. } // if: the interface is supported, but something else went wrong.
  771. } // if: we did not get a pointer to the IClusCfgInitialize interface
  772. //
  773. // Create and initialize the Post configuration manager
  774. //
  775. hr = THR( CoCreateInstance( CLSID_ClusCfgPostConfigManager, NULL, CLSCTX_SERVER, TypeSafeParams( IPostCfgManager, &ppcm ) ) );
  776. if ( FAILED( hr ) )
  777. {
  778. //
  779. // TODO: gpease 11-JUN-2000
  780. // Notify the UI layer. What are the major and minor task ids?
  781. //
  782. LOG_STATUS_REPORT( L"Failed to CoCreate the Post Configuration Manager", hr );
  783. goto Cleanup;
  784. }
  785. // Check if this component supports the callback interface.
  786. hrTemp = THR( ppcm->TypeSafeQI( IClusCfgInitialize, &pcci ) );
  787. if ( FAILED( hrTemp ) )
  788. {
  789. LOG_STATUS_REPORT( L"Could not get a pointer to the IClusCfgInitialize interface. This post configuration manager does not support initialization", hr );
  790. } // if: the callback interface is not supported
  791. else
  792. {
  793. // Initialize this component.
  794. hr = THR( pcci->Initialize( punkCallback, m_lcid ) );
  795. if ( FAILED( hr ) )
  796. {
  797. LOG_STATUS_REPORT( L"Could not initialize the post configuration manager", hr );
  798. goto Cleanup;
  799. } // if: the initialization failed
  800. } // else: the callback interface is supported
  801. if ( m_punkEnumResources != NULL )
  802. {
  803. hr = THR( m_punkEnumResources->TypeSafeQI( IEnumClusCfgManagedResources, &peccmr ) );
  804. } // if:
  805. else
  806. {
  807. Assert( ( ecmCommitChangesMode != cmCREATE_CLUSTER ) && ( ecmCommitChangesMode != cmADD_NODE_TO_CLUSTER) );
  808. hr = THR( GetManagedResourcesEnum( &peccmr ) );
  809. } // else:
  810. //
  811. // If we are here, then the BaseCluster and Post configuration components were successfully
  812. // created and initialized. Now perform the desired action.
  813. //
  814. if ( ( ecmCommitChangesMode == cmCREATE_CLUSTER ) || ( ecmCommitChangesMode == cmADD_NODE_TO_CLUSTER ) )
  815. {
  816. if ( !m_fCanBeClustered )
  817. {
  818. //
  819. // TODO: 01-JUN-2000 GalenB
  820. //
  821. // Need better error code... What is the major and minor taskids?
  822. //
  823. hr = S_FALSE;
  824. LOG_STATUS_REPORT( L"It was previously determined that this node cannot be clustered.", hr );
  825. goto Cleanup;
  826. } // if: this node cannot be part of a cluster
  827. //
  828. // If the cluster service is being started for the first time, as a part
  829. // of adding this node to a cluster (forming or joining), then we have
  830. // to wait till the post-configuration steps are completed before we
  831. // can send out notifications. Create an event that indicates that post configuration
  832. // has completed.
  833. //
  834. TraceFlow1( "Trying to create an event named '%s'.", POSTCONFIG_COMPLETE_EVENT_NAME );
  835. // Create an event in the unsignalled state.
  836. heventPostCfgCompletion = CreateEvent(
  837. NULL // event security attributes
  838. , TRUE // manual-reset event
  839. , FALSE // create in unsignaled state
  840. , POSTCONFIG_COMPLETE_EVENT_NAME
  841. );
  842. if ( heventPostCfgCompletion == NULL )
  843. {
  844. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  845. LogMsg( L"[SRV] Error %#08x occurred trying to create an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  846. TraceFlow2( "Error %#08x occurred trying to create an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  847. goto Cleanup;
  848. } // if: we could not get a handle to the event
  849. // Reset the event, just as a safetly measure, in case the event already existed before the call above.
  850. if ( ResetEvent( heventPostCfgCompletion ) == 0 )
  851. {
  852. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  853. LogMsg( L"[SRV] Error %#08x occurred trying to unsignal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  854. TraceFlow2( "Error %#08x occurred trying to unsignal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  855. goto Cleanup;
  856. } // if: ResetEvent() failed()
  857. } // if: we are forming or joining
  858. if ( ecmCommitChangesMode == cmCREATE_CLUSTER )
  859. {
  860. // Commit the base cluster
  861. hr = THR( HrFormCluster( pClusCfgClusterInfo, (( IClusCfgBaseCluster * ) mqiInterfaces[ 0 ].pItf) ) );
  862. if ( FAILED( hr ) )
  863. {
  864. goto Cleanup;
  865. } // if:
  866. // Commit the post configuration steps
  867. hr = THR( ppcm->CommitChanges( peccmr, pClusCfgClusterInfo ) );
  868. if ( FAILED( hr ) )
  869. {
  870. goto Cleanup;
  871. } // if:
  872. // Signal the event to indicate that post configuration is complete.
  873. if ( SetEvent( heventPostCfgCompletion ) == 0 )
  874. {
  875. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  876. LogMsg( L"[SRV] Error %#08x occurred trying to signal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  877. TraceFlow2( "Error %#08x occurred trying to signal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  878. goto Cleanup;
  879. } // if: SetEvent() failed()
  880. } // if: we are forming a cluster.
  881. else if ( ecmCommitChangesMode == cmADD_NODE_TO_CLUSTER )
  882. {
  883. // Commit the base cluster
  884. hr = THR( HrJoinToCluster( pClusCfgClusterInfo, (( IClusCfgBaseCluster * ) mqiInterfaces[ 0 ].pItf) ) );
  885. if ( FAILED( hr ) )
  886. {
  887. goto Cleanup;
  888. } // if:
  889. // Commit the post configuration steps
  890. hr = THR( ppcm->CommitChanges( peccmr, pClusCfgClusterInfo ) );
  891. if ( FAILED( hr ) )
  892. {
  893. goto Cleanup;
  894. } // if:
  895. // Signal the event to indicate that post configuration is complete.
  896. if ( SetEvent( heventPostCfgCompletion ) == 0 )
  897. {
  898. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  899. LogMsg( L"[SRV] Error %#08x occurred trying to signal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  900. TraceFlow2( "Error %#08x occurred trying to signal an event named '%ls'.", hr, POSTCONFIG_COMPLETE_EVENT_NAME );
  901. goto Cleanup;
  902. } // if: SetEvent() failed()
  903. } // else if: we are joining a cluster
  904. else if ( ecmCommitChangesMode == cmCLEANUP_NODE_AFTER_EVICT )
  905. {
  906. // This node has been evicted - clean it up.
  907. hr = THR( HrEvictedFromCluster( ppcm, peccmr, pClusCfgClusterInfo, (( IClusCfgBaseCluster * ) mqiInterfaces[ 0 ].pItf) ) );
  908. if ( FAILED( hr ) )
  909. {
  910. goto Cleanup;
  911. } // if:
  912. } // else if: we have just been evicted from a cluster
  913. Cleanup:
  914. if ( punkCallback != NULL )
  915. {
  916. punkCallback->Release();
  917. } // if:
  918. if ( pcci != NULL )
  919. {
  920. pcci->Release();
  921. } // if:
  922. if ( ppcm != NULL )
  923. {
  924. ppcm->Release( );
  925. } // if:
  926. if ( peccmr != NULL )
  927. {
  928. peccmr->Release( );
  929. } // if:
  930. if ( mqiInterfaces[ 0 ].pItf != NULL )
  931. {
  932. mqiInterfaces[ 0 ].pItf->Release();
  933. } // if:
  934. if ( mqiInterfaces[ 1 ].pItf != NULL )
  935. {
  936. mqiInterfaces[ 1 ].pItf->Release();
  937. } // if:
  938. if ( pClusCfgClusterInfo != NULL )
  939. {
  940. pClusCfgClusterInfo->Release();
  941. } // if:
  942. if ( piccni != NULL )
  943. {
  944. piccni->Release();
  945. } // if:
  946. if ( heventPostCfgCompletion != NULL )
  947. {
  948. // If we had created this event, then signal this event to let the
  949. // startup notification thread proceed.
  950. SetEvent( heventPostCfgCompletion );
  951. CloseHandle( heventPostCfgCompletion );
  952. } // if:
  953. if ( FAILED( hr ) )
  954. {
  955. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_CommitChanges, IDS_ERROR_COMMIT_CHANGES, hr );
  956. } // if:
  957. else
  958. {
  959. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_CommitChanges, IDS_COMMIT_CHANGES, hr );
  960. } // else:
  961. HRETURN( hr );
  962. } //*** CClusCfgServer::CommitChanges
  963. //////////////////////////////////////////////////////////////////////////////
  964. //++
  965. //
  966. // CClusCfgServer::GetBindingString
  967. //
  968. // Description:
  969. // Get the binding string for this server.
  970. //
  971. // Arguments:
  972. //
  973. // Return Value:
  974. //
  975. // Remarks:
  976. // None.
  977. //
  978. //--
  979. //////////////////////////////////////////////////////////////////////////////
  980. STDMETHODIMP
  981. CClusCfgServer::GetBindingString( BSTR * pbstrBindingStringOut )
  982. {
  983. TraceFunc( "[IClusCfgServer]" );
  984. HRESULT hr = S_OK;
  985. if ( pbstrBindingStringOut == NULL )
  986. {
  987. hr = THR( E_POINTER );
  988. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetBindingString_Pointer, IDS_ERROR_NULL_POINTER, hr );
  989. goto Cleanup;
  990. } // if:
  991. if ( m_bstrBindingString == NULL )
  992. {
  993. hr = S_FALSE;
  994. LOG_STATUS_REPORT1( TASKID_Minor_Server_GetBindingString_NULL, L"Binding string is NULL. Must be a local connection.", hr );
  995. goto Cleanup;
  996. } // if:
  997. *pbstrBindingStringOut = SysAllocString( m_bstrBindingString );
  998. if ( *pbstrBindingStringOut == NULL )
  999. {
  1000. hr = THR( E_OUTOFMEMORY );
  1001. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Server_GetBindingString_Memory, IDS_ERROR_OUTOFMEMORY, hr );
  1002. } // if:
  1003. Cleanup:
  1004. HRETURN( hr );
  1005. } //*** CClusCfgServer::GetBindingString
  1006. //////////////////////////////////////////////////////////////////////////////
  1007. //++
  1008. //
  1009. // CClusCfgServer::SetBindingString
  1010. //
  1011. // Description:
  1012. // Set the binding string of this server.
  1013. //
  1014. // Arguments:
  1015. //
  1016. // Return Value:
  1017. //
  1018. // Remarks:
  1019. // None.
  1020. //
  1021. //--
  1022. //////////////////////////////////////////////////////////////////////////////
  1023. STDMETHODIMP
  1024. CClusCfgServer::SetBindingString( LPCWSTR pcszBindingStringIn )
  1025. {
  1026. TraceFunc1( "[IClusCfgServer] pcszBindingStringIn = '%ls'", pcszBindingStringIn == NULL ? L"<null>" : pcszBindingStringIn );
  1027. HRESULT hr = S_OK;
  1028. BSTR bstr = NULL;
  1029. if ( pcszBindingStringIn == NULL )
  1030. {
  1031. hr = THR( E_INVALIDARG );
  1032. goto Cleanup;
  1033. } // if:
  1034. bstr = TraceSysAllocString( pcszBindingStringIn );
  1035. if ( bstr == NULL )
  1036. {
  1037. hr = THR( E_OUTOFMEMORY );
  1038. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_SetBindingString_Server, IDS_ERROR_OUTOFMEMORY, hr );
  1039. goto Cleanup;
  1040. } // if:
  1041. TraceSysFreeString( m_bstrBindingString );
  1042. m_bstrBindingString = bstr;
  1043. Cleanup:
  1044. HRETURN( hr );
  1045. } //*** CClusCfgServer::SetBindingString
  1046. //*************************************************************************//
  1047. /////////////////////////////////////////////////////////////////////////////
  1048. // CClusCfgServer class -- IClusCfgCapabilities interfaces.
  1049. /////////////////////////////////////////////////////////////////////////////
  1050. //////////////////////////////////////////////////////////////////////////////
  1051. //++
  1052. //
  1053. // CClusCfgServer::CanNodeBeClustered
  1054. //
  1055. // Description:
  1056. // Can this node be added to a cluster?
  1057. //
  1058. // Arguments:
  1059. //
  1060. //
  1061. // Return Value:
  1062. // S_OK
  1063. // Node can be clustered.
  1064. //
  1065. // S_FALSE
  1066. // Node cannot be clustered.
  1067. //
  1068. // other HRESULTs
  1069. // The call failed.
  1070. //
  1071. // Remarks:
  1072. // None.
  1073. //
  1074. //--
  1075. //////////////////////////////////////////////////////////////////////////////
  1076. STDMETHODIMP
  1077. CClusCfgServer::CanNodeBeClustered( void )
  1078. {
  1079. TraceFunc( "[IClusCfgServer]" );
  1080. HRESULT hr;
  1081. ICatInformation * pici = NULL;
  1082. CATID rgCatIds[ 1 ];
  1083. IEnumCLSID * pieclsids = NULL;
  1084. IClusCfgCapabilities * piccc = NULL;
  1085. CLSID clsid;
  1086. ULONG cFetched;
  1087. IUnknown * punk = NULL;
  1088. //
  1089. // KB: 10-SEP-2000 GalenB
  1090. //
  1091. // Last ditch effort to clean up a node that is in a bad state before trying
  1092. // to add it into a cluster.
  1093. //
  1094. hr = STHR( HrHasNodeBeenEvicted() );
  1095. if ( hr == S_OK )
  1096. {
  1097. hr = THR( HrCleanUpNode() ) ;
  1098. if ( FAILED( hr ) )
  1099. {
  1100. goto Cleanup;
  1101. } // if:
  1102. } // if:
  1103. else if ( FAILED( hr ) )
  1104. {
  1105. goto Cleanup;
  1106. } // else if:
  1107. rgCatIds[ 0 ] = CATID_ClusCfgCapabilities;
  1108. hr = THR( CoCreateInstance( CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatInformation, (void **) &pici ) );
  1109. if ( FAILED( hr ) )
  1110. {
  1111. LOG_STATUS_REPORT( L"Failed to CoCreate CLSID_StdComponentCategoriesMgr component", hr );
  1112. goto Cleanup;
  1113. }
  1114. hr = THR( pici->EnumClassesOfCategories( 1, rgCatIds, 0, NULL, &pieclsids ) );
  1115. if ( FAILED( hr ) )
  1116. {
  1117. LOG_STATUS_REPORT( L"Failed to get enumerator for the IClusCfgClusterCapabilites components", hr );
  1118. goto Cleanup;
  1119. } // if:
  1120. for ( ; ; )
  1121. {
  1122. hr = STHR( pieclsids->Next( 1, &clsid, &cFetched ) );
  1123. if ( FAILED( hr ) )
  1124. {
  1125. LOG_STATUS_REPORT( L"IClusCfgClusterCapabilites component enumerator failed", hr );
  1126. break;
  1127. } // if:
  1128. if ( ( hr == S_FALSE ) && ( cFetched == 0 ) )
  1129. {
  1130. hr = S_OK;
  1131. break;
  1132. } // if:
  1133. hr = THR( HrCoCreateInternalInstance( clsid, NULL, CLSCTX_ALL, IID_IClusCfgCapabilities, (void **) &piccc ) );
  1134. if ( FAILED( hr ) )
  1135. {
  1136. LOG_STATUS_REPORT( L"Failed to CoCreate IClusCfgClusterCapabilites component", hr );
  1137. continue;
  1138. } // if:
  1139. hr = THR( piccc->TypeSafeQI( IUnknown, &punk ) );
  1140. if ( FAILED( hr ) )
  1141. {
  1142. LOG_STATUS_REPORT( L"Failed to QI IClusCfgClusterCapabilites component for IUnknown", hr );
  1143. piccc->Release();
  1144. piccc = NULL;
  1145. continue;
  1146. } // if:
  1147. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  1148. if ( FAILED( hr ) )
  1149. {
  1150. LOG_STATUS_REPORT( L"Failed to initialize IClusCfgClusterCapabilites component", hr );
  1151. piccc->Release();
  1152. piccc = NULL;
  1153. punk->Release();
  1154. punk = NULL;
  1155. continue;
  1156. } // if:
  1157. punk->Release();
  1158. punk = NULL;
  1159. hr = STHR( piccc->CanNodeBeClustered() );
  1160. if ( FAILED( hr ) )
  1161. {
  1162. LOG_STATUS_REPORT( L"IClusCfgClusterCapabilites component failed in CanNodeBeClustered()", hr );
  1163. piccc->Release();
  1164. piccc = NULL;
  1165. continue;
  1166. } // if:
  1167. if ( hr == S_FALSE )
  1168. {
  1169. m_fCanBeClustered = false;
  1170. } // if:
  1171. piccc->Release();
  1172. piccc = NULL;
  1173. } // for:
  1174. if ( !m_fCanBeClustered )
  1175. {
  1176. hr = S_FALSE;
  1177. } // if:
  1178. Cleanup:
  1179. if ( punk != NULL )
  1180. {
  1181. punk->Release();
  1182. } // if:
  1183. if ( piccc != NULL )
  1184. {
  1185. piccc->Release();
  1186. } // if:
  1187. if ( pieclsids != NULL )
  1188. {
  1189. pieclsids->Release();
  1190. } // if:
  1191. if ( pici != NULL )
  1192. {
  1193. pici->Release();
  1194. } // if:
  1195. HRETURN( hr );
  1196. } //*** CClusCfgServer::CanNodeBeClustered
  1197. //*************************************************************************//
  1198. /////////////////////////////////////////////////////////////////////////////
  1199. // CClusCfgServer class -- IClusCfgPollingCallbackInfo interface.
  1200. /////////////////////////////////////////////////////////////////////////////
  1201. //////////////////////////////////////////////////////////////////////////////
  1202. //++
  1203. //
  1204. // CClusCfgServer::GetCallback
  1205. //
  1206. // Description:
  1207. // Return the pointer to the embedded polling callback object.
  1208. //
  1209. // Arguments:
  1210. // ppiccpcOut
  1211. //
  1212. // Return Value:
  1213. // S_OK
  1214. // Success
  1215. //
  1216. // Remarks:
  1217. // None.
  1218. //
  1219. //--
  1220. //////////////////////////////////////////////////////////////////////////////
  1221. STDMETHODIMP
  1222. CClusCfgServer::GetCallback( IClusCfgPollingCallback ** ppiccpcOut )
  1223. {
  1224. TraceFunc( "[IClusCfgServer]" );
  1225. Assert( m_picccCallback != NULL );
  1226. HRESULT hr = S_OK;
  1227. if ( ppiccpcOut == NULL )
  1228. {
  1229. hr = THR( E_POINTER );
  1230. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_GetCallback, IDS_ERROR_NULL_POINTER, hr );
  1231. goto Cleanup;
  1232. } // if:
  1233. hr = THR( m_picccCallback->TypeSafeQI( IClusCfgPollingCallback, ppiccpcOut ) );
  1234. Cleanup:
  1235. HRETURN( hr );
  1236. } //*** CClusCfgServer::GetCallback
  1237. //////////////////////////////////////////////////////////////////////////////
  1238. //++
  1239. //
  1240. // CClusCfgServer::SetPollingMode
  1241. //
  1242. // Description:
  1243. // Set the polling mode of the callback.
  1244. //
  1245. // Arguments:
  1246. // fPollingModeIn
  1247. //
  1248. // Return Value:
  1249. // S_OK
  1250. // Success
  1251. //
  1252. // Remarks:
  1253. // None.
  1254. //
  1255. //--
  1256. //////////////////////////////////////////////////////////////////////////////
  1257. STDMETHODIMP
  1258. CClusCfgServer::SetPollingMode( BOOL fPollingModeIn )
  1259. {
  1260. TraceFunc( "[IClusCfgServer]" );
  1261. Assert( m_picccCallback != NULL );
  1262. HRESULT hr = S_OK;
  1263. IClusCfgSetPollingCallback * piccspc = NULL;
  1264. m_fUsePolling = fPollingModeIn;
  1265. hr = THR( m_picccCallback->TypeSafeQI( IClusCfgSetPollingCallback, &piccspc ) );
  1266. if ( FAILED( hr ) )
  1267. {
  1268. goto Cleanup;
  1269. } // if:
  1270. hr = THR( piccspc->SetPollingMode( m_fUsePolling ) );
  1271. Cleanup:
  1272. if ( piccspc != NULL )
  1273. {
  1274. piccspc->Release();
  1275. } // if:
  1276. HRETURN( hr );
  1277. } //*** CClusCfgServer::SetPollingMode
  1278. //*************************************************************************//
  1279. /////////////////////////////////////////////////////////////////////////////
  1280. // CClusCfgServer class -- IClusCfgVerify interface.
  1281. /////////////////////////////////////////////////////////////////////////////
  1282. //////////////////////////////////////////////////////////////////////////////
  1283. //++
  1284. //
  1285. // CClusCfgServer::VerifyCredentials
  1286. //
  1287. // Description:
  1288. // Validate the passed in credentials.
  1289. //
  1290. // Arguments:
  1291. //
  1292. // Return Value:
  1293. // S_OK
  1294. // The credentials are valid.
  1295. //
  1296. // other HRESULTs
  1297. // The call failed.
  1298. //
  1299. // Remarks:
  1300. // None.
  1301. //
  1302. //--
  1303. //////////////////////////////////////////////////////////////////////////////
  1304. STDMETHODIMP
  1305. CClusCfgServer::VerifyCredentials(
  1306. LPCWSTR pcszNameIn,
  1307. LPCWSTR pcszDomainIn,
  1308. LPCWSTR pcszPasswordIn
  1309. )
  1310. {
  1311. TraceFunc( "[IClusCfgVerify]" );
  1312. HRESULT hr = S_OK;
  1313. HANDLE hToken = NULL;
  1314. //
  1315. // Logon the passed in user to ensure that it is valid.
  1316. //
  1317. //
  1318. // KB: 04 May 2000 GalenB
  1319. //
  1320. // New for Whistler... You no longer have to grant your processes TCB privilege. But it doesn't seem to work!
  1321. //
  1322. if ( !LogonUserW(
  1323. const_cast< LPWSTR >( pcszNameIn )
  1324. , const_cast< LPWSTR >( pcszDomainIn )
  1325. , const_cast< LPWSTR >( pcszPasswordIn )
  1326. , LOGON32_LOGON_NETWORK
  1327. , LOGON32_PROVIDER_DEFAULT
  1328. , &hToken
  1329. ) )
  1330. {
  1331. DWORD sc;
  1332. sc = TW32( GetLastError() );
  1333. hr = HRESULT_FROM_WIN32( sc );
  1334. } // if:
  1335. if ( hToken != NULL )
  1336. {
  1337. CloseHandle( hToken );
  1338. } // if:
  1339. HRETURN( hr );
  1340. } //*** CClusCfgServer::VerifyCredentials
  1341. //////////////////////////////////////////////////////////////////////////////
  1342. //++
  1343. //
  1344. // CClusCfgServer::VerifyConnectionToCluster
  1345. //
  1346. // Description:
  1347. // Verify that that this server is the same as the passed in server.
  1348. //
  1349. // Arguments:
  1350. // pcszClusterNameIn
  1351. //
  1352. // Return Value:
  1353. // S_OK
  1354. // This is the server.
  1355. //
  1356. // S_FALSE
  1357. // This is not the server.
  1358. //
  1359. // other HRESULTs
  1360. // The call failed.
  1361. //
  1362. // Remarks:
  1363. // None.
  1364. //
  1365. //--
  1366. //////////////////////////////////////////////////////////////////////////////
  1367. STDMETHODIMP
  1368. CClusCfgServer::VerifyConnectionToCluster(
  1369. LPCWSTR pcszClusterNameIn
  1370. )
  1371. {
  1372. TraceFunc1( "[IClusCfgVerify] pcszClusterNameIn = '%ls'", pcszClusterNameIn );
  1373. DWORD sc;
  1374. DWORD dwClusterState;
  1375. HRESULT hr = S_FALSE;
  1376. HCLUSTER hCluster = NULL;
  1377. BSTR bstrClusterName = NULL;
  1378. BSTR bstrDomainName = NULL;
  1379. WCHAR * psz = NULL;
  1380. size_t cch;
  1381. //
  1382. // Test arguments
  1383. //
  1384. if ( pcszClusterNameIn == NULL )
  1385. {
  1386. goto InvalidArg;
  1387. } // if:
  1388. //
  1389. // See if we are clustered.
  1390. //
  1391. sc = TW32( GetNodeClusterState( NULL, &dwClusterState ) );
  1392. if ( sc != ERROR_SUCCESS )
  1393. {
  1394. hr = HRESULT_FROM_WIN32( sc );
  1395. goto Cleanup;
  1396. } // if : GetClusterState() failed
  1397. //
  1398. // If the current cluster node state is running or not running then this node is part of a cluster.
  1399. //
  1400. if ( ( dwClusterState != ClusterStateNotRunning ) && ( dwClusterState != ClusterStateRunning ) )
  1401. {
  1402. hr = S_FALSE;
  1403. goto Cleanup;
  1404. } // if:
  1405. //
  1406. // Open the cluster to get the cluster's name.
  1407. //
  1408. hCluster = OpenCluster( NULL );
  1409. if ( hCluster == NULL )
  1410. {
  1411. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  1412. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_VerifyConnection_OpenCluster, IDS_ERROR_OPEN_CLUSTER_FAILED, hr );
  1413. goto Cleanup;
  1414. } // if:
  1415. //
  1416. // Try to get the cluster's name.
  1417. //
  1418. hr = THR( HrGetClusterInformation( hCluster, &bstrClusterName, NULL ) );
  1419. if ( FAILED( hr ) )
  1420. {
  1421. goto Cleanup;
  1422. } // if:
  1423. cch = wcslen( bstrClusterName );
  1424. //
  1425. // See if the domain name was given.
  1426. //
  1427. psz = wcschr( pcszClusterNameIn, L'.' );
  1428. if ( psz == NULL )
  1429. {
  1430. //
  1431. // If no domain was given, see if it matches the cluster's name.
  1432. //
  1433. if ( _wcsicmp( bstrClusterName, pcszClusterNameIn ) == 0 )
  1434. {
  1435. hr = S_OK;
  1436. goto Cleanup;
  1437. } // if:
  1438. goto Cleanup;
  1439. } // if:
  1440. //
  1441. // If if the cluster name matches.
  1442. //
  1443. if ( (size_t) ( psz - pcszClusterNameIn ) != cch )
  1444. {
  1445. goto Cleanup; // nope
  1446. } // if:
  1447. if ( ( wcslen( pcszClusterNameIn ) < cch ) || ( memcmp( bstrClusterName, pcszClusterNameIn, cch ) != 0 ) )
  1448. {
  1449. goto Cleanup;
  1450. } // if:
  1451. //
  1452. // Make sure we are in the same domain.
  1453. //
  1454. hr = THR( HrGetComputerName( ComputerNameDnsDomain, &bstrDomainName ) );
  1455. if ( FAILED( hr ) )
  1456. {
  1457. goto Cleanup;
  1458. } // if:
  1459. psz++;
  1460. if ( _wcsicmp( bstrDomainName, psz ) == 0 )
  1461. {
  1462. hr = S_OK;
  1463. goto Cleanup;
  1464. } // if:
  1465. Assert( hr == S_FALSE );
  1466. goto Cleanup;
  1467. InvalidArg:
  1468. hr = THR( E_INVALIDARG );
  1469. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_VerifyConnection_InvalidArg, IDS_ERROR_INVALIDARG, hr );
  1470. goto Cleanup;
  1471. Cleanup:
  1472. if ( hr == S_FALSE )
  1473. {
  1474. LOG_STATUS_REPORT( L"Server name does not match what client is expecting.", hr );
  1475. } // if:
  1476. else if ( hr == S_OK )
  1477. {
  1478. LOG_STATUS_REPORT( L"Server name matches what client is expecting.", hr );
  1479. } // else if:
  1480. if ( hCluster != NULL )
  1481. {
  1482. CloseCluster( hCluster );
  1483. } // if:
  1484. TraceSysFreeString( bstrClusterName );
  1485. TraceSysFreeString( bstrDomainName );
  1486. HRETURN( hr );
  1487. } // ClusCfgServer::VerifyConnection
  1488. //////////////////////////////////////////////////////////////////////////////
  1489. //++
  1490. //
  1491. // CClusCfgServer::VerifyConnectionToNode
  1492. //
  1493. // Description:
  1494. // Verify that that this server is the same as the passed in server.
  1495. //
  1496. // Arguments:
  1497. // pcszNodeNameIn
  1498. //
  1499. // Return Value:
  1500. // S_OK
  1501. // This is the server.
  1502. //
  1503. // S_FALSE
  1504. // This is not the server.
  1505. //
  1506. // other HRESULTs
  1507. // The call failed.
  1508. //
  1509. // Remarks:
  1510. // None.
  1511. //
  1512. //--
  1513. //////////////////////////////////////////////////////////////////////////////
  1514. STDMETHODIMP
  1515. CClusCfgServer::VerifyConnectionToNode(
  1516. LPCWSTR pcszNodeNameIn
  1517. )
  1518. {
  1519. TraceFunc1( "[IClusCfgVerify] pcszNodeNameIn = '%ls'", pcszNodeNameIn );
  1520. HRESULT hr = S_FALSE;
  1521. LPWSTR psz;
  1522. //
  1523. // Test arguments
  1524. //
  1525. if ( pcszNodeNameIn == NULL )
  1526. {
  1527. goto InvalidArg;
  1528. } // if:
  1529. //
  1530. // Test state.
  1531. //
  1532. if ( m_bstrNodeName == NULL )
  1533. {
  1534. goto OutOfMemory;
  1535. } // if:
  1536. //
  1537. // See if it matches the nodes name.
  1538. //
  1539. if ( _wcsicmp( pcszNodeNameIn, m_bstrNodeName ) == 0 )
  1540. {
  1541. hr = S_OK;
  1542. goto Cleanup;
  1543. } // if:
  1544. //
  1545. // If there isn't a domain attached to the node name, then check only
  1546. // the hostname.
  1547. //
  1548. psz = wcschr( pcszNodeNameIn, L'.' );
  1549. if ( psz == NULL )
  1550. {
  1551. if ( _wcsnicmp( pcszNodeNameIn, m_bstrNodeName, wcslen( pcszNodeNameIn ) ) == 0 )
  1552. {
  1553. hr = S_OK;
  1554. goto Cleanup;
  1555. } // if:
  1556. } // if:
  1557. Assert( hr == S_FALSE );
  1558. goto Cleanup;
  1559. InvalidArg:
  1560. LogMsg( L"[SRV] VerifyConnection - Invalid argument." );
  1561. hr = THR( E_INVALIDARG );
  1562. goto Cleanup;
  1563. OutOfMemory:
  1564. LogMsg( L"[SRV] VerifyConnection - out of memory." );
  1565. hr = E_OUTOFMEMORY;
  1566. Cleanup:
  1567. if ( hr == S_FALSE )
  1568. {
  1569. LogMsg( L"[SRV] VerifyConnection - Server name does not match what client is expecting." );
  1570. } // if:
  1571. else if ( hr == S_OK )
  1572. {
  1573. LogMsg( L"[SRV] VerifyConnection - Server name matches what client is expecting." );
  1574. } // else if:
  1575. HRETURN( hr );
  1576. } // ClusCfgServer::VerifyConnection
  1577. //*************************************************************************//
  1578. /////////////////////////////////////////////////////////////////////////////
  1579. // CClusCfgServer class -- Private Methods.
  1580. /////////////////////////////////////////////////////////////////////////////
  1581. //////////////////////////////////////////////////////////////////////////////
  1582. //++
  1583. //
  1584. // CClusCfgServer::HrInit
  1585. //
  1586. // Description:
  1587. // Initialize this component.
  1588. //
  1589. // Arguments:
  1590. //
  1591. //
  1592. // Return Value:
  1593. // S_OK
  1594. // Success
  1595. //
  1596. // Remarks:
  1597. // None.
  1598. //
  1599. //--
  1600. //////////////////////////////////////////////////////////////////////////////
  1601. HRESULT
  1602. CClusCfgServer::HrInit( void )
  1603. {
  1604. TraceFunc( "" );
  1605. HRESULT hr = S_FALSE;
  1606. IUnknown * punk = NULL;
  1607. hr = THR( CClusCfgCallback::S_HrCreateInstance( &punk ) );
  1608. if ( FAILED ( hr ) )
  1609. {
  1610. LogMsg( L"[SRV] Could not create CClusCfgCallback. (hr = %#08x)", hr );
  1611. goto Cleanup;
  1612. } // if:
  1613. hr = THR( punk->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  1614. if ( FAILED( hr ) )
  1615. {
  1616. LogMsg( L"[SRV] Could not QI callback for a punk. (hr = %#08x)", hr );
  1617. goto Cleanup;
  1618. } // if:
  1619. hr = THR( HrGetComputerName( ComputerNameDnsFullyQualified, &m_bstrNodeName ) );
  1620. Cleanup:
  1621. if ( punk != NULL )
  1622. {
  1623. punk->Release();
  1624. } // if:
  1625. HRETURN( hr );
  1626. } //*** CClusCfgServer::HrInit
  1627. //////////////////////////////////////////////////////////////////////////////
  1628. //++
  1629. //
  1630. // CClusCfgServer::HrInitializeForLocalServer
  1631. //
  1632. // Description:
  1633. // Initialize this component.
  1634. //
  1635. // Arguments:
  1636. //
  1637. //
  1638. // Return Value:
  1639. // S_OK
  1640. // Success
  1641. //
  1642. // Remarks:
  1643. // None.
  1644. //
  1645. //--
  1646. //////////////////////////////////////////////////////////////////////////////
  1647. HRESULT
  1648. CClusCfgServer::HrInitializeForLocalServer( void )
  1649. {
  1650. TraceFunc( "" );
  1651. HRESULT hr = S_OK;
  1652. IWbemLocator * pIWbemLocator = NULL;
  1653. BSTR bstrNameSpace = NULL;
  1654. hr = CoCreateInstance( CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pIWbemLocator );
  1655. if ( FAILED( hr ) )
  1656. {
  1657. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_HrInitializeForLocalServer_WbemLocator, IDS_ERROR_WBEM_LOCATOR_CREATE_FAILED, hr );
  1658. goto Cleanup;
  1659. } // if:
  1660. bstrNameSpace = TraceSysAllocString( L"\\\\.\\root\\cimv2" );
  1661. if ( bstrNameSpace == NULL )
  1662. {
  1663. hr = THR( E_OUTOFMEMORY );
  1664. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_HrInitializeForLocalServer_Memory, IDS_ERROR_OUTOFMEMORY, hr );
  1665. goto Cleanup;
  1666. } // if:
  1667. hr = THR( pIWbemLocator->ConnectServer(
  1668. bstrNameSpace,
  1669. NULL, // using current account for simplicity
  1670. NULL, // using current password for simplicity
  1671. NULL, // locale
  1672. 0L, // securityFlags, reserved must be 0
  1673. NULL, // authority (domain for NTLM)
  1674. NULL, // context
  1675. &m_pIWbemServices
  1676. ) );
  1677. if ( FAILED( hr ) )
  1678. {
  1679. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_WBEM_Connection_Failure, IDS_ERROR_WBEM_CONNECTION_FAILURE, hr );
  1680. goto Cleanup;
  1681. } // if:
  1682. hr = THR( HrSetBlanket() );
  1683. if ( FAILED( hr ) )
  1684. {
  1685. STATUS_REPORT( TASKID_Major_Establish_Connection, TASKID_Minor_HrInitializeForLocalServer_Blanket, IDS_ERROR_WBEM_BLANKET_FAILURE, hr );
  1686. goto Cleanup;
  1687. } // if:
  1688. Cleanup:
  1689. TraceSysFreeString( bstrNameSpace );
  1690. if ( pIWbemLocator != NULL )
  1691. {
  1692. pIWbemLocator->Release();
  1693. } // if:
  1694. HRETURN( hr );
  1695. } //*** CClusCfgServer::HrInitializeForLocalServer
  1696. //////////////////////////////////////////////////////////////////////////////
  1697. //++
  1698. //
  1699. // CClusCfgServer::HrSetBlanket
  1700. //
  1701. // Description:
  1702. // Adjusts the security blanket on the IWbemServices pointer.
  1703. //
  1704. // Arguments:
  1705. // None.
  1706. //
  1707. // Return Value:
  1708. //
  1709. //
  1710. // Remarks:
  1711. // None.
  1712. //
  1713. //--
  1714. //////////////////////////////////////////////////////////////////////////////
  1715. HRESULT
  1716. CClusCfgServer::HrSetBlanket( void )
  1717. {
  1718. TraceFunc( "" );
  1719. Assert( m_pIWbemServices != NULL );
  1720. HRESULT hr = S_FALSE;
  1721. if ( m_pIWbemServices )
  1722. {
  1723. IClientSecurity * pCliSec;
  1724. hr = THR( m_pIWbemServices->TypeSafeQI( IClientSecurity, &pCliSec ) );
  1725. if ( SUCCEEDED( hr ) )
  1726. {
  1727. hr = THR( pCliSec->SetBlanket(
  1728. m_pIWbemServices,
  1729. RPC_C_AUTHN_WINNT,
  1730. RPC_C_AUTHZ_NONE,
  1731. NULL,
  1732. RPC_C_AUTHN_LEVEL_CONNECT,
  1733. RPC_C_IMP_LEVEL_IMPERSONATE,
  1734. NULL,
  1735. EOAC_NONE
  1736. ) );
  1737. pCliSec->Release();
  1738. } // if:
  1739. } // if:
  1740. HRETURN( hr );
  1741. } //*** CClusCfgServer::HrSetBlanket
  1742. //////////////////////////////////////////////////////////////////////////////
  1743. //++
  1744. //
  1745. // CClusCfgServer::HrFormCluster
  1746. //
  1747. // Description:
  1748. // Form a new cluster.
  1749. //
  1750. // Arguments:
  1751. // None.
  1752. //
  1753. // Return Value:
  1754. //
  1755. //
  1756. // Remarks:
  1757. // None.
  1758. //
  1759. //--
  1760. //////////////////////////////////////////////////////////////////////////////
  1761. HRESULT
  1762. CClusCfgServer::HrFormCluster(
  1763. IClusCfgClusterInfo * piccciIn,
  1764. IClusCfgBaseCluster * piccbcaIn
  1765. )
  1766. {
  1767. TraceFunc( "" );
  1768. HRESULT hr;
  1769. BSTR bstrClusterName = NULL;
  1770. BSTR bstrClusterBindingString = NULL;
  1771. BSTR bstrClusterAccountName = NULL;
  1772. BSTR bstrClusterAccountPwd = NULL;
  1773. BSTR bstrClusterAccountDomain = NULL;
  1774. BSTR bstrClusterIPNetwork = NULL;
  1775. ULONG ulClusterIPAddress = 0;
  1776. ULONG ulClusterIPSubnetMask = 0;
  1777. IClusCfgCredentials * picccServiceAccount = NULL;
  1778. IClusCfgNetworkInfo * piccni = NULL;
  1779. //
  1780. // Get the parameters required to form a cluster.
  1781. //
  1782. hr = THR( piccciIn->GetName( &bstrClusterName ) );
  1783. if ( FAILED( hr ) )
  1784. {
  1785. goto Cleanup;
  1786. } // if: we could not get the name of the cluster
  1787. TraceMemoryAddBSTR( bstrClusterName );
  1788. hr = STHR( piccciIn->GetBindingString( &bstrClusterBindingString ) );
  1789. if ( FAILED( hr ) )
  1790. {
  1791. goto Cleanup;
  1792. } // if: we could not get the binding string of the cluster.
  1793. TraceMemoryAddBSTR( bstrClusterBindingString );
  1794. hr = THR( piccciIn->GetClusterServiceAccountCredentials( &picccServiceAccount ) );
  1795. if ( FAILED( hr ) )
  1796. {
  1797. goto Cleanup;
  1798. } // if: we could not get the cluster service account credentials
  1799. hr = THR( picccServiceAccount->GetCredentials( &bstrClusterAccountName, &bstrClusterAccountDomain, &bstrClusterAccountPwd ) );
  1800. if ( FAILED( hr ) )
  1801. {
  1802. goto Cleanup;
  1803. } // if: we could not get the service account name. domain and password.
  1804. TraceMemoryAddBSTR( bstrClusterAccountName );
  1805. TraceMemoryAddBSTR( bstrClusterAccountDomain );
  1806. TraceMemoryAddBSTR( bstrClusterAccountPwd );
  1807. hr = THR( piccciIn->GetIPAddress( &ulClusterIPAddress ) );
  1808. if ( FAILED( hr ) )
  1809. {
  1810. goto Cleanup;
  1811. } // if: we could not get the cluster IP address
  1812. hr = THR( piccciIn->GetSubnetMask( &ulClusterIPSubnetMask ) );
  1813. if ( FAILED( hr ) )
  1814. {
  1815. goto Cleanup;
  1816. } // if: we could not get the cluster subnet mask
  1817. hr = THR( piccciIn->GetNetworkInfo( &piccni ) );
  1818. if ( FAILED( hr ) )
  1819. {
  1820. goto Cleanup;
  1821. } // if: we could not get the network info of the network the cluster name should be on.
  1822. hr = THR( piccni->GetName( &bstrClusterIPNetwork ) );
  1823. if ( FAILED( hr ) )
  1824. {
  1825. goto Cleanup;
  1826. } // if: we could not get the name of the cluster name network.
  1827. TraceMemoryAddBSTR( bstrClusterIPNetwork );
  1828. //
  1829. // Indicate that a cluster should be formed when Commit() is called.
  1830. //
  1831. hr = THR( piccbcaIn->SetForm(
  1832. bstrClusterName
  1833. , bstrClusterBindingString
  1834. , bstrClusterAccountName
  1835. , bstrClusterAccountPwd
  1836. , bstrClusterAccountDomain
  1837. , ulClusterIPAddress
  1838. , ulClusterIPSubnetMask
  1839. , bstrClusterIPNetwork
  1840. ) );
  1841. if ( FAILED( hr ) )
  1842. {
  1843. goto Cleanup;
  1844. } // if: SetForm() failed.
  1845. // Initiate cluster formation.
  1846. hr = THR( piccbcaIn->Commit() );
  1847. Cleanup:
  1848. TraceSysFreeString( bstrClusterName );
  1849. TraceSysFreeString( bstrClusterBindingString );
  1850. TraceSysFreeString( bstrClusterAccountName );
  1851. TraceSysFreeString( bstrClusterAccountPwd );
  1852. TraceSysFreeString( bstrClusterAccountDomain );
  1853. TraceSysFreeString( bstrClusterIPNetwork );
  1854. if ( piccni != NULL )
  1855. {
  1856. piccni->Release();
  1857. } // if:
  1858. if ( picccServiceAccount != NULL )
  1859. {
  1860. picccServiceAccount->Release();
  1861. } // if:
  1862. HRETURN( hr );
  1863. } //*** CClusCfgServer::HrFormCluster
  1864. //////////////////////////////////////////////////////////////////////////////
  1865. //++
  1866. //
  1867. // CClusCfgServer::HrJoinToCluster
  1868. //
  1869. // Description:
  1870. // Join a node to a cluster.
  1871. //
  1872. // Arguments:
  1873. // None.
  1874. //
  1875. // Return Value:
  1876. //
  1877. //
  1878. // Remarks:
  1879. // None.
  1880. //
  1881. //--
  1882. //////////////////////////////////////////////////////////////////////////////
  1883. HRESULT
  1884. CClusCfgServer::HrJoinToCluster(
  1885. IClusCfgClusterInfo * piccciIn,
  1886. IClusCfgBaseCluster * piccbcaIn
  1887. )
  1888. {
  1889. TraceFunc( "" );
  1890. HRESULT hr;
  1891. BSTR bstrClusterName = NULL;
  1892. BSTR bstrClusterBindingString = NULL;
  1893. BSTR bstrClusterAccountName = NULL;
  1894. BSTR bstrClusterAccountPwd = NULL;
  1895. BSTR bstrClusterAccountDomain = NULL;
  1896. IClusCfgCredentials * picccServiceAccount = NULL;
  1897. //
  1898. // Get the parameters required to form a cluster.
  1899. //
  1900. hr = THR( piccciIn->GetName( &bstrClusterName ) );
  1901. if ( FAILED( hr ) )
  1902. {
  1903. goto Cleanup;
  1904. } // if: we could not get the name of the cluster
  1905. TraceMemoryAddBSTR( bstrClusterName );
  1906. hr = THR( piccciIn->GetBindingString( &bstrClusterBindingString ) );
  1907. if ( FAILED( hr ) )
  1908. {
  1909. goto Cleanup;
  1910. } // if: we could not get the cluster binding string.
  1911. TraceMemoryAddBSTR( bstrClusterBindingString );
  1912. hr = THR( piccciIn->GetClusterServiceAccountCredentials( &picccServiceAccount ) );
  1913. if ( FAILED( hr ) )
  1914. {
  1915. goto Cleanup;
  1916. } // if: we could not get the cluster service account credentials
  1917. hr = THR( picccServiceAccount->GetCredentials( &bstrClusterAccountName, &bstrClusterAccountDomain, &bstrClusterAccountPwd ) );
  1918. if ( FAILED( hr ) )
  1919. {
  1920. goto Cleanup;
  1921. } // if: we could not get the service account name. domain and password.
  1922. TraceMemoryAddBSTR( bstrClusterAccountName );
  1923. TraceMemoryAddBSTR( bstrClusterAccountDomain );
  1924. TraceMemoryAddBSTR( bstrClusterAccountPwd );
  1925. //
  1926. // Indicate that a cluster should be formed when Commit() is called.
  1927. //
  1928. hr = THR( piccbcaIn->SetJoin( bstrClusterName, bstrClusterBindingString, bstrClusterAccountName, bstrClusterAccountPwd, bstrClusterAccountDomain ) );
  1929. if ( FAILED( hr ) )
  1930. {
  1931. goto Cleanup;
  1932. } // if: SetJoin() failed.
  1933. // Initiate joining of the node to the cluster.
  1934. hr = THR( piccbcaIn->Commit() );
  1935. Cleanup:
  1936. TraceSysFreeString( bstrClusterName );
  1937. TraceSysFreeString( bstrClusterBindingString );
  1938. TraceSysFreeString( bstrClusterAccountName );
  1939. TraceSysFreeString( bstrClusterAccountPwd );
  1940. TraceSysFreeString( bstrClusterAccountDomain );
  1941. if ( picccServiceAccount != NULL )
  1942. {
  1943. picccServiceAccount->Release();
  1944. } // if:
  1945. HRETURN( hr );
  1946. } //*** CClusCfgServer::HrJoinToCluster
  1947. //////////////////////////////////////////////////////////////////////////////
  1948. //++
  1949. //
  1950. // CClusCfgServer::HrEvictedFromCluster
  1951. //
  1952. // Description:
  1953. // Cleanup after a node has been evicted from a cluster. If another cleanup
  1954. // session is in progress, wait for it to complete and then attempt cleanup.
  1955. // In this way, if the other cleanup failed, this will retry it. If it had
  1956. // suceeded, this will do nothing.
  1957. //
  1958. // This function first calls the CommitChanges() method of the PostConfigManager
  1959. // (which will inform resource types and memberset listeners that this node
  1960. // has been evicted). It then cleans up the base cluster.
  1961. //
  1962. // Arguments:
  1963. // IPostCfgManager * ppcmIn
  1964. // Pointer to the IPostCfgManager interface
  1965. //
  1966. // IEnumClusCfgManagedResources * peccmrIn
  1967. // Argument needed by the IPostCfgManager::CommitChanges()
  1968. //
  1969. // IClusCfgClusterInfo * piccciIn
  1970. // Pointer to the cluster info
  1971. //
  1972. // IClusCfgBaseCluster * piccbcaIn
  1973. // Pointer to the IClusCfgBaseCluster interface that is used to clean up
  1974. // the base cluster.
  1975. //
  1976. // Return Value:
  1977. // S_OK
  1978. // If everything went well
  1979. //
  1980. // other HRESULTs
  1981. // If the call failed
  1982. //
  1983. // Remarks:
  1984. // None.
  1985. //
  1986. //--
  1987. //////////////////////////////////////////////////////////////////////////////
  1988. HRESULT
  1989. CClusCfgServer::HrEvictedFromCluster(
  1990. IPostCfgManager * ppcmIn,
  1991. IEnumClusCfgManagedResources * peccmrIn,
  1992. IClusCfgClusterInfo * piccciIn,
  1993. IClusCfgBaseCluster * piccbcaIn
  1994. )
  1995. {
  1996. TraceFunc( "" );
  1997. HRESULT hr = S_OK;
  1998. DWORD dwStatus = ERROR_SUCCESS;
  1999. HANDLE hsCleanupLock = NULL;
  2000. HANDLE heventCleanupComplete = NULL;
  2001. bool fLockAcquired = false;
  2002. DWORD dwClusterState;
  2003. HKEY hNodeStateKey = NULL;
  2004. DWORD dwEvictState = 1;
  2005. TraceFlow( "Trying to create cleanup lock." );
  2006. // First, try and acquire a lock, so that two cleanup operations cannot overlap.
  2007. hsCleanupLock = CreateSemaphore( NULL, 1, 1, CLEANUP_LOCK_NAME );
  2008. if ( hsCleanupLock == NULL )
  2009. {
  2010. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  2011. TraceFlow1( "Error %#x occurred trying to create the cleanup lock.", hr );
  2012. LogMsg( "Error %#08x occurred trying to create the cleanup lock.", hr );
  2013. goto Cleanup;
  2014. } // CreateSemaphore() failed
  2015. TraceFlow( "Created cleanup lock. Now, trying to acquire it." );
  2016. LogMsg( "Trying to acquire cleanup lock." );
  2017. do
  2018. {
  2019. // Wait for any message sent or posted to this queue
  2020. // or for our lock to be released.
  2021. dwStatus = MsgWaitForMultipleObjects(
  2022. 1
  2023. , &hsCleanupLock
  2024. , FALSE
  2025. , 300000 // If this lock has not been released in 5 minutes, abort.
  2026. , QS_ALLINPUT
  2027. );
  2028. // The result tells us the type of event we have.
  2029. if ( dwStatus == ( WAIT_OBJECT_0 + 1 ) )
  2030. {
  2031. MSG msg;
  2032. // Read all of the messages in this next loop,
  2033. // removing each message as we read it.
  2034. while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != 0 )
  2035. {
  2036. // If it is a quit message, we are done pumping messages.
  2037. if ( msg.message == WM_QUIT)
  2038. {
  2039. TraceFlow( "Get a WM_QUIT message. Cleanup message pump loop." );
  2040. break;
  2041. } // if: we got a WM_QUIT message
  2042. // Otherwise, dispatch the message.
  2043. DispatchMessage( &msg );
  2044. } // while: there are still messages in the window message queue
  2045. } // if: we have a message in the window message queue
  2046. else
  2047. {
  2048. if ( dwStatus == WAIT_OBJECT_0 )
  2049. {
  2050. fLockAcquired = true;
  2051. LogMsg( "Cleanup lock acquired." );
  2052. TraceFlow( "Our lock has been granted. Exiting wait loop." );
  2053. break;
  2054. } // else if: our lock is signaled
  2055. else
  2056. {
  2057. if ( dwStatus == -1 )
  2058. {
  2059. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  2060. LogMsg( "Error %#x occurred trying to wait for our lock to be granted.", hr );
  2061. TraceFlow1( "Error %#x occurred trying to wait for our lock to be granted.", hr );
  2062. } // if: MsgWaitForMultipleObjects() returned an error
  2063. else
  2064. {
  2065. hr = THR( HRESULT_FROM_WIN32( dwStatus ) );
  2066. LogMsg( "An error occurred trying to wait for our lock to be granted. Status code is %#x.", dwStatus );
  2067. TraceFlow1( "An error occurred trying to wait for our lock to be granted. Status code is %#x.", dwStatus );
  2068. } // else: an unexpected value was returned by MsgWaitForMultipleObjects()
  2069. break;
  2070. } // else: an unexpected result
  2071. } // else: MsgWaitForMultipleObjects() exited for a reason other than a waiting message
  2072. }
  2073. while( true ); // do-while: loop infinitely
  2074. if ( FAILED( hr ) )
  2075. {
  2076. goto Cleanup;
  2077. } // if: we could not acquire the cleanup lock
  2078. // Check if the install state is correct before invoking post configuration manager.
  2079. dwStatus = TW32( GetNodeClusterState( NULL, &dwClusterState ) );
  2080. if ( dwStatus != ERROR_SUCCESS )
  2081. {
  2082. TraceFlow1( "Error %#x occurred trying to determine the installation state of this node.", dwStatus );
  2083. LogMsg( "Error %#x occurred trying to determine the installation state of this node.", dwStatus );
  2084. hr = HRESULT_FROM_WIN32( dwStatus );
  2085. goto Cleanup;
  2086. } // if : GetClusterState() failed
  2087. // Check if this node is part of a cluster.
  2088. if ( ( dwClusterState != ClusterStateNotRunning ) && ( dwClusterState != ClusterStateRunning ) )
  2089. {
  2090. TraceFlow( "This node is not part of a cluster - no cleanup is necessary." );
  2091. LogMsg( "This node is not part of a cluster - no cleanup is necessary." );
  2092. goto Cleanup;
  2093. } // if: this node is not part of a cluster
  2094. //
  2095. // Set a registry value indicating that this node has been evicted.
  2096. // If, for some reason, the cleanup could not be completed, the cluster
  2097. // service will check this flag the next time it comes up and restarts
  2098. // cleanup.
  2099. //
  2100. dwStatus = TW32(
  2101. RegOpenKeyEx(
  2102. HKEY_LOCAL_MACHINE
  2103. , CLUSREG_KEYNAME_NODE_DATA
  2104. , 0
  2105. , KEY_ALL_ACCESS
  2106. , &hNodeStateKey
  2107. )
  2108. );
  2109. if ( dwStatus != ERROR_SUCCESS )
  2110. {
  2111. hr = HRESULT_FROM_WIN32( dwStatus );
  2112. LogMsg( "Error %#08x occurred trying to open a registry key to set a value indicating that this node has been evicted.", hr );
  2113. TraceFlow1( "Error %#08x occurred trying to open a registry key to set a value indicating that this node has been evicted.", hr );
  2114. goto Cleanup;
  2115. } // if: RegOpenKeyEx() has failed
  2116. dwStatus = TW32(
  2117. RegSetValueEx(
  2118. hNodeStateKey
  2119. , CLUSREG_NAME_EVICTION_STATE
  2120. , 0
  2121. , REG_DWORD
  2122. , reinterpret_cast< const BYTE * >( &dwEvictState )
  2123. , sizeof( dwEvictState )
  2124. )
  2125. );
  2126. if ( dwStatus != ERROR_SUCCESS )
  2127. {
  2128. hr = HRESULT_FROM_WIN32( dwStatus );
  2129. LogMsg( "Error %#08x occurred trying to set a registry value indicating that this node has been evicted.", hr );
  2130. TraceFlow1( "Error %#08x occurred trying to set a registry value indicating that this node has been evicted.", hr );
  2131. goto Cleanup;
  2132. } // if: RegSetValueEx() has failed
  2133. // Commit the post configuration steps first
  2134. hr = THR( ppcmIn->CommitChanges( peccmrIn, piccciIn ) );
  2135. if ( FAILED( hr ) )
  2136. {
  2137. TraceFlow1( "Error %#x occurred calling IPostCfgManager::CommitChanges().", hr );
  2138. LogMsg( "Error %#x occurred during the post configuration step of cleanup.", hr);
  2139. goto Cleanup;
  2140. } // if: post configuration failed
  2141. TraceFlow( "IPostCfgManager::CommitChanges() completed successfully during cleanup." );
  2142. hr = THR( piccbcaIn->SetCleanup() );
  2143. if ( FAILED( hr ) )
  2144. {
  2145. TraceFlow1( "Error %#x occurred calling IClusCfgBaseCluster::SetCleanup().", hr );
  2146. LogMsg( "Error %#x occurred initiating cleanup of the base cluster.", hr);
  2147. goto Cleanup;
  2148. } // if: SetCleanup() failed
  2149. // Initiate the cleanup
  2150. hr = THR( piccbcaIn->Commit() );
  2151. if ( FAILED( hr ) )
  2152. {
  2153. TraceFlow1( "Error %#x occurred calling IClusCfgBaseCluster::CommitChanges().", hr );
  2154. LogMsg( "Error %#x occurred trying to cleanup the base cluster.", hr);
  2155. goto Cleanup;
  2156. } // if: base cluster cleanup failed
  2157. TraceFlow( "Base cluster successfully cleaned up." );
  2158. // If we are here, then cleanup has completed successfully. If some other process is waiting
  2159. // for cleanup to complete, release that process by signaling an event.
  2160. {
  2161. // Open the event. Note, if this event does not already exist, then it means that nobody is
  2162. // waiting on this event. So, it is ok for OpenEvent to fail.
  2163. heventCleanupComplete = OpenEvent( EVENT_ALL_ACCESS, FALSE, SUCCESSFUL_CLEANUP_EVENT_NAME );
  2164. if ( heventCleanupComplete == NULL )
  2165. {
  2166. dwStatus = GetLastError();
  2167. TraceFlow1( "Status %#x was returned trying to open the cleanup completion event. This just means that no process is waiting on this event.", dwStatus );
  2168. LogMsg( "Status %#x was returned trying to open the cleanup completion event. This just means that no process is waiting on this event.", dwStatus );
  2169. goto Cleanup;
  2170. } // if: OpenEvent() failed
  2171. if ( PulseEvent( heventCleanupComplete ) == FALSE )
  2172. {
  2173. // Error, but not fatal. hr should still be S_OK.
  2174. dwStatus = TW32( GetLastError() );
  2175. TraceFlow1( "Error %#x occurred trying to pulse the cleanup completion event. This is not a fatal error.", dwStatus );
  2176. LogMsg( "Error %#x occurred trying to pulse the cleanup completion event. This is not a fatal error.", dwStatus );
  2177. goto Cleanup;
  2178. } // if: PulseEvent() failed
  2179. TraceFlow( "Cleanup completion event has been set." );
  2180. }
  2181. Cleanup:
  2182. if ( heventCleanupComplete == NULL )
  2183. {
  2184. CloseHandle( heventCleanupComplete );
  2185. } // if: we had opened the cleanup complete event
  2186. if ( hsCleanupLock != NULL )
  2187. {
  2188. if ( fLockAcquired )
  2189. {
  2190. ReleaseSemaphore( hsCleanupLock, 1, NULL );
  2191. LogMsg( "Cleanup lock released." );
  2192. TraceFlow( "Cleanup lock released." );
  2193. } // if: we have acquired the semaphore but not released it yet
  2194. CloseHandle( hsCleanupLock );
  2195. } // if: we had created a cleanup lock
  2196. if ( hNodeStateKey != NULL )
  2197. {
  2198. RegCloseKey( hNodeStateKey );
  2199. } // if: we had opened the node state registry key
  2200. HRETURN( hr );
  2201. } //*** CClusCfgServer::HrEvictedFromCluster
  2202. //////////////////////////////////////////////////////////////////////////////
  2203. //++
  2204. //
  2205. // CClusCfgServer::HrHasNodeBeenEvicted
  2206. //
  2207. // Description:
  2208. // Has this node been evicted?
  2209. //
  2210. // Arguments:
  2211. //
  2212. //
  2213. // Return Value:
  2214. // S_OK
  2215. // The node needs to be cleanedup.
  2216. //
  2217. // S_FALSE
  2218. // The node does not need to be cleanup.
  2219. //
  2220. // Win32 error as HRESULT.
  2221. //
  2222. // Remarks:
  2223. // None.
  2224. //
  2225. //--
  2226. //////////////////////////////////////////////////////////////////////////////
  2227. HRESULT
  2228. CClusCfgServer::HrHasNodeBeenEvicted( void )
  2229. {
  2230. TraceFunc( "" );
  2231. HRESULT hr = S_FALSE;
  2232. DWORD sc;
  2233. DWORD dwClusterState;
  2234. BOOL fEvicted = false;
  2235. sc = TW32( GetNodeClusterState( NULL, &dwClusterState ) );
  2236. if ( sc != ERROR_SUCCESS )
  2237. {
  2238. hr = HRESULT_FROM_WIN32( sc );
  2239. goto Cleanup;
  2240. } // if : GetClusterState() failed
  2241. //
  2242. // If the cluster service is not running then we need to check if we should
  2243. // clean it up or not.
  2244. //
  2245. if ( dwClusterState == ClusterStateNotRunning )
  2246. {
  2247. sc = TW32( ClRtlHasNodeBeenEvicted( &fEvicted ) );
  2248. if ( sc != ERROR_SUCCESS )
  2249. {
  2250. hr = HRESULT_FROM_WIN32( sc );
  2251. goto Cleanup;
  2252. } // if:
  2253. if ( fEvicted )
  2254. {
  2255. hr = S_OK;
  2256. } // if:
  2257. } // if:
  2258. Cleanup:
  2259. HRETURN( hr );
  2260. } //*** CClusCfgServer::HrHasNodeBeenEvicted
  2261. /////////////////////////////////////////////////////////////////////////////
  2262. //++
  2263. //
  2264. // CClusCfgServer::HrCleanUpNode
  2265. //
  2266. // Description:
  2267. // Cleanup this node because it was evicted.
  2268. //
  2269. // Arguments:
  2270. // None.
  2271. //
  2272. // Return Value:
  2273. // S_OK
  2274. // Success.
  2275. //
  2276. // Remarks:
  2277. // None.
  2278. //
  2279. //--
  2280. //////////////////////////////////////////////////////////////////////////////
  2281. HRESULT
  2282. CClusCfgServer::HrCleanUpNode( void )
  2283. {
  2284. TraceFunc( "" );
  2285. HRESULT hr = S_OK;
  2286. IClusCfgEvictCleanup * pcceEvict = NULL;
  2287. hr = THR(
  2288. CoCreateInstance(
  2289. CLSID_ClusCfgEvictCleanup
  2290. , NULL
  2291. , CLSCTX_LOCAL_SERVER
  2292. , __uuidof( pcceEvict )
  2293. , reinterpret_cast< void ** >( &pcceEvict )
  2294. ) );
  2295. if ( FAILED( hr ) )
  2296. {
  2297. goto Cleanup;
  2298. } // if: the ClusCfgEvictCleanup object could not be created
  2299. hr = THR( pcceEvict->CleanupLocalNode( 0 ) ); // 0 means "cleanup immediately"
  2300. if ( FAILED( hr ) )
  2301. {
  2302. goto Cleanup;
  2303. } // if: an error occurred during cleanup
  2304. Cleanup:
  2305. if ( pcceEvict != NULL )
  2306. {
  2307. pcceEvict->Release();
  2308. } // if:
  2309. HRETURN( hr );
  2310. } //*** CClusCfgServer::HrCleanUpNode
  2311. /////////////////////////////////////////////////////////////////////////////
  2312. //++
  2313. //
  2314. // CClusCfgServer::HrCreateClusterNodeInfo
  2315. //
  2316. // Description:
  2317. // Create the cluster node info object and store it in the member
  2318. // variable.
  2319. //
  2320. // Arguments:
  2321. // None.
  2322. //
  2323. // Return Value:
  2324. // S_OK
  2325. // Success.
  2326. //
  2327. // Remarks:
  2328. // None.
  2329. //
  2330. //--
  2331. //////////////////////////////////////////////////////////////////////////////
  2332. HRESULT
  2333. CClusCfgServer::HrCreateClusterNodeInfo( void )
  2334. {
  2335. TraceFunc( "" );
  2336. Assert( m_punkNodeInfo == NULL );
  2337. HRESULT hr = S_OK;
  2338. hr = THR( CClusCfgNodeInfo::S_HrCreateInstance( &m_punkNodeInfo ) );
  2339. if ( FAILED( hr ) )
  2340. {
  2341. goto Cleanup;
  2342. } // if:
  2343. m_punkNodeInfo = TraceInterface( L"CClusCfgNodeInfo", IUnknown, m_punkNodeInfo, 1 );
  2344. hr = THR( HrSetInitialize( m_punkNodeInfo, m_picccCallback, m_lcid ) );
  2345. if ( FAILED( hr ) )
  2346. {
  2347. goto Cleanup;
  2348. } // if:
  2349. hr = THR( HrSetWbemServices( m_punkNodeInfo, m_pIWbemServices ) );
  2350. Cleanup:
  2351. HRETURN( hr );
  2352. } //*** CClusCfgServer::HrCreateClusterNodeInfo