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.

277 lines
7.3 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 <admex.h>
  11. #include <bootimp.hxx>
  12. CAdmExt::CAdmExt()
  13. {
  14. }
  15. CAdmExt::~CAdmExt()
  16. {
  17. }
  18. HRESULT
  19. CAdmExt::QueryInterface(REFIID riid, void **ppObject) {
  20. if (riid==IID_IUnknown || riid==IID_IADMEXT) {
  21. *ppObject = (IADMEXT *) this;
  22. }
  23. else {
  24. return E_NOINTERFACE;
  25. }
  26. AddRef();
  27. return NO_ERROR;
  28. }
  29. ULONG
  30. CAdmExt::AddRef()
  31. {
  32. DWORD dwRefCount;
  33. InterlockedIncrement((long *)&g_dwRefCount);
  34. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  35. return dwRefCount;
  36. }
  37. ULONG
  38. CAdmExt::Release()
  39. {
  40. DWORD dwRefCount;
  41. InterlockedDecrement((long *)&g_dwRefCount);
  42. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  43. //
  44. // This is now a member of class factory.
  45. // It is not dynamically allocated, so don't delete it.
  46. //
  47. /*
  48. if (dwRefCount == 0) {
  49. delete this;
  50. return 0;
  51. }
  52. */
  53. return dwRefCount;
  54. }
  55. HRESULT STDMETHODCALLTYPE
  56. CAdmExt::Initialize(void)
  57. {
  58. InitComAdmindata( FALSE );
  59. return ERROR_SUCCESS;
  60. }
  61. HRESULT STDMETHODCALLTYPE
  62. CAdmExt::EnumDcomCLSIDs(
  63. /* [size_is][out] */ CLSID *pclsid,
  64. /* [in] */ DWORD dwEnumIIDIndex)
  65. {
  66. if ( dwEnumIIDIndex == 0 )
  67. {
  68. *pclsid = CLSID_MSCryptoAdmEx;
  69. return ERROR_SUCCESS;
  70. }
  71. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  72. }
  73. HRESULT STDMETHODCALLTYPE
  74. CAdmExt::Terminate(void)
  75. {
  76. TerminateComAdmindata();
  77. return ERROR_SUCCESS;
  78. }
  79. CAdmExtSrvFactory::CAdmExtSrvFactory()
  80. :m_admextObject()
  81. {
  82. m_dwRefCount=0;
  83. g_dwRefCount = 0;
  84. //
  85. // Addref object, so refcount doesn't go to 0 if all clients release.
  86. //
  87. m_admextObject.AddRef();
  88. }
  89. CAdmExtSrvFactory::~CAdmExtSrvFactory()
  90. {
  91. m_admextObject.Release();
  92. }
  93. HRESULT
  94. CAdmExtSrvFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void ** ppObject)
  95. {
  96. if (pUnkOuter != NULL) {
  97. return CLASS_E_NOAGGREGATION;
  98. }
  99. if (FAILED(m_admextObject.QueryInterface(riid, ppObject))) {
  100. return E_NOINTERFACE;
  101. }
  102. return NO_ERROR;
  103. }
  104. HRESULT
  105. CAdmExtSrvFactory::LockServer(BOOL fLock)
  106. {
  107. if (fLock) {
  108. InterlockedIncrement((long *)&g_dwRefCount);
  109. }
  110. else {
  111. InterlockedDecrement((long *)&g_dwRefCount);
  112. }
  113. return NO_ERROR;
  114. }
  115. HRESULT
  116. CAdmExtSrvFactory::QueryInterface(REFIID riid, void **ppObject)
  117. {
  118. if (riid==IID_IUnknown || riid == IID_IClassFactory) {
  119. *ppObject = (IClassFactory *) this;
  120. }
  121. else {
  122. return E_NOINTERFACE;
  123. }
  124. AddRef();
  125. return NO_ERROR;
  126. }
  127. ULONG
  128. CAdmExtSrvFactory::AddRef()
  129. {
  130. DWORD dwRefCount;
  131. InterlockedIncrement((long *)&g_dwRefCount);
  132. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  133. return dwRefCount;
  134. }
  135. ULONG
  136. CAdmExtSrvFactory::Release()
  137. {
  138. DWORD dwRefCount;
  139. InterlockedDecrement((long *)&g_dwRefCount);
  140. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  141. //
  142. // There must only be one copy of this. So keep the first one around regardless.
  143. //
  144. // if (dwRefCount == 0) {
  145. // delete this;
  146. // }
  147. return dwRefCount;
  148. }
  149. STDAPI BootDllRegisterServer(void)
  150. {
  151. HKEY hKeyCLSID, hKeyInproc32;
  152. DWORD dwDisposition;
  153. HMODULE hModule;
  154. DWORD dwReturn = ERROR_SUCCESS;
  155. dwReturn = RegCreateKeyEx(HKEY_CLASSES_ROOT,
  156. TEXT("CLSID\\{c4376b00-f87b-11d0-a6a6-00a0c922e752}"),
  157. NULL,
  158. TEXT(""),
  159. REG_OPTION_NON_VOLATILE,
  160. KEY_ALL_ACCESS,
  161. NULL,
  162. &hKeyCLSID,
  163. &dwDisposition);
  164. if (dwReturn == ERROR_SUCCESS) {
  165. dwReturn = RegSetValueEx(hKeyCLSID,
  166. TEXT(""),
  167. NULL,
  168. REG_SZ,
  169. (BYTE*) TEXT("IISAdmin Security Extension"),
  170. sizeof(TEXT("IISAdmin Security Extension")));
  171. if (dwReturn == ERROR_SUCCESS) {
  172. dwReturn = RegCreateKeyEx(hKeyCLSID,
  173. "InprocServer32",
  174. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  175. &hKeyInproc32, &dwDisposition);
  176. if (dwReturn == ERROR_SUCCESS) {
  177. hModule=GetModuleHandle(TEXT("ADMEXS.DLL"));
  178. if (!hModule) {
  179. dwReturn = GetLastError();
  180. }
  181. else {
  182. TCHAR szName[MAX_PATH+1];
  183. if (GetModuleFileName(hModule,
  184. szName,
  185. sizeof(szName)) == NULL) {
  186. dwReturn = GetLastError();
  187. }
  188. else {
  189. dwReturn = RegSetValueEx(hKeyInproc32,
  190. TEXT(""),
  191. NULL,
  192. REG_SZ,
  193. (BYTE*) szName,
  194. sizeof(TCHAR)*(lstrlen(szName)+1));
  195. if (dwReturn == ERROR_SUCCESS) {
  196. dwReturn = RegSetValueEx(hKeyInproc32,
  197. TEXT("ThreadingModel"),
  198. NULL,
  199. REG_SZ,
  200. (BYTE*) TEXT("Both"),
  201. sizeof(TEXT("Both")));
  202. }
  203. }
  204. }
  205. RegCloseKey(hKeyInproc32);
  206. }
  207. }
  208. RegCloseKey(hKeyCLSID);
  209. }
  210. if (dwReturn == ERROR_SUCCESS) {
  211. dwReturn = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  212. IISADMIN_EXTENSIONS_REG_KEY
  213. TEXT("\\{c4376b00-f87b-11d0-a6a6-00a0c922e752}"),
  214. NULL,
  215. TEXT(""),
  216. REG_OPTION_NON_VOLATILE,
  217. KEY_ALL_ACCESS,
  218. NULL,
  219. &hKeyCLSID,
  220. &dwDisposition);
  221. if (dwReturn == ERROR_SUCCESS) {
  222. RegCloseKey(hKeyCLSID);
  223. }
  224. }
  225. return HRESULT_FROM_WIN32(dwReturn);
  226. }
  227. STDAPI BootDllUnregisterServer(void)
  228. {
  229. DWORD dwReturn = ERROR_SUCCESS;
  230. DWORD dwTemp;
  231. dwTemp = RegDeleteKey(HKEY_CLASSES_ROOT,
  232. TEXT("CLSID\\{c4376b00-f87b-11d0-a6a6-00a0c922e752}\\InprocServer32"));
  233. if (dwTemp != ERROR_SUCCESS) {
  234. dwReturn = dwTemp;
  235. }
  236. dwReturn = RegDeleteKey(HKEY_CLASSES_ROOT,
  237. TEXT("CLSID\\{c4376b00-f87b-11d0-a6a6-00a0c922e752}"));
  238. if (dwTemp != ERROR_SUCCESS) {
  239. dwReturn = dwTemp;
  240. }
  241. dwTemp = RegDeleteKey(HKEY_LOCAL_MACHINE,
  242. IISADMIN_EXTENSIONS_REG_KEY
  243. TEXT("\\{c4376b00-f87b-11d0-a6a6-00a0c922e752}"));
  244. if (dwTemp != ERROR_SUCCESS) {
  245. dwReturn = dwTemp;
  246. }
  247. return HRESULT_FROM_WIN32(dwReturn);
  248. }