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.

523 lines
18 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. servinfo.h
  5. Abstract:
  6. Contains the public definitions for the server information structure.
  7. Author:
  8. Henry Sanders (henrysa) 10-Aug-2000
  9. Revision History:
  10. --*/
  11. #ifndef _SERVINFO_H_
  12. #define _SERVINFO_H_
  13. //
  14. // Forward references.
  15. //
  16. typedef unsigned char BYTE;
  17. typedef unsigned char *PBYTE;
  18. //
  19. // Private constants.
  20. //
  21. #define SERVER_NAME_BUFFER_SIZE 64
  22. #define UC_DEFAULT_SI_TABLE_SIZE 32
  23. #define UC_DEFAULT_INITIAL_CONNECTION_COUNT 1
  24. //
  25. // Private types.
  26. //
  27. //
  28. // Cloned Security DATA_BLOB
  29. //
  30. typedef struct _HTTP_DATA_BLOB
  31. {
  32. ULONG cbData;
  33. PUCHAR pbData;
  34. } HTTP_DATA_BLOB, *PHTTP_DATA_BLOB;
  35. //
  36. // The structure of the server info table header. The server info table is a
  37. // hash table consisting of an array of these headers, each of which points
  38. // to a linked list of server info structures.
  39. //
  40. typedef struct _UC_SERVER_INFO_TABLE_HEADER
  41. {
  42. UL_ERESOURCE Resource;
  43. LIST_ENTRY List;
  44. ULONG Version;
  45. } UC_SERVER_INFO_TABLE_HEADER, *PUC_SERVER_INFO_TABLE_HEADER;
  46. //
  47. // Public constants
  48. //
  49. #define DEFAULT_MAX_CONNECTION_COUNT 2
  50. //
  51. // Public types
  52. //
  53. //
  54. // The structure representing our server information. This contains information
  55. // the the version of the remote server, whether or not pipelining is supported
  56. // to that server, etc. Note that this information is about the final endpoint
  57. // server, not the first hop server (which may be a proxy).
  58. //
  59. typedef struct _UC_COMMON_SERVER_INFORMATION
  60. {
  61. ULONG Signature;
  62. LONG RefCount;
  63. LIST_ENTRY Linkage;
  64. WCHAR ServerNameBuffer[SERVER_NAME_BUFFER_SIZE];
  65. CHAR AnsiServerNameBuffer[SERVER_NAME_BUFFER_SIZE];
  66. USHORT ServerNameLength;
  67. USHORT AnsiServerNameLength;
  68. PWSTR pServerName;
  69. PSTR pAnsiServerName;
  70. ULONG bPortNumber :1;
  71. ULONG Version11 :1;
  72. PUC_SERVER_INFO_TABLE_HEADER pHeader;
  73. PEPROCESS pProcess;
  74. } UC_COMMON_SERVER_INFORMATION, *PUC_COMMON_SERVER_INFORMATION;
  75. typedef enum _HTTP_SSL_SERVER_CERT_INFO_STATE
  76. {
  77. HttpSslServerCertInfoStateNotPresent,
  78. HttpSslServerCertInfoStateNotValidated,
  79. HttpSslServerCertInfoStateValidated,
  80. HttpSslServerCertInfoStateMax
  81. } HTTP_SSL_SERVER_CERT_INFO_STATE, *PHTTP_SSL_SERVER_CEERT_INFO_STATE;
  82. //
  83. // The following structure is used to maintain a per-process Server Information
  84. // structure. By default, threads of the same process will share this info.
  85. //
  86. // This structure contains a list of connections that we have outstanding to
  87. // the server. There is a default list we use when direct connected, and there
  88. // is also a list of proxies being used to get to the server, each of which
  89. // may itself have a list of connections.
  90. //
  91. typedef struct _UC_PROCESS_SERVER_INFORMATION
  92. {
  93. //
  94. // Structure signature.
  95. //
  96. ULONG Signature;
  97. LIST_ENTRY Linkage; // Linkage on free list or
  98. // in server info table.
  99. PUC_CLIENT_CONNECTION *Connections; // Connections to server
  100. ULONG ActualConnectionCount; // actual # of elements
  101. // in Connections array
  102. //
  103. // Initial array of pointers to connections
  104. //
  105. PUC_CLIENT_CONNECTION ConnectionArray[DEFAULT_MAX_CONNECTION_COUNT];
  106. ULONG NextConnection; // index of the next
  107. // connection to be used.
  108. LONG RefCount;
  109. ULONG CurrentConnectionCount; // Number of connections in
  110. //
  111. ULONG MaxConnectionCount; // Maximum number of
  112. // connections allowed.
  113. ULONG ConnectionTimeout;
  114. ULONG IgnoreContinues; // True if we want to ignore
  115. // 1XX responses
  116. BOOLEAN bSecure;
  117. BOOLEAN bProxy;
  118. UL_PUSH_LOCK PushLock; // Push lock protecting this.
  119. PUC_COMMON_SERVER_INFORMATION pServerInfo; // Info regarding origin server
  120. PUC_COMMON_SERVER_INFORMATION pNextHopInfo;// Info regarding next hop
  121. ULONG GreatestAuthHeaderMaxLength;
  122. LIST_ENTRY pAuthListHead; // List of URIs for pre-auth
  123. LONG PreAuthEnable;
  124. LONG ProxyPreAuthEnable;
  125. PUC_HTTP_AUTH pProxyAuthInfo;
  126. //
  127. // This contains the resolved address - Could be either the
  128. // server or the proxy address. The resolution is done in user mode, so
  129. // we don't even know what this is.
  130. //
  131. union
  132. {
  133. TA_IP_ADDRESS V4Address;
  134. TA_IP6_ADDRESS V6Address;
  135. TRANSPORT_ADDRESS GenericTransportAddress;
  136. } RemoteAddress;
  137. PTRANSPORT_ADDRESS pTransportAddress;
  138. ULONG TransportAddressLength;
  139. PEPROCESS pProcess;
  140. // Ssl protocol version
  141. ULONG SslProtocolVersion;
  142. // Ok to access ServerCertValidation without holding lock
  143. ULONG ServerCertValidation;
  144. HTTP_SSL_SERVER_CERT_INFO_STATE ServerCertInfoState;
  145. HTTP_SSL_SERVER_CERT_INFO ServerCertInfo;
  146. // Client cert
  147. PVOID pClientCert;
  148. } UC_PROCESS_SERVER_INFORMATION, *PUC_PROCESS_SERVER_INFORMATION;
  149. #define UC_PROCESS_SERVER_INFORMATION_SIGNATURE MAKE_SIGNATURE('UcSp')
  150. #define UC_COMMON_SERVER_INFORMATION_SIGNATURE MAKE_SIGNATURE('UcSc')
  151. #define IS_VALID_SERVER_INFORMATION(pInfo) \
  152. HAS_VALID_SIGNATURE(pInfo, UC_PROCESS_SERVER_INFORMATION_SIGNATURE)
  153. #define REFERENCE_SERVER_INFORMATION(s) \
  154. UcReferenceServerInformation( \
  155. (s) \
  156. )
  157. #define DEREFERENCE_SERVER_INFORMATION(s) \
  158. UcDereferenceServerInformation( \
  159. (s) \
  160. )
  161. #define IS_VALID_COMMON_SERVER_INFORMATION(pInfo) \
  162. HAS_VALID_SIGNATURE(pInfo, UC_COMMON_SERVER_INFORMATION_SIGNATURE)
  163. #define REFERENCE_COMMON_SERVER_INFORMATION(s) \
  164. UcReferenceCommonServerInformation( \
  165. (s) \
  166. )
  167. #define DEREFERENCE_COMMON_SERVER_INFORMATION(s) \
  168. UcDereferenceCommonServerInformation( \
  169. (s) \
  170. )
  171. //
  172. // Add a connection at the specified place in servinfo connections array
  173. //
  174. #define ADD_CONNECTION_TO_SERV_INFO(pServInfo, pConnection, index) \
  175. do { \
  176. ASSERT(index < pServInfo->MaxConnectionCount); \
  177. ASSERT(pServInfo->Connections[index] == NULL); \
  178. \
  179. pConnection->pServerInfo = pServInfo; \
  180. pConnection->ConnectionIndex = index; \
  181. \
  182. pServInfo->Connections[index] = pConnection; \
  183. pServInfo->CurrentConnectionCount++; \
  184. ASSERT(pServInfo->CurrentConnectionCount<= pServInfo->MaxConnectionCount);\
  185. } while (0, 0)
  186. //
  187. // Free serialized certificate and serialized cert store.
  188. //
  189. #define UC_FREE_SERIALIZED_CERT(pServerCertInfo, pProcess) \
  190. do { \
  191. if ((pServerCertInfo)->Cert.pSerializedCert) \
  192. { \
  193. UL_FREE_POOL_WITH_QUOTA( \
  194. (pServerCertInfo)->Cert.pSerializedCert, \
  195. UC_SSL_CERT_DATA_POOL_TAG, \
  196. NonPagedPool, \
  197. (pServerCertInfo)->Cert.SerializedCertLength, \
  198. pProcess); \
  199. \
  200. (pServerCertInfo)->Cert.pSerializedCert = NULL; \
  201. (pServerCertInfo)->Cert.SerializedCertLength = 0; \
  202. } \
  203. \
  204. if ((pServerCertInfo)->Cert.pSerializedCertStore) \
  205. { \
  206. UL_FREE_POOL_WITH_QUOTA( \
  207. (pServerCertInfo)->Cert.pSerializedCertStore, \
  208. UC_SSL_CERT_DATA_POOL_TAG, \
  209. NonPagedPool, \
  210. (pServerCertInfo)->Cert.SerializedCertStoreLength, \
  211. pProcess); \
  212. \
  213. (pServerCertInfo)->Cert.pSerializedCertStore = NULL; \
  214. (pServerCertInfo)->Cert.SerializedCertStoreLength = 0; \
  215. } \
  216. } while (0, 0)
  217. //
  218. // Move serialized certificate and serialized store from a connection to
  219. // a server information.
  220. //
  221. #define UC_MOVE_SERIALIZED_CERT(pServInfo, pConnection) \
  222. do { \
  223. PHTTP_SSL_SERVER_CERT_INFO pServerCertInfo = &pConnection->ServerCertInfo;\
  224. \
  225. UC_FREE_SERIALIZED_CERT(&pServInfo->ServerCertInfo, pServInfo->pProcess); \
  226. \
  227. RtlCopyMemory(&pServInfo->ServerCertInfo.Cert, \
  228. &pServerCertInfo->Cert, \
  229. sizeof(HTTP_SSL_SERIALIZED_CERT)); \
  230. \
  231. pServerCertInfo->Cert.pSerializedCert = NULL; \
  232. pServerCertInfo->Cert.SerializedCertLength = 0; \
  233. \
  234. pServerCertInfo->Cert.pSerializedCertStore = NULL; \
  235. pServerCertInfo->Cert.SerializedCertStoreLength = 0; \
  236. \
  237. } while (0, 0)
  238. //
  239. // Free certificate issuer list.
  240. //
  241. #define UC_FREE_CERT_ISSUER_LIST(pServerCertInfo, pProcess) \
  242. do { \
  243. if ((pServerCertInfo)->IssuerInfo.IssuerListLength) \
  244. { \
  245. UL_FREE_POOL_WITH_QUOTA( \
  246. (pServerCertInfo)->IssuerInfo.pIssuerList, \
  247. UC_SSL_CERT_DATA_POOL_TAG, \
  248. NonPagedPool, \
  249. (pServerCertInfo)->IssuerInfo.IssuerListLength, \
  250. pProcess); \
  251. \
  252. (pServerCertInfo)->IssuerInfo.IssuerListLength = 0; \
  253. (pServerCertInfo)->IssuerInfo.IssuerCount = 0; \
  254. (pServerCertInfo)->IssuerInfo.pIssuerList = NULL; \
  255. } \
  256. } while (0, 0)
  257. //
  258. // First copy issuer list if any.
  259. //
  260. #define UC_MOVE_CERT_ISSUER_LIST(pServInfo, pConnection) \
  261. do { \
  262. if ((pConnection)->ServerCertInfo.IssuerInfo.IssuerListLength) \
  263. { \
  264. /* Free old copy */ \
  265. UC_FREE_CERT_ISSUER_LIST(&(pServInfo)->ServerCertInfo, \
  266. (pServInfo)->pProcess); \
  267. \
  268. /* Get new copy */ \
  269. RtlCopyMemory(&(pServInfo)->ServerCertInfo.IssuerInfo, \
  270. &(pConnection)->ServerCertInfo.IssuerInfo, \
  271. sizeof((pConnection)->ServerCertInfo.IssuerInfo)); \
  272. \
  273. /* Remove it from the connection */ \
  274. RtlZeroMemory(&(pConnection)->ServerCertInfo.IssuerInfo, \
  275. sizeof((pConnection)->ServerCertInfo.IssuerInfo)); \
  276. } \
  277. } while (0, 0)
  278. //
  279. // Compare server cert hash on pservinfo and pconnection.
  280. //
  281. #define UC_COMPARE_CERT_HASH(pSCI1, pSCI2) \
  282. ((pSCI1)->Cert.CertHashLength == (pSCI2)->Cert.CertHashLength && \
  283. (RtlCompareMemory((pSCI1)->Cert.CertHash, \
  284. (pSCI2)->Cert.CertHash, \
  285. (pSCI1)->Cert.CertHashLength) \
  286. == (pSCI1)->Cert.CertHashLength))
  287. //
  288. // Indicates if SERVER_CERT_INFO.Cert contains serialized certificate.
  289. //
  290. #define HTTP_SSL_SERIALIZED_CERT_PRESENT 0x00000001
  291. //
  292. // Private prototypes.
  293. //
  294. NTSTATUS
  295. UcpLookupCommonServerInformation(
  296. PWSTR pServerName,
  297. USHORT ServerNameLength,
  298. ULONG CommonHashCode,
  299. PEPROCESS pProcess,
  300. PUC_COMMON_SERVER_INFORMATION *pCommonInfo
  301. );
  302. VOID
  303. UcpFreeServerInformation(
  304. PUC_PROCESS_SERVER_INFORMATION pInfo
  305. );
  306. VOID
  307. UcpFreeCommonServerInformation(
  308. PUC_COMMON_SERVER_INFORMATION pInfo
  309. );
  310. NTSTATUS
  311. UcpGetConnectionOnServInfo(
  312. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  313. IN ULONG ConnectionIndex,
  314. OUT PUC_CLIENT_CONNECTION *ppConnection
  315. );
  316. NTSTATUS
  317. UcpGetNextConnectionOnServInfo(
  318. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  319. OUT PUC_CLIENT_CONNECTION *ppConnection
  320. );
  321. NTSTATUS
  322. UcpSetServInfoMaxConnectionCount(
  323. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  324. IN ULONG NewCount
  325. );
  326. NTSTATUS
  327. UcpFixupIssuerList(
  328. IN OUT PUCHAR pIssuerList,
  329. IN PUCHAR BaseAddr,
  330. IN ULONG IssuerCount,
  331. IN ULONG IssuerListLength
  332. );
  333. BOOLEAN
  334. UcpNeedToCaptureSerializedCert(
  335. IN PHTTP_SSL_SERVER_CERT_INFO pCertInfo,
  336. IN PUC_PROCESS_SERVER_INFORMATION pServInfo
  337. );
  338. //
  339. // Public prototypes
  340. //
  341. NTSTATUS
  342. UcInitializeServerInformation(
  343. VOID
  344. );
  345. VOID
  346. UcTerminateServerInformation(
  347. VOID
  348. );
  349. NTSTATUS
  350. UcCreateServerInformation(
  351. OUT PUC_PROCESS_SERVER_INFORMATION *pServerInfo,
  352. IN PWSTR pServerName,
  353. IN USHORT ServerNameLength,
  354. IN PWSTR pProxyName,
  355. IN USHORT ProxyNameLength,
  356. IN PTRANSPORT_ADDRESS pTransportAddress,
  357. IN USHORT TransportAddressLength,
  358. IN KPROCESSOR_MODE RequestorMode
  359. );
  360. VOID
  361. UcReferenceServerInformation(
  362. PUC_PROCESS_SERVER_INFORMATION pServerInfo
  363. );
  364. VOID
  365. UcDereferenceServerInformation(
  366. PUC_PROCESS_SERVER_INFORMATION pServerInfo
  367. );
  368. VOID
  369. UcReferenceCommonServerInformation(
  370. PUC_COMMON_SERVER_INFORMATION pServerInfo
  371. );
  372. VOID
  373. UcDereferenceCommonServerInformation(
  374. PUC_COMMON_SERVER_INFORMATION pServerInfo
  375. );
  376. NTSTATUS
  377. UcSendRequest(
  378. PUC_PROCESS_SERVER_INFORMATION pServerInfo,
  379. PUC_HTTP_REQUEST pRequest
  380. );
  381. VOID
  382. UcCloseServerInformation(
  383. IN PUC_PROCESS_SERVER_INFORMATION pServInfo
  384. );
  385. NTSTATUS
  386. UcSetServerContextInformation(
  387. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  388. IN HTTP_SERVER_CONFIG_ID ConfigID,
  389. IN PVOID pMdlBuffer,
  390. IN ULONG BufferLength,
  391. IN PIRP pIrp
  392. );
  393. NTSTATUS
  394. UcQueryServerContextInformation(
  395. IN PUC_PROCESS_SERVER_INFORMATION pServInfo,
  396. IN HTTP_SERVER_CONFIG_ID ConfigID,
  397. IN PVOID pOutBuffer,
  398. IN ULONG OutBufferLength,
  399. OUT PULONG pBytesTaken,
  400. IN PVOID pAppBase
  401. );
  402. NTSTATUS
  403. UcCaptureSslServerCertInfo(
  404. IN PUX_FILTER_CONNECTION pConnection,
  405. IN PHTTP_SSL_SERVER_CERT_INFO pCertInfo,
  406. IN ULONG CertInfoLength,
  407. OUT PHTTP_SSL_SERVER_CERT_INFO pCopyCertInfo,
  408. OUT PULONG pTakenLength
  409. );
  410. #endif