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.

511 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterWMIProvider.cpp
  7. //
  8. // Description:
  9. // Implementation of the provider registration and entry point.
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include <initguid.h>
  17. #include "ProvFactory.h"
  18. #include "InstanceProv.h"
  19. #include "EventProv.h"
  20. #include "ClusterWMIProvider.tmh"
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Global Data
  23. //////////////////////////////////////////////////////////////////////////////
  24. // {598065EA-EDC9-4b2c-913B-5104D04D098A}
  25. DEFINE_GUID( CLSID_CLUSTER_WMI_PROVIDER,
  26. 0x598065ea, 0xedc9, 0x4b2c, 0x91, 0x3b, 0x51, 0x4, 0xd0, 0x4d, 0x9, 0x8a );
  27. // {6A52C339-DCB0-4682-8B1B-02DE2C436A6D}
  28. DEFINE_GUID( CLSID_CLUSTER_WMI_CLASS_PROVIDER,
  29. 0x6a52c339, 0xdcb0, 0x4682, 0x8b, 0x1b, 0x2, 0xde, 0x2c, 0x43, 0x6a, 0x6d );
  30. // {92863246-4EDE-4eff-B606-79C1971DB230}
  31. DEFINE_GUID( CLSID_CLUSTER_WMI_EVENT_PROVIDER,
  32. 0x92863246, 0x4ede, 0x4eff, 0xb6, 0x6, 0x79, 0xc1, 0x97, 0x1d, 0xb2, 0x30 );
  33. // Count number of objects and number of locks.
  34. long g_cObj = 0;
  35. long g_cLock = 0;
  36. HMODULE g_hModule;
  37. FactoryData g_FactoryDataArray[] =
  38. {
  39. {
  40. &CLSID_CLUSTER_WMI_PROVIDER,
  41. CInstanceProv::S_HrCreateThis,
  42. L"Cluster service WMI instance provider"
  43. },
  44. {
  45. &CLSID_CLUSTER_WMI_CLASS_PROVIDER,
  46. CClassProv::S_HrCreateThis,
  47. L"Cluster service WMI class provider"
  48. },
  49. {
  50. &CLSID_CLUSTER_WMI_EVENT_PROVIDER,
  51. CEventProv::S_HrCreateThis,
  52. L"Cluster service WMI event provider"
  53. },
  54. };
  55. //////////////////////////////////////////////////////////////////////////////
  56. //++
  57. //
  58. // BOOL
  59. // WINAPI
  60. // DllMain(
  61. // HANDLE hModule,
  62. // DWORD ul_reason_for_call,
  63. // LPVOID lpReserved
  64. // )
  65. //
  66. // Description:
  67. // Main DLL entry point.
  68. //
  69. // Arguments:
  70. // hModule -- DLL module handle.
  71. // ul_reason_for_call --
  72. // lpReserved --
  73. //
  74. // Return Values:
  75. // TRUE
  76. //
  77. //--
  78. //////////////////////////////////////////////////////////////////////////////
  79. BOOL
  80. WINAPI
  81. DllMain(
  82. HANDLE hModule,
  83. DWORD ul_reason_for_call,
  84. LPVOID lpReserved
  85. )
  86. {
  87. // begin_wpp config
  88. // CUSTOM_TYPE(dllreason, ItemListLong(DLL_PROCESS_DETACH, DLL_PROCESS_ATTACH, DLL_THREAD_ATTACH, DLL_THREAD_DETACH) );
  89. //
  90. // CUSTOM_TYPE(EventIdx, ItemSetLong(NODE_STATE, NODE_DELETED, NODE_ADDED, NODE_PROPERTY, REGISTRY_NAME,REGISTRY_ATTRIBUTES, REGISTRY_VALUE, REGISTRY_SUBTREE, RESOURCE_STATE, RESOURCE_DELETED, RESOURCE_ADDED, RESOURCE_PROPERTY, GROUP_STATE, GROUP_DELETED, GROUP_ADDED, GROUP_PROPERTY, RESOURCE_TYPE_DELETED, RESOURCE_TYPE_ADDED, RESOURCE_TYPE_PROPERTY, CLUSTER_RECONNECT, NETWORK_STATE, NETWORK_DELETED, NETWORK_ADDED, NETWORK_PROPERTY, NETINTERFACE_STATE, NETINTERFACE_DELETED, NETINTERFACE_ADDED, NETINTERFACE_PROPERTY, QUORUM_STATE, CLUSTER_STATE, CLUSTER_PROPERTY, HANDLE_CLOSE));
  91. //
  92. // CUSTOM_TYPE(GroupState, ItemListLong(Online, Offline, Failed, PartialOnline, Pending) );
  93. // CUSTOM_TYPE(ResourceState, ItemListLong(Initing, Initializing, Online, Offline, Failed) );
  94. // end_wpp
  95. //
  96. // Cluster event filter flags.
  97. //
  98. /*
  99. NODE_STATE = 0x00000001,
  100. NODE_DELETED = 0x00000002,
  101. NODE_ADDED = 0x00000004,
  102. NODE_PROPERTY = 0x00000008,
  103. REGISTRY_NAME = 0x00000010,
  104. REGISTRY_ATTRIBUTES = 0x00000020,
  105. REGISTRY_VALUE = 0x00000040,
  106. REGISTRY_SUBTREE = 0x00000080,
  107. RESOURCE_STATE = 0x00000100,
  108. RESOURCE_DELETED = 0x00000200,
  109. RESOURCE_ADDED = 0x00000400,
  110. RESOURCE_PROPERTY = 0x00000800,
  111. GROUP_STATE = 0x00001000,
  112. GROUP_DELETED = 0x00002000,
  113. GROUP_ADDED = 0x00004000,
  114. GROUP_PROPERTY = 0x00008000,
  115. RESOURCE_TYPE_DELETED = 0x00010000,
  116. RESOURCE_TYPE_ADDED = 0x00020000,
  117. RESOURCE_TYPE_PROPERTY = 0x00040000,
  118. CLUSTER_RECONNECT = 0x00080000,
  119. NETWORK_STATE = 0x00100000,
  120. NETWORK_DELETED = 0x00200000,
  121. NETWORK_ADDED = 0x00400000,
  122. NETWORK_PROPERTY = 0x00800000,
  123. NETINTERFACE_STATE = 0x01000000,
  124. NETINTERFACE_DELETED = 0x02000000,
  125. NETINTERFACE_ADDED = 0x04000000,
  126. NETINTERFACE_PROPERTY = 0x08000000,
  127. QUORUM_STATE = 0x10000000,
  128. CLUSTER_STATE = 0x20000000,
  129. CLUSTER_PROPERTY = 0x40000000,
  130. HANDLE_CLOSE = 0x80000000,
  131. */
  132. //#ifdef _DEBUG
  133. // _CrtSetBreakAlloc( 228 );
  134. //#endif
  135. TracePrint(("ClusWMI: DllMain entry, reason = %!dllreason!", ul_reason_for_call));
  136. g_hModule = static_cast< HMODULE >( hModule );
  137. switch ( ul_reason_for_call ) {
  138. case DLL_PROCESS_ATTACH:
  139. WPP_INIT_TRACING( NULL );
  140. break;
  141. case DLL_PROCESS_DETACH:
  142. WPP_CLEANUP();
  143. break;
  144. default:
  145. break;
  146. }
  147. return TRUE;
  148. } //*** DllMain()
  149. //////////////////////////////////////////////////////////////////////////////
  150. //++
  151. //
  152. // STDAPI
  153. // DllCanUnloadNow( void )
  154. //
  155. // Description:
  156. // Called periodically by Ole in order to determine if the
  157. // DLL can be freed.
  158. //
  159. // Arguments:
  160. // None.
  161. //
  162. // Return Values:
  163. // S_OK if there are no objects in use and the class factory
  164. // isn't locked.
  165. //
  166. //--
  167. //////////////////////////////////////////////////////////////////////////////
  168. STDAPI DllCanUnloadNow( void )
  169. {
  170. SCODE sc;
  171. //It is OK to unload if there are no objects or locks on the
  172. // class factory.
  173. sc = ( (0L == g_cObj) && (0L == g_cLock) ) ? S_OK : S_FALSE;
  174. TracePrint(("ClusWMI: DllCanUnloadNow is returning %d", sc));
  175. return sc;
  176. } //*** DllCanUnloadNow()
  177. //////////////////////////////////////////////////////////////////////////////
  178. //++
  179. //
  180. // STDAPI
  181. // DllRegisterServer( void )
  182. //
  183. // Description:
  184. // Called during setup or by regsvr32.
  185. //
  186. // Arguments:
  187. // None.
  188. //
  189. // Return Values:
  190. // NOERROR if registration successful, error otherwise.
  191. // SELFREG_E_CLASS
  192. //
  193. //--
  194. //////////////////////////////////////////////////////////////////////////////
  195. STDAPI DllRegisterServer( void )
  196. {
  197. WCHAR wszID[ 128 ];
  198. WCHAR wszCLSID[ 128 ];
  199. WCHAR wszModule[ MAX_PATH ];
  200. INT idx;
  201. WCHAR * pwszModel = L"Both";
  202. HKEY hKey1;
  203. HKEY hKey2;
  204. DWORD dwRt = ERROR_SUCCESS;
  205. INT cArray = sizeof ( g_FactoryDataArray ) / sizeof ( FactoryData );
  206. TracePrint(("ClusWMI: DllRegisterServer entry"));
  207. // Create the path.
  208. try
  209. {
  210. do
  211. {
  212. DWORD cbModuleNameSize = 0;
  213. if ( GetModuleFileName( g_hModule, wszModule, MAX_PATH ) == 0 )
  214. {
  215. dwRt = GetLastError();
  216. break;
  217. }
  218. cbModuleNameSize = ( lstrlenW( wszModule ) + 1 ) * sizeof( wszModule[ 0 ] );
  219. for ( idx = 0 ; idx < cArray && dwRt == ERROR_SUCCESS ; idx++ )
  220. {
  221. LPCWSTR pwszName = g_FactoryDataArray[ idx ].m_pwszRegistryName;
  222. StringFromGUID2(
  223. *g_FactoryDataArray[ idx ].m_pCLSID,
  224. wszID,
  225. 128
  226. );
  227. lstrcpyW( wszCLSID, L"Software\\Classes\\CLSID\\" );
  228. lstrcatW( wszCLSID, wszID );
  229. // Create entries under CLSID
  230. dwRt = RegCreateKeyW(
  231. HKEY_LOCAL_MACHINE,
  232. wszCLSID,
  233. &hKey1
  234. );
  235. if ( dwRt != ERROR_SUCCESS )
  236. {
  237. break;
  238. }
  239. dwRt = RegSetValueEx(
  240. hKey1,
  241. NULL,
  242. 0,
  243. REG_SZ,
  244. (BYTE *) pwszName,
  245. sizeof( WCHAR ) * ( lstrlenW( pwszName ) + 1 )
  246. );
  247. if ( dwRt != ERROR_SUCCESS )
  248. {
  249. break;
  250. }
  251. dwRt = RegCreateKeyW(
  252. hKey1,
  253. L"InprocServer32",
  254. & hKey2
  255. );
  256. if ( dwRt != ERROR_SUCCESS )
  257. {
  258. break;
  259. }
  260. dwRt = RegSetValueEx(
  261. hKey2,
  262. NULL,
  263. 0,
  264. REG_SZ,
  265. (BYTE *) wszModule,
  266. cbModuleNameSize
  267. );
  268. if ( dwRt != ERROR_SUCCESS )
  269. {
  270. break;
  271. }
  272. dwRt = RegSetValueExW(
  273. hKey2,
  274. L"ThreadingModel",
  275. 0,
  276. REG_SZ,
  277. (BYTE *) pwszModel,
  278. sizeof( WCHAR ) * ( lstrlen( pwszModel ) + 1 )
  279. );
  280. if ( dwRt != ERROR_SUCCESS )
  281. {
  282. break;
  283. }
  284. RegCloseKey( hKey1 );
  285. RegCloseKey( hKey2 );
  286. } // for: each entry in factory entry array
  287. if ( dwRt != ERROR_SUCCESS )
  288. {
  289. break;
  290. }
  291. }
  292. while( false ); // dummy do-while loop to avoid gotos
  293. }
  294. catch ( ... )
  295. {
  296. RegCloseKey( hKey1 );
  297. RegCloseKey( hKey2 );
  298. dwRt = SELFREG_E_CLASS;
  299. }
  300. TracePrint(("ClusWMI: RegisterServer returned %d", dwRt));
  301. return dwRt;
  302. } //*** DllRegisterServer()
  303. //////////////////////////////////////////////////////////////////////////////
  304. //++
  305. //
  306. // STDAPI
  307. // DllUnregisterServer( void )
  308. //
  309. // Description:
  310. // Called when it is time to remove the registry entries.
  311. //
  312. // Arguments:
  313. // None.
  314. //
  315. // Return Values:
  316. // NOERROR if registration successful, error otherwise.
  317. // SELFREG_E_CLASS
  318. //
  319. //--
  320. //////////////////////////////////////////////////////////////////////////////
  321. STDAPI DllUnregisterServer( void )
  322. {
  323. WCHAR wszID[ 128 ];
  324. WCHAR wszCLSID[ 128 ];
  325. HKEY hKey;
  326. INT idx;
  327. DWORD dwRet = ERROR_SUCCESS;
  328. INT cArray = sizeof ( g_FactoryDataArray ) / sizeof ( FactoryData );
  329. for ( idx = 0 ; idx < 2 && dwRet == ERROR_SUCCESS ; idx++ )
  330. {
  331. StringFromGUID2(
  332. *g_FactoryDataArray[ idx ].m_pCLSID,
  333. wszID,
  334. 128
  335. );
  336. lstrcpyW( wszCLSID, L"Software\\Classes\\CLSID\\" );
  337. lstrcatW( wszCLSID, wszID );
  338. // First delete the InProcServer subkey.
  339. dwRet = RegOpenKeyW(
  340. HKEY_LOCAL_MACHINE,
  341. wszCLSID,
  342. &hKey
  343. );
  344. if ( dwRet != ERROR_SUCCESS )
  345. {
  346. break;
  347. }
  348. dwRet = RegDeleteKeyW( hKey, L"InProcServer32" );
  349. RegCloseKey( hKey );
  350. if ( dwRet != ERROR_SUCCESS )
  351. {
  352. break;
  353. }
  354. dwRet = RegOpenKeyW(
  355. HKEY_LOCAL_MACHINE,
  356. L"Software\\Classes\\CLSID",
  357. &hKey
  358. );
  359. if ( dwRet != ERROR_SUCCESS )
  360. {
  361. break;
  362. }
  363. dwRet = RegDeleteKeyW( hKey,wszID );
  364. RegCloseKey( hKey );
  365. if ( dwRet != ERROR_SUCCESS )
  366. {
  367. break;
  368. }
  369. } // for: each object
  370. if ( dwRet != ERROR_SUCCESS )
  371. {
  372. dwRet = SELFREG_E_CLASS;
  373. }
  374. return dwRet;
  375. } //*** DllUnregisterServer()
  376. //////////////////////////////////////////////////////////////////////////////
  377. //++
  378. //
  379. // STDAPI
  380. // DllGetClassObject(
  381. // REFCLSID rclsidIn,
  382. // REFIID riidIn,
  383. // PPVOID ppvOut
  384. // )
  385. //
  386. // Description:
  387. // Called by Ole when some client wants a class factory. Return
  388. // one only if it is the sort of class this DLL supports.
  389. //
  390. // Arguments:
  391. // rclsidIn --
  392. // riidIn --
  393. // ppvOut --
  394. //
  395. // Return Values:
  396. // NOERROR if registration successful, error otherwise.
  397. // E_OUTOFMEMORY
  398. // E_FAIL
  399. //
  400. //--
  401. //////////////////////////////////////////////////////////////////////////////
  402. STDAPI
  403. DllGetClassObject(
  404. REFCLSID rclsidIn,
  405. REFIID riidIn,
  406. PPVOID ppvOut
  407. )
  408. {
  409. HRESULT hr;
  410. CProvFactory * pObj = NULL;
  411. UINT idx;
  412. UINT cDataArray = sizeof ( g_FactoryDataArray ) / sizeof ( FactoryData );
  413. for ( idx = 0 ; idx < cDataArray ; idx++ )
  414. {
  415. if ( rclsidIn == *g_FactoryDataArray[ idx ].m_pCLSID )
  416. {
  417. pObj= new CProvFactory( &g_FactoryDataArray[ idx ] );
  418. if ( NULL == pObj )
  419. {
  420. return E_OUTOFMEMORY;
  421. }
  422. hr = pObj->QueryInterface( riidIn, ppvOut );
  423. if ( FAILED( hr ) )
  424. {
  425. delete pObj;
  426. }
  427. return hr;
  428. }
  429. }
  430. return E_FAIL;
  431. } //*** DllGetClassObject()