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.

501 lines
17 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // MSClus.cpp
  7. //
  8. // Description:
  9. // Implementation of the DLL Exports for the MSCLUS automation classes.
  10. //
  11. // Author:
  12. // Charles Stacy Harris (stacyh) 28-Feb-1997
  13. // Galen Barbee (galenb) July 1998
  14. //
  15. // Revision History:
  16. // July 1998 GalenB Maaaaaajjjjjjjjjoooooorrrr clean up
  17. //
  18. // Notes:
  19. //
  20. /////////////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include <ShlWapi.h>
  23. #include <atlimpl.cpp>
  24. #include <initguid.h>
  25. #include <ClusRtl.h>
  26. #include "ClusterObject.h"
  27. #include "property.h"
  28. #include "ClusNeti.h"
  29. #include "ClusNetw.h"
  30. #include "ClusRes.h"
  31. #include "ClusRest.h"
  32. #include "ClusResg.h"
  33. #include "ClusNode.h"
  34. #include "Version.h"
  35. #include "ClusApp.h"
  36. #include "Cluster.h"
  37. #define IID_DEFINED
  38. #include "msclus_i.c"
  39. #undef IID_DEFINED
  40. CComModule _Module;
  41. BEGIN_OBJECT_MAP(ObjectMap)
  42. OBJECT_ENTRY(CLSID_ClusApplication, CClusApplication)
  43. OBJECT_ENTRY(CLSID_Cluster, CCluster)
  44. OBJECT_ENTRY(CLSID_ClusVersion, CClusVersion)
  45. OBJECT_ENTRY(CLSID_DomainNames, CDomainNames)
  46. OBJECT_ENTRY(CLSID_ClusResGroupPreferredOwnerNodes, CClusResGroupPreferredOwnerNodes)
  47. OBJECT_ENTRY(CLSID_ClusterNames, CClusterNames)
  48. OBJECT_ENTRY(CLSID_ClusNetInterface, CClusNetInterface)
  49. OBJECT_ENTRY(CLSID_ClusNetInterfaces, CClusNetInterfaces)
  50. OBJECT_ENTRY(CLSID_ClusNetwork, CClusNetwork)
  51. OBJECT_ENTRY(CLSID_ClusNetworks, CClusNetworks)
  52. OBJECT_ENTRY(CLSID_ClusNetworkNetInterfaces, CClusNetworkNetInterfaces)
  53. OBJECT_ENTRY(CLSID_ClusNode, CClusNode)
  54. OBJECT_ENTRY(CLSID_ClusNodes, CClusNodes)
  55. OBJECT_ENTRY(CLSID_ClusNodeNetInterfaces, CClusNodeNetInterfaces)
  56. OBJECT_ENTRY(CLSID_ClusProperty, CClusProperty)
  57. OBJECT_ENTRY(CLSID_ClusProperties, CClusProperties)
  58. OBJECT_ENTRY(CLSID_ClusRefObject, CClusRefObject)
  59. OBJECT_ENTRY(CLSID_ClusResDependencies, CClusResDependencies)
  60. // OBJECT_ENTRY(CLSID_CClusResDependents , CClusResDependents )
  61. OBJECT_ENTRY(CLSID_ClusResGroup, CClusResGroup)
  62. OBJECT_ENTRY(CLSID_ClusResGroups, CClusResGroups)
  63. OBJECT_ENTRY(CLSID_ClusResource, CClusResource)
  64. OBJECT_ENTRY(CLSID_ClusResources, CClusResources)
  65. OBJECT_ENTRY(CLSID_ClusResPossibleOwnerNodes, CClusResPossibleOwnerNodes)
  66. OBJECT_ENTRY(CLSID_ClusResType, CClusResType)
  67. OBJECT_ENTRY(CLSID_ClusResTypes, CClusResTypes)
  68. OBJECT_ENTRY(CLSID_ClusResTypeResources, CClusResTypeResources)
  69. OBJECT_ENTRY(CLSID_ClusResGroupResources, CClusResGroupResources)
  70. #if CLUSAPI_VERSION >= 0x0500
  71. OBJECT_ENTRY(CLSID_ClusResTypePossibleOwnerNodes, CClusResTypePossibleOwnerNodes)
  72. #endif // CLUSAPI_VERSION >= 0x0500
  73. OBJECT_ENTRY(CLSID_ClusPropertyValue, CClusPropertyValue)
  74. OBJECT_ENTRY(CLSID_ClusPropertyValues, CClusPropertyValues)
  75. OBJECT_ENTRY(CLSID_ClusPropertyValueData, CClusPropertyValueData)
  76. OBJECT_ENTRY(CLSID_ClusPartition, CClusPartition)
  77. OBJECT_ENTRY(CLSID_ClusPartitions, CClusPartitions)
  78. OBJECT_ENTRY(CLSID_ClusDisk, CClusDisk)
  79. OBJECT_ENTRY(CLSID_ClusDisks, CClusDisks)
  80. OBJECT_ENTRY(CLSID_ClusScsiAddress, CClusScsiAddress)
  81. OBJECT_ENTRY(CLSID_ClusRegistryKeys, CClusResourceRegistryKeys)
  82. #if CLUSAPI_VERSION >= 0x0500
  83. OBJECT_ENTRY(CLSID_ClusCryptoKeys, CClusResourceCryptoKeys)
  84. #endif // CLUSAPI_VERSION >= 0x0500
  85. END_OBJECT_MAP()
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Forward function declarations
  88. /////////////////////////////////////////////////////////////////////////////
  89. static void RegisterRegistryCleanUp( void );
  90. static void UnregisterRegistryCleanUp( void );
  91. static const LPWSTR g_ptszRegisterRegistryNodesToDelete[] =
  92. {
  93. _T( "software\\classes\\MSCluster.Application" ),
  94. _T( "software\\classes\\MSCluster.Application.2" ),
  95. _T( "software\\classes\\MSCluster.Cluster.2" ),
  96. _T( "software\\classes\\MSCluster.ClusGroupResources" ),
  97. _T( "software\\classes\\MSCluster.ClusGroupResources.1" ),
  98. _T( "software\\classes\\MSCluster.ClusGroupOwners" ),
  99. _T( "software\\classes\\MSCluster.ClusGroupOwners.1" ),
  100. _T( "software\\classes\\MSCluster.ClusResOwners" ),
  101. _T( "software\\classes\\MSCluster.ClusResOwners.1" ),
  102. _T( "software\\classes\\CLSID\\{f2e60717-2631-11d1-89f1-00a0c90d061e}" ),
  103. _T( "software\\classes\\interface\\{f2e60718-2631-11d1-89f1-00a0c90d061e}" ),
  104. _T( "software\\classes\\CLSID\\{f2e60719-2631-11d1-89f1-00a0c90d061e}" ),
  105. _T( "software\\classes\\interface\\{f2e6071a-2631-11d1-89f1-00a0c90d061e}" ),
  106. _T( "software\\classes\\interface\\{f2e606e0-2631-11d1-89f1-00a0c90d061e}" ),
  107. _T( "software\\classes\\interface\\{f2e606e1-2631-11d1-89f1-00a0c90d061e}" ),
  108. _T( "software\\classes\\interface\\{f2e606e3-2631-11d1-89f1-00a0c90d061e}" ),
  109. _T( "software\\classes\\interface\\{f2e606e5-2631-11d1-89f1-00a0c90d061e}" ),
  110. _T( "software\\classes\\interface\\{f2e606e7-2631-11d1-89f1-00a0c90d061e}" ),
  111. _T( "software\\classes\\interface\\{f2e606e9-2631-11d1-89f1-00a0c90d061e}" ),
  112. _T( "software\\classes\\interface\\{f2e606eb-2631-11d1-89f1-00a0c90d061e}" ),
  113. _T( "software\\classes\\interface\\{f2e606ed-2631-11d1-89f1-00a0c90d061e}" ),
  114. _T( "software\\classes\\interface\\{f2e606ef-2631-11d1-89f1-00a0c90d061e}" ),
  115. _T( "software\\classes\\interface\\{f2e606f3-2631-11d1-89f1-00a0c90d061e}" ),
  116. _T( "software\\classes\\interface\\{f2e606f5-2631-11d1-89f1-00a0c90d061e}" ),
  117. _T( "software\\classes\\interface\\{f2e606f7-2631-11d1-89f1-00a0c90d061e}" ),
  118. _T( "software\\classes\\interface\\{f2e606f9-2631-11d1-89f1-00a0c90d061e}" ),
  119. _T( "software\\classes\\interface\\{f2e606fb-2631-11d1-89f1-00a0c90d061e}" ),
  120. _T( "software\\classes\\interface\\{f2e606fd-2631-11d1-89f1-00a0c90d061e}" ),
  121. _T( "software\\classes\\interface\\{f2e606fe-2631-11d1-89f1-00a0c90d061e}" ),
  122. _T( "software\\classes\\interface\\{f2e606ff-2631-11d1-89f1-00a0c90d061e}" ),
  123. _T( "software\\classes\\interface\\{f2e60700-2631-11d1-89f1-00a0c90d061e}" ),
  124. _T( "software\\classes\\interface\\{f2e60702-2631-11d1-89f1-00a0c90d061e}" ),
  125. _T( "software\\classes\\interface\\{f2e60704-2631-11d1-89f1-00a0c90d061e}" ),
  126. _T( "software\\classes\\CLSID\\{f2e606f2-2631-11d1-89f1-00a0c90d061e}" ),
  127. NULL
  128. };
  129. /*
  130. static const LPWSTR g_ptszUnregisterRegistryNodesToDelete[] =
  131. {
  132. // _T( "software\\classes\\typelib\\{f2e606e0-2631-11d1-89f1-00a0c90d061e}" ),
  133. _T( "software\\classes\\interface\\{f2e606e2-2631-11d1-89f1-00a0c90d061e}" ),
  134. _T( "software\\classes\\interface\\{f2e606e4-2631-11d1-89f1-00a0c90d061e}" ),
  135. _T( "software\\classes\\interface\\{f2e606e6-2631-11d1-89f1-00a0c90d061e}" ),
  136. _T( "software\\classes\\interface\\{f2e606e8-2631-11d1-89f1-00a0c90d061e}" ),
  137. _T( "software\\classes\\interface\\{f2e606ea-2631-11d1-89f1-00a0c90d061e}" ),
  138. _T( "software\\classes\\interface\\{f2e606ec-2631-11d1-89f1-00a0c90d061e}" ),
  139. _T( "software\\classes\\interface\\{f2e606ee-2631-11d1-89f1-00a0c90d061e}" ),
  140. _T( "software\\classes\\interface\\{f2e606f0-2631-11d1-89f1-00a0c90d061e}" ),
  141. _T( "software\\classes\\interface\\{f2e606f2-2631-11d1-89f1-00a0c90d061e}" ),
  142. _T( "software\\classes\\interface\\{f2e606f4-2631-11d1-89f1-00a0c90d061e}" ),
  143. _T( "software\\classes\\interface\\{f2e606f6-2631-11d1-89f1-00a0c90d061e}" ),
  144. _T( "software\\classes\\interface\\{f2e606f8-2631-11d1-89f1-00a0c90d061e}" ),
  145. _T( "software\\classes\\interface\\{f2e606fa-2631-11d1-89f1-00a0c90d061e}" ),
  146. _T( "software\\classes\\interface\\{f2e606fc-2631-11d1-89f1-00a0c90d061e}" ),
  147. _T( "software\\classes\\interface\\{f2e606fe-2631-11d1-89f1-00a0c90d061e}" ),
  148. _T( "software\\classes\\interface\\{f2e60700-2631-11d1-89f1-00a0c90d061e}" ),
  149. _T( "software\\classes\\interface\\{f2e60702-2631-11d1-89f1-00a0c90d061e}" ),
  150. _T( "software\\classes\\interface\\{f2e60704-2631-11d1-89f1-00a0c90d061e}" ),
  151. _T( "software\\classes\\interface\\{f2e60706-2631-11d1-89f1-00a0c90d061e}" ),
  152. _T( "software\\classes\\interface\\{f2e60708-2631-11d1-89f1-00a0c90d061e}" ),
  153. _T( "software\\classes\\interface\\{f2e6070a-2631-11d1-89f1-00a0c90d061e}" ),
  154. _T( "software\\classes\\interface\\{f2e6070c-2631-11d1-89f1-00a0c90d061e}" ),
  155. _T( "software\\classes\\interface\\{f2e6070e-2631-11d1-89f1-00a0c90d061e}" ),
  156. _T( "software\\classes\\interface\\{f2e60710-2631-11d1-89f1-00a0c90d061e}" ),
  157. _T( "software\\classes\\interface\\{f2e60712-2631-11d1-89f1-00a0c90d061e}" ),
  158. _T( "software\\classes\\interface\\{f2e60714-2631-11d1-89f1-00a0c90d061e}" ),
  159. _T( "software\\classes\\interface\\{f2e60716-2631-11d1-89f1-00a0c90d061e}" ),
  160. NULL
  161. };
  162. */
  163. /////////////////////////////////////////////////////////////////////////////
  164. //++
  165. //
  166. // DllMain
  167. //
  168. // Description:
  169. // DLL Entry Point.
  170. //
  171. // Arguments:
  172. // hInstance [IN] - Out instance handle.
  173. // dwReason [IN] - The reason we are being called.
  174. // lpReserved [IN] - Don't rightly know what this is...
  175. //
  176. // Return Value:
  177. // TRUE if successful, FALSE if not.
  178. //
  179. //--
  180. /////////////////////////////////////////////////////////////////////////////
  181. extern "C" BOOL WINAPI DllMain(
  182. IN HINSTANCE hInstance,
  183. IN DWORD dwReason,
  184. IN LPVOID //lpReserved
  185. )
  186. {
  187. if ( dwReason == DLL_PROCESS_ATTACH )
  188. {
  189. #ifdef _DEBUG
  190. _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
  191. _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
  192. #endif
  193. _Module.Init( ObjectMap, hInstance );
  194. DisableThreadLibraryCalls( hInstance );
  195. }
  196. else if ( dwReason == DLL_PROCESS_DETACH )
  197. {
  198. _Module.Term();
  199. }
  200. return TRUE; // ok
  201. } //*** DllMain()
  202. /////////////////////////////////////////////////////////////////////////////
  203. //++
  204. //
  205. // DllCanUnloadNow
  206. //
  207. // Description:
  208. // Used to determine whether the DLL can be unloaded by OLE.
  209. //
  210. // Arguments:
  211. // None.
  212. //
  213. // Return Value:
  214. // S_OK if we can unload, S_FALSE if we cannot.
  215. //
  216. //--
  217. /////////////////////////////////////////////////////////////////////////////
  218. STDAPI DllCanUnloadNow( void )
  219. {
  220. return ( _Module.GetLockCount() == 0 ) ? S_OK : S_FALSE;
  221. } //*** DllCanUnloadNow()
  222. /////////////////////////////////////////////////////////////////////////////
  223. //++
  224. //
  225. // DllGetClassObject
  226. //
  227. // Description:
  228. // Retrieves the class object from a DLL object handler or object
  229. // application. DllGetClassObject is called from within the
  230. // CoGetClassObject function when the class context is a DLL.
  231. //
  232. // Arguments:
  233. // rclsid [IN] - CLSID that will associate the correct data and code.
  234. // riid [IN] - Reference to the identifier of the interface that the
  235. // caller is to use to communicate with the class object.
  236. // Usually, this is IID_IClassFactory (defined in the OLE
  237. // headers as the interface identifier for IClassFactory).
  238. // ppv [OUT] - Address of pointer variable that receives the interface
  239. // pointer requested in riid. Upon successful return, *ppv
  240. // contains the requested interface pointer. If an error
  241. // occurs, the interface pointer is NULL.
  242. //
  243. // Return Value:
  244. // S_OK if successful, or CLASS_E_CLASSNOTAVAILABLE if not.
  245. //
  246. //--
  247. /////////////////////////////////////////////////////////////////////////////
  248. STDAPI DllGetClassObject(
  249. IN REFCLSID rclsid,
  250. IN REFIID riid,
  251. OUT LPVOID * ppv
  252. )
  253. {
  254. return _Module.GetClassObject( rclsid, riid, ppv );
  255. } //*** DllGetClassObject()
  256. /////////////////////////////////////////////////////////////////////////////
  257. //++
  258. //
  259. // DllRegisterServer
  260. //
  261. // Description:
  262. // Add entries to the system registry.
  263. //
  264. // Arguments:
  265. // None.
  266. //
  267. // Return Value:
  268. // S_OK if successful, or other HRESULT error if not.
  269. //
  270. //--
  271. /////////////////////////////////////////////////////////////////////////////
  272. STDAPI DllRegisterServer( void )
  273. {
  274. RegisterRegistryCleanUp();
  275. //
  276. // Registers object, typelib and all interfaces in typelib
  277. //
  278. return _Module.RegisterServer( TRUE );
  279. } //*** DllRegisterServer()
  280. /////////////////////////////////////////////////////////////////////////////
  281. //++
  282. //
  283. // DllUnregisterServer
  284. //
  285. // Description:
  286. // Removes entries from the system registry.
  287. //
  288. // Arguments:
  289. // None.
  290. //
  291. // Return Value:
  292. // S_OK if successful, or other HRESULT error if not.
  293. //
  294. //--
  295. /////////////////////////////////////////////////////////////////////////////
  296. STDAPI DllUnregisterServer( void )
  297. {
  298. HRESULT _hr = S_FALSE;
  299. UnregisterRegistryCleanUp();
  300. //
  301. // Unregisters object, typelib and all interfaces in typelib
  302. //
  303. _hr = _Module.UnregisterServer();
  304. if ( SUCCEEDED( _hr ) )
  305. {
  306. #if _WIN32_WINNT >= 0x0400
  307. _hr = UnRegisterTypeLib( LIBID_MSClusterLib, 1, 0, LOCALE_NEUTRAL, SYS_WIN32 );
  308. #endif
  309. } //if: server was unregistered
  310. return _hr;
  311. } //*** DllUnregisterServer()
  312. /////////////////////////////////////////////////////////////////////////////
  313. //++
  314. //
  315. // HrGetCluster
  316. //
  317. // Description:
  318. // Common implementation of creating a new cluster object.
  319. //
  320. // Arguments:
  321. // ppCluster [OUT] - Catches the newly created object.
  322. // pClusRefObject [IN] - Object that wraps the cluster handle.
  323. //
  324. // Return Value:
  325. // S_OK for success
  326. //
  327. //--
  328. /////////////////////////////////////////////////////////////////////////////
  329. HRESULT HrGetCluster(
  330. OUT ISCluster ** ppCluster,
  331. IN ISClusRefObject * pClusRefObject
  332. )
  333. {
  334. //ASSERT( ppCluster != NULL );
  335. ASSERT( pClusRefObject != NULL );
  336. HRESULT _hr = E_POINTER;
  337. if ( ( ppCluster != NULL ) && ( pClusRefObject != NULL ) )
  338. {
  339. HCLUSTER hCluster = NULL;
  340. _hr = pClusRefObject->get_Handle( (ULONG_PTR *) &hCluster );
  341. if ( SUCCEEDED( _hr ) )
  342. {
  343. CComObject< CCluster > * pCluster = NULL;
  344. _hr = CComObject< CCluster >::CreateInstance( &pCluster );
  345. if ( SUCCEEDED( _hr ) )
  346. {
  347. pCluster->ClusRefObject( pClusRefObject );
  348. pCluster->Hcluster( hCluster );
  349. _hr = pCluster->QueryInterface( IID_ISCluster, (void **) ppCluster );
  350. }
  351. }
  352. }
  353. return _hr;
  354. } //*** HrGetCluster()
  355. /////////////////////////////////////////////////////////////////////////////
  356. //++
  357. //
  358. // RegisterRegistryCleanUp
  359. //
  360. // Description:
  361. // Clean up the registry during registration
  362. //
  363. // Arguments:
  364. // None.
  365. //
  366. // Return Value:
  367. // None.
  368. //
  369. //--
  370. /////////////////////////////////////////////////////////////////////////////
  371. static void RegisterRegistryCleanUp( void )
  372. {
  373. int nIndex;;
  374. for ( nIndex = 0; ; nIndex++ )
  375. {
  376. if ( g_ptszRegisterRegistryNodesToDelete[ nIndex ] == NULL )
  377. {
  378. break;
  379. } // if:
  380. SHDeleteKey( HKEY_LOCAL_MACHINE, g_ptszRegisterRegistryNodesToDelete[ nIndex ] );
  381. } // for:
  382. } //*** RegisterRegistryCleanUp()
  383. /////////////////////////////////////////////////////////////////////////////
  384. //++
  385. //
  386. // UnregisterRegistryCleanUp
  387. //
  388. // Description:
  389. // Clean up the registry during unregistration
  390. //
  391. // Arguments:
  392. // None.
  393. //
  394. // Return Value:
  395. // None.
  396. //
  397. //--
  398. /////////////////////////////////////////////////////////////////////////////
  399. static void UnregisterRegistryCleanUp( void )
  400. {
  401. return;
  402. } //*** UnregisterRegistryCleanUp()
  403. /////////////////////////////////////////////////////////////////////////////
  404. //++
  405. //
  406. // ClearIDispatchEnum
  407. //
  408. // Description:
  409. // Cleans up an Enum of IDispatch pointers.
  410. //
  411. // Arguments:
  412. // ppVarVect [IN OUT] - The enum to clean up.
  413. //
  414. // Return Value:
  415. // None.
  416. //
  417. //--
  418. /////////////////////////////////////////////////////////////////////////////
  419. void ClearIDispatchEnum(
  420. IN OUT CComVariant ** ppvarVect
  421. )
  422. {
  423. if ( ppvarVect != NULL )
  424. {
  425. size_t cCount = ARRAYSIZE( *ppvarVect );
  426. size_t iIndex;
  427. for ( iIndex = 0; iIndex < cCount; iIndex++ )
  428. {
  429. (*ppvarVect[iIndex]).pdispVal->Release();
  430. } // for:
  431. delete [] *ppvarVect;
  432. *ppvarVect = NULL;
  433. }
  434. } //*** ClearIDispatchEnum()
  435. /////////////////////////////////////////////////////////////////////////////
  436. //++
  437. //
  438. // ClearVariantEnum
  439. //
  440. // Description:
  441. // Cleans up an Enum of variant values.
  442. //
  443. // Arguments:
  444. // ppVarVect [IN OUT] - The enum to clean up.
  445. //
  446. // Return Value:
  447. // None.
  448. //
  449. //--
  450. /////////////////////////////////////////////////////////////////////////////
  451. void ClearVariantEnum(
  452. IN OUT CComVariant ** ppvarVect
  453. )
  454. {
  455. if ( ppvarVect != NULL )
  456. {
  457. delete [] *ppvarVect;
  458. *ppvarVect = NULL;
  459. }
  460. } //*** ClearVariantEnum()