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.

250 lines
5.5 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. Routine Description:
  13. main routine.
  14. Arguments:
  15. argc - # of command line arguments.
  16. argv - Arguments.
  17. Return Value:
  18. Success/Failure.
  19. --***************************************************************************/
  20. int _cdecl wmain(int argc, LPWSTR argv[])
  21. {
  22. DWORD Status = NO_ERROR;
  23. HTTPCFG_TYPE Type;
  24. HTTPAPI_VERSION HttpApiVersion = HTTPAPI_VERSION_1;
  25. WORD wVersionRequested;
  26. WSADATA wsaData;
  27. // Parse command line parameters.
  28. if(argc < 3)
  29. {
  30. NlsPutMsg(HTTPCFG_USAGE, argv[0]);
  31. return 0;
  32. }
  33. argv++; argc --;
  34. //
  35. // First parse the type of operation.
  36. //
  37. if(_wcsicmp(argv[0], L"set") == 0)
  38. {
  39. Type = HttpCfgTypeSet;
  40. }
  41. else if(_wcsicmp(argv[0], L"query") == 0)
  42. {
  43. Type = HttpCfgTypeQuery;
  44. }
  45. else if(_wcsicmp(argv[0], L"delete") == 0)
  46. {
  47. Type = HttpCfgTypeDelete;
  48. }
  49. else if(_wcsicmp(argv[0], L"?") == 0)
  50. {
  51. NlsPutMsg(HTTPCFG_USAGE, argv[0]);
  52. return 0;
  53. }
  54. else
  55. {
  56. NlsPutMsg(HTTPCFG_INVALID_SWITCH, argv[0]);
  57. return ERROR_INVALID_PARAMETER;
  58. }
  59. argv++; argc--;
  60. //
  61. // Call HttpInitialize.
  62. //
  63. if((Status = HttpInitialize(
  64. HttpApiVersion,
  65. HTTP_INITIALIZE_CONFIG,
  66. NULL)) != NO_ERROR)
  67. {
  68. NlsPutMsg(HTTPCFG_HTTPINITIALIZE, Status);
  69. return Status;
  70. }
  71. //
  72. // Call WSAStartup as we are using some winsock functions.
  73. //
  74. wVersionRequested = MAKEWORD( 2, 2 );
  75. if(WSAStartup( wVersionRequested, &wsaData ) != 0)
  76. {
  77. HttpTerminate(HTTP_INITIALIZE_CONFIG, NULL);
  78. return GetLastError();
  79. }
  80. //
  81. // Call the corresponding API.
  82. //
  83. if(_wcsicmp(argv[0], L"ssl") == 0)
  84. {
  85. argv++; argc--;
  86. Status = DoSsl(argc, argv, Type);
  87. }
  88. else if(_wcsicmp(argv[0], L"urlacl") == 0)
  89. {
  90. argv++; argc--;
  91. Status = DoUrlAcl(argc, argv, Type);
  92. }
  93. else if(_wcsicmp(argv[0], L"iplisten") == 0)
  94. {
  95. argv++; argc--;
  96. Status = DoIpListen(argc, argv, Type);
  97. }
  98. else
  99. {
  100. NlsPutMsg(HTTPCFG_INVALID_SWITCH, argv[0]);
  101. Status = ERROR_INVALID_PARAMETER;
  102. }
  103. WSACleanup();
  104. HttpTerminate(HTTP_INITIALIZE_CONFIG, NULL);
  105. return Status;
  106. }
  107. /***************************************************************************++
  108. Routine Description:
  109. Write output
  110. Arguments:
  111. Handle - Handle to write to.
  112. MsgNumber - The message number.
  113. ... - Optional arguments.
  114. Return Value:
  115. Success/Failure.
  116. --***************************************************************************/
  117. UINT
  118. NlsPutMsg (
  119. IN UINT MsgNumber,
  120. IN ...
  121. )
  122. {
  123. UINT msglen;
  124. VOID *vp;
  125. va_list arglist;
  126. va_start(arglist, MsgNumber);
  127. msglen = FormatMessage(
  128. FORMAT_MESSAGE_FROM_HMODULE |
  129. FORMAT_MESSAGE_ALLOCATE_BUFFER, // dwFlags.
  130. NULL, // lpSource.
  131. MsgNumber, // dwMessageId.
  132. 0L, // dwLanguageId (default)
  133. (LPWSTR)&vp,
  134. 0,
  135. &arglist
  136. );
  137. if(!msglen)
  138. {
  139. return 0;
  140. }
  141. wprintf(L"%ws", vp);
  142. LocalFree(vp);
  143. return msglen;
  144. }
  145. /***************************************************************************++
  146. Routine Description:
  147. Given a WCHAR IP, this routine converts it to a SOCKADDR.
  148. Arguments:
  149. pIp - IP address to covert.
  150. pBuffer - Buffer, must be == sizeof(SOCKADDR_STORAGE)
  151. Length - Length of buffer
  152. Return Value:
  153. Success/Failure.
  154. --***************************************************************************/
  155. DWORD
  156. GetAddress(
  157. PWCHAR pIp,
  158. PVOID pBuffer,
  159. ULONG Length
  160. )
  161. {
  162. DWORD Status;
  163. DWORD TempStatus;
  164. if(pIp == NULL)
  165. {
  166. return ERROR_INVALID_PARAMETER;
  167. }
  168. //
  169. // The address could be a v4 or a v6 address. First, let's try v4.
  170. //
  171. Status = WSAStringToAddress(
  172. pIp,
  173. AF_INET,
  174. NULL,
  175. pBuffer,
  176. (LPINT)&Length
  177. );
  178. if(Status != NO_ERROR)
  179. {
  180. //
  181. // Now, try v6
  182. //
  183. Status = WSAGetLastError();
  184. TempStatus = WSAStringToAddress(
  185. pIp,
  186. AF_INET6,
  187. NULL,
  188. pBuffer,
  189. (LPINT)&Length
  190. );
  191. //
  192. // If IPv6 also fails, then we want to return the original
  193. // error.
  194. //
  195. // If it succeeds, we want to return NO_ERROR.
  196. //
  197. if(TempStatus == NO_ERROR)
  198. {
  199. Status = NO_ERROR;
  200. }
  201. }
  202. return Status;
  203. }