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.

219 lines
6.4 KiB

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