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