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 2000,2006 The FreeRADIUS server project
21 #include <freeradius-devel/ident.h>
24 #include <freeradius-devel/radiusd.h>
25 #include <freeradius-devel/modules.h>
28 * The instance data for rlm_always is the list of fake values we are
31 typedef struct rlm_always_t {
39 * A mapping of configuration file names to internal variables.
41 * Note that the string is dynamically allocated, so it MUST
42 * be freed. When the configuration file parse re-reads the string,
43 * it free's the old one, and strdup's the new one, placing the pointer
44 * to the strdup'd string into 'config.string'. This gets around
47 static const CONF_PARSER module_config[] = {
48 { "rcode", PW_TYPE_STRING_PTR, offsetof(rlm_always_t,rcode_str),
50 { "simulcount", PW_TYPE_INTEGER, offsetof(rlm_always_t,simulcount),
52 { "mpp", PW_TYPE_BOOLEAN, offsetof(rlm_always_t,mpp),
55 { NULL, -1, 0, NULL, NULL } /* end the list */
58 static int str2rcode(const char *s)
60 if(!strcasecmp(s, "reject"))
61 return RLM_MODULE_REJECT;
62 else if(!strcasecmp(s, "fail"))
63 return RLM_MODULE_FAIL;
64 else if(!strcasecmp(s, "ok"))
66 else if(!strcasecmp(s, "handled"))
67 return RLM_MODULE_HANDLED;
68 else if(!strcasecmp(s, "invalid"))
69 return RLM_MODULE_INVALID;
70 else if(!strcasecmp(s, "userlock"))
71 return RLM_MODULE_USERLOCK;
72 else if(!strcasecmp(s, "notfound"))
73 return RLM_MODULE_NOTFOUND;
74 else if(!strcasecmp(s, "noop"))
75 return RLM_MODULE_NOOP;
76 else if(!strcasecmp(s, "updated"))
77 return RLM_MODULE_UPDATED;
80 "rlm_always: Unknown module rcode '%s'.\n", s);
85 static int always_instantiate(CONF_SECTION *conf, void **instance)
90 * Set up a storage area for instance data
92 data = rad_malloc(sizeof(*data));
96 memset(data, 0, sizeof(*data));
99 * If the configuration parameters can't be parsed, then
102 if (cf_section_parse(conf, data, module_config) < 0) {
108 * Convert the rcode string to an int, and get rid of it
110 data->rcode = str2rcode(data->rcode_str);
111 if (data->rcode == -1) {
122 * Just return the rcode ... this function is autz, auth, acct, and
125 static int always_return(void *instance, REQUEST *request)
127 /* quiet the compiler */
130 return ((struct rlm_always_t *)instance)->rcode;
133 #ifdef WITH_SESSION_MGMT
135 * checksimul fakes some other variables besides the rcode...
137 static int always_checksimul(void *instance, REQUEST *request)
139 struct rlm_always_t *inst = instance;
141 request->simul_count = inst->simulcount;
144 request->simul_mpp = 2;
150 static int always_detach(void *instance)
156 module_t rlm_always = {
159 RLM_TYPE_CHECK_CONFIG_SAFE, /* type */
160 always_instantiate, /* instantiation */
161 always_detach, /* detach */
163 always_return, /* authentication */
164 always_return, /* authorization */
165 always_return, /* preaccounting */
166 always_return, /* accounting */
167 #ifdef WITH_SESSION_MGMT
168 always_checksimul, /* checksimul */
172 always_return, /* pre-proxy */
173 always_return, /* post-proxy */
174 always_return /* post-auth */
177 always_return, /* recv-coa */
178 always_return /* send-coa */