From: Alan T. DeKok Date: Wed, 27 Apr 2011 07:41:08 +0000 (+0200) Subject: Load the default virtual server before any others X-Git-Tag: release_2_1_11~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a356d1ddef385cf61903deb9840df201a0476f75;p=thirdparty%2Ffreeradius-server.git Load the default virtual server before any others This avoids user surprise --- diff --git a/src/main/modules.c b/src/main/modules.c index aeb55fc8e3c..39f441fdf37 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -1004,7 +1004,7 @@ static int load_byserver(CONF_SECTION *cs) subcs = cf_section_sub_find(cs, section_type_value[comp].section); if (!subcs) continue; - + if (cf_item_find_next(subcs, NULL) == NULL) continue; /* @@ -1053,7 +1053,7 @@ static int load_byserver(CONF_SECTION *cs) subsubcs = cf_itemtosection(modref); name1 = cf_section_name1(subsubcs); - + if (strcmp(name1, section_type_value[comp].typename) == 0) { if (!define_type(dattr, cf_section_name2(subsubcs))) { @@ -1206,23 +1206,43 @@ static int load_byserver(CONF_SECTION *cs) */ int virtual_servers_load(CONF_SECTION *config) { - int null_server = FALSE; CONF_SECTION *cs; static int first_time = TRUE; DEBUG2("%s: #### Loading Virtual Servers ####", mainconfig.name); + /* + * If we have "server { ...}", then there SHOULD NOT be + * bare "authorize", etc. sections. if there is no such + * server, then try to load the old-style sections first. + * + * In either case, load the "default" virtual server first. + * this matches better iwth users expectations. + */ + cs = cf_section_find_name2(config, "server", NULL); + if (!cs) { + if (load_byserver(config) < 0) { + return -1; + } + } else { + if (load_byserver(cs) < 0) { + return -1; + } + } + /* * Load all of the virtual servers. */ for (cs = cf_subsection_find_next(config, NULL, "server"); cs != NULL; cs = cf_subsection_find_next(config, cs, "server")) { + const char *name2; virtual_server_t *server; - if (!cf_section_name2(cs)) null_server = TRUE; + name2 = cf_section_name2(cs); + if (!name2) continue; /* handled above */ - server = virtual_server_find(cf_section_name2(cs)); + server = virtual_server_find(name2); if (server) { radlog(L_ERR, "Duplicate virtual server \"%s\" in file %s:%d and file %s:%d", server->name, @@ -1244,16 +1264,6 @@ int virtual_servers_load(CONF_SECTION *config) } } - /* - * No empty server defined. Try to load an old-style - * one for backwards compatibility. - */ - if (!null_server) { - if (load_byserver(config) < 0) { - return -1; - } - } - /* * If we succeed the first time around, remember that. */