The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
log.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/**
18 * $Id: 520be9d127d0ef2f097b486752105788dd41418c $
19 *
20 * @brief Logging functions used by the server core.
21 * @file src/lib/server/log.c
22 *
23 * @copyright 2000,2006 The FreeRADIUS server project
24 * @copyright 2000 Miquel van Smoorenburg (miquels@cistron.nl)
25 * @copyright 2000 Alan DeKok (aland@freeradius.org)
26 * @copyright 2001 Chad Miller (cmiller@surfsouth.com)
27 */
28RCSID("$Id: 520be9d127d0ef2f097b486752105788dd41418c $")
29
30#include <freeradius-devel/util/debug.h>
31#include <freeradius-devel/util/dict.h>
32#include <freeradius-devel/util/log.h>
33#include <freeradius-devel/util/syserror.h>
34#include <freeradius-devel/util/file.h>
35
36#include <freeradius-devel/server/log.h>
37#include <freeradius-devel/server/pair.h>
38#include <freeradius-devel/server/util.h>
39
40#include <freeradius-devel/unlang/xlat.h>
41
42#ifdef HAVE_SYS_STAT_H
43# include <sys/stat.h>
44#endif
45
46#include <fcntl.h>
47
48#ifdef HAVE_SYSLOG_H
49# include <syslog.h>
50#endif
51
52#include <sys/file.h>
53#include <pthread.h>
54
55static _Thread_local TALLOC_CTX *fr_vlog_request_pool;
56static _Thread_local fr_sbuff_t *fr_log_request_oid_buff;
57
58/** Syslog facility table
59 *
60 * Maps syslog facility keywords, to the syslog facility macros defined
61 * in the system's syslog.h.
62 *
63 * @note Not all facilities are supported by every operating system.
64 * If a facility is unavailable it will not appear in the table.
65 */
67#ifdef LOG_AUTH
68 { L("auth"), LOG_AUTH },
69#endif
70
71#ifdef LOG_AUTHPRIV
72 { L("authpriv"), LOG_AUTHPRIV },
73#endif
74
75#ifdef LOG_CRON
76 { L("cron"), LOG_CRON },
77#endif
78
79#ifdef LOG_DAEMON
80 { L("daemon"), LOG_DAEMON },
81#endif
82
83#ifdef LOG_FTP
84 { L("ftp"), LOG_FTP },
85#endif
86
87#ifdef LOG_KERN
88 { L("kern"), LOG_KERN },
89#endif
90
91#ifdef LOG_LOCAL0
92 { L("local0"), LOG_LOCAL0 },
93#endif
94
95#ifdef LOG_LOCAL1
96 { L("local1"), LOG_LOCAL1 },
97#endif
98
99#ifdef LOG_LOCAL2
100 { L("local2"), LOG_LOCAL2 },
101#endif
102
103#ifdef LOG_LOCAL3
104 { L("local3"), LOG_LOCAL3 },
105#endif
106
107#ifdef LOG_LOCAL4
108 { L("local4"), LOG_LOCAL4 },
109#endif
110
111#ifdef LOG_LOCAL5
112 { L("local5"), LOG_LOCAL5 },
113#endif
114
115#ifdef LOG_LOCAL6
116 { L("local6"), LOG_LOCAL6 },
117#endif
118
119#ifdef LOG_LOCAL7
120 { L("local7"), LOG_LOCAL7 },
121#endif
122
123#ifdef LOG_LPR
124 { L("lpr"), LOG_LPR },
125#endif
126
127#ifdef LOG_MAIL
128 { L("mail"), LOG_MAIL },
129#endif
130
131#ifdef LOG_NEWS
132 { L("news"), LOG_NEWS },
133#endif
134
135#ifdef LOG_USER
136 { L("user"), LOG_USER },
137#endif
138
139#ifdef LOG_UUCP
140 { L("uucp"), LOG_UUCP }
141#endif
142};
144
145/** Syslog severity table
146 *
147 * Maps syslog severity keywords, to the syslog severity macros defined
148 * in the system's syslog.h file.
149 *
150 */
152#ifdef LOG_ALERT
153 { L("alert"), LOG_ALERT },
154#endif
155
156#ifdef LOG_CRIT
157 { L("critical"), LOG_CRIT },
158#endif
159
160#ifdef LOG_DEBUG
161 { L("debug"), LOG_DEBUG },
162#endif
163
164#ifdef LOG_EMERG
165 { L("emergency"), LOG_EMERG },
166#endif
167
168#ifdef LOG_ERR
169 { L("error"), LOG_ERR },
170#endif
171
172#ifdef LOG_INFO
173 { L("info"), LOG_INFO },
174#endif
175
176#ifdef LOG_NOTICE
177 { L("notice"), LOG_NOTICE },
178#endif
179
180#ifdef LOG_WARNING
181 { L("warning"), LOG_WARNING },
182#endif
183};
185
187 { L("file"), L_DST_FILES },
188 { L("files"), L_DST_FILES },
189 { L("null"), L_DST_NULL },
190 { L("stderr"), L_DST_STDERR },
191 { L("stdout"), L_DST_STDOUT },
192 { L("syslog"), L_DST_SYSLOG },
193};
195
196static char const spaces[] = " ";
197
199
202 { .out = &dict_freeradius, .proto = "freeradius" },
203 { NULL }
204};
205
207
210 { .out = &attr_module_failure_message, .name = "Module-Failure-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
211 { NULL }
212};
213
214typedef struct {
215 char const *name; //!< name of this logging destination
216 fr_log_t *log; //!< pointer to the log structure
217 CONF_SECTION *cs; //!< where this log configuration came from
218
219 fr_rb_node_t name_node; //!< tree by name
220 fr_rb_node_t filename_node; //!< tree by name
222
223typedef struct {
224 char const *name; //!< name of this logging source
225 uint32_t id; //!< LOG_ID of this source
226 fr_log_t *original; //!< the original fr_log_t
227 fr_log_t **log; //!< where the logs should go
228
229 fr_rb_node_t name_node; //!< tree by name only
230 fr_rb_node_t id_node; //!< tree by ID
232
233static fr_rb_tree_t *dst_tree = NULL;
235static fr_rb_tree_t *src_tree = NULL;
236
237/** Send a server log message to its destination without evaluating its debug level
238 *
239 * @param[in] log destination.
240 * @param[in] type of log message.
241 * @param[in] file src file the log message was generated in.
242 * @param[in] line number the log message was generated on.
243 * @param[in] fmt with printf style substitution tokens.
244 * @param[in] ... Substitution arguments.
245 */
246
247static CC_HINT(format (printf, 5, 6))
249 char const *file, int line,
250 char const *fmt, ...)
251{
252 va_list ap;
253
254 va_start(ap, fmt);
255 fr_vlog(log, type, file, line, fmt, ap);
256 va_end(ap);
257}
258
259/** Whether a request specific debug message should be logged
260 *
261 * @param lvl of debugging this message should be logged at.
262 * @param request The current request.
263 * @return
264 * - true if message should be logged.
265 * - false if message shouldn't be logged.
266 */
267inline bool log_rdebug_enabled(fr_log_lvl_t lvl, request_t const *request)
268{
269 if (!request->log.dst) return false;
270
271 if (lvl <= request->log.lvl) return true;
272
273 return false;
274}
275
276/** Cleanup the memory pool used by vlog_request
277 *
278 */
279static int _fr_vlog_request_pool_free(void *arg)
280{
281 return talloc_free(arg);
282}
283
284/** Send a log message to its destination, possibly including fields from the request
285 *
286 * @param[in] type of log message, #L_ERR, #L_WARN, #L_INFO, #L_DBG.
287 * @param[in] lvl Minimum required server or request level to output this message.
288 * @param[in] request The current request.
289 * @param[in] file src file the log message was generated in.
290 * @param[in] line number the log message was generated on.
291 * @param[in] fmt with printf style substitution tokens.
292 * @param[in] ap Substitution arguments.
293 * @param[in] uctx The #fr_log_t specifying the destination for log messages.
294 */
296 char const *file, int line,
297 char const *fmt, va_list ap, void *uctx)
298{
299 char const *filename;
300 FILE *fp = NULL;
301
302 char *p;
303 char const *extra = "";
304 uint8_t unlang_indent, module_indent;
305 va_list aq;
306
307 char const *fmt_location = "";
308 char const *fmt_prefix = "";
309 char const *fmt_module = "";
310 char const *fmt_exp;
311
312 fr_log_t *log_dst = uctx;
313 TALLOC_CTX *pool;
314
315 /*
316 * No output means no output.
317 */
318 if (!log_dst) return;
319 if (!log_rdebug_enabled(lvl, request)) return;
320
321 /*
322 * Allocate a thread local, 4k pool so we don't
323 * need to keep allocating memory on the heap.
324 */
326 if (!pool) {
327 pool = talloc_pool(NULL, 4096);
328 if (!pool) {
329 fr_perror("Failed allocating memory for vlog_request_pool");
330 return;
331 }
333 }
334
335 filename = log_dst->file;
336
337 /*
338 * Debug messages get treated specially.
339 */
340 if ((type & L_DBG) != 0) {
341 /*
342 * If we're debugging to a file, then use that.
343 *
344 * @todo: have fr_vlog() take a fr_log_t*, so
345 * that we can cache the opened descriptor, and
346 * we don't need to re-open it on every log
347 * message.
348 */
349 switch (log_dst->dst) {
350 case L_DST_FILES:
351 fp = fopen(log_dst->file, "a");
352 if (!fp) goto finish;
353 break;
354
355#if defined(HAVE_FOPENCOOKIE) || defined (HAVE_FUNOPEN)
356 case L_DST_FUNC:
357 {
358# ifdef HAVE_FOPENCOOKIE
360
361 /*
362 * These must be set separately as they have different prototypes.
363 */
364 io.read = NULL;
365 io.seek = NULL;
366 io.close = NULL;
367 io.write = log_dst->cookie_write;
368
369 fp = fopencookie(log_dst->cookie, "w", io);
370# else
371 fp = funopen(log_dst->cookie, NULL, log_dst->cookie_write, NULL, NULL);
372
373# endif
374 if (!fp) goto finish;
375 }
376 break;
377#endif
378 default:
379 break;
380 }
381 goto print_fmt;
382 }
383
384 if (filename) {
385 char *exp;
386 log_dst_t *dst;
387
388 dst = request->log.dst;
389
390 /*
391 * Prevent infinitely recursive calls if
392 * xlat_aeval attempts to write to the request log.
393 */
394 request->log.dst = NULL;
395
396 /*
397 * This is SLOW! Doing it for every log message
398 * in every request is NOT recommended!
399 */
400 if (xlat_aeval(request, &exp, request, filename, rad_filename_escape, NULL) < 0) return;
401
402 /*
403 * Restore the original logging function
404 */
405 request->log.dst = dst;
406
407 /*
408 * Ensure the directory structure exists, for
409 * where we're going to write the log file.
410 */
411 p = strrchr(exp, FR_DIR_SEP);
412 if (p) {
413 *p = '\0';
414 if (fr_mkdir(NULL, exp, -1, S_IRWXU, NULL, NULL) < 0) {
415 ERROR("Failed creating %s: %s", exp, fr_syserror(errno));
416 talloc_free(exp);
417 return;
418 }
419 *p = FR_DIR_SEP;
420 }
421
422 fp = fopen(exp, "a");
423 talloc_free(exp);
424 }
425
426print_fmt:
427 /*
428 * Request prefix i.e.
429 *
430 * (0) <fmt>
431 */
432 if (request->name) {
433 if ((request->seq_start == 0) || (request->number == request->seq_start)) {
434 fmt_prefix = talloc_typed_asprintf(pool, "(%s) ", request->name);
435 } else {
436 fmt_prefix = talloc_typed_asprintf(pool, "(%s,%" PRIu64 ") ",
437 request->name, request->seq_start);
438 }
439 }
440
441 /*
442 * Make sure the indent isn't set to something crazy
443 */
444 unlang_indent = request->log.indent.unlang > sizeof(spaces) - 1 ?
445 sizeof(spaces) - 1 :
446 request->log.indent.unlang;
447
448 module_indent = request->log.indent.module > sizeof(spaces) - 1 ?
449 sizeof(spaces) - 1 :
450 request->log.indent.module;
451
452 /*
453 * Module name and indentation i.e.
454 *
455 * test - <fmt>
456 */
457 if (request->module) {
458 fmt_module = talloc_typed_asprintf(pool, "%s - %.*s", request->module, module_indent, spaces);
459 }
460
461 /*
462 * If we don't copy the original ap we get a segfault from vasprintf. This is apparently
463 * due to ap sometimes being implemented with a stack offset which is invalidated if
464 * ap is passed into another function. See here:
465 * http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html
466 *
467 * I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when
468 * running unit tests which generate errors under CI.
469 */
470 va_copy(aq, ap);
471 if (!log_dst->suppress_secrets) {
472 fmt_exp = fr_vasprintf(pool, fmt, aq);
473 } else {
474 fmt_exp = fr_vasprintf_secure(pool, fmt, aq);
475 }
476 va_end(aq);
477
478 /*
479 * Logging to a file descriptor
480 */
481 if (fp) {
482 char time_buff[64]; /* The current timestamp */
483
484 time_t timeval;
485 timeval = time(NULL);
486
487#if 0
488 fmt_location = talloc_typed_asprintf(pool, "%s[%i]: ", file, line);
489#endif
490
491#ifdef HAVE_GMTIME_R
492 if (log_dates_utc) {
493 struct tm utc;
494 gmtime_r(&timeval, &utc);
495 ASCTIME_R(&utc, time_buff, sizeof(time_buff));
496 } else
497#endif
498 {
499 CTIME_R(&timeval, time_buff, sizeof(time_buff));
500 }
501
502 /*
503 * Strip trailing new lines
504 */
505 p = strrchr(time_buff, '\n');
506 if (p) p[0] = '\0';
507
508 fprintf(fp,
509 "%s" /* location */
510 "%s" /* prefix */
511 "%s : " /* time */
512 "%s" /* facility */
513 "%.*s" /* indent */
514 "%s" /* module */
515 "%s" /* message */
516 "\n",
517 fmt_location,
518 fmt_prefix,
519 time_buff,
521 unlang_indent, spaces,
522 fmt_module,
523 fmt_exp);
524 fclose(fp);
525 goto finish;
526 }
527
528 /*
529 * Logging everywhere else
530 */
531 if (!DEBUG_ENABLED3) switch (type) {
532 case L_DBG_WARN:
533 extra = "WARNING: ";
535 break;
536
537 case L_DBG_ERR:
538 extra = "ERROR: ";
540 break;
541 default:
542 break;
543 }
544
546 "%s" /* prefix */
547 "%.*s" /* indent */
548 "%s" /* module */
549 "%s" /* extra */
550 "%s", /* message */
551 fmt_prefix,
552 unlang_indent, spaces,
553 fmt_module,
554 extra,
555 fmt_exp);
556
557finish:
558 talloc_free_children(pool);
559}
560
561/** Add a module failure message fr_pair_t to the request
562 *
563 * @param[in] request The current request.
564 * @param[in] fmt with printf style substitution tokens.
565 * @param[in] ap Substitution arguments.
566 */
567static void vlog_module_failure_msg(request_t *request, char const *fmt, va_list ap)
568{
569 char *p;
570 fr_pair_t *vp;
571 va_list aq;
572
573 if (!fmt || !request || !request->packet) return;
574
576
578
579 /*
580 * If we don't copy the original ap we get a segfault from vasprintf. This is apparently
581 * due to ap sometimes being implemented with a stack offset which is invalidated if
582 * ap is passed into another function. See here:
583 * http://julipedia.meroh.net/2011/09/using-vacopy-to-safely-pass-ap.html
584 *
585 * I don't buy that explanation, but doing a va_copy here does prevent SEGVs seen when
586 * running unit tests which generate errors under CI.
587 */
588 va_copy(aq, ap);
589 p = fr_vasprintf(vp, fmt, aq);
590 va_end(aq);
591
592 if (request->module && (request->module[0] != '\0')) {
593 fr_pair_value_aprintf(vp, "%s: %s", request->module, p);
594 talloc_free(p);
595 } else {
597 }
598}
599
600/** Marshal variadic log arguments into a va_list and pass to normal logging functions
601 *
602 * @see log_request_error for more details.
603 *
604 * @param[in] type the log category.
605 * @param[in] lvl of debugging this message should be logged at.
606 * @param[in] request The current request.
607 * @param[in] file src file the log message was generated in.
608 * @param[in] line number the log message was generated on.
609 * @param[in] fmt with printf style substitution tokens.
610 * @param[in] ... Substitution arguments.
611 */
613 char const *file, int line, char const *fmt, ...)
614{
615 va_list ap;
616 log_dst_t *dst;
617
618 if (!request->log.dst) return;
619
620 va_start(ap, fmt);
621 for (dst = request->log.dst; dst; dst = dst->next) {
622 if (lvl > dst->lvl) continue;
623
624 dst->func(type, lvl, request, file, line, fmt, ap, dst->uctx);
625 }
626 va_end(ap);
627}
628
629/** Marshal variadic log arguments into a va_list and pass to error logging functions
630 *
631 * This could all be done in a macro, but it turns out some implementations of the
632 * variadic macros do not work at all well if the va_list being written to is further
633 * up the stack (which is required as you still need a function to convert the ellipsis
634 * into a va_list).
635 *
636 * So, we use this small wrapper function instead, which will hopefully guarantee
637 * consistent behaviour.
638 *
639 * @param[in] type the log category.
640 * @param[in] lvl of debugging this message should be logged at.
641 * @param[in] request The current request.
642 * @param[in] file src file the log message was generated in.
643 * @param[in] line number the log message was generated on.
644 * @param[in] fmt with printf style substitution tokens.
645 * @param[in] ... Substitution arguments.
646 */
648 char const *file, int line, char const *fmt, ...)
649{
650 va_list ap;
651 log_dst_t *dst_p;
652
653 if (!request->log.dst) return;
654
655 va_start(ap, fmt);
656 for (dst_p = request->log.dst; dst_p; dst_p = dst_p->next) {
657 dst_p->func(type, lvl, request, file, line, fmt, ap, dst_p->uctx);
658 }
659 if ((type == L_ERR) || (type == L_DBG_ERR) || (type == L_DBG_ERR_REQ)) {
660 vlog_module_failure_msg(request, fmt, ap);
661 }
662
663 va_end(ap);
664}
665
666/** Drain any outstanding messages from the fr_strerror buffers
667 *
668 * This function drains any messages from fr_strerror buffer adding a prefix (fmt)
669 * to the first message.
670 *
671 * @param[in] type the log category.
672 * @param[in] lvl of debugging this message should be logged at.
673 * @param[in] request The current request.
674 * @param[in] file src file the log message was generated in.
675 * @param[in] line number the log message was generated on.
676 * @param[in] fmt with printf style substitution tokens.
677 * @param[in] ... Substitution arguments.
678 */
680 char const *file, int line, char const *fmt, ...)
681{
682 char const *error;
683
684 if (!request->log.dst) return;
685
686 /*
687 * No strerror gets us identical behaviour to log_request_error
688 */
689 error = fr_strerror_pop();
690 if (!error) {
691 va_list ap;
692 log_dst_t *dst_p;
693
694 if (!fmt) return; /* NOOP */
695
696 va_start(ap, fmt);
697 for (dst_p = request->log.dst; dst_p; dst_p = dst_p->next) {
698 dst_p->func(type, lvl, request, file, line, fmt, ap, dst_p->uctx);
699 }
700 if ((type == L_ERR) || (type == L_DBG_ERR) || (type == L_DBG_ERR_REQ)) {
701 vlog_module_failure_msg(request, fmt, ap);
702 }
703 va_end(ap);
704
705 return; /* DONE */
706 }
707
708 /*
709 * Concatenate fmt with fr_strerror()
710 */
711 if (fmt) {
712 va_list ap;
713 char *tmp;
714
715 va_start(ap, fmt);
716 tmp = fr_vasprintf(request, fmt, ap);
717 va_end(ap);
718
719 if (!tmp) return;
720
721 log_request_error(type, lvl, request, file, line, "%s: %s", tmp, error);
722 talloc_free(tmp);
723 } else {
724 log_request_error(type, lvl, request, file, line, "%s", error);
725 }
726
727 /*
728 * Only the first message gets the prefix
729 */
730 while ((error = fr_strerror_pop())) log_request_error(type, lvl, request, file, line, "%s", error);
731}
732
733/** Cleanup the memory pool used by the OID sbuff
734 *
735 */
736static int _fr_log_request_oid_buff_free(void *arg)
737{
738 return talloc_free(arg);
739}
740
741/** Allocate an extensible sbuff for printing OID strings
742 *
743 */
744static inline CC_HINT(always_inline) fr_sbuff_t *log_request_oid_buff(void)
745{
746 fr_sbuff_t *sbuff;
748
750 if (unlikely(!sbuff)) {
751 sbuff = talloc(NULL, fr_sbuff_t);
752 if (!sbuff) {
753 fr_perror("Failed allocating memory for fr_log_request_oid_buff");
754 return NULL;
755 }
756 tctx = talloc(sbuff, fr_sbuff_uctx_talloc_t);
757 if (!tctx) {
758 fr_perror("Failed allocating memory for fr_sbuff_uctx_talloc_t");
759 talloc_free(sbuff);
760 return NULL;
761 }
762
763 fr_sbuff_init_talloc(sbuff, sbuff, tctx, 1024, (FR_DICT_ATTR_MAX_NAME_LEN + 1) * FR_DICT_MAX_TLV_STACK);
764
766 } else {
767 fr_sbuff_set(sbuff, fr_sbuff_start(sbuff)); /* Reset position */
768 }
769
770 return sbuff;
771}
772
773/** Print a #fr_pair_t.
774 *
775 * @param[in] lvl Debug lvl (1-4).
776 * @param[in] request to read logging params from.
777 * @param[in] parent of pair to print, may be NULL.
778 * @param[in] vp to print.
779 * @param[in] prefix (optional).
780 */
782 fr_pair_t const *parent, fr_pair_t const *vp, char const *prefix)
783{
784 fr_dict_attr_t const *parent_da = NULL;
785 fr_sbuff_t *oid_buff;
786
787 if (!request->log.dst) return;
788
789 if (!log_rdebug_enabled(lvl, request)) return;
790
792
793 oid_buff = log_request_oid_buff();
794
795 if (parent && (parent->vp_type != FR_TYPE_GROUP)) parent_da = parent->da;
796 if (fr_dict_attr_oid_print(oid_buff, parent_da, vp->da, false) <= 0) return;
797
798 /*
799 * Recursively print grouped attributes.
800 */
801 switch (vp->vp_type) {
803 RDEBUGX(lvl, "%s%pV {", prefix ? prefix : "",
804 fr_box_strvalue_len(fr_sbuff_start(oid_buff), fr_sbuff_used(oid_buff)));
805 log_request_pair_list(lvl, request, vp, &vp->vp_group, NULL);
806 RDEBUGX(lvl, "}");
807 break;
808
809 case FR_TYPE_QUOTED:
810 RDEBUGX(lvl, "%s%pV = \"%pV\"", prefix ? prefix : "",
812 &vp->data);
813 break;
814 default:
815 RDEBUGX(lvl, "%s%pV = %pV", prefix ? prefix : "",
817 &vp->data);
818 break;
819 }
820}
821
822/** Print a #fr_pair_list_t
823 *
824 * @param[in] lvl Debug lvl (1-4).
825 * @param[in] request to read logging params from.
826 * @param[in] parent of vps to print, may be NULL.
827 * @param[in] vps to print.
828 * @param[in] prefix (optional).
829 */
831 fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
832{
833 if (fr_pair_list_empty(vps) || !request->log.dst) return;
834
835 if (!log_rdebug_enabled(lvl, request)) return;
836
837 RINDENT();
840
841 log_request_pair(lvl, request, parent, vp, prefix);
842 }
843 REXDENT();
844}
845
846/** Print a list of protocol fr_pair_ts.
847 *
848 * @param[in] lvl Debug lvl (1-4).
849 * @param[in] request to read logging params from.
850 * @param[in] parent of vps to print, may be NULL.
851 * @param[in] vps to print.
852 * @param[in] prefix (optional).
853 */
855 fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
856{
857 if (fr_pair_list_empty(vps) || !request->log.dst) return;
858
859 if (!log_rdebug_enabled(lvl, request)) return;
860
861 RINDENT();
864
865 if (!fr_dict_attr_common_parent(fr_dict_root(request->dict), vp->da, true)) continue;
866
867 log_request_pair(lvl, request, parent, vp, prefix);
868 }
869 REXDENT();
870}
871
872/** Write the string being parsed, and a marker showing where the parse error occurred
873 *
874 * @param[in] type the log category.
875 * @param[in] lvl of debugging this message should be logged at.
876 * @param[in] request The current request.
877 * @param[in] file src file the log message was generated in.
878 * @param[in] line number the log message was generated on.
879 * @param[in] str Subject string we're printing a marker for.
880 * @param[in] str_len Subject string length. Use SIZE_MAX for the
881 * length of the string.
882 * @param[in] marker_idx The position of the marker relative to the string.
883 * @param[in] marker_fmt What the parse error was.
884 * @param[in] ... Arguments for fmt string.
885 */
887 char const *file, int line,
888 char const *str, size_t str_len,
889 ssize_t marker_idx, char const *marker_fmt, ...)
890{
891 char const *ellipses = "";
892 rindent_t indent;
893 va_list ap;
894 char *error;
895 static char const marker_spaces[] = " "; /* 60 */
896
897 if (str_len == SIZE_MAX) str_len = strlen(str);
898
899 if (marker_idx < 0) marker_idx = marker_idx * -1;
900
901 if ((size_t)marker_idx >= sizeof(marker_spaces)) {
902 size_t offset = (marker_idx - (sizeof(marker_spaces) - 1)) + (sizeof(marker_spaces) * 0.75);
903 marker_idx -= offset;
904 str += offset;
905 str_len -= offset;
906
907 ellipses = "... ";
908 }
909
910 /*
911 * Don't want format markers being indented
912 */
913 indent = request->log.indent;
914 request->log.indent.module = 0;
915 request->log.indent.unlang = 0;
916
917 va_start(ap, marker_fmt);
918 error = fr_vasprintf(request, marker_fmt, ap);
919 va_end(ap);
920
921 log_request(type, lvl, request, file, line, "%s%.*s", ellipses, (int)str_len, str);
922 log_request(type, lvl, request, file, line, "%s%.*s^ %s", ellipses, (int) marker_idx, marker_spaces, error);
923 talloc_free(error);
924
925 request->log.indent = indent;
926}
927
929 char const *file, int line,
930 uint8_t const *data, size_t data_len)
931{
932 size_t i, j, len;
933 char buffer[(0x10 * 3) + 1];
934 char *p, *end = buffer + sizeof(buffer);
935
936 for (i = 0; i < data_len; i += 0x10) {
937 len = 0x10;
938 if ((i + len) > data_len) len = data_len - i;
939
940 for (p = buffer, j = 0; j < len; j++, p += 3) snprintf(p, end - p, "%02x ", data[i + j]);
941 log_request(type, lvl, request, file, line, "%04x: %s", (int)i, buffer);
942 }
943}
944
945/** Function to provide as the readable callback to the event loop
946 *
947 * Writes any data read from a file descriptor to the request log,
948 * tries very hard not to chop lines in the middle, but will split
949 * at 1024 byte boundaries if forced to.
950 *
951 * @param[in] el UNUSED
952 * @param[in] fd UNUSED
953 * @param[in] flags UNUSED
954 * @param[in] uctx Pointer to a log_fd_event_ctx_t
955 */
956void log_request_fd_event(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
957{
958 char buffer[1024];
959 log_fd_event_ctx_t *log_info = uctx;
960 request_t *request = log_info->request;
961 fr_sbuff_t sbuff;
962 fr_sbuff_marker_t m_start, m_end;
963
964 fr_sbuff_term_t const line_endings = FR_SBUFF_TERMS(L("\n"), L("\r"));
965
966 if (!RDEBUG_ENABLEDX(log_info->lvl)) {
967 while (read(fd, buffer, sizeof(buffer) > 0));
968 return;
969 }
970
971 fr_sbuff_init_out(&sbuff, buffer, sizeof(buffer));
972 fr_sbuff_marker(&m_start, &sbuff);
973 fr_sbuff_marker(&m_end, &sbuff);
974
975#ifndef NDEBUG
976 memset(buffer, 0x42, sizeof(buffer));
977#endif
978
979 for (;;) {
980 ssize_t slen;
981
982 slen = read(fd, fr_sbuff_current(&m_end), fr_sbuff_remaining(&m_end));
983 if (slen < 0) {
984 if (errno == EINTR) continue;
985
986 /*
987 * This can happen if the I/O handler is
988 * manually called to clear out any pending
989 * data, and we're using a nonblocking FD.
990 *
991 * This can happen with the exec code if
992 * the EVFILT_PROC event gets passed before
993 * the EVFILT_READ event.
994 */
995 if (errno == EWOULDBLOCK) slen = 0;
996 }
997 if ((slen < 0) && (errno == EINTR)) continue;
998
999 if (slen > 0) fr_sbuff_advance(&m_end, slen);
1000
1001 while (fr_sbuff_ahead(&m_end) > 0) {
1002 fr_sbuff_adv_until(&sbuff, fr_sbuff_ahead(&m_end), &line_endings, '\0');
1003
1004 /*
1005 * Incomplete line, try and read the rest.
1006 */
1007 if ((slen > 0) && (fr_sbuff_used(&m_start) > 0) &&
1008 !fr_sbuff_is_terminal(&sbuff, &line_endings)) {
1009 break;
1010 }
1011
1012 log_request(log_info->type, log_info->lvl, log_info->request,
1013 __FILE__, __LINE__,
1014 "%s%s%pV",
1015 log_info->prefix ? log_info->prefix : "",
1016 log_info->prefix ? " - " : "",
1018 fr_sbuff_behind(&m_start)));
1019
1020 fr_sbuff_advance(&sbuff, 1); /* Skip the whitespace */
1021 fr_sbuff_set(&m_start, &sbuff);
1022 }
1023
1024 /*
1025 * Error or done
1026 */
1027 if (slen <= 0) break;
1028
1029 /*
1030 * Clear out the existing data
1031 */
1032 fr_sbuff_shift(&sbuff, fr_sbuff_used(&m_start));
1033 }
1034}
1035
1036/** Log a fatal error, then exit
1037 *
1038 */
1039void log_fatal(fr_log_t const *log, char const *file, int line, char const *fmt, ...)
1040{
1041 va_list ap;
1042
1043 va_start(ap, fmt);
1044 fr_vlog(log, L_ERR, file, line, fmt, ap);
1045 va_end(ap);
1046
1047 fr_exit_now(EXIT_FAILURE);
1048}
1049
1050/** Register a logging destination.
1051 *
1052 */
1053static void log_register_dst(char const *name, fr_log_t *log, CONF_SECTION *cs)
1054{
1055 fr_log_track_t *dst;
1056
1057 MEM(dst = talloc_zero(dst_tree, fr_log_track_t));
1058 dst->name = name;
1059 dst->log = log;
1060 dst->cs = cs;
1061
1062 fr_rb_insert(dst_tree, dst);
1063
1064 if (log->dst != L_DST_FILES) return;
1065
1066 fr_assert(log->file != NULL);
1067
1069}
1070
1071/** Get a logging destination by name.
1072 *
1073 */
1075{
1076 fr_log_track_t find, *found;
1077
1078 memset(&find, 0, sizeof(find));
1079 find.name = name;
1080
1081 found = fr_rb_find(dst_tree, &find);
1082 return (found) ? found->log : NULL;
1083}
1084
1085static int _log_free(fr_log_t *log)
1086{
1087 fr_assert(log->dst == L_DST_FILES);
1088
1089 fclose(log->handle);
1090 return 0;
1091}
1092
1093static char const *log_destination = NULL;
1094static bool log_timestamp;
1096
1097/*
1098 * Parse an fr_log_t configuration.
1099 */
1100static const conf_parser_t log_config[] = {
1101 { FR_CONF_POINTER("destination", FR_TYPE_STRING, 0, &log_destination), .dflt = "file" },
1102#if 0
1103 /*
1104 * @todo - once we allow this, also check that there's only _one_ destination
1105 * which uses syslog_facility.
1106 */
1107 { FR_CONF_OFFSET("syslog_facility", main_config_t, syslog_facility), .dflt = "daemon",
1109 .uctx = &(cf_table_parse_ctx_t){
1110 .table = syslog_facility_table,
1112 }
1113 },
1114#endif
1115 { FR_CONF_POINTER_IS_SET("timestamp", FR_TYPE_BOOL, 0, &log_timestamp) },
1116 { FR_CONF_OFFSET("file", fr_log_t, file), },
1117 { FR_CONF_OFFSET("colourise", fr_log_t, colourise) },
1118 { FR_CONF_OFFSET("line_number", fr_log_t, line_number) },
1119 { FR_CONF_OFFSET("use_utc", fr_log_t, dates_utc) },
1120 { FR_CONF_OFFSET("print_level", fr_log_t, print_level) },
1122};
1123
1124/** Parse a named logging section.
1125 *
1126 * @todo - we should probably allow for TCP sockets, too. But then
1127 * those can block. So we then also need a way to buffer outbound
1128 * log messages, and discard log messages if the buffer is full.
1129 *
1130 * This should probably be done with a FILE*, and L_DST_FUNC.
1131 */
1133{
1134 fr_log_track_t *dst;
1135 fr_log_t *log;
1136 char const *name;
1137
1138 name = cf_section_name2(cs);
1139 if (!name) name = "DEFAULT";
1140
1142 .name = name,
1143 });
1144 if (dst) {
1145 fr_strerror_printf("Cannot add duplicate log destination '%s'", name);
1146 return -1;
1147 }
1148
1149 MEM(log = talloc_zero(dst_tree, fr_log_t));
1150
1151 if (cf_section_rules_push(cs, log_config) < 0) {
1152 error:
1153 talloc_free(log);
1154 return -1;
1155 }
1156
1157 if (cf_section_parse(log, log, cs) < 0) goto error;
1158
1160 switch (log->dst) {
1161 case L_DST_NUM_DEST:
1162 fr_strerror_printf("Unknown log_destination '%s'", log_destination);
1164 log_destination = NULL;
1165 goto error;
1166
1167#ifdef HAVE_SYSLOG_H
1168 case L_DST_SYSLOG:
1170 log_destination = NULL;
1171
1172 if (fr_log_init_syslog(log) < 0) goto error;
1173 break;
1174#endif
1175
1176 case L_DST_STDOUT:
1178 log_destination = NULL;
1179
1180 if (fr_log_init_std(log, L_DST_STDOUT) < 0) goto error;
1181 break;
1182
1183 case L_DST_STDERR:
1185 log_destination = NULL;
1186
1187 if (fr_log_init_std(log, L_DST_STDERR) < 0) goto error;
1188 break;
1189
1190 case L_DST_FILES:
1192 log_destination = NULL;
1193
1194 if (!log->file) {
1195 fr_strerror_const("Specified \"files\" as a log destination, but no log filename was given!");
1196 goto error;
1197 }
1198
1200 .log = log,
1201 });
1202 if (dst) {
1203 fr_strerror_printf("The log destination '%s' is already logging to file %s",
1204 dst->name, log->file);
1205 goto error;
1206 }
1207
1208 if (fr_log_init_file(log, log->file) < 0) goto error;
1209
1210 talloc_set_destructor(log, _log_free);
1211 break;
1212
1213 case L_DST_NULL:
1214 break;
1215
1216 default:
1218 log_destination = NULL;
1219
1220 fr_assert(0);
1221 break;
1222 }
1223
1226 } else {
1228 }
1229
1230 log_register_dst(name, log, cs);
1231
1232 return 0;
1233}
1234
1235static int8_t _log_track_name_cmp(void const *two, void const *one)
1236{
1237 fr_log_track_t const *a = one;
1238 fr_log_track_t const *b = two;
1239
1240 return CMP(strcmp(a->name, b->name), 0);
1241}
1242
1243static int8_t _log_track_filename_cmp(void const *two, void const *one)
1244{
1245 fr_log_track_t const *a = one;
1246 fr_log_track_t const *b = two;
1247
1248 fr_assert(a->log);
1249 fr_assert(a->log->dst == L_DST_FILES);
1250
1251 fr_assert(b->log);
1252 fr_assert(b->log->dst == L_DST_FILES);
1253
1254 return CMP(strcmp(a->log->file, b->log->file), 0);
1255}
1256
1257/** Initialises the server logging functionality, and the underlying libfreeradius log
1258 *
1259 * @note Call log free when the server is done to fix any spurious memory leaks.
1260 *
1261 * @param[in] log Logging parameters.
1262 * @param[in] daemonize Changes what we do with stdout/stderr.
1263 * @return
1264 * - 0 on success.
1265 * - -1 on failure.
1266 */
1267int log_global_init(fr_log_t *log, bool daemonize)
1268{
1269 int ret;
1270
1271 ret = fr_log_init_legacy(log, daemonize);
1272 if (ret < 0) return ret;
1273
1274 if (fr_dict_autoload(log_dict) < 0) {
1275 fr_perror("log_init");
1276 return -1;
1277 }
1278
1280 fr_perror("log_init");
1281 return -1;
1282 }
1283
1284 dst_tree = fr_rb_inline_alloc(NULL, fr_log_track_t, name_node,
1285 _log_track_name_cmp, NULL);
1286 if (!dst_tree) {
1287 fr_perror("log_init");
1288 return -1;
1289 }
1290
1291 filename_tree = fr_rb_inline_alloc(NULL, fr_log_track_t, filename_node,
1293 if (!filename_tree) {
1294 fr_perror("log_init");
1295 return -1;
1296 }
1297
1298 log_register_dst("default", log, NULL);
1299
1300 return ret;
1301}
1302
1304{
1306 TALLOC_FREE(src_tree);
1307 TALLOC_FREE(dst_tree);
1308 TALLOC_FREE(filename_tree);
1309}
static int const char char buffer[256]
Definition acutest.h:576
int const char * file
Definition acutest.h:702
va_end(args)
static int const char * fmt
Definition acutest.h:573
int const char int line
Definition acutest.h:702
va_start(args, fmt)
#define fr_atexit_thread_local(_name, _free, _uctx)
Definition atexit.h:221
#define RCSID(id)
Definition build.h:483
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:112
#define unlikely(_x)
Definition build.h:381
#define UNUSED
Definition build.h:315
#define NUM_ELEMENTS(_t)
Definition build.h:337
int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
Parse a configuration section into user-supplied variables.
Definition cf_parse.c:1124
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition cf_parse.c:1550
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:642
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:596
#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_POINTER_IS_SET(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result, recording if a defaul...
Definition cf_parse.h:338
#define cf_section_rules_push(_cs, _rule)
Definition cf_parse.h:674
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:323
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:579
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1185
static fr_atomic_queue_t * aq
#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:234
#define ERROR(fmt,...)
Definition dhcpclient.c:41
#define fr_dict_autofree(_to_free)
Definition dict.h:853
fr_dict_attr_t const * fr_dict_attr_common_parent(fr_dict_attr_t const *a, fr_dict_attr_t const *b, bool is_ancestor)
Find a common ancestor that two TLV type attributes share.
Definition dict_util.c:2037
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
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:268
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:281
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:4090
#define fr_dict_autoload(_to_load)
Definition dict.h:850
#define FR_DICT_MAX_TLV_STACK
Maximum TLV stack size.
Definition dict.h:495
#define FR_DICT_ATTR_MAX_NAME_LEN
Maximum length of a attribute name.
Definition dict.h:475
Specifies an attribute which must be present for the module to function.
Definition dict.h:267
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:280
ssize_t fr_mkdir(int *fd_out, char const *path, ssize_t len, mode_t mode, fr_mkdir_func_t func, void *uctx)
Create directories that are missing in the specified path.
Definition file.c:219
FILE * fopencookie(void *cookie, const char *mode, cookie_io_functions_t io_funcs)
Definition fopencookie.c:99
cookie_close_function_t close
Definition fopencookie.h:55
cookie_seek_function_t seek
Definition fopencookie.h:54
cookie_read_function_t read
Definition fopencookie.h:52
cookie_write_function_t write
Definition fopencookie.h:53
static fr_rb_tree_t * filename_tree
Definition log.c:234
void log_request_hex(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, uint8_t const *data, size_t data_len)
Definition log.c:928
static const conf_parser_t log_config[]
Definition log.c:1100
static bool log_timestamp
Definition log.c:1094
fr_rb_node_t filename_node
tree by name
Definition log.c:220
static int8_t _log_track_name_cmp(void const *two, void const *one)
Definition log.c:1235
static fr_sbuff_t * log_request_oid_buff(void)
Allocate an extensible sbuff for printing OID strings.
Definition log.c:744
static fr_dict_attr_t const * attr_module_failure_message
Definition log.c:206
void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a list of protocol fr_pair_ts.
Definition log.c:854
static char const * log_destination
Definition log.c:1093
fr_rb_node_t id_node
tree by ID
Definition log.c:230
fr_table_num_sorted_t const log_destination_table[]
Definition log.c:186
void log_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Marshal variadic log arguments into a va_list and pass to normal logging functions.
Definition log.c:612
int log_global_init(fr_log_t *log, bool daemonize)
Initialises the server logging functionality, and the underlying libfreeradius log.
Definition log.c:1267
static fr_rb_tree_t * dst_tree
Definition log.c:233
static _Thread_local fr_sbuff_t * fr_log_request_oid_buff
Definition log.c:56
fr_dict_autoload_t log_dict[]
Definition log.c:201
static fr_dict_t const * dict_freeradius
Definition log.c:198
static int _fr_log_request_oid_buff_free(void *arg)
Cleanup the memory pool used by the OID sbuff.
Definition log.c:736
void log_request_perror(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Drain any outstanding messages from the fr_strerror buffers.
Definition log.c:679
static int _log_free(fr_log_t *log)
Definition log.c:1085
size_t log_destination_table_len
Definition log.c:194
bool log_rdebug_enabled(fr_log_lvl_t lvl, request_t const *request)
Whether a request specific debug message should be logged.
Definition log.c:267
fr_rb_node_t name_node
tree by name only
Definition log.c:229
static int8_t _log_track_filename_cmp(void const *two, void const *one)
Definition log.c:1243
void log_request_marker(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *str, size_t str_len, ssize_t marker_idx, char const *marker_fmt,...)
Write the string being parsed, and a marker showing where the parse error occurred.
Definition log.c:886
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition log.c:830
int log_parse_section(CONF_SECTION *cs)
Parse a named logging section.
Definition log.c:1132
fr_table_num_sorted_t const syslog_severity_table[]
Syslog severity table.
Definition log.c:151
fr_log_t * log_dst_by_name(char const *name)
Get a logging destination by name.
Definition log.c:1074
fr_dict_attr_autoload_t log_dict_attr[]
Definition log.c:209
fr_log_t ** log
where the logs should go
Definition log.c:227
static fr_rb_tree_t * src_tree
Definition log.c:235
fr_log_t * original
the original fr_log_t
Definition log.c:226
void log_fatal(fr_log_t const *log, char const *file, int line, char const *fmt,...)
Log a fatal error, then exit.
Definition log.c:1039
static void vlog_module_failure_msg(request_t *request, char const *fmt, va_list ap)
Add a module failure message fr_pair_t to the request.
Definition log.c:567
fr_log_t * log
pointer to the log structure
Definition log.c:216
void log_request_fd_event(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, void *uctx)
Function to provide as the readable callback to the event loop.
Definition log.c:956
size_t syslog_facility_table_len
Definition log.c:143
static bool log_timestamp_is_set
Definition log.c:1095
static void log_always(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 without evaluating its debug level.
Definition log.c:248
CONF_SECTION * cs
where this log configuration came from
Definition log.c:217
size_t syslog_severity_table_len
Definition log.c:184
static char const spaces[]
Definition log.c:196
char const * name
name of this logging source
Definition log.c:224
void log_request_error(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Marshal variadic log arguments into a va_list and pass to error logging functions.
Definition log.c:647
char const * name
name of this logging destination
Definition log.c:215
uint32_t id
LOG_ID of this source.
Definition log.c:225
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:295
static void log_register_dst(char const *name, fr_log_t *log, CONF_SECTION *cs)
Register a logging destination.
Definition log.c:1053
void log_request_pair(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_t const *vp, char const *prefix)
Print a fr_pair_t.
Definition log.c:781
fr_rb_node_t name_node
tree by name
Definition log.c:219
static _Thread_local TALLOC_CTX * fr_vlog_request_pool
Definition log.c:55
fr_table_num_sorted_t const syslog_facility_table[]
Syslog facility table.
Definition log.c:66
void log_global_free(void)
Definition log.c:1303
static int _fr_vlog_request_pool_free(void *arg)
Cleanup the memory pool used by vlog_request.
Definition log.c:279
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
fr_log_lvl_t lvl
Log messages with lvl >= to this should be logged.
Definition log.h:73
request_t * request
request to log messages in the context of.
Definition log.h:86
#define RDEBUG_ENABLEDX(_x)
True if specified lvl is enabled.
Definition log.h:338
#define RDEBUGX(_l, fmt,...)
Definition log.h:340
fr_log_lvl_t lvl
Priority of the message.
Definition log.h:85
void * uctx
Context to pass to the logging function.
Definition log.h:72
log_dst_t * next
Next logging destination.
Definition log.h:74
#define DEBUG_ENABLED3
True if global debug level 1-3 messages are enabled.
Definition log.h:259
char const * prefix
To add to log messages.
Definition log.h:87
fr_log_type_t type
What type of log message it is.
Definition log.h:84
log_func_t func
Function to call to log to this destination.
Definition log.h:71
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
Definition log.h:70
Context structure for the log fd event function.
Definition log.h:83
ssize_t rad_filename_escape(UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg)
Escapes the raw string such that it should be safe to use as part of a file path.
Definition util.c:216
talloc_free(reap)
Stores all information relating to an event list.
Definition event.c:411
fr_table_num_ordered_t const fr_log_levels[]
Maps log categories to message prefixes.
Definition log.c:245
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
Definition log.c:907
int fr_log_init_syslog(fr_log_t *log)
Initialise a syslog logging destination.
Definition log.c:1135
int fr_log_init_std(fr_log_t *log, fr_log_dst_t dst_type)
Initialise log dst for stdout, stderr or /dev/null.
Definition log.c:1028
int fr_log_init_file(fr_log_t *log, char const *file)
Initialise a file logging destination.
Definition log.c:1083
void fr_vlog(fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt, va_list ap)
Send a server log message to its destination.
Definition log.c:344
bool log_dates_utc
Definition log.c:289
@ L_DST_NULL
Discard log messages.
Definition log.h:83
@ L_DST_STDERR
Log to stderr.
Definition log.h:81
@ L_DST_FILES
Log to a file on disk.
Definition log.h:79
@ L_DST_FUNC
Send log messages to a FILE*, via fopencookie()
Definition log.h:82
@ L_DST_NUM_DEST
Definition log.h:84
@ L_DST_STDOUT
Log to stdout.
Definition log.h:78
@ L_DST_SYSLOG
Log to syslog.
Definition log.h:80
@ L_TIMESTAMP_ON
Always log timestamps.
Definition log.h:90
@ L_TIMESTAMP_OFF
Never log timestamps.
Definition log.h:91
@ L_TIMESTAMP_AUTO
Timestamp logging preference not specified.
Definition log.h:88
fr_log_lvl_t
Definition log.h:67
fr_log_type_t
Definition log.h:54
@ L_DBG_WARN_REQ
Less severe warning only displayed when debugging is enabled.
Definition log.h:63
@ L_ERR
Error message.
Definition log.h:56
@ L_DBG_ERR
Error only displayed when debugging is enabled.
Definition log.h:62
@ L_DBG_ERR_REQ
Less severe error only displayed when debugging is enabled.
Definition log.h:64
@ L_DBG_WARN
Warning only displayed when debugging is enabled.
Definition log.h:61
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:59
Main server configuration.
Definition main_config.h:51
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_GROUP
A grouping of other attributes.
unsigned int uint32_t
long int ssize_t
ssize_t fr_dict_attr_oid_print(fr_sbuff_t *out, fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
unsigned char uint8_t
struct tm * gmtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:201
int fr_pair_value_aprintf(fr_pair_t *vp, char const *fmt,...)
Print data into an "string" data type.
Definition pair.c:2698
int fr_pair_value_strdup_shallow(fr_pair_t *vp, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a vp, but don't copy it.
Definition pair.c:2658
char * fr_vasprintf_secure(TALLOC_CTX *ctx, char const *fmt, va_list ap)
Definition print.c:856
char * fr_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap)
Definition print.c:851
#define fr_assert(_expr)
Definition rad_assert.h:38
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:577
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:626
#define fr_rb_inline_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black tree.
Definition rb.h:271
The main red black tree structure.
Definition rb.h:73
static char const * name
size_t fr_sbuff_shift(fr_sbuff_t *sbuff, size_t shift)
Shift the contents of the sbuff, returning the number of bytes we managed to shift.
Definition sbuff.c:195
bool fr_sbuff_is_terminal(fr_sbuff_t *in, fr_sbuff_term_t const *tt)
Efficient terminal string search.
Definition sbuff.c:2152
size_t fr_sbuff_adv_until(fr_sbuff_t *sbuff, size_t len, fr_sbuff_term_t const *tt, char escape_chr)
Wind position until we hit a character in the terminal set.
Definition sbuff.c:1852
#define fr_sbuff_start(_sbuff_or_marker)
#define fr_sbuff_set(_dst, _src)
#define fr_sbuff_current(_sbuff_or_marker)
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition sbuff.h:192
#define fr_sbuff_init_out(_out, _start, _len_or_end)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define fr_sbuff_remaining(_sbuff_or_marker)
#define fr_sbuff_used(_sbuff_or_marker)
#define fr_sbuff_behind(_sbuff_or_marker)
#define fr_sbuff_ahead(_sbuff_or_marker)
Set of terminal elements.
Talloc sbuff extension structure.
Definition sbuff.h:139
#define pair_prepend_request(_attr, _da)
Allocate and prepend a fr_pair_t to the request list.
Definition pair.h:77
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
fr_aka_sim_id_type_t type
fr_pair_t * vp
Definition log.h:96
fr_log_dst_t dst
Log destination.
Definition log.h:97
fr_log_timestamp_t timestamp
Prefix log messages with timestamps.
Definition log.h:110
char const * file
Path to log file.
Definition log.h:113
FILE * handle
Path to log file.
Definition log.h:116
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
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:653
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:492
static int talloc_const_free(void const *ptr)
Free const'd memory.
Definition talloc.h:224
static fr_event_list_t * el
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
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
#define PAIR_VERIFY(_x)
Definition pair.h:191
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:261
static fr_slen_t parent
Definition pair.h:851
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:733
char const * fr_strerror_pop(void)
Pop the last library error.
Definition strerror.c:681
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
#define FR_TYPE_QUOTED
Definition types.h:292
#define FR_TYPE_STRUCTURAL
Definition types.h:296
static fr_slen_t data
Definition value.h:1265
#define fr_box_strvalue_len(_val, _len)
Definition value.h:286