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.

648 lines
16 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. httpfilt.h
  5. Abstract:
  6. This module contains the Microsoft HTTP filter extension info
  7. Revision History:
  8. --*/
  9. #ifndef _HTTPFILT_H_
  10. #define _HTTPFILT_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. //
  15. // Current version of the filter spec is 4.0
  16. //
  17. #define HTTP_FILTER_REVISION MAKELONG( 0, 4)
  18. #define SF_MAX_USERNAME (256+1)
  19. #define SF_MAX_PASSWORD (256+1)
  20. #define SF_MAX_AUTH_TYPE (32+1)
  21. #define SF_MAX_FILTER_DESC_LEN (256+1)
  22. typedef
  23. VOID (WINAPI * PFN_SF_NOTIFY) (
  24. DWORD dwNotifyType,
  25. LPVOID pInstance
  26. );
  27. //
  28. // These values can be used with the pfnSFCallback function supplied in
  29. // the filter context structure
  30. //
  31. enum SF_REQ_TYPE
  32. {
  33. //
  34. // Sends a complete HTTP server response header including
  35. // the status, server version, message time and MIME version.
  36. //
  37. // Server extensions should append other information at the end,
  38. // such as Content-type, Content-length etc followed by an extra
  39. // '\r\n'.
  40. //
  41. // pData - Zero terminated string pointing to optional
  42. // status string (i.e., "401 Access Denied") or NULL for
  43. // the default response of "200 OK".
  44. //
  45. // ul1 - Zero terminated string pointing to optional data to be
  46. // appended and set with the header. If NULL, the header will
  47. // be terminated with an empty line.
  48. //
  49. SF_REQ_SEND_RESPONSE_HEADER,
  50. //
  51. // If the server denies the HTTP request, add the specified headers
  52. // to the server error response.
  53. //
  54. // This allows an authentication filter to advertise its services
  55. // w/o filtering every request. Generally the headers will be
  56. // WWW-Authenticate headers with custom authentication schemes but
  57. // no restriction is placed on what headers may be specified.
  58. //
  59. // pData - Zero terminated string pointing to one or more header lines
  60. // with terminating '\r\n'.
  61. //
  62. SF_REQ_ADD_HEADERS_ON_DENIAL,
  63. //
  64. // Only used by raw data filters that return SF_STATUS_READ_NEXT
  65. //
  66. // ul1 - size in bytes for the next read
  67. //
  68. SF_REQ_SET_NEXT_READ_SIZE,
  69. //
  70. // Used to indicate this request is a proxy request
  71. //
  72. // ul1 - The proxy flags to set
  73. // 0x00000001 - This is a HTTP proxy request
  74. //
  75. //
  76. SF_REQ_SET_PROXY_INFO,
  77. //
  78. // Returns the connection ID contained in the ConnID field of an
  79. // ISAPI Application's Extension Control Block. This value can be used
  80. // as a key to cooridinate shared data between Filters and Applications.
  81. //
  82. // pData - Pointer to DWORD that receives the connection ID.
  83. //
  84. SF_REQ_GET_CONNID,
  85. //
  86. // Used to set a SSPI security context + impersonation token
  87. // derived from a client certificate.
  88. //
  89. // pData - certificate info ( PHTTP_FILTER_CERTIFICATE_INFO )
  90. // ul1 - CtxtHandle*
  91. // ul2 - impersonation handle
  92. //
  93. SF_REQ_SET_CERTIFICATE_INFO,
  94. //
  95. // Used to get an IIS property
  96. // as defined in SF_PROPERTY_IIS
  97. //
  98. // ul1 - Property ID
  99. //
  100. SF_REQ_GET_PROPERTY,
  101. //
  102. // Used to normalize an URL
  103. //
  104. // pData - URL to normalize
  105. //
  106. SF_REQ_NORMALIZE_URL,
  107. //
  108. // Indicates end of renegotiation
  109. //
  110. // pData - LPBOOL : TRUE if renegotiation succeeded
  111. //
  112. SF_REQ_DONE_RENEGOTIATE,
  113. //
  114. // Set notify call-back
  115. //
  116. // ul1 - notification type ( SF_NOTIFY_TYPE )
  117. // pData - ptr to notify function ( PFN_SF_NOTIFY )
  118. //
  119. SF_REQ_SET_NOTIFY,
  120. //
  121. // Disable Notifications
  122. //
  123. // ul1 - notifications to disable
  124. //
  125. SF_REQ_DISABLE_NOTIFICATIONS,
  126. };
  127. enum SF_PROPERTY_IIS
  128. {
  129. SF_PROPERTY_CLIENT_CERT_ENABLED, // return BOOL in pData as LPBOOL
  130. SF_PROPERTY_MD5_ENABLED, // return BOOL in pData as LPBOOL
  131. SF_PROPERTY_DIR_MAP_CERT, // return BOOL in pData as LPBOOL
  132. SF_PROPERTY_GET_CERT11_MAPPER, // These 4 functions returns ptr
  133. SF_PROPERTY_GET_RULE_MAPPER, // to RefBlob containing mapper
  134. SF_PROPERTY_GET_MD5_MAPPER,
  135. SF_PROPERTY_GET_ITA_MAPPER,
  136. SF_PROPERTY_GET_INSTANCE_ID,
  137. SF_PROPERTY_MD_IF,
  138. SF_PROPERTY_SSL_CTXT,
  139. SF_PROPERTY_INSTANCE_NUM_ID,
  140. } ;
  141. enum SF_NOTIFY_TYPE
  142. {
  143. SF_NOTIFY_MAPPER_MD5_CHANGED,
  144. SF_NOTIFY_MAPPER_ITA_CHANGED,
  145. SF_NOTIFY_MAPPER_CERT11_CHANGED,
  146. SF_NOTIFY_MAPPER_CERTW_CHANGED,
  147. SF_NOTIFY_MAPPER_SSLKEYS_CHANGED,
  148. SF_NOTIFY_MAPPER_CERT11_TOUCHED,
  149. } ;
  150. //
  151. // These values are returned by the filter entry point when a new request is
  152. // received indicating their interest in this particular request
  153. //
  154. enum SF_STATUS_TYPE
  155. {
  156. //
  157. // The filter has handled the HTTP request. The server should disconnect
  158. // the session.
  159. //
  160. SF_STATUS_REQ_FINISHED = 0x8000000,
  161. //
  162. // Same as SF_STATUS_FINISHED except the server should keep the TCP
  163. // session open if the option was negotiated
  164. //
  165. SF_STATUS_REQ_FINISHED_KEEP_CONN,
  166. //
  167. // The next filter in the notification chain should be called
  168. //
  169. SF_STATUS_REQ_NEXT_NOTIFICATION,
  170. //
  171. // This filter handled the notification. No other handles should be
  172. // called for this particular notification type
  173. //
  174. SF_STATUS_REQ_HANDLED_NOTIFICATION,
  175. //
  176. // An error occurred. The server should use GetLastError() and indicate
  177. // the error to the client
  178. //
  179. SF_STATUS_REQ_ERROR,
  180. //
  181. // The filter is an opaque stream filter and we're negotiating the
  182. // session parameters. Only valid for raw read notification.
  183. //
  184. SF_STATUS_REQ_READ_NEXT
  185. };
  186. //
  187. // pvNotification points to this structure for all request notification types
  188. //
  189. typedef struct _HTTP_FILTER_CONTEXT
  190. {
  191. DWORD cbSize;
  192. //
  193. // This is the structure revision level.
  194. //
  195. DWORD Revision;
  196. //
  197. // Private context information for the server.
  198. //
  199. PVOID ServerContext;
  200. DWORD ulReserved;
  201. //
  202. // TRUE if this request is coming over a secure port
  203. //
  204. BOOL fIsSecurePort;
  205. //
  206. // A context that can be used by the filter
  207. //
  208. PVOID pFilterContext;
  209. //
  210. // Server callbacks
  211. //
  212. BOOL (WINAPI * GetServerVariable) (
  213. struct _HTTP_FILTER_CONTEXT * pfc,
  214. LPSTR lpszVariableName,
  215. LPVOID lpvBuffer,
  216. LPDWORD lpdwSize
  217. );
  218. BOOL (WINAPI * AddResponseHeaders) (
  219. struct _HTTP_FILTER_CONTEXT * pfc,
  220. LPSTR lpszHeaders,
  221. DWORD dwReserved
  222. );
  223. BOOL (WINAPI * WriteClient) (
  224. struct _HTTP_FILTER_CONTEXT * pfc,
  225. LPVOID Buffer,
  226. LPDWORD lpdwBytes,
  227. DWORD dwReserved
  228. );
  229. VOID * (WINAPI * AllocMem) (
  230. struct _HTTP_FILTER_CONTEXT * pfc,
  231. DWORD cbSize,
  232. DWORD dwReserved
  233. );
  234. BOOL (WINAPI * ServerSupportFunction) (
  235. struct _HTTP_FILTER_CONTEXT * pfc,
  236. enum SF_REQ_TYPE sfReq,
  237. PVOID pData,
  238. DWORD ul1,
  239. DWORD ul2
  240. );
  241. } HTTP_FILTER_CONTEXT, *PHTTP_FILTER_CONTEXT;
  242. //
  243. // This structure is the notification info for the read and send raw data
  244. // notification types
  245. //
  246. typedef struct _HTTP_FILTER_RAW_DATA
  247. {
  248. //
  249. // This is a pointer to the data for the filter to process.
  250. //
  251. PVOID pvInData;
  252. DWORD cbInData; // Number of valid data bytes
  253. DWORD cbInBuffer; // Total size of buffer
  254. DWORD dwReserved;
  255. } HTTP_FILTER_RAW_DATA, *PHTTP_FILTER_RAW_DATA;
  256. //
  257. // This structure is the notification info for when the server is about to
  258. // process the client headers
  259. //
  260. typedef struct _HTTP_FILTER_PREPROC_HEADERS
  261. {
  262. //
  263. // For SF_NOTIFY_PREPROC_HEADERS, retrieves the specified header value.
  264. // Header names should include the trailing ':'. The special values
  265. // 'method', 'url' and 'version' can be used to retrieve the individual
  266. // portions of the request line
  267. //
  268. BOOL (WINAPI * GetHeader) (
  269. struct _HTTP_FILTER_CONTEXT * pfc,
  270. LPSTR lpszName,
  271. LPVOID lpvBuffer,
  272. LPDWORD lpdwSize
  273. );
  274. //
  275. // Replaces this header value to the specified value. To delete a header,
  276. // specified a value of '\0'.
  277. //
  278. BOOL (WINAPI * SetHeader) (
  279. struct _HTTP_FILTER_CONTEXT * pfc,
  280. LPSTR lpszName,
  281. LPSTR lpszValue
  282. );
  283. //
  284. // Adds the specified header and value
  285. //
  286. BOOL (WINAPI * AddHeader) (
  287. struct _HTTP_FILTER_CONTEXT * pfc,
  288. LPSTR lpszName,
  289. LPSTR lpszValue
  290. );
  291. DWORD HttpStatus; // New in 4.0, status for SEND_RESPONSE
  292. DWORD SubStatus; // New in 4.0, status for SEND_RESPONSE
  293. } HTTP_FILTER_PREPROC_HEADERS, *PHTTP_FILTER_PREPROC_HEADERS;
  294. typedef HTTP_FILTER_PREPROC_HEADERS HTTP_FILTER_SEND_RESPONSE;
  295. typedef HTTP_FILTER_PREPROC_HEADERS *PHTTP_FILTER_SEND_RESPONSE;
  296. //
  297. // Authentication information for this request.
  298. //
  299. typedef struct _HTTP_FILTER_AUTHENT
  300. {
  301. //
  302. // Pointer to username and password, empty strings for the anonymous user
  303. //
  304. // Client's can overwrite these buffers which are guaranteed to be at
  305. // least SF_MAX_USERNAME and SF_MAX_PASSWORD bytes large.
  306. //
  307. CHAR * pszUser;
  308. DWORD cbUserBuff;
  309. CHAR * pszPassword;
  310. DWORD cbPasswordBuff;
  311. } HTTP_FILTER_AUTHENT, *PHTTP_FILTER_AUTHENT;
  312. //
  313. // Authentication information for this request.
  314. //
  315. typedef struct _HTTP_FILTER_AUTHENTEX
  316. {
  317. //
  318. // Pointer to username and password, empty strings for the anonymous user
  319. //
  320. // Client can overwrite hAccessToken
  321. //
  322. CHAR * pszUser;
  323. DWORD cbUserBuff;
  324. CHAR * pszLogonUser;
  325. DWORD cbLogonUserBuff;
  326. CHAR * pszPassword;
  327. CHAR * pszRealm;
  328. CHAR * pszAuthType;
  329. DWORD cbAuthTypeBuff;
  330. HANDLE hAccessTokenPrimary;
  331. HANDLE hAccessTokenImpersonation;
  332. } HTTP_FILTER_AUTHENTEX, *PHTTP_FILTER_AUTHENTEX;
  333. //
  334. // Indicates the server is going to use the specific physical mapping for
  335. // the specified URL. Filters can modify the physical path in place.
  336. //
  337. typedef struct _HTTP_FILTER_URL_MAP
  338. {
  339. const CHAR * pszURL;
  340. CHAR * pszPhysicalPath;
  341. DWORD cbPathBuff;
  342. } HTTP_FILTER_URL_MAP, *PHTTP_FILTER_URL_MAP;
  343. //
  344. // Indicates the server is going to delete the specified impersonation token
  345. // Only called if the token was created by the filter
  346. //
  347. typedef struct _HTTP_FILTER_REQUEST_CLOSE_SECURITY_CONTEXT
  348. {
  349. PVOID pCtxt;
  350. } HTTP_FILTER_REQUEST_CLOSE_SECURITY_CONTEXT,
  351. *PHTTP_FILTER_REQUEST_CLOSE_SECURITY_CONTEXT;
  352. //
  353. // Bitfield indicating the requested resource has been denied by the server due
  354. // to a logon failure, an ACL on a resource, an ISAPI Filter or an
  355. // ISAPI Application/CGI Application.
  356. //
  357. // SF_DENIED_BY_CONFIG can appear with SF_DENIED_LOGON if the server
  358. // configuration did not allow the user to logon.
  359. //
  360. #define SF_DENIED_LOGON 0x00000001
  361. #define SF_DENIED_RESOURCE 0x00000002
  362. #define SF_DENIED_FILTER 0x00000004
  363. #define SF_DENIED_APPLICATION 0x00000008
  364. #define SF_DENIED_BY_CONFIG 0x00010000
  365. typedef struct _HTTP_FILTER_ACCESS_DENIED
  366. {
  367. const CHAR * pszURL; // Requesting URL
  368. const CHAR * pszPhysicalPath; // Physical path of resource
  369. DWORD dwReason; // Bitfield of SF_DENIED flags
  370. } HTTP_FILTER_ACCESS_DENIED, *PHTTP_FILTER_ACCESS_DENIED;
  371. //
  372. // The server request a SSL certificate renegotiation.
  373. // If filter accepts, it must set fAccepted to TRUE
  374. //
  375. typedef struct _HTTP_FILTER_REQUEST_CERT
  376. {
  377. BOOL fAccepted; // [out] request accepted
  378. BOOL fMapCert; // [in] TRUE if cert to be mapped to
  379. // NT account
  380. DWORD dwReserved;
  381. } HTTP_FILTER_REQUEST_CERT, *PHTTP_FILTER_REQUEST_CERT;
  382. //
  383. // The log information about to be written to the server log file. The
  384. // string pointers can be replaced but the memory must remain valid until
  385. // the next notification
  386. //
  387. typedef struct _HTTP_FILTER_LOG
  388. {
  389. const CHAR * pszClientHostName;
  390. const CHAR * pszClientUserName;
  391. const CHAR * pszServerName;
  392. const CHAR * pszOperation;
  393. const CHAR * pszTarget;
  394. const CHAR * pszParameters;
  395. DWORD dwHttpStatus;
  396. DWORD dwWin32Status;
  397. DWORD dwBytesSent; // IIS 3.0 and later
  398. DWORD dwBytesRecvd; // IIS 3.0 and later
  399. DWORD msTimeForProcessing; // IIS 3.0 and later
  400. } HTTP_FILTER_LOG, *PHTTP_FILTER_LOG;
  401. //
  402. // Notification Flags
  403. //
  404. // SF_NOTIFY_SECURE_PORT
  405. // SF_NOTIFY_NONSECURE_PORT
  406. //
  407. // Indicates whether the application wants to be notified for transactions
  408. // that are happenning on the server port(s) that support data encryption
  409. // (such as PCT and SSL), on only the non-secure port(s) or both.
  410. //
  411. // SF_NOTIFY_READ_RAW_DATA
  412. //
  413. // Applications are notified after the server reads a block of memory
  414. // from the client but before the server does any processing on the
  415. // block. The data block may contain HTTP headers and entity data.
  416. //
  417. //
  418. //
  419. #define SF_NOTIFY_SECURE_PORT 0x00000001
  420. #define SF_NOTIFY_NONSECURE_PORT 0x00000002
  421. #define SF_NOTIFY_READ_RAW_DATA 0x00008000
  422. #define SF_NOTIFY_PREPROC_HEADERS 0x00004000
  423. #define SF_NOTIFY_AUTHENTICATION 0x00002000
  424. #define SF_NOTIFY_URL_MAP 0x00001000
  425. #define SF_NOTIFY_ACCESS_DENIED 0x00000800
  426. #define SF_NOTIFY_SEND_RESPONSE 0x00000040
  427. #define SF_NOTIFY_SEND_RAW_DATA 0x00000400
  428. #define SF_NOTIFY_LOG 0x00000200
  429. #define SF_NOTIFY_END_OF_REQUEST 0x00000080
  430. #define SF_NOTIFY_END_OF_NET_SESSION 0x00000100
  431. #define SF_NOTIFY_AUTHENTICATIONEX 0x20000000
  432. #define SF_NOTIFY_REQUEST_SECURITY_CONTEXT_CLOSE \
  433. 0x10000000
  434. #define SF_NOTIFY_RENEGOTIATE_CERT 0x08000000
  435. //
  436. // Filter ordering flags
  437. //
  438. // Filters will tend to be notified by their specified
  439. // ordering. For ties, notification order is determined by load order.
  440. //
  441. // SF_NOTIFY_ORDER_HIGH - Authentication or data transformation filters
  442. // SF_NOTIFY_ORDER_MEDIUM
  443. // SF_NOTIFY_ORDER_LOW - Logging filters that want the results of any other
  444. // filters might specify this order.
  445. //
  446. #define SF_NOTIFY_ORDER_HIGH 0x00080000
  447. #define SF_NOTIFY_ORDER_MEDIUM 0x00040000
  448. #define SF_NOTIFY_ORDER_LOW 0x00020000
  449. #define SF_NOTIFY_ORDER_DEFAULT SF_NOTIFY_ORDER_LOW
  450. #define SF_NOTIFY_ORDER_MASK (SF_NOTIFY_ORDER_HIGH | \
  451. SF_NOTIFY_ORDER_MEDIUM | \
  452. SF_NOTIFY_ORDER_LOW)
  453. //
  454. // Filter version information, passed to GetFilterVersion
  455. //
  456. typedef struct _HTTP_FILTER_VERSION
  457. {
  458. //
  459. // Version of the spec the server is using
  460. //
  461. DWORD dwServerFilterVersion;
  462. //
  463. // Fields specified by the client
  464. //
  465. DWORD dwFilterVersion;
  466. CHAR lpszFilterDesc[SF_MAX_FILTER_DESC_LEN];
  467. DWORD dwFlags;
  468. } HTTP_FILTER_VERSION, *PHTTP_FILTER_VERSION;
  469. typedef struct _HTTP_FILTER_CERTIFICATE_INFO
  470. {
  471. PBYTE pbCert;
  472. DWORD cbCert;
  473. } HTTP_FILTER_CERTIFICATE_INFO, *PHTTP_FILTER_CERTIFICATE_INFO;
  474. //
  475. // A filter DLL's entry point looks like this. The return code should be
  476. // an SF_STATUS_TYPE
  477. //
  478. // NotificationType - Type of notification
  479. // pvNotification - Pointer to notification specific data
  480. //
  481. DWORD
  482. WINAPI
  483. HttpFilterProc(
  484. HTTP_FILTER_CONTEXT * pfc,
  485. DWORD NotificationType,
  486. VOID * pvNotification
  487. );
  488. BOOL
  489. WINAPI
  490. GetFilterVersion(
  491. HTTP_FILTER_VERSION * pVer
  492. );
  493. BOOL
  494. WINAPI
  495. TerminateFilter(
  496. DWORD dwFlags
  497. );
  498. #ifdef __cplusplus
  499. }
  500. #endif
  501. #endif //_HTTPFILT_H_