Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ACL management functions. |
| 3 | * |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 13 | #include <ctype.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #include <common/config.h> |
| 18 | #include <common/mini-clist.h> |
| 19 | #include <common/standard.h> |
Krzysztof Piotr Oledzki | 8c8bd45 | 2010-01-29 19:29:32 +0100 | [diff] [blame] | 20 | #include <common/uri_auth.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 22 | #include <types/global.h> |
| 23 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 24 | #include <proto/acl.h> |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 25 | #include <proto/arg.h> |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 26 | #include <proto/auth.h> |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 27 | #include <proto/buffers.h> |
Willy Tarreau | 404e8ab | 2009-07-26 19:40:40 +0200 | [diff] [blame] | 28 | #include <proto/log.h> |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 29 | #include <proto/proxy.h> |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 31 | #include <ebsttree.h> |
| 32 | |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 33 | /* The capabilities of filtering hooks describe the type of information |
| 34 | * available to each of them. |
| 35 | */ |
| 36 | const unsigned int filt_cap[] = { |
| 37 | [ACL_HOOK_REQ_FE_TCP] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY, |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 38 | [ACL_HOOK_REQ_FE_TCP_CONTENT] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY, |
| 39 | [ACL_HOOK_REQ_FE_HTTP_IN] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 40 | [ACL_HOOK_REQ_FE_SWITCH] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 41 | [ACL_HOOK_REQ_BE_TCP_CONTENT] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 42 | [ACL_HOOK_REQ_BE_HTTP_IN] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 43 | [ACL_HOOK_REQ_BE_SWITCH] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 44 | [ACL_HOOK_REQ_FE_HTTP_OUT] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
| 45 | [ACL_HOOK_REQ_BE_HTTP_OUT] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY|ACL_USE_L6REQ_ANY|ACL_USE_L7REQ_ANY|ACL_USE_HDR_ANY, |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 46 | |
Willy Tarreau | 0645787 | 2010-05-23 12:24:38 +0200 | [diff] [blame] | 47 | [ACL_HOOK_RTR_BE_TCP_CONTENT] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY, |
| 48 | [ACL_HOOK_RTR_BE_HTTP_IN] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY|ACL_USE_L7RTR_ANY, |
| 49 | [ACL_HOOK_RTR_FE_TCP_CONTENT] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY|ACL_USE_L7RTR_ANY, |
| 50 | [ACL_HOOK_RTR_FE_HTTP_IN] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY|ACL_USE_L7RTR_ANY, |
| 51 | [ACL_HOOK_RTR_BE_HTTP_OUT] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY|ACL_USE_L7RTR_ANY, |
| 52 | [ACL_HOOK_RTR_FE_HTTP_OUT] = ACL_USE_REQ_PERMANENT|ACL_USE_REQ_CACHEABLE|ACL_USE_L6RTR_ANY|ACL_USE_L7RTR_ANY, |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 55 | /* List head of all known ACL keywords */ |
| 56 | static struct acl_kw_list acl_keywords = { |
| 57 | .list = LIST_HEAD_INIT(acl_keywords.list) |
| 58 | }; |
| 59 | |
| 60 | |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 61 | /* |
| 62 | * These functions are only used for debugging complex configurations. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 63 | */ |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 64 | |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 65 | /* force TRUE to be returned at the fetch level */ |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 66 | static int |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 67 | acl_fetch_true(struct proxy *px, struct session *l4, void *l7, int dir, |
| 68 | struct acl_expr *expr, struct acl_test *test) |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 69 | { |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 70 | test->flags |= ACL_TEST_F_SET_RES_PASS; |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 71 | return 1; |
| 72 | } |
| 73 | |
Willy Tarreau | b6fb420 | 2008-07-20 11:18:28 +0200 | [diff] [blame] | 74 | /* wait for more data as long as possible, then return TRUE. This should be |
| 75 | * used with content inspection. |
| 76 | */ |
| 77 | static int |
| 78 | acl_fetch_wait_end(struct proxy *px, struct session *l4, void *l7, int dir, |
| 79 | struct acl_expr *expr, struct acl_test *test) |
| 80 | { |
| 81 | if (dir & ACL_PARTIAL) { |
| 82 | test->flags |= ACL_TEST_F_MAY_CHANGE; |
| 83 | return 0; |
| 84 | } |
| 85 | test->flags |= ACL_TEST_F_SET_RES_PASS; |
| 86 | return 1; |
| 87 | } |
| 88 | |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 89 | /* force FALSE to be returned at the fetch level */ |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 90 | static int |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 91 | acl_fetch_false(struct proxy *px, struct session *l4, void *l7, int dir, |
| 92 | struct acl_expr *expr, struct acl_test *test) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 93 | { |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 94 | test->flags |= ACL_TEST_F_SET_RES_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 95 | return 1; |
| 96 | } |
| 97 | |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 98 | /* return the number of bytes in the request buffer */ |
| 99 | static int |
| 100 | acl_fetch_req_len(struct proxy *px, struct session *l4, void *l7, int dir, |
| 101 | struct acl_expr *expr, struct acl_test *test) |
| 102 | { |
| 103 | if (!l4 || !l4->req) |
| 104 | return 0; |
| 105 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 106 | temp_pattern.data.integer = l4->req->i; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 107 | test->flags = ACL_TEST_F_VOLATILE | ACL_TEST_F_MAY_CHANGE; |
| 108 | return 1; |
| 109 | } |
| 110 | |
Emeric Brun | 38e7176 | 2010-09-23 17:59:18 +0200 | [diff] [blame] | 111 | |
| 112 | static int |
| 113 | acl_fetch_ssl_hello_type(struct proxy *px, struct session *l4, void *l7, int dir, |
| 114 | struct acl_expr *expr, struct acl_test *test) |
| 115 | { |
| 116 | int hs_len; |
| 117 | int hs_type, bleft; |
| 118 | struct buffer *b; |
| 119 | const unsigned char *data; |
| 120 | |
| 121 | if (!l4) |
| 122 | goto not_ssl_hello; |
| 123 | |
| 124 | b = ((dir & ACL_DIR_MASK) == ACL_DIR_RTR) ? l4->rep : l4->req; |
| 125 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 126 | bleft = b->i; |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 127 | data = (const unsigned char *)b->p; |
Emeric Brun | 38e7176 | 2010-09-23 17:59:18 +0200 | [diff] [blame] | 128 | |
| 129 | if (!bleft) |
| 130 | goto too_short; |
| 131 | |
| 132 | if ((*data >= 0x14 && *data <= 0x17) || (*data == 0xFF)) { |
| 133 | /* SSLv3 header format */ |
| 134 | if (bleft < 9) |
| 135 | goto too_short; |
| 136 | |
| 137 | /* ssl version 3 */ |
| 138 | if ((data[1] << 16) + data[2] < 0x00030000) |
| 139 | goto not_ssl_hello; |
| 140 | |
| 141 | /* ssl message len must present handshake type and len */ |
| 142 | if ((data[3] << 8) + data[4] < 4) |
| 143 | goto not_ssl_hello; |
| 144 | |
| 145 | /* format introduced with SSLv3 */ |
| 146 | |
| 147 | hs_type = (int)data[5]; |
| 148 | hs_len = ( data[6] << 16 ) + ( data[7] << 8 ) + data[8]; |
| 149 | |
| 150 | /* not a full handshake */ |
| 151 | if (bleft < (9 + hs_len)) |
| 152 | goto too_short; |
| 153 | |
| 154 | } |
| 155 | else { |
| 156 | goto not_ssl_hello; |
| 157 | } |
| 158 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 159 | temp_pattern.data.integer = hs_type; |
Emeric Brun | 38e7176 | 2010-09-23 17:59:18 +0200 | [diff] [blame] | 160 | test->flags = ACL_TEST_F_VOLATILE; |
| 161 | |
| 162 | return 1; |
| 163 | |
| 164 | too_short: |
| 165 | test->flags = ACL_TEST_F_MAY_CHANGE; |
| 166 | |
| 167 | not_ssl_hello: |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 172 | /* Return the version of the SSL protocol in the request. It supports both |
| 173 | * SSLv3 (TLSv1) header format for any message, and SSLv2 header format for |
| 174 | * the hello message. The SSLv3 format is described in RFC 2246 p49, and the |
| 175 | * SSLv2 format is described here, and completed p67 of RFC 2246 : |
| 176 | * http://wp.netscape.com/eng/security/SSL_2.html |
| 177 | * |
| 178 | * Note: this decoder only works with non-wrapping data. |
| 179 | */ |
| 180 | static int |
| 181 | acl_fetch_req_ssl_ver(struct proxy *px, struct session *l4, void *l7, int dir, |
| 182 | struct acl_expr *expr, struct acl_test *test) |
| 183 | { |
| 184 | int version, bleft, msg_len; |
| 185 | const unsigned char *data; |
| 186 | |
| 187 | if (!l4 || !l4->req) |
| 188 | return 0; |
| 189 | |
| 190 | msg_len = 0; |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 191 | bleft = l4->req->i; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 192 | if (!bleft) |
| 193 | goto too_short; |
| 194 | |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 195 | data = (const unsigned char *)l4->req->p; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 196 | if ((*data >= 0x14 && *data <= 0x17) || (*data == 0xFF)) { |
| 197 | /* SSLv3 header format */ |
| 198 | if (bleft < 5) |
| 199 | goto too_short; |
| 200 | |
| 201 | version = (data[1] << 16) + data[2]; /* version: major, minor */ |
| 202 | msg_len = (data[3] << 8) + data[4]; /* record length */ |
| 203 | |
| 204 | /* format introduced with SSLv3 */ |
| 205 | if (version < 0x00030000) |
| 206 | goto not_ssl; |
| 207 | |
| 208 | /* message length between 1 and 2^14 + 2048 */ |
| 209 | if (msg_len < 1 || msg_len > ((1<<14) + 2048)) |
| 210 | goto not_ssl; |
| 211 | |
| 212 | bleft -= 5; data += 5; |
| 213 | } else { |
| 214 | /* SSLv2 header format, only supported for hello (msg type 1) */ |
| 215 | int rlen, plen, cilen, silen, chlen; |
| 216 | |
| 217 | if (*data & 0x80) { |
| 218 | if (bleft < 3) |
| 219 | goto too_short; |
| 220 | /* short header format : 15 bits for length */ |
| 221 | rlen = ((data[0] & 0x7F) << 8) | data[1]; |
| 222 | plen = 0; |
| 223 | bleft -= 2; data += 2; |
| 224 | } else { |
| 225 | if (bleft < 4) |
| 226 | goto too_short; |
| 227 | /* long header format : 14 bits for length + pad length */ |
| 228 | rlen = ((data[0] & 0x3F) << 8) | data[1]; |
| 229 | plen = data[2]; |
| 230 | bleft -= 3; data += 2; |
| 231 | } |
| 232 | |
| 233 | if (*data != 0x01) |
| 234 | goto not_ssl; |
| 235 | bleft--; data++; |
| 236 | |
| 237 | if (bleft < 8) |
| 238 | goto too_short; |
| 239 | version = (data[0] << 16) + data[1]; /* version: major, minor */ |
| 240 | cilen = (data[2] << 8) + data[3]; /* cipher len, multiple of 3 */ |
| 241 | silen = (data[4] << 8) + data[5]; /* session_id_len: 0 or 16 */ |
| 242 | chlen = (data[6] << 8) + data[7]; /* 16<=challenge length<=32 */ |
| 243 | |
| 244 | bleft -= 8; data += 8; |
| 245 | if (cilen % 3 != 0) |
| 246 | goto not_ssl; |
| 247 | if (silen && silen != 16) |
| 248 | goto not_ssl; |
| 249 | if (chlen < 16 || chlen > 32) |
| 250 | goto not_ssl; |
| 251 | if (rlen != 9 + cilen + silen + chlen) |
| 252 | goto not_ssl; |
| 253 | |
| 254 | /* focus on the remaining data length */ |
| 255 | msg_len = cilen + silen + chlen + plen; |
| 256 | } |
| 257 | /* We could recursively check that the buffer ends exactly on an SSL |
| 258 | * fragment boundary and that a possible next segment is still SSL, |
| 259 | * but that's a bit pointless. However, we could still check that |
| 260 | * all the part of the request which fits in a buffer is already |
| 261 | * there. |
| 262 | */ |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 263 | if (msg_len > buffer_max_len(l4->req) + l4->req->data - l4->req->p) |
| 264 | msg_len = buffer_max_len(l4->req) + l4->req->data - l4->req->p; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 265 | |
| 266 | if (bleft < msg_len) |
| 267 | goto too_short; |
| 268 | |
| 269 | /* OK that's enough. We have at least the whole message, and we have |
| 270 | * the protocol version. |
| 271 | */ |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 272 | temp_pattern.data.integer = version; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 273 | test->flags = ACL_TEST_F_VOLATILE; |
| 274 | return 1; |
| 275 | |
| 276 | too_short: |
| 277 | test->flags = ACL_TEST_F_MAY_CHANGE; |
| 278 | not_ssl: |
| 279 | return 0; |
| 280 | } |
| 281 | |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 282 | /* Try to extract the Server Name Indication that may be presented in a TLS |
| 283 | * client hello handshake message. The format of the message is the following |
| 284 | * (cf RFC5246 + RFC6066) : |
| 285 | * TLS frame : |
| 286 | * - uint8 type = 0x16 (Handshake) |
| 287 | * - uint16 version >= 0x0301 (TLSv1) |
| 288 | * - uint16 length (frame length) |
| 289 | * - TLS handshake : |
| 290 | * - uint8 msg_type = 0x01 (ClientHello) |
| 291 | * - uint24 length (handshake message length) |
| 292 | * - ClientHello : |
| 293 | * - uint16 client_version >= 0x0301 (TLSv1) |
Willy Tarreau | d017f11 | 2012-04-09 09:24:11 +0200 | [diff] [blame] | 294 | * - uint8 Random[32] (4 first ones are timestamp) |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 295 | * - SessionID : |
| 296 | * - uint8 session_id_len (0..32) (SessionID len in bytes) |
| 297 | * - uint8 session_id[session_id_len] |
| 298 | * - CipherSuite : |
| 299 | * - uint16 cipher_len >= 2 (Cipher length in bytes) |
| 300 | * - uint16 ciphers[cipher_len/2] |
| 301 | * - CompressionMethod : |
| 302 | * - uint8 compression_len >= 1 (# of supported methods) |
| 303 | * - uint8 compression_methods[compression_len] |
| 304 | * - optional client_extension_len (in bytes) |
| 305 | * - optional sequence of ClientHelloExtensions (as many bytes as above): |
| 306 | * - uint16 extension_type = 0 for server_name |
| 307 | * - uint16 extension_len |
| 308 | * - opaque extension_data[extension_len] |
| 309 | * - uint16 server_name_list_len (# of bytes here) |
| 310 | * - opaque server_names[server_name_list_len bytes] |
| 311 | * - uint8 name_type = 0 for host_name |
| 312 | * - uint16 name_len |
| 313 | * - opaque hostname[name_len bytes] |
| 314 | */ |
| 315 | static int |
| 316 | acl_fetch_ssl_hello_sni(struct proxy *px, struct session *l4, void *l7, int dir, |
| 317 | struct acl_expr *expr, struct acl_test *test) |
| 318 | { |
| 319 | int hs_len, ext_len, bleft; |
| 320 | struct buffer *b; |
| 321 | unsigned char *data; |
| 322 | |
| 323 | if (!l4) |
| 324 | goto not_ssl_hello; |
| 325 | |
| 326 | b = ((dir & ACL_DIR_MASK) == ACL_DIR_RTR) ? l4->rep : l4->req; |
| 327 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 328 | bleft = b->i; |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 329 | data = (unsigned char *)b->p; |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 330 | |
| 331 | /* Check for SSL/TLS Handshake */ |
| 332 | if (!bleft) |
| 333 | goto too_short; |
| 334 | if (*data != 0x16) |
| 335 | goto not_ssl_hello; |
| 336 | |
| 337 | /* Check for TLSv1 or later (SSL version >= 3.1) */ |
| 338 | if (bleft < 3) |
| 339 | goto too_short; |
| 340 | if (data[1] < 0x03 || data[2] < 0x01) |
| 341 | goto not_ssl_hello; |
| 342 | |
| 343 | if (bleft < 5) |
| 344 | goto too_short; |
| 345 | hs_len = (data[3] << 8) + data[4]; |
| 346 | if (hs_len < 1 + 3 + 2 + 32 + 1 + 2 + 2 + 1 + 1 + 2 + 2) |
| 347 | goto not_ssl_hello; /* too short to have an extension */ |
| 348 | |
| 349 | data += 5; /* enter TLS handshake */ |
| 350 | bleft -= 5; |
| 351 | |
| 352 | /* Check for a complete client hello starting at <data> */ |
| 353 | if (bleft < 1) |
| 354 | goto too_short; |
| 355 | if (data[0] != 0x01) /* msg_type = Client Hello */ |
| 356 | goto not_ssl_hello; |
| 357 | |
| 358 | /* Check the Hello's length */ |
| 359 | if (bleft < 4) |
| 360 | goto too_short; |
| 361 | hs_len = (data[1] << 16) + (data[2] << 8) + data[3]; |
| 362 | if (hs_len < 2 + 32 + 1 + 2 + 2 + 1 + 1 + 2 + 2) |
| 363 | goto not_ssl_hello; /* too short to have an extension */ |
| 364 | |
| 365 | /* We want the full handshake here */ |
| 366 | if (bleft < hs_len) |
| 367 | goto too_short; |
| 368 | |
| 369 | data += 4; |
| 370 | /* Start of the ClientHello message */ |
| 371 | if (data[0] < 0x03 || data[1] < 0x01) /* TLSv1 minimum */ |
| 372 | goto not_ssl_hello; |
| 373 | |
Willy Tarreau | d017f11 | 2012-04-09 09:24:11 +0200 | [diff] [blame] | 374 | ext_len = data[34]; /* session_id_len */ |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 375 | if (ext_len > 32 || ext_len > (hs_len - 35)) /* check for correct session_id len */ |
| 376 | goto not_ssl_hello; |
| 377 | |
| 378 | /* Jump to cipher suite */ |
| 379 | hs_len -= 35 + ext_len; |
| 380 | data += 35 + ext_len; |
| 381 | |
| 382 | if (hs_len < 4 || /* minimum one cipher */ |
| 383 | (ext_len = (data[0] << 8) + data[1]) < 2 || /* minimum 2 bytes for a cipher */ |
| 384 | ext_len > hs_len) |
| 385 | goto not_ssl_hello; |
| 386 | |
| 387 | /* Jump to the compression methods */ |
| 388 | hs_len -= 2 + ext_len; |
| 389 | data += 2 + ext_len; |
| 390 | |
| 391 | if (hs_len < 2 || /* minimum one compression method */ |
| 392 | data[0] < 1 || data[0] > hs_len) /* minimum 1 bytes for a method */ |
| 393 | goto not_ssl_hello; |
| 394 | |
| 395 | /* Jump to the extensions */ |
| 396 | hs_len -= 1 + data[0]; |
| 397 | data += 1 + data[0]; |
| 398 | |
| 399 | if (hs_len < 2 || /* minimum one extension list length */ |
| 400 | (ext_len = (data[0] << 8) + data[1]) > hs_len - 2) /* list too long */ |
| 401 | goto not_ssl_hello; |
| 402 | |
| 403 | hs_len = ext_len; /* limit ourselves to the extension length */ |
| 404 | data += 2; |
| 405 | |
| 406 | while (hs_len >= 4) { |
| 407 | int ext_type, name_type, srv_len, name_len; |
| 408 | |
| 409 | ext_type = (data[0] << 8) + data[1]; |
| 410 | ext_len = (data[2] << 8) + data[3]; |
| 411 | |
| 412 | if (ext_len > hs_len - 4) /* Extension too long */ |
| 413 | goto not_ssl_hello; |
| 414 | |
| 415 | if (ext_type == 0) { /* Server name */ |
| 416 | if (ext_len < 2) /* need one list length */ |
| 417 | goto not_ssl_hello; |
| 418 | |
| 419 | srv_len = (data[4] << 8) + data[5]; |
| 420 | if (srv_len < 4 || srv_len > hs_len - 6) |
| 421 | goto not_ssl_hello; /* at least 4 bytes per server name */ |
| 422 | |
| 423 | name_type = data[6]; |
| 424 | name_len = (data[7] << 8) + data[8]; |
| 425 | |
| 426 | if (name_type == 0) { /* hostname */ |
Willy Tarreau | 62e7c71 | 2012-03-10 09:05:30 +0100 | [diff] [blame] | 427 | temp_pattern.data.str.str = (char *)data + 9; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 428 | temp_pattern.data.str.len = name_len; |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 429 | test->flags = ACL_TEST_F_VOLATILE; |
Willy Tarreau | b6672b5 | 2011-12-12 17:23:41 +0100 | [diff] [blame] | 430 | return 1; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | hs_len -= 4 + ext_len; |
| 435 | data += 4 + ext_len; |
| 436 | } |
| 437 | /* server name not found */ |
| 438 | goto not_ssl_hello; |
| 439 | |
| 440 | too_short: |
| 441 | test->flags = ACL_TEST_F_MAY_CHANGE; |
| 442 | |
| 443 | not_ssl_hello: |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 448 | /* Fetch the RDP cookie identified in the expression. |
| 449 | * Note: this decoder only works with non-wrapping data. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 450 | * Accepts either 0 or 1 argument. Argument is a string (cookie name), other |
| 451 | * types will lead to undefined behaviour. |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 452 | */ |
| 453 | int |
| 454 | acl_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, int dir, |
| 455 | struct acl_expr *expr, struct acl_test *test) |
| 456 | { |
| 457 | int bleft; |
| 458 | const unsigned char *data; |
| 459 | |
| 460 | if (!l4 || !l4->req) |
| 461 | return 0; |
| 462 | |
| 463 | test->flags = 0; |
| 464 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 465 | bleft = l4->req->i; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 466 | if (bleft <= 11) |
| 467 | goto too_short; |
| 468 | |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 469 | data = (const unsigned char *)l4->req->p + 11; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 470 | bleft -= 11; |
| 471 | |
| 472 | if (bleft <= 7) |
| 473 | goto too_short; |
| 474 | |
| 475 | if (strncasecmp((const char *)data, "Cookie:", 7) != 0) |
| 476 | goto not_cookie; |
| 477 | |
| 478 | data += 7; |
| 479 | bleft -= 7; |
| 480 | |
| 481 | while (bleft > 0 && *data == ' ') { |
| 482 | data++; |
| 483 | bleft--; |
| 484 | } |
| 485 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 486 | if (expr->args) { |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 487 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 488 | if (bleft <= expr->args->data.str.len) |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 489 | goto too_short; |
| 490 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 491 | if ((data[expr->args->data.str.len] != '=') || |
| 492 | strncasecmp(expr->args->data.str.str, (const char *)data, expr->args->data.str.len) != 0) |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 493 | goto not_cookie; |
| 494 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 495 | data += expr->args->data.str.len + 1; |
| 496 | bleft -= expr->args->data.str.len + 1; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 497 | } else { |
| 498 | while (bleft > 0 && *data != '=') { |
| 499 | if (*data == '\r' || *data == '\n') |
| 500 | goto not_cookie; |
| 501 | data++; |
| 502 | bleft--; |
| 503 | } |
| 504 | |
| 505 | if (bleft < 1) |
| 506 | goto too_short; |
| 507 | |
| 508 | if (*data != '=') |
| 509 | goto not_cookie; |
| 510 | |
| 511 | data++; |
| 512 | bleft--; |
| 513 | } |
| 514 | |
| 515 | /* data points to cookie value */ |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 516 | temp_pattern.data.str.str = (char *)data; |
| 517 | temp_pattern.data.str.len = 0; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 518 | |
| 519 | while (bleft > 0 && *data != '\r') { |
| 520 | data++; |
| 521 | bleft--; |
| 522 | } |
| 523 | |
| 524 | if (bleft < 2) |
| 525 | goto too_short; |
| 526 | |
| 527 | if (data[0] != '\r' || data[1] != '\n') |
| 528 | goto not_cookie; |
| 529 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 530 | temp_pattern.data.str.len = (char *)data - temp_pattern.data.str.str; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 531 | test->flags = ACL_TEST_F_VOLATILE; |
| 532 | return 1; |
| 533 | |
| 534 | too_short: |
| 535 | test->flags = ACL_TEST_F_MAY_CHANGE; |
| 536 | not_cookie: |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int |
| 541 | acl_fetch_rdp_cookie_cnt(struct proxy *px, struct session *l4, void *l7, int dir, |
| 542 | struct acl_expr *expr, struct acl_test *test) |
| 543 | { |
| 544 | int ret; |
| 545 | |
| 546 | ret = acl_fetch_rdp_cookie(px, l4, l7, dir, expr, test); |
| 547 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 548 | temp_pattern.data.str.str = NULL; |
| 549 | temp_pattern.data.str.len = 0; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 550 | |
| 551 | if (test->flags & ACL_TEST_F_MAY_CHANGE) |
| 552 | return 0; |
| 553 | |
| 554 | test->flags = ACL_TEST_F_VOLATILE; |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 555 | temp_pattern.data.integer = ret; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 556 | |
| 557 | return 1; |
| 558 | } |
| 559 | |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 560 | |
| 561 | /* |
| 562 | * These functions are exported and may be used by any other component. |
| 563 | */ |
| 564 | |
| 565 | /* ignore the current line */ |
| 566 | int acl_parse_nothing(const char **text, struct acl_pattern *pattern, int *opaque) |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 567 | { |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 568 | return 1; |
| 569 | } |
| 570 | |
| 571 | /* always fake a data retrieval */ |
| 572 | int acl_fetch_nothing(struct proxy *px, struct session *l4, void *l7, int dir, |
| 573 | struct acl_expr *expr, struct acl_test *test) |
| 574 | { |
| 575 | return 1; |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* always return false */ |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 579 | int acl_match_nothing(struct acl_test *test, struct acl_pattern *pattern) |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 580 | { |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 581 | return ACL_PAT_FAIL; |
Willy Tarreau | a590983 | 2007-06-17 20:40:25 +0200 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 585 | /* NB: For two strings to be identical, it is required that their lengths match */ |
| 586 | int acl_match_str(struct acl_test *test, struct acl_pattern *pattern) |
| 587 | { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 588 | int icase; |
| 589 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 590 | if (pattern->len != temp_pattern.data.str.len) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 591 | return ACL_PAT_FAIL; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 592 | |
| 593 | icase = pattern->flags & ACL_PAT_F_IGNORE_CASE; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 594 | if ((icase && strncasecmp(pattern->ptr.str, temp_pattern.data.str.str, temp_pattern.data.str.len) == 0) || |
| 595 | (!icase && strncmp(pattern->ptr.str, temp_pattern.data.str.str, temp_pattern.data.str.len) == 0)) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 596 | return ACL_PAT_PASS; |
| 597 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 600 | /* Lookup a string in the expression's pattern tree. The node is returned if it |
| 601 | * exists, otherwise NULL. |
| 602 | */ |
| 603 | void *acl_lookup_str(struct acl_test *test, struct acl_expr *expr) |
| 604 | { |
| 605 | /* data are stored in a tree */ |
| 606 | struct ebmb_node *node; |
| 607 | char prev; |
| 608 | |
| 609 | /* we may have to force a trailing zero on the test pattern */ |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 610 | prev = temp_pattern.data.str.str[temp_pattern.data.str.len]; |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 611 | if (prev) |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 612 | temp_pattern.data.str.str[temp_pattern.data.str.len] = '\0'; |
| 613 | node = ebst_lookup(&expr->pattern_tree, temp_pattern.data.str.str); |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 614 | if (prev) |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 615 | temp_pattern.data.str.str[temp_pattern.data.str.len] = prev; |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 616 | return node; |
| 617 | } |
| 618 | |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 619 | /* Executes a regex. It needs to change the data. If it is marked READ_ONLY |
| 620 | * then it will be allocated and duplicated in place so that others may use |
| 621 | * it later on. Note that this is embarrassing because we always try to avoid |
| 622 | * allocating memory at run time. |
| 623 | */ |
| 624 | int acl_match_reg(struct acl_test *test, struct acl_pattern *pattern) |
| 625 | { |
| 626 | char old_char; |
| 627 | int ret; |
| 628 | |
| 629 | if (unlikely(test->flags & ACL_TEST_F_READ_ONLY)) { |
| 630 | char *new_str; |
| 631 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 632 | new_str = calloc(1, temp_pattern.data.str.len + 1); |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 633 | if (!new_str) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 634 | return ACL_PAT_FAIL; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 635 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 636 | memcpy(new_str, temp_pattern.data.str.str, temp_pattern.data.str.len); |
| 637 | new_str[temp_pattern.data.str.len] = 0; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 638 | if (test->flags & ACL_TEST_F_MUST_FREE) |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 639 | free(temp_pattern.data.str.str); |
| 640 | temp_pattern.data.str.str = new_str; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 641 | test->flags |= ACL_TEST_F_MUST_FREE; |
| 642 | test->flags &= ~ACL_TEST_F_READ_ONLY; |
| 643 | } |
| 644 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 645 | old_char = temp_pattern.data.str.str[temp_pattern.data.str.len]; |
| 646 | temp_pattern.data.str.str[temp_pattern.data.str.len] = 0; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 647 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 648 | if (regexec(pattern->ptr.reg, temp_pattern.data.str.str, 0, NULL, 0) == 0) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 649 | ret = ACL_PAT_PASS; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 650 | else |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 651 | ret = ACL_PAT_FAIL; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 652 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 653 | temp_pattern.data.str.str[temp_pattern.data.str.len] = old_char; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 654 | return ret; |
| 655 | } |
| 656 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 657 | /* Checks that the pattern matches the beginning of the tested string. */ |
| 658 | int acl_match_beg(struct acl_test *test, struct acl_pattern *pattern) |
| 659 | { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 660 | int icase; |
| 661 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 662 | if (pattern->len > temp_pattern.data.str.len) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 663 | return ACL_PAT_FAIL; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 664 | |
| 665 | icase = pattern->flags & ACL_PAT_F_IGNORE_CASE; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 666 | if ((icase && strncasecmp(pattern->ptr.str, temp_pattern.data.str.str, pattern->len) != 0) || |
| 667 | (!icase && strncmp(pattern->ptr.str, temp_pattern.data.str.str, pattern->len) != 0)) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 668 | return ACL_PAT_FAIL; |
| 669 | return ACL_PAT_PASS; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /* Checks that the pattern matches the end of the tested string. */ |
| 673 | int acl_match_end(struct acl_test *test, struct acl_pattern *pattern) |
| 674 | { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 675 | int icase; |
| 676 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 677 | if (pattern->len > temp_pattern.data.str.len) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 678 | return ACL_PAT_FAIL; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 679 | icase = pattern->flags & ACL_PAT_F_IGNORE_CASE; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 680 | if ((icase && strncasecmp(pattern->ptr.str, temp_pattern.data.str.str + temp_pattern.data.str.len - pattern->len, pattern->len) != 0) || |
| 681 | (!icase && strncmp(pattern->ptr.str, temp_pattern.data.str.str + temp_pattern.data.str.len - pattern->len, pattern->len) != 0)) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 682 | return ACL_PAT_FAIL; |
| 683 | return ACL_PAT_PASS; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* Checks that the pattern is included inside the tested string. |
| 687 | * NB: Suboptimal, should be rewritten using a Boyer-Moore method. |
| 688 | */ |
| 689 | int acl_match_sub(struct acl_test *test, struct acl_pattern *pattern) |
| 690 | { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 691 | int icase; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 692 | char *end; |
| 693 | char *c; |
| 694 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 695 | if (pattern->len > temp_pattern.data.str.len) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 696 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 697 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 698 | end = temp_pattern.data.str.str + temp_pattern.data.str.len - pattern->len; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 699 | icase = pattern->flags & ACL_PAT_F_IGNORE_CASE; |
| 700 | if (icase) { |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 701 | for (c = temp_pattern.data.str.str; c <= end; c++) { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 702 | if (tolower(*c) != tolower(*pattern->ptr.str)) |
| 703 | continue; |
| 704 | if (strncasecmp(pattern->ptr.str, c, pattern->len) == 0) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 705 | return ACL_PAT_PASS; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 706 | } |
| 707 | } else { |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 708 | for (c = temp_pattern.data.str.str; c <= end; c++) { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 709 | if (*c != *pattern->ptr.str) |
| 710 | continue; |
| 711 | if (strncmp(pattern->ptr.str, c, pattern->len) == 0) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 712 | return ACL_PAT_PASS; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 713 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 714 | } |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 715 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 716 | } |
| 717 | |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 718 | /* Background: Fast way to find a zero byte in a word |
| 719 | * http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord |
| 720 | * hasZeroByte = (v - 0x01010101UL) & ~v & 0x80808080UL; |
| 721 | * |
| 722 | * To look for 4 different byte values, xor the word with those bytes and |
| 723 | * then check for zero bytes: |
| 724 | * |
| 725 | * v = (((unsigned char)c * 0x1010101U) ^ delimiter) |
| 726 | * where <delimiter> is the 4 byte values to look for (as an uint) |
| 727 | * and <c> is the character that is being tested |
| 728 | */ |
| 729 | static inline unsigned int is_delimiter(unsigned char c, unsigned int mask) |
| 730 | { |
| 731 | mask ^= (c * 0x01010101); /* propagate the char to all 4 bytes */ |
| 732 | return (mask - 0x01010101) & ~mask & 0x80808080U; |
| 733 | } |
| 734 | |
| 735 | static inline unsigned int make_4delim(unsigned char d1, unsigned char d2, unsigned char d3, unsigned char d4) |
| 736 | { |
| 737 | return d1 << 24 | d2 << 16 | d3 << 8 | d4; |
| 738 | } |
| 739 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 740 | /* This one is used by other real functions. It checks that the pattern is |
| 741 | * included inside the tested string, but enclosed between the specified |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 742 | * delimiters or at the beginning or end of the string. The delimiters are |
| 743 | * provided as an unsigned int made by make_4delim() and match up to 4 different |
| 744 | * delimiters. Delimiters are stripped at the beginning and end of the pattern. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 745 | */ |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 746 | static int match_word(struct acl_test *test, struct acl_pattern *pattern, unsigned int delimiters) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 747 | { |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 748 | int may_match, icase; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 749 | char *c, *end; |
| 750 | char *ps; |
| 751 | int pl; |
| 752 | |
| 753 | pl = pattern->len; |
| 754 | ps = pattern->ptr.str; |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 755 | |
| 756 | while (pl > 0 && is_delimiter(*ps, delimiters)) { |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 757 | pl--; |
| 758 | ps++; |
| 759 | } |
| 760 | |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 761 | while (pl > 0 && is_delimiter(ps[pl - 1], delimiters)) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 762 | pl--; |
| 763 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 764 | if (pl > temp_pattern.data.str.len) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 765 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 766 | |
| 767 | may_match = 1; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 768 | icase = pattern->flags & ACL_PAT_F_IGNORE_CASE; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 769 | end = temp_pattern.data.str.str + temp_pattern.data.str.len - pl; |
| 770 | for (c = temp_pattern.data.str.str; c <= end; c++) { |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 771 | if (is_delimiter(*c, delimiters)) { |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 772 | may_match = 1; |
| 773 | continue; |
| 774 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 775 | |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 776 | if (!may_match) |
| 777 | continue; |
| 778 | |
| 779 | if (icase) { |
| 780 | if ((tolower(*c) == tolower(*ps)) && |
| 781 | (strncasecmp(ps, c, pl) == 0) && |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 782 | (c == end || is_delimiter(c[pl], delimiters))) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 783 | return ACL_PAT_PASS; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 784 | } else { |
| 785 | if ((*c == *ps) && |
| 786 | (strncmp(ps, c, pl) == 0) && |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 787 | (c == end || is_delimiter(c[pl], delimiters))) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 788 | return ACL_PAT_PASS; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 789 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 790 | may_match = 0; |
| 791 | } |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 792 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* Checks that the pattern is included inside the tested string, but enclosed |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 796 | * between the delimiters '?' or '/' or at the beginning or end of the string. |
| 797 | * Delimiters at the beginning or end of the pattern are ignored. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 798 | */ |
| 799 | int acl_match_dir(struct acl_test *test, struct acl_pattern *pattern) |
| 800 | { |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 801 | return match_word(test, pattern, make_4delim('/', '?', '?', '?')); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /* Checks that the pattern is included inside the tested string, but enclosed |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 805 | * between the delmiters '/', '?', '.' or ":" or at the beginning or end of |
| 806 | * the string. Delimiters at the beginning or end of the pattern are ignored. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 807 | */ |
| 808 | int acl_match_dom(struct acl_test *test, struct acl_pattern *pattern) |
| 809 | { |
Finn Arne Gangstad | e8c7ecc | 2011-09-09 16:09:50 +0200 | [diff] [blame] | 810 | return match_word(test, pattern, make_4delim('/', '?', '.', ':')); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* Checks that the integer in <test> is included between min and max */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 814 | int acl_match_int(struct acl_test *test, struct acl_pattern *pattern) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 815 | { |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 816 | if ((!pattern->val.range.min_set || pattern->val.range.min <= temp_pattern.data.integer) && |
| 817 | (!pattern->val.range.max_set || temp_pattern.data.integer <= pattern->val.range.max)) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 818 | return ACL_PAT_PASS; |
| 819 | return ACL_PAT_FAIL; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 820 | } |
| 821 | |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 822 | /* Checks that the length of the pattern in <test> is included between min and max */ |
| 823 | int acl_match_len(struct acl_test *test, struct acl_pattern *pattern) |
| 824 | { |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 825 | if ((!pattern->val.range.min_set || pattern->val.range.min <= temp_pattern.data.str.len) && |
| 826 | (!pattern->val.range.max_set || temp_pattern.data.str.len <= pattern->val.range.max)) |
Willy Tarreau | 0e69854 | 2011-09-16 08:32:32 +0200 | [diff] [blame] | 827 | return ACL_PAT_PASS; |
| 828 | return ACL_PAT_FAIL; |
| 829 | } |
| 830 | |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 831 | int acl_match_ip(struct acl_test *test, struct acl_pattern *pattern) |
| 832 | { |
| 833 | struct in_addr *s; |
| 834 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 835 | if (temp_pattern.type != PATTERN_TYPE_IP) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 836 | return ACL_PAT_FAIL; |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 837 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 838 | s = &temp_pattern.data.ip; |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 839 | if (((s->s_addr ^ pattern->val.ipv4.addr.s_addr) & pattern->val.ipv4.mask.s_addr) == 0) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 840 | return ACL_PAT_PASS; |
| 841 | return ACL_PAT_FAIL; |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 844 | /* Lookup an IPv4 address in the expression's pattern tree using the longest |
| 845 | * match method. The node is returned if it exists, otherwise NULL. |
| 846 | */ |
| 847 | void *acl_lookup_ip(struct acl_test *test, struct acl_expr *expr) |
| 848 | { |
| 849 | struct in_addr *s; |
| 850 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 851 | if (temp_pattern.type != PATTERN_TYPE_IP) |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 852 | return ACL_PAT_FAIL; |
| 853 | |
Willy Tarreau | f4362b3 | 2011-12-16 17:49:52 +0100 | [diff] [blame] | 854 | s = &temp_pattern.data.ip; |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 855 | return ebmb_lookup_longest(&expr->pattern_tree, &s->s_addr); |
| 856 | } |
| 857 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 858 | /* Parse a string. It is allocated and duplicated. */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 859 | int acl_parse_str(const char **text, struct acl_pattern *pattern, int *opaque) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 860 | { |
| 861 | int len; |
| 862 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 863 | len = strlen(*text); |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 864 | |
| 865 | if (pattern->flags & ACL_PAT_F_TREE_OK) { |
| 866 | /* we're allowed to put the data in a tree whose root is pointed |
| 867 | * to by val.tree. |
| 868 | */ |
| 869 | struct ebmb_node *node; |
| 870 | |
| 871 | node = calloc(1, sizeof(*node) + len + 1); |
| 872 | if (!node) |
| 873 | return 0; |
| 874 | memcpy(node->key, *text, len + 1); |
| 875 | if (ebst_insert(pattern->val.tree, node) != node) |
| 876 | free(node); /* was a duplicate */ |
| 877 | pattern->flags |= ACL_PAT_F_TREE; /* this pattern now contains a tree */ |
| 878 | return 1; |
| 879 | } |
| 880 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 881 | pattern->ptr.str = strdup(*text); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 882 | if (!pattern->ptr.str) |
| 883 | return 0; |
| 884 | pattern->len = len; |
| 885 | return 1; |
| 886 | } |
| 887 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 888 | /* Parse and concatenate all further strings into one. */ |
| 889 | int |
| 890 | acl_parse_strcat(const char **text, struct acl_pattern *pattern, int *opaque) |
| 891 | { |
| 892 | |
| 893 | int len = 0, i; |
| 894 | char *s; |
| 895 | |
| 896 | for (i = 0; *text[i]; i++) |
| 897 | len += strlen(text[i])+1; |
| 898 | |
| 899 | pattern->ptr.str = s = calloc(1, len); |
| 900 | if (!pattern->ptr.str) |
| 901 | return 0; |
| 902 | |
| 903 | for (i = 0; *text[i]; i++) |
| 904 | s += sprintf(s, i?" %s":"%s", text[i]); |
| 905 | |
| 906 | pattern->len = len; |
| 907 | |
| 908 | return i; |
| 909 | } |
| 910 | |
Krzysztof Piotr Oledzki | 8001d61 | 2008-05-31 13:53:23 +0200 | [diff] [blame] | 911 | /* Free data allocated by acl_parse_reg */ |
| 912 | static void acl_free_reg(void *ptr) { |
| 913 | |
| 914 | regfree((regex_t *)ptr); |
| 915 | } |
| 916 | |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 917 | /* Parse a regex. It is allocated. */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 918 | int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque) |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 919 | { |
| 920 | regex_t *preg; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 921 | int icase; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 922 | |
| 923 | preg = calloc(1, sizeof(regex_t)); |
| 924 | |
| 925 | if (!preg) |
| 926 | return 0; |
| 927 | |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 928 | icase = (pattern->flags & ACL_PAT_F_IGNORE_CASE) ? REG_ICASE : 0; |
| 929 | if (regcomp(preg, *text, REG_EXTENDED | REG_NOSUB | icase) != 0) { |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 930 | free(preg); |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | pattern->ptr.reg = preg; |
Krzysztof Piotr Oledzki | 8001d61 | 2008-05-31 13:53:23 +0200 | [diff] [blame] | 935 | pattern->freeptrbuf = &acl_free_reg; |
Willy Tarreau | f3d2598 | 2007-05-08 22:45:09 +0200 | [diff] [blame] | 936 | return 1; |
| 937 | } |
| 938 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 939 | /* Parse a range of positive integers delimited by either ':' or '-'. If only |
| 940 | * one integer is read, it is set as both min and max. An operator may be |
| 941 | * specified as the prefix, among this list of 5 : |
| 942 | * |
| 943 | * 0:eq, 1:gt, 2:ge, 3:lt, 4:le |
| 944 | * |
| 945 | * The default operator is "eq". It supports range matching. Ranges are |
| 946 | * rejected for other operators. The operator may be changed at any time. |
| 947 | * The operator is stored in the 'opaque' argument. |
| 948 | * |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 949 | */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 950 | int acl_parse_int(const char **text, struct acl_pattern *pattern, int *opaque) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 951 | { |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 952 | signed long long i; |
| 953 | unsigned int j, last, skip = 0; |
| 954 | const char *ptr = *text; |
| 955 | |
| 956 | |
Willy Tarreau | 8f8e645 | 2007-06-17 21:51:38 +0200 | [diff] [blame] | 957 | while (!isdigit((unsigned char)*ptr)) { |
Willy Tarreau | 1c7cc5b | 2010-07-18 10:46:33 +0200 | [diff] [blame] | 958 | switch (get_std_op(ptr)) { |
| 959 | case STD_OP_EQ: *opaque = 0; break; |
| 960 | case STD_OP_GT: *opaque = 1; break; |
| 961 | case STD_OP_GE: *opaque = 2; break; |
| 962 | case STD_OP_LT: *opaque = 3; break; |
| 963 | case STD_OP_LE: *opaque = 4; break; |
| 964 | default: |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 965 | return 0; |
Willy Tarreau | 1c7cc5b | 2010-07-18 10:46:33 +0200 | [diff] [blame] | 966 | } |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 967 | |
| 968 | skip++; |
| 969 | ptr = text[skip]; |
| 970 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 971 | |
| 972 | last = i = 0; |
| 973 | while (1) { |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 974 | j = *ptr++; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 975 | if ((j == '-' || j == ':') && !last) { |
| 976 | last++; |
| 977 | pattern->val.range.min = i; |
| 978 | i = 0; |
| 979 | continue; |
| 980 | } |
| 981 | j -= '0'; |
| 982 | if (j > 9) |
| 983 | // also catches the terminating zero |
| 984 | break; |
| 985 | i *= 10; |
| 986 | i += j; |
| 987 | } |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 988 | |
| 989 | if (last && *opaque >= 1 && *opaque <= 4) |
| 990 | /* having a range with a min or a max is absurd */ |
| 991 | return 0; |
| 992 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 993 | if (!last) |
| 994 | pattern->val.range.min = i; |
| 995 | pattern->val.range.max = i; |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 996 | |
| 997 | switch (*opaque) { |
| 998 | case 0: /* eq */ |
| 999 | pattern->val.range.min_set = 1; |
| 1000 | pattern->val.range.max_set = 1; |
| 1001 | break; |
| 1002 | case 1: /* gt */ |
| 1003 | pattern->val.range.min++; /* gt = ge + 1 */ |
| 1004 | case 2: /* ge */ |
| 1005 | pattern->val.range.min_set = 1; |
| 1006 | pattern->val.range.max_set = 0; |
| 1007 | break; |
| 1008 | case 3: /* lt */ |
| 1009 | pattern->val.range.max--; /* lt = le - 1 */ |
| 1010 | case 4: /* le */ |
| 1011 | pattern->val.range.min_set = 0; |
| 1012 | pattern->val.range.max_set = 1; |
| 1013 | break; |
| 1014 | } |
| 1015 | return skip + 1; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
Willy Tarreau | 4a26d2f | 2008-07-15 16:05:33 +0200 | [diff] [blame] | 1018 | /* Parse a range of positive 2-component versions delimited by either ':' or |
| 1019 | * '-'. The version consists in a major and a minor, both of which must be |
| 1020 | * smaller than 65536, because internally they will be represented as a 32-bit |
| 1021 | * integer. |
| 1022 | * If only one version is read, it is set as both min and max. Just like for |
| 1023 | * pure integers, an operator may be specified as the prefix, among this list |
| 1024 | * of 5 : |
| 1025 | * |
| 1026 | * 0:eq, 1:gt, 2:ge, 3:lt, 4:le |
| 1027 | * |
| 1028 | * The default operator is "eq". It supports range matching. Ranges are |
| 1029 | * rejected for other operators. The operator may be changed at any time. |
| 1030 | * The operator is stored in the 'opaque' argument. This allows constructs |
| 1031 | * such as the following one : |
| 1032 | * |
| 1033 | * acl obsolete_ssl ssl_req_proto lt 3 |
| 1034 | * acl unsupported_ssl ssl_req_proto gt 3.1 |
| 1035 | * acl valid_ssl ssl_req_proto 3.0-3.1 |
| 1036 | * |
| 1037 | */ |
| 1038 | int acl_parse_dotted_ver(const char **text, struct acl_pattern *pattern, int *opaque) |
| 1039 | { |
| 1040 | signed long long i; |
| 1041 | unsigned int j, last, skip = 0; |
| 1042 | const char *ptr = *text; |
| 1043 | |
| 1044 | |
| 1045 | while (!isdigit((unsigned char)*ptr)) { |
Willy Tarreau | 1c7cc5b | 2010-07-18 10:46:33 +0200 | [diff] [blame] | 1046 | switch (get_std_op(ptr)) { |
| 1047 | case STD_OP_EQ: *opaque = 0; break; |
| 1048 | case STD_OP_GT: *opaque = 1; break; |
| 1049 | case STD_OP_GE: *opaque = 2; break; |
| 1050 | case STD_OP_LT: *opaque = 3; break; |
| 1051 | case STD_OP_LE: *opaque = 4; break; |
| 1052 | default: |
Willy Tarreau | 4a26d2f | 2008-07-15 16:05:33 +0200 | [diff] [blame] | 1053 | return 0; |
Willy Tarreau | 1c7cc5b | 2010-07-18 10:46:33 +0200 | [diff] [blame] | 1054 | } |
Willy Tarreau | 4a26d2f | 2008-07-15 16:05:33 +0200 | [diff] [blame] | 1055 | |
| 1056 | skip++; |
| 1057 | ptr = text[skip]; |
| 1058 | } |
| 1059 | |
| 1060 | last = i = 0; |
| 1061 | while (1) { |
| 1062 | j = *ptr++; |
| 1063 | if (j == '.') { |
| 1064 | /* minor part */ |
| 1065 | if (i >= 65536) |
| 1066 | return 0; |
| 1067 | i <<= 16; |
| 1068 | continue; |
| 1069 | } |
| 1070 | if ((j == '-' || j == ':') && !last) { |
| 1071 | last++; |
| 1072 | if (i < 65536) |
| 1073 | i <<= 16; |
| 1074 | pattern->val.range.min = i; |
| 1075 | i = 0; |
| 1076 | continue; |
| 1077 | } |
| 1078 | j -= '0'; |
| 1079 | if (j > 9) |
| 1080 | // also catches the terminating zero |
| 1081 | break; |
| 1082 | i = (i & 0xFFFF0000) + (i & 0xFFFF) * 10; |
| 1083 | i += j; |
| 1084 | } |
| 1085 | |
| 1086 | /* if we only got a major version, let's shift it now */ |
| 1087 | if (i < 65536) |
| 1088 | i <<= 16; |
| 1089 | |
| 1090 | if (last && *opaque >= 1 && *opaque <= 4) |
| 1091 | /* having a range with a min or a max is absurd */ |
| 1092 | return 0; |
| 1093 | |
| 1094 | if (!last) |
| 1095 | pattern->val.range.min = i; |
| 1096 | pattern->val.range.max = i; |
| 1097 | |
| 1098 | switch (*opaque) { |
| 1099 | case 0: /* eq */ |
| 1100 | pattern->val.range.min_set = 1; |
| 1101 | pattern->val.range.max_set = 1; |
| 1102 | break; |
| 1103 | case 1: /* gt */ |
| 1104 | pattern->val.range.min++; /* gt = ge + 1 */ |
| 1105 | case 2: /* ge */ |
| 1106 | pattern->val.range.min_set = 1; |
| 1107 | pattern->val.range.max_set = 0; |
| 1108 | break; |
| 1109 | case 3: /* lt */ |
| 1110 | pattern->val.range.max--; /* lt = le - 1 */ |
| 1111 | case 4: /* le */ |
| 1112 | pattern->val.range.min_set = 0; |
| 1113 | pattern->val.range.max_set = 1; |
| 1114 | break; |
| 1115 | } |
| 1116 | return skip + 1; |
| 1117 | } |
| 1118 | |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 1119 | /* Parse an IP address and an optional mask in the form addr[/mask]. |
| 1120 | * The addr may either be an IPv4 address or a hostname. The mask |
| 1121 | * may either be a dotted mask or a number of bits. Returns 1 if OK, |
| 1122 | * otherwise 0. |
| 1123 | */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1124 | int acl_parse_ip(const char **text, struct acl_pattern *pattern, int *opaque) |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 1125 | { |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 1126 | struct eb_root *tree = NULL; |
| 1127 | if (pattern->flags & ACL_PAT_F_TREE_OK) |
| 1128 | tree = pattern->val.tree; |
| 1129 | |
| 1130 | if (str2net(*text, &pattern->val.ipv4.addr, &pattern->val.ipv4.mask)) { |
| 1131 | unsigned int mask = ntohl(pattern->val.ipv4.mask.s_addr); |
| 1132 | struct ebmb_node *node; |
| 1133 | /* check if the mask is contiguous so that we can insert the |
| 1134 | * network into the tree. A continuous mask has only ones on |
| 1135 | * the left. This means that this mask + its lower bit added |
| 1136 | * once again is null. |
| 1137 | */ |
| 1138 | if (mask + (mask & -mask) == 0 && tree) { |
| 1139 | mask = mask ? 33 - flsnz(mask & -mask) : 0; /* equals cidr value */ |
| 1140 | /* FIXME: insert <addr>/<mask> into the tree here */ |
| 1141 | node = calloc(1, sizeof(*node) + 4); /* reserve 4 bytes for IPv4 address */ |
| 1142 | if (!node) |
| 1143 | return 0; |
| 1144 | memcpy(node->key, &pattern->val.ipv4.addr, 4); /* network byte order */ |
| 1145 | node->node.pfx = mask; |
| 1146 | if (ebmb_insert_prefix(tree, node, 4) != node) |
| 1147 | free(node); /* was a duplicate */ |
| 1148 | pattern->flags |= ACL_PAT_F_TREE; |
| 1149 | return 1; |
| 1150 | } |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1151 | return 1; |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 1152 | } |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1153 | else |
| 1154 | return 0; |
Willy Tarreau | a67fad9 | 2007-05-08 19:50:09 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1157 | /* |
| 1158 | * Registers the ACL keyword list <kwl> as a list of valid keywords for next |
| 1159 | * parsing sessions. |
| 1160 | */ |
| 1161 | void acl_register_keywords(struct acl_kw_list *kwl) |
| 1162 | { |
| 1163 | LIST_ADDQ(&acl_keywords.list, &kwl->list); |
| 1164 | } |
| 1165 | |
| 1166 | /* |
| 1167 | * Unregisters the ACL keyword list <kwl> from the list of valid keywords. |
| 1168 | */ |
| 1169 | void acl_unregister_keywords(struct acl_kw_list *kwl) |
| 1170 | { |
| 1171 | LIST_DEL(&kwl->list); |
| 1172 | LIST_INIT(&kwl->list); |
| 1173 | } |
| 1174 | |
| 1175 | /* Return a pointer to the ACL <name> within the list starting at <head>, or |
| 1176 | * NULL if not found. |
| 1177 | */ |
| 1178 | struct acl *find_acl_by_name(const char *name, struct list *head) |
| 1179 | { |
| 1180 | struct acl *acl; |
| 1181 | list_for_each_entry(acl, head, list) { |
| 1182 | if (strcmp(acl->name, name) == 0) |
| 1183 | return acl; |
| 1184 | } |
| 1185 | return NULL; |
| 1186 | } |
| 1187 | |
| 1188 | /* Return a pointer to the ACL keyword <kw>, or NULL if not found. Note that if |
| 1189 | * <kw> contains an opening parenthesis, only the left part of it is checked. |
| 1190 | */ |
| 1191 | struct acl_keyword *find_acl_kw(const char *kw) |
| 1192 | { |
| 1193 | int index; |
| 1194 | const char *kwend; |
| 1195 | struct acl_kw_list *kwl; |
| 1196 | |
| 1197 | kwend = strchr(kw, '('); |
| 1198 | if (!kwend) |
| 1199 | kwend = kw + strlen(kw); |
| 1200 | |
| 1201 | list_for_each_entry(kwl, &acl_keywords.list, list) { |
| 1202 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1203 | if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) && |
| 1204 | kwl->kw[index].kw[kwend-kw] == 0) |
| 1205 | return &kwl->kw[index]; |
| 1206 | } |
| 1207 | } |
| 1208 | return NULL; |
| 1209 | } |
| 1210 | |
Willy Tarreau | dfd7fca | 2011-03-09 07:27:02 +0100 | [diff] [blame] | 1211 | /* NB: does nothing if <pat> is NULL */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1212 | static void free_pattern(struct acl_pattern *pat) |
| 1213 | { |
Willy Tarreau | dfd7fca | 2011-03-09 07:27:02 +0100 | [diff] [blame] | 1214 | if (!pat) |
| 1215 | return; |
Krzysztof Piotr Oledzki | 8001d61 | 2008-05-31 13:53:23 +0200 | [diff] [blame] | 1216 | |
| 1217 | if (pat->ptr.ptr) { |
| 1218 | if (pat->freeptrbuf) |
| 1219 | pat->freeptrbuf(pat->ptr.ptr); |
| 1220 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1221 | free(pat->ptr.ptr); |
Krzysztof Piotr Oledzki | 8001d61 | 2008-05-31 13:53:23 +0200 | [diff] [blame] | 1222 | } |
| 1223 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1224 | free(pat); |
| 1225 | } |
| 1226 | |
| 1227 | static void free_pattern_list(struct list *head) |
| 1228 | { |
| 1229 | struct acl_pattern *pat, *tmp; |
| 1230 | list_for_each_entry_safe(pat, tmp, head, list) |
| 1231 | free_pattern(pat); |
| 1232 | } |
| 1233 | |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1234 | static void free_pattern_tree(struct eb_root *root) |
| 1235 | { |
| 1236 | struct eb_node *node, *next; |
| 1237 | node = eb_first(root); |
| 1238 | while (node) { |
| 1239 | next = eb_next(node); |
| 1240 | free(node); |
| 1241 | node = next; |
| 1242 | } |
| 1243 | } |
| 1244 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1245 | static struct acl_expr *prune_acl_expr(struct acl_expr *expr) |
| 1246 | { |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1247 | struct arg *arg; |
| 1248 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1249 | free_pattern_list(&expr->patterns); |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1250 | free_pattern_tree(&expr->pattern_tree); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1251 | LIST_INIT(&expr->patterns); |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1252 | |
| 1253 | for (arg = expr->args; arg; arg++) { |
| 1254 | if (arg->type == ARGT_STOP) |
| 1255 | break; |
| 1256 | if (arg->type == ARGT_FE || arg->type == ARGT_BE || |
| 1257 | arg->type == ARGT_TAB || arg->type == ARGT_SRV || |
| 1258 | arg->type == ARGT_USR || arg->type == ARGT_STR) { |
| 1259 | free(arg->data.str.str); |
| 1260 | arg->data.str.str = NULL; |
| 1261 | } |
| 1262 | arg++; |
| 1263 | } |
| 1264 | |
| 1265 | free(expr->args); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1266 | expr->kw->use_cnt--; |
| 1267 | return expr; |
| 1268 | } |
| 1269 | |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1270 | static int acl_read_patterns_from_file( struct acl_keyword *aclkw, |
| 1271 | struct acl_expr *expr, |
| 1272 | const char *filename, int patflags) |
| 1273 | { |
| 1274 | FILE *file; |
| 1275 | char *c; |
| 1276 | const char *args[2]; |
| 1277 | struct acl_pattern *pattern; |
| 1278 | int opaque; |
Willy Tarreau | 6a8097f | 2011-02-26 15:14:15 +0100 | [diff] [blame] | 1279 | int ret = 0; |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1280 | |
| 1281 | file = fopen(filename, "r"); |
| 1282 | if (!file) |
| 1283 | return 0; |
| 1284 | |
| 1285 | /* now parse all patterns. The file may contain only one pattern per |
| 1286 | * line. If the line contains spaces, they will be part of the pattern. |
| 1287 | * The pattern stops at the first CR, LF or EOF encountered. |
| 1288 | */ |
| 1289 | opaque = 0; |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1290 | pattern = NULL; |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1291 | args[1] = ""; |
| 1292 | while (fgets(trash, sizeof(trash), file) != NULL) { |
| 1293 | |
| 1294 | c = trash; |
Willy Tarreau | 58215a0 | 2010-05-13 22:07:43 +0200 | [diff] [blame] | 1295 | |
| 1296 | /* ignore lines beginning with a dash */ |
| 1297 | if (*c == '#') |
| 1298 | continue; |
| 1299 | |
| 1300 | /* strip leading spaces and tabs */ |
| 1301 | while (*c == ' ' || *c == '\t') |
| 1302 | c++; |
| 1303 | |
Willy Tarreau | 58215a0 | 2010-05-13 22:07:43 +0200 | [diff] [blame] | 1304 | |
| 1305 | args[0] = c; |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1306 | while (*c && *c != '\n' && *c != '\r') |
| 1307 | c++; |
| 1308 | *c = 0; |
| 1309 | |
Willy Tarreau | 5109196 | 2011-01-03 21:04:10 +0100 | [diff] [blame] | 1310 | /* empty lines are ignored too */ |
| 1311 | if (c == args[0]) |
| 1312 | continue; |
| 1313 | |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1314 | /* we keep the previous pattern along iterations as long as it's not used */ |
| 1315 | if (!pattern) |
| 1316 | pattern = (struct acl_pattern *)malloc(sizeof(*pattern)); |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1317 | if (!pattern) |
| 1318 | goto out_close; |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1319 | |
| 1320 | memset(pattern, 0, sizeof(*pattern)); |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1321 | pattern->flags = patflags; |
| 1322 | |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1323 | if ((aclkw->requires & ACL_MAY_LOOKUP) && !(pattern->flags & ACL_PAT_F_IGNORE_CASE)) { |
| 1324 | /* we pre-set the data pointer to the tree's head so that functions |
| 1325 | * which are able to insert in a tree know where to do that. |
| 1326 | */ |
| 1327 | pattern->flags |= ACL_PAT_F_TREE_OK; |
| 1328 | pattern->val.tree = &expr->pattern_tree; |
| 1329 | } |
| 1330 | |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1331 | if (!aclkw->parse(args, pattern, &opaque)) |
| 1332 | goto out_free_pattern; |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1333 | |
| 1334 | /* if the parser did not feed the tree, let's chain the pattern to the list */ |
| 1335 | if (!(pattern->flags & ACL_PAT_F_TREE)) { |
| 1336 | LIST_ADDQ(&expr->patterns, &pattern->list); |
| 1337 | pattern = NULL; /* get a new one */ |
| 1338 | } |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1339 | } |
Willy Tarreau | 6a8097f | 2011-02-26 15:14:15 +0100 | [diff] [blame] | 1340 | |
| 1341 | ret = 1; /* success */ |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1342 | |
| 1343 | out_free_pattern: |
| 1344 | free_pattern(pattern); |
| 1345 | out_close: |
| 1346 | fclose(file); |
Willy Tarreau | 6a8097f | 2011-02-26 15:14:15 +0100 | [diff] [blame] | 1347 | return ret; |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1350 | /* Parse an ACL expression starting at <args>[0], and return it. |
| 1351 | * Right now, the only accepted syntax is : |
| 1352 | * <subject> [<value>...] |
| 1353 | */ |
| 1354 | struct acl_expr *parse_acl_expr(const char **args) |
| 1355 | { |
| 1356 | __label__ out_return, out_free_expr, out_free_pattern; |
| 1357 | struct acl_expr *expr; |
| 1358 | struct acl_keyword *aclkw; |
| 1359 | struct acl_pattern *pattern; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 1360 | int opaque, patflags; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1361 | const char *arg; |
| 1362 | |
| 1363 | aclkw = find_acl_kw(args[0]); |
| 1364 | if (!aclkw || !aclkw->parse) |
| 1365 | goto out_return; |
| 1366 | |
| 1367 | expr = (struct acl_expr *)calloc(1, sizeof(*expr)); |
| 1368 | if (!expr) |
| 1369 | goto out_return; |
| 1370 | |
| 1371 | expr->kw = aclkw; |
| 1372 | aclkw->use_cnt++; |
| 1373 | LIST_INIT(&expr->patterns); |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1374 | expr->pattern_tree = EB_ROOT_UNIQUE; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1375 | |
| 1376 | arg = strchr(args[0], '('); |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1377 | if (aclkw->arg_mask) { |
| 1378 | int nbargs = 0; |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1379 | char *end; |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1380 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1381 | if (arg != NULL) { |
| 1382 | /* there are 0 or more arguments in the form "subject(arg[,arg]*)" */ |
| 1383 | arg++; |
| 1384 | end = strchr(arg, ')'); |
| 1385 | if (!end) |
| 1386 | goto out_free_expr; |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1387 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1388 | /* Parse the arguments. Note that currently we have no way to |
| 1389 | * report parsing errors, hence the NULL in the error pointers. |
| 1390 | * An error is also reported if some mandatory arguments are |
| 1391 | * missing. |
| 1392 | */ |
| 1393 | nbargs = make_arg_list(arg, end - arg, aclkw->arg_mask, &expr->args, |
| 1394 | NULL, NULL, NULL); |
| 1395 | if (nbargs < 0) |
| 1396 | goto out_free_expr; |
| 1397 | } |
| 1398 | else if (ARGM(aclkw->arg_mask)) { |
| 1399 | /* there were some mandatory arguments */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1400 | goto out_free_expr; |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | else { |
| 1404 | if (arg) { |
| 1405 | /* no argument expected */ |
| 1406 | goto out_free_expr; |
| 1407 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1410 | args++; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 1411 | |
| 1412 | /* check for options before patterns. Supported options are : |
| 1413 | * -i : ignore case for all patterns by default |
| 1414 | * -f : read patterns from those files |
| 1415 | * -- : everything after this is not an option |
| 1416 | */ |
| 1417 | patflags = 0; |
| 1418 | while (**args == '-') { |
| 1419 | if ((*args)[1] == 'i') |
| 1420 | patflags |= ACL_PAT_F_IGNORE_CASE; |
Willy Tarreau | 2b5285d | 2010-05-09 23:45:24 +0200 | [diff] [blame] | 1421 | else if ((*args)[1] == 'f') { |
| 1422 | if (!acl_read_patterns_from_file(aclkw, expr, args[1], patflags | ACL_PAT_F_FROM_FILE)) |
| 1423 | goto out_free_expr; |
| 1424 | args++; |
| 1425 | } |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 1426 | else if ((*args)[1] == '-') { |
| 1427 | args++; |
| 1428 | break; |
| 1429 | } |
| 1430 | else |
| 1431 | break; |
| 1432 | args++; |
| 1433 | } |
| 1434 | |
| 1435 | /* now parse all patterns */ |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1436 | opaque = 0; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1437 | while (**args) { |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1438 | int ret; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1439 | pattern = (struct acl_pattern *)calloc(1, sizeof(*pattern)); |
| 1440 | if (!pattern) |
| 1441 | goto out_free_expr; |
Willy Tarreau | c8d7c96 | 2007-06-17 08:20:33 +0200 | [diff] [blame] | 1442 | pattern->flags = patflags; |
| 1443 | |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1444 | ret = aclkw->parse(args, pattern, &opaque); |
| 1445 | if (!ret) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1446 | goto out_free_pattern; |
| 1447 | LIST_ADDQ(&expr->patterns, &pattern->list); |
Willy Tarreau | ae8b796 | 2007-06-09 23:10:04 +0200 | [diff] [blame] | 1448 | args += ret; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | return expr; |
| 1452 | |
| 1453 | out_free_pattern: |
| 1454 | free_pattern(pattern); |
| 1455 | out_free_expr: |
| 1456 | prune_acl_expr(expr); |
| 1457 | free(expr); |
| 1458 | out_return: |
| 1459 | return NULL; |
| 1460 | } |
| 1461 | |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 1462 | /* Purge everything in the acl <acl>, then return <acl>. */ |
| 1463 | struct acl *prune_acl(struct acl *acl) { |
| 1464 | |
| 1465 | struct acl_expr *expr, *exprb; |
| 1466 | |
| 1467 | free(acl->name); |
| 1468 | |
| 1469 | list_for_each_entry_safe(expr, exprb, &acl->expr, list) { |
| 1470 | LIST_DEL(&expr->list); |
| 1471 | prune_acl_expr(expr); |
| 1472 | free(expr); |
| 1473 | } |
| 1474 | |
| 1475 | return acl; |
| 1476 | } |
| 1477 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1478 | /* Parse an ACL with the name starting at <args>[0], and with a list of already |
| 1479 | * known ACLs in <acl>. If the ACL was not in the list, it will be added. |
Willy Tarreau | 2a56c5e | 2010-03-15 16:13:29 +0100 | [diff] [blame] | 1480 | * A pointer to that ACL is returned. If the ACL has an empty name, then it's |
| 1481 | * an anonymous one and it won't be merged with any other one. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1482 | * |
| 1483 | * args syntax: <aclname> <acl_expr> |
| 1484 | */ |
| 1485 | struct acl *parse_acl(const char **args, struct list *known_acl) |
| 1486 | { |
| 1487 | __label__ out_return, out_free_acl_expr, out_free_name; |
| 1488 | struct acl *cur_acl; |
| 1489 | struct acl_expr *acl_expr; |
| 1490 | char *name; |
| 1491 | |
Willy Tarreau | 2a56c5e | 2010-03-15 16:13:29 +0100 | [diff] [blame] | 1492 | if (**args && invalid_char(*args)) |
Willy Tarreau | 2e74c3f | 2007-12-02 18:45:09 +0100 | [diff] [blame] | 1493 | goto out_return; |
| 1494 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1495 | acl_expr = parse_acl_expr(args + 1); |
| 1496 | if (!acl_expr) |
| 1497 | goto out_return; |
| 1498 | |
Willy Tarreau | 404e8ab | 2009-07-26 19:40:40 +0200 | [diff] [blame] | 1499 | /* Check for args beginning with an opening parenthesis just after the |
| 1500 | * subject, as this is almost certainly a typo. Right now we can only |
| 1501 | * emit a warning, so let's do so. |
| 1502 | */ |
Krzysztof Piotr Oledzki | 4cdd831 | 2009-10-05 00:23:35 +0200 | [diff] [blame] | 1503 | if (!strchr(args[1], '(') && *args[2] == '(') |
Willy Tarreau | 404e8ab | 2009-07-26 19:40:40 +0200 | [diff] [blame] | 1504 | Warning("parsing acl '%s' :\n" |
| 1505 | " matching '%s' for pattern '%s' is likely a mistake and probably\n" |
| 1506 | " not what you want. Maybe you need to remove the extraneous space before '('.\n" |
| 1507 | " If you are really sure this is not an error, please insert '--' between the\n" |
| 1508 | " match and the pattern to make this warning message disappear.\n", |
| 1509 | args[0], args[1], args[2]); |
| 1510 | |
Willy Tarreau | 2a56c5e | 2010-03-15 16:13:29 +0100 | [diff] [blame] | 1511 | if (*args[0]) |
| 1512 | cur_acl = find_acl_by_name(args[0], known_acl); |
| 1513 | else |
| 1514 | cur_acl = NULL; |
| 1515 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1516 | if (!cur_acl) { |
| 1517 | name = strdup(args[0]); |
| 1518 | if (!name) |
| 1519 | goto out_free_acl_expr; |
| 1520 | cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl)); |
| 1521 | if (cur_acl == NULL) |
| 1522 | goto out_free_name; |
| 1523 | |
| 1524 | LIST_INIT(&cur_acl->expr); |
| 1525 | LIST_ADDQ(known_acl, &cur_acl->list); |
| 1526 | cur_acl->name = name; |
| 1527 | } |
| 1528 | |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1529 | cur_acl->requires |= acl_expr->kw->requires; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1530 | LIST_ADDQ(&cur_acl->expr, &acl_expr->list); |
| 1531 | return cur_acl; |
| 1532 | |
| 1533 | out_free_name: |
| 1534 | free(name); |
| 1535 | out_free_acl_expr: |
| 1536 | prune_acl_expr(acl_expr); |
| 1537 | free(acl_expr); |
| 1538 | out_return: |
| 1539 | return NULL; |
| 1540 | } |
| 1541 | |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1542 | /* Some useful ACLs provided by default. Only those used are allocated. */ |
| 1543 | |
| 1544 | const struct { |
| 1545 | const char *name; |
| 1546 | const char *expr[4]; /* put enough for longest expression */ |
| 1547 | } default_acl_list[] = { |
Willy Tarreau | 58393e1 | 2008-07-20 10:39:22 +0200 | [diff] [blame] | 1548 | { .name = "TRUE", .expr = {"always_true",""}}, |
| 1549 | { .name = "FALSE", .expr = {"always_false",""}}, |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1550 | { .name = "LOCALHOST", .expr = {"src","127.0.0.1/8",""}}, |
Willy Tarreau | 2492d5b | 2009-07-11 00:06:00 +0200 | [diff] [blame] | 1551 | { .name = "HTTP", .expr = {"req_proto_http",""}}, |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1552 | { .name = "HTTP_1.0", .expr = {"req_ver","1.0",""}}, |
| 1553 | { .name = "HTTP_1.1", .expr = {"req_ver","1.1",""}}, |
| 1554 | { .name = "METH_CONNECT", .expr = {"method","CONNECT",""}}, |
| 1555 | { .name = "METH_GET", .expr = {"method","GET","HEAD",""}}, |
| 1556 | { .name = "METH_HEAD", .expr = {"method","HEAD",""}}, |
| 1557 | { .name = "METH_OPTIONS", .expr = {"method","OPTIONS",""}}, |
| 1558 | { .name = "METH_POST", .expr = {"method","POST",""}}, |
| 1559 | { .name = "METH_TRACE", .expr = {"method","TRACE",""}}, |
| 1560 | { .name = "HTTP_URL_ABS", .expr = {"url_reg","^[^/:]*://",""}}, |
| 1561 | { .name = "HTTP_URL_SLASH", .expr = {"url_beg","/",""}}, |
| 1562 | { .name = "HTTP_URL_STAR", .expr = {"url","*",""}}, |
| 1563 | { .name = "HTTP_CONTENT", .expr = {"hdr_val(content-length)","gt","0",""}}, |
Emeric Brun | bede3d0 | 2009-06-30 17:54:00 +0200 | [diff] [blame] | 1564 | { .name = "RDP_COOKIE", .expr = {"req_rdp_cookie_cnt","gt","0",""}}, |
Willy Tarreau | c631770 | 2008-07-20 09:29:50 +0200 | [diff] [blame] | 1565 | { .name = "REQ_CONTENT", .expr = {"req_len","gt","0",""}}, |
Willy Tarreau | b6fb420 | 2008-07-20 11:18:28 +0200 | [diff] [blame] | 1566 | { .name = "WAIT_END", .expr = {"wait_end",""}}, |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1567 | { .name = NULL, .expr = {""}} |
| 1568 | }; |
| 1569 | |
| 1570 | /* Find a default ACL from the default_acl list, compile it and return it. |
| 1571 | * If the ACL is not found, NULL is returned. In theory, it cannot fail, |
| 1572 | * except when default ACLs are broken, in which case it will return NULL. |
| 1573 | * If <known_acl> is not NULL, the ACL will be queued at its tail. |
| 1574 | */ |
| 1575 | struct acl *find_acl_default(const char *acl_name, struct list *known_acl) |
| 1576 | { |
| 1577 | __label__ out_return, out_free_acl_expr, out_free_name; |
| 1578 | struct acl *cur_acl; |
| 1579 | struct acl_expr *acl_expr; |
| 1580 | char *name; |
| 1581 | int index; |
| 1582 | |
| 1583 | for (index = 0; default_acl_list[index].name != NULL; index++) { |
| 1584 | if (strcmp(acl_name, default_acl_list[index].name) == 0) |
| 1585 | break; |
| 1586 | } |
| 1587 | |
| 1588 | if (default_acl_list[index].name == NULL) |
| 1589 | return NULL; |
| 1590 | |
| 1591 | acl_expr = parse_acl_expr((const char **)default_acl_list[index].expr); |
| 1592 | if (!acl_expr) |
| 1593 | goto out_return; |
| 1594 | |
| 1595 | name = strdup(acl_name); |
| 1596 | if (!name) |
| 1597 | goto out_free_acl_expr; |
| 1598 | cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl)); |
| 1599 | if (cur_acl == NULL) |
| 1600 | goto out_free_name; |
| 1601 | |
| 1602 | cur_acl->name = name; |
Willy Tarreau | a55b7dc | 2009-07-12 09:21:30 +0200 | [diff] [blame] | 1603 | cur_acl->requires |= acl_expr->kw->requires; |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1604 | LIST_INIT(&cur_acl->expr); |
| 1605 | LIST_ADDQ(&cur_acl->expr, &acl_expr->list); |
| 1606 | if (known_acl) |
| 1607 | LIST_ADDQ(known_acl, &cur_acl->list); |
| 1608 | |
| 1609 | return cur_acl; |
| 1610 | |
| 1611 | out_free_name: |
| 1612 | free(name); |
| 1613 | out_free_acl_expr: |
| 1614 | prune_acl_expr(acl_expr); |
| 1615 | free(acl_expr); |
| 1616 | out_return: |
| 1617 | return NULL; |
| 1618 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1619 | |
| 1620 | /* Purge everything in the acl_cond <cond>, then return <cond>. */ |
| 1621 | struct acl_cond *prune_acl_cond(struct acl_cond *cond) |
| 1622 | { |
| 1623 | struct acl_term_suite *suite, *tmp_suite; |
| 1624 | struct acl_term *term, *tmp_term; |
| 1625 | |
| 1626 | /* iterate through all term suites and free all terms and all suites */ |
| 1627 | list_for_each_entry_safe(suite, tmp_suite, &cond->suites, list) { |
| 1628 | list_for_each_entry_safe(term, tmp_term, &suite->terms, list) |
| 1629 | free(term); |
| 1630 | free(suite); |
| 1631 | } |
| 1632 | return cond; |
| 1633 | } |
| 1634 | |
| 1635 | /* Parse an ACL condition starting at <args>[0], relying on a list of already |
| 1636 | * known ACLs passed in <known_acl>. The new condition is returned (or NULL in |
| 1637 | * case of low memory). Supports multiple conditions separated by "or". |
| 1638 | */ |
| 1639 | struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl, int pol) |
| 1640 | { |
| 1641 | __label__ out_return, out_free_suite, out_free_term; |
Willy Tarreau | 74b98a8 | 2007-06-16 19:35:18 +0200 | [diff] [blame] | 1642 | int arg, neg; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1643 | const char *word; |
| 1644 | struct acl *cur_acl; |
| 1645 | struct acl_term *cur_term; |
| 1646 | struct acl_term_suite *cur_suite; |
| 1647 | struct acl_cond *cond; |
| 1648 | |
| 1649 | cond = (struct acl_cond *)calloc(1, sizeof(*cond)); |
| 1650 | if (cond == NULL) |
| 1651 | goto out_return; |
| 1652 | |
| 1653 | LIST_INIT(&cond->list); |
| 1654 | LIST_INIT(&cond->suites); |
| 1655 | cond->pol = pol; |
| 1656 | |
| 1657 | cur_suite = NULL; |
Willy Tarreau | 74b98a8 | 2007-06-16 19:35:18 +0200 | [diff] [blame] | 1658 | neg = 0; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1659 | for (arg = 0; *args[arg]; arg++) { |
| 1660 | word = args[arg]; |
| 1661 | |
| 1662 | /* remove as many exclamation marks as we can */ |
| 1663 | while (*word == '!') { |
| 1664 | neg = !neg; |
| 1665 | word++; |
| 1666 | } |
| 1667 | |
| 1668 | /* an empty word is allowed because we cannot force the user to |
| 1669 | * always think about not leaving exclamation marks alone. |
| 1670 | */ |
| 1671 | if (!*word) |
| 1672 | continue; |
| 1673 | |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1674 | if (strcasecmp(word, "or") == 0 || strcmp(word, "||") == 0) { |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1675 | /* new term suite */ |
| 1676 | cur_suite = NULL; |
| 1677 | neg = 0; |
| 1678 | continue; |
| 1679 | } |
| 1680 | |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 1681 | if (strcmp(word, "{") == 0) { |
| 1682 | /* we may have a complete ACL expression between two braces, |
| 1683 | * find the last one. |
| 1684 | */ |
| 1685 | int arg_end = arg + 1; |
| 1686 | const char **args_new; |
| 1687 | |
| 1688 | while (*args[arg_end] && strcmp(args[arg_end], "}") != 0) |
| 1689 | arg_end++; |
| 1690 | |
| 1691 | if (!*args[arg_end]) |
| 1692 | goto out_free_suite; |
| 1693 | |
| 1694 | args_new = calloc(1, (arg_end - arg + 1) * sizeof(*args_new)); |
| 1695 | if (!args_new) |
| 1696 | goto out_free_suite; |
| 1697 | |
Willy Tarreau | 2a56c5e | 2010-03-15 16:13:29 +0100 | [diff] [blame] | 1698 | args_new[0] = ""; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 1699 | memcpy(args_new + 1, args + arg + 1, (arg_end - arg) * sizeof(*args_new)); |
| 1700 | args_new[arg_end - arg] = ""; |
| 1701 | cur_acl = parse_acl(args_new, known_acl); |
| 1702 | free(args_new); |
| 1703 | |
| 1704 | if (!cur_acl) |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1705 | goto out_free_suite; |
Willy Tarreau | 95fa469 | 2010-02-01 13:05:50 +0100 | [diff] [blame] | 1706 | arg = arg_end; |
| 1707 | } |
| 1708 | else { |
| 1709 | /* search for <word> in the known ACL names. If we do not find |
| 1710 | * it, let's look for it in the default ACLs, and if found, add |
| 1711 | * it to the list of ACLs of this proxy. This makes it possible |
| 1712 | * to override them. |
| 1713 | */ |
| 1714 | cur_acl = find_acl_by_name(word, known_acl); |
| 1715 | if (cur_acl == NULL) { |
| 1716 | cur_acl = find_acl_default(word, known_acl); |
| 1717 | if (cur_acl == NULL) |
| 1718 | goto out_free_suite; |
| 1719 | } |
Willy Tarreau | 16fbe82 | 2007-06-17 11:54:31 +0200 | [diff] [blame] | 1720 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1721 | |
| 1722 | cur_term = (struct acl_term *)calloc(1, sizeof(*cur_term)); |
| 1723 | if (cur_term == NULL) |
| 1724 | goto out_free_suite; |
| 1725 | |
| 1726 | cur_term->acl = cur_acl; |
| 1727 | cur_term->neg = neg; |
Willy Tarreau | a980263 | 2008-07-25 19:13:19 +0200 | [diff] [blame] | 1728 | cond->requires |= cur_acl->requires; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1729 | |
| 1730 | if (!cur_suite) { |
| 1731 | cur_suite = (struct acl_term_suite *)calloc(1, sizeof(*cur_suite)); |
| 1732 | if (cur_term == NULL) |
| 1733 | goto out_free_term; |
| 1734 | LIST_INIT(&cur_suite->terms); |
| 1735 | LIST_ADDQ(&cond->suites, &cur_suite->list); |
| 1736 | } |
| 1737 | LIST_ADDQ(&cur_suite->terms, &cur_term->list); |
Willy Tarreau | 74b98a8 | 2007-06-16 19:35:18 +0200 | [diff] [blame] | 1738 | neg = 0; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | return cond; |
| 1742 | |
| 1743 | out_free_term: |
| 1744 | free(cur_term); |
| 1745 | out_free_suite: |
| 1746 | prune_acl_cond(cond); |
| 1747 | free(cond); |
| 1748 | out_return: |
| 1749 | return NULL; |
| 1750 | } |
| 1751 | |
Willy Tarreau | 2bbba41 | 2010-01-28 16:48:33 +0100 | [diff] [blame] | 1752 | /* Builds an ACL condition starting at the if/unless keyword. The complete |
| 1753 | * condition is returned. NULL is returned in case of error or if the first |
| 1754 | * word is neither "if" nor "unless". It automatically sets the file name and |
| 1755 | * the line number in the condition for better error reporting, and adds the |
| 1756 | * ACL requirements to the proxy's acl_requires. |
| 1757 | */ |
| 1758 | struct acl_cond *build_acl_cond(const char *file, int line, struct proxy *px, const char **args) |
| 1759 | { |
| 1760 | int pol = ACL_COND_NONE; |
| 1761 | struct acl_cond *cond = NULL; |
| 1762 | |
| 1763 | if (!strcmp(*args, "if")) { |
| 1764 | pol = ACL_COND_IF; |
| 1765 | args++; |
| 1766 | } |
| 1767 | else if (!strcmp(*args, "unless")) { |
| 1768 | pol = ACL_COND_UNLESS; |
| 1769 | args++; |
| 1770 | } |
| 1771 | else |
| 1772 | return NULL; |
| 1773 | |
| 1774 | cond = parse_acl_cond(args, &px->acl, pol); |
| 1775 | if (!cond) |
| 1776 | return NULL; |
| 1777 | |
| 1778 | cond->file = file; |
| 1779 | cond->line = line; |
| 1780 | px->acl_requires |= cond->requires; |
| 1781 | |
| 1782 | return cond; |
| 1783 | } |
| 1784 | |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1785 | /* Execute condition <cond> and return either ACL_PAT_FAIL, ACL_PAT_MISS or |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1786 | * ACL_PAT_PASS depending on the test results. ACL_PAT_MISS may only be |
| 1787 | * returned if <dir> contains ACL_PARTIAL, indicating that incomplete data |
| 1788 | * is being examined. |
| 1789 | * This function only computes the condition, it does not apply the polarity |
| 1790 | * required by IF/UNLESS, it's up to the caller to do this using something like |
| 1791 | * this : |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1792 | * |
| 1793 | * res = acl_pass(res); |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1794 | * if (res == ACL_PAT_MISS) |
| 1795 | * return 0; |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1796 | * if (cond->pol == ACL_COND_UNLESS) |
| 1797 | * res = !res; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1798 | */ |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 1799 | int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, int dir) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1800 | { |
| 1801 | __label__ fetch_next; |
| 1802 | struct acl_term_suite *suite; |
| 1803 | struct acl_term *term; |
| 1804 | struct acl_expr *expr; |
| 1805 | struct acl *acl; |
| 1806 | struct acl_pattern *pattern; |
| 1807 | struct acl_test test; |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1808 | int acl_res, suite_res, cond_res; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1809 | |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1810 | /* We're doing a logical OR between conditions so we initialize to FAIL. |
| 1811 | * The MISS status is propagated down from the suites. |
| 1812 | */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1813 | cond_res = ACL_PAT_FAIL; |
| 1814 | list_for_each_entry(suite, &cond->suites, list) { |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1815 | /* Evaluate condition suite <suite>. We stop at the first term |
| 1816 | * which returns ACL_PAT_FAIL. The MISS status is still propagated |
| 1817 | * in case of uncertainty in the result. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1818 | */ |
| 1819 | |
| 1820 | /* we're doing a logical AND between terms, so we must set the |
| 1821 | * initial value to PASS. |
| 1822 | */ |
| 1823 | suite_res = ACL_PAT_PASS; |
| 1824 | list_for_each_entry(term, &suite->terms, list) { |
| 1825 | acl = term->acl; |
| 1826 | |
| 1827 | /* FIXME: use cache ! |
| 1828 | * check acl->cache_idx for this. |
| 1829 | */ |
| 1830 | |
| 1831 | /* ACL result not cached. Let's scan all the expressions |
| 1832 | * and use the first one to match. |
| 1833 | */ |
| 1834 | acl_res = ACL_PAT_FAIL; |
| 1835 | list_for_each_entry(expr, &acl->expr, list) { |
Willy Tarreau | d41f8d8 | 2007-06-10 10:06:18 +0200 | [diff] [blame] | 1836 | /* we need to reset context and flags */ |
| 1837 | memset(&test, 0, sizeof(test)); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1838 | fetch_next: |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1839 | if (!expr->kw->fetch(px, l4, l7, dir, expr, &test)) { |
| 1840 | /* maybe we could not fetch because of missing data */ |
| 1841 | if (test.flags & ACL_TEST_F_MAY_CHANGE && dir & ACL_PARTIAL) |
| 1842 | acl_res |= ACL_PAT_MISS; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1843 | continue; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1844 | } |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1845 | |
Willy Tarreau | a79534f | 2008-07-20 10:13:37 +0200 | [diff] [blame] | 1846 | if (test.flags & ACL_TEST_F_RES_SET) { |
| 1847 | if (test.flags & ACL_TEST_F_RES_PASS) |
| 1848 | acl_res |= ACL_PAT_PASS; |
| 1849 | else |
| 1850 | acl_res |= ACL_PAT_FAIL; |
| 1851 | } |
| 1852 | else { |
Willy Tarreau | 020534d | 2010-05-16 21:45:45 +0200 | [diff] [blame] | 1853 | if (!eb_is_empty(&expr->pattern_tree)) { |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 1854 | /* a tree is present, let's check what type it is */ |
| 1855 | if (expr->kw->match == acl_match_str) |
| 1856 | acl_res |= acl_lookup_str(&test, expr) ? ACL_PAT_PASS : ACL_PAT_FAIL; |
Willy Tarreau | b337b53 | 2010-05-13 20:03:41 +0200 | [diff] [blame] | 1857 | else if (expr->kw->match == acl_match_ip) |
| 1858 | acl_res |= acl_lookup_ip(&test, expr) ? ACL_PAT_PASS : ACL_PAT_FAIL; |
Willy Tarreau | c426296 | 2010-05-10 23:42:40 +0200 | [diff] [blame] | 1859 | } |
| 1860 | |
Willy Tarreau | a79534f | 2008-07-20 10:13:37 +0200 | [diff] [blame] | 1861 | /* call the match() function for all tests on this value */ |
| 1862 | list_for_each_entry(pattern, &expr->patterns, list) { |
Willy Tarreau | a79534f | 2008-07-20 10:13:37 +0200 | [diff] [blame] | 1863 | if (acl_res == ACL_PAT_PASS) |
| 1864 | break; |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1865 | acl_res |= expr->kw->match(&test, pattern); |
Willy Tarreau | a79534f | 2008-07-20 10:13:37 +0200 | [diff] [blame] | 1866 | } |
Krzysztof Piotr Oledzki | d7528e5 | 2010-01-29 17:55:53 +0100 | [diff] [blame] | 1867 | |
Willy Tarreau | e56cda9 | 2010-05-11 23:25:05 +0200 | [diff] [blame] | 1868 | if ((test.flags & ACL_TEST_F_NULL_MATCH) && |
Willy Tarreau | 020534d | 2010-05-16 21:45:45 +0200 | [diff] [blame] | 1869 | LIST_ISEMPTY(&expr->patterns) && eb_is_empty(&expr->pattern_tree)) |
Krzysztof Piotr Oledzki | d7528e5 | 2010-01-29 17:55:53 +0100 | [diff] [blame] | 1870 | acl_res |= expr->kw->match(&test, NULL); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1871 | } |
| 1872 | /* |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1873 | * OK now acl_res holds the result of this expression |
| 1874 | * as one of ACL_PAT_FAIL, ACL_PAT_MISS or ACL_PAT_PASS. |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1875 | * |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1876 | * Then if (!MISS) we can cache the result, and put |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1877 | * (test.flags & ACL_TEST_F_VOLATILE) in the cache flags. |
| 1878 | * |
| 1879 | * FIXME: implement cache. |
| 1880 | * |
| 1881 | */ |
| 1882 | |
| 1883 | /* now we may have some cleanup to do */ |
| 1884 | if (test.flags & ACL_TEST_F_MUST_FREE) { |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 1885 | free(temp_pattern.data.str.str); |
| 1886 | temp_pattern.data.str.len = 0; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1889 | /* we're ORing these terms, so a single PASS is enough */ |
| 1890 | if (acl_res == ACL_PAT_PASS) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1891 | break; |
| 1892 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1893 | if (test.flags & ACL_TEST_F_FETCH_MORE) |
| 1894 | goto fetch_next; |
Willy Tarreau | b686644 | 2008-07-14 23:54:42 +0200 | [diff] [blame] | 1895 | |
| 1896 | /* sometimes we know the fetched data is subject to change |
| 1897 | * later and give another chance for a new match (eg: request |
| 1898 | * size, time, ...) |
| 1899 | */ |
| 1900 | if (test.flags & ACL_TEST_F_MAY_CHANGE && dir & ACL_PARTIAL) |
| 1901 | acl_res |= ACL_PAT_MISS; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1902 | } |
| 1903 | /* |
| 1904 | * Here we have the result of an ACL (cached or not). |
| 1905 | * ACLs are combined, negated or not, to form conditions. |
| 1906 | */ |
| 1907 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1908 | if (term->neg) |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1909 | acl_res = acl_neg(acl_res); |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1910 | |
| 1911 | suite_res &= acl_res; |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1912 | |
| 1913 | /* we're ANDing these terms, so a single FAIL is enough */ |
| 1914 | if (suite_res == ACL_PAT_FAIL) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1915 | break; |
| 1916 | } |
| 1917 | cond_res |= suite_res; |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1918 | |
| 1919 | /* we're ORing these terms, so a single PASS is enough */ |
| 1920 | if (cond_res == ACL_PAT_PASS) |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1921 | break; |
| 1922 | } |
Willy Tarreau | 1138281 | 2008-07-09 16:18:21 +0200 | [diff] [blame] | 1923 | return cond_res; |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1927 | /* Reports a pointer to the first ACL used in condition <cond> which requires |
| 1928 | * at least one of the USE_FLAGS in <require>. Returns NULL if none matches. |
| 1929 | * The construct is almost the same as for acl_exec_cond() since we're walking |
| 1930 | * down the ACL tree as well. It is important that the tree is really walked |
| 1931 | * through and never cached, because that way, this function can be used as a |
| 1932 | * late check. |
| 1933 | */ |
Willy Tarreau | f1e98b8 | 2010-01-28 17:59:39 +0100 | [diff] [blame] | 1934 | struct acl *cond_find_require(const struct acl_cond *cond, unsigned int require) |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 1935 | { |
| 1936 | struct acl_term_suite *suite; |
| 1937 | struct acl_term *term; |
| 1938 | struct acl *acl; |
| 1939 | |
| 1940 | list_for_each_entry(suite, &cond->suites, list) { |
| 1941 | list_for_each_entry(term, &suite->terms, list) { |
| 1942 | acl = term->acl; |
| 1943 | if (acl->requires & require) |
| 1944 | return acl; |
| 1945 | } |
| 1946 | } |
| 1947 | return NULL; |
| 1948 | } |
| 1949 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1950 | /* |
| 1951 | * Find targets for userlist and groups in acl. Function returns the number |
| 1952 | * of errors or OK if everything is fine. |
| 1953 | */ |
| 1954 | int |
| 1955 | acl_find_targets(struct proxy *p) |
| 1956 | { |
| 1957 | |
| 1958 | struct acl *acl; |
| 1959 | struct acl_expr *expr; |
| 1960 | struct acl_pattern *pattern; |
| 1961 | struct userlist *ul; |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 1962 | struct arg *arg; |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1963 | int cfgerr = 0; |
| 1964 | |
| 1965 | list_for_each_entry(acl, &p->acl, list) { |
| 1966 | list_for_each_entry(expr, &acl->expr, list) { |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 1967 | for (arg = expr->args; arg; arg++) { |
| 1968 | if (arg->type == ARGT_STOP) |
| 1969 | break; |
| 1970 | else if (arg->type == ARGT_SRV) { |
| 1971 | struct proxy *px; |
| 1972 | struct server *srv; |
| 1973 | char *pname, *sname; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1974 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 1975 | if (!expr->args->data.str.len) { |
| 1976 | Alert("proxy %s: acl '%s' %s(): missing server name.\n", |
| 1977 | p->id, acl->name, expr->kw->kw); |
| 1978 | cfgerr++; |
| 1979 | continue; |
| 1980 | } |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1981 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 1982 | pname = expr->args->data.str.str; |
| 1983 | sname = strrchr(pname, '/'); |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1984 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 1985 | if (sname) |
| 1986 | *sname++ = '\0'; |
| 1987 | else { |
| 1988 | sname = pname; |
| 1989 | pname = NULL; |
| 1990 | } |
| 1991 | |
| 1992 | px = p; |
| 1993 | if (pname) { |
| 1994 | px = findproxy(pname, PR_CAP_BE); |
| 1995 | if (!px) { |
| 1996 | Alert("proxy %s: acl '%s' %s(): unable to find proxy '%s'.\n", |
| 1997 | p->id, acl->name, expr->kw->kw, pname); |
| 1998 | cfgerr++; |
| 1999 | continue; |
| 2000 | } |
| 2001 | } |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 2002 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2003 | srv = findserver(px, sname); |
| 2004 | if (!srv) { |
| 2005 | Alert("proxy %s: acl '%s' %s(): unable to find server '%s'.\n", |
| 2006 | p->id, acl->name, expr->kw->kw, sname); |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 2007 | cfgerr++; |
| 2008 | continue; |
| 2009 | } |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 2010 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2011 | free(expr->args->data.str.str); |
| 2012 | expr->args->data.srv = srv; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 2013 | continue; |
| 2014 | } |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2015 | else if (arg->type == ARGT_USR) { |
| 2016 | if (!expr->args->data.str.len) { |
| 2017 | Alert("proxy %s: acl '%s' %s(): missing userlist name.\n", |
| 2018 | p->id, acl->name, expr->kw->kw); |
| 2019 | cfgerr++; |
| 2020 | continue; |
| 2021 | } |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2022 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2023 | if (p->uri_auth && p->uri_auth->userlist && |
| 2024 | !strcmp(p->uri_auth->userlist->name, expr->args->data.str.str)) |
| 2025 | ul = p->uri_auth->userlist; |
| 2026 | else |
| 2027 | ul = auth_find_userlist(expr->args->data.str.str); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2028 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2029 | if (!ul) { |
| 2030 | Alert("proxy %s: acl '%s' %s(%s): unable to find userlist.\n", |
| 2031 | p->id, acl->name, expr->kw->kw, expr->args->data.str.str); |
| 2032 | cfgerr++; |
| 2033 | continue; |
| 2034 | } |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2035 | |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2036 | free(expr->args->data.str.str); |
| 2037 | expr->args->data.usr = ul; |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2038 | } |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2039 | } /* end of args processing */ |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2040 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2041 | |
| 2042 | if (!strcmp(expr->kw->kw, "http_auth_group")) { |
Willy Tarreau | 63364ee | 2012-04-19 19:11:13 +0200 | [diff] [blame^] | 2043 | /* note: argument resolved above thanks to ARGT_USR */ |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2044 | |
| 2045 | if (LIST_ISEMPTY(&expr->patterns)) { |
| 2046 | Alert("proxy %s: acl %s %s(): no groups specified.\n", |
| 2047 | p->id, acl->name, expr->kw->kw); |
| 2048 | cfgerr++; |
| 2049 | continue; |
| 2050 | } |
| 2051 | |
| 2052 | list_for_each_entry(pattern, &expr->patterns, list) { |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 2053 | pattern->val.group_mask = auth_resolve_groups(expr->args->data.usr, pattern->ptr.str); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 2054 | |
| 2055 | free(pattern->ptr.str); |
| 2056 | pattern->ptr.str = NULL; |
| 2057 | pattern->len = 0; |
| 2058 | |
| 2059 | if (!pattern->val.group_mask) { |
| 2060 | Alert("proxy %s: acl %s %s(): invalid group(s).\n", |
| 2061 | p->id, acl->name, expr->kw->kw); |
| 2062 | cfgerr++; |
| 2063 | continue; |
| 2064 | } |
| 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | return cfgerr; |
| 2071 | } |
Willy Tarreau | dd64f8d | 2008-07-27 22:02:32 +0200 | [diff] [blame] | 2072 | |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 2073 | /************************************************************************/ |
| 2074 | /* All supported keywords must be declared here. */ |
| 2075 | /************************************************************************/ |
| 2076 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 2077 | /* Note: must not be declared <const> as its list will be overwritten. |
| 2078 | * Please take care of keeping this list alphabetically sorted. |
| 2079 | */ |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 2080 | static struct acl_kw_list acl_kws = {{ },{ |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 2081 | { "always_false", acl_parse_nothing, acl_fetch_false, acl_match_nothing, ACL_USE_NOTHING, 0 }, |
| 2082 | { "always_true", acl_parse_nothing, acl_fetch_true, acl_match_nothing, ACL_USE_NOTHING, 0 }, |
| 2083 | { "rep_ssl_hello_type", acl_parse_int, acl_fetch_ssl_hello_type, acl_match_int, ACL_USE_L6RTR_VOLATILE, 0 }, |
| 2084 | { "req_len", acl_parse_int, acl_fetch_req_len, acl_match_int, ACL_USE_L6REQ_VOLATILE, 0 }, |
| 2085 | { "req_rdp_cookie", acl_parse_str, acl_fetch_rdp_cookie, acl_match_str, ACL_USE_L6REQ_VOLATILE|ACL_MAY_LOOKUP, ARG1(0,STR) }, |
| 2086 | { "req_rdp_cookie_cnt", acl_parse_int, acl_fetch_rdp_cookie_cnt, acl_match_int, ACL_USE_L6REQ_VOLATILE, ARG1(0,STR) }, |
| 2087 | { "req_ssl_hello_type", acl_parse_int, acl_fetch_ssl_hello_type, acl_match_int, ACL_USE_L6REQ_VOLATILE, 0 }, |
| 2088 | { "req_ssl_sni", acl_parse_str, acl_fetch_ssl_hello_sni, acl_match_str, ACL_USE_L6REQ_VOLATILE|ACL_MAY_LOOKUP, 0 }, |
| 2089 | { "req_ssl_ver", acl_parse_dotted_ver, acl_fetch_req_ssl_ver, acl_match_int, ACL_USE_L6REQ_VOLATILE, 0 }, |
| 2090 | { "wait_end", acl_parse_nothing, acl_fetch_wait_end, acl_match_nothing, ACL_USE_NOTHING, 0 }, |
Willy Tarreau | a84d374 | 2007-05-07 00:36:48 +0200 | [diff] [blame] | 2091 | { NULL, NULL, NULL, NULL } |
| 2092 | }}; |
| 2093 | |
| 2094 | |
| 2095 | __attribute__((constructor)) |
| 2096 | static void __acl_init(void) |
| 2097 | { |
| 2098 | acl_register_keywords(&acl_kws); |
| 2099 | } |
| 2100 | |
| 2101 | |
| 2102 | /* |
| 2103 | * Local variables: |
| 2104 | * c-indent-level: 8 |
| 2105 | * c-basic-offset: 8 |
| 2106 | * End: |
| 2107 | */ |