📄 modcall.c
字号:
/* * Keep track of how many load balancing servers * we've gone through. */ count++; /* * See the "camel book" for why this works. * * If (rand(0..n) < 1), pick the current realm. * We add a scale factor of 65536, to avoid * floating point. */ if ((count * (lrad_rand() & 0xffff)) < (uint32_t) 0x10000) { child = p; } } rad_assert(child != NULL); /* * Call the chosen child, with fail-over to the next one * if it is down. */ p = child; do { /* * Call the chosen entry. If we're done, then * stop. */ if (!call_one(component, p, request, &priority, &myresult)) { break; } /* * Go to the next one, and wrap around to the beginning if * we reach the end. */ p = p->next; if (!p) p = g->children; } while (p != child); /* * And return whatever was decided. */ return myresult;}int modcall(int component, modcallable *c, REQUEST *request){ int myresult; /* Choose a default return value appropriate for the component */ switch(component) { case RLM_COMPONENT_AUTZ: myresult = RLM_MODULE_NOTFOUND; break; case RLM_COMPONENT_AUTH: myresult = RLM_MODULE_REJECT; break; case RLM_COMPONENT_PREACCT: myresult = RLM_MODULE_NOOP; break; case RLM_COMPONENT_ACCT: myresult = RLM_MODULE_NOOP; break; case RLM_COMPONENT_SESS: myresult = RLM_MODULE_FAIL; break; case RLM_COMPONENT_PRE_PROXY: myresult = RLM_MODULE_NOOP; break; case RLM_COMPONENT_POST_PROXY: myresult = RLM_MODULE_NOOP; break; case RLM_COMPONENT_POST_AUTH: myresult = RLM_MODULE_NOOP; break; default: myresult = RLM_MODULE_FAIL; break; } if(c == NULL) { DEBUG2("modcall[%s]: NULL object returns %s for request %d", comp2str[component], lrad_int2str(rcode_table, myresult, "??"), request->number); return myresult; } switch (c->type) { case MOD_LOAD_BALANCE: { modgroup *g = mod_callabletogroup(c); DEBUG2("modcall: entering load-balance group %s for request %d", c->name, request->number); myresult = call_modloadbalance(component, g, request, myresult); DEBUG2("modcall: load-balance group %s returns %s for request %d", c->name, lrad_int2str(rcode_table, myresult, "??"), request->number); } break; case MOD_REDUNDANT_LOAD_BALANCE: { modgroup *g = mod_callabletogroup(c); DEBUG2("modcall: entering redundant-load-balance group %s for request %d", c->name, request->number); myresult = call_modredundantloadbalance(component, g, request, myresult); DEBUG2("modcall: redundant-load-balance group %s returns %s for request %d", c->name, lrad_int2str(rcode_table, myresult, "??"), request->number); } break; case MOD_GROUP: { modgroup *g = mod_callabletogroup(c); DEBUG2("modcall: entering group %s%s for request %d", lrad_int2str(grouptype_table, g->grouptype, ""), c->name, request->number); myresult = call_modgroup(component, g, request, myresult); DEBUG2("modcall: leaving group %s%s (returns %s) for request %d", lrad_int2str(grouptype_table, g->grouptype, ""), c->name, lrad_int2str(rcode_table, myresult, "??"), request->number); } break; case MOD_SINGLE: { modsingle *sp = mod_callabletosingle(c); myresult = call_modsingle(component, sp, request, myresult); DEBUG2(" modcall[%s]: module \"%s\" returns %s for request %d", comp2str[component], c->name, lrad_int2str(rcode_table, myresult, "??"), request->number); } break; default: radlog(L_ERR, "Internal error processing module entry"); break; } return myresult;}#if 0/* If you suspect a bug in the parser, you'll want to use these dump * functions. dump_tree should reproduce a whole tree exactly as it was found * in radiusd.conf, but in long form (all actions explicitly defined) */static void dump_mc(modcallable *c, int indent){ int i; if(c->type==MOD_SINGLE) { modsingle *single = mod_callabletosingle(c); DEBUG("%.*s%s {", indent, "\t\t\t\t\t\t\t\t\t\t\t", single->modinst->name); } else { modgroup *g = mod_callabletogroup(c); modcallable *p; DEBUG("%.*sgroup {", indent, "\t\t\t\t\t\t\t\t\t\t\t"); for(p = g->children;p;p = p->next) dump_mc(p, indent+1); } for(i = 0; i<RLM_MODULE_NUMCODES; ++i) { DEBUG("%.*s%s = %s", indent+1, "\t\t\t\t\t\t\t\t\t\t\t", lrad_int2str(rcode_table, i, "??"), action2str(c->actions[i])); } DEBUG("%.*s}", indent, "\t\t\t\t\t\t\t\t\t\t\t");}static void dump_tree(int comp, modcallable *c){ DEBUG("[%s]", comp2str[comp]); dump_mc(c, 0);}#elsestatic void dump_tree(int comp UNUSED, modcallable *c UNUSED){ return;}#endif/* These are the default actions. For each component, the group{} block * behaves like the code from the old module_*() function. redundant{} and * append{} are based on my guesses of what they will be used for. --Pac. */static const intdefaultactions[RLM_COMPONENT_COUNT][GROUPTYPE_COUNT][RLM_MODULE_NUMCODES] ={ /* authenticate */ { /* group */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ 1, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ 1, /* noop */ 1 /* updated */ }, /* redundant */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ }, /* append */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ 2, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ } }, /* authorize */ { /* group */ { MOD_ACTION_RETURN, /* reject */ MOD_ACTION_RETURN, /* fail */ 3, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ 1, /* notfound */ 2, /* noop */ 4 /* updated */ }, /* redundant */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ }, /* append */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ 2, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ } }, /* preacct */ { /* group */ { MOD_ACTION_RETURN, /* reject */ MOD_ACTION_RETURN, /* fail */ 2, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ 1, /* noop */ 3 /* updated */ }, /* redundant */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ }, /* append */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ 2, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ } }, /* accounting */ { /* group */ { MOD_ACTION_RETURN, /* reject */ MOD_ACTION_RETURN, /* fail */ 2, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ 1, /* noop */ 3 /* updated */ }, /* redundant */ { 1, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ 1, /* invalid */ 1, /* userlock */ 1, /* notfound */ 2, /* noop */ 4 /* updated */ }, /* append */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ 2, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ } }, /* checksimul */ { /* group */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ }, /* redundant */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ }, /* append */ { MOD_ACTION_RETURN, /* reject */ 1, /* fail */ MOD_ACTION_RETURN, /* ok */ MOD_ACTION_RETURN, /* handled */ MOD_ACTION_RETURN, /* invalid */ MOD_ACTION_RETURN, /* userlock */ MOD_ACTION_RETURN, /* notfound */ MOD_ACTION_RETURN, /* noop */ MOD_ACTION_RETURN /* updated */ } }, /* pre-proxy */ { /* group */ { MOD_ACTION_RETURN, /* reject */ MOD_ACTION_RETURN, /* fail */ 3, /* ok */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -