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 10f4697..a57741a 100644 (file)
@@ -34,6 +34,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 4bd6142..de22577 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 1257555..e86175d 100644 (file)
@@ -48,11 +48,18 @@ RCSID("$Id$")
 #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
        }