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.

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