2 * modules.c Radius module support.
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 2003,2006 The FreeRADIUS server project
21 * Copyright 2000 Alan DeKok <aland@ox.org>
22 * Copyright 2000 Alan Curry <pacman@world.std.com>
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/modpriv.h>
30 #include <freeradius-devel/modcall.h>
31 #include <freeradius-devel/rad_assert.h>
33 extern int check_config;
35 typedef struct indexed_modcallable {
39 modcallable *modulelist;
40 } indexed_modcallable;
43 * For each component, keep an ordered list of ones to call.
45 static rbtree_t *components = NULL;
47 static rbtree_t *module_tree = NULL;
49 static rbtree_t *instance_tree = NULL;
51 typedef struct section_type_value_t {
55 } section_type_value_t;
57 struct fr_module_hup_t {
58 module_instance_t *mi;
61 fr_module_hup_t *next;
66 * Ordered by component
68 static const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = {
69 { "authenticate", "Auth-Type", PW_AUTH_TYPE },
70 { "authorize", "Autz-Type", PW_AUTZ_TYPE },
71 { "preacct", "Pre-Acct-Type", PW_PRE_ACCT_TYPE },
72 { "accounting", "Acct-Type", PW_ACCT_TYPE },
73 { "session", "Session-Type", PW_SESSION_TYPE },
74 { "pre-proxy", "Pre-Proxy-Type", PW_PRE_PROXY_TYPE },
75 { "post-proxy", "Post-Proxy-Type", PW_POST_PROXY_TYPE },
76 { "post-auth", "Post-Auth-Type", PW_POST_AUTH_TYPE },
80 #ifdef WITHOUT_LIBLTDL
81 typedef struct lt_dlmodule_t {
87 * Define modules here.
89 extern module_t rlm_pap;
90 extern module_t rlm_chap;
91 extern module_t rlm_eap;
94 * EAP structures are defined elsewhere.
96 typedef struct eap_type_t EAP_TYPE;
99 * And so on for other EAP types.
101 extern EAP_TYPE rlm_eap_md5;
103 static const lt_dlmodule_t lt_dlmodules[] = {
104 { "rlm_pap", &rlm_pap },
105 { "rlm_chap", &rlm_chap },
106 { "rlm_eap", &rlm_eap },
107 { "rlm_eap_md5", &rlm_eap_md5 },
110 * Add other modules here.
117 lt_dlhandle lt_dlopenext(const char *name)
121 for (i = 0; lt_dlmodules[i].name != NULL; i++) {
122 if (strcmp(name, lt_dlmodules[i].name) == 0) {
123 return lt_dlmodules[i].ref;
130 void *lt_dlsym(lt_dlhandle handle, UNUSED const char *symbol)
134 #endif /* WITHOUT_LIBLTDL */
137 static void indexed_modcallable_free(void *data)
139 indexed_modcallable *c = data;
141 modcallable_free(&c->modulelist);
145 static int indexed_modcallable_cmp(const void *one, const void *two)
148 const indexed_modcallable *a = one;
149 const indexed_modcallable *b = two;
151 if (a->server && !b->server) return -1;
152 if (!a->server && b->server) return +1;
153 if (a->server && b->server) {
154 rcode = strcmp(a->server, b->server);
155 if (rcode != 0) return rcode;
158 if (a->comp < b->comp) return -1;
159 if (a->comp > b->comp) return +1;
161 return a->idx - b->idx;
166 * Compare two module entries
168 static int module_instance_cmp(const void *one, const void *two)
170 const module_instance_t *a = one;
171 const module_instance_t *b = two;
173 return strcmp(a->name, b->name);
177 static void module_instance_free_old(CONF_SECTION *cs, module_instance_t *node,
180 fr_module_hup_t *mh, **last;
183 * Walk the list, freeing up old instances.
190 * Free only every 60 seconds.
192 if ((when - mh->when) < 60) {
197 cf_section_parse_free(cs, mh->insthandle);
199 if (node->entry->module->detach) {
200 (node->entry->module->detach)(mh->insthandle);
202 free(mh->insthandle);
212 * Free a module instance.
214 static void module_instance_free(void *data)
216 module_instance_t *this = data;
218 module_instance_free_old(this->cs, this, time(NULL) + 100);
220 if (this->entry->module->detach) {
221 (this->entry->module->detach)(this->insthandle);
224 #ifdef HAVE_PTHREAD_H
228 * The mutex MIGHT be locked...
229 * we'll check for that later, I guess.
231 pthread_mutex_destroy(this->mutex);
235 memset(this, 0, sizeof(*this));
241 * Compare two module entries
243 static int module_entry_cmp(const void *one, const void *two)
245 const module_entry_t *a = one;
246 const module_entry_t *b = two;
248 return strcmp(a->name, b->name);
252 * Free a module entry.
254 static void module_entry_free(void *data)
256 module_entry_t *this = data;
258 lt_dlclose(this->handle); /* ignore any errors */
259 memset(this, 0, sizeof(*this));
265 * Remove the module lists.
267 int detach_modules(void)
269 rbtree_free(instance_tree);
270 rbtree_free(components);
271 rbtree_free(module_tree);
280 * Find a module on disk or in memory, and link to it.
282 static module_entry_t *linkto_module(const char *module_name,
285 module_entry_t myentry;
286 module_entry_t *node;
288 char module_struct[256];
290 const module_t *module;
292 strlcpy(myentry.name, module_name, sizeof(myentry.name));
293 node = rbtree_finddata(module_tree, &myentry);
294 if (node) return node;
297 * Keep the handle around so we can dlclose() it.
299 handle = lt_dlopenext(module_name);
300 if (handle == NULL) {
301 cf_log_err(cf_sectiontoitem(cs),
302 "Failed to link to module '%s': %s\n",
303 module_name, lt_dlerror());
308 * Link to the module's rlm_FOO{} module structure.
310 * The module_name variable has the version number
311 * embedded in it, and we don't want that here.
313 strcpy(module_struct, module_name);
314 p = strrchr(module_struct, '-');
317 DEBUG3(" (Loaded %s, checking if it's valid)", module_name);
320 * libltld MAY core here, if the handle it gives us contains
323 module = lt_dlsym(handle, module_struct);
325 cf_log_err(cf_sectiontoitem(cs),
326 "Failed linking to %s structure: %s\n",
327 module_name, lt_dlerror());
332 * Before doing anything else, check if it's sane.
334 if (module->magic != RLM_MODULE_MAGIC_NUMBER) {
336 cf_log_err(cf_sectiontoitem(cs),
337 "Invalid version in module '%s'",
343 /* make room for the module type */
344 node = rad_malloc(sizeof(*node));
345 memset(node, 0, sizeof(*node));
346 strlcpy(node->name, module_name, sizeof(node->name));
347 node->module = module;
348 node->handle = handle;
350 cf_log_module(cs, "Linked to module %s", module_name);
353 * Add the module as "rlm_foo-version" to the configuration
356 if (!rbtree_insert(module_tree, node)) {
357 radlog(L_ERR, "Failed to cache module %s", module_name);
367 * Find a module instance.
369 module_instance_t *find_module_instance(CONF_SECTION *modules,
370 const char *instname, int do_link)
372 int check_config_safe = FALSE;
374 const char *name1, *name2;
375 module_instance_t *node, myNode;
376 char module_name[256];
378 if (!modules) return NULL;
381 * Module instances are declared in the modules{} block
382 * and referenced later by their name, which is the
383 * name2 from the config section, or name1 if there was
386 cs = cf_section_sub_find_name2(modules, NULL, instname);
388 radlog(L_ERR, "ERROR: Cannot find a configuration entry for module \"%s\".\n", instname);
393 * If there's already a module instance, return it.
395 strlcpy(myNode.name, instname, sizeof(myNode.name));
396 node = rbtree_finddata(instance_tree, &myNode);
397 if (node) return node;
399 if (!do_link) return NULL;
401 name1 = cf_section_name1(cs);
402 name2 = cf_section_name2(cs);
405 * Found the configuration entry.
407 node = rad_malloc(sizeof(*node));
408 memset(node, 0, sizeof(*node));
410 node->insthandle = NULL;
414 * Names in the "modules" section aren't prefixed
415 * with "rlm_", so we add it here.
417 snprintf(module_name, sizeof(module_name), "rlm_%s", name1);
419 node->entry = linkto_module(module_name, cs);
422 /* linkto_module logs any errors */
426 if (check_config && (node->entry->module->instantiate) &&
427 (node->entry->module->type & RLM_TYPE_CHECK_CONFIG_SAFE) == 0) {
428 const char *value = NULL;
431 cp = cf_pair_find(cs, "force_check_config");
432 if (cp) value = cf_pair_value(cp);
434 if (value && (strcmp(value, "yes") == 0)) goto print_inst;
436 cf_log_module(cs, "Skipping instantiation of %s", instname);
439 check_config_safe = TRUE;
440 cf_log_module(cs, "Instantiating %s", instname);
444 * Call the module's instantiation routine.
446 if ((node->entry->module->instantiate) &&
447 (!check_config || check_config_safe) &&
448 ((node->entry->module->instantiate)(cs, &node->insthandle) < 0)) {
449 cf_log_err(cf_sectiontoitem(cs),
450 "Instantiation failed for module \"%s\"",
457 * We're done. Fill in the rest of the data structure,
458 * and link it to the module instance list.
460 strlcpy(node->name, instname, sizeof(node->name));
462 #ifdef HAVE_PTHREAD_H
464 * If we're threaded, check if the module is thread-safe.
466 * If it isn't, we create a mutex.
468 if ((node->entry->module->type & RLM_TYPE_THREAD_UNSAFE) != 0) {
469 node->mutex = (pthread_mutex_t *) rad_malloc(sizeof(pthread_mutex_t));
471 * Initialize the mutex.
473 pthread_mutex_init(node->mutex, NULL);
476 * The module is thread-safe. Don't give it a mutex.
482 rbtree_insert(instance_tree, node);
487 static indexed_modcallable *lookup_by_index(const char *server, int comp,
490 indexed_modcallable myc;
496 return rbtree_finddata(components, &myc);
500 * Create a new sublist.
502 static indexed_modcallable *new_sublist(const char *server, int comp, int idx)
504 indexed_modcallable *c;
506 c = lookup_by_index(server, comp, idx);
508 /* It is an error to try to create a sublist that already
509 * exists. It would almost certainly be caused by accidental
510 * duplication in the config file.
512 * index 0 is the exception, because it is used when we want
513 * to collect _all_ listed modules under a single index by
514 * default, which is currently the case in all components
515 * except authenticate. */
523 c = rad_malloc(sizeof(*c));
524 c->modulelist = NULL;
529 if (!rbtree_insert(components, c)) {
537 int indexed_modcall(int comp, int idx, REQUEST *request)
540 indexed_modcallable *this;
541 modcallable *list = NULL;
543 this = lookup_by_index(request->server, comp, idx);
545 if (idx != 0) DEBUG2(" WARNING: Unknown value specified for %s. Cannot perform requested action.",
546 section_type_value[comp].typename);
548 list = this->modulelist;
551 request->component = section_type_value[comp].section;
553 rcode = modcall(comp, list, request);
555 request->module = "";
556 request->component = "";
561 * Load a sub-module list, as found inside an Auth-Type foo {}
564 static int load_subcomponent_section(modcallable *parent, CONF_SECTION *cs,
565 const char *server, int attr, int comp)
567 indexed_modcallable *subcomp;
570 const char *name2 = cf_section_name2(cs);
572 rad_assert(comp >= RLM_COMPONENT_AUTH);
573 rad_assert(comp < RLM_COMPONENT_COUNT);
579 cf_log_err(cf_sectiontoitem(cs),
580 "No name specified for %s block",
581 section_type_value[comp].typename);
588 ml = compile_modgroup(parent, comp, cs);
594 * We must assign a numeric index to this subcomponent.
595 * It is generated and placed in the dictionary
596 * automatically. If it isn't found, it's a serious
599 dval = dict_valbyname(attr, name2);
601 cf_log_err(cf_sectiontoitem(cs),
602 "%s %s Not previously configured",
603 section_type_value[comp].typename, name2);
604 modcallable_free(&ml);
608 subcomp = new_sublist(server, comp, dval->value);
610 modcallable_free(&ml);
614 subcomp->modulelist = ml;
618 static int define_type(const DICT_ATTR *dattr, const char *name)
624 * If the value already exists, don't
627 dval = dict_valbyname(dattr->attr, name);
631 * Create a new unique value with a
632 * meaningless number. You can't look at
633 * it from outside of this code, so it
634 * doesn't matter. The only requirement
635 * is that it's unique.
638 value = fr_rand() & 0x00ffffff;
639 } while (dict_valbyattr(dattr->attr, value));
641 if (dict_addvalue(name, dattr->name, value) < 0) {
642 radlog(L_ERR, "%s", fr_strerror());
649 static int load_component_section(CONF_SECTION *cs,
650 const char *server, int comp)
655 indexed_modcallable *subcomp;
657 const char *visiblename;
658 const DICT_ATTR *dattr;
661 * Find the attribute used to store VALUEs for this section.
663 dattr = dict_attrbyvalue(section_type_value[comp].attr);
665 cf_log_err(cf_sectiontoitem(cs),
666 "No such attribute %s",
667 section_type_value[comp].typename);
672 * Loop over the entries in the named section, loading
673 * the sections this time.
675 for (modref = cf_item_find_next(cs, NULL);
677 modref = cf_item_find_next(cs, modref)) {
679 CONF_PAIR *cp = NULL;
680 CONF_SECTION *scs = NULL;
682 if (cf_item_is_section(modref)) {
683 scs = cf_itemtosection(modref);
685 name1 = cf_section_name1(scs);
688 section_type_value[comp].typename) == 0) {
689 if (!load_subcomponent_section(NULL, scs,
693 return -1; /* FIXME: memleak? */
700 } else if (cf_item_is_pair(modref)) {
701 cp = cf_itemtopair(modref);
704 continue; /* ignore it */
708 * Try to compile one entry.
710 this = compile_modsingle(NULL, comp, modref, &modname);
712 cf_log_err(cf_sectiontoitem(cs),
713 "Errors parsing %s section.\n",
714 cf_section_name1(cs));
719 * Look for Auth-Type foo {}, which are special
720 * cases of named sections, and allowable ONLY
723 * i.e. They're not allowed in a "group" or "redundant"
726 if (comp == RLM_COMPONENT_AUTH) {
728 const char *modrefname = NULL;
730 modrefname = cf_pair_attr(cp);
732 modrefname = cf_section_name2(scs);
734 modcallable_free(&this);
735 cf_log_err(cf_sectiontoitem(cs),
736 "Errors parsing %s sub-section.\n",
737 cf_section_name1(scs));
742 dval = dict_valbyname(PW_AUTH_TYPE, modrefname);
745 * It's a section, but nothing we
748 modcallable_free(&this);
749 cf_log_err(cf_sectiontoitem(cs),
750 "Unknown Auth-Type \"%s\" in %s sub-section.",
751 modrefname, section_type_value[comp].section);
756 /* See the comment in new_sublist() for explanation
757 * of the special index 0 */
761 subcomp = new_sublist(server, comp, idx);
762 if (subcomp == NULL) {
763 modcallable_free(&this);
767 /* If subcomp->modulelist is NULL, add_to_modcallable will
769 visiblename = cf_section_name2(cs);
770 if (visiblename == NULL)
771 visiblename = cf_section_name1(cs);
772 add_to_modcallable(&subcomp->modulelist, this,
779 static int load_byserver(CONF_SECTION *cs)
782 const char *server = cf_section_name2(cs);
784 cf_log_info(cs, " modules {");
787 * Define types first.
789 for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
794 subcs = cf_section_sub_find(cs,
795 section_type_value[comp].section);
796 if (!subcs) continue;
798 if (cf_item_find_next(subcs, NULL) == NULL) continue;
801 * Find the attribute used to store VALUEs for this section.
803 dattr = dict_attrbyvalue(section_type_value[comp].attr);
805 cf_log_err(cf_sectiontoitem(subcs),
806 "No such attribute %s",
807 section_type_value[comp].typename);
808 cf_log_info(cs, " }");
813 * Define dynamic types, so that others can reference
816 for (modref = cf_item_find_next(subcs, NULL);
818 modref = cf_item_find_next(subcs, modref)) {
820 CONF_SECTION *subsubcs;
823 * Create types for simple references
824 * only when parsing the authenticate
827 if ((section_type_value[comp].attr == PW_AUTH_TYPE) &&
828 cf_item_is_pair(modref)) {
829 CONF_PAIR *cp = cf_itemtopair(modref);
830 if (!define_type(dattr, cf_pair_attr(cp))) {
837 if (!cf_item_is_section(modref)) continue;
839 subsubcs = cf_itemtosection(modref);
840 name1 = cf_section_name1(subsubcs);
842 if (strcmp(name1, section_type_value[comp].typename) == 0) {
843 if (!define_type(dattr,
844 cf_section_name2(subsubcs))) {
845 cf_log_info(cs, " }");
850 } /* loop over components */
853 * Loop over all of the known components, finding their
854 * configuration section, and loading it.
857 for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
860 subcs = cf_section_sub_find(cs,
861 section_type_value[comp].section);
862 if (!subcs) continue;
864 if (cf_item_find_next(subcs, NULL) == NULL) continue;
866 cf_log_module(cs, "Checking %s {...} for more modules to load",
867 section_type_value[comp].section);
871 * Skip pre/post-proxy sections if we're not
874 if (!mainconfig.proxy_requests &&
875 ((comp == PW_PRE_PROXY_TYPE) ||
876 (comp == PW_PRE_PROXY_TYPE))) {
881 if (load_component_section(subcs, server, comp) < 0) {
882 cf_log_info(cs, " }");
886 } /* loop over components */
889 * We haven't loaded any of the normal sections. Maybe we're
890 * supposed to load the vmps section.
892 * This is a bit of a hack...
897 subcs = cf_section_sub_find(cs, "vmps");
899 cf_log_module(cs, "Checking vmps {...} for more modules to load");
900 if (load_component_section(subcs, server,
901 RLM_COMPONENT_POST_AUTH) < 0) {
909 const DICT_ATTR *dattr;
911 dattr = dict_attrbyname("DHCP-Message-Type");
913 radlog(L_ERR, "No DHCP-Message-Type attribute");
918 * Handle each DHCP Message type separately.
920 for (subcs = cf_subsection_find_next(cs, NULL,
923 subcs = cf_subsection_find_next(cs, subcs,
925 const char *name2 = cf_section_name2(subcs);
927 DEBUG2(" Module: Checking dhcp %s {...} for more modules to load", name2);
928 if (!load_subcomponent_section(NULL, subcs,
931 RLM_COMPONENT_POST_AUTH)) {
932 return -1; /* FIXME: memleak? */
940 cf_log_info(cs, " }");
942 if (!flag && server) {
943 DEBUG("WARNING: Server %s is empty, and will do nothing!",
951 int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when)
953 void *insthandle = NULL;
957 !node->entry->module->instantiate ||
958 ((node->entry->module->type & RLM_TYPE_HUP_SAFE) == 0)) {
962 cf_log_module(cs, "Trying to reload module \"%s\"", node->name);
964 if ((node->entry->module->instantiate)(cs, &insthandle) < 0) {
965 cf_log_err(cf_sectiontoitem(cs),
966 "HUP failed for module \"%s\". Using old configuration.",
971 radlog(L_INFO, " Module: Reloaded module \"%s\"", node->name);
973 module_instance_free_old(cs, node, when);
976 * Save the old instance handle for later deletion.
978 mh = rad_malloc(sizeof(*mh));
981 mh->insthandle = node->insthandle;
985 node->insthandle = insthandle;
988 * FIXME: Set a timeout to come back in 60s, so that
989 * we can pro-actively clean up the old instances.
996 int module_hup(CONF_SECTION *modules)
1001 module_instance_t *node;
1003 if (!modules) return 0;
1008 * Loop over the modules
1010 for (ci=cf_item_find_next(modules, NULL);
1012 ci=cf_item_find_next(modules, ci)) {
1013 const char *instname;
1014 module_instance_t myNode;
1017 * If it's not a section, ignore it.
1019 if (!cf_item_is_section(ci)) continue;
1021 cs = cf_itemtosection(ci);
1022 instname = cf_section_name2(cs);
1023 if (!instname) instname = cf_section_name1(cs);
1025 strlcpy(myNode.name, instname, sizeof(myNode.name));
1026 node = rbtree_finddata(instance_tree, &myNode);
1028 module_hup_module(cs, node, when);
1036 * Parse the module config sections, and load
1037 * and call each module's init() function.
1039 * Libtool makes your life a LOT easier, especially with libltdl.
1040 * see: http://www.gnu.org/software/libtool/
1042 int setup_modules(int reload, CONF_SECTION *config)
1044 CONF_SECTION *cs, *modules;
1045 rad_listen_t *listener;
1046 int null_server = FALSE;
1048 if (reload) return 0;
1051 * If necessary, initialize libltdl.
1055 * Set the default list of preloaded symbols.
1056 * This is used to initialize libltdl's list of
1057 * preloaded modules.
1059 * i.e. Static modules.
1061 LTDL_SET_PRELOADED_SYMBOLS();
1063 if (lt_dlinit() != 0) {
1064 radlog(L_ERR, "Failed to initialize libraries: %s\n",
1070 * Set the search path to ONLY our library directory.
1071 * This prevents the modules from being found from
1072 * any location on the disk.
1074 lt_dlsetsearchpath(radlib_dir);
1077 * Set up the internal module struct.
1079 module_tree = rbtree_create(module_entry_cmp,
1080 module_entry_free, 0);
1082 radlog(L_ERR, "Failed to initialize modules\n");
1086 instance_tree = rbtree_create(module_instance_cmp,
1087 module_instance_free, 0);
1088 if (!instance_tree) {
1089 radlog(L_ERR, "Failed to initialize modules\n");
1094 components = rbtree_create(indexed_modcallable_cmp,
1095 indexed_modcallable_free, 0);
1097 radlog(L_ERR, "Failed to initialize components\n");
1102 * Remember where the modules were stored.
1104 modules = cf_section_sub_find(config, "modules");
1106 radlog(L_ERR, "Cannot find a \"modules\" section in the configuration file!");
1110 DEBUG2("%s: #### Instantiating modules ####", mainconfig.name);
1113 * Look for the 'instantiate' section, which tells us
1114 * the instantiation order of the modules, and also allows
1115 * us to load modules with no authorize/authenticate/etc.
1118 cs = cf_section_sub_find(config, "instantiate");
1122 module_instance_t *module;
1125 cf_log_info(cs, " instantiate {");
1128 * Loop over the items in the 'instantiate' section.
1130 for (ci=cf_item_find_next(cs, NULL);
1132 ci=cf_item_find_next(cs, ci)) {
1135 * Skip sections and "other" stuff.
1136 * Sections will be handled later, if
1137 * they're referenced at all...
1139 if (!cf_item_is_pair(ci)) {
1143 cp = cf_itemtopair(ci);
1144 name = cf_pair_attr(cp);
1145 module = find_module_instance(modules, name, 1);
1149 } /* loop over items in the subsection */
1151 cf_log_info(cs, " }");
1152 } /* if there's an 'instantiate' section. */
1155 * Loop over the listeners, figuring out which sections
1158 for (listener = mainconfig.listen;
1160 listener = listener->next) {
1163 if (listener->type == RAD_LISTEN_PROXY) continue;
1165 cs = cf_section_sub_find_name2(config,
1166 "server", listener->server);
1167 if (!cs && (listener->server != NULL)) {
1168 listener->print(listener, buffer, sizeof(buffer));
1170 radlog(L_ERR, "No server has been defined for %s", buffer);
1175 DEBUG2("%s: #### Loading Virtual Servers ####", mainconfig.name);
1178 * Load all of the virtual servers.
1180 for (cs = cf_subsection_find_next(config, NULL, "server");
1182 cs = cf_subsection_find_next(config, cs, "server")) {
1183 const char *name2 = cf_section_name2(cs);
1186 cf_log_info(cs, "server %s {", name2);
1188 cf_log_info(cs, "server {");
1191 if (load_byserver(cs) < 0) {
1192 cf_log_info(cs, "}");
1195 cf_log_info(cs, "}");
1199 * No empty server defined. Try to load an old-style
1200 * one for backwards compatibility.
1203 cf_log_info(cs, "server {");
1204 if (load_byserver(config) < 0) {
1205 cf_log_info(cs, "}");
1208 cf_log_info(cs, "}");
1215 * Call all authorization modules until one returns
1216 * somethings else than RLM_MODULE_OK
1218 int module_authorize(int autz_type, REQUEST *request)
1220 return indexed_modcall(RLM_COMPONENT_AUTZ, autz_type, request);
1224 * Authenticate a user/password with various methods.
1226 int module_authenticate(int auth_type, REQUEST *request)
1228 return indexed_modcall(RLM_COMPONENT_AUTH, auth_type, request);
1231 #ifdef WITH_ACCOUNTING
1233 * Do pre-accounting for ALL configured sessions
1235 int module_preacct(REQUEST *request)
1237 return indexed_modcall(RLM_COMPONENT_PREACCT, 0, request);
1241 * Do accounting for ALL configured sessions
1243 int module_accounting(int acct_type, REQUEST *request)
1245 return indexed_modcall(RLM_COMPONENT_ACCT, acct_type, request);
1249 #ifdef WITH_SESSION_MGMT
1251 * See if a user is already logged in.
1253 * Returns: 0 == OK, 1 == double logins, 2 == multilink attempt
1255 int module_checksimul(int sess_type, REQUEST *request, int maxsimul)
1259 if(!request->username)
1262 request->simul_count = 0;
1263 request->simul_max = maxsimul;
1264 request->simul_mpp = 1;
1266 rcode = indexed_modcall(RLM_COMPONENT_SESS, sess_type, request);
1268 if (rcode != RLM_MODULE_OK) {
1269 /* FIXME: Good spot for a *rate-limited* warning to the log */
1273 return (request->simul_count < maxsimul) ? 0 : request->simul_mpp;
1279 * Do pre-proxying for ALL configured sessions
1281 int module_pre_proxy(int type, REQUEST *request)
1283 return indexed_modcall(RLM_COMPONENT_PRE_PROXY, type, request);
1287 * Do post-proxying for ALL configured sessions
1289 int module_post_proxy(int type, REQUEST *request)
1291 return indexed_modcall(RLM_COMPONENT_POST_PROXY, type, request);
1296 * Do post-authentication for ALL configured sessions
1298 int module_post_auth(int postauth_type, REQUEST *request)
1300 return indexed_modcall(RLM_COMPONENT_POST_AUTH, postauth_type, request);