2 * conffile.c Read the radiusd.conf file.
4 * Yep I should learn to use lex & yacc, or at least
5 * write a decent parser. I know how to do that, really :)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Copyright 2000 The FreeRADIUS server project
25 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
26 * Copyright 2000 Alan DeKok <aland@ox.org>
30 #include "libradius.h"
37 # include <netinet/in.h>
45 static const char rcsid[] =
48 #define xstrdup strdup
50 typedef enum conf_type {
56 struct conf_item *next;
57 struct conf_part *parent;
71 struct conf_item *children;
74 CONF_SECTION *config = NULL;
79 extern RADCLIENT *clients;
81 extern int read_realms_file(const char *file);
83 static int generate_realms(const char *filename);
84 static int generate_clients(const char *filename);
85 static CONF_SECTION *conf_read(const char *fromfile, int fromline, const char *conffile);
88 #define RADIUS_CONFIG "radiusd.conf"
92 * Isolate the scary casts in these tiny provably-safe functions
94 CONF_PAIR *cf_itemtopair(CONF_ITEM *ci)
98 assert(ci->type == CONF_ITEM_PAIR);
99 return (CONF_PAIR *)ci;
101 CONF_SECTION *cf_itemtosection(CONF_ITEM *ci)
105 assert(ci->type == CONF_ITEM_SECTION);
106 return (CONF_SECTION *)ci;
108 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp)
112 return (CONF_ITEM *)cp;
114 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs)
118 return (CONF_ITEM *)cs;
122 * Create a new CONF_PAIR
124 static CONF_PAIR *cf_pair_alloc(const char *attr, const char *value,
125 int operator, CONF_SECTION *parent)
129 cp = (CONF_PAIR *)rad_malloc(sizeof(CONF_PAIR));
130 memset(cp, 0, sizeof(CONF_PAIR));
131 cp->item.type = CONF_ITEM_PAIR;
132 cp->item.parent = parent;
133 cp->attr = xstrdup(attr);
134 cp->value = xstrdup(value);
135 cp->operator = operator;
143 void cf_pair_free(CONF_PAIR **cp)
145 if (!cp || !*cp) return;
153 memset(*cp, 0, sizeof(*cp));
161 * Allocate a CONF_SECTION
163 static CONF_SECTION *cf_section_alloc(const char *name1, const char *name2,
164 CONF_SECTION *parent)
168 if (name1 == NULL || !name1[0])
171 cs = (CONF_SECTION *)rad_malloc(sizeof(CONF_SECTION));
172 memset(cs, 0, sizeof(CONF_SECTION));
173 cs->item.type = CONF_ITEM_SECTION;
174 cs->item.parent = parent;
175 cs->name1 = xstrdup(name1);
176 cs->name2 = (name2 && *name2) ? xstrdup(name2) : NULL;
182 * Free a CONF_SECTION
184 void cf_section_free(CONF_SECTION **cs)
186 CONF_ITEM *ci, *next;
188 if (!cs || !*cs) return;
190 for (ci = (*cs)->children; ci; ci = next) {
192 if (ci->type==CONF_ITEM_PAIR) {
193 CONF_PAIR *pair = cf_itemtopair(ci);
196 CONF_SECTION *section = cf_itemtosection(ci);
197 cf_section_free(§ion);
201 if ((*cs)->name1) free((*cs)->name1);
202 if ((*cs)->name2) free((*cs)->name2);
205 * And free the section
208 memset(*cs, 0, sizeof(*cs));
216 * Add an item to a configuration section.
218 static void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci_new)
222 for (ci = cs->children; ci && ci->next; ci = ci->next)
226 cs->children = ci_new;
232 * Expand the variables in an input string.
234 static const char *cf_expand_variables(const char *cf, int *lineno,
236 char *output, const char *input)
239 const char *end, *ptr;
242 CONF_SECTION *outercs;
246 while (*ptr >= ' ') {
248 * Ignore anything other than "${"
250 if ((*ptr != '$') || (ptr[1] != '{')) {
256 * Look for trailing '}', and silently
257 * ignore anything that doesn't match.
259 * FIXME! This is probably wrong...
261 end = strchr(ptr, '}');
269 memcpy(name, ptr, end - ptr);
270 name[end - ptr] = '\0';
272 cpn = cf_pair_find(cs, name);
275 * Also look recursively up the section tree,
276 * so things like ${confdir} can be defined
277 * there and used inside the module config
280 for (outercs=cs->item.parent;
281 (cpn == NULL) && (outercs != NULL);
282 outercs=outercs->item.parent) {
283 cpn = cf_pair_find(outercs, name);
286 radlog(L_ERR, "%s[%d]: Unknown variable \"%s\"",
292 * Substitute the value of the variable.
294 strcpy(p, cpn->value);
297 } /* loop over all of the input string. */
305 * Parse a configuration section into user-supplied variables.
307 int cf_section_parse(CONF_SECTION *cs, const CONF_PARSER *variables)
313 CONF_SECTION *subsection;
319 * Handle the user-supplied variables.
321 for (i = 0; variables[i].name != NULL; i++) {
322 value = variables[i].dflt;
324 cp = cf_pair_find(cs, variables[i].name);
329 switch (variables[i].type)
331 case PW_TYPE_SUBSECTION:
332 subsection = cf_section_sub_find(cs,variables[i].name);
335 * If the configuration section is NOT there,
338 * FIXME! This is probably wrong... we should
339 * probably set the items to their default values.
345 rcode = cf_section_parse(subsection,
346 (CONF_PARSER *) variables[i].data);
352 case PW_TYPE_BOOLEAN:
354 * Allow yes/no and on/off
356 if ((strcasecmp(value, "yes") == 0) ||
357 (strcasecmp(value, "on") == 0)) {
358 *(int *)variables[i].data = 1;
359 } else if ((strcasecmp(value, "no") == 0) ||
360 (strcasecmp(value, "off") == 0)) {
361 *(int *)variables[i].data = 0;
363 *(int *)variables[i].data = 0;
364 radlog(L_ERR, "Bad value \"%s\" for boolean variable %s", value, variables[i].name);
367 DEBUG2(" %s: %s = %s",
373 case PW_TYPE_INTEGER:
374 *(int *)variables[i].data = strtol(value, 0, 0);
375 DEBUG2(" %s: %s = %d",
378 *(int *)variables[i].data);
381 case PW_TYPE_STRING_PTR:
382 q = (char **) variables[i].data;
388 * Expand variables while parsing,
389 * but ONLY expand ones which haven't already
392 if (value && (value == variables[i].dflt)) {
393 value = cf_expand_variables(NULL, 0, cs, buffer,value);
399 DEBUG2(" %s: %s = \"%s\"",
402 value ? value : "(null)");
403 *q = value ? strdup(value) : NULL;
408 * Allow '*' as any address
410 if (strcmp(value, "*") == 0) {
411 *(uint32_t *) variables[i].data = 0;
414 ipaddr = ip_getaddr(value);
416 radlog(L_ERR, "Can't find IP address for host %s", value);
419 DEBUG2(" %s: %s = %s IP address [%s]",
422 value, ip_ntoa(buffer, ipaddr));
423 *(uint32_t *) variables[i].data = ipaddr;
427 radlog(L_ERR, "type %d not supported yet", variables[i].type);
430 } /* switch over variable type */
431 } /* for all variables in the configuration section */
437 * Read a part of the config file.
439 static CONF_SECTION *cf_section_read(const char *cf, int *lineno, FILE *fp,
440 const char *name1, const char *name2,
441 CONF_SECTION *parent)
443 CONF_SECTION *cs, *css;
454 * Ensure that the user can't add CONF_SECTIONs
455 * with 'internal' names;
457 if ((name1 != NULL) && (name1[0] == '_')) {
458 radlog(L_ERR, "%s[%d]: Illegal configuration section name",
464 * Allocate new section.
466 cs = cf_section_alloc(name1, name2, parent);
467 cs->item.lineno = *lineno;
472 while (fgets(buf, sizeof(buf), fp) != NULL) {
476 t1 = gettoken(&ptr, buf1, sizeof(buf1));
479 * Skip comments and blank lines immediately.
481 if ((*buf1 == '#') || (*buf1 == '\0')) {
486 * Allow for $INCLUDE files
488 * Currently this allows for includes only at the top
489 * level of config. IE you cannot have an $INCLUDE nested
490 * inside section. -cparker
492 if ((strcasecmp(buf1, "$INCLUDE") == 0) &&
493 (name1 == NULL) && (name2 == NULL)) {
497 t2 = getword(&ptr, buf2, sizeof(buf2));
499 value = cf_expand_variables(cf, lineno, cs, buf, buf2);
501 cf_section_free(&cs);
505 DEBUG2( "Config: including file: %s", value );
507 if ((is = conf_read(cf, *lineno, value)) == NULL) {
508 cf_section_free(&cs);
513 * Add the included conf to our CONF_SECTION
516 if (is->children != NULL) {
517 cf_item_add(cs, is->children);
519 /* the file was empty */
520 cf_section_free(&is);
528 * No '=': must be a section or sub-section.
530 if (strchr(ptr, '=') == NULL) {
531 t2 = gettoken(&ptr, buf2, sizeof(buf2));
532 t3 = gettoken(&ptr, buf3, sizeof(buf3));
534 t2 = gettoken(&ptr, buf2, sizeof(buf2));
535 t3 = getword(&ptr, buf3, sizeof(buf3));
539 * See if it's the end of a section.
541 if (t1 == T_RCBRACE) {
542 if (name1 == NULL || buf2[0]) {
543 radlog(L_ERR, "%s[%d]: Unexpected end of section",
545 cf_section_free(&cs);
552 * Perhaps a subsection.
554 if (t2 == T_LCBRACE || t3 == T_LCBRACE) {
555 css = cf_section_read(cf, lineno, fp, buf1,
556 t2==T_LCBRACE ? NULL : buf2, cs);
558 cf_section_free(&cs);
561 cf_item_add(cs, cf_sectiontoitem(css));
567 * Ignore semi-colons.
569 if (*buf2 == ';') *buf2 = '\0';
572 * Must be a normal attr = value line.
574 if (buf1[0] != 0 && buf2[0] == 0 && buf3[0] == 0) {
576 } else if (buf1[0] == 0 || buf2[0] == 0 || buf3[0] == 0 ||
577 (t2 < T_EQSTART || t2 > T_EQEND)) {
578 radlog(L_ERR, "%s[%d]: Line is not in 'attribute = value' format",
580 cf_section_free(&cs);
585 * Ensure that the user can't add CONF_PAIRs
586 * with 'internal' names;
588 if (buf1[0] == '_') {
589 radlog(L_ERR, "%s[%d]: Illegal configuration pair name \"%s\"",
591 cf_section_free(&cs);
596 * Handle variable substitution via ${foo}
598 value = cf_expand_variables(cf, lineno, cs, buf, buf3);
600 cf_section_free(&cs);
606 * Add this CONF_PAIR to our CONF_SECTION
608 cpn = cf_pair_alloc(buf1, value, t2, parent);
609 cpn->item.lineno = *lineno;
610 cf_item_add(cs, cf_pairtoitem(cpn));
614 * See if EOF was unexpected ..
617 radlog(L_ERR, "%s[%d]: Unexpected end of file", cf, *lineno);
618 cf_section_free(&cs);
626 * Read the config file.
628 static CONF_SECTION *conf_read(const char *fromfile, int fromline, const char *conffile)
634 if ((fp = fopen(conffile, "r")) == NULL) {
636 radlog(L_ERR|L_CONS, "%s[%d]: Unable to open file \"%s\": %s",
637 fromfile, fromline, conffile, strerror(errno));
639 radlog(L_ERR|L_CONS, "Unable to open file \"%s\": %s",
640 conffile, strerror(errno));
645 cs = cf_section_read(conffile, &lineno, fp, NULL, NULL, NULL);
652 * These are not used anywhere else..
654 static const char *localstatedir = NULL;
655 static const char *prefix = NULL;
657 static CONF_PARSER directory_config[] = {
659 * FIXME: 'prefix' is the ONLY one which should be configured
660 * at compile time. Hard-coding it here is bad. It will be cleaned
661 * up once we clean up the hard-coded defines for the locations of
664 { "prefix", PW_TYPE_STRING_PTR, &prefix, "/usr/local"},
665 { "localstatedir", PW_TYPE_STRING_PTR, &localstatedir, "${prefix}/var"},
666 { "logdir", PW_TYPE_STRING_PTR, &radlog_dir, "${localstatedir}/log"},
667 { "libdir", PW_TYPE_STRING_PTR, &radlib_dir, "${prefix}/lib"},
668 { "radacctdir", PW_TYPE_STRING_PTR, &radacct_dir, "${logdir}/radacct" },
669 { "hostname_lookups", PW_TYPE_BOOLEAN, &librad_dodns, "no" },
672 * We don't allow re-defining this, as doing so will cause
673 * all sorts of confusion.
676 { "confdir", PW_TYPE_STRING_PTR, &radius_dir, RADIUS_DIR },
678 { NULL, -1, NULL, NULL }
683 * Read the configuration and library
684 * This uses the new kind of configuration file as defined by
685 * Miquel at http://www.miquels.cistron.nl/radius/
688 int read_radius_conf_file(void)
693 /* Lets go look for the new configuration files */
694 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
695 if ((cs = conf_read(NULL, 0, buffer)) == NULL) {
700 * Free the old configuration data, and replace it
703 cf_section_free(&config);
707 * And parse the directory configuration values.
709 cs = cf_section_find(NULL);
714 * This allows us to figure out where, relative to
715 * radiusd.conf, the other configuration files exist.
717 cf_section_parse(cs, directory_config);
719 /* Initialize the dictionary */
720 DEBUG2("read_config_files: reading dictionary");
721 if (dict_init(radius_dir, RADIUS_DICTIONARY) != 0) {
722 radlog(L_ERR|L_CONS, "Errors reading dictionary: %s",
727 /* old-style clients file */
728 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_CLIENTS);
729 DEBUG2("read_config_files: reading clients");
730 if (read_clients_file(buffer) < 0) {
731 radlog(L_ERR|L_CONS, "Errors reading clients");
736 * Add to that, the *new* list of clients.
738 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
739 if (generate_clients(buffer) < 0) {
743 /* old-style realms file */
744 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_REALMS);
745 DEBUG2("read_config_files: reading realms");
746 if (read_realms_file(buffer) < 0) {
747 radlog(L_ERR|L_CONS, "Errors reading realms");
752 * If there isn't any realms it isn't fatal..
754 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
755 if (generate_realms(buffer) < 0) {
759 /* old-style naslist file */
760 sprintf(buffer, "%.200s/%.50s", radius_dir, RADIUS_NASLIST);
761 DEBUG2("read_config_files: reading naslist");
762 if (read_naslist_file(buffer) < 0) {
763 radlog(L_ERR|L_CONS, "Errors reading naslist");
771 * Create the linked list of realms from the new configuration type
772 * This way we don't have to change to much in the other source-files
775 static int generate_realms(const char *filename)
779 char *s, *authhost, *accthost;
781 for (cs = cf_subsection_find_next(config, NULL, "realm"); cs != NULL;
782 cs = cf_subsection_find_next(config, cs, "realm")) {
784 radlog(L_CONS|L_ERR, "%s[%d]: Missing realm name", filename, cs->item.lineno);
788 * We've found a realm, allocate space for it
790 c = rad_malloc(sizeof(REALM));
791 memset(c, 0, sizeof(REALM));
793 * An authhost must exist in the configuration
795 if ((authhost = cf_section_value_find(cs, "authhost")) == NULL) {
797 "%s[%d]: No authhost entry in realm",
798 filename, cs->item.lineno);
801 if ((s = strchr(authhost, ':')) != NULL) {
803 c->auth_port = atoi(s);
805 c->auth_port = auth_port;
807 accthost = cf_section_value_find(cs, "accthost");
808 if ((s =strchr(accthost, ':')) != NULL) {
810 c->acct_port = atoi(s);
812 c->acct_port = acct_port;
814 if (strcmp(authhost, "LOCAL") != 0)
815 c->ipaddr = ip_getaddr(authhost);
818 * Double check length, just to be sure!
820 if (strlen(authhost) >= sizeof(c->server)) {
821 radlog(L_ERR, "%s[%d]: Server name of length %d is greater that allowed: %d",
822 filename, cs->item.lineno,
823 strlen(authhost), sizeof(c->server) - 1);
826 if (strlen(cs->name2) >= sizeof(c->realm)) {
827 radlog(L_ERR, "%s[%d]: Realm name of length %d is greater than allowed %d",
828 filename, cs->item.lineno,
829 strlen(cs->name2), sizeof(c->server) - 1);
833 strcpy(c->realm, cs->name2);
834 strcpy(c->server, authhost);
836 s = cf_section_value_find(cs, "secret");
838 radlog(L_ERR, "%s[%d]: No shared secret supplied for realm",
839 filename, cs->item.lineno);
843 if (strlen(s) >= sizeof(c->secret)) {
844 radlog(L_ERR, "%s[%d]: Secret of length %d is greater than the allowed maximum of %d.",
845 filename, cs->item.lineno,
846 strlen(s), sizeof(c->secret) - 1);
849 strNcpy((char *)c->secret, s, sizeof(c->secret));
853 if ((cf_section_value_find(cs, "nostrip")) != NULL)
855 if ((cf_section_value_find(cs, "noacct")) != NULL)
857 if ((cf_section_value_find(cs, "trusted")) != NULL)
859 if ((cf_section_value_find(cs, "notrealm")) != NULL)
861 if ((cf_section_value_find(cs, "notsuffix")) != NULL)
874 * Create the linked list of realms from the new configuration type
875 * This way we don't have to change to much in the other source-files
877 static int generate_clients(const char *filename)
881 char *hostnm, *secret, *shortnm, *netmask;
883 for (cs = cf_subsection_find_next(config, NULL, "client"); cs != NULL;
884 cs = cf_subsection_find_next(config, cs, "client")) {
886 radlog(L_CONS|L_ERR, "%s[%d]: Missing client name", filename, cs->item.lineno);
890 * Check the lengths, we don't want any core dumps
893 secret = cf_section_value_find(cs, "secret");
894 shortnm = cf_section_value_find(cs, "shortname");
895 netmask = strchr(hostnm, '/');
897 if (strlen(secret) >= sizeof(c->secret)) {
898 radlog(L_ERR, "%s[%d]: Secret of length %d is greater than the allowed maximum of %d.",
899 filename, cs->item.lineno,
900 strlen(secret), sizeof(c->secret) - 1);
903 if (strlen(shortnm) > sizeof(c->shortname)) {
904 radlog(L_ERR, "%s[%d]: Client short name of length %d is greater than the allowed maximum of %d.",
905 filename, cs->item.lineno,
906 strlen(shortnm), sizeof(c->shortname) - 1);
910 * The size is fine.. Let's create the buffer
912 c = rad_malloc(sizeof(RADCLIENT));
921 mask_length = atoi(netmask + 1);
922 if ((mask_length <= 0) || (mask_length > 32)) {
923 radlog(L_ERR, "%s[%d]: Invalid value '%s' for IP network mask.",
924 filename, cs->item.lineno, netmask + 1);
928 c->netmask = (1 << 31);
929 for (i = 1; i < mask_length; i++) {
930 c->netmask |= (c->netmask >> 1);
934 c->netmask = htonl(c->netmask);
937 c->ipaddr = ip_getaddr(hostnm);
938 if (c->ipaddr == INADDR_NONE) {
939 radlog(L_CONS|L_ERR, "%s[%d]: Failed to look up hostname %s",
940 filename, cs->item.lineno, hostnm);
945 * Update the client name again...
949 c->ipaddr &= c->netmask;
950 strcpy(c->longname, hostnm);
952 ip_hostname(c->longname, sizeof(c->longname),
956 strcpy((char *)c->secret, secret);
957 strcpy(c->shortname, shortnm);
967 * Return a CONF_PAIR within a CONF_SECTION.
970 CONF_PAIR *cf_pair_find(CONF_SECTION *section, const char *name)
974 if (section == NULL) {
978 for (ci = section->children; ci; ci = ci->next) {
979 if (ci->type != CONF_ITEM_PAIR)
981 if (name == NULL || strcmp(cf_itemtopair(ci)->attr, name) == 0)
985 return cf_itemtopair(ci);
989 * Return the attr of a CONF_PAIR
992 char *cf_pair_attr(CONF_PAIR *pair)
994 return (pair ? pair->attr : NULL);
998 * Return the value of a CONF_PAIR
1001 char *cf_pair_value(CONF_PAIR *pair)
1003 return (pair ? pair->value : NULL);
1007 * Return the first label of a CONF_SECTION
1010 char *cf_section_name1(CONF_SECTION *section)
1012 return (section ? section->name1 : NULL);
1016 * Return the second label of a CONF_SECTION
1019 char *cf_section_name2(CONF_SECTION *section)
1021 return (section ? section->name2 : NULL);
1025 * Find a value in a CONF_SECTION
1027 char *cf_section_value_find(CONF_SECTION *section, const char *attr)
1031 cp = cf_pair_find(section, attr);
1033 return (cp ? cp->value : NULL);
1037 * Return the next pair after a CONF_PAIR
1038 * with a certain name (char *attr) If the requested
1039 * attr is NULL, any attr matches.
1042 CONF_PAIR *cf_pair_find_next(CONF_SECTION *section, CONF_PAIR *pair, const char *attr)
1047 * If pair is NULL this must be a first time run
1048 * Find the pair with correct name
1052 return cf_pair_find(section, attr);
1055 ci = cf_pairtoitem(pair)->next;
1057 for (; ci; ci = ci->next) {
1058 if (ci->type != CONF_ITEM_PAIR)
1060 if (attr == NULL || strcmp(cf_itemtopair(ci)->attr, attr) == 0)
1064 return cf_itemtopair(ci);
1068 * Find a CONF_SECTION, or return the root if name is NULL
1071 CONF_SECTION *cf_section_find(const char *name)
1074 return cf_section_sub_find(config, name);
1080 * Find a sub-section in a section
1083 CONF_SECTION *cf_section_sub_find(CONF_SECTION *section, const char *name)
1087 for (ci = section->children; ci; ci = ci->next) {
1088 if (ci->type != CONF_ITEM_SECTION)
1090 if (strcmp(cf_itemtosection(ci)->name1, name) == 0)
1094 return cf_itemtosection(ci);
1099 * Return the next subsection after a CONF_SECTION
1100 * with a certain name1 (char *name1). If the requested
1101 * name1 is NULL, any name1 matches.
1104 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
1105 CONF_SECTION *subsection,
1111 * If subsection is NULL this must be a first time run
1112 * Find the subsection with correct name
1115 if (subsection == NULL){
1116 ci = section->children;
1118 ci = cf_sectiontoitem(subsection)->next;
1121 for (; ci; ci = ci->next) {
1122 if (ci->type != CONF_ITEM_SECTION)
1124 if ((name1 == NULL) ||
1125 (strcmp(cf_itemtosection(ci)->name1, name1) == 0))
1129 return cf_itemtosection(ci);
1133 * Return the next item after a CONF_ITEM.
1136 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item)
1139 * If item is NULL this must be a first time run
1140 * Return the first item
1144 return section->children;
1150 int cf_section_lineno(CONF_SECTION *section)
1152 return cf_sectiontoitem(section)->lineno;
1155 int cf_pair_lineno(CONF_PAIR *pair)
1157 return cf_pairtoitem(pair)->lineno;
1160 int cf_item_is_section(CONF_ITEM *item)
1162 return item->type == CONF_ITEM_SECTION;
1167 * JMG dump_config tries to dump the config structure in a readable format
1171 static int dump_config_section(CONF_SECTION *cs, int indent)
1177 /* The DEBUG macro doesn't let me
1178 * for(i=0;i<indent;++i) debugputchar('\t');
1179 * so I had to get creative. --Pac. */
1181 for (ci = cs->children; ci; ci = ci->next) {
1182 if (ci->type == CONF_ITEM_PAIR) {
1183 cp=cf_itemtopair(ci);
1184 DEBUG("%.*s%s = %s",
1185 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1186 cp->attr, cp->value);
1188 scs=cf_itemtosection(ci);
1189 DEBUG("%.*s%s %s%s{",
1190 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1192 scs->name2 ? scs->name2 : "",
1193 scs->name2 ? " " : "");
1194 dump_config_section(scs, indent+1);
1196 indent, "\t\t\t\t\t\t\t\t\t\t\t");
1203 int dump_config(void)
1205 return dump_config_section(config, 0);