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.

244 lines
7.0 KiB

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