#include <freeradius-devel/ident.h>
RCSID("$Id$")
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/modules.h>
typedef struct rlm_always_t {
char *rcode_str;
int rcode;
int simulcount;
int mpp;
} rlm_always_t;
static const CONF_PARSER module_config[] = {
{ "rcode", PW_TYPE_STRING_PTR, offsetof(rlm_always_t,rcode_str),
NULL, "fail" },
{ "simulcount", PW_TYPE_INTEGER, offsetof(rlm_always_t,simulcount),
NULL, "0" },
{ "mpp", PW_TYPE_BOOLEAN, offsetof(rlm_always_t,mpp),
NULL, "no" },
{ NULL, -1, 0, NULL, NULL }
};
static int str2rcode(const char *s)
{
if(!strcasecmp(s, "reject"))
return RLM_MODULE_REJECT;
else if(!strcasecmp(s, "fail"))
return RLM_MODULE_FAIL;
else if(!strcasecmp(s, "ok"))
return RLM_MODULE_OK;
else if(!strcasecmp(s, "handled"))
return RLM_MODULE_HANDLED;
else if(!strcasecmp(s, "invalid"))
return RLM_MODULE_INVALID;
else if(!strcasecmp(s, "userlock"))
return RLM_MODULE_USERLOCK;
else if(!strcasecmp(s, "notfound"))
return RLM_MODULE_NOTFOUND;
else if(!strcasecmp(s, "noop"))
return RLM_MODULE_NOOP;
else if(!strcasecmp(s, "updated"))
return RLM_MODULE_UPDATED;
else {
radlog(L_ERR|L_CONS,
"rlm_always: Unknown module rcode '%s'.\n", s);
return -1;
}
}
static int always_instantiate(CONF_SECTION *conf, void **instance)
{
rlm_always_t *data;
data = rad_malloc(sizeof(*data));
if (!data) {
return -1;
}
memset(data, 0, sizeof(*data));
if (cf_section_parse(conf, data, module_config) < 0) {
free(data);
return -1;
}
data->rcode = str2rcode(data->rcode_str);
if (data->rcode == -1) {
free(data);
return -1;
}
*instance = data;
return 0;
}
static int always_return(void *instance, REQUEST *request)
{
request = request;
return ((struct rlm_always_t *)instance)->rcode;
}
static int always_checksimul(void *instance, REQUEST *request)
{
struct rlm_always_t *inst = instance;
request->simul_count = inst->simulcount;
if (inst->mpp)
request->simul_mpp = 2;
return inst->rcode;
}
static int always_detach(void *instance)
{
free(instance);
return 0;
}
module_t rlm_always = {
RLM_MODULE_INIT,
"always",
RLM_TYPE_CHECK_CONFIG_SAFE,
always_instantiate,
always_detach,
{
always_return,
always_return,
always_return,
always_return,
always_checksimul,
always_return,
always_return,
always_return
#ifdef WITH_COA
,
always_return,
always_return
#endif
},
};