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.

252 lines
6.5 KiB

  1. //***************************************************************************
  2. //
  3. // MAINDLL.CPP
  4. //
  5. // Module: IIS WMI Instance provider
  6. //
  7. // Purpose: Contains DLL entry points. Also has code that controls
  8. // when the DLL can be unloaded by tracking the number of
  9. // objects and locks as well as routines that support
  10. // self registration.
  11. //
  12. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  13. //
  14. //***************************************************************************
  15. #include <objbase.h>
  16. #include <initguid.h>
  17. #include <olectl.h>
  18. #include "iisprov.h"
  19. static HMODULE s_hModule;
  20. //Count number of objects and number of locks.
  21. long g_cObj=0;
  22. long g_cLock=0;
  23. // GuidGen generated GUID for the IIS WMI Provider.
  24. DEFINE_GUID(CLSID_IISWbemProvider, 0x1339f295, 0x5c3f, 0x45ab, 0xa1, 0x17, 0xc9, 0x1b, 0x0, 0x24, 0x8, 0xd5);
  25. // the GUID in somewhat more legibal terms: {1339F295-5C3F-45ab-A117-C91B002408D5}
  26. //***************************************************************************
  27. //
  28. // DllMain
  29. //
  30. // Purpose: Entry point for DLL.
  31. //
  32. // Return: TRUE if OK.
  33. //
  34. //***************************************************************************
  35. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD ulReason, LPVOID pvReserved)
  36. {
  37. switch( ulReason )
  38. {
  39. case DLL_PROCESS_ATTACH:
  40. s_hModule = hInstance;
  41. break;
  42. case DLL_PROCESS_DETACH:
  43. break;
  44. }
  45. return TRUE;
  46. }
  47. //***************************************************************************
  48. //
  49. // DllGetClassObject
  50. //
  51. // Purpose: Called by Ole when some client wants a class factory. Return
  52. // one only if it is the sort of class this DLL supports.
  53. //
  54. //***************************************************************************
  55. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv)
  56. {
  57. HRESULT hr;
  58. CProvFactory *pObj;
  59. if (CLSID_IISWbemProvider != rclsid)
  60. return E_FAIL;
  61. pObj=new CProvFactory();
  62. if (NULL==pObj)
  63. return E_OUTOFMEMORY;
  64. hr=pObj->QueryInterface(riid, ppv);
  65. if (FAILED(hr))
  66. delete pObj;
  67. return hr;
  68. }
  69. //***************************************************************************
  70. //
  71. // DllCanUnloadNow
  72. //
  73. // Purpose: Called periodically by Ole in order to determine if the
  74. // DLL can be freed.
  75. //
  76. // Return: S_OK if there are no objects in use and the class factory
  77. // isn't locked.
  78. //
  79. //***************************************************************************
  80. STDAPI DllCanUnloadNow(void)
  81. {
  82. SCODE sc;
  83. //It is OK to unload if there are no objects or locks on the
  84. // class factory.
  85. sc = (0L>=g_cObj && 0L>=g_cLock) ? S_OK : S_FALSE;
  86. return sc;
  87. }
  88. //***************************************************************************
  89. //
  90. // DllRegisterServer
  91. //
  92. // Purpose: Called during setup or by regsvr32.
  93. //
  94. // Return: NOERROR if registration successful, error otherwise.
  95. //***************************************************************************
  96. STDAPI DllRegisterServer(void)
  97. {
  98. WCHAR szID[MAX_PATH+1];
  99. WCHAR wcID[MAX_PATH+1];
  100. WCHAR szCLSID[MAX_PATH+1];
  101. WCHAR szModule[MAX_PATH+1];
  102. WCHAR * pName = L"Microsoft Internet Information Server Provider";
  103. WCHAR * pModel = L"Both";
  104. HKEY hKey1, hKey2;
  105. // Create the path.
  106. StringFromGUID2(CLSID_IISWbemProvider, wcID, MAX_PATH);
  107. lstrcpyW(szID, wcID);
  108. lstrcpyW(szCLSID, L"Software\\classes\\CLSID\\");
  109. lstrcatW(szCLSID, szID);
  110. // Create entries under CLSID
  111. LONG lRet;
  112. lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
  113. szCLSID,
  114. 0,
  115. NULL,
  116. 0,
  117. KEY_ALL_ACCESS,
  118. NULL,
  119. &hKey1,
  120. NULL);
  121. if(lRet != ERROR_SUCCESS)
  122. return SELFREG_E_CLASS;
  123. RegSetValueExW(hKey1,
  124. NULL,
  125. 0,
  126. REG_SZ,
  127. (BYTE *)pName,
  128. lstrlenW(pName)*sizeof(WCHAR)+1);
  129. lRet = RegCreateKeyExW(hKey1,
  130. L"InprocServer32",
  131. 0,
  132. NULL,
  133. 0,
  134. KEY_ALL_ACCESS,
  135. NULL,
  136. &hKey2,
  137. NULL);
  138. if(lRet != ERROR_SUCCESS)
  139. {
  140. RegCloseKey(hKey1);
  141. return SELFREG_E_CLASS;
  142. }
  143. GetModuleFileNameW(s_hModule, szModule, MAX_PATH);
  144. RegSetValueExW(hKey2,
  145. NULL,
  146. 0,
  147. REG_SZ,
  148. (BYTE*)szModule,
  149. lstrlenW(szModule) * sizeof(WCHAR) + 1);
  150. RegSetValueExW(hKey2,
  151. L"ThreadingModel",
  152. 0,
  153. REG_SZ,
  154. (BYTE *)pModel,
  155. lstrlenW(pModel) * sizeof(WCHAR) + 1);
  156. RegCloseKey(hKey1);
  157. RegCloseKey(hKey2);
  158. return S_OK;
  159. }
  160. //***************************************************************************
  161. //
  162. // DllUnregisterServer
  163. //
  164. // Purpose: Called when it is time to remove the registry entries.
  165. //
  166. // Return: NOERROR if registration successful, error otherwise.
  167. //***************************************************************************
  168. STDAPI DllUnregisterServer(void)
  169. {
  170. WCHAR szID[MAX_PATH+1];
  171. WCHAR wcID[MAX_PATH+1];
  172. WCHAR szCLSID[MAX_PATH+1];
  173. HKEY hKey;
  174. // Create the path using the CLSID
  175. StringFromGUID2(CLSID_IISWbemProvider, wcID, 128);
  176. lstrcpyW(szID, wcID);
  177. lstrcpyW(szCLSID, L"Software\\classes\\CLSID\\");
  178. lstrcatW(szCLSID, szID);
  179. // First delete the InProcServer subkey.
  180. LONG lRet;
  181. lRet = RegOpenKeyExW(
  182. HKEY_LOCAL_MACHINE,
  183. szCLSID,
  184. 0,
  185. KEY_ALL_ACCESS,
  186. &hKey
  187. );
  188. if(lRet == ERROR_SUCCESS)
  189. {
  190. RegDeleteKeyW(hKey, L"InProcServer32");
  191. RegCloseKey(hKey);
  192. }
  193. lRet = RegOpenKeyExW(
  194. HKEY_LOCAL_MACHINE,
  195. L"Software\\classes\\CLSID",
  196. 0,
  197. KEY_ALL_ACCESS,
  198. &hKey
  199. );
  200. if(lRet == ERROR_SUCCESS)
  201. {
  202. RegDeleteKeyW(hKey,szID);
  203. RegCloseKey(hKey);
  204. }
  205. return S_OK;
  206. }