]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add "syslog_facility" to rlm_linelog
authorMatthew Newton <mcn4@leicester.ac.uk>
Mon, 6 Feb 2012 15:07:32 +0000 (16:07 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 6 Feb 2012 15:07:32 +0000 (16:07 +0100)
Document it.  Export the facility name to integer table
from mainconfig.c

raddb/modules/linelog
src/main/mainconfig.c
src/modules/rlm_linelog/rlm_linelog.c

index 10f4697e79eaa2628ef1afa6e509b199fb3745cb..a57741ac3fa5f884ed64d896da3807af5d2a6b99 100644 (file)
@@ -33,6 +33,12 @@ linelog {
        #
        # group = freerad
 
+       #
+       # If logging via syslog, the facility can be set here. Otherwise
+       # the syslog_facility option in radiusd.conf will be used.
+       #
+       # syslog_facility = daemon
+
        #
        #  The default format string.
        format = "This is a log message for %{User-Name}"
index 4bd6142dc18523779c5fd3053c2ec411960e4ccc..de225776bae3d28883fba59e13ceb07d55ffb7d8 100644 (file)
@@ -97,7 +97,11 @@ static const char *my_name = NULL;
 static const char *sbindir = NULL;
 static const char *run_dir = NULL;
 static char *syslog_facility = NULL;
-static const FR_NAME_NUMBER str2fac[] = {
+
+/*
+ *     Syslog facility table.
+ */
+const FR_NAME_NUMBER syslog_str2fac[] = {
 #ifdef LOG_KERN
        { "kern", LOG_KERN },
 #endif
@@ -838,7 +842,7 @@ int read_mainconfig(int reload)
                                cf_section_free(&cs);
                                return -1;
                        }
-                       mainconfig.syslog_facility = fr_str2int(str2fac, syslog_facility, -1);
+                       mainconfig.syslog_facility = fr_str2int(syslog_str2fac, syslog_facility, -1);
                        if (mainconfig.syslog_facility < 0) {
                                fprintf(stderr, "radiusd: Error: Unknown syslog_facility %s\n",
                                        syslog_facility);
index 12575550111bef4cc5852992efd2973c8aa53a74..e86175d6d831cd259e91250b7d2dd9f9d0048e74 100644 (file)
@@ -47,12 +47,19 @@ RCSID("$Id$")
 #endif
 #endif
 
+/*
+ *     Syslog facilities from main/mainconfig.c
+ */
+extern const FR_NAME_NUMBER syslog_str2fac[];
+
 /*
  *     Define a structure for our module configuration.
  */
 typedef struct rlm_linelog_t {
        CONF_SECTION    *cs;
        char            *filename;
+       char            *syslog_facility;
+       int             facility;
        int             permissions;
        char            *group;
        char            *line;
@@ -71,6 +78,8 @@ typedef struct rlm_linelog_t {
 static const CONF_PARSER module_config[] = {
        { "filename",  PW_TYPE_STRING_PTR,
          offsetof(rlm_linelog_t,filename), NULL,  NULL},
+       { "syslog_facility",  PW_TYPE_STRING_PTR,
+         offsetof(rlm_linelog_t,syslog_facility), NULL,  NULL},
        { "permissions",  PW_TYPE_INTEGER,
          offsetof(rlm_linelog_t,permissions), NULL,  "0600"},
        { "group",  PW_TYPE_STRING_PTR,
@@ -125,6 +134,19 @@ static int linelog_instantiate(CONF_SECTION *conf, void **instance)
                linelog_detach(inst);
                return -1;
        }
+#else
+       inst->facility = 0;
+
+       if (inst->syslog_facility) {
+               inst->facility = fr_str2int(syslog_str2fac, inst->syslog_facility, -1);
+               if (inst->facility < 0) {
+                       radlog(L_ERR, "rlm_linelog: Bad syslog facility '%s'", inst->syslog_facility);
+                       linelog_detach(inst);
+                       return -1;
+               }
+       }
+
+       inst->facility |= LOG_INFO;
 #endif
 
        if (!inst->line) {
@@ -314,7 +336,7 @@ static int do_linelog(void *instance, REQUEST *request)
 
 #ifdef HAVE_SYSLOG_H
        } else {
-               syslog(LOG_INFO, "%s", line);
+               syslog(inst->facility, "%s", line);
 #endif
        }