Allow "no overwrite" for config variables
authorAlan T. DeKok <aland@freeradius.org>
Sun, 26 Jan 2014 14:42:44 +0000 (09:42 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 26 Jan 2014 14:43:56 +0000 (09:43 -0500)
This allows variables to be set from the command line.  Then,
when the config files are read, they entries in the files are
ignored

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

index f16ba26..10679f3 100644 (file)
@@ -38,6 +38,7 @@ typedef struct conf_data CONF_DATA;
 #define PW_TYPE_DEPRECATED     (1 << 10)
 #define PW_TYPE_REQUIRED       (1 << 11)
 #define PW_TYPE_ATTRIBUTE      (1 << 12)
+#define PW_TYPE_NO_OVERWRITE    (1 << 13)
 
 typedef struct CONF_PARSER {
   char const *name;
index 04b5171..e8f625c 100644 (file)
@@ -869,7 +869,7 @@ static char const *parse_spaces = "
 int cf_item_parse(CONF_SECTION *cs, char const *name, int type, void *data, char const *dflt)
 {
        int rcode;
-       bool deprecated, required, attribute;
+       bool deprecated, required, attribute, no_overwrite;
        char **q;
        char const *value;
        fr_ipaddr_t ipaddr;
@@ -881,6 +881,7 @@ int cf_item_parse(CONF_SECTION *cs, char const *name, int type, void *data, char
        deprecated = (type & PW_TYPE_DEPRECATED);
        required = (type & PW_TYPE_REQUIRED);
        attribute = (type & PW_TYPE_ATTRIBUTE);
+       no_overwrite = (type & PW_TYPE_NO_OVERWRITE);
 
        type &= 0xff;           /* normal types are small */
        rcode = 0;
@@ -951,6 +952,16 @@ int cf_item_parse(CONF_SECTION *cs, char const *name, int type, void *data, char
        case PW_TYPE_STRING_PTR:
                q = (char **) data;
                if (*q != NULL) {
+                       /*
+                        *      Don't over-write something we got from
+                        *      the command line.
+                        */
+                       if (no_overwrite) {
+                               cf_log_info(cs, "%.*s\t%s = \"%s\"",
+                                           cs->depth, parse_spaces, name, *q);
+                               break;
+                       }
+
                        talloc_free(*q);
                }
 
index c62b5ba..6810a59 100644 (file)
@@ -163,6 +163,8 @@ static const CONF_PARSER server_config[] = {
        { "logdir",          PW_TYPE_STRING_PTR, 0, &radlog_dir,        "${localstatedir}/log"},
        { "run_dir",        PW_TYPE_STRING_PTR, 0, &run_dir,       "${localstatedir}/run/${name}"},
        { "libdir",          PW_TYPE_STRING_PTR, 0, &radlib_dir,        "${prefix}/lib"},
+       { "dict_dir",           PW_TYPE_STRING_PTR | PW_TYPE_NO_OVERWRITE, 0,
+         &mainconfig.dictionary_dir, "${prefix}/share" },
        { "radacctdir",  PW_TYPE_STRING_PTR, 0, &radacct_dir,       "${logdir}/radacct" },
        { "hostname_lookups",   PW_TYPE_BOOLEAN,    0, &fr_dns_lookups,      "no" },
        { "max_request_time", PW_TYPE_INTEGER, 0, &mainconfig.max_request_time, STRINGIFY(MAX_REQUEST_TIME) },