2 * This program is is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * @brief Translates requests between the server an a perl interpreter.
22 * @copyright 2002,2006 The FreeRADIUS server project
23 * @copyright 2002 Boian Jordanov <bjordanov@orbitel.bg>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/rad_assert.h>
38 #include <semaphore.h>
41 extern char **environ;
45 * Define a structure for our module configuration.
47 * These variables do not need to be in a structure, but it's
48 * a lot cleaner to do so, and a pointer to the structure can
49 * be used as the instance handle.
51 typedef struct rlm_perl_t {
52 /* Name of the perl module */
55 /* Name of the functions for each module method */
56 char const *func_authorize;
57 char const *func_authenticate;
58 char const *func_accounting;
59 char const *func_start_accounting;
60 char const *func_stop_accounting;
61 char const *func_preacct;
62 char const *func_checksimul;
63 char const *func_detach;
64 char const *func_xlat;
66 char const *func_pre_proxy;
67 char const *func_post_proxy;
69 char const *func_post_auth;
71 char const *func_recv_coa;
72 char const *func_send_coa;
74 char const *xlat_name;
75 char const *perl_flags;
76 PerlInterpreter *perl;
78 pthread_key_t *thread_key;
81 pthread_mutex_t clone_mutex;
84 HV *rad_perlconf_hv; //!< holds "config" items (perl %RAD_PERLCONF hash).
88 * A mapping of configuration file names to internal variables.
90 #define RLM_PERL_CONF(_x) { "func_" STRINGIFY(_x), PW_TYPE_STRING, \
91 offsetof(rlm_perl_t,func_##_x), NULL, STRINGIFY(_x)}
93 static const CONF_PARSER module_config[] = {
94 { "module", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, rlm_perl_t, module), NULL },
95 { "filename", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_REQUIRED, rlm_perl_t, module), NULL },
97 RLM_PERL_CONF(authorize),
98 RLM_PERL_CONF(authenticate),
99 RLM_PERL_CONF(post_auth),
100 RLM_PERL_CONF(accounting),
101 RLM_PERL_CONF(preacct),
102 RLM_PERL_CONF(checksimul),
103 RLM_PERL_CONF(detach),
107 RLM_PERL_CONF(pre_proxy),
108 RLM_PERL_CONF(post_proxy),
111 RLM_PERL_CONF(recv_coa),
112 RLM_PERL_CONF(send_coa),
114 { "perl_flags", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_perl_t, perl_flags), NULL },
116 { "func_start_accounting", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_perl_t, func_start_accounting), NULL },
118 { "func_stop_accounting", FR_CONF_OFFSET(PW_TYPE_STRING, rlm_perl_t, func_stop_accounting), NULL },
120 { NULL, -1, 0, NULL, NULL } /* end the list */
126 EXTERN_C void boot_DynaLoader(pTHX_ CV* cv);
129 # define dl_librefs "DynaLoader::dl_librefs"
130 # define dl_modules "DynaLoader::dl_modules"
131 static void rlm_perl_clear_handles(pTHX)
133 AV *librefs = get_av(dl_librefs, false);
139 static void **rlm_perl_get_handles(pTHX)
142 AV *librefs = get_av(dl_librefs, false);
143 AV *modules = get_av(dl_modules, false);
146 if (!librefs) return NULL;
148 if (!(AvFILL(librefs) >= 0)) {
152 handles = (void **)rad_malloc(sizeof(void *) * (AvFILL(librefs)+2));
154 for (i = 0; i <= AvFILL(librefs); i++) {
156 SV *handle_sv = *av_fetch(librefs, i, false);
158 ERROR("Could not fetch $%s[%d]!", dl_librefs, (int)i);
161 handle = (void *)SvIV(handle_sv);
163 if (handle) handles[i] = handle;
169 handles[i] = (void *)0;
174 static void rlm_perl_close_handles(void **handles)
182 for (i = 0; handles[i]; i++) {
183 DEBUG("Close %p", handles[i]);
191 static void rlm_perl_destruct(PerlInterpreter *perl)
195 PERL_SET_CONTEXT(perl);
197 PL_perl_destruct_level = 2;
199 PL_origenviron = environ;
206 * FIXME: This shouldn't happen
209 while (PL_scopestack_ix > 1) {
218 static void rlm_destroy_perl(PerlInterpreter *perl)
223 PERL_SET_CONTEXT(perl);
225 handles = rlm_perl_get_handles(aTHX);
226 if (handles) rlm_perl_close_handles(handles);
227 rlm_perl_destruct(perl);
231 static void rlm_perl_make_key(pthread_key_t *key)
233 pthread_key_create(key, (void (*)(void *))rlm_destroy_perl);
236 static PerlInterpreter *rlm_perl_clone(PerlInterpreter *perl, pthread_key_t *key)
240 PerlInterpreter *interp;
243 PERL_SET_CONTEXT(perl);
245 interp = pthread_getspecific(*key);
246 if (interp) return interp;
248 interp = perl_clone(perl, clone_flags);
252 # if PERL_REVISION >= 5 && PERL_VERSION <8
255 ptr_table_free(PL_ptr_table);
258 PERL_SET_CONTEXT(aTHX);
259 rlm_perl_clear_handles(aTHX);
261 ret = pthread_setspecific(*key, interp);
263 DEBUG("rlm_perl: Failed associating interpretor with thread %s", fr_syserror(ret));
265 rlm_perl_destruct(interp);
274 * This is wrapper for radlog
275 * Now users can call radiusd::radlog(level,msg) wich is the same
276 * calling radlog from C code.
278 static XS(XS_radiusd_radlog)
282 croak("Usage: radiusd::radlog(level, message)");
287 level = (int) SvIV(ST(0));
288 msg = (char *) SvPV(ST(1), PL_na);
291 * Because 'msg' is a 'char *', we don't want '%s', etc.
292 * in it to give us printf-style vulnerabilities.
294 radlog(level, "rlm_perl: %s", msg);
299 static void xs_init(pTHX)
301 char const *file = __FILE__;
303 /* DynaLoader is a special case */
304 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
306 newXS("radiusd::radlog",XS_radiusd_radlog, "rlm_perl");
312 static ssize_t perl_xlat(void *instance, REQUEST *request, char const *fmt, char *out, size_t freespace)
315 rlm_perl_t *inst = (rlm_perl_t *) instance;
323 PerlInterpreter *interp;
325 pthread_mutex_lock(&inst->clone_mutex);
326 interp = rlm_perl_clone(inst->perl, inst->thread_key);
329 PERL_SET_CONTEXT(interp);
331 pthread_mutex_unlock(&inst->clone_mutex);
333 PERL_SET_CONTEXT(inst->perl);
348 XPUSHs(sv_2mortal(newSVpvn(p, q - p)));
352 * Don't use an empty string
354 while (*p == ' ') p++;
364 XPUSHs(sv_2mortal(newSVpvn(p, strlen(p))));
369 count = call_pv(inst->func_xlat, G_SCALAR | G_EVAL);
373 REDEBUG("Exit %s", SvPV(ERRSV,n_a));
375 } else if (count > 0) {
377 strlcpy(out, tmp, freespace);
380 RDEBUG("Len is %zu , out is %s freespace is %zu", ret, out, freespace);
393 * Parse a configuration section, and populate a HV.
394 * This function is recursively called (allows to have nested hashes.)
396 static void perl_parse_config(CONF_SECTION *cs, int lvl, HV *rad_hv)
398 if (!cs || !rad_hv) return;
400 int indent_section = (lvl + 1) * 4;
401 int indent_item = (lvl + 2) * 4;
403 DEBUG("%*s%s {", indent_section, " ", cf_section_name1(cs));
405 CONF_ITEM *ci = NULL;
407 while ((ci = cf_item_find_next(cs, ci))) {
410 * Create a new HV, store it as a reference in current HV,
411 * Then recursively call perl_parse_config with this section and the new HV.
413 if (cf_item_is_section(ci)) {
414 CONF_SECTION *sub_cs = cf_item_to_section(ci);
415 char const *key = cf_section_name1(sub_cs); /* hash key */
421 if (hv_exists(rad_hv, key, strlen(key))) {
422 WARN("rlm_perl: Ignoring duplicate config section '%s'", key);
427 ref = newRV_inc((SV*) sub_hv);
429 (void)hv_store(rad_hv, key, strlen(key), ref, 0);
431 perl_parse_config(sub_cs, lvl + 1, sub_hv);
432 } else if (cf_item_is_pair(ci)){
433 CONF_PAIR *cp = cf_item_to_pair(ci);
434 char const *key = cf_pair_attr(cp); /* hash key */
435 char const *value = cf_pair_value(cp); /* hash value */
437 if (!key || !value) continue;
441 * Store item attr / value in current HV.
443 if (hv_exists(rad_hv, key, strlen(key))) {
444 WARN("rlm_perl: Ignoring duplicate config item '%s'", key);
448 (void)hv_store(rad_hv, key, strlen(key), newSVpvn(value, strlen(value)), 0);
450 DEBUG("%*s%s = %s", indent_item, " ", key, value);
454 DEBUG("%*s}", indent_section, " ");
457 static int mod_bootstrap(CONF_SECTION *conf, void *instance)
459 rlm_perl_t *inst = instance;
461 char const *xlat_name;
463 xlat_name = cf_section_name2(conf);
464 if (!xlat_name) xlat_name = cf_section_name1(conf);
466 xlat_register(xlat_name, perl_xlat, NULL, inst);
472 * Do any per-module initialization that is separate to each
473 * configured instance of the module. e.g. set up connections
474 * to external databases, read configuration files, set up
475 * dictionary entries, etc.
477 * If configuration information is given in the config section
478 * that must be referenced in later calls, store a handle to it
479 * in *instance otherwise put a null pointer there.
481 * Setup a hashes wich we will use later
482 * parse a module and give him a chance to live
485 static int mod_instantiate(CONF_SECTION *conf, void *instance)
487 rlm_perl_t *inst = instance;
490 char const **embed_c; /* Stupid Perl and lack of const consistency */
493 int exitstatus = 0, argc=0;
500 * Create pthread key. This key will be stored in instance
502 pthread_mutex_init(&inst->clone_mutex, NULL);
504 inst->thread_key = rad_malloc(sizeof(*inst->thread_key));
505 memset(inst->thread_key,0,sizeof(*inst->thread_key));
507 rlm_perl_make_key(inst->thread_key);
511 * Setup the argument array we pass to the perl interpreter
513 MEM(embed_c = talloc_zero_array(inst, char const *, 4));
514 memcpy(&embed, &embed_c, sizeof(embed));
516 if (inst->perl_flags) {
517 embed_c[1] = inst->perl_flags;
518 embed_c[2] = inst->module;
522 embed_c[1] = inst->module;
528 * Create tweak the server's environment to support
529 * perl. Docs say only call this once... Oops.
531 PERL_SYS_INIT3(&argc, &embed, &envp);
534 * Allocate a new perl interpreter to do the parsing
536 if ((inst->perl = perl_alloc()) == NULL) {
537 ERROR("rlm_perl: No memory for allocating new perl !");
540 perl_construct(inst->perl); /* ...and initialise it */
543 PL_perl_destruct_level = 2;
548 PERL_SET_CONTEXT(inst->perl);
551 #if PERL_REVISION >= 5 && PERL_VERSION >=8
552 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
555 exitstatus = perl_parse(inst->perl, xs_init, argc, embed, NULL);
558 PL_endav = (AV *)NULL;
561 ERROR("rlm_perl: perl_parse failed: %s not found or has syntax errors", inst->module);
565 /* parse perl configuration sub-section */
566 cs = cf_section_sub_find(conf, "config");
568 inst->rad_perlconf_hv = get_hv("RAD_PERLCONF", 1);
569 perl_parse_config(cs, 0, inst->rad_perlconf_hv);
572 inst->perl_parsed = true;
573 perl_run(inst->perl);
580 static void perl_vp_to_svpvn_element(REQUEST *request, AV *av, VALUE_PAIR const *vp,
581 int *i, const char *hash_name, const char *list_name)
587 switch (vp->da->type) {
589 RDEBUG("$%s{'%s'}[%i] = &%s:%s -> '%s'", hash_name, vp->da->name, *i,
590 list_name, vp->da->name, vp->vp_strvalue);
591 av_push(av, newSVpvn(vp->vp_strvalue, vp->vp_length));
595 len = vp_prints_value(buffer, sizeof(buffer), vp, 0);
596 RDEBUG("$%s{'%s'}[%i] = &%s:%s -> '%s'", hash_name, vp->da->name, *i,
597 list_name, vp->da->name, buffer);
598 av_push(av, newSVpvn(buffer, truncate_len(len, sizeof(buffer))));
605 * get the vps and put them in perl hash
606 * If one VP have multiple values it is added as array_ref
607 * Example for this is Cisco-AVPair that holds multiple values.
608 * Which will be available as array_ref in $RAD_REQUEST{'Cisco-AVPair'}
610 static void perl_store_vps(UNUSED TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vps, HV *rad_hv,
611 const char *hash_name, const char *list_name)
620 fr_pair_list_sort(vps, fr_pair_cmp_by_da_tag);
621 for (vp = fr_cursor_init(&cursor, vps);
623 vp = fr_cursor_next(&cursor)) {
633 * Tagged attributes are added to the hash with name
634 * <attribute>:<tag>, others just use the normal attribute
637 if (vp->da->flags.has_tag && (vp->tag != TAG_ANY)) {
638 snprintf(namebuf, sizeof(namebuf), "%s:%d", vp->da->name, vp->tag);
645 * We've sorted by type, then tag, so attributes of the
646 * same type/tag should follow on from each other.
648 if ((next = fr_cursor_next_peek(&cursor)) && ATTRIBUTE_EQ(vp, next)) {
654 perl_vp_to_svpvn_element(request, av, vp, &i, hash_name, list_name);
656 perl_vp_to_svpvn_element(request, av, next, &i, hash_name, list_name);
657 fr_cursor_next(&cursor);
658 } while ((next = fr_cursor_next_peek(&cursor)) && ATTRIBUTE_EQ(vp, next));
659 (void)hv_store(rad_hv, name, strlen(name), newRV_noinc((SV *)av), 0);
665 * It's a normal single valued attribute
667 switch (vp->da->type) {
669 RDEBUG("$%s{'%s'} = &%s:%s -> '%s'", hash_name, vp->da->name, list_name,
670 vp->da->name, vp->vp_strvalue);
671 (void)hv_store(rad_hv, name, strlen(name), newSVpvn(vp->vp_strvalue, vp->vp_length), 0);
675 len = vp_prints_value(buffer, sizeof(buffer), vp, 0);
676 RDEBUG("$%s{'%s'} = &%s:%s -> '%s'", hash_name, vp->da->name,
677 list_name, vp->da->name, buffer);
678 (void)hv_store(rad_hv, name, strlen(name),
679 newSVpvn(buffer, truncate_len(len, sizeof(buffer))), 0);
688 * Verify that a Perl SV is a string and save it in FreeRadius
692 static int pairadd_sv(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vps, char *key, SV *sv, FR_TOKEN op,
693 const char *hash_name, const char *list_name)
701 vp = fr_pair_make(ctx, vps, key, NULL, op);
704 REDEBUG("Failed to create pair %s:%s %s %s", list_name, key,
705 fr_int2str(fr_tokens, op, "<INVALID>"), val);
709 switch (vp->da->type) {
711 fr_pair_value_bstrncpy(vp, val, len);
715 if (fr_pair_value_from_str(vp, val, len) < 0) goto fail;
718 RDEBUG("&%s:%s %s $%s{'%s'} -> '%s'", list_name, key, fr_int2str(fr_tokens, op, "<INVALID>"),
719 hash_name, key, val);
726 * Gets the content from hashes
728 static int get_hv_content(TALLOC_CTX *ctx, REQUEST *request, HV *my_hv, VALUE_PAIR **vps,
729 const char *hash_name, const char *list_name)
734 I32 key_len, len, i, j;
738 for (i = hv_iterinit(my_hv); i > 0; i--) {
739 res_sv = hv_iternextsv(my_hv,&key,&key_len);
740 if (SvROK(res_sv) && (SvTYPE(SvRV(res_sv)) == SVt_PVAV)) {
741 av = (AV*)SvRV(res_sv);
743 for (j = 0; j <= len; j++) {
744 av_sv = av_fetch(av, j, 0);
745 ret = pairadd_sv(ctx, request, vps, key, *av_sv, T_OP_ADD, hash_name, list_name) + ret;
747 } else ret = pairadd_sv(ctx, request, vps, key, res_sv, T_OP_EQ, hash_name, list_name) + ret;
754 * Call the function_name inside the module
755 * Store all vps in hashes %RAD_CHECK %RAD_REPLY %RAD_REQUEST
758 static int do_perl(void *instance, REQUEST *request, char const *function_name)
761 rlm_perl_t *inst = instance;
763 int exitstatus=0, count;
771 HV *rad_request_proxy_hv;
772 HV *rad_request_proxy_reply_hv;
776 * Radius has told us to call this function, but none
779 if (!function_name) return RLM_MODULE_FAIL;
782 pthread_mutex_lock(&inst->clone_mutex);
784 PerlInterpreter *interp;
786 interp = rlm_perl_clone(inst->perl,inst->thread_key);
789 PERL_SET_CONTEXT(interp);
792 pthread_mutex_unlock(&inst->clone_mutex);
794 PERL_SET_CONTEXT(inst->perl);
803 rad_reply_hv = get_hv("RAD_REPLY", 1);
804 rad_check_hv = get_hv("RAD_CHECK", 1);
805 rad_config_hv = get_hv("RAD_CONFIG", 1);
806 rad_request_hv = get_hv("RAD_REQUEST", 1);
808 perl_store_vps(request->packet, request, &request->packet->vps, rad_request_hv, "RAD_REQUEST", "request");
809 perl_store_vps(request->reply, request, &request->reply->vps, rad_reply_hv, "RAD_REPLY", "reply");
810 perl_store_vps(request, request, &request->config, rad_check_hv, "RAD_CHECK", "control");
811 perl_store_vps(request, request, &request->config, rad_config_hv, "RAD_CONFIG", "control");
814 rad_request_proxy_hv = get_hv("RAD_REQUEST_PROXY",1);
815 rad_request_proxy_reply_hv = get_hv("RAD_REQUEST_PROXY_REPLY",1);
817 if (request->proxy != NULL) {
818 perl_store_vps(request->proxy, request, &request->proxy->vps, rad_request_proxy_hv,
819 "RAD_REQUEST_PROXY", "proxy-request");
821 hv_undef(rad_request_proxy_hv);
824 if (request->proxy_reply != NULL) {
825 perl_store_vps(request->proxy_reply, request, &request->proxy_reply->vps,
826 rad_request_proxy_reply_hv, "RAD_REQUEST_PROXY_REPLY", "proxy-reply");
828 hv_undef(rad_request_proxy_reply_hv);
834 * This way %RAD_xx can be pushed onto stack as sub parameters.
835 * XPUSHs( newRV_noinc((SV *)rad_request_hv) );
836 * XPUSHs( newRV_noinc((SV *)rad_reply_hv) );
837 * XPUSHs( newRV_noinc((SV *)rad_check_hv) );
841 count = call_pv(function_name, G_SCALAR | G_EVAL | G_NOARGS);
846 RDEBUG("perl_embed:: module = %s , func = %s exit status= %s\n",
847 inst->module, function_name, SvPV(ERRSV,n_a));
853 if (exitstatus >= 100 || exitstatus < 0) {
854 exitstatus = RLM_MODULE_FAIL;
864 if ((get_hv_content(request->packet, request, rad_request_hv, &vp, "RAD_REQUEST", "request")) == 0) {
865 fr_pair_list_free(&request->packet->vps);
866 request->packet->vps = vp;
870 * Update cached copies
872 request->username = fr_pair_find_by_num(request->packet->vps, PW_USER_NAME, 0, TAG_ANY);
873 request->password = fr_pair_find_by_num(request->packet->vps, PW_USER_PASSWORD, 0, TAG_ANY);
874 if (!request->password)
875 request->password = fr_pair_find_by_num(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY);
878 if ((get_hv_content(request->reply, request, rad_reply_hv, &vp, "RAD_REPLY", "reply")) == 0) {
879 fr_pair_list_free(&request->reply->vps);
880 request->reply->vps = vp;
884 if ((get_hv_content(request, request, rad_check_hv, &vp, "RAD_CHECK", "control")) == 0) {
885 fr_pair_list_free(&request->config);
886 request->config = vp;
891 if (request->proxy &&
892 (get_hv_content(request->proxy, request, rad_request_proxy_hv, &vp,
893 "RAD_REQUEST_PROXY", "proxy-request") == 0)) {
894 fr_pair_list_free(&request->proxy->vps);
895 request->proxy->vps = vp;
899 if (request->proxy_reply &&
900 (get_hv_content(request->proxy_reply, request, rad_request_proxy_reply_hv, &vp,
901 "RAD_REQUEST_PROXY_REPLY", "proxy-reply") == 0)) {
902 fr_pair_list_free(&request->proxy_reply->vps);
903 request->proxy_reply->vps = vp;
912 #define RLM_PERL_FUNC(_x) static rlm_rcode_t CC_HINT(nonnull) mod_##_x(void *instance, REQUEST *request) \
914 return do_perl(instance, request, \
915 ((rlm_perl_t *)instance)->func_##_x); \
918 RLM_PERL_FUNC(authorize)
919 RLM_PERL_FUNC(authenticate)
920 RLM_PERL_FUNC(post_auth)
922 RLM_PERL_FUNC(checksimul)
925 RLM_PERL_FUNC(pre_proxy)
926 RLM_PERL_FUNC(post_proxy)
930 RLM_PERL_FUNC(recv_coa)
931 RLM_PERL_FUNC(send_coa)
934 RLM_PERL_FUNC(preacct)
937 * Write accounting information to this modules database.
939 static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *request)
942 int acctstatustype=0;
944 if ((pair = fr_pair_find_by_num(request->packet->vps, PW_ACCT_STATUS_TYPE, 0, TAG_ANY)) != NULL) {
945 acctstatustype = pair->vp_integer;
947 RDEBUG("Invalid Accounting Packet");
948 return RLM_MODULE_INVALID;
951 switch (acctstatustype) {
952 case PW_STATUS_START:
953 if (((rlm_perl_t *)instance)->func_start_accounting) {
954 return do_perl(instance, request,
955 ((rlm_perl_t *)instance)->func_start_accounting);
957 return do_perl(instance, request,
958 ((rlm_perl_t *)instance)->func_accounting);
962 if (((rlm_perl_t *)instance)->func_stop_accounting) {
963 return do_perl(instance, request,
964 ((rlm_perl_t *)instance)->func_stop_accounting);
966 return do_perl(instance, request,
967 ((rlm_perl_t *)instance)->func_accounting);
971 return do_perl(instance, request,
972 ((rlm_perl_t *)instance)->func_accounting);
978 * Detach a instance give a chance to a module to make some internal setup ...
980 DIAG_OFF(nested-externs)
981 static int mod_detach(void *instance)
983 rlm_perl_t *inst = (rlm_perl_t *) instance;
984 int exitstatus = 0, count = 0;
986 if (inst->rad_perlconf_hv != NULL) hv_undef(inst->rad_perlconf_hv);
988 if (inst->perl_parsed && inst->func_detach) {
990 PERL_SET_CONTEXT(inst->perl);
992 dSP; ENTER; SAVETMPS;
995 count = call_pv(inst->func_detach, G_SCALAR | G_EVAL );
1000 if (exitstatus >= 100 || exitstatus < 0) {
1001 exitstatus = RLM_MODULE_FAIL;
1011 rlm_perl_destruct(inst->perl);
1012 pthread_mutex_destroy(&inst->clone_mutex);
1014 perl_destruct(inst->perl);
1015 perl_free(inst->perl);
1021 DIAG_ON(nested-externs)
1024 * The module name should be the only globally exported symbol.
1025 * That is, everything else should be 'static'.
1027 * If the module needs to temporarily modify it's instantiation
1028 * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
1029 * The server will then take care of ensuring that the module
1030 * is single-threaded.
1032 extern module_t rlm_perl;
1033 module_t rlm_perl = {
1034 .magic = RLM_MODULE_INIT,
1037 .type = RLM_TYPE_THREAD_SAFE,
1039 .type = RLM_TYPE_THREAD_UNSAFE,
1041 .inst_size = sizeof(rlm_perl_t),
1042 .config = module_config,
1043 .bootstrap = mod_bootstrap,
1044 .instantiate = mod_instantiate,
1045 .detach = mod_detach,
1047 [MOD_AUTHENTICATE] = mod_authenticate,
1048 [MOD_AUTHORIZE] = mod_authorize,
1049 [MOD_PREACCT] = mod_preacct,
1050 [MOD_ACCOUNTING] = mod_accounting,
1051 [MOD_SESSION] = mod_checksimul,
1053 [MOD_PRE_PROXY] = mod_pre_proxy,
1054 [MOD_POST_PROXY] = mod_post_proxy,
1056 [MOD_POST_AUTH] = mod_post_auth,
1058 [MOD_RECV_COA] = mod_recv_coa,
1059 [MOD_SEND_COA] = mod_send_coa