dnsmasq: Don't expose *.bind data incl version
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 120-dnsmasq-compile-time-option-NO_ID.patch
1 From f6bea86c78ba9efbd01da3dd2fb18764ec806290 Mon Sep 17 00:00:00 2001
2 From: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
3 Date: Wed, 7 Sep 2016 09:35:07 +0100
4 Subject: [PATCH] dnsmasq: compile time option NO_ID
5
6 Some consider it good practice to obscure software version numbers to
7 clients. Compiling with -DNO_ID removes the *.bind info structure.
8 This includes: version, author, copyright, cachesize, cache insertions,
9 evictions, misses & hits, auth & servers.
10
11 Signed-off-by: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
12 ---
13 src/cache.c | 2 ++
14 src/config.h | 5 +++++
15 src/dnsmasq.h | 4 ++++
16 src/option.c | 8 ++++++--
17 src/rfc1035.c | 3 ++-
18 5 files changed, 19 insertions(+), 3 deletions(-)
19
20 --- a/src/cache.c
21 +++ b/src/cache.c
22 @@ -1290,6 +1290,7 @@ void cache_add_dhcp_entry(char *host_nam
23 }
24 #endif
25
26 +#ifndef NO_ID
27 int cache_make_stat(struct txt_record *t)
28 {
29 static char *buff = NULL;
30 @@ -1385,6 +1386,7 @@ int cache_make_stat(struct txt_record *t
31 *buff = len;
32 return 1;
33 }
34 +#endif
35
36 /* There can be names in the cache containing control chars, don't
37 mess up logging or open security holes. */
38 --- a/src/config.h
39 +++ b/src/config.h
40 @@ -120,6 +120,8 @@ HAVE_LOOP
41 HAVE_INOTIFY
42 use the Linux inotify facility to efficiently re-read configuration files.
43
44 +NO_ID
45 + Don't report *.bind CHAOS info to clients.
46 NO_IPV6
47 NO_TFTP
48 NO_DHCP
49 @@ -434,6 +436,9 @@ static char *compile_opts =
50 "no-"
51 #endif
52 "DNSSEC "
53 +#ifdef NO_ID
54 +"no-ID "
55 +#endif
56 #ifndef HAVE_LOOP
57 "no-"
58 #endif
59 --- a/src/dnsmasq.h
60 +++ b/src/dnsmasq.h
61 @@ -286,6 +286,7 @@ struct naptr {
62 struct naptr *next;
63 };
64
65 +#ifndef NO_ID
66 #define TXT_STAT_CACHESIZE 1
67 #define TXT_STAT_INSERTS 2
68 #define TXT_STAT_EVICTIONS 3
69 @@ -293,6 +294,7 @@ struct naptr {
70 #define TXT_STAT_HITS 5
71 #define TXT_STAT_AUTH 6
72 #define TXT_STAT_SERVERS 7
73 +#endif
74
75 struct txt_record {
76 char *name;
77 @@ -1078,7 +1080,9 @@ void cache_add_dhcp_entry(char *host_nam
78 struct in_addr a_record_from_hosts(char *name, time_t now);
79 void cache_unhash_dhcp(void);
80 void dump_cache(time_t now);
81 +#ifndef NO_ID
82 int cache_make_stat(struct txt_record *t);
83 +#endif
84 char *cache_get_name(struct crec *crecp);
85 char *cache_get_cname_target(struct crec *crecp);
86 struct crec *cache_enumerate(int init);
87 --- a/src/option.c
88 +++ b/src/option.c
89 @@ -657,7 +657,8 @@ static int atoi_check8(char *a, int *res
90 return 1;
91 }
92 #endif
93 -
94 +
95 +#ifndef NO_ID
96 static void add_txt(char *name, char *txt, int stat)
97 {
98 struct txt_record *r = opt_malloc(sizeof(struct txt_record));
99 @@ -670,13 +671,14 @@ static void add_txt(char *name, char *tx
100 *(r->txt) = len;
101 memcpy((r->txt)+1, txt, len);
102 }
103 -
104 +
105 r->stat = stat;
106 r->name = opt_string_alloc(name);
107 r->next = daemon->txt;
108 daemon->txt = r;
109 r->class = C_CHAOS;
110 }
111 +#endif
112
113 static void do_usage(void)
114 {
115 @@ -4515,6 +4517,7 @@ void read_opts(int argc, char **argv, ch
116 daemon->soa_expiry = SOA_EXPIRY;
117 daemon->max_port = MAX_PORT;
118
119 +#ifndef NO_ID
120 add_txt("version.bind", "dnsmasq-" VERSION, 0 );
121 add_txt("authors.bind", "Simon Kelley", 0);
122 add_txt("copyright.bind", COPYRIGHT, 0);
123 @@ -4527,6 +4530,7 @@ void read_opts(int argc, char **argv, ch
124 add_txt("auth.bind", NULL, TXT_STAT_AUTH);
125 #endif
126 add_txt("servers.bind", NULL, TXT_STAT_SERVERS);
127 +#endif
128
129 while (1)
130 {
131 --- a/src/rfc1035.c
132 +++ b/src/rfc1035.c
133 @@ -1264,6 +1264,7 @@ size_t answer_request(struct dns_header
134 unsigned long ttl = daemon->local_ttl;
135 int ok = 1;
136 log_query(F_CONFIG | F_RRNAME, name, NULL, "<TXT>");
137 +#ifndef NO_ID
138 /* Dynamically generate stat record */
139 if (t->stat != 0)
140 {
141 @@ -1271,7 +1272,7 @@ size_t answer_request(struct dns_header
142 if (!cache_make_stat(t))
143 ok = 0;
144 }
145 -
146 +#endif
147 if (ok && add_resource_record(header, limit, &trunc, nameoffset, &ansp,
148 ttl, NULL,
149 T_TXT, t->class, "t", t->len, t->txt))