Patch from "Alan Curry" <pacman-radius@cqc.com>
authoraland <aland>
Fri, 18 Aug 2000 17:31:22 +0000 (17:31 +0000)
committeraland <aland>
Fri, 18 Aug 2000 17:31:22 +0000 (17:31 +0000)
2. Make cf_section_parse always fill in default values for variables that
   aren't present in the config file. This fixes the bug where you set a
   variable to an odd value, then delete it from the config file and HUP
   doesn't notice the change.

src/include/conffile.h
src/main/conffile.c
src/main/modules.c
src/main/radiusd.c
src/main/threads.c
src/modules/rlm_example/rlm_example.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_unix/rlm_unix.c

index 98f1cc7..be2c50f 100644 (file)
@@ -39,8 +39,13 @@ typedef struct CONF_PARSER {
   const char *name;
   int type;                    /* PW_TYPE_STRING, etc. */
   void *data;                  /* pointer to where to put it */
+  const char *dflt;            /* default as it would appear in radiusd.conf */
 } CONF_PARSER;
 
+/* This preprocessor trick will be useful in initializing CONF_PARSER struct */
+#define XStringify(x) #x
+#define Stringify(x) XStringify(x)
+
 CONF_SECTION   *conf_read(const char *conffile);
 CONF_PAIR      *cf_pair_alloc(const char *attr, const char *value, int operator);
 void           cf_pair_add(CONF_SECTION *cs, CONF_PAIR *cp_new);
index 3138e04..41ee880 100644 (file)
@@ -117,7 +117,7 @@ void cf_section_free(CONF_SECTION *cs)
        }
 
        /*
-        * Clear out any possible subsections aswell
+        * Clear out any possible subsections as well
         */
        for (sub = cs->sub; sub; sub = next_sub) {
                next_sub = sub->next;
@@ -143,14 +143,17 @@ int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
        CONF_PAIR       *cp;
        uint32_t        ipaddr;
        char            buffer[1024];
+       const char      *value;
 
        /*
         *      Handle the user-supplied variables.
         */
        for (i = 0; variables[i].name != NULL; i++) {
+               value = variables[i].dflt;
+
                cp = cf_pair_find(cs, variables[i].name);
-               if (!cp) {
-                       continue;
+               if (cp) {
+                       value = cp->value;
                }
                
                switch (variables[i].type)
@@ -159,25 +162,25 @@ int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
                        /*
                         *      Allow yes/no and on/off
                         */
-                       if ((strcasecmp(cp->value, "yes") == 0) ||
-                           (strcasecmp(cp->value, "on") == 0)) {
+                       if ((strcasecmp(value, "yes") == 0) ||
+                           (strcasecmp(value, "on") == 0)) {
                                *(int *)variables[i].data = 1;
-                       } else if ((strcasecmp(cp->value, "no") == 0) ||
-                                  (strcasecmp(cp->value, "off") == 0)) {
+                       } else if ((strcasecmp(value, "no") == 0) ||
+                                  (strcasecmp(value, "off") == 0)) {
                                *(int *)variables[i].data = 0;
                        } else {
                                *(int *)variables[i].data = 0;
-                               log(L_ERR, "Bad value \"%s\" for boolean variable %s", cp->value, cp->attr);
+                               log(L_ERR, "Bad value \"%s\" for boolean variable %s", value, variables[i].name);
                                return -1;
                        }
                        DEBUG2("Config: %s.%s = %s",
                               cs->name1,
                               variables[i].name,
-                              cp->value);
+                              value);
                        break;
 
                case PW_TYPE_INTEGER:
-                       *(int *)variables[i].data = atoi(cp->value);
+                       *(int *)variables[i].data = strtol(value, 0, 0);
                        DEBUG2("Config: %s.%s = %d",
                               cs->name1,
                               variables[i].name,
@@ -192,27 +195,27 @@ int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
                        DEBUG2("Config: %s.%s = \"%s\"",
                               cs->name1,
                               variables[i].name,
-                              cp->value);
-                       *q = strdup(cp->value);
+                              value ? value : "(null)");
+                       *q = value ? strdup(value) : NULL;
                        break;
 
                case PW_TYPE_IPADDR:
                        /*
                         *      Allow '*' as any address
                         */
-                       if (strcmp(cp->value, "*") == 0) {
+                       if (strcmp(value, "*") == 0) {
                                *(uint32_t *) variables[i].data = 0;
                                break;
                        }
-                       ipaddr = ip_getaddr(cp->value);
+                       ipaddr = ip_getaddr(value);
                        if (ipaddr == 0) {
-                               log(L_ERR, "Can't find IP address for host %s", cp->value);
+                               log(L_ERR, "Can't find IP address for host %s", value);
                                return -1;
                        }
                        DEBUG2("Config: %s.%s = %s IP address [%s]",
                               cs->name1,
                               variables[i].name,
-                              cp->value, ip_ntoa(buffer, ipaddr));
+                              value, ip_ntoa(buffer, ipaddr));
                        *(uint32_t *) variables[i].data = ipaddr;
                        break;
                        
index 3c3b5da..4c5876e 100644 (file)
@@ -175,10 +175,11 @@ static int new_authtype_value(const char *name)
   return new_value->value;
 }
 
+/* Why is this both here and in radiusd.c:server_config? --Pac. */
 static CONF_PARSER module_config[] = {
-  { "lib_dir",            PW_TYPE_STRING_PTR, &radlib_dir },
+  { "lib_dir",            PW_TYPE_STRING_PTR, &radlib_dir,        LIBDIR },
 
-  { NULL, -1, NULL}
+  { NULL, -1, NULL, NULL }
 };
 
 /*
index 465b618..0745331 100644 (file)
@@ -141,36 +141,42 @@ extern int        rad_spawn_child(REQUEST *, RAD_REQUEST_FUNP);
  *     A mapping of configuration file names to internal variables
  */
 static CONF_PARSER server_config[] = {
-  { "max_request_time",   PW_TYPE_INTEGER,    &max_request_time },
-  { "cleanup_delay",      PW_TYPE_INTEGER,    &cleanup_delay    },
-  { "max_requests",       PW_TYPE_INTEGER,    &max_requests     },
-  { "port",               PW_TYPE_INTEGER,    &auth_port },
-  { "allow_core_dumps",   PW_TYPE_BOOLEAN,    &allow_core_dumps },
-  { "log_stripped_names", PW_TYPE_BOOLEAN,    &log_stripped_names },
-  { "log_auth",           PW_TYPE_BOOLEAN,    &log_auth },
-  { "log_auth_pass",      PW_TYPE_BOOLEAN,    &log_auth_pass },
-  { "pidfile",            PW_TYPE_STRING_PTR, &pid_file },
-  { "log_dir",            PW_TYPE_STRING_PTR, &radlog_dir },
-  { "lib_dir",            PW_TYPE_STRING_PTR, &radlib_dir },
-  { "acct_dir",           PW_TYPE_STRING_PTR, &radacct_dir },
-  { "bind_address",       PW_TYPE_IPADDR,     &myip },
-  { "proxy_requests",     PW_TYPE_BOOLEAN,    &proxy_requests },
+  { "max_request_time",   PW_TYPE_INTEGER,
+    &max_request_time,    Stringify(MAX_REQUEST_TIME) },
+  { "cleanup_delay",      PW_TYPE_INTEGER,
+    &cleanup_delay,       Stringify(CLEANUP_DELAY) },
+  { "max_requests",       PW_TYPE_INTEGER,
+    &max_requests,       Stringify(MAX_REQUESTS) },
+  { "port",               PW_TYPE_INTEGER,
+    &auth_port,                  Stringify(PW_AUTH_UDP_PORT) },
+  { "allow_core_dumps",   PW_TYPE_BOOLEAN,    &allow_core_dumps,  "no" },
+  { "log_stripped_names", PW_TYPE_BOOLEAN,    &log_stripped_names,"no" },
+  { "log_auth",           PW_TYPE_BOOLEAN,    &log_auth,          "no" },
+  { "log_auth_pass",      PW_TYPE_BOOLEAN,    &log_auth_pass,     "no" },
+  { "pidfile",            PW_TYPE_STRING_PTR, &pid_file,          RADIUS_PID },
+  { "log_dir",            PW_TYPE_STRING_PTR, &radlog_dir,        RADLOG_DIR },
+  { "lib_dir",            PW_TYPE_STRING_PTR, &radlib_dir,        LIBDIR },
+  { "acct_dir",           PW_TYPE_STRING_PTR, &radacct_dir,       RADACCT_DIR },
+  { "bind_address",       PW_TYPE_IPADDR,     &myip,              "*" },
+  { "proxy_requests",     PW_TYPE_BOOLEAN,    &proxy_requests,    "yes" },
 #if 0
-  { "confdir",            PW_TYPE_STRING_PTR, &radius_dir },
+  { "confdir",            PW_TYPE_STRING_PTR, &radius_dir,        RADIUS_DIR },
 #endif
 
-  { NULL, -1, NULL}
+  { 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 },
-  { "retry_count",  PW_TYPE_INTEGER,    &proxy_retry_count },
-  { "synchonous",   PW_TYPE_BOOLEAN,    &proxy_synchronous },
+  { "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, -1, NULL, NULL }
 };
 
 /*
@@ -203,7 +209,7 @@ static void reread_config(int reload)
        /*
         *      And parse the server's configuration values.
         */
-       cs = cf_section_find("main");
+       cs = cf_section_find(NULL);
        if (!cs)
                return;
 
@@ -413,11 +419,7 @@ int main(int argc, char **argv)
 
        debug_flag = 0;
        spawn_flag = TRUE;
-       radacct_dir = strdup(RADACCT_DIR);
        radius_dir = strdup(RADIUS_DIR);
-       radlog_dir = strdup(RADLOG_DIR);
-       radlib_dir = strdup(LIBDIR);
-       pid_file = strdup(RADIUS_PID);
 
        signal(SIGHUP, sig_hup);
        signal(SIGINT, sig_fatal);
index 9845b36..81001d6 100644 (file)
@@ -80,13 +80,18 @@ static THREAD_POOL thread_pool;
  *     A mapping of configuration file names to internal integers
  */
 static const CONF_PARSER thread_config[] = {
-       { "start_servers",       PW_TYPE_INTEGER, &thread_pool.start_threads}, 
-       { "max_servers",         PW_TYPE_INTEGER, &thread_pool.max_threads}, 
-       { "min_spare_servers",   PW_TYPE_INTEGER, &thread_pool.min_spare_threads}, 
-       { "max_spare_servers",   PW_TYPE_INTEGER, &thread_pool.max_spare_threads}, 
-       { "max_requests_per_server", PW_TYPE_INTEGER, &thread_pool.max_requests_per_thread}, 
+       { "start_servers",                      PW_TYPE_INTEGER,
+         &thread_pool.start_threads,           "5" }, 
+       { "max_servers",                        PW_TYPE_INTEGER,
+         &thread_pool.max_threads,             "32" }, 
+       { "min_spare_servers",                  PW_TYPE_INTEGER,
+         &thread_pool.min_spare_threads,       "3" }, 
+       { "max_spare_servers",                  PW_TYPE_INTEGER,
+         &thread_pool.max_spare_threads,       "10" }, 
+       { "max_requests_per_server",            PW_TYPE_INTEGER,
+         &thread_pool.max_requests_per_thread, "0"}, 
        
-       { NULL, -1, NULL}
+       { NULL, -1, NULL, NULL }
 };
 
 /*
@@ -384,11 +389,6 @@ int thread_pool_init(void)
        thread_pool.head = NULL;
        thread_pool.tail = NULL;
        thread_pool.total_threads = 0;
-       thread_pool.start_threads = 5;
-       thread_pool.max_threads = 32;
-       thread_pool.min_spare_threads = 3;
-       thread_pool.max_spare_threads = 10;
-       thread_pool.max_requests_per_thread = 0; /* infinity */
 
        pool_cf = cf_section_find("thread");
        if (pool_cf) {
index 651986c..ac867aa 100644 (file)
@@ -23,15 +23,10 @@ typedef struct example_config_t {
 } example_config_t;
 
 /*
- *     Define the local copy of our example configuration,
- *     and initialize it so some values.
+ *     Define the local copy of our example configuration.
+ *     Initialization will be done by the CONF_PARSER.
  */
-static example_config_t config = {
-       FALSE,                  /* boolean */
-       1,                      /* integer */
-       NULL,                   /* string */
-       0                       /* IP address */
-};
+static example_config_t config;
 
 /*
  *     A mapping of configuration file names to internal variables.
@@ -43,12 +38,12 @@ static example_config_t config = {
  *     buffer over-flows.
  */
 static CONF_PARSER module_config[] = {
-  { "integer", PW_TYPE_INTEGER,    &config.value },
-  { "boolean", PW_TYPE_BOOLEAN,    &config.boolean },
-  { "string",  PW_TYPE_STRING_PTR, &config.string },
-  { "ipaddr",  PW_TYPE_IPADDR,     &config.ipaddr },
+  { "integer", PW_TYPE_INTEGER,    &config.value,   "1" },
+  { "boolean", PW_TYPE_BOOLEAN,    &config.boolean, "no" },
+  { "string",  PW_TYPE_STRING_PTR, &config.string,  NULL },
+  { "ipaddr",  PW_TYPE_IPADDR,     &config.ipaddr,  "*" },
 
-  { NULL, -1, NULL}            /* end the list */
+  { NULL, -1, NULL, NULL }             /* end the list */
 };
 
 /*
index 99fa228..5550fef 100644 (file)
@@ -102,21 +102,21 @@ static int cleanup;
 static int readers; /* number of threads performing LDAP lookups */ 
 
 static CONF_PARSER ldap_config[] = {
-  { "server",          PW_TYPE_STRING_PTR,     &ldap_server },
-  { "port",            PW_TYPE_INTEGER,        &ldap_port },
-  { "net_timeout",     PW_TYPE_INTEGER,        &ldap_net_timeout.tv_sec},
-  { "timeout",         PW_TYPE_INTEGER,        &ldap_timeout.tv_sec},
-
-  { "identity",                PW_TYPE_STRING_PTR,     &ldap_login },
-  { "password",                PW_TYPE_STRING_PTR,     &ldap_password },
-  { "basedn",          PW_TYPE_STRING_PTR,     &ldap_basedn },
-  { "filter",          PW_TYPE_STRING_PTR,     &ldap_filter },
-  { "access_group",    PW_TYPE_STRING_PTR,     &ldap_radius_group },
-
-  { "cache_size",      PW_TYPE_INTEGER,        &ldap_cache_size },
-  { "cache_ttl",       PW_TYPE_INTEGER,        &ldap_cache_ttl },
+  { "server",          PW_TYPE_STRING_PTR, &ldap_server,             NULL },
+  { "port",            PW_TYPE_INTEGER,    &ldap_port,               "389" },
+  { "net_timeout",     PW_TYPE_INTEGER,    &ldap_net_timeout.tv_sec, "-1" },
+  { "timeout",         PW_TYPE_INTEGER,    &ldap_timeout.tv_sec,     "-1" },
+
+  { "identity",                PW_TYPE_STRING_PTR, &ldap_login,              NULL },
+  { "password",                PW_TYPE_STRING_PTR, &ldap_password,           NULL },
+  { "basedn",          PW_TYPE_STRING_PTR, &ldap_basedn,             NULL },
+  { "filter",          PW_TYPE_STRING_PTR, &ldap_filter,             NULL },
+  { "access_group",    PW_TYPE_STRING_PTR, &ldap_radius_group,       NULL },
+
+  { "cache_size",      PW_TYPE_INTEGER,    &ldap_cache_size,         "0" },
+  { "cache_ttl",       PW_TYPE_INTEGER,    &ldap_cache_ttl,          "30" },
   
-  { NULL, -1, NULL}
+  { NULL, -1, NULL, NULL }
 };
 
 /* LDAP attribute name that controls remote access */
index 0c0cf1c..2fb87aa 100644 (file)
@@ -51,25 +51,43 @@ static SQL_CONFIG config = {
 };
 
 static CONF_PARSER module_config[] = {
-        { "sensitiveusername", PW_TYPE_BOOLEAN , &config.sensitiveusername},
-        { "deletestalesessions", PW_TYPE_BOOLEAN , &config.deletestalesessions },
-        { "sqltrace", PW_TYPE_BOOLEAN , &config.sqltrace },
-        { "max_sql_socks", PW_TYPE_INTEGER , &config.max_sql_socks },
-        { "server", PW_TYPE_STRING_PTR , &config.sql_server },
-        { "login", PW_TYPE_STRING_PTR , &config.sql_login },
-        { "password", PW_TYPE_STRING_PTR , &config.sql_password },
-        { "db", PW_TYPE_STRING_PTR , &config.sql_db },
-        { "authcheck_table", PW_TYPE_STRING_PTR , &config.sql_authcheck_table },
-        { "authreply_table", PW_TYPE_STRING_PTR , &config.sql_authreply_table },
-        { "groupcheck_table", PW_TYPE_STRING_PTR , &config.sql_groupcheck_table },
-        { "groupreply_table", PW_TYPE_STRING_PTR , &config.sql_groupreply_table },
-        { "usergroup_table", PW_TYPE_STRING_PTR , &config.sql_usergroup_table },
-        { "realmgroup_table", PW_TYPE_STRING_PTR , &config.sql_realmgroup_table },
-        { "acct_table", PW_TYPE_STRING_PTR , &config.sql_acct_table },
-        { "nas_table", PW_TYPE_STRING_PTR , &config.sql_nas_table },
-        { "realm_table", PW_TYPE_STRING_PTR , &config.sql_realm_table },
-        { "dict_table", PW_TYPE_STRING_PTR , &config.sql_dict_table },
-       { NULL, -1, NULL}
+        { "sensitiveusername",         PW_TYPE_BOOLEAN,
+         &config.sensitiveusername,    "1" },
+        { "deletestalesessions",       PW_TYPE_BOOLEAN,
+         &config.deletestalesessions,  "0" },
+        { "sqltrace",                  PW_TYPE_BOOLEAN,
+         &config.sqltrace,             "0" },
+        { "max_sql_socks",             PW_TYPE_INTEGER,
+         &config.max_sql_socks,        Stringify(MAX_SQL_SOCKS) },
+        { "server",                    PW_TYPE_STRING_PTR,
+         &config.sql_server,           "localhost" },
+        { "login",                     PW_TYPE_STRING_PTR,
+         &config.sql_login,            "" },
+        { "password",                  PW_TYPE_STRING_PTR,
+         &config.sql_password,         "" },
+        { "db",                                PW_TYPE_STRING_PTR,
+         &config.sql_db,               "radius" },
+        { "authcheck_table",           PW_TYPE_STRING_PTR,
+         &config.sql_authcheck_table,  "radcheck" },
+        { "authreply_table",           PW_TYPE_STRING_PTR,
+         &config.sql_authreply_table,  "radreply" },
+        { "groupcheck_table",          PW_TYPE_STRING_PTR,
+         &config.sql_groupcheck_table, "radgroupcheck" },
+        { "groupreply_table",          PW_TYPE_STRING_PTR,
+         &config.sql_groupreply_table, "radgroupreply" },
+        { "usergroup_table",           PW_TYPE_STRING_PTR,
+         &config.sql_usergroup_table,  "usergroup" },
+        { "realmgroup_table",          PW_TYPE_STRING_PTR,
+         &config.sql_realmgroup_table, "realmgroup" },
+        { "acct_table",                        PW_TYPE_STRING_PTR,
+         &config.sql_acct_table,       "radacct" },
+        { "nas_table",                 PW_TYPE_STRING_PTR,
+         &config.sql_nas_table,        "nas" },
+        { "realm_table",               PW_TYPE_STRING_PTR,
+         &config.sql_realm_table,      "realms" },
+        { "dict_table",                        PW_TYPE_STRING_PTR,
+         &config.sql_dict_table,       "dictionary" },
+       { NULL, -1, NULL, NULL }
 };
 
 
index 2374d13..8ff88ce 100644 (file)
@@ -57,12 +57,12 @@ static char *shadow_file = NULL;
 static char *group_file = NULL;
 
 static CONF_PARSER module_config[] = {
-       { "cache",  PW_TYPE_BOOLEAN,    &cache_passwd },
-       { "passwd", PW_TYPE_STRING_PTR, &passwd_file },
-       { "shadow", PW_TYPE_STRING_PTR, &shadow_file },
-       { "group",  PW_TYPE_STRING_PTR, &group_file },
+       { "cache",  PW_TYPE_BOOLEAN,    &cache_passwd, "yes" },
+       { "passwd", PW_TYPE_STRING_PTR, &passwd_file,  NULL },
+       { "shadow", PW_TYPE_STRING_PTR, &shadow_file,  NULL },
+       { "group",  PW_TYPE_STRING_PTR, &group_file,   NULL },
        
-       { NULL, -1, NULL}               /* end the list */
+       { NULL, -1, NULL, NULL }                /* end the list */
 };
 
 /*