04a7d0bb7c8dff7778c231ff1fd5e3a4e2ff4e6f
[freeradius.git] / src / main / modules.c
1 /*
2  * modules.c    Radius module support.
3  *
4  * Version:     $Id$
5  *
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.
10  *
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.
15  *
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
19  *
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>
23  */
24
25 #include <freeradius-devel/ident.h>
26 RCSID("$Id$")
27
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>
32
33 extern int check_config;
34
35 typedef struct indexed_modcallable {
36         int             comp;
37         int             idx;
38         modcallable     *modulelist;
39 } indexed_modcallable;
40
41 typedef struct virtual_server_t {
42         const char      *name;
43         time_t          created;
44         int             can_free;
45         CONF_SECTION    *cs;
46         rbtree_t        *components;
47         modcallable     *mc[RLM_COMPONENT_COUNT];
48         CONF_SECTION    *subcs[RLM_COMPONENT_COUNT];
49         struct virtual_server_t *next;
50 } virtual_server_t;
51
52 /*
53  *      Keep a hash of virtual servers, so that we can reload them.
54  */
55 #define VIRTUAL_SERVER_HASH_SIZE (256)
56 static virtual_server_t *virtual_servers[VIRTUAL_SERVER_HASH_SIZE];
57
58 static rbtree_t *module_tree = NULL;
59
60 static rbtree_t *instance_tree = NULL;
61
62 struct fr_module_hup_t {
63         module_instance_t       *mi;
64         time_t                  when;
65         void                    *insthandle;
66         fr_module_hup_t         *next;
67 };
68
69
70 typedef struct section_type_value_t {
71         const char      *section;
72         const char      *typename;
73         int             attr;
74 } section_type_value_t;
75
76 /*
77  *      Ordered by component
78  */
79 static const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = {
80         { "authenticate", "Auth-Type",       PW_AUTH_TYPE },
81         { "authorize",    "Autz-Type",       PW_AUTZ_TYPE },
82         { "preacct",      "Pre-Acct-Type",   PW_PRE_ACCT_TYPE },
83         { "accounting",   "Acct-Type",       PW_ACCT_TYPE },
84         { "session",      "Session-Type",    PW_SESSION_TYPE },
85         { "pre-proxy",    "Pre-Proxy-Type",  PW_PRE_PROXY_TYPE },
86         { "post-proxy",   "Post-Proxy-Type", PW_POST_PROXY_TYPE },
87         { "post-auth",    "Post-Auth-Type",  PW_POST_AUTH_TYPE }
88 #ifdef WITH_COA
89         ,
90         { "recv-coa",     "Recv-CoA-Type",   PW_RECV_COA_TYPE },
91         { "send-coa",     "Send-CoA-Type",   PW_SEND_COA_TYPE }
92 #endif
93 };
94
95
96 #ifdef WITHOUT_LIBLTDL
97 #ifdef WITH_DLOPEN
98 #include <dlfcn.h>
99
100 #ifndef RTLD_NOW
101 #define RTLD_NOW (0)
102 #endif
103 #ifndef RTLD_LOCAL
104 #define RTLD_LOCAL (0)
105 #endif
106
107 #define fr_dlopenext lt_dlopenext
108 #ifndef LT_SHREXT
109 #ifdef __APPLE__
110 #define LT_SHREXT ".so"
111 #elif defined (WIN32)
112 #define LT_SHREXT ".dll"
113 #else
114 #define LT_SHREXT ".dylib"
115 #endif
116 #endif
117
118 lt_dlhandle lt_dlopenext(const char *name)
119 {
120         char buffer[256];
121
122         strlcpy(buffer, name, sizeof(buffer));
123
124         /*
125          *      FIXME: Make this configurable...
126          */
127         strlcat(buffer, LT_SHREXT, sizeof(buffer));
128
129         return dlopen(buffer, RTLD_NOW | RTLD_LOCAL);
130 }
131
132 void *lt_dlsym(lt_dlhandle handle, UNUSED const char *symbol)
133 {
134         return dlsym(handle, symbol);
135 }
136
137 int lt_dlclose(lt_dlhandle handle)
138 {
139         if (!handle) return 0;
140
141         return dlclose(handle);
142 }
143
144 const char *lt_dlerror(void)
145 {
146         return dlerror();
147 }
148
149
150 #else  /* without dlopen */
151 typedef struct lt_dlmodule_t {
152   const char    *name;
153   void          *ref;
154 } lt_dlmodule_t;
155
156 typedef struct eap_type_t EAP_TYPE;
157 typedef struct rlm_sql_module_t rlm_sql_module_t;
158
159 /*
160  *      FIXME: Write hackery to auto-generate this data.
161  *      We only need to do this on systems that don't have dlopen.
162  */
163 extern module_t rlm_pap;
164 extern module_t rlm_chap;
165 extern module_t rlm_eap;
166 extern module_t rlm_sql;
167 /* and so on ... */
168
169 extern EAP_TYPE rlm_eap_md5;
170 extern rlm_sql_module_t rlm_sql_mysql;
171 /* and so on ... */
172
173 static const lt_dlmodule_t lt_dlmodules[] = {
174         { "rlm_pap", &rlm_pap },
175         { "rlm_chap", &rlm_chap },
176         { "rlm_eap", &rlm_eap },
177         /* and so on ... */
178
179         { "rlm_eap_md5", &rlm_eap_md5 },
180         /* and so on ... */
181                 
182         { "rlm_sql_mysql", &rlm_sql_mysql },
183         /* and so on ... */
184                 
185         { NULL, NULL }
186 };
187
188 #define fr_dlopenext lt_dlopenext
189 lt_dlhandle lt_dlopenext(const char *name)
190 {
191         int i;
192
193         for (i = 0; lt_dlmodules[i].name != NULL; i++) {
194                 if (strcmp(name, lt_dlmodules[i].name) == 0) {
195                         return lt_dlmodules[i].ref;
196                 }
197         }
198
199         return NULL;
200 }
201
202 void *lt_dlsym(lt_dlhandle handle, UNUSED const char *symbol)
203 {
204         return handle;
205 }
206
207 int lt_dlclose(lt_dlhandle handle)
208 {
209         return 0;
210 }
211
212 const char *lt_dlerror(void)
213 {
214         return "Unspecified error";
215 }
216
217 #endif  /* WITH_DLOPEN */
218 #else   /* WITHOUT_LIBLTDL */
219
220 /*
221  *      Solve the issues of libraries linking to other libraries
222  *      by using a newer libltdl API.
223  */
224 #ifndef HAVE_LT_DLADVISE_INIT
225 #define fr_dlopenext lt_dlopenext
226 #else
227 static lt_dlhandle fr_dlopenext(const char *filename)
228 {
229         lt_dlhandle handle = 0;
230         lt_dladvise advise;
231
232         if (!lt_dladvise_init (&advise) &&
233             !lt_dladvise_ext (&advise) &&
234             !lt_dladvise_global (&advise)) {
235                 handle = lt_dlopenadvise (filename, advise);
236         }
237
238         lt_dladvise_destroy (&advise);
239
240         return handle;
241 }
242 #endif  /* HAVE_LT_DLADVISE_INIT */
243 #endif /* WITHOUT_LIBLTDL */
244
245 static int virtual_server_idx(const char *name)
246 {
247         uint32_t hash;
248
249         if (!name) return 0;
250
251         hash = fr_hash_string(name);
252                 
253         return hash & (VIRTUAL_SERVER_HASH_SIZE - 1);
254 }
255
256 static void virtual_server_free(virtual_server_t *server)
257 {
258         if (!server) return;
259
260         if (server->components) rbtree_free(server->components);
261         server->components = NULL;
262
263         free(server);
264 }
265
266 void virtual_servers_free(time_t when)
267 {
268         int i;
269         virtual_server_t **last;
270         
271         for (i = 0; i < VIRTUAL_SERVER_HASH_SIZE; i++) {
272                 virtual_server_t *server, *next;
273
274                 last = &virtual_servers[i];
275                 for (server = virtual_servers[i];
276                      server != NULL;
277                      server = next) {
278                         next = server->next;
279
280                         /*
281                          *      If we delete it, fix the links so that
282                          *      we don't orphan anything.  Also,
283                          *      delete it if it's old, AND a newer one
284                          *      was defined.
285                          *
286                          *      Otherwise, the last pointer gets set to
287                          *      the one we didn't delete.
288                          */
289                         if ((when == 0) ||
290                             ((server->created < when) && server->can_free)) {
291                                 *last = server->next;
292                                 virtual_server_free(server);
293                         } else {
294                                 last = &(server->next);
295                         }
296                 }
297         }
298 }
299
300 static void indexed_modcallable_free(void *data)
301 {
302         indexed_modcallable *c = data;
303
304         modcallable_free(&c->modulelist);
305         free(c);
306 }
307
308 static int indexed_modcallable_cmp(const void *one, const void *two)
309 {
310         const indexed_modcallable *a = one;
311         const indexed_modcallable *b = two;
312
313         if (a->comp < b->comp) return -1;
314         if (a->comp >  b->comp) return +1;
315
316         return a->idx - b->idx;
317 }
318
319
320 /*
321  *      Compare two module entries
322  */
323 static int module_instance_cmp(const void *one, const void *two)
324 {
325         const module_instance_t *a = one;
326         const module_instance_t *b = two;
327
328         return strcmp(a->name, b->name);
329 }
330
331
332 static void module_instance_free_old(CONF_SECTION *cs, module_instance_t *node,
333                                      time_t when)
334 {
335         fr_module_hup_t *mh, **last;
336
337         /*
338          *      Walk the list, freeing up old instances.
339          */
340         last = &(node->mh);
341         while (*last) {
342                 mh = *last;
343
344                 /*
345                  *      Free only every 60 seconds.
346                  */
347                 if ((when - mh->when) < 60) {
348                         last = &(mh->next);
349                         continue;
350                 }
351
352                 cf_section_parse_free(cs, mh->insthandle);
353                 
354                 if (node->entry->module->detach) {
355                         (node->entry->module->detach)(mh->insthandle);
356                 } else {
357                         free(mh->insthandle);
358                 }
359
360                 *last = mh->next;
361                 free(mh);
362         }
363 }
364
365
366 /*
367  *      Free a module instance.
368  */
369 static void module_instance_free(void *data)
370 {
371         module_instance_t *this = data;
372
373         module_instance_free_old(this->cs, this, time(NULL) + 100);
374
375         if (this->entry->module->detach) {
376                 (this->entry->module->detach)(this->insthandle);
377         }
378
379 #ifdef HAVE_PTHREAD_H
380         if (this->mutex) {
381                 /*
382                  *      FIXME
383                  *      The mutex MIGHT be locked...
384                  *      we'll check for that later, I guess.
385                  */
386                 pthread_mutex_destroy(this->mutex);
387                 free(this->mutex);
388         }
389 #endif
390         memset(this, 0, sizeof(*this));
391         free(this);
392 }
393
394
395 /*
396  *      Compare two module entries
397  */
398 static int module_entry_cmp(const void *one, const void *two)
399 {
400         const module_entry_t *a = one;
401         const module_entry_t *b = two;
402
403         return strcmp(a->name, b->name);
404 }
405
406 /*
407  *      Free a module entry.
408  */
409 static void module_entry_free(void *data)
410 {
411         module_entry_t *this = data;
412
413         lt_dlclose(this->handle);       /* ignore any errors */
414         memset(this, 0, sizeof(*this));
415         free(this);
416 }
417
418
419 /*
420  *      Remove the module lists.
421  */
422 int detach_modules(void)
423 {
424         rbtree_free(instance_tree);
425         rbtree_free(module_tree);
426
427         lt_dlexit();
428
429         return 0;
430 }
431
432
433 /*
434  *      Find a module on disk or in memory, and link to it.
435  */
436 static module_entry_t *linkto_module(const char *module_name,
437                                      CONF_SECTION *cs)
438 {
439         module_entry_t myentry;
440         module_entry_t *node;
441         lt_dlhandle handle = NULL;
442         char module_struct[256];
443         char *p;
444         const module_t *module;
445
446         strlcpy(myentry.name, module_name, sizeof(myentry.name));
447         node = rbtree_finddata(module_tree, &myentry);
448         if (node) return node;
449
450         /*
451          *      Link to the module's rlm_FOO{} module structure.
452          *
453          *      The module_name variable has the version number
454          *      embedded in it, and we don't want that here.
455          */
456         strcpy(module_struct, module_name);
457         p = strrchr(module_struct, '-');
458         if (p) *p = '\0';
459
460 #if defined(WITHOUT_LIBLTDL) && defined (WITH_DLOPEN) && defined(RTLD_SELF)
461         module = lt_dlsym(RTLD_SELF, module_struct);
462         if (module) goto open_self;
463 #endif
464
465         /*
466          *      Keep the handle around so we can dlclose() it.
467          */
468         handle = fr_dlopenext(module_name);
469         if (handle == NULL) {
470                 cf_log_err(cf_sectiontoitem(cs),
471                            "Failed to link to module '%s': %s\n",
472                            module_name, lt_dlerror());
473                 return NULL;
474         }
475
476         DEBUG3("    (Loaded %s, checking if it's valid)", module_name);
477
478         /*
479          *      libltld MAY core here, if the handle it gives us contains
480          *      garbage data.
481          */
482         module = lt_dlsym(handle, module_struct);
483         if (!module) {
484                 cf_log_err(cf_sectiontoitem(cs),
485                            "Failed linking to %s structure: %s\n",
486                            module_name, lt_dlerror());
487                 lt_dlclose(handle);
488                 return NULL;
489         }
490
491 #if defined(WITHOUT_LIBLTDL) && defined (WITH_DLOPEN) && defined(RTLD_SELF)
492  open_self:
493 #endif
494         /*
495          *      Before doing anything else, check if it's sane.
496          */
497         if (module->magic != RLM_MODULE_MAGIC_NUMBER) {
498                 lt_dlclose(handle);
499                 cf_log_err(cf_sectiontoitem(cs),
500                            "Invalid version in module '%s'",
501                            module_name);
502                 return NULL;
503
504         }
505
506         /* make room for the module type */
507         node = rad_malloc(sizeof(*node));
508         memset(node, 0, sizeof(*node));
509         strlcpy(node->name, module_name, sizeof(node->name));
510         node->module = module;
511         node->handle = handle;
512
513         cf_log_module(cs, "Linked to module %s", module_name);
514
515         /*
516          *      Add the module as "rlm_foo-version" to the configuration
517          *      section.
518          */
519         if (!rbtree_insert(module_tree, node)) {
520                 radlog(L_ERR, "Failed to cache module %s", module_name);
521                 lt_dlclose(handle);
522                 free(node);
523                 return NULL;
524         }
525
526         return node;
527 }
528
529 /*
530  *      Find a module instance.
531  */
532 module_instance_t *find_module_instance(CONF_SECTION *modules,
533                                         const char *instname, int do_link)
534 {
535         int check_config_safe = FALSE;
536         CONF_SECTION *cs;
537         const char *name1;
538         module_instance_t *node, myNode;
539         char module_name[256];
540
541         if (!modules) return NULL;
542
543         /*
544          *      Module instances are declared in the modules{} block
545          *      and referenced later by their name, which is the
546          *      name2 from the config section, or name1 if there was
547          *      no name2.
548          */
549         cs = cf_section_sub_find_name2(modules, NULL, instname);
550         if (cs == NULL) {
551                 radlog(L_ERR, "ERROR: Cannot find a configuration entry for module \"%s\".\n", instname);
552                 return NULL;
553         }
554
555         /*
556          *      If there's already a module instance, return it.
557          */
558         strlcpy(myNode.name, instname, sizeof(myNode.name));
559         node = rbtree_finddata(instance_tree, &myNode);
560         if (node) return node;
561
562         if (!do_link) return NULL;
563
564         name1 = cf_section_name1(cs);
565
566         /*
567          *      Found the configuration entry.
568          */
569         node = rad_malloc(sizeof(*node));
570         memset(node, 0, sizeof(*node));
571
572         node->insthandle = NULL;
573         node->cs = cs;
574
575         /*
576          *      Names in the "modules" section aren't prefixed
577          *      with "rlm_", so we add it here.
578          */
579         snprintf(module_name, sizeof(module_name), "rlm_%s", name1);
580
581         node->entry = linkto_module(module_name, cs);
582         if (!node->entry) {
583                 free(node);
584                 /* linkto_module logs any errors */
585                 return NULL;
586         }
587
588         if (check_config && (node->entry->module->instantiate) &&
589             (node->entry->module->type & RLM_TYPE_CHECK_CONFIG_SAFE) == 0) {
590                 const char *value = NULL;
591                 CONF_PAIR *cp;
592
593                 cp = cf_pair_find(cs, "force_check_config");
594                 if (cp) value = cf_pair_value(cp);
595
596                 if (value && (strcmp(value, "yes") == 0)) goto print_inst;
597
598                 cf_log_module(cs, "Skipping instantiation of %s", instname);
599         } else {
600         print_inst:
601                 check_config_safe = TRUE;
602                 cf_log_module(cs, "Instantiating module \"%s\" from file %s",
603                               instname, cf_section_filename(cs));
604         }
605
606         /*
607          *      Call the module's instantiation routine.
608          */
609         if ((node->entry->module->instantiate) &&
610             (!check_config || check_config_safe) &&
611             ((node->entry->module->instantiate)(cs, &node->insthandle) < 0)) {
612                 cf_log_err(cf_sectiontoitem(cs),
613                            "Instantiation failed for module \"%s\"",
614                            instname);
615                 free(node);
616                 return NULL;
617         }
618
619         /*
620          *      We're done.  Fill in the rest of the data structure,
621          *      and link it to the module instance list.
622          */
623         strlcpy(node->name, instname, sizeof(node->name));
624
625 #ifdef HAVE_PTHREAD_H
626         /*
627          *      If we're threaded, check if the module is thread-safe.
628          *
629          *      If it isn't, we create a mutex.
630          */
631         if ((node->entry->module->type & RLM_TYPE_THREAD_UNSAFE) != 0) {
632                 node->mutex = (pthread_mutex_t *) rad_malloc(sizeof(pthread_mutex_t));
633                 /*
634                  *      Initialize the mutex.
635                  */
636                 pthread_mutex_init(node->mutex, NULL);
637         } else {
638                 /*
639                  *      The module is thread-safe.  Don't give it a mutex.
640                  */
641                 node->mutex = NULL;
642         }
643
644 #endif
645         rbtree_insert(instance_tree, node);
646
647         return node;
648 }
649
650 static indexed_modcallable *lookup_by_index(rbtree_t *components,
651                                             int comp, int idx)
652 {
653         indexed_modcallable myc;
654         
655         myc.comp = comp;
656         myc.idx = idx;
657
658         return rbtree_finddata(components, &myc);
659 }
660
661 /*
662  *      Create a new sublist.
663  */
664 static indexed_modcallable *new_sublist(rbtree_t *components, int comp, int idx)
665 {
666         indexed_modcallable *c;
667
668         c = lookup_by_index(components, comp, idx);
669
670         /* It is an error to try to create a sublist that already
671          * exists. It would almost certainly be caused by accidental
672          * duplication in the config file.
673          *
674          * index 0 is the exception, because it is used when we want
675          * to collect _all_ listed modules under a single index by
676          * default, which is currently the case in all components
677          * except authenticate. */
678         if (c) {
679                 if (idx == 0) {
680                         return c;
681                 }
682                 return NULL;
683         }
684
685         c = rad_malloc(sizeof(*c));
686         c->modulelist = NULL;
687         c->comp = comp;
688         c->idx = idx;
689
690         if (!rbtree_insert(components, c)) {
691                 free(c);
692                 return NULL;
693         }
694
695         return c;
696 }
697
698 int indexed_modcall(int comp, int idx, REQUEST *request)
699 {
700         int rcode;
701         modcallable *list = NULL;
702         virtual_server_t *server;
703
704         /*
705          *      Hack to find the correct virtual server.
706          */
707         rcode = virtual_server_idx(request->server);
708         for (server = virtual_servers[rcode];
709              server != NULL;
710              server = server->next) {
711                 if (!request->server && !server->name) break;
712
713                 if ((request->server && server->name) &&
714                     (strcmp(request->server, server->name) == 0)) break;
715         }
716
717         if (!server) {
718                 RDEBUG("No such virtual server \"%s\"", request->server);
719                 return RLM_MODULE_FAIL;
720         }
721
722         if (idx == 0) {
723                 list = server->mc[comp];
724                 if (!list) RDEBUG2("  WARNING: Empty %s section.  Using default return values.", section_type_value[comp].section);
725
726         } else {
727                 indexed_modcallable *this;
728
729                 this = lookup_by_index(server->components, comp, idx);
730                 if (this) {
731                         list = this->modulelist;
732                 } else {
733                         RDEBUG2("  WARNING: Unknown value specified for %s.  Cannot perform requested action.",
734                                 section_type_value[comp].typename);
735                 }
736         }
737         
738         if (server->subcs[comp]) {
739                 if (idx == 0) {
740                         RDEBUG("# Executing section %s from file %s",
741                                section_type_value[comp].section,
742                                cf_section_filename(server->subcs[comp]));
743                 } else {
744                         RDEBUG("# Executing group from file %s",
745                                cf_section_filename(server->subcs[comp]));
746                 }
747         }
748         request->component = section_type_value[comp].section;
749
750         rcode = modcall(comp, list, request);
751
752         request->module = "";
753         request->component = "<core>";
754         return rcode;
755 }
756
757 /*
758  *      Load a sub-module list, as found inside an Auth-Type foo {}
759  *      block
760  */
761 static int load_subcomponent_section(modcallable *parent, CONF_SECTION *cs,
762                                      rbtree_t *components, int attr, int comp)
763 {
764         indexed_modcallable *subcomp;
765         modcallable *ml;
766         DICT_VALUE *dval;
767         const char *name2 = cf_section_name2(cs);
768
769         rad_assert(comp >= RLM_COMPONENT_AUTH);
770         rad_assert(comp < RLM_COMPONENT_COUNT);
771
772         /*
773          *      Sanity check.
774          */
775         if (!name2) {
776                 cf_log_err(cf_sectiontoitem(cs),
777                            "No name specified for %s block",
778                            section_type_value[comp].typename);
779                 return 1;
780         }
781
782         /*
783          *      Compile the group.
784          */
785         ml = compile_modgroup(parent, comp, cs);
786         if (!ml) {
787                 return 0;
788         }
789
790         /*
791          *      We must assign a numeric index to this subcomponent.
792          *      It is generated and placed in the dictionary
793          *      automatically.  If it isn't found, it's a serious
794          *      error.
795          */
796         dval = dict_valbyname(attr, 0, name2);
797         if (!dval) {
798                 cf_log_err(cf_sectiontoitem(cs),
799                            "%s %s Not previously configured",
800                            section_type_value[comp].typename, name2);
801                 modcallable_free(&ml);
802                 return 0;
803         }
804
805         subcomp = new_sublist(components, comp, dval->value);
806         if (!subcomp) {
807                 modcallable_free(&ml);
808                 return 1;
809         }
810
811         subcomp->modulelist = ml;
812         return 1;               /* OK */
813 }
814
815 static int define_type(const DICT_ATTR *dattr, const char *name)
816 {
817         uint32_t value;
818         DICT_VALUE *dval;
819
820         /*
821          *      If the value already exists, don't
822          *      create it again.
823          */
824         dval = dict_valbyname(dattr->attr, dattr->vendor, name);
825         if (dval) return 1;
826
827         /*
828          *      Create a new unique value with a
829          *      meaningless number.  You can't look at
830          *      it from outside of this code, so it
831          *      doesn't matter.  The only requirement
832          *      is that it's unique.
833          */
834         do {
835                 value = fr_rand() & 0x00ffffff;
836         } while (dict_valbyattr(dattr->attr, dattr->vendor, value));
837
838         if (dict_addvalue(name, dattr->name, value) < 0) {
839                 radlog(L_ERR, "%s", fr_strerror());
840                 return 0;
841         }
842
843         return 1;
844 }
845
846 static int load_component_section(CONF_SECTION *cs,
847                                   rbtree_t *components, int comp)
848 {
849         modcallable *this;
850         CONF_ITEM *modref;
851         int idx;
852         indexed_modcallable *subcomp;
853         const char *modname;
854         const char *visiblename;
855         const DICT_ATTR *dattr;
856
857         /*
858          *      Find the attribute used to store VALUEs for this section.
859          */
860         dattr = dict_attrbyvalue(section_type_value[comp].attr, 0);
861         if (!dattr) {
862                 cf_log_err(cf_sectiontoitem(cs),
863                            "No such attribute %s",
864                            section_type_value[comp].typename);
865                 return -1;
866         }
867
868         /*
869          *      Loop over the entries in the named section, loading
870          *      the sections this time.
871          */
872         for (modref = cf_item_find_next(cs, NULL);
873              modref != NULL;
874              modref = cf_item_find_next(cs, modref)) {
875                 const char *name1;
876                 CONF_PAIR *cp = NULL;
877                 CONF_SECTION *scs = NULL;
878
879                 if (cf_item_is_section(modref)) {
880                         scs = cf_itemtosection(modref);
881
882                         name1 = cf_section_name1(scs);
883
884                         if (strcmp(name1,
885                                    section_type_value[comp].typename) == 0) {
886                                 if (!load_subcomponent_section(NULL, scs,
887                                                                components,
888                                                                dattr->attr,
889                                                                comp)) {
890                                         return -1; /* FIXME: memleak? */
891                                 }
892                                 continue;
893                         }
894
895                         cp = NULL;
896
897                 } else if (cf_item_is_pair(modref)) {
898                         cp = cf_itemtopair(modref);
899
900                 } else {
901                         continue; /* ignore it */
902                 }
903
904                 /*
905                  *      Try to compile one entry.
906                  */
907                 this = compile_modsingle(NULL, comp, modref, &modname);
908                 if (!this) {
909                         cf_log_err(cf_sectiontoitem(cs),
910                                    "Errors parsing %s section.\n",
911                                    cf_section_name1(cs));
912                         return -1;
913                 }
914
915                 /*
916                  *      Look for Auth-Type foo {}, which are special
917                  *      cases of named sections, and allowable ONLY
918                  *      at the top-level.
919                  *
920                  *      i.e. They're not allowed in a "group" or "redundant"
921                  *      subsection.
922                  */
923                 if (comp == RLM_COMPONENT_AUTH) {
924                         DICT_VALUE *dval;
925                         const char *modrefname = NULL;
926                         if (cp) {
927                                 modrefname = cf_pair_attr(cp);
928                         } else {
929                                 modrefname = cf_section_name2(scs);
930                                 if (!modrefname) {
931                                         modcallable_free(&this);
932                                         cf_log_err(cf_sectiontoitem(cs),
933                                                    "Errors parsing %s sub-section.\n",
934                                                    cf_section_name1(scs));
935                                         return -1;
936                                 }
937                         }
938
939                         dval = dict_valbyname(PW_AUTH_TYPE, 0, modrefname);
940                         if (!dval) {
941                                 /*
942                                  *      It's a section, but nothing we
943                                  *      recognize.  Die!
944                                  */
945                                 modcallable_free(&this);
946                                 cf_log_err(cf_sectiontoitem(cs),
947                                            "Unknown Auth-Type \"%s\" in %s sub-section.",
948                                            modrefname, section_type_value[comp].section);
949                                 return -1;
950                         }
951                         idx = dval->value;
952                 } else {
953                         /* See the comment in new_sublist() for explanation
954                          * of the special index 0 */
955                         idx = 0;
956                 }
957
958                 subcomp = new_sublist(components, comp, idx);
959                 if (subcomp == NULL) {
960                         modcallable_free(&this);
961                         continue;
962                 }
963
964                 /* If subcomp->modulelist is NULL, add_to_modcallable will
965                  * create it */
966                 visiblename = cf_section_name2(cs);
967                 if (visiblename == NULL)
968                         visiblename = cf_section_name1(cs);
969                 add_to_modcallable(&subcomp->modulelist, this,
970                                    comp, visiblename);
971         }
972
973         return 0;
974 }
975
976 static int load_byserver(CONF_SECTION *cs)
977 {
978         int comp, flag;
979         const char *name = cf_section_name2(cs);
980         rbtree_t *components;
981         virtual_server_t *server = NULL;
982         indexed_modcallable *c;
983
984         if (name) {
985                 cf_log_info(cs, "server %s { # from file %s",
986                             name, cf_section_filename(cs));
987         } else {
988                 cf_log_info(cs, "server { # from file %s",
989                             cf_section_filename(cs));
990         }
991
992         cf_log_info(cs, " modules {");
993
994         components = rbtree_create(indexed_modcallable_cmp,
995                                    indexed_modcallable_free, 0);
996         if (!components) {
997                 radlog(L_ERR, "Failed to initialize components\n");
998                 goto error;
999         }
1000
1001         server = rad_malloc(sizeof(*server));
1002         memset(server, 0, sizeof(*server));
1003
1004         server->name = name;
1005         server->created = time(NULL);
1006         server->cs = cs;
1007         server->components = components;
1008
1009         /*
1010          *      Define types first.
1011          */
1012         for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
1013                 CONF_SECTION *subcs;
1014                 CONF_ITEM *modref;
1015                 DICT_ATTR *dattr;
1016
1017                 subcs = cf_section_sub_find(cs,
1018                                             section_type_value[comp].section);
1019                 if (!subcs) continue;
1020                         
1021                 if (cf_item_find_next(subcs, NULL) == NULL) continue;
1022
1023                 /*
1024                  *      Find the attribute used to store VALUEs for this section.
1025                  */
1026                 dattr = dict_attrbyvalue(section_type_value[comp].attr, 0);
1027                 if (!dattr) {
1028                         cf_log_err(cf_sectiontoitem(subcs),
1029                                    "No such attribute %s",
1030                                    section_type_value[comp].typename);
1031                 error:
1032                         if (debug_flag == 0) {
1033                                 radlog(L_ERR, "Failed to load virtual server %s",
1034                                        (name != NULL) ? name : "<default>");
1035                         }
1036                         virtual_server_free(server);
1037                         return -1;
1038                 }
1039
1040                 /*
1041                  *      Define dynamic types, so that others can reference
1042                  *      them.
1043                  */
1044                 for (modref = cf_item_find_next(subcs, NULL);
1045                      modref != NULL;
1046                      modref = cf_item_find_next(subcs, modref)) {
1047                         const char *name1;
1048                         CONF_SECTION *subsubcs;
1049
1050                         /*
1051                          *      Create types for simple references
1052                          *      only when parsing the authenticate
1053                          *      section.
1054                          */
1055                         if ((section_type_value[comp].attr == PW_AUTH_TYPE) &&
1056                             cf_item_is_pair(modref)) {
1057                                 CONF_PAIR *cp = cf_itemtopair(modref);
1058                                 if (!define_type(dattr, cf_pair_attr(cp))) {
1059                                         goto error;
1060                                 }
1061
1062                                 continue;
1063                         }
1064
1065                         if (!cf_item_is_section(modref)) continue;
1066                         
1067                         subsubcs = cf_itemtosection(modref);
1068                         name1 = cf_section_name1(subsubcs);
1069                 
1070                         if (strcmp(name1, section_type_value[comp].typename) == 0) {
1071                                 if (!define_type(dattr,
1072                                                  cf_section_name2(subsubcs))) {
1073                                         goto error;
1074                                 }
1075                         }
1076                 }
1077         } /* loop over components */
1078
1079         /*
1080          *      Loop over all of the known components, finding their
1081          *      configuration section, and loading it.
1082          */
1083         flag = 0;
1084         for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
1085                 CONF_SECTION *subcs;
1086
1087                 subcs = cf_section_sub_find(cs,
1088                                             section_type_value[comp].section);
1089                 if (!subcs) continue;
1090                         
1091                 if (cf_item_find_next(subcs, NULL) == NULL) continue;
1092                         
1093                 cf_log_module(cs, "Checking %s {...} for more modules to load",
1094                        section_type_value[comp].section);
1095
1096 #ifdef WITH_PROXY
1097                 /*
1098                  *      Skip pre/post-proxy sections if we're not
1099                  *      proxying.
1100                  */
1101                 if (!mainconfig.proxy_requests &&
1102                     ((comp == PW_PRE_PROXY_TYPE) ||
1103                      (comp == PW_PRE_PROXY_TYPE))) {
1104                         continue;
1105                 }
1106 #endif
1107
1108                 if (load_component_section(subcs, components, comp) < 0) {
1109                         goto error;
1110                 }
1111
1112                 /*
1113                  *      Cache a default, if it exists.  Some people
1114                  *      put empty sections for some reason...
1115                  */
1116                 c = lookup_by_index(components, comp, 0);
1117                 if (c) server->mc[comp] = c->modulelist;
1118
1119                 server->subcs[comp] = subcs;
1120
1121                 flag = 1;
1122         } /* loop over components */
1123
1124         /*
1125          *      We haven't loaded any of the normal sections.  Maybe we're
1126          *      supposed to load the vmps section.
1127          *
1128          *      This is a bit of a hack...
1129          */
1130         if (!flag) {
1131                 CONF_SECTION *subcs;
1132
1133                 subcs = cf_section_sub_find(cs, "vmps");
1134                 if (subcs) {
1135                         cf_log_module(cs, "Checking vmps {...} for more modules to load");              
1136                         if (load_component_section(subcs, components,
1137                                                    RLM_COMPONENT_POST_AUTH) < 0) {
1138                                 goto error;
1139                         }
1140                         c = lookup_by_index(components,
1141                                             RLM_COMPONENT_POST_AUTH, 0);
1142                         if (c) server->mc[RLM_COMPONENT_POST_AUTH] = c->modulelist;
1143                         flag = 1;
1144                 }
1145
1146 #ifdef WITH_DHCP
1147                 if (!flag) {
1148                         const DICT_ATTR *dattr;
1149
1150                         dattr = dict_attrbyname("DHCP-Message-Type");
1151
1152                         /*
1153                          *      Handle each DHCP Message type separately.
1154                          */
1155                         if (dattr) for (subcs = cf_subsection_find_next(cs, NULL, "dhcp");
1156                                         subcs != NULL;
1157                                         subcs = cf_subsection_find_next(cs, subcs,
1158                                                                         "dhcp")) {
1159                                 const char *name2 = cf_section_name2(subcs);
1160
1161                                 DEBUG2(" Module: Checking dhcp %s {...} for more modules to load", name2);
1162                                 if (!load_subcomponent_section(NULL, subcs,
1163                                                                components,
1164                                                                dattr->attr,
1165                                                                RLM_COMPONENT_POST_AUTH)) {
1166                                         goto error; /* FIXME: memleak? */
1167                                 }
1168                                 c = lookup_by_index(components,
1169                                                     RLM_COMPONENT_POST_AUTH, 0);
1170                                 if (c) server->mc[RLM_COMPONENT_POST_AUTH] = c->modulelist;
1171                                 flag = 1;
1172                         }
1173                 }
1174 #endif
1175         }
1176
1177         cf_log_info(cs, " } # modules");
1178         cf_log_info(cs, "} # server");
1179
1180         if (!flag && name) {
1181                 DEBUG("WARNING: Server %s is empty, and will do nothing!",
1182                       name);
1183         }
1184
1185         if (debug_flag == 0) {
1186                 radlog(L_INFO, "Loaded virtual server %s",
1187                        (name != NULL) ? name : "<default>");
1188         }
1189
1190         /*
1191          *      Now that it is OK, insert it into the list.
1192          *
1193          *      This is thread-safe...
1194          */
1195         comp = virtual_server_idx(name);
1196         server->next = virtual_servers[comp];
1197         virtual_servers[comp] = server;
1198
1199         /*
1200          *      Mark OLDER ones of the same name as being unused.
1201          */
1202         server = server->next;
1203         while (server) {
1204                 if ((!name && !server->name) ||
1205                     (name && server->name &&
1206                      (strcmp(server->name, name) == 0))) {
1207                         server->can_free = TRUE;
1208                         break;
1209                 }
1210                 server = server->next;
1211         }
1212
1213         return 0;
1214 }
1215
1216
1217 /*
1218  *      Load all of the virtual servers.
1219  */
1220 int virtual_servers_load(CONF_SECTION *config)
1221 {
1222         int null_server = FALSE;
1223         CONF_SECTION *cs;
1224         static int first_time = TRUE;
1225
1226         DEBUG2("%s: #### Loading Virtual Servers ####", mainconfig.name);
1227
1228         /*
1229          *      Load all of the virtual servers.
1230          */
1231         for (cs = cf_subsection_find_next(config, NULL, "server");
1232              cs != NULL;
1233              cs = cf_subsection_find_next(config, cs, "server")) {
1234                 if (!cf_section_name2(cs)) null_server = TRUE;
1235
1236                 if (load_byserver(cs) < 0) {
1237                         /*
1238                          *      Once we successfully staryed once,
1239                          *      continue loading the OTHER servers,
1240                          *      even if one fails.
1241                          */
1242                         if (!first_time) continue;
1243                         return -1;
1244                 }
1245         }
1246
1247         /*
1248          *      No empty server defined.  Try to load an old-style
1249          *      one for backwards compatibility.
1250          */
1251         if (!null_server) {
1252                 if (load_byserver(config) < 0) {
1253                         return -1;
1254                 }
1255         }
1256
1257         /*
1258          *      If we succeed the first time around, remember that.
1259          */
1260         first_time = FALSE;
1261
1262         return 0;
1263 }
1264
1265 int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when)
1266 {
1267         void *insthandle = NULL;
1268         fr_module_hup_t *mh;
1269
1270         if (!node ||
1271             !node->entry->module->instantiate ||
1272             ((node->entry->module->type & RLM_TYPE_HUP_SAFE) == 0)) {
1273                 return 1;
1274         }
1275
1276         cf_log_module(cs, "Trying to reload module \"%s\"", node->name);
1277         
1278         if ((node->entry->module->instantiate)(cs, &insthandle) < 0) {
1279                 cf_log_err(cf_sectiontoitem(cs),
1280                            "HUP failed for module \"%s\".  Using old configuration.",
1281                            node->name);
1282                 return 0;
1283         }
1284
1285         radlog(L_INFO, " Module: Reloaded module \"%s\"", node->name);
1286
1287         module_instance_free_old(cs, node, when);
1288
1289         /*
1290          *      Save the old instance handle for later deletion.
1291          */
1292         mh = rad_malloc(sizeof(*mh));
1293         mh->mi = node;
1294         mh->when = when;
1295         mh->insthandle = node->insthandle;
1296         mh->next = node->mh;
1297         node->mh = mh;
1298
1299         node->insthandle = insthandle;
1300         
1301         /*
1302          *      FIXME: Set a timeout to come back in 60s, so that
1303          *      we can pro-actively clean up the old instances.
1304          */
1305
1306         return 1;
1307 }
1308
1309
1310 int module_hup(CONF_SECTION *modules)
1311 {
1312         time_t when;
1313         CONF_ITEM *ci;
1314         CONF_SECTION *cs;
1315         module_instance_t *node;
1316
1317         if (!modules) return 0;
1318
1319         when = time(NULL);
1320
1321         /*
1322          *      Loop over the modules
1323          */
1324         for (ci=cf_item_find_next(modules, NULL);
1325              ci != NULL;
1326              ci=cf_item_find_next(modules, ci)) {
1327                 const char *instname;
1328                 module_instance_t myNode;
1329
1330                 /*
1331                  *      If it's not a section, ignore it.
1332                  */
1333                 if (!cf_item_is_section(ci)) continue;
1334
1335                 cs = cf_itemtosection(ci);
1336                 instname = cf_section_name2(cs);
1337                 if (!instname) instname = cf_section_name1(cs);
1338
1339                 strlcpy(myNode.name, instname, sizeof(myNode.name));
1340                 node = rbtree_finddata(instance_tree, &myNode);
1341
1342                 module_hup_module(cs, node, when);
1343         }
1344
1345         return 1;
1346 }
1347
1348
1349 /*
1350  *      Parse the module config sections, and load
1351  *      and call each module's init() function.
1352  *
1353  *      Libtool makes your life a LOT easier, especially with libltdl.
1354  *      see: http://www.gnu.org/software/libtool/
1355  */
1356 int setup_modules(int reload, CONF_SECTION *config)
1357 {
1358         CONF_SECTION    *cs, *modules;
1359         rad_listen_t    *listener;
1360
1361         if (reload) return 0;
1362
1363         /*
1364          *      If necessary, initialize libltdl.
1365          */
1366         if (!reload) {
1367                 /*
1368                  *      This line works around a completely
1369                  *
1370                  *              RIDICULOUS INSANE IDIOTIC
1371                  *
1372                  *      bug in libltdl on certain systems.  The "set
1373                  *      preloaded symbols" macro below ends up
1374                  *      referencing this name, but it isn't defined
1375                  *      anywhere in the libltdl source.  As a result,
1376                  *      any program STUPID enough to rely on libltdl
1377                  *      fails to link, because the symbol isn't
1378                  *      defined anywhere.
1379                  *
1380                  *      It's like libtool and libltdl are some kind
1381                  *      of sick joke.
1382                  */
1383 #ifdef IE_LIBTOOL_DIE
1384 #define lt__PROGRAM__LTX_preloaded_symbols lt_libltdl_LTX_preloaded_symbols
1385 #endif
1386
1387                 /*
1388                  *      Set the default list of preloaded symbols.
1389                  *      This is used to initialize libltdl's list of
1390                  *      preloaded modules.
1391                  *
1392                  *      i.e. Static modules.
1393                  */
1394                 LTDL_SET_PRELOADED_SYMBOLS();
1395
1396                 if (lt_dlinit() != 0) {
1397                         radlog(L_ERR, "Failed to initialize libraries: %s\n",
1398                                         lt_dlerror());
1399                         return -1;
1400                 }
1401
1402                 /*
1403                  *      Set the search path to ONLY our library directory.
1404                  *      This prevents the modules from being found from
1405                  *      any location on the disk.
1406                  */
1407                 lt_dlsetsearchpath(radlib_dir);
1408
1409                 /*
1410                  *      Set up the internal module struct.
1411                  */
1412                 module_tree = rbtree_create(module_entry_cmp,
1413                                             module_entry_free, 0);
1414                 if (!module_tree) {
1415                         radlog(L_ERR, "Failed to initialize modules\n");
1416                         return -1;
1417                 }
1418
1419                 instance_tree = rbtree_create(module_instance_cmp,
1420                                               module_instance_free, 0);
1421                 if (!instance_tree) {
1422                         radlog(L_ERR, "Failed to initialize modules\n");
1423                         return -1;
1424                 }
1425         }
1426
1427         memset(virtual_servers, 0, sizeof(virtual_servers));
1428
1429         /*
1430          *      Remember where the modules were stored.
1431          */
1432         modules = cf_section_sub_find(config, "modules");
1433         if (!modules) {
1434                 radlog(L_ERR, "Cannot find a \"modules\" section in the configuration file!");
1435                 return -1;
1436         }
1437
1438         DEBUG2("%s: #### Instantiating modules ####", mainconfig.name);
1439
1440         /*
1441          *  Look for the 'instantiate' section, which tells us
1442          *  the instantiation order of the modules, and also allows
1443          *  us to load modules with no authorize/authenticate/etc.
1444          *  sections.
1445          */
1446         cs = cf_section_sub_find(config, "instantiate");
1447         if (cs != NULL) {
1448                 CONF_ITEM *ci;
1449                 CONF_PAIR *cp;
1450                 module_instance_t *module;
1451                 const char *name;
1452
1453                 cf_log_info(cs, " instantiate {");
1454
1455                 /*
1456                  *  Loop over the items in the 'instantiate' section.
1457                  */
1458                 for (ci=cf_item_find_next(cs, NULL);
1459                      ci != NULL;
1460                      ci=cf_item_find_next(cs, ci)) {
1461
1462                         /*
1463                          *      Skip sections and "other" stuff.
1464                          *      Sections will be handled later, if
1465                          *      they're referenced at all...
1466                          */
1467                         if (!cf_item_is_pair(ci)) {
1468                                 continue;
1469                         }
1470
1471                         cp = cf_itemtopair(ci);
1472                         name = cf_pair_attr(cp);
1473                         module = find_module_instance(modules, name, 1);
1474                         if (!module) {
1475                                 return -1;
1476                         }
1477                 } /* loop over items in the subsection */
1478
1479                 cf_log_info(cs, " }");
1480         } /* if there's an 'instantiate' section. */
1481
1482         /*
1483          *      Loop over the listeners, figuring out which sections
1484          *      to load.
1485          */
1486         for (listener = mainconfig.listen;
1487              listener != NULL;
1488              listener = listener->next) {
1489                 char buffer[256];
1490
1491 #ifdef WITH_PROXY
1492                 if (listener->type == RAD_LISTEN_PROXY) continue;
1493 #endif
1494
1495                 cs = cf_section_sub_find_name2(config,
1496                                                "server", listener->server);
1497                 if (!cs && (listener->server != NULL)) {
1498                         listener->print(listener, buffer, sizeof(buffer));
1499
1500                         radlog(L_ERR, "No server has been defined for %s", buffer);
1501                         return -1;
1502                 }
1503         }
1504
1505         if (virtual_servers_load(config) < 0) return -1;
1506
1507         return 0;
1508 }
1509
1510 /*
1511  *      Call all authorization modules until one returns
1512  *      somethings else than RLM_MODULE_OK
1513  */
1514 int module_authorize(int autz_type, REQUEST *request)
1515 {
1516         return indexed_modcall(RLM_COMPONENT_AUTZ, autz_type, request);
1517 }
1518
1519 /*
1520  *      Authenticate a user/password with various methods.
1521  */
1522 int module_authenticate(int auth_type, REQUEST *request)
1523 {
1524         return indexed_modcall(RLM_COMPONENT_AUTH, auth_type, request);
1525 }
1526
1527 #ifdef WITH_ACCOUNTING
1528 /*
1529  *      Do pre-accounting for ALL configured sessions
1530  */
1531 int module_preacct(REQUEST *request)
1532 {
1533         return indexed_modcall(RLM_COMPONENT_PREACCT, 0, request);
1534 }
1535
1536 /*
1537  *      Do accounting for ALL configured sessions
1538  */
1539 int module_accounting(int acct_type, REQUEST *request)
1540 {
1541         return indexed_modcall(RLM_COMPONENT_ACCT, acct_type, request);
1542 }
1543 #endif
1544
1545 #ifdef WITH_SESSION_MGMT
1546 /*
1547  *      See if a user is already logged in.
1548  *
1549  *      Returns: 0 == OK, 1 == double logins, 2 == multilink attempt
1550  */
1551 int module_checksimul(int sess_type, REQUEST *request, int maxsimul)
1552 {
1553         int rcode;
1554
1555         if(!request->username)
1556                 return 0;
1557
1558         request->simul_count = 0;
1559         request->simul_max = maxsimul;
1560         request->simul_mpp = 1;
1561
1562         rcode = indexed_modcall(RLM_COMPONENT_SESS, sess_type, request);
1563
1564         if (rcode != RLM_MODULE_OK) {
1565                 /* FIXME: Good spot for a *rate-limited* warning to the log */
1566                 return 0;
1567         }
1568
1569         return (request->simul_count < maxsimul) ? 0 : request->simul_mpp;
1570 }
1571 #endif
1572
1573 #ifdef WITH_PROXY
1574 /*
1575  *      Do pre-proxying for ALL configured sessions
1576  */
1577 int module_pre_proxy(int type, REQUEST *request)
1578 {
1579         return indexed_modcall(RLM_COMPONENT_PRE_PROXY, type, request);
1580 }
1581
1582 /*
1583  *      Do post-proxying for ALL configured sessions
1584  */
1585 int module_post_proxy(int type, REQUEST *request)
1586 {
1587         return indexed_modcall(RLM_COMPONENT_POST_PROXY, type, request);
1588 }
1589 #endif
1590
1591 /*
1592  *      Do post-authentication for ALL configured sessions
1593  */
1594 int module_post_auth(int postauth_type, REQUEST *request)
1595 {
1596         return indexed_modcall(RLM_COMPONENT_POST_AUTH, postauth_type, request);
1597 }
1598
1599 #ifdef WITH_COA
1600 int module_recv_coa(int recv_coa_type, REQUEST *request)
1601 {
1602         return indexed_modcall(RLM_COMPONENT_RECV_COA, recv_coa_type, request);
1603 }
1604
1605 int module_send_coa(int send_coa_type, REQUEST *request)
1606 {
1607         return indexed_modcall(RLM_COMPONENT_SEND_COA, send_coa_type, request);
1608 }
1609 #endif