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