From: Matthew Newton Date: Mon, 6 Feb 2012 15:07:32 +0000 (+0100) Subject: Add "syslog_facility" to rlm_linelog X-Git-Tag: release_2_2_0~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b4295e92d454940525f445c55f172dbaf762169;p=thirdparty%2Ffreeradius-server.git Add "syslog_facility" to rlm_linelog Document it. Export the facility name to integer table from mainconfig.c --- diff --git a/raddb/modules/linelog b/raddb/modules/linelog index 10f4697e79e..a57741ac3fa 100644 --- a/raddb/modules/linelog +++ b/raddb/modules/linelog @@ -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}" diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 4bd6142dc18..de225776bae 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -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); diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index 12575550111..e86175d6d83 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -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 }