Skip to content

Commit

Permalink
Move xlat's to bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Apr 29, 2015
1 parent 345509c commit 25cdf27
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 131 deletions.
4 changes: 2 additions & 2 deletions src/modules/proto_dhcp/rlm_dhcp.c
Expand Up @@ -144,7 +144,7 @@ static ssize_t dhcp_xlat(UNUSED void *instance, REQUEST *request, char const *fm
/*
* Instantiate the module.
*/
static int mod_instantiate(UNUSED CONF_SECTION *conf, void *instance)
static int mod_bootstrap(UNUSED CONF_SECTION *conf, void *instance)
{
rlm_dhcp_t *inst = instance;
DICT_ATTR const *da;
Expand Down Expand Up @@ -194,5 +194,5 @@ module_t rlm_dhcp = {
.magic = RLM_MODULE_INIT,
.name = "dhcp",
.inst_size = sizeof(rlm_dhcp_t),
.instantiate = mod_instantiate
.bootstrap = mod_bootstrap,
};
32 changes: 22 additions & 10 deletions src/modules/rlm_cache/rlm_cache.c
Expand Up @@ -676,13 +676,10 @@ static int mod_detach(void *instance)
return 0;
}

/*
* Instantiate the module.
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)

static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
rlm_cache_t *inst = instance;
CONF_SECTION *update;

inst->cs = conf;

Expand All @@ -694,11 +691,25 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
*/
xlat_register(inst->xlat_name, cache_xlat, NULL, inst);

return 0;
}


/*
* Instantiate the module.
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
rlm_cache_t *inst = instance;
CONF_SECTION *update;

inst->cs = conf;

/*
* Sanity check for crazy people.
*/
if (strncmp(inst->driver_name, "rlm_cache_", 8) != 0) {
ERROR("rlm_cache (%s): \"%s\" is NOT an Cache driver!", inst->xlat_name, inst->driver_name);
cf_log_err_cs(conf, "\"%s\" is NOT an Cache driver!", inst->driver_name);
return -1;
}

Expand All @@ -707,15 +718,15 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
*/
inst->handle = lt_dlopenext(inst->driver_name);
if (!inst->handle) {
ERROR("rlm_cache (%s): Could not link driver %s: %s", inst->xlat_name, inst->driver_name, dlerror());
ERROR("rlm_cache (%s): Make sure it (and all its dependent libraries!) are in the search path"
"of your system's ld", inst->xlat_name);
cf_log_err_cs(conf, "Could not link driver %s: %s", inst->driver_name, dlerror());
cf_log_err_cs(conf, "Make sure it (and all its dependent libraries!) are in the search path"
"of your system's ld");
return -1;
}

inst->module = (cache_module_t *) dlsym(inst->handle, inst->driver_name);
if (!inst->module) {
ERROR("rlm_cache (%s): Could not link symbol %s: %s", inst->xlat_name, inst->driver_name, dlerror());
cf_log_err_cs(conf, "Could not link symbol %s: %s", inst->driver_name, dlerror());
return -1;
}

Expand Down Expand Up @@ -806,6 +817,7 @@ module_t rlm_cache = {
.name = "cache",
.inst_size = sizeof(rlm_cache_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.methods = {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/rlm_date/rlm_date.c
Expand Up @@ -101,7 +101,7 @@ static ssize_t xlat_date_convert(void *instance, REQUEST *request, char const *f
}
DIAG_ON(format-nonliteral)

static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
rlm_date_t *inst = instance;

Expand All @@ -121,6 +121,6 @@ module_t rlm_date = {
.name = "date",
.inst_size = sizeof(rlm_date_t),
.config = module_config,
.instantiate = mod_instantiate
.bootstrap = mod_bootstrap
};

4 changes: 2 additions & 2 deletions src/modules/rlm_exec/rlm_exec.c
Expand Up @@ -204,7 +204,7 @@ static ssize_t exec_xlat(void *instance, REQUEST *request, char const *fmt, char
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
char const *p;
rlm_exec_t *inst = instance;
Expand Down Expand Up @@ -468,7 +468,7 @@ module_t rlm_exec = {
.type = RLM_TYPE_THREAD_SAFE,
.inst_size = sizeof(rlm_exec_t),
.config = module_config,
.instantiate = mod_instantiate,
.bootstrap = mod_bootstrap,
.methods = {
[MOD_AUTHENTICATE] = mod_exec_dispatch,
[MOD_AUTHORIZE] = mod_exec_dispatch,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/rlm_expr/rlm_expr.c
Expand Up @@ -1648,7 +1648,7 @@ static ssize_t rpad_xlat(UNUSED void *instance, REQUEST *request,
* that must be referenced in later calls, store a handle to it
* in *instance otherwise put a null pointer there.
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
rlm_expr_t *inst = instance;

Expand Down Expand Up @@ -1708,5 +1708,5 @@ module_t rlm_expr = {
.name = "expr",
.inst_size = sizeof(rlm_expr_t),
.config = module_config,
.instantiate = mod_instantiate,
.bootstrap = mod_bootstrap,
};
4 changes: 2 additions & 2 deletions src/modules/rlm_idn/rlm_idn.c
Expand Up @@ -131,7 +131,7 @@ static ssize_t xlat_idna(void *instance, REQUEST *request, char const *fmt, char
return len;
}

static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
rlm_idn_t *inst = instance;
char const *xlat_name;
Expand All @@ -155,5 +155,5 @@ module_t rlm_idn = {
.type = RLM_TYPE_THREAD_SAFE,
.inst_size = sizeof(rlm_idn_t),
.config = mod_config,
.instantiate = mod_instantiate
.bootstrap = mod_bootstrap
};
16 changes: 8 additions & 8 deletions src/modules/rlm_ldap/rlm_ldap.c
Expand Up @@ -544,6 +544,11 @@ static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
ldap_instance_t *inst = instance;

inst->name = cf_section_name2(conf);
if (!inst->name) {
inst->name = cf_section_name1(conf);
}

/*
* Setup the cache attribute
*/
Expand Down Expand Up @@ -590,6 +595,9 @@ static int mod_bootstrap(CONF_SECTION *conf, void *instance)
inst->group_da = dict_attrbyname("LDAP-Group");
}

xlat_register(inst->name, ldap_xlat, rlm_ldap_escape_func, inst);
xlat_register("ldapquote", ldapquote_xlat, NULL, inst);

return 0;
}

Expand Down Expand Up @@ -619,11 +627,6 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
inst->chase_referrals_unset = true; /* use OpenLDAP defaults */
}

inst->name = cf_section_name2(conf);
if (!inst->name) {
inst->name = cf_section_name1(conf);
}

/*
* Only needs to be done once, prevents races in environment
* initialisation within libldap.
Expand Down Expand Up @@ -1069,9 +1072,6 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
return -1;
}

xlat_register(inst->name, ldap_xlat, rlm_ldap_escape_func, inst);
xlat_register("ldapquote", ldapquote_xlat, NULL, inst);

/*
* Initialize the socket pool.
*/
Expand Down
28 changes: 18 additions & 10 deletions src/modules/rlm_mschap/rlm_mschap.c
Expand Up @@ -565,11 +565,7 @@ static const CONF_PARSER module_config[] = {
};


/*
* Create instance for our module. Allocate space for
* instance structure and read configuration parameters
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
char const *name;
rlm_mschap_t *inst = instance;
Expand All @@ -582,6 +578,17 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
inst->xlat_name = name;
xlat_register(inst->xlat_name, mschap_xlat, NULL, inst);

return 0;
}

/*
* Create instance for our module. Allocate space for
* instance structure and read configuration parameters
*/
static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
rlm_mschap_t *inst = instance;

/*
* For backwards compatibility
*/
Expand All @@ -602,11 +609,11 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)

inst->wb_pool = fr_connection_pool_module_init(conf, inst, mod_conn_create, NULL, NULL);
if (!inst->wb_pool) {
ERROR("rlm_mschap (%s): unable to initialise winbind connection pool", name);
cf_log_err_cs(conf, "Unable to initialise winbind connection pool");
return -1;
}
#else
ERROR("rlm_mschap (%s): 'winbind' auth not enabled at compiled time", name);
cf_log_err_cs(conf, "'winbind' auth not enabled at compiled time");
return -1;
#endif
}
Expand All @@ -618,14 +625,14 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)

switch (inst->method) {
case AUTH_INTERNAL:
DEBUG("rlm_mschap (%s): using internal authentication", name);
DEBUG("rlm_mschap (%s): using internal authentication", inst->xlat_name);
break;
case AUTH_NTLMAUTH_EXEC:
DEBUG("rlm_mschap (%s): authenticating by calling 'ntlm_auth'", name);
DEBUG("rlm_mschap (%s): authenticating by calling 'ntlm_auth'", inst->xlat_name);
break;
#ifdef WITH_AUTH_WINBIND
case AUTH_WBCLIENT:
DEBUG("rlm_mschap (%s): authenticating directly to winbind", name);
DEBUG("rlm_mschap (%s): authenticating directly to winbind", inst->xlat_name);
break;
#endif
}
Expand Down Expand Up @@ -1989,6 +1996,7 @@ module_t rlm_mschap = {
.type = RLM_TYPE_THREAD_SAFE | RLM_TYPE_HUP_SAFE,
.inst_size = sizeof(rlm_mschap_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.methods = {
Expand Down
24 changes: 15 additions & 9 deletions src/modules/rlm_perl/rlm_perl.c
Expand Up @@ -454,6 +454,20 @@ static void perl_parse_config(CONF_SECTION *cs, int lvl, HV *rad_hv)
DEBUG("%*s}", indent_section, " ");
}

static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
rlm_perl_t *inst = instance;

char const *xlat_name;

xlat_name = cf_section_name2(conf);
if (!xlat_name) xlat_name = cf_section_name1(conf);

xlat_register(xlat_name, perl_xlat, NULL, inst);

return 0;
}

/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
Expand All @@ -476,16 +490,11 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
char const **embed_c; /* Stupid Perl and lack of const consistency */
char **embed;
char **envp = NULL;
char const *xlat_name;
int exitstatus = 0, argc=0;
char arg[] = "0";

CONF_SECTION *cs;

xlat_name = cf_section_name2(conf);
if (!xlat_name) xlat_name = cf_section_name1(conf);
if (xlat_name) xlat_register(xlat_name, perl_xlat, NULL, inst);

#ifdef USE_ITHREADS
/*
* Create pthread key. This key will be stored in instance
Expand Down Expand Up @@ -556,12 +565,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
/* parse perl configuration sub-section */
cs = cf_section_sub_find(conf, "config");
if (cs) {
DEBUG("rlm_perl (%s): parsing 'config' section...", xlat_name);

inst->rad_perlconf_hv = get_hv("RAD_PERLCONF", 1);
perl_parse_config(cs, 0, inst->rad_perlconf_hv);

DEBUG("rlm_perl (%s): done parsing 'config'.", xlat_name);
}

inst->perl_parsed = true;
Expand Down Expand Up @@ -1035,6 +1040,7 @@ module_t rlm_perl = {
#endif
.inst_size = sizeof(rlm_perl_t),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.methods = {
Expand Down
21 changes: 11 additions & 10 deletions src/modules/rlm_redis/rlm_redis.c
Expand Up @@ -259,23 +259,23 @@ int rlm_redis_finish_query(REDISSOCK *dissocket)
return 0;
}

static int mod_instantiate(CONF_SECTION *conf, void *instance)
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
{
static bool version_done;

REDIS_INST *inst = instance;

if (!version_done) {
version_done = true;

INFO("rlm_redis: libhiredis version: %i.%i.%i", HIREDIS_MAJOR, HIREDIS_MINOR, HIREDIS_PATCH);
}
INFO("rlm_redis: libhiredis version: %i.%i.%i", HIREDIS_MAJOR, HIREDIS_MINOR, HIREDIS_PATCH);

inst->xlat_name = cf_section_name2(conf);

if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf);

xlat_register(inst->xlat_name, redis_xlat, NULL, inst); /* FIXME! */
xlat_register(inst->xlat_name, redis_xlat, NULL, inst);

return 0;
}

static int mod_instantiate(CONF_SECTION *conf, void *instance)
{
REDIS_INST *inst = instance;

inst->pool = fr_connection_pool_module_init(conf, inst, mod_conn_create, NULL, NULL);
if (!inst->pool) {
Expand All @@ -295,6 +295,7 @@ module_t rlm_redis = {
.type = RLM_TYPE_THREAD_SAFE,
.inst_size = sizeof(REDIS_INST),
.config = module_config,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach
};

0 comments on commit 25cdf27

Please sign in to comment.