4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 * Copyright 2006 Suntel Communications - www.suntel.com.tr
19 * Copyright 2006 The FreeRADIUS server project
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/autoconf.h>
33 #include <freeradius-devel/radiusd.h>
34 #include <freeradius-devel/modules.h>
35 #include <freeradius-devel/conffile.h>
37 typedef struct rlm_acctlog_t {
46 static const CONF_PARSER module_config[] = {
47 { "acctlog_update", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctupdate), NULL, ""},
48 { "acctlog_start", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctstart), NULL, ""},
49 { "acctlog_stop", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctstop), NULL, ""},
50 { "acctlog_on", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, accton), NULL, ""},
51 { "acctlog_off", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctoff), NULL, ""},
52 { NULL, -1, 0, NULL, NULL } /* end the list */
56 static int acctlog_detach(void *instance)
58 rlm_acctlog_t *inst = instance;
65 static int acctlog_instantiate(CONF_SECTION *conf, void **instance)
69 inst = rad_malloc(sizeof(*inst));
70 memset(inst, 0, sizeof(*inst));
72 if (cf_section_parse(conf, inst, module_config) < 0) {
83 static int do_acctlog_acct(void *instance, REQUEST *request)
88 char logstr[MAX_STRING_LEN];
89 int acctstatustype = 0;
92 inst = (rlm_acctlog_t*) instance;
94 if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL) {
95 acctstatustype = pair->lvalue;
97 radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
98 radlog(L_ERR, "rlm_acctlog (%s)", logstr);
99 return RLM_MODULE_INVALID;
102 switch (acctstatustype) {
103 case PW_STATUS_START:
104 radius_xlat(logstr, sizeof(logstr), inst->acctstart, request, NULL);
107 radius_xlat(logstr, sizeof(logstr), inst->acctstop, request, NULL);
109 case PW_STATUS_ALIVE:
110 radius_xlat(logstr, sizeof(logstr), inst->acctupdate, request, NULL);
112 case PW_STATUS_ACCOUNTING_ON:
113 radius_xlat(logstr, sizeof(logstr), inst->accton, request, NULL);
115 case PW_STATUS_ACCOUNTING_OFF:
116 radius_xlat(logstr, sizeof(logstr), inst->acctoff, request, NULL);
122 radlog(L_ACCT,"%s", logstr);
124 return RLM_MODULE_OK;
128 * Externally visible module definition.
130 module_t rlm_acctlog = {
133 RLM_TYPE_THREAD_SAFE, /* type */
134 acctlog_instantiate, /* instantiation */
135 acctlog_detach, /* detach */
137 NULL, /* authentication */
138 NULL, /* authorization */
139 NULL, /* preaccounting */
140 do_acctlog_acct, /* accounting */
141 NULL, /* checksimul */
142 NULL, /* pre-proxy */
143 NULL, /* post-proxy */