Skip to content

Commit

Permalink
Fix use of add_to_modcallable()
Browse files Browse the repository at this point in the history
it should just add.  It shouldn't create the parent
  • Loading branch information
alandekok committed Mar 22, 2014
1 parent a26d563 commit 1eff459
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 83 deletions.
7 changes: 3 additions & 4 deletions src/include/modcall.h
Expand Up @@ -31,17 +31,16 @@ modcallable *compile_modgroup(modcallable *parent,
/* Create a single modcallable node that references a module instance. This
* may be a CONF_SECTION containing action specifiers like "notfound = return"
* or a simple CONF_PAIR, in which case the default actions are used. */
modcallable *compile_modsingle(modcallable *parent, rlm_components_t component, CONF_ITEM *ci,
modcallable *compile_modsingle(modcallable **parent, rlm_components_t component, CONF_ITEM *ci,
char const **modname);

/*
* Do the second pass on compiling the modules.
*/
bool modcall_pass2(modcallable *mc);

/* Add an entry to the end of a modgroup, creating it first if necessary */
void add_to_modcallable(modcallable **parent, modcallable *this,
rlm_components_t component, char const *name);
/* Add an entry to the end of a modgroup */
void add_to_modcallable(modcallable *parent, modcallable *this);

/* Free a tree returned by compile_modgroup or compile_modsingle */
void modcallable_free(modcallable **pc);
Expand Down
63 changes: 36 additions & 27 deletions src/main/modcall.c
Expand Up @@ -2260,13 +2260,42 @@ static modcallable *do_compile_modsingle(modcallable *parent,
return csingle;
}

modcallable *compile_modsingle(modcallable *parent,
modcallable *compile_modsingle(modcallable **parent,
rlm_components_t component, CONF_ITEM *ci,
char const **modname)
{
modcallable *ret = do_compile_modsingle(parent, component, ci,
GROUPTYPE_SIMPLE,
modname);
modcallable *ret;

if (!*parent) {
modcallable *c;
modgroup *g;
CONF_SECTION *parentcs;

g = rad_malloc(sizeof *g);
memset(g, 0, sizeof(*g));
g->grouptype = GROUPTYPE_SIMPLE;
c = mod_grouptocallable(g);
c->next = NULL;
memcpy(c->actions,
defaultactions[component][GROUPTYPE_SIMPLE],
sizeof(c->actions));

parentcs = cf_item_parent(ci);
c->name = cf_section_name2(parentcs);
if (!c->name) {
c->name = cf_section_name1(parentcs);
}

c->type = MOD_GROUP;
c->method = component;
g->children = NULL;

*parent = mod_grouptocallable(g);
}

ret = do_compile_modsingle(*parent, component, ci,
GROUPTYPE_SIMPLE,
modname);
dump_tree(component, ret);
return ret;
}
Expand Down Expand Up @@ -2422,34 +2451,14 @@ modcallable *compile_modgroup(modcallable *parent,
return ret;
}

void add_to_modcallable(modcallable **parent, modcallable *this,
rlm_components_t component, char const *name)
void add_to_modcallable(modcallable *parent, modcallable *this)
{
modgroup *g;

rad_assert(this != NULL);
rad_assert(parent != NULL);

if (*parent == NULL) {
modcallable *c;

g = rad_malloc(sizeof *g);
memset(g, 0, sizeof(*g));
g->grouptype = GROUPTYPE_SIMPLE;
c = mod_grouptocallable(g);
c->next = NULL;
memcpy(c->actions,
defaultactions[component][GROUPTYPE_SIMPLE],
sizeof(c->actions));
rad_assert(name != NULL);
c->name = name;
c->type = MOD_GROUP;
c->method = component;
g->children = NULL;

*parent = mod_grouptocallable(g);
} else {
g = mod_callabletogroup(*parent);
}
g = mod_callabletogroup(parent);

add_child(g, this);
}
Expand Down
92 changes: 40 additions & 52 deletions src/main/modules.c
Expand Up @@ -885,7 +885,6 @@ static int load_component_section(CONF_SECTION *cs,
int idx;
indexed_modcallable *subcomp;
char const *modname;
char const *visiblename;
DICT_ATTR const *da;

/*
Expand Down Expand Up @@ -971,46 +970,6 @@ static int load_component_section(CONF_SECTION *cs,
continue; /* ignore it */
}

/*
* Try to compile one entry.
*/
this = compile_modsingle(NULL, comp, modref, &modname);

/*
* It's OK for the module to not exist.
*/
if (!this && modname && (modname[0] == '-')) {
int i;

if (last_ignored < 0) {
save_complain:
last_ignored++;
ignored[last_ignored] = modname;

complain:
WDEBUG("Ignoring \"%s\" (see raddb/mods-available/README.rst)", modname + 1);
continue;
}

if (last_ignored >= MAX_IGNORED) goto complain;

for (i = 0; i <= last_ignored; i++) {
if (strcmp(ignored[i], modname) == 0) {
break;
}
}

if (i > last_ignored) goto save_complain;
continue;
}

if (!this) {
cf_log_err_cs(cs,
"Errors parsing %s section.\n",
cf_section_name1(cs));
return -1;
}

/*
* Look for Auth-Type foo {}, which are special
* cases of named sections, and allowable ONLY
Expand All @@ -1027,7 +986,6 @@ static int load_component_section(CONF_SECTION *cs,
} else {
modrefname = cf_section_name2(scs);
if (!modrefname) {
modcallable_free(&this);
cf_log_err_cs(cs,
"Errors parsing %s sub-section.\n",
cf_section_name1(scs));
Expand All @@ -1041,7 +999,6 @@ static int load_component_section(CONF_SECTION *cs,
* It's a section, but nothing we
* recognize. Die!
*/
modcallable_free(&this);
cf_log_err_cs(cs,
"Unknown Auth-Type \"%s\" in %s sub-section.",
modrefname, section_type_value[comp].section);
Expand All @@ -1055,18 +1012,49 @@ static int load_component_section(CONF_SECTION *cs,
}

subcomp = new_sublist(cs, components, comp, idx);
if (subcomp == NULL) {
modcallable_free(&this);
if (!subcomp) continue;

/*
* Try to compile one entry.
*/
this = compile_modsingle(&subcomp->modulelist, comp, modref, &modname);

/*
* It's OK for the module to not exist.
*/
if (!this && modname && (modname[0] == '-')) {
int i;

if (last_ignored < 0) {
save_complain:
last_ignored++;
ignored[last_ignored] = modname;

complain:
WDEBUG("Ignoring \"%s\" (see raddb/mods-available/README.rst)", modname + 1);
continue;
}

if (last_ignored >= MAX_IGNORED) goto complain;

for (i = 0; i <= last_ignored; i++) {
if (strcmp(ignored[i], modname) == 0) {
break;
}
}

if (i > last_ignored) goto save_complain;
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);
if (!this) {
cf_log_err_cs(cs,
"Errors parsing %s section.\n",
cf_section_name1(cs));
return -1;
}

add_to_modcallable(subcomp->modulelist, this);
}

return 0;
Expand Down

0 comments on commit 1eff459

Please sign in to comment.