From: Alan T. DeKok Date: Mon, 13 Jun 2011 09:31:47 +0000 (+0200) Subject: Allow policies to refer to modules of the same name X-Git-Tag: release_3_0_0_beta0~772 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd4ae9e0ea536b576a8c30345b6f8e7f7ed1792b;p=thirdparty%2Ffreeradius-server.git Allow policies to refer to modules of the same name policy { files { files ... } } Means that you can over-ride the behavior of the "files" module, and add anything else you need. --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 9baca4f8f68..cc9eb4f6c2f 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -92,6 +92,7 @@ int cf_pair_lineno(CONF_PAIR *pair); const char *cf_pair_filename(CONF_PAIR *pair); const char *cf_section_filename(CONF_SECTION *section); CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item); +CONF_SECTION *cf_item_parent(CONF_ITEM *ci); int cf_item_is_section(CONF_ITEM *item); int cf_item_is_pair(CONF_ITEM *item); CONF_PAIR *cf_itemtopair(CONF_ITEM *item); diff --git a/src/main/conffile.c b/src/main/conffile.c index 2d827fcec9f..cb9a8a9bcc7 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -2183,6 +2183,13 @@ CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item) } } +CONF_SECTION *cf_item_parent(CONF_ITEM *ci) +{ + if (!ci) return NULL; + + return ci->parent; +} + int cf_section_lineno(CONF_SECTION *section) { return cf_sectiontoitem(section)->lineno; diff --git a/src/main/modcall.c b/src/main/modcall.c index 0fecc7f3cf8..3585b5f334a 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -1982,6 +1982,7 @@ static modcallable *do_compile_modsingle(modcallable *parent, * codes. */ } else { + CONF_SECTION *loop; CONF_PAIR *cp = cf_itemtopair(ci); modrefname = cf_pair_attr(cp); @@ -2013,6 +2014,20 @@ static modcallable *do_compile_modsingle(modcallable *parent, if (cs) subcs = cf_section_sub_find_name2(cs, NULL, modrefname); } + + /* + * Allow policies to over-ride module names. + * i.e. the "sql" policy can do some extra things, + * and then call the "sql" module. + */ + for (loop = cf_item_parent(ci); + loop && subcs; + loop = cf_item_parent(cf_sectiontoitem(loop))) { + if (loop == subcs) { + subcs = NULL; + } + } + if (subcs) { DEBUG2(" Module: Loading virtual module %s", modrefname);