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
7.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. classfactory.cxx
  5. Abstract:
  6. starts/stops SSL configuration provider
  7. Author:
  8. Michael W. Thomas 16-Sep-97
  9. Jaroslav DUnajsky 24-Apr-2001
  10. - used code brom svcext.dll to write new metabase extension that gets started
  11. - during iisadmin startup and starts SSL CONFIG PROVIDER
  12. --*/
  13. #define INITGUID
  14. #include "precomp.hxx"
  15. //
  16. // Globals
  17. //
  18. ULONG g_dwRefCount;
  19. CAdmExtSrvFactory g_aesFactory;
  20. DECLARE_DEBUG_PRINTS_OBJECT();
  21. DECLARE_DEBUG_VARIABLE();
  22. DECLARE_PLATFORM_TYPE();
  23. #define SZ_EXTENSION_DESCRIPTION TEXT("SSL CONFIG PROVIDER - IISAdmin extension")
  24. #define SZ_DLLNAME TEXT("sslcfg.dll")
  25. CAdmExtSrvFactory::CAdmExtSrvFactory()
  26. :m_admextObject()
  27. {
  28. m_dwRefCount=0;
  29. g_dwRefCount = 0;
  30. //
  31. // Addref object, so refcount doesn't go to 0 if all clients release.
  32. //
  33. m_admextObject.AddRef();
  34. }
  35. CAdmExtSrvFactory::~CAdmExtSrvFactory()
  36. {
  37. m_admextObject.Release();
  38. }
  39. HRESULT
  40. CAdmExtSrvFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void ** ppObject)
  41. {
  42. if (pUnkOuter != NULL) {
  43. return CLASS_E_NOAGGREGATION;
  44. }
  45. if (FAILED(m_admextObject.QueryInterface(riid, ppObject))) {
  46. return E_NOINTERFACE;
  47. }
  48. return NO_ERROR;
  49. }
  50. HRESULT
  51. CAdmExtSrvFactory::LockServer(BOOL fLock)
  52. {
  53. if (fLock) {
  54. InterlockedIncrement((long *)&g_dwRefCount);
  55. }
  56. else {
  57. InterlockedDecrement((long *)&g_dwRefCount);
  58. }
  59. return NO_ERROR;
  60. }
  61. HRESULT
  62. CAdmExtSrvFactory::QueryInterface(REFIID riid, void **ppObject)
  63. {
  64. if (riid==IID_IUnknown || riid == IID_IClassFactory) {
  65. *ppObject = (IClassFactory *) this;
  66. }
  67. else {
  68. *ppObject = NULL;
  69. return E_NOINTERFACE;
  70. }
  71. AddRef();
  72. return NO_ERROR;
  73. }
  74. ULONG
  75. CAdmExtSrvFactory::AddRef()
  76. {
  77. DWORD dwRefCount;
  78. InterlockedIncrement((long *)&g_dwRefCount);
  79. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  80. return dwRefCount;
  81. }
  82. ULONG
  83. CAdmExtSrvFactory::Release()
  84. {
  85. DWORD dwRefCount;
  86. InterlockedDecrement((long *)&g_dwRefCount);
  87. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  88. //
  89. // There must only be one copy of this. So keep the first one around regardless.
  90. //
  91. // if (dwRefCount == 0) {
  92. // delete this;
  93. // }
  94. return dwRefCount;
  95. }
  96. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppObject)
  97. {
  98. if (rclsid != CLSID_SSLCONFIGPROV) {
  99. return CLASS_E_CLASSNOTAVAILABLE;
  100. }
  101. if (FAILED(g_aesFactory.QueryInterface(riid, ppObject))) {
  102. *ppObject = NULL;
  103. return E_INVALIDARG;
  104. }
  105. return NO_ERROR;
  106. }
  107. HRESULT _stdcall DllCanUnloadNow() {
  108. if (g_dwRefCount) {
  109. return S_FALSE;
  110. }
  111. else {
  112. return S_OK;
  113. }
  114. }
  115. STDAPI DllRegisterServer(void)
  116. {
  117. HKEY hKeyCLSID, hKeyInproc32;
  118. DWORD dwDisposition;
  119. HMODULE hModule;
  120. DWORD dwReturn = ERROR_SUCCESS;
  121. dwReturn = RegCreateKeyEx(HKEY_CLASSES_ROOT,
  122. TEXT("CLSID\\") SZ_CLSID_SSLCONFIGPROV,
  123. NULL,
  124. TEXT(""),
  125. REG_OPTION_NON_VOLATILE,
  126. KEY_ALL_ACCESS,
  127. NULL,
  128. &hKeyCLSID,
  129. &dwDisposition);
  130. if (dwReturn == ERROR_SUCCESS) {
  131. dwReturn = RegSetValueEx(hKeyCLSID,
  132. TEXT(""),
  133. NULL,
  134. REG_SZ,
  135. (BYTE*) SZ_EXTENSION_DESCRIPTION ,
  136. sizeof(SZ_EXTENSION_DESCRIPTION ));
  137. if (dwReturn == ERROR_SUCCESS) {
  138. dwReturn = RegCreateKeyEx(hKeyCLSID,
  139. TEXT("InprocServer32"),
  140. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  141. &hKeyInproc32, &dwDisposition);
  142. if (dwReturn == ERROR_SUCCESS) {
  143. hModule=GetModuleHandle(SZ_DLLNAME);
  144. if (!hModule) {
  145. dwReturn = GetLastError();
  146. }
  147. else {
  148. TCHAR szName[MAX_PATH+1];
  149. if (GetModuleFileName(hModule,
  150. szName,
  151. sizeof(szName)/sizeof(szName[0])) == NULL) {
  152. dwReturn = GetLastError();
  153. }
  154. else {
  155. dwReturn = RegSetValueEx(hKeyInproc32,
  156. TEXT(""),
  157. NULL,
  158. REG_SZ,
  159. (BYTE*) szName,
  160. sizeof(TCHAR)*(lstrlen(szName)+1));
  161. if (dwReturn == ERROR_SUCCESS) {
  162. dwReturn = RegSetValueEx(hKeyInproc32,
  163. TEXT("ThreadingModel"),
  164. NULL,
  165. REG_SZ,
  166. (BYTE*) TEXT("Both"),
  167. sizeof(TEXT("Both")));
  168. }
  169. }
  170. }
  171. RegCloseKey(hKeyInproc32);
  172. }
  173. }
  174. RegCloseKey(hKeyCLSID);
  175. }
  176. if (dwReturn == ERROR_SUCCESS) {
  177. dwReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  178. IISADMIN_EXTENSIONS_REG_KEY
  179. TEXT("\\") SZ_CLSID_SSLCONFIGPROV,
  180. NULL,
  181. TEXT(""),
  182. REG_OPTION_NON_VOLATILE,
  183. KEY_ALL_ACCESS,
  184. NULL,
  185. &hKeyCLSID,
  186. &dwDisposition);
  187. if (dwReturn == ERROR_SUCCESS) {
  188. RegCloseKey(hKeyCLSID);
  189. }
  190. }
  191. return HRESULT_FROM_WIN32(dwReturn);
  192. }
  193. STDAPI DllUnregisterServer(void)
  194. {
  195. DWORD dwReturn = ERROR_SUCCESS;
  196. DWORD dwTemp;
  197. dwTemp = RegDeleteKey(HKEY_CLASSES_ROOT,
  198. TEXT("CLSID\\") SZ_CLSID_SSLCONFIGPROV TEXT("\\InprocServer32"));
  199. if (dwTemp != ERROR_SUCCESS) {
  200. dwReturn = dwTemp;
  201. }
  202. dwTemp = RegDeleteKey(HKEY_CLASSES_ROOT,
  203. TEXT("CLSID\\") SZ_CLSID_SSLCONFIGPROV);
  204. if (dwTemp != ERROR_SUCCESS) {
  205. dwReturn = dwTemp;
  206. }
  207. dwTemp = RegDeleteKey(HKEY_LOCAL_MACHINE,
  208. IISADMIN_EXTENSIONS_REG_KEY
  209. TEXT("\\") SZ_CLSID_SSLCONFIGPROV );
  210. if (dwTemp != ERROR_SUCCESS) {
  211. dwReturn = dwTemp;
  212. }
  213. return HRESULT_FROM_WIN32(dwReturn);
  214. }