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.

440 lines
9.6 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. // Galen Barbee (GalenB) 22-JAN-2000
  17. // David Potter (DavidP) 22-JAN-2000
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20. #include "pch.h"
  21. #include <initguid.h>
  22. #include <guids.h>
  23. #include <ClusRtl.h>
  24. #include "Callback.h"
  25. DEFINE_MODULE( "CLUSCFGSERVERTEST" )
  26. //
  27. // Declarations
  28. //
  29. typedef HRESULT (* PDLLREGISTERSERVER)( void );
  30. //
  31. // Globals
  32. //
  33. HINSTANCE g_hInstance = NULL;
  34. LONG g_cObjects = 0;
  35. IClusCfgServer * g_pccs = NULL;
  36. //
  37. // Register the DLL
  38. //
  39. HRESULT
  40. HrRegisterTheDll( void )
  41. {
  42. TraceFunc( "" );
  43. HRESULT hr;
  44. PDLLREGISTERSERVER pDllRegisterServer;
  45. HMODULE hLib = NULL;
  46. //
  47. // Make sure the DLL is properly registered.
  48. //
  49. hLib = LoadLibrary( L"..\\..\\..\\..\\dll\\obj\\i386\\ClusCfgServer.dll" );
  50. if ( hLib == NULL )
  51. goto Win32Error;
  52. pDllRegisterServer = reinterpret_cast< PDLLREGISTERSERVER >( GetProcAddress( hLib, "DllRegisterServer" ) );
  53. if ( pDllRegisterServer == NULL )
  54. goto Win32Error;
  55. hr = THR( pDllRegisterServer() );
  56. if ( FAILED( hr ) )
  57. goto Cleanup;
  58. Cleanup:
  59. if ( hLib != NULL )
  60. {
  61. FreeLibrary( hLib );
  62. }
  63. HRETURN( hr );
  64. Win32Error:
  65. hr = THR( HRESULT_FROM_WIN32( GetLastError() ) );
  66. goto Cleanup;
  67. }
  68. //
  69. // This tests the Storage device enumeration.
  70. //
  71. HRESULT
  72. HrTestManagedResourceEnum( void )
  73. {
  74. TraceFunc( "" );
  75. HRESULT hr;
  76. IEnumClusCfgManagedResources * pesd = NULL;
  77. ULONG cReceived = 0;
  78. IClusCfgManagedResourceInfo * rgDevices[ 10 ];
  79. hr = g_pccs->GetManagedResourcesEnum( &pesd );
  80. if ( FAILED( hr ) )
  81. {
  82. goto Cleanup;
  83. } // if:
  84. while ( hr == S_OK )
  85. {
  86. hr = pesd->Next( sizeof( rgDevices ) / sizeof( rgDevices[ 0 ] ), &rgDevices[ 0 ], &cReceived );
  87. if ( FAILED( hr ) )
  88. {
  89. goto Cleanup;
  90. } // if:
  91. DebugMsg( "cReceived = %u", cReceived );
  92. for ( ULONG idx = 0; idx < cReceived; idx++ )
  93. {
  94. BSTR bstr;
  95. THR( rgDevices[ idx ]->GetUID( &bstr ) );
  96. DebugMsg( "Device %u, UID = %ws", idx, bstr );
  97. SysFreeString( bstr );
  98. rgDevices[ idx ]->Release();
  99. } // for:
  100. } // while:
  101. if ( hr == S_FALSE )
  102. {
  103. hr = S_OK;
  104. } // if:
  105. Cleanup:
  106. if ( pesd != NULL )
  107. {
  108. pesd->Release();
  109. }
  110. HRETURN( hr );
  111. } //*** HrTestManagedResourceEnum()
  112. //
  113. // This tests the Storage device enumeration.
  114. //
  115. HRESULT
  116. HrTestNetworksEnum( void )
  117. {
  118. TraceFunc( "" );
  119. HRESULT hr;
  120. IEnumClusCfgNetworks * pens = NULL;
  121. ULONG cReceived = 0;
  122. IClusCfgNetworkInfo * rdNetworks[ 10 ];
  123. BSTR bstrUID;
  124. LPWSTR lpsz = NULL;
  125. ULONG ulDottedQuad;
  126. IClusCfgIPAddressInfo * piccipai = NULL;
  127. hr = g_pccs->GetNetworksEnum( &pens );
  128. if ( FAILED( hr ) )
  129. {
  130. goto Cleanup;
  131. } // if:
  132. while ( hr == S_OK )
  133. {
  134. hr = STHR( pens->Next( sizeof( rdNetworks ) / sizeof( rdNetworks[ 0 ] ), &rdNetworks[ 0 ], &cReceived ) );
  135. if ( FAILED( hr ) )
  136. {
  137. goto Cleanup;
  138. } // if:
  139. for ( ULONG idx = 0; idx < cReceived; idx++ )
  140. {
  141. hr = THR( rdNetworks[ idx ]->GetPrimaryNetworkAddress( &piccipai ) );
  142. if ( SUCCEEDED( hr ) )
  143. {
  144. hr = THR( piccipai->GetIPAddress( &ulDottedQuad ) );
  145. if ( SUCCEEDED( hr ) )
  146. {
  147. DWORD sc;
  148. sc = ClRtlTcpipAddressToString( ulDottedQuad, &lpsz );
  149. if ( sc == ERROR_SUCCESS )
  150. {
  151. LocalFree( lpsz );
  152. lpsz = NULL;
  153. } // if:
  154. } // if:
  155. piccipai->Release();
  156. } // if:
  157. hr = THR( rdNetworks[ idx ]->GetUID( &bstrUID ) );
  158. if ( SUCCEEDED( hr ) )
  159. {
  160. SysFreeString( bstrUID );
  161. } // if:
  162. rdNetworks[ idx ]->Release();
  163. } // for:
  164. } // while:
  165. if ( hr == S_FALSE )
  166. {
  167. hr = S_OK;
  168. } // if:
  169. Cleanup:
  170. if ( pens != NULL )
  171. {
  172. pens->Release();
  173. }
  174. if ( lpsz != NULL )
  175. {
  176. LocalFree( lpsz );
  177. } // if:
  178. HRETURN( hr );
  179. } //*** HrTestNetworksEnum()
  180. //
  181. // This tests the node information
  182. //
  183. HRESULT
  184. HrTestNodeInfo( void )
  185. {
  186. TraceFunc( "" );
  187. HRESULT hr;
  188. IClusCfgNodeInfo * pccni = NULL;
  189. DWORD dwNodeHighestVersion;
  190. DWORD dwNodeLowestVersion;
  191. SDriveLetterMapping dlmDriveLetterUsage;
  192. IClusCfgClusterInfo * pccci = NULL;
  193. DWORD dwMajorVersion;
  194. DWORD dwMinorVersion;
  195. WORD wSuiteMask;
  196. BYTE bProductType;
  197. BSTR bstrCSDVersion = NULL;
  198. hr = g_pccs->GetClusterNodeInfo( &pccni );
  199. if ( FAILED( hr ) )
  200. {
  201. goto Cleanup;
  202. } // if:
  203. hr = pccni->GetClusterVersion( &dwNodeHighestVersion, &dwNodeLowestVersion );
  204. if ( FAILED( hr ) )
  205. {
  206. goto Cleanup;
  207. } // if:
  208. hr = pccni->GetOSVersion( &dwMajorVersion, &dwMinorVersion, &wSuiteMask, &bProductType, &bstrCSDVersion );
  209. if ( FAILED( hr ) )
  210. {
  211. goto Cleanup;
  212. } // if:
  213. hr = pccni->GetDriveLetterMappings( &dlmDriveLetterUsage );
  214. if ( FAILED( hr ) )
  215. {
  216. goto Cleanup;
  217. } // if:
  218. hr = pccni->GetClusterConfigInfo( &pccci );
  219. if ( FAILED( hr ) )
  220. {
  221. goto Cleanup;
  222. } // if:
  223. Cleanup:
  224. if ( pccci != NULL )
  225. {
  226. pccci->Release();
  227. }
  228. if ( pccni != NULL )
  229. {
  230. pccni->Release();
  231. }
  232. SysFreeString( bstrCSDVersion );
  233. HRETURN( hr );
  234. } //*** HrTestNodeInfo()
  235. //////////////////////////////////////////////////////////////////////////////
  236. //
  237. // int
  238. // _cdecl
  239. // main( void )
  240. //
  241. // Description:
  242. // Program entrance.
  243. //
  244. // Arguments:
  245. // None.
  246. //
  247. // Return Value:
  248. // S_OK (0) - Success.
  249. // other HRESULTs - Error.
  250. //
  251. //////////////////////////////////////////////////////////////////////////////
  252. int _cdecl
  253. main( void )
  254. {
  255. HRESULT hr;
  256. IClusCfgInitialize * pgcci = NULL;
  257. IClusCfgCapabilities * piccc = NULL;
  258. IUnknown * punkCallback = NULL;
  259. TraceInitializeProcess();
  260. #if 0
  261. hr = THR( HrRegisterTheDll() );
  262. if ( FAILED( hr ) )
  263. {
  264. goto Cleanup;
  265. } // if:
  266. #endif
  267. //
  268. // Start up the Cluster configuration server
  269. //
  270. hr = THR( CoInitialize( NULL ) );
  271. if ( FAILED( hr ) )
  272. {
  273. goto Cleanup;
  274. } // if:
  275. hr = THR( CoInitializeSecurity(
  276. NULL,
  277. -1,
  278. NULL,
  279. NULL,
  280. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  281. RPC_C_IMP_LEVEL_IMPERSONATE,
  282. NULL,
  283. EOAC_NONE,
  284. 0
  285. ) );
  286. if ( FAILED( hr ) )
  287. {
  288. goto Cleanup;
  289. } // if:
  290. hr = THR( CoCreateInstance( CLSID_ClusCfgServer, NULL, CLSCTX_SERVER, TypeSafeParams( IClusCfgServer, &g_pccs ) ) );
  291. if ( FAILED( hr ) )
  292. {
  293. goto Cleanup;
  294. } // if:
  295. hr = THR( g_pccs->TypeSafeQI( IClusCfgInitialize, &pgcci ) );
  296. if ( FAILED( hr ) )
  297. {
  298. goto Cleanup;
  299. } // if:
  300. hr = THR( Callback::S_HrCreateInstance( &punkCallback ) );
  301. if ( FAILED( hr ) )
  302. {
  303. goto Cleanup;
  304. } // if:
  305. hr = pgcci->Initialize( punkCallback, GetUserDefaultLCID() );
  306. if ( FAILED( hr ) )
  307. {
  308. goto Cleanup;
  309. } // if:
  310. hr = THR( g_pccs->TypeSafeQI( IClusCfgCapabilities, &piccc ) );
  311. if ( FAILED( hr ) )
  312. {
  313. goto Cleanup;
  314. } // if:
  315. hr = THR( piccc->CanNodeBeClustered() );
  316. if ( FAILED( hr ) || ( hr == S_FALSE ) )
  317. {
  318. goto Cleanup;
  319. } // if:
  320. hr = THR( HrTestNodeInfo() );
  321. if ( FAILED( hr ) )
  322. {
  323. goto Cleanup;
  324. } // if:
  325. hr = THR( HrTestManagedResourceEnum() );
  326. if ( FAILED( hr ) )
  327. {
  328. goto Cleanup;
  329. } // if:
  330. hr = THR( HrTestNetworksEnum() );
  331. if ( FAILED( hr ) )
  332. {
  333. goto Cleanup;
  334. } // if:
  335. Cleanup:
  336. if ( punkCallback != NULL )
  337. {
  338. punkCallback->Release();
  339. } // if:
  340. if ( piccc != NULL )
  341. {
  342. piccc->Release();
  343. } // if:
  344. if ( pgcci != NULL )
  345. {
  346. pgcci->Release();
  347. } // if:
  348. if ( g_pccs != NULL )
  349. {
  350. g_pccs->Release();
  351. }
  352. CoUninitialize();
  353. TraceTerminateProcess();
  354. return 0;
  355. }