4 * This program is is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 if the
6 * License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * Copyright 2000 The FreeRADIUS server project
21 #include "libradius.h"
31 static const char rcsid[] = "$Id$";
34 * The instance data for rlm_always is the list of fake values we are
37 typedef struct rlm_always_t {
45 * A mapping of configuration file names to internal variables.
47 * Note that the string is dynamically allocated, so it MUST
48 * be freed. When the configuration file parse re-reads the string,
49 * it free's the old one, and strdup's the new one, placing the pointer
50 * to the strdup'd string into 'config.string'. This gets around
53 static CONF_PARSER module_config[] = {
54 { "rcode", PW_TYPE_STRING_PTR, offsetof(rlm_always_t,rcode_str),
56 { "simulcount", PW_TYPE_INTEGER, offsetof(rlm_always_t,simulcount),
58 { "mpp", PW_TYPE_BOOLEAN, offsetof(rlm_always_t,mpp),
61 { NULL, -1, 0, NULL, NULL } /* end the list */
64 static int str2rcode(const char *s)
66 if(!strcasecmp(s, "reject"))
67 return RLM_MODULE_REJECT;
68 else if(!strcasecmp(s, "fail"))
69 return RLM_MODULE_FAIL;
70 else if(!strcasecmp(s, "ok"))
72 else if(!strcasecmp(s, "handled"))
73 return RLM_MODULE_HANDLED;
74 else if(!strcasecmp(s, "invalid"))
75 return RLM_MODULE_INVALID;
76 else if(!strcasecmp(s, "userlock"))
77 return RLM_MODULE_USERLOCK;
78 else if(!strcasecmp(s, "notfound"))
79 return RLM_MODULE_NOTFOUND;
80 else if(!strcasecmp(s, "noop"))
81 return RLM_MODULE_NOOP;
82 else if(!strcasecmp(s, "updated"))
83 return RLM_MODULE_UPDATED;
86 "rlm_always: Unknown module rcode '%s'.\n", s);
91 static int always_instantiate(CONF_SECTION *conf, void **instance)
96 * Set up a storage area for instance data
98 data = rad_malloc(sizeof(*data));
101 * If the configuration parameters can't be parsed, then
104 if (cf_section_parse(conf, data, module_config) < 0) {
110 * Convert the rcode string to an int, and get rid of it
112 data->rcode = str2rcode(data->rcode_str);
113 free(data->rcode_str);
114 if (data->rcode == -1) {
125 * Just return the rcode ... this function is autz, auth, acct, and
128 static int always_return(void *instance, REQUEST *request)
130 /* quiet the compiler */
133 return ((struct rlm_always_t *)instance)->rcode;
137 * checksimul fakes some other variables besides the rcode...
139 static int always_checksimul(void *instance, REQUEST *request)
141 struct rlm_always_t *inst = instance;
143 request->simul_count = inst->simulcount;
146 request->simul_mpp = 2;
151 static int always_detach(void *instance)
157 module_t rlm_always = {
159 RLM_TYPE_THREAD_SAFE, /* type */
160 NULL, /* initialization */
161 always_instantiate, /* instantiation */
163 always_return, /* authentication */
164 always_return, /* authorization */
165 always_return, /* preaccounting */
166 always_return, /* accounting */
167 always_checksimul, /* checksimul */
168 NULL, /* pre-proxy */
169 NULL, /* post-proxy */
172 always_detach, /* detach */