From: Matthew Newton Date: Wed, 11 Jan 2012 12:29:02 +0000 (+0000) Subject: Add new 'group' option to rlm_linelog X-Git-Tag: release_3_0_0_beta0~398 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=freeradius.git;a=commitdiff_plain;h=b7c04b5c9dd699122ba80bc8d29863ab9e4b1c23 Add new 'group' option to rlm_linelog Allows the group to be set when updating linelogs, rather than being fixed as the group of the running daemon. --- diff --git a/raddb/mods-available/linelog b/raddb/mods-available/linelog index 2be4d81..10f4697 100644 --- a/raddb/mods-available/linelog +++ b/raddb/mods-available/linelog @@ -26,6 +26,14 @@ linelog { permissions = 0600 # + # The Unix group of the log file. + # + # The user that freeradius runs as must be in the specified + # group, otherwise it will not be possible to set the group. + # + # group = freerad + + # # The default format string. format = "This is a log message for %{User-Name}" diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index 24c809f..6773978 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -31,6 +31,14 @@ RCSID("$Id$") #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_GRP_H +#include +#endif + #ifdef HAVE_SYSLOG_H #include @@ -46,6 +54,7 @@ typedef struct rlm_linelog_t { CONF_SECTION *cs; char *filename; int permissions; + char *group; char *line; char *reference; } rlm_linelog_t; @@ -64,6 +73,8 @@ static const CONF_PARSER module_config[] = { offsetof(rlm_linelog_t,filename), NULL, NULL}, { "permissions", PW_TYPE_INTEGER, offsetof(rlm_linelog_t,permissions), NULL, "0600"}, + { "group", PW_TYPE_STRING_PTR, + offsetof(rlm_linelog_t,group), NULL, NULL}, { "format", PW_TYPE_STRING_PTR, offsetof(rlm_linelog_t,line), NULL, NULL}, { "reference", PW_TYPE_STRING_PTR, @@ -199,6 +210,12 @@ static int do_linelog(void *instance, REQUEST *request) rlm_linelog_t *inst = (rlm_linelog_t*) instance; const char *value = inst->line; +#ifdef HAVE_GRP_H + gid_t gid; + struct group *grp; + char *endptr; +#endif + if (inst->reference) { CONF_ITEM *ci; CONF_PAIR *cp; @@ -263,6 +280,25 @@ static int do_linelog(void *instance, REQUEST *request) } } +#ifdef HAVE_GRP_H + if (inst->group != NULL) { + gid = strtol(inst->group, &endptr, 10); + if (*endptr != '\0') { + grp = getgrnam(inst->group); + if (grp == NULL) { + RDEBUG2("Unable to find system group \"%s\"", inst->group); + goto skip_group; + } + gid = grp->gr_gid; + } + + if (chown(buffer, -1, gid) == -1) { + RDEBUG2("Unable to change system group of \"%s\"", buffer); + } + } +#endif + + skip_group: /* * FIXME: Check length. */