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.

1354 lines
31 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // main.cpp
  7. //
  8. // Description:
  9. // The entry point for the application that launches unattended
  10. // installation of the cluster. This application parses input parameters,
  11. // CoCreates the Configuration Wizard Component, passes the parsed
  12. // parameters and invokes the Wizard. The Wizard may or may not show any
  13. // UI depending on swithes and the (in)availability of information.
  14. //
  15. // Maintained By:
  16. // Geoffrey Pease (GPease) 22-JAN-2000
  17. // Vijay Vasu (VVasu) 22-JAN-2000
  18. // Galen Barbee (GalenB) 22-JAN-2000
  19. // David Potter (DavidP) 22-JAN-2000
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22. #include "pch.h"
  23. #include <initguid.h>
  24. #include <guids.h>
  25. #include "UINotification.h"
  26. #include "Callback.h"
  27. #include <winsock2.h>
  28. // {F4A50885-A4B9-4c4d-B67C-9E4DD94A315E}
  29. DEFINE_GUID( CLSID_TaskType,
  30. 0xf4a50885, 0xa4b9, 0x4c4d, 0xb6, 0x7c, 0x9e, 0x4d, 0xd9, 0x4a, 0x31, 0x5e);
  31. //
  32. // KB: Turn this on to run all tests. Some of these might return errors, but none
  33. // of them should cause the program to crash.
  34. //
  35. //#define TURN_ON_ALL_TESTS
  36. //
  37. // KB: Turn this on to run a regression pass.
  38. //
  39. #define REGRESSION_PASS
  40. DEFINE_MODULE( "MIDDLETIERTEST" )
  41. //
  42. // Declarations
  43. //
  44. typedef HRESULT (* PDLLREGISTERSERVER)( void );
  45. //
  46. // Globals
  47. //
  48. HINSTANCE g_hInstance = NULL;
  49. LONG g_cObjects = 0;
  50. IServiceProvider * g_psp = NULL;
  51. BOOL g_fWait = FALSE; // global synchronization
  52. OBJECTCOOKIE g_cookieCluster = NULL;
  53. //
  54. // Register the DLL
  55. //
  56. HRESULT
  57. HrRegisterTheDll( void )
  58. {
  59. TraceFunc( "" );
  60. HRESULT hr;
  61. PDLLREGISTERSERVER pDllRegisterServer;
  62. HMODULE hLib = NULL;
  63. //
  64. // Make sure the DLL is properly registered.
  65. //
  66. hLib = LoadLibrary( L"..\\..\\..\\..\\dll\\obj\\i386\\ClusCfgServer.dll" );
  67. if ( hLib == NULL )
  68. goto Win32Error;
  69. pDllRegisterServer = reinterpret_cast< PDLLREGISTERSERVER >( GetProcAddress( hLib, "DllRegisterServer" ) );
  70. if ( pDllRegisterServer == NULL )
  71. goto Win32Error;
  72. hr = THR( pDllRegisterServer( ) );
  73. if ( FAILED( hr ) )
  74. goto Cleanup;
  75. Cleanup:
  76. if ( hLib != NULL )
  77. {
  78. FreeLibrary( hLib );
  79. }
  80. HRETURN( hr );
  81. Win32Error:
  82. hr = THR( HRESULT_FROM_WIN32( GetLastError( ) ) );
  83. goto Cleanup;
  84. }
  85. //
  86. // This tests the Object Manager code path to retrieve information
  87. // from a soon-to-be or existing cluster node.
  88. //
  89. HRESULT
  90. HrTestAddingNode(
  91. BSTR bstrNodeNameIn
  92. )
  93. {
  94. TraceFunc( "" );
  95. HRESULT hr;
  96. DWORD dwHigh;
  97. DWORD dwLow;
  98. OBJECTCOOKIE cookie;
  99. SDriveLetterMapping dlmDriveLetterUsage;
  100. BSTR bstrName = NULL;
  101. IUnknown * punk = NULL;
  102. IUnknown * punk2 = NULL;
  103. IObjectManager * pom = NULL;
  104. IClusCfgNodeInfo * pccni = NULL;
  105. IClusCfgNodeInfo * pccni2 = NULL;
  106. IClusCfgClusterInfo * pccci = NULL;
  107. // Get OS Version stuff
  108. DWORD dwMajorVersionOut;
  109. DWORD dwMinorVersionOut;
  110. WORD wSuiteMaskOut;
  111. BYTE bProductTypeOut;
  112. BSTR bstrCSDVersionOut;
  113. //
  114. // Contact the Object Manager
  115. //
  116. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager, IObjectManager, &pom ) );
  117. if ( FAILED( hr ) )
  118. goto Cleanup;
  119. //
  120. // Try to find my test machine.
  121. //
  122. hr = E_PENDING;
  123. while ( hr == E_PENDING )
  124. {
  125. DebugMsg( "Trying to FindObject( ... %s ... )", bstrNodeNameIn );
  126. hr = pom->FindObject( CLSID_NodeType,
  127. g_cookieCluster,
  128. bstrNodeNameIn,
  129. DFGUID_NodeInformation,
  130. &cookie,
  131. &punk
  132. );
  133. if ( hr == E_PENDING )
  134. {
  135. Assert( punk == NULL );
  136. Sleep( 1000 ); // 1 Second
  137. continue;
  138. }
  139. THR( hr );
  140. if ( FAILED( hr ) )
  141. goto Cleanup;
  142. }
  143. hr = THR( punk->TypeSafeQI( IClusCfgNodeInfo, &pccni ) );
  144. if ( FAILED( hr ) )
  145. goto Cleanup;
  146. punk->Release( );
  147. punk = NULL;
  148. //
  149. // Interrogate the information retrieved.
  150. //
  151. hr = THR( pccni->GetName( &bstrName ) );
  152. if ( FAILED( hr ) )
  153. goto Cleanup;
  154. DebugMsg( "bstrName = %s", bstrName );
  155. #if defined(TURN_ON_ALL_TESTS)
  156. hr = THR( pccni->SetName( L"gpease-wolf1.NTDEV.MICROSOFT.COM" ) );
  157. if ( FAILED( hr ) )
  158. goto Cleanup;
  159. DebugMsg( "Successfully called SetName( )." );
  160. #endif
  161. hr = STHR( pccni->IsMemberOfCluster( ) );
  162. if ( FAILED( hr ) )
  163. goto Cleanup;
  164. DebugMsg( "IsMemberOfCluster == %s", BOOLTOSTRING( hr == S_OK ) );
  165. if ( hr == S_OK )
  166. {
  167. hr = THR( pccni->GetClusterConfigInfo( &pccci ) );
  168. if ( FAILED( hr ) )
  169. goto Cleanup;
  170. DebugMsg( "Succesfully called GetClusterConfigInfo( )" );
  171. }
  172. hr = THR( pccni->GetOSVersion( &dwMajorVersionOut,
  173. &dwMinorVersionOut,
  174. &wSuiteMaskOut,
  175. &bProductTypeOut,
  176. &bstrCSDVersionOut
  177. ) );
  178. if ( FAILED( hr ) )
  179. goto Cleanup;
  180. DebugMsg( "Successfully called GetOSVersion( )" );
  181. hr = THR( pccni->GetClusterVersion( &dwHigh, &dwLow ) );
  182. if ( FAILED( hr ) )
  183. goto Cleanup;
  184. DebugMsg( "Version: dwHigh = %#x, dwLow = %#x", dwHigh, dwLow );
  185. hr = THR( pccni->GetDriveLetterMappings( &dlmDriveLetterUsage ) );
  186. if ( FAILED( hr ) )
  187. goto Cleanup;
  188. //
  189. // TODO: gpease 08-MAR-2000
  190. // Make this dump the table.
  191. //
  192. DebugMsg( "Succesfully called GetDriveLetterMappings( )" );
  193. //
  194. // Try getting the same object.
  195. //
  196. hr = THR( pom->GetObject( DFGUID_NodeInformation,
  197. cookie,
  198. &punk
  199. ) );
  200. if ( FAILED( hr ) )
  201. goto Cleanup;
  202. hr = THR( punk->TypeSafeQI( IClusCfgNodeInfo, &pccni2 ) );
  203. if ( FAILED( hr ) )
  204. goto Cleanup;
  205. punk->Release( );
  206. punk = NULL;
  207. DebugMsg( "GetObject succeeded." );
  208. //
  209. // They should be the same object.
  210. //
  211. hr = THR( pccni->TypeSafeQI( IUnknown, &punk ) );
  212. if ( FAILED( hr ) )
  213. goto Cleanup;
  214. hr = THR( pccni2->TypeSafeQI( IUnknown, &punk2 ) );
  215. if ( FAILED( hr ) )
  216. goto Cleanup;
  217. AssertMsg( punk == punk2, "These should be the same!" );
  218. Cleanup:
  219. if ( pom != NULL )
  220. {
  221. pom->Release( );
  222. }
  223. if ( punk != NULL )
  224. {
  225. punk->Release( );
  226. }
  227. if ( punk2 != NULL )
  228. {
  229. punk2->Release( );
  230. }
  231. if ( pccni != NULL )
  232. {
  233. pccni->Release( );
  234. }
  235. if ( bstrName != NULL )
  236. {
  237. TraceSysFreeString( bstrName );
  238. }
  239. if ( pccci != NULL )
  240. {
  241. pccci->Release( );
  242. }
  243. if ( pccni2 != NULL )
  244. {
  245. pccni2->Release( );
  246. }
  247. HRETURN( hr );
  248. }
  249. //
  250. // This tests the Analyze Cluster Tasks.
  251. //
  252. HRESULT
  253. HrTestTaskAnalyzeCluster( void )
  254. {
  255. TraceFunc( "" );
  256. HRESULT hr;
  257. OBJECTCOOKIE cookie;
  258. DWORD dwCookie;
  259. CUINotification * puin;
  260. IUnknown * punk = NULL;
  261. IObjectManager * pom = NULL;
  262. ITaskManager * ptm = NULL;
  263. ITaskAnalyzeCluster * ptac = NULL;
  264. IConnectionPoint * pcp = NULL;
  265. INotifyUI * pnui = NULL;
  266. IClusCfgCallback * pcccb = NULL;
  267. //
  268. // Gather the manager needed to complete this task.
  269. //
  270. hr = THR( g_psp->TypeSafeQS( CLSID_TaskManager,
  271. ITaskManager,
  272. &ptm
  273. ) );
  274. if ( FAILED( hr ) )
  275. goto Cleanup;
  276. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager,
  277. IObjectManager,
  278. &pom
  279. ) );
  280. if ( FAILED( hr ) )
  281. goto Cleanup;
  282. //
  283. // Ask the object manager to create a cookie for the task
  284. // to use as a completion cookie.
  285. //
  286. hr = THR( pom->FindObject( CLSID_TaskType,
  287. g_cookieCluster,
  288. L"AnalyzeTask",
  289. IID_NULL,
  290. &cookie,
  291. NULL
  292. ) );
  293. if ( FAILED( hr ) )
  294. goto Cleanup;
  295. //
  296. // Create a notification object that will be called when
  297. // the task is completed.
  298. //
  299. hr = THR( CUINotification::S_HrCreateInstance( &punk ) );
  300. if ( FAILED( hr ) )
  301. goto Cleanup;
  302. puin = reinterpret_cast< CUINotification * >( punk );
  303. THR( puin->HrSetCompletionCookie( cookie ) );
  304. hr = THR( punk->TypeSafeQI( INotifyUI, &pnui ) );
  305. if ( FAILED( hr ) )
  306. goto Cleanup;
  307. punk->Release( );
  308. punk = NULL;
  309. //
  310. // Register the notification object with the Notification Manager.
  311. //
  312. hr = THR( g_psp->TypeSafeQS( CLSID_NotificationManager,
  313. IConnectionPoint,
  314. &pcp
  315. ) );
  316. if ( FAILED( hr ) )
  317. goto Cleanup;
  318. hr = THR( pcp->Advise( pnui, &dwCookie ) );
  319. if ( FAILED( hr ) )
  320. goto Cleanup;
  321. //
  322. // Ask the Task Manager to create the Analyze Cluster Task.
  323. //
  324. hr = THR( ptm->CreateTask( TASK_AnalyzeCluster,
  325. &punk
  326. ) );
  327. if ( FAILED( hr ) )
  328. goto Cleanup;
  329. hr = THR( punk->TypeSafeQI( ITaskAnanlyzeCluster, &ptac ) );
  330. if ( FAILED( hr ) )
  331. goto Cleanup;
  332. punk->Release( );
  333. punk = NULL;
  334. //
  335. // The the task what cookie to use for the notification.
  336. //
  337. hr = THR( ptac->SetCookie( cookie ) );
  338. if ( FAILED( hr ) )
  339. goto Cleanup;
  340. //
  341. // Tell the task which cluster to analyze.
  342. //
  343. hr = THR( ptac->SetClusterCookie( g_cookieCluster ) );
  344. if ( FAILED( hr ) )
  345. goto Cleanup;
  346. //
  347. // Create a callback object.
  348. //
  349. Assert( punk == NULL );
  350. hr = THR( CCallback::S_HrCreateInstance( &punk ) );
  351. if ( FAILED( hr ) )
  352. goto Cleanup;
  353. punk = TraceInterface( L"CCallback", IUnknown, punk, 1 );
  354. hr = THR( punk->TypeSafeQI( IClusCfgCallback, &pcccb ) );
  355. if ( FAILED( hr ) )
  356. goto Cleanup;
  357. //
  358. // The the action where to call us back.
  359. //
  360. hr = THR( ptac->SetCallback( pcccb ) );
  361. if ( FAILED( hr ) )
  362. goto Cleanup;
  363. //
  364. // Reset g_fWait and submit the task.
  365. //
  366. g_fWait = TRUE;
  367. hr = THR( ptm->SubmitTask( ptac ) );
  368. if ( FAILED( hr ) )
  369. goto Cleanup;
  370. //
  371. // Wait for the task to complete.
  372. //
  373. while( g_fWait )
  374. {
  375. Sleep( 1 ); // sleep a millisecond
  376. }
  377. //
  378. // Unregister the notification object.
  379. //
  380. hr = THR( pcp->Unadvise( dwCookie ) );
  381. if ( FAILED( hr ) )
  382. goto Cleanup;
  383. Cleanup:
  384. if ( pcp != NULL )
  385. {
  386. pcp->Release( );
  387. }
  388. if ( pom != NULL )
  389. {
  390. pom->Release( );
  391. }
  392. if ( ptm != NULL )
  393. {
  394. ptm->Release( );
  395. }
  396. if ( ptac != NULL )
  397. {
  398. ptac->Release( );
  399. }
  400. if ( punk != NULL )
  401. {
  402. punk->Release( );
  403. }
  404. if ( pnui != NULL )
  405. {
  406. pnui->Release( );
  407. }
  408. if ( pcccb != NULL )
  409. {
  410. pcccb->Release( );
  411. }
  412. HRETURN( hr );
  413. }
  414. //
  415. // This tests the Commit Cluster Changes Tasks.
  416. //
  417. HRESULT
  418. HrTestTaskCommitClusterChanges( void )
  419. {
  420. TraceFunc( "" );
  421. HRESULT hr;
  422. OBJECTCOOKIE cookie;
  423. DWORD dwCookie;
  424. CUINotification * puin;
  425. IUnknown * punk = NULL;
  426. IObjectManager * pom = NULL;
  427. ITaskManager * ptm = NULL;
  428. ITaskCommitClusterChanges * ptccc = NULL;
  429. IConnectionPoint * pcp = NULL;
  430. INotifyUI * pnui = NULL;
  431. IClusCfgCallback * pcccb = NULL;
  432. //
  433. // Gather the manager needed to complete this task.
  434. //
  435. hr = THR( g_psp->TypeSafeQS( CLSID_TaskManager,
  436. ITaskManager,
  437. &ptm
  438. ) );
  439. if ( FAILED( hr ) )
  440. goto Cleanup;
  441. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager,
  442. IObjectManager,
  443. &pom
  444. ) );
  445. if ( FAILED( hr ) )
  446. goto Cleanup;
  447. //
  448. // Ask the object manager to create a cookie for the task
  449. // to use as a completion cookie.
  450. //
  451. hr = THR( pom->FindObject( CLSID_TaskType,
  452. g_cookieCluster,
  453. L"CommitClusterChanges",
  454. IID_NULL,
  455. &cookie,
  456. NULL
  457. ) );
  458. if ( FAILED( hr ) )
  459. goto Cleanup;
  460. //
  461. // Create a notification object that will be called when
  462. // the task is completed.
  463. //
  464. hr = THR( CUINotification::S_HrCreateInstance( &punk ) );
  465. if ( FAILED( hr ) )
  466. goto Cleanup;
  467. puin = reinterpret_cast< CUINotification * >( punk );
  468. THR( puin->HrSetCompletionCookie( cookie ) );
  469. hr = THR( punk->TypeSafeQI( INotifyUI, &pnui ) );
  470. if ( FAILED( hr ) )
  471. goto Cleanup;
  472. punk->Release( );
  473. punk = NULL;
  474. //
  475. // Register the notification object with the Notification Manager.
  476. //
  477. hr = THR( g_psp->TypeSafeQS( CLSID_NotificationManager,
  478. IConnectionPoint,
  479. &pcp
  480. ) );
  481. if ( FAILED( hr ) )
  482. goto Cleanup;
  483. hr = THR( pcp->Advise( pnui, &dwCookie ) );
  484. if ( FAILED( hr ) )
  485. goto Cleanup;
  486. //
  487. // Ask the Task Manager to create the Analyze Cluster Task.
  488. //
  489. hr = THR( ptm->CreateTask( TASK_CommitClusterChanges,
  490. &punk
  491. ) );
  492. if ( FAILED( hr ) )
  493. goto Cleanup;
  494. hr = THR( punk->TypeSafeQI( ITaskCommitClusterChanges, &ptccc ) );
  495. if ( FAILED( hr ) )
  496. goto Cleanup;
  497. punk->Release( );
  498. punk = NULL;
  499. //
  500. // The the task what cookie to use for the notification.
  501. //
  502. hr = THR( ptccc->SetCookie( cookie ) );
  503. if ( FAILED( hr ) )
  504. goto Cleanup;
  505. //
  506. // Tell the task which cluster to commit.
  507. //
  508. hr = THR( ptccc->SetClusterCookie( g_cookieCluster ) );
  509. if ( FAILED( hr ) )
  510. goto Cleanup;
  511. //
  512. // Create a callback object.
  513. //
  514. Assert( punk == NULL );
  515. hr = THR( CCallback::S_HrCreateInstance( &punk ) );
  516. if ( FAILED( hr ) )
  517. goto Cleanup;
  518. punk = TraceInterface( L"CCallback", IUnknown, punk, 1 );
  519. hr = THR( punk->TypeSafeQI( IClusCfgCallback, &pcccb ) );
  520. if ( FAILED( hr ) )
  521. goto Cleanup;
  522. //
  523. // The the action where to call us back.
  524. //
  525. hr = THR( ptccc->SetCallback( pcccb ) );
  526. if ( FAILED( hr ) )
  527. goto Cleanup;
  528. //
  529. // Reset g_fWait and submit the task.
  530. //
  531. g_fWait = TRUE;
  532. hr = THR( ptm->SubmitTask( ptccc ) );
  533. if ( FAILED( hr ) )
  534. goto Cleanup;
  535. //
  536. // Wait for the task to complete.
  537. //
  538. while( g_fWait )
  539. {
  540. Sleep( 1 ); // sleep a millisecond
  541. }
  542. //
  543. // Unregister the notification object.
  544. //
  545. hr = THR( pcp->Unadvise( dwCookie ) );
  546. if ( FAILED( hr ) )
  547. goto Cleanup;
  548. Cleanup:
  549. if ( pcp != NULL )
  550. {
  551. pcp->Release( );
  552. }
  553. if ( pom != NULL )
  554. {
  555. pom->Release( );
  556. }
  557. if ( ptm != NULL )
  558. {
  559. ptm->Release( );
  560. }
  561. if ( ptccc != NULL )
  562. {
  563. ptccc->Release( );
  564. }
  565. if ( punk != NULL )
  566. {
  567. punk->Release( );
  568. }
  569. if ( pnui != NULL )
  570. {
  571. pnui->Release( );
  572. }
  573. if ( pcccb != NULL )
  574. {
  575. pcccb->Release( );
  576. }
  577. HRETURN( hr );
  578. }
  579. //
  580. // This tests the object manager's node enumerator.
  581. //
  582. HRESULT
  583. HrTestEnumNodes( void )
  584. {
  585. TraceFunc( "" );
  586. HRESULT hr;
  587. OBJECTCOOKIE cookieDummy;
  588. ULONG celtFetched;
  589. BSTR bstrName = NULL;
  590. IUnknown * punk = NULL;
  591. IObjectManager * pom = NULL;
  592. IEnumNodes * pen = NULL;
  593. IClusCfgNodeInfo * pccni = NULL;
  594. //
  595. // Gather the manager needed to complete this task.
  596. //
  597. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager,
  598. IObjectManager,
  599. &pom
  600. ) );
  601. if ( FAILED( hr ) )
  602. goto Cleanup;
  603. //
  604. // Ask the object manager to create a cookie for the task
  605. // to use as a completion cookie.
  606. //
  607. hr = THR( pom->FindObject( CLSID_NodeType,
  608. g_cookieCluster,
  609. NULL,
  610. DFGUID_EnumNodes,
  611. &cookieDummy, // not needed, but the proxy code wants something
  612. &punk
  613. ) );
  614. if ( FAILED( hr ) )
  615. goto Cleanup;
  616. hr = THR( punk->TypeSafeQI( IEnumNodes, &pen ) );
  617. if ( FAILED( hr ) )
  618. goto Cleanup;
  619. //
  620. // Enumerate the nodes.
  621. //
  622. Assert( hr == S_OK );
  623. while ( hr == S_OK )
  624. {
  625. hr = STHR( pen->Next( 1, &pccni, &celtFetched ) );
  626. if ( hr == S_FALSE )
  627. break; // exit loop
  628. if ( FAILED( hr ) )
  629. goto Cleanup;
  630. hr = THR( pccni->GetName( &bstrName ) );
  631. if ( FAILED( hr ) )
  632. goto Cleanup;
  633. DebugMsg( "Node Name: %s", bstrName );
  634. TraceSysFreeString( bstrName );
  635. pccni->Release( );
  636. pccni = NULL;
  637. }
  638. hr = S_OK;
  639. Cleanup:
  640. if ( pom != NULL )
  641. {
  642. pom->Release( );
  643. }
  644. if ( punk != NULL )
  645. {
  646. punk->Release( );
  647. }
  648. if ( pen != NULL )
  649. {
  650. pen->Release( );
  651. }
  652. if ( pccni != NULL )
  653. {
  654. pccni->Release( );
  655. }
  656. if ( bstrName != NULL )
  657. {
  658. TraceSysFreeString( bstrName );
  659. }
  660. HRETURN( hr );
  661. }
  662. //
  663. // This tests all the object manager's enumerators. It should be executed
  664. // while the object cache is empty.
  665. //
  666. HRESULT
  667. HrTestEmptyEnumerations( void )
  668. {
  669. TraceFunc( "" );
  670. HRESULT hr;
  671. OBJECTCOOKIE cookie;
  672. IUnknown * punk = NULL;
  673. IObjectManager * pom = NULL;
  674. IEnumNodes * pen = NULL;
  675. IClusCfgNodeInfo * pccni = NULL;
  676. IEnumClusCfgManagedResources * peccmr = NULL;
  677. IEnumClusCfgNetworks * peccn = NULL;
  678. IClusCfgManagedResourceInfo * pccmri = NULL;
  679. IClusCfgNetworkInfo * pccneti = NULL;
  680. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager,
  681. IObjectManager,
  682. &pom
  683. ) );
  684. if ( FAILED( hr ) )
  685. goto Cleanup;
  686. //
  687. // This should fail.
  688. //
  689. hr = pom->FindObject( CLSID_NodeType,
  690. NULL,
  691. NULL,
  692. DFGUID_EnumNodes,
  693. &cookie,
  694. &punk
  695. );
  696. if ( FAILED( hr ) )
  697. {
  698. hr = S_OK; // ignore the failure.
  699. goto EnumResources;
  700. }
  701. hr = THR( punk->TypeSafeQI( IEnumNodes, &pen ) );
  702. if ( FAILED( hr ) )
  703. goto Cleanup;
  704. punk->Release( );
  705. punk = NULL;
  706. //
  707. // If it didn't fail, then this shouldn't AV.
  708. //
  709. Assert( hr == S_OK );
  710. while ( hr == S_OK )
  711. {
  712. hr = STHR( pen->Next( 1, &pccni, NULL ) );
  713. if ( hr == S_FALSE )
  714. break;
  715. if ( FAILED( hr ) )
  716. goto Cleanup;
  717. pccni->Release( );
  718. pccni = NULL;
  719. }
  720. EnumResources:
  721. //
  722. // This should fail.
  723. //
  724. hr = pom->FindObject( CLSID_NodeType,
  725. NULL,
  726. NULL,
  727. DFGUID_EnumManageableResources,
  728. &cookie,
  729. &punk
  730. );
  731. if ( FAILED( hr ) )
  732. {
  733. hr = S_OK; // ignore the failure.
  734. goto EnumNetworks;
  735. }
  736. hr = THR( punk->TypeSafeQI( IEnumClusCfgManagedResources, &peccmr ) );
  737. if ( FAILED( hr ) )
  738. goto Cleanup;
  739. punk->Release( );
  740. punk = NULL;
  741. //
  742. // If it didn't fail, then this shouldn't AV.
  743. //
  744. Assert( hr == S_OK );
  745. while ( hr == S_OK )
  746. {
  747. hr = STHR( peccmr->Next( 1, &pccmri, NULL ) );
  748. if ( hr == S_FALSE )
  749. break;
  750. if ( FAILED( hr ) )
  751. goto Cleanup;
  752. pccmri->Release( );
  753. pccmri = NULL;
  754. }
  755. EnumNetworks:
  756. //
  757. // This should fail.
  758. //
  759. hr = pom->FindObject( CLSID_NodeType,
  760. NULL,
  761. NULL,
  762. DFGUID_EnumManageableNetworks,
  763. &cookie,
  764. &punk
  765. );
  766. if ( FAILED( hr ) )
  767. {
  768. hr = S_OK; // ignore the failure.
  769. goto Cleanup;
  770. }
  771. hr = THR( punk->TypeSafeQI( IEnumClusCfgNetworks, &peccn ) );
  772. if ( FAILED( hr ) )
  773. goto Cleanup;
  774. punk->Release( );
  775. punk = NULL;
  776. //
  777. // If it didn't fail, then this shouldn't AV.
  778. //
  779. Assert( hr == S_OK );
  780. while ( hr == S_OK )
  781. {
  782. hr = STHR( peccn->Next( 1, &pccneti, NULL ) );
  783. if ( hr == S_FALSE )
  784. break;
  785. if ( FAILED( hr ) )
  786. goto Cleanup;
  787. pccneti->Release( );
  788. pccneti = NULL;
  789. }
  790. hr = S_OK;
  791. Cleanup:
  792. if ( punk != NULL )
  793. {
  794. punk->Release( );
  795. }
  796. if ( peccmr != NULL )
  797. {
  798. peccmr->Release( );
  799. }
  800. if ( peccn != NULL )
  801. {
  802. peccn->Release( );
  803. }
  804. if ( pccni != NULL )
  805. {
  806. pccni->Release( );
  807. }
  808. if ( pccmri != NULL )
  809. {
  810. pccmri->Release( );
  811. }
  812. if ( pccneti != NULL )
  813. {
  814. pccneti->Release( );
  815. }
  816. if ( pen != NULL )
  817. {
  818. pen->Release( );
  819. }
  820. if ( pom != NULL )
  821. {
  822. pom->Release( );
  823. }
  824. HRETURN( hr );
  825. }
  826. //
  827. // This tests the Cluster Configuration object in the object manager.
  828. //
  829. HRESULT
  830. HrTestClusterConfiguration(
  831. BSTR bstrClusterNameIn,
  832. BSTR bstrAccountNameIn,
  833. BSTR bstrPasswordIn,
  834. BSTR bstrDomainIn,
  835. ULONG ulClusterIPIn,
  836. ULONG ulClusterSubnetIn,
  837. OBJECTCOOKIE * pcookieClusterOut
  838. )
  839. {
  840. TraceFunc( "" );
  841. HRESULT hr;
  842. ULONG ulClusterIP;
  843. ULONG ulClusterSubnet;
  844. BSTR bstrClusterName = NULL;
  845. BSTR bstrAccountName = NULL;
  846. BSTR bstrPassword = NULL;
  847. BSTR bstrDomain = NULL;
  848. IUnknown * punk = NULL;
  849. IObjectManager * pom = NULL;
  850. IClusCfgClusterInfo * pccci = NULL;
  851. IClusCfgCredentials * piccc = NULL;
  852. //
  853. // Retrieve the Object Manager
  854. //
  855. hr = THR( g_psp->TypeSafeQS( CLSID_ObjectManager,
  856. IObjectManager,
  857. &pom
  858. ) );
  859. if ( FAILED( hr ) )
  860. goto Cleanup;
  861. //
  862. // Ask the Object Manager for the cluster configuration object.
  863. //
  864. hr = E_PENDING;
  865. while ( hr == E_PENDING )
  866. {
  867. // Don't wrap. this can fail with E_PENDING.
  868. hr = pom->FindObject( CLSID_ClusterConfigurationType,
  869. NULL,
  870. bstrClusterNameIn,
  871. DFGUID_ClusterConfigurationInfo,
  872. pcookieClusterOut,
  873. &punk
  874. );
  875. if ( hr == E_PENDING )
  876. {
  877. Sleep( 1000 ); // 1 Second
  878. continue;
  879. }
  880. THR( hr );
  881. if ( FAILED( hr ) )
  882. goto Cleanup;
  883. } // while: pending
  884. hr = THR( punk->TypeSafeQI( IClusCfgClusterInfo, &pccci ) );
  885. if ( FAILED( hr ) )
  886. goto Cleanup;
  887. punk->Release( );
  888. punk = NULL;
  889. //
  890. // Exercise the forming and joining flags.
  891. //
  892. hr = THR( pccci->SetForming( TRUE ) );
  893. if ( FAILED( hr ) )
  894. goto Cleanup;
  895. #if defined(TURN_ON_ALL_TESTS)
  896. // This will fail.
  897. hr = pccci->SetJoining( TRUE );
  898. Assert( FAILED( hr ) );
  899. #endif
  900. hr = THR( pccci->SetForming( FALSE ) );
  901. if ( FAILED( hr ) )
  902. goto Cleanup;
  903. hr = THR( pccci->SetJoining( TRUE ) );
  904. if ( FAILED( hr ) )
  905. goto Cleanup;
  906. #if defined(TURN_ON_ALL_TESTS)
  907. // This will fail.
  908. hr = pccci->SetForming( TRUE );
  909. Assert( FAILED( hr ) );
  910. #endif
  911. hr = THR( pccci->SetJoining( FALSE ) );
  912. if ( FAILED( hr ) )
  913. goto Cleanup;
  914. //
  915. // Test account info.
  916. //
  917. hr = THR( pccci->GetClusterServiceAccountCredentials( &piccc ) );
  918. if ( FAILED( hr ) )
  919. goto Cleanup;
  920. hr = THR( piccc->SetCredentials( bstrAccountNameIn, bstrDomainIn, bstrPasswordIn ) );
  921. if ( FAILED( hr ) )
  922. goto Cleanup;
  923. hr = THR( piccc->GetCredentials( &bstrAccountName, &bstrDomain, &bstrPassword ) );
  924. if ( FAILED( hr ) )
  925. goto Cleanup;
  926. Assert( StrCmp( bstrAccountNameIn, bstrAccountName ) == 0 );
  927. Assert( StrCmp( bstrPasswordIn, bstrPassword ) == 0 );
  928. Assert( StrCmp( bstrDomainIn, bstrDomain ) == 0 );
  929. piccc->Release();
  930. piccc = NULL;
  931. //
  932. //. Test cluster name.
  933. //
  934. hr = THR( pccci->SetName( bstrClusterNameIn ) );
  935. if ( FAILED( hr ) )
  936. goto Cleanup;
  937. hr = THR( pccci->GetName( &bstrClusterName ) );
  938. if ( FAILED( hr ) )
  939. goto Cleanup;
  940. Assert( StrCmp( bstrClusterNameIn, bstrClusterName ) == 0 );
  941. //
  942. // Test IP/subnet.
  943. //
  944. hr = THR( pccci->SetIPAddress( ulClusterIPIn ) );
  945. if ( FAILED( hr ) )
  946. goto Cleanup;
  947. hr = THR( pccci->SetSubnetMask( ulClusterSubnetIn ) );
  948. if ( FAILED( hr ) )
  949. goto Cleanup;
  950. hr = THR( pccci->GetIPAddress( &ulClusterIP ) );
  951. if ( FAILED( hr ) )
  952. goto Cleanup;
  953. hr = THR( pccci->GetSubnetMask( &ulClusterSubnet ) );
  954. if ( FAILED( hr ) )
  955. goto Cleanup;
  956. Assert( ulClusterIP == ulClusterIPIn );
  957. Assert( ulClusterSubnet == ulClusterSubnetIn );
  958. Cleanup:
  959. if ( punk != NULL )
  960. {
  961. punk->Release( );
  962. }
  963. if ( bstrClusterName != NULL )
  964. {
  965. TraceSysFreeString( bstrClusterName );
  966. }
  967. if ( bstrAccountName != NULL )
  968. {
  969. TraceSysFreeString( bstrAccountName );
  970. }
  971. if ( bstrPassword != NULL )
  972. {
  973. TraceSysFreeString( bstrPassword );
  974. }
  975. if ( bstrDomain != NULL )
  976. {
  977. TraceSysFreeString( bstrDomain );
  978. }
  979. if ( pom != NULL )
  980. {
  981. pom->Release( );
  982. }
  983. if ( piccc != NULL )
  984. {
  985. piccc->Release( );
  986. }
  987. if ( pccci != NULL )
  988. {
  989. pccci->Release( );
  990. }
  991. HRETURN( hr );
  992. }
  993. //////////////////////////////////////////////////////////////////////////////
  994. //
  995. // int
  996. // _cdecl
  997. // main( void )
  998. //
  999. // Description:
  1000. // Program entrance.
  1001. //
  1002. // Arguments:
  1003. // None.
  1004. //
  1005. // Return Value:
  1006. // S_OK (0) - Success.
  1007. // other HRESULTs - Error.
  1008. //
  1009. //////////////////////////////////////////////////////////////////////////////
  1010. int
  1011. _cdecl
  1012. main( void )
  1013. {
  1014. TraceInitializeProcess( NULL, 0 );
  1015. HRESULT hr;
  1016. ULONG ulClusterIP;
  1017. ULONG ulClusterSubnet;
  1018. ulClusterIP = inet_addr( "10.1.1.10" );
  1019. ulClusterSubnet = inet_addr( "255.255.0.0" );
  1020. hr = THR( CoInitialize( NULL ) );
  1021. if ( FAILED( hr ) )
  1022. goto Cleanup;
  1023. #if 0
  1024. hr = THR( HrRegisterTheDll( ) );
  1025. if ( FAILED( hr ) )
  1026. goto Cleanup;
  1027. #endif
  1028. //
  1029. // Start up the middle tier.
  1030. //
  1031. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  1032. NULL,
  1033. CLSCTX_SERVER,
  1034. TypeSafeParams( IServiceProvider, &g_psp )
  1035. ) );
  1036. if ( FAILED( hr ) )
  1037. goto Cleanup;
  1038. #if 0 || defined(TURN_ON_ALL_TESTS)
  1039. hr = THR( HrTestEmptyEnumerations( ) );
  1040. if ( FAILED( hr ) )
  1041. goto Cleanup;
  1042. #endif
  1043. #if 0 || defined(TURN_ON_ALL_TESTS) || defined(REGRESSION_PASS)
  1044. hr = THR( HrTestClusterConfiguration( L"GPEASEDEV-CLUS.NTDEV.MICROSOFT.COM",
  1045. L"ntdev",
  1046. L"ntdevntdev",
  1047. L"ntdev",
  1048. ulClusterIP,
  1049. ulClusterSubnet,
  1050. &g_cookieCluster
  1051. ) );
  1052. if ( FAILED( hr ) )
  1053. goto Cleanup;
  1054. #endif
  1055. #if 1 || defined(TURN_ON_ALL_TESTS) || defined(REGRESSION_PASS)
  1056. hr = THR( HrTestAddingNode( L"GPEASE-WOLF1.NTDEV.MICROSOFT.COM" ) );
  1057. if ( FAILED( hr ) )
  1058. goto Cleanup;
  1059. #if 0 || defined(TURN_ON_ALL_TESTS)
  1060. //
  1061. // KB: Since HrTestAddingNode( ) changes the name of the node when
  1062. // TURN_ON_ALL_TESTS is on, it doesn't make sense to try to
  1063. // connect to another node.
  1064. //
  1065. hr = THR( HrTestAddingNode( L"GALENB-CLUS.NTDEV.MICROSOFT.COM" ) );
  1066. if ( FAILED( hr ) )
  1067. goto Cleanup;
  1068. #endif
  1069. #endif // HrTestAddingNode
  1070. #if 1 || defined(TURN_ON_ALL_TESTS) || defined(REGRESSION_PASS)
  1071. //
  1072. // KB: HrTestAddingNode() must be run before this or the test
  1073. // will failed.
  1074. //
  1075. hr = THR( HrTestEnumNodes( ) );
  1076. if ( FAILED( hr ) )
  1077. goto Cleanup;
  1078. #endif // HrTestEnumNodes
  1079. #if 0 || defined(TURN_ON_ALL_TESTS) || defined(REGRESSION_PASS)
  1080. hr = THR( HrTestTaskAnalyzeCluster( ) );
  1081. if ( FAILED( hr ) )
  1082. goto Cleanup;
  1083. #endif // HrTestTaskAnalyzeCluster
  1084. #if 0 || defined(TURN_ON_ALL_TESTS) || defined(REGRESSION_PASS)
  1085. hr = THR( HrTestTaskCommitClusterChanges( ) );
  1086. if ( FAILED( hr ) )
  1087. goto Cleanup;
  1088. #endif // HrTestTaskCommitClusterChanges
  1089. Cleanup:
  1090. if ( g_psp != NULL )
  1091. {
  1092. g_psp->Release( );
  1093. }
  1094. CoUninitialize( );
  1095. TraceTerminateProcess( NULL, 0 );
  1096. return 0;
  1097. }