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.

467 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name :
  4. clapi.cpp
  5. Abstract:
  6. CLAPI - Common logging layer
  7. Author:
  8. Terence Kwan ( terryk ) 18-Sep-1996
  9. Project:
  10. IIS Logging 3.0
  11. --*/
  12. #include "precomp.hxx"
  13. #include "comlog.hxx"
  14. #include <inetsvcs.h>
  15. DECLARE_PLATFORM_TYPE();
  16. // by exporting DllRegisterServer, you can use regsvr.exe
  17. #define CLAPI_PROG_ID "CLAPI.INETLOGINFORMATION"
  18. #define CLAPI_CLSID_KEY_NAME "CLSID"
  19. #define CLAPI_INPROC_SERVER "InProcServer32"
  20. #define CLAPI_CLSID "{A1F89741-F619-11CF-BC0F-00AA006111E0}"
  21. /*
  22. #define LOGPUBLIC_PROG_ID "MSIISLOG.MSLOGPUBLIC"
  23. #define LOGPUBLIC_CLSID "{FB583AC4-C361-11d1-8BA4-080009DCC2FA}"
  24. */
  25. extern "C" {
  26. BOOL
  27. WINAPI
  28. DLLEntry(
  29. HINSTANCE hDll,
  30. DWORD dwReason,
  31. LPVOID lpvReserved
  32. );
  33. }
  34. BOOL
  35. WINAPI
  36. DLLEntry(
  37. HINSTANCE hDll,
  38. DWORD dwReason,
  39. LPVOID
  40. )
  41. /*++
  42. Routine Description:
  43. DLL entrypoint.
  44. Arguments:
  45. hDLL - Instance handle.
  46. Reason - The reason the entrypoint was called.
  47. DLL_PROCESS_ATTACH
  48. DLL_PROCESS_DETACH
  49. DLL_THREAD_ATTACH
  50. DLL_THREAD_DETACH
  51. Reserved - Reserved.
  52. Return Value:
  53. BOOL - TRUE if the action succeeds.
  54. --*/
  55. {
  56. BOOL bReturn = TRUE;
  57. switch ( dwReason ) {
  58. case DLL_PROCESS_ATTACH:
  59. DisableThreadLibraryCalls(hDll);
  60. break;
  61. case DLL_PROCESS_DETACH:
  62. break;
  63. default:
  64. break;
  65. }
  66. return bReturn;
  67. } // DllEntry
  68. STDAPI
  69. DllRegisterServer(void)
  70. /*++
  71. Routine Description:
  72. MFC register server function
  73. Arguments:
  74. Return Value:
  75. --*/
  76. {
  77. LONG ret = E_UNEXPECTED;
  78. HKEY hProgID = NULL;
  79. HKEY hCLSID = NULL;
  80. HKEY hClapi = NULL;
  81. HKEY hKey;
  82. HMODULE hModule;
  83. CHAR szName[MAX_PATH+1];
  84. //
  85. // CLAPI.INETLOGINFORMATION
  86. //
  87. hProgID = CreateKey(
  88. HKEY_CLASSES_ROOT,
  89. CLAPI_PROG_ID,
  90. CLAPI_PROG_ID);
  91. if ( hProgID == NULL ) {
  92. IIS_PRINTF((buff,"Cannot set value for key %s\n", CLAPI_PROG_ID));
  93. goto exit;
  94. }
  95. hCLSID = CreateKey(hProgID,
  96. CLAPI_CLSID_KEY_NAME,
  97. CLAPI_CLSID);
  98. if ( hCLSID == NULL ) {
  99. IIS_PRINTF((buff,"Cannot set value %s for key %s\n",
  100. CLAPI_CLSID_KEY_NAME, CLAPI_CLSID));
  101. goto exit;
  102. }
  103. RegCloseKey(hCLSID);
  104. hCLSID = NULL;
  105. //
  106. // CLSID
  107. //
  108. if ( RegOpenKeyExA(HKEY_CLASSES_ROOT,
  109. CLAPI_CLSID_KEY_NAME,
  110. 0,
  111. KEY_ALL_ACCESS,
  112. &hCLSID) != ERROR_SUCCESS ) {
  113. IIS_PRINTF((buff,"Cannot open CLSID key\n"));
  114. goto exit;
  115. }
  116. hClapi = CreateKey(hCLSID,CLAPI_CLSID,CLAPI_PROG_ID);
  117. if ( hClapi == NULL ) {
  118. goto exit;
  119. }
  120. //
  121. // InProcServer32
  122. //
  123. hModule=GetModuleHandleA("iscomlog.dll");
  124. if (hModule == NULL) {
  125. IIS_PRINTF((buff,"GetModuleHandle failed with %d\n",GetLastError()));
  126. goto exit;
  127. }
  128. if (GetModuleFileNameA(hModule, szName, sizeof(szName))==0) {
  129. IIS_PRINTF((buff,
  130. "GetModuleFileName failed with %d\n",GetLastError()));
  131. goto exit;
  132. }
  133. hKey = CreateKey(hClapi,CLAPI_INPROC_SERVER,szName);
  134. if ( hKey == NULL ) {
  135. goto exit;
  136. }
  137. if (RegSetValueExA(hKey,
  138. "ThreadingModel",
  139. 0,
  140. REG_SZ,
  141. (LPBYTE)"Both",
  142. sizeof("Both")) != ERROR_SUCCESS) {
  143. RegCloseKey(hKey);
  144. hKey = NULL;
  145. goto exit;
  146. }
  147. RegCloseKey(hKey);
  148. /*
  149. //
  150. // Set ProgID key
  151. //
  152. hKey = CreateKey(hClapi,"ProgID",CLAPI_PROG_ID);
  153. if ( hKey == NULL ) {
  154. goto exit;
  155. }
  156. RegCloseKey(hKey);
  157. ret = S_OK;
  158. if ( hClapi != NULL ) {
  159. RegCloseKey(hClapi);
  160. hClapi = NULL;
  161. }
  162. if ( hProgID != NULL ) {
  163. RegCloseKey(hProgID);
  164. hProgID = NULL;
  165. }
  166. if ( hCLSID != NULL ) {
  167. RegCloseKey(hCLSID);
  168. hCLSID = NULL;
  169. }
  170. //
  171. // MSIISLOG.MSLOGPUBLIC
  172. //
  173. hProgID = CreateKey(
  174. HKEY_CLASSES_ROOT,
  175. LOGPUBLIC_PROG_ID,
  176. LOGPUBLIC_PROG_ID);
  177. if ( hProgID == NULL ) {
  178. IIS_PRINTF((buff,"Cannot set value for key %s\n", LOGPUBLIC_PROG_ID));
  179. goto exit;
  180. }
  181. hCLSID = CreateKey(hProgID,
  182. CLAPI_CLSID_KEY_NAME,
  183. LOGPUBLIC_CLSID);
  184. if ( hCLSID == NULL ) {
  185. IIS_PRINTF((buff,"Cannot set value %s for key %s\n",
  186. CLAPI_CLSID_KEY_NAME, LOGPUBLIC_CLSID));
  187. goto exit;
  188. }
  189. RegCloseKey(hCLSID);
  190. hCLSID = NULL;
  191. //
  192. // CLSID
  193. //
  194. if ( RegOpenKeyExA(HKEY_CLASSES_ROOT,
  195. CLAPI_CLSID_KEY_NAME,
  196. 0,
  197. KEY_ALL_ACCESS,
  198. &hCLSID) != ERROR_SUCCESS ) {
  199. IIS_PRINTF((buff,"Cannot open CLSID key\n"));
  200. goto exit;
  201. }
  202. hClapi = CreateKey(hCLSID,LOGPUBLIC_CLSID,LOGPUBLIC_PROG_ID);
  203. if ( hClapi == NULL ) {
  204. goto exit;
  205. }
  206. //
  207. // InProcServer32
  208. //
  209. hModule=GetModuleHandleA("iscomlog.dll");
  210. if (hModule == NULL) {
  211. IIS_PRINTF((buff,"GetModuleHandle failed with %d\n",GetLastError()));
  212. goto exit;
  213. }
  214. if (GetModuleFileNameA(hModule, szName, sizeof(szName))==0) {
  215. IIS_PRINTF((buff,
  216. "GetModuleFileName failed with %d\n",GetLastError()));
  217. goto exit;
  218. }
  219. hKey = CreateKey(hClapi,CLAPI_INPROC_SERVER,szName);
  220. if ( hKey == NULL ) {
  221. goto exit;
  222. }
  223. if (RegSetValueExA(hKey,
  224. "ThreadingModel",
  225. 0,
  226. REG_SZ,
  227. (LPBYTE)"Both",
  228. sizeof("Both")) != ERROR_SUCCESS) {
  229. RegCloseKey(hKey);
  230. goto exit;
  231. }
  232. RegCloseKey(hKey);
  233. //
  234. // Set ProgID key
  235. //
  236. hKey = CreateKey(hClapi,"ProgID",LOGPUBLIC_PROG_ID);
  237. if ( hKey == NULL ) {
  238. goto exit;
  239. }
  240. RegCloseKey(hKey);
  241. */
  242. ret = S_OK;
  243. exit:
  244. if ( hClapi != NULL ) {
  245. RegCloseKey(hClapi);
  246. hClapi = NULL;
  247. }
  248. if ( hProgID != NULL ) {
  249. RegCloseKey(hProgID);
  250. hProgID = NULL;
  251. }
  252. if ( hCLSID != NULL ) {
  253. RegCloseKey(hCLSID);
  254. hCLSID = NULL;
  255. }
  256. return ret;
  257. } // DllRegisterServer
  258. STDAPI
  259. DllUnregisterServer(
  260. VOID
  261. )
  262. {
  263. LONG err;
  264. CHAR tmpBuf[MAX_PATH+1];
  265. //
  266. // delete CLASSES/CLAPI.INETLOGINFORMATION/CLSID
  267. //
  268. strcpy(tmpBuf,CLAPI_PROG_ID);
  269. strcat(tmpBuf,TEXT("\\"));
  270. strcat(tmpBuf,CLAPI_CLSID_KEY_NAME);
  271. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  272. //
  273. // delete CLASSES/CLAPI.INETLOGINFORMATION
  274. //
  275. err = RegDeleteKey(HKEY_CLASSES_ROOT, CLAPI_PROG_ID);
  276. //
  277. // delete CLASSES/CLSID/{}/InProcServer32
  278. //
  279. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  280. strcat(tmpBuf,TEXT("\\"));
  281. strcat(tmpBuf,CLAPI_CLSID);
  282. strcat(tmpBuf,TEXT("\\"));
  283. strcat(tmpBuf,CLAPI_INPROC_SERVER);
  284. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  285. //
  286. // delete CLASSES/CLSID/{}/ProgID
  287. //
  288. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  289. strcat(tmpBuf,TEXT("\\"));
  290. strcat(tmpBuf,CLAPI_CLSID);
  291. strcat(tmpBuf,TEXT("\\"));
  292. strcat(tmpBuf,"ProgID");
  293. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  294. //
  295. // delete CLASSES/CLSID/{}
  296. //
  297. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  298. strcat(tmpBuf,TEXT("\\"));
  299. strcat(tmpBuf,CLAPI_CLSID);
  300. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  301. /*
  302. //
  303. // delete CLASSES/MSIISLOG.MSLOGPUBLIC/CLSID
  304. //
  305. strcpy(tmpBuf,LOGPUBLIC_PROG_ID);
  306. strcat(tmpBuf,TEXT("\\"));
  307. strcat(tmpBuf,CLAPI_CLSID_KEY_NAME);
  308. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  309. //
  310. // delete CLASSES/CLAPI.INETLOGINFORMATION
  311. //
  312. err = RegDeleteKey(HKEY_CLASSES_ROOT, LOGPUBLIC_PROG_ID);
  313. //
  314. // delete CLASSES/CLSID/{}/InProcServer32
  315. //
  316. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  317. strcat(tmpBuf,TEXT("\\"));
  318. strcat(tmpBuf,LOGPUBLIC_CLSID);
  319. strcat(tmpBuf,TEXT("\\"));
  320. strcat(tmpBuf,CLAPI_INPROC_SERVER);
  321. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  322. //
  323. // delete CLASSES/CLSID/{}/ProgID
  324. //
  325. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  326. strcat(tmpBuf,TEXT("\\"));
  327. strcat(tmpBuf,LOGPUBLIC_CLSID);
  328. strcat(tmpBuf,TEXT("\\"));
  329. strcat(tmpBuf,"ProgID");
  330. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  331. //
  332. // delete CLASSES/CLSID/{}
  333. //
  334. strcpy(tmpBuf,CLAPI_CLSID_KEY_NAME);
  335. strcat(tmpBuf,TEXT("\\"));
  336. strcat(tmpBuf,LOGPUBLIC_CLSID);
  337. err = RegDeleteKey(HKEY_CLASSES_ROOT, tmpBuf);
  338. */
  339. return S_OK;
  340. } // DllUnregisterServer