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 2000,2006 The FreeRADIUS server project
23 #include <freeradius-devel/ident.h>
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/modpriv.h>
28 #include <freeradius-devel/modcall.h>
29 #include <freeradius-devel/rad_assert.h>
31 extern int radius_get_vp(REQUEST *request, const char *name, VALUE_PAIR **vp_p);
33 /* mutually-recursive static functions need a prototype up front */
34 static modcallable *do_compile_modgroup(modcallable *,
38 /* Actions may be a positive integer (the highest one returned in the group
39 * will be returned), or the keyword "return", represented here by
40 * MOD_ACTION_RETURN, to cause an immediate return.
41 * There's also the keyword "reject", represented here by MOD_ACTION_REJECT
42 * to cause an immediate reject. */
43 #define MOD_ACTION_RETURN (-1)
44 #define MOD_ACTION_REJECT (-2)
46 /* Here are our basic types: modcallable, modgroup, and modsingle. For an
47 * explanation of what they are all about, see ../../doc/README.failover */
50 struct modcallable *next;
52 enum { MOD_SINGLE = 1, MOD_GROUP, MOD_LOAD_BALANCE, MOD_REDUNDANT_LOAD_BALANCE,
54 MOD_IF, MOD_ELSE, MOD_ELSIF, MOD_UPDATE, MOD_SWITCH, MOD_CASE,
56 MOD_POLICY, MOD_REFERENCE, MOD_XLAT } type;
58 int actions[RLM_MODULE_NUMCODES];
61 #define GROUPTYPE_SIMPLE 0
62 #define GROUPTYPE_REDUNDANT 1
63 #define GROUPTYPE_APPEND 2
64 #define GROUPTYPE_COUNT 3
67 modcallable mc; /* self */
68 int grouptype; /* after mc */
69 modcallable *children;
76 module_instance_t *modinst;
91 static const FR_NAME_NUMBER grouptype_table[] = {
92 { "", GROUPTYPE_SIMPLE },
93 { "redundant ", GROUPTYPE_REDUNDANT },
94 { "append ", GROUPTYPE_APPEND },
98 /* Simple conversions: modsingle and modgroup are subclasses of modcallable,
99 * so we often want to go back and forth between them. */
100 static modsingle *mod_callabletosingle(modcallable *p)
102 rad_assert(p->type==MOD_SINGLE);
103 return (modsingle *)p;
105 static modgroup *mod_callabletogroup(modcallable *p)
107 rad_assert((p->type > MOD_SINGLE) && (p->type <= MOD_POLICY));
109 return (modgroup *)p;
111 static modcallable *mod_singletocallable(modsingle *p)
113 return (modcallable *)p;
115 static modcallable *mod_grouptocallable(modgroup *p)
117 return (modcallable *)p;
120 static modref *mod_callabletoref(modcallable *p)
122 rad_assert(p->type==MOD_REFERENCE);
125 static modcallable *mod_reftocallable(modref *p)
127 return (modcallable *)p;
130 static modxlat *mod_callabletoxlat(modcallable *p)
132 rad_assert(p->type==MOD_XLAT);
135 static modcallable *mod_xlattocallable(modxlat *p)
137 return (modcallable *)p;
140 /* modgroups are grown by adding a modcallable to the end */
141 /* FIXME: This is O(N^2) */
142 static void add_child(modgroup *g, modcallable *c)
144 modcallable **head = &g->children;
145 modcallable *node = *head;
146 modcallable **last = head;
155 rad_assert(c->next == NULL);
157 c->parent = mod_grouptocallable(g);
160 /* Here's where we recognize all of our keywords: first the rcodes, then the
162 static const FR_NAME_NUMBER rcode_table[] = {
163 { "reject", RLM_MODULE_REJECT },
164 { "fail", RLM_MODULE_FAIL },
165 { "ok", RLM_MODULE_OK },
166 { "handled", RLM_MODULE_HANDLED },
167 { "invalid", RLM_MODULE_INVALID },
168 { "userlock", RLM_MODULE_USERLOCK },
169 { "notfound", RLM_MODULE_NOTFOUND },
170 { "noop", RLM_MODULE_NOOP },
171 { "updated", RLM_MODULE_UPDATED },
177 * Compile action && rcode for later use.
179 static int compile_action(modcallable *c, CONF_PAIR *cp)
182 const char *attr, *value;
184 attr = cf_pair_attr(cp);
185 value = cf_pair_value(cp);
186 if (!value) return 0;
188 if (!strcasecmp(value, "return"))
189 action = MOD_ACTION_RETURN;
191 else if (!strcasecmp(value, "break"))
192 action = MOD_ACTION_RETURN;
194 else if (!strcasecmp(value, "reject"))
195 action = MOD_ACTION_REJECT;
197 else if (strspn(value, "0123456789")==strlen(value)) {
198 action = atoi(value);
201 * Don't allow priority zero, for future use.
203 if (action == 0) return 0;
205 cf_log_err(cf_pairtoitem(cp), "Unknown action '%s'.\n",
210 if (strcasecmp(attr, "default") != 0) {
213 rcode = fr_str2int(rcode_table, attr, -1);
215 cf_log_err(cf_pairtoitem(cp),
216 "Unknown module rcode '%s'.\n",
220 c->actions[rcode] = action;
222 } else { /* set all unset values to the default */
225 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
226 if (!c->actions[i]) c->actions[i] = action;
233 /* Some short names for debugging output */
234 static const char * const comp2str[] = {
250 #ifdef HAVE_PTHREAD_H
252 * Lock the mutex for the module
254 static void safe_lock(module_instance_t *instance)
257 pthread_mutex_lock(instance->mutex);
261 * Unlock the mutex for the module
263 static void safe_unlock(module_instance_t *instance)
266 pthread_mutex_unlock(instance->mutex);
270 * No threads: these functions become NULL's.
272 #define safe_lock(foo)
273 #define safe_unlock(foo)
276 static int call_modsingle(int component, modsingle *sp, REQUEST *request)
281 rad_assert(request != NULL);
284 * If the request should stop, refuse to do anything.
286 blocked = (request->master_state == REQUEST_STOP_PROCESSING);
287 if (blocked) return RLM_MODULE_NOOP;
289 RDEBUG3(" modsingle[%s]: calling %s (%s) for request %d",
290 comp2str[component], sp->modinst->name,
291 sp->modinst->entry->name, request->number);
293 if (sp->modinst->dead) {
294 myresult = RLM_MODULE_FAIL;
298 safe_lock(sp->modinst);
301 * For logging unresponsive children.
303 request->module = sp->modinst->name;
305 myresult = sp->modinst->entry->module->methods[component](
306 sp->modinst->insthandle, request);
308 request->module = "";
309 safe_unlock(sp->modinst);
312 * Wasn't blocked, and now is. Complain!
314 blocked = (request->master_state == REQUEST_STOP_PROCESSING);
316 radlog(L_INFO, "WARNING: Module %s became unblocked for request %u",
317 sp->modinst->entry->name, request->number);
321 RDEBUG3(" modsingle[%s]: returned from %s (%s) for request %d",
322 comp2str[component], sp->modinst->name,
323 sp->modinst->entry->name, request->number);
329 static int default_component_results[RLM_COMPONENT_COUNT] = {
330 RLM_MODULE_REJECT, /* AUTH */
331 RLM_MODULE_NOTFOUND, /* AUTZ */
332 RLM_MODULE_NOOP, /* PREACCT */
333 RLM_MODULE_NOOP, /* ACCT */
334 RLM_MODULE_FAIL, /* SESS */
335 RLM_MODULE_NOOP, /* PRE_PROXY */
336 RLM_MODULE_NOOP, /* POST_PROXY */
337 RLM_MODULE_NOOP /* POST_AUTH */
340 RLM_MODULE_NOOP, /* RECV_COA_TYPE */
341 RLM_MODULE_NOOP /* SEND_COA_TYPE */
346 static const char *group_name[] = {
350 "load-balance group",
351 "redundant-load-balance group",
363 /* Here's where we recognize all of our keywords: first the rcodes, then the
365 const FR_NAME_NUMBER mod_rcode_table[] = {
366 { "reject", RLM_MODULE_REJECT },
367 { "fail", RLM_MODULE_FAIL },
368 { "ok", RLM_MODULE_OK },
369 { "handled", RLM_MODULE_HANDLED },
370 { "invalid", RLM_MODULE_INVALID },
371 { "userlock", RLM_MODULE_USERLOCK },
372 { "notfound", RLM_MODULE_NOTFOUND },
373 { "noop", RLM_MODULE_NOOP },
374 { "updated", RLM_MODULE_UPDATED },
378 static const char *modcall_spaces = "++++++++++++++++++++++++++++++++";
380 #define MODCALL_STACK_MAX (32)
382 #define MOD_LOG_OPEN_BRACE(_name) RDEBUG2("%.*s%s %s {", depth + 1, modcall_spaces, _name, c->name)
383 #define MOD_LOG_CLOSE_BRACE() RDEBUG2("%.*s} # %s %s = %s", depth + 1, modcall_spaces, \
384 group_name[c->type], c->name ? c->name : "", \
385 fr_int2str(mod_rcode_table, result, "<invalid>"))
388 * Don't call the modules recursively. Instead, do them
389 * iteratively, and manage the call stack ourselves.
391 typedef struct modcall_stack_entry_t {
395 } modcall_stack_entry_t;
398 static int modcall_recurse(REQUEST *request, int component, int depth,
399 modcall_stack_entry_t *entry);
402 * Call a child of a block.
404 static void modcall_child(REQUEST *request, int component, int depth,
405 modcall_stack_entry_t *entry, modcallable *c,
406 int *result, int *priority)
408 modcall_stack_entry_t *next;
410 if (depth >= MODCALL_STACK_MAX) {
411 radlog(L_ERR, "Internal sanity check failed: module stack is too deep");
416 * Initialize the childs stack frame.
420 next->result = entry->result;
423 if (!modcall_recurse(request, component,
425 *result = RLM_MODULE_FAIL;
429 *result = next->result;
430 *priority = next->priority;
436 * Interpret the various types of blocks.
438 static int modcall_recurse(REQUEST *request, int component, int depth,
439 modcall_stack_entry_t *entry)
441 int if_taken, was_if;
443 int result, priority;
445 was_if = if_taken = FALSE;
446 result = RLM_MODULE_FAIL;
453 * Nothing more to do. Return the code and priority
454 * which was set by the caller.
459 * We've been asked to stop. Do so.
461 if ((request->master_state == REQUEST_STOP_PROCESSING) ||
463 (request->parent->master_state == REQUEST_STOP_PROCESSING))) {
464 entry->result = RLM_MODULE_FAIL;
465 entry->priority = 9999;
470 * Handle "if" conditions.
472 if (c->type == MOD_IF) {
478 g = mod_callabletogroup(c);
481 RDEBUG2("%.*s? %s %s", depth + 1, modcall_spaces,
482 group_name[c->type], c->name);
484 if (radius_evaluate_condition(request, entry->result,
485 0, &p, TRUE, &condition)) {
486 RDEBUG2("%.*s? %s %s -> %s", depth + 1, modcall_spaces,
488 c->name, condition ? "TRUE" : "FALSE");
494 * Didn't pass. Remember that.
503 * We took the "if". Go recurse into its' children.
511 * "else" if the previous "if" was taken.
512 * "if" if the previous if wasn't taken.
514 if (c->type == MOD_ELSIF) {
515 if (!was_if) goto elsif_error;
518 * Like MOD_ELSE, but allow for a later "else"
521 RDEBUG2("%.*s ... skipping %s for request %d: Preceding \"if\" was taken",
522 depth + 1, modcall_spaces,
523 group_name[c->type], request->number);
530 * Check the "if" condition.
536 * "else" for a preceding "if".
538 if (c->type == MOD_ELSE) {
539 if (!was_if) { /* error */
541 RDEBUG2("%.*s ... skipping %s for request %d: No preceding \"if\"",
542 depth + 1, modcall_spaces,
543 group_name[c->type], request->number);
548 RDEBUG2("%.*s ... skipping %s for request %d: Preceding \"if\" was taken",
549 depth + 1, modcall_spaces,
550 group_name[c->type], request->number);
557 * We need to process it. Go do that.
565 * We're no longer processing if/else/elsif. Reset the
566 * trackers for those conditions.
571 if (c->type == MOD_SINGLE) {
575 * Process a stand-alone child, and fall through
576 * to dealing with it's parent.
578 sp = mod_callabletosingle(c);
580 result = call_modsingle(c->method, sp, request);
581 RDEBUG2("%.*s[%s] = %s", depth + 1, modcall_spaces, c->name ? c->name : "",
582 fr_int2str(mod_rcode_table, result, "<invalid>"));
583 goto calculate_result;
587 * Update attribute(s)
589 if (c->type == MOD_UPDATE) {
591 modgroup *g = mod_callabletogroup(c);
593 MOD_LOG_OPEN_BRACE("update");
594 rcode = radius_update_attrlist(request, g->cs,
596 if (rcode != RLM_MODULE_UPDATED) {
598 goto calculate_result;
601 result = RLM_MODULE_NOOP;
602 MOD_LOG_CLOSE_BRACE();
607 * Child is a group that has children of it's own.
609 if ((c->type == MOD_GROUP) || (c->type == MOD_POLICY) ||
610 (c->type == MOD_CASE)) {
614 g = mod_callabletogroup(c);
616 MOD_LOG_OPEN_BRACE(group_name[c->type]);
617 modcall_child(request, component,
618 depth + 1, entry, g->children,
620 MOD_LOG_CLOSE_BRACE();
621 goto calculate_result;
624 if (c->type == MOD_SWITCH) {
625 modcallable *this, *found, *null_case;
629 MOD_LOG_OPEN_BRACE("switch");
632 * If there's no %, it refers to an attribute.
633 * Otherwise, expand it.
635 if (!strchr(c->name, '%')) {
636 VALUE_PAIR *vp = NULL;
638 radius_get_vp(request, c->name, &vp);
640 vp_prints_value(buffer,
647 radius_xlat(buffer, sizeof(buffer),
648 c->name, request, NULL);
652 * Find either the exact matching name, or the
653 * "case {...}" statement.
655 g = mod_callabletogroup(c);
656 null_case = found = NULL;
657 for (this = g->children; this; this = this->next) {
659 if (!null_case) null_case = this;
662 if (strcmp(buffer, this->name) == 0) {
668 if (!found) found = null_case;
670 MOD_LOG_OPEN_BRACE(group_name[c->type]);
671 modcall_child(request, component,
672 depth + 1, entry, found,
674 MOD_LOG_CLOSE_BRACE();
675 goto calculate_result;
678 if ((c->type == MOD_LOAD_BALANCE) ||
679 (c->type == MOD_REDUNDANT_LOAD_BALANCE)) {
681 modcallable *this, *found;
684 MOD_LOG_OPEN_BRACE("load-balance");
686 g = mod_callabletogroup(c);
688 for (this = g->children; this; this = this->next) {
696 if ((count * (fr_rand() & 0xffff)) < (uint32_t) 0x10000) {
701 MOD_LOG_OPEN_BRACE(group_name[c->type]);
703 if (c->type == MOD_LOAD_BALANCE) {
704 modcall_child(request, component,
705 depth + 1, entry, found,
712 * Loop over all children in this
713 * section. If we get FAIL, then
714 * continue. Otherwise, stop.
716 for (i = 1; i < count; i++) {
717 modcall_child(request, component,
718 depth + 1, entry, found,
720 if (c->actions[result] == MOD_ACTION_RETURN) {
726 MOD_LOG_CLOSE_BRACE();
727 goto calculate_result;
728 } /* MOD_LOAD_BALANCE */
731 * Reference another virtual server.
733 * This should really be deleted, and replaced with a
734 * more abstracted / functional version.
736 if (c->type == MOD_REFERENCE) {
737 modref *mr = mod_callabletoref(c);
738 char const *server = request->server;
740 if (server == mr->ref_name) {
741 radlog(L_INFO, "WARNING: Suppressing recursive call to server %s", server);
745 request->server = mr->ref_name;
746 RDEBUG("server %s { # nested call", mr->ref_name);
747 result = indexed_modcall(component, 0, request);
748 RDEBUG("} # server %s with nested call", mr->ref_name);
749 request->server = server;
750 goto calculate_result;
751 } /* MOD_REFERENCE */
754 * xlat a string without doing anything else
756 * This should really be deleted, and replaced with a
757 * more abstracted / functional version.
759 if (c->type == MOD_XLAT) {
760 modxlat *mx = mod_callabletoxlat(c);
764 radius_xlat(buffer, sizeof(buffer),
765 mx->xlat_name, request, NULL);
767 RDEBUG("`%s`", mx->xlat_name);
768 radius_exec_program(mx->xlat_name, request,
770 request->packet->vps,
778 * Add new module types here.
783 * The child's action says return. Do so.
785 if ((c->actions[result] == MOD_ACTION_RETURN) &&
787 entry->result = result;
792 * If "reject", break out of the loop and return
795 if (c->actions[result] == MOD_ACTION_REJECT) {
796 entry->result = RLM_MODULE_REJECT;
801 * The array holds a default priority for this return
802 * code. Grab it in preference to any unset priority.
804 if (priority < 0) priority = c->actions[result];
807 * We're higher than any previous priority, remember this
808 * return code and priority.
810 if (priority > entry->priority) {
811 entry->result = result;
812 entry->priority = priority;
816 * If we're processing a "case" statement, we return once
817 * it's done, rather than going to the next "case" statement.
819 if (c->type == MOD_CASE) return TRUE;
822 entry->c = entry->c->next;
824 if (entry->c) goto redo;
834 * @brief Call a module, iteratively, with a local stack, rather than
835 * recursively. What did Paul Graham say about Lisp...?
837 int modcall(int component, modcallable *c, REQUEST *request)
839 modcall_stack_entry_t stack[MODCALL_STACK_MAX];
841 if ((component < 0) || (component >= RLM_COMPONENT_COUNT)) {
842 return RLM_MODULE_FAIL;
846 * Set up the initial stack frame.
849 stack[0].result = default_component_results[component];
850 stack[0].priority = 0;
853 * Call the main handler.
855 if (!modcall_recurse(request, component, 0, &stack[0])) {
856 return RLM_MODULE_FAIL;
862 return stack[0].result;
866 static const char *action2str(int action)
869 if(action==MOD_ACTION_RETURN)
871 if(action==MOD_ACTION_REJECT)
873 snprintf(buf, sizeof buf, "%d", action);
877 /* If you suspect a bug in the parser, you'll want to use these dump
878 * functions. dump_tree should reproduce a whole tree exactly as it was found
879 * in radiusd.conf, but in long form (all actions explicitly defined) */
880 static void dump_mc(modcallable *c, int indent)
884 if(c->type==MOD_SINGLE) {
885 modsingle *single = mod_callabletosingle(c);
886 DEBUG("%.*s%s {", indent, "\t\t\t\t\t\t\t\t\t\t\t",
887 single->modinst->name);
888 } else if ((c->type > MOD_SINGLE) && (c->type <= MOD_POLICY)) {
889 modgroup *g = mod_callabletogroup(c);
891 DEBUG("%.*s%s {", indent, "\t\t\t\t\t\t\t\t\t\t\t",
892 group_name[c->type]);
893 for(p = g->children;p;p = p->next)
894 dump_mc(p, indent+1);
895 } /* else ignore it for now */
897 for(i = 0; i<RLM_MODULE_NUMCODES; ++i) {
898 DEBUG("%.*s%s = %s", indent+1, "\t\t\t\t\t\t\t\t\t\t\t",
899 fr_int2str(rcode_table, i, "??"),
900 action2str(c->actions[i]));
903 DEBUG("%.*s}", indent, "\t\t\t\t\t\t\t\t\t\t\t");
906 static void dump_tree(int comp, modcallable *c)
908 RDEBUG("[%s]", comp2str[comp]);
912 #define dump_tree(a, b)
915 /* These are the default actions. For each component, the group{} block
916 * behaves like the code from the old module_*() function. redundant{} and
917 * append{} are based on my guesses of what they will be used for. --Pac. */
919 defaultactions[RLM_COMPONENT_COUNT][GROUPTYPE_COUNT][RLM_MODULE_NUMCODES] =
925 MOD_ACTION_RETURN, /* reject */
927 MOD_ACTION_RETURN, /* ok */
928 MOD_ACTION_RETURN, /* handled */
930 MOD_ACTION_RETURN, /* userlock */
931 MOD_ACTION_RETURN, /* notfound */
937 MOD_ACTION_RETURN, /* reject */
939 MOD_ACTION_RETURN, /* ok */
940 MOD_ACTION_RETURN, /* handled */
941 MOD_ACTION_RETURN, /* invalid */
942 MOD_ACTION_RETURN, /* userlock */
943 MOD_ACTION_RETURN, /* notfound */
944 MOD_ACTION_RETURN, /* noop */
945 MOD_ACTION_RETURN /* updated */
949 MOD_ACTION_RETURN, /* reject */
951 MOD_ACTION_RETURN, /* ok */
952 MOD_ACTION_RETURN, /* handled */
953 MOD_ACTION_RETURN, /* invalid */
954 MOD_ACTION_RETURN, /* userlock */
956 MOD_ACTION_RETURN, /* noop */
957 MOD_ACTION_RETURN /* updated */
964 MOD_ACTION_RETURN, /* reject */
965 MOD_ACTION_RETURN, /* fail */
967 MOD_ACTION_RETURN, /* handled */
968 MOD_ACTION_RETURN, /* invalid */
969 MOD_ACTION_RETURN, /* userlock */
976 MOD_ACTION_RETURN, /* reject */
978 MOD_ACTION_RETURN, /* ok */
979 MOD_ACTION_RETURN, /* handled */
980 MOD_ACTION_RETURN, /* invalid */
981 MOD_ACTION_RETURN, /* userlock */
982 MOD_ACTION_RETURN, /* notfound */
983 MOD_ACTION_RETURN, /* noop */
984 MOD_ACTION_RETURN /* updated */
988 MOD_ACTION_RETURN, /* reject */
990 MOD_ACTION_RETURN, /* ok */
991 MOD_ACTION_RETURN, /* handled */
992 MOD_ACTION_RETURN, /* invalid */
993 MOD_ACTION_RETURN, /* userlock */
995 MOD_ACTION_RETURN, /* noop */
996 MOD_ACTION_RETURN /* updated */
1003 MOD_ACTION_RETURN, /* reject */
1004 MOD_ACTION_RETURN, /* fail */
1006 MOD_ACTION_RETURN, /* handled */
1007 MOD_ACTION_RETURN, /* invalid */
1008 MOD_ACTION_RETURN, /* userlock */
1009 MOD_ACTION_RETURN, /* notfound */
1015 MOD_ACTION_RETURN, /* reject */
1017 MOD_ACTION_RETURN, /* ok */
1018 MOD_ACTION_RETURN, /* handled */
1019 MOD_ACTION_RETURN, /* invalid */
1020 MOD_ACTION_RETURN, /* userlock */
1021 MOD_ACTION_RETURN, /* notfound */
1022 MOD_ACTION_RETURN, /* noop */
1023 MOD_ACTION_RETURN /* updated */
1027 MOD_ACTION_RETURN, /* reject */
1029 MOD_ACTION_RETURN, /* ok */
1030 MOD_ACTION_RETURN, /* handled */
1031 MOD_ACTION_RETURN, /* invalid */
1032 MOD_ACTION_RETURN, /* userlock */
1034 MOD_ACTION_RETURN, /* noop */
1035 MOD_ACTION_RETURN /* updated */
1042 MOD_ACTION_RETURN, /* reject */
1043 MOD_ACTION_RETURN, /* fail */
1045 MOD_ACTION_RETURN, /* handled */
1046 MOD_ACTION_RETURN, /* invalid */
1047 MOD_ACTION_RETURN, /* userlock */
1048 MOD_ACTION_RETURN, /* notfound */
1056 MOD_ACTION_RETURN, /* ok */
1057 MOD_ACTION_RETURN, /* handled */
1066 MOD_ACTION_RETURN, /* reject */
1068 MOD_ACTION_RETURN, /* ok */
1069 MOD_ACTION_RETURN, /* handled */
1070 MOD_ACTION_RETURN, /* invalid */
1071 MOD_ACTION_RETURN, /* userlock */
1073 MOD_ACTION_RETURN, /* noop */
1074 MOD_ACTION_RETURN /* updated */
1081 MOD_ACTION_RETURN, /* reject */
1083 MOD_ACTION_RETURN, /* ok */
1084 MOD_ACTION_RETURN, /* handled */
1085 MOD_ACTION_RETURN, /* invalid */
1086 MOD_ACTION_RETURN, /* userlock */
1087 MOD_ACTION_RETURN, /* notfound */
1088 MOD_ACTION_RETURN, /* noop */
1089 MOD_ACTION_RETURN /* updated */
1093 MOD_ACTION_RETURN, /* reject */
1095 MOD_ACTION_RETURN, /* ok */
1096 MOD_ACTION_RETURN, /* handled */
1097 MOD_ACTION_RETURN, /* invalid */
1098 MOD_ACTION_RETURN, /* userlock */
1099 MOD_ACTION_RETURN, /* notfound */
1100 MOD_ACTION_RETURN, /* noop */
1101 MOD_ACTION_RETURN /* updated */
1105 MOD_ACTION_RETURN, /* reject */
1107 MOD_ACTION_RETURN, /* ok */
1108 MOD_ACTION_RETURN, /* handled */
1109 MOD_ACTION_RETURN, /* invalid */
1110 MOD_ACTION_RETURN, /* userlock */
1111 MOD_ACTION_RETURN, /* notfound */
1112 MOD_ACTION_RETURN, /* noop */
1113 MOD_ACTION_RETURN /* updated */
1120 MOD_ACTION_RETURN, /* reject */
1121 MOD_ACTION_RETURN, /* fail */
1123 MOD_ACTION_RETURN, /* handled */
1124 MOD_ACTION_RETURN, /* invalid */
1125 MOD_ACTION_RETURN, /* userlock */
1132 MOD_ACTION_RETURN, /* reject */
1134 MOD_ACTION_RETURN, /* ok */
1135 MOD_ACTION_RETURN, /* handled */
1136 MOD_ACTION_RETURN, /* invalid */
1137 MOD_ACTION_RETURN, /* userlock */
1138 MOD_ACTION_RETURN, /* notfound */
1139 MOD_ACTION_RETURN, /* noop */
1140 MOD_ACTION_RETURN /* updated */
1144 MOD_ACTION_RETURN, /* reject */
1146 MOD_ACTION_RETURN, /* ok */
1147 MOD_ACTION_RETURN, /* handled */
1148 MOD_ACTION_RETURN, /* invalid */
1149 MOD_ACTION_RETURN, /* userlock */
1151 MOD_ACTION_RETURN, /* noop */
1152 MOD_ACTION_RETURN /* updated */
1159 MOD_ACTION_RETURN, /* reject */
1160 MOD_ACTION_RETURN, /* fail */
1162 MOD_ACTION_RETURN, /* handled */
1163 MOD_ACTION_RETURN, /* invalid */
1164 MOD_ACTION_RETURN, /* userlock */
1171 MOD_ACTION_RETURN, /* reject */
1173 MOD_ACTION_RETURN, /* ok */
1174 MOD_ACTION_RETURN, /* handled */
1175 MOD_ACTION_RETURN, /* invalid */
1176 MOD_ACTION_RETURN, /* userlock */
1177 MOD_ACTION_RETURN, /* notfound */
1178 MOD_ACTION_RETURN, /* noop */
1179 MOD_ACTION_RETURN /* updated */
1183 MOD_ACTION_RETURN, /* reject */
1185 MOD_ACTION_RETURN, /* ok */
1186 MOD_ACTION_RETURN, /* handled */
1187 MOD_ACTION_RETURN, /* invalid */
1188 MOD_ACTION_RETURN, /* userlock */
1190 MOD_ACTION_RETURN, /* noop */
1191 MOD_ACTION_RETURN /* updated */
1198 MOD_ACTION_RETURN, /* reject */
1199 MOD_ACTION_RETURN, /* fail */
1201 MOD_ACTION_RETURN, /* handled */
1202 MOD_ACTION_RETURN, /* invalid */
1203 MOD_ACTION_RETURN, /* userlock */
1210 MOD_ACTION_RETURN, /* reject */
1212 MOD_ACTION_RETURN, /* ok */
1213 MOD_ACTION_RETURN, /* handled */
1214 MOD_ACTION_RETURN, /* invalid */
1215 MOD_ACTION_RETURN, /* userlock */
1216 MOD_ACTION_RETURN, /* notfound */
1217 MOD_ACTION_RETURN, /* noop */
1218 MOD_ACTION_RETURN /* updated */
1222 MOD_ACTION_RETURN, /* reject */
1224 MOD_ACTION_RETURN, /* ok */
1225 MOD_ACTION_RETURN, /* handled */
1226 MOD_ACTION_RETURN, /* invalid */
1227 MOD_ACTION_RETURN, /* userlock */
1229 MOD_ACTION_RETURN, /* noop */
1230 MOD_ACTION_RETURN /* updated */
1239 MOD_ACTION_RETURN, /* reject */
1240 MOD_ACTION_RETURN, /* fail */
1242 MOD_ACTION_RETURN, /* handled */
1243 MOD_ACTION_RETURN, /* invalid */
1244 MOD_ACTION_RETURN, /* userlock */
1251 MOD_ACTION_RETURN, /* reject */
1253 MOD_ACTION_RETURN, /* ok */
1254 MOD_ACTION_RETURN, /* handled */
1255 MOD_ACTION_RETURN, /* invalid */
1256 MOD_ACTION_RETURN, /* userlock */
1257 MOD_ACTION_RETURN, /* notfound */
1258 MOD_ACTION_RETURN, /* noop */
1259 MOD_ACTION_RETURN /* updated */
1263 MOD_ACTION_RETURN, /* reject */
1265 MOD_ACTION_RETURN, /* ok */
1266 MOD_ACTION_RETURN, /* handled */
1267 MOD_ACTION_RETURN, /* invalid */
1268 MOD_ACTION_RETURN, /* userlock */
1270 MOD_ACTION_RETURN, /* noop */
1271 MOD_ACTION_RETURN /* updated */
1278 MOD_ACTION_RETURN, /* reject */
1279 MOD_ACTION_RETURN, /* fail */
1281 MOD_ACTION_RETURN, /* handled */
1282 MOD_ACTION_RETURN, /* invalid */
1283 MOD_ACTION_RETURN, /* userlock */
1290 MOD_ACTION_RETURN, /* reject */
1292 MOD_ACTION_RETURN, /* ok */
1293 MOD_ACTION_RETURN, /* handled */
1294 MOD_ACTION_RETURN, /* invalid */
1295 MOD_ACTION_RETURN, /* userlock */
1296 MOD_ACTION_RETURN, /* notfound */
1297 MOD_ACTION_RETURN, /* noop */
1298 MOD_ACTION_RETURN /* updated */
1302 MOD_ACTION_RETURN, /* reject */
1304 MOD_ACTION_RETURN, /* ok */
1305 MOD_ACTION_RETURN, /* handled */
1306 MOD_ACTION_RETURN, /* invalid */
1307 MOD_ACTION_RETURN, /* userlock */
1309 MOD_ACTION_RETURN, /* noop */
1310 MOD_ACTION_RETURN /* updated */
1318 static modcallable *do_compile_modupdate(modcallable *parent,
1319 int component, CONF_SECTION *cs,
1323 const char *vp_name;
1325 modcallable *csingle;
1327 VALUE_PAIR *head, **tail;
1329 static const char *attrlist_names[] = {
1330 "request", "reply", "proxy-request", "proxy-reply",
1331 "config", "control",
1332 "coa", "coa-reply", "disconnect", "disconnect-reply",
1336 component = component; /* -Wunused */
1338 if (!cf_section_name2(cs)) {
1339 cf_log_err(cf_sectiontoitem(cs),
1340 "Require list name for 'update'.\n");
1345 if (strncmp(vp_name, "outer.", 6) == 0) {
1349 for (i = 0; attrlist_names[i] != NULL; i++) {
1350 if (strcmp(vp_name, attrlist_names[i]) == 0) {
1357 cf_log_err(cf_sectiontoitem(cs),
1358 "Unknown attribute list \"%s\"",
1367 * Walk through the children of the update section,
1368 * ensuring that they're all known attributes.
1370 for (ci=cf_item_find_next(cs, NULL);
1372 ci=cf_item_find_next(cs, ci)) {
1376 if (cf_item_is_section(ci)) {
1377 cf_log_err(ci, "\"update\" sections cannot have subsections");
1381 if (!cf_item_is_pair(ci)) continue;
1383 cp = cf_itemtopair(ci); /* can't return NULL */
1384 vp = cf_pairtovp(cp);
1387 cf_log_err(ci, "ERROR: %s", fr_strerror());
1391 if ((vp->operator != T_OP_EQ) &&
1392 (vp->operator != T_OP_CMP_EQ) &&
1393 (vp->operator != T_OP_ADD) &&
1394 (vp->operator != T_OP_SUB) &&
1395 (vp->operator != T_OP_LE) &&
1396 (vp->operator != T_OP_GE) &&
1397 (vp->operator != T_OP_CMP_FALSE) &&
1398 (vp->operator != T_OP_SET)) {
1401 cf_log_err(ci, "Invalid operator for attribute");
1406 * A few more sanity checks. The enforcement of
1407 * <= or >= can only happen for integer
1410 if ((vp->operator == T_OP_LE) ||
1411 (vp->operator == T_OP_GE)) {
1412 if ((vp->type != PW_TYPE_BYTE) &&
1413 (vp->type != PW_TYPE_SHORT) &&
1414 (vp->type != PW_TYPE_INTEGER)) {
1417 cf_log_err(ci, "Enforcment of <= or >= is possible only for integer attributes");
1427 cf_log_err(cf_sectiontoitem(cs),
1428 "ERROR: update %s section cannot be empty",
1433 g = rad_malloc(sizeof(*g)); /* never fails */
1434 memset(g, 0, sizeof(*g));
1435 csingle = mod_grouptocallable(g);
1437 csingle->parent = parent;
1438 csingle->next = NULL;
1439 csingle->name = name2;
1440 csingle->type = MOD_UPDATE;
1441 csingle->method = component;
1443 g->grouptype = GROUPTYPE_SIMPLE;
1452 static modcallable *do_compile_modswitch(modcallable *parent,
1453 int component, CONF_SECTION *cs)
1455 modcallable *csingle;
1457 int had_seen_default = FALSE;
1459 component = component; /* -Wunused */
1461 if (!cf_section_name2(cs)) {
1462 cf_log_err(cf_sectiontoitem(cs),
1463 "You must specify a variable to switch over for 'switch'.");
1467 if (!cf_item_find_next(cs, NULL)) {
1468 cf_log_err(cf_sectiontoitem(cs), "'switch' statments cannot be empty.");
1473 * Walk through the children of the switch section,
1474 * ensuring that they're all 'case' statements
1476 for (ci=cf_item_find_next(cs, NULL);
1478 ci=cf_item_find_next(cs, ci)) {
1479 CONF_SECTION *subcs;
1480 const char *name1, *name2;
1482 if (!cf_item_is_section(ci)) {
1483 if (!cf_item_is_pair(ci)) continue;
1485 cf_log_err(ci, "\"switch\" sections can only have \"case\" subsections");
1489 subcs = cf_itemtosection(ci); /* can't return NULL */
1490 name1 = cf_section_name1(subcs);
1492 if (strcmp(name1, "case") != 0) {
1493 cf_log_err(ci, "\"switch\" sections can only have \"case\" subsections");
1497 name2 = cf_section_name2(subcs);
1498 if (!name2 && !had_seen_default) {
1499 had_seen_default = TRUE;
1503 if (!name2 || (name2[0] == '\0')) {
1504 cf_log_err(ci, "\"case\" sections must have a name");
1509 csingle= do_compile_modgroup(parent, component, cs,
1510 GROUPTYPE_SIMPLE, GROUPTYPE_SIMPLE);
1511 if (!csingle) return NULL;
1512 csingle->type = MOD_SWITCH;
1517 static modcallable *do_compile_modserver(modcallable *parent,
1518 int component, CONF_ITEM *ci,
1523 modcallable *csingle;
1524 CONF_SECTION *subcs;
1527 subcs = cf_section_sub_find_name2(cs, comp2str[component], NULL);
1529 cf_log_err(ci, "Server %s has no %s section",
1530 server, comp2str[component]);
1534 mr = rad_malloc(sizeof(*mr));
1535 memset(mr, 0, sizeof(*mr));
1537 csingle = mod_reftocallable(mr);
1538 csingle->parent = parent;
1539 csingle->next = NULL;
1540 csingle->name = name;
1541 csingle->type = MOD_REFERENCE;
1542 csingle->method = component;
1544 memcpy(csingle->actions, defaultactions[component][GROUPTYPE_SIMPLE],
1545 sizeof(csingle->actions));
1547 mr->ref_name = strdup(server);
1553 static modcallable *do_compile_modxlat(modcallable *parent,
1554 int component, const char *fmt)
1556 modcallable *csingle;
1559 mx = rad_malloc(sizeof(*mx));
1560 memset(mx, 0, sizeof(*mx));
1562 csingle = mod_xlattocallable(mx);
1563 csingle->parent = parent;
1564 csingle->next = NULL;
1565 csingle->name = "expand";
1566 csingle->type = MOD_XLAT;
1567 csingle->method = component;
1569 memcpy(csingle->actions, defaultactions[component][GROUPTYPE_SIMPLE],
1570 sizeof(csingle->actions));
1572 mx->xlat_name = strdup(fmt);
1573 if (fmt[0] != '%') {
1577 strcpy(mx->xlat_name, fmt + 1);
1578 p = strrchr(mx->xlat_name, '`');
1586 * redundant, etc. can refer to modules or groups, but not much else.
1588 static int all_children_are_modules(CONF_SECTION *cs, const char *name)
1592 for (ci=cf_item_find_next(cs, NULL);
1594 ci=cf_item_find_next(cs, ci)) {
1596 * If we're a redundant, etc. group, then the
1597 * intention is to call modules, rather than
1598 * processing logic. These checks aren't
1599 * *strictly* necessary, but they keep the users
1600 * from doing crazy things.
1602 if (cf_item_is_section(ci)) {
1603 CONF_SECTION *subcs = cf_itemtosection(ci);
1604 const char *name1 = cf_section_name1(subcs);
1606 if ((strcmp(name1, "if") == 0) ||
1607 (strcmp(name1, "else") == 0) ||
1608 (strcmp(name1, "elsif") == 0) ||
1609 (strcmp(name1, "update") == 0) ||
1610 (strcmp(name1, "switch") == 0) ||
1611 (strcmp(name1, "case") == 0)) {
1612 cf_log_err(ci, "%s sections cannot contain a \"%s\" statement",
1619 if (cf_item_is_pair(ci)) {
1620 CONF_PAIR *cp = cf_itemtopair(ci);
1621 if (cf_pair_value(cp) != NULL) {
1623 "Entry with no value is invalid");
1634 * Compile one entry of a module call.
1636 static modcallable *do_compile_modsingle(modcallable *parent,
1637 int component, CONF_ITEM *ci,
1639 const char **modname)
1644 const char *modrefname;
1646 modcallable *csingle;
1647 module_instance_t *this;
1648 CONF_SECTION *cs, *subcs, *modules;
1650 if (cf_item_is_section(ci)) {
1653 cs = cf_itemtosection(ci);
1654 modrefname = cf_section_name1(cs);
1655 name2 = cf_section_name2(cs);
1656 if (!name2) name2 = "_UnNamedGroup";
1659 * group{}, redundant{}, or append{} may appear
1660 * where a single module instance was expected.
1661 * In that case, we hand it off to
1664 if (strcmp(modrefname, "group") == 0) {
1666 return do_compile_modgroup(parent, component, cs,
1670 } else if (strcmp(modrefname, "redundant") == 0) {
1673 if (!all_children_are_modules(cs, modrefname)) {
1677 return do_compile_modgroup(parent, component, cs,
1678 GROUPTYPE_REDUNDANT,
1681 } else if (strcmp(modrefname, "append") == 0) {
1683 return do_compile_modgroup(parent, component, cs,
1687 } else if (strcmp(modrefname, "load-balance") == 0) {
1690 if (!all_children_are_modules(cs, modrefname)) {
1694 csingle= do_compile_modgroup(parent, component, cs,
1697 if (!csingle) return NULL;
1698 csingle->type = MOD_LOAD_BALANCE;
1701 } else if (strcmp(modrefname, "redundant-load-balance") == 0) {
1704 if (!all_children_are_modules(cs, modrefname)) {
1708 csingle= do_compile_modgroup(parent, component, cs,
1709 GROUPTYPE_REDUNDANT,
1711 if (!csingle) return NULL;
1712 csingle->type = MOD_REDUNDANT_LOAD_BALANCE;
1716 } else if (strcmp(modrefname, "if") == 0) {
1717 if (!cf_section_name2(cs)) {
1718 cf_log_err(ci, "'if' without condition.");
1723 csingle= do_compile_modgroup(parent, component, cs,
1726 if (!csingle) return NULL;
1727 csingle->type = MOD_IF;
1729 if (!radius_evaluate_condition(NULL, 0, 0, modname,
1731 modcallable_free(&csingle);
1738 } else if (strcmp(modrefname, "elsif") == 0) {
1740 ((parent->type == MOD_LOAD_BALANCE) ||
1741 (parent->type == MOD_REDUNDANT_LOAD_BALANCE))) {
1742 cf_log_err(ci, "'elsif' cannot be used in this section.");
1746 if (!cf_section_name2(cs)) {
1747 cf_log_err(ci, "'elsif' without condition.");
1752 csingle= do_compile_modgroup(parent, component, cs,
1755 if (!csingle) return NULL;
1756 csingle->type = MOD_ELSIF;
1758 if (!radius_evaluate_condition(NULL, 0, 0, modname,
1760 modcallable_free(&csingle);
1767 } else if (strcmp(modrefname, "else") == 0) {
1769 ((parent->type == MOD_LOAD_BALANCE) ||
1770 (parent->type == MOD_REDUNDANT_LOAD_BALANCE))) {
1771 cf_log_err(ci, "'else' cannot be used in this section section.");
1775 if (cf_section_name2(cs)) {
1776 cf_log_err(ci, "Cannot have conditions on 'else'.");
1781 csingle= do_compile_modgroup(parent, component, cs,
1784 if (!csingle) return NULL;
1785 csingle->type = MOD_ELSE;
1788 } else if (strcmp(modrefname, "update") == 0) {
1791 csingle = do_compile_modupdate(parent, component, cs,
1793 if (!csingle) return NULL;
1797 } else if (strcmp(modrefname, "switch") == 0) {
1800 csingle = do_compile_modswitch(parent, component, cs);
1801 if (!csingle) return NULL;
1805 } else if (strcmp(modrefname, "case") == 0) {
1811 * FIXME: How to tell that the parent can only
1812 * be a "switch" statement?
1815 cf_log_err(ci, "\"case\" statements may only appear within a \"switch\" section");
1819 csingle= do_compile_modgroup(parent, component, cs,
1822 if (!csingle) return NULL;
1823 csingle->type = MOD_CASE;
1824 csingle->name = cf_section_name2(cs); /* may be NULL */
1827 * Set all of it's codes to return, so that
1828 * when we pick a 'case' statement, we don't
1829 * fall through to processing the next one.
1831 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
1832 csingle->actions[i] = MOD_ACTION_RETURN;
1837 } /* else it's something like sql { fail = 1 ...} */
1839 } else if (!cf_item_is_pair(ci)) { /* CONF_DATA or some such */
1843 * Else it's a module reference, with updated return
1848 CONF_PAIR *cp = cf_itemtopair(ci);
1849 modrefname = cf_pair_attr(cp);
1852 * Actions (ok = 1), etc. are orthoganal to just
1853 * about everything else.
1855 if (cf_pair_value(cp) != NULL) {
1856 cf_log_err(ci, "Entry is not a reference to a module");
1860 if (((modrefname[0] == '%') && (modrefname[1] == '{')) ||
1861 (modrefname[0] == '`')) {
1862 return do_compile_modxlat(parent, component,
1867 * See if the module is a virtual one. If so,
1868 * return that, rather than doing anything here.
1871 cs = cf_section_find("instantiate");
1872 if (cs) subcs = cf_section_sub_find_name2(cs, NULL,
1875 (cs = cf_section_find("policy")) != NULL) {
1878 snprintf(buffer, sizeof(buffer), "%s.%s",
1879 modrefname, comp2str[component]);
1882 * Prefer name.section, then name.
1884 subcs = cf_section_sub_find_name2(cs, NULL,
1887 subcs = cf_section_sub_find_name2(cs, NULL,
1893 * Allow policies to over-ride module names.
1894 * i.e. the "sql" policy can do some extra things,
1895 * and then call the "sql" module.
1897 for (loop = cf_item_parent(ci);
1899 loop = cf_item_parent(cf_sectiontoitem(loop))) {
1900 if (loop == subcs) {
1906 DEBUG2(" Module: Loading virtual module %s",
1910 * redundant foo {} is a single.
1912 if (cf_section_name2(subcs)) {
1913 return do_compile_modsingle(parent,
1915 cf_sectiontoitem(subcs),
1920 * foo {} is a group.
1922 return do_compile_modgroup(parent,
1932 * Not a virtual module. It must be a real module.
1934 modules = cf_section_find("modules");
1937 if (modules && cf_section_sub_find_name2(modules, NULL, modrefname)) {
1938 this = find_module_instance(modules, modrefname, 1);
1946 * Maybe it's module.method
1948 p = strrchr(modrefname, '.');
1949 if (p) for (i = RLM_COMPONENT_AUTH;
1950 i < RLM_COMPONENT_COUNT;
1952 if (strcmp(p + 1, comp2str[i]) == 0) {
1955 strlcpy(buffer, modrefname, sizeof(buffer));
1956 buffer[p - modrefname] = '\0';
1959 this = find_module_instance(cf_section_find("modules"), buffer, 1);
1961 !this->entry->module->methods[i]) {
1963 cf_log_err(ci, "Module %s has no such method %s", buffer, comp2str[i]);
1971 if (strncmp(modrefname, "server[", 7) == 0) {
1974 strlcpy(buffer, modrefname + 7, sizeof(buffer));
1975 p = strrchr(buffer, ']');
1976 if (!p || p[1] != '\0' || (p == buffer)) {
1977 cf_log_err(ci, "Invalid server reference in \"%s\".", modrefname);
1982 cs = cf_section_sub_find_name2(NULL, "server", buffer);
1984 cf_log_err(ci, "No such server \"%s\".", buffer);
1988 return do_compile_modserver(parent, component, ci,
1989 modrefname, cs, buffer);
1993 cf_log_err(ci, "Failed to find \"%s\" in the \"modules\" section.", modrefname);
1998 * We know it's all OK, allocate the structures, and fill
2001 single = rad_malloc(sizeof(*single));
2002 memset(single, 0, sizeof(*single));
2003 csingle = mod_singletocallable(single);
2004 csingle->parent = parent;
2005 csingle->next = NULL;
2006 if (!parent || (component != RLM_COMPONENT_AUTH)) {
2007 memcpy(csingle->actions, defaultactions[component][grouptype],
2008 sizeof csingle->actions);
2009 } else { /* inside Auth-Type has different rules */
2010 memcpy(csingle->actions, defaultactions[RLM_COMPONENT_AUTZ][grouptype],
2011 sizeof csingle->actions);
2013 rad_assert(modrefname != NULL);
2014 csingle->name = modrefname;
2015 csingle->type = MOD_SINGLE;
2016 csingle->method = component;
2019 * Singles can override the actions, virtual modules cannot.
2021 * FIXME: We may want to re-visit how to do this...
2022 * maybe a csingle as a ref?
2024 if (cf_item_is_section(ci)) {
2027 cs = cf_itemtosection(ci);
2028 for (csi=cf_item_find_next(cs, NULL);
2030 csi=cf_item_find_next(cs, csi)) {
2032 if (cf_item_is_section(csi)) {
2033 cf_log_err(csi, "Subsection of module instance call not allowed");
2034 modcallable_free(&csingle);
2038 if (!cf_item_is_pair(csi)) continue;
2040 if (!compile_action(csingle, cf_itemtopair(csi))) {
2041 modcallable_free(&csingle);
2048 * Bail out if the module in question does not supply the
2051 if (!this->entry->module->methods[component]) {
2052 cf_log_err(ci, "\"%s\" modules aren't allowed in '%s' sections -- they have no such method.", this->entry->module->name,
2053 comp2str[component]);
2054 modcallable_free(&csingle);
2058 single->modinst = this;
2059 *modname = this->entry->module->name;
2063 modcallable *compile_modsingle(modcallable *parent,
2064 int component, CONF_ITEM *ci,
2065 const char **modname)
2067 modcallable *ret = do_compile_modsingle(parent, component, ci,
2070 dump_tree(component, ret);
2076 * Internal compile group code.
2078 static modcallable *do_compile_modgroup(modcallable *parent,
2079 int component, CONF_SECTION *cs,
2080 int grouptype, int parentgrouptype)
2087 g = rad_malloc(sizeof(*g));
2088 memset(g, 0, sizeof(*g));
2089 g->grouptype = grouptype;
2091 c = mod_grouptocallable(g);
2093 c->type = MOD_GROUP;
2095 memset(c->actions, 0, sizeof(c->actions));
2098 * Remember the name for printing, etc.
2100 * FIXME: We may also want to put the names into a
2101 * rbtree, so that groups can reference each other...
2103 c->name = cf_section_name2(cs);
2105 c->name = cf_section_name1(cs);
2106 if (strcmp(c->name, "group") == 0) {
2109 c->type = MOD_POLICY;
2115 * Loop over the children of this group.
2117 for (ci=cf_item_find_next(cs, NULL);
2119 ci=cf_item_find_next(cs, ci)) {
2122 * Sections are references to other groups, or
2123 * to modules with updated return codes.
2125 if (cf_item_is_section(ci)) {
2126 const char *junk = NULL;
2127 modcallable *single;
2128 CONF_SECTION *subcs = cf_itemtosection(ci);
2130 single = do_compile_modsingle(c, component, ci,
2133 cf_log_err(ci, "Failed to parse \"%s\" subsection.",
2134 cf_section_name1(subcs));
2135 modcallable_free(&c);
2138 add_child(g, single);
2140 } else if (!cf_item_is_pair(ci)) { /* CONF_DATA */
2144 const char *attr, *value;
2145 CONF_PAIR *cp = cf_itemtopair(ci);
2147 attr = cf_pair_attr(cp);
2148 value = cf_pair_value(cp);
2151 * A CONF_PAIR is either a module
2152 * instance with no actions
2156 modcallable *single;
2157 const char *junk = NULL;
2159 single = do_compile_modsingle(c,
2166 "Failed to parse \"%s\" entry.",
2168 modcallable_free(&c);
2171 add_child(g, single);
2174 * Or a module instance with action.
2176 } else if (!compile_action(c, cp)) {
2177 modcallable_free(&c);
2179 } /* else it worked */
2184 * Set the default actions, if they haven't already been
2187 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
2188 if (!c->actions[i]) {
2189 if (!parent || (component != RLM_COMPONENT_AUTH)) {
2190 c->actions[i] = defaultactions[component][parentgrouptype][i];
2191 } else { /* inside Auth-Type has different rules */
2192 c->actions[i] = defaultactions[RLM_COMPONENT_AUTZ][parentgrouptype][i];
2198 * FIXME: If there are no children, return NULL?
2200 return mod_grouptocallable(g);
2203 modcallable *compile_modgroup(modcallable *parent,
2204 int component, CONF_SECTION *cs)
2206 modcallable *ret = do_compile_modgroup(parent, component, cs,
2209 dump_tree(component, ret);
2213 void add_to_modcallable(modcallable **parent, modcallable *this,
2214 int component, const char *name)
2218 rad_assert(this != NULL);
2220 if (*parent == NULL) {
2223 g = rad_malloc(sizeof *g);
2224 memset(g, 0, sizeof(*g));
2225 g->grouptype = GROUPTYPE_SIMPLE;
2226 c = mod_grouptocallable(g);
2229 defaultactions[component][GROUPTYPE_SIMPLE],
2230 sizeof(c->actions));
2231 rad_assert(name != NULL);
2233 c->type = MOD_GROUP;
2234 c->method = component;
2237 *parent = mod_grouptocallable(g);
2239 g = mod_callabletogroup(*parent);
2245 void modcallable_free(modcallable **pc)
2247 modcallable *c, *loop, *next;
2249 if (!pc || !*pc) return;
2253 if ((c->type > MOD_SINGLE) && (c->type <= MOD_POLICY)) {
2254 modgroup *g = mod_callabletogroup(c);
2256 if (g->children) for (loop = g->children;
2260 modcallable_free(&loop);