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>
25 #include <freeradius-devel/autoconf.h>
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
34 #include <freeradius-devel/radiusd.h>
35 #include <freeradius-devel/modules.h>
36 #include <freeradius-devel/modcall.h>
38 #include <freeradius-devel/rad_assert.h>
43 typedef enum policy_lex_t {
45 POLICY_LEX_EOF, /* end of the file/input */
46 POLICY_LEX_EOL, /* end of the line */
47 POLICY_LEX_WHITESPACE,
51 POLICY_LEX_LC_BRACKET, /* left curly bracket */
52 POLICY_LEX_RC_BRACKET, /* right curly bracket */
54 POLICY_LEX_L_AND, /* logical AND */
55 POLICY_LEX_L_OR, /* logical OR */
56 POLICY_LEX_AND, /* bit-wise AND */
57 POLICY_LEX_OR, /* bit-wise OR */
59 POLICY_LEX_PLUS, /* + */
60 POLICY_LEX_MINUS, /* - */
61 POLICY_LEX_ASSIGN, /* = */
62 POLICY_LEX_CMP_EQUALS,
63 POLICY_LEX_CMP_NOT_EQUALS,
71 POLICY_LEX_RX_NOT_EQUALS,
72 POLICY_LEX_SET_EQUALS, /* := */
73 POLICY_LEX_AND_EQUALS, /* &= */
74 POLICY_LEX_OR_EQUALS, /* |= */
75 POLICY_LEX_PLUS_EQUALS, /* += */
76 POLICY_LEX_MINUS_EQUALS, /* -= */
77 POLICY_LEX_CONCAT_EQUALS, /* .= */
78 POLICY_LEX_VARIABLE, /* %{foo} */
79 POLICY_LEX_FUNCTION, /* Hmmm... */
80 POLICY_LEX_DOUBLE_QUOTED_STRING,
81 POLICY_LEX_SINGLE_QUOTED_STRING,
82 POLICY_LEX_BACK_QUOTED_STRING,
86 typedef enum policy_type_t {
89 POLICY_TYPE_CONDITIONAL,
90 POLICY_TYPE_ASSIGNMENT,
91 POLICY_TYPE_ATTRIBUTE_LIST,
93 POLICY_TYPE_NAMED_POLICY,
102 * For our policy language, we want to have some reserved words.
104 typedef enum policy_reserved_word_t {
105 POLICY_RESERVED_UNKNOWN = 0,
106 POLICY_RESERVED_CONTROL,
107 POLICY_RESERVED_REQUEST,
108 POLICY_RESERVED_REPLY,
109 POLICY_RESERVED_PROXY_REQUEST,
110 POLICY_RESERVED_PROXY_REPLY,
112 POLICY_RESERVED_ELSE,
113 POLICY_RESERVED_DEBUG,
114 POLICY_RESERVED_PRINT,
115 POLICY_RESERVED_POLICY,
116 POLICY_RESERVED_INCLUDE,
117 POLICY_RESERVED_RETURN,
118 POLICY_RESERVED_MODULE,
119 POLICY_RESERVED_NUM_WORDS
120 } policy_reserved_word_t;
123 #define POLICY_DEBUG_NONE 0
124 #define POLICY_DEBUG_PEEK (1 << 0)
125 #define POLICY_DEBUG_PRINT_TOKENS (1 << 1)
126 #define POLICY_DEBUG_PRINT_POLICY (1 << 2)
127 #define POLICY_DEBUG_EVALUATE (1 << 3)
132 typedef struct policy_item_t {
133 struct policy_item_t *next;
140 * A list of attributes to add/replace/whatever in a packet.
142 typedef struct policy_print_t {
144 policy_lex_t rhs_type;
150 * A list of attributes to add/replace/whatever in a packet.
152 typedef struct policy_attributes_t {
154 policy_reserved_word_t where; /* where to do it */
155 policy_lex_t how; /* how to do */
156 policy_item_t *attributes; /* things to do */
157 /* FIXME: VALUE_PAIR *vps; */
158 } policy_attributes_t;
162 * Holds a named policy
164 typedef struct policy_named_t {
167 policy_item_t *policy;
172 * Reference to a named policy
174 typedef struct policy_call_t {
183 typedef struct policy_return_t {
190 * Holds an assignment.
192 typedef struct policy_assignment_t {
195 policy_lex_t assign; /* operator for the assignment */
196 policy_lex_t rhs_type;
198 } policy_assignment_t;
204 typedef struct policy_condition_t {
207 policy_lex_t lhs_type;
209 policy_lex_t compare;
210 policy_lex_t rhs_type; /* bare word, quoted string, etc. */
213 policy_lex_t child_condition;
214 policy_item_t *child;
215 } policy_condition_t;
219 * Holds an "if" statement. The "else" may be a block, or another "if"
221 typedef struct policy_if_t {
223 policy_item_t *condition;
224 policy_item_t *if_true;
225 policy_item_t *if_false; /* assignment, or other 'if' */
230 * Holds a reference to calling other modules... wild.
232 typedef struct policy_module_t {
234 int component; /* authorize, authenticate, etc. */
241 * Define a structure for our module configuration.
243 * These variables do not need to be in a structure, but it's
244 * a lot cleaner to do so, and a pointer to the structure can
245 * be used as the instance handle.
247 typedef struct rlm_policy_t {
256 extern const LRAD_NAME_NUMBER rlm_policy_tokens[];
257 extern const LRAD_NAME_NUMBER policy_reserved_words[];
258 extern const LRAD_NAME_NUMBER policy_return_codes[];
259 extern const LRAD_NAME_NUMBER policy_component_names[];
261 extern int rlm_policy_insert(rbtree_t *head, policy_named_t *policy);
262 extern policy_named_t *rlm_policy_find(rbtree_t *head, const char *name);
264 extern int rlm_policy_parse(rbtree_t *policies, const char *filename);
265 extern void rlm_policy_free_item(policy_item_t *item);
266 extern void rlm_policy_print(const policy_item_t *item);
267 extern int rlm_policy_evaluate(rlm_policy_t *inst, REQUEST *request,
270 #endif /* _RLM_POLICY_H */