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/radiusd.h>
29 #include <freeradius-devel/modules.h>
31 typedef struct rlm_acctlog_t {
40 static const CONF_PARSER module_config[] = {
41 { "acctlog_update", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctupdate), NULL, ""},
42 { "acctlog_start", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctstart), NULL, ""},
43 { "acctlog_stop", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctstop), NULL, ""},
44 { "acctlog_on", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, accton), NULL, ""},
45 { "acctlog_off", PW_TYPE_STRING_PTR, offsetof(rlm_acctlog_t, acctoff), NULL, ""},
46 { NULL, -1, 0, NULL, NULL } /* end the list */
50 static int acctlog_detach(void *instance)
52 rlm_acctlog_t *inst = instance;
59 static int acctlog_instantiate(CONF_SECTION *conf, void **instance)
63 inst = rad_malloc(sizeof(*inst));
64 memset(inst, 0, sizeof(*inst));
66 if (cf_section_parse(conf, inst, module_config) < 0) {
77 static int do_acctlog_acct(void *instance, REQUEST *request)
82 char logstr[MAX_STRING_LEN];
83 int acctstatustype = 0;
86 inst = (rlm_acctlog_t*) instance;
88 if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL) {
89 acctstatustype = pair->vp_integer;
91 radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
92 radlog(L_ERR, "rlm_acctlog (%s)", logstr);
93 return RLM_MODULE_INVALID;
96 switch (acctstatustype) {
98 radius_xlat(logstr, sizeof(logstr), inst->acctstart, request, NULL);
101 radius_xlat(logstr, sizeof(logstr), inst->acctstop, request, NULL);
103 case PW_STATUS_ALIVE:
104 radius_xlat(logstr, sizeof(logstr), inst->acctupdate, request, NULL);
106 case PW_STATUS_ACCOUNTING_ON:
107 radius_xlat(logstr, sizeof(logstr), inst->accton, request, NULL);
109 case PW_STATUS_ACCOUNTING_OFF:
110 radius_xlat(logstr, sizeof(logstr), inst->acctoff, request, NULL);
116 radlog(L_ACCT,"%s", logstr);
118 return RLM_MODULE_OK;
122 * Externally visible module definition.
124 module_t rlm_acctlog = {
127 RLM_TYPE_THREAD_SAFE, /* type */
128 acctlog_instantiate, /* instantiation */
129 acctlog_detach, /* detach */
131 NULL, /* authentication */
132 NULL, /* authorization */
133 NULL, /* preaccounting */
134 do_acctlog_acct, /* accounting */
135 NULL, /* checksimul */
136 NULL, /* pre-proxy */
137 NULL, /* post-proxy */