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>
32 /* mutually-recursive static functions need a prototype up front */
33 static modcallable *do_compile_modgroup(modcallable *,
37 /* Actions may be a positive integer (the highest one returned in the group
38 * will be returned), or the keyword "return", represented here by
39 * MOD_ACTION_RETURN, to cause an immediate return.
40 * There's also the keyword "reject", represented here by MOD_ACTION_REJECT
41 * to cause an immediate reject. */
42 #define MOD_ACTION_RETURN (-1)
43 #define MOD_ACTION_REJECT (-2)
45 /* Here are our basic types: modcallable, modgroup, and modsingle. For an
46 * explanation of what they are all about, see ../../doc/README.failover */
49 struct modcallable *next;
51 enum { MOD_SINGLE = 1, MOD_GROUP, MOD_LOAD_BALANCE, MOD_REDUNDANT_LOAD_BALANCE,
53 MOD_IF, MOD_ELSE, MOD_ELSIF, MOD_UPDATE, MOD_SWITCH, MOD_CASE,
55 MOD_POLICY, MOD_REFERENCE, MOD_XLAT } type;
57 int actions[RLM_MODULE_NUMCODES];
60 #define GROUPTYPE_SIMPLE 0
61 #define GROUPTYPE_REDUNDANT 1
62 #define GROUPTYPE_APPEND 2
63 #define GROUPTYPE_COUNT 3
66 modcallable mc; /* self */
67 int grouptype; /* after mc */
68 modcallable *children;
75 module_instance_t *modinst;
90 static const FR_NAME_NUMBER grouptype_table[] = {
91 { "", GROUPTYPE_SIMPLE },
92 { "redundant ", GROUPTYPE_REDUNDANT },
93 { "append ", GROUPTYPE_APPEND },
97 /* Simple conversions: modsingle and modgroup are subclasses of modcallable,
98 * so we often want to go back and forth between them. */
99 static modsingle *mod_callabletosingle(modcallable *p)
101 rad_assert(p->type==MOD_SINGLE);
102 return (modsingle *)p;
104 static modgroup *mod_callabletogroup(modcallable *p)
106 rad_assert((p->type > MOD_SINGLE) && (p->type <= MOD_POLICY));
108 return (modgroup *)p;
110 static modcallable *mod_singletocallable(modsingle *p)
112 return (modcallable *)p;
114 static modcallable *mod_grouptocallable(modgroup *p)
116 return (modcallable *)p;
119 static modref *mod_callabletoref(modcallable *p)
121 rad_assert(p->type==MOD_REFERENCE);
124 static modcallable *mod_reftocallable(modref *p)
126 return (modcallable *)p;
129 static modxlat *mod_callabletoxlat(modcallable *p)
131 rad_assert(p->type==MOD_XLAT);
134 static modcallable *mod_xlattocallable(modxlat *p)
136 return (modcallable *)p;
139 /* modgroups are grown by adding a modcallable to the end */
140 /* FIXME: This is O(N^2) */
141 static void add_child(modgroup *g, modcallable *c)
143 modcallable **head = &g->children;
144 modcallable *node = *head;
145 modcallable **last = head;
154 rad_assert(c->next == NULL);
156 c->parent = mod_grouptocallable(g);
159 /* Here's where we recognize all of our keywords: first the rcodes, then the
161 static const FR_NAME_NUMBER rcode_table[] = {
162 { "reject", RLM_MODULE_REJECT },
163 { "fail", RLM_MODULE_FAIL },
164 { "ok", RLM_MODULE_OK },
165 { "handled", RLM_MODULE_HANDLED },
166 { "invalid", RLM_MODULE_INVALID },
167 { "userlock", RLM_MODULE_USERLOCK },
168 { "notfound", RLM_MODULE_NOTFOUND },
169 { "noop", RLM_MODULE_NOOP },
170 { "updated", RLM_MODULE_UPDATED },
176 * Compile action && rcode for later use.
178 static int compile_action(modcallable *c, CONF_PAIR *cp)
181 const char *attr, *value;
183 attr = cf_pair_attr(cp);
184 value = cf_pair_value(cp);
185 if (!value) return 0;
187 if (!strcasecmp(value, "return"))
188 action = MOD_ACTION_RETURN;
190 else if (!strcasecmp(value, "break"))
191 action = MOD_ACTION_RETURN;
193 else if (!strcasecmp(value, "reject"))
194 action = MOD_ACTION_REJECT;
196 else if (strspn(value, "0123456789")==strlen(value)) {
197 action = atoi(value);
200 * Don't allow priority zero, for future use.
202 if (action == 0) return 0;
204 cf_log_err(cf_pairtoitem(cp), "Unknown action '%s'.\n",
209 if (strcasecmp(attr, "default") != 0) {
212 rcode = fr_str2int(rcode_table, attr, -1);
214 cf_log_err(cf_pairtoitem(cp),
215 "Unknown module rcode '%s'.\n",
219 c->actions[rcode] = action;
221 } else { /* set all unset values to the default */
224 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
225 if (!c->actions[i]) c->actions[i] = action;
232 /* Some short names for debugging output */
233 static const char * const comp2str[] = {
249 #ifdef HAVE_PTHREAD_H
251 * Lock the mutex for the module
253 static void safe_lock(module_instance_t *instance)
256 pthread_mutex_lock(instance->mutex);
260 * Unlock the mutex for the module
262 static void safe_unlock(module_instance_t *instance)
265 pthread_mutex_unlock(instance->mutex);
269 * No threads: these functions become NULL's.
271 #define safe_lock(foo)
272 #define safe_unlock(foo)
275 static int call_modsingle(int component, modsingle *sp, REQUEST *request)
279 rad_assert(request != NULL);
281 RDEBUG3(" modsingle[%s]: calling %s (%s) for request %d",
282 comp2str[component], sp->modinst->name,
283 sp->modinst->entry->name, request->number);
285 if (sp->modinst->dead) {
286 myresult = RLM_MODULE_FAIL;
290 safe_lock(sp->modinst);
293 * For logging unresponsive children.
295 request->module = sp->modinst->name;
297 myresult = sp->modinst->entry->module->methods[component](
298 sp->modinst->insthandle, request);
300 request->module = "";
301 safe_unlock(sp->modinst);
304 RDEBUG3(" modsingle[%s]: returned from %s (%s) for request %d",
305 comp2str[component], sp->modinst->name,
306 sp->modinst->entry->name, request->number);
312 static int default_component_results[RLM_COMPONENT_COUNT] = {
313 RLM_MODULE_REJECT, /* AUTH */
314 RLM_MODULE_NOTFOUND, /* AUTZ */
315 RLM_MODULE_NOOP, /* PREACCT */
316 RLM_MODULE_NOOP, /* ACCT */
317 RLM_MODULE_FAIL, /* SESS */
318 RLM_MODULE_NOOP, /* PRE_PROXY */
319 RLM_MODULE_NOOP, /* POST_PROXY */
320 RLM_MODULE_NOOP /* POST_AUTH */
323 RLM_MODULE_NOOP, /* RECV_COA_TYPE */
324 RLM_MODULE_NOOP /* SEND_COA_TYPE */
329 static const char *group_name[] = {
333 "load-balance group",
334 "redundant-load-balance group",
346 static const char *modcall_spaces = "++++++++++++++++++++++++++++++++";
348 #define MODCALL_STACK_MAX (32)
351 * Don't call the modules recursively. Instead, do them
352 * iteratively, and manage the call stack ourselves.
354 typedef struct modcall_stack {
357 int priority[MODCALL_STACK_MAX];
358 int result[MODCALL_STACK_MAX];
359 modcallable *children[MODCALL_STACK_MAX];
360 modcallable *start[MODCALL_STACK_MAX];
365 * Call a module, iteratively, with a local stack, rather than
366 * recursively. What did Paul Graham say about Lisp...?
368 int modcall(int component, modcallable *c, REQUEST *request)
372 modcallable *parent, *child;
374 int if_taken, was_if;
376 if ((component < 0) || (component >= RLM_COMPONENT_COUNT)) {
377 return RLM_MODULE_FAIL;
381 stack.priority[0] = 0;
382 stack.children[0] = c;
383 stack.start[0] = NULL;
384 myresult = stack.result[0] = default_component_results[component];
385 was_if = if_taken = FALSE;
389 * A module has taken too long to process the request,
390 * and we've been told to stop processing it.
392 if ((request->master_state == REQUEST_STOP_PROCESSING) ||
394 (request->parent->master_state == REQUEST_STOP_PROCESSING))) {
395 myresult = RLM_MODULE_FAIL;
399 child = stack.children[stack.pointer];
401 myresult = stack.result[stack.pointer];
404 parent = child->parent;
407 if ((child->type == MOD_ELSE) || (child->type == MOD_ELSIF)) {
408 myresult = stack.result[stack.pointer];
410 if (!was_if) { /* error */
411 RDEBUG2("%.*s ... skipping %s for request %d: No preceding \"if\"",
412 stack.pointer + 1, modcall_spaces,
413 group_name[child->type],
418 RDEBUG2("%.*s ... skipping %s for request %d: Preceding \"if\" was taken",
419 stack.pointer + 1, modcall_spaces,
420 group_name[child->type],
427 * "if" or "elsif". Evaluate the condition.
429 if ((child->type == MOD_IF) || (child->type == MOD_ELSIF)) {
430 int condition = TRUE;
431 const char *p = child->name;
433 RDEBUG2("%.*s? %s %s",
434 stack.pointer + 1, modcall_spaces,
435 (child->type == MOD_IF) ? "if" : "elsif",
438 if (radius_evaluate_condition(request, myresult,
439 0, &p, TRUE, &condition)) {
440 RDEBUG2("%.*s? %s %s -> %s",
441 stack.pointer + 1, modcall_spaces,
442 (child->type == MOD_IF) ? "if" : "elsif",
443 child->name, (condition != FALSE) ? "TRUE" : "FALSE");
446 * This should never happen, the
447 * condition is checked when the
448 * module section is loaded.
454 stack.result[stack.pointer] = myresult;
455 stack.children[stack.pointer] = NULL;
459 } /* else process it as a simple group */
462 if (child->type == MOD_UPDATE) {
464 modgroup *g = mod_callabletogroup(child);
466 rcode = radius_update_attrlist(request, g->cs,
467 g->vps, child->name);
468 if (rcode != RLM_MODULE_UPDATED) {
472 * FIXME: Set priority based on
473 * previous priority, so that we
474 * don't stop on reject when the
475 * default priority was to
484 if (child->type == MOD_REFERENCE) {
485 modref *mr = mod_callabletoref(child);
486 const char *server = request->server;
488 if (server == mr->ref_name) {
489 RDEBUG("WARNING: Suppressing recursive call to server %s", server);
490 myresult = RLM_MODULE_NOOP;
494 request->server = mr->ref_name;
495 RDEBUG("server %s { # nested call", mr->ref_name);
496 myresult = indexed_modcall(component, 0, request);
497 RDEBUG("} # server %s with nested call", mr->ref_name);
498 request->server = server;
502 if (child->type == MOD_XLAT) {
503 modxlat *mx = mod_callabletoxlat(child);
507 radius_xlat(buffer, sizeof(buffer),
508 mx->xlat_name, request, NULL);
510 RDEBUG("`%s`", mx->xlat_name);
511 radius_exec_program(mx->xlat_name, request,
513 request->packet->vps,
521 * Child is a group that has children of it's own.
523 if (child->type != MOD_SINGLE) {
527 modcallable *null_case;
529 modgroup *g = mod_callabletogroup(child);
534 * Catastrophic error. This SHOULD have
535 * been caught when we were reading in the
540 if (stack.pointer >= MODCALL_STACK_MAX) {
541 radlog(L_ERR, "Internal sanity check failed: module stack is too deep");
545 stack.priority[stack.pointer] = 0;
546 stack.result[stack.pointer] = default_component_results[component];
547 switch (child->type) {
557 case MOD_POLICY: /* same as MOD_GROUP */
558 stack.children[stack.pointer] = g->children;
562 * See the "camel book" for why
565 * If (rand(0..n) < 1), pick the
566 * current realm. We add a scale
567 * factor of 65536, to avoid
570 case MOD_LOAD_BALANCE:
571 case MOD_REDUNDANT_LOAD_BALANCE:
573 for(p = g->children; p; p = p->next) {
582 if ((count * (fr_rand() & 0xffff)) < (uint32_t) 0x10000) {
586 stack.children[stack.pointer] = q;
591 if (!strchr(child->name, '%')) {
592 VALUE_PAIR *vp = NULL;
594 radius_get_vp(request, child->name,
597 vp_prints_value(buffer,
604 radius_xlat(buffer, sizeof(buffer),
605 child->name, request, NULL);
607 null_case = q = NULL;
608 for(p = g->children; p; p = p->next) {
610 if (!null_case) null_case = p;
613 if (strcmp(buffer, p->name) == 0) {
619 if (!q) q = null_case;
621 stack.children[stack.pointer] = q;
626 RDEBUG2("Internal sanity check failed in modcall %d", child->type);
627 exit(1); /* internal sanity check failure */
632 stack.start[stack.pointer] = stack.children[stack.pointer];
634 RDEBUG2("%.*s- entering %s %s {...}",
635 stack.pointer, modcall_spaces,
636 group_name[child->type],
637 child->name ? child->name : "");
640 * Catch the special case of a NULL group.
642 if (!stack.children[stack.pointer]) {
644 * Print message for NULL group
646 RDEBUG2("%.*s- %s %s returns %s",
647 stack.pointer + 1, modcall_spaces,
648 group_name[child->type],
649 child->name ? child->name : "",
650 fr_int2str(rcode_table,
651 stack.result[stack.pointer],
657 * The child may be a group, so we want to
658 * recurse into it's children, rather than
659 * falling through to the code below.
665 * Process a stand-alone child, and fall through
666 * to dealing with it's parent.
668 sp = mod_callabletosingle(child);
670 myresult = call_modsingle(child->method, sp, request);
672 RDEBUG2("%.*s[%s] returns %s",
673 stack.pointer + 1, modcall_spaces,
674 child->name ? child->name : "",
675 fr_int2str(rcode_table, myresult, "??"));
678 * This is a bit of a hack...
680 if (component != RLM_COMPONENT_SESS) request->simul_max = myresult;
683 * FIXME: Allow modules to push a modcallable
684 * onto this stack. This should simplify
685 * configuration a LOT!
687 * Once we do that, we can't do load-time
688 * checking of the maximum stack depth, and we've
689 * got to cache the stack pointer before storing
692 * Also, if the stack changed, we need to set
693 * children[ptr] to NULL, and process the next
694 * entry on the stack, rather than falling
695 * through to finalize the processing of this
698 * Don't put "myresult" on the stack here,
699 * we have to do so with priority.
703 * We roll back up the stack at this point.
707 * The child's action says return. Do so.
709 if (child->actions[myresult] == MOD_ACTION_RETURN) {
710 stack.result[stack.pointer] = myresult;
711 stack.children[stack.pointer] = NULL;
716 * If "reject", break out of the loop and return
719 if (child->actions[myresult] == MOD_ACTION_REJECT) {
720 stack.children[stack.pointer] = NULL;
721 stack.result[stack.pointer] = RLM_MODULE_REJECT;
726 * Otherwise, the action is a number, the
727 * preference level of this return code. If no
728 * higher preference has been seen yet, remember
731 if (child->actions[myresult] >= stack.priority[stack.pointer]) {
732 stack.result[stack.pointer] = myresult;
733 stack.priority[stack.pointer] = child->actions[myresult];
741 * No parent, we must be done.
744 rad_assert(stack.pointer == 0);
745 myresult = stack.result[0];
749 rad_assert(child != NULL);
752 * Go to the "next" child, whatever that is.
754 switch (parent->type) {
762 case MOD_POLICY: /* same as MOD_GROUP */
763 stack.children[stack.pointer] = child->next;
769 case MOD_LOAD_BALANCE:
770 stack.children[stack.pointer] = NULL;
773 case MOD_REDUNDANT_LOAD_BALANCE:
775 stack.children[stack.pointer] = child->next;
777 modgroup *g = mod_callabletogroup(parent);
779 stack.children[stack.pointer] = g->children;
781 if (stack.children[stack.pointer] == stack.start[stack.pointer]) {
782 stack.children[stack.pointer] = NULL;
786 RDEBUG2("Internal sanity check failed in modcall next %d", child->type);
791 * No child, we're done this group, and we return
792 * "myresult" to the caller by pushing it back up
795 if (!stack.children[stack.pointer]) {
797 rad_assert(stack.pointer > 0);
798 myresult = stack.result[stack.pointer];
801 if (stack.pointer == 0) break;
803 RDEBUG2("%.*s- %s %s returns %s",
804 stack.pointer + 1, modcall_spaces,
805 group_name[parent->type],
806 parent->name ? parent->name : "",
807 fr_int2str(rcode_table, myresult, "??"));
810 if ((parent->type == MOD_IF) ||
811 (parent->type == MOD_ELSIF)) {
812 if_taken = was_if = TRUE;
814 if_taken = was_if = FALSE;
821 child = stack.children[stack.pointer];
822 parent = child->parent;
826 } /* loop until done */
833 static const char *action2str(int action)
836 if(action==MOD_ACTION_RETURN)
838 if(action==MOD_ACTION_REJECT)
840 snprintf(buf, sizeof buf, "%d", action);
844 /* If you suspect a bug in the parser, you'll want to use these dump
845 * functions. dump_tree should reproduce a whole tree exactly as it was found
846 * in radiusd.conf, but in long form (all actions explicitly defined) */
847 static void dump_mc(modcallable *c, int indent)
851 if(c->type==MOD_SINGLE) {
852 modsingle *single = mod_callabletosingle(c);
853 RDEBUG("%.*s%s {", indent, "\t\t\t\t\t\t\t\t\t\t\t",
854 single->modinst->name);
856 modgroup *g = mod_callabletogroup(c);
858 RDEBUG("%.*s%s {", indent, "\t\t\t\t\t\t\t\t\t\t\t",
859 group_name[c->type]);
860 for(p = g->children;p;p = p->next)
861 dump_mc(p, indent+1);
864 for(i = 0; i<RLM_MODULE_NUMCODES; ++i) {
865 RDEBUG("%.*s%s = %s", indent+1, "\t\t\t\t\t\t\t\t\t\t\t",
866 fr_int2str(rcode_table, i, "??"),
867 action2str(c->actions[i]));
870 RDEBUG("%.*s}", indent, "\t\t\t\t\t\t\t\t\t\t\t");
873 static void dump_tree(int comp, modcallable *c)
875 RDEBUG("[%s]", comp2str[comp]);
879 #define dump_tree(a, b)
882 /* These are the default actions. For each component, the group{} block
883 * behaves like the code from the old module_*() function. redundant{} and
884 * append{} are based on my guesses of what they will be used for. --Pac. */
886 defaultactions[RLM_COMPONENT_COUNT][GROUPTYPE_COUNT][RLM_MODULE_NUMCODES] =
892 MOD_ACTION_RETURN, /* reject */
894 MOD_ACTION_RETURN, /* ok */
895 MOD_ACTION_RETURN, /* handled */
897 MOD_ACTION_RETURN, /* userlock */
898 MOD_ACTION_RETURN, /* notfound */
904 MOD_ACTION_RETURN, /* reject */
906 MOD_ACTION_RETURN, /* ok */
907 MOD_ACTION_RETURN, /* handled */
908 MOD_ACTION_RETURN, /* invalid */
909 MOD_ACTION_RETURN, /* userlock */
910 MOD_ACTION_RETURN, /* notfound */
911 MOD_ACTION_RETURN, /* noop */
912 MOD_ACTION_RETURN /* updated */
916 MOD_ACTION_RETURN, /* reject */
918 MOD_ACTION_RETURN, /* ok */
919 MOD_ACTION_RETURN, /* handled */
920 MOD_ACTION_RETURN, /* invalid */
921 MOD_ACTION_RETURN, /* userlock */
923 MOD_ACTION_RETURN, /* noop */
924 MOD_ACTION_RETURN /* updated */
931 MOD_ACTION_RETURN, /* reject */
932 MOD_ACTION_RETURN, /* fail */
934 MOD_ACTION_RETURN, /* handled */
935 MOD_ACTION_RETURN, /* invalid */
936 MOD_ACTION_RETURN, /* userlock */
943 MOD_ACTION_RETURN, /* reject */
945 MOD_ACTION_RETURN, /* ok */
946 MOD_ACTION_RETURN, /* handled */
947 MOD_ACTION_RETURN, /* invalid */
948 MOD_ACTION_RETURN, /* userlock */
949 MOD_ACTION_RETURN, /* notfound */
950 MOD_ACTION_RETURN, /* noop */
951 MOD_ACTION_RETURN /* updated */
955 MOD_ACTION_RETURN, /* reject */
957 MOD_ACTION_RETURN, /* ok */
958 MOD_ACTION_RETURN, /* handled */
959 MOD_ACTION_RETURN, /* invalid */
960 MOD_ACTION_RETURN, /* userlock */
962 MOD_ACTION_RETURN, /* noop */
963 MOD_ACTION_RETURN /* updated */
970 MOD_ACTION_RETURN, /* reject */
971 MOD_ACTION_RETURN, /* fail */
973 MOD_ACTION_RETURN, /* handled */
974 MOD_ACTION_RETURN, /* invalid */
975 MOD_ACTION_RETURN, /* userlock */
976 MOD_ACTION_RETURN, /* notfound */
982 MOD_ACTION_RETURN, /* reject */
984 MOD_ACTION_RETURN, /* ok */
985 MOD_ACTION_RETURN, /* handled */
986 MOD_ACTION_RETURN, /* invalid */
987 MOD_ACTION_RETURN, /* userlock */
988 MOD_ACTION_RETURN, /* notfound */
989 MOD_ACTION_RETURN, /* noop */
990 MOD_ACTION_RETURN /* updated */
994 MOD_ACTION_RETURN, /* reject */
996 MOD_ACTION_RETURN, /* ok */
997 MOD_ACTION_RETURN, /* handled */
998 MOD_ACTION_RETURN, /* invalid */
999 MOD_ACTION_RETURN, /* userlock */
1001 MOD_ACTION_RETURN, /* noop */
1002 MOD_ACTION_RETURN /* updated */
1009 MOD_ACTION_RETURN, /* reject */
1010 MOD_ACTION_RETURN, /* fail */
1012 MOD_ACTION_RETURN, /* handled */
1013 MOD_ACTION_RETURN, /* invalid */
1014 MOD_ACTION_RETURN, /* userlock */
1015 MOD_ACTION_RETURN, /* notfound */
1023 MOD_ACTION_RETURN, /* ok */
1024 MOD_ACTION_RETURN, /* handled */
1033 MOD_ACTION_RETURN, /* reject */
1035 MOD_ACTION_RETURN, /* ok */
1036 MOD_ACTION_RETURN, /* handled */
1037 MOD_ACTION_RETURN, /* invalid */
1038 MOD_ACTION_RETURN, /* userlock */
1040 MOD_ACTION_RETURN, /* noop */
1041 MOD_ACTION_RETURN /* updated */
1048 MOD_ACTION_RETURN, /* reject */
1050 MOD_ACTION_RETURN, /* ok */
1051 MOD_ACTION_RETURN, /* handled */
1052 MOD_ACTION_RETURN, /* invalid */
1053 MOD_ACTION_RETURN, /* userlock */
1054 MOD_ACTION_RETURN, /* notfound */
1055 MOD_ACTION_RETURN, /* noop */
1056 MOD_ACTION_RETURN /* updated */
1060 MOD_ACTION_RETURN, /* reject */
1062 MOD_ACTION_RETURN, /* ok */
1063 MOD_ACTION_RETURN, /* handled */
1064 MOD_ACTION_RETURN, /* invalid */
1065 MOD_ACTION_RETURN, /* userlock */
1066 MOD_ACTION_RETURN, /* notfound */
1067 MOD_ACTION_RETURN, /* noop */
1068 MOD_ACTION_RETURN /* updated */
1072 MOD_ACTION_RETURN, /* reject */
1074 MOD_ACTION_RETURN, /* ok */
1075 MOD_ACTION_RETURN, /* handled */
1076 MOD_ACTION_RETURN, /* invalid */
1077 MOD_ACTION_RETURN, /* userlock */
1078 MOD_ACTION_RETURN, /* notfound */
1079 MOD_ACTION_RETURN, /* noop */
1080 MOD_ACTION_RETURN /* updated */
1087 MOD_ACTION_RETURN, /* reject */
1088 MOD_ACTION_RETURN, /* fail */
1090 MOD_ACTION_RETURN, /* handled */
1091 MOD_ACTION_RETURN, /* invalid */
1092 MOD_ACTION_RETURN, /* userlock */
1099 MOD_ACTION_RETURN, /* reject */
1101 MOD_ACTION_RETURN, /* ok */
1102 MOD_ACTION_RETURN, /* handled */
1103 MOD_ACTION_RETURN, /* invalid */
1104 MOD_ACTION_RETURN, /* userlock */
1105 MOD_ACTION_RETURN, /* notfound */
1106 MOD_ACTION_RETURN, /* noop */
1107 MOD_ACTION_RETURN /* updated */
1111 MOD_ACTION_RETURN, /* reject */
1113 MOD_ACTION_RETURN, /* ok */
1114 MOD_ACTION_RETURN, /* handled */
1115 MOD_ACTION_RETURN, /* invalid */
1116 MOD_ACTION_RETURN, /* userlock */
1118 MOD_ACTION_RETURN, /* noop */
1119 MOD_ACTION_RETURN /* updated */
1126 MOD_ACTION_RETURN, /* reject */
1127 MOD_ACTION_RETURN, /* fail */
1129 MOD_ACTION_RETURN, /* handled */
1130 MOD_ACTION_RETURN, /* invalid */
1131 MOD_ACTION_RETURN, /* userlock */
1138 MOD_ACTION_RETURN, /* reject */
1140 MOD_ACTION_RETURN, /* ok */
1141 MOD_ACTION_RETURN, /* handled */
1142 MOD_ACTION_RETURN, /* invalid */
1143 MOD_ACTION_RETURN, /* userlock */
1144 MOD_ACTION_RETURN, /* notfound */
1145 MOD_ACTION_RETURN, /* noop */
1146 MOD_ACTION_RETURN /* updated */
1150 MOD_ACTION_RETURN, /* reject */
1152 MOD_ACTION_RETURN, /* ok */
1153 MOD_ACTION_RETURN, /* handled */
1154 MOD_ACTION_RETURN, /* invalid */
1155 MOD_ACTION_RETURN, /* userlock */
1157 MOD_ACTION_RETURN, /* noop */
1158 MOD_ACTION_RETURN /* updated */
1165 MOD_ACTION_RETURN, /* reject */
1166 MOD_ACTION_RETURN, /* fail */
1168 MOD_ACTION_RETURN, /* handled */
1169 MOD_ACTION_RETURN, /* invalid */
1170 MOD_ACTION_RETURN, /* userlock */
1177 MOD_ACTION_RETURN, /* reject */
1179 MOD_ACTION_RETURN, /* ok */
1180 MOD_ACTION_RETURN, /* handled */
1181 MOD_ACTION_RETURN, /* invalid */
1182 MOD_ACTION_RETURN, /* userlock */
1183 MOD_ACTION_RETURN, /* notfound */
1184 MOD_ACTION_RETURN, /* noop */
1185 MOD_ACTION_RETURN /* updated */
1189 MOD_ACTION_RETURN, /* reject */
1191 MOD_ACTION_RETURN, /* ok */
1192 MOD_ACTION_RETURN, /* handled */
1193 MOD_ACTION_RETURN, /* invalid */
1194 MOD_ACTION_RETURN, /* userlock */
1196 MOD_ACTION_RETURN, /* noop */
1197 MOD_ACTION_RETURN /* updated */
1206 MOD_ACTION_RETURN, /* reject */
1207 MOD_ACTION_RETURN, /* fail */
1209 MOD_ACTION_RETURN, /* handled */
1210 MOD_ACTION_RETURN, /* invalid */
1211 MOD_ACTION_RETURN, /* userlock */
1218 MOD_ACTION_RETURN, /* reject */
1220 MOD_ACTION_RETURN, /* ok */
1221 MOD_ACTION_RETURN, /* handled */
1222 MOD_ACTION_RETURN, /* invalid */
1223 MOD_ACTION_RETURN, /* userlock */
1224 MOD_ACTION_RETURN, /* notfound */
1225 MOD_ACTION_RETURN, /* noop */
1226 MOD_ACTION_RETURN /* updated */
1230 MOD_ACTION_RETURN, /* reject */
1232 MOD_ACTION_RETURN, /* ok */
1233 MOD_ACTION_RETURN, /* handled */
1234 MOD_ACTION_RETURN, /* invalid */
1235 MOD_ACTION_RETURN, /* userlock */
1237 MOD_ACTION_RETURN, /* noop */
1238 MOD_ACTION_RETURN /* updated */
1245 MOD_ACTION_RETURN, /* reject */
1246 MOD_ACTION_RETURN, /* fail */
1248 MOD_ACTION_RETURN, /* handled */
1249 MOD_ACTION_RETURN, /* invalid */
1250 MOD_ACTION_RETURN, /* userlock */
1257 MOD_ACTION_RETURN, /* reject */
1259 MOD_ACTION_RETURN, /* ok */
1260 MOD_ACTION_RETURN, /* handled */
1261 MOD_ACTION_RETURN, /* invalid */
1262 MOD_ACTION_RETURN, /* userlock */
1263 MOD_ACTION_RETURN, /* notfound */
1264 MOD_ACTION_RETURN, /* noop */
1265 MOD_ACTION_RETURN /* updated */
1269 MOD_ACTION_RETURN, /* reject */
1271 MOD_ACTION_RETURN, /* ok */
1272 MOD_ACTION_RETURN, /* handled */
1273 MOD_ACTION_RETURN, /* invalid */
1274 MOD_ACTION_RETURN, /* userlock */
1276 MOD_ACTION_RETURN, /* noop */
1277 MOD_ACTION_RETURN /* updated */
1285 static modcallable *do_compile_modupdate(modcallable *parent,
1286 int component, CONF_SECTION *cs,
1290 const char *vp_name;
1292 modcallable *csingle;
1294 VALUE_PAIR *head, **tail;
1296 static const char *attrlist_names[] = {
1297 "request", "reply", "proxy-request", "proxy-reply",
1298 "config", "control",
1299 "coa", "coa-reply", "disconnect", "disconnect-reply",
1303 component = component; /* -Wunused */
1305 if (!cf_section_name2(cs)) {
1306 cf_log_err(cf_sectiontoitem(cs),
1307 "Require list name for 'update'.\n");
1312 if (strncmp(vp_name, "outer.", 6) == 0) {
1316 for (i = 0; attrlist_names[i] != NULL; i++) {
1317 if (strcmp(vp_name, attrlist_names[i]) == 0) {
1324 cf_log_err(cf_sectiontoitem(cs),
1325 "Unknown attribute list \"%s\"",
1334 * Walk through the children of the update section,
1335 * ensuring that they're all known attributes.
1337 for (ci=cf_item_find_next(cs, NULL);
1339 ci=cf_item_find_next(cs, ci)) {
1343 if (cf_item_is_section(ci)) {
1344 cf_log_err(ci, "\"update\" sections cannot have subsections");
1348 if (!cf_item_is_pair(ci)) continue;
1350 cp = cf_itemtopair(ci); /* can't return NULL */
1351 vp = cf_pairtovp(cp);
1354 cf_log_err(ci, "ERROR: %s", fr_strerror());
1358 if ((vp->operator != T_OP_EQ) &&
1359 (vp->operator != T_OP_CMP_EQ) &&
1360 (vp->operator != T_OP_ADD) &&
1361 (vp->operator != T_OP_SUB) &&
1362 (vp->operator != T_OP_LE) &&
1363 (vp->operator != T_OP_GE) &&
1364 (vp->operator != T_OP_CMP_FALSE) &&
1365 (vp->operator != T_OP_SET)) {
1368 cf_log_err(ci, "Invalid operator for attribute");
1373 * A few more sanity checks. The enforcement of
1374 * <= or >= can only happen for integer
1377 if ((vp->operator == T_OP_LE) ||
1378 (vp->operator == T_OP_GE)) {
1379 if ((vp->type != PW_TYPE_BYTE) &&
1380 (vp->type != PW_TYPE_SHORT) &&
1381 (vp->type != PW_TYPE_INTEGER)) {
1384 cf_log_err(ci, "Enforcment of <= or >= is possible only for integer attributes");
1394 cf_log_err(cf_sectiontoitem(cs),
1395 "ERROR: update %s section cannot be empty",
1400 g = rad_malloc(sizeof(*g)); /* never fails */
1401 memset(g, 0, sizeof(*g));
1402 csingle = mod_grouptocallable(g);
1404 csingle->parent = parent;
1405 csingle->next = NULL;
1406 csingle->name = name2;
1407 csingle->type = MOD_UPDATE;
1408 csingle->method = component;
1410 g->grouptype = GROUPTYPE_SIMPLE;
1419 static modcallable *do_compile_modswitch(modcallable *parent,
1420 int component, CONF_SECTION *cs)
1422 modcallable *csingle;
1424 int had_seen_default = FALSE;
1426 component = component; /* -Wunused */
1428 if (!cf_section_name2(cs)) {
1429 cf_log_err(cf_sectiontoitem(cs),
1430 "You must specify a variable to switch over for 'switch'.");
1434 if (!cf_item_find_next(cs, NULL)) {
1435 cf_log_err(cf_sectiontoitem(cs), "'switch' statments cannot be empty.");
1440 * Walk through the children of the switch section,
1441 * ensuring that they're all 'case' statements
1443 for (ci=cf_item_find_next(cs, NULL);
1445 ci=cf_item_find_next(cs, ci)) {
1446 CONF_SECTION *subcs;
1447 const char *name1, *name2;
1449 if (!cf_item_is_section(ci)) {
1450 if (!cf_item_is_pair(ci)) continue;
1452 cf_log_err(ci, "\"switch\" sections can only have \"case\" subsections");
1456 subcs = cf_itemtosection(ci); /* can't return NULL */
1457 name1 = cf_section_name1(subcs);
1459 if (strcmp(name1, "case") != 0) {
1460 cf_log_err(ci, "\"switch\" sections can only have \"case\" subsections");
1464 name2 = cf_section_name2(subcs);
1465 if (!name2 && !had_seen_default) {
1466 had_seen_default = TRUE;
1470 if (!name2 || (name2[0] == '\0')) {
1471 cf_log_err(ci, "\"case\" sections must have a name");
1476 csingle= do_compile_modgroup(parent, component, cs,
1477 GROUPTYPE_SIMPLE, GROUPTYPE_SIMPLE);
1478 if (!csingle) return NULL;
1479 csingle->type = MOD_SWITCH;
1484 static modcallable *do_compile_modserver(modcallable *parent,
1485 int component, CONF_ITEM *ci,
1490 modcallable *csingle;
1491 CONF_SECTION *subcs;
1494 subcs = cf_section_sub_find_name2(cs, comp2str[component], NULL);
1496 cf_log_err(ci, "Server %s has no %s section",
1497 server, comp2str[component]);
1501 mr = rad_malloc(sizeof(*mr));
1502 memset(mr, 0, sizeof(*mr));
1504 csingle = mod_reftocallable(mr);
1505 csingle->parent = parent;
1506 csingle->next = NULL;
1507 csingle->name = name;
1508 csingle->type = MOD_REFERENCE;
1509 csingle->method = component;
1511 memcpy(csingle->actions, defaultactions[component][GROUPTYPE_SIMPLE],
1512 sizeof(csingle->actions));
1514 mr->ref_name = strdup(server);
1520 static modcallable *do_compile_modxlat(modcallable *parent,
1521 int component, const char *fmt)
1523 modcallable *csingle;
1526 mx = rad_malloc(sizeof(*mx));
1527 memset(mx, 0, sizeof(*mx));
1529 csingle = mod_xlattocallable(mx);
1530 csingle->parent = parent;
1531 csingle->next = NULL;
1532 csingle->name = "expand";
1533 csingle->type = MOD_XLAT;
1534 csingle->method = component;
1536 memcpy(csingle->actions, defaultactions[component][GROUPTYPE_SIMPLE],
1537 sizeof(csingle->actions));
1539 mx->xlat_name = strdup(fmt);
1540 if (fmt[0] != '%') {
1544 strcpy(mx->xlat_name, fmt + 1);
1545 p = strrchr(mx->xlat_name, '`');
1553 * redundant, etc. can refer to modules or groups, but not much else.
1555 static int all_children_are_modules(CONF_SECTION *cs, const char *name)
1559 for (ci=cf_item_find_next(cs, NULL);
1561 ci=cf_item_find_next(cs, ci)) {
1563 * If we're a redundant, etc. group, then the
1564 * intention is to call modules, rather than
1565 * processing logic. These checks aren't
1566 * *strictly* necessary, but they keep the users
1567 * from doing crazy things.
1569 if (cf_item_is_section(ci)) {
1570 CONF_SECTION *subcs = cf_itemtosection(ci);
1571 const char *name1 = cf_section_name1(subcs);
1573 if ((strcmp(name1, "if") == 0) ||
1574 (strcmp(name1, "else") == 0) ||
1575 (strcmp(name1, "elsif") == 0) ||
1576 (strcmp(name1, "update") == 0) ||
1577 (strcmp(name1, "switch") == 0) ||
1578 (strcmp(name1, "case") == 0)) {
1579 cf_log_err(ci, "%s sections cannot contain a \"%s\" statement",
1586 if (cf_item_is_pair(ci)) {
1587 CONF_PAIR *cp = cf_itemtopair(ci);
1588 if (cf_pair_value(cp) != NULL) {
1590 "Entry with no value is invalid");
1601 * Compile one entry of a module call.
1603 static modcallable *do_compile_modsingle(modcallable *parent,
1604 int component, CONF_ITEM *ci,
1606 const char **modname)
1611 const char *modrefname;
1613 modcallable *csingle;
1614 module_instance_t *this;
1615 CONF_SECTION *cs, *subcs, *modules;
1617 if (cf_item_is_section(ci)) {
1620 cs = cf_itemtosection(ci);
1621 modrefname = cf_section_name1(cs);
1622 name2 = cf_section_name2(cs);
1623 if (!name2) name2 = "_UnNamedGroup";
1626 * group{}, redundant{}, or append{} may appear
1627 * where a single module instance was expected.
1628 * In that case, we hand it off to
1631 if (strcmp(modrefname, "group") == 0) {
1633 return do_compile_modgroup(parent, component, cs,
1637 } else if (strcmp(modrefname, "redundant") == 0) {
1640 if (!all_children_are_modules(cs, modrefname)) {
1644 return do_compile_modgroup(parent, component, cs,
1645 GROUPTYPE_REDUNDANT,
1648 } else if (strcmp(modrefname, "append") == 0) {
1650 return do_compile_modgroup(parent, component, cs,
1654 } else if (strcmp(modrefname, "load-balance") == 0) {
1657 if (!all_children_are_modules(cs, modrefname)) {
1661 csingle= do_compile_modgroup(parent, component, cs,
1664 if (!csingle) return NULL;
1665 csingle->type = MOD_LOAD_BALANCE;
1668 } else if (strcmp(modrefname, "redundant-load-balance") == 0) {
1671 if (!all_children_are_modules(cs, modrefname)) {
1675 csingle= do_compile_modgroup(parent, component, cs,
1676 GROUPTYPE_REDUNDANT,
1678 if (!csingle) return NULL;
1679 csingle->type = MOD_REDUNDANT_LOAD_BALANCE;
1683 } else if (strcmp(modrefname, "if") == 0) {
1684 if (!cf_section_name2(cs)) {
1685 cf_log_err(ci, "'if' without condition.");
1690 csingle= do_compile_modgroup(parent, component, cs,
1693 if (!csingle) return NULL;
1694 csingle->type = MOD_IF;
1696 if (!radius_evaluate_condition(NULL, 0, 0, modname,
1698 modcallable_free(&csingle);
1705 } else if (strcmp(modrefname, "elsif") == 0) {
1707 ((parent->type == MOD_LOAD_BALANCE) ||
1708 (parent->type == MOD_REDUNDANT_LOAD_BALANCE))) {
1709 cf_log_err(ci, "'elsif' cannot be used in this section section.");
1713 if (!cf_section_name2(cs)) {
1714 cf_log_err(ci, "'elsif' without condition.");
1719 csingle= do_compile_modgroup(parent, component, cs,
1722 if (!csingle) return NULL;
1723 csingle->type = MOD_ELSIF;
1725 if (!radius_evaluate_condition(NULL, 0, 0, modname,
1727 modcallable_free(&csingle);
1734 } else if (strcmp(modrefname, "else") == 0) {
1736 ((parent->type == MOD_LOAD_BALANCE) ||
1737 (parent->type == MOD_REDUNDANT_LOAD_BALANCE))) {
1738 cf_log_err(ci, "'else' cannot be used in this section section.");
1742 if (cf_section_name2(cs)) {
1743 cf_log_err(ci, "Cannot have conditions on 'else'.");
1748 csingle= do_compile_modgroup(parent, component, cs,
1751 if (!csingle) return NULL;
1752 csingle->type = MOD_ELSE;
1755 } else if (strcmp(modrefname, "update") == 0) {
1758 csingle = do_compile_modupdate(parent, component, cs,
1760 if (!csingle) return NULL;
1764 } else if (strcmp(modrefname, "switch") == 0) {
1767 csingle = do_compile_modswitch(parent, component, cs);
1768 if (!csingle) return NULL;
1772 } else if (strcmp(modrefname, "case") == 0) {
1778 * FIXME: How to tell that the parent can only
1779 * be a "switch" statement?
1782 cf_log_err(ci, "\"case\" statements may only appear within a \"switch\" section");
1786 csingle= do_compile_modgroup(parent, component, cs,
1789 if (!csingle) return NULL;
1790 csingle->type = MOD_CASE;
1791 csingle->name = cf_section_name2(cs); /* may be NULL */
1794 * Set all of it's codes to return, so that
1795 * when we pick a 'case' statement, we don't
1796 * fall through to processing the next one.
1798 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
1799 csingle->actions[i] = MOD_ACTION_RETURN;
1804 } /* else it's something like sql { fail = 1 ...} */
1806 } else if (!cf_item_is_pair(ci)) { /* CONF_DATA or some such */
1810 * Else it's a module reference, with updated return
1814 CONF_PAIR *cp = cf_itemtopair(ci);
1815 modrefname = cf_pair_attr(cp);
1818 * Actions (ok = 1), etc. are orthoganal to just
1819 * about everything else.
1821 if (cf_pair_value(cp) != NULL) {
1822 cf_log_err(ci, "Entry is not a reference to a module");
1826 if (((modrefname[0] == '%') && (modrefname[1] == '{')) ||
1827 (modrefname[0] == '`')) {
1828 return do_compile_modxlat(parent, component,
1833 * See if the module is a virtual one. If so,
1834 * return that, rather than doing anything here.
1837 cs = cf_section_find("instantiate");
1838 if (cs) subcs = cf_section_sub_find_name2(cs, NULL,
1841 cs = cf_section_find("policy");
1842 if (cs) subcs = cf_section_sub_find_name2(cs, NULL,
1846 DEBUG2(" Module: Loading virtual module %s",
1850 * redundant foo {} is a single.
1852 if (cf_section_name2(subcs)) {
1853 return do_compile_modsingle(parent,
1855 cf_sectiontoitem(subcs),
1860 * foo {} is a group.
1862 return do_compile_modgroup(parent,
1872 * Not a virtual module. It must be a real module.
1874 modules = cf_section_find("modules");
1877 if (modules && cf_section_sub_find_name2(modules, NULL, modrefname)) {
1878 this = find_module_instance(modules, modrefname, 1);
1886 * Maybe it's module.method
1888 p = strrchr(modrefname, '.');
1889 if (p) for (i = RLM_COMPONENT_AUTH;
1890 i < RLM_COMPONENT_COUNT;
1892 if (strcmp(p + 1, comp2str[i]) == 0) {
1895 strlcpy(buffer, modrefname, sizeof(buffer));
1896 buffer[p - modrefname] = '\0';
1899 this = find_module_instance(cf_section_find("modules"), buffer, 1);
1901 !this->entry->module->methods[i]) {
1903 cf_log_err(ci, "Module %s has no such method %s", buffer, comp2str[i]);
1911 if (strncmp(modrefname, "server[", 7) == 0) {
1914 strlcpy(buffer, modrefname + 7, sizeof(buffer));
1915 p = strrchr(buffer, ']');
1916 if (!p || p[1] != '\0' || (p == buffer)) {
1917 cf_log_err(ci, "Invalid server reference in \"%s\".", modrefname);
1922 cs = cf_section_sub_find_name2(NULL, "server", buffer);
1924 cf_log_err(ci, "No such server \"%s\".", buffer);
1928 return do_compile_modserver(parent, component, ci,
1929 modrefname, cs, buffer);
1933 cf_log_err(ci, "Failed to load module \"%s\".", modrefname);
1938 * We know it's all OK, allocate the structures, and fill
1941 single = rad_malloc(sizeof(*single));
1942 memset(single, 0, sizeof(*single));
1943 csingle = mod_singletocallable(single);
1944 csingle->parent = parent;
1945 csingle->next = NULL;
1946 if (!parent || (component != RLM_COMPONENT_AUTH)) {
1947 memcpy(csingle->actions, defaultactions[component][grouptype],
1948 sizeof csingle->actions);
1949 } else { /* inside Auth-Type has different rules */
1950 memcpy(csingle->actions, defaultactions[RLM_COMPONENT_AUTZ][grouptype],
1951 sizeof csingle->actions);
1953 rad_assert(modrefname != NULL);
1954 csingle->name = modrefname;
1955 csingle->type = MOD_SINGLE;
1956 csingle->method = component;
1959 * Singles can override the actions, virtual modules cannot.
1961 * FIXME: We may want to re-visit how to do this...
1962 * maybe a csingle as a ref?
1964 if (cf_item_is_section(ci)) {
1965 cs = cf_itemtosection(ci);
1967 for (ci=cf_item_find_next(cs, NULL);
1969 ci=cf_item_find_next(cs, ci)) {
1971 if (cf_item_is_section(ci)) {
1972 cf_log_err(ci, "Subsection of module instance call not allowed");
1973 modcallable_free(&csingle);
1977 if (!cf_item_is_pair(ci)) continue;
1979 if (!compile_action(csingle, cf_itemtopair(ci))) {
1980 modcallable_free(&csingle);
1987 * Bail out if the module in question does not supply the
1990 if (!this->entry->module->methods[component]) {
1991 cf_log_err(ci, "\"%s\" modules aren't allowed in '%s' sections -- they have no such method.", this->entry->module->name,
1992 comp2str[component]);
1993 modcallable_free(&csingle);
1997 single->modinst = this;
1998 *modname = this->entry->module->name;
2002 modcallable *compile_modsingle(modcallable *parent,
2003 int component, CONF_ITEM *ci,
2004 const char **modname)
2006 modcallable *ret = do_compile_modsingle(parent, component, ci,
2009 dump_tree(component, ret);
2015 * Internal compile group code.
2017 static modcallable *do_compile_modgroup(modcallable *parent,
2018 int component, CONF_SECTION *cs,
2019 int grouptype, int parentgrouptype)
2026 g = rad_malloc(sizeof(*g));
2027 memset(g, 0, sizeof(*g));
2028 g->grouptype = grouptype;
2030 c = mod_grouptocallable(g);
2032 c->type = MOD_GROUP;
2034 memset(c->actions, 0, sizeof(c->actions));
2037 * Remember the name for printing, etc.
2039 * FIXME: We may also want to put the names into a
2040 * rbtree, so that groups can reference each other...
2042 c->name = cf_section_name2(cs);
2044 c->name = cf_section_name1(cs);
2045 if (strcmp(c->name, "group") == 0) {
2048 c->type = MOD_POLICY;
2054 * Loop over the children of this group.
2056 for (ci=cf_item_find_next(cs, NULL);
2058 ci=cf_item_find_next(cs, ci)) {
2061 * Sections are references to other groups, or
2062 * to modules with updated return codes.
2064 if (cf_item_is_section(ci)) {
2065 const char *junk = NULL;
2066 modcallable *single;
2067 CONF_SECTION *subcs = cf_itemtosection(ci);
2069 single = do_compile_modsingle(c, component, ci,
2072 cf_log_err(ci, "Failed to parse \"%s\" subsection.",
2073 cf_section_name1(subcs));
2074 modcallable_free(&c);
2077 add_child(g, single);
2079 } else if (!cf_item_is_pair(ci)) { /* CONF_DATA */
2083 const char *attr, *value;
2084 CONF_PAIR *cp = cf_itemtopair(ci);
2086 attr = cf_pair_attr(cp);
2087 value = cf_pair_value(cp);
2090 * A CONF_PAIR is either a module
2091 * instance with no actions
2095 modcallable *single;
2096 const char *junk = NULL;
2098 single = do_compile_modsingle(c,
2105 "Failed to parse \"%s\" entry.",
2107 modcallable_free(&c);
2110 add_child(g, single);
2113 * Or a module instance with action.
2115 } else if (!compile_action(c, cp)) {
2116 modcallable_free(&c);
2118 } /* else it worked */
2123 * Set the default actions, if they haven't already been
2126 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
2127 if (!c->actions[i]) {
2128 if (!parent || (component != RLM_COMPONENT_AUTH)) {
2129 c->actions[i] = defaultactions[component][parentgrouptype][i];
2130 } else { /* inside Auth-Type has different rules */
2131 c->actions[i] = defaultactions[RLM_COMPONENT_AUTZ][parentgrouptype][i];
2137 * FIXME: If there are no children, return NULL?
2139 return mod_grouptocallable(g);
2142 modcallable *compile_modgroup(modcallable *parent,
2143 int component, CONF_SECTION *cs)
2145 modcallable *ret = do_compile_modgroup(parent, component, cs,
2148 dump_tree(component, ret);
2152 void add_to_modcallable(modcallable **parent, modcallable *this,
2153 int component, const char *name)
2157 rad_assert(this != NULL);
2159 if (*parent == NULL) {
2162 g = rad_malloc(sizeof *g);
2163 memset(g, 0, sizeof(*g));
2164 g->grouptype = GROUPTYPE_SIMPLE;
2165 c = mod_grouptocallable(g);
2168 defaultactions[component][GROUPTYPE_SIMPLE],
2169 sizeof(c->actions));
2170 rad_assert(name != NULL);
2172 c->type = MOD_GROUP;
2173 c->method = component;
2176 *parent = mod_grouptocallable(g);
2178 g = mod_callabletogroup(*parent);
2184 void modcallable_free(modcallable **pc)
2186 modcallable *c, *loop, *next;
2188 if (c->type != MOD_SINGLE) {
2189 modgroup *g = mod_callabletogroup(c);
2191 for(loop = g->children;
2195 modcallable_free(&loop);