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.

530 lines
15 KiB

  1. extern "C" {
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. }
  6. #include <dbgutil.h>
  7. #include <ole2.h>
  8. #include <windows.h>
  9. #define SECURITY_WIN32
  10. #include <sspi.h>
  11. #include <admex.h>
  12. #include "comobj.hxx"
  13. #include "bootimp.hxx"
  14. #include <stdio.h>
  15. extern ULONG g_dwRefCount;
  16. CAdmExtSrvFactory g_aesFactory;
  17. CADMEXCOMSrvFactory::CADMEXCOMSrvFactory()
  18. {
  19. m_dwRefCount=0;
  20. }
  21. CADMEXCOMSrvFactory::~CADMEXCOMSrvFactory()
  22. {
  23. }
  24. HRESULT
  25. CADMEXCOMSrvFactory::CreateInstance(
  26. IUnknown *pUnkOuter,
  27. REFIID riid,
  28. void ** ppObject
  29. )
  30. {
  31. DBGPRINTF( (DBG_CONTEXT, "[CADMCOMSrvFactory::CreateInstance]\n"));
  32. HRESULT hresReturn = E_NOINTERFACE;
  33. if (pUnkOuter != NULL) {
  34. return CLASS_E_NOAGGREGATION;
  35. }
  36. if ( IID_IUnknown==riid ||
  37. IID_IMSAdminReplication==riid ||
  38. IID_IMSAdminCryptoCapabilities==riid )
  39. {
  40. CADMEXCOM *padmcom = new CADMEXCOM();
  41. if( padmcom == NULL )
  42. {
  43. hresReturn = E_OUTOFMEMORY;
  44. }
  45. else
  46. {
  47. hresReturn = padmcom->QueryInterface(riid, ppObject);
  48. if( FAILED(hresReturn) )
  49. {
  50. DBGPRINTF( (DBG_CONTEXT, "[CADMEXCOMSrvFactory::CreateInstance] no I/F\n"));
  51. delete padmcom;
  52. }
  53. }
  54. }
  55. return hresReturn;
  56. }
  57. HRESULT
  58. CADMEXCOMSrvFactory::LockServer(BOOL fLock)
  59. {
  60. if (fLock) {
  61. InterlockedIncrement((long *)&g_dwRefCount);
  62. }
  63. else {
  64. InterlockedDecrement((long *)&g_dwRefCount);
  65. }
  66. return NO_ERROR;
  67. }
  68. HRESULT
  69. CADMEXCOMSrvFactory::QueryInterface(
  70. REFIID riid,
  71. void **ppObject
  72. )
  73. {
  74. if (riid==IID_IUnknown || riid == IID_IClassFactory) {
  75. *ppObject = (IClassFactory *) this;
  76. }
  77. else {
  78. return E_NOINTERFACE;
  79. }
  80. AddRef();
  81. return NO_ERROR;
  82. }
  83. ULONG
  84. CADMEXCOMSrvFactory::AddRef(
  85. )
  86. {
  87. DWORD dwRefCount;
  88. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  89. return dwRefCount;
  90. }
  91. ULONG
  92. CADMEXCOMSrvFactory::Release()
  93. {
  94. DWORD dwRefCount;
  95. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  96. if (dwRefCount == 0) {
  97. delete this;
  98. }
  99. return dwRefCount;
  100. }
  101. STDAPI DllGetClassObject(
  102. REFCLSID rclsid,
  103. REFIID riid,
  104. void** ppObject)
  105. {
  106. if ( rclsid == CLSID_MSCryptoAdmEx ) {
  107. CADMEXCOMSrvFactory *pFactory = new CADMEXCOMSrvFactory;
  108. if (FAILED(pFactory->QueryInterface(riid, ppObject))) {
  109. delete pFactory;
  110. *ppObject = NULL;
  111. DBGPRINTF( (DBG_CONTEXT, "[CADMEXCOMSrvFactory::DllGetClassObject] no I/F for CLSID_MSCryptoAdmEx\n" ) );
  112. return E_INVALIDARG;
  113. }
  114. return NO_ERROR;
  115. }
  116. else if ( rclsid == CLSID_ADMEXT) {
  117. if (FAILED(g_aesFactory.QueryInterface(riid, ppObject))) {
  118. *ppObject = NULL;
  119. DBGPRINTF( (DBG_CONTEXT, "[CADMEXCOMSrvFactory::DllGetClassObject] no I/F for CLSID_ADMEXT\n" ) );
  120. return E_INVALIDARG;
  121. }
  122. return NO_ERROR;
  123. }
  124. else {
  125. DBGPRINTF( (DBG_CONTEXT, "[CADMEXCOMSrvFactory::DllGetClassObject] bad class\n" ) );
  126. return CLASS_E_CLASSNOTAVAILABLE;
  127. }
  128. }
  129. HRESULT _stdcall DllCanUnloadNow(
  130. )
  131. {
  132. if (g_dwRefCount) {
  133. return S_FALSE;
  134. }
  135. else {
  136. return S_OK;
  137. }
  138. }
  139. STDAPI DllRegisterServer(
  140. )
  141. {
  142. HKEY hKeyCLSID, hKeyInproc32;
  143. HKEY hKeyIF, hKeyStub32;
  144. HKEY hKeyAppExe, hKeyAppID, hKeyTemp;
  145. DWORD dwDisposition;
  146. BOOL bIsWin95 = FALSE;
  147. char pszName[MAX_PATH+1 + sizeof("inetinfo.exe -e iisadmin")];
  148. //
  149. // if win95, then don't register as service
  150. //
  151. if ( IISGetPlatformType() == PtWindows95 ) {
  152. bIsWin95 = TRUE;
  153. }
  154. //
  155. // register AppExe
  156. //
  157. HRESULT hr;
  158. if (bIsWin95) {
  159. HMODULE hModule=GetModuleHandle(TEXT("ADMEXS.DLL"));
  160. if (!hModule) {
  161. return E_UNEXPECTED;
  162. }
  163. WCHAR wchName[MAX_PATH + 1];
  164. if (GetModuleFileName(hModule, pszName, sizeof(pszName))==0) {
  165. return E_UNEXPECTED;
  166. }
  167. int i;
  168. //
  169. // Set pszName to the command to start the web server
  170. //
  171. for (i = strlen(pszName) -1; (i >= 0) && (pszName[i] != '/') & (pszName[i] != '\\'); i--) {
  172. }
  173. pszName[i + 1] = '\0';
  174. strcat(pszName, "inetinfo.exe -e iisadmin");
  175. }
  176. //
  177. // register CLSID
  178. //
  179. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  180. TEXT("CLSID\\{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}"),
  181. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  182. &hKeyCLSID, &dwDisposition)!=ERROR_SUCCESS) {
  183. return E_UNEXPECTED;
  184. }
  185. if (RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("IIS Admin Crypto Extension"), sizeof(TEXT("IIS Admin Crypto Extension")))!=ERROR_SUCCESS) {
  186. RegCloseKey(hKeyCLSID);
  187. return E_UNEXPECTED;
  188. }
  189. if (RegSetValueEx(hKeyCLSID, TEXT("AppID"), NULL, REG_SZ, (BYTE*) TEXT("{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}"), sizeof(TEXT("{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}")))!=ERROR_SUCCESS) {
  190. RegCloseKey(hKeyCLSID);
  191. return E_UNEXPECTED;
  192. }
  193. if (bIsWin95) {
  194. if (RegCreateKeyEx(hKeyCLSID,
  195. TEXT("LocalServer32"),
  196. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  197. &hKeyTemp, &dwDisposition)!=ERROR_SUCCESS) {
  198. RegCloseKey(hKeyCLSID);
  199. return E_UNEXPECTED;
  200. }
  201. if (RegSetValueEx(hKeyTemp, TEXT(""), NULL, REG_SZ, (BYTE*) pszName, strlen(pszName) + 1)!=ERROR_SUCCESS) {
  202. RegCloseKey(hKeyTemp);
  203. RegCloseKey(hKeyCLSID);
  204. return E_UNEXPECTED;
  205. }
  206. RegCloseKey(hKeyTemp);
  207. }
  208. else {
  209. if (RegSetValueEx(hKeyCLSID, TEXT("LocalService"), NULL, REG_SZ, (BYTE*) TEXT("IISADMIN"), sizeof(TEXT("IISADMIN")))!=ERROR_SUCCESS) {
  210. RegCloseKey(hKeyCLSID);
  211. return E_UNEXPECTED;
  212. }
  213. }
  214. RegCloseKey(hKeyCLSID);
  215. //
  216. // AppID
  217. //
  218. //
  219. // register CLSID
  220. //
  221. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  222. TEXT("AppID\\{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}"),
  223. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  224. &hKeyCLSID, &dwDisposition)!=ERROR_SUCCESS) {
  225. return E_UNEXPECTED;
  226. }
  227. if (RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("IIS Admin Crypto Extension"), sizeof(TEXT("IIS Admin Crypto Extension")))!=ERROR_SUCCESS) {
  228. RegCloseKey(hKeyCLSID);
  229. return E_UNEXPECTED;
  230. }
  231. if (bIsWin95) {
  232. if (RegCreateKeyEx(hKeyCLSID,
  233. TEXT("LocalServer32"),
  234. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  235. &hKeyTemp, &dwDisposition)!=ERROR_SUCCESS) {
  236. RegCloseKey(hKeyCLSID);
  237. return E_UNEXPECTED;
  238. }
  239. if (RegSetValueEx(hKeyTemp, TEXT(""), NULL, REG_SZ, (BYTE*) pszName, strlen(pszName) + 1)!=ERROR_SUCCESS) {
  240. RegCloseKey(hKeyTemp);
  241. RegCloseKey(hKeyCLSID);
  242. return E_UNEXPECTED;
  243. }
  244. RegCloseKey(hKeyTemp);
  245. }
  246. else {
  247. if (RegSetValueEx(hKeyCLSID, TEXT("LocalService"), NULL, REG_SZ, (BYTE*) TEXT("IISADMIN"), sizeof(TEXT("IISADMIN")))!=ERROR_SUCCESS) {
  248. RegCloseKey(hKeyCLSID);
  249. return E_UNEXPECTED;
  250. }
  251. }
  252. RegCloseKey(hKeyCLSID);
  253. //
  254. // Main Interfaces
  255. //
  256. //
  257. // ANSI Main Interface
  258. //
  259. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  260. TEXT("CLSID\\{c804d980-ebec-11d0-a6a0-00a0c922e752}"),
  261. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  262. &hKeyCLSID, &dwDisposition)!=ERROR_SUCCESS) {
  263. return E_UNEXPECTED;
  264. }
  265. if (RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("PSFactoryBuffer"), sizeof(TEXT("PSFactoryBuffer")))!=ERROR_SUCCESS) {
  266. RegCloseKey(hKeyCLSID);
  267. return E_UNEXPECTED;
  268. }
  269. if (RegCreateKeyEx(hKeyCLSID,
  270. "InprocServer32",
  271. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  272. &hKeyInproc32, &dwDisposition)!=ERROR_SUCCESS) {
  273. RegCloseKey(hKeyCLSID);
  274. return E_UNEXPECTED;
  275. }
  276. if (RegSetValueEx(hKeyInproc32, TEXT(""), NULL, REG_SZ, (BYTE*) "ADMXPROX.DLL", sizeof(TEXT("ADMPROX.DLL")))!=ERROR_SUCCESS) {
  277. RegCloseKey(hKeyInproc32);
  278. RegCloseKey(hKeyCLSID);
  279. return E_UNEXPECTED;
  280. }
  281. if (RegSetValueEx(hKeyInproc32, TEXT("ThreadingModel"), NULL, REG_SZ, (BYTE*) "Both", sizeof("Both")-1 )!=ERROR_SUCCESS) {
  282. RegCloseKey(hKeyInproc32);
  283. RegCloseKey(hKeyCLSID);
  284. return E_UNEXPECTED;
  285. }
  286. RegCloseKey(hKeyInproc32);
  287. RegCloseKey(hKeyCLSID);
  288. //
  289. // Crypto Main Interface
  290. //
  291. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  292. TEXT("CLSID\\{78b64540-f26d-11d0-a6a3-00a0c922e752}"),
  293. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  294. &hKeyCLSID, &dwDisposition)!=ERROR_SUCCESS) {
  295. return E_UNEXPECTED;
  296. }
  297. if (RegSetValueEx(hKeyCLSID, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("PSFactoryBuffer"), sizeof(TEXT("PSFactoryBuffer")))!=ERROR_SUCCESS) {
  298. RegCloseKey(hKeyCLSID);
  299. return E_UNEXPECTED;
  300. }
  301. if (RegCreateKeyEx(hKeyCLSID,
  302. "InprocServer32",
  303. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  304. &hKeyInproc32, &dwDisposition)!=ERROR_SUCCESS) {
  305. RegCloseKey(hKeyCLSID);
  306. return E_UNEXPECTED;
  307. }
  308. if (RegSetValueEx(hKeyInproc32, TEXT(""), NULL, REG_SZ, (BYTE*) "ADMXPROX.DLL", sizeof(TEXT("ADMPROX.DLL")))!=ERROR_SUCCESS) {
  309. RegCloseKey(hKeyInproc32);
  310. RegCloseKey(hKeyCLSID);
  311. return E_UNEXPECTED;
  312. }
  313. if (RegSetValueEx(hKeyInproc32, TEXT("ThreadingModel"), NULL, REG_SZ, (BYTE*) "Both", sizeof("Both")-1 )!=ERROR_SUCCESS) {
  314. RegCloseKey(hKeyInproc32);
  315. RegCloseKey(hKeyCLSID);
  316. return E_UNEXPECTED;
  317. }
  318. RegCloseKey(hKeyInproc32);
  319. RegCloseKey(hKeyCLSID);
  320. //
  321. // register Interfaces
  322. //
  323. //
  324. // ANSI Main Interface
  325. //
  326. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  327. TEXT("Interface\\{c804d980-ebec-11d0-a6a0-00a0c922e752}"),
  328. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  329. &hKeyIF, &dwDisposition)!=ERROR_SUCCESS) {
  330. return E_UNEXPECTED;
  331. }
  332. if (RegSetValueEx(hKeyIF, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("ADMEX"), sizeof(TEXT("ADMEX")))!=ERROR_SUCCESS) {
  333. RegCloseKey(hKeyIF);
  334. return E_UNEXPECTED;
  335. }
  336. if (RegCreateKeyEx(hKeyIF,
  337. "ProxyStubClsid32",
  338. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  339. &hKeyStub32, &dwDisposition)!=ERROR_SUCCESS) {
  340. RegCloseKey(hKeyIF);
  341. return E_UNEXPECTED;
  342. }
  343. if (RegSetValueEx(hKeyStub32, TEXT(""), NULL, REG_SZ, (BYTE*)"{c804d980-ebec-11d0-a6a0-00a0c922e752}", sizeof("{CBA424F0-483A-11D0-9D2A-00A0C922E703}") )!=ERROR_SUCCESS) {
  344. RegCloseKey(hKeyStub32);
  345. RegCloseKey(hKeyIF);
  346. return E_UNEXPECTED;
  347. }
  348. RegCloseKey(hKeyStub32);
  349. RegCloseKey(hKeyIF);
  350. //
  351. // Crypto Main Interface
  352. //
  353. if (RegCreateKeyEx(HKEY_CLASSES_ROOT,
  354. TEXT("Interface\\{78b64540-f26d-11d0-a6a3-00a0c922e752}"),
  355. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  356. &hKeyIF, &dwDisposition)!=ERROR_SUCCESS) {
  357. return E_UNEXPECTED;
  358. }
  359. if (RegSetValueEx(hKeyIF, TEXT(""), NULL, REG_SZ, (BYTE*) TEXT("ADMEX"), sizeof(TEXT("ADMEX")))!=ERROR_SUCCESS) {
  360. RegCloseKey(hKeyIF);
  361. return E_UNEXPECTED;
  362. }
  363. if (RegCreateKeyEx(hKeyIF,
  364. "ProxyStubClsid32",
  365. NULL, TEXT(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
  366. &hKeyStub32, &dwDisposition)!=ERROR_SUCCESS) {
  367. RegCloseKey(hKeyIF);
  368. return E_UNEXPECTED;
  369. }
  370. if (RegSetValueEx(hKeyStub32, TEXT(""), NULL, REG_SZ, (BYTE*)"{78b64540-f26d-11d0-a6a3-00a0c922e752}", sizeof("{78b64540-f26d-11d0-a6a3-00a0c922e752}") )!=ERROR_SUCCESS) {
  371. RegCloseKey(hKeyStub32);
  372. RegCloseKey(hKeyIF);
  373. return E_UNEXPECTED;
  374. }
  375. RegCloseKey(hKeyStub32);
  376. RegCloseKey(hKeyIF);
  377. return BootDllRegisterServer();;
  378. }
  379. STDAPI DllUnregisterServer(void) {
  380. BOOL bIsWin95 = FALSE;
  381. //
  382. // if win95, then don't register as service
  383. //
  384. if ( IISGetPlatformType() == PtWindows95 ) {
  385. bIsWin95 = TRUE;
  386. }
  387. //
  388. // register AppID
  389. //
  390. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("AppID\\{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}"));
  391. //
  392. // register CLSID
  393. //
  394. if (bIsWin95) {
  395. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}\\LocalServer32"));
  396. }
  397. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{9f0bd3a0-ec01-11d0-a6a0-00a0c922e752}"));
  398. //
  399. // Main Interfaces
  400. //
  401. //
  402. // Crypto Interface
  403. //
  404. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{78b64540-f26d-11d0-a6a3-00a0c922e752}\\InprocServer32"));
  405. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{78b64540-f26d-11d0-a6a3-00a0c922e752}"));
  406. //
  407. // Replication Interface
  408. //
  409. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{c804d980-ebec-11d0-a6a0-00a0c922e752}\\InprocServer32"));
  410. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("CLSID\\{c804d980-ebec-11d0-a6a0-00a0c922e752}"));
  411. //
  412. // deregister Interfaces
  413. //
  414. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Interface\\{78b64540-f26d-11d0-a6a3-00a0c922e752}\\ProxyStubClsid32"));
  415. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Interface\\{78b64540-f26d-11d0-a6a3-00a0c922e752}"));
  416. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Interface\\{c804d980-ebec-11d0-a6a0-00a0c922e752}\\ProxyStubClsid32"));
  417. RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Interface\\{c804d980-ebec-11d0-a6a0-00a0c922e752}"));
  418. return BootDllUnregisterServer();
  419. }