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
*/
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:
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;
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;
/*
*/
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) {
}
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;
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));
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);
}
}
} /* 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;
}
/*
* 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, ...)
{
}
+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
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
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);
}
/*
int comp, flag;
const char *server = cf_section_name2(cs);
- DEBUG2(" modules {");
+ cf_log_info(cs, " modules {");
/*
* Define types first.
cf_log_err(cf_sectiontoitem(subcs),
"No such attribute %s",
section_type_value[comp].typename);
- DEBUG2(" }");
+ cf_log_info(cs, " }");
return -1;
}
if (strcmp(name1, section_type_value[comp].typename) == 0) {
if (!define_type(dattr,
cf_section_name2(subsubcs))) {
- DEBUG2(" }");
+ cf_log_info(cs, " }");
return -1;
}
}
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;
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;
}
}
- DEBUG2(" }");
+ cf_log_info(cs, " }");
if (!flag && server) {
DEBUG("WARNING: Server %s is empty, and will do nothing!",
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),
module_instance_t *module;
const char *name;
- DEBUG2(" instantiate {");
+ cf_log_info(cs, " instantiate {");
/*
* Loop over the items in the 'instantiate' section.
}
} /* loop over items in the subsection */
- DEBUG2(" }");
+ cf_log_info(cs, " }");
} /* if there's an 'instantiate' section. */
/*
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, "}");
}
/*
* 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;