2 * rlm_policy.h Header file for policy module
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2004 Alan DeKok <aland@freeradius.org>
21 * Copyright 2006 The FreeRADIUS server project
26 #include <freeradius-devel/ident.h>
27 RCSIDH(rlm_policy_h, "$Id$")
29 #include <freeradius-devel/radiusd.h>
30 #include <freeradius-devel/modules.h>
31 #include <freeradius-devel/modcall.h>
32 #include <freeradius-devel/rad_assert.h>
37 typedef enum policy_lex_t {
39 POLICY_LEX_EOF, /* end of the file/input */
40 POLICY_LEX_EOL, /* end of the line */
41 POLICY_LEX_WHITESPACE,
45 POLICY_LEX_LC_BRACKET, /* left curly bracket */
46 POLICY_LEX_RC_BRACKET, /* right curly bracket */
48 POLICY_LEX_L_AND, /* logical AND */
49 POLICY_LEX_L_OR, /* logical OR */
50 POLICY_LEX_AND, /* bit-wise AND */
51 POLICY_LEX_OR, /* bit-wise OR */
53 POLICY_LEX_PLUS, /* + */
54 POLICY_LEX_MINUS, /* - */
55 POLICY_LEX_ASSIGN, /* = */
56 POLICY_LEX_CMP_EQUALS,
57 POLICY_LEX_CMP_NOT_EQUALS,
65 POLICY_LEX_RX_NOT_EQUALS,
66 POLICY_LEX_SET_EQUALS, /* := */
67 POLICY_LEX_AND_EQUALS, /* &= */
68 POLICY_LEX_OR_EQUALS, /* |= */
69 POLICY_LEX_PLUS_EQUALS, /* += */
70 POLICY_LEX_MINUS_EQUALS, /* -= */
71 POLICY_LEX_CONCAT_EQUALS, /* .= */
72 POLICY_LEX_VARIABLE, /* %{foo} */
73 POLICY_LEX_FUNCTION, /* Hmmm... */
74 POLICY_LEX_DOUBLE_QUOTED_STRING,
75 POLICY_LEX_SINGLE_QUOTED_STRING,
76 POLICY_LEX_BACK_QUOTED_STRING,
80 typedef enum policy_type_t {
83 POLICY_TYPE_CONDITIONAL,
84 POLICY_TYPE_ASSIGNMENT,
85 POLICY_TYPE_ATTRIBUTE_LIST,
87 POLICY_TYPE_NAMED_POLICY,
96 * For our policy language, we want to have some reserved words.
98 typedef enum policy_reserved_word_t {
99 POLICY_RESERVED_UNKNOWN = 0,
100 POLICY_RESERVED_CONTROL,
101 POLICY_RESERVED_REQUEST,
102 POLICY_RESERVED_REPLY,
103 POLICY_RESERVED_PROXY_REQUEST,
104 POLICY_RESERVED_PROXY_REPLY,
106 POLICY_RESERVED_ELSE,
107 POLICY_RESERVED_DEBUG,
108 POLICY_RESERVED_PRINT,
109 POLICY_RESERVED_POLICY,
110 POLICY_RESERVED_INCLUDE,
111 POLICY_RESERVED_RETURN,
112 POLICY_RESERVED_MODULE,
113 POLICY_RESERVED_NUM_WORDS
114 } policy_reserved_word_t;
117 #define POLICY_DEBUG_NONE 0
118 #define POLICY_DEBUG_PEEK (1 << 0)
119 #define POLICY_DEBUG_PRINT_TOKENS (1 << 1)
120 #define POLICY_DEBUG_PRINT_POLICY (1 << 2)
121 #define POLICY_DEBUG_EVALUATE (1 << 3)
126 typedef struct policy_item_t {
127 struct policy_item_t *next;
134 * A list of attributes to add/replace/whatever in a packet.
136 typedef struct policy_print_t {
138 policy_lex_t rhs_type;
144 * A list of attributes to add/replace/whatever in a packet.
146 typedef struct policy_attributes_t {
148 policy_reserved_word_t where; /* where to do it */
149 policy_lex_t how; /* how to do */
150 policy_item_t *attributes; /* things to do */
151 /* FIXME: VALUE_PAIR *vps; */
152 } policy_attributes_t;
156 * Holds a named policy
158 typedef struct policy_named_t {
161 policy_item_t *policy;
166 * Reference to a named policy
168 typedef struct policy_call_t {
177 typedef struct policy_return_t {
184 * Holds an assignment.
186 typedef struct policy_assignment_t {
189 policy_lex_t assign; /* operator for the assignment */
190 policy_lex_t rhs_type;
192 } policy_assignment_t;
198 typedef struct policy_condition_t {
201 policy_lex_t lhs_type;
203 policy_lex_t compare;
204 policy_lex_t rhs_type; /* bare word, quoted string, etc. */
207 policy_lex_t child_condition;
208 policy_item_t *child;
209 } policy_condition_t;
213 * Holds an "if" statement. The "else" may be a block, or another "if"
215 typedef struct policy_if_t {
217 policy_item_t *condition;
218 policy_item_t *if_true;
219 policy_item_t *if_false; /* assignment, or other 'if' */
224 * Holds a reference to calling other modules... wild.
226 typedef struct policy_module_t {
228 int component; /* authorize, authenticate, etc. */
235 * Define a structure for our module configuration.
237 * These variables do not need to be in a structure, but it's
238 * a lot cleaner to do so, and a pointer to the structure can
239 * be used as the instance handle.
241 typedef struct rlm_policy_t {
250 extern const LRAD_NAME_NUMBER rlm_policy_tokens[];
251 extern const LRAD_NAME_NUMBER policy_reserved_words[];
252 extern const LRAD_NAME_NUMBER policy_return_codes[];
253 extern const LRAD_NAME_NUMBER policy_component_names[];
255 extern int rlm_policy_insert(rbtree_t *head, policy_named_t *policy);
256 extern policy_named_t *rlm_policy_find(rbtree_t *head, const char *name);
258 extern int rlm_policy_parse(rbtree_t *policies, const char *filename);
259 extern void rlm_policy_free_item(policy_item_t *item);
260 extern void rlm_policy_print(const policy_item_t *item);
261 extern int rlm_policy_evaluate(rlm_policy_t *inst, REQUEST *request,
264 #endif /* _RLM_POLICY_H */