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;
82 static int generate_realms(const char *filename);
83 static int generate_clients(const char *filename);
84 static CONF_SECTION *conf_read(const char *fromfile, int fromline,
85 const char *conffile, CONF_SECTION *parent);
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);
207 * And free the section
210 memset(*cs, 0, sizeof(*cs));
218 * Add an item to a configuration section.
220 static void cf_item_add(CONF_SECTION *cs, CONF_ITEM *ci_new)
224 for (ci = cs->children; ci && ci->next; ci = ci->next)
228 cs->children = ci_new;
234 * Expand the variables in an input string.
236 static const char *cf_expand_variables(const char *cf, int *lineno,
238 char *output, const char *input)
241 const char *end, *ptr;
244 CONF_SECTION *outercs;
248 while (*ptr >= ' ') {
250 * Ignore anything other than "${"
252 if ((*ptr == '$') && (ptr[1] == '{')) {
254 * Look for trailing '}', and log a
255 * warning for anything that doesn't match,
256 * and exit with a fatal error.
258 end = strchr(ptr, '}');
261 radlog(L_INFO, "%s[%d]: Variable expansion missing }",
268 memcpy(name, ptr, end - ptr);
269 name[end - ptr] = '\0';
271 cpn = cf_pair_find(cs, name);
274 * Also look recursively up the section tree,
275 * so things like ${confdir} can be defined
276 * there and used inside the module config
279 for (outercs=cs->item.parent;
280 (cpn == NULL) && (outercs != NULL);
281 outercs=outercs->item.parent) {
282 cpn = cf_pair_find(outercs, name);
285 radlog(L_ERR, "%s[%d]: Unknown variable \"%s\"",
291 * Substitute the value of the variable.
293 strcpy(p, cpn->value);
297 } else if (memcmp(ptr, "$ENV{", 5) == 0) {
303 * Look for trailing '}', and log a
304 * warning for anything that doesn't match,
305 * and exit with a fatal error.
307 end = strchr(ptr, '}');
310 radlog(L_INFO, "%s[%d]: Environment variable expansion missing }",
315 memcpy(name, ptr, end - ptr);
316 name[end - ptr] = '\0';
319 * Get the environment variable.
320 * If none exists, then make it an empty string.
334 * Copy it over verbatim.
338 } /* loop over all of the input string. */
346 * Parse a configuration section into user-supplied variables.
348 int cf_section_parse(CONF_SECTION *cs, void *base, const CONF_PARSER *variables)
354 CONF_SECTION *subsection;
361 * Handle the user-supplied variables.
363 for (i = 0; variables[i].name != NULL; i++) {
364 value = variables[i].dflt;
366 data = ((char *)base) + variables[i].offset;
368 data = variables[i].data;
371 cp = cf_pair_find(cs, variables[i].name);
376 switch (variables[i].type)
378 case PW_TYPE_SUBSECTION:
379 subsection = cf_section_sub_find(cs,variables[i].name);
382 * If the configuration section is NOT there,
385 * FIXME! This is probably wrong... we should
386 * probably set the items to their default values.
388 if (subsection == NULL) {
392 rcode = cf_section_parse(subsection, base,
393 (CONF_PARSER *) data);
399 case PW_TYPE_BOOLEAN:
401 * Allow yes/no and on/off
403 if ((strcasecmp(value, "yes") == 0) ||
404 (strcasecmp(value, "on") == 0)) {
406 } else if ((strcasecmp(value, "no") == 0) ||
407 (strcasecmp(value, "off") == 0)) {
411 radlog(L_ERR, "Bad value \"%s\" for boolean variable %s", value, variables[i].name);
414 DEBUG2(" %s: %s = %s",
420 case PW_TYPE_INTEGER:
421 *(int *)data = strtol(value, 0, 0);
422 DEBUG2(" %s: %s = %d",
428 case PW_TYPE_STRING_PTR:
430 if (base == NULL && *q != NULL) {
435 * Expand variables while parsing,
436 * but ONLY expand ones which haven't already
439 if (value && (value == variables[i].dflt)) {
440 value = cf_expand_variables(NULL, 0, cs, buffer,value);
446 DEBUG2(" %s: %s = \"%s\"",
449 value ? value : "(null)");
450 *q = value ? strdup(value) : NULL;
455 * Allow '*' as any address
457 if (strcmp(value, "*") == 0) {
458 *(uint32_t *) data = 0;
461 ipaddr = ip_getaddr(value);
463 radlog(L_ERR, "Can't find IP address for host %s", value);
466 DEBUG2(" %s: %s = %s IP address [%s]",
469 value, ip_ntoa(buffer, ipaddr));
470 *(uint32_t *) data = ipaddr;
474 radlog(L_ERR, "type %d not supported yet", variables[i].type);
477 } /* switch over variable type */
478 } /* for all variables in the configuration section */
484 * Read a part of the config file.
486 static CONF_SECTION *cf_section_read(const char *cf, int *lineno, FILE *fp,
487 const char *name1, const char *name2,
488 CONF_SECTION *parent)
490 CONF_SECTION *cs, *css;
501 * Ensure that the user can't add CONF_SECTIONs
502 * with 'internal' names;
504 if ((name1 != NULL) && (name1[0] == '_')) {
505 radlog(L_ERR, "%s[%d]: Illegal configuration section name",
511 * Allocate new section.
513 cs = cf_section_alloc(name1, name2, parent);
514 cs->item.lineno = *lineno;
519 while (fgets(buf, sizeof(buf), fp) != NULL) {
523 t1 = gettoken(&ptr, buf1, sizeof(buf1));
526 * Skip comments and blank lines immediately.
528 if ((*buf1 == '#') || (*buf1 == '\0')) {
533 * Allow for $INCLUDE files
535 * This *SHOULD* work for any level include.
536 * I really really really hate this file. -cparker
538 if (strcasecmp(buf1, "$INCLUDE") == 0) {
542 t2 = getword(&ptr, buf2, sizeof(buf2));
544 value = cf_expand_variables(cf, lineno, cs, buf, buf2);
546 cf_section_free(&cs);
550 DEBUG2( "Config: including file: %s", value );
552 if ((is = conf_read(cf, *lineno, value, parent)) == NULL) {
553 cf_section_free(&cs);
558 * Add the included conf to our CONF_SECTION
561 if (is->children != NULL) {
565 * Re-write the parent of the
566 * moved children to be the
567 * upper-layer section.
569 for (ci = is->children; ci; ci = ci->next) {
574 * If there are children, then
575 * move them up a layer.
578 cf_item_add(cs, is->children);
583 * Always free the section for the
586 cf_section_free(&is);
593 * No '=': must be a section or sub-section.
595 if (strchr(ptr, '=') == NULL) {
596 t2 = gettoken(&ptr, buf2, sizeof(buf2));
597 t3 = gettoken(&ptr, buf3, sizeof(buf3));
599 t2 = gettoken(&ptr, buf2, sizeof(buf2));
600 t3 = getword(&ptr, buf3, sizeof(buf3));
604 * See if it's the end of a section.
606 if (t1 == T_RCBRACE) {
607 if (name1 == NULL || buf2[0]) {
608 radlog(L_ERR, "%s[%d]: Unexpected end of section",
610 cf_section_free(&cs);
617 * Perhaps a subsection.
619 if (t2 == T_LCBRACE || t3 == T_LCBRACE) {
620 css = cf_section_read(cf, lineno, fp, buf1,
621 t2==T_LCBRACE ? NULL : buf2, cs);
623 cf_section_free(&cs);
626 cf_item_add(cs, cf_sectiontoitem(css));
632 * Ignore semi-colons.
638 * Must be a normal attr = value line.
640 if (buf1[0] != 0 && buf2[0] == 0 && buf3[0] == 0) {
642 } else if (buf1[0] == 0 || buf2[0] == 0 || buf3[0] == 0 ||
643 (t2 < T_EQSTART || t2 > T_EQEND)) {
644 radlog(L_ERR, "%s[%d]: Line is not in 'attribute = value' format",
646 cf_section_free(&cs);
651 * Ensure that the user can't add CONF_PAIRs
652 * with 'internal' names;
654 if (buf1[0] == '_') {
655 radlog(L_ERR, "%s[%d]: Illegal configuration pair name \"%s\"",
657 cf_section_free(&cs);
662 * Handle variable substitution via ${foo}
664 value = cf_expand_variables(cf, lineno, cs, buf, buf3);
666 cf_section_free(&cs);
672 * Add this CONF_PAIR to our CONF_SECTION
674 cpn = cf_pair_alloc(buf1, value, t2, parent);
675 cpn->item.lineno = *lineno;
676 cf_item_add(cs, cf_pairtoitem(cpn));
680 * See if EOF was unexpected ..
683 radlog(L_ERR, "%s[%d]: Unexpected end of file", cf, *lineno);
684 cf_section_free(&cs);
692 * Read the config file.
694 static CONF_SECTION *conf_read(const char *fromfile, int fromline,
695 const char *conffile, CONF_SECTION *parent)
701 if ((fp = fopen(conffile, "r")) == NULL) {
703 radlog(L_ERR|L_CONS, "%s[%d]: Unable to open file \"%s\": %s",
704 fromfile, fromline, conffile, strerror(errno));
706 radlog(L_ERR|L_CONS, "Unable to open file \"%s\": %s",
707 conffile, strerror(errno));
713 cs = cf_section_read(conffile, &lineno, fp, NULL, NULL, parent);
715 cs = cf_section_read(conffile, &lineno, fp, NULL, NULL, NULL);
724 * These are not used anywhere else..
726 static const char *localstatedir = NULL;
727 static const char *prefix = NULL;
729 static CONF_PARSER directory_config[] = {
731 * FIXME: 'prefix' is the ONLY one which should be configured
732 * at compile time. Hard-coding it here is bad. It will be cleaned
733 * up once we clean up the hard-coded defines for the locations of
736 { "prefix", PW_TYPE_STRING_PTR, 0, &prefix, "/usr/local"},
737 { "localstatedir", PW_TYPE_STRING_PTR, 0, &localstatedir, "${prefix}/var"},
738 { "logdir", PW_TYPE_STRING_PTR, 0, &radlog_dir, "${localstatedir}/log"},
739 { "libdir", PW_TYPE_STRING_PTR, 0, &radlib_dir, "${prefix}/lib"},
740 { "radacctdir", PW_TYPE_STRING_PTR, 0, &radacct_dir, "${logdir}/radacct" },
741 { "hostname_lookups", PW_TYPE_BOOLEAN, 0, &librad_dodns, "no" },
744 * We don't allow re-defining this, as doing so will cause
745 * all sorts of confusion.
748 { "confdir", PW_TYPE_STRING_PTR, 0, &radius_dir, RADIUS_DIR },
750 { NULL, -1, 0, NULL, NULL }
754 int read_radius_conf_file(void)
759 /* Lets go look for the new configuration files */
760 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
761 if ((cs = conf_read(NULL, 0, buffer, NULL)) == NULL) {
766 * Free the old configuration data, and replace it
769 cf_section_free(&config);
773 * And parse the directory configuration values.
775 cs = cf_section_find(NULL);
780 * This allows us to figure out where, relative to
781 * radiusd.conf, the other configuration files exist.
783 cf_section_parse(cs, NULL, directory_config);
785 /* Initialize the dictionary */
786 DEBUG2("read_config_files: reading dictionary");
787 if (dict_init(radius_dir, RADIUS_DICTIONARY) != 0) {
788 radlog(L_ERR|L_CONS, "Errors reading dictionary: %s",
793 /* old-style clients file */
794 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CLIENTS);
795 DEBUG2("read_config_files: reading clients");
796 if (read_clients_file(buffer) < 0) {
797 radlog(L_ERR|L_CONS, "Errors reading clients");
802 * Add to that, the *new* list of clients.
804 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
805 if (generate_clients(buffer) < 0) {
809 /* old-style realms file */
810 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_REALMS);
811 DEBUG2("read_config_files: reading realms");
812 if (read_realms_file(buffer) < 0) {
813 radlog(L_ERR|L_CONS, "Errors reading realms");
818 * If there isn't any realms it isn't fatal..
820 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);
821 if (generate_realms(buffer) < 0) {
825 /* old-style naslist file */
826 snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_NASLIST);
827 DEBUG2("read_config_files: reading naslist");
828 if (read_naslist_file(buffer) < 0) {
829 radlog(L_ERR|L_CONS, "Errors reading naslist");
837 * Create the linked list of realms from the new configuration type
838 * This way we don't have to change to much in the other source-files
841 static int generate_realms(const char *filename)
845 char *s, *authhost, *accthost;
847 for (cs = cf_subsection_find_next(config, NULL, "realm"); cs != NULL;
848 cs = cf_subsection_find_next(config, cs, "realm")) {
850 radlog(L_CONS|L_ERR, "%s[%d]: Missing realm name", filename, cs->item.lineno);
854 * We've found a realm, allocate space for it
856 c = rad_malloc(sizeof(REALM));
857 memset(c, 0, sizeof(REALM));
859 * An authhost must exist in the configuration
861 if ((authhost = cf_section_value_find(cs, "authhost")) == NULL) {
863 "%s[%d]: No authhost entry in realm",
864 filename, cs->item.lineno);
867 if ((s = strchr(authhost, ':')) != NULL) {
869 c->auth_port = atoi(s);
871 c->auth_port = auth_port;
873 accthost = cf_section_value_find(cs, "accthost");
874 if ((s =strchr(accthost, ':')) != NULL) {
876 c->acct_port = atoi(s);
878 c->acct_port = acct_port;
880 if (strcmp(authhost, "LOCAL") != 0)
881 c->ipaddr = ip_getaddr(authhost);
884 * Double check length, just to be sure!
886 if (strlen(authhost) >= sizeof(c->server)) {
887 radlog(L_ERR, "%s[%d]: Server name of length %d is greater that allowed: %d",
888 filename, cs->item.lineno,
889 strlen(authhost), sizeof(c->server) - 1);
892 if (strlen(cs->name2) >= sizeof(c->realm)) {
893 radlog(L_ERR, "%s[%d]: Realm name of length %d is greater than allowed %d",
894 filename, cs->item.lineno,
895 strlen(cs->name2), sizeof(c->server) - 1);
899 strcpy(c->realm, cs->name2);
900 strcpy(c->server, authhost);
902 s = cf_section_value_find(cs, "secret");
904 radlog(L_ERR, "%s[%d]: No shared secret supplied for realm",
905 filename, cs->item.lineno);
909 if (strlen(s) >= sizeof(c->secret)) {
910 radlog(L_ERR, "%s[%d]: Secret of length %d is greater than the allowed maximum of %d.",
911 filename, cs->item.lineno,
912 strlen(s), sizeof(c->secret) - 1);
915 strNcpy((char *)c->secret, s, sizeof(c->secret));
919 if ((cf_section_value_find(cs, "nostrip")) != NULL)
921 if ((cf_section_value_find(cs, "noacct")) != NULL)
923 if ((cf_section_value_find(cs, "trusted")) != NULL)
925 if ((cf_section_value_find(cs, "notrealm")) != NULL)
927 if ((cf_section_value_find(cs, "notsuffix")) != NULL)
940 * Create the linked list of realms from the new configuration type
941 * This way we don't have to change to much in the other source-files
943 static int generate_clients(const char *filename)
947 char *hostnm, *secret, *shortnm, *netmask;
949 for (cs = cf_subsection_find_next(config, NULL, "client"); cs != NULL;
950 cs = cf_subsection_find_next(config, cs, "client")) {
952 radlog(L_CONS|L_ERR, "%s[%d]: Missing client name", filename, cs->item.lineno);
956 * Check the lengths, we don't want any core dumps
959 secret = cf_section_value_find(cs, "secret");
960 shortnm = cf_section_value_find(cs, "shortname");
961 netmask = strchr(hostnm, '/');
963 if (strlen(secret) >= sizeof(c->secret)) {
964 radlog(L_ERR, "%s[%d]: Secret of length %d is greater than the allowed maximum of %d.",
965 filename, cs->item.lineno,
966 strlen(secret), sizeof(c->secret) - 1);
969 if (strlen(shortnm) > sizeof(c->shortname)) {
970 radlog(L_ERR, "%s[%d]: Client short name of length %d is greater than the allowed maximum of %d.",
971 filename, cs->item.lineno,
972 strlen(shortnm), sizeof(c->shortname) - 1);
976 * The size is fine.. Let's create the buffer
978 c = rad_malloc(sizeof(RADCLIENT));
987 mask_length = atoi(netmask + 1);
988 if ((mask_length <= 0) || (mask_length > 32)) {
989 radlog(L_ERR, "%s[%d]: Invalid value '%s' for IP network mask.",
990 filename, cs->item.lineno, netmask + 1);
994 c->netmask = (1 << 31);
995 for (i = 1; i < mask_length; i++) {
996 c->netmask |= (c->netmask >> 1);
1000 c->netmask = htonl(c->netmask);
1003 c->ipaddr = ip_getaddr(hostnm);
1004 if (c->ipaddr == INADDR_NONE) {
1005 radlog(L_CONS|L_ERR, "%s[%d]: Failed to look up hostname %s",
1006 filename, cs->item.lineno, hostnm);
1011 * Update the client name again...
1015 c->ipaddr &= c->netmask;
1016 strcpy(c->longname, hostnm);
1018 ip_hostname(c->longname, sizeof(c->longname),
1022 strcpy((char *)c->secret, secret);
1023 strcpy(c->shortname, shortnm);
1033 * Return a CONF_PAIR within a CONF_SECTION.
1036 CONF_PAIR *cf_pair_find(CONF_SECTION *section, const char *name)
1040 if (section == NULL) {
1044 for (ci = section->children; ci; ci = ci->next) {
1045 if (ci->type != CONF_ITEM_PAIR)
1047 if (name == NULL || strcmp(cf_itemtopair(ci)->attr, name) == 0)
1051 return cf_itemtopair(ci);
1055 * Return the attr of a CONF_PAIR
1058 char *cf_pair_attr(CONF_PAIR *pair)
1060 return (pair ? pair->attr : NULL);
1064 * Return the value of a CONF_PAIR
1067 char *cf_pair_value(CONF_PAIR *pair)
1069 return (pair ? pair->value : NULL);
1073 * Return the first label of a CONF_SECTION
1076 char *cf_section_name1(CONF_SECTION *section)
1078 return (section ? section->name1 : NULL);
1082 * Return the second label of a CONF_SECTION
1085 char *cf_section_name2(CONF_SECTION *section)
1087 return (section ? section->name2 : NULL);
1091 * Find a value in a CONF_SECTION
1093 char *cf_section_value_find(CONF_SECTION *section, const char *attr)
1097 cp = cf_pair_find(section, attr);
1099 return (cp ? cp->value : NULL);
1103 * Return the next pair after a CONF_PAIR
1104 * with a certain name (char *attr) If the requested
1105 * attr is NULL, any attr matches.
1108 CONF_PAIR *cf_pair_find_next(CONF_SECTION *section, CONF_PAIR *pair, const char *attr)
1113 * If pair is NULL this must be a first time run
1114 * Find the pair with correct name
1118 return cf_pair_find(section, attr);
1121 ci = cf_pairtoitem(pair)->next;
1123 for (; ci; ci = ci->next) {
1124 if (ci->type != CONF_ITEM_PAIR)
1126 if (attr == NULL || strcmp(cf_itemtopair(ci)->attr, attr) == 0)
1130 return cf_itemtopair(ci);
1134 * Find a CONF_SECTION, or return the root if name is NULL
1137 CONF_SECTION *cf_section_find(const char *name)
1140 return cf_section_sub_find(config, name);
1146 * Find a sub-section in a section
1149 CONF_SECTION *cf_section_sub_find(CONF_SECTION *section, const char *name)
1153 for (ci = section->children; ci; ci = ci->next) {
1154 if (ci->type != CONF_ITEM_SECTION)
1156 if (strcmp(cf_itemtosection(ci)->name1, name) == 0)
1160 return cf_itemtosection(ci);
1165 * Return the next subsection after a CONF_SECTION
1166 * with a certain name1 (char *name1). If the requested
1167 * name1 is NULL, any name1 matches.
1170 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
1171 CONF_SECTION *subsection,
1177 * If subsection is NULL this must be a first time run
1178 * Find the subsection with correct name
1181 if (subsection == NULL){
1182 ci = section->children;
1184 ci = cf_sectiontoitem(subsection)->next;
1187 for (; ci; ci = ci->next) {
1188 if (ci->type != CONF_ITEM_SECTION)
1190 if ((name1 == NULL) ||
1191 (strcmp(cf_itemtosection(ci)->name1, name1) == 0))
1195 return cf_itemtosection(ci);
1199 * Return the next item after a CONF_ITEM.
1202 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item)
1205 * If item is NULL this must be a first time run
1206 * Return the first item
1210 return section->children;
1216 int cf_section_lineno(CONF_SECTION *section)
1218 return cf_sectiontoitem(section)->lineno;
1221 int cf_pair_lineno(CONF_PAIR *pair)
1223 return cf_pairtoitem(pair)->lineno;
1226 int cf_item_is_section(CONF_ITEM *item)
1228 return item->type == CONF_ITEM_SECTION;
1233 * JMG dump_config tries to dump the config structure in a readable format
1237 static int dump_config_section(CONF_SECTION *cs, int indent)
1243 /* The DEBUG macro doesn't let me
1244 * for(i=0;i<indent;++i) debugputchar('\t');
1245 * so I had to get creative. --Pac. */
1247 for (ci = cs->children; ci; ci = ci->next) {
1248 if (ci->type == CONF_ITEM_PAIR) {
1249 cp=cf_itemtopair(ci);
1250 DEBUG("%.*s%s = %s",
1251 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1252 cp->attr, cp->value);
1254 scs=cf_itemtosection(ci);
1255 DEBUG("%.*s%s %s%s{",
1256 indent, "\t\t\t\t\t\t\t\t\t\t\t",
1258 scs->name2 ? scs->name2 : "",
1259 scs->name2 ? " " : "");
1260 dump_config_section(scs, indent+1);
1262 indent, "\t\t\t\t\t\t\t\t\t\t\t");
1269 int dump_config(void)
1271 return dump_config_section(config, 0);