Stop resolver scripts from signalling "not found".
[libradsec.git] / catgconf.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include "debug.h"
6 #include "gconfig.h"
7
8 int listconfig(struct gconffile **cf, char *block, int compact) {
9     char *opt = NULL, *val = NULL;
10     int conftype;
11
12     for (;;) {
13         free(opt);
14         free(val);
15         if (!getconfigline(cf, block, &opt, &val, &conftype))
16             return -1;
17         if (!opt)
18             return 0;           /* Success.  */
19
20         if (conftype == CONF_STR && !strcasecmp(opt, "include")) {
21             if (!pushgconfpaths(cf, val))
22                 debugx(1, DBG_ERR, "failed to include config file %s", val);
23             continue;
24         }
25
26         switch (conftype) {
27         case CONF_STR:
28             if (block)
29                 printf(compact ? "%s=%s;" : "\t%s=%s\n", opt, val);
30             else
31                 printf("%s=%s\n", opt, val);
32             break;
33         case CONF_CBK:
34             printf("%s %s {%s", opt, val, compact ? "" : "\n");
35             if (listconfig(cf, val, compact))
36                 return -1;
37             printf("}\n");
38             break;
39         default:
40             printf("Unsupported config type\n");
41             return -1;
42         }
43     }
44
45     return 0;                   /* Success.  */
46 }
47
48 int main(int argc, char **argv) {
49     int c, compact = 0;
50     struct gconffile *cfs;
51
52     debug_init("radsecproxy-conf");
53     debug_set_level(DBG_WARN);
54
55     while ((c = getopt(argc, argv, "c")) != -1) {
56         switch (c) {
57         case 'c':
58             compact = 1;
59             break;
60         default:
61             goto usage;
62         }
63     }
64     if (argc - optind != 1)
65         goto usage;
66
67     cfs = openconfigfile(argv[optind]);
68     return listconfig(&cfs, NULL, compact);
69
70 usage:
71     debug(DBG_ERR, "Usage:\n%s [ -c ] configfile", argv[0]);
72     exit(1);
73 }
74
75 /* Local Variables: */
76 /* c-file-style: "stroustrup" */
77 /* End: */