Skip to content

Commit

Permalink
Fix Module-Return-Code expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Apr 26, 2014
1 parent 8469d70 commit 2fb40d9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
20 changes: 0 additions & 20 deletions src/include/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,6 @@ RCSIDH(modules_h, "$Id$")
extern "C" {
#endif

/** Return codes indicating the result of the module call
*
* All module functions must return one of the codes listed below (apart from
* RLM_MODULE_NUMCODES, which is used to check for validity).
*/
typedef enum rlm_rcodes {
RLM_MODULE_REJECT = 0, //!< Immediately reject the request.
RLM_MODULE_FAIL, //!< Module failed, don't reply.
RLM_MODULE_OK, //!< The module is OK, continue.
RLM_MODULE_HANDLED, //!< The module handled the request, so stop.
RLM_MODULE_INVALID, //!< The module considers the request invalid.
RLM_MODULE_USERLOCK, //!< Reject the request (user is locked out).
RLM_MODULE_NOTFOUND, //!< User not found.
RLM_MODULE_NOOP, //!< Module succeeded without doing anything.
RLM_MODULE_UPDATED, //!< OK (pairs modified).
RLM_MODULE_NUMCODES, //!< How many valid return codes there are.
RLM_MODULE_UNKNOWN //!< Error resolving rcode (should not be
//!< returned by modules).
} rlm_rcode_t;

/** The different section components of the server
*
* Used as indexes in the methods array in the module_t struct.
Expand Down
22 changes: 22 additions & 0 deletions src/include/radiusd.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ typedef enum RAD_LISTEN_TYPE {
RAD_LISTEN_MAX
} RAD_LISTEN_TYPE;

/** Return codes indicating the result of the module call
*
* All module functions must return one of the codes listed below (apart from
* RLM_MODULE_NUMCODES, which is used to check for validity).
*/
typedef enum rlm_rcodes {
RLM_MODULE_REJECT = 0, //!< Immediately reject the request.
RLM_MODULE_FAIL, //!< Module failed, don't reply.
RLM_MODULE_OK, //!< The module is OK, continue.
RLM_MODULE_HANDLED, //!< The module handled the request, so stop.
RLM_MODULE_INVALID, //!< The module considers the request invalid.
RLM_MODULE_USERLOCK, //!< Reject the request (user is locked out).
RLM_MODULE_NOTFOUND, //!< User not found.
RLM_MODULE_NOOP, //!< Module succeeded without doing anything.
RLM_MODULE_UPDATED, //!< OK (pairs modified).
RLM_MODULE_NUMCODES, //!< How many valid return codes there are.
RLM_MODULE_UNKNOWN //!< Error resolving rcode (should not be
//!< returned by modules).
} rlm_rcode_t;
extern const FR_NAME_NUMBER modreturn_table[];

/*
* For listening on multiple IP's and ports.
Expand Down Expand Up @@ -230,6 +250,8 @@ struct request {
rad_listen_t *proxy_listener;//!< Listener for outgoing requests.
#endif

rlm_rcode_t rcode; //!< Last rcode returned by a module

int simul_max; //!< Maximum number of concurrent sessions for this user.
#ifdef WITH_SESSION_MGMT
int simul_count; //!< The current number of sessions for this user.
Expand Down
4 changes: 2 additions & 2 deletions src/main/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RCSID("$Id$")
#ifdef WITH_EVAL_DEBUG
#define EVAL_DEBUG(fmt, ...) printf("EVAL: ");printf(fmt, ## __VA_ARGS__);printf("\n");fflush(stdout)

static const FR_NAME_NUMBER template_names[] = {
static FR_NAME_NUMBER const template_names[] = {
{ "literal", VPT_TYPE_LITERAL },
{ "xlat", VPT_TYPE_XLAT },
{ "attr", VPT_TYPE_ATTR },
Expand All @@ -49,7 +49,7 @@ static const FR_NAME_NUMBER template_names[] = {
#define EVAL_DEBUG(...)
#endif

static const FR_NAME_NUMBER modreturn_table[] = {
FR_NAME_NUMBER const modreturn_table[] = {
{ "reject", RLM_MODULE_REJECT },
{ "fail", RLM_MODULE_FAIL },
{ "ok", RLM_MODULE_OK },
Expand Down
8 changes: 3 additions & 5 deletions src/main/modcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ static void safe_unlock(module_instance_t *instance)

static rlm_rcode_t call_modsingle(rlm_components_t component, modsingle *sp, REQUEST *request)
{
rlm_rcode_t myresult;
int blocked;

rad_assert(request != NULL);
Expand All @@ -297,7 +296,7 @@ static rlm_rcode_t call_modsingle(rlm_components_t component, modsingle *sp, REQ
sp->modinst->entry->name, request->number);

if (sp->modinst->force) {
myresult = sp->modinst->code;
request->rcode = sp->modinst->code;
goto fail;
}

Expand All @@ -308,8 +307,7 @@ static rlm_rcode_t call_modsingle(rlm_components_t component, modsingle *sp, REQ
*/
request->module = sp->modinst->name;

myresult = sp->modinst->entry->module->methods[component](
sp->modinst->insthandle, request);
request->rcode = sp->modinst->entry->module->methods[component](sp->modinst->insthandle, request);

request->module = "";
safe_unlock(sp->modinst);
Expand All @@ -327,7 +325,7 @@ static rlm_rcode_t call_modsingle(rlm_components_t component, modsingle *sp, REQ
comp2str[component], sp->modinst->name,
sp->modinst->entry->name, request->number);

return myresult;
return request->rcode;
}

static int default_component_results[RLM_COMPONENT_COUNT] = {
Expand Down
3 changes: 2 additions & 1 deletion src/main/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,8 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DI
return talloc_typed_strdup(ctx, request->server);

case PW_MODULE_RETURN_CODE:
return talloc_typed_asprintf(ctx, "%d", request->simul_max); /* hack */
if (!request->rcode) return NULL;
return talloc_typed_strdup(ctx, fr_int2str(modreturn_table, request->rcode, ""));
}

/*
Expand Down
12 changes: 9 additions & 3 deletions src/tests/keywords/virtual-attr
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ if ("%{Virtual-Server}" != 'default') {
}
}

# This is actually request->simul_max not the rcode
if ("%{Module-Return-Code}" != 0) {
if ("%{Module-Return-Code}" != '') {
update reply {
Filter-Id += "fail 3"
Filter-Id += "fail 3a"
}
}

ok
if ("%{Module-Return-Code}" != 'ok') {
update reply {
Filter-Id += "fail 3b"
}
}

Expand Down

0 comments on commit 2fb40d9

Please sign in to comment.