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.

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