The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_linelog.c
Go to the documentation of this file.
1/*
2 * rlm_linelog.c
3 *
4 * Version: $Id: 396b5abc6e6e1c3a860616cf2096f72205b7b15c $
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 * @copyright 2004,2006 The FreeRADIUS server project
21 * @copyright 2004 Alan DeKok (aland@freeradius.org)
22 */
23
24RCSID("$Id: 396b5abc6e6e1c3a860616cf2096f72205b7b15c $")
25
26#include <freeradius-devel/server/base.h>
27#include <freeradius-devel/server/exfile.h>
28#include <freeradius-devel/server/module_rlm.h>
29#include <freeradius-devel/server/tmpl_dcursor.h>
30#include <freeradius-devel/server/rcode.h>
31#include <freeradius-devel/server/tmpl.h>
32#include <freeradius-devel/unlang/call_env.h>
33#include <freeradius-devel/unlang/tmpl.h>
34#include <freeradius-devel/unlang/module.h>
35
36#include <freeradius-devel/util/debug.h>
37#include <freeradius-devel/util/iovec.h>
38#include <freeradius-devel/util/perm.h>
39#include <freeradius-devel/util/print.h>
40#include <freeradius-devel/util/value.h>
41#include <freeradius-devel/util/types.h>
42
43#include <freeradius-devel/unlang/xlat_func.h>
44
45#ifdef HAVE_FCNTL_H
46# include <fcntl.h>
47#endif
48
49#ifdef HAVE_UNISTD_H
50# include <unistd.h>
51#endif
52
53#ifdef HAVE_GRP_H
54# include <grp.h>
55#endif
56
57#ifdef HAVE_SYSLOG_H
58# include <syslog.h>
59# ifndef LOG_INFO
60# define LOG_INFO (0)
61# endif
62#endif
63
64#include <sys/uio.h>
65
66static int linelog_escape_func(fr_value_box_t *vb, UNUSED void *uctx);
67static int call_env_filename_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci,
68 call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule);
69typedef enum {
71 LINELOG_DST_FILE, //!< Log to a file.
72 LINELOG_DST_REQUEST, //!< Log to the request->log
73 LINELOG_DST_SYSLOG, //!< Log to syslog.
74 LINELOG_DST_UNIX, //!< Log via Unix socket.
75 LINELOG_DST_UDP, //!< Log via UDP.
76 LINELOG_DST_TCP, //!< Log via TCP.
77 LINELOG_DST_STDOUT, //!< Log to stdout.
78 LINELOG_DST_STDERR, //!< Log to stderr.
80
82 { L("file"), LINELOG_DST_FILE },
83 { L("files"), LINELOG_DST_FILE },
84 { L("request"), LINELOG_DST_REQUEST },
85 { L("stderr"), LINELOG_DST_STDERR },
86 { L("stdout"), LINELOG_DST_STDOUT },
87 { L("syslog"), LINELOG_DST_SYSLOG },
88 { L("tcp"), LINELOG_DST_TCP },
89 { L("udp"), LINELOG_DST_UDP },
90 { L("unix"), LINELOG_DST_UNIX }
91};
93
94typedef struct {
95 fr_ipaddr_t dst_ipaddr; //!< Network server.
96 fr_ipaddr_t src_ipaddr; //!< Send requests from a given src_ipaddr.
97 uint16_t port; //!< Network port.
98 fr_time_delta_t timeout; //!< How long to wait for read/write operations.
100
101/** linelog module instance
102 */
103typedef struct {
104 fr_pool_t *pool; //!< Connection pool instance.
105
106 char const *delimiter; //!< Line termination string (usually \n).
107 size_t delimiter_len; //!< Length of line termination string.
108
109 linefr_log_dst_t log_dst; //!< Logging destination.
110 char const *log_dst_str; //!< Logging destination string.
111
112 struct {
113 char const *facility; //!< Syslog facility string.
114 char const *severity; //!< Syslog severity string.
115 int priority; //!< Bitwise | of severity and facility.
116 } syslog;
117
118 struct {
119 mode_t permissions; //!< Permissions to use when creating new files.
120 char const *group_str; //!< Group to set on new files.
121 gid_t group; //!< Resolved gid.
122 exfile_t *ef; //!< Exclusive file access handle.
123 bool escape; //!< Do filename escaping, yes / no.
124 bool fsync; //!< fsync after each write.
126
127 struct {
128 char const *path; //!< Where the UNIX socket lives.
129 fr_time_delta_t timeout; //!< How long to wait for read/write operations.
130 } unix_sock; // Lowercase unix is a macro on some systems?!
131
132 linelog_net_t tcp; //!< TCP server.
133 linelog_net_t udp; //!< UDP server.
134
135 CONF_SECTION *cs; //!< #CONF_SECTION to use as the root for #log_ref lookups.
136
137 bool triggers; //!< Do we do triggers.
139
140typedef struct {
141 int sockfd; //!< File descriptor associated with socket
143
144
145static const conf_parser_t file_config[] = {
146 { FR_CONF_OFFSET("permissions", rlm_linelog_t, file.permissions), .dflt = "0600", .func = cf_parse_permissions },
147 { FR_CONF_OFFSET("group", rlm_linelog_t, file.group_str) },
148 { FR_CONF_OFFSET("escape_filenames", rlm_linelog_t, file.escape), .dflt = "no" },
149 { FR_CONF_OFFSET("fsync", rlm_linelog_t, file.fsync), .dflt = "no" },
151};
152
153static const conf_parser_t syslog_config[] = {
154 { FR_CONF_OFFSET("facility", rlm_linelog_t, syslog.facility) },
155 { FR_CONF_OFFSET("severity", rlm_linelog_t, syslog.severity), .dflt = "info" },
157};
158
159static const conf_parser_t unix_config[] = {
160 { FR_CONF_OFFSET_FLAGS("filename", CONF_FLAG_FILE_SOCKET, rlm_linelog_t, unix_sock.path) },
162};
163
164static const conf_parser_t udp_config[] = {
166 { FR_CONF_OFFSET("port", linelog_net_t, port) },
167 { FR_CONF_OFFSET("timeout", linelog_net_t, timeout), .dflt = "1000" },
169};
170
171static const conf_parser_t tcp_config[] = {
173 { FR_CONF_OFFSET("port", linelog_net_t, port) },
174 { FR_CONF_OFFSET("timeout", linelog_net_t, timeout), .dflt = "1000" },
176};
177
178static const conf_parser_t module_config[] = {
179 { FR_CONF_OFFSET_FLAGS("destination", CONF_FLAG_REQUIRED, rlm_linelog_t, log_dst_str) },
180
181 { FR_CONF_OFFSET("delimiter", rlm_linelog_t, delimiter), .dflt = "\n" },
182
183 { FR_CONF_OFFSET("triggers", rlm_linelog_t, triggers) },
184
185 /*
186 * Log destinations
187 */
188 { FR_CONF_POINTER("file", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) file_config },
189 { FR_CONF_POINTER("syslog", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) syslog_config },
190 { FR_CONF_POINTER("unix", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) unix_config },
193
194 /*
195 * Deprecated config items
196 */
197 { FR_CONF_DEPRECATED("permissions", rlm_linelog_t, file.permissions) },
198 { FR_CONF_DEPRECATED("group", rlm_linelog_t, file.group_str) },
199
200 { FR_CONF_DEPRECATED("syslog_facility", rlm_linelog_t, syslog.facility) },
201 { FR_CONF_DEPRECATED("syslog_severity", rlm_linelog_t, syslog.severity) },
203};
204
205typedef struct {
206 tmpl_t *log_src; //!< Source of log messages.
207
208 fr_value_box_t *log_ref; //!< Path to a #CONF_PAIR (to use as the source of
209 ///< log messages).
210
211 fr_value_box_t *log_head; //!< Header to add to each new log file.
212
213 fr_value_box_t *filename; //!< File name, if output is to a file.
215
216#define LINELOG_BOX_ESCAPE { \
217 .func = linelog_escape_func, \
218 .safe_for = (fr_value_box_safe_for_t) linelog_escape_func, \
219 .always_escape = false, \
220 }
221
237
251
253{
254 if (shutdown(conn->sockfd, SHUT_RDWR) < 0) DEBUG3("Shutdown failed: %s", fr_syserror(errno));
255 if (close(conn->sockfd) < 0) DEBUG3("Closing socket failed: %s", fr_syserror(errno));
256
257 return 0;
258}
259
260static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
261{
262 rlm_linelog_t const *inst = talloc_get_type_abort(instance, rlm_linelog_t);
263 linelog_conn_t *conn;
264 int sockfd = -1;
265
266 switch (inst->log_dst) {
267 case LINELOG_DST_UNIX:
268 DEBUG2("Opening UNIX socket at \"%s\"", inst->unix_sock.path);
269 sockfd = fr_socket_client_unix(inst->unix_sock.path, true);
270 if (sockfd < 0) {
271 PERROR("Failed opening UNIX socket");
272 return NULL;
273 }
274 break;
275
276 case LINELOG_DST_TCP:
277 DEBUG2("Opening TCP connection to %pV:%u", fr_box_ipaddr(inst->tcp.dst_ipaddr), inst->tcp.port);
278
279 sockfd = fr_socket_client_tcp(NULL, NULL, &inst->tcp.dst_ipaddr, inst->tcp.port, true);
280 if (sockfd < 0) {
281 PERROR("Failed opening TCP socket");
282 return NULL;
283 }
284 break;
285
286 case LINELOG_DST_UDP:
287 DEBUG2("Opening UDP connection to %pV:%u", fr_box_ipaddr(inst->udp.dst_ipaddr), inst->udp.port);
288
289 sockfd = fr_socket_client_udp(NULL, NULL, NULL, &inst->udp.dst_ipaddr, inst->udp.port, true);
290 if (sockfd < 0) {
291 PERROR("Failed opening UDP socket");
292 return NULL;
293 }
294 break;
295
296 /*
297 * Are not connection oriented destinations
298 */
300 case LINELOG_DST_FILE:
305 fr_assert(0);
306 return NULL;
307 }
308
309 if (errno == EINPROGRESS) {
310 if (fr_time_delta_ispos(timeout)) {
311 DEBUG2("Waiting for connection to complete...");
312 } else {
313 DEBUG2("Blocking until connection complete...");
314 }
315 if (fr_socket_wait_for_connect(sockfd, timeout) < 0) {
316 PERROR("Failed connecting to log destination");
317 close(sockfd);
318 return NULL;
319 }
320 }
321 DEBUG2("Connection successful");
322
323 /*
324 * Set blocking operation as we have no timeout set
325 */
326 if (!fr_time_delta_ispos(timeout) && (fr_blocking(sockfd) < 0)) {
327 ERROR("Failed setting nonblock flag on fd");
328 close(sockfd);
329 return NULL;
330 }
331
332 conn = talloc_zero(ctx, linelog_conn_t);
333 conn->sockfd = sockfd;
334 talloc_set_destructor(conn, _mod_conn_free);
335
336 return conn;
337}
338
339/** Escape unprintable characters
340 *
341 * - Newline is escaped as ``\\n``.
342 * - Return is escaped as ``\\r``.
343 * - All other unprintables are escaped as @verbatim <oct><oct><oct> @endverbatim.
344 *
345 * @param vb Value box to escape.
346 * @param uctx unused.
347 */
348/*
349 * Escape unprintable characters.
350 */
351static int linelog_escape_func(fr_value_box_t *vb, UNUSED void *uctx)
352{
353 char *escaped;
354
355 if (vb->vb_length == 0) return 0;
356
357 MEM(escaped = fr_asprint(vb, vb->vb_strvalue, vb->vb_length, 0));
359
360 return 0;
361}
362
363static void linelog_hexdump(request_t *request, struct iovec *vector_p, size_t vector_len, char const *msg)
364{
365 fr_dbuff_t *agg;
366
367 FR_DBUFF_TALLOC_THREAD_LOCAL(&agg, 1024, SIZE_MAX);
368 fr_concatv(agg, vector_p, vector_len);
369
370 RHEXDUMP3(fr_dbuff_start(agg), fr_dbuff_used(agg), "%s", msg);
371}
372
373static int linelog_write(rlm_linelog_t const *inst, linelog_call_env_t const *call_env, request_t *request, struct iovec *vector_p, size_t vector_len, bool with_delim)
374{
375 int ret = 0;
376 linelog_conn_t *conn;
378
379 /*
380 * Reserve a handle, write out the data, close the handle
381 */
382 switch (inst->log_dst) {
383 case LINELOG_DST_FILE:
384 {
385 int fd = -1;
386 char const *path;
387 off_t offset;
388 char *p;
389
390 if (!call_env->filename) {
391 RERROR("Missing filename");
392 return -1;
393 }
394
395 path = call_env->filename->vb_strvalue;
396
397 /* check path and eventually create subdirs */
398 p = strrchr(path, '/');
399 if (p) {
400 *p = '\0';
401 if (fr_mkdir(NULL, path, -1, 0700, NULL, NULL) < 0) {
402 RERROR("Failed to create directory %pV: %s", call_env->filename, fr_syserror(errno));
403 return -1;
404 }
405 *p = '/';
406 }
407
408 fd = exfile_open(inst->file.ef, path, inst->file.permissions, &offset);
409 if (fd < 0) {
410 RERROR("Failed to open %pV: %s", call_env->filename, fr_syserror(errno));
411 return -1;
412 }
413
414 if (inst->file.group_str && (chown(path, -1, inst->file.group) == -1)) {
415 RPWARN("Unable to change system group of \"%pV\": %s", call_env->filename, fr_strerror());
416 }
417
418 /*
419 * If a header format is defined and we are at the beginning
420 * of the file then expand the format and write it out before
421 * writing the actual log entries.
422 */
423 if (call_env->log_head && (offset == 0)) {
424 struct iovec head_vector_s[2];
425 size_t head_vector_len;
426
427 memcpy(&head_vector_s[0].iov_base, &call_env->log_head->vb_strvalue, sizeof(head_vector_s[0].iov_base));
428 head_vector_s[0].iov_len = call_env->log_head->vb_length;
429
430 if (!with_delim) {
431 head_vector_len = 1;
432 } else {
433 memcpy(&head_vector_s[1].iov_base, &(inst->delimiter),
434 sizeof(head_vector_s[1].iov_base));
435 head_vector_s[1].iov_len = inst->delimiter_len;
436 head_vector_len = 2;
437 }
438
439 if (RDEBUG_ENABLED3) linelog_hexdump(request, head_vector_s, head_vector_len, "linelog header");
440
441 if (writev(fd, &head_vector_s[0], head_vector_len) < 0) {
442 write_fail:
443 RERROR("Failed writing to \"%pV\": %s", call_env->filename, fr_syserror(errno));
444 exfile_close(inst->file.ef, fd);
445
446 /* Assert on the extra fatal errors */
447 fr_assert((errno != EINVAL) && (errno != EFAULT));
448
449 return -1;
450 }
451 if (inst->file.fsync && (fsync(fd) < 0)) {
452 RERROR("Failed syncing \"%pV\" to persistent storage: %s", call_env->filename, fr_syserror(errno));
453 exfile_close(inst->file.ef, fd);
454 return -1;
455 }
456 }
457
458 if (RDEBUG_ENABLED3) linelog_hexdump(request, vector_p, vector_len, "linelog data");
459
460 ret = writev(fd, vector_p, vector_len);
461 if (ret < 0) goto write_fail;
462
463 exfile_close(inst->file.ef, fd);
464 }
465 break;
466
468 {
469 size_t i;
470
471 ret = 0;
472 for (i = 0; i < vector_len; i++) {
473 RINFO("%.*s", (int)vector_p[i].iov_len, (char *)vector_p[i].iov_base);
474 ret += vector_p[i].iov_len;
475 }
476 }
477 break;
478
479 case LINELOG_DST_UNIX:
480 if (fr_time_delta_ispos(inst->unix_sock.timeout)) {
481 timeout = inst->unix_sock.timeout;
482 }
483 goto do_write;
484
485 case LINELOG_DST_UDP:
486 if (fr_time_delta_ispos(inst->udp.timeout)) {
487 timeout = inst->udp.timeout;
488 }
489 goto do_write;
490
491 case LINELOG_DST_TCP:
492 {
493 int i, num;
494 if (fr_time_delta_ispos(inst->tcp.timeout)) {
495 timeout = inst->tcp.timeout;
496 }
497
498 do_write:
499 num = fr_pool_state(inst->pool)->num;
500 conn = fr_pool_connection_get(inst->pool, request);
501 if (!conn) return -1;
502
503 for (i = num; i >= 0; i--) {
504 ssize_t wrote;
505 char discard[64];
506
507 if (RDEBUG_ENABLED3) linelog_hexdump(request, vector_p, vector_len, "linelog data");
508 wrote = fr_writev(conn->sockfd, vector_p, vector_len, timeout);
509 if (wrote < 0) switch (errno) {
510 /* Errors that indicate we should reconnect */
511 case EDESTADDRREQ:
512 case EPIPE:
513 case EBADF:
514 case ECONNRESET:
515 case ENETDOWN:
516 case ENETUNREACH:
517 case EADDRNOTAVAIL: /* Which is OSX for outbound interface is down? */
518 RWARN("Failed writing to socket: %s. Will reconnect and try again...",
519 fr_syserror(errno));
520 conn = fr_pool_connection_reconnect(inst->pool, request, conn);
521 if (!conn) {
522 ret = -1;
523 goto done;
524 }
525 continue;
526
527 /* Assert on the extra fatal errors */
528 case EINVAL:
529 case EFAULT:
530 fr_assert(0);
532
533 /* Normal errors that just cause the module to fail */
534 default:
535 RERROR("Failed writing to socket: %s", fr_syserror(errno));
536 ret = -1;
537 goto done;
538 }
539 RDEBUG2("Wrote %zi bytes", wrote);
540 ret = wrote;
541
542 /* Drain the receive buffer */
543 while (read(conn->sockfd, discard, sizeof(discard)) > 0);
544 break;
545 }
546 done:
547 fr_pool_connection_release(inst->pool, request, conn);
548 }
549 break;
550
551#ifdef HAVE_SYSLOG_H
553 {
554 size_t i;
555
556 ret = 0;
557 for (i = 0; i < vector_len; i++) {
558 syslog(inst->syslog.priority, "%.*s", (int)vector_p[i].iov_len, (char *)vector_p[i].iov_base);
559 ret += vector_p[i].iov_len;
560 }
561 }
562 break;
563#endif
564
567 {
568 int fd = inst->log_dst == LINELOG_DST_STDOUT ? STDOUT_FILENO : STDERR_FILENO;
569 if ((ret = writev(fd, vector_p, vector_len)) < 0) {
570 RERROR("Failed writing to \"%s\": %s",
572 fr_syserror(errno));
573 }
574 }
575 break;
576
578 fr_assert(0);
579 ret = -1;
580 break;
581 }
582
583 return ret;
584}
585
587 xlat_ctx_t const *xctx, request_t *request,
588 fr_value_box_list_t *args)
589{
591 linelog_call_env_t const *call_env = talloc_get_type_abort(xctx->env_data, linelog_call_env_t);
592
593 struct iovec vector[2];
594 size_t i = 0;
595 bool with_delim;
596 fr_value_box_t *msg, *wrote;
597 ssize_t slen;
598
599 XLAT_ARGS(args, &msg);
600
601 vector[i].iov_base = UNCONST(char *, msg->vb_strvalue);
602 vector[i].iov_len = msg->vb_length;
603 i++;
604
605 with_delim = (inst->log_dst != LINELOG_DST_SYSLOG) && (inst->delimiter_len > 0);
606 if (with_delim) {
607 memcpy(&vector[i].iov_base, &(inst->delimiter), sizeof(vector[i].iov_base));
608 vector[i].iov_len = inst->delimiter_len;
609 i++;
610 }
611 slen = linelog_write(inst, call_env, request, vector, i, with_delim);
612 if (slen < 0) return XLAT_ACTION_FAIL;
613
614 MEM(wrote = fr_value_box_alloc(ctx, FR_TYPE_SIZE, NULL));
615 wrote->vb_size = (size_t)slen;
616
617 fr_dcursor_insert(out, wrote);
618
619 return XLAT_ACTION_DONE;
620}
621
622typedef struct {
623 fr_value_box_list_t expanded; //!< The result of expanding the fmt tmpl
624 bool with_delim; //!< Whether to add a delimiter
626
628{
630 linelog_call_env_t const *call_env = talloc_get_type_abort(mctx->env_data, linelog_call_env_t);
631 rlm_linelog_rctx_t *rctx = talloc_get_type_abort(mctx->rctx, rlm_linelog_rctx_t);
632 struct iovec *vector;
633 struct iovec *vector_p;
634 size_t vector_len;
635
636 vector_len = fr_value_box_list_num_elements(&rctx->expanded);
637 if (vector_len == 0) {
638 RDEBUG2("No data to write");
640 }
641
642 /*
643 * Add extra space for the delimiter
644 */
645 if (rctx->with_delim) vector_len *= 2;
646
647 MEM(vector = vector_p = talloc_array(rctx, struct iovec, vector_len));
649 switch(vb->type) {
650 default:
651 if (unlikely(fr_value_box_cast_in_place(rctx, vb, FR_TYPE_STRING, vb->enumv) < 0)) {
652 REDEBUG("Failed casting value to string");
654 }
656
657 case FR_TYPE_STRING:
658 vector_p->iov_base = UNCONST(char *, vb->vb_strvalue);
659 vector_p->iov_len = vb->vb_length;
660 vector_p++;
661 break;
662
663 case FR_TYPE_OCTETS:
664 vector_p->iov_base = UNCONST(char *, vb->vb_octets);
665 vector_p->iov_len = vb->vb_length;
666 vector_p++;
667 break;
668 }
669
670 /*
671 * Don't add the delim for the last element
672 */
673 if (rctx->with_delim) {
674 memcpy(&vector_p->iov_base, &(inst->delimiter), sizeof(vector_p->iov_base));
675 vector_p->iov_len = inst->delimiter_len;
676 vector_p++;
677 }
678 }
679
680 RETURN_UNLANG_RCODE(linelog_write(inst, call_env, request, vector, vector_len, rctx->with_delim) < 0 ? RLM_MODULE_FAIL : RLM_MODULE_OK);
681}
682
683/** Write a linelog message
684 *
685 * Write a log message to syslog or a flat file.
686 *
687 * @param[in] p_result the result of the module call:
688 * - #RLM_MODULE_NOOP if no message to log.
689 * - #RLM_MODULE_FAIL if we failed writing the message.
690 * - #RLM_MODULE_OK on success.
691 * @param[in] mctx module calling context.
692 * @param[in] request The current request.
693 */
694static unlang_action_t CC_HINT(nonnull) mod_do_linelog(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
695{
697 linelog_call_env_t const *call_env = talloc_get_type_abort(mctx->env_data, linelog_call_env_t);
698 CONF_SECTION *conf = mctx->mi->conf;
699
700 char buff[4096];
701 char *p = buff;
702 tmpl_t *empty, *vpt = NULL, *vpt_p = NULL;
703 ssize_t slen;
704 bool with_delim;
705
706 TALLOC_CTX *frame_ctx = unlang_interpret_frame_talloc_ctx(request);
707
708 if (!call_env->log_src && !call_env->log_ref) {
709 cf_log_err(conf, "A 'format', or 'reference' configuration item must be set to call this module");
711 }
712
713 buff[0] = '.'; /* force to be in current section (by default) */
714 buff[1] = '\0';
715 buff[2] = '\0';
716
717 /*
718 * Expand log_ref to a config path, using the module
719 * configuration section as the root.
720 */
721 if (call_env->log_ref) {
722 CONF_ITEM *ci;
723 CONF_PAIR *cp;
724 char const *tmpl_str;
725
726 memcpy(buff + 1, call_env->log_ref->vb_strvalue, call_env->log_ref->vb_length);
727 buff[call_env->log_ref->vb_length + 1] = '\0';
728
729 if (buff[1] == '.') p++;
730
731 /*
732 * Don't go back up.
733 */
734 if (buff[2] == '.') {
735 REDEBUG("Invalid path \"%s\"", p);
737 }
738
739 ci = cf_reference_item(NULL, inst->cs, p);
740 if (!ci) {
741 RPDEBUG2("Failed finding reference '%s'", p);
742 goto default_msg;
743 }
744
745 if (!cf_item_is_pair(ci)) {
746 REDEBUG("Path \"%s\" resolves to a section (should be a pair)", p);
748 }
749
750 cp = cf_item_to_pair(ci);
751 tmpl_str = cf_pair_value(cp);
752 if (!tmpl_str || (tmpl_str[0] == '\0')) {
753 RDEBUG2("Path \"%s\" resolves to an empty config pair", p);
754 empty = talloc(frame_ctx, tmpl_t);
755 vpt_p = tmpl_init_shallow(empty, TMPL_TYPE_DATA, T_DOUBLE_QUOTED_STRING, "", 0, NULL);
756 fr_value_box_init_null(&empty->data.literal);
757 fr_value_box_strdup_shallow(&empty->data.literal, NULL, "", false);
758 goto build_vector;
759 }
760
761 /*
762 * Alloc a template from the value of the CONF_PAIR
763 * using request as the context (which will hopefully avoid an alloc).
764 */
765 slen = tmpl_afrom_substr(frame_ctx, &vpt,
766 &FR_SBUFF_IN(tmpl_str, talloc_array_length(tmpl_str) - 1),
768 NULL,
769 &(tmpl_rules_t){
770 .attr = {
771 .list_def = request_attr_request,
772 .dict_def = request->local_dict,
773 .allow_unknown = true,
774 .allow_unresolved = false,
775 },
776 .xlat = {
777 .runtime_el = unlang_interpret_event_list(request),
778 },
779 .at_runtime = true,
780 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
781 });
782 if (!vpt) {
783 REMARKER(tmpl_str, -slen, "%s", fr_strerror());
785 }
786 if (tmpl_resolve(vpt, NULL) < 0) {
787 RPERROR("Runtime resolution of tmpl failed");
790 }
791 vpt_p = vpt;
792 } else {
793 default_msg:
794 /*
795 * Use the default format string
796 */
797 if (!call_env->log_src) {
798 RDEBUG2("No default message configured");
800 }
801 /*
802 * Use the pre-parsed format template
803 */
804 RDEBUG2("Using default message");
805 vpt_p = call_env->log_src;
806 }
807
808build_vector:
809 with_delim = (inst->log_dst != LINELOG_DST_SYSLOG) && (inst->delimiter_len > 0);
810
811 /*
812 * Log all the things!
813 */
814 switch (vpt_p->type) {
815 case TMPL_TYPE_ATTR:
816 {
817 #define VECTOR_INCREMENT 20
818 fr_dcursor_t cursor;
820 fr_pair_t *vp;
821 int alloced = VECTOR_INCREMENT, i;
822 struct iovec *vector = NULL, *vector_p;
823 size_t vector_len;
825
826 MEM(vector = talloc_array(frame_ctx, struct iovec, alloced));
827 for (vp = tmpl_dcursor_init(NULL, NULL, &cc, &cursor, request, vpt_p), i = 0;
828 vp;
829 vp = fr_dcursor_next(&cursor), i++) {
830 /* need extra for line terminator */
831 if ((with_delim && ((i + 1) >= alloced)) ||
832 (i >= alloced)) {
833 alloced += VECTOR_INCREMENT;
834 MEM(vector = talloc_realloc(frame_ctx, vector, struct iovec, alloced));
835 }
836
837 switch (vp->vp_type) {
838 case FR_TYPE_OCTETS:
839 case FR_TYPE_STRING:
840 vector[i].iov_len = vp->vp_length;
841 vector[i].iov_base = vp->vp_ptr;
842 break;
843
844 default:
845 vector[i].iov_len = fr_value_box_aprint(vector, &p, &vp->data, NULL);
846 vector[i].iov_base = p;
847 break;
848 }
849
850 /*
851 * Add the line delimiter string
852 */
853 if (with_delim) {
854 i++;
855 memcpy(&vector[i].iov_base, &(inst->delimiter), sizeof(vector[i].iov_base));
856 vector[i].iov_len = inst->delimiter_len;
857 }
858 }
860 vector_p = vector;
861 vector_len = i;
862
863 if (vector_len == 0) {
864 RDEBUG2("No data to write");
865 rcode = RLM_MODULE_NOOP;
866 } else {
867 rcode = linelog_write(inst, call_env, request, vector_p, vector_len, with_delim) < 0 ? RLM_MODULE_FAIL : RLM_MODULE_OK;
868 }
869
871 talloc_free(vector);
872
873 RETURN_UNLANG_RCODE(rcode);
874 }
875
876 /*
877 * Log a format string. We need to yield as this might contain asynchronous expansions.
878 */
879 default:
880 {
881 rlm_linelog_rctx_t *rctx;
882
883 MEM(rctx = talloc(frame_ctx, rlm_linelog_rctx_t));
884 fr_value_box_list_init(&rctx->expanded);
885 rctx->with_delim = with_delim;
886
887 return unlang_module_yield_to_tmpl(rctx, &rctx->expanded, request, vpt_p, NULL, mod_do_linelog_resume, NULL, 0, rctx);
888 }
889 }
890}
891
892/*
893 * Custom call env parser for filenames - sets the correct escaping function
894 */
895static int call_env_filename_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci,
896 call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
897{
899 tmpl_t *parsed;
900 CONF_PAIR const *to_parse = cf_item_to_pair(ci);
901 tmpl_rules_t our_rules;
902
903 /*
904 * If we're not logging to a file destination, do nothing
905 */
907
908 our_rules = *t_rules;
911 .safe_for = (inst->file.escape) ? (fr_value_box_safe_for_t)rad_filename_box_escape :
913 .always_escape = false,
914 };
916 our_rules.literals_safe_for = our_rules.escape.box_escape.safe_for;
917
918 if (tmpl_afrom_substr(ctx, &parsed,
919 &FR_SBUFF_IN(cf_pair_value(to_parse), talloc_array_length(cf_pair_value(to_parse)) - 1),
921 &our_rules) < 0) return -1;
922
923 *(void **)out = parsed;
924 return 0;
925}
926
927static int mod_detach(module_detach_ctx_t const *mctx)
928{
929 rlm_linelog_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_linelog_t);
930
931 fr_pool_free(inst->pool);
932
933 return 0;
934}
935
936/*
937 * Instantiate the module.
938 */
939static int mod_instantiate(module_inst_ctx_t const *mctx)
940{
941 rlm_linelog_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_linelog_t);
942 CONF_SECTION *cs, *conf = mctx->mi->conf;
943 char prefix[100];
944
946 if (inst->log_dst == LINELOG_DST_INVALID) {
947 cf_log_err(conf, "Invalid log destination \"%s\"", inst->log_dst_str);
948 return -1;
949 }
950
951 snprintf(prefix, sizeof(prefix), "rlm_linelog (%s)", mctx->mi->name);
952
953 /*
954 * Setup the logging destination
955 */
956 switch (inst->log_dst) {
957 case LINELOG_DST_FILE:
958 {
959 cs = cf_section_find(conf, "file", CF_IDENT_ANY);
960 if (!cs) {
961 no_filename:
962 cf_log_err(conf, "No value provided for 'file.filename'");
963 return -1;
964 }
965 if (!cf_pair_find(cs, "filename")) goto no_filename;
966
967 inst->file.ef = module_rlm_exfile_init(inst, conf, 256, fr_time_delta_from_sec(30), true,
968 inst->triggers, NULL, NULL);
969 if (!inst->file.ef) {
970 cf_log_err(conf, "Failed creating log file context");
971 return -1;
972 }
973
974 if (inst->file.group_str) {
975 char *endptr;
976
977 inst->file.group = strtol(inst->file.group_str, &endptr, 10);
978 if (*endptr != '\0') {
979 if (fr_perm_gid_from_str(inst, &(inst->file.group), inst->file.group_str) < 0) {
980 cf_log_err(conf, "Unable to find system group \"%s\"",
981 inst->file.group_str);
982 return -1;
983 }
984 }
985 }
986 }
987 break;
988
990 {
991 int num;
992
993#ifndef HAVE_SYSLOG_H
994 cf_log_err(conf, "Syslog output is not supported on this system");
995 return -1;
996#else
997 if (inst->syslog.facility) {
998 num = fr_table_value_by_str(syslog_facility_table, inst->syslog.facility, -1);
999 if (num < 0) {
1000 cf_log_err(conf, "Invalid syslog facility \"%s\"", inst->syslog.facility);
1001 return -1;
1002 }
1003 inst->syslog.priority |= num;
1004 }
1005
1006 num = fr_table_value_by_str(syslog_severity_table, inst->syslog.severity, -1);
1007 if (num < 0) {
1008 cf_log_err(conf, "Invalid syslog severity \"%s\"", inst->syslog.severity);
1009 return -1;
1010 }
1011 inst->syslog.priority |= num;
1012#endif
1013 }
1014 break;
1015
1016 case LINELOG_DST_UNIX:
1017#ifndef HAVE_SYS_UN_H
1018 cf_log_err(conf, "Unix sockets are not supported on this system");
1019 return -1;
1020#else
1022 inst, mod_conn_create, NULL, prefix, NULL, NULL);
1023 if (!inst->pool) return -1;
1024#endif
1025 break;
1026
1027 case LINELOG_DST_UDP:
1029 inst, mod_conn_create, NULL, prefix, NULL, NULL);
1030 if (!inst->pool) return -1;
1031 break;
1032
1033 case LINELOG_DST_TCP:
1035 inst, mod_conn_create, NULL, prefix, NULL, NULL);
1036 if (!inst->pool) return -1;
1037 break;
1038
1040 case LINELOG_DST_STDOUT:
1041 case LINELOG_DST_STDERR:
1042 break;
1043
1045 fr_assert(0);
1046 break;
1047 }
1048
1049 inst->delimiter_len = talloc_array_length(inst->delimiter) - 1;
1050 inst->cs = conf;
1051
1052 return 0;
1053}
1054
1055static int mod_bootstrap(module_inst_ctx_t const *mctx)
1056{
1057 xlat_t *xlat;
1058
1059 static xlat_arg_parser_t const linelog_xlat_args[] = {
1060 { .required = true, .concat = true, .type = FR_TYPE_STRING },
1062 };
1063
1064 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, linelog_xlat, FR_TYPE_SIZE);
1065 xlat_func_args_set(xlat, linelog_xlat_args);
1067
1068 return 0;
1069}
1070
1071/*
1072 * Externally visible module definition.
1073 */
1076 .common = {
1077 .magic = MODULE_MAGIC_INIT,
1078 .name = "linelog",
1079 .inst_size = sizeof(rlm_linelog_t),
1081 .bootstrap = mod_bootstrap,
1082 .instantiate = mod_instantiate,
1083 .detach = mod_detach
1084 },
1085 .method_group = {
1086 .bindings = (module_method_binding_t[]){
1087 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_do_linelog, .method_env = &linelog_method_env },
1089 }
1090 }
1091};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
int const char * file
Definition acutest.h:702
log_entry msg
Definition acutest.h:794
va_list args
Definition acutest.h:770
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define RCSID(id)
Definition build.h:485
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
#define NUM_ELEMENTS(_t)
Definition build.h:339
#define CALL_ENV_TERMINATOR
Definition call_env.h:236
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition call_env.h:240
call_env_parser_t const * env
Parsing rules for call method env.
Definition call_env.h:247
#define FR_CALL_ENV_SUBSECTION(_name, _name2, _flags, _subcs)
Specify a call_env_parser_t which defines a nested subsection.
Definition call_env.h:402
@ CALL_ENV_FLAG_CONCAT
If the tmpl produced multiple boxes they should be concatenated.
Definition call_env.h:76
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
Definition call_env.h:85
@ CALL_ENV_FLAG_NONE
Definition call_env.h:74
@ CALL_ENV_FLAG_BARE_WORD_ATTRIBUTE
bare words are treated as an attribute, but strings may be xlats.
Definition call_env.h:92
module_instance_t const * mi
Module instance that the callenv is registered to.
Definition call_env.h:229
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
Definition call_env.h:340
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition call_env.h:389
Per method call config.
Definition call_env.h:180
CONF_ITEM * cf_reference_item(CONF_SECTION const *parent_cs, CONF_SECTION const *outer_cs, char const *ptr)
Definition cf_file.c:3745
int cf_parse_permissions(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Generic function for resolving permissions to a mode-t.
Definition cf_parse.c:1715
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:662
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:616
#define FR_CONF_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a matching CONF_PAIR is found
Definition cf_parse.h:414
#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:284
#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:339
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:272
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:313
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:434
@ CONF_FLAG_FILE_SOCKET
File matching value must exist, and must be a unix socket.
Definition cf_parse.h:444
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:428
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:599
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:631
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1426
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1625
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1581
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:286
#define CF_IDENT_ANY
Definition cf_util.h:78
#define fr_dbuff_used(_dbuff_or_marker)
Return the number of bytes remaining between the start of the dbuff or marker and the current positio...
Definition dbuff.h:767
#define fr_dbuff_start(_dbuff_or_marker)
Return the 'start' position of a dbuff or marker.
Definition dbuff.h:898
#define FR_DBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
Create a function local and thread local extensible dbuff.
Definition dbuff.h:556
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static int fr_dcursor_insert(fr_dcursor_t *cursor, void *v)
Insert directly after the current item.
Definition dcursor.h:437
#define MEM(x)
Definition debug.h:36
#define ERROR(fmt,...)
Definition dhcpclient.c:41
static int sockfd
Definition dhcpclient.c:56
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, off_t *offset)
Open a new log file, or maybe an existing one.
Definition exfile.c:526
int exfile_close(exfile_t *ef, int fd)
Close the log file.
Definition exfile.c:582
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
IPv4/6 prefix.
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:1665
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:2017
ssize_t fr_writev(int fd, struct iovec vector[], int iovcnt, fr_time_delta_t timeout)
Write out a vector to a file descriptor.
Definition iovec.c:68
fr_slen_t fr_concatv(fr_dbuff_t *out, struct iovec vector[], int iovcnt)
Concatenate an iovec into a dbuff.
Definition iovec.c:38
fr_table_num_sorted_t const syslog_severity_table[]
Syslog severity table.
Definition log.c:151
fr_table_num_sorted_t const syslog_facility_table[]
Syslog facility table.
Definition log.c:66
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
#define RPDEBUG2(fmt,...)
Definition log.h:347
#define RDEBUG_ENABLED3
True if request debug level 1-3 messages are enabled.
Definition log.h:335
#define RWARN(fmt,...)
Definition log.h:297
#define RERROR(fmt,...)
Definition log.h:298
#define RPWARN(fmt,...)
Definition log.h:301
#define RPERROR(fmt,...)
Definition log.h:302
#define REMARKER(_str, _marker_idx, _marker,...)
Output string with error marker, showing where format error occurred.
Definition log.h:498
#define RINFO(fmt,...)
Definition log.h:296
#define RHEXDUMP3(_data, _len, _fmt,...)
Definition log.h:705
int rad_filename_box_escape(fr_value_box_t *vb, UNUSED void *uxtc)
Definition util.c:281
int rad_filename_box_make_safe(fr_value_box_t *vb, UNUSED void *uxtc)
Definition util.c:160
talloc_free(reap)
unsigned short uint16_t
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_OCTETS
Raw octets.
long int ssize_t
unsigned int mode_t
long long int off_t
unsigned long int size_t
int fr_blocking(UNUSED int fd)
Definition misc.c:299
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
exfile_t * module_rlm_exfile_init(TALLOC_CTX *ctx, CONF_SECTION *module, uint32_t max_entries, fr_time_delta_t max_idle, bool locking, bool triggers, char const *trigger_prefix, fr_pair_list_t *trigger_args)
Initialise a module specific exfile handle.
Definition module_rlm.c:103
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:246
fr_pool_t * module_rlm_connection_pool_init(CONF_SECTION *module, void *opaque, fr_pool_connection_create_t c, fr_pool_connection_alive_t a, char const *log_prefix, char const *trigger_prefix, fr_pair_list_t *trigger_args)
Initialise a module specific connection pool.
Definition module_rlm.c:297
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
int fr_perm_gid_from_str(TALLOC_CTX *ctx, gid_t *out, char const *name)
Resolve a group name to a GID.
Definition perm.c:473
void fr_pool_connection_release(fr_pool_t *pool, request_t *request, void *conn)
Release a connection.
Definition pool.c:1405
void fr_pool_free(fr_pool_t *pool)
Delete a connection pool.
Definition pool.c:1327
fr_pool_state_t const * fr_pool_state(fr_pool_t *pool)
Get the number of connections currently in the pool.
Definition pool.c:1171
void * fr_pool_connection_get(fr_pool_t *pool, request_t *request)
Reserve a connection in the connection pool.
Definition pool.c:1390
void * fr_pool_connection_reconnect(fr_pool_t *pool, request_t *request, void *conn)
Reconnect a suspected inviable connection.
Definition pool.c:1498
A connection pool.
Definition pool.c:85
uint32_t num
Number of connections in the pool.
Definition pool.h:67
char * fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
Escape string that may contain binary data, and write it to a new buffer.
Definition print.c:428
static const conf_parser_t config[]
Definition base.c:186
#define fr_assert(_expr)
Definition rad_assert.h:38
static bool done
Definition radclient.c:81
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define DEBUG2(fmt,...)
Definition radclient.h:43
static rs_t * conf
Definition radsniff.c:53
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:57
#define RETURN_UNLANG_FAIL
Definition rcode.h:59
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:45
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:44
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:50
#define RETURN_UNLANG_NOOP
Definition rcode.h:65
fr_dict_attr_t const * request_attr_request
Definition request.c:43
static int mod_detach(module_detach_ctx_t const *mctx)
static int call_env_filename_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
module_rlm_t rlm_linelog
tmpl_t * log_src
Source of log messages.
static const conf_parser_t file_config[]
static const call_env_method_t linelog_xlat_method_env
static unlang_action_t mod_do_linelog_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
#define LINELOG_BOX_ESCAPE
linelog_net_t tcp
TCP server.
linelog_net_t udp
UDP server.
static unlang_action_t mod_do_linelog(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Write a linelog message.
static const conf_parser_t syslog_config[]
fr_ipaddr_t src_ipaddr
Send requests from a given src_ipaddr.
Definition rlm_linelog.c:96
size_t delimiter_len
Length of line termination string.
static xlat_action_t linelog_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
static int _mod_conn_free(linelog_conn_t *conn)
bool triggers
Do we do triggers.
static int mod_bootstrap(module_inst_ctx_t const *mctx)
fr_value_box_list_t expanded
The result of expanding the fmt tmpl.
#define VECTOR_INCREMENT
fr_ipaddr_t dst_ipaddr
Network server.
Definition rlm_linelog.c:95
static const conf_parser_t udp_config[]
static void linelog_hexdump(request_t *request, struct iovec *vector_p, size_t vector_len, char const *msg)
fr_pool_t * pool
Connection pool instance.
static int linelog_write(rlm_linelog_t const *inst, linelog_call_env_t const *call_env, request_t *request, struct iovec *vector_p, size_t vector_len, bool with_delim)
fr_time_delta_t timeout
How long to wait for read/write operations.
Definition rlm_linelog.c:98
int sockfd
File descriptor associated with socket.
linefr_log_dst_t
Definition rlm_linelog.c:69
@ LINELOG_DST_FILE
Log to a file.
Definition rlm_linelog.c:71
@ LINELOG_DST_STDERR
Log to stderr.
Definition rlm_linelog.c:78
@ LINELOG_DST_UNIX
Log via Unix socket.
Definition rlm_linelog.c:74
@ LINELOG_DST_STDOUT
Log to stdout.
Definition rlm_linelog.c:77
@ LINELOG_DST_TCP
Log via TCP.
Definition rlm_linelog.c:76
@ LINELOG_DST_INVALID
Definition rlm_linelog.c:70
@ LINELOG_DST_REQUEST
Log to the request->log.
Definition rlm_linelog.c:72
@ LINELOG_DST_UDP
Log via UDP.
Definition rlm_linelog.c:75
@ LINELOG_DST_SYSLOG
Log to syslog.
Definition rlm_linelog.c:73
fr_value_box_t * log_head
Header to add to each new log file.
static void * mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout)
uint16_t port
Network port.
Definition rlm_linelog.c:97
static fr_table_num_sorted_t const linefr_log_dst_table[]
Definition rlm_linelog.c:81
static const call_env_method_t linelog_method_env
CONF_SECTION * cs
CONF_SECTION to use as the root for #log_ref lookups.
static const conf_parser_t module_config[]
static int linelog_escape_func(fr_value_box_t *vb, UNUSED void *uctx)
Escape unprintable characters.
fr_value_box_t * log_ref
Path to a CONF_PAIR (to use as the source of log messages).
static const conf_parser_t unix_config[]
fr_value_box_t * filename
File name, if output is to a file.
static size_t linefr_log_dst_table_len
Definition rlm_linelog.c:92
static int mod_instantiate(module_inst_ctx_t const *mctx)
char const * delimiter
Line termination string (usually ).
bool with_delim
Whether to add a delimiter.
static const conf_parser_t tcp_config[]
linefr_log_dst_t log_dst
Logging destination.
char const * log_dst_str
Logging destination string.
linelog module instance
#define FR_SBUFF_IN(_start, _len_or_end)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
char const * name
Instance name e.g. user_database.
Definition module.h:355
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:291
void * boot
Data allocated during the boostrap phase.
Definition module.h:294
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
Named methods exported by a module.
Definition module.h:174
tmpl_escape_t escape
How escaping should be handled during evaluation.
Definition tmpl.h:349
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
Definition tmpl.h:347
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
static fr_slen_t vpt
Definition tmpl.h:1269
tmpl_t * tmpl_init_shallow(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len, tmpl_rules_t const *t_rules))
Initialise a tmpl without copying the input name string.
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:41
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
int fr_socket_client_udp(char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, bool async)
Establish a connected UDP socket.
Definition socket.c:640
int fr_socket_client_tcp(char const *ifname, fr_ipaddr_t *src_ipaddr, fr_ipaddr_t const *dst_ipaddr, uint16_t dst_port, bool async)
Establish a connected TCP socket.
Definition socket.c:735
int fr_socket_wait_for_connect(int sockfd, fr_time_delta_t timeout)
Wait for a socket to be connected, with an optional timeout.
Definition socket.c:809
int fr_socket_client_unix(UNUSED char const *path, UNUSED bool async)
Definition socket.c:570
unlang_action_t unlang_module_yield_to_tmpl(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt, unlang_tmpl_args_t *args, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Push a pre-compiled tmpl and resumption state onto the stack for evaluation.
Definition module.c:216
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
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
#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
#define talloc_get_type_abort_const
Definition talloc.h:287
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:294
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
#define fr_time_delta_ispos(_a)
Definition time.h:290
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
void tmpl_dcursor_clear(tmpl_dcursor_ctx_t *cc)
Clear any temporary state allocations.
#define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt)
Maintains state between cursor calls.
fr_value_box_escape_t box_escape
How to escape when returned from evaluation.
Definition tmpl_escape.h:81
@ TMPL_ESCAPE_PRE_CONCAT
Pre-concatenation escaping is useful for DSLs where elements of the expansion are static,...
Definition tmpl_escape.h:61
tmpl_escape_mode_t mode
Whether to apply escape function after concatenation, i.e.
Definition tmpl_escape.h:83
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
close(uq->fd)
uint8_t required
Argument must be present, and non-empty.
Definition xlat.h:146
#define XLAT_ARGS(_list,...)
Populate local variables with value boxes from the input list.
Definition xlat.h:383
#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_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
Definition for a single argument consumend by an xlat function.
Definition xlat.h:145
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
Definition value.c:612
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
Convert one type of fr_value_box_t to another in place.
Definition value.c:3976
void fr_value_box_strdup_shallow_replace(fr_value_box_t *vb, char const *src, ssize_t len)
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a new one.
Definition value.c:4493
void fr_value_box_strdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Assign a buffer containing a nul terminated string to a box, but don't copy it.
Definition value.c:4477
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:643
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
#define fr_box_ipaddr(_val)
Definition value.h:316
#define fr_value_box_init_null(_vb)
Initialise an empty/null box that will be filled later.
Definition value.h:615
fr_value_box_safe_for_t safe_for
Definition value.h:677
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:162
int nonnull(2, 5))
fr_value_box_escape_func_t func
Definition value.h:676
#define fr_value_box_list_foreach(_list_head, _iter)
Definition value.h:224
static size_t char ** out
Definition value.h:1023
#define FR_VALUE_BOX_SAFE_FOR_ANY
Definition value.h:173
void * env_data
Expanded call env data.
Definition xlat_ctx.h:53
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition xlat_ctx.h:52
An xlat calling ctx.
Definition xlat_ctx.h:49
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:363
void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env_method)
Register call environment of an xlat.
Definition xlat_func.c:389