From 7a1af48ee91d6eee1a63df06b7fb42c82ecf4a58 Mon Sep 17 00:00:00 2001 From: aland Date: Mon, 3 Sep 2007 09:32:52 +0000 Subject: [PATCH] Whoops.. old-style realms tried to create pools sized by the sub-sections named "realm" of the current realm, which didn't exist. Add a new API to get the next matching section from the parent of the section we have. It now works. --- src/include/conffile.h | 3 +++ src/main/conffile.c | 18 +++++++++++++++++- src/main/realms.c | 10 ++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/include/conffile.h b/src/include/conffile.h index 6ab926d..646e077 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -76,6 +76,9 @@ int dump_config(void); CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section, CONF_SECTION *subsection, const char *name1); +CONF_SECTION *cf_section_find_next(CONF_SECTION *section, + CONF_SECTION *subsection, + const char *name1); int cf_section_lineno(CONF_SECTION *section); int cf_pair_lineno(CONF_PAIR *pair); const char *cf_pair_filename(CONF_PAIR *pair); diff --git a/src/main/conffile.c b/src/main/conffile.c index 5eb9f44..fdb0a8b 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -1336,7 +1336,7 @@ static int cf_section_read(const char *filename, int *lineno, FILE *fp, server = server->item.parent; } - if (!server) { + if (0 && !server) { radlog(L_ERR, "%s[%d]: Processing directives such as \"%s\" cannot be used here.", filename, *lineno, buf1); return -1; @@ -1792,6 +1792,22 @@ CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section, return cf_itemtosection(ci); } + +/* + * Return the next section after a CONF_SECTION + * with a certain name1 (char *name1). If the requested + * name1 is NULL, any name1 matches. + */ + +CONF_SECTION *cf_section_find_next(CONF_SECTION *section, + CONF_SECTION *subsection, + const char *name1) +{ + if (!section->item.parent) return NULL; + + return cf_subsection_find_next(section->item.parent, subsection, name1); +} + /* * Return the next item after a CONF_ITEM. */ diff --git a/src/main/realms.c b/src/main/realms.c index 2d8e5de..5c553a3 100644 --- a/src/main/realms.c +++ b/src/main/realms.c @@ -806,15 +806,21 @@ static int old_server_add(CONF_SECTION *cs, const char *realm, * Count the old-style realms of this name. */ num_home_servers = 0; - for (subcs = cf_subsection_find_next(cs, NULL, "realm"); + for (subcs = cf_section_find_next(cs, NULL, "realm"); subcs != NULL; - subcs = cf_subsection_find_next(cs, subcs, "realm")) { + subcs = cf_section_find_next(cs, subcs, "realm")) { const char *this = cf_section_name2(subcs); if (!this || (strcmp(this, realm) != 0)) continue; num_home_servers++; } + if (num_home_servers == 0) { + cf_log_err(cf_sectiontoitem(cs), "Internal error counting pools for home server %s.", name); + free(home); + return 0; + } + pool = rad_malloc(sizeof(*pool) + num_home_servers * sizeof(pool->servers[0])); memset(pool, 0, sizeof(*pool) + num_home_servers * sizeof(pool->servers[0])); -- 2.1.4