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 {
38 modcallable *modulelist;
39 } indexed_modcallable;
41 typedef struct virtual_server_t {
46 struct virtual_server_t *next;
50 * Keep a hash of virtual servers, so that we can reload them.
52 #define VIRTUAL_SERVER_HASH_SIZE (256)
53 static virtual_server_t *virtual_servers[VIRTUAL_SERVER_HASH_SIZE];
55 static rbtree_t *module_tree = NULL;
57 static rbtree_t *instance_tree = NULL;
59 typedef struct section_type_value_t {
63 } section_type_value_t;
65 struct fr_module_hup_t {
66 module_instance_t *mi;
69 fr_module_hup_t *next;
74 * Ordered by component
76 static const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = {
77 { "authenticate", "Auth-Type", PW_AUTH_TYPE },
78 { "authorize", "Autz-Type", PW_AUTZ_TYPE },
79 { "preacct", "Pre-Acct-Type", PW_PRE_ACCT_TYPE },
80 { "accounting", "Acct-Type", PW_ACCT_TYPE },
81 { "session", "Session-Type", PW_SESSION_TYPE },
82 { "pre-proxy", "Pre-Proxy-Type", PW_PRE_PROXY_TYPE },
83 { "post-proxy", "Post-Proxy-Type", PW_POST_PROXY_TYPE },
84 { "post-auth", "Post-Auth-Type", PW_POST_AUTH_TYPE },
88 #ifdef WITHOUT_LIBLTDL
89 typedef struct lt_dlmodule_t {
95 * Define modules here.
97 extern module_t rlm_pap;
98 extern module_t rlm_chap;
99 extern module_t rlm_eap;
102 * EAP structures are defined elsewhere.
104 typedef struct eap_type_t EAP_TYPE;
107 * And so on for other EAP types.
109 extern EAP_TYPE rlm_eap_md5;
111 static const lt_dlmodule_t lt_dlmodules[] = {
112 { "rlm_pap", &rlm_pap },
113 { "rlm_chap", &rlm_chap },
114 { "rlm_eap", &rlm_eap },
115 { "rlm_eap_md5", &rlm_eap_md5 },
118 * Add other modules here.
125 lt_dlhandle lt_dlopenext(const char *name)
129 for (i = 0; lt_dlmodules[i].name != NULL; i++) {
130 if (strcmp(name, lt_dlmodules[i].name) == 0) {
131 return lt_dlmodules[i].ref;
138 void *lt_dlsym(lt_dlhandle handle, UNUSED const char *symbol)
142 #endif /* WITHOUT_LIBLTDL */
144 static int virtual_server_idx(const char *name)
150 hash = fr_hash_string(name);
152 return hash & (VIRTUAL_SERVER_HASH_SIZE - 1);
155 static void virtual_server_free(virtual_server_t *server)
157 if (server->components) rbtree_free(server->components);
158 server->components = NULL;
163 void virtual_servers_free(time_t when)
166 virtual_server_t **last;
168 for (i = 0; i < VIRTUAL_SERVER_HASH_SIZE; i++) {
169 virtual_server_t *server, *next;
171 last = &virtual_servers[i];
172 for (server = virtual_servers[i];
178 * If we delete it, fix the links so that
179 * we don't orphan anything.
181 * Otherwise, the last pointer gets set to
182 * the one we didn't delete.
184 if ((when == 0) || (server->created < when)) {
185 *last = server->next;
186 virtual_server_free(server);
188 last = &(server->next);
194 static void indexed_modcallable_free(void *data)
196 indexed_modcallable *c = data;
198 modcallable_free(&c->modulelist);
202 static int indexed_modcallable_cmp(const void *one, const void *two)
204 const indexed_modcallable *a = one;
205 const indexed_modcallable *b = two;
207 if (a->comp < b->comp) return -1;
208 if (a->comp > b->comp) return +1;
210 return a->idx - b->idx;
215 * Compare two module entries
217 static int module_instance_cmp(const void *one, const void *two)
219 const module_instance_t *a = one;
220 const module_instance_t *b = two;
222 return strcmp(a->name, b->name);
226 static void module_instance_free_old(CONF_SECTION *cs, module_instance_t *node,
229 fr_module_hup_t *mh, **last;
232 * Walk the list, freeing up old instances.
239 * Free only every 60 seconds.
241 if ((when - mh->when) < 60) {
246 cf_section_parse_free(cs, mh->insthandle);
248 if (node->entry->module->detach) {
249 (node->entry->module->detach)(mh->insthandle);
251 free(mh->insthandle);
261 * Free a module instance.
263 static void module_instance_free(void *data)
265 module_instance_t *this = data;
267 module_instance_free_old(this->cs, this, time(NULL) + 100);
269 if (this->entry->module->detach) {
270 (this->entry->module->detach)(this->insthandle);
273 #ifdef HAVE_PTHREAD_H
277 * The mutex MIGHT be locked...
278 * we'll check for that later, I guess.
280 pthread_mutex_destroy(this->mutex);
284 memset(this, 0, sizeof(*this));
290 * Compare two module entries
292 static int module_entry_cmp(const void *one, const void *two)
294 const module_entry_t *a = one;
295 const module_entry_t *b = two;
297 return strcmp(a->name, b->name);
301 * Free a module entry.
303 static void module_entry_free(void *data)
305 module_entry_t *this = data;
307 lt_dlclose(this->handle); /* ignore any errors */
308 memset(this, 0, sizeof(*this));
314 * Remove the module lists.
316 int detach_modules(void)
318 rbtree_free(instance_tree);
319 rbtree_free(module_tree);
328 * Find a module on disk or in memory, and link to it.
330 static module_entry_t *linkto_module(const char *module_name,
333 module_entry_t myentry;
334 module_entry_t *node;
336 char module_struct[256];
338 const module_t *module;
340 strlcpy(myentry.name, module_name, sizeof(myentry.name));
341 node = rbtree_finddata(module_tree, &myentry);
342 if (node) return node;
345 * Keep the handle around so we can dlclose() it.
347 handle = lt_dlopenext(module_name);
348 if (handle == NULL) {
349 cf_log_err(cf_sectiontoitem(cs),
350 "Failed to link to module '%s': %s\n",
351 module_name, lt_dlerror());
356 * Link to the module's rlm_FOO{} module structure.
358 * The module_name variable has the version number
359 * embedded in it, and we don't want that here.
361 strcpy(module_struct, module_name);
362 p = strrchr(module_struct, '-');
365 DEBUG3(" (Loaded %s, checking if it's valid)", module_name);
368 * libltld MAY core here, if the handle it gives us contains
371 module = lt_dlsym(handle, module_struct);
373 cf_log_err(cf_sectiontoitem(cs),
374 "Failed linking to %s structure: %s\n",
375 module_name, lt_dlerror());
380 * Before doing anything else, check if it's sane.
382 if (module->magic != RLM_MODULE_MAGIC_NUMBER) {
384 cf_log_err(cf_sectiontoitem(cs),
385 "Invalid version in module '%s'",
391 /* make room for the module type */
392 node = rad_malloc(sizeof(*node));
393 memset(node, 0, sizeof(*node));
394 strlcpy(node->name, module_name, sizeof(node->name));
395 node->module = module;
396 node->handle = handle;
398 cf_log_module(cs, "Linked to module %s", module_name);
401 * Add the module as "rlm_foo-version" to the configuration
404 if (!rbtree_insert(module_tree, node)) {
405 radlog(L_ERR, "Failed to cache module %s", module_name);
415 * Find a module instance.
417 module_instance_t *find_module_instance(CONF_SECTION *modules,
418 const char *instname, int do_link)
420 int check_config_safe = FALSE;
422 const char *name1, *name2;
423 module_instance_t *node, myNode;
424 char module_name[256];
426 if (!modules) return NULL;
429 * Module instances are declared in the modules{} block
430 * and referenced later by their name, which is the
431 * name2 from the config section, or name1 if there was
434 cs = cf_section_sub_find_name2(modules, NULL, instname);
436 radlog(L_ERR, "ERROR: Cannot find a configuration entry for module \"%s\".\n", instname);
441 * If there's already a module instance, return it.
443 strlcpy(myNode.name, instname, sizeof(myNode.name));
444 node = rbtree_finddata(instance_tree, &myNode);
445 if (node) return node;
447 if (!do_link) return NULL;
449 name1 = cf_section_name1(cs);
450 name2 = cf_section_name2(cs);
453 * Found the configuration entry.
455 node = rad_malloc(sizeof(*node));
456 memset(node, 0, sizeof(*node));
458 node->insthandle = NULL;
462 * Names in the "modules" section aren't prefixed
463 * with "rlm_", so we add it here.
465 snprintf(module_name, sizeof(module_name), "rlm_%s", name1);
467 node->entry = linkto_module(module_name, cs);
470 /* linkto_module logs any errors */
474 if (check_config && (node->entry->module->instantiate) &&
475 (node->entry->module->type & RLM_TYPE_CHECK_CONFIG_SAFE) == 0) {
476 const char *value = NULL;
479 cp = cf_pair_find(cs, "force_check_config");
480 if (cp) value = cf_pair_value(cp);
482 if (value && (strcmp(value, "yes") == 0)) goto print_inst;
484 cf_log_module(cs, "Skipping instantiation of %s", instname);
487 check_config_safe = TRUE;
488 cf_log_module(cs, "Instantiating %s", instname);
492 * Call the module's instantiation routine.
494 if ((node->entry->module->instantiate) &&
495 (!check_config || check_config_safe) &&
496 ((node->entry->module->instantiate)(cs, &node->insthandle) < 0)) {
497 cf_log_err(cf_sectiontoitem(cs),
498 "Instantiation failed for module \"%s\"",
505 * We're done. Fill in the rest of the data structure,
506 * and link it to the module instance list.
508 strlcpy(node->name, instname, sizeof(node->name));
510 #ifdef HAVE_PTHREAD_H
512 * If we're threaded, check if the module is thread-safe.
514 * If it isn't, we create a mutex.
516 if ((node->entry->module->type & RLM_TYPE_THREAD_UNSAFE) != 0) {
517 node->mutex = (pthread_mutex_t *) rad_malloc(sizeof(pthread_mutex_t));
519 * Initialize the mutex.
521 pthread_mutex_init(node->mutex, NULL);
524 * The module is thread-safe. Don't give it a mutex.
530 rbtree_insert(instance_tree, node);
535 static indexed_modcallable *lookup_by_index(rbtree_t *components,
538 indexed_modcallable myc;
543 return rbtree_finddata(components, &myc);
547 * Create a new sublist.
549 static indexed_modcallable *new_sublist(rbtree_t *components, int comp, int idx)
551 indexed_modcallable *c;
553 c = lookup_by_index(components, comp, idx);
555 /* It is an error to try to create a sublist that already
556 * exists. It would almost certainly be caused by accidental
557 * duplication in the config file.
559 * index 0 is the exception, because it is used when we want
560 * to collect _all_ listed modules under a single index by
561 * default, which is currently the case in all components
562 * except authenticate. */
570 c = rad_malloc(sizeof(*c));
571 c->modulelist = NULL;
575 if (!rbtree_insert(components, c)) {
583 int indexed_modcall(int comp, int idx, REQUEST *request)
586 indexed_modcallable *this;
587 modcallable *list = NULL;
588 virtual_server_t *server;
590 rcode = virtual_server_idx(request->server);
591 for (server = virtual_servers[rcode];
593 server = server->next) {
594 if (!request->server && !server->name) break;
596 if ((request->server && server->name) &&
597 (strcmp(request->server, server->name) == 0)) break;
601 RDEBUG("No such virtual server %s", request->server);
602 return RLM_MODULE_FAIL;
605 this = lookup_by_index(server->components, comp, idx);
607 if (idx != 0) DEBUG2(" WARNING: Unknown value specified for %s. Cannot perform requested action.",
608 section_type_value[comp].typename);
610 list = this->modulelist;
613 request->component = section_type_value[comp].section;
615 rcode = modcall(comp, list, request);
617 request->module = "";
618 request->component = "";
623 * Load a sub-module list, as found inside an Auth-Type foo {}
626 static int load_subcomponent_section(modcallable *parent, CONF_SECTION *cs,
627 rbtree_t *components, int attr, int comp)
629 indexed_modcallable *subcomp;
632 const char *name2 = cf_section_name2(cs);
634 rad_assert(comp >= RLM_COMPONENT_AUTH);
635 rad_assert(comp < RLM_COMPONENT_COUNT);
641 cf_log_err(cf_sectiontoitem(cs),
642 "No name specified for %s block",
643 section_type_value[comp].typename);
650 ml = compile_modgroup(parent, comp, cs);
656 * We must assign a numeric index to this subcomponent.
657 * It is generated and placed in the dictionary
658 * automatically. If it isn't found, it's a serious
661 dval = dict_valbyname(attr, name2);
663 cf_log_err(cf_sectiontoitem(cs),
664 "%s %s Not previously configured",
665 section_type_value[comp].typename, name2);
666 modcallable_free(&ml);
670 subcomp = new_sublist(components, comp, dval->value);
672 modcallable_free(&ml);
676 subcomp->modulelist = ml;
680 static int define_type(const DICT_ATTR *dattr, const char *name)
686 * If the value already exists, don't
689 dval = dict_valbyname(dattr->attr, name);
693 * Create a new unique value with a
694 * meaningless number. You can't look at
695 * it from outside of this code, so it
696 * doesn't matter. The only requirement
697 * is that it's unique.
700 value = fr_rand() & 0x00ffffff;
701 } while (dict_valbyattr(dattr->attr, value));
703 if (dict_addvalue(name, dattr->name, value) < 0) {
704 radlog(L_ERR, "%s", fr_strerror());
711 static int load_component_section(CONF_SECTION *cs,
712 rbtree_t *components, int comp)
717 indexed_modcallable *subcomp;
719 const char *visiblename;
720 const DICT_ATTR *dattr;
723 * Find the attribute used to store VALUEs for this section.
725 dattr = dict_attrbyvalue(section_type_value[comp].attr);
727 cf_log_err(cf_sectiontoitem(cs),
728 "No such attribute %s",
729 section_type_value[comp].typename);
734 * Loop over the entries in the named section, loading
735 * the sections this time.
737 for (modref = cf_item_find_next(cs, NULL);
739 modref = cf_item_find_next(cs, modref)) {
741 CONF_PAIR *cp = NULL;
742 CONF_SECTION *scs = NULL;
744 if (cf_item_is_section(modref)) {
745 scs = cf_itemtosection(modref);
747 name1 = cf_section_name1(scs);
750 section_type_value[comp].typename) == 0) {
751 if (!load_subcomponent_section(NULL, scs,
755 return -1; /* FIXME: memleak? */
762 } else if (cf_item_is_pair(modref)) {
763 cp = cf_itemtopair(modref);
766 continue; /* ignore it */
770 * Try to compile one entry.
772 this = compile_modsingle(NULL, comp, modref, &modname);
774 cf_log_err(cf_sectiontoitem(cs),
775 "Errors parsing %s section.\n",
776 cf_section_name1(cs));
781 * Look for Auth-Type foo {}, which are special
782 * cases of named sections, and allowable ONLY
785 * i.e. They're not allowed in a "group" or "redundant"
788 if (comp == RLM_COMPONENT_AUTH) {
790 const char *modrefname = NULL;
792 modrefname = cf_pair_attr(cp);
794 modrefname = cf_section_name2(scs);
796 modcallable_free(&this);
797 cf_log_err(cf_sectiontoitem(cs),
798 "Errors parsing %s sub-section.\n",
799 cf_section_name1(scs));
804 dval = dict_valbyname(PW_AUTH_TYPE, modrefname);
807 * It's a section, but nothing we
810 modcallable_free(&this);
811 cf_log_err(cf_sectiontoitem(cs),
812 "Unknown Auth-Type \"%s\" in %s sub-section.",
813 modrefname, section_type_value[comp].section);
818 /* See the comment in new_sublist() for explanation
819 * of the special index 0 */
823 subcomp = new_sublist(components, comp, idx);
824 if (subcomp == NULL) {
825 modcallable_free(&this);
829 /* If subcomp->modulelist is NULL, add_to_modcallable will
831 visiblename = cf_section_name2(cs);
832 if (visiblename == NULL)
833 visiblename = cf_section_name1(cs);
834 add_to_modcallable(&subcomp->modulelist, this,
841 static int load_byserver(CONF_SECTION *cs)
844 const char *name = cf_section_name2(cs);
845 rbtree_t *components;
846 virtual_server_t *server;
848 cf_log_info(cs, " modules {");
850 components = rbtree_create(indexed_modcallable_cmp,
851 indexed_modcallable_free, 0);
853 radlog(L_ERR, "Failed to initialize components\n");
857 server = rad_malloc(sizeof(*server));
858 memset(server, 0, sizeof(*server));
861 server->created = time(NULL);
863 server->components = components;
866 * Define types first.
868 for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
873 subcs = cf_section_sub_find(cs,
874 section_type_value[comp].section);
875 if (!subcs) continue;
877 if (cf_item_find_next(subcs, NULL) == NULL) continue;
880 * Find the attribute used to store VALUEs for this section.
882 dattr = dict_attrbyvalue(section_type_value[comp].attr);
884 cf_log_err(cf_sectiontoitem(subcs),
885 "No such attribute %s",
886 section_type_value[comp].typename);
887 cf_log_info(cs, " }");
889 virtual_server_free(server);
894 * Define dynamic types, so that others can reference
897 for (modref = cf_item_find_next(subcs, NULL);
899 modref = cf_item_find_next(subcs, modref)) {
901 CONF_SECTION *subsubcs;
904 * Create types for simple references
905 * only when parsing the authenticate
908 if ((section_type_value[comp].attr == PW_AUTH_TYPE) &&
909 cf_item_is_pair(modref)) {
910 CONF_PAIR *cp = cf_itemtopair(modref);
911 if (!define_type(dattr, cf_pair_attr(cp))) {
918 if (!cf_item_is_section(modref)) continue;
920 subsubcs = cf_itemtosection(modref);
921 name1 = cf_section_name1(subsubcs);
923 if (strcmp(name1, section_type_value[comp].typename) == 0) {
924 if (!define_type(dattr,
925 cf_section_name2(subsubcs))) {
926 cf_log_info(cs, " }");
931 } /* loop over components */
934 * Loop over all of the known components, finding their
935 * configuration section, and loading it.
938 for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
941 subcs = cf_section_sub_find(cs,
942 section_type_value[comp].section);
943 if (!subcs) continue;
945 if (cf_item_find_next(subcs, NULL) == NULL) continue;
947 cf_log_module(cs, "Checking %s {...} for more modules to load",
948 section_type_value[comp].section);
952 * Skip pre/post-proxy sections if we're not
955 if (!mainconfig.proxy_requests &&
956 ((comp == PW_PRE_PROXY_TYPE) ||
957 (comp == PW_PRE_PROXY_TYPE))) {
962 if (load_component_section(subcs, components, comp) < 0) {
963 cf_log_info(cs, " }");
967 } /* loop over components */
970 * We haven't loaded any of the normal sections. Maybe we're
971 * supposed to load the vmps section.
973 * This is a bit of a hack...
978 subcs = cf_section_sub_find(cs, "vmps");
980 cf_log_module(cs, "Checking vmps {...} for more modules to load");
981 if (load_component_section(subcs, components,
982 RLM_COMPONENT_POST_AUTH) < 0) {
990 const DICT_ATTR *dattr;
992 dattr = dict_attrbyname("DHCP-Message-Type");
994 radlog(L_ERR, "No DHCP-Message-Type attribute");
999 * Handle each DHCP Message type separately.
1001 for (subcs = cf_subsection_find_next(cs, NULL,
1004 subcs = cf_subsection_find_next(cs, subcs,
1006 const char *name2 = cf_section_name2(subcs);
1008 DEBUG2(" Module: Checking dhcp %s {...} for more modules to load", name2);
1009 if (!load_subcomponent_section(NULL, subcs,
1012 RLM_COMPONENT_POST_AUTH)) {
1013 goto error; /* FIXME: memleak? */
1021 cf_log_info(cs, " }");
1023 if (!flag && name) {
1024 DEBUG("WARNING: Server %s is empty, and will do nothing!",
1029 * Now that it is OK, insert it into the list.
1031 * This is thread-safe...
1033 comp = virtual_server_idx(name);
1034 server->next = virtual_servers[comp];
1035 virtual_servers[comp] = server;
1042 * Load all of the virtual servers.
1044 int virtual_servers_load(CONF_SECTION *config)
1046 int null_server = FALSE;
1049 DEBUG2("%s: #### Loading Virtual Servers ####", mainconfig.name);
1052 * Load all of the virtual servers.
1054 for (cs = cf_subsection_find_next(config, NULL, "server");
1056 cs = cf_subsection_find_next(config, cs, "server")) {
1057 const char *name2 = cf_section_name2(cs);
1060 cf_log_info(cs, "server %s {", name2);
1062 cf_log_info(cs, "server {");
1065 if (load_byserver(cs) < 0) {
1066 cf_log_info(cs, "}");
1069 cf_log_info(cs, "}");
1070 if (debug_flag == 0) {
1071 radlog(L_INFO, "Loaded virtual server %s", name2);
1076 * No empty server defined. Try to load an old-style
1077 * one for backwards compatibility.
1080 cf_log_info(cs, "server {");
1081 if (load_byserver(config) < 0) {
1082 cf_log_info(cs, "}");
1085 cf_log_info(cs, "}");
1091 int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when)
1093 void *insthandle = NULL;
1094 fr_module_hup_t *mh;
1097 !node->entry->module->instantiate ||
1098 ((node->entry->module->type & RLM_TYPE_HUP_SAFE) == 0)) {
1102 cf_log_module(cs, "Trying to reload module \"%s\"", node->name);
1104 if ((node->entry->module->instantiate)(cs, &insthandle) < 0) {
1105 cf_log_err(cf_sectiontoitem(cs),
1106 "HUP failed for module \"%s\". Using old configuration.",
1111 radlog(L_INFO, " Module: Reloaded module \"%s\"", node->name);
1113 module_instance_free_old(cs, node, when);
1116 * Save the old instance handle for later deletion.
1118 mh = rad_malloc(sizeof(*mh));
1121 mh->insthandle = node->insthandle;
1122 mh->next = node->mh;
1125 node->insthandle = insthandle;
1128 * FIXME: Set a timeout to come back in 60s, so that
1129 * we can pro-actively clean up the old instances.
1136 int module_hup(CONF_SECTION *modules)
1141 module_instance_t *node;
1143 if (!modules) return 0;
1148 * Loop over the modules
1150 for (ci=cf_item_find_next(modules, NULL);
1152 ci=cf_item_find_next(modules, ci)) {
1153 const char *instname;
1154 module_instance_t myNode;
1157 * If it's not a section, ignore it.
1159 if (!cf_item_is_section(ci)) continue;
1161 cs = cf_itemtosection(ci);
1162 instname = cf_section_name2(cs);
1163 if (!instname) instname = cf_section_name1(cs);
1165 strlcpy(myNode.name, instname, sizeof(myNode.name));
1166 node = rbtree_finddata(instance_tree, &myNode);
1168 module_hup_module(cs, node, when);
1176 * Parse the module config sections, and load
1177 * and call each module's init() function.
1179 * Libtool makes your life a LOT easier, especially with libltdl.
1180 * see: http://www.gnu.org/software/libtool/
1182 int setup_modules(int reload, CONF_SECTION *config)
1184 CONF_SECTION *cs, *modules;
1185 rad_listen_t *listener;
1187 if (reload) return 0;
1190 * If necessary, initialize libltdl.
1194 * Set the default list of preloaded symbols.
1195 * This is used to initialize libltdl's list of
1196 * preloaded modules.
1198 * i.e. Static modules.
1200 LTDL_SET_PRELOADED_SYMBOLS();
1202 if (lt_dlinit() != 0) {
1203 radlog(L_ERR, "Failed to initialize libraries: %s\n",
1209 * Set the search path to ONLY our library directory.
1210 * This prevents the modules from being found from
1211 * any location on the disk.
1213 lt_dlsetsearchpath(radlib_dir);
1216 * Set up the internal module struct.
1218 module_tree = rbtree_create(module_entry_cmp,
1219 module_entry_free, 0);
1221 radlog(L_ERR, "Failed to initialize modules\n");
1225 instance_tree = rbtree_create(module_instance_cmp,
1226 module_instance_free, 0);
1227 if (!instance_tree) {
1228 radlog(L_ERR, "Failed to initialize modules\n");
1233 memset(virtual_servers, 0, sizeof(virtual_servers));
1236 * Remember where the modules were stored.
1238 modules = cf_section_sub_find(config, "modules");
1240 radlog(L_ERR, "Cannot find a \"modules\" section in the configuration file!");
1244 DEBUG2("%s: #### Instantiating modules ####", mainconfig.name);
1247 * Look for the 'instantiate' section, which tells us
1248 * the instantiation order of the modules, and also allows
1249 * us to load modules with no authorize/authenticate/etc.
1252 cs = cf_section_sub_find(config, "instantiate");
1256 module_instance_t *module;
1259 cf_log_info(cs, " instantiate {");
1262 * Loop over the items in the 'instantiate' section.
1264 for (ci=cf_item_find_next(cs, NULL);
1266 ci=cf_item_find_next(cs, ci)) {
1269 * Skip sections and "other" stuff.
1270 * Sections will be handled later, if
1271 * they're referenced at all...
1273 if (!cf_item_is_pair(ci)) {
1277 cp = cf_itemtopair(ci);
1278 name = cf_pair_attr(cp);
1279 module = find_module_instance(modules, name, 1);
1283 } /* loop over items in the subsection */
1285 cf_log_info(cs, " }");
1286 } /* if there's an 'instantiate' section. */
1289 * Loop over the listeners, figuring out which sections
1292 for (listener = mainconfig.listen;
1294 listener = listener->next) {
1297 if (listener->type == RAD_LISTEN_PROXY) continue;
1299 cs = cf_section_sub_find_name2(config,
1300 "server", listener->server);
1301 if (!cs && (listener->server != NULL)) {
1302 listener->print(listener, buffer, sizeof(buffer));
1304 radlog(L_ERR, "No server has been defined for %s", buffer);
1309 if (virtual_servers_load(config) < 0) return -1;
1315 * Call all authorization modules until one returns
1316 * somethings else than RLM_MODULE_OK
1318 int module_authorize(int autz_type, REQUEST *request)
1320 return indexed_modcall(RLM_COMPONENT_AUTZ, autz_type, request);
1324 * Authenticate a user/password with various methods.
1326 int module_authenticate(int auth_type, REQUEST *request)
1328 return indexed_modcall(RLM_COMPONENT_AUTH, auth_type, request);
1331 #ifdef WITH_ACCOUNTING
1333 * Do pre-accounting for ALL configured sessions
1335 int module_preacct(REQUEST *request)
1337 return indexed_modcall(RLM_COMPONENT_PREACCT, 0, request);
1341 * Do accounting for ALL configured sessions
1343 int module_accounting(int acct_type, REQUEST *request)
1345 return indexed_modcall(RLM_COMPONENT_ACCT, acct_type, request);
1349 #ifdef WITH_SESSION_MGMT
1351 * See if a user is already logged in.
1353 * Returns: 0 == OK, 1 == double logins, 2 == multilink attempt
1355 int module_checksimul(int sess_type, REQUEST *request, int maxsimul)
1359 if(!request->username)
1362 request->simul_count = 0;
1363 request->simul_max = maxsimul;
1364 request->simul_mpp = 1;
1366 rcode = indexed_modcall(RLM_COMPONENT_SESS, sess_type, request);
1368 if (rcode != RLM_MODULE_OK) {
1369 /* FIXME: Good spot for a *rate-limited* warning to the log */
1373 return (request->simul_count < maxsimul) ? 0 : request->simul_mpp;
1379 * Do pre-proxying for ALL configured sessions
1381 int module_pre_proxy(int type, REQUEST *request)
1383 return indexed_modcall(RLM_COMPONENT_PRE_PROXY, type, request);
1387 * Do post-proxying for ALL configured sessions
1389 int module_post_proxy(int type, REQUEST *request)
1391 return indexed_modcall(RLM_COMPONENT_POST_PROXY, type, request);
1396 * Do post-authentication for ALL configured sessions
1398 int module_post_auth(int postauth_type, REQUEST *request)
1400 return indexed_modcall(RLM_COMPONENT_POST_AUTH, postauth_type, request);