6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2004 The FreeRADIUS server project
21 * Copyright 2004 Alan DeKok <aland@freeradius.org>
24 #include <freeradius-devel/autoconf.h>
37 #include <freeradius-devel/radiusd.h>
38 #include <freeradius-devel/modules.h>
39 #include <freeradius-devel/conffile.h>
42 static const char rcsid[] = "$Id$";
45 * Define a structure for our module configuration.
47 * These variables do not need to be in a structure, but it's
48 * a lot cleaner to do so, and a pointer to the structure can
49 * be used as the instance handle.
51 typedef struct rlm_linelog_t {
57 * A mapping of configuration file names to internal variables.
59 * Note that the string is dynamically allocated, so it MUST
60 * be freed. When the configuration file parse re-reads the string,
61 * it free's the old one, and strdup's the new one, placing the pointer
62 * to the strdup'd string into 'config.string'. This gets around
65 static const CONF_PARSER module_config[] = {
66 { "filename", PW_TYPE_STRING_PTR,
67 offsetof(rlm_linelog_t,filename), NULL, NULL},
68 { "format", PW_TYPE_STRING_PTR,
69 offsetof(rlm_linelog_t,line), NULL, NULL},
70 { NULL, -1, 0, NULL, NULL } /* end the list */
74 static int linelog_detach(void *instance)
76 rlm_linelog_t *inst = instance;
78 if (inst->filename) free(inst->filename);
79 if (inst->line) free(inst->line);
86 * Instantiate the module.
88 static int linelog_instantiate(CONF_SECTION *conf, void **instance)
93 * Set up a storage area for instance data
95 inst = rad_malloc(sizeof(*inst));
96 memset(inst, 0, sizeof(*inst));
99 * If the configuration parameters can't be parsed, then
102 if (cf_section_parse(conf, inst, module_config) < 0) {
103 linelog_detach(inst);
112 static int do_linelog(void *instance, REQUEST *request)
120 inst = (rlm_linelog_t*) instance;
123 * FIXME: Check length.
125 radius_xlat(buffer, sizeof(buffer), inst->filename, request, NULL);
127 fd = open(buffer, O_WRONLY | O_APPEND | O_CREAT, 0600);
129 radlog(L_ERR, "rlm_linelog: Failed to open %s: %s",
130 buffer, strerror(errno));
131 return RLM_MODULE_FAIL;
135 * FIXME: Check length.
137 radius_xlat(line, sizeof(line) - 1, inst->line, request, NULL);
139 p = strchr(line, '\n');
140 if (!p) strcat(line, "\n");
142 write(fd, line, strlen(line));
145 return RLM_MODULE_OK;
150 * Externally visible module definition.
152 module_t rlm_linelog = {
155 RLM_TYPE_THREAD_SAFE, /* type */
156 linelog_instantiate, /* instantiation */
157 linelog_detach, /* detach */
159 do_linelog, /* authentication */
160 do_linelog, /* authorization */
161 do_linelog, /* preaccounting */
162 do_linelog, /* accounting */
163 NULL, /* checksimul */
164 do_linelog, /* pre-proxy */
165 do_linelog, /* post-proxy */
166 do_linelog /* post-auth */