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/autoconf.h>
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
38 #include <freeradius-devel/radiusd.h>
39 #include <freeradius-devel/modules.h>
40 #include <freeradius-devel/modcall.h>
42 #include <freeradius-devel/rad_assert.h>
47 typedef enum policy_lex_t {
49 POLICY_LEX_EOF, /* end of the file/input */
50 POLICY_LEX_EOL, /* end of the line */
51 POLICY_LEX_WHITESPACE,
55 POLICY_LEX_LC_BRACKET, /* left curly bracket */
56 POLICY_LEX_RC_BRACKET, /* right curly bracket */
58 POLICY_LEX_L_AND, /* logical AND */
59 POLICY_LEX_L_OR, /* logical OR */
60 POLICY_LEX_AND, /* bit-wise AND */
61 POLICY_LEX_OR, /* bit-wise OR */
63 POLICY_LEX_PLUS, /* + */
64 POLICY_LEX_MINUS, /* - */
65 POLICY_LEX_ASSIGN, /* = */
66 POLICY_LEX_CMP_EQUALS,
67 POLICY_LEX_CMP_NOT_EQUALS,
75 POLICY_LEX_RX_NOT_EQUALS,
76 POLICY_LEX_SET_EQUALS, /* := */
77 POLICY_LEX_AND_EQUALS, /* &= */
78 POLICY_LEX_OR_EQUALS, /* |= */
79 POLICY_LEX_PLUS_EQUALS, /* += */
80 POLICY_LEX_MINUS_EQUALS, /* -= */
81 POLICY_LEX_CONCAT_EQUALS, /* .= */
82 POLICY_LEX_VARIABLE, /* %{foo} */
83 POLICY_LEX_FUNCTION, /* Hmmm... */
84 POLICY_LEX_DOUBLE_QUOTED_STRING,
85 POLICY_LEX_SINGLE_QUOTED_STRING,
86 POLICY_LEX_BACK_QUOTED_STRING,
90 typedef enum policy_type_t {
93 POLICY_TYPE_CONDITIONAL,
94 POLICY_TYPE_ASSIGNMENT,
95 POLICY_TYPE_ATTRIBUTE_LIST,
97 POLICY_TYPE_NAMED_POLICY,
101 POLICY_TYPE_NUM_TYPES
106 * For our policy language, we want to have some reserved words.
108 typedef enum policy_reserved_word_t {
109 POLICY_RESERVED_UNKNOWN = 0,
110 POLICY_RESERVED_CONTROL,
111 POLICY_RESERVED_REQUEST,
112 POLICY_RESERVED_REPLY,
113 POLICY_RESERVED_PROXY_REQUEST,
114 POLICY_RESERVED_PROXY_REPLY,
116 POLICY_RESERVED_ELSE,
117 POLICY_RESERVED_DEBUG,
118 POLICY_RESERVED_PRINT,
119 POLICY_RESERVED_POLICY,
120 POLICY_RESERVED_INCLUDE,
121 POLICY_RESERVED_RETURN,
122 POLICY_RESERVED_MODULE,
123 POLICY_RESERVED_NUM_WORDS
124 } policy_reserved_word_t;
127 #define POLICY_DEBUG_NONE 0
128 #define POLICY_DEBUG_PEEK (1 << 0)
129 #define POLICY_DEBUG_PRINT_TOKENS (1 << 1)
130 #define POLICY_DEBUG_PRINT_POLICY (1 << 2)
131 #define POLICY_DEBUG_EVALUATE (1 << 3)
136 typedef struct policy_item_t {
137 struct policy_item_t *next;
144 * A list of attributes to add/replace/whatever in a packet.
146 typedef struct policy_print_t {
148 policy_lex_t rhs_type;
154 * A list of attributes to add/replace/whatever in a packet.
156 typedef struct policy_attributes_t {
158 policy_reserved_word_t where; /* where to do it */
159 policy_lex_t how; /* how to do */
160 policy_item_t *attributes; /* things to do */
161 /* FIXME: VALUE_PAIR *vps; */
162 } policy_attributes_t;
166 * Holds a named policy
168 typedef struct policy_named_t {
171 policy_item_t *policy;
176 * Reference to a named policy
178 typedef struct policy_call_t {
187 typedef struct policy_return_t {
194 * Holds an assignment.
196 typedef struct policy_assignment_t {
199 policy_lex_t assign; /* operator for the assignment */
200 policy_lex_t rhs_type;
202 } policy_assignment_t;
208 typedef struct policy_condition_t {
211 policy_lex_t lhs_type;
213 policy_lex_t compare;
214 policy_lex_t rhs_type; /* bare word, quoted string, etc. */
217 policy_lex_t child_condition;
218 policy_item_t *child;
219 } policy_condition_t;
223 * Holds an "if" statement. The "else" may be a block, or another "if"
225 typedef struct policy_if_t {
227 policy_item_t *condition;
228 policy_item_t *if_true;
229 policy_item_t *if_false; /* assignment, or other 'if' */
234 * Holds a reference to calling other modules... wild.
236 typedef struct policy_module_t {
238 int component; /* authorize, authenticate, etc. */
245 * Define a structure for our module configuration.
247 * These variables do not need to be in a structure, but it's
248 * a lot cleaner to do so, and a pointer to the structure can
249 * be used as the instance handle.
251 typedef struct rlm_policy_t {
260 extern const LRAD_NAME_NUMBER rlm_policy_tokens[];
261 extern const LRAD_NAME_NUMBER policy_reserved_words[];
262 extern const LRAD_NAME_NUMBER policy_return_codes[];
263 extern const LRAD_NAME_NUMBER policy_component_names[];
265 extern int rlm_policy_insert(rbtree_t *head, policy_named_t *policy);
266 extern policy_named_t *rlm_policy_find(rbtree_t *head, const char *name);
268 extern int rlm_policy_parse(rbtree_t *policies, const char *filename);
269 extern void rlm_policy_free_item(policy_item_t *item);
270 extern void rlm_policy_print(const policy_item_t *item);
271 extern int rlm_policy_evaluate(rlm_policy_t *inst, REQUEST *request,
274 #endif /* _RLM_POLICY_H */