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.

596 lines
16 KiB

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