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.

663 lines
26 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. dllreg.cxx
  5. Abstract:
  6. This module implements the dll registration for w3svc.dll
  7. Author:
  8. Michael Thomas (michth) Feb-17-1998
  9. --*/
  10. #include "w3p.hxx"
  11. #include "iadmw.h"
  12. #include "w3subs.hxx"
  13. //
  14. // Headers for logging fields
  15. //
  16. #define CPU_LOGGING_HEADER_EVENT L"s-event"
  17. #define CPU_LOGGING_HEADER_ACTIVE_PROCS L"s-active-procs"
  18. #define CPU_LOGGING_HEADER_KERNEL_TIME L"s-kernel-time"
  19. #define CPU_LOGGING_HEADER_PAGE_FAULTS L"s-page-faults"
  20. #define CPU_LOGGING_HEADER_PROC_TYPE L"s-process-type"
  21. #define CPU_LOGGING_HEADER_TERMINATED_PROCS L"s-stopped-procs"
  22. #define CPU_LOGGING_HEADER_TOTAL_PROCS L"s-total-procs"
  23. #define CPU_LOGGING_HEADER_USER_TIME L"s-user-time"
  24. #define MAX_RESOURCE_LOG_NAME_LEN 256
  25. #define CUSTOM_LOGGING_PATH_W L"/LM/Logging/Custom Logging"
  26. #define WEB_SERVER_PATH_W L"/LM/W3SVC"
  27. #define W3_SERVICE_NAME_W L"W3SVC"
  28. HRESULT
  29. SetFieldData(IMSAdminBaseW * pcCom,
  30. METADATA_HANDLE mhCustomLogging,
  31. HINSTANCE hInstance,
  32. DWORD dwNameResourceId,
  33. LPCWSTR pszwcPath,
  34. LPCWSTR pszwcHeader,
  35. DWORD dwHeaderSize,
  36. DWORD dwMask,
  37. DWORD dwDataType = MD_LOGCUSTOM_DATATYPE_ULONG);
  38. /*++
  39. Routine Description:
  40. Write all custom logging info for a field to the netabase,
  41. Arguments:
  42. pcCom Metabase interface
  43. mhCustomLogging Metabase Handle to CUSTOM_LOGGING_PATH_W
  44. hInstance Instance handle to w3svc.dll
  45. dwNameResourceId The id of the logging field name resource.
  46. pszwcPath The metabase subpath of this field
  47. pszwcHeader The logging field header
  48. dwHeaderSize Length of the logging field header in bytes include the trailing 0
  49. dwMask The logging mask bit for the field
  50. dwDataType The logging type of this field
  51. Return Value:
  52. Notes:
  53. --*/
  54. HRESULT
  55. SetFieldData(IMSAdminBaseW * pcCom,
  56. METADATA_HANDLE mhCustomLogging,
  57. HINSTANCE hInstance,
  58. DWORD dwNameResourceId,
  59. LPCWSTR pszwcPath,
  60. LPCWSTR pszwcHeader,
  61. DWORD dwHeaderSize,
  62. DWORD dwMask,
  63. DWORD dwDataType)
  64. {
  65. HRESULT hresReturn = ERROR_SUCCESS;
  66. METADATA_RECORD mdrData;
  67. WCHAR pszwBuffer[MAX_RESOURCE_LOG_NAME_LEN ];
  68. //
  69. // Create the key
  70. //
  71. hresReturn = pcCom->AddKey( mhCustomLogging,
  72. pszwcPath );
  73. //
  74. // OK if it already exists
  75. //
  76. if (hresReturn == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) {
  77. hresReturn = ERROR_SUCCESS;
  78. }
  79. if (SUCCEEDED(hresReturn)) {
  80. //
  81. // Set field name
  82. //
  83. hresReturn = GetUnicodeResourceString(hInstance,
  84. dwNameResourceId,
  85. pszwBuffer,
  86. MAX_RESOURCE_LOG_NAME_LEN);
  87. if (SUCCEEDED(hresReturn)) {
  88. MD_SET_DATA_RECORD(&mdrData,
  89. MD_LOGCUSTOM_PROPERTY_NAME,
  90. METADATA_NO_ATTRIBUTES,
  91. IIS_MD_UT_SERVER,
  92. STRING_METADATA,
  93. (wcslen(pszwBuffer) + 1) * 2,
  94. (PBYTE)pszwBuffer);
  95. hresReturn = pcCom->SetData(mhCustomLogging,
  96. pszwcPath,
  97. &mdrData);
  98. }
  99. //
  100. // Set field header
  101. //
  102. if (SUCCEEDED(hresReturn)) {
  103. MD_SET_DATA_RECORD(&mdrData,
  104. MD_LOGCUSTOM_PROPERTY_HEADER,
  105. METADATA_NO_ATTRIBUTES,
  106. IIS_MD_UT_SERVER,
  107. STRING_METADATA,
  108. dwHeaderSize,
  109. (PBYTE)pszwcHeader);
  110. hresReturn = pcCom->SetData(mhCustomLogging,
  111. pszwcPath,
  112. &mdrData);
  113. }
  114. //
  115. // Set field mask
  116. //
  117. if (SUCCEEDED(hresReturn)) {
  118. MD_SET_DATA_RECORD(&mdrData,
  119. MD_LOGCUSTOM_PROPERTY_MASK,
  120. METADATA_NO_ATTRIBUTES,
  121. IIS_MD_UT_SERVER,
  122. DWORD_METADATA,
  123. sizeof(DWORD),
  124. (PBYTE)&dwMask);
  125. hresReturn = pcCom->SetData(mhCustomLogging,
  126. pszwcPath,
  127. &mdrData);
  128. }
  129. //
  130. // Set field data type
  131. //
  132. if (SUCCEEDED(hresReturn)) {
  133. if (dwDataType != MD_LOGCUSTOM_DATATYPE_ULONG) {
  134. MD_SET_DATA_RECORD(&mdrData,
  135. MD_LOGCUSTOM_PROPERTY_DATATYPE,
  136. METADATA_NO_ATTRIBUTES,
  137. IIS_MD_UT_SERVER,
  138. DWORD_METADATA,
  139. sizeof(DWORD),
  140. (PBYTE)&dwDataType);
  141. hresReturn = pcCom->SetData(mhCustomLogging,
  142. pszwcPath,
  143. &mdrData);
  144. }
  145. }
  146. }
  147. return hresReturn;
  148. }
  149. /*++
  150. Routine Description:
  151. Register w3svc.
  152. Write CPU Logging and Limits defaults
  153. Write CPU Logging custom logging info.
  154. Return Value:
  155. error code
  156. --*/
  157. STDAPI DllRegisterServer(void)
  158. {
  159. METADATA_RECORD mdrData;
  160. IMSAdminBaseW * pcCom = NULL;
  161. METADATA_HANDLE mhCustomLogging;
  162. METADATA_HANDLE mhWebServer;
  163. DWORD dwData;
  164. WCHAR pszwData[256];
  165. HRESULT hresReturn;
  166. HINSTANCE hInstance;
  167. WCHAR pszwBuffer[MAX_RESOURCE_LOG_NAME_LEN ];
  168. //
  169. // Get module handle for w3svc.dll, to pass to GetUnicodeResourceString.
  170. //
  171. hInstance = GetModuleHandle("W3SVC.DLL");
  172. if (hInstance == NULL) {
  173. hresReturn = HRESULT_FROM_WIN32(GetLastError());
  174. }
  175. else {
  176. //
  177. // Get the metabase interface
  178. //
  179. hresReturn = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  180. if (hresReturn == RPC_E_CHANGED_MODE) {
  181. hresReturn = CoInitialize(NULL);
  182. }
  183. if (SUCCEEDED(hresReturn)) {
  184. hresReturn = CoCreateInstance(CLSID_MSAdminBase_W,
  185. NULL,
  186. CLSCTX_SERVER,
  187. IID_IMSAdminBase_W,
  188. (void**) &pcCom);
  189. if (SUCCEEDED(hresReturn)) {
  190. //
  191. // Open custom logging node
  192. //
  193. hresReturn = pcCom->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  194. CUSTOM_LOGGING_PATH_W,
  195. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  196. 40000,
  197. &mhCustomLogging);
  198. if (SUCCEEDED(hresReturn)) {
  199. /*
  200. removed for iis51/iis60
  201. -----------------------
  202. //
  203. // Add CPU Logging key
  204. //
  205. hresReturn = pcCom->AddKey( mhCustomLogging,
  206. W3_CPU_LOG_PATH_W );
  207. if (hresReturn == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) {
  208. hresReturn = ERROR_SUCCESS;
  209. }
  210. */
  211. if (SUCCEEDED(hresReturn)) {
  212. /*
  213. removed for iis51/iis60
  214. -----------------------
  215. //
  216. // Set field name
  217. //
  218. hresReturn = GetUnicodeResourceString(hInstance,
  219. IDS_CPU_LOGGING_NAME,
  220. pszwBuffer,
  221. MAX_RESOURCE_LOG_NAME_LEN);
  222. if (SUCCEEDED(hresReturn)) {
  223. MD_SET_DATA_RECORD(&mdrData,
  224. MD_LOGCUSTOM_PROPERTY_NAME,
  225. METADATA_NO_ATTRIBUTES,
  226. IIS_MD_UT_SERVER,
  227. STRING_METADATA,
  228. (wcslen(pszwBuffer) + 1) * 2,
  229. (PBYTE)pszwBuffer);
  230. hresReturn = pcCom->SetData(mhCustomLogging,
  231. W3_CPU_LOG_PATH_W,
  232. &mdrData);
  233. }
  234. if (SUCCEEDED(hresReturn)) {
  235. //
  236. // Logging Property id is the same for all fields, so set it here
  237. // Also needed here for the UI
  238. //
  239. dwData = MD_CPU_LOGGING_MASK;
  240. MD_SET_DATA_RECORD(&mdrData,
  241. MD_LOGCUSTOM_PROPERTY_ID,
  242. METADATA_INHERIT,
  243. IIS_MD_UT_SERVER,
  244. DWORD_METADATA,
  245. sizeof(DWORD),
  246. (PBYTE)&dwData);
  247. hresReturn = pcCom->SetData(mhCustomLogging,
  248. W3_CPU_LOG_PATH_W,
  249. &mdrData);
  250. }
  251. removed for iis51/iis60
  252. -----------------------
  253. if (SUCCEEDED(hresReturn)) {
  254. //
  255. // Set mask bit for enable flag
  256. //
  257. dwData = MD_CPU_ENABLE_LOGGING;
  258. MD_SET_DATA_RECORD(&mdrData,
  259. MD_LOGCUSTOM_PROPERTY_MASK,
  260. METADATA_NO_ATTRIBUTES,
  261. IIS_MD_UT_SERVER,
  262. DWORD_METADATA,
  263. sizeof(DWORD),
  264. (PBYTE)&dwData);
  265. hresReturn = pcCom->SetData(mhCustomLogging,
  266. W3_CPU_LOG_PATH_W,
  267. &mdrData);
  268. }
  269. if (SUCCEEDED(hresReturn)) {
  270. //
  271. // Most fields are dwords, so set that here and override if different
  272. //
  273. dwData = MD_LOGCUSTOM_DATATYPE_ULONG;
  274. MD_SET_DATA_RECORD(&mdrData,
  275. MD_LOGCUSTOM_PROPERTY_DATATYPE,
  276. METADATA_INHERIT,
  277. IIS_MD_UT_SERVER,
  278. DWORD_METADATA,
  279. sizeof(DWORD),
  280. (PBYTE)&dwData);
  281. hresReturn = pcCom->SetData(mhCustomLogging,
  282. W3_CPU_LOG_PATH_W,
  283. &mdrData);
  284. }
  285. if (SUCCEEDED(hresReturn)) {
  286. //
  287. // Set the services string
  288. //
  289. memcpy(pszwData, W3_SERVICE_NAME_W, sizeof(W3_SERVICE_NAME_W));
  290. pszwData[sizeof(W3_SERVICE_NAME_W)/2] = 0;
  291. MD_SET_DATA_RECORD(&mdrData,
  292. MD_LOGCUSTOM_SERVICES_STRING,
  293. METADATA_INHERIT,
  294. IIS_MD_UT_SERVER,
  295. MULTISZ_METADATA,
  296. sizeof(W3_SERVICE_NAME_W) + 2,
  297. (PBYTE)pszwData);
  298. hresReturn = pcCom->SetData(mhCustomLogging,
  299. W3_CPU_LOG_PATH_W,
  300. &mdrData);
  301. }
  302. //
  303. // Set up all of the fields
  304. //
  305. if (SUCCEEDED(hresReturn)) {
  306. hresReturn = SetFieldData(pcCom,
  307. mhCustomLogging,
  308. hInstance,
  309. IDS_CPU_LOGGING_NAME_EVENT,
  310. W3_CPU_LOG_PATH_W W3_CPU_LOG_EVENT_PATH_W,
  311. CPU_LOGGING_HEADER_EVENT,
  312. sizeof(CPU_LOGGING_HEADER_EVENT),
  313. MD_CPU_ENABLE_EVENT,
  314. MD_LOGCUSTOM_DATATYPE_LPSTR);
  315. }
  316. if (SUCCEEDED(hresReturn)) {
  317. hresReturn = SetFieldData(pcCom,
  318. mhCustomLogging,
  319. hInstance,
  320. IDS_CPU_LOGGING_NAME_PROC_TYPE,
  321. W3_CPU_LOG_PATH_W W3_CPU_LOG_PROCESS_TYPE_PATH_W,
  322. CPU_LOGGING_HEADER_PROC_TYPE,
  323. sizeof(CPU_LOGGING_HEADER_PROC_TYPE),
  324. MD_CPU_ENABLE_PROC_TYPE,
  325. MD_LOGCUSTOM_DATATYPE_LPSTR);
  326. }
  327. if (SUCCEEDED(hresReturn)) {
  328. hresReturn = SetFieldData(pcCom,
  329. mhCustomLogging,
  330. hInstance,
  331. IDS_CPU_LOGGING_NAME_USER_TIME,
  332. W3_CPU_LOG_PATH_W W3_CPU_LOG_USER_TIME_PATH_W,
  333. CPU_LOGGING_HEADER_USER_TIME,
  334. sizeof(CPU_LOGGING_HEADER_USER_TIME),
  335. MD_CPU_ENABLE_USER_TIME,
  336. MD_LOGCUSTOM_DATATYPE_LPSTR);
  337. }
  338. if (SUCCEEDED(hresReturn)) {
  339. hresReturn = SetFieldData(pcCom,
  340. mhCustomLogging,
  341. hInstance,
  342. IDS_CPU_LOGGING_NAME_KERNEL_TIME,
  343. W3_CPU_LOG_PATH_W W3_CPU_LOG_KERNEL_TIME_PATH_W,
  344. CPU_LOGGING_HEADER_KERNEL_TIME,
  345. sizeof(CPU_LOGGING_HEADER_KERNEL_TIME),
  346. MD_CPU_ENABLE_KERNEL_TIME,
  347. MD_LOGCUSTOM_DATATYPE_LPSTR);
  348. }
  349. if (SUCCEEDED(hresReturn)) {
  350. hresReturn = SetFieldData(pcCom,
  351. mhCustomLogging,
  352. hInstance,
  353. IDS_CPU_LOGGING_NAME_PAGE_FAULTS,
  354. W3_CPU_LOG_PATH_W W3_CPU_LOG_PAGE_FAULT_PATH_W,
  355. CPU_LOGGING_HEADER_PAGE_FAULTS,
  356. sizeof(CPU_LOGGING_HEADER_PAGE_FAULTS),
  357. MD_CPU_ENABLE_PAGE_FAULTS);
  358. }
  359. if (SUCCEEDED(hresReturn)) {
  360. hresReturn = SetFieldData(pcCom,
  361. mhCustomLogging,
  362. hInstance,
  363. IDS_CPU_LOGGING_NAME_TOTAL_PROCS,
  364. W3_CPU_LOG_PATH_W W3_CPU_LOG_TOTAL_PROCS_PATH_W,
  365. CPU_LOGGING_HEADER_TOTAL_PROCS,
  366. sizeof(CPU_LOGGING_HEADER_TOTAL_PROCS),
  367. MD_CPU_ENABLE_TOTAL_PROCS);
  368. }
  369. if (SUCCEEDED(hresReturn)) {
  370. hresReturn = SetFieldData(pcCom,
  371. mhCustomLogging,
  372. hInstance,
  373. IDS_CPU_LOGGING_NAME_ACTIVE_PROCS,
  374. W3_CPU_LOG_PATH_W W3_CPU_LOG_ACTIVE_PROCS_PATH_W,
  375. CPU_LOGGING_HEADER_ACTIVE_PROCS,
  376. sizeof(CPU_LOGGING_HEADER_ACTIVE_PROCS),
  377. MD_CPU_ENABLE_ACTIVE_PROCS);
  378. }
  379. if (SUCCEEDED(hresReturn)) {
  380. hresReturn = SetFieldData(pcCom,
  381. mhCustomLogging,
  382. hInstance,
  383. IDS_CPU_LOGGING_NAME_TERMINATED_PROCS,
  384. W3_CPU_LOG_PATH_W W3_CPU_LOG_TERMINATED_PROCS_PATH_W,
  385. CPU_LOGGING_HEADER_TERMINATED_PROCS,
  386. sizeof(CPU_LOGGING_HEADER_TERMINATED_PROCS),
  387. MD_CPU_ENABLE_TERMINATED_PROCS);
  388. }
  389. */
  390. }
  391. pcCom->CloseKey(mhCustomLogging);
  392. }
  393. if (SUCCEEDED(hresReturn)) {
  394. //
  395. // Set up service level CPU Logging and Limit defaults
  396. // at "/lm/w3svc"
  397. // Default values include reset interval, logging interval,
  398. // logging options, logging mask, cgi enabled, and app enabled.
  399. //
  400. hresReturn = pcCom->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  401. WEB_SERVER_PATH_W,
  402. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  403. 40000,
  404. &mhWebServer);
  405. if (SUCCEEDED(hresReturn)) {
  406. dwData = DEFAULT_W3_CPU_RESET_INTERVAL;
  407. MD_SET_DATA_RECORD(&mdrData,
  408. MD_CPU_RESET_INTERVAL,
  409. METADATA_INHERIT,
  410. IIS_MD_UT_SERVER,
  411. DWORD_METADATA,
  412. sizeof(DWORD),
  413. (PBYTE)&dwData);
  414. hresReturn = pcCom->SetData(mhWebServer,
  415. NULL,
  416. &mdrData);
  417. if (SUCCEEDED(hresReturn)) {
  418. dwData = DEFAULT_W3_CPU_QUERY_INTERVAL;
  419. MD_SET_DATA_RECORD(&mdrData,
  420. MD_CPU_LOGGING_INTERVAL,
  421. METADATA_INHERIT,
  422. IIS_MD_UT_SERVER,
  423. DWORD_METADATA,
  424. sizeof(DWORD),
  425. (PBYTE)&dwData);
  426. hresReturn = pcCom->SetData(mhWebServer,
  427. NULL,
  428. &mdrData);
  429. }
  430. if (SUCCEEDED(hresReturn)) {
  431. dwData = DEFAULT_W3_CPU_LOGGING_OPTIONS;
  432. MD_SET_DATA_RECORD(&mdrData,
  433. MD_CPU_LOGGING_OPTIONS,
  434. METADATA_INHERIT,
  435. IIS_MD_UT_SERVER,
  436. DWORD_METADATA,
  437. sizeof(DWORD),
  438. (PBYTE)&dwData);
  439. hresReturn = pcCom->SetData(mhWebServer,
  440. NULL,
  441. &mdrData);
  442. }
  443. if (SUCCEEDED(hresReturn)) {
  444. dwData = DEFAULT_W3_CPU_LOGGING_MASK;
  445. MD_SET_DATA_RECORD(&mdrData,
  446. MD_CPU_LOGGING_MASK,
  447. METADATA_INHERIT,
  448. IIS_MD_UT_SERVER,
  449. DWORD_METADATA,
  450. sizeof(DWORD),
  451. (PBYTE)&dwData);
  452. hresReturn = pcCom->SetData(mhWebServer,
  453. NULL,
  454. &mdrData);
  455. }
  456. if (SUCCEEDED(hresReturn)) {
  457. dwData = TRUE;
  458. MD_SET_DATA_RECORD(&mdrData,
  459. MD_CPU_CGI_ENABLED,
  460. METADATA_INHERIT,
  461. IIS_MD_UT_FILE,
  462. DWORD_METADATA,
  463. sizeof(DWORD),
  464. (PBYTE)&dwData);
  465. hresReturn = pcCom->SetData(mhWebServer,
  466. NULL,
  467. &mdrData);
  468. }
  469. if (SUCCEEDED(hresReturn)) {
  470. dwData = TRUE;
  471. MD_SET_DATA_RECORD(&mdrData,
  472. MD_CPU_APP_ENABLED,
  473. METADATA_INHERIT,
  474. IIS_MD_UT_FILE,
  475. DWORD_METADATA,
  476. sizeof(DWORD),
  477. (PBYTE)&dwData);
  478. hresReturn = pcCom->SetData(mhWebServer,
  479. NULL,
  480. &mdrData);
  481. }
  482. pcCom->CloseKey(mhWebServer);
  483. }
  484. }
  485. pcCom->Release();
  486. }
  487. CoUninitialize();
  488. }
  489. }
  490. return hresReturn;
  491. }
  492. /*++
  493. Routine Description:
  494. Unregister w3svc.
  495. Delete CPU Logging custom logging info.
  496. Return Value:
  497. error code
  498. --*/
  499. STDAPI DllUnregisterServer(void)
  500. {
  501. IMSAdminBaseW * pcCom = NULL;
  502. METADATA_HANDLE mhCustomLogging;
  503. HRESULT hresReturn;
  504. hresReturn = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  505. if (hresReturn == RPC_E_CHANGED_MODE) {
  506. hresReturn = CoInitialize(NULL);
  507. }
  508. if (SUCCEEDED(hresReturn)) {
  509. hresReturn = CoCreateInstance(CLSID_MSAdminBase_W,
  510. NULL,
  511. CLSCTX_SERVER,
  512. IID_IMSAdminBase_W,
  513. (void**) &pcCom);
  514. if (SUCCEEDED(hresReturn)) {
  515. hresReturn = pcCom->OpenKey(METADATA_MASTER_ROOT_HANDLE,
  516. L"/LM/Logging/Custom Logging" ,
  517. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  518. 40000,
  519. &mhCustomLogging);
  520. if (SUCCEEDED(hresReturn)) {
  521. hresReturn = pcCom->DeleteKey(mhCustomLogging,
  522. W3_CPU_LOG_PATH_W);
  523. pcCom->CloseKey(mhCustomLogging);
  524. }
  525. pcCom->Release();
  526. }
  527. CoUninitialize();
  528. }
  529. //
  530. // OpenKey and DeleteKey can return path not found. This is ok,
  531. // don't need to do anything.
  532. //
  533. if (hresReturn == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) {
  534. hresReturn = ERROR_SUCCESS;
  535. }
  536. return hresReturn;
  537. }