Add all home_servers in the configuration.
[freeradius.git] / src / main / realms.c
index 37ceb48..2994cb8 100644 (file)
@@ -399,7 +399,7 @@ static void null_free(UNUSED void *data)
 {
 }
 
-static int home_server_add(realm_config_t *rc, CONF_SECTION *cs, int pool_type)
+static int home_server_add(realm_config_t *rc, CONF_SECTION *cs)
 {
        const char *name2;
        home_server *home;
@@ -409,13 +409,6 @@ static int home_server_add(realm_config_t *rc, CONF_SECTION *cs, int pool_type)
        free(hs_virtual_server); /* used only for printing during parsing */
        hs_virtual_server = NULL;
 
-       name2 = cf_section_name1(cs);
-       if (!name2 || (strcasecmp(name2, "home_server") != 0)) {
-               cf_log_err(cf_sectiontoitem(cs),
-                          "Section is not a home_server.");
-               return 0;
-       }
-
        name2 = cf_section_name2(cs);
        if (!name2) {
                cf_log_err(cf_sectiontoitem(cs),
@@ -537,18 +530,10 @@ static int home_server_add(realm_config_t *rc, CONF_SECTION *cs, int pool_type)
        if (strcasecmp(hs_type, "auth") == 0) {
                home->type = HOME_TYPE_AUTH;
                if (home->no_response_fail == 2) home->no_response_fail = 0;
-               if (pool_type != home->type) {
-               mismatch:
-                       cf_log_err(cf_sectiontoitem(cs),
-                                  "Home server %s of unexpected type \"%s\"",
-                                  name2, hs_type);
-                       goto error;
-               }
 
        } else if (strcasecmp(hs_type, "acct") == 0) {
                home->type = HOME_TYPE_ACCT;
                if (home->no_response_fail == 2) home->no_response_fail = 1;
-               if (pool_type != home->type) goto mismatch;
 
        } else if (strcasecmp(hs_type, "auth+acct") == 0) {
                home->type = HOME_TYPE_AUTH;
@@ -559,8 +544,6 @@ static int home_server_add(realm_config_t *rc, CONF_SECTION *cs, int pool_type)
                home->type = HOME_TYPE_COA;
                dual = FALSE;
 
-               if (pool_type != home->type) goto mismatch;
-
                if (home->server != NULL) {
                        cf_log_err(cf_sectiontoitem(cs),
                                   "Home servers of type \"coa\" cannot point to a virtual server");
@@ -852,10 +835,6 @@ static int pool_check_home_server(realm_config_t *rc, CONF_PAIR *cp,
                return 0;
        }
        
-       if (!home_server_add(rc, server_cs, server_type)) {
-               return 0;
-       }
-       
        home = rbtree_finddata(home_servers_byname, &myhome);
        if (!home) {
                cf_log_err(cf_pairtoitem(cp),
@@ -1816,6 +1795,16 @@ int realms_init(CONF_SECTION *config)
        }
 #endif
 
+       for (cs = cf_subsection_find_next(config, NULL, "home_server");
+            cs != NULL;
+            cs = cf_subsection_find_next(config, cs, "home_server")) {
+               if (!home_server_add(rc, cs)) {
+                       free(rc);
+                       realms_free();
+                       return 0;
+               }
+       }
+
        for (cs = cf_subsection_find_next(config, NULL, "realm");
             cs != NULL;
             cs = cf_subsection_find_next(config, cs, "realm")) {
@@ -1847,22 +1836,6 @@ int realms_init(CONF_SECTION *config)
                        return 0;
                }
        }
-
-       /*
-        *      CoA home servers aren't tied to realms.
-        */
-       for (cs = cf_subsection_find_next(config, NULL, "home_server");
-            cs != NULL;
-            cs = cf_subsection_find_next(config, cs, "home_server")) {
-               /*
-                *      Server was already loaded.
-                */
-               if (cf_data_find(cs, "home_server")) continue;
-
-               if (!home_server_add(rc, cs, HOME_TYPE_COA)) {
-                       return 0;
-               }
-       }
 #endif