]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add and document "log = ..." in a virtual server.
authorAlan T. DeKok <aland@freeradius.org>
Sat, 23 Nov 2024 17:31:51 +0000 (12:31 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 23 Nov 2024 17:31:51 +0000 (12:31 -0500)
so each virtual server can add a diffeent logging destination
for all requests which get processed through it

raddb/sites-available/default
src/lib/server/log.c
src/lib/server/virtual_servers.c

index de8d3aa2967bef894f33b7bdae92bc7122c9e793..72f890c1b22081133a2634444957e4fb80a89a36 100644 (file)
@@ -62,7 +62,7 @@
 #
 server default {
        #
-       #  namespace::
+       #  namespace:: The protocol namespace (i.e. dictionary) to use.
        #
        #  In v4, all "server" sections MUST start with a "namespace"
        #  parameter.  This tells the server which protocol is being used.
@@ -72,6 +72,23 @@ server default {
        #
        namespace = radius
 
+       #
+       #  log:: The name of the logging section to use.
+       #
+       #  The top configuration section can contain multiple section "log foo { ... }".
+       #  Each of those sections is a different named logging destination.
+       #
+       #  This configuration item allows setting a different logging destination for an
+       #  individual virtual server.
+       #
+       #  There are some limitations.
+       #
+       #  * this logging is in _addition_ to the default logging to "log { .... }".
+       #  * it is not currently possible to _replace_ the default logging destination
+       #  * the name given here _must_ be a fixed string, and is not dynamically expanded.
+       #
+#      log = some_other_logging_destination
+
        #
        #  ### RADIUS Configuration
        #
index 92f932c307fd62f20b6ee3394bb5ef483b6741e3..520be9d127d0ef2f097b486752105788dd41418c 100644 (file)
@@ -1063,6 +1063,8 @@ static void log_register_dst(char const *name, fr_log_t *log, CONF_SECTION *cs)
 
        if (log->dst != L_DST_FILES) return;
 
+       fr_assert(log->file != NULL);
+
        fr_rb_insert(filename_tree, dst);
 }
 
@@ -1134,7 +1136,7 @@ int log_parse_section(CONF_SECTION *cs)
        char const *name;
 
        name = cf_section_name2(cs);
-       if (!name) name = cf_section_name1(cs);
+       if (!name) name = "DEFAULT";
 
        dst = fr_rb_find(dst_tree, &(fr_log_track_t) {
                        .name = name,
index 2428d95735e41c27c91c248bb509377e8f1c63e7..d9cd20ea493758810dc978672501616de3375ed9 100644 (file)
@@ -62,6 +62,9 @@ struct virtual_server_s {
                                                                ///< cached for convenience.
 
        fr_rb_tree_t                    *sections;              //!< List of sections that need to be compiled.
+
+       fr_log_t                        *log;                   //!< log destination
+       char const                      *log_name;              //!< name of log destination
 };
 
 static fr_dict_t const *dict_freeradius;
@@ -146,6 +149,8 @@ static const conf_parser_t server_config[] = {
                         .subcs_size = sizeof(fr_virtual_listen_t), .subcs_type = "fr_virtual_listen_t",
                         .func = listen_parse },
 
+       { FR_CONF_OFFSET("log", virtual_server_t, log_name), },
+
        CONF_PARSER_TERMINATOR
 };
 
@@ -680,6 +685,11 @@ unlang_action_t virtual_server_push(request_t *request, CONF_SECTION *server_cs,
                return UNLANG_ACTION_FAIL;
        }
 
+       /*
+        *      Log here, too.
+        */
+       if (server->log) request_log_prepend(request, server->log, fr_debug_lvl);
+
        /*
         *      Bootstrap the stack with a module instance.
         */
@@ -1512,10 +1522,28 @@ int virtual_servers_instantiate(void)
                CONF_ITEM                       *ci = NULL;
                CONF_SECTION                    *server_cs = virtual_servers[i]->server_cs;
                fr_dict_t const                 *dict;
-               virtual_server_t const          *vs = virtual_servers[i];
+               virtual_server_t                *vs = virtual_servers[i];
                fr_process_module_t const       *process = (fr_process_module_t const *)
                                                            vs->process_mi->module->exported;
 
+               /*
+                *      Set up logging before doing anything else.
+                */
+               if (vs->log_name) {
+                       vs->log = log_dst_by_name(vs->log_name);
+                       if (!vs->log) {
+                               CONF_PAIR *cp = cf_pair_find(server_cs, "log");
+
+                               if (cp) {
+                                       cf_log_err(cp, "Unknown log destination '%s'", vs->log_name);
+                               } else {
+                                       cf_log_err(server_cs, "Unknown log destination '%s'", vs->log_name);
+                               }
+
+                               return -1;
+                       }
+               }
+
                dict = virtual_server_local_dict(server_cs, *(process)->dict);
                if (!dict) return -1;