added PW_TYPE_SUBSECTION for configuration file parser, so that
authoraland <aland>
Fri, 10 Nov 2000 20:51:25 +0000 (20:51 +0000)
committeraland <aland>
Fri, 10 Nov 2000 20:51:25 +0000 (20:51 +0000)
it can automagically walk through subsections, too.

src/include/conffile.h
src/main/conffile.c
src/main/radiusd.c

index 32cff84..30ed6fe 100644 (file)
@@ -24,6 +24,7 @@ typedef struct conf_part CONF_SECTION;
  */
 #define PW_TYPE_STRING_PTR     100
 #define PW_TYPE_BOOLEAN                101
+#define PW_TYPE_SUBSECTION     102
 
 typedef struct CONF_PARSER {
   const char *name;
index f6b5d35..e07455c 100644 (file)
@@ -275,8 +275,10 @@ static const char *cf_expand_variables(const char *cf, int *lineno,
 int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
 {
        int             i;
+       int             rcode;
        char            **q;
        CONF_PAIR       *cp;
+       CONF_SECTION    *subsection;
        uint32_t        ipaddr;
        char            buffer[1024];
        const char      *value;
@@ -294,6 +296,27 @@ int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
                
                switch (variables[i].type)
                {
+               case PW_TYPE_SUBSECTION:
+                       subsection = cf_section_sub_find(cs,variables[i].name);
+
+                       /*
+                        *      If the configuration section is NOT there,
+                        *      then ignore it.
+                        *
+                        *      FIXME! This is probably wrong... we should
+                        *      probably set the items to their default values.
+                        */
+                       if (!subsection) {
+                               break;
+                       }
+
+                       rcode = cf_section_parse(subsection,
+                                                (CONF_PARSER *) variables[i].data);
+                       if (rcode < 0) {
+                               return -1;
+                       }
+                       break;
+
                case PW_TYPE_BOOLEAN:
                        /*
                         *      Allow yes/no and on/off
@@ -330,11 +353,13 @@ int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
                        }
 
                        /*
-                        *      Expand variables while parsing.
+                        *      Expand variables while parsing,
+                        *      but ONLY expand ones which haven't already
+                        *      been expanded.
                         */
-                       if (value) {
-                         cf_expand_variables(NULL, 0, cs, buffer, value);
-                         value = buffer;
+                       if (value && (value == variables[i].dflt)) {
+                               cf_expand_variables(NULL, 0, cs, buffer,value);
+                               value = buffer;
                        }
 
                        DEBUG2("Config: %s.%s = \"%s\"",
index db87586..2ba50e3 100644 (file)
@@ -152,6 +152,19 @@ extern int rad_spawn_child(REQUEST *, RAD_REQUEST_FUNP);
 #endif
 
 /*
+ *     Map the proxy server configuration parameters to variables.
+ */
+static CONF_PARSER proxy_config[] = {
+  { "retry_delay",  PW_TYPE_INTEGER,
+    &proxy_retry_delay, Stringify(RETRY_DELAY) },
+  { "retry_count",  PW_TYPE_INTEGER,
+    &proxy_retry_count, Stringify(RETRY_COUNT) },
+  { "synchronous",  PW_TYPE_BOOLEAN, &proxy_synchronous, "yes" },
+
+  { NULL, -1, NULL, NULL }
+};
+
+/*
  *     A mapping of configuration file names to internal variables
  */
 static CONF_PARSER server_config[] = {
@@ -170,9 +183,9 @@ static CONF_PARSER server_config[] = {
   { "log_auth_goodpass",  PW_TYPE_BOOLEAN,    &mainconfig.log_auth_goodpass, "no" },
   { "pidfile",            PW_TYPE_STRING_PTR, &pid_file,          "${run_dir}/radiusd.pid"},
   { "bind_address",       PW_TYPE_IPADDR,     &myip,              "*" },
-  { "proxy_requests",     PW_TYPE_BOOLEAN,    &proxy_requests,    "yes" },
   { "user",           PW_TYPE_STRING_PTR, &uid_name,  NULL},
   { "group",          PW_TYPE_STRING_PTR, &gid_name,  NULL},
+
   { "usercollide",    PW_TYPE_BOOLEAN,    &mainconfig.do_usercollide, "no" },
   { "lower_user",     PW_TYPE_BOOLEAN,    &mainconfig.do_lower_user, "no" },
   { "lower_pass",     PW_TYPE_BOOLEAN,    &mainconfig.do_lower_pass, "no" },
@@ -180,19 +193,9 @@ static CONF_PARSER server_config[] = {
   { "nospace_user",   PW_TYPE_BOOLEAN,    &mainconfig.do_nospace_user, "no" },
   { "nospace_pass",   PW_TYPE_BOOLEAN,    &mainconfig.do_nospace_pass, "no" },
   { "nospace_time",   PW_TYPE_STRING_PTR, &mainconfig.nospace_time, "before" },
-  { NULL, -1, NULL, NULL }
-};
-
-/*
- *     Map the proxy server configuration parameters to variables.
- */
-static CONF_PARSER proxy_config[] = {
-  { "retry_delay",  PW_TYPE_INTEGER,
-    &proxy_retry_delay, Stringify(RETRY_DELAY) },
-  { "retry_count",  PW_TYPE_INTEGER,
-    &proxy_retry_count, Stringify(RETRY_COUNT) },
-  { "synchronous",  PW_TYPE_BOOLEAN, &proxy_synchronous, "yes" },
 
+  { "proxy_requests", PW_TYPE_BOOLEAN,    &proxy_requests,    "yes" },
+  { "proxy",          PW_TYPE_SUBSECTION, proxy_config,       NULL },
   { NULL, -1, NULL, NULL }
 };
 
@@ -313,15 +316,6 @@ static int reread_config(int reload)
                }
        }
 
-
-       /*
-        *      Parse the server's proxy configuration values.
-        */
-       if ((proxy_requests) &&
-           ((cs = cf_section_find("proxy")) != NULL)) {
-               cf_section_parse(cs, proxy_config);
-       }
-
        return 0;
 }