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.

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