]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "request" destination for linelog
authorAlan T. DeKok <aland@freeradius.org>
Sun, 8 Oct 2023 16:37:26 +0000 (12:37 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 8 Oct 2023 16:37:26 +0000 (12:37 -0400)
so that it can log to the normal request log

doc/antora/modules/raddb/pages/mods-available/linelog.adoc
raddb/mods-available/linelog
src/modules/rlm_linelog/rlm_linelog.c

index e5331c86651e248787c66596624336a359fda2cd..99264c5918f5232f3c042e5c8a1cf58ecb26b557 100644 (file)
@@ -86,15 +86,22 @@ May be one of:
 
 [options="header,autowidth"]
 |===
-| Option | Description
-| file   | Write to a file.
-| syslog | Send via the system's syslog() function.
-| file   | Write to a file - NYI.
-| tcp    | Write to a TCP socket.
-| udp    | Write to a UDP socket.
-| unix   | Write to a UNIX socket.
+| Option  | Description
+| file    | Write to a file.
+| request | Write to the logging destination of the current request
+| stdout  | Write to stdout
+| stderr  | Write to stderr
+| syslog  | Send via the system's syslog() function.
+| tcp     | Write to a TCP socket.
+| udp     | Write to a UDP socket.
+| unix    | Write to a UNIX socket.
 |===
 
+The `stdout` and `stderr` destinations are likely to work only when
+the server is running in debug mode.  When the server is running in
+background mode, both `stdout` and `stderr` are usually redirected
+to `/dev/null`.
+
 
 
 .File as the destination for log messages.
@@ -349,7 +356,7 @@ Don't log anything for other `link:https://freeradius.org/rfc/rfc2866.html#Acct-
 linelog {
 #      delimiter = "\n"
        format = "This is a log message for %{User-Name}"
-       reference = "messages.%{&reply.Packet-Type || default}"
+       reference = "messages.%{&reply.Packet-Type || 'default'}"
        messages {
                default = "Unknown packet type %{Packet-Type}"
                Access-Accept = "Sent accept: %{User-Name}"
@@ -402,7 +409,7 @@ linelog log_accounting {
                filename = ${logdir}/linelog-accounting
                permissions = 0600
        }
-       reference = "Accounting-Request.%{&Acct-Status-Type || unknown}"
+       reference = "Accounting-Request.%{&Acct-Status-Type || 'unknown'}"
        Accounting-Request {
                Start = "Connect: [%{User-Name}] (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} ip %{Framed-IP-Address})"
                Stop = "Disconnect: [%{User-Name}] (did %{Called-Station-Id} cli %{Calling-Station-Id} port %{NAS-Port} ip %{Framed-IP-Address}) %{Acct-Session-Time} seconds"
index 1a3866637a6e8e27d8e2e1656f924eef321c9c35..cbf7ad33976e700f20d45142abdd0868cf24e1a1 100644 (file)
@@ -100,14 +100,22 @@ linelog {
        #
        #  [options="header,autowidth"]
        #  |===
-       #  | Option | Description
-       #  | file   | Write to a file.
-       #  | syslog | Send via the system's syslog() function.
-       #  | tcp    | Write to a TCP socket.
-       #  | udp    | Write to a UDP socket.
-       #  | unix   | Write to a UNIX socket.
+       #  | Option  | Description
+       #  | file    | Write to a file.
+       #  | request | Write to the logging destination of the current request
+       #  | stdout  | Write to stdout
+       #  | stderr  | Write to stderr
+       #  | syslog  | Send via the system's syslog() function.
+       #  | tcp     | Write to a TCP socket.
+       #  | udp     | Write to a UDP socket.
+       #  | unix    | Write to a UNIX socket.
        #  |===
        #
+       #  The `stdout` and `stderr` destinations are likely to work only when
+       #  the server is running in debug mode.  When the server is running in
+       #  background mode, both `stdout` and `stderr` are usually redirected
+       #  to `/dev/null`.
+       #
        destination = file
 
        #
index 2d67774a67d0cf9983302ba01600b8593d95848b..87db6556a83bd5d70b6e1097834d70d1bb236eda 100644 (file)
@@ -57,6 +57,7 @@ RCSID("$Id$")
 typedef enum {
        LINELOG_DST_INVALID = 0,
        LINELOG_DST_FILE,                               //!< Log to a file.
+       LINELOG_DST_REQUEST,                            //!< Log to the request->log
        LINELOG_DST_SYSLOG,                             //!< Log to syslog.
        LINELOG_DST_UNIX,                               //!< Log via Unix socket.
        LINELOG_DST_UDP,                                //!< Log via UDP.
@@ -67,6 +68,7 @@ typedef enum {
 
 static fr_table_num_sorted_t const linefr_log_dst_table[] = {
        { L("file"),    LINELOG_DST_FILE        },
+       { L("request"), LINELOG_DST_REQUEST     },
        { L("stderr"),  LINELOG_DST_STDERR      },
        { L("stdout"),  LINELOG_DST_STDOUT      },
        { L("syslog"),  LINELOG_DST_SYSLOG      },
@@ -245,6 +247,7 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t ti
         */
        case LINELOG_DST_INVALID:
        case LINELOG_DST_FILE:
+       case LINELOG_DST_REQUEST:
        case LINELOG_DST_SYSLOG:
        case LINELOG_DST_STDOUT:
        case LINELOG_DST_STDERR:
@@ -423,6 +426,18 @@ static int linelog_write(rlm_linelog_t const *inst, request_t *request, struct i
        }
                break;
 
+       case LINELOG_DST_REQUEST:
+       {
+               size_t i;
+
+               ret = 0;
+               for (i = 0; i < vector_len; i++) {
+                       RINFO("%.*s", (int)vector_p[i].iov_len, (char *)vector_p[i].iov_base);
+                       ret += vector_p[i].iov_len;
+               }
+       }
+               break;
+
        case LINELOG_DST_UNIX:
                if (fr_time_delta_ispos(inst->unix_sock.timeout)) {
                        timeout = inst->unix_sock.timeout;