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.

324 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 2002 - 2002 Microsoft Corporation. All Rights Reserved.
  3. THIS CODE AND INFORMATION IS PROVIDED "AS-IS" WITHOUT WARRANTY OF
  4. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. PARTICULAR PURPOSE.
  7. THIS CODE IS NOT SUPPORTED BY MICROSOFT.
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. //
  12. // Private functions.
  13. //
  14. /***************************************************************************++
  15. Routine Description:
  16. Prints a record in the URL ACL store.
  17. Arguments:
  18. pOutput - A pointer to HTTP_SERVICE_CONFIG_URLACL_SET
  19. Return Value:
  20. None.
  21. --***************************************************************************/
  22. void
  23. PrintUrlAclRecord(
  24. IN PUCHAR pOutput
  25. )
  26. {
  27. PHTTP_SERVICE_CONFIG_URLACL_SET pSetParam;
  28. pSetParam = (PHTTP_SERVICE_CONFIG_URLACL_SET) pOutput;
  29. NlsPutMsg(
  30. HTTPCFG_URLACL_URL,
  31. pSetParam->KeyDesc.pUrlPrefix
  32. );
  33. NlsPutMsg(
  34. HTTPCFG_URLACL_ACL,
  35. pSetParam->ParamDesc.pStringSecurityDescriptor
  36. );
  37. NlsPutMsg(
  38. HTTPCFG_RECORD_SEPARATOR
  39. );
  40. }
  41. /***************************************************************************++
  42. Routine Description:
  43. Sets an URL ACL entry.
  44. Arguments:
  45. pUrl - The URL
  46. pAcl - The ACL specified as a SDDL string.
  47. Return Value:
  48. Success/Failure.
  49. --***************************************************************************/
  50. int
  51. DoUrlAclSet(
  52. IN PWSTR pUrl,
  53. IN PWSTR pAcl
  54. )
  55. {
  56. HTTP_SERVICE_CONFIG_URLACL_SET SetParam;
  57. DWORD Status;
  58. ZeroMemory(&SetParam, sizeof(SetParam));
  59. SetParam.KeyDesc.pUrlPrefix = pUrl;
  60. SetParam.ParamDesc.pStringSecurityDescriptor = pAcl;
  61. Status = HttpSetServiceConfiguration(
  62. NULL,
  63. HttpServiceConfigUrlAclInfo,
  64. &SetParam,
  65. sizeof(SetParam),
  66. NULL
  67. );
  68. NlsPutMsg(HTTPCFG_SETSERVICE_STATUS, Status);
  69. return Status;
  70. }
  71. /***************************************************************************++
  72. Routine Description:
  73. Queries for a URL ACL entry.
  74. Arguments:
  75. pUrl - The URL (if NULL, then enumerate the store).
  76. Return Value:
  77. Success/Failure.
  78. --***************************************************************************/
  79. int DoUrlAclQuery(
  80. IN PWSTR pUrl
  81. )
  82. {
  83. DWORD Status;
  84. PUCHAR pOutput = NULL;
  85. DWORD OutputLength = 0;
  86. DWORD ReturnLength = 0;
  87. HTTP_SERVICE_CONFIG_URLACL_QUERY QueryParam;
  88. ZeroMemory(&QueryParam, sizeof(QueryParam));
  89. if(pUrl)
  90. {
  91. // If a URL is specified, we'll Query for an exact entry.
  92. //
  93. QueryParam.QueryDesc = HttpServiceConfigQueryExact;
  94. QueryParam.KeyDesc.pUrlPrefix = pUrl;
  95. }
  96. else
  97. {
  98. //
  99. // No URL is specified, so enumerate the entire store.
  100. //
  101. QueryParam.QueryDesc = HttpServiceConfigQueryNext;
  102. }
  103. for(;;)
  104. {
  105. //
  106. // First, compute bytes required for querying the first entry.
  107. //
  108. Status = HttpQueryServiceConfiguration(
  109. NULL,
  110. HttpServiceConfigUrlAclInfo,
  111. &QueryParam,
  112. sizeof(QueryParam),
  113. pOutput,
  114. OutputLength,
  115. &ReturnLength,
  116. NULL
  117. );
  118. if(Status == ERROR_INSUFFICIENT_BUFFER)
  119. {
  120. // If the API completes with ERROR_INSUFFICIENT_BUFFER, we'll
  121. // allocate memory for it & continue with the loop where we'll
  122. // call it again.
  123. if(pOutput)
  124. {
  125. // If there was an existing buffer, free it.
  126. LocalFree(pOutput);
  127. }
  128. // Allocate a new buffer
  129. pOutput = LocalAlloc(LMEM_FIXED, ReturnLength);
  130. if(!pOutput)
  131. {
  132. return ERROR_NOT_ENOUGH_MEMORY;
  133. }
  134. OutputLength = ReturnLength;
  135. }
  136. else if(Status == NO_ERROR)
  137. {
  138. // The query succeeded! We'll print the record that we just
  139. // queried.
  140. PrintUrlAclRecord(pOutput);
  141. if(pUrl)
  142. {
  143. //
  144. // If we are not enumerating, we are done.
  145. //
  146. break;
  147. }
  148. else
  149. {
  150. //
  151. // Since we are enumerating, we'll move on to the next
  152. // record. This is done by incrementing the cursor, till
  153. // we get ERROR_NO_MORE_ITEMS.
  154. //
  155. QueryParam.dwToken ++;
  156. }
  157. }
  158. else if(ERROR_NO_MORE_ITEMS == Status && pUrl == NULL)
  159. {
  160. // We are enumerating and we have reached the end. This is
  161. // indicated by a ERROR_NO_MORE_ITEMS error code.
  162. // This is not a real error, since it is used to indicate that
  163. // we've finished enumeration.
  164. Status = NO_ERROR;
  165. break;
  166. }
  167. else
  168. {
  169. //
  170. // Some other error, so we are done
  171. //
  172. NlsPutMsg(HTTPCFG_QUERYSERVICE_STATUS, Status);
  173. break;
  174. }
  175. }
  176. if(pOutput)
  177. {
  178. LocalFree(pOutput);
  179. }
  180. return Status;
  181. }
  182. /***************************************************************************++
  183. Routine Description:
  184. Deletes an URL ACL entry.
  185. Arguments:
  186. pUrl - The URL
  187. Return Value:
  188. Success/Failure.
  189. --***************************************************************************/
  190. int DoUrlAclDelete(
  191. IN PWSTR pUrl
  192. )
  193. {
  194. HTTP_SERVICE_CONFIG_URLACL_SET SetParam;
  195. DWORD Status;
  196. SetParam.KeyDesc.pUrlPrefix = pUrl;
  197. Status = HttpDeleteServiceConfiguration(
  198. NULL,
  199. HttpServiceConfigUrlAclInfo,
  200. &SetParam,
  201. sizeof(SetParam),
  202. NULL
  203. );
  204. NlsPutMsg(HTTPCFG_DELETESERVICE_STATUS, Status);
  205. return Status;
  206. }
  207. //
  208. // Public function.
  209. //
  210. /***************************************************************************++
  211. Routine Description:
  212. The function that parses parameters specific to URL ACL &
  213. calls Set, Query or Delete.
  214. Arguments:
  215. argc - Count of arguments.
  216. argv - Pointer to command line arguments.
  217. Type - Type of operation to be performed.
  218. Return Value:
  219. Success/Failure.
  220. --***************************************************************************/
  221. int
  222. DoUrlAcl(
  223. int argc,
  224. WCHAR **argv,
  225. HTTPCFG_TYPE Type
  226. )
  227. {
  228. PWCHAR pUrl = NULL;
  229. PWCHAR pAcl = NULL;
  230. while(argc>=2 && (argv[0][0] == '-' || argv[0][0]== '/'))
  231. {
  232. switch(toupper(argv[0][1]))
  233. {
  234. case 'U':
  235. pUrl = argv[1];
  236. break;
  237. case 'A':
  238. pAcl = argv[1];
  239. break;
  240. default:
  241. NlsPutMsg(HTTPCFG_INVALID_SWITCH, argv[0]);
  242. return ERROR_INVALID_PARAMETER;
  243. }
  244. argc -=2;
  245. argv +=2;
  246. }
  247. switch(Type)
  248. {
  249. case HttpCfgTypeSet:
  250. return DoUrlAclSet(pUrl, pAcl);
  251. case HttpCfgTypeQuery:
  252. return DoUrlAclQuery(pUrl);
  253. case HttpCfgTypeDelete:
  254. return DoUrlAclDelete(pUrl);
  255. default:
  256. NlsPutMsg(HTTPCFG_INVALID_SWITCH, argv[0]);
  257. return ERROR_INVALID_PARAMETER;
  258. }
  259. }