The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
unit_test_module.c
Go to the documentation of this file.
1/*
2 * This program 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
5 * (at 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 * $Id: 68bb1c2ec382d3e7a859daef72e2abc5faad7643 $
18 *
19 * @file unit_test_module.c
20 * @brief Module test framework
21 *
22 * @copyright 2000-2018 The FreeRADIUS server project
23 * @copyright 2013 Alan DeKok (aland@freeradius.org)
24 * @copyright 2018 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
25 */
26RCSID("$Id: 68bb1c2ec382d3e7a859daef72e2abc5faad7643 $")
27
28#include <freeradius-devel/server/base.h>
29#include <freeradius-devel/server/map_proc.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/util/debug.h>
32#include <freeradius-devel/util/rand.h>
33#include <freeradius-devel/util/value.h>
34#include <freeradius-devel/util/strerror.h>
35#include <freeradius-devel/util/sbuff.h>
36#include <freeradius-devel/util/time.h>
37#include <freeradius-devel/io/listen.h>
38
39#include <freeradius-devel/tls/base.h>
40#include <freeradius-devel/tls/version.h>
41
42#include <freeradius-devel/unlang/base.h>
43#include <freeradius-devel/unlang/xlat_func.h>
44
45#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
46#include <freeradius-devel/radius/radius.h>
47
48#ifdef HAVE_GETOPT_H
49# include <getopt.h>
50#endif
51
52#define EXIT_WITH_FAILURE \
53do { \
54 ret = EXIT_FAILURE; \
55 goto cleanup; \
56} while (0)
57
58/*
59 * Global variables.
60 */
61static bool filedone = false;
62static int my_debug_lvl = 0;
63
64char const *radiusd_version = RADIUSD_VERSION_BUILD("unit_test_module");
65
68
69#define PROTOCOL_NAME unit_test_module_dict[1].proto
70
73 { .out = &dict_freeradius, .proto = "freeradius" },
74 { .out = &dict_protocol, .proto = "radius" }, /* hacked in-place with '-p protocol' */
76};
77
80
83 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_protocol },
84 { .out = &attr_net, .name = "Net", .type = FR_TYPE_TLV, .dict = &dict_freeradius },
85
87};
88
89/*
90 * Static functions.
91 */
92static void usage(main_config_t const *config, int status);
93
94static fr_client_t *client_alloc(TALLOC_CTX *ctx, char const *ip, char const *name)
95{
96 CONF_SECTION *cs;
97 fr_client_t *client;
98
99 cs = cf_section_alloc(ctx, NULL, "client", name);
100 MEM(cf_pair_alloc(cs, "ipaddr", ip, T_OP_EQ, T_BARE_WORD, T_BARE_WORD));
101 MEM(cf_pair_alloc(cs, "secret", "supersecret", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING));
102 MEM(cf_pair_alloc(cs, "nas_type", "test", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING));
103 MEM(cf_pair_alloc(cs, "shortname", "test", T_OP_EQ, T_BARE_WORD, T_DOUBLE_QUOTED_STRING));
107
108 client = client_afrom_cs(ctx, cs, NULL, 0);
109 if (!client) {
110 PERROR("Failed creating test client");
111 fr_assert(0);
112 }
113 talloc_steal(client, cs);
114 fr_assert(client);
115
116 return client;
117}
118
120{
121 if (fr_type_is_leaf(vp->vp_type)) {
122 vp->vp_immutable = false;
123
124 return;
125 }
126
128
129 fr_pair_list_foreach(&vp->vp_group, child) {
130 pair_mutable(child);
131 }
132}
133
134static request_t *request_from_internal(TALLOC_CTX *ctx)
135{
136 request_t *request;
137
138 /*
139 * Create and initialize the new request.
140 */
141 request = request_local_alloc_internal(ctx, NULL);
142 if (!request->packet) request->packet = fr_packet_alloc(request, false);
143 if (!request->reply) request->reply = fr_packet_alloc(request, false);
144
145 request->packet->socket = (fr_socket_t){
146 .type = SOCK_DGRAM,
147 .inet = {
148 .src_ipaddr = {
149 .af = AF_INET,
150 .prefix = 32,
151 .addr = {
152 .v4 = {
153 .s_addr = htonl(INADDR_LOOPBACK)
154 }
155 }
156 },
157 .src_port = 18120,
158 .dst_ipaddr = {
159 .af = AF_INET,
160 .prefix = 32,
161 .addr = {
162 .v4 = {
163 .s_addr = htonl(INADDR_LOOPBACK)
164 }
165 }
166 },
167 .dst_port = 1812
168 }
169 };
170
171 request->log.dst = talloc_zero(request, log_dst_t);
172 request->log.dst->func = vlog_request;
173 request->log.dst->uctx = &default_log;
174 request->log.dst->lvl = fr_debug_lvl;
175
176 request->master_state = REQUEST_ACTIVE;
177 request->log.lvl = fr_debug_lvl;
178 request->async = talloc_zero(request, fr_async_t);
179
180 if (fr_packet_pairs_from_packet(request->request_ctx, &request->request_pairs, request->packet) < 0) {
181 talloc_free(request);
182 fprintf(stderr, "Failed converting packet IPs to attributes");
183 return NULL;
184 }
185
186 return request;
187}
188
189static request_t *request_from_file(TALLOC_CTX *ctx, FILE *fp, fr_client_t *client, CONF_SECTION *server_cs)
190{
191 fr_pair_t *vp;
192 request_t *request;
193 fr_dcursor_t cursor;
194
195 static int number = 0;
196
197 if (!dict_protocol) {
198 fr_strerror_printf_push("%s dictionary failed to load", PROTOCOL_NAME);
199 return NULL;
200 }
201
202 /*
203 * Create and initialize the new request.
204 */
205 request = request_local_alloc_external(ctx, (&(request_init_args_t){ .namespace = dict_protocol }));
206
207 request->packet = fr_packet_alloc(request, false);
208 if (!request->packet) {
209 oom:
210 fr_strerror_const("No memory");
211 error:
212 talloc_free(request);
213 return NULL;
214 }
215 request->packet->timestamp = fr_time();
216
217 request->reply = fr_packet_alloc(request, false);
218 if (!request->reply) goto oom;
219
220 request->client = client;
221 request->number = number++;
222 request->name = talloc_typed_asprintf(request, "%" PRIu64, request->number);
223 request->master_state = REQUEST_ACTIVE;
224
225 /*
226 * Read packet from fp
227 */
228 if (fr_pair_list_afrom_file(request->request_ctx, dict_protocol, &request->request_pairs, fp, &filedone, true) < 0) {
229 goto error;
230 }
231
232 /*
233 * Pretend that the attributes came in "over the wire".
234 *
235 * @todo - do this only for protocol attributes, and not internal ones?
236 */
237 fr_pair_list_tainted(&request->request_pairs);
238
239 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_packet_type);
240 if (!vp) {
241 fr_strerror_printf("Input packet does not specify a Packet-Type");
242 goto error;
243 }
244 /*
245 * Set the defaults for IPs, etc.
246 */
247 request->packet->code = vp->vp_uint32;
248
249 /*
250 * Now delete the packet-type to ensure
251 * the virtual attribute gets used in
252 * the tests.
253 */
254 fr_pair_delete_by_da(&request->request_pairs, attr_packet_type);
255
256 request->packet->socket = (fr_socket_t){
257 .type = SOCK_DGRAM,
258 .inet = {
259 .src_ipaddr = {
260 .af = AF_INET,
261 .prefix = 32,
262 .addr = {
263 .v4 = {
264 .s_addr = htonl(INADDR_LOOPBACK)
265 }
266 }
267 },
268 .src_port = 18120,
269 .dst_ipaddr = {
270 .af = AF_INET,
271 .prefix = 32,
272 .addr = {
273 .v4 = {
274 .s_addr = htonl(INADDR_LOOPBACK)
275 }
276 }
277 },
278 .dst_port = 1812
279 }
280 };
281
282 /*
283 * Fill in the packet header from attributes, and then
284 * re-realize the attributes.
285 */
286 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_packet_type);
287 if (vp) request->packet->code = vp->vp_uint32;
288
289 fr_packet_net_from_pairs(request->packet, &request->request_pairs);
290
291 /*
292 * The input might have updated only some of the Net.*
293 * attributes. So for consistency, we create all of them
294 * from the packet header.
295 */
296 if (fr_packet_pairs_from_packet(request->request_ctx, &request->request_pairs, request->packet) < 0) {
297 fr_strerror_const("Failed converting packet IPs to attributes");
298 goto error;
299 }
300
301 /*
302 * For laziness in the tests, allow the Net.* to be mutable
303 */
304 for (vp = fr_pair_dcursor_by_ancestor_init(&cursor, &request->request_pairs, attr_net);
305 vp != NULL;
306 vp = fr_dcursor_next(&cursor)) {
308 }
309
310 if (fr_debug_lvl) {
311 for (vp = fr_pair_dcursor_init(&cursor, &request->request_pairs);
312 vp;
313 vp = fr_dcursor_next(&cursor)) {
314 /*
315 * Take this opportunity to verify all the fr_pair_ts are still valid.
316 */
317 if (!talloc_get_type(vp, fr_pair_t)) {
318 ERROR("Expected fr_pair_t pointer got \"%s\"", talloc_get_name(vp));
319
321 fr_assert(0);
322 }
323
324 fr_log(&default_log, L_DBG, __FILE__, __LINE__, "%pP", vp);
325 }
326 }
327
328 /*
329 * Build the reply template from the request.
330 */
331 fr_socket_addr_swap(&request->reply->socket, &request->packet->socket);
332
333 request->reply->id = request->packet->id;
334 request->reply->code = 0; /* UNKNOWN code */
335 memcpy(request->reply->vector, request->packet->vector, sizeof(request->reply->vector));
336 request->reply->data = NULL;
337 request->reply->data_len = 0;
338
339 /*
340 * Debugging
341 */
342 request->log.dst = talloc_zero(request, log_dst_t);
343 request->log.dst->func = vlog_request;
344 request->log.dst->uctx = &default_log;
345 request->log.dst->lvl = fr_debug_lvl;
346
347 request->master_state = REQUEST_ACTIVE;
348 request->log.lvl = fr_debug_lvl;
349 request->async = talloc_zero(request, fr_async_t);
350
351
352 /*
353 * New async listeners
354 */
355 unlang_call_push(NULL, request, server_cs, UNLANG_TOP_FRAME);
356
357 return request;
358}
359
360
361static void print_packet(FILE *fp, fr_packet_t *packet, fr_pair_list_t *list)
362{
363 fr_dict_enum_value_t const *dv;
364 fr_log_t log;
365
366 (void) fr_log_init_fp(&log, fp);
367
369 if (dv) {
370 fr_log(&default_log, L_DBG, __FILE__, __LINE__, "Packet-Type = %s", dv->name);
371 } else {
372 fr_log(&default_log, L_DBG, __FILE__, __LINE__, "Packet-Type = %u", packet->code);
373 }
374
375 fr_pair_list_log(&default_log, 2, list);
376}
377
378/*
379 * A common function for reports of too much text when handling xlat
380 * and xlat_expr in do_xlats().
381 * The convolution deals with the edge case of the line being so long
382 * that it plus the surrounding text from the format could won't fit
383 * in the output sbuff, along with the fact that you don't print the
384 * %d or %.*s. OTOH it does include slen, but...
385 * * the format string is 41 characters minus 6 for %d and %.*s
386 * * given that slen reflects text read from line, once slen is
387 * large enough, we know line will fit
388 */
389static inline CC_HINT(always_inline) void too_much_text(fr_sbuff_t *out, ssize_t slen, fr_sbuff_t *line)
390{
391 char const *format = "ERROR offset %d 'Too much text' ::%.*s::";
392
393 (void) fr_sbuff_in_sprintf(out, format, (int) slen,
394 fr_sbuff_remaining(out) - (strlen(format) - 5),
396}
397
398/*
399 * Read a file composed of xlat's and expected results
400 */
401static bool do_xlats(fr_event_list_t *el, request_t *request, char const *filename, FILE *fp)
402{
403 int lineno = 0;
404 ssize_t len;
405 char line_buff[8192];
406 char output_buff[8192];
407 char unescaped[sizeof(output_buff)];
410
411 static fr_sbuff_escape_rules_t unprintables = {
412 .name = "unprintables",
413 .chr = '\\',
414 .esc = {
417 },
418 .do_utf8 = true,
419 .do_oct = true
420 };
421
422 while (fgets(line_buff, sizeof(line_buff), fp) != NULL) {
423 lineno++;
424
425 line = FR_SBUFF_IN(line_buff, sizeof(line_buff));
426 if (!fr_sbuff_adv_to_chr(&line, SIZE_MAX, '\n')) {
427 if (!feof(fp)) {
428 fprintf(stderr, "%s[%d] Line too long\n", filename, lineno);
429 return false;
430 }
431 } else {
432 fr_sbuff_terminate(&line);
433 }
434 line.end = line.p;
435 fr_sbuff_set_to_start(&line);
436
437 /*
438 * Ignore blank lines and comments
439 */
440 fr_sbuff_adv_past_whitespace(&line, SIZE_MAX, NULL);
441 if (*fr_sbuff_current(&line) < ' ') continue;
442 if (fr_sbuff_is_char(&line, '#')) continue;
443
444 /*
445 * Look for "match", as it needs the output_buffer to be left alone.
446 */
447 if (fr_sbuff_adv_past_str_literal(&line, "match ") > 0) {
448 size_t output_len = strlen(output_buff);
449
450 if (!fr_sbuff_is_str(&line, output_buff, output_len) || (output_len != fr_sbuff_remaining(&line))) {
451 fprintf(stderr, "Mismatch at %s[%u]\n\tgot : %s (%zu)\n\texpected : %s (%zu)\n",
452 filename, lineno, output_buff, output_len, fr_sbuff_current(&line), fr_sbuff_remaining(&line));
453 return false;
454 }
455 continue;
456 }
457
458 /*
459 * The rest of the keywords create output.
460 */
461 output_buff[0] = '\0';
462 out = FR_SBUFF_OUT(output_buff, sizeof(output_buff));
463
464 /*
465 * Look for "xlat"
466 */
467 if (fr_sbuff_adv_past_str_literal(&line, "xlat ") > 0) {
468 ssize_t slen;
469 TALLOC_CTX *xlat_ctx = talloc_init_const("xlat");
470 xlat_exp_head_t *head = NULL;
471 fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double };
472 tmpl_rules_t t_rules = (tmpl_rules_t) {
473 .attr = {
475 .list_def = request_attr_request,
476 .allow_unresolved = true,
477 },
478 .xlat = {
479 .runtime_el = el,
480 },
481 .at_runtime = true,
482 };
483
484
485 slen = xlat_tokenize(xlat_ctx, &head, &line, &p_rules, &t_rules);
486 if (slen <= 0) {
488 fr_sbuff_in_sprintf(&out, "ERROR offset %d '%s'", (int) -slen, fr_strerror());
489 continue;
490 }
491
492 if (fr_sbuff_remaining(&line) > 0) {
494 too_much_text(&out, slen, &line);
495 continue;
496 }
497
498 len = xlat_eval_compiled(unescaped, sizeof(unescaped), request, head, NULL, NULL);
499 if (len < 0) {
500 char const *err = fr_strerror();
502 (void) fr_sbuff_in_sprintf(&out, "ERROR expanding xlat: %s", *err ? err : "no error provided");
503 continue;
504 }
505
506 /*
507 * Escape the output as if it were a double quoted string.
508 */
509 fr_sbuff_in_escape(&out, unescaped, len, &unprintables);
510
511 TALLOC_FREE(xlat_ctx); /* also frees 'head' */
512 continue;
513 }
514
515 /*
516 * Look for "xlat_expr"
517 */
518 if (fr_sbuff_adv_past_str_literal(&line, "xlat_expr ") > 0) {
519 ssize_t slen;
520 TALLOC_CTX *xlat_ctx = talloc_init_const("xlat");
521 xlat_exp_head_t *head = NULL;
522
524 &line,
525 NULL,
526 &(tmpl_rules_t) {
527 .attr = {
528 .dict_def = dict_protocol,
529 .list_def = request_attr_request,
530 .allow_unresolved = true,
531 },
532 .xlat = {
533 .runtime_el = el,
534 },
535 .at_runtime = true,
536 });
537 if (slen <= 0) {
539 fr_sbuff_in_sprintf(&out, "ERROR offset %d '%s'", (int) -slen - 1, fr_strerror());
540 continue;
541 }
542
543 if (fr_sbuff_remaining(&line) > 0) {
545 too_much_text(&out, slen, &line);
546 continue;
547 }
548
549 if (xlat_resolve(head, NULL) < 0) {
551 (void) fr_sbuff_in_sprintf(&out, "ERROR resolving xlat: %s", fr_strerror());
552 continue;
553 }
554
555 len = xlat_eval_compiled(unescaped, sizeof(unescaped), request, head, NULL, NULL);
556 if (len < 0) {
557 char const *err = fr_strerror();
559 (void) fr_sbuff_in_sprintf(&out, "ERROR expanding xlat: %s", *err ? err : "no error provided");
560 continue;
561 }
562
563 /*
564 * Escape the output as if it were a double quoted string.
565 */
566 fr_sbuff_in_escape(&out, unescaped, len, &unprintables);
567
568 TALLOC_FREE(xlat_ctx); /* also frees 'head' */
569 continue;
570 }
571
572 fprintf(stderr, "Unknown keyword in %s[%d]\n", filename, lineno);
573 return false;
574 }
575
576 return true;
577}
578
579/*
580 * Verify the result of the map.
581 */
582static int map_proc_verify(CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst,
583 tmpl_t const *src, UNUSED map_list_t const *maps)
584{
585 if (!src) {
586 cf_log_err(cs, "Missing source");
587
588 return -1;
589 }
590
591 return 0;
592}
593
595 UNUSED request_t *request, UNUSED fr_value_box_list_t *src,
596 UNUSED map_list_t const *maps)
597{
599}
600
601static request_t *request_clone(request_t *old, int number, CONF_SECTION *server_cs)
602{
603 request_t *request;
604
605 request = request_local_alloc_internal(NULL, (&(request_init_args_t){ .namespace = old->proto_dict }));
606 if (!request) return NULL;
607
608 if (!request->packet) request->packet = fr_packet_alloc(request, false);
609 if (!request->reply) request->reply = fr_packet_alloc(request, false);
610
611 memcpy(request->packet, old->packet, sizeof(*request->packet));
612 (void) fr_pair_list_copy(request->request_ctx, &request->request_pairs, &old->request_pairs);
613 request->packet->timestamp = fr_time();
614 request->number = number;
615 request->name = talloc_typed_asprintf(request, "%" PRIu64, request->number);
616
617 unlang_call_push(NULL, request, server_cs, UNLANG_TOP_FRAME);
618
619 request->master_state = REQUEST_ACTIVE;
620
621 return request;
622}
623
624static void cancel_request(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t when, void *uctx)
625{
626 request_t *request = talloc_get_type_abort(uctx, request_t);
628 request->rcode = RLM_MODULE_TIMEOUT;
629}
630
632
633/** Sythentic time source for tests
634 *
635 * This allows us to artificially advance time for tests.
636 */
642 { .required = true, .type = FR_TYPE_TIME_DELTA, .single = true },
644};
645
647
649{
650 request_t *request = talloc_get_type_abort(uctx, request_t);
652}
653
655 UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
656{
657 fr_value_box_t *vb;
658
659 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
660 vb->vb_time_delta = time_offset;
662
663 return XLAT_ACTION_DONE;
664}
665
667 UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, fr_value_box_list_t *in)
668{
669 fr_value_box_t *delta;
670
671 XLAT_ARGS(in, &delta);
672
673 /*
674 * This ensures we take a pass through the timer list
675 * otherwise the time advances can be ignored.
676 */
678 RPERROR("Failed to add timer");
679 return XLAT_ACTION_FAIL;
680 }
681
683
684 time_offset = fr_time_delta_add(time_offset, delta->vb_time_delta);
685
687
688 unlang_xlat_yield(request, xlat_func_time_advance_resume, NULL, 0, NULL);
689
690 return XLAT_ACTION_YIELD;
691}
692
693/**
694 *
695 * @hidecallgraph
696 */
697int main(int argc, char *argv[])
698{
699 int ret = EXIT_SUCCESS;
700 int c;
701 int count = 1;
702 const char *input_file = NULL;
703 const char *xlat_input_file = NULL;
704 const char *output_file = NULL;
705 const char *filter_file = NULL;
706 FILE *fp = NULL;
707 request_t *request = NULL;
708 fr_pair_t *vp;
709 fr_pair_list_t filter_vps;
710 bool xlat_only = false;
711 fr_event_list_t *el = NULL;
712 fr_client_t *client = NULL;
713 fr_dict_t *dict = NULL;
714 fr_dict_t const *dict_check;
715 char const *receipt_file = NULL;
716
717 xlat_t *time_advance = NULL;
718
719 TALLOC_CTX *autofree;
720 TALLOC_CTX *thread_ctx;
721
722 char *p;
724
725 CONF_SECTION *server_cs;
726
727#ifndef NDEBUG
728 size_t memory_used_before = 0;
729 size_t memory_used_after = 0;
730#endif
731 virtual_server_t const *vs;
732
733 fr_pair_list_init(&filter_vps);
734
735 /*
736 * Must be called first, so the handler is called last
737 */
739
741 thread_ctx = talloc_new(autofree);
742
744 if (!config) {
745 fr_perror("unit_test_module");
746 fr_exit_now(EXIT_FAILURE);
747 }
748
749 p = strrchr(argv[0], FR_DIR_SEP);
750 if (!p) {
751 main_config_name_set_default(config, argv[0], false);
752 } else {
754 }
755
757
758 /*
759 * If the server was built with debugging enabled always install
760 * the basic fatal signal handlers.
761 */
762#ifndef NDEBUG
763 if (fr_fault_setup(autofree, getenv("PANIC_ACTION"), argv[0]) < 0) {
764 fr_perror("%s", config->name);
765 fr_exit_now(EXIT_FAILURE);
766 }
767#else
769#endif
770
771 fr_debug_lvl = 0;
773
774 /*
775 * The tests should have only IPs, not host names.
776 */
778
779 /*
780 * We always log to stdout.
781 */
783 default_log.fd = STDOUT_FILENO;
785
786 /* Process the options. */
787 while ((c = getopt(argc, argv, "c:d:D:f:hi:I:mMn:o:p:r:S:xXz")) != -1) {
788 switch (c) {
789 case 'c':
790 count = atoi(optarg);
791 break;
792
793 case 'd':
795 break;
796
797 case 'D':
799 break;
800
801 case 'f':
802 filter_file = optarg;
803 break;
804
805 case 'h':
806 usage(config, EXIT_SUCCESS);
807 break;
808
809 case 'i':
810 input_file = optarg;
811 break;
812
813 case 'I':
814 xlat_input_file = optarg;
815 xlat_only = true;
816 break;
817
818 case 'M':
819 talloc_enable_leak_report();
820 break;
821
822 case 'n':
823 config->name = optarg;
824 break;
825
826 case 'o':
827 output_file = optarg;
828 break;
829
830 case 'p':
831 PROTOCOL_NAME = optarg;
832 break;
833
834 case 'r':
835 receipt_file = optarg;
836 break;
837
838 case 'S': /* Migration support */
839#if 0
840 if (main_config_parse_option(optarg) < 0) {
841 fprintf(stderr, "%s: Unknown configuration option '%s'\n",
842 config->name, optarg);
843 fr_exit_now(EXIT_FAILURE);
844 }
845#endif
846 break;
847
848 case 'X':
849 fr_debug_lvl += 2;
851 break;
852
853 case 'x':
854 fr_debug_lvl++;
855 if (fr_debug_lvl > 2) default_log.print_level = true;
856 break;
857
858 case 'z':
859 my_debug_lvl++;
860 break;
861
862 default:
863 usage(config, EXIT_FAILURE);
864 break;
865 }
866 }
867
868 if (receipt_file && (fr_unlink(receipt_file) < 0)) {
869 fr_perror("%s", config->name);
871 }
872
873#ifdef WITH_TLS
874 /*
875 * Mismatch between build time OpenSSL and linked SSL, better to die
876 * here than segfault later.
877 */
879
880 /*
881 * Initialising OpenSSL once, here, is safer than having individual modules do it.
882 * Must be called before display_version to ensure relevant engines are loaded.
883 *
884 * fr_openssl_init() must be called before *ANY* OpenSSL functions are used, which is why
885 * it's called so early.
886 */
887 if (fr_openssl_init() < 0) EXIT_WITH_FAILURE;
888#endif
889
891
892 /*
893 * Mismatch between the binary and the libraries it depends on
894 */
896 fr_perror("%s", config->name);
897 ret = EXIT_FAILURE;
898 goto cleanup;
899 }
900
901 /*
902 * Initialize the DL infrastructure, which is used by the
903 * config file parser.
904 */
905 modules_init(config->lib_dir);
906
907 if (!fr_dict_global_ctx_init(NULL, true, config->dict_dir)) {
908 fr_perror("%s", config->name);
910 }
911
913 fr_perror("%s", config->name);
915 }
916
917#ifdef WITH_TLS
918 if (fr_tls_dict_init() < 0) EXIT_WITH_FAILURE;
919#endif
920
921 /*
922 * Load the custom dictionary
923 */
924 if (fr_dict_read(dict, config->confdir, FR_DICTIONARY_FILE) == -1) {
925 PERROR("Failed to initialize the dictionaries");
927 }
928
930 fr_perror("%s", config->name);
932 }
934 fr_perror("%s", config->name);
936 }
937
938 if (request_global_init() < 0) {
939 fr_perror("unit_test_module");
941 }
942
943 if (map_proc_register(NULL, NULL, "test-fail", mod_map_proc, map_proc_verify, 0, 0) < 0) {
945 }
946
947 /*
948 * Needed for the triggers. Which are always run-time expansions.
949 */
950 if (main_loop_init() < 0) {
951 PERROR("Failed initialising main event loop");
953 }
954 /*
955 * Initialise the interpreter, registering operations.
956 * This initialises
957 */
958 if (unlang_global_init() < 0) {
959 fr_perror("%s", config->name);
961 }
962
963 time_advance = xlat_func_register(NULL, "time.advance", xlat_func_time_advance, FR_TYPE_VOID);
964 if (!time_advance) EXIT_WITH_FAILURE;
966
967 /*
968 * Ensure that we load the correct virtual server for the
969 * protocol, if necessary.
970 */
971 if (!getenv("PROTOCOL")) {
972 setenv("PROTOCOL", PROTOCOL_NAME, true);
973 }
974
975 /*
976 * Setup the global structures for module lists
977 */
978 if (modules_rlm_init() < 0) {
979 fr_perror("%s", config->name);
981 }
982 if (virtual_servers_init() < 0) {
983 fr_perror("%s", config->name);
985 }
986
987 if (main_config_init(config) < 0) {
989 }
990
991 /*
992 * Create a dummy client on 127.0.0.1, if one doesn't already exist.
993 */
994 client = client_find(NULL, &(fr_ipaddr_t) { .af = AF_INET, .prefix = 32, .addr.v4.s_addr = htonl(INADDR_LOOPBACK) },
995 IPPROTO_IP);
996 if (!client) {
997 client = client_alloc(NULL, "127.0.0.1", "test");
998 client_add(NULL, client);
999 }
1000
1001 if (server_init(config->root_cs, config->confdir, dict) < 0) EXIT_WITH_FAILURE;
1002
1003 vs = virtual_server_find("default");
1004 if (!vs) {
1005 ERROR("Cannot find virtual server 'default'");
1007 }
1008
1009 server_cs = virtual_server_cs(vs);
1010
1011 /*
1012 * Do some sanity checking.
1013 */
1014 dict_check = virtual_server_dict_by_name("default");
1015 if (!dict_check || !fr_dict_compatible(dict_check, dict_protocol)) {
1016 ERROR("Virtual server namespace does not match requested namespace '%s'", PROTOCOL_NAME);
1018 }
1019
1020 /*
1021 * Get the main event list.
1022 */
1024 fr_assert(el != NULL);
1026
1027 /*
1028 * Simulate thread specific instantiation
1029 */
1032 if (xlat_thread_instantiate(thread_ctx, el) < 0) EXIT_WITH_FAILURE;
1033 unlang_thread_instantiate(thread_ctx);
1034
1035 /*
1036 * Set the panic action (if required)
1037 */
1038 {
1039 char const *panic_action = NULL;
1040
1041 panic_action = getenv("PANIC_ACTION");
1042 if (!panic_action) panic_action = config->panic_action;
1043
1044 if (panic_action && (fr_fault_setup(autofree, panic_action, argv[0]) < 0)) {
1045 fr_perror("%s", config->name);
1047 }
1048 }
1049
1050 setlinebuf(stdout); /* unbuffered output */
1051
1052#ifndef NDEBUG
1053 memory_used_before = talloc_total_size(autofree);
1054#endif
1055
1056 if (!input_file && !xlat_only) input_file = "-";
1057
1058 if (input_file) {
1059 if (strcmp(input_file, "-") == 0) {
1060 fp = stdin;
1061 } else {
1062 fp = fopen(input_file, "r");
1063 if (!fp) {
1064 fprintf(stderr, "Failed reading %s: %s\n",
1065 input_file, fr_syserror(errno));
1067 }
1068 }
1069
1070 /*
1071 * Grab the VPs from stdin, or from the file.
1072 */
1073 request = request_from_file(autofree, fp, client, server_cs);
1074 if (!request) {
1075 fr_perror("Failed reading input from %s", input_file);
1077 }
1078 } else {
1080 }
1081
1082 /*
1083 * For simplicity, read xlat's.
1084 */
1085 if (xlat_only) {
1086 if (fp && (fp != stdin)) fclose(fp);
1087
1088 fp = fopen(xlat_input_file, "r");
1089 if (!fp) {
1090 fprintf(stderr, "Failed reading %s: %s\n",
1091 xlat_input_file, fr_syserror(errno));
1093 }
1094
1095 if (!do_xlats(el, request, xlat_input_file, fp)) ret = EXIT_FAILURE;
1096 fclose(fp);
1097 goto cleanup;
1098 }
1099
1100 /*
1101 * No filter file, OR there's no more input, OR we're
1102 * reading from a file, and it's different from the
1103 * filter file.
1104 */
1105 if (!filter_file || filedone ||
1106 ((input_file != NULL) && (strcmp(filter_file, input_file) != 0))) {
1107 if (output_file) {
1108 if (fp && (fp != stdin)) fclose(fp);
1109 fp = NULL;
1110 }
1111 filedone = false;
1112 }
1113
1114 /*
1115 * There is a filter file. If necessary, open it. If we
1116 * already are reading it via "input_file", then we don't
1117 * need to re-open it.
1118 */
1119 if (filter_file) {
1120 if (!fp) {
1121 fp = fopen(filter_file, "r");
1122 if (!fp) {
1123 fprintf(stderr, "Failed reading %s: %s\n", filter_file, fr_syserror(errno));
1125 }
1126 }
1127
1128 if (fr_pair_list_afrom_file(request->request_ctx, dict_protocol, &filter_vps, fp, &filedone, true) < 0) {
1129 fr_perror("Failed reading attributes from %s", filter_file);
1131 }
1132
1133 /*
1134 * Filter files can't be empty.
1135 */
1136 if (fr_pair_list_empty(&filter_vps)) {
1137 fr_perror("No attributes in filter file %s", filter_file);
1139 }
1140
1141 /*
1142 * FIXME: loop over input packets.
1143 */
1144 fclose(fp);
1145 }
1146
1147 if (count == 1) {
1148 fr_timer_in(request, el->tl, &request->timeout, config->worker.max_request_time, false, cancel_request, request);
1150
1151 } else {
1152 int i;
1153 request_t *cached = request;
1154
1155 for (i = 0; i < count; i++) {
1156#ifndef NDEBUG
1157 size_t request_used_before, request_used_after;
1158#endif
1159
1160 request = request_clone(cached, i, server_cs);
1161
1162#ifndef NDEBUG
1163 request_used_before = talloc_total_size(autofree);
1164
1165 /*
1166 * Artificially limit the number of instructions which are run.
1167 */
1168 if (config->ins_max) {
1169 if (config->ins_countup) {
1170 request->ins_max = i + 1;
1171 } else {
1172 request->ins_max = config->ins_max;
1173 }
1174
1175 if (request->ins_max < 10) request->ins_max = 10;
1176
1177 request->ins_count = 0;
1178 }
1179#endif
1180
1181 fr_timer_in(request, el->tl, &request->timeout, config->worker.max_request_time, false, cancel_request, request);
1183 talloc_free(request);
1184
1185#ifndef NDEBUG
1186 request_used_after = talloc_total_size(autofree);
1187 fr_assert(request_used_after == request_used_before);
1188#endif
1189 }
1190
1191 request = cached;
1192 }
1193
1194 if (!output_file || (strcmp(output_file, "-") == 0)) {
1195 fp = stdout;
1196 } else {
1197 fp = fopen(output_file, "w");
1198 if (!fp) {
1199 fprintf(stderr, "Failed writing %s: %s\n", output_file, fr_syserror(errno));
1200 goto cleanup;
1201 }
1202 }
1203
1204 print_packet(fp, request->reply, &request->reply_pairs);
1205
1206 if (output_file) fclose(fp);
1207
1208 /*
1209 * Update the list with the response type, so that it can
1210 * be matched in filters.
1211 *
1212 * Some state machines already include a response Packet-Type
1213 * so we need to try and update it, else we end up with two!
1214 */
1215 if (!fr_pair_list_empty(&filter_vps)) {
1216 fr_pair_t const *failed[2];
1217
1219 vp->vp_uint32 = request->reply->code;
1220
1221 if (!fr_pair_validate(failed, &filter_vps, &request->reply_pairs)) {
1222 fr_pair_validate_debug(failed);
1223
1224 fr_perror("Output file %s does not match attributes in filter %s",
1225 output_file ? output_file : "-", filter_file);
1226 fr_fprintf_pair_list(stderr, &filter_vps);
1227 ret = EXIT_FAILURE;
1228 goto cleanup;
1229 }
1230 }
1231
1232 INFO("Exiting normally");
1233
1234cleanup:
1235 talloc_free(request);
1236
1237 /*
1238 * No leaks.
1239 */
1240#ifndef NDEBUG
1241 memory_used_after = talloc_total_size(autofree);
1242 if (memory_used_after != memory_used_before) {
1243 printf("WARNING: May have leaked memory (%zd - %zd = %zd)\n",
1244 memory_used_after, memory_used_before, memory_used_after - memory_used_before);
1245 }
1246#endif
1247
1248 map_proc_unregister("test-fail");
1249
1250 /*
1251 * Free thread data
1252 */
1253 talloc_free(thread_ctx);
1254
1255 /*
1256 * Ensure all thread local memory is cleaned up
1257 * at the appropriate time. This emulates what's
1258 * done with worker/network threads in the
1259 * scheduler.
1260 */
1262
1263 /*
1264 * Give processes a chance to exit
1265 */
1267
1269
1270 /*
1271 * Ensure all thread local memory is cleaned up
1272 * at the appropriate time. This emulates what's
1273 * done with worker/network threads in the
1274 * scheduler.
1275 */
1277
1278 server_free();
1279
1280 /*
1281 * Virtual servers need to be freed before modules
1282 * as state entries containing data with module-specific
1283 * destructors may exist.
1284 */
1286
1287 /*
1288 * Free modules, this needs to be done explicitly
1289 * because some libraries used by modules use atexit
1290 * handlers registered after ours, and they may deinit
1291 * themselves before we free the modules and cause
1292 * crashes on exit.
1293 */
1295
1296 /*
1297 * And now nothing should be left anywhere except the
1298 * parsed configuration items.
1299 */
1301
1302#ifdef WITH_TLS
1303 fr_tls_dict_free();
1304#endif
1305
1306 /*
1307 * Free any autoload dictionaries
1308 */
1310
1311 /*
1312 * Free our explicitly loaded internal dictionary
1313 */
1314 if (fr_dict_free(&dict, __FILE__) < 0) {
1315 fr_perror("unit_test_module - dict");
1316 ret = EXIT_FAILURE;
1317 }
1318
1319 /*
1320 * Free any openssl resources and the TLS dictionary
1321 */
1322#ifdef WITH_TLS
1323 fr_openssl_free();
1324#endif
1325
1326 if (receipt_file && (ret == EXIT_SUCCESS) && (fr_touch(NULL, receipt_file, 0644, true, 0755) <= 0)) {
1327 fr_perror("unit_test_module");
1328 ret = EXIT_FAILURE;
1329 }
1330
1331 if (talloc_free(autofree) < 0) {
1332 fr_perror("unit_test_module - autofree");
1333 ret = EXIT_FAILURE;
1334 }
1335
1336 /*
1337 * Ensure our atexit handlers run before any other
1338 * atexit handlers registered by third party libraries.
1339 */
1341
1342 return ret;
1343}
1344
1345
1346/*
1347 * Display the syntax for starting this program.
1348 */
1349static NEVER_RETURNS void usage(main_config_t const *config, int status)
1350{
1351 FILE *output = status ? stderr : stdout;
1352
1353 fprintf(output, "Usage: %s [options]\n", config->name);
1354 fprintf(output, "Options:\n");
1355 fprintf(output, " -c <count> Run packets through the interpreter <count> times\n");
1356 fprintf(output, " -d <confdir> Configuration file directory. (defaults to " CONFDIR ").");
1357 fprintf(output, " -D <dict_dir> Dictionary files are in \"dict_dir/*\".\n");
1358 fprintf(output, " -f <file> Filter reply against attributes in 'file'.\n");
1359 fprintf(output, " -h Print this help message.\n");
1360 fprintf(output, " -i <file> File containing request attributes.\n");
1361 fprintf(output, " -m On SIGINT or SIGQUIT exit cleanly instead of immediately.\n");
1362 fprintf(output, " -n <name> Read ${confdir}/name.conf instead of ${confdir}/radiusd.conf.\n");
1363 fprintf(output, " -o <file> Output file for the reply.\n");
1364 fprintf(output, " -p <radius|...> Define which protocol namespace is used to read the file\n");
1365 fprintf(output, " Use radius, dhcpv4, or dhcpv6\n");
1366 fprintf(output, " -X Turn on full debugging.\n");
1367 fprintf(output, " -x Turn on additional debugging. (-xx gives more debugging).\n");
1368 fprintf(output, " -r <receipt_file> Create the <receipt_file> as a 'success' exit.\n");
1369
1370 fr_exit_now(status);
1371}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
int const char int line
Definition acutest.h:704
int fr_atexit_global_setup(void)
Setup the atexit handler, should be called at the start of a program's execution.
Definition atexit.c:160
int fr_atexit_global_trigger_all(void)
Cause all global free triggers to fire.
Definition atexit.c:286
#define fr_atexit_thread_trigger_all(...)
Definition atexit.h:233
static TALLOC_CTX * autofree
Definition fuzzer.c:46
#define RCSID(id)
Definition build.h:487
#define NEVER_RETURNS
Should be placed before the function return type.
Definition build.h:315
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
unlang_action_t unlang_call_push(unlang_result_t *p_result, request_t *request, CONF_SECTION *server_cs, bool top_frame)
Push a call frame onto the stack.
Definition call.c:147
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_quote, fr_token_t rhs_quote)
Allocate a CONF_PAIR.
Definition cf_util.c:1266
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:288
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
Definition cf_util.h:146
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:408
static char panic_action[512]
The command to execute when panicking.
Definition debug.c:66
void fr_disable_null_tracking_on_free(TALLOC_CTX *ctx)
Disable the null tracking context when a talloc chunk is freed.
Definition debug.c:1021
int fr_log_talloc_report(TALLOC_CTX const *ctx)
Generate a talloc memory report for a context and print to stderr/stdout.
Definition debug.c:962
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
Definition debug.c:1056
void fr_talloc_fault_setup(void)
Register talloc fault handlers.
Definition debug.c:1037
#define MEM(x)
Definition debug.h:36
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:226
void dependency_version_print(void)
Definition dependency.c:365
#define ERROR(fmt,...)
Definition dhcpclient.c:41
static NEVER_RETURNS void usage(void)
Definition dhcpclient.c:114
#define fr_dict_autofree(_to_free)
Definition dict.h:917
static fr_slen_t err
Definition dict.h:884
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char const *dependent))
(Re-)Initialize the special internal dictionary
bool fr_dict_compatible(fr_dict_t const *dict1, fr_dict_t const *dict2)
See if two dictionaries have the same end parent.
Definition dict_util.c:2885
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename))
Read supplementary attribute definitions into an existing dictionary.
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
Definition dict_util.c:4330
fr_dict_enum_value_t const * fr_dict_enum_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the structure representing an enum value in a fr_dict_attr_t.
Definition dict_util.c:3656
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4396
#define fr_dict_autoload(_to_load)
Definition dict.h:914
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
fr_dict_gctx_t * fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir))
Initialise the global protocol hashes.
Definition dict_util.c:4714
char const * name
Enum name.
Definition dict.h:256
static fr_slen_t in
Definition dict.h:884
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
Value of an enumerated attribute.
Definition dict.h:255
talloc_free(hp)
bool fr_hostname_lookups
hostname -> IP lookups?
Definition inet.c:53
bool fr_reverse_lookups
IP -> hostname lookups?
Definition inet.c:52
IPv4/6 prefix.
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
Definition interpret.c:1639
void unlang_interpret_signal(request_t *request, fr_signal_t action)
Send a signal (usually stop) to a request.
Definition interpret.c:1416
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:2052
#define UNLANG_TOP_FRAME
Definition interpret.h:36
rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request)
Execute an unlang section synchronously.
Minimal data structure to use the new code.
Definition listen.h:63
int server_init(CONF_SECTION *cs, char const *conf_dir, fr_dict_t *dict)
Initialize src/lib/server/.
Definition base.c:42
void server_free(void)
Free src/lib/server/.
Definition base.c:137
Describes a host allowed to send packets to the server.
Definition client.h:80
void vlog_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt, va_list ap, void *uctx)
Send a log message to its destination, possibly including fields from the request.
Definition log.c:293
#define PERROR(_fmt,...)
Definition log.h:228
#define RPERROR(fmt,...)
Definition log.h:314
Definition log.h:70
int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet_t const *packet)
Allocate a "Net." struct with src/dst host and port.
Definition packet.c:91
void fr_packet_net_from_pairs(fr_packet_t *packet, fr_pair_list_t const *list)
Convert pairs to information in a packet.
Definition packet.c:154
int unlang_global_init(void)
Definition base.c:158
#define fr_time()
Definition event.c:60
unsigned int fr_event_list_reap_signal(fr_event_list_t *el, fr_time_delta_t timeout, int signal)
Send a signal to all the processes we have in our reap list, and reap them.
Definition event.c:1699
Stores all information relating to an event list.
Definition event.c:377
int fr_unlink(char const *filename)
Remove a regular file from the filesystem.
Definition file.c:367
ssize_t fr_touch(int *fd_out, char const *filename, mode_t mode, bool mkdir, mode_t dir_mode)
Create an empty file.
Definition file.c:323
int fr_debug_lvl
Definition log.c:40
fr_log_t default_log
Definition log.c:288
int fr_log_init_fp(fr_log_t *log, FILE *fp)
Initialise a file logging destination to a FILE*.
Definition log.c:1056
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:577
@ L_DST_STDOUT
Log to stdout.
Definition log.h:78
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:59
fr_packet_t * fr_packet_alloc(TALLOC_CTX *ctx, bool new_vector)
Allocate a new fr_packet_t.
Definition packet.c:38
int main_config_free(main_config_t **config)
main_config_t * main_config_alloc(TALLOC_CTX *ctx)
Allocate a main_config_t struct, setting defaults.
void main_config_name_set_default(main_config_t *config, char const *name, bool overwrite_config)
Set the server name.
int main_config_init(main_config_t *config)
void main_config_confdir_set(main_config_t *config, char const *name)
Set the global radius config directory.
void main_config_dict_dir_set(main_config_t *config, char const *name)
Set the global dictionary directory.
int main_config_parse_option(char const *value)
Main server configuration.
Definition main_config.h:51
fr_event_list_t * main_loop_event_list(void)
Return the main loop event list.
Definition main_loop.c:164
int main_loop_init(void)
Initialise the main event loop, setting up signal handlers.
Definition main_loop.c:253
void main_loop_free(void)
Definition main_loop.c:189
int map_proc_unregister(char const *name)
Unregister a map processor by name.
Definition map_proc.c:177
int map_proc_register(TALLOC_CTX *ctx, void const *mod_inst, char const *name, map_proc_func_t evaluate, map_proc_instantiate_t instantiate, size_t inst_size, fr_value_box_safe_for_t literals_safe_for)
Register a map processor.
Definition map_proc.c:125
Temporary structure to hold arguments for map calls.
Definition map_proc.h:52
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
long int ssize_t
int modules_rlm_free(void)
Cleanup all global structures.
int modules_rlm_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Allocates thread-specific data for all registered backend modules.
Definition module_rlm.c:973
int modules_rlm_init(void)
Initialise the module list structure.
void fr_pair_list_tainted(fr_pair_list_t *list)
Mark up a list of VPs as tainted.
Definition pair.c:3428
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2332
void fr_pair_validate_debug(fr_pair_t const *failed[2])
Write an error to the library errorbuff detailing the mismatch.
Definition pair.c:2102
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:709
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1698
bool fr_pair_validate(fr_pair_t const *failed[2], fr_pair_list_t *filter, fr_pair_list_t *list)
Uses fr_pair_cmp to verify all fr_pair_ts in list match the filter defined by check.
Definition pair.c:2137
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
int fr_pair_list_afrom_file(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *out, FILE *fp, bool *pfiledone, bool allow_exec)
Read valuepairs from the fp up to End-Of-File.
static const conf_parser_t config[]
Definition base.c:169
#define fr_assert(_expr)
Definition rad_assert.h:38
#define RDEBUG(fmt,...)
#define INFO(fmt,...)
Definition radict.c:64
static bool cleanup
Definition radsniff.c:60
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
fr_dict_attr_t const * request_attr_request
Definition request.c:43
int request_global_init(void)
Definition request.c:596
#define request_local_alloc_internal(_ctx, _args)
Allocate a new internal request outside of the request pool.
Definition request.h:343
#define request_local_alloc_external(_ctx, _args)
Allocate a new external request outside of the request pool.
Definition request.h:335
@ REQUEST_ACTIVE
Request is active (running or runnable)
Definition request.h:87
Optional arguments for initialising requests.
Definition request.h:287
static char const * name
ssize_t fr_sbuff_in_escape(fr_sbuff_t *sbuff, char const *in, size_t inlen, fr_sbuff_escape_rules_t const *e_rules)
Print an escaped string to an sbuff.
Definition sbuff.c:1622
char * fr_sbuff_adv_to_chr(fr_sbuff_t *sbuff, size_t len, char c)
Wind position to first instance of specified char.
Definition sbuff.c:1989
ssize_t fr_sbuff_in_sprintf(fr_sbuff_t *sbuff, char const *fmt,...)
Print using a fmt string to an sbuff.
Definition sbuff.c:1597
#define fr_sbuff_adv_past_str_literal(_sbuff, _needle)
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_sbuff_adv_past_whitespace(_sbuff, _len, _tt)
#define fr_sbuff_current(_sbuff_or_marker)
#define fr_sbuff_is_char(_sbuff_or_marker, _c)
#define SBUFF_CHAR_UNPRINTABLES_EXTENDED
#define fr_sbuff_remaining(_sbuff_or_marker)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SBUFF_CHAR_UNPRINTABLES_LOW
#define pair_update_reply(_attr, _da)
Return or allocate a fr_pair_t in the reply list.
Definition pair.h:129
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:339
struct tmpl_rules_s tmpl_rules_t
Definition tmpl.h:233
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
fr_client_t * client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *server_cs, size_t extra)
Allocate a new client from a config section.
Definition client.c:709
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition client.c:373
bool client_add(fr_client_list_t *clients, fr_client_t *client)
Add a client to a fr_client_list_t.
Definition client.c:182
void modules_init(char const *lib_dir)
Perform global initialisation for modules.
Definition module.c:1909
return count
Definition module.c:155
fr_pair_t * vp
Definition log.h:96
fr_log_dst_t dst
Log destination.
Definition log.h:97
int fd
File descriptor to write messages to.
Definition log.h:112
bool print_level
sometimes we don't want log levels printed
Definition log.h:106
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:545
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
Definition talloc.h:123
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:51
int fr_time_start(void)
Initialize the local time.
Definition time.c:150
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
Definition time.h:255
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_wrap(_time)
Definition time.h:152
static fr_time_t fr_time_add_delta_time(fr_time_delta_t a, fr_time_t b)
Definition time.h:180
static fr_unix_time_t fr_time_to_unix_time(fr_time_t when)
Convert an fr_time_t (internal time) to our version of unix time (wallclock time)
Definition time.h:688
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
void fr_timer_list_set_time_func(fr_timer_list_t *tl, fr_event_time_source_t func)
Override event list time source.
Definition timer.c:1200
An event timer list.
Definition timer.c:50
A timer event.
Definition timer.c:84
#define fr_timer_in(...)
Definition timer.h:87
int fr_openssl_version_consistent(void)
Definition version.c:246
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
static char const * receipt_file
static fr_event_list_t * el
static bool filedone
int main(int argc, char *argv[])
static request_t * request_clone(request_t *old, int number, CONF_SECTION *server_cs)
static fr_dict_attr_t const * attr_packet_type
#define PROTOCOL_NAME
static fr_timer_t * time_advance_timer
static fr_client_t * client_alloc(TALLOC_CTX *ctx, char const *ip, char const *name)
static fr_dict_t const * dict_freeradius
static fr_dict_attr_t const * attr_net
static void pair_mutable(fr_pair_t *vp)
static fr_dict_t const * dict_protocol
fr_dict_attr_autoload_t unit_test_module_dict_attr[]
char const * radiusd_version
static xlat_action_t xlat_func_time_advance(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, fr_value_box_list_t *in)
static request_t * request_from_file(TALLOC_CTX *ctx, FILE *fp, fr_client_t *client, CONF_SECTION *server_cs)
static int my_debug_lvl
static xlat_action_t xlat_func_time_advance_resume(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
static fr_time_delta_t time_offset
#define EXIT_WITH_FAILURE
static xlat_arg_parser_t const xlat_func_time_advance_args[]
static unlang_action_t mod_map_proc(unlang_result_t *p_result, UNUSED map_ctx_t const *mpctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *src, UNUSED map_list_t const *maps)
static int map_proc_verify(CONF_SECTION *cs, UNUSED void const *mod_inst, UNUSED void *proc_inst, tmpl_t const *src, UNUSED map_list_t const *maps)
static void too_much_text(fr_sbuff_t *out, ssize_t slen, fr_sbuff_t *line)
static void print_packet(FILE *fp, fr_packet_t *packet, fr_pair_list_t *list)
fr_dict_autoload_t unit_test_module_dict[]
static fr_time_t _synthetic_time_source(void)
Sythentic time source for tests.
static void time_advance_resume(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
static void cancel_request(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t when, void *uctx)
static bool do_xlats(fr_event_list_t *el, request_t *request, char const *filename, FILE *fp)
static request_t * request_from_internal(TALLOC_CTX *ctx)
int unlang_thread_instantiate(TALLOC_CTX *ctx)
Create thread-specific data structures for unlang.
Definition compile.c:2293
xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t resume, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition xlat.c:544
fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
Tokenize an xlat expansion.
ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1873
static fr_slen_t head
Definition xlat.h:420
int xlat_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Create thread specific instance tree and create thread instances.
Definition xlat_inst.c:442
#define XLAT_ARGS(_list,...)
Populate local variables with value boxes from the input list.
Definition xlat.h:383
unsigned int required
Argument must be present, and non-empty.
Definition xlat.h:146
int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
Walk over an xlat tree recursively, resolving any unresolved functions or references.
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:170
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_YIELD
An xlat function pushed a resume frame onto the stack.
Definition xlat.h:42
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
fr_slen_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Definition xlat_expr.c:3165
Definition for a single argument consumend by an xlat function.
Definition xlat.h:145
#define FR_DICTIONARY_FILE
Definition conf.h:7
#define FR_DICTIONARY_INTERNAL_DIR
Definition conf.h:8
unsigned int code
Packet code (type).
Definition packet.h:61
void fr_fprintf_pair_list(FILE *fp, fr_pair_list_t const *list)
Definition pair_print.c:491
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:279
#define fr_pair_list_log(_log, _lvl, _list)
Definition pair.h:864
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:604
#define fr_pair_dcursor_by_ancestor_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes descended from the specified fr_dict_attr_t.
Definition pair.h:657
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Definition socket.h:121
Holds information necessary for binding or connecting to a socket.
Definition socket.h:63
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:732
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_printf_push(_fmt,...)
Add a message to an existing stack of messages at the tail.
Definition strerror.h:84
#define fr_strerror_const(_msg)
Definition strerror.h:223
#define fr_type_is_structural(_x)
Definition types.h:393
#define fr_type_is_leaf(_x)
Definition types.h:394
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
Definition version.c:40
#define RADIUSD_VERSION_BUILD(_x)
Create a version string for a utility in the suite of FreeRADIUS utilities.
Definition version.h:58
#define RADIUSD_MAGIC_NUMBER
Definition version.h:81
fr_sbuff_unescape_rules_t const fr_value_unescape_double
Definition value.c:272
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:644
#define fr_box_time_delta(_val)
Definition value.h:366
#define fr_box_uint32(_val)
Definition value.h:335
int format(printf, 5, 0))
static size_t char ** out
Definition value.h:1030
#define fr_box_date(_val)
Definition value.h:347
fr_dict_t const * virtual_server_dict_by_name(char const *virtual_server)
Return the namespace for the named virtual server.
virtual_server_t const * virtual_server_find(char const *name)
Return virtual server matching the specified name.
CONF_SECTION * virtual_server_cs(virtual_server_t const *vs)
Return the configuration section for a virtual server.
int virtual_servers_init(void)
Performs global initialisation for the virtual server code.
int virtual_servers_free(void)
int virtual_servers_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Perform thread instantiation for all process modules and listeners.
static TALLOC_CTX * xlat_ctx
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:363
xlat_t * xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type)
Register an xlat function.
Definition xlat_func.c:216