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>
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
41 #ifdef HAVE_SYS_STAT_H
49 #include "rad_assert.h"
54 static const char rcsid[] =
57 typedef enum conf_type {
63 struct conf_item *next;
64 struct conf_part *parent;
78 struct conf_item *children;
79 rbtree_t *pair_tree; /* and a partridge.. */
80 rbtree_t *section_tree; /* no jokes here */
81 rbtree_t *name2_tree; /* for sections of the same name2 */
85 * Isolate the scary casts in these tiny provably-safe functions
87 CONF_PAIR *cf_itemtopair(CONF_ITEM *ci)
91 rad_assert(ci->type == CONF_ITEM_PAIR);
92 return (CONF_PAIR *)ci;
94 CONF_SECTION *cf_itemtosection(CONF_ITEM *ci)
98 rad_assert(ci->type == CONF_ITEM_SECTION);
99 return (CONF_SECTION *)ci;
101 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp)
105 return (CONF_ITEM *)cp;
107 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs)
111 return (CONF_ITEM *)cs;
115 * Create a new CONF_PAIR
117 static CONF_PAIR *cf_pair_alloc(const char *attr, const char *value,
118 LRAD_TOKEN operator, CONF_SECTION *parent)
122 cp = rad_malloc(sizeof(*cp));
123 memset(cp, 0, sizeof(*cp));
124 cp->item.type = CONF_ITEM_PAIR;
125 cp->item.parent = parent;
126 cp->attr = strdup(attr);
127 cp->value = strdup(value);
128 cp->operator = operator;
136 void cf_pair_free(CONF_PAIR **cp)
138 if (!cp || !*cp) return;
146 memset(*cp, 0, sizeof(*cp));
155 * rbtree callback function
157 static int pair_cmp(const void *a, const void *b)
159 const CONF_PAIR *one = a;
160 const CONF_PAIR *two = b;
162 return strcmp(one->attr, two->attr);
167 * rbtree callback function
169 static int section_cmp(const void *a, const void *b)
171 const CONF_SECTION *one = a;
172 const CONF_SECTION *two = b;
174 return strcmp(one->name1, two->name1);
179 * rbtree callback function
181 static int name2_cmp(const void *a, const void *b)
183 const CONF_SECTION *one = a;
184 const CONF_SECTION *two = b;
186 rad_assert(strcmp(one->name1, two->name1) == 0);
188 if (!one->name2 && !two->name2) return 0;
189 if (!one->name2) return -1;
190 if (!two->name2) return +1;
192 return strcmp(one->name2, two->name2);
197 * Free a CONF_SECTION
199 void cf_section_free(CONF_SECTION **cs)
201 CONF_ITEM *ci, *next;
203 if (!cs || !*cs) return;
205 for (ci = (*cs)->children; ci; ci = next) {
207 if (ci->type==CONF_ITEM_PAIR) {
208 CONF_PAIR *pair = cf_itemtopair(ci);
211 CONF_SECTION *section = cf_itemtosection(ci);
212 cf_section_free(§ion);
220 if ((*cs)->pair_tree)
221 rbtree_free((*cs)->pair_tree);
222 if ((*cs)->section_tree)
223 rbtree_free((*cs)->section_tree);
224 if ((*cs)->name2_tree)
225 rbtree_free((*cs)->name2_tree);
228 * And free the section
231 memset(*cs, 0, sizeof(*cs));
240 * Allocate a CONF_SECTION
242 static CONF_SECTION *cf_section_alloc(const char *name1, const char *name2,
243 CONF_SECTION *parent)
247 if (name1 == NULL || !name1[0])
250 cs = rad_malloc(sizeof(*cs));
251 memset(cs, 0, sizeof(*cs));
252 cs->item.type = CONF_ITEM_SECTION;
253 cs->item.parent = parent;
254 cs->name1 = strdup(name1);
256 cf_section_free(&cs);
260 if (name2 && *name2) {
261 cs->name2 = strdup(name2);
263 cf_section_free(&cs);
267 cs->pair_tree = rbtree_create(pair_cmp, NULL, 0);
268 if (!cs->pair_tree) {
269 cf_section_free(&cs);
274 * Don't create the section tree here, it may not
282 * Add an item to a configuration section.
284 static void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci_new)
288 for (ci = cs->children; ci && ci->next; ci = ci->next)
292 cs->children = ci_new;
300 if (ci_new->type == CONF_ITEM_PAIR) {
301 rbtree_insert(cs->pair_tree, ci_new);
303 } else if (ci_new->type == CONF_ITEM_SECTION) {
304 const CONF_SECTION *cs_new = cf_itemtosection(ci_new);
306 if (!cs->section_tree) {
307 cs->section_tree = rbtree_create(section_cmp, NULL, 0);
308 /* ignore any errors */
311 if (cs->section_tree) {
312 rbtree_insert(cs->section_tree, cs_new);
316 * Two names: find the named instance.
319 CONF_SECTION *old_cs;
322 * Find the FIRST CONF_SECTION having the
323 * given name1, and create a new tree
326 old_cs = rbtree_finddata(cs->section_tree, cs_new);
327 if (!old_cs) return; /* this is a bad error! */
329 if (!old_cs->name2_tree) {
330 old_cs->name2_tree = rbtree_create(name2_cmp,
333 if (old_cs->name2_tree) {
334 rbtree_insert(old_cs->name2_tree, cs_new);
337 } /* was a section */
339 ci_new = ci_new->next;
340 } /* loop over ci_new */
344 * Expand the variables in an input string.
346 static const char *cf_expand_variables(const char *cf, int *lineno,
347 const CONF_SECTION *outercs,
348 char *output, const char *input)
351 const char *end, *ptr;
353 const CONF_SECTION *parentcs;
356 * Find the master parent conf section.
357 * We can't use mainconfig.config, because we're in the
358 * process of re-building it, and it isn't set up yet...
360 for (parentcs = outercs;
361 parentcs->item.parent != NULL;
362 parentcs = parentcs->item.parent) {
370 * Ignore anything other than "${"
372 if ((*ptr == '$') && (ptr[1] == '{')) {
375 const CONF_SECTION *cs;
378 * FIXME: Add support for ${foo:-bar},
383 * Look for trailing '}', and log a
384 * warning for anything that doesn't match,
385 * and exit with a fatal error.
387 end = strchr(ptr, '}');
390 radlog(L_INFO, "%s[%d]: Variable expansion missing }",
401 * ${.foo} means "foo from the current section"
409 * ${..foo} means "foo from the section
410 * enclosing this section" (etc.)
412 while (*ptr == '.') {
414 cs = cs->item.parent;
421 * ${foo} is local, with
422 * main as lower priority
427 * ${foo.bar.baz} is always rooted
430 for (q = ptr; *q && q != end; q++) {
442 * Find the next section.
445 (*ptr != 0) && (*ptr != '.') &&
453 * The character is a '.', find a
454 * section (as the user has given
455 * us a subsection to find)
460 ptr++; /* skip the period */
463 * Find the sub-section.
465 next = cf_section_sub_find(cs, name);
467 radlog(L_ERR, "config: No such section %s in variable %s", name, input);
472 } else { /* no period, must be a conf-part */
474 * Find in the current referenced
477 cp = cf_pair_find(cs, name);
480 * It it was NOT ${..foo}
482 * top-level config items.
484 if (!up) cp = cf_pair_find(parentcs, name);
487 radlog(L_ERR, "config: No such entry %s for string %s", name, input);
491 } /* until cp is non-NULL */
494 * Substitute the value of the variable.
496 strcpy(p, cp->value);
500 } else if (memcmp(ptr, "$ENV{", 5) == 0) {
506 * Look for trailing '}', and log a
507 * warning for anything that doesn't match,
508 * and exit with a fatal error.
510 end = strchr(ptr, '}');
513 radlog(L_INFO, "%s[%d]: Environment variable expansion missing }",
518 memcpy(name, ptr, end - ptr);
519 name[end - ptr] = '\0';
522 * Get the environment variable.
523 * If none exists, then make it an empty string.
537 * Copy it over verbatim.
541 } /* loop over all of the input string. */
550 * Parses an item (not a CONF_ITEM) into the specified format,
551 * with a default value.
553 * Returns -1 on error, 0 for correctly parsed, and 1 if the
554 * default value was used. Note that the default value will be
555 * used ONLY if the CONF_PAIR is NULL.
557 int cf_item_parse(const CONF_SECTION *cs, const char *name,
558 int type, void *data, const char *dflt)
563 lrad_ipaddr_t ipaddr;
567 cp = cf_pair_find(cs, name);
572 return 1; /* nothing to parse, return default value */
580 case PW_TYPE_BOOLEAN:
582 * Allow yes/no and on/off
584 if ((strcasecmp(value, "yes") == 0) ||
585 (strcasecmp(value, "on") == 0)) {
587 } else if ((strcasecmp(value, "no") == 0) ||
588 (strcasecmp(value, "off") == 0)) {
592 radlog(L_ERR, "Bad value \"%s\" for boolean variable %s", value, name);
595 DEBUG2(" %s: %s = %s", cs->name1, name, value);
598 case PW_TYPE_INTEGER:
599 *(int *)data = strtol(value, 0, 0);
600 DEBUG2(" %s: %s = %d",
605 case PW_TYPE_STRING_PTR:
612 * Expand variables which haven't already been
613 * expanded automagically when the configuration
619 int lineno = cs->item.lineno;
622 * FIXME: sizeof(buffer)?
624 value = cf_expand_variables("?",
627 if (!value) return -1;
630 DEBUG2(" %s: %s = \"%s\"",
632 value ? value : "(null)");
633 *q = value ? strdup(value) : NULL;
638 * Allow '*' as any address
640 if (strcmp(value, "*") == 0) {
641 *(uint32_t *) data = htonl(INADDR_ANY);
642 DEBUG2(" %s: %s = *", cs->name1, name);
645 if (ip_hton(value, AF_INET, &ipaddr) < 0) {
646 radlog(L_ERR, "Can't find IP address for host %s", value);
649 DEBUG2(" %s: %s = %s IP address [%s]",
650 cs->name1, name, value,
651 ip_ntoh(&ipaddr, ipbuf, sizeof(ipbuf)));
652 *(uint32_t *) data = ipaddr.ipaddr.ip4addr.s_addr;
655 case PW_TYPE_IPV6ADDR:
656 if (ip_hton(value, AF_INET6, &ipaddr) < 0) {
657 radlog(L_ERR, "Can't find IPv6 address for host %s", value);
660 DEBUG2(" %s: %s = %s IPv6 address [%s]",
661 cs->name1, name, value,
662 ip_ntoh(&ipaddr, ipbuf, sizeof(ipbuf)));
663 memcpy(data, &ipaddr.ipaddr.ip6addr,
664 sizeof(ipaddr.ipaddr.ip6addr));
668 radlog(L_ERR, "type %d not supported yet", type);
671 } /* switch over variable type */
677 * Parse a configuration section into user-supplied variables.
679 int cf_section_parse(const CONF_SECTION *cs, void *base,
680 const CONF_PARSER *variables)
686 * Handle the known configuration parameters.
688 for (i = 0; variables[i].name != NULL; i++) {
690 * Handle subsections specially
692 if (variables[i].type == PW_TYPE_SUBSECTION) {
693 const CONF_SECTION *subcs;
694 subcs = cf_section_sub_find(cs, variables[i].name);
697 * If the configuration section is NOT there,
700 * FIXME! This is probably wrong... we should
701 * probably set the items to their default values.
703 if (!subcs) continue;
705 if (!variables[i].data) {
706 DEBUG2("Internal sanity check 1 failed in cf_section_parse");
710 if (cf_section_parse(subcs, base,
711 (CONF_PARSER *) variables[i].data) < 0) {
715 } /* else it's a CONF_PAIR */
717 if (variables[i].data) {
718 data = variables[i].data; /* prefer this. */
720 data = ((char *)base) + variables[i].offset;
722 DEBUG2("Internal sanity check 2 failed in cf_section_parse");
727 * Parse the pair we found, or a default value.
729 if (cf_item_parse(cs, variables[i].name, variables[i].type,
730 data, variables[i].dflt) < 0) {
733 } /* for all variables in the configuration section */
739 * Used in a few places, so in one function for clarity.
741 static void cf_fixup_children(CONF_SECTION *cs, CONF_SECTION *is)
744 * Add the included conf
745 * to our CONF_SECTION
747 if (is->children != NULL) {
751 * Re-write the parent of the
752 * moved children to be the
753 * upper-layer section.
755 for (ci = is->children; ci; ci = ci->next) {
760 * If there are children, then
761 * move them up a layer.
764 cf_item_add(cs, is->children);
769 * Always free the section for the
772 cf_section_free(&is);
777 * Read a part of the config file.
779 static CONF_SECTION *cf_section_read(const char *cf, int *lineno, FILE *fp,
780 const char *name1, const char *name2,
781 CONF_SECTION *parent)
783 CONF_SECTION *cs, *css;
796 * Ensure that the user can't add CONF_SECTIONs
797 * with 'internal' names;
799 if ((name1 != NULL) && (name1[0] == '_')) {
800 radlog(L_ERR, "%s[%d]: Illegal configuration section name",
806 * Allocate new section.
808 cs = cf_section_alloc(name1, name2, parent);
809 cs->item.lineno = *lineno;
812 * Read, checking for line continuations ('\\' at EOL)
818 * Get data, and remember if we are at EOF.
820 eof = (fgets(cbuf, sizeof(buf) - (cbuf - buf), fp) == NULL);
826 * We've filled the buffer, and there isn't
829 if ((len == sizeof(buf)) &&
830 (cbuf[len - 1] != '\n')) {
831 radlog(L_ERR, "%s[%d]: Line too long",
833 cf_section_free(&cs);
838 * Check for continuations.
840 if (cbuf[len - 1] == '\n') len--;
843 * Last character is '\\'. Over-write it,
844 * and read another line.
846 if ((len > 0) && (cbuf[len - 1] == '\\')) {
847 cbuf[len - 1] = '\0';
853 * We're at EOF, and haven't read anything. Stop.
855 if (eof && (cbuf == buf)) {
860 t1 = gettoken(&ptr, buf1, sizeof(buf1));
863 * Skip comments and blank lines immediately.
865 if ((*buf1 == '#') || (*buf1 == '\0')) {
870 * Allow for $INCLUDE files
872 * This *SHOULD* work for any level include.
873 * I really really really hate this file. -cparker
875 if (strcasecmp(buf1, "$INCLUDE") == 0) {
878 t2 = getword(&ptr, buf2, sizeof(buf2));
880 value = cf_expand_variables(cf, lineno, cs, buf, buf2);
882 cf_section_free(&cs);
890 * Include ALL non-"dot" files in the directory.
893 if (value[strlen(value) - 1] == '/') {
896 struct stat stat_buf;
898 DEBUG2( "Config: including files in directory: %s", value );
899 dir = opendir(value);
901 radlog(L_ERR, "%s[%d]: Error reading directory %s: %s",
904 cf_section_free(&cs);
909 * Read the directory, ignoring "." files.
911 while ((dp = readdir(dir)) != NULL) {
914 if (dp->d_name[0] == '.') continue;
917 * Check for valid characters
919 for (p = dp->d_name; *p != '\0'; p++) {
920 if (isalpha((int)*p) ||
923 (*p == '.')) continue;
926 if (*p != '\0') continue;
928 snprintf(buf2, sizeof(buf2), "%s%s",
930 if ((stat(buf2, &stat_buf) != 0) ||
931 S_ISDIR(stat_buf.st_mode)) continue;
932 if ((is = conf_read(cf, *lineno, buf2, parent)) == NULL) {
934 cf_section_free(&cs);
938 cf_fixup_children(cs, is);
943 { /* it was a normal file */
944 DEBUG2( "Config: including file: %s", value );
945 if ((is = conf_read(cf, *lineno, value, parent)) == NULL) {
946 cf_section_free(&cs);
949 cf_fixup_children(cs, is);
952 } /* we were in an include */
955 * No '=': must be a section or sub-section.
957 if (strchr(ptr, '=') == NULL) {
958 t2 = gettoken(&ptr, buf2, sizeof(buf2));
959 t3 = gettoken(&ptr, buf3, sizeof(buf3));
961 t2 = gettoken(&ptr, buf2, sizeof(buf2));
962 t3 = getword(&ptr, buf3, sizeof(buf3));
966 * See if it's the end of a section.
968 if (t1 == T_RCBRACE) {
969 if (name1 == NULL || buf2[0]) {
970 radlog(L_ERR, "%s[%d]: Unexpected end of section",
972 cf_section_free(&cs);
979 * Perhaps a subsection.
981 if (t2 == T_LCBRACE || t3 == T_LCBRACE) {
982 css = cf_section_read(cf, lineno, fp, buf1,
983 t2==T_LCBRACE ? NULL : buf2, cs);
985 cf_section_free(&cs);
988 cf_item_add(cs, cf_sectiontoitem(css));
994 * Ignore semi-colons.
1000 * Must be a normal attr = value line.
1002 if (buf1[0] != 0 && buf2[0] == 0 && buf3[0] == 0) {
1004 } else if (buf1[0] == 0 || buf2[0] == 0 ||
1005 (t2 < T_EQSTART || t2 > T_EQEND)) {
1006 radlog(L_ERR, "%s[%d]: Line is not in 'attribute = value' format",
1008 cf_section_free(&cs);
1013 * Ensure that the user can't add CONF_PAIRs
1014 * with 'internal' names;
1016 if (buf1[0] == '_') {
1017 radlog(L_ERR, "%s[%d]: Illegal configuration pair name \"%s\"",
1019 cf_section_free(&cs);
1024 * Handle variable substitution via ${foo}
1026 value = cf_expand_variables(cf, lineno, cs, buf, buf3);
1028 cf_section_free(&cs);
1034 * Add this CONF_PAIR to our CONF_SECTION
1036 cpn = cf_pair_alloc(buf1, value, t2, parent);
1037 cpn->item.lineno = *lineno;
1038 cf_item_add(cs, cf_pairtoitem(cpn));
1042 * See if EOF was unexpected ..
1044 if (name1 != NULL) {
1045 radlog(L_ERR, "%s[%d]: Unexpected end of file", cf, *lineno);
1046 cf_section_free(&cs);
1054 * Read the config file.
1056 CONF_SECTION *conf_read(const char *fromfile, int fromline,
1057 const char *conffile, CONF_SECTION *parent)
1063 if ((fp = fopen(conffile, "r")) == NULL) {
1065 radlog(L_ERR|L_CONS, "%s[%d]: Unable to open file \"%s\": %s",
1066 fromfile, fromline, conffile, strerror(errno));
1068 radlog(L_ERR|L_CONS, "Unable to open file \"%s\": %s",
1069 conffile, strerror(errno));
1074 cs = cf_section_read(conffile, &lineno, fp, NULL, NULL, parent);
1083 * Return a CONF_PAIR within a CONF_SECTION.
1085 CONF_PAIR *cf_pair_find(const CONF_SECTION *cs, const char *name)
1089 if (!cs) cs = mainconfig.config;
1092 * Find the name in the tree, for speed.
1098 return rbtree_finddata(cs->pair_tree, &mycp);
1102 * Else find the first one
1104 for (ci = cs->children; ci; ci = ci->next) {
1105 if (ci->type == CONF_ITEM_PAIR)
1106 return cf_itemtopair(ci);
1113 * Return the attr of a CONF_PAIR
1116 char *cf_pair_attr(CONF_PAIR *pair)
1118 return (pair ? pair->attr : NULL);
1122 * Return the value of a CONF_PAIR
1125 char *cf_pair_value(CONF_PAIR *pair)
1127 return (pair ? pair->value : NULL);
1131 * Return the first label of a CONF_SECTION
1134 const char *cf_section_name1(const CONF_SECTION *cs)
1136 return (cs ? cs->name1 : NULL);
1140 * Return the second label of a CONF_SECTION
1143 const char *cf_section_name2(const CONF_SECTION *cs)
1145 return (cs ? cs->name2 : NULL);
1149 * Find a value in a CONF_SECTION
1151 char *cf_section_value_find(const CONF_SECTION *cs, const char *attr)
1155 cp = cf_pair_find(cs, attr);
1157 return (cp ? cp->value : NULL);
1161 * Return the next pair after a CONF_PAIR
1162 * with a certain name (char *attr) If the requested
1163 * attr is NULL, any attr matches.
1166 CONF_PAIR *cf_pair_find_next(const CONF_SECTION *cs,
1167 const CONF_PAIR *pair, const char *attr)
1172 * If pair is NULL this must be a first time run
1173 * Find the pair with correct name
1177 return cf_pair_find(cs, attr);
1180 ci = cf_pairtoitem(pair)->next;
1182 for (; ci; ci = ci->next) {
1183 if (ci->type != CONF_ITEM_PAIR)
1185 if (attr == NULL || strcmp(cf_itemtopair(ci)->attr, attr) == 0)
1189 return cf_itemtopair(ci);
1193 * Find a CONF_SECTION, or return the root if name is NULL
1196 CONF_SECTION *cf_section_find(const char *name)
1199 return cf_section_sub_find(mainconfig.config, name);
1201 return mainconfig.config;
1205 * Find a sub-section in a section
1208 CONF_SECTION *cf_section_sub_find(const CONF_SECTION *cs, const char *name)
1213 * Do the fast lookup if possible.
1215 if (name && cs->section_tree) {
1220 return rbtree_finddata(cs->section_tree, &mycs);
1223 for (ci = cs->children; ci; ci = ci->next) {
1224 if (ci->type != CONF_ITEM_SECTION)
1226 if (strcmp(cf_itemtosection(ci)->name1, name) == 0)
1230 return cf_itemtosection(ci);
1236 * Find a CONF_SECTION with both names.
1238 CONF_SECTION *cf_section_sub_find_name2(const CONF_SECTION *cs,
1239 const char *name1, const char *name2)
1243 if (!name2) return cf_section_sub_find(cs, name1);
1245 if (!cs) cs = mainconfig.config;
1247 if (cs->section_tree) {
1248 CONF_SECTION mycs, *master_cs;
1253 master_cs = rbtree_finddata(cs->section_tree, &mycs);
1255 return rbtree_finddata(master_cs->name2_tree, &mycs);
1260 * Else do it the old-fashioned way.
1262 for (ci = cs->children; ci; ci = ci->next) {
1263 CONF_SECTION *subcs;
1265 if (ci->type != CONF_ITEM_SECTION)
1268 subcs = cf_itemtosection(ci);
1269 if ((strcmp(subcs->name1, name1) == 0) &&
1270 (subcs->name2 != NULL) &&
1271 (strcmp(subcs->name2, name2) == 0))
1275 return cf_itemtosection(ci);
1279 * Return the next subsection after a CONF_SECTION
1280 * with a certain name1 (char *name1). If the requested
1281 * name1 is NULL, any name1 matches.
1284 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
1285 CONF_SECTION *subsection,
1291 * If subsection is NULL this must be a first time run
1292 * Find the subsection with correct name
1295 if (subsection == NULL){
1296 ci = section->children;
1298 ci = cf_sectiontoitem(subsection)->next;
1301 for (; ci; ci = ci->next) {
1302 if (ci->type != CONF_ITEM_SECTION)
1304 if ((name1 == NULL) ||
1305 (strcmp(cf_itemtosection(ci)->name1, name1) == 0))
1309 return cf_itemtosection(ci);
1313 * Return the next item after a CONF_ITEM.
1316 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item)
1319 * If item is NULL this must be a first time run
1320 * Return the first item
1324 return section->children;
1330 int cf_section_lineno(CONF_SECTION *section)
1332 return cf_sectiontoitem(section)->lineno;
1335 int cf_pair_lineno(CONF_PAIR *pair)
1337 return cf_pairtoitem(pair)->lineno;
1340 int cf_item_is_section(CONF_ITEM *item)
1342 return item->type == CONF_ITEM_SECTION;
1348 * JMG dump_config tries to dump the config structure in a readable format
1352 static int dump_config_section(CONF_SECTION *cs, int indent)
1358 /* The DEBUG macro doesn't let me
1359 * for(i=0;i<indent;++i) debugputchar('\t');
1360 * so I had to get creative. --Pac. */
1362 for (ci = cs->children; ci; ci = ci->next) {
1363 if (ci->type == CONF_ITEM_PAIR) {
1364 cp=cf_itemtopair(ci);
1365 DEBUG("%.*s%s = %s",
1366 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1367 cp->attr, cp->value);
1369 scs=cf_itemtosection(ci);
1370 DEBUG("%.*s%s %s%s{",
1371 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1373 scs->name2 ? scs->name2 : "",
1374 scs->name2 ? " " : "");
1375 dump_config_section(scs, indent+1);
1377 indent, "\t\t\t\t\t\t\t\t\t\t\t");
1384 int dump_config(void)
1386 return dump_config_section(mainconfig.config, 0);