blob: dd6dae5073f3f17612d116a1bf632c0cefb63352 [file] [log] [blame]
Willy Tarreaua84d3742007-05-07 00:36:48 +02001/*
Willy Tarreau2bbba412010-01-28 16:48:33 +01002 * include/proto/acl.h
3 * This file provides interface definitions for ACL manipulation.
4 *
Willy Tarreaud4c33c82013-01-07 21:59:07 +01005 * Copyright (C) 2000-2013 Willy Tarreau - w@1wt.eu
Willy Tarreau2bbba412010-01-28 16:48:33 +01006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
Willy Tarreaua84d3742007-05-07 00:36:48 +020021
22#ifndef _PROTO_ACL_H
23#define _PROTO_ACL_H
24
25#include <common/config.h>
26#include <types/acl.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020027#include <proto/sample.h>
Willy Tarreaua84d3742007-05-07 00:36:48 +020028
29/*
30 * FIXME: we need destructor functions too !
31 */
32
Thierry FOURNIERa65b3432013-11-28 18:22:00 +010033/* Negate an acl result. This turns (ACL_MATCH_FAIL, ACL_MATCH_MISS,
34 * ACL_MATCH_PASS) into (ACL_MATCH_PASS, ACL_MATCH_MISS, ACL_MATCH_FAIL).
Willy Tarreau11382812008-07-09 16:18:21 +020035 */
Willy Tarreau0cba6072013-11-28 22:21:02 +010036static inline enum acl_test_res acl_neg(enum acl_test_res res)
Willy Tarreau11382812008-07-09 16:18:21 +020037{
38 return (3 >> res);
39}
40
Thierry FOURNIERa65b3432013-11-28 18:22:00 +010041/* Convert an acl result to a boolean. Only ACL_MATCH_PASS returns 1. */
Willy Tarreau0cba6072013-11-28 22:21:02 +010042static inline int acl_pass(enum acl_test_res res)
Willy Tarreau11382812008-07-09 16:18:21 +020043{
44 return (res >> 1);
45}
Willy Tarreaua84d3742007-05-07 00:36:48 +020046
47/* Return a pointer to the ACL <name> within the list starting at <head>, or
48 * NULL if not found.
49 */
50struct acl *find_acl_by_name(const char *name, struct list *head);
51
52/* Return a pointer to the ACL keyword <kw> within the list starting at <head>,
53 * or NULL if not found. Note that if <kw> contains an opening parenthesis,
54 * only the left part of it is checked.
55 */
56struct acl_keyword *find_acl_kw(const char *kw);
57
58/* Parse an ACL expression starting at <args>[0], and return it.
59 * Right now, the only accepted syntax is :
60 * <subject> [<value>...]
61 */
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +010062struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *al, const char *file, int line);
Willy Tarreaua84d3742007-05-07 00:36:48 +020063
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +020064/* Purge everything in the acl <acl>, then return <acl>. */
65struct acl *prune_acl(struct acl *acl);
66
Willy Tarreaua84d3742007-05-07 00:36:48 +020067/* Parse an ACL with the name starting at <args>[0], and with a list of already
68 * known ACLs in <acl>. If the ACL was not in the list, it will be added.
69 * A pointer to that ACL is returned.
70 *
71 * args syntax: <aclname> <acl_expr>
72 */
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +010073struct acl *parse_acl(const char **args, struct list *known_acl, char **err, struct arg_list *al, const char *file, int line);
Willy Tarreaua84d3742007-05-07 00:36:48 +020074
75/* Purge everything in the acl_cond <cond>, then return <cond>. */
76struct acl_cond *prune_acl_cond(struct acl_cond *cond);
77
78/* Parse an ACL condition starting at <args>[0], relying on a list of already
79 * known ACLs passed in <known_acl>. The new condition is returned (or NULL in
80 * case of low memory). Supports multiple conditions separated by "or".
81 */
Willy Tarreau0cba6072013-11-28 22:21:02 +010082struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl,
Thierry FOURNIER0d6ba512014-02-11 03:31:34 +010083 enum acl_cond_pol pol, char **err, struct arg_list *al,
84 const char *file, int line);
Willy Tarreaua84d3742007-05-07 00:36:48 +020085
Willy Tarreau2bbba412010-01-28 16:48:33 +010086/* Builds an ACL condition starting at the if/unless keyword. The complete
87 * condition is returned. NULL is returned in case of error or if the first
88 * word is neither "if" nor "unless". It automatically sets the file name and
Willy Tarreau25320b22013-03-24 07:22:08 +010089 * the line number in the condition for better error reporting, and sets the
90 * HTTP initialization requirements in the proxy. If <err> is not NULL, it will
Willy Tarreaub7451bb2012-04-27 12:38:15 +020091 * be set to an error message upon errors, that the caller will have to free.
Willy Tarreau2bbba412010-01-28 16:48:33 +010092 */
Christopher Faulet1b421ea2017-09-22 14:38:56 +020093struct acl_cond *build_acl_cond(const char *file, int line, struct list *known_acl,
94 struct proxy *px, const char **args, char **err);
Willy Tarreau2bbba412010-01-28 16:48:33 +010095
Thierry FOURNIERa65b3432013-11-28 18:22:00 +010096/* Execute condition <cond> and return either ACL_TEST_FAIL, ACL_TEST_MISS or
97 * ACL_TEST_PASS depending on the test results. ACL_TEST_MISS may only be
98 * returned if <opt> does not contain SMP_OPT_FINAL, indicating that incomplete
99 * data is being examined. The function automatically sets SMP_OPT_ITERATE. This
100 * function only computes the condition, it does not apply the polarity required
101 * by IF/UNLESS, it's up to the caller to do this.
Willy Tarreaua84d3742007-05-07 00:36:48 +0200102 */
Willy Tarreau192252e2015-04-04 01:47:55 +0200103enum acl_test_res acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt);
Willy Tarreaua84d3742007-05-07 00:36:48 +0200104
Willy Tarreaua91d0a52013-03-25 08:12:18 +0100105/* Returns a pointer to the first ACL conflicting with usage at place <where>
106 * which is one of the SMP_VAL_* bits indicating a check place, or NULL if
107 * no conflict is found. Only full conflicts are detected (ACL is not usable).
108 * Use the next function to check for useless keywords.
109 */
110const struct acl *acl_cond_conflicts(const struct acl_cond *cond, unsigned int where);
111
112/* Returns a pointer to the first ACL and its first keyword to conflict with
113 * usage at place <where> which is one of the SMP_VAL_* bits indicating a check
114 * place. Returns true if a conflict is found, with <acl> and <kw> set (if non
115 * null), or false if not conflict is found. The first useless keyword is
116 * returned.
Willy Tarreaudd64f8d2008-07-27 22:02:32 +0200117 */
Willy Tarreau93fddf12013-03-31 22:59:32 +0200118int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, char const **kw);
Willy Tarreaudd64f8d2008-07-27 22:02:32 +0200119
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +0100120/*
121 * Find targets for userlist and groups in acl. Function returns the number
122 * of errors or OK if everything is fine.
123 */
124int acl_find_targets(struct proxy *p);
125
Willy Tarreaua84d3742007-05-07 00:36:48 +0200126/* Return a pointer to the ACL <name> within the list starting at <head>, or
127 * NULL if not found.
128 */
129struct acl *find_acl_by_name(const char *name, struct list *head);
130
131/*
132 * Registers the ACL keyword list <kwl> as a list of valid keywords for next
133 * parsing sessions.
134 */
135void acl_register_keywords(struct acl_kw_list *kwl);
136
137/*
138 * Unregisters the ACL keyword list <kwl> from the list of valid keywords.
139 */
140void acl_unregister_keywords(struct acl_kw_list *kwl);
141
Willy Tarreau8ed669b2013-01-11 15:49:37 +0100142/* initializes ACLs by resolving the sample fetch names they rely upon.
143 * Returns 0 on success, otherwise an error.
144 */
145int init_acl();
146
Willy Tarreauf3d25982007-05-08 22:45:09 +0200147
Willy Tarreaua84d3742007-05-07 00:36:48 +0200148#endif /* _PROTO_ACL_H */
149
150/*
151 * Local variables:
152 * c-indent-level: 8
153 * c-basic-offset: 8
154 * End:
155 */