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.

402 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. iisbind.cxx
  5. Abstract:
  6. This module implements the IIS_SERVER_BINDING class.
  7. Author:
  8. Keith Moore (keithmo) 16-Jan-1997
  9. Revision History:
  10. --*/
  11. #include "tcpdllp.hxx"
  12. #pragma hdrstop
  13. #include <iisbind.hxx>
  14. //
  15. // Private constants.
  16. //
  17. //
  18. // Private types.
  19. //
  20. //
  21. // Private globals.
  22. //
  23. //
  24. // Private prototypes.
  25. //
  26. //
  27. // Public functions.
  28. //
  29. IIS_SERVER_BINDING::IIS_SERVER_BINDING(
  30. IN DWORD IpAddress,
  31. IN USHORT IpPort,
  32. IN const CHAR * HostName,
  33. IN PIIS_ENDPOINT Endpoint
  34. ) :
  35. m_IpAddress( IpAddress ),
  36. m_IpPort( IpPort ),
  37. m_HostName( HostName ),
  38. m_Endpoint( Endpoint )
  39. /*++
  40. Routine Description:
  41. IIS_SERVER_BINDING constructor.
  42. Arguments:
  43. IpAddress - The IP address for this binding. May be INADDR_ANY.
  44. IpPort - The IP port for this binding. Required.
  45. HostName - The host name for this binding. May be empty ("").
  46. Endpoint - The IIS_ENDPOINT to associate with this binding.
  47. Return Value:
  48. None.
  49. --*/
  50. {
  51. //
  52. // Sanity check.
  53. //
  54. DBG_ASSERT( HostName != NULL );
  55. DBG_ASSERT( Endpoint != NULL );
  56. } // IIS_SERVER_BINDING::IIS_SERVER_BINDING
  57. IIS_SERVER_BINDING::~IIS_SERVER_BINDING()
  58. /*++
  59. Routine Description:
  60. IIS_SERVER_BINDING destructor.
  61. Arguments:
  62. None.
  63. Return Value:
  64. None.
  65. --*/
  66. {
  67. //
  68. // This space intentionally left blank.
  69. //
  70. } // IIS_SERVER_BINDING::~IIS_SERVER_BINDING()
  71. DWORD
  72. IIS_SERVER_BINDING::ParseDescriptor(
  73. IN const CHAR * Descriptor,
  74. OUT LPDWORD IpAddress,
  75. OUT PUSHORT IpPort,
  76. OUT const CHAR ** HostName
  77. )
  78. /*++
  79. Routine Description:
  80. Parses a descriptor string of the form "ip_address:ip_port:host_name"
  81. into its component parts.
  82. Arguments:
  83. Descriptor - The descriptor string.
  84. IpAddress - Receives the IP address component if present, or
  85. INADDR_ANY if not.
  86. IpPort - Recieves the IP port component.
  87. HostName - Receives a pointer to the host name component.
  88. Return Value:
  89. DWORD - Completion status. 0 if successful, !0 otherwise.
  90. --*/
  91. {
  92. const CHAR * ipAddressString;
  93. const CHAR * ipPortString;
  94. const CHAR * hostNameString;
  95. const CHAR * end;
  96. CHAR temp[sizeof("123.123.123.123")];
  97. INT length;
  98. LONG tempPort;
  99. //
  100. // Sanity check.
  101. //
  102. DBG_ASSERT( Descriptor != NULL );
  103. DBG_ASSERT( IpAddress != NULL );
  104. DBG_ASSERT( IpPort != NULL );
  105. DBG_ASSERT( HostName != NULL );
  106. //
  107. // Find the various parts of the descriptor;
  108. //
  109. ipAddressString = Descriptor;
  110. ipPortString = strchr( ipAddressString, ':' );
  111. if( ipPortString == NULL ) {
  112. goto fatal;
  113. }
  114. ipPortString++;
  115. hostNameString = strchr( ipPortString, ':' );
  116. if( hostNameString == NULL ) {
  117. goto fatal;
  118. }
  119. hostNameString++;
  120. //
  121. // Validate and parse the IP address portion.
  122. //
  123. if( *ipAddressString == ':' ) {
  124. *IpAddress = INADDR_ANY;
  125. } else {
  126. length = DIFF(ipPortString - ipAddressString) - 1;
  127. if( length >= sizeof(temp) ) {
  128. goto fatal;
  129. }
  130. memcpy(
  131. temp,
  132. ipAddressString,
  133. length
  134. );
  135. temp[length] = '\0';
  136. *IpAddress = (DWORD)inet_addr( temp );
  137. if( *IpAddress == INADDR_NONE ) {
  138. goto fatal;
  139. }
  140. }
  141. //
  142. // Validate and parse the port.
  143. //
  144. if( *ipPortString == ':' ) {
  145. goto fatal;
  146. }
  147. length = DIFF(hostNameString - ipPortString);
  148. if( length >= sizeof(temp) ) {
  149. goto fatal;
  150. }
  151. memcpy(
  152. temp,
  153. ipPortString,
  154. length
  155. );
  156. temp[length] = '\0';
  157. tempPort = strtol(
  158. temp,
  159. (CHAR **)&end,
  160. 0
  161. );
  162. if( tempPort <= 0 || tempPort > 0xFFFF ) {
  163. goto fatal;
  164. }
  165. if( *end != ':' ) {
  166. goto fatal;
  167. }
  168. *IpPort = (USHORT)tempPort;
  169. //
  170. // Validate and parse the host name.
  171. //
  172. if( *hostNameString == ' ' || *hostNameString == ':' ) {
  173. goto fatal;
  174. }
  175. *HostName = hostNameString;
  176. return NO_ERROR;
  177. fatal:
  178. return ERROR_INVALID_PARAMETER;
  179. } // IIS_SERVER_BINDING::ParseDescriptor
  180. DWORD
  181. IIS_SERVER_BINDING::Compare(
  182. IN const CHAR * Descriptor,
  183. OUT LPBOOL Result
  184. )
  185. /*++
  186. Routine Description:
  187. Compares the current binding with the descriptor string.
  188. Arguments:
  189. Descriptor - The descriptor to compare against.
  190. Result - Receives the result of the comparison (TRUE if they match,
  191. FALSE otherwise).
  192. Return Value:
  193. DWORD - Completion status. 0 if successful, !0 otherwise.
  194. --*/
  195. {
  196. DWORD ipAddress;
  197. USHORT ipPort;
  198. const CHAR * hostName;
  199. DWORD status;
  200. //
  201. // Sanity check.
  202. //
  203. DBG_ASSERT( Descriptor != NULL );
  204. DBG_ASSERT( Result != NULL );
  205. //
  206. // Parse the descriptor.
  207. //
  208. status = ParseDescriptor(
  209. Descriptor,
  210. &ipAddress,
  211. &ipPort,
  212. &hostName
  213. );
  214. if( status == NO_ERROR ) {
  215. *Result = Compare(
  216. ipAddress,
  217. ipPort,
  218. hostName
  219. );
  220. }
  221. return status;
  222. } // IIS_SERVER_BINDING::Compare
  223. BOOL
  224. IIS_SERVER_BINDING::Compare(
  225. IN DWORD IpAddress,
  226. IN USHORT IpPort,
  227. IN const CHAR * HostName
  228. )
  229. /*++
  230. Routine Description:
  231. Compares the current binding with the specified IP address, IP port,
  232. and host name.
  233. Arguments:
  234. IpAddress - The IP address to compare against.
  235. IpPort - The IP port to compare against.
  236. HostName - The host name to compare against.
  237. Return Value:
  238. BOOL - TRUE if they match, FALSE otherwise.
  239. --*/
  240. {
  241. //
  242. // Sanity check.
  243. //
  244. DBG_ASSERT( HostName != NULL );
  245. //
  246. // Compare the components.
  247. //
  248. if( IpAddress == QueryIpAddress() &&
  249. IpPort == QueryIpPort() &&
  250. !_stricmp(
  251. HostName,
  252. QueryHostName()
  253. ) ) {
  254. return TRUE;
  255. }
  256. return FALSE;
  257. } // IIS_SERVER_BINDING::Compare
  258. //
  259. // Private functions.
  260. //