Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

740 lines
17 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgCapabilities.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CClusCfgCapabilities class.
  10. //
  11. // The class CClusCfgCapabilities is the implementations of the
  12. // IClusCfgCapabilities interface.
  13. //
  14. // Maintained By:
  15. // Galen Barbee (GalenB) 12-DEC-2000
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19. // Include Files
  20. //////////////////////////////////////////////////////////////////////////////
  21. #include "Pch.h"
  22. #include "CClusCfgCapabilities.h"
  23. #include <ClusRtl.h>
  24. //////////////////////////////////////////////////////////////////////////////
  25. // Constant Definitions
  26. //////////////////////////////////////////////////////////////////////////////
  27. DEFINE_THISCLASS( "CClusCfgCapabilities" );
  28. //*************************************************************************//
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CClusCfgCapabilities class
  31. /////////////////////////////////////////////////////////////////////////////
  32. //////////////////////////////////////////////////////////////////////////////
  33. //++
  34. //
  35. // CClusCfgCapabilities::S_HrCreateInstance
  36. //
  37. // Description:
  38. // Create a CClusCfgCapabilities instance.
  39. //
  40. // Arguments:
  41. // ppunkOut -
  42. //
  43. // Return Values:
  44. // Pointer to CClusCfgCapabilities instance.
  45. //
  46. //--
  47. //////////////////////////////////////////////////////////////////////////////
  48. HRESULT
  49. CClusCfgCapabilities::S_HrCreateInstance( IUnknown ** ppunkOut )
  50. {
  51. TraceFunc( "" );
  52. HRESULT hr = S_OK;
  53. CClusCfgCapabilities * pccs = NULL;
  54. if ( ppunkOut == NULL )
  55. {
  56. hr = THR( E_POINTER );
  57. goto Cleanup;
  58. } // if:
  59. pccs = new CClusCfgCapabilities();
  60. if ( pccs == NULL )
  61. {
  62. hr = THR( E_OUTOFMEMORY );
  63. goto Cleanup;
  64. } // if: error allocating object
  65. hr = THR( pccs->HrInit() );
  66. if ( FAILED( hr ) )
  67. {
  68. goto Cleanup;
  69. } // if: HrInit() failed
  70. hr = THR( pccs->TypeSafeQI( IUnknown, ppunkOut ) );
  71. if ( FAILED( hr ) )
  72. {
  73. goto Cleanup;
  74. } // if: QI failed
  75. Cleanup:
  76. if ( FAILED( hr ) )
  77. {
  78. LogMsg( L"[SRV] CClusCfgCapabilities::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  79. } // if:
  80. if ( pccs != NULL )
  81. {
  82. pccs->Release();
  83. } // if:
  84. HRETURN( hr );
  85. } //*** CClusCfgCapabilities::S_HrCreateInstance
  86. //////////////////////////////////////////////////////////////////////////////
  87. //++
  88. //
  89. // CClusCfgCapabilities::S_RegisterCatIDSupport
  90. //
  91. // Description:
  92. // Registers/unregisters this class with the categories that it belongs
  93. // to.
  94. //
  95. // Arguments:
  96. // picrIn
  97. // Used to register/unregister our CATID support.
  98. //
  99. // fCreateIn
  100. // When true we are registering the server. When false we are
  101. // un-registering the server.
  102. //
  103. // Return Values:
  104. // S_OK
  105. // Success.
  106. //
  107. // E_INVALIDARG
  108. // The passed in ICatRgister pointer was NULL.
  109. //
  110. // other HRESULTs
  111. // Registration/Unregistration failed.
  112. //
  113. //--
  114. //////////////////////////////////////////////////////////////////////////////
  115. HRESULT
  116. CClusCfgCapabilities::S_RegisterCatIDSupport(
  117. ICatRegister * picrIn,
  118. BOOL fCreateIn
  119. )
  120. {
  121. TraceFunc( "" );
  122. HRESULT hr = S_OK;
  123. CATID rgCatIds[ 1 ];
  124. if ( picrIn == NULL )
  125. {
  126. hr = THR( E_INVALIDARG );
  127. goto Cleanup;
  128. } // if:
  129. rgCatIds[ 0 ] = CATID_ClusCfgCapabilities;
  130. if ( fCreateIn )
  131. {
  132. hr = THR( picrIn->RegisterClassImplCategories( CLSID_ClusCfgCapabilities, 1, rgCatIds ) );
  133. } // if:
  134. Cleanup:
  135. HRETURN( hr );
  136. } //*** CClusCfgCapabilities::S_RegisterCatIDSupport
  137. //////////////////////////////////////////////////////////////////////////////
  138. //++
  139. //
  140. // CClusCfgCapabilities::CClusCfgCapabilities
  141. //
  142. // Description:
  143. // Constructor of the CClusCfgCapabilities class. This initializes
  144. // the m_cRef variable to 1 instead of 0 to account of possible
  145. // QueryInterface failure in DllGetClassObject.
  146. //
  147. // Arguments:
  148. // None.
  149. //
  150. // Return Value:
  151. // None.
  152. //
  153. // Remarks:
  154. // None.
  155. //
  156. //--
  157. //////////////////////////////////////////////////////////////////////////////
  158. CClusCfgCapabilities::CClusCfgCapabilities( void )
  159. : m_cRef( 1 )
  160. , m_lcid( LOCALE_NEUTRAL )
  161. {
  162. TraceFunc( "" );
  163. // Increment the count of components in memory so the DLL hosting this
  164. // object cannot be unloaded.
  165. InterlockedIncrement( &g_cObjects );
  166. Assert( m_picccCallback == NULL );
  167. TraceFuncExit();
  168. } //*** CClusCfgCapabilities::CClusCfgCapabilities
  169. //////////////////////////////////////////////////////////////////////////////
  170. //++
  171. //
  172. // CClusCfgCapabilities::~CClusCfgCapabilities
  173. //
  174. // Description:
  175. // Destructor of the CClusCfgCapabilities class.
  176. //
  177. // Arguments:
  178. // None.
  179. //
  180. // Return Value:
  181. // None.
  182. //
  183. // Remarks:
  184. // None.
  185. //
  186. //--
  187. //////////////////////////////////////////////////////////////////////////////
  188. CClusCfgCapabilities::~CClusCfgCapabilities( void )
  189. {
  190. TraceFunc( "" );
  191. if ( m_picccCallback != NULL )
  192. {
  193. m_picccCallback->Release();
  194. } // if:
  195. // There's going to be one less component in memory. Decrement component count.
  196. InterlockedDecrement( &g_cObjects );
  197. TraceFuncExit();
  198. } //*** CClusCfgCapabilities::~CClusCfgCapabilities
  199. //*************************************************************************//
  200. /////////////////////////////////////////////////////////////////////////////
  201. // CClusCfgCapabilities -- IUknkown interface.
  202. /////////////////////////////////////////////////////////////////////////////
  203. //////////////////////////////////////////////////////////////////////////////
  204. //++
  205. //
  206. // [IUnknown]
  207. // CClusCfgCapabilities::AddRef
  208. //
  209. // Description:
  210. // Increment the reference count of this object by one.
  211. //
  212. // Arguments:
  213. // None.
  214. //
  215. // Return Value:
  216. // The new reference count.
  217. //
  218. // Remarks:
  219. // None.
  220. //
  221. //--
  222. //////////////////////////////////////////////////////////////////////////////
  223. STDMETHODIMP_( ULONG )
  224. CClusCfgCapabilities::AddRef( void )
  225. {
  226. TraceFunc( "[IUnknown]" );
  227. InterlockedIncrement( & m_cRef );
  228. CRETURN( m_cRef );
  229. } //*** CClusCfgCapabilities::AddRef
  230. //////////////////////////////////////////////////////////////////////////////
  231. //++
  232. //
  233. // [IUnknown]
  234. // CClusCfgCapabilities::Release
  235. //
  236. // Description:
  237. // Decrement the reference count of this object by one.
  238. //
  239. // Arguments:
  240. // None.
  241. //
  242. // Return Value:
  243. // The new reference count.
  244. //
  245. // Remarks:
  246. // None.
  247. //
  248. //--
  249. //////////////////////////////////////////////////////////////////////////////
  250. STDMETHODIMP_( ULONG )
  251. CClusCfgCapabilities::Release( void )
  252. {
  253. TraceFunc( "[IUnknown]" );
  254. LONG cRef;
  255. cRef = InterlockedDecrement( &m_cRef );
  256. if ( cRef == 0 )
  257. {
  258. TraceDo( delete this );
  259. } // if: reference count equal to zero
  260. CRETURN( cRef );
  261. } //*** CClusCfgCapabilities::Release
  262. //////////////////////////////////////////////////////////////////////////////
  263. //++
  264. //
  265. // [IUnknown]
  266. // CClusCfgCapabilities::QueryInterface
  267. //
  268. // Description:
  269. // Query this object for the passed in interface.
  270. //
  271. // Arguments:
  272. // riidIn
  273. // Id of interface requested.
  274. //
  275. // ppvOut
  276. // Pointer to the requested interface.
  277. //
  278. // Return Value:
  279. // S_OK
  280. // If the interface is available on this object.
  281. //
  282. // E_NOINTERFACE
  283. // If the interface is not available.
  284. //
  285. // E_POINTER
  286. // ppvOut was NULL.
  287. //
  288. // Remarks:
  289. // None.
  290. //
  291. //--
  292. //////////////////////////////////////////////////////////////////////////////
  293. STDMETHODIMP
  294. CClusCfgCapabilities::QueryInterface(
  295. REFIID riidIn
  296. , void ** ppvOut
  297. )
  298. {
  299. TraceQIFunc( riidIn, ppvOut );
  300. HRESULT hr = S_OK;
  301. //
  302. // Validate arguments.
  303. //
  304. Assert( ppvOut != NULL );
  305. if ( ppvOut == NULL )
  306. {
  307. hr = THR( E_POINTER );
  308. goto Cleanup;
  309. }
  310. //
  311. // Handle known interfaces.
  312. //
  313. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  314. {
  315. *ppvOut = static_cast< IClusCfgCapabilities * >( this );
  316. } // if: IUnknown
  317. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  318. {
  319. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  320. } // else if: IClusCfgInitialize
  321. else if ( IsEqualIID( riidIn, IID_IClusCfgCapabilities ) )
  322. {
  323. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCapabilities, this, 0 );
  324. } // else if: IClusCfgCapabilities
  325. else
  326. {
  327. *ppvOut = NULL;
  328. hr = E_NOINTERFACE;
  329. }
  330. //
  331. // Add a reference to the interface if successful.
  332. //
  333. if ( SUCCEEDED( hr ) )
  334. {
  335. ((IUnknown *) *ppvOut)->AddRef();
  336. } // if: success
  337. Cleanup:
  338. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  339. } //*** CClusCfgCapabilities::QueryInterface
  340. //*************************************************************************//
  341. /////////////////////////////////////////////////////////////////////////////
  342. // CClusCfgCapabilities -- IClusCfgInitialize interface.
  343. /////////////////////////////////////////////////////////////////////////////
  344. //////////////////////////////////////////////////////////////////////////////
  345. //++
  346. //
  347. // [IClusCfgInitialize]
  348. // CClusCfgCapabilities::Initialize
  349. //
  350. // Description:
  351. // Initialize this component.
  352. //
  353. // Arguments:
  354. // IN IUknown * punkCallbackIn
  355. //
  356. // IN LCID lcidIn
  357. //
  358. // Return Value:
  359. // S_OK
  360. // Success
  361. //
  362. // E_POINTER
  363. // The punkCallbackIn param is NULL.
  364. //
  365. // Remarks:
  366. // None.
  367. //
  368. //--
  369. //////////////////////////////////////////////////////////////////////////////
  370. STDMETHODIMP
  371. CClusCfgCapabilities::Initialize(
  372. IUnknown * punkCallbackIn,
  373. LCID lcidIn
  374. )
  375. {
  376. TraceFunc( "[IClusCfgInitialize]" );
  377. Assert( m_picccCallback == NULL );
  378. HRESULT hr = S_OK;
  379. m_lcid = lcidIn;
  380. if ( punkCallbackIn == NULL )
  381. {
  382. hr = THR( E_POINTER );
  383. goto Cleanup;
  384. } // if:
  385. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  386. Cleanup:
  387. HRETURN( hr );
  388. } //*** CClusCfgCapabilities::Initialize
  389. //*************************************************************************//
  390. /////////////////////////////////////////////////////////////////////////////
  391. // CClusCfgCapabilities class -- IClusCfgCapabilities interfaces.
  392. /////////////////////////////////////////////////////////////////////////////
  393. //////////////////////////////////////////////////////////////////////////////
  394. //++
  395. //
  396. // [IClusCfgCapabilities]
  397. // CClusCfgCapabilities::CanNodeBeClustered
  398. //
  399. // Description:
  400. // Can this node be added to a cluster?
  401. //
  402. // Arguments:
  403. //
  404. //
  405. // Return Value:
  406. // S_OK
  407. // Node can be clustered.
  408. //
  409. // S_FALSE
  410. // Node cannot be clustered.
  411. //
  412. // other HRESULTs
  413. // The call failed.
  414. //
  415. // Remarks:
  416. // None.
  417. //
  418. //--
  419. //////////////////////////////////////////////////////////////////////////////
  420. STDMETHODIMP
  421. CClusCfgCapabilities::CanNodeBeClustered( void )
  422. {
  423. TraceFunc( "[IClusCfgCapabilities]" );
  424. HRESULT hr = S_OK;
  425. //
  426. // Since this only displays a warning there is no need to abort the whole
  427. // process if this call fails.
  428. //
  429. THR( HrCheckForSFM() );
  430. hr = STHR( HrIsOSVersionValid() );
  431. HRETURN( hr );
  432. } //*** CClusCfgCapabilities::CanNodeBeClustered
  433. //*************************************************************************//
  434. /////////////////////////////////////////////////////////////////////////////
  435. // CClusCfgCapabilities class -- Private Methods.
  436. /////////////////////////////////////////////////////////////////////////////
  437. //////////////////////////////////////////////////////////////////////////////
  438. //++
  439. //
  440. // CClusCfgCapabilities::HrInit
  441. //
  442. // Description:
  443. // Initialize this component.
  444. //
  445. // Arguments:
  446. // None.
  447. //
  448. // Return Value:
  449. // S_OK
  450. // Success
  451. //
  452. // Remarks:
  453. // None.
  454. //
  455. //--
  456. //////////////////////////////////////////////////////////////////////////////
  457. HRESULT
  458. CClusCfgCapabilities::HrInit( void )
  459. {
  460. TraceFunc( "" );
  461. HRESULT hr = S_OK;
  462. // IUnknown
  463. Assert( m_cRef == 1 );
  464. HRETURN( hr );
  465. } //*** CClusCfgCapabilities::HrInit
  466. //////////////////////////////////////////////////////////////////////////////
  467. //++
  468. //
  469. // CClusCfgCapabilities::HrCheckForSFM
  470. //
  471. // Description:
  472. // Checks for Services for Macintosh (SFM) and displays a warning
  473. // in the UI if found.
  474. //
  475. // Arguments:
  476. // None.
  477. //
  478. // Return Value:
  479. // S_OK
  480. // Success
  481. //
  482. // Remarks:
  483. // None.
  484. //
  485. //--
  486. //////////////////////////////////////////////////////////////////////////////
  487. HRESULT
  488. CClusCfgCapabilities::HrCheckForSFM( void )
  489. {
  490. TraceFunc( "" );
  491. HRESULT hr = S_OK;
  492. BOOL fSFMInstalled = FALSE;
  493. DWORD sc;
  494. sc = TW32( ClRtlIsServicesForMacintoshInstalled( &fSFMInstalled ) );
  495. if ( sc == ERROR_SUCCESS )
  496. {
  497. if ( fSFMInstalled )
  498. {
  499. LogMsg( L"[SRV] Services for Macintosh was found on this node." );
  500. hr = S_FALSE;
  501. STATUS_REPORT_REF(
  502. TASKID_Major_Check_Node_Feasibility
  503. , TASKID_Minor_ServicesForMac_Installed
  504. , IDS_WARN_SERVICES_FOR_MAC_INSTALLED
  505. , IDS_WARN_SERVICES_FOR_MAC_INSTALLED_REF
  506. , hr
  507. );
  508. } // if:
  509. } // if:
  510. else
  511. {
  512. hr = MAKE_HRESULT( 0, FACILITY_WIN32, sc );
  513. STATUS_REPORT_REF(
  514. TASKID_Major_Check_Node_Feasibility
  515. , TASKID_Minor_ServicesForMac_Installed
  516. , IDS_WARN_SERVICES_FOR_MAC_FAILED
  517. , IDS_WARN_SERVICES_FOR_MAC_FAILED_REF
  518. , hr
  519. );
  520. } // else:
  521. hr = S_OK;
  522. HRETURN( hr );
  523. } //*** CClusCfgCapabilities::HrCheckForSFM
  524. //////////////////////////////////////////////////////////////////////////////
  525. //++
  526. //
  527. // CClusCfgCapabilities::HrIsOSVersionValid
  528. //
  529. // Description:
  530. // Can this node be added to a cluster?
  531. //
  532. // Arguments:
  533. // None.
  534. //
  535. // Return Value:
  536. // S_OK
  537. // Node can be clustered.
  538. //
  539. // S_FALSE
  540. // Node cannot be clustered.
  541. //
  542. // other HRESULTs
  543. // The call failed.
  544. //
  545. // Remarks:
  546. // None.
  547. //
  548. //--
  549. //////////////////////////////////////////////////////////////////////////////
  550. HRESULT
  551. CClusCfgCapabilities::HrIsOSVersionValid( void )
  552. {
  553. TraceFunc( "" );
  554. HRESULT hr = S_OK;
  555. HRESULT hrSSR;
  556. BOOL fRet;
  557. BSTR bstrMsg = NULL;
  558. //
  559. // Get the message to be displayed in the UI for status reports.
  560. //
  561. hr = THR( HrLoadStringIntoBSTR( g_hInstance, IDS_VALIDATING_NODE_OS_VERSION, &bstrMsg ) );
  562. if ( FAILED( hr ) )
  563. {
  564. goto Cleanup;
  565. } // if:
  566. //
  567. // Send the initial status report to be displayed in the UI.
  568. //
  569. hrSSR = THR( HrSendStatusReport(
  570. m_picccCallback
  571. , TASKID_Major_Check_Node_Feasibility
  572. , TASKID_Minor_Validating_Node_OS_Version
  573. , 0
  574. , 1
  575. , 0
  576. , S_OK
  577. , bstrMsg
  578. ) );
  579. if ( FAILED( hrSSR ) )
  580. {
  581. hr = hrSSR;
  582. goto Cleanup;
  583. } // if:
  584. //
  585. // Find out if the OS is valid for clustering.
  586. //
  587. fRet = ClRtlIsOSValid();
  588. if ( ! fRet )
  589. {
  590. DWORD sc = TW32( GetLastError() );
  591. hrSSR = HRESULT_FROM_WIN32( sc );
  592. hr = S_FALSE;
  593. } // if:
  594. else
  595. {
  596. hrSSR = S_OK;
  597. } // else:
  598. //
  599. // Send the final status report.
  600. //
  601. hrSSR = THR( HrSendStatusReport(
  602. m_picccCallback
  603. , TASKID_Major_Check_Node_Feasibility
  604. , TASKID_Minor_Validating_Node_OS_Version
  605. , 0
  606. , 1
  607. , 1
  608. , hrSSR
  609. , bstrMsg
  610. ) );
  611. if ( FAILED( hrSSR ) )
  612. {
  613. hr = hrSSR;
  614. goto Cleanup;
  615. } // if:
  616. Cleanup:
  617. TraceSysFreeString( bstrMsg );
  618. HRETURN( hr );
  619. } //*** CClusCfgCapabilities::HrIsOSVersionValid