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"
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
42 #ifdef HAVE_SYS_STAT_H
50 #include "rad_assert.h"
55 static const char rcsid[] =
58 typedef enum conf_type {
64 struct conf_item *next;
65 struct conf_part *parent;
79 struct conf_item *children;
80 rbtree_t *pair_tree; /* and a partridge.. */
81 rbtree_t *section_tree; /* no jokes here */
82 rbtree_t *name2_tree; /* for sections of the same name2 */
86 * Isolate the scary casts in these tiny provably-safe functions
88 CONF_PAIR *cf_itemtopair(CONF_ITEM *ci)
92 rad_assert(ci->type == CONF_ITEM_PAIR);
93 return (CONF_PAIR *)ci;
95 CONF_SECTION *cf_itemtosection(CONF_ITEM *ci)
99 rad_assert(ci->type == CONF_ITEM_SECTION);
100 return (CONF_SECTION *)ci;
102 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp)
106 return (CONF_ITEM *)cp;
108 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs)
112 return (CONF_ITEM *)cs;
116 * Create a new CONF_PAIR
118 static CONF_PAIR *cf_pair_alloc(const char *attr, const char *value,
119 LRAD_TOKEN operator, CONF_SECTION *parent)
123 cp = rad_malloc(sizeof(*cp));
124 memset(cp, 0, sizeof(*cp));
125 cp->item.type = CONF_ITEM_PAIR;
126 cp->item.parent = parent;
127 cp->attr = strdup(attr);
128 cp->value = strdup(value);
129 cp->operator = operator;
137 void cf_pair_free(CONF_PAIR **cp)
139 if (!cp || !*cp) return;
147 memset(*cp, 0, sizeof(*cp));
156 * rbtree callback function
158 static int pair_cmp(const void *a, const void *b)
160 const CONF_PAIR *one = a;
161 const CONF_PAIR *two = b;
163 return strcmp(one->attr, two->attr);
168 * rbtree callback function
170 static int section_cmp(const void *a, const void *b)
172 const CONF_SECTION *one = a;
173 const CONF_SECTION *two = b;
175 return strcmp(one->name1, two->name1);
180 * rbtree callback function
182 static int name2_cmp(const void *a, const void *b)
184 const CONF_SECTION *one = a;
185 const CONF_SECTION *two = b;
187 rad_assert(strcmp(one->name1, two->name1) == 0);
189 if (!one->name2 && !two->name2) return 0;
190 if (!one->name2) return -1;
191 if (!two->name2) return +1;
193 return strcmp(one->name2, two->name2);
198 * Free a CONF_SECTION
200 void cf_section_free(CONF_SECTION **cs)
202 CONF_ITEM *ci, *next;
204 if (!cs || !*cs) return;
206 for (ci = (*cs)->children; ci; ci = next) {
208 if (ci->type==CONF_ITEM_PAIR) {
209 CONF_PAIR *pair = cf_itemtopair(ci);
212 CONF_SECTION *section = cf_itemtosection(ci);
213 cf_section_free(§ion);
221 if ((*cs)->pair_tree)
222 rbtree_free((*cs)->pair_tree);
223 if ((*cs)->section_tree)
224 rbtree_free((*cs)->section_tree);
225 if ((*cs)->name2_tree)
226 rbtree_free((*cs)->name2_tree);
229 * And free the section
232 memset(*cs, 0, sizeof(*cs));
241 * Allocate a CONF_SECTION
243 static CONF_SECTION *cf_section_alloc(const char *name1, const char *name2,
244 CONF_SECTION *parent)
248 if (name1 == NULL || !name1[0])
251 cs = rad_malloc(sizeof(*cs));
252 memset(cs, 0, sizeof(*cs));
253 cs->item.type = CONF_ITEM_SECTION;
254 cs->item.parent = parent;
255 cs->name1 = strdup(name1);
257 cf_section_free(&cs);
261 if (name2 && *name2) {
262 cs->name2 = strdup(name2);
264 cf_section_free(&cs);
268 cs->pair_tree = rbtree_create(pair_cmp, NULL, 0);
269 if (!cs->pair_tree) {
270 cf_section_free(&cs);
275 * Don't create the section tree here, it may not
283 * Add an item to a configuration section.
285 static void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci_new)
289 for (ci = cs->children; ci && ci->next; ci = ci->next)
293 cs->children = ci_new;
301 if (ci_new->type == CONF_ITEM_PAIR) {
302 rbtree_insert(cs->pair_tree, ci_new);
304 } else if (ci_new->type == CONF_ITEM_SECTION) {
305 const CONF_SECTION *cs_new = cf_itemtosection(ci_new);
307 if (!cs->section_tree) {
308 cs->section_tree = rbtree_create(section_cmp, NULL, 0);
309 /* ignore any errors */
312 if (cs->section_tree) {
313 rbtree_insert(cs->section_tree, cs_new);
317 * Two names: find the named instance.
320 CONF_SECTION *old_cs;
323 * Find the FIRST CONF_SECTION having the
324 * given name1, and create a new tree
327 old_cs = rbtree_finddata(cs->section_tree, cs_new);
328 if (!old_cs) return; /* this is a bad error! */
330 if (!old_cs->name2_tree) {
331 old_cs->name2_tree = rbtree_create(name2_cmp,
334 if (old_cs->name2_tree) {
335 rbtree_insert(old_cs->name2_tree, cs_new);
338 } /* was a section */
340 ci_new = ci_new->next;
341 } /* loop over ci_new */
345 * Expand the variables in an input string.
347 static const char *cf_expand_variables(const char *cf, int *lineno,
348 const CONF_SECTION *outercs,
349 char *output, const char *input)
352 const char *end, *ptr;
354 const CONF_SECTION *parentcs;
357 * Find the master parent conf section.
358 * We can't use mainconfig.config, because we're in the
359 * process of re-building it, and it isn't set up yet...
361 for (parentcs = outercs;
362 parentcs->item.parent != NULL;
363 parentcs = parentcs->item.parent) {
371 * Ignore anything other than "${"
373 if ((*ptr == '$') && (ptr[1] == '{')) {
376 const CONF_SECTION *cs;
379 * FIXME: Add support for ${foo:-bar},
384 * Look for trailing '}', and log a
385 * warning for anything that doesn't match,
386 * and exit with a fatal error.
388 end = strchr(ptr, '}');
391 radlog(L_INFO, "%s[%d]: Variable expansion missing }",
402 * ${.foo} means "foo from the current section"
410 * ${..foo} means "foo from the section
411 * enclosing this section" (etc.)
413 while (*ptr == '.') {
415 cs = cs->item.parent;
422 * ${foo} is local, with
423 * main as lower priority
428 * ${foo.bar.baz} is always rooted
431 for (q = ptr; *q && q != end; q++) {
443 * Find the next section.
446 (*ptr != 0) && (*ptr != '.') &&
454 * The character is a '.', find a
455 * section (as the user has given
456 * us a subsection to find)
461 ptr++; /* skip the period */
464 * Find the sub-section.
466 next = cf_section_sub_find(cs, name);
468 radlog(L_ERR, "config: No such section %s in variable %s", name, input);
473 } else { /* no period, must be a conf-part */
475 * Find in the current referenced
478 cp = cf_pair_find(cs, name);
481 * It it was NOT ${..foo}
483 * top-level config items.
485 if (!up) cp = cf_pair_find(parentcs, name);
488 radlog(L_ERR, "config: No such entry %s for string %s", name, input);
492 } /* until cp is non-NULL */
495 * Substitute the value of the variable.
497 strcpy(p, cp->value);
501 } else if (memcmp(ptr, "$ENV{", 5) == 0) {
507 * Look for trailing '}', and log a
508 * warning for anything that doesn't match,
509 * and exit with a fatal error.
511 end = strchr(ptr, '}');
514 radlog(L_INFO, "%s[%d]: Environment variable expansion missing }",
519 memcpy(name, ptr, end - ptr);
520 name[end - ptr] = '\0';
523 * Get the environment variable.
524 * If none exists, then make it an empty string.
538 * Copy it over verbatim.
542 } /* loop over all of the input string. */
551 * Parses a CONF_PAIR into the specified format, with a default
554 * Returns -1 on error, 0 for correctly parsed, and 1 if the
555 * default value was used. Note that the default value will be
556 * used ONLY if the CONF_PAIR is NULL.
558 int cf_pair_parse(const CONF_SECTION *cs, const CONF_PAIR *cp,
559 const char *name, int type, void *data, const char *dflt)
564 lrad_ipaddr_t ipaddr;
575 case PW_TYPE_BOOLEAN:
577 * Allow yes/no and on/off
579 if ((strcasecmp(value, "yes") == 0) ||
580 (strcasecmp(value, "on") == 0)) {
582 } else if ((strcasecmp(value, "no") == 0) ||
583 (strcasecmp(value, "off") == 0)) {
587 radlog(L_ERR, "Bad value \"%s\" for boolean variable %s", value, name);
590 DEBUG2(" %s: %s = %s", cs->name1, name, value);
593 case PW_TYPE_INTEGER:
594 *(int *)data = strtol(value, 0, 0);
595 DEBUG2(" %s: %s = %d",
600 case PW_TYPE_STRING_PTR:
607 * Expand variables which haven't already been
608 * expanded automagically when the configuration
611 if (value && (value == dflt)) {
612 int lineno = cs->item.lineno;
613 value = cf_expand_variables("?",
616 if (!value) return -1;
619 DEBUG2(" %s: %s = \"%s\"",
621 value ? value : "(null)");
622 *q = value ? strdup(value) : NULL;
627 * Allow '*' as any address
629 if (strcmp(value, "*") == 0) {
630 *(uint32_t *) data = htonl(INADDR_ANY);
633 if (ip_hton(value, AF_INET, &ipaddr) < 0) {
634 radlog(L_ERR, "Can't find IP address for host %s", value);
637 DEBUG2(" %s: %s = %s IP address [%s]",
638 cs->name1, name, value,
639 ip_ntoh(&ipaddr, buffer, sizeof(buffer)));
640 *(uint32_t *) data = ipaddr.ipaddr.ip4addr.s_addr;
643 case PW_TYPE_IPV6ADDR:
645 * Allow '*' as any address
647 if (strcmp(value, "*") == 0) {
648 memcpy(data, 0, sizeof(ipaddr.ipaddr.ip6addr));
651 if (ip_hton(value, AF_INET6, &ipaddr) < 0) {
652 radlog(L_ERR, "Can't find IPv6 address for host %s", value);
655 DEBUG2(" %s: %s = %s IPv6 address [%s]",
656 cs->name1, name, value,
657 ip_ntoh(&ipaddr, buffer, sizeof(buffer)));
658 memcpy(data, &ipaddr.ipaddr.ip6addr,
659 sizeof(ipaddr.ipaddr.ip6addr));
663 radlog(L_ERR, "type %d not supported yet", type);
666 } /* switch over variable type */
672 * Parse a configuration section into user-supplied variables.
674 int cf_section_parse(const CONF_SECTION *cs, void *base,
675 const CONF_PARSER *variables)
682 * Handle the known configuration parameters.
684 for (i = 0; variables[i].name != NULL; i++) {
686 * Handle subsections specially
688 if (variables[i].type == PW_TYPE_SUBSECTION) {
689 const CONF_SECTION *subcs;
690 subcs = cf_section_sub_find(cs, variables[i].name);
693 * If the configuration section is NOT there,
696 * FIXME! This is probably wrong... we should
697 * probably set the items to their default values.
699 if (!subcs) continue;
701 if (!variables[i].data) {
702 DEBUG2("Internal sanity check 1 failed in cf_section_parse!");
706 if (cf_section_parse(subcs, base,
707 (CONF_PARSER *) variables[i].data) < 0) {
711 } /* else it's a CONF_PAIR */
713 if (variables[i].data) {
714 data = variables[i].data; /* prefer this. */
716 data = ((char *)base) + variables[i].offset;
718 DEBUG2("Internal sanity check 2 failed in cf_section_parse!");
722 cp = cf_pair_find(cs, variables[i].name);
723 if (cf_pair_parse(cs, cp, variables[i].name, variables[i].type,
724 data, variables[i].dflt) < 0) {
727 } /* for all variables in the configuration section */
733 * Used in a few places, so in one function for clarity.
735 static void cf_fixup_children(CONF_SECTION *cs, CONF_SECTION *is)
738 * Add the included conf
739 * to our CONF_SECTION
741 if (is->children != NULL) {
745 * Re-write the parent of the
746 * moved children to be the
747 * upper-layer section.
749 for (ci = is->children; ci; ci = ci->next) {
754 * If there are children, then
755 * move them up a layer.
758 cf_item_add(cs, is->children);
763 * Always free the section for the
766 cf_section_free(&is);
771 * Read a part of the config file.
773 static CONF_SECTION *cf_section_read(const char *cf, int *lineno, FILE *fp,
774 const char *name1, const char *name2,
775 CONF_SECTION *parent)
777 CONF_SECTION *cs, *css;
790 * Ensure that the user can't add CONF_SECTIONs
791 * with 'internal' names;
793 if ((name1 != NULL) && (name1[0] == '_')) {
794 radlog(L_ERR, "%s[%d]: Illegal configuration section name",
800 * Allocate new section.
802 cs = cf_section_alloc(name1, name2, parent);
803 cs->item.lineno = *lineno;
806 * Read, checking for line continuations ('\\' at EOL)
812 * Get data, and remember if we are at EOF.
814 eof = (fgets(cbuf, sizeof(buf) - (cbuf - buf), fp) == NULL);
820 * We've filled the buffer, and there isn't
823 if ((len == sizeof(buf)) &&
824 (cbuf[len - 1] != '\n')) {
825 radlog(L_ERR, "%s[%d]: Line too long",
827 cf_section_free(&cs);
832 * Check for continuations.
834 if (cbuf[len - 1] == '\n') len--;
837 * Last character is '\\'. Over-write it,
838 * and read another line.
840 if ((len > 0) && (cbuf[len - 1] == '\\')) {
841 cbuf[len - 1] = '\0';
847 * We're at EOF, and haven't read anything. Stop.
849 if (eof && (cbuf == buf)) {
854 t1 = gettoken(&ptr, buf1, sizeof(buf1));
857 * Skip comments and blank lines immediately.
859 if ((*buf1 == '#') || (*buf1 == '\0')) {
864 * Allow for $INCLUDE files
866 * This *SHOULD* work for any level include.
867 * I really really really hate this file. -cparker
869 if (strcasecmp(buf1, "$INCLUDE") == 0) {
872 t2 = getword(&ptr, buf2, sizeof(buf2));
874 value = cf_expand_variables(cf, lineno, cs, buf, buf2);
876 cf_section_free(&cs);
884 * Include ALL non-"dot" files in the directory.
887 if (value[strlen(value) - 1] == '/') {
890 struct stat stat_buf;
892 DEBUG2( "Config: including files in directory: %s", value );
893 dir = opendir(value);
895 radlog(L_ERR, "%s[%d]: Error reading directory %s: %s",
898 cf_section_free(&cs);
903 * Read the directory, ignoring "." files.
905 while ((dp = readdir(dir)) != NULL) {
908 if (dp->d_name[0] == '.') continue;
911 * Check for valid characters
913 for (p = dp->d_name; *p != '\0'; p++) {
914 if (isalpha((int)*p) ||
917 (*p == '.')) continue;
920 if (*p != '\0') continue;
922 snprintf(buf2, sizeof(buf2), "%s%s",
924 if ((stat(buf2, &stat_buf) != 0) ||
925 S_ISDIR(stat_buf.st_mode)) continue;
926 if ((is = conf_read(cf, *lineno, buf2, parent)) == NULL) {
928 cf_section_free(&cs);
932 cf_fixup_children(cs, is);
937 { /* it was a normal file */
938 DEBUG2( "Config: including file: %s", value );
939 if ((is = conf_read(cf, *lineno, value, parent)) == NULL) {
940 cf_section_free(&cs);
943 cf_fixup_children(cs, is);
946 } /* we were in an include */
949 * No '=': must be a section or sub-section.
951 if (strchr(ptr, '=') == NULL) {
952 t2 = gettoken(&ptr, buf2, sizeof(buf2));
953 t3 = gettoken(&ptr, buf3, sizeof(buf3));
955 t2 = gettoken(&ptr, buf2, sizeof(buf2));
956 t3 = getword(&ptr, buf3, sizeof(buf3));
960 * See if it's the end of a section.
962 if (t1 == T_RCBRACE) {
963 if (name1 == NULL || buf2[0]) {
964 radlog(L_ERR, "%s[%d]: Unexpected end of section",
966 cf_section_free(&cs);
973 * Perhaps a subsection.
975 if (t2 == T_LCBRACE || t3 == T_LCBRACE) {
976 css = cf_section_read(cf, lineno, fp, buf1,
977 t2==T_LCBRACE ? NULL : buf2, cs);
979 cf_section_free(&cs);
982 cf_item_add(cs, cf_sectiontoitem(css));
988 * Ignore semi-colons.
994 * Must be a normal attr = value line.
996 if (buf1[0] != 0 && buf2[0] == 0 && buf3[0] == 0) {
998 } else if (buf1[0] == 0 || buf2[0] == 0 ||
999 (t2 < T_EQSTART || t2 > T_EQEND)) {
1000 radlog(L_ERR, "%s[%d]: Line is not in 'attribute = value' format",
1002 cf_section_free(&cs);
1007 * Ensure that the user can't add CONF_PAIRs
1008 * with 'internal' names;
1010 if (buf1[0] == '_') {
1011 radlog(L_ERR, "%s[%d]: Illegal configuration pair name \"%s\"",
1013 cf_section_free(&cs);
1018 * Handle variable substitution via ${foo}
1020 value = cf_expand_variables(cf, lineno, cs, buf, buf3);
1022 cf_section_free(&cs);
1028 * Add this CONF_PAIR to our CONF_SECTION
1030 cpn = cf_pair_alloc(buf1, value, t2, parent);
1031 cpn->item.lineno = *lineno;
1032 cf_item_add(cs, cf_pairtoitem(cpn));
1036 * See if EOF was unexpected ..
1038 if (name1 != NULL) {
1039 radlog(L_ERR, "%s[%d]: Unexpected end of file", cf, *lineno);
1040 cf_section_free(&cs);
1048 * Read the config file.
1050 CONF_SECTION *conf_read(const char *fromfile, int fromline,
1051 const char *conffile, CONF_SECTION *parent)
1057 if ((fp = fopen(conffile, "r")) == NULL) {
1059 radlog(L_ERR|L_CONS, "%s[%d]: Unable to open file \"%s\": %s",
1060 fromfile, fromline, conffile, strerror(errno));
1062 radlog(L_ERR|L_CONS, "Unable to open file \"%s\": %s",
1063 conffile, strerror(errno));
1068 cs = cf_section_read(conffile, &lineno, fp, NULL, NULL, parent);
1077 * Return a CONF_PAIR within a CONF_SECTION.
1079 CONF_PAIR *cf_pair_find(const CONF_SECTION *cs, const char *name)
1083 if (!cs) cs = mainconfig.config;
1086 * Find the name in the tree, for speed.
1092 return rbtree_finddata(cs->pair_tree, &mycp);
1096 * Else find the first one
1098 for (ci = cs->children; ci; ci = ci->next) {
1099 if (ci->type == CONF_ITEM_PAIR)
1100 return cf_itemtopair(ci);
1107 * Return the attr of a CONF_PAIR
1110 char *cf_pair_attr(CONF_PAIR *pair)
1112 return (pair ? pair->attr : NULL);
1116 * Return the value of a CONF_PAIR
1119 char *cf_pair_value(CONF_PAIR *pair)
1121 return (pair ? pair->value : NULL);
1125 * Return the first label of a CONF_SECTION
1128 const char *cf_section_name1(const CONF_SECTION *cs)
1130 return (cs ? cs->name1 : NULL);
1134 * Return the second label of a CONF_SECTION
1137 const char *cf_section_name2(const CONF_SECTION *cs)
1139 return (cs ? cs->name2 : NULL);
1143 * Find a value in a CONF_SECTION
1145 char *cf_section_value_find(const CONF_SECTION *cs, const char *attr)
1149 cp = cf_pair_find(cs, attr);
1151 return (cp ? cp->value : NULL);
1155 * Return the next pair after a CONF_PAIR
1156 * with a certain name (char *attr) If the requested
1157 * attr is NULL, any attr matches.
1160 CONF_PAIR *cf_pair_find_next(const CONF_SECTION *cs,
1161 const CONF_PAIR *pair, const char *attr)
1166 * If pair is NULL this must be a first time run
1167 * Find the pair with correct name
1171 return cf_pair_find(cs, attr);
1174 ci = cf_pairtoitem(pair)->next;
1176 for (; ci; ci = ci->next) {
1177 if (ci->type != CONF_ITEM_PAIR)
1179 if (attr == NULL || strcmp(cf_itemtopair(ci)->attr, attr) == 0)
1183 return cf_itemtopair(ci);
1187 * Find a CONF_SECTION, or return the root if name is NULL
1190 CONF_SECTION *cf_section_find(const char *name)
1193 return cf_section_sub_find(mainconfig.config, name);
1195 return mainconfig.config;
1199 * Find a sub-section in a section
1202 CONF_SECTION *cf_section_sub_find(const CONF_SECTION *cs, const char *name)
1207 * Do the fast lookup if possible.
1209 if (name && cs->section_tree) {
1214 return rbtree_finddata(cs->section_tree, &mycs);
1217 for (ci = cs->children; ci; ci = ci->next) {
1218 if (ci->type != CONF_ITEM_SECTION)
1220 if (strcmp(cf_itemtosection(ci)->name1, name) == 0)
1224 return cf_itemtosection(ci);
1230 * Find a CONF_SECTION with both names.
1232 CONF_SECTION *cf_section_sub_find_name2(const CONF_SECTION *cs,
1233 const char *name1, const char *name2)
1237 if (!name2) return cf_section_sub_find(cs, name1);
1239 if (!cs) cs = mainconfig.config;
1241 if (cs->section_tree) {
1242 CONF_SECTION mycs, *master_cs;
1247 master_cs = rbtree_finddata(cs->section_tree, &mycs);
1249 return rbtree_finddata(master_cs->name2_tree, &mycs);
1254 * Else do it the old-fashioned way.
1256 for (ci = cs->children; ci; ci = ci->next) {
1257 CONF_SECTION *subcs;
1259 if (ci->type != CONF_ITEM_SECTION)
1262 subcs = cf_itemtosection(ci);
1263 if ((strcmp(subcs->name1, name1) == 0) &&
1264 (subcs->name2 != NULL) &&
1265 (strcmp(subcs->name2, name2) == 0))
1269 return cf_itemtosection(ci);
1273 * Return the next subsection after a CONF_SECTION
1274 * with a certain name1 (char *name1). If the requested
1275 * name1 is NULL, any name1 matches.
1278 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
1279 CONF_SECTION *subsection,
1285 * If subsection is NULL this must be a first time run
1286 * Find the subsection with correct name
1289 if (subsection == NULL){
1290 ci = section->children;
1292 ci = cf_sectiontoitem(subsection)->next;
1295 for (; ci; ci = ci->next) {
1296 if (ci->type != CONF_ITEM_SECTION)
1298 if ((name1 == NULL) ||
1299 (strcmp(cf_itemtosection(ci)->name1, name1) == 0))
1303 return cf_itemtosection(ci);
1307 * Return the next item after a CONF_ITEM.
1310 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item)
1313 * If item is NULL this must be a first time run
1314 * Return the first item
1318 return section->children;
1324 int cf_section_lineno(CONF_SECTION *section)
1326 return cf_sectiontoitem(section)->lineno;
1329 int cf_pair_lineno(CONF_PAIR *pair)
1331 return cf_pairtoitem(pair)->lineno;
1334 int cf_item_is_section(CONF_ITEM *item)
1336 return item->type == CONF_ITEM_SECTION;
1342 * JMG dump_config tries to dump the config structure in a readable format
1346 static int dump_config_section(CONF_SECTION *cs, int indent)
1352 /* The DEBUG macro doesn't let me
1353 * for(i=0;i<indent;++i) debugputchar('\t');
1354 * so I had to get creative. --Pac. */
1356 for (ci = cs->children; ci; ci = ci->next) {
1357 if (ci->type == CONF_ITEM_PAIR) {
1358 cp=cf_itemtopair(ci);
1359 DEBUG("%.*s%s = %s",
1360 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1361 cp->attr, cp->value);
1363 scs=cf_itemtosection(ci);
1364 DEBUG("%.*s%s %s%s{",
1365 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1367 scs->name2 ? scs->name2 : "",
1368 scs->name2 ? " " : "");
1369 dump_config_section(scs, indent+1);
1371 indent, "\t\t\t\t\t\t\t\t\t\t\t");
1378 int dump_config(void)
1380 return dump_config_section(mainconfig.config, 0);