The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_perl.c
Go to the documentation of this file.
1/*
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.
6 *
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.
11 *
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
15 */
16
17/**
18 * $Id: 376354d83c641a8e972de243b8460fb991d95f7e $
19 * @file rlm_perl.c
20 * @brief Translates requests between the server an a perl interpreter.
21 *
22 * @copyright 2002,2006 The FreeRADIUS server project
23 * @copyright 2002 Boian Jordanov (bjordanov@orbitel.bg)
24 */
25RCSID("$Id: 376354d83c641a8e972de243b8460fb991d95f7e $")
26
27#define LOG_PREFIX "perl"
28
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/util/debug.h>
32#include <freeradius-devel/unlang/xlat_func.h>
33#include <freeradius-devel/unlang/xlat.h>
34#include <freeradius-devel/radius/radius.h>
35
37DIAG_OFF(compound-token-split-by-macro) /* Perl does horrible things with macros */
39
40#ifdef INADDR_ANY
41# undef INADDR_ANY
42#endif
43#include <EXTERN.h>
44#include <perl.h>
45#include <XSUB.h>
46#include <dlfcn.h>
47#include <semaphore.h>
48
49#if defined(__APPLE__) || defined(__FreeBSD__)
50extern char **environ;
51#endif
52
53#ifndef USE_ITHREADS
54# error perl must be compiled with USE_ITHREADS
55#endif
56
57typedef struct {
58 bool request; //!< Should the request list be replaced after module call
59 bool reply; //!< Should the reply list be replaced after module call
60 bool control; //!< Should the control list be replaced after module call
61 bool session; //!< Should the session list be replaced after module call
63
64/*
65 * Define a structure for our module configuration.
66 *
67 * These variables do not need to be in a structure, but it's
68 * a lot cleaner to do so, and a pointer to the structure can
69 * be used as the instance handle.
70 */
71typedef struct {
72 /* Name of the perl module */
73 char const *module;
74
75 /* Name of the functions for each module method */
76 char const *func_authorize;
77 char const *func_authenticate;
78 char const *func_accounting;
79 char const *func_preacct;
80 char const *func_detach;
81 char const *func_post_auth;
82 char const *perl_flags;
83 PerlInterpreter *perl;
86 HV *rad_perlconf_hv; //!< holds "config" items (perl %RAD_PERLCONF hash).
87
89
90typedef struct {
91 PerlInterpreter *perl; //!< Thread specific perl interpreter.
93
94static void *perl_dlhandle; //!< To allow us to load perl's symbols into the global symbol table.
95
96static const conf_parser_t replace_config[] = {
97 { FR_CONF_OFFSET("request", rlm_perl_replace_t, request) },
98 { FR_CONF_OFFSET("reply", rlm_perl_replace_t, reply) },
99 { FR_CONF_OFFSET("control", rlm_perl_replace_t, control) },
100 { FR_CONF_OFFSET("session", rlm_perl_replace_t, session) },
102};
103
104/*
105 * A mapping of configuration file names to internal variables.
106 */
107#define RLM_PERL_CONF(_x) { FR_CONF_OFFSET("func_" STRINGIFY(_x), rlm_perl_t, func_##_x), \
108 .data = NULL, .dflt = STRINGIFY(_x), .quote = T_INVALID }
109
110static const conf_parser_t module_config[] = {
112
113 RLM_PERL_CONF(authorize),
114 RLM_PERL_CONF(authenticate),
115 RLM_PERL_CONF(post_auth),
116 RLM_PERL_CONF(accounting),
117 RLM_PERL_CONF(preacct),
118 RLM_PERL_CONF(detach),
119
120 { FR_CONF_OFFSET("perl_flags", rlm_perl_t, perl_flags) },
121
122 { FR_CONF_OFFSET_SUBSECTION("replace", 0, rlm_perl_t, replace, replace_config) },
123
125};
126
127/*
128 * man perlembed
129 */
130EXTERN_C void boot_DynaLoader(pTHX_ CV* cv);
131
132static _Thread_local request_t *rlm_perl_request;
133
134# define dl_librefs "DynaLoader::dl_librefs"
135# define dl_modules "DynaLoader::dl_modules"
136static void rlm_perl_clear_handles(pTHX)
137{
138 AV *librefs = get_av(dl_librefs, false);
139 if (librefs) {
140 av_clear(librefs);
141 }
142}
143
144static void **rlm_perl_get_handles(pTHX)
145{
146 I32 i;
147 AV *librefs = get_av(dl_librefs, false);
148 AV *modules = get_av(dl_modules, false);
149 void **handles;
150
151 if (!librefs) return NULL;
152
153 if (!(AvFILL(librefs) >= 0)) {
154 return NULL;
155 }
156
157 MEM(handles = talloc_array(NULL, void *, AvFILL(librefs) + 2));
158 for (i = 0; i <= AvFILL(librefs); i++) {
159 void *handle;
160 SV *handle_sv = *av_fetch(librefs, i, false);
161 if (!handle_sv) {
162 ERROR("Could not fetch $%s[%d]!", dl_librefs, (int)i);
163 continue;
164 }
165 handle = (void *)SvIV(handle_sv);
166
167 if (handle) handles[i] = handle;
168 }
169
170 av_clear(modules);
171 av_clear(librefs);
172
173 handles[i] = (void *)0;
174
175 return handles;
176}
177
178static void rlm_perl_close_handles(void **handles)
179{
180 int i;
181
182 if (!handles) {
183 return;
184 }
185
186 for (i = 0; handles[i]; i++) {
187 DEBUG("Close %p", handles[i]);
188 dlclose(handles[i]);
189 }
190
191 talloc_free(handles);
192}
193
194/*
195 * This is wrapper for fr_log
196 * Now users can call radiusd::log(level,msg) which is the same
197 * as calling fr_log from C code.
198 */
199static XS(XS_radiusd_log)
200{
201 dXSARGS;
202 if (items !=2)
203 croak("Usage: radiusd::log(level, message)");
204 {
205 int level;
206 char *msg;
207
208 level = (int) SvIV(ST(0));
209 msg = (char *) SvPV(ST(1), PL_na);
210
211 /*
212 * Because 'msg' is a 'char *', we don't want '%s', etc.
213 * in it to give us printf-style vulnerabilities.
214 */
215 fr_log(&default_log, level, __FILE__, __LINE__, "rlm_perl: %s", msg);
216 }
217 XSRETURN_NO;
218}
219
220/*
221 * This is a wrapper for xlat_aeval
222 * Now users are able to get data that is accessible only via xlat
223 * e.g. %client(...)
224 * Call syntax is radiusd::xlat(string), string will be handled the
225 * same way it is described in EXPANSIONS section of man unlang
226 */
227static XS(XS_radiusd_xlat)
228{
229 dXSARGS;
230 char *in_str;
231 char *expanded;
232 ssize_t slen;
233 request_t *request;
234
235 if (items != 1) croak("Usage: radiusd::xlat(string)");
236
237 request = rlm_perl_request;
238
239 in_str = (char *) SvPV(ST(0), PL_na);
240
241 slen = xlat_aeval(request, &expanded, request, in_str, NULL, NULL);
242 if (slen < 0) {
243 REDEBUG("Error parsing xlat '%s'", in_str);
244 XSRETURN_UNDEF;
245 }
246
247 XST_mPV(0, expanded);
248 talloc_free(expanded);
249 XSRETURN(1);
250}
251
252static void xs_init(pTHX)
253{
254 char const *file = __FILE__;
255
256 /* DynaLoader is a special case */
257 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
258
259 newXS("radiusd::log",XS_radiusd_log, "rlm_perl");
260 newXS("radiusd::xlat",XS_radiusd_xlat, "rlm_perl");
261}
262
263/** Convert a list of value boxes to a Perl array for passing to subroutines
264 *
265 * The Perl array object should be created before calling this
266 * to populate it.
267 *
268 * @param[in,out] av Perl array object to append values to.
269 * @param[in] head of VB list.
270 * @return
271 * - 0 on success
272 * - -1 on failure
273 */
274static int perl_vblist_to_av(AV *av, fr_value_box_list_t *head) {
275 fr_value_box_t *vb = NULL;
276 SV *sv;
277
278 while ((vb = fr_value_box_list_next(head, vb))) {
279 switch (vb->type) {
280 case FR_TYPE_STRING:
281 sv = newSVpvn(vb->vb_strvalue, vb->vb_length);
282 break;
283
284 case FR_TYPE_OCTETS:
285 sv = newSVpvn((char const *)vb->vb_octets, vb->vb_length);
286 break;
287
288 case FR_TYPE_GROUP:
289 {
290 AV *sub_av;
291 sub_av = newAV();
292 perl_vblist_to_av(sub_av, &vb->vb_group);
293 sv = newRV_inc((SV *)sub_av);
294 }
295 break;
296 default:
297 {
298 char buffer[1024];
299 ssize_t slen;
300
301 slen = fr_value_box_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), vb, NULL);
302 if (slen < 0) return -1;
303 sv = newSVpvn(buffer, (size_t)slen);
304 }
305 break;
306 }
307 if (!sv) return -1;
308 if (vb->tainted) SvTAINT(sv);
309 av_push(av, sv);
310 }
311 return 0;
312}
313
314/** Parse a Perl SV and create value boxes, appending to a list
315 *
316 * For parsing values passed back from a Perl subroutine
317 *
318 * When hashes are returned, first the key is added as a value box then the value
319 *
320 * @param[in] ctx to allocate boxes in.
321 * @param[out] list to append value boxes to.
322 * @param[in] request being handled - only used for debug messages
323 * @param[in] sv to parse
324 * @return
325 * - 0 on success
326 * - -1 on failure
327 */
328static int perl_sv_to_vblist(TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request, SV *sv) {
329 fr_value_box_t *vb = NULL;
330 char *tmp;
331 STRLEN len;
332 AV *av;
333 HV *hv;
334 I32 sv_len, i;
335 int type;
336
337 type = SvTYPE(sv);
338
339 switch (type) {
340 case SVt_IV:
341 /* Integer or Reference */
342 if (SvROK(sv)) {
343 DEBUG3("Reference returned");
344 if (perl_sv_to_vblist(ctx, list, request, SvRV(sv)) < 0) return -1;
345 break;
346 }
347 DEBUG3("Integer returned");
348 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_INT32, NULL));
349 vb->vb_int32 = SvIV(sv);
350 break;
351
352 case SVt_NV:
353 /* Float */
354 DEBUG3("Float returned");
355 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_FLOAT64, NULL));
356 vb->vb_float64 = SvNV(sv);
357 break;
358
359 case SVt_PV:
360 /* String */
361 DEBUG3("String returned");
362 tmp = SvPVutf8(sv, len);
363 MEM(vb = fr_value_box_alloc_null(ctx));
364 if (fr_value_box_bstrndup(vb, vb, NULL, tmp, len, SvTAINTED(sv)) < 0) {
365 talloc_free(vb);
366 RPEDEBUG("Failed to allocate %ld for output", len);
367 return -1;
368 }
369 break;
370
371 case SVt_PVAV:
372 /* Array */
373 {
374 SV **av_sv;
375 DEBUG3("Array returned");
376 av = (AV*)sv;
377 sv_len = av_len(av);
378 for (i = 0; i <= sv_len; i++) {
379 av_sv = av_fetch(av, i, 0);
380 if (SvOK(*av_sv)) {
381 if (perl_sv_to_vblist(ctx, list, request, *av_sv) < 0) return -1;
382 }
383 }
384 }
385 break;
386
387 case SVt_PVHV:
388 /* Hash */
389 {
390 SV *hv_sv;
391 DEBUG3("Hash returned");
392 hv = (HV*)sv;
393 for (i = hv_iterinit(hv); i > 0; i--) {
394 hv_sv = hv_iternextsv(hv, &tmp, &sv_len);
395 /*
396 * Add key first
397 */
398 MEM(vb = fr_value_box_alloc_null(ctx));
399 if (fr_value_box_bstrndup(vb, vb, NULL, tmp, sv_len, SvTAINTED(hv_sv)) < 0) {
400 talloc_free(vb);
401 RPEDEBUG("Failed to allocate %d for output", sv_len);
402 return -1;
403 }
404 fr_value_box_list_insert_tail(list, vb);
405
406 /*
407 * Now process value
408 */
409 if (perl_sv_to_vblist(ctx, list, request, hv_sv) < 0) return -1;
410
411 }
412 /*
413 * Box has already been added to list - return
414 */
415 return 0;
416 }
417
418 case SVt_NULL:
419 break;
420
421 default:
422 RPEDEBUG("Perl returned unsupported data type %d", type);
423 return -1;
424
425 }
426
427 if (vb) {
428 vb->tainted = SvTAINTED(sv);
429 fr_value_box_list_insert_tail(list, vb);
430 }
431
432 return 0;
433}
434
436 { .required = true, .single = true, .type = FR_TYPE_STRING },
437 { .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .type = FR_TYPE_VOID },
439};
440
441/** Call perl code using an xlat
442 *
443 * @ingroup xlat_functions
444 */
445static xlat_action_t perl_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
446 xlat_ctx_t const *xctx,
447 request_t *request, fr_value_box_list_t *in)
448{
450 int count, i;
452 STRLEN n_a;
453 fr_value_box_t *func = fr_value_box_list_pop_head(in);
454 fr_value_box_t *child;
455 SV *sv;
456 AV *av;
457 fr_value_box_list_t list, sub_list;
458 fr_value_box_t *vb = NULL;
459
460 fr_value_box_list_init(&list);
461 fr_value_box_list_init(&sub_list);
462
463 {
464 dTHXa(t->perl);
465 PERL_SET_CONTEXT(t->perl);
466 }
467
468 {
469 dSP;
470 ENTER;SAVETMPS;
471
472 PUSHMARK(SP);
473
475 fr_assert(arg->type == FR_TYPE_GROUP);
476 if (fr_value_box_list_empty(&arg->vb_group)) continue;
477
478 if (fr_value_box_list_num_elements(&arg->vb_group) == 1) {
479 child = fr_value_box_list_head(&arg->vb_group);
480 /*
481 * Single child value - add as scalar
482 */
483 if (child->vb_length == 0) continue;
484 DEBUG3("Passing single value %pV", child);
485 sv = newSVpvn(child->vb_strvalue, child->vb_length);
486 if (child->tainted) SvTAINT(sv);
487 XPUSHs(sv_2mortal(sv));
488 continue;
489 }
490
491 /*
492 * Multiple child values - create array and pass reference
493 */
494 av = newAV();
495 perl_vblist_to_av(av, &arg->vb_group);
496 DEBUG3("Passing list as array %pM", &arg->vb_group);
497 sv = newRV_inc((SV *)av);
498 XPUSHs(sv_2mortal(sv));
499 }
500
501 PUTBACK;
502
503 count = call_pv(func->vb_strvalue, G_ARRAY | G_EVAL);
504
505 SPAGAIN;
506 if (SvTRUE(ERRSV)) {
507 REDEBUG("Exit %s", SvPV(ERRSV,n_a));
508 (void)POPs;
509 goto cleanup;
510 }
511
512 /*
513 * As results are popped from a stack, they are in reverse
514 * sequence. Add to a temporary list and then prepend to
515 * main list.
516 */
517 for (i = 0; i < count; i++) {
518 sv = POPs;
519 if (perl_sv_to_vblist(ctx, &sub_list, request, sv) < 0) goto cleanup;
520 fr_value_box_list_move_head(&list, &sub_list);
521 }
522 ret = XLAT_ACTION_DONE;
523
524 /*
525 * Move the assembled list of boxes to the output
526 */
527 while ((vb = fr_value_box_list_pop_head(&list))) fr_dcursor_append(out, vb);
528
529 cleanup:
530 PUTBACK;
531 FREETMPS;
532 LEAVE;
533
534 }
535
536 return ret;
537}
538
539/*
540 * Parse a configuration section, and populate a HV.
541 * This function is recursively called (allows to have nested hashes.)
542 */
543static void perl_parse_config(CONF_SECTION *cs, int lvl, HV *rad_hv)
544{
545 int indent_section = (lvl + 1) * 4;
546 int indent_item = (lvl + 2) * 4;
547
548 if (!cs || !rad_hv) return;
549
550 DEBUG("%*s%s {", indent_section, " ", cf_section_name1(cs));
551
552 for (CONF_ITEM *ci = NULL; (ci = cf_item_next(cs, ci)); ) {
553 /*
554 * This is a section.
555 * Create a new HV, store it as a reference in current HV,
556 * Then recursively call perl_parse_config with this section and the new HV.
557 */
558 if (cf_item_is_section(ci)) {
559 CONF_SECTION *sub_cs = cf_item_to_section(ci);
560 char const *key = cf_section_name1(sub_cs); /* hash key */
561 HV *sub_hv;
562 SV *ref;
563
564 if (!key) continue;
565
566 if (hv_exists(rad_hv, key, strlen(key))) {
567 WARN("Ignoring duplicate config section '%s'", key);
568 continue;
569 }
570
571 sub_hv = newHV();
572 ref = newRV_inc((SV*) sub_hv);
573
574 (void)hv_store(rad_hv, key, strlen(key), ref, 0);
575
576 perl_parse_config(sub_cs, lvl + 1, sub_hv);
577 } else if (cf_item_is_pair(ci)){
578 CONF_PAIR *cp = cf_item_to_pair(ci);
579 char const *key = cf_pair_attr(cp); /* hash key */
580 char const *value = cf_pair_value(cp); /* hash value */
581
582 if (!key || !value) continue;
583
584 /*
585 * This is an item.
586 * Store item attr / value in current HV.
587 */
588 if (hv_exists(rad_hv, key, strlen(key))) {
589 WARN("Ignoring duplicate config item '%s'", key);
590 continue;
591 }
592
593 (void)hv_store(rad_hv, key, strlen(key), newSVpvn(value, strlen(value)), 0);
594
595 DEBUG("%*s%s = %s", indent_item, " ", key, value);
596 }
597 }
598
599 DEBUG("%*s}", indent_section, " ");
600}
601
602static void perl_store_vps(request_t *request, fr_pair_list_t *vps, HV *rad_hv,
603 const char *hash_name, bool dbg_print);
604
605static void perl_vp_to_svpvn_element(request_t *request, AV *av, fr_pair_t *vp,
606 int *i, const char *hash_name, bool dbg_print)
607{
608
609 SV *sv;
610
611 if (dbg_print) RDEBUG2("$%s{'%s'}[%i] = %pP", hash_name, vp->da->name, *i, vp);
612 switch (vp->vp_type) {
613 case FR_TYPE_STRING:
614 sv = newSVpvn(vp->vp_strvalue, vp->vp_length);
615 break;
616
617 case FR_TYPE_OCTETS:
618 sv = newSVpvn((char const *)vp->vp_octets, vp->vp_length);
619 break;
620
622 {
623 HV *hv;
624 hv = newHV();
625 perl_store_vps(request, &vp->vp_group, hv, vp->da->name, false);
626 sv = newRV_noinc((SV *)hv);
627 }
628 break;
629
630 default:
631 {
632 char buffer[1024];
633 ssize_t slen;
634
636 if (slen < 0) return;
637
638 sv = newSVpvn(buffer, (size_t)slen);
639 }
640 break;
641 }
642
643 if (!sv) return;
644 SvTAINT(sv);
645 av_push(av, sv);
646 (*i)++;
647}
648
649/*
650 * get the vps and put them in perl hash
651 * If one VP have multiple values it is added as array_ref
652 * Example for this is Vendor-Specific.Cisco.AVPair that holds multiple values.
653 * Which will be available as array_ref in $RAD_REQUEST{'Vendor-Specific.Cisco.AVPair'}
654 */
655static void perl_store_vps(request_t *request, fr_pair_list_t *vps, HV *rad_hv,
656 const char *hash_name, bool dbg_print)
657{
658 fr_pair_t *vp;
659 fr_dcursor_t cursor;
660
661 hv_undef(rad_hv);
662
663 RINDENT();
665 for (vp = fr_pair_dcursor_init(&cursor, vps);
666 vp;
667 vp = fr_dcursor_next(&cursor)) {
668 fr_pair_t *next;
669 char const *name;
670 name = vp->da->name;
671
672 /*
673 * We've sorted by type, then tag, so attributes of the
674 * same type/tag should follow on from each other.
675 */
676 if ((next = fr_dcursor_next_peek(&cursor)) && ATTRIBUTE_EQ(vp, next)) {
677 int i = 0;
678 AV *av;
679
680 av = newAV();
681 perl_vp_to_svpvn_element(request, av, vp, &i, hash_name, dbg_print);
682 do {
683 perl_vp_to_svpvn_element(request, av, next, &i, hash_name, dbg_print);
684 fr_dcursor_next(&cursor);
685 } while ((next = fr_dcursor_next_peek(&cursor)) && ATTRIBUTE_EQ(vp, next));
686 (void)hv_store(rad_hv, name, strlen(name), newRV_noinc((SV *)av), 0);
687
688 continue;
689 }
690
691 /*
692 * It's a normal single valued attribute
693 */
694 if (dbg_print) RDEBUG2("$%s{'%s'} = %pP'", hash_name, vp->da->name, vp);
695 switch (vp->vp_type) {
696 case FR_TYPE_STRING:
697 (void)hv_store(rad_hv, name, strlen(name), newSVpvn(vp->vp_strvalue, vp->vp_length), 0);
698 break;
699
700 case FR_TYPE_OCTETS:
701 (void)hv_store(rad_hv, name, strlen(name),
702 newSVpvn((char const *)vp->vp_octets, vp->vp_length), 0);
703 break;
704
706 {
707 HV *hv;
708 hv = newHV();
709 perl_store_vps(request, &vp->vp_group, hv, vp->da->name, false);
710 (void)hv_store(rad_hv, name, strlen(name), newRV_noinc((SV *)hv), 0);
711 }
712 break;
713
714 default:
715 {
716 char buffer[1024];
717 ssize_t slen;
718
720 (void)hv_store(rad_hv, name, strlen(name),
721 newSVpvn(buffer, (size_t)(slen)), 0);
722 }
723 break;
724 }
725 }
726 REXDENT();
727}
728
729static int get_hv_content(TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pair_list_t *vps, const char *list_name,
730 fr_dict_attr_t const *parent, bool dbg_print);
731
732/*
733 *
734 * Verify that a Perl SV is a string and save it in FreeRadius
735 * Value Pair Format
736 *
737 */
738static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, char *key, SV *sv,
739 const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
740{
741 char *val;
742 fr_pair_t *vp;
743 STRLEN len;
744 fr_dict_attr_t const *da;
745
746 if (!SvOK(sv)) return -1;
747
748 val = SvPV(sv, len);
749
750 da = fr_dict_attr_by_name(NULL, parent, key);
751 if (!da) {
752 REDEBUG("Ignoring unknown attribute '%s'", key);
753 return -1;
754 }
755 fr_assert(da != NULL);
756
757 vp = fr_pair_afrom_da(ctx, da);
758 if (!vp) {
759 fail:
761 RPEDEBUG("Failed to create pair %s.%s = %s", list_name, key, val);
762 return -1;
763 }
764
765 switch (vp->vp_type) {
766 case FR_TYPE_STRING:
767 fr_pair_value_bstrndup(vp, val, len, true);
768 break;
769
770 case FR_TYPE_OCTETS:
771 fr_pair_value_memdup(vp, (uint8_t const *)val, len, true);
772 break;
773
775 {
776 HV *hv;
777 if (!SvROK(sv) || (SvTYPE(SvRV(sv)) != SVt_PVHV)) {
778 RPEDEBUG("%s should be retuned as a hash", vp->da->name);
779 goto fail;
780 }
781 hv = (HV *)SvRV(sv);
782 if (get_hv_content(vp, request, hv, &vp->vp_group, list_name, da, false) < 0) goto fail;
783 if (vp->vp_type == FR_TYPE_STRUCT) fr_pair_list_sort(&vp->vp_group, fr_pair_cmp_by_da);
784 }
785 break;
786
787 default:
788 if (fr_pair_value_from_str(vp, val, len, NULL, false) < 0) goto fail;
789 }
790 fr_pair_append(vps, vp);
791
793
794 if (dbg_print) RDEBUG2("%s.%pP", list_name, vp);
795 return 0;
796}
797
798/*
799 * Gets the content from hashes
800 */
801static int get_hv_content(TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pair_list_t *vps,
802 const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
803{
804 SV *res_sv, **av_sv;
805 AV *av;
806 char *key;
807 I32 key_len, len, i, j;
808 int ret = 0;
809
810 for (i = hv_iterinit(my_hv); i > 0; i--) {
811 res_sv = hv_iternextsv(my_hv,&key,&key_len);
812 if (SvROK(res_sv) && (SvTYPE(SvRV(res_sv)) == SVt_PVAV)) {
813 av = (AV*)SvRV(res_sv);
814 len = av_len(av);
815 for (j = 0; j <= len; j++) {
816 av_sv = av_fetch(av, j, 0);
817 if (pairadd_sv(ctx, request, vps, key, *av_sv, list_name, parent, dbg_print) < 0) continue;
818 ret++;
819 }
820 } else {
821 if (pairadd_sv(ctx, request, vps, key, res_sv, list_name, parent, dbg_print) < 0) continue;
822 ret++;
823 }
824 }
825
826 if (!fr_pair_list_empty(vps)) PAIR_LIST_VERIFY(vps);
827
828 return ret;
829}
830
831/*
832 * Call the function_name inside the module
833 * Store all vps in hashes %RAD_CONFIG %RAD_REPLY %RAD_REQUEST
834 *
835 */
836static unlang_action_t do_perl(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request,
837 PerlInterpreter *interp, char const *function_name)
838{
839
840 rlm_perl_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_perl_t);
841 fr_pair_list_t vps;
842 int ret=0, count;
843 STRLEN n_a;
844
845 HV *rad_reply_hv;
846 HV *rad_config_hv;
847 HV *rad_request_hv;
848 HV *rad_state_hv;
849
850 /*
851 * Radius has told us to call this function, but none
852 * is defined.
853 */
854 if (!function_name) RETURN_MODULE_FAIL;
855
856 {
857 dTHXa(interp);
858 PERL_SET_CONTEXT(interp);
859 }
860
861 {
862 dSP;
863
864 ENTER;
865 SAVETMPS;
866
867 rad_reply_hv = get_hv("RAD_REPLY", 1);
868 rad_config_hv = get_hv("RAD_CONFIG", 1);
869 rad_request_hv = get_hv("RAD_REQUEST", 1);
870 rad_state_hv = get_hv("RAD_STATE", 1);
871
872 perl_store_vps(request, &request->request_pairs, rad_request_hv, "RAD_REQUEST", true);
873 perl_store_vps(request, &request->reply_pairs, rad_reply_hv, "RAD_REPLY", true);
874 perl_store_vps(request, &request->control_pairs, rad_config_hv, "RAD_CONFIG", true);
875 perl_store_vps(request, &request->session_state_pairs, rad_state_hv, "RAD_STATE", true);
876
877 /*
878 * Store pointer to request structure globally so radiusd::xlat works
879 */
880 rlm_perl_request = request;
881
882 PUSHMARK(SP);
883 /*
884 * This way %RAD_xx can be pushed onto stack as sub parameters.
885 * XPUSHs( newRV_noinc((SV *)rad_request_hv) );
886 * XPUSHs( newRV_noinc((SV *)rad_reply_hv) );
887 * XPUSHs( newRV_noinc((SV *)rad_config_hv) );
888 * PUTBACK;
889 */
890
891 count = call_pv(function_name, G_SCALAR | G_EVAL | G_NOARGS);
892
893 rlm_perl_request = NULL;
894
895 SPAGAIN;
896
897 if (SvTRUE(ERRSV)) {
898 REDEBUG("perl_embed:: module = %s , func = %s exit status= %s\n",
899 inst->module, function_name, SvPV(ERRSV,n_a));
900 (void)POPs;
901 ret = RLM_MODULE_FAIL;
902 } else if (count == 1) {
903 ret = POPi;
904 if (ret >= 100 || ret < 0) {
905 ret = RLM_MODULE_FAIL;
906 }
907 }
908
909
910 PUTBACK;
911 FREETMPS;
912 LEAVE;
913
914 fr_pair_list_init(&vps);
915 if (inst->replace.request &&
916 (get_hv_content(request->request_ctx, request, rad_request_hv, &vps, "request",
917 fr_dict_root(request->dict), true)) > 0) {
918 fr_pair_list_free(&request->request_pairs);
919 fr_pair_list_append(&request->request_pairs, &vps);
920 }
921
922 if (inst->replace.reply &&
923 (get_hv_content(request->reply_ctx, request, rad_reply_hv, &vps, "reply",
924 fr_dict_root(request->dict), true)) > 0) {
925 fr_pair_list_free(&request->reply_pairs);
926 fr_pair_list_append(&request->reply_pairs, &vps);
927 }
928
929 if (inst->replace.control &&
930 (get_hv_content(request->control_ctx, request, rad_config_hv, &vps, "control",
931 fr_dict_root(request->dict), true)) > 0) {
932 fr_pair_list_free(&request->control_pairs);
933 fr_pair_list_append(&request->control_pairs, &vps);
934 }
935
936 if (inst->replace.session &&
937 (get_hv_content(request->session_state_ctx, request, rad_state_hv, &vps, "session-state",
938 fr_dict_root(request->dict), true)) > 0) {
939 fr_pair_list_free(&request->session_state_pairs);
940 fr_pair_list_append(&request->session_state_pairs, &vps);
941 }
942 }
943
945}
946
947#define RLM_PERL_FUNC(_x) \
948static unlang_action_t CC_HINT(nonnull) mod_##_x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \
949{ \
950 rlm_perl_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_perl_t); \
951 return do_perl(p_result, mctx, request, \
952 ((rlm_perl_thread_t *)talloc_get_type_abort(mctx->thread, rlm_perl_thread_t))->perl, \
953 inst->func_##_x); \
954}
955
956RLM_PERL_FUNC(authorize)
957RLM_PERL_FUNC(authenticate)
958RLM_PERL_FUNC(post_auth)
959RLM_PERL_FUNC(preacct)
960RLM_PERL_FUNC(accounting)
961
963DIAG_OFF(shadow)
964static void rlm_perl_interp_free(PerlInterpreter *perl)
965{
966 void **handles;
967
968 {
969 dTHXa(perl);
970 PERL_SET_CONTEXT(perl);
971 }
972
973 handles = rlm_perl_get_handles(aTHX);
974 if (handles) rlm_perl_close_handles(handles);
975
976 PL_perl_destruct_level = 2;
977
978 PL_origenviron = environ;
979
980 /*
981 * FIXME: This shouldn't happen
982 *
983 */
984 while (PL_scopestack_ix > 1) LEAVE;
985
986 perl_destruct(perl);
987 perl_free(perl);
988}
989DIAG_ON(shadow)
991
993{
994 rlm_perl_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_perl_t);
995 rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t);
996 PerlInterpreter *interp;
997 UV clone_flags = 0;
998
999 PERL_SET_CONTEXT(inst->perl);
1000
1001 interp = perl_clone(inst->perl, clone_flags);
1002 {
1003 dTHXa(interp); /* Sets the current thread's interpreter */
1004 }
1005# if PERL_REVISION >= 5 && PERL_VERSION <8
1006 call_pv("CLONE", 0);
1007# endif
1008 ptr_table_free(PL_ptr_table);
1009 PL_ptr_table = NULL;
1010
1011 PERL_SET_CONTEXT(aTHX);
1013
1014 t->perl = interp; /* Store perl interp for easy freeing later */
1015
1016 return 0;
1017}
1018
1020{
1021 rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t);
1022
1024
1025 return 0;
1026}
1027
1028/*
1029 * Do any per-module initialization that is separate to each
1030 * configured instance of the module. e.g. set up connections
1031 * to external databases, read configuration files, set up
1032 * dictionary entries, etc.
1033 *
1034 * If configuration information is given in the config section
1035 * that must be referenced in later calls, store a handle to it
1036 * in *instance otherwise put a null pointer there.
1037 *
1038 * Setup a hashes which we will use later
1039 * parse a module and give it a chance to live
1040 *
1041 */
1042static int mod_instantiate(module_inst_ctx_t const *mctx)
1043{
1044 rlm_perl_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_perl_t);
1045 CONF_SECTION *conf = mctx->mi->conf;
1046 AV *end_AV;
1047
1048 char const **embed_c; /* Stupid Perl and lack of const consistency */
1049 char **embed;
1050 int ret = 0, argc = 0;
1051 char arg[] = "0";
1052
1053 CONF_SECTION *cs;
1054
1055 /*
1056 * Setup the argument array we pass to the perl interpreter
1057 */
1058 MEM(embed_c = talloc_zero_array(inst, char const *, 4));
1059 memcpy(&embed, &embed_c, sizeof(embed));
1060 embed_c[0] = NULL;
1061 if (inst->perl_flags) {
1062 embed_c[1] = inst->perl_flags;
1063 embed_c[2] = inst->module;
1064 embed_c[3] = arg;
1065 argc = 4;
1066 } else {
1067 embed_c[1] = inst->module;
1068 embed_c[2] = arg;
1069 argc = 3;
1070 }
1071
1072 /*
1073 * Allocate a new perl interpreter to do the parsing
1074 */
1075 if ((inst->perl = perl_alloc()) == NULL) {
1076 ERROR("No memory for allocating new perl interpreter!");
1077 return -1;
1078 }
1079 perl_construct(inst->perl); /* ...and initialise it */
1080
1081 PL_perl_destruct_level = 2;
1082 {
1083 dTHXa(inst->perl);
1084 }
1085 PERL_SET_CONTEXT(inst->perl);
1086
1087#if PERL_REVISION >= 5 && PERL_VERSION >=8
1088 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
1089#endif
1090
1091 ret = perl_parse(inst->perl, xs_init, argc, embed, NULL);
1092
1093 end_AV = PL_endav;
1094 PL_endav = (AV *)NULL;
1095
1096 if (ret) {
1097 ERROR("Perl_parse failed: %s not found or has syntax errors", inst->module);
1098 return -1;
1099 }
1100
1101 /* parse perl configuration sub-section */
1102 cs = cf_section_find(conf, "config", NULL);
1103 if (cs) {
1104 inst->rad_perlconf_hv = get_hv("RAD_PERLCONF", 1);
1105 perl_parse_config(cs, 0, inst->rad_perlconf_hv);
1106 }
1107
1108 inst->perl_parsed = true;
1109 perl_run(inst->perl);
1110
1111 PL_endav = end_AV;
1112
1113 return 0;
1114}
1115
1116/*
1117 * Detach a instance give a chance to a module to make some internal setup ...
1118 */
1119DIAG_OFF(nested-externs)
1120static int mod_detach(module_detach_ctx_t const *mctx)
1121{
1122 rlm_perl_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_perl_t);
1123 int ret = 0, count = 0;
1124
1125
1126 if (inst->perl_parsed) {
1127 dTHXa(inst->perl);
1128 PERL_SET_CONTEXT(inst->perl);
1129 if (inst->rad_perlconf_hv != NULL) hv_undef(inst->rad_perlconf_hv);
1130
1131 if (inst->func_detach) {
1132 dSP; ENTER; SAVETMPS;
1133 PUSHMARK(SP);
1134
1135 count = call_pv(inst->func_detach, G_SCALAR | G_EVAL );
1136 SPAGAIN;
1137
1138 if (count == 1) {
1139 ret = POPi;
1140 if (ret >= 100 || ret < 0) {
1141 ret = RLM_MODULE_FAIL;
1142 }
1143 }
1144 PUTBACK;
1145 FREETMPS;
1146 LEAVE;
1147 }
1148 }
1149
1151
1152 return ret;
1153}
1154DIAG_ON(nested-externs)
1155
1156static int mod_bootstrap(module_inst_ctx_t const *mctx)
1157{
1158 xlat_t *xlat;
1159
1160 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, perl_xlat, FR_TYPE_VOID);
1162
1163 return 0;
1164}
1165
1166static int mod_load(void)
1167{
1168 char const **embed_c; /* Stupid Perl and lack of const consistency */
1169 char **embed;
1170 char **envp = NULL;
1171 int argc = 0;
1172
1173#define LOAD_INFO(_fmt, ...) fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_perl - " _fmt, ## __VA_ARGS__)
1174#define LOAD_WARN(_fmt, ...) fr_log_perror(LOG_DST, L_WARN, __FILE__, __LINE__, \
1175 &(fr_log_perror_format_t){ \
1176 .first_prefix = "rlm_perl - ", \
1177 .subsq_prefix = "rlm_perl - ", \
1178 }, \
1179 _fmt, ## __VA_ARGS__)
1180
1181 LOAD_INFO("Perl version: %s", PERL_API_VERSION_STRING);
1182 dependency_version_number_add(NULL, "perl", PERL_API_VERSION_STRING);
1183
1184 /*
1185 * Load perl using RTLD_GLOBAL and dlopen.
1186 * This fixes issues where Perl C extensions
1187 * can't find the symbols they need.
1188 */
1189 perl_dlhandle = dl_open_by_sym("perl_construct", RTLD_NOW | RTLD_GLOBAL);
1190 if (!perl_dlhandle) LOAD_WARN("Failed loading libperl symbols into global symbol table");
1191
1192 /*
1193 * Setup the argument array we pass to the perl interpreter
1194 */
1195 MEM(embed_c = talloc_zero_array(NULL, char const *, 1));
1196 memcpy(&embed, &embed_c, sizeof(embed));
1197 embed_c[0] = NULL;
1198 argc = 1;
1199
1200 PERL_SYS_INIT3(&argc, &embed, &envp);
1201
1202 talloc_free(embed_c);
1203
1204 return 0;
1205}
1206
1207static void mod_unload(void)
1208{
1209 if (perl_dlhandle) dlclose(perl_dlhandle);
1210 PERL_SYS_TERM();
1211}
1212
1213/*
1214 * The module name should be the only globally exported symbol.
1215 * That is, everything else should be 'static'.
1216 *
1217 * If the module needs to temporarily modify it's instantiation
1218 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1219 * The server will then take care of ensuring that the module
1220 * is single-threaded.
1221 */
1222extern module_rlm_t rlm_perl;
1224 .common = {
1225 .magic = MODULE_MAGIC_INIT,
1226 .name = "perl",
1227 .inst_size = sizeof(rlm_perl_t),
1228
1230 .onload = mod_load,
1231 .unload = mod_unload,
1232 .bootstrap = mod_bootstrap,
1234 .detach = mod_detach,
1235
1236 .thread_inst_size = sizeof(rlm_perl_thread_t),
1237 .thread_instantiate = mod_thread_instantiate,
1238 .thread_detach = mod_thread_detach,
1239 },
1240 .method_group = {
1241 .bindings = (module_method_binding_t[]){
1242 /*
1243 * Hack to support old configurations
1244 */
1245 { .section = SECTION_NAME("accounting", CF_IDENT_ANY), .method = mod_accounting },
1246 { .section = SECTION_NAME("authenticate", CF_IDENT_ANY), .method = mod_authenticate },
1247 { .section = SECTION_NAME("authorize", CF_IDENT_ANY), .method = mod_authorize },
1248
1249 { .section = SECTION_NAME("recv", "accounting-request"), .method = mod_preacct },
1250 { .section = SECTION_NAME("recv", CF_IDENT_ANY), .method = mod_authorize },
1251
1252 { .section = SECTION_NAME("send", CF_IDENT_ANY), .method = mod_post_auth },
1254 }
1255 }
1256};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
static int const char char buffer[256]
Definition acutest.h:576
int const char * file
Definition acutest.h:702
log_entry msg
Definition acutest.h:794
#define RCSID(id)
Definition build.h:483
#define DIAG_UNKNOWN_PRAGMAS
Definition build.h:456
#define DIAG_ON(_x)
Definition build.h:458
#define DIAG_OFF(_x)
Definition build.h:457
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:642
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:256
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:297
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:418
@ CONF_FLAG_FILE_INPUT
File matching value must exist, and must be readable.
Definition cf_parse.h:424
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:579
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:632
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1171
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1028
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:684
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:618
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:664
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1594
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1578
#define cf_item_next(_ci, _curr)
Definition cf_util.h:92
#define CF_IDENT_ANY
Definition cf_util.h:78
static int split(char **input, char **output, bool syntax_string)
Definition command.c:385
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:406
static void * fr_dcursor_next_peek(fr_dcursor_t *cursor)
Return the next iterator item without advancing the cursor.
Definition dcursor.h:303
#define MEM(x)
Definition debug.h:36
int dependency_version_number_add(CONF_SECTION *cs, char const *name, char const *version)
Add a library/server version pair to the main configuration.
Definition dependency.c:153
#define ERROR(fmt,...)
Definition dhcpclient.c:41
#define DEBUG(fmt,...)
Definition dhcpclient.c:39
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3263
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2400
static fr_slen_t in
Definition dict.h:824
Test enumeration values.
Definition dict_test.h:92
void * dl_open_by_sym(char const *sym_name, int flags)
Utility function to dlopen the library containing a particular symbol.
Definition dl.c:186
#define RTLD_NOW
Definition dl.c:44
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static xlat_action_t perl_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Call perl code using an xlat.
Definition rlm_perl.c:445
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define DEBUG3(_fmt,...)
Definition log.h:266
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
talloc_free(reap)
fr_log_t default_log
Definition log.c:291
void fr_log(fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt,...)
Send a server log message to its destination.
Definition log.c:583
#define ENTER(_x)
Definition machine.h:93
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
long int ssize_t
unsigned char uint8_t
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
void * thread
Thread instance data.
Definition module_ctx.h:67
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Temporary structure to hold arguments for thread_instantiation calls.
Definition module_ctx.h:63
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:257
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition pair.c:2981
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1345
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:283
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
Definition pair.c:2784
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, bool tainted)
Convert string value to native attribute value.
Definition pair.c:2589
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1844
static const conf_parser_t config[]
Definition base.c:183
#define fr_assert(_expr)
Definition rad_assert.h:38
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define WARN(fmt,...)
Definition radclient.h:47
static bool cleanup
Definition radsniff.c:60
static rs_t * conf
Definition radsniff.c:53
#define RETURN_MODULE_RCODE(_rcode)
Definition rcode.h:64
#define RETURN_MODULE_FAIL
Definition rcode.h:56
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
static unlang_action_t mod_authenticate(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_chap.c:228
static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_chap.c:176
static unlang_action_t mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Write accounting data to Couchbase documents.
static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_detail.c:375
static int perl_sv_to_vblist(TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request, SV *sv)
Parse a Perl SV and create value boxes, appending to a list.
Definition rlm_perl.c:328
static int mod_detach(module_detach_ctx_t const *mctx)
Definition rlm_perl.c:1120
static int mod_load(void)
Definition rlm_perl.c:1166
PerlInterpreter * perl
Thread specific perl interpreter.
Definition rlm_perl.c:91
#define RLM_PERL_FUNC(_x)
Definition rlm_perl.c:947
HV * rad_perlconf_hv
holds "config" items (perl RAD_PERLCONF hash).
Definition rlm_perl.c:86
rlm_perl_replace_t replace
Definition rlm_perl.c:85
char const *char const * func_authorize
Definition rlm_perl.c:76
static xlat_arg_parser_t const perl_xlat_args[]
Definition rlm_perl.c:435
char const * func_detach
Definition rlm_perl.c:80
static void ** rlm_perl_get_handles(pTHX)
Definition rlm_perl.c:144
bool perl_parsed
Definition rlm_perl.c:84
static const conf_parser_t replace_config[]
Definition rlm_perl.c:96
char const * func_authenticate
Definition rlm_perl.c:77
char const * func_preacct
Definition rlm_perl.c:79
static XS(XS_radiusd_log)
Definition rlm_perl.c:199
EXTERN_C void boot_DynaLoader(pTHX_ CV *cv)
static void perl_parse_config(CONF_SECTION *cs, int lvl, HV *rad_hv)
Definition rlm_perl.c:543
#define RLM_PERL_CONF(_x)
Definition rlm_perl.c:107
char const * perl_flags
Definition rlm_perl.c:82
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition rlm_perl.c:1156
#define dl_modules
Definition rlm_perl.c:135
module_rlm_t rlm_perl
Definition rlm_perl.c:1223
static void rlm_perl_interp_free(PerlInterpreter *perl)
Definition rlm_perl.c:964
static unlang_action_t do_perl(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, PerlInterpreter *interp, char const *function_name)
Definition rlm_perl.c:836
static void mod_unload(void)
Definition rlm_perl.c:1207
static void xs_init(pTHX)
Definition rlm_perl.c:252
char const * func_post_auth
Definition rlm_perl.c:81
#define LOAD_WARN(_fmt,...)
static void rlm_perl_close_handles(void **handles)
Definition rlm_perl.c:178
static void perl_store_vps(request_t *request, fr_pair_list_t *vps, HV *rad_hv, const char *hash_name, bool dbg_print)
Definition rlm_perl.c:655
bool session
Should the session list be replaced after module call.
Definition rlm_perl.c:61
static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, char *key, SV *sv, const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
Definition rlm_perl.c:738
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Definition rlm_perl.c:992
PerlInterpreter * perl
Definition rlm_perl.c:83
static void perl_vp_to_svpvn_element(request_t *request, AV *av, fr_pair_t *vp, int *i, const char *hash_name, bool dbg_print)
Definition rlm_perl.c:605
#define dl_librefs
Definition rlm_perl.c:134
static int perl_vblist_to_av(AV *av, fr_value_box_list_t *head)
Convert a list of value boxes to a Perl array for passing to subroutines.
Definition rlm_perl.c:274
static void * perl_dlhandle
To allow us to load perl's symbols into the global symbol table.
Definition rlm_perl.c:94
#define LOAD_INFO(_fmt,...)
static const conf_parser_t module_config[]
Definition rlm_perl.c:110
static int get_hv_content(TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pair_list_t *vps, const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
Definition rlm_perl.c:801
static _Thread_local request_t * rlm_perl_request
Definition rlm_perl.c:132
bool reply
Should the reply list be replaced after module call.
Definition rlm_perl.c:59
bool control
Should the control list be replaced after module call.
Definition rlm_perl.c:60
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Definition rlm_perl.c:1019
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_perl.c:1042
static void rlm_perl_clear_handles(pTHX)
Definition rlm_perl.c:136
bool request
Should the request list be replaced after module call.
Definition rlm_perl.c:58
char const * func_accounting
Definition rlm_perl.c:78
static char const * name
static int instantiate(module_inst_ctx_t const *mctx)
Definition rlm_rest.c:1310
static unlang_action_t mod_preacct(rlm_rcode_t *p_result, module_ctx_t const *mctx, UNUSED request_t *request)
Definition rlm_test.c:246
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:329
size_t inst_size
Size of the module's instance data.
Definition module.h:203
void * data
Module's instance data.
Definition module.h:271
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:151
Named methods exported by a module.
Definition module.h:173
return count
Definition module.c:163
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define talloc_get_type_abort_const
Definition talloc.h:282
@ T_BARE_WORD
Definition token.h:120
bool required
Argument must be present, and non-empty.
Definition xlat.h:148
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:139
static fr_slen_t head
Definition xlat.h:422
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:168
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1554
Definition for a single argument consumend by an xlat function.
Definition xlat.h:147
#define ATTRIBUTE_EQ(_x, _y)
Definition pair.h:148
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
#define PAIR_VERIFY(_x)
Definition pair.h:191
void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_token_t quote)
Print the value of an attribute to a string.
Definition pair_print.c:53
#define PAIR_LIST_VERIFY(_x)
Definition pair.h:194
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:591
static fr_slen_t parent
Definition pair.h:851
#define FR_TYPE_STRUCTURAL
Definition types.h:296
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules)
Print one boxed value to a string.
Definition value.c:5352
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
Definition value.c:4148
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:621
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:632
#define fr_value_box_list_foreach(_list_head, _iter)
Definition value.h:206
static size_t char ** out
Definition value.h:997
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition xlat_ctx.h:52
An xlat calling ctx.
Definition xlat_ctx.h:49
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:365