xref: /openbsd/sbin/unwind/printconf.c (revision 76d0caae)
1 /*	$OpenBSD: printconf.c,v 1.16 2019/12/01 14:37:34 otto Exp $	*/
2 
3 /*
4  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
5  * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <sys/queue.h>
21 
22 #include <event.h>
23 #include <imsg.h>
24 #include <stdio.h>
25 #include <string.h>
26 
27 #include "unwind.h"
28 
29 void
30 print_config(struct uw_conf *conf)
31 {
32 	struct uw_forwarder	*uw_forwarder;
33 	int			 i;
34 	enum uw_resolver_type	 j;
35 
36 	if (conf->res_pref.len > 0) {
37 		printf("preference {");
38 		for (i = 0; i < conf->res_pref.len; i++) {
39 			printf(" %s",
40 			    uw_resolver_type_str[conf->res_pref.types[i]]);
41 		}
42 		printf(" }\n");
43 	}
44 
45 	if (!TAILQ_EMPTY(&conf->uw_forwarder_list) ||
46 	    !TAILQ_EMPTY(&conf->uw_dot_forwarder_list)) {
47 		printf("forwarder {\n");
48 		TAILQ_FOREACH(uw_forwarder, &conf->uw_forwarder_list, entry) {
49 			printf("\t");
50 			printf("%s", uw_forwarder->ip);
51 			if (uw_forwarder->port != 53)
52 				printf(" port %d", uw_forwarder->port);
53 			printf("\n");
54 		}
55 		TAILQ_FOREACH(uw_forwarder, &conf->uw_dot_forwarder_list,
56 		    entry) {
57 			printf("\t");
58 			printf("%s", uw_forwarder->ip);
59 			if (uw_forwarder->port != 853)
60 				printf(" port %d", uw_forwarder->port);
61 			if (uw_forwarder->auth_name[0] != '\0')
62 				printf(" authentication name %s",
63 				    uw_forwarder->auth_name);
64 			printf(" DoT\n");
65 		}
66 		printf("}\n");
67 	}
68 
69 	if (conf->blocklist_file != NULL)
70 		printf("block list \"%s\"%s\n", conf->blocklist_file,
71 		    conf->blocklist_log ? " log" : "");
72 	for (j = 0; j < UW_RES_NONE; j++) {
73 		struct force_tree_entry	*e;
74 		int			 empty = 1;
75 
76 		RB_FOREACH(e, force_tree, &conf->force) {
77 			if (e->type != j || e->acceptbogus)
78 				continue;
79 			empty = 0;
80 			break;
81 		}
82 		if (!empty) {
83 
84 			printf("force %s {", uw_resolver_type_str[j]);
85 			RB_FOREACH(e, force_tree, &conf->force) {
86 				if (e->type != j || e->acceptbogus)
87 					continue;
88 				printf("\n\t%s", e->domain);
89 			}
90 			printf("\n}\n");
91 		}
92 
93 		empty = 1;
94 		RB_FOREACH(e, force_tree, &conf->force) {
95 			if (e->type != j || !e->acceptbogus)
96 				continue;
97 			empty = 0;
98 			break;
99 		}
100 		if (!empty) {
101 
102 			printf("force accept bogus %s {",
103 			    uw_resolver_type_str[j]);
104 			RB_FOREACH(e, force_tree, &conf->force) {
105 				if (e->type != j || !e->acceptbogus)
106 					continue;
107 				printf("\n\t%s", e->domain);
108 			}
109 			printf("\n}\n");
110 		}
111 	}
112 }
113