/src/haproxy/include/haproxy/acl.h
Line | Count | Source |
1 | | /* |
2 | | * include/haproxy/acl.h |
3 | | * This file provides interface definitions for ACL manipulation. |
4 | | * |
5 | | * Copyright (C) 2000-2013 Willy Tarreau - w@1wt.eu |
6 | | * |
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 | | */ |
21 | | |
22 | | #ifndef _HAPROXY_ACL_H |
23 | | #define _HAPROXY_ACL_H |
24 | | |
25 | | #include <haproxy/acl-t.h> |
26 | | #include <haproxy/api.h> |
27 | | #include <haproxy/arg-t.h> |
28 | | |
29 | | struct stream; |
30 | | |
31 | | /* |
32 | | * FIXME: we need destructor functions too ! |
33 | | */ |
34 | | |
35 | | /* Negate an acl result. This turns (ACL_MATCH_FAIL, ACL_MATCH_MISS, |
36 | | * ACL_MATCH_PASS) into (ACL_MATCH_PASS, ACL_MATCH_MISS, ACL_MATCH_FAIL). |
37 | | */ |
38 | | static inline enum acl_test_res acl_neg(enum acl_test_res res) |
39 | 0 | { |
40 | 0 | return (3 >> res); |
41 | 0 | } Unexecuted instantiation: haproxy.c:acl_neg Unexecuted instantiation: listener.c:acl_neg Unexecuted instantiation: proxy.c:acl_neg Unexecuted instantiation: sample.c:acl_neg Unexecuted instantiation: stream.c:acl_neg Unexecuted instantiation: tcp_rules.c:acl_neg Unexecuted instantiation: uri_auth.c:acl_neg Unexecuted instantiation: acl.c:acl_neg Unexecuted instantiation: action.c:acl_neg Unexecuted instantiation: backend.c:acl_neg Unexecuted instantiation: cfgparse-listen.c:acl_neg Unexecuted instantiation: cfgparse.c:acl_neg Unexecuted instantiation: frontend.c:acl_neg Unexecuted instantiation: http_ana.c:acl_neg Unexecuted instantiation: http_rules.c:acl_neg Unexecuted instantiation: payload.c:acl_neg Unexecuted instantiation: fcgi-app.c:acl_neg Unexecuted instantiation: flt_spoe.c:acl_neg |
42 | | |
43 | | /* Convert an acl result to a boolean. Only ACL_MATCH_PASS returns 1. */ |
44 | | static inline int acl_pass(enum acl_test_res res) |
45 | 0 | { |
46 | 0 | return (res >> 1); |
47 | 0 | } Unexecuted instantiation: haproxy.c:acl_pass Unexecuted instantiation: listener.c:acl_pass Unexecuted instantiation: proxy.c:acl_pass Unexecuted instantiation: sample.c:acl_pass Unexecuted instantiation: stream.c:acl_pass Unexecuted instantiation: tcp_rules.c:acl_pass Unexecuted instantiation: uri_auth.c:acl_pass Unexecuted instantiation: acl.c:acl_pass Unexecuted instantiation: action.c:acl_pass Unexecuted instantiation: backend.c:acl_pass Unexecuted instantiation: cfgparse-listen.c:acl_pass Unexecuted instantiation: cfgparse.c:acl_pass Unexecuted instantiation: frontend.c:acl_pass Unexecuted instantiation: http_ana.c:acl_pass Unexecuted instantiation: http_rules.c:acl_pass Unexecuted instantiation: payload.c:acl_pass Unexecuted instantiation: fcgi-app.c:acl_pass Unexecuted instantiation: flt_spoe.c:acl_pass |
48 | | |
49 | | /* Return a pointer to the ACL <name> within the list starting at <head>, or |
50 | | * NULL if not found. |
51 | | */ |
52 | | struct acl *find_acl_by_name(const char *name, struct list *head); |
53 | | struct acl *find_acl_default(const char *acl_name, struct list *known_acl, |
54 | | char **err, struct arg_list *al, |
55 | | const char *file, int line); |
56 | | |
57 | | /* Return a pointer to the ACL keyword <kw> within the list starting at <head>, |
58 | | * or NULL if not found. Note that if <kw> contains an opening parenthesis, |
59 | | * only the left part of it is checked. |
60 | | */ |
61 | | struct acl_keyword *find_acl_kw(const char *kw); |
62 | | |
63 | | /* Parse an ACL expression starting at <args>[0], and return it. |
64 | | * Right now, the only accepted syntax is : |
65 | | * <subject> [<value>...] |
66 | | */ |
67 | | struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *al, const char *file, int line); |
68 | | |
69 | | /* Purge everything in the acl <acl>, then return <acl>. */ |
70 | | struct acl *prune_acl(struct acl *acl); |
71 | | |
72 | | /* Parse an ACL with the name starting at <args>[0], and with a list of already |
73 | | * known ACLs in <acl>. If the ACL was not in the list, it will be added. |
74 | | * A pointer to that ACL is returned. |
75 | | * |
76 | | * args syntax: <aclname> <acl_expr> |
77 | | */ |
78 | | struct acl *parse_acl(const char **args, struct list *known_acl, char **err, struct arg_list *al, const char *file, int line); |
79 | | |
80 | | /* Parse an ACL condition starting at <args>[0], relying on a list of already |
81 | | * known ACLs passed in <known_acl>. The new condition is returned (or NULL in |
82 | | * case of low memory). Supports multiple conditions separated by "or". |
83 | | */ |
84 | | struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl, |
85 | | enum acl_cond_pol pol, char **err, struct arg_list *al, |
86 | | const char *file, int line); |
87 | | |
88 | | /* Builds an ACL condition starting at the if/unless keyword. The complete |
89 | | * condition is returned. NULL is returned in case of error or if the first |
90 | | * word is neither "if" nor "unless". It automatically sets the file name and |
91 | | * the line number in the condition for better error reporting, and sets the |
92 | | * HTTP initialization requirements in the proxy. If <err> is not NULL, it will |
93 | | * be set to an error message upon errors, that the caller will have to free. |
94 | | */ |
95 | | struct acl_cond *build_acl_cond(const char *file, int line, struct list *known_acl, |
96 | | struct proxy *px, const char **args, char **err); |
97 | | |
98 | | /* Execute condition <cond> and return either ACL_TEST_FAIL, ACL_TEST_MISS or |
99 | | * ACL_TEST_PASS depending on the test results. ACL_TEST_MISS may only be |
100 | | * returned if <opt> does not contain SMP_OPT_FINAL, indicating that incomplete |
101 | | * data is being examined. The function automatically sets SMP_OPT_ITERATE. This |
102 | | * function only computes the condition, it does not apply the polarity required |
103 | | * by IF/UNLESS, it's up to the caller to do this. |
104 | | */ |
105 | | enum acl_test_res acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt); |
106 | | |
107 | | |
108 | | /* helper that combines acl_exec_cond() and acl_pass(), and also takes into |
109 | | * account cond->pol in order to return either 1 if the cond should pass and |
110 | | * 0 otherwise |
111 | | * <cond> may be NULL, in which case 1 is returned as the cond cannot fail |
112 | | */ |
113 | | static inline int acl_match_cond(struct acl_cond *cond, struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt) |
114 | 0 | { |
115 | 0 | int ret; |
116 | |
|
117 | 0 | if (!cond) |
118 | 0 | return 1; |
119 | | |
120 | 0 | ret = acl_pass(acl_exec_cond(cond, px, sess, strm, opt)); |
121 | 0 | if (cond->pol == ACL_COND_UNLESS) |
122 | 0 | ret = !ret; |
123 | |
|
124 | 0 | return ret; |
125 | 0 | } Unexecuted instantiation: haproxy.c:acl_match_cond Unexecuted instantiation: listener.c:acl_match_cond Unexecuted instantiation: proxy.c:acl_match_cond Unexecuted instantiation: sample.c:acl_match_cond Unexecuted instantiation: stream.c:acl_match_cond Unexecuted instantiation: tcp_rules.c:acl_match_cond Unexecuted instantiation: uri_auth.c:acl_match_cond Unexecuted instantiation: acl.c:acl_match_cond Unexecuted instantiation: action.c:acl_match_cond Unexecuted instantiation: backend.c:acl_match_cond Unexecuted instantiation: cfgparse-listen.c:acl_match_cond Unexecuted instantiation: cfgparse.c:acl_match_cond Unexecuted instantiation: frontend.c:acl_match_cond Unexecuted instantiation: http_ana.c:acl_match_cond Unexecuted instantiation: http_rules.c:acl_match_cond Unexecuted instantiation: payload.c:acl_match_cond Unexecuted instantiation: fcgi-app.c:acl_match_cond Unexecuted instantiation: flt_spoe.c:acl_match_cond |
126 | | |
127 | | /* Returns a pointer to the first ACL conflicting with usage at place <where> |
128 | | * which is one of the SMP_VAL_* bits indicating a check place, or NULL if |
129 | | * no conflict is found. Only full conflicts are detected (ACL is not usable). |
130 | | * Use the next function to check for useless keywords. |
131 | | */ |
132 | | const struct acl *acl_cond_conflicts(const struct acl_cond *cond, unsigned int where); |
133 | | |
134 | | /* Returns a pointer to the first ACL and its first keyword to conflict with |
135 | | * usage at place <where> which is one of the SMP_VAL_* bits indicating a check |
136 | | * place. Returns true if a conflict is found, with <acl> and <kw> set (if non |
137 | | * null), or false if not conflict is found. The first useless keyword is |
138 | | * returned. |
139 | | */ |
140 | | int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, char const **kw); |
141 | | |
142 | | /* |
143 | | * Find targets for userlist and groups in acl. Function returns the number |
144 | | * of errors or OK if everything is fine. |
145 | | */ |
146 | | int acl_find_targets(struct proxy *p); |
147 | | |
148 | | /* Return a pointer to the ACL <name> within the list starting at <head>, or |
149 | | * NULL if not found. |
150 | | */ |
151 | | struct acl *find_acl_by_name(const char *name, struct list *head); |
152 | | |
153 | | /* |
154 | | * Registers the ACL keyword list <kwl> as a list of valid keywords for next |
155 | | * parsing sessions. |
156 | | */ |
157 | | void acl_register_keywords(struct acl_kw_list *kwl); |
158 | | |
159 | | /* |
160 | | * Unregisters the ACL keyword list <kwl> from the list of valid keywords. |
161 | | */ |
162 | | void acl_unregister_keywords(struct acl_kw_list *kwl); |
163 | | |
164 | | /* initializes ACLs by resolving the sample fetch names they rely upon. |
165 | | * Returns 0 on success, otherwise an error. |
166 | | */ |
167 | | int init_acl(void); |
168 | | |
169 | | void acl_dump_kwd(void); |
170 | | |
171 | | void free_acl_cond(struct acl_cond *cond); |
172 | | |
173 | | #endif /* _HAPROXY_ACL_H */ |
174 | | |
175 | | /* |
176 | | * Local variables: |
177 | | * c-indent-level: 8 |
178 | | * c-basic-offset: 8 |
179 | | * End: |
180 | | */ |