📄 modules.c
字号:
ml = compile_modgroup(comp, cs, filename); /* We must assign a numeric index to this subcomponent. For * auth, it is generated and placed in the dictionary by * new_sectiontype_value(). The others are just numbers that are pulled * out of thin air, and the names are neither put into the dictionary * nor checked for uniqueness, but all that could be fixed in a few * minutes, if anyone finds a real use for indexed config of * components other than auth. */ dval = NULL; if (comp==RLM_COMPONENT_AUTH) { dval = dict_valbyname(PW_AUTH_TYPE, cf_section_name2(cs)); } else if (comp == RLM_COMPONENT_AUTZ) { dval = dict_valbyname(PW_AUTZ_TYPE, cf_section_name2(cs)); } else if (comp == RLM_COMPONENT_ACCT) { dval = dict_valbyname(PW_ACCT_TYPE, cf_section_name2(cs)); } else if (comp == RLM_COMPONENT_SESS) { dval = dict_valbyname(PW_SESSION_TYPE, cf_section_name2(cs)); } else if (comp == RLM_COMPONENT_POST_AUTH) { dval = dict_valbyname(PW_POST_AUTH_TYPE, cf_section_name2(cs)); } if (dval) { idx = dval->value; } else { idx = meaningless_counter++; } subcomp = new_sublist(comp, idx); if (!subcomp) { radlog(L_ERR|L_CONS, "%s[%d] %s %s already configured - skipping", filename, cf_section_lineno(cs), subcomponent_names[comp], cf_section_name2(cs)); modcallable_free(&ml); return; } subcomp->modulelist = ml;}static int load_component_section(CONF_SECTION *cs, int comp, const char *filename){ modcallable *this; CONF_ITEM *modref; int idx; indexed_modcallable *subcomp; const char *modname; char *visiblename; for (modref=cf_item_find_next(cs, NULL); modref != NULL; modref=cf_item_find_next(cs, modref)) { if (cf_item_is_section(modref)) { const char *sec_name; CONF_SECTION *scs; scs = cf_itemtosection(modref); sec_name = cf_section_name1(scs); if (strcmp(sec_name, subcomponent_names[comp]) == 0) { load_subcomponent_section(scs, comp, filename); continue; } /* * Allow old names, too. */ if (strcmp(sec_name, old_subcomponent_names[comp]) == 0) { load_subcomponent_section(scs, comp, filename); continue; } } else { CONF_PAIR *cp; cp = cf_itemtopair(modref); } /* * FIXME: This calls exit if the reference can't be * found. We should instead print a better error, * and return the failure code up the stack. */ this = compile_modsingle(comp, modref, filename, &modname); if (comp == RLM_COMPONENT_AUTH) { DICT_VALUE *dval; dval = dict_valbyname(PW_AUTH_TYPE, modname); if (!dval) { /* * It's a section, but nothing we * recognize. Die! */ radlog(L_ERR|L_CONS, "%s[%d] Unknown Auth-Type \"%s\" in %s section.", filename, cf_section_lineno(cs), modname, component_names[comp]); return -1; } idx = dval->value; } else { /* See the comment in new_sublist() for explanation * of the special index 0 */ idx = 0; } subcomp = new_sublist(comp, idx); if (subcomp == NULL) { radlog(L_INFO|L_CONS, "%s %s %s already configured - skipping", filename, subcomponent_names[comp], modname); modcallable_free(&this); continue; } /* If subcomp->modulelist is NULL, add_to_modcallable will * create it */ visiblename = cf_section_name2(cs); if (visiblename == NULL) visiblename = cf_section_name1(cs); add_to_modcallable(&subcomp->modulelist, this, comp, visiblename); } return 0;}typedef struct section_type_value_t { const char *section; const char *typename; int attr;} section_type_value_t;static const section_type_value_t section_type_value[] = { { "authorize", "Autz-Type", PW_AUTZ_TYPE }, { "authenticate", "Auth-Type", PW_AUTH_TYPE }, { "accounting", "Acct-Type", PW_ACCT_TYPE }, { "session", "Session-Type", PW_SESSION_TYPE }, { "post-auth", "Post-Auth-Type", PW_POST_AUTH_TYPE }, { "preacct", "Pre-Acct-Type", PW_PRE_ACCT_TYPE }, { "post-proxy", "Post-Proxy-Type", PW_POST_PROXY_TYPE }, { "pre-proxy", "Pre-Proxy-Type", PW_PRE_PROXY_TYPE }, { NULL, NULL, 0 }};/* * Delete ASAP. */static const section_type_value_t old_section_type_value[] = { { "authorize", "autztype", PW_AUTZ_TYPE }, { "authenticate", "authtype", PW_AUTH_TYPE }, { "accounting", "acctype", PW_ACCT_TYPE }, { "session", "sesstype", PW_SESSION_TYPE }, { "post-auth", "post-authtype", PW_POST_AUTH_TYPE }, { NULL, NULL, 0 }};/* * Parse the module config sections, and load * and call each module's init() function. * * Libtool makes your life a LOT easier, especially with libltdl. * see: http://www.gnu.org/software/libtool/ */int setup_modules(void){ int comp; CONF_SECTION *cs; /* * FIXME: This should be pulled from somewhere else. */ const char *filename="radiusd.conf"; /* * No current list of modules: Go initialize libltdl. */ if (!module_list) { /* * Set the default list of preloaded symbols. * This is used to initialize libltdl's list of * preloaded modules. * * i.e. Static modules. */ LTDL_SET_PRELOADED_SYMBOLS(); if (lt_dlinit() != 0) { radlog(L_ERR|L_CONS, "Failed to initialize libraries: %s\n", lt_dlerror()); exit(1); /* FIXME */ } /* * Set the search path to ONLY our library directory. * This prevents the modules from being found from * any location on the disk. */ lt_dlsetsearchpath(radlib_dir); DEBUG2("Module: Library search path is %s", lt_dlgetsearchpath()); /* * Initialize the components. */ for (comp = 0; comp < RLM_COMPONENT_COUNT; comp++) { components[comp] = NULL; } } else { detach_modules(); } /* * Create any DICT_VALUE's for the types. See * 'doc/configurable_failover' for examples of 'authtype' * used to create new Auth-Type values. In order to * let the user create new names, we've got to look for * those names, and create DICT_VALUE's for them. */ for (comp = 0; section_type_value[comp].section != NULL; comp++) { const char *name2; DICT_ATTR *dattr; DICT_VALUE *dval; CONF_SECTION *sub, *next; CONF_PAIR *cp; /* * Big-time YUCK */ static int my_value = 32767; cs = cf_section_find(section_type_value[comp].section); if (!cs) continue; sub = NULL; do { /* * See if there's a sub-section by that * name. */ next = cf_subsection_find_next(cs, sub, section_type_value[comp].typename); /* * Allow some old names, too. */ if (!next && (comp <= 4)) { next = cf_subsection_find_next(cs, sub, old_section_type_value[comp].typename); } sub = next; /* * If so, look for it to define a new * value. */ name2 = cf_section_name2(sub); if (!name2) continue; /* * If the value already exists, don't * create it again. */ dval = dict_valbyname(section_type_value[comp].attr, name2); if (dval) continue; /* * Find the attribute for the value. */ dattr = dict_attrbyvalue(section_type_value[comp].attr); if (!dattr) continue; /* * Finally, create the new attribute. */ if (dict_addvalue(name2, dattr->name, my_value++) < 0) { radlog(L_ERR, "%s", librad_errstr); exit(1); } } while (sub != NULL); /* * Loop over the non-sub-sections, too. */ cp = NULL; do { /* * See if there's a conf-pair by that * name. */ cp = cf_pair_find_next(cs, cp, NULL); if (!cp) break; /* * If the value already exists, don't * create it again. */ name2 = cf_pair_attr(cp); dval = dict_valbyname(section_type_value[comp].attr, name2); if (dval) continue; /* * Find the attribute for the value. */ dattr = dict_attrbyvalue(section_type_value[comp].attr); if (!dattr) continue; /* * Finally, create the new attribute. */ if (dict_addvalue(name2, dattr->name, my_value++) < 0) { radlog(L_ERR, "%s", librad_errstr); exit(1); } } while (cp != NULL); } /* over the sections which can have redundent sub-sections */ /* * Look for the 'instantiate' section, which tells us * the instantiation order of the modules, and also allows * us to load modules with no authorize/authenticate/etc. * sections. */ cs = cf_section_find("instantiate"); if (cs != NULL) { CONF_ITEM *ci; CONF_PAIR *cp; module_instance_t *module; const char *name; /* * Loop over the items in the 'instantiate' section. */ for (ci=cf_item_find_next(cs, NULL); ci != NULL; ci=cf_item_find_next(cs, ci)) { if (cf_item_is_section(ci)) { radlog(L_ERR|L_CONS, "%s[%d] Subsection for module instantiate is not allowed\n", filename, cf_section_lineno(cf_itemtosection(ci))); exit(1); } cp = cf_itemtopair(ci); name = cf_pair_attr(cp); module = find_module_instance(name); if (!module) { exit(1); } } /* loop over items in the subsection */ } /* if there's an 'instantiate' section. */ /* * Loop over all of the known components, finding their * configuration section, and loading it. */ for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) { cs = cf_section_find(component_names[comp]); if (cs == NULL) continue; if (load_component_section(cs, comp, filename) < 0) { exit(1); } } return 0;}/* * Call all authorization modules until one returns * somethings else than RLM_MODULE_OK */int module_authorize(int autz_type, REQUEST *request){ /* * We have a proxied packet, and we've been told * to NOT pass proxied packets through 'authorize' * a second time. So stop. */ if ((request->proxy != NULL && mainconfig.post_proxy_authorize == FALSE)) { DEBUG2(" authorize: Skipping authorize in post-proxy stage"); return RLM_MODULE_NOOP; } return indexed_modcall(RLM_COMPONENT_AUTZ, autz_type, request);}/* * Authenticate a user/password with various methods. */int module_authenticate(int auth_type, REQUEST *request){ return indexed_modcall(RLM_COMPONENT_AUTH, auth_type, request);}/* * Do pre-accounting for ALL configured sessions */int module_preacct(REQUEST *request){ return indexed_modcall(RLM_COMPONENT_PREACCT, 0, request);}/* * Do accounting for ALL configured sessions */int module_accounting(int acct_type, REQUEST *request){ return indexed_modcall(RLM_COMPONENT_ACCT, acct_type, request);}/* * See if a user is already logged in. * * Returns: 0 == OK, 1 == double logins, 2 == multilink attempt */int module_checksimul(int sess_type, REQUEST *request, int maxsimul){ int rcode; if(!components[RLM_COMPONENT_SESS]) return 0; if(!request->username) return 0; request->simul_count = 0; request->simul_max = maxsimul; request->simul_mpp = 1; rcode = indexed_modcall(RLM_COMPONENT_SESS, sess_type, request); if (rcode != RLM_MODULE_OK) { /* FIXME: Good spot for a *rate-limited* warning to the log */ return 0; } return (request->simul_count < maxsimul) ? 0 : request->simul_mpp;}/* * Do pre-proxying for ALL configured sessions */int module_pre_proxy(REQUEST *request){ return indexed_modcall(RLM_COMPONENT_PRE_PROXY, 0, request);}/* * Do post-proxying for ALL configured sessions */int module_post_proxy(REQUEST *request){ return indexed_modcall(RLM_COMPONENT_POST_PROXY, 0, request);}/* * Do post-authentication for ALL configured sessions */int module_post_auth(int postauth_type, REQUEST *request){ return indexed_modcall(RLM_COMPONENT_POST_AUTH, postauth_type, request);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -