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.

668 lines
19 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. Config.c
  5. Abstract:
  6. User-mode interface to HTTP.SYS: Configuration Group handler.
  7. Author:
  8. Keith Moore (keithmo) 15-Dec-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //
  13. // Private macros.
  14. //
  15. //
  16. // Private prototypes.
  17. //
  18. /***************************************************************************++
  19. Routine Description:
  20. Private function to add a URL to a config group.
  21. Arguments:
  22. UrlType - Type of URL (Reservation or Registration).
  23. ControlChannelHandle - Supplies a control channel handle.
  24. ConfigGroupId - Supplies an identifier as returned by
  25. HttpCreateConfigGroup().
  26. pFullyQualifiedUrl - The URL.
  27. UrlContext - URL Context.
  28. pSecurityDescriptor - Security Descriptor
  29. Return Value:
  30. ULONG - Completion status.
  31. --***************************************************************************/
  32. ULONG
  33. AddUrlToConfigGroup(
  34. IN HTTP_URL_OPERATOR_TYPE UrlType,
  35. IN HANDLE ControlChannelHandle,
  36. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  37. IN PCWSTR pFullyQualifiedUrl,
  38. IN HTTP_URL_CONTEXT UrlContext,
  39. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  40. IN ULONG SecurityDescriptorLength
  41. )
  42. {
  43. NTSTATUS Status;
  44. HTTP_CONFIG_GROUP_URL_INFO urlInfo;
  45. //
  46. // Initialize the input structure.
  47. //
  48. urlInfo.UrlType = UrlType;
  49. urlInfo.ConfigGroupId = ConfigGroupId;
  50. urlInfo.UrlContext = UrlContext;
  51. urlInfo.pSecurityDescriptor = pSecurityDescriptor;
  52. urlInfo.SecurityDescriptorLength = SecurityDescriptorLength;
  53. Status = RtlInitUnicodeStringEx( &urlInfo.FullyQualifiedUrl, pFullyQualifiedUrl );
  54. if ( !NT_SUCCESS(Status) )
  55. {
  56. return HttpApiNtStatusToWin32Status( Status );
  57. }
  58. // Make the request.
  59. return HttpApiSynchronousDeviceControl(
  60. ControlChannelHandle, // FileHandle
  61. IOCTL_HTTP_ADD_URL_TO_CONFIG_GROUP, // IoControlCode
  62. &urlInfo, // pInputBuffer
  63. sizeof(urlInfo), // InputBufferLength
  64. NULL, // pOutputBuffer
  65. 0, // OutputBufferLength
  66. NULL // pBytesTransferred
  67. );
  68. } // HttpAddUrlToConfigGroup
  69. /***************************************************************************++
  70. Routine Description:
  71. Private function to remove a URL to a config group.
  72. Arguments:
  73. UrlType - Type of URL (Reservation or Registration).
  74. ControlChannelHandle - Supplies a control channel handle.
  75. ConfigGroupId - Supplies an identifier as returned by
  76. HttpCreateConfigGroup().
  77. pFullyQualifiedUrl - The URL.
  78. Return Value:
  79. ULONG - Completion status.
  80. --***************************************************************************/
  81. ULONG
  82. RemoveUrlFromConfigGroup(
  83. IN HTTP_URL_OPERATOR_TYPE UrlType,
  84. IN HANDLE ControlChannelHandle,
  85. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  86. IN PCWSTR pFullyQualifiedUrl
  87. )
  88. {
  89. NTSTATUS Status;
  90. HTTP_CONFIG_GROUP_URL_INFO urlInfo;
  91. // Initialize the input structure.
  92. urlInfo.UrlType = UrlType;
  93. urlInfo.ConfigGroupId = ConfigGroupId;
  94. Status = RtlInitUnicodeStringEx( &urlInfo.FullyQualifiedUrl, pFullyQualifiedUrl );
  95. if ( !NT_SUCCESS(Status) )
  96. {
  97. return HttpApiNtStatusToWin32Status( Status );
  98. }
  99. // Make the request.
  100. return HttpApiSynchronousDeviceControl(
  101. ControlChannelHandle, // FileHandle
  102. IOCTL_HTTP_REMOVE_URL_FROM_CONFIG_GROUP, // IoControlCode
  103. &urlInfo, // pInputBuffer
  104. sizeof(urlInfo), // InputBufferLength
  105. NULL, // pOutputBuffer
  106. 0, // OutputBufferLength
  107. NULL // pBytesTransferred
  108. );
  109. }
  110. //
  111. // Public functions.
  112. //
  113. /***************************************************************************++
  114. Routine Description:
  115. Creates a new configuration group.
  116. Arguments:
  117. ControlChannelHandle - Supplies a control channel handle.
  118. pConfigGroupId - Receives an opaque identifier for the new
  119. configuration group.
  120. Return Value:
  121. ULONG - Completion status.
  122. --***************************************************************************/
  123. ULONG
  124. WINAPI
  125. HttpCreateConfigGroup(
  126. IN HANDLE ControlChannelHandle,
  127. OUT PHTTP_CONFIG_GROUP_ID pConfigGroupId
  128. )
  129. {
  130. ULONG result;
  131. HTTP_CONFIG_GROUP_INFO configGroupInfo;
  132. //
  133. // Make the request.
  134. //
  135. result = HttpApiSynchronousDeviceControl(
  136. ControlChannelHandle, // FileHandle
  137. IOCTL_HTTP_CREATE_CONFIG_GROUP, // IoControlCode
  138. NULL, // pInputBuffer
  139. 0, // InputBufferLength
  140. &configGroupInfo, // pOutputBuffer
  141. sizeof(configGroupInfo), // OutputBufferLength
  142. NULL // pBytesTransferred
  143. );
  144. if (result == NO_ERROR)
  145. {
  146. //
  147. // Retrieve the container ID.
  148. //
  149. *pConfigGroupId = configGroupInfo.ConfigGroupId;
  150. }
  151. return result;
  152. } // HttpCreateConfigGroup
  153. /***************************************************************************++
  154. Routine Description:
  155. Deletes an existing configuration group.
  156. Arguments:
  157. ControlChannelHandle - Supplies a control channel handle.
  158. ConfigGroupId - Supplies an identifier as returned by
  159. HttpCreateConfigGroup().
  160. Return Value:
  161. ULONG - Completion status.
  162. --***************************************************************************/
  163. ULONG
  164. WINAPI
  165. HttpDeleteConfigGroup(
  166. IN HANDLE ControlChannelHandle,
  167. IN HTTP_CONFIG_GROUP_ID ConfigGroupId
  168. )
  169. {
  170. HTTP_CONFIG_GROUP_INFO configGroupInfo;
  171. //
  172. // Initialize the input structure.
  173. //
  174. configGroupInfo.ConfigGroupId = ConfigGroupId;
  175. //
  176. // Make the request.
  177. //
  178. return HttpApiSynchronousDeviceControl(
  179. ControlChannelHandle, // FileHandle
  180. IOCTL_HTTP_DELETE_CONFIG_GROUP, // IoControlCode
  181. &configGroupInfo, // pInputBuffer
  182. sizeof(configGroupInfo), // InputBufferLength
  183. NULL, // pOutputBuffer
  184. 0, // OutputBufferLength
  185. NULL // pBytesTransferred
  186. );
  187. } // HttpDeleteConfigGroup
  188. /***************************************************************************++
  189. Routine Description:
  190. Adds a fully qualified URL to an configuration group.
  191. Arguments:
  192. ControlChannelHandle - Supplies a control channel handle.
  193. ConfigGroupId - Supplies an identifier as returned by
  194. HttpCreateConfigGroup().
  195. pFullyQualifiedUrl - Supplies the fully qualified URL to add to the
  196. container.
  197. UrlContext - Supplies an uninterpreted context to be associated with
  198. the URL.
  199. Return Value:
  200. ULONG - Completion status.
  201. --***************************************************************************/
  202. ULONG
  203. WINAPI
  204. HttpAddUrlToConfigGroup(
  205. IN HANDLE ControlChannelHandle,
  206. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  207. IN PCWSTR pFullyQualifiedUrl,
  208. IN HTTP_URL_CONTEXT UrlContext
  209. )
  210. {
  211. return AddUrlToConfigGroup(
  212. HttpUrlOperatorTypeRegistration,
  213. ControlChannelHandle,
  214. ConfigGroupId,
  215. pFullyQualifiedUrl,
  216. UrlContext,
  217. NULL,
  218. 0
  219. );
  220. } // HttpAddUrlToConfigGroup
  221. /***************************************************************************++
  222. Routine Description:
  223. Removes a fully qualified URL from an configuration group.
  224. Arguments:
  225. ControlChannelHandle - Supplies a control channel handle.
  226. ConfigGroupId - Supplies an identifier as returned by
  227. HttpCreateConfigGroup().
  228. pFullyQualifiedUrl - Supplies the fully qualified URL to remove from
  229. the container.
  230. Return Value:
  231. ULONG - Completion status.
  232. --***************************************************************************/
  233. ULONG
  234. WINAPI
  235. HttpRemoveUrlFromConfigGroup(
  236. IN HANDLE ControlChannelHandle,
  237. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  238. IN PCWSTR pFullyQualifiedUrl
  239. )
  240. {
  241. return RemoveUrlFromConfigGroup(
  242. HttpUrlOperatorTypeRegistration,
  243. ControlChannelHandle,
  244. ConfigGroupId,
  245. pFullyQualifiedUrl
  246. );
  247. } // HttpRemoveUrlFromConfigGroup
  248. /***************************************************************************++
  249. Routine Description:
  250. Removes all URLs from an configuration group.
  251. Arguments:
  252. ControlChannelHandle - Supplies a control channel handle.
  253. ConfigGroupId - Supplies an identifier as returned by
  254. HttpCreateConfigGroup().
  255. Return Value:
  256. ULONG - Completion status.
  257. --***************************************************************************/
  258. ULONG
  259. WINAPI
  260. HttpRemoveAllUrlsFromConfigGroup(
  261. IN HANDLE ControlChannelHandle,
  262. IN HTTP_CONFIG_GROUP_ID ConfigGroupId
  263. )
  264. {
  265. HTTP_REMOVE_ALL_URLS_INFO urlInfo;
  266. //
  267. // Initialize the input structure.
  268. //
  269. urlInfo.ConfigGroupId = ConfigGroupId;
  270. //
  271. // Make the request.
  272. //
  273. return HttpApiSynchronousDeviceControl(
  274. ControlChannelHandle, // FileHandle
  275. IOCTL_HTTP_REMOVE_ALL_URLS_FROM_CONFIG_GROUP,
  276. // IoControlCode
  277. &urlInfo, // pInputBuffer
  278. sizeof(urlInfo), // InputBufferLength
  279. NULL, // pOutputBuffer
  280. 0, // OutputBufferLength
  281. NULL // pBytesTransferred
  282. );
  283. } // HttpRemoveAllUrlsFromConfigGroup
  284. /***************************************************************************++
  285. Routine Description:
  286. Queries information from an configuration group.
  287. Arguments:
  288. ControlChannelHandle - Supplies a control channel handle.
  289. ConfigGroupId - Supplies an identifier as returned by
  290. HttpCreateConfigGroup().
  291. InformationClass - Supplies the type of information to query.
  292. pConfigGroupInformation - Supplies a buffer for the query.
  293. Length - Supplies the length of pConfigGroupInformation.
  294. pReturnLength - Receives the length of data written to the buffer.
  295. Return Value:
  296. ULONG - Completion status.
  297. --***************************************************************************/
  298. ULONG
  299. WINAPI
  300. HttpQueryConfigGroupInformation(
  301. IN HANDLE ControlChannelHandle,
  302. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  303. IN HTTP_CONFIG_GROUP_INFORMATION_CLASS InformationClass,
  304. OUT PVOID pConfigGroupInformation,
  305. IN ULONG Length,
  306. OUT PULONG pReturnLength OPTIONAL
  307. )
  308. {
  309. HTTP_CONFIG_GROUP_INFO configGroupInfo;
  310. //
  311. // Initialize the input structure.
  312. //
  313. configGroupInfo.ConfigGroupId = ConfigGroupId;
  314. configGroupInfo.InformationClass = InformationClass;
  315. //
  316. // Make the request.
  317. //
  318. return HttpApiSynchronousDeviceControl(
  319. ControlChannelHandle, // FileHandle
  320. IOCTL_HTTP_QUERY_CONFIG_GROUP, // IoControlCode
  321. &configGroupInfo, // pInputBuffer
  322. sizeof(configGroupInfo), // InputBufferLength
  323. pConfigGroupInformation, // pOutputBuffer
  324. Length, // OutputBufferLength
  325. pReturnLength // pBytesTransferred
  326. );
  327. } // HttpQueryConfigGroupInformation
  328. /***************************************************************************++
  329. Routine Description:
  330. Before passing down the config group information. Make sure that the
  331. directory name in the HttpConfigGroupLogInformation is not pointing back
  332. to local machine if it's a UNC path
  333. Arguments:
  334. pConfigGroupInformation - Supplies the config group info with dir name
  335. Length - Length of the above
  336. Return
  337. STATUS_SUCCESS : If the UNC path doesn't include the local machine name
  338. Or if the path is not UNC path.
  339. STATUS_INVALID_PARAMETER : If the buffer itself is corrupted or something
  340. fatal is preventing us from getting computer
  341. name when path is UNC.
  342. STATUS_NOT_SUPPORTED: If UNC path points back to the local machine.
  343. --***************************************************************************/
  344. NTSTATUS
  345. HttpApiConfigGroupInformationSanityCheck(
  346. IN HTTP_CONFIG_GROUP_INFORMATION_CLASS InformationClass,
  347. IN PVOID pConfigGroupInformation,
  348. IN ULONG Length
  349. )
  350. {
  351. PHTTP_CONFIG_GROUP_LOGGING pLoggingInfo;
  352. WCHAR pwszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  353. ULONG ulComputerNameLength;
  354. PWCHAR pwsz,pwszT;
  355. ULONG ulSrcUncLength;
  356. ULONG ulDirNameLength;
  357. //
  358. // Only for HttpConfigGroupLogInformation
  359. //
  360. if(InformationClass != HttpConfigGroupLogInformation ||
  361. pConfigGroupInformation == NULL
  362. )
  363. {
  364. return STATUS_SUCCESS;
  365. }
  366. if (Length < sizeof(HTTP_CONFIG_GROUP_LOGGING))
  367. {
  368. return STATUS_INVALID_PARAMETER;
  369. }
  370. //
  371. // Try to check the log dir name if it's a UNC Path
  372. //
  373. __try
  374. {
  375. pLoggingInfo = (PHTTP_CONFIG_GROUP_LOGGING)pConfigGroupInformation;
  376. ulDirNameLength = pLoggingInfo->LogFileDir.Length / sizeof(WCHAR);
  377. if (ulDirNameLength > 2)
  378. {
  379. if (pLoggingInfo->LogFileDir.Buffer[0] == L'\\' &&
  380. pLoggingInfo->LogFileDir.Buffer[1] == L'\\')
  381. {
  382. // UNC Path
  383. ULONG ccLength = MAX_COMPUTERNAME_LENGTH + 1;
  384. if (!GetComputerNameW(pwszComputerName, &ccLength))
  385. {
  386. // This should never fail unless there's really fatal
  387. // system problem. But if it fails then refuse the
  388. // UNC path regardless.
  389. return STATUS_INVALID_PARAMETER;
  390. }
  391. if (ccLength == 0)
  392. {
  393. return STATUS_INVALID_PARAMETER;
  394. }
  395. ulComputerNameLength = ccLength;
  396. // Extract the computername from the full path
  397. pwsz = pwszT = &pLoggingInfo->LogFileDir.Buffer[2];
  398. ulDirNameLength -= 2;
  399. // Forward the temp pointer to the end of the supposed
  400. // computername
  401. while(ulDirNameLength && *pwszT != UNICODE_NULL && *pwszT != L'\\')
  402. {
  403. pwszT++;
  404. ulDirNameLength--;
  405. }
  406. ulSrcUncLength = (ULONG) DIFF(pwszT - pwsz);
  407. // Compare not case sensitive
  408. if(ulComputerNameLength == ulSrcUncLength &&
  409. _wcsnicmp(pwszComputerName, pwsz, ulSrcUncLength) == 0
  410. )
  411. {
  412. return STATUS_NOT_SUPPORTED;
  413. }
  414. }
  415. }
  416. }
  417. __except( EXCEPTION_EXECUTE_HANDLER )
  418. {
  419. return STATUS_INVALID_PARAMETER;
  420. }
  421. return STATUS_SUCCESS;
  422. }
  423. /***************************************************************************++
  424. Routine Description:
  425. Sets information in an configuration group.
  426. Arguments:
  427. ControlChannelHandle - Supplies a control channel handle.
  428. ConfigGroupId - Supplies an identifier as returned by
  429. HttpCreateConfigGroup().
  430. InformationClass - Supplies the type of information to set.
  431. pConfigGroupInformation - Supplies the data to set.
  432. Length - Supplies the length of pConfigGroupInformation.
  433. Return Value:
  434. ULONG - Completion status.
  435. --***************************************************************************/
  436. ULONG
  437. WINAPI
  438. HttpSetConfigGroupInformation(
  439. IN HANDLE ControlChannelHandle,
  440. IN HTTP_CONFIG_GROUP_ID ConfigGroupId,
  441. IN HTTP_CONFIG_GROUP_INFORMATION_CLASS InformationClass,
  442. IN PVOID pConfigGroupInformation,
  443. IN ULONG Length
  444. )
  445. {
  446. NTSTATUS status;
  447. HTTP_CONFIG_GROUP_INFO configGroupInfo;
  448. //
  449. // Initialize the input structure.
  450. //
  451. configGroupInfo.ConfigGroupId = ConfigGroupId;
  452. configGroupInfo.InformationClass = InformationClass;
  453. status = HttpApiConfigGroupInformationSanityCheck(
  454. InformationClass,
  455. pConfigGroupInformation,
  456. Length
  457. );
  458. if (!NT_SUCCESS(status))
  459. {
  460. return HttpApiNtStatusToWin32Status(status);
  461. }
  462. //
  463. // Make the request.
  464. //
  465. return HttpApiSynchronousDeviceControl(
  466. ControlChannelHandle, // FileHandle
  467. IOCTL_HTTP_SET_CONFIG_GROUP, // IoControlCode
  468. &configGroupInfo, // pInputBuffer
  469. sizeof(configGroupInfo), // InputBufferLength
  470. pConfigGroupInformation, // pOutputBuffer
  471. Length, // OutputBufferLength
  472. NULL // pBytesTransferred
  473. );
  474. } // HttpSetConfigGroupInformation
  475. //
  476. // Private functions.
  477. //