Replaced DEBUG2 stuff with log of config/modules, to make it
authoraland <aland>
Thu, 27 Dec 2007 05:41:40 +0000 (05:41 +0000)
committeraland <aland>
Thu, 27 Dec 2007 05:41:40 +0000 (05:41 +0000)
clear what's going on, and to have one point of control for
logging information

src/include/conffile.h
src/main/conffile.c
src/main/listen.c
src/main/modules.c
src/modules/rlm_eap/eap.c

index c0f945b..31eba43 100644 (file)
@@ -94,9 +94,14 @@ CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp);
 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs);
 int cf_section_template(CONF_SECTION *cs, CONF_SECTION *template);
 void cf_log_err(CONF_ITEM *ci, const char *fmt, ...);
+void cf_log_info(CONF_SECTION *cs, const char *fmt, ...);
+void cf_log_module(CONF_SECTION *cs, const char *fmt, ...);
 CONF_ITEM *cf_reference_item(const CONF_SECTION *parentcs,
                             CONF_SECTION *outercs,
                             const char *ptr);
+extern int cf_log_config;
+extern int cf_log_modules;
+
 /*
  *     Big magic.
  */
index d660b81..255fde1 100644 (file)
@@ -99,6 +99,9 @@ static int cf_data_add_internal(CONF_SECTION *cs, const char *name,
 static void *cf_data_find_internal(CONF_SECTION *cs, const char *name,
                                   int flag);
 
+int cf_log_config = 1;
+int cf_log_modules = 1;
+
 /*
  *     Isolate the scary casts in these tiny provably-safe functions
  */
@@ -838,12 +841,12 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                        radlog(L_ERR, "Bad value \"%s\" for boolean variable %s", value, name);
                        return -1;
                }
-               DEBUG2("\t%s = %s", name, value);
+               cf_log_info(cs, "\t%s = %s", name, value);
                break;
 
        case PW_TYPE_INTEGER:
                *(int *)data = strtol(value, 0, 0);
-               DEBUG2("\t%s = %d", name, *(int *)data);
+               cf_log_info(cs, "\t%s = %d", name, *(int *)data);
                break;
 
        case PW_TYPE_STRING_PTR:
@@ -871,7 +874,7 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                        if (!value) return -1;
                }
 
-               DEBUG2("\t%s = \"%s\"", name, value ? value : "(null)");
+               cf_log_info(cs, "\t%s = \"%s\"", name, value ? value : "(null)");
                *q = value ? strdup(value) : NULL;
                break;
 
@@ -905,7 +908,7 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                        if (!value) return -1;
                }
 
-               DEBUG2("\t%s = \"%s\"", name, value ? value : "(null)");
+               cf_log_info(cs, "\t%s = \"%s\"", name, value ? value : "(null)");
                *q = value ? strdup(value) : NULL;
 
                /*
@@ -932,7 +935,7 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                 */
                if (strcmp(value, "*") == 0) {
                        *(uint32_t *) data = htonl(INADDR_ANY);
-                       DEBUG2("\t%s = *", name);
+                       cf_log_info(cs, "\t%s = *", name);
                        break;
                }
                if (ip_hton(value, AF_INET, &ipaddr) < 0) {
@@ -941,9 +944,9 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                }
                
                if (strspn(value, "0123456789.") == strlen(value)) {
-                       DEBUG2("\t%s = %s", name, value);
+                       cf_log_info(cs, "\t%s = %s", name, value);
                } else {
-                       DEBUG2("\t%s = %s IP address [%s]", name, value,
+                       cf_log_info(cs, "\t%s = %s IP address [%s]", name, value,
                               ip_ntoh(&ipaddr, ipbuf, sizeof(ipbuf)));
                }
                *(uint32_t *) data = ipaddr.ipaddr.ip4addr.s_addr;
@@ -954,7 +957,7 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
                        radlog(L_ERR, "Can't find IPv6 address for host %s", value);
                        return -1;
                }
-               DEBUG2("\t%s = %s IPv6 address [%s]", name, value,
+               cf_log_info(cs, "\t%s = %s IPv6 address [%s]", name, value,
                               ip_ntoh(&ipaddr, ipbuf, sizeof(ipbuf)));
                memcpy(data, &ipaddr.ipaddr.ip6addr,
                       sizeof(ipaddr.ipaddr.ip6addr));
@@ -983,10 +986,10 @@ int cf_section_parse(CONF_SECTION *cs, void *base,
        cs->variables = variables; /* this doesn't hurt anything */
 
        if (!cs->name2) {
-               DEBUG2("%.*s%s {", cs->depth, parse_spaces,
+               cf_log_info(cs, "%.*s%s {", cs->depth, parse_spaces,
                       cs->name1);
        } else {
-               DEBUG2("%.*s%s %s {", cs->depth, parse_spaces,
+               cf_log_info(cs, "%.*s%s %s {", cs->depth, parse_spaces,
                       cs->name1, cs->name2);
        }
 
@@ -1040,14 +1043,14 @@ int cf_section_parse(CONF_SECTION *cs, void *base,
                }
        } /* for all variables in the configuration section */
 
-       DEBUG2("%.*s}", cs->depth, parse_spaces);
+       cf_log_info(cs, "%.*s}", cs->depth, parse_spaces);
 
        cs->base = base;
 
        return 0;
 
  error:
-       DEBUG2("%.*s}", cs->depth, parse_spaces);
+       cf_log_info(cs, "%.*s}", cs->depth, parse_spaces);
        cf_section_parse_free(cs, base);
        return -1;
 }
@@ -2324,7 +2327,8 @@ int cf_section_template(CONF_SECTION *cs, CONF_SECTION *template)
 /*
  *     This is here to make the rest of the code easier to read.  It
  *     ties conffile.c to log.c, but it means we don't have to
- *     pollute the 
+ *     pollute every other function with the knowledge of the
+ *     configuration internals.
  */
 void cf_log_err(CONF_ITEM *ci, const char *fmt, ...)
 {
@@ -2339,6 +2343,33 @@ void cf_log_err(CONF_ITEM *ci, const char *fmt, ...)
 }
 
 
+void cf_log_info(UNUSED CONF_SECTION *cs, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       if (debug_flag > 1 && cf_log_config) vradlog(L_DBG, fmt, ap);
+       va_end(ap);
+}
+
+/*
+ *     Wrapper to simplify the code.
+ */
+void cf_log_module(UNUSED CONF_SECTION *cs, const char *fmt, ...)
+{
+       va_list ap;
+       char buffer[256];
+
+       va_start(ap, fmt);
+       if (debug_flag > 1 && cf_log_modules) {
+               vsnprintf(buffer, sizeof(buffer), fmt, ap);
+
+               radlog(L_DBG, " Module: %s", buffer);
+       }
+       va_end(ap);
+}
+
+
 #if 0
 /*
  * JMG dump_config tries to dump the config structure in a readable format
index 4697e06..797b33a 100644 (file)
@@ -1052,7 +1052,7 @@ static rad_listen_t *listen_parse(CONF_SECTION *cs, const char *server)
 
        listen_type = NULL;
        
-       DEBUG2("listen {");
+       cf_log_info(cs, "listen {");
 
        rcode = cf_item_parse(cs, "type", PW_TYPE_STRING_PTR,
                              &listen_type, "");
@@ -1104,7 +1104,7 @@ static rad_listen_t *listen_parse(CONF_SECTION *cs, const char *server)
                return NULL;
        }
 
-       DEBUG2("}");
+       cf_log_info(cs, "}");
 
        return this;
 }
index be3c197..1ceb282 100644 (file)
@@ -253,7 +253,7 @@ static module_entry_t *linkto_module(const char *module_name,
        node->module = module;
        node->handle = handle;
 
-       DEBUG(" Module: Linked to module %s", module_name);
+       cf_log_module(cs, "Linked to module %s", module_name);
 
        /*
         *      Add the module as "rlm_foo-version" to the configuration
@@ -327,9 +327,9 @@ module_instance_t *find_module_instance(CONF_SECTION *modules,
 
        if (check_config && (node->entry->module->instantiate) &&
            (node->entry->module->type & RLM_TYPE_CHECK_CONFIG_SAFE) == 0) {
-               DEBUG2(" Module: Skipping instantiation of %s", instname);
+               cf_log_module(cs, "Skipping instantiation of %s", instname);
        } else {
-               DEBUG2(" Module: Instantiating %s", instname);
+               cf_log_module(cs, "Instantiating %s", instname);
        }
 
        /*
@@ -670,7 +670,7 @@ static int load_byserver(CONF_SECTION *cs)
        int comp, flag;
        const char *server = cf_section_name2(cs);
 
-       DEBUG2(" modules {");
+       cf_log_info(cs, " modules {");
 
        /*
         *      Define types first.
@@ -694,7 +694,7 @@ static int load_byserver(CONF_SECTION *cs)
                        cf_log_err(cf_sectiontoitem(subcs),
                                   "No such attribute %s",
                                   section_type_value[comp].typename);
-                       DEBUG2(" }");
+                       cf_log_info(cs, " }");
                        return -1;
                }
 
@@ -731,7 +731,7 @@ static int load_byserver(CONF_SECTION *cs)
                        if (strcmp(name1, section_type_value[comp].typename) == 0) {
                                if (!define_type(dattr,
                                                 cf_section_name2(subsubcs))) {
-                                       DEBUG2(" }");
+                                       cf_log_info(cs, " }");
                                        return -1;
                                }
                        }
@@ -752,11 +752,11 @@ static int load_byserver(CONF_SECTION *cs)
                        
                if (cf_item_find_next(subcs, NULL) == NULL) continue;
                        
-               DEBUG2(" Module: Checking %s {...} for more modules to load",
+               cf_log_module(cs, "Checking %s {...} for more modules to load",
                       section_type_value[comp].section);
 
                if (load_component_section(subcs, server, comp) < 0) {
-                       DEBUG2(" }");
+                       cf_log_info(cs, " }");
                        return -1;
                }
                flag = 1;
@@ -773,7 +773,7 @@ static int load_byserver(CONF_SECTION *cs)
 
                subcs = cf_section_sub_find(cs, "vmps");
                if (subcs) {
-                       DEBUG2(" Module: Checking vmps {...} for more modules to load");                
+                       cf_log_module(cs, "Checking vmps {...} for more modules to load");              
                        if (load_component_section(subcs, server,
                                                   RLM_COMPONENT_POST_AUTH) < 0) {
                                return -1;
@@ -782,7 +782,7 @@ static int load_byserver(CONF_SECTION *cs)
                }
        }
 
-       DEBUG2(" }");
+       cf_log_info(cs, " }");
 
        if (!flag && server) {
                DEBUG("WARNING: Server %s is empty, and will do nothing!",
@@ -840,7 +840,7 @@ int module_hup(CONF_SECTION *modules)
                        continue;
                }
 
-               DEBUG2(" Module: Trying to reload module \"%s\"", node->name);
+               cf_log_module(cs, "Trying to reload module \"%s\"", node->name);
 
                if ((node->entry->module->instantiate)(cs, &insthandle) < 0) {
                        cf_log_err(cf_sectiontoitem(cs),
@@ -989,7 +989,7 @@ int setup_modules(int reload, CONF_SECTION *config)
                module_instance_t *module;
                const char *name;
 
-               DEBUG2(" instantiate {");
+               cf_log_info(cs, " instantiate {");
 
                /*
                 *  Loop over the items in the 'instantiate' section.
@@ -1014,7 +1014,7 @@ int setup_modules(int reload, CONF_SECTION *config)
                        }
                } /* loop over items in the subsection */
 
-               DEBUG2(" }");
+               cf_log_info(cs, " }");
        } /* if there's an 'instantiate' section. */
 
        /*
@@ -1049,16 +1049,16 @@ int setup_modules(int reload, CONF_SECTION *config)
                const char *name2 = cf_section_name2(cs);
 
                if (name2) {
-                       DEBUG2("server %s {", name2);
+                       cf_log_info(cs, "server %s {", name2);
                } else {
-                       DEBUG2("server {");
+                       cf_log_info(cs, "server {");
                        null_server = TRUE;
                }
                if (load_byserver(cs) < 0) {
-                       DEBUG2("}");
+                       cf_log_info(cs, "}");
                        return -1;
                }
-               DEBUG2("}");
+               cf_log_info(cs, "}");
        }
 
        /*
@@ -1066,12 +1066,12 @@ int setup_modules(int reload, CONF_SECTION *config)
         *      one for backwards compatibility.
         */
        if (!null_server) {
-               DEBUG2("server {");
+               cf_log_info(cs, "server {");
                if (load_byserver(config) < 0) {
-                       DEBUG2("}");
+                       cf_log_info(cs, "}");
                        return -1;
                }
-               DEBUG2("}");
+               cf_log_info(cs, "}");
        }
 
        return 0;
index 27fb0d3..1251dea 100644 (file)
@@ -120,9 +120,9 @@ int eaptype_load(EAP_TYPES **type, int eap_type, CONF_SECTION *cs)
                free(node);
                return -1;
        }
-       DEBUG("  eap: Linked to sub-module %s", buffer);
+       cf_log_module(cs, "Linked to sub-module %s", buffer);
 
-       DEBUG("  eap: Instantiating eap-%s", eaptype_name);
+       cf_log_module(cs, "Instantiating eap-%s", eaptype_name);
 
        if ((node->type->attach) &&
            ((node->type->attach)(node->cs, &(node->type_data)) < 0)) {