blob: f0966a51cb50a22407ad004801d5887815b48b9b [file] [log] [blame]
Willy Tarreaua84d3742007-05-07 00:36:48 +02001/*
2 * ACL management functions.
3 *
Willy Tarreau0e698542011-09-16 08:32:32 +02004 * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
Willy Tarreaua84d3742007-05-07 00:36:48 +02005 *
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 Tarreauae8b7962007-06-09 23:10:04 +020013#include <ctype.h>
Willy Tarreaua84d3742007-05-07 00:36:48 +020014#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 Oledzki8c8bd452010-01-29 19:29:32 +010020#include <common/uri_auth.h>
Willy Tarreaua84d3742007-05-07 00:36:48 +020021
Willy Tarreau2b5285d2010-05-09 23:45:24 +020022#include <types/global.h>
23
Willy Tarreaua84d3742007-05-07 00:36:48 +020024#include <proto/acl.h>
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +010025#include <proto/auth.h>
Willy Tarreau44b90cc2010-05-24 20:27:29 +020026#include <proto/buffers.h>
Willy Tarreau404e8ab2009-07-26 19:40:40 +020027#include <proto/log.h>
Willy Tarreau0b1cd942010-05-16 22:18:27 +020028#include <proto/proxy.h>
Willy Tarreaua84d3742007-05-07 00:36:48 +020029
Willy Tarreauc4262962010-05-10 23:42:40 +020030#include <ebsttree.h>
31
Willy Tarreaua9802632008-07-25 19:13:19 +020032/* The capabilities of filtering hooks describe the type of information
33 * available to each of them.
34 */
35const unsigned int filt_cap[] = {
36 [ACL_HOOK_REQ_FE_TCP] = ACL_USE_TCP4_ANY|ACL_USE_TCP6_ANY|ACL_USE_TCP_ANY,
Willy Tarreau06457872010-05-23 12:24:38 +020037 [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 Tarreaua9802632008-07-25 19:13:19 +020045
Willy Tarreau06457872010-05-23 12:24:38 +020046 [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 Tarreaua9802632008-07-25 19:13:19 +020052};
53
Willy Tarreaua84d3742007-05-07 00:36:48 +020054/* List head of all known ACL keywords */
55static struct acl_kw_list acl_keywords = {
56 .list = LIST_HEAD_INIT(acl_keywords.list)
57};
58
59
Willy Tarreaua5909832007-06-17 20:40:25 +020060/*
61 * These functions are only used for debugging complex configurations.
Willy Tarreaua84d3742007-05-07 00:36:48 +020062 */
Willy Tarreaua5909832007-06-17 20:40:25 +020063
Willy Tarreau58393e12008-07-20 10:39:22 +020064/* force TRUE to be returned at the fetch level */
Willy Tarreaua5909832007-06-17 20:40:25 +020065static int
Willy Tarreau58393e12008-07-20 10:39:22 +020066acl_fetch_true(struct proxy *px, struct session *l4, void *l7, int dir,
67 struct acl_expr *expr, struct acl_test *test)
Willy Tarreaua5909832007-06-17 20:40:25 +020068{
Willy Tarreau58393e12008-07-20 10:39:22 +020069 test->flags |= ACL_TEST_F_SET_RES_PASS;
Willy Tarreaua5909832007-06-17 20:40:25 +020070 return 1;
71}
72
Willy Tarreaub6fb4202008-07-20 11:18:28 +020073/* wait for more data as long as possible, then return TRUE. This should be
74 * used with content inspection.
75 */
76static int
77acl_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 Tarreau58393e12008-07-20 10:39:22 +020088/* force FALSE to be returned at the fetch level */
Willy Tarreaua5909832007-06-17 20:40:25 +020089static int
Willy Tarreau58393e12008-07-20 10:39:22 +020090acl_fetch_false(struct proxy *px, struct session *l4, void *l7, int dir,
91 struct acl_expr *expr, struct acl_test *test)
Willy Tarreaua84d3742007-05-07 00:36:48 +020092{
Willy Tarreau58393e12008-07-20 10:39:22 +020093 test->flags |= ACL_TEST_F_SET_RES_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +020094 return 1;
95}
96
Willy Tarreau44b90cc2010-05-24 20:27:29 +020097/* return the number of bytes in the request buffer */
98static int
99acl_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 Brun38e71762010-09-23 17:59:18 +0200110
111static int
112acl_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 Tarreau44b90cc2010-05-24 20:27:29 +0200171/* 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 */
179static int
180acl_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
Willy Tarreaub6672b52011-12-12 17:23:41 +0100281/* Try to extract the Server Name Indication that may be presented in a TLS
282 * client hello handshake message. The format of the message is the following
283 * (cf RFC5246 + RFC6066) :
284 * TLS frame :
285 * - uint8 type = 0x16 (Handshake)
286 * - uint16 version >= 0x0301 (TLSv1)
287 * - uint16 length (frame length)
288 * - TLS handshake :
289 * - uint8 msg_type = 0x01 (ClientHello)
290 * - uint24 length (handshake message length)
291 * - ClientHello :
292 * - uint16 client_version >= 0x0301 (TLSv1)
293 * - uint8 Random[32]
294 * - SessionID :
295 * - uint8 session_id_len (0..32) (SessionID len in bytes)
296 * - uint8 session_id[session_id_len]
297 * - CipherSuite :
298 * - uint16 cipher_len >= 2 (Cipher length in bytes)
299 * - uint16 ciphers[cipher_len/2]
300 * - CompressionMethod :
301 * - uint8 compression_len >= 1 (# of supported methods)
302 * - uint8 compression_methods[compression_len]
303 * - optional client_extension_len (in bytes)
304 * - optional sequence of ClientHelloExtensions (as many bytes as above):
305 * - uint16 extension_type = 0 for server_name
306 * - uint16 extension_len
307 * - opaque extension_data[extension_len]
308 * - uint16 server_name_list_len (# of bytes here)
309 * - opaque server_names[server_name_list_len bytes]
310 * - uint8 name_type = 0 for host_name
311 * - uint16 name_len
312 * - opaque hostname[name_len bytes]
313 */
314static int
315acl_fetch_ssl_hello_sni(struct proxy *px, struct session *l4, void *l7, int dir,
316 struct acl_expr *expr, struct acl_test *test)
317{
318 int hs_len, ext_len, bleft;
319 struct buffer *b;
320 unsigned char *data;
321
322 if (!l4)
323 goto not_ssl_hello;
324
325 b = ((dir & ACL_DIR_MASK) == ACL_DIR_RTR) ? l4->rep : l4->req;
326
327 bleft = b->l;
328 data = (unsigned char *)b->w;
329
330 /* Check for SSL/TLS Handshake */
331 if (!bleft)
332 goto too_short;
333 if (*data != 0x16)
334 goto not_ssl_hello;
335
336 /* Check for TLSv1 or later (SSL version >= 3.1) */
337 if (bleft < 3)
338 goto too_short;
339 if (data[1] < 0x03 || data[2] < 0x01)
340 goto not_ssl_hello;
341
342 if (bleft < 5)
343 goto too_short;
344 hs_len = (data[3] << 8) + data[4];
345 if (hs_len < 1 + 3 + 2 + 32 + 1 + 2 + 2 + 1 + 1 + 2 + 2)
346 goto not_ssl_hello; /* too short to have an extension */
347
348 data += 5; /* enter TLS handshake */
349 bleft -= 5;
350
351 /* Check for a complete client hello starting at <data> */
352 if (bleft < 1)
353 goto too_short;
354 if (data[0] != 0x01) /* msg_type = Client Hello */
355 goto not_ssl_hello;
356
357 /* Check the Hello's length */
358 if (bleft < 4)
359 goto too_short;
360 hs_len = (data[1] << 16) + (data[2] << 8) + data[3];
361 if (hs_len < 2 + 32 + 1 + 2 + 2 + 1 + 1 + 2 + 2)
362 goto not_ssl_hello; /* too short to have an extension */
363
364 /* We want the full handshake here */
365 if (bleft < hs_len)
366 goto too_short;
367
368 data += 4;
369 /* Start of the ClientHello message */
370 if (data[0] < 0x03 || data[1] < 0x01) /* TLSv1 minimum */
371 goto not_ssl_hello;
372
373 ext_len = data[35];
374 if (ext_len > 32 || ext_len > (hs_len - 35)) /* check for correct session_id len */
375 goto not_ssl_hello;
376
377 /* Jump to cipher suite */
378 hs_len -= 35 + ext_len;
379 data += 35 + ext_len;
380
381 if (hs_len < 4 || /* minimum one cipher */
382 (ext_len = (data[0] << 8) + data[1]) < 2 || /* minimum 2 bytes for a cipher */
383 ext_len > hs_len)
384 goto not_ssl_hello;
385
386 /* Jump to the compression methods */
387 hs_len -= 2 + ext_len;
388 data += 2 + ext_len;
389
390 if (hs_len < 2 || /* minimum one compression method */
391 data[0] < 1 || data[0] > hs_len) /* minimum 1 bytes for a method */
392 goto not_ssl_hello;
393
394 /* Jump to the extensions */
395 hs_len -= 1 + data[0];
396 data += 1 + data[0];
397
398 if (hs_len < 2 || /* minimum one extension list length */
399 (ext_len = (data[0] << 8) + data[1]) > hs_len - 2) /* list too long */
400 goto not_ssl_hello;
401
402 hs_len = ext_len; /* limit ourselves to the extension length */
403 data += 2;
404
405 while (hs_len >= 4) {
406 int ext_type, name_type, srv_len, name_len;
407
408 ext_type = (data[0] << 8) + data[1];
409 ext_len = (data[2] << 8) + data[3];
410
411 if (ext_len > hs_len - 4) /* Extension too long */
412 goto not_ssl_hello;
413
414 if (ext_type == 0) { /* Server name */
415 if (ext_len < 2) /* need one list length */
416 goto not_ssl_hello;
417
418 srv_len = (data[4] << 8) + data[5];
419 if (srv_len < 4 || srv_len > hs_len - 6)
420 goto not_ssl_hello; /* at least 4 bytes per server name */
421
422 name_type = data[6];
423 name_len = (data[7] << 8) + data[8];
424
425 if (name_type == 0) { /* hostname */
426 test->ptr = data + 9;
427 test->len = name_len;
428 test->flags = ACL_TEST_F_VOLATILE;
429 //fprintf(stderr, "found SNI : <");
430 //write(2, test->ptr, test->len);
431 //fprintf(stderr, ">\n");
432 return 1;
433 }
434 }
435
436 hs_len -= 4 + ext_len;
437 data += 4 + ext_len;
438 }
439 /* server name not found */
440 goto not_ssl_hello;
441
442 too_short:
443 test->flags = ACL_TEST_F_MAY_CHANGE;
444
445 not_ssl_hello:
446
447 return 0;
448}
449
Willy Tarreau44b90cc2010-05-24 20:27:29 +0200450/* Fetch the RDP cookie identified in the expression.
451 * Note: this decoder only works with non-wrapping data.
452 */
453int
454acl_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
465 bleft = l4->req->l;
466 if (bleft <= 11)
467 goto too_short;
468
469 data = (const unsigned char *)l4->req->w + 11;
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
486 if (expr->arg_len) {
487
488 if (bleft <= expr->arg_len)
489 goto too_short;
490
491 if ((data[expr->arg_len] != '=') ||
492 strncasecmp(expr->arg.str, (const char *)data, expr->arg_len) != 0)
493 goto not_cookie;
494
495 data += expr->arg_len + 1;
496 bleft -= expr->arg_len + 1;
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 */
516 test->ptr = (char *)data;
517 test->len = 0;
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
530 test->len = (char *)data - test->ptr;
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
540static int
541acl_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
548 test->ptr = NULL;
549 test->len = 0;
550
551 if (test->flags & ACL_TEST_F_MAY_CHANGE)
552 return 0;
553
554 test->flags = ACL_TEST_F_VOLATILE;
555 test->i = ret;
556
557 return 1;
558}
559
Willy Tarreau58393e12008-07-20 10:39:22 +0200560
561/*
562 * These functions are exported and may be used by any other component.
563 */
564
565/* ignore the current line */
566int acl_parse_nothing(const char **text, struct acl_pattern *pattern, int *opaque)
Willy Tarreaua5909832007-06-17 20:40:25 +0200567{
Willy Tarreau58393e12008-07-20 10:39:22 +0200568 return 1;
569}
570
571/* always fake a data retrieval */
572int 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 Tarreaua5909832007-06-17 20:40:25 +0200576}
577
578/* always return false */
Willy Tarreau58393e12008-07-20 10:39:22 +0200579int acl_match_nothing(struct acl_test *test, struct acl_pattern *pattern)
Willy Tarreaua5909832007-06-17 20:40:25 +0200580{
Willy Tarreau11382812008-07-09 16:18:21 +0200581 return ACL_PAT_FAIL;
Willy Tarreaua5909832007-06-17 20:40:25 +0200582}
583
584
Willy Tarreaua84d3742007-05-07 00:36:48 +0200585/* NB: For two strings to be identical, it is required that their lengths match */
586int acl_match_str(struct acl_test *test, struct acl_pattern *pattern)
587{
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200588 int icase;
589
Willy Tarreaua84d3742007-05-07 00:36:48 +0200590 if (pattern->len != test->len)
Willy Tarreau11382812008-07-09 16:18:21 +0200591 return ACL_PAT_FAIL;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200592
593 icase = pattern->flags & ACL_PAT_F_IGNORE_CASE;
594 if ((icase && strncasecmp(pattern->ptr.str, test->ptr, test->len) == 0) ||
595 (!icase && strncmp(pattern->ptr.str, test->ptr, test->len) == 0))
Willy Tarreau11382812008-07-09 16:18:21 +0200596 return ACL_PAT_PASS;
597 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200598}
599
Willy Tarreauc4262962010-05-10 23:42:40 +0200600/* Lookup a string in the expression's pattern tree. The node is returned if it
601 * exists, otherwise NULL.
602 */
603void *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 */
610 prev = test->ptr[test->len];
611 if (prev)
612 test->ptr[test->len] = '\0';
613 node = ebst_lookup(&expr->pattern_tree, test->ptr);
614 if (prev)
615 test->ptr[test->len] = prev;
616 return node;
617}
618
Willy Tarreauf3d25982007-05-08 22:45:09 +0200619/* 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 */
624int 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
632 new_str = calloc(1, test->len + 1);
633 if (!new_str)
Willy Tarreau11382812008-07-09 16:18:21 +0200634 return ACL_PAT_FAIL;
Willy Tarreauf3d25982007-05-08 22:45:09 +0200635
636 memcpy(new_str, test->ptr, test->len);
637 new_str[test->len] = 0;
638 if (test->flags & ACL_TEST_F_MUST_FREE)
639 free(test->ptr);
640 test->ptr = new_str;
641 test->flags |= ACL_TEST_F_MUST_FREE;
642 test->flags &= ~ACL_TEST_F_READ_ONLY;
643 }
644
645 old_char = test->ptr[test->len];
646 test->ptr[test->len] = 0;
647
648 if (regexec(pattern->ptr.reg, test->ptr, 0, NULL, 0) == 0)
Willy Tarreau11382812008-07-09 16:18:21 +0200649 ret = ACL_PAT_PASS;
Willy Tarreauf3d25982007-05-08 22:45:09 +0200650 else
Willy Tarreau11382812008-07-09 16:18:21 +0200651 ret = ACL_PAT_FAIL;
Willy Tarreauf3d25982007-05-08 22:45:09 +0200652
653 test->ptr[test->len] = old_char;
654 return ret;
655}
656
Willy Tarreaua84d3742007-05-07 00:36:48 +0200657/* Checks that the pattern matches the beginning of the tested string. */
658int acl_match_beg(struct acl_test *test, struct acl_pattern *pattern)
659{
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200660 int icase;
661
Willy Tarreaua84d3742007-05-07 00:36:48 +0200662 if (pattern->len > test->len)
Willy Tarreau11382812008-07-09 16:18:21 +0200663 return ACL_PAT_FAIL;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200664
665 icase = pattern->flags & ACL_PAT_F_IGNORE_CASE;
666 if ((icase && strncasecmp(pattern->ptr.str, test->ptr, pattern->len) != 0) ||
667 (!icase && strncmp(pattern->ptr.str, test->ptr, pattern->len) != 0))
Willy Tarreau11382812008-07-09 16:18:21 +0200668 return ACL_PAT_FAIL;
669 return ACL_PAT_PASS;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200670}
671
672/* Checks that the pattern matches the end of the tested string. */
673int acl_match_end(struct acl_test *test, struct acl_pattern *pattern)
674{
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200675 int icase;
676
Willy Tarreaua84d3742007-05-07 00:36:48 +0200677 if (pattern->len > test->len)
Willy Tarreau11382812008-07-09 16:18:21 +0200678 return ACL_PAT_FAIL;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200679 icase = pattern->flags & ACL_PAT_F_IGNORE_CASE;
680 if ((icase && strncasecmp(pattern->ptr.str, test->ptr + test->len - pattern->len, pattern->len) != 0) ||
681 (!icase && strncmp(pattern->ptr.str, test->ptr + test->len - pattern->len, pattern->len) != 0))
Willy Tarreau11382812008-07-09 16:18:21 +0200682 return ACL_PAT_FAIL;
683 return ACL_PAT_PASS;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200684}
685
686/* Checks that the pattern is included inside the tested string.
687 * NB: Suboptimal, should be rewritten using a Boyer-Moore method.
688 */
689int acl_match_sub(struct acl_test *test, struct acl_pattern *pattern)
690{
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200691 int icase;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200692 char *end;
693 char *c;
694
695 if (pattern->len > test->len)
Willy Tarreau11382812008-07-09 16:18:21 +0200696 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200697
698 end = test->ptr + test->len - pattern->len;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200699 icase = pattern->flags & ACL_PAT_F_IGNORE_CASE;
700 if (icase) {
701 for (c = test->ptr; c <= end; c++) {
702 if (tolower(*c) != tolower(*pattern->ptr.str))
703 continue;
704 if (strncasecmp(pattern->ptr.str, c, pattern->len) == 0)
Willy Tarreau11382812008-07-09 16:18:21 +0200705 return ACL_PAT_PASS;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200706 }
707 } else {
708 for (c = test->ptr; c <= end; c++) {
709 if (*c != *pattern->ptr.str)
710 continue;
711 if (strncmp(pattern->ptr.str, c, pattern->len) == 0)
Willy Tarreau11382812008-07-09 16:18:21 +0200712 return ACL_PAT_PASS;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200713 }
Willy Tarreaua84d3742007-05-07 00:36:48 +0200714 }
Willy Tarreau11382812008-07-09 16:18:21 +0200715 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200716}
717
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200718/* 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 */
729static 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
735static 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 Tarreaua84d3742007-05-07 00:36:48 +0200740/* 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 Gangstade8c7ecc2011-09-09 16:09:50 +0200742 * 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 Tarreaua84d3742007-05-07 00:36:48 +0200745 */
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200746static int match_word(struct acl_test *test, struct acl_pattern *pattern, unsigned int delimiters)
Willy Tarreaua84d3742007-05-07 00:36:48 +0200747{
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200748 int may_match, icase;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200749 char *c, *end;
750 char *ps;
751 int pl;
752
753 pl = pattern->len;
754 ps = pattern->ptr.str;
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200755
756 while (pl > 0 && is_delimiter(*ps, delimiters)) {
Willy Tarreaua84d3742007-05-07 00:36:48 +0200757 pl--;
758 ps++;
759 }
760
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200761 while (pl > 0 && is_delimiter(ps[pl - 1], delimiters))
Willy Tarreaua84d3742007-05-07 00:36:48 +0200762 pl--;
763
764 if (pl > test->len)
Willy Tarreau11382812008-07-09 16:18:21 +0200765 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200766
767 may_match = 1;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200768 icase = pattern->flags & ACL_PAT_F_IGNORE_CASE;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200769 end = test->ptr + test->len - pl;
770 for (c = test->ptr; c <= end; c++) {
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200771 if (is_delimiter(*c, delimiters)) {
Willy Tarreaua84d3742007-05-07 00:36:48 +0200772 may_match = 1;
773 continue;
774 }
Willy Tarreaua84d3742007-05-07 00:36:48 +0200775
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200776 if (!may_match)
777 continue;
778
779 if (icase) {
780 if ((tolower(*c) == tolower(*ps)) &&
781 (strncasecmp(ps, c, pl) == 0) &&
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200782 (c == end || is_delimiter(c[pl], delimiters)))
Willy Tarreau11382812008-07-09 16:18:21 +0200783 return ACL_PAT_PASS;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200784 } else {
785 if ((*c == *ps) &&
786 (strncmp(ps, c, pl) == 0) &&
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200787 (c == end || is_delimiter(c[pl], delimiters)))
Willy Tarreau11382812008-07-09 16:18:21 +0200788 return ACL_PAT_PASS;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200789 }
Willy Tarreaua84d3742007-05-07 00:36:48 +0200790 may_match = 0;
791 }
Willy Tarreau11382812008-07-09 16:18:21 +0200792 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200793}
794
795/* Checks that the pattern is included inside the tested string, but enclosed
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200796 * 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 Tarreaua84d3742007-05-07 00:36:48 +0200798 */
799int acl_match_dir(struct acl_test *test, struct acl_pattern *pattern)
800{
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200801 return match_word(test, pattern, make_4delim('/', '?', '?', '?'));
Willy Tarreaua84d3742007-05-07 00:36:48 +0200802}
803
804/* Checks that the pattern is included inside the tested string, but enclosed
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200805 * 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 Tarreaua84d3742007-05-07 00:36:48 +0200807 */
808int acl_match_dom(struct acl_test *test, struct acl_pattern *pattern)
809{
Finn Arne Gangstade8c7ecc2011-09-09 16:09:50 +0200810 return match_word(test, pattern, make_4delim('/', '?', '.', ':'));
Willy Tarreaua84d3742007-05-07 00:36:48 +0200811}
812
813/* Checks that the integer in <test> is included between min and max */
Willy Tarreauae8b7962007-06-09 23:10:04 +0200814int acl_match_int(struct acl_test *test, struct acl_pattern *pattern)
Willy Tarreaua84d3742007-05-07 00:36:48 +0200815{
Willy Tarreauae8b7962007-06-09 23:10:04 +0200816 if ((!pattern->val.range.min_set || pattern->val.range.min <= test->i) &&
817 (!pattern->val.range.max_set || test->i <= pattern->val.range.max))
Willy Tarreau11382812008-07-09 16:18:21 +0200818 return ACL_PAT_PASS;
819 return ACL_PAT_FAIL;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200820}
821
Willy Tarreau0e698542011-09-16 08:32:32 +0200822/* Checks that the length of the pattern in <test> is included between min and max */
823int acl_match_len(struct acl_test *test, struct acl_pattern *pattern)
824{
825 if ((!pattern->val.range.min_set || pattern->val.range.min <= test->len) &&
826 (!pattern->val.range.max_set || test->len <= pattern->val.range.max))
827 return ACL_PAT_PASS;
828 return ACL_PAT_FAIL;
829}
830
Willy Tarreaua67fad92007-05-08 19:50:09 +0200831int acl_match_ip(struct acl_test *test, struct acl_pattern *pattern)
832{
833 struct in_addr *s;
834
835 if (test->i != AF_INET)
Willy Tarreau11382812008-07-09 16:18:21 +0200836 return ACL_PAT_FAIL;
Willy Tarreaua67fad92007-05-08 19:50:09 +0200837
838 s = (void *)test->ptr;
839 if (((s->s_addr ^ pattern->val.ipv4.addr.s_addr) & pattern->val.ipv4.mask.s_addr) == 0)
Willy Tarreau11382812008-07-09 16:18:21 +0200840 return ACL_PAT_PASS;
841 return ACL_PAT_FAIL;
Willy Tarreaua67fad92007-05-08 19:50:09 +0200842}
843
Willy Tarreaub337b532010-05-13 20:03:41 +0200844/* 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 */
847void *acl_lookup_ip(struct acl_test *test, struct acl_expr *expr)
848{
849 struct in_addr *s;
850
851 if (test->i != AF_INET)
852 return ACL_PAT_FAIL;
853
854 s = (void *)test->ptr;
855
856 return ebmb_lookup_longest(&expr->pattern_tree, &s->s_addr);
857}
858
Willy Tarreaua84d3742007-05-07 00:36:48 +0200859/* Parse a string. It is allocated and duplicated. */
Willy Tarreauae8b7962007-06-09 23:10:04 +0200860int acl_parse_str(const char **text, struct acl_pattern *pattern, int *opaque)
Willy Tarreaua84d3742007-05-07 00:36:48 +0200861{
862 int len;
863
Willy Tarreauae8b7962007-06-09 23:10:04 +0200864 len = strlen(*text);
Willy Tarreauc4262962010-05-10 23:42:40 +0200865
866 if (pattern->flags & ACL_PAT_F_TREE_OK) {
867 /* we're allowed to put the data in a tree whose root is pointed
868 * to by val.tree.
869 */
870 struct ebmb_node *node;
871
872 node = calloc(1, sizeof(*node) + len + 1);
873 if (!node)
874 return 0;
875 memcpy(node->key, *text, len + 1);
876 if (ebst_insert(pattern->val.tree, node) != node)
877 free(node); /* was a duplicate */
878 pattern->flags |= ACL_PAT_F_TREE; /* this pattern now contains a tree */
879 return 1;
880 }
881
Willy Tarreauae8b7962007-06-09 23:10:04 +0200882 pattern->ptr.str = strdup(*text);
Willy Tarreaua84d3742007-05-07 00:36:48 +0200883 if (!pattern->ptr.str)
884 return 0;
885 pattern->len = len;
886 return 1;
887}
888
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +0100889/* Parse and concatenate all further strings into one. */
890int
891acl_parse_strcat(const char **text, struct acl_pattern *pattern, int *opaque)
892{
893
894 int len = 0, i;
895 char *s;
896
897 for (i = 0; *text[i]; i++)
898 len += strlen(text[i])+1;
899
900 pattern->ptr.str = s = calloc(1, len);
901 if (!pattern->ptr.str)
902 return 0;
903
904 for (i = 0; *text[i]; i++)
905 s += sprintf(s, i?" %s":"%s", text[i]);
906
907 pattern->len = len;
908
909 return i;
910}
911
Krzysztof Piotr Oledzki8001d612008-05-31 13:53:23 +0200912/* Free data allocated by acl_parse_reg */
913static void acl_free_reg(void *ptr) {
914
915 regfree((regex_t *)ptr);
916}
917
Willy Tarreauf3d25982007-05-08 22:45:09 +0200918/* Parse a regex. It is allocated. */
Willy Tarreauae8b7962007-06-09 23:10:04 +0200919int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque)
Willy Tarreauf3d25982007-05-08 22:45:09 +0200920{
921 regex_t *preg;
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200922 int icase;
Willy Tarreauf3d25982007-05-08 22:45:09 +0200923
924 preg = calloc(1, sizeof(regex_t));
925
926 if (!preg)
927 return 0;
928
Willy Tarreauc8d7c962007-06-17 08:20:33 +0200929 icase = (pattern->flags & ACL_PAT_F_IGNORE_CASE) ? REG_ICASE : 0;
930 if (regcomp(preg, *text, REG_EXTENDED | REG_NOSUB | icase) != 0) {
Willy Tarreauf3d25982007-05-08 22:45:09 +0200931 free(preg);
932 return 0;
933 }
934
935 pattern->ptr.reg = preg;
Krzysztof Piotr Oledzki8001d612008-05-31 13:53:23 +0200936 pattern->freeptrbuf = &acl_free_reg;
Willy Tarreauf3d25982007-05-08 22:45:09 +0200937 return 1;
938}
939
Willy Tarreauae8b7962007-06-09 23:10:04 +0200940/* Parse a range of positive integers delimited by either ':' or '-'. If only
941 * one integer is read, it is set as both min and max. An operator may be
942 * specified as the prefix, among this list of 5 :
943 *
944 * 0:eq, 1:gt, 2:ge, 3:lt, 4:le
945 *
946 * The default operator is "eq". It supports range matching. Ranges are
947 * rejected for other operators. The operator may be changed at any time.
948 * The operator is stored in the 'opaque' argument.
949 *
Willy Tarreaua84d3742007-05-07 00:36:48 +0200950 */
Willy Tarreauae8b7962007-06-09 23:10:04 +0200951int acl_parse_int(const char **text, struct acl_pattern *pattern, int *opaque)
Willy Tarreaua84d3742007-05-07 00:36:48 +0200952{
Willy Tarreauae8b7962007-06-09 23:10:04 +0200953 signed long long i;
954 unsigned int j, last, skip = 0;
955 const char *ptr = *text;
956
957
Willy Tarreau8f8e6452007-06-17 21:51:38 +0200958 while (!isdigit((unsigned char)*ptr)) {
Willy Tarreau1c7cc5b2010-07-18 10:46:33 +0200959 switch (get_std_op(ptr)) {
960 case STD_OP_EQ: *opaque = 0; break;
961 case STD_OP_GT: *opaque = 1; break;
962 case STD_OP_GE: *opaque = 2; break;
963 case STD_OP_LT: *opaque = 3; break;
964 case STD_OP_LE: *opaque = 4; break;
965 default:
Willy Tarreauae8b7962007-06-09 23:10:04 +0200966 return 0;
Willy Tarreau1c7cc5b2010-07-18 10:46:33 +0200967 }
Willy Tarreauae8b7962007-06-09 23:10:04 +0200968
969 skip++;
970 ptr = text[skip];
971 }
Willy Tarreaua84d3742007-05-07 00:36:48 +0200972
973 last = i = 0;
974 while (1) {
Willy Tarreauae8b7962007-06-09 23:10:04 +0200975 j = *ptr++;
Willy Tarreaua84d3742007-05-07 00:36:48 +0200976 if ((j == '-' || j == ':') && !last) {
977 last++;
978 pattern->val.range.min = i;
979 i = 0;
980 continue;
981 }
982 j -= '0';
983 if (j > 9)
984 // also catches the terminating zero
985 break;
986 i *= 10;
987 i += j;
988 }
Willy Tarreauae8b7962007-06-09 23:10:04 +0200989
990 if (last && *opaque >= 1 && *opaque <= 4)
991 /* having a range with a min or a max is absurd */
992 return 0;
993
Willy Tarreaua84d3742007-05-07 00:36:48 +0200994 if (!last)
995 pattern->val.range.min = i;
996 pattern->val.range.max = i;
Willy Tarreauae8b7962007-06-09 23:10:04 +0200997
998 switch (*opaque) {
999 case 0: /* eq */
1000 pattern->val.range.min_set = 1;
1001 pattern->val.range.max_set = 1;
1002 break;
1003 case 1: /* gt */
1004 pattern->val.range.min++; /* gt = ge + 1 */
1005 case 2: /* ge */
1006 pattern->val.range.min_set = 1;
1007 pattern->val.range.max_set = 0;
1008 break;
1009 case 3: /* lt */
1010 pattern->val.range.max--; /* lt = le - 1 */
1011 case 4: /* le */
1012 pattern->val.range.min_set = 0;
1013 pattern->val.range.max_set = 1;
1014 break;
1015 }
1016 return skip + 1;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001017}
1018
Willy Tarreau4a26d2f2008-07-15 16:05:33 +02001019/* Parse a range of positive 2-component versions delimited by either ':' or
1020 * '-'. The version consists in a major and a minor, both of which must be
1021 * smaller than 65536, because internally they will be represented as a 32-bit
1022 * integer.
1023 * If only one version is read, it is set as both min and max. Just like for
1024 * pure integers, an operator may be specified as the prefix, among this list
1025 * of 5 :
1026 *
1027 * 0:eq, 1:gt, 2:ge, 3:lt, 4:le
1028 *
1029 * The default operator is "eq". It supports range matching. Ranges are
1030 * rejected for other operators. The operator may be changed at any time.
1031 * The operator is stored in the 'opaque' argument. This allows constructs
1032 * such as the following one :
1033 *
1034 * acl obsolete_ssl ssl_req_proto lt 3
1035 * acl unsupported_ssl ssl_req_proto gt 3.1
1036 * acl valid_ssl ssl_req_proto 3.0-3.1
1037 *
1038 */
1039int acl_parse_dotted_ver(const char **text, struct acl_pattern *pattern, int *opaque)
1040{
1041 signed long long i;
1042 unsigned int j, last, skip = 0;
1043 const char *ptr = *text;
1044
1045
1046 while (!isdigit((unsigned char)*ptr)) {
Willy Tarreau1c7cc5b2010-07-18 10:46:33 +02001047 switch (get_std_op(ptr)) {
1048 case STD_OP_EQ: *opaque = 0; break;
1049 case STD_OP_GT: *opaque = 1; break;
1050 case STD_OP_GE: *opaque = 2; break;
1051 case STD_OP_LT: *opaque = 3; break;
1052 case STD_OP_LE: *opaque = 4; break;
1053 default:
Willy Tarreau4a26d2f2008-07-15 16:05:33 +02001054 return 0;
Willy Tarreau1c7cc5b2010-07-18 10:46:33 +02001055 }
Willy Tarreau4a26d2f2008-07-15 16:05:33 +02001056
1057 skip++;
1058 ptr = text[skip];
1059 }
1060
1061 last = i = 0;
1062 while (1) {
1063 j = *ptr++;
1064 if (j == '.') {
1065 /* minor part */
1066 if (i >= 65536)
1067 return 0;
1068 i <<= 16;
1069 continue;
1070 }
1071 if ((j == '-' || j == ':') && !last) {
1072 last++;
1073 if (i < 65536)
1074 i <<= 16;
1075 pattern->val.range.min = i;
1076 i = 0;
1077 continue;
1078 }
1079 j -= '0';
1080 if (j > 9)
1081 // also catches the terminating zero
1082 break;
1083 i = (i & 0xFFFF0000) + (i & 0xFFFF) * 10;
1084 i += j;
1085 }
1086
1087 /* if we only got a major version, let's shift it now */
1088 if (i < 65536)
1089 i <<= 16;
1090
1091 if (last && *opaque >= 1 && *opaque <= 4)
1092 /* having a range with a min or a max is absurd */
1093 return 0;
1094
1095 if (!last)
1096 pattern->val.range.min = i;
1097 pattern->val.range.max = i;
1098
1099 switch (*opaque) {
1100 case 0: /* eq */
1101 pattern->val.range.min_set = 1;
1102 pattern->val.range.max_set = 1;
1103 break;
1104 case 1: /* gt */
1105 pattern->val.range.min++; /* gt = ge + 1 */
1106 case 2: /* ge */
1107 pattern->val.range.min_set = 1;
1108 pattern->val.range.max_set = 0;
1109 break;
1110 case 3: /* lt */
1111 pattern->val.range.max--; /* lt = le - 1 */
1112 case 4: /* le */
1113 pattern->val.range.min_set = 0;
1114 pattern->val.range.max_set = 1;
1115 break;
1116 }
1117 return skip + 1;
1118}
1119
Willy Tarreaua67fad92007-05-08 19:50:09 +02001120/* Parse an IP address and an optional mask in the form addr[/mask].
1121 * The addr may either be an IPv4 address or a hostname. The mask
1122 * may either be a dotted mask or a number of bits. Returns 1 if OK,
1123 * otherwise 0.
1124 */
Willy Tarreauae8b7962007-06-09 23:10:04 +02001125int acl_parse_ip(const char **text, struct acl_pattern *pattern, int *opaque)
Willy Tarreaua67fad92007-05-08 19:50:09 +02001126{
Willy Tarreaub337b532010-05-13 20:03:41 +02001127 struct eb_root *tree = NULL;
1128 if (pattern->flags & ACL_PAT_F_TREE_OK)
1129 tree = pattern->val.tree;
1130
1131 if (str2net(*text, &pattern->val.ipv4.addr, &pattern->val.ipv4.mask)) {
1132 unsigned int mask = ntohl(pattern->val.ipv4.mask.s_addr);
1133 struct ebmb_node *node;
1134 /* check if the mask is contiguous so that we can insert the
1135 * network into the tree. A continuous mask has only ones on
1136 * the left. This means that this mask + its lower bit added
1137 * once again is null.
1138 */
1139 if (mask + (mask & -mask) == 0 && tree) {
1140 mask = mask ? 33 - flsnz(mask & -mask) : 0; /* equals cidr value */
1141 /* FIXME: insert <addr>/<mask> into the tree here */
1142 node = calloc(1, sizeof(*node) + 4); /* reserve 4 bytes for IPv4 address */
1143 if (!node)
1144 return 0;
1145 memcpy(node->key, &pattern->val.ipv4.addr, 4); /* network byte order */
1146 node->node.pfx = mask;
1147 if (ebmb_insert_prefix(tree, node, 4) != node)
1148 free(node); /* was a duplicate */
1149 pattern->flags |= ACL_PAT_F_TREE;
1150 return 1;
1151 }
Willy Tarreauae8b7962007-06-09 23:10:04 +02001152 return 1;
Willy Tarreaub337b532010-05-13 20:03:41 +02001153 }
Willy Tarreauae8b7962007-06-09 23:10:04 +02001154 else
1155 return 0;
Willy Tarreaua67fad92007-05-08 19:50:09 +02001156}
1157
Willy Tarreaua84d3742007-05-07 00:36:48 +02001158/*
1159 * Registers the ACL keyword list <kwl> as a list of valid keywords for next
1160 * parsing sessions.
1161 */
1162void acl_register_keywords(struct acl_kw_list *kwl)
1163{
1164 LIST_ADDQ(&acl_keywords.list, &kwl->list);
1165}
1166
1167/*
1168 * Unregisters the ACL keyword list <kwl> from the list of valid keywords.
1169 */
1170void acl_unregister_keywords(struct acl_kw_list *kwl)
1171{
1172 LIST_DEL(&kwl->list);
1173 LIST_INIT(&kwl->list);
1174}
1175
1176/* Return a pointer to the ACL <name> within the list starting at <head>, or
1177 * NULL if not found.
1178 */
1179struct acl *find_acl_by_name(const char *name, struct list *head)
1180{
1181 struct acl *acl;
1182 list_for_each_entry(acl, head, list) {
1183 if (strcmp(acl->name, name) == 0)
1184 return acl;
1185 }
1186 return NULL;
1187}
1188
1189/* Return a pointer to the ACL keyword <kw>, or NULL if not found. Note that if
1190 * <kw> contains an opening parenthesis, only the left part of it is checked.
1191 */
1192struct acl_keyword *find_acl_kw(const char *kw)
1193{
1194 int index;
1195 const char *kwend;
1196 struct acl_kw_list *kwl;
1197
1198 kwend = strchr(kw, '(');
1199 if (!kwend)
1200 kwend = kw + strlen(kw);
1201
1202 list_for_each_entry(kwl, &acl_keywords.list, list) {
1203 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1204 if ((strncmp(kwl->kw[index].kw, kw, kwend - kw) == 0) &&
1205 kwl->kw[index].kw[kwend-kw] == 0)
1206 return &kwl->kw[index];
1207 }
1208 }
1209 return NULL;
1210}
1211
Willy Tarreaudfd7fca2011-03-09 07:27:02 +01001212/* NB: does nothing if <pat> is NULL */
Willy Tarreaua84d3742007-05-07 00:36:48 +02001213static void free_pattern(struct acl_pattern *pat)
1214{
Willy Tarreaudfd7fca2011-03-09 07:27:02 +01001215 if (!pat)
1216 return;
Krzysztof Piotr Oledzki8001d612008-05-31 13:53:23 +02001217
1218 if (pat->ptr.ptr) {
1219 if (pat->freeptrbuf)
1220 pat->freeptrbuf(pat->ptr.ptr);
1221
Willy Tarreaua84d3742007-05-07 00:36:48 +02001222 free(pat->ptr.ptr);
Krzysztof Piotr Oledzki8001d612008-05-31 13:53:23 +02001223 }
1224
Willy Tarreaua84d3742007-05-07 00:36:48 +02001225 free(pat);
1226}
1227
1228static void free_pattern_list(struct list *head)
1229{
1230 struct acl_pattern *pat, *tmp;
1231 list_for_each_entry_safe(pat, tmp, head, list)
1232 free_pattern(pat);
1233}
1234
Willy Tarreaue56cda92010-05-11 23:25:05 +02001235static void free_pattern_tree(struct eb_root *root)
1236{
1237 struct eb_node *node, *next;
1238 node = eb_first(root);
1239 while (node) {
1240 next = eb_next(node);
1241 free(node);
1242 node = next;
1243 }
1244}
1245
Willy Tarreaua84d3742007-05-07 00:36:48 +02001246static struct acl_expr *prune_acl_expr(struct acl_expr *expr)
1247{
1248 free_pattern_list(&expr->patterns);
Willy Tarreaue56cda92010-05-11 23:25:05 +02001249 free_pattern_tree(&expr->pattern_tree);
Willy Tarreaua84d3742007-05-07 00:36:48 +02001250 LIST_INIT(&expr->patterns);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001251 if (expr->arg_len && expr->arg.str)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001252 free(expr->arg.str);
1253 expr->kw->use_cnt--;
1254 return expr;
1255}
1256
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001257static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
1258 struct acl_expr *expr,
1259 const char *filename, int patflags)
1260{
1261 FILE *file;
1262 char *c;
1263 const char *args[2];
1264 struct acl_pattern *pattern;
1265 int opaque;
Willy Tarreau6a8097f2011-02-26 15:14:15 +01001266 int ret = 0;
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001267
1268 file = fopen(filename, "r");
1269 if (!file)
1270 return 0;
1271
1272 /* now parse all patterns. The file may contain only one pattern per
1273 * line. If the line contains spaces, they will be part of the pattern.
1274 * The pattern stops at the first CR, LF or EOF encountered.
1275 */
1276 opaque = 0;
Willy Tarreaue56cda92010-05-11 23:25:05 +02001277 pattern = NULL;
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001278 args[1] = "";
1279 while (fgets(trash, sizeof(trash), file) != NULL) {
1280
1281 c = trash;
Willy Tarreau58215a02010-05-13 22:07:43 +02001282
1283 /* ignore lines beginning with a dash */
1284 if (*c == '#')
1285 continue;
1286
1287 /* strip leading spaces and tabs */
1288 while (*c == ' ' || *c == '\t')
1289 c++;
1290
Willy Tarreau58215a02010-05-13 22:07:43 +02001291
1292 args[0] = c;
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001293 while (*c && *c != '\n' && *c != '\r')
1294 c++;
1295 *c = 0;
1296
Willy Tarreau51091962011-01-03 21:04:10 +01001297 /* empty lines are ignored too */
1298 if (c == args[0])
1299 continue;
1300
Willy Tarreaue56cda92010-05-11 23:25:05 +02001301 /* we keep the previous pattern along iterations as long as it's not used */
1302 if (!pattern)
1303 pattern = (struct acl_pattern *)malloc(sizeof(*pattern));
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001304 if (!pattern)
1305 goto out_close;
Willy Tarreaue56cda92010-05-11 23:25:05 +02001306
1307 memset(pattern, 0, sizeof(*pattern));
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001308 pattern->flags = patflags;
1309
Willy Tarreaue56cda92010-05-11 23:25:05 +02001310 if ((aclkw->requires & ACL_MAY_LOOKUP) && !(pattern->flags & ACL_PAT_F_IGNORE_CASE)) {
1311 /* we pre-set the data pointer to the tree's head so that functions
1312 * which are able to insert in a tree know where to do that.
1313 */
1314 pattern->flags |= ACL_PAT_F_TREE_OK;
1315 pattern->val.tree = &expr->pattern_tree;
1316 }
1317
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001318 if (!aclkw->parse(args, pattern, &opaque))
1319 goto out_free_pattern;
Willy Tarreaue56cda92010-05-11 23:25:05 +02001320
1321 /* if the parser did not feed the tree, let's chain the pattern to the list */
1322 if (!(pattern->flags & ACL_PAT_F_TREE)) {
1323 LIST_ADDQ(&expr->patterns, &pattern->list);
1324 pattern = NULL; /* get a new one */
1325 }
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001326 }
Willy Tarreau6a8097f2011-02-26 15:14:15 +01001327
1328 ret = 1; /* success */
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001329
1330 out_free_pattern:
1331 free_pattern(pattern);
1332 out_close:
1333 fclose(file);
Willy Tarreau6a8097f2011-02-26 15:14:15 +01001334 return ret;
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001335}
1336
Willy Tarreaua84d3742007-05-07 00:36:48 +02001337/* Parse an ACL expression starting at <args>[0], and return it.
1338 * Right now, the only accepted syntax is :
1339 * <subject> [<value>...]
1340 */
1341struct acl_expr *parse_acl_expr(const char **args)
1342{
1343 __label__ out_return, out_free_expr, out_free_pattern;
1344 struct acl_expr *expr;
1345 struct acl_keyword *aclkw;
1346 struct acl_pattern *pattern;
Willy Tarreauc8d7c962007-06-17 08:20:33 +02001347 int opaque, patflags;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001348 const char *arg;
1349
1350 aclkw = find_acl_kw(args[0]);
1351 if (!aclkw || !aclkw->parse)
1352 goto out_return;
1353
1354 expr = (struct acl_expr *)calloc(1, sizeof(*expr));
1355 if (!expr)
1356 goto out_return;
1357
1358 expr->kw = aclkw;
1359 aclkw->use_cnt++;
1360 LIST_INIT(&expr->patterns);
Willy Tarreaue56cda92010-05-11 23:25:05 +02001361 expr->pattern_tree = EB_ROOT_UNIQUE;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001362 expr->arg.str = NULL;
Willy Tarreaubb768912007-06-10 11:17:01 +02001363 expr->arg_len = 0;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001364
1365 arg = strchr(args[0], '(');
1366 if (arg != NULL) {
1367 char *end, *arg2;
1368 /* there is an argument in the form "subject(arg)" */
1369 arg++;
1370 end = strchr(arg, ')');
1371 if (!end)
1372 goto out_free_expr;
Willy Tarreauac778f52010-01-26 19:02:46 +01001373 arg2 = my_strndup(arg, end - arg);
Willy Tarreau1edb1442010-01-27 20:13:38 +01001374 if (!arg2)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001375 goto out_free_expr;
Willy Tarreaubb768912007-06-10 11:17:01 +02001376 expr->arg_len = end - arg;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001377 expr->arg.str = arg2;
1378 }
1379
Willy Tarreaua84d3742007-05-07 00:36:48 +02001380 args++;
Willy Tarreauc8d7c962007-06-17 08:20:33 +02001381
1382 /* check for options before patterns. Supported options are :
1383 * -i : ignore case for all patterns by default
1384 * -f : read patterns from those files
1385 * -- : everything after this is not an option
1386 */
1387 patflags = 0;
1388 while (**args == '-') {
1389 if ((*args)[1] == 'i')
1390 patflags |= ACL_PAT_F_IGNORE_CASE;
Willy Tarreau2b5285d2010-05-09 23:45:24 +02001391 else if ((*args)[1] == 'f') {
1392 if (!acl_read_patterns_from_file(aclkw, expr, args[1], patflags | ACL_PAT_F_FROM_FILE))
1393 goto out_free_expr;
1394 args++;
1395 }
Willy Tarreauc8d7c962007-06-17 08:20:33 +02001396 else if ((*args)[1] == '-') {
1397 args++;
1398 break;
1399 }
1400 else
1401 break;
1402 args++;
1403 }
1404
1405 /* now parse all patterns */
Willy Tarreauae8b7962007-06-09 23:10:04 +02001406 opaque = 0;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001407 while (**args) {
Willy Tarreauae8b7962007-06-09 23:10:04 +02001408 int ret;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001409 pattern = (struct acl_pattern *)calloc(1, sizeof(*pattern));
1410 if (!pattern)
1411 goto out_free_expr;
Willy Tarreauc8d7c962007-06-17 08:20:33 +02001412 pattern->flags = patflags;
1413
Willy Tarreauae8b7962007-06-09 23:10:04 +02001414 ret = aclkw->parse(args, pattern, &opaque);
1415 if (!ret)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001416 goto out_free_pattern;
1417 LIST_ADDQ(&expr->patterns, &pattern->list);
Willy Tarreauae8b7962007-06-09 23:10:04 +02001418 args += ret;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001419 }
1420
1421 return expr;
1422
1423 out_free_pattern:
1424 free_pattern(pattern);
1425 out_free_expr:
1426 prune_acl_expr(expr);
1427 free(expr);
1428 out_return:
1429 return NULL;
1430}
1431
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +02001432/* Purge everything in the acl <acl>, then return <acl>. */
1433struct acl *prune_acl(struct acl *acl) {
1434
1435 struct acl_expr *expr, *exprb;
1436
1437 free(acl->name);
1438
1439 list_for_each_entry_safe(expr, exprb, &acl->expr, list) {
1440 LIST_DEL(&expr->list);
1441 prune_acl_expr(expr);
1442 free(expr);
1443 }
1444
1445 return acl;
1446}
1447
Willy Tarreaua84d3742007-05-07 00:36:48 +02001448/* Parse an ACL with the name starting at <args>[0], and with a list of already
1449 * known ACLs in <acl>. If the ACL was not in the list, it will be added.
Willy Tarreau2a56c5e2010-03-15 16:13:29 +01001450 * A pointer to that ACL is returned. If the ACL has an empty name, then it's
1451 * an anonymous one and it won't be merged with any other one.
Willy Tarreaua84d3742007-05-07 00:36:48 +02001452 *
1453 * args syntax: <aclname> <acl_expr>
1454 */
1455struct acl *parse_acl(const char **args, struct list *known_acl)
1456{
1457 __label__ out_return, out_free_acl_expr, out_free_name;
1458 struct acl *cur_acl;
1459 struct acl_expr *acl_expr;
1460 char *name;
1461
Willy Tarreau2a56c5e2010-03-15 16:13:29 +01001462 if (**args && invalid_char(*args))
Willy Tarreau2e74c3f2007-12-02 18:45:09 +01001463 goto out_return;
1464
Willy Tarreaua84d3742007-05-07 00:36:48 +02001465 acl_expr = parse_acl_expr(args + 1);
1466 if (!acl_expr)
1467 goto out_return;
1468
Willy Tarreau404e8ab2009-07-26 19:40:40 +02001469 /* Check for args beginning with an opening parenthesis just after the
1470 * subject, as this is almost certainly a typo. Right now we can only
1471 * emit a warning, so let's do so.
1472 */
Krzysztof Piotr Oledzki4cdd8312009-10-05 00:23:35 +02001473 if (!strchr(args[1], '(') && *args[2] == '(')
Willy Tarreau404e8ab2009-07-26 19:40:40 +02001474 Warning("parsing acl '%s' :\n"
1475 " matching '%s' for pattern '%s' is likely a mistake and probably\n"
1476 " not what you want. Maybe you need to remove the extraneous space before '('.\n"
1477 " If you are really sure this is not an error, please insert '--' between the\n"
1478 " match and the pattern to make this warning message disappear.\n",
1479 args[0], args[1], args[2]);
1480
Willy Tarreau2a56c5e2010-03-15 16:13:29 +01001481 if (*args[0])
1482 cur_acl = find_acl_by_name(args[0], known_acl);
1483 else
1484 cur_acl = NULL;
1485
Willy Tarreaua84d3742007-05-07 00:36:48 +02001486 if (!cur_acl) {
1487 name = strdup(args[0]);
1488 if (!name)
1489 goto out_free_acl_expr;
1490 cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl));
1491 if (cur_acl == NULL)
1492 goto out_free_name;
1493
1494 LIST_INIT(&cur_acl->expr);
1495 LIST_ADDQ(known_acl, &cur_acl->list);
1496 cur_acl->name = name;
1497 }
1498
Willy Tarreaua9802632008-07-25 19:13:19 +02001499 cur_acl->requires |= acl_expr->kw->requires;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001500 LIST_ADDQ(&cur_acl->expr, &acl_expr->list);
1501 return cur_acl;
1502
1503 out_free_name:
1504 free(name);
1505 out_free_acl_expr:
1506 prune_acl_expr(acl_expr);
1507 free(acl_expr);
1508 out_return:
1509 return NULL;
1510}
1511
Willy Tarreau16fbe822007-06-17 11:54:31 +02001512/* Some useful ACLs provided by default. Only those used are allocated. */
1513
1514const struct {
1515 const char *name;
1516 const char *expr[4]; /* put enough for longest expression */
1517} default_acl_list[] = {
Willy Tarreau58393e12008-07-20 10:39:22 +02001518 { .name = "TRUE", .expr = {"always_true",""}},
1519 { .name = "FALSE", .expr = {"always_false",""}},
Willy Tarreau16fbe822007-06-17 11:54:31 +02001520 { .name = "LOCALHOST", .expr = {"src","127.0.0.1/8",""}},
Willy Tarreau2492d5b2009-07-11 00:06:00 +02001521 { .name = "HTTP", .expr = {"req_proto_http",""}},
Willy Tarreau16fbe822007-06-17 11:54:31 +02001522 { .name = "HTTP_1.0", .expr = {"req_ver","1.0",""}},
1523 { .name = "HTTP_1.1", .expr = {"req_ver","1.1",""}},
1524 { .name = "METH_CONNECT", .expr = {"method","CONNECT",""}},
1525 { .name = "METH_GET", .expr = {"method","GET","HEAD",""}},
1526 { .name = "METH_HEAD", .expr = {"method","HEAD",""}},
1527 { .name = "METH_OPTIONS", .expr = {"method","OPTIONS",""}},
1528 { .name = "METH_POST", .expr = {"method","POST",""}},
1529 { .name = "METH_TRACE", .expr = {"method","TRACE",""}},
1530 { .name = "HTTP_URL_ABS", .expr = {"url_reg","^[^/:]*://",""}},
1531 { .name = "HTTP_URL_SLASH", .expr = {"url_beg","/",""}},
1532 { .name = "HTTP_URL_STAR", .expr = {"url","*",""}},
1533 { .name = "HTTP_CONTENT", .expr = {"hdr_val(content-length)","gt","0",""}},
Emeric Brunbede3d02009-06-30 17:54:00 +02001534 { .name = "RDP_COOKIE", .expr = {"req_rdp_cookie_cnt","gt","0",""}},
Willy Tarreauc6317702008-07-20 09:29:50 +02001535 { .name = "REQ_CONTENT", .expr = {"req_len","gt","0",""}},
Willy Tarreaub6fb4202008-07-20 11:18:28 +02001536 { .name = "WAIT_END", .expr = {"wait_end",""}},
Willy Tarreau16fbe822007-06-17 11:54:31 +02001537 { .name = NULL, .expr = {""}}
1538};
1539
1540/* Find a default ACL from the default_acl list, compile it and return it.
1541 * If the ACL is not found, NULL is returned. In theory, it cannot fail,
1542 * except when default ACLs are broken, in which case it will return NULL.
1543 * If <known_acl> is not NULL, the ACL will be queued at its tail.
1544 */
1545struct acl *find_acl_default(const char *acl_name, struct list *known_acl)
1546{
1547 __label__ out_return, out_free_acl_expr, out_free_name;
1548 struct acl *cur_acl;
1549 struct acl_expr *acl_expr;
1550 char *name;
1551 int index;
1552
1553 for (index = 0; default_acl_list[index].name != NULL; index++) {
1554 if (strcmp(acl_name, default_acl_list[index].name) == 0)
1555 break;
1556 }
1557
1558 if (default_acl_list[index].name == NULL)
1559 return NULL;
1560
1561 acl_expr = parse_acl_expr((const char **)default_acl_list[index].expr);
1562 if (!acl_expr)
1563 goto out_return;
1564
1565 name = strdup(acl_name);
1566 if (!name)
1567 goto out_free_acl_expr;
1568 cur_acl = (struct acl *)calloc(1, sizeof(*cur_acl));
1569 if (cur_acl == NULL)
1570 goto out_free_name;
1571
1572 cur_acl->name = name;
Willy Tarreaua55b7dc2009-07-12 09:21:30 +02001573 cur_acl->requires |= acl_expr->kw->requires;
Willy Tarreau16fbe822007-06-17 11:54:31 +02001574 LIST_INIT(&cur_acl->expr);
1575 LIST_ADDQ(&cur_acl->expr, &acl_expr->list);
1576 if (known_acl)
1577 LIST_ADDQ(known_acl, &cur_acl->list);
1578
1579 return cur_acl;
1580
1581 out_free_name:
1582 free(name);
1583 out_free_acl_expr:
1584 prune_acl_expr(acl_expr);
1585 free(acl_expr);
1586 out_return:
1587 return NULL;
1588}
Willy Tarreaua84d3742007-05-07 00:36:48 +02001589
1590/* Purge everything in the acl_cond <cond>, then return <cond>. */
1591struct acl_cond *prune_acl_cond(struct acl_cond *cond)
1592{
1593 struct acl_term_suite *suite, *tmp_suite;
1594 struct acl_term *term, *tmp_term;
1595
1596 /* iterate through all term suites and free all terms and all suites */
1597 list_for_each_entry_safe(suite, tmp_suite, &cond->suites, list) {
1598 list_for_each_entry_safe(term, tmp_term, &suite->terms, list)
1599 free(term);
1600 free(suite);
1601 }
1602 return cond;
1603}
1604
1605/* Parse an ACL condition starting at <args>[0], relying on a list of already
1606 * known ACLs passed in <known_acl>. The new condition is returned (or NULL in
1607 * case of low memory). Supports multiple conditions separated by "or".
1608 */
1609struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl, int pol)
1610{
1611 __label__ out_return, out_free_suite, out_free_term;
Willy Tarreau74b98a82007-06-16 19:35:18 +02001612 int arg, neg;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001613 const char *word;
1614 struct acl *cur_acl;
1615 struct acl_term *cur_term;
1616 struct acl_term_suite *cur_suite;
1617 struct acl_cond *cond;
1618
1619 cond = (struct acl_cond *)calloc(1, sizeof(*cond));
1620 if (cond == NULL)
1621 goto out_return;
1622
1623 LIST_INIT(&cond->list);
1624 LIST_INIT(&cond->suites);
1625 cond->pol = pol;
1626
1627 cur_suite = NULL;
Willy Tarreau74b98a82007-06-16 19:35:18 +02001628 neg = 0;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001629 for (arg = 0; *args[arg]; arg++) {
1630 word = args[arg];
1631
1632 /* remove as many exclamation marks as we can */
1633 while (*word == '!') {
1634 neg = !neg;
1635 word++;
1636 }
1637
1638 /* an empty word is allowed because we cannot force the user to
1639 * always think about not leaving exclamation marks alone.
1640 */
1641 if (!*word)
1642 continue;
1643
Willy Tarreau16fbe822007-06-17 11:54:31 +02001644 if (strcasecmp(word, "or") == 0 || strcmp(word, "||") == 0) {
Willy Tarreaua84d3742007-05-07 00:36:48 +02001645 /* new term suite */
1646 cur_suite = NULL;
1647 neg = 0;
1648 continue;
1649 }
1650
Willy Tarreau95fa4692010-02-01 13:05:50 +01001651 if (strcmp(word, "{") == 0) {
1652 /* we may have a complete ACL expression between two braces,
1653 * find the last one.
1654 */
1655 int arg_end = arg + 1;
1656 const char **args_new;
1657
1658 while (*args[arg_end] && strcmp(args[arg_end], "}") != 0)
1659 arg_end++;
1660
1661 if (!*args[arg_end])
1662 goto out_free_suite;
1663
1664 args_new = calloc(1, (arg_end - arg + 1) * sizeof(*args_new));
1665 if (!args_new)
1666 goto out_free_suite;
1667
Willy Tarreau2a56c5e2010-03-15 16:13:29 +01001668 args_new[0] = "";
Willy Tarreau95fa4692010-02-01 13:05:50 +01001669 memcpy(args_new + 1, args + arg + 1, (arg_end - arg) * sizeof(*args_new));
1670 args_new[arg_end - arg] = "";
1671 cur_acl = parse_acl(args_new, known_acl);
1672 free(args_new);
1673
1674 if (!cur_acl)
Willy Tarreau16fbe822007-06-17 11:54:31 +02001675 goto out_free_suite;
Willy Tarreau95fa4692010-02-01 13:05:50 +01001676 arg = arg_end;
1677 }
1678 else {
1679 /* search for <word> in the known ACL names. If we do not find
1680 * it, let's look for it in the default ACLs, and if found, add
1681 * it to the list of ACLs of this proxy. This makes it possible
1682 * to override them.
1683 */
1684 cur_acl = find_acl_by_name(word, known_acl);
1685 if (cur_acl == NULL) {
1686 cur_acl = find_acl_default(word, known_acl);
1687 if (cur_acl == NULL)
1688 goto out_free_suite;
1689 }
Willy Tarreau16fbe822007-06-17 11:54:31 +02001690 }
Willy Tarreaua84d3742007-05-07 00:36:48 +02001691
1692 cur_term = (struct acl_term *)calloc(1, sizeof(*cur_term));
1693 if (cur_term == NULL)
1694 goto out_free_suite;
1695
1696 cur_term->acl = cur_acl;
1697 cur_term->neg = neg;
Willy Tarreaua9802632008-07-25 19:13:19 +02001698 cond->requires |= cur_acl->requires;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001699
1700 if (!cur_suite) {
1701 cur_suite = (struct acl_term_suite *)calloc(1, sizeof(*cur_suite));
1702 if (cur_term == NULL)
1703 goto out_free_term;
1704 LIST_INIT(&cur_suite->terms);
1705 LIST_ADDQ(&cond->suites, &cur_suite->list);
1706 }
1707 LIST_ADDQ(&cur_suite->terms, &cur_term->list);
Willy Tarreau74b98a82007-06-16 19:35:18 +02001708 neg = 0;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001709 }
1710
1711 return cond;
1712
1713 out_free_term:
1714 free(cur_term);
1715 out_free_suite:
1716 prune_acl_cond(cond);
1717 free(cond);
1718 out_return:
1719 return NULL;
1720}
1721
Willy Tarreau2bbba412010-01-28 16:48:33 +01001722/* Builds an ACL condition starting at the if/unless keyword. The complete
1723 * condition is returned. NULL is returned in case of error or if the first
1724 * word is neither "if" nor "unless". It automatically sets the file name and
1725 * the line number in the condition for better error reporting, and adds the
1726 * ACL requirements to the proxy's acl_requires.
1727 */
1728struct acl_cond *build_acl_cond(const char *file, int line, struct proxy *px, const char **args)
1729{
1730 int pol = ACL_COND_NONE;
1731 struct acl_cond *cond = NULL;
1732
1733 if (!strcmp(*args, "if")) {
1734 pol = ACL_COND_IF;
1735 args++;
1736 }
1737 else if (!strcmp(*args, "unless")) {
1738 pol = ACL_COND_UNLESS;
1739 args++;
1740 }
1741 else
1742 return NULL;
1743
1744 cond = parse_acl_cond(args, &px->acl, pol);
1745 if (!cond)
1746 return NULL;
1747
1748 cond->file = file;
1749 cond->line = line;
1750 px->acl_requires |= cond->requires;
1751
1752 return cond;
1753}
1754
Willy Tarreau11382812008-07-09 16:18:21 +02001755/* Execute condition <cond> and return either ACL_PAT_FAIL, ACL_PAT_MISS or
Willy Tarreaub6866442008-07-14 23:54:42 +02001756 * ACL_PAT_PASS depending on the test results. ACL_PAT_MISS may only be
1757 * returned if <dir> contains ACL_PARTIAL, indicating that incomplete data
1758 * is being examined.
1759 * This function only computes the condition, it does not apply the polarity
1760 * required by IF/UNLESS, it's up to the caller to do this using something like
1761 * this :
Willy Tarreau11382812008-07-09 16:18:21 +02001762 *
1763 * res = acl_pass(res);
Willy Tarreaub6866442008-07-14 23:54:42 +02001764 * if (res == ACL_PAT_MISS)
1765 * return 0;
Willy Tarreau11382812008-07-09 16:18:21 +02001766 * if (cond->pol == ACL_COND_UNLESS)
1767 * res = !res;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001768 */
Willy Tarreaud41f8d82007-06-10 10:06:18 +02001769int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, int dir)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001770{
1771 __label__ fetch_next;
1772 struct acl_term_suite *suite;
1773 struct acl_term *term;
1774 struct acl_expr *expr;
1775 struct acl *acl;
1776 struct acl_pattern *pattern;
1777 struct acl_test test;
Willy Tarreau11382812008-07-09 16:18:21 +02001778 int acl_res, suite_res, cond_res;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001779
Willy Tarreau11382812008-07-09 16:18:21 +02001780 /* We're doing a logical OR between conditions so we initialize to FAIL.
1781 * The MISS status is propagated down from the suites.
1782 */
Willy Tarreaua84d3742007-05-07 00:36:48 +02001783 cond_res = ACL_PAT_FAIL;
1784 list_for_each_entry(suite, &cond->suites, list) {
Willy Tarreau11382812008-07-09 16:18:21 +02001785 /* Evaluate condition suite <suite>. We stop at the first term
1786 * which returns ACL_PAT_FAIL. The MISS status is still propagated
1787 * in case of uncertainty in the result.
Willy Tarreaua84d3742007-05-07 00:36:48 +02001788 */
1789
1790 /* we're doing a logical AND between terms, so we must set the
1791 * initial value to PASS.
1792 */
1793 suite_res = ACL_PAT_PASS;
1794 list_for_each_entry(term, &suite->terms, list) {
1795 acl = term->acl;
1796
1797 /* FIXME: use cache !
1798 * check acl->cache_idx for this.
1799 */
1800
1801 /* ACL result not cached. Let's scan all the expressions
1802 * and use the first one to match.
1803 */
1804 acl_res = ACL_PAT_FAIL;
1805 list_for_each_entry(expr, &acl->expr, list) {
Willy Tarreaud41f8d82007-06-10 10:06:18 +02001806 /* we need to reset context and flags */
1807 memset(&test, 0, sizeof(test));
Willy Tarreaua84d3742007-05-07 00:36:48 +02001808 fetch_next:
Willy Tarreaub6866442008-07-14 23:54:42 +02001809 if (!expr->kw->fetch(px, l4, l7, dir, expr, &test)) {
1810 /* maybe we could not fetch because of missing data */
1811 if (test.flags & ACL_TEST_F_MAY_CHANGE && dir & ACL_PARTIAL)
1812 acl_res |= ACL_PAT_MISS;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001813 continue;
Willy Tarreaub6866442008-07-14 23:54:42 +02001814 }
Willy Tarreaua84d3742007-05-07 00:36:48 +02001815
Willy Tarreaua79534f2008-07-20 10:13:37 +02001816 if (test.flags & ACL_TEST_F_RES_SET) {
1817 if (test.flags & ACL_TEST_F_RES_PASS)
1818 acl_res |= ACL_PAT_PASS;
1819 else
1820 acl_res |= ACL_PAT_FAIL;
1821 }
1822 else {
Willy Tarreau020534d2010-05-16 21:45:45 +02001823 if (!eb_is_empty(&expr->pattern_tree)) {
Willy Tarreauc4262962010-05-10 23:42:40 +02001824 /* a tree is present, let's check what type it is */
1825 if (expr->kw->match == acl_match_str)
1826 acl_res |= acl_lookup_str(&test, expr) ? ACL_PAT_PASS : ACL_PAT_FAIL;
Willy Tarreaub337b532010-05-13 20:03:41 +02001827 else if (expr->kw->match == acl_match_ip)
1828 acl_res |= acl_lookup_ip(&test, expr) ? ACL_PAT_PASS : ACL_PAT_FAIL;
Willy Tarreauc4262962010-05-10 23:42:40 +02001829 }
1830
Willy Tarreaua79534f2008-07-20 10:13:37 +02001831 /* call the match() function for all tests on this value */
1832 list_for_each_entry(pattern, &expr->patterns, list) {
Willy Tarreaua79534f2008-07-20 10:13:37 +02001833 if (acl_res == ACL_PAT_PASS)
1834 break;
Willy Tarreaue56cda92010-05-11 23:25:05 +02001835 acl_res |= expr->kw->match(&test, pattern);
Willy Tarreaua79534f2008-07-20 10:13:37 +02001836 }
Krzysztof Piotr Oledzkid7528e52010-01-29 17:55:53 +01001837
Willy Tarreaue56cda92010-05-11 23:25:05 +02001838 if ((test.flags & ACL_TEST_F_NULL_MATCH) &&
Willy Tarreau020534d2010-05-16 21:45:45 +02001839 LIST_ISEMPTY(&expr->patterns) && eb_is_empty(&expr->pattern_tree))
Krzysztof Piotr Oledzkid7528e52010-01-29 17:55:53 +01001840 acl_res |= expr->kw->match(&test, NULL);
Willy Tarreaua84d3742007-05-07 00:36:48 +02001841 }
1842 /*
Willy Tarreau11382812008-07-09 16:18:21 +02001843 * OK now acl_res holds the result of this expression
1844 * as one of ACL_PAT_FAIL, ACL_PAT_MISS or ACL_PAT_PASS.
Willy Tarreaua84d3742007-05-07 00:36:48 +02001845 *
Willy Tarreau11382812008-07-09 16:18:21 +02001846 * Then if (!MISS) we can cache the result, and put
Willy Tarreaua84d3742007-05-07 00:36:48 +02001847 * (test.flags & ACL_TEST_F_VOLATILE) in the cache flags.
1848 *
1849 * FIXME: implement cache.
1850 *
1851 */
1852
1853 /* now we may have some cleanup to do */
1854 if (test.flags & ACL_TEST_F_MUST_FREE) {
1855 free(test.ptr);
1856 test.len = 0;
1857 }
1858
Willy Tarreau11382812008-07-09 16:18:21 +02001859 /* we're ORing these terms, so a single PASS is enough */
1860 if (acl_res == ACL_PAT_PASS)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001861 break;
1862
Willy Tarreaua84d3742007-05-07 00:36:48 +02001863 if (test.flags & ACL_TEST_F_FETCH_MORE)
1864 goto fetch_next;
Willy Tarreaub6866442008-07-14 23:54:42 +02001865
1866 /* sometimes we know the fetched data is subject to change
1867 * later and give another chance for a new match (eg: request
1868 * size, time, ...)
1869 */
1870 if (test.flags & ACL_TEST_F_MAY_CHANGE && dir & ACL_PARTIAL)
1871 acl_res |= ACL_PAT_MISS;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001872 }
1873 /*
1874 * Here we have the result of an ACL (cached or not).
1875 * ACLs are combined, negated or not, to form conditions.
1876 */
1877
Willy Tarreaua84d3742007-05-07 00:36:48 +02001878 if (term->neg)
Willy Tarreau11382812008-07-09 16:18:21 +02001879 acl_res = acl_neg(acl_res);
Willy Tarreaua84d3742007-05-07 00:36:48 +02001880
1881 suite_res &= acl_res;
Willy Tarreau11382812008-07-09 16:18:21 +02001882
1883 /* we're ANDing these terms, so a single FAIL is enough */
1884 if (suite_res == ACL_PAT_FAIL)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001885 break;
1886 }
1887 cond_res |= suite_res;
Willy Tarreau11382812008-07-09 16:18:21 +02001888
1889 /* we're ORing these terms, so a single PASS is enough */
1890 if (cond_res == ACL_PAT_PASS)
Willy Tarreaua84d3742007-05-07 00:36:48 +02001891 break;
1892 }
Willy Tarreau11382812008-07-09 16:18:21 +02001893 return cond_res;
Willy Tarreaua84d3742007-05-07 00:36:48 +02001894}
1895
1896
Willy Tarreaudd64f8d2008-07-27 22:02:32 +02001897/* Reports a pointer to the first ACL used in condition <cond> which requires
1898 * at least one of the USE_FLAGS in <require>. Returns NULL if none matches.
1899 * The construct is almost the same as for acl_exec_cond() since we're walking
1900 * down the ACL tree as well. It is important that the tree is really walked
1901 * through and never cached, because that way, this function can be used as a
1902 * late check.
1903 */
Willy Tarreauf1e98b82010-01-28 17:59:39 +01001904struct acl *cond_find_require(const struct acl_cond *cond, unsigned int require)
Willy Tarreaudd64f8d2008-07-27 22:02:32 +02001905{
1906 struct acl_term_suite *suite;
1907 struct acl_term *term;
1908 struct acl *acl;
1909
1910 list_for_each_entry(suite, &cond->suites, list) {
1911 list_for_each_entry(term, &suite->terms, list) {
1912 acl = term->acl;
1913 if (acl->requires & require)
1914 return acl;
1915 }
1916 }
1917 return NULL;
1918}
1919
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001920/*
1921 * Find targets for userlist and groups in acl. Function returns the number
1922 * of errors or OK if everything is fine.
1923 */
1924int
1925acl_find_targets(struct proxy *p)
1926{
1927
1928 struct acl *acl;
1929 struct acl_expr *expr;
1930 struct acl_pattern *pattern;
1931 struct userlist *ul;
1932 int cfgerr = 0;
1933
1934 list_for_each_entry(acl, &p->acl, list) {
1935 list_for_each_entry(expr, &acl->expr, list) {
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001936 if (strcmp(expr->kw->kw, "srv_is_up") == 0 ||
1937 strcmp(expr->kw->kw, "srv_conn") == 0) {
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001938 struct proxy *px;
1939 struct server *srv;
1940 char *pname, *sname;
1941
1942 if (!expr->arg.str || !*expr->arg.str) {
1943 Alert("proxy %s: acl %s %s(): missing server name.\n",
1944 p->id, acl->name, expr->kw->kw);
1945 cfgerr++;
1946 continue;
1947 }
1948
1949 pname = expr->arg.str;
1950 sname = strrchr(pname, '/');
1951
1952 if (sname)
1953 *sname++ = '\0';
1954 else {
1955 sname = pname;
1956 pname = NULL;
1957 }
1958
1959 px = p;
1960 if (pname) {
1961 px = findproxy(pname, PR_CAP_BE);
1962 if (!px) {
1963 Alert("proxy %s: acl %s %s(): unable to find proxy '%s'.\n",
1964 p->id, acl->name, expr->kw->kw, pname);
1965 cfgerr++;
1966 continue;
1967 }
1968 }
1969
1970 srv = findserver(px, sname);
1971 if (!srv) {
1972 Alert("proxy %s: acl %s %s(): unable to find server '%s'.\n",
1973 p->id, acl->name, expr->kw->kw, sname);
1974 cfgerr++;
1975 continue;
1976 }
1977
1978 free(expr->arg.str);
1979 expr->arg_len = 0;
1980 expr->arg.srv = srv;
1981 continue;
1982 }
1983
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001984 if (strstr(expr->kw->kw, "http_auth") == expr->kw->kw) {
1985
1986 if (!expr->arg.str || !*expr->arg.str) {
1987 Alert("proxy %s: acl %s %s(): missing userlist name.\n",
1988 p->id, acl->name, expr->kw->kw);
1989 cfgerr++;
1990 continue;
1991 }
1992
Krzysztof Piotr Oledzki8c8bd452010-01-29 19:29:32 +01001993 if (p->uri_auth && p->uri_auth->userlist &&
1994 !strcmp(p->uri_auth->userlist->name, expr->arg.str))
1995 ul = p->uri_auth->userlist;
1996 else
1997 ul = auth_find_userlist(expr->arg.str);
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001998
1999 if (!ul) {
2000 Alert("proxy %s: acl %s %s(%s): unable to find userlist.\n",
2001 p->id, acl->name, expr->kw->kw, expr->arg.str);
2002 cfgerr++;
2003 continue;
2004 }
2005
2006 expr->arg_len = 0;
2007 expr->arg.ul = ul;
2008 }
2009
2010
2011 if (!strcmp(expr->kw->kw, "http_auth_group")) {
2012
2013 if (LIST_ISEMPTY(&expr->patterns)) {
2014 Alert("proxy %s: acl %s %s(): no groups specified.\n",
2015 p->id, acl->name, expr->kw->kw);
2016 cfgerr++;
2017 continue;
2018 }
2019
2020 list_for_each_entry(pattern, &expr->patterns, list) {
2021 pattern->val.group_mask = auth_resolve_groups(expr->arg.ul, pattern->ptr.str);
2022
2023 free(pattern->ptr.str);
2024 pattern->ptr.str = NULL;
2025 pattern->len = 0;
2026
2027 if (!pattern->val.group_mask) {
2028 Alert("proxy %s: acl %s %s(): invalid group(s).\n",
2029 p->id, acl->name, expr->kw->kw);
2030 cfgerr++;
2031 continue;
2032 }
2033 }
2034 }
2035 }
2036 }
2037
2038 return cfgerr;
2039}
Willy Tarreaudd64f8d2008-07-27 22:02:32 +02002040
Willy Tarreaua84d3742007-05-07 00:36:48 +02002041/************************************************************************/
2042/* All supported keywords must be declared here. */
2043/************************************************************************/
2044
2045/* Note: must not be declared <const> as its list will be overwritten */
2046static struct acl_kw_list acl_kws = {{ },{
Emeric Brun38e71762010-09-23 17:59:18 +02002047 { "always_true", acl_parse_nothing, acl_fetch_true, acl_match_nothing, ACL_USE_NOTHING },
2048 { "always_false", acl_parse_nothing, acl_fetch_false, acl_match_nothing, ACL_USE_NOTHING },
2049 { "wait_end", acl_parse_nothing, acl_fetch_wait_end, acl_match_nothing, ACL_USE_NOTHING },
2050 { "req_len", acl_parse_int, acl_fetch_req_len, acl_match_int, ACL_USE_L6REQ_VOLATILE },
2051 { "req_ssl_hello_type", acl_parse_int, acl_fetch_ssl_hello_type, acl_match_int, ACL_USE_L6REQ_VOLATILE },
2052 { "rep_ssl_hello_type", acl_parse_int, acl_fetch_ssl_hello_type, acl_match_int, ACL_USE_L6RTR_VOLATILE },
2053 { "req_ssl_ver", acl_parse_dotted_ver, acl_fetch_req_ssl_ver, acl_match_int, ACL_USE_L6REQ_VOLATILE },
2054 { "req_rdp_cookie", acl_parse_str, acl_fetch_rdp_cookie, acl_match_str, ACL_USE_L6REQ_VOLATILE|ACL_MAY_LOOKUP },
2055 { "req_rdp_cookie_cnt", acl_parse_int, acl_fetch_rdp_cookie_cnt, acl_match_int, ACL_USE_L6REQ_VOLATILE },
Willy Tarreaub6672b52011-12-12 17:23:41 +01002056 { "req_ssl_sni", acl_parse_str, acl_fetch_ssl_hello_sni, acl_match_str, ACL_USE_L6REQ_VOLATILE|ACL_MAY_LOOKUP },
Willy Tarreaua84d3742007-05-07 00:36:48 +02002057#if 0
2058 { "time", acl_parse_time, acl_fetch_time, acl_match_time },
2059#endif
2060 { NULL, NULL, NULL, NULL }
2061}};
2062
2063
2064__attribute__((constructor))
2065static void __acl_init(void)
2066{
2067 acl_register_keywords(&acl_kws);
2068}
2069
2070
2071/*
2072 * Local variables:
2073 * c-indent-level: 8
2074 * c-basic-offset: 8
2075 * End:
2076 */