| 1 | Downloaded from:
|
| 2 | http://lizzy.dyndns.org/~jos/djbdns-1.05-jumbo-josb.patch
|
| 3 |
|
| 4 | This patch combines the following patches:
|
| 5 | - Claudiu Costin's jumbo-p13.patch
|
| 6 | http://www.ro.kde.org/djbdns/mywork/jumbo/jumbo-p13.patch.gz
|
| 7 | - Guilherme Balena Versiani's djbdns SRV+NAPTR combined patch
|
| 8 | http://mywebpage.netscape.com/guibv/djbdns-1.05-srvnaptr.diff
|
| 9 |
|
| 10 | diff -ruN djbdns-1.05-dist/CHANGES djbdns-1.05/CHANGES
|
| 11 | |
| 12 | |
| 13 | @@ -374,3 +374,5 @@
|
| 14 | ui: servers print starting message.
|
| 15 | internal: some respond() declarations.
|
| 16 | version: djbdns 1.05.
|
| 17 | +20010313
|
| 18 | + patch: to dump and reload the cache
|
| 19 | diff -ruN djbdns-1.05-dist/Makefile djbdns-1.05/Makefile
|
| 20 | |
| 21 | |
| 22 | @@ -4,6 +4,8 @@
|
| 23 |
|
| 24 | default: it
|
| 25 |
|
| 26 | +include Makefile.sig
|
| 27 | +
|
| 28 | alloc.a: \
|
| 29 | makelib alloc.o alloc_re.o getln.o getln2.o stralloc_cat.o \
|
| 30 | stralloc_catb.o stralloc_cats.o stralloc_copy.o stralloc_eady.o \
|
| 31 | @@ -149,13 +151,13 @@
|
| 32 |
|
| 33 | cache.o: \
|
| 34 | compile cache.c alloc.h byte.h uint32.h exit.h tai.h uint64.h cache.h \
|
| 35 | -uint32.h uint64.h
|
| 36 | +uint32.h uint64.h env.h error.h open.h openreadclose.h
|
| 37 | ./compile cache.c
|
| 38 |
|
| 39 | cachetest: \
|
| 40 | -load cachetest.o cache.o libtai.a buffer.a alloc.a unix.a byte.a
|
| 41 | - ./load cachetest cache.o libtai.a buffer.a alloc.a unix.a \
|
| 42 | - byte.a
|
| 43 | +load cachetest.o cache.o libtai.a buffer.a alloc.a unix.a byte.a env.a
|
| 44 | + ./load cachetest cache.o libtai.a buffer.a unix.a env.a \
|
| 45 | + alloc.a byte.a dns.a
|
| 46 |
|
| 47 | cachetest.o: \
|
| 48 | compile cachetest.c buffer.h exit.h cache.h uint32.h uint64.h str.h
|
| 49 | @@ -228,11 +230,11 @@
|
| 50 | dns.a: \
|
| 51 | makelib dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o dns_ipq.o dns_mx.o \
|
| 52 | dns_name.o dns_nd.o dns_packet.o dns_random.o dns_rcip.o dns_rcrw.o \
|
| 53 | -dns_resolve.o dns_sortip.o dns_transmit.o dns_txt.o
|
| 54 | +dns_resolve.o dns_rotateip.o dns_sortip.o dns_transmit.o dns_txt.o
|
| 55 | ./makelib dns.a dns_dfd.o dns_domain.o dns_dtda.o dns_ip.o \
|
| 56 | dns_ipq.o dns_mx.o dns_name.o dns_nd.o dns_packet.o \
|
| 57 | dns_random.o dns_rcip.o dns_rcrw.o dns_resolve.o \
|
| 58 | - dns_sortip.o dns_transmit.o dns_txt.o
|
| 59 | + dns_rotateip.o dns_sortip.o dns_transmit.o dns_txt.o
|
| 60 |
|
| 61 | dns_dfd.o: \
|
| 62 | compile dns_dfd.c error.h alloc.h byte.h dns.h stralloc.h gen_alloc.h \
|
| 63 | @@ -301,6 +303,10 @@
|
| 64 | dns.h stralloc.h gen_alloc.h iopause.h taia.h
|
| 65 | ./compile dns_resolve.c
|
| 66 |
|
| 67 | +dns_rotateip.o: \
|
| 68 | +compile dns_rotateip.c byte.h dns.h stralloc.h gen_alloc.h
|
| 69 | + ./compile dns_rotateip.c
|
| 70 | +
|
| 71 | dns_sortip.o: \
|
| 72 | compile dns_sortip.c byte.h dns.h stralloc.h gen_alloc.h iopause.h \
|
| 73 | taia.h tai.h uint64.h taia.h
|
| 74 | @@ -320,10 +326,10 @@
|
| 75 | dnscache: \
|
| 76 | load dnscache.o droproot.o okclient.o log.o cache.o query.o \
|
| 77 | response.o dd.o roots.o iopause.o prot.o dns.a env.a alloc.a buffer.a \
|
| 78 | -libtai.a unix.a byte.a socket.lib
|
| 79 | +libtai.a unix.a byte.a sig.a socket.lib
|
| 80 | ./load dnscache droproot.o okclient.o log.o cache.o \
|
| 81 | query.o response.o dd.o roots.o iopause.o prot.o dns.a \
|
| 82 | - env.a alloc.a buffer.a libtai.a unix.a byte.a `cat \
|
| 83 | + env.a alloc.a buffer.a libtai.a unix.a byte.a sig.a `cat \
|
| 84 | socket.lib`
|
| 85 |
|
| 86 | dnscache-conf: \
|
| 87 | @@ -626,9 +632,9 @@
|
| 88 | ./compile parsetype.c
|
| 89 |
|
| 90 | pickdns: \
|
| 91 | -load pickdns.o server.o response.o droproot.o qlog.o prot.o dns.a \
|
| 92 | +load pickdns.o server.o iopause.o response.o droproot.o qlog.o prot.o dns.a \
|
| 93 | env.a libtai.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
|
| 94 | - ./load pickdns server.o response.o droproot.o qlog.o \
|
| 95 | + ./load pickdns server.o iopause.o response.o droproot.o qlog.o \
|
| 96 | prot.o dns.a env.a libtai.a cdb.a alloc.a buffer.a unix.a \
|
| 97 | byte.a `cat socket.lib`
|
| 98 |
|
| 99 | @@ -704,9 +710,9 @@
|
| 100 | ./compile random-ip.c
|
| 101 |
|
| 102 | rbldns: \
|
| 103 | -load rbldns.o server.o response.o dd.o droproot.o qlog.o prot.o dns.a \
|
| 104 | +load rbldns.o server.o iopause.o response.o dd.o droproot.o qlog.o prot.o dns.a \
|
| 105 | env.a libtai.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
|
| 106 | - ./load rbldns server.o response.o dd.o droproot.o qlog.o \
|
| 107 | + ./load rbldns server.o iopause.o response.o dd.o droproot.o qlog.o \
|
| 108 | prot.o dns.a env.a libtai.a cdb.a alloc.a buffer.a unix.a \
|
| 109 | byte.a `cat socket.lib`
|
| 110 |
|
| 111 | @@ -774,7 +780,7 @@
|
| 112 | compile server.c byte.h case.h env.h buffer.h strerr.h ip4.h uint16.h \
|
| 113 | ndelay.h socket.h uint16.h droproot.h qlog.h uint16.h response.h \
|
| 114 | uint32.h dns.h stralloc.h gen_alloc.h iopause.h taia.h tai.h uint64.h \
|
| 115 | -taia.h
|
| 116 | +taia.h iopause.h alloc.h
|
| 117 | ./compile server.c
|
| 118 |
|
| 119 | setup: \
|
| 120 | @@ -979,10 +985,10 @@
|
| 121 | ./compile timeoutwrite.c
|
| 122 |
|
| 123 | tinydns: \
|
| 124 | -load tinydns.o server.o droproot.o tdlookup.o response.o qlog.o \
|
| 125 | +load tinydns.o server.o iopause.o droproot.o tdlookup.o response.o qlog.o \
|
| 126 | prot.o dns.a libtai.a env.a cdb.a alloc.a buffer.a unix.a byte.a \
|
| 127 | socket.lib
|
| 128 | - ./load tinydns server.o droproot.o tdlookup.o response.o \
|
| 129 | + ./load tinydns server.o iopause.o droproot.o tdlookup.o response.o \
|
| 130 | qlog.o prot.o dns.a libtai.a env.a cdb.a alloc.a buffer.a \
|
| 131 | unix.a byte.a `cat socket.lib`
|
| 132 |
|
| 133 | @@ -1084,10 +1090,10 @@
|
| 134 | ./compile utime.c
|
| 135 |
|
| 136 | walldns: \
|
| 137 | -load walldns.o server.o response.o droproot.o qlog.o prot.o dd.o \
|
| 138 | +load walldns.o server.o iopause.o response.o droproot.o qlog.o prot.o dd.o \
|
| 139 | dns.a env.a cdb.a alloc.a buffer.a unix.a byte.a socket.lib
|
| 140 | - ./load walldns server.o response.o droproot.o qlog.o \
|
| 141 | - prot.o dd.o dns.a env.a cdb.a alloc.a buffer.a unix.a \
|
| 142 | + ./load walldns server.o iopause.o response.o droproot.o qlog.o \
|
| 143 | + prot.o dd.o dns.a libtai.a env.a cdb.a alloc.a buffer.a unix.a \
|
| 144 | byte.a `cat socket.lib`
|
| 145 |
|
| 146 | walldns-conf: \
|
| 147 | diff -ruN djbdns-1.05-dist/Makefile.sig djbdns-1.05/Makefile.sig
|
| 148 | |
| 149 | |
| 150 | @@ -0,0 +1,27 @@
|
| 151 | +sig.o: \
|
| 152 | +compile sig.c sig.h
|
| 153 | + ./compile sig.c
|
| 154 | +
|
| 155 | +sig_block.o: \
|
| 156 | +compile sig_block.c sig.h hassgprm.h
|
| 157 | + ./compile sig_block.c
|
| 158 | +
|
| 159 | +sig_catch.o: \
|
| 160 | +compile sig_catch.c sig.h hassgact.h
|
| 161 | + ./compile sig_catch.c
|
| 162 | +
|
| 163 | +sig_pause.o: \
|
| 164 | +compile sig_pause.c sig.h hassgprm.h
|
| 165 | + ./compile sig_pause.c
|
| 166 | +
|
| 167 | +sig.a: \
|
| 168 | +makelib sig.o sig_block.o sig_catch.o sig_pause.o
|
| 169 | + ./makelib sig.a sig.o sig_block.o sig_catch.o sig_pause.o
|
| 170 | +
|
| 171 | +hassgact.h: \
|
| 172 | +choose compile load trysgact.c hassgact.h1 hassgact.h2
|
| 173 | + ./choose cl trysgact hassgact.h1 hassgact.h2 > hassgact.h
|
| 174 | +
|
| 175 | +hassgprm.h: \
|
| 176 | +choose compile load trysgprm.c hassgprm.h1 hassgprm.h2
|
| 177 | + ./choose cl trysgprm hassgprm.h1 hassgprm.h2 > hassgprm.h
|
| 178 | diff -ruN djbdns-1.05-dist/README djbdns-1.05/README
|
| 179 | |
| 180 | |
| 181 | @@ -1,3 +1,9 @@
|
| 182 | +patchlevel fg1
|
| 183 | +20010313
|
| 184 | +by Florent Guillaume <[email protected]>
|
| 185 | +patch home page: http://mapage.noos.fr/efgeor/djbdns/index.html
|
| 186 | +Uses parts of Felix von Leitner's djb-0.5.2 package: http://www.fefe.de/djb/
|
| 187 | +
|
| 188 | djbdns 1.05
|
| 189 | 20010211
|
| 190 | Copyright 2001
|
| 191 | diff -ruN djbdns-1.05-dist/SYSDEPS djbdns-1.05/SYSDEPS
|
| 192 | |
| 193 | |
| 194 | @@ -7,4 +7,6 @@
|
| 195 | direntry.h
|
| 196 | hasshsgr.h
|
| 197 | hasdevtcp.h
|
| 198 | +hassgact.h
|
| 199 | +hassgprm.h
|
| 200 | socket.lib
|
| 201 | diff -ruN djbdns-1.05-dist/TARGETS djbdns-1.05/TARGETS
|
| 202 | |
| 203 | |
| 204 | @@ -214,3 +214,10 @@
|
| 205 | it
|
| 206 | setup
|
| 207 | check
|
| 208 | +sig.o
|
| 209 | +sig.a
|
| 210 | +sig_catch.o
|
| 211 | +sig_block.o
|
| 212 | +hassgact.h
|
| 213 | +hassgprm.h
|
| 214 | +sig_pause.o
|
| 215 | diff -ruN djbdns-1.05-dist/VERSION djbdns-1.05/VERSION
|
| 216 | |
| 217 | |
| 218 | @@ -1 +1 @@
|
| 219 | -djbdns 1.05
|
| 220 | +djbdns 1.05-fg1
|
| 221 | diff -ruN djbdns-1.05-dist/auto_home.c djbdns-1.05/auto_home.c
|
| 222 | |
| 223 | |
| 224 | @@ -0,0 +1,3 @@
|
| 225 | +const char auto_home[] = "\
|
| 226 | +\057\165\163\162\057\154\157\143\141\154\
|
| 227 | +";
|
| 228 | diff -ruN djbdns-1.05-dist/axfr-get.c djbdns-1.05/axfr-get.c
|
| 229 | |
| 230 | |
| 231 | @@ -209,6 +209,57 @@
|
| 232 | if (!stralloc_cats(&line,".:")) return 0;
|
| 233 | if (!stralloc_catulong0(&line,dist,0)) return 0;
|
| 234 | }
|
| 235 | + else if (byte_equal(data,2,DNS_T_SRV)) {
|
| 236 | + uint16 priority, weight, port;
|
| 237 | + if (!stralloc_copys(&line,"S")) return 0;
|
| 238 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 239 | + if (!stralloc_cats(&line,"::")) return 0;
|
| 240 | + pos = x_copy(buf,len,pos,data,2);
|
| 241 | + uint16_unpack_big(data,&priority);
|
| 242 | + pos = x_copy(buf,len,pos,data,2);
|
| 243 | + uint16_unpack_big(data,&weight);
|
| 244 | + pos = x_copy(buf,len,pos,data,2);
|
| 245 | + uint16_unpack_big(data,&port);
|
| 246 | + x_getname(buf,len,pos,&d1);
|
| 247 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 248 | + if (!stralloc_cats(&line,".:")) return 0;
|
| 249 | + if (!stralloc_catulong0(&line,port,0)) return 0;
|
| 250 | + if (!stralloc_cats(&line,":")) return 0;
|
| 251 | + if (!stralloc_catulong0(&line,priority,0)) return 0;
|
| 252 | + if (!stralloc_cats(&line,":")) return 0;
|
| 253 | + if (!stralloc_catulong0(&line,weight,0)) return 0;
|
| 254 | + }
|
| 255 | + else if (byte_equal(data,2,DNS_T_NAPTR)) {
|
| 256 | + uint16 order, preference;
|
| 257 | + char flags[255], service[255], regexp[255];
|
| 258 | + char fs, ss, rs;
|
| 259 | + if (!stralloc_copys(&line,"N")) return 0;
|
| 260 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 261 | + if (!stralloc_cats(&line,":")) return 0;
|
| 262 | + pos = x_copy(buf,len,pos,data,2);
|
| 263 | + uint16_unpack_big(data,&order);
|
| 264 | + pos = x_copy(buf,len,pos,data,2);
|
| 265 | + uint16_unpack_big(data,&preference);
|
| 266 | + pos = x_copy(buf,len,pos,&fs,1);
|
| 267 | + pos = x_copy(buf,len,pos,flags,fs);
|
| 268 | + pos = x_copy(buf,len,pos,&ss,1);
|
| 269 | + pos = x_copy(buf,len,pos,service,ss);
|
| 270 | + pos = x_copy(buf,len,pos,&rs,1);
|
| 271 | + pos = x_copy(buf,len,pos,regexp,rs);
|
| 272 | + x_getname(buf,len,pos,&d1);
|
| 273 | + if (!stralloc_catulong0(&line,order,0)) return 0;
|
| 274 | + if (!stralloc_cats(&line,":")) return 0;
|
| 275 | + if (!stralloc_catulong0(&line,preference,0)) return 0;
|
| 276 | + if (!stralloc_cats(&line,":")) return 0;
|
| 277 | + if (!stralloc_catb(&line,flags,fs)) return 0;
|
| 278 | + if (!stralloc_cats(&line,":")) return 0;
|
| 279 | + if (!stralloc_catb(&line,service,ss)) return 0;
|
| 280 | + if (!stralloc_cats(&line,":")) return 0;
|
| 281 | + if (!stralloc_catb(&line,regexp,rs)) return 0;
|
| 282 | + if (!stralloc_cats(&line,":")) return 0;
|
| 283 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 284 | + if (!stralloc_cats(&line,".")) return 0;
|
| 285 | + }
|
| 286 | else if (byte_equal(data,2,DNS_T_A) && (dlen == 4)) {
|
| 287 | char ipstr[IP4_FMT];
|
| 288 | if (!stralloc_copys(&line,"+")) return 0;
|
| 289 | @@ -217,6 +268,14 @@
|
| 290 | x_copy(buf,len,pos,data,4);
|
| 291 | if (!stralloc_catb(&line,ipstr,ip4_fmt(ipstr,data))) return 0;
|
| 292 | }
|
| 293 | + else if (byte_equal(data,2,DNS_T_PTR)) {
|
| 294 | + if (!stralloc_copys(&line,"^")) return 0;
|
| 295 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 296 | + if (!stralloc_cats(&line,":")) return 0;
|
| 297 | + x_getname(buf,len,pos,&d1);
|
| 298 | + if (!dns_domain_todot_cat(&line,d1)) return 0;
|
| 299 | + if (!stralloc_cats(&line,".")) return 0;
|
| 300 | + }
|
| 301 | else {
|
| 302 | unsigned char ch;
|
| 303 | unsigned char ch2;
|
| 304 | diff -ruN djbdns-1.05-dist/cache.c djbdns-1.05/cache.c
|
| 305 | |
| 306 | |
| 307 | @@ -1,12 +1,23 @@
|
| 308 | +#ifdef DUMPCACHE
|
| 309 | +#include <stdio.h>
|
| 310 | +#include <unistd.h>
|
| 311 | +#include "error.h"
|
| 312 | +#include "open.h"
|
| 313 | +#include "openreadclose.h"
|
| 314 | +#endif
|
| 315 | +#include "env.h"
|
| 316 | #include "alloc.h"
|
| 317 | #include "byte.h"
|
| 318 | #include "uint32.h"
|
| 319 | #include "exit.h"
|
| 320 | #include "tai.h"
|
| 321 | #include "cache.h"
|
| 322 | +#include "dns.h"
|
| 323 | +#include "buffer.h"
|
| 324 |
|
| 325 | uint64 cache_motion = 0;
|
| 326 |
|
| 327 | +static char *rrobin;
|
| 328 | static char *x = 0;
|
| 329 | static uint32 size;
|
| 330 | static uint32 hsize;
|
| 331 | @@ -87,6 +98,12 @@
|
| 332 | uint32 u;
|
| 333 | unsigned int loop;
|
| 334 | double d;
|
| 335 | + static int trigger=0;
|
| 336 | +
|
| 337 | + if (!trigger) {
|
| 338 | + rrobin = env_get("ROUNDROBIN");
|
| 339 | + trigger++;
|
| 340 | + }
|
| 341 |
|
| 342 | if (!x) return 0;
|
| 343 | if (keylen > MAXKEYLEN) return 0;
|
| 344 | @@ -111,7 +128,11 @@
|
| 345 | u = get4(pos + 8);
|
| 346 | if (u > size - pos - 20 - keylen) cache_impossible();
|
| 347 | *datalen = u;
|
| 348 | -
|
| 349 | + if (byte_equal(key,2,DNS_T_A)) {
|
| 350 | + if (rrobin) {
|
| 351 | + dns_rotateip(x + pos + 20 + keylen,u);
|
| 352 | + }
|
| 353 | + }
|
| 354 | return x + pos + 20 + keylen;
|
| 355 | }
|
| 356 | }
|
| 357 | @@ -205,3 +226,97 @@
|
| 358 |
|
| 359 | return 1;
|
| 360 | }
|
| 361 | +
|
| 362 | +#ifdef DUMPCACHE
|
| 363 | +static int fd;
|
| 364 | +
|
| 365 | +static int cache_writeline(const char *buf, unsigned int len)
|
| 366 | +{
|
| 367 | + int w;
|
| 368 | +
|
| 369 | + while (len) {
|
| 370 | + w = write(fd,buf,len);
|
| 371 | + if (w == -1) {
|
| 372 | + if (errno == error_intr) continue;
|
| 373 | + close(fd);
|
| 374 | + return -1;
|
| 375 | + }
|
| 376 | + buf += w;
|
| 377 | + len -= w;
|
| 378 | + }
|
| 379 | + return 0;
|
| 380 | +}
|
| 381 | +
|
| 382 | +int cache_dump(void)
|
| 383 | +{
|
| 384 | + static char *fn;
|
| 385 | + static char *fntmp;
|
| 386 | + uint32 pos;
|
| 387 | + unsigned int len;
|
| 388 | +
|
| 389 | + fn = env_get("DUMPCACHE");
|
| 390 | + if (!fn) return 999;
|
| 391 | + fntmp = env_get("DUMPCACHETMP");
|
| 392 | + if (!fntmp) return 999;
|
| 393 | + fd = open_trunc(fntmp);
|
| 394 | + if (fd == -1) return -1;
|
| 395 | +
|
| 396 | + pos = oldest;
|
| 397 | + while (pos < unused) {
|
| 398 | + len = get4(pos + 4) + get4(pos + 8) + 16;
|
| 399 | + if (cache_writeline(x + pos + 4, len)) return -1;
|
| 400 | + pos += 4 + len;
|
| 401 | + }
|
| 402 | + pos = hsize;
|
| 403 | + while (pos < writer) {
|
| 404 | + len = get4(pos + 4) + get4(pos + 8) + 16;
|
| 405 | + if (cache_writeline(x + pos + 4, len)) return -1;
|
| 406 | + pos += 4 + len;
|
| 407 | + }
|
| 408 | +
|
| 409 | + if (fsync(fd) == -1) return -1;
|
| 410 | + if (close(fd) == -1) return -1;
|
| 411 | + if (rename(fntmp,fn) == -1) return -1;
|
| 412 | + return 0;
|
| 413 | +}
|
| 414 | +
|
| 415 | +int cache_slurp(const char *fn)
|
| 416 | +{
|
| 417 | + static stralloc buf = {0};
|
| 418 | + char *p;
|
| 419 | + uint32 pos;
|
| 420 | + unsigned int len;
|
| 421 | + uint32 keylen;
|
| 422 | + uint32 datalen;
|
| 423 | + struct tai now;
|
| 424 | + struct tai expire;
|
| 425 | + int nb;
|
| 426 | +
|
| 427 | + if (openreadclose(fn,&buf,16384) != 1) goto DIE;
|
| 428 | + tai_now(&now);
|
| 429 | + p = buf.s;
|
| 430 | + pos = 0;
|
| 431 | + len = buf.len;
|
| 432 | + nb = 0;
|
| 433 | + while (pos + 16 <= len) {
|
| 434 | + uint32_unpack(p + pos, &keylen);
|
| 435 | + uint32_unpack(p + pos + 4, &datalen);
|
| 436 | + tai_unpack(p + pos + 8, &expire);
|
| 437 | + pos += 16;
|
| 438 | + if (pos + keylen + datalen > len) break; /* missing data */
|
| 439 | + if (!tai_less(&expire,&now)) {
|
| 440 | + tai_sub(&expire,&expire,&now);
|
| 441 | + cache_set(p + pos, keylen, p + pos + keylen, datalen, (unsigned int)expire.x);
|
| 442 | + }
|
| 443 | + pos += keylen + datalen;
|
| 444 | + nb++;
|
| 445 | + }
|
| 446 | + alloc_free(buf.s); buf.s = 0;
|
| 447 | + return nb;
|
| 448 | +
|
| 449 | + DIE:
|
| 450 | + alloc_free(buf.s); buf.s = 0;
|
| 451 | + if (errno == error_noent) return 0;
|
| 452 | + return -1;
|
| 453 | +}
|
| 454 | +#endif
|
| 455 | diff -ruN djbdns-1.05-dist/cache.h djbdns-1.05/cache.h
|
| 456 | |
| 457 | |
| 458 | @@ -8,5 +8,9 @@
|
| 459 | extern int cache_init(unsigned int);
|
| 460 | extern void cache_set(const char *,unsigned int,const char *,unsigned int,uint32);
|
| 461 | extern char *cache_get(const char *,unsigned int,unsigned int *,uint32 *);
|
| 462 | +#ifdef DUMPCACHE
|
| 463 | +extern int cache_dump(void);
|
| 464 | +extern int cache_slurp(const char *);
|
| 465 | +#endif
|
| 466 |
|
| 467 | #endif
|
| 468 | diff -ruN djbdns-1.05-dist/chkshsgr.c djbdns-1.05/chkshsgr.c
|
| 469 | |
| 470 | |
| 471 | @@ -1,4 +1,6 @@
|
| 472 | #include "exit.h"
|
| 473 | +#include <grp.h>
|
| 474 | +#include <unistd.h>
|
| 475 |
|
| 476 | int main()
|
| 477 | {
|
| 478 | diff -ruN djbdns-1.05-dist/direntry.h djbdns-1.05/direntry.h
|
| 479 | |
| 480 | |
| 481 | @@ -0,0 +1,10 @@
|
| 482 | +#ifndef DIRENTRY_H
|
| 483 | +#define DIRENTRY_H
|
| 484 | +
|
| 485 | +/* sysdep: +dirent */
|
| 486 | +
|
| 487 | +#include <sys/types.h>
|
| 488 | +#include <dirent.h>
|
| 489 | +#define direntry struct dirent
|
| 490 | +
|
| 491 | +#endif
|
| 492 | diff -ruN djbdns-1.05-dist/dns.h djbdns-1.05/dns.h
|
| 493 | |
| 494 | |
| 495 | @@ -20,6 +20,8 @@
|
| 496 | #define DNS_T_SIG "\0\30"
|
| 497 | #define DNS_T_KEY "\0\31"
|
| 498 | #define DNS_T_AAAA "\0\34"
|
| 499 | +#define DNS_T_SRV "\0\41"
|
| 500 | +#define DNS_T_NAPTR "\0\43"
|
| 501 | #define DNS_T_AXFR "\0\374"
|
| 502 | #define DNS_T_ANY "\0\377"
|
| 503 |
|
| 504 | @@ -43,6 +45,7 @@
|
| 505 | extern unsigned int dns_random(unsigned int);
|
| 506 |
|
| 507 | extern void dns_sortip(char *,unsigned int);
|
| 508 | +extern void dns_rotateip(char *,unsigned int);
|
| 509 |
|
| 510 | extern void dns_domain_free(char **);
|
| 511 | extern int dns_domain_copy(char **,const char *);
|
| 512 | diff -ruN djbdns-1.05-dist/dns_rotateip.c djbdns-1.05/dns_rotateip.c
|
| 513 | |
| 514 | |
| 515 | @@ -0,0 +1,15 @@
|
| 516 | +#include "byte.h"
|
| 517 | +
|
| 518 | +void dns_rotateip(char *s, unsigned int n)
|
| 519 | +{
|
| 520 | + unsigned int i;
|
| 521 | + char tmp[4];
|
| 522 | +
|
| 523 | + i = n >> 2;
|
| 524 | + while (i > 1) {
|
| 525 | + --i;
|
| 526 | + byte_copy(tmp,4,s + (i << 2));
|
| 527 | + byte_copy(s + (i << 2),4,s);
|
| 528 | + byte_copy(s,4,tmp);
|
| 529 | + }
|
| 530 | +}
|
| 531 | diff -ruN djbdns-1.05-dist/dnscache-conf.c djbdns-1.05/dnscache-conf.c
|
| 532 | |
| 533 | |
| 534 | @@ -32,6 +32,10 @@
|
| 535 | char *user;
|
| 536 | char *loguser;
|
| 537 | struct passwd *pw;
|
| 538 | +#ifdef DUMPCACHE
|
| 539 | +int useruid;
|
| 540 | +int usergid;
|
| 541 | +#endif
|
| 542 | const char *myip;
|
| 543 |
|
| 544 | uint32 seed[32];
|
| 545 | @@ -81,6 +85,14 @@
|
| 546 | myip = argv[4];
|
| 547 | if (!myip) myip = "127.0.0.1";
|
| 548 |
|
| 549 | +#ifdef DUMPCACHE
|
| 550 | + pw = getpwnam(user);
|
| 551 | + seed_addtime();
|
| 552 | + if (!pw)
|
| 553 | + strerr_die3x(111,FATAL,"unknown account ",user);
|
| 554 | + useruid = pw->pw_uid;
|
| 555 | + usergid = pw->pw_gid;
|
| 556 | +#endif
|
| 557 | pw = getpwnam(loguser);
|
| 558 | seed_addtime();
|
| 559 | if (!pw)
|
| 560 | @@ -120,6 +132,14 @@
|
| 561 | seed_addtime(); perm(0644);
|
| 562 | seed_addtime(); start("env/DATALIMIT"); outs("3000000\n"); finish();
|
| 563 | seed_addtime(); perm(0644);
|
| 564 | +#ifdef DUMPCACHE
|
| 565 | + seed_addtime(); start("env/SLURPCACHE"); outs("dump/slurpcache\n"); finish();
|
| 566 | + seed_addtime(); perm(0644);
|
| 567 | + seed_addtime(); start("env/DUMPCACHE"); outs("dump/dumpcache\n"); finish();
|
| 568 | + seed_addtime(); perm(0644);
|
| 569 | + seed_addtime(); start("env/DUMPCACHETMP"); outs("dump/dumpcache.tmp\n"); finish();
|
| 570 | + seed_addtime(); perm(0644);
|
| 571 | +#endif
|
| 572 | seed_addtime(); start("run");
|
| 573 | outs("#!/bin/sh\nexec 2>&1\nexec <seed\nexec envdir ./env sh -c '\n exec envuidgid "); outs(user);
|
| 574 | outs(" softlimit -o250 -d \"$DATALIMIT\" ");
|
| 575 | @@ -131,6 +151,11 @@
|
| 576 | seed_addtime(); perm(0755);
|
| 577 | seed_addtime(); makedir("root");
|
| 578 | seed_addtime(); perm(02755);
|
| 579 | +#ifdef DUMPCACHE
|
| 580 | + seed_addtime(); makedir("root/dump");
|
| 581 | + seed_addtime(); owner(useruid,usergid);
|
| 582 | + seed_addtime(); perm(02755);
|
| 583 | +#endif
|
| 584 | seed_addtime(); makedir("root/ip");
|
| 585 | seed_addtime(); perm(02755);
|
| 586 | seed_addtime(); start("root/ip/127.0.0.1"); finish();
|
| 587 | diff -ruN djbdns-1.05-dist/dnscache.c djbdns-1.05/dnscache.c
|
| 588 | |
| 589 | |
| 590 | @@ -5,6 +5,7 @@
|
| 591 | #include "strerr.h"
|
| 592 | #include "error.h"
|
| 593 | #include "ip4.h"
|
| 594 | +#include "str.h"
|
| 595 | #include "uint16.h"
|
| 596 | #include "uint64.h"
|
| 597 | #include "socket.h"
|
| 598 | @@ -22,6 +23,7 @@
|
| 599 | #include "log.h"
|
| 600 | #include "okclient.h"
|
| 601 | #include "droproot.h"
|
| 602 | +#include "sig.h"
|
| 603 |
|
| 604 | static int packetquery(char *buf,unsigned int len,char **q,char qtype[2],char qclass[2],char id[2])
|
| 605 | {
|
| 606 | @@ -47,12 +49,20 @@
|
| 607 |
|
| 608 |
|
| 609 | static char myipoutgoing[4];
|
| 610 | -static char myipincoming[4];
|
| 611 | static char buf[1024];
|
| 612 | uint64 numqueries = 0;
|
| 613 |
|
| 614 | +struct interf {
|
| 615 | + char ip[4];
|
| 616 | + int udp53;
|
| 617 | + int tcp53;
|
| 618 | + iopause_fd *udp53io;
|
| 619 | + iopause_fd *tcp53io;
|
| 620 | +
|
| 621 | + struct interf *next;
|
| 622 | +} ;
|
| 623 |
|
| 624 | -static int udp53;
|
| 625 | +struct interf *interhead = 0;
|
| 626 |
|
| 627 | #define MAXUDP 200
|
| 628 | static struct udpclient {
|
| 629 | @@ -60,6 +70,7 @@
|
| 630 | struct taia start;
|
| 631 | uint64 active; /* query number, if active; otherwise 0 */
|
| 632 | iopause_fd *io;
|
| 633 | + int fd;
|
| 634 | char ip[4];
|
| 635 | uint16 port;
|
| 636 | char id[2];
|
| 637 | @@ -78,12 +89,12 @@
|
| 638 | if (!u[j].active) return;
|
| 639 | response_id(u[j].id);
|
| 640 | if (response_len > 512) response_tc();
|
| 641 | - socket_send4(udp53,response,response_len,u[j].ip,u[j].port);
|
| 642 | + socket_send4(u[j].fd,response,response_len,u[j].ip,u[j].port);
|
| 643 | log_querydone(&u[j].active,response_len);
|
| 644 | u[j].active = 0; --uactive;
|
| 645 | }
|
| 646 |
|
| 647 | -void u_new(void)
|
| 648 | +void u_new(int fd)
|
| 649 | {
|
| 650 | int j;
|
| 651 | int i;
|
| 652 | @@ -108,8 +119,9 @@
|
| 653 |
|
| 654 | x = u + j;
|
| 655 | taia_now(&x->start);
|
| 656 | + x->fd = fd;
|
| 657 |
|
| 658 | - len = socket_recv4(udp53,buf,sizeof buf,x->ip,&x->port);
|
| 659 | + len = socket_recv4(x->fd,buf,sizeof buf,x->ip,&x->port);
|
| 660 | if (len == -1) return;
|
| 661 | if (len >= sizeof buf) return;
|
| 662 | if (x->port < 1024) if (x->port != 53) return;
|
| 663 | @@ -129,8 +141,6 @@
|
| 664 | }
|
| 665 |
|
| 666 |
|
| 667 | -static int tcp53;
|
| 668 | -
|
| 669 | #define MAXTCP 20
|
| 670 | struct tcpclient {
|
| 671 | struct query q;
|
| 672 | @@ -138,6 +148,7 @@
|
| 673 | struct taia timeout;
|
| 674 | uint64 active; /* query number or 1, if active; otherwise 0 */
|
| 675 | iopause_fd *io;
|
| 676 | + int fd;
|
| 677 | char ip[4]; /* send response to this address */
|
| 678 | uint16 port; /* send response to this port */
|
| 679 | char id[2];
|
| 680 | @@ -266,7 +277,7 @@
|
| 681 | x->state = 0;
|
| 682 | }
|
| 683 |
|
| 684 | -void t_new(void)
|
| 685 | +void t_new(int fd)
|
| 686 | {
|
| 687 | int i;
|
| 688 | int j;
|
| 689 | @@ -290,8 +301,9 @@
|
| 690 |
|
| 691 | x = t + j;
|
| 692 | taia_now(&x->start);
|
| 693 | + x->fd = fd;
|
| 694 |
|
| 695 | - x->tcp = socket_accept4(tcp53,x->ip,&x->port);
|
| 696 | + x->tcp = socket_accept4(x->fd,x->ip,&x->port);
|
| 697 | if (x->tcp == -1) return;
|
| 698 | if (x->port < 1024) if (x->port != 53) { close(x->tcp); return; }
|
| 699 | if (!okclient(x->ip)) { close(x->tcp); return; }
|
| 700 | @@ -304,19 +316,44 @@
|
| 701 | log_tcpopen(x->ip,x->port);
|
| 702 | }
|
| 703 |
|
| 704 | +#ifdef DUMPCACHE
|
| 705 | +static void do_dump(void)
|
| 706 | +{
|
| 707 | + int r;
|
| 708 | + r = cache_dump();
|
| 709 | + if (r < 0)
|
| 710 | + r = errno;
|
| 711 | + log_dump(r);
|
| 712 | +}
|
| 713 | +#endif
|
| 714 | +
|
| 715 | +#define FATAL "dnscache: fatal: "
|
| 716 | +
|
| 717 | +iopause_fd *io = 0;
|
| 718 | +int numio;
|
| 719 | +
|
| 720 | +void hup_me()
|
| 721 | +{
|
| 722 | + if (!roots_init())
|
| 723 | + strerr_die2sys(111,FATAL,"unable to read servers: ");
|
| 724 | +
|
| 725 | + log_reread();
|
| 726 | +}
|
| 727 |
|
| 728 | -iopause_fd io[3 + MAXUDP + MAXTCP];
|
| 729 | -iopause_fd *udp53io;
|
| 730 | -iopause_fd *tcp53io;
|
| 731 |
|
| 732 | static void doit(void)
|
| 733 | {
|
| 734 | int j;
|
| 735 | struct taia deadline;
|
| 736 | struct taia stamp;
|
| 737 | + struct interf *inter;
|
| 738 | int iolen;
|
| 739 | int r;
|
| 740 |
|
| 741 | + io = (iopause_fd *) alloc((numio + 1 + MAXUDP + MAXTCP) * sizeof(iopause_fd));
|
| 742 | + if (!io)
|
| 743 | + strerr_die2sys(111,FATAL,"unable to alloc io: ");
|
| 744 | +
|
| 745 | for (;;) {
|
| 746 | taia_now(&stamp);
|
| 747 | taia_uint(&deadline,120);
|
| 748 | @@ -324,13 +361,15 @@
|
| 749 |
|
| 750 | iolen = 0;
|
| 751 |
|
| 752 | - udp53io = io + iolen++;
|
| 753 | - udp53io->fd = udp53;
|
| 754 | - udp53io->events = IOPAUSE_READ;
|
| 755 | -
|
| 756 | - tcp53io = io + iolen++;
|
| 757 | - tcp53io->fd = tcp53;
|
| 758 | - tcp53io->events = IOPAUSE_READ;
|
| 759 | + for (inter = interhead; inter != 0; inter = inter->next) {
|
| 760 | + inter->udp53io = io + iolen++;
|
| 761 | + inter->udp53io->fd = inter->udp53;
|
| 762 | + inter->udp53io->events = IOPAUSE_READ;
|
| 763 | +
|
| 764 | + inter->tcp53io = io + iolen++;
|
| 765 | + inter->tcp53io->fd = inter->tcp53;
|
| 766 | + inter->tcp53io->events = IOPAUSE_READ;
|
| 767 | + }
|
| 768 |
|
| 769 | for (j = 0;j < MAXUDP;++j)
|
| 770 | if (u[j].active) {
|
| 771 | @@ -372,46 +411,83 @@
|
| 772 | t_rw(j);
|
| 773 | }
|
| 774 |
|
| 775 | - if (udp53io)
|
| 776 | - if (udp53io->revents)
|
| 777 | - u_new();
|
| 778 | -
|
| 779 | - if (tcp53io)
|
| 780 | - if (tcp53io->revents)
|
| 781 | - t_new();
|
| 782 | + for (inter = interhead; inter != 0; inter = inter->next) {
|
| 783 | + if (inter->udp53io)
|
| 784 | + if (inter->udp53io->revents)
|
| 785 | + u_new(inter->udp53);
|
| 786 | +
|
| 787 | + if (inter->tcp53io)
|
| 788 | + if (inter->tcp53io->revents)
|
| 789 | + t_new(inter->tcp53);
|
| 790 | + }
|
| 791 | }
|
| 792 | }
|
| 793 |
|
| 794 | -#define FATAL "dnscache: fatal: "
|
| 795 | -
|
| 796 | char seed[128];
|
| 797 |
|
| 798 | int main()
|
| 799 | {
|
| 800 | char *x;
|
| 801 | + char nxdip[4];
|
| 802 | + int len;
|
| 803 | + int pos;
|
| 804 | + int oldpos;
|
| 805 | + char iptmp[4];
|
| 806 | + char iperr[IP4_FMT];
|
| 807 | + struct interf *inter;
|
| 808 | + struct interf *itmp;
|
| 809 | unsigned long cachesize;
|
| 810 |
|
| 811 | x = env_get("IP");
|
| 812 | if (!x)
|
| 813 | strerr_die2x(111,FATAL,"$IP not set");
|
| 814 | - if (!ip4_scan(x,myipincoming))
|
| 815 | - strerr_die3x(111,FATAL,"unable to parse IP address ",x);
|
| 816 |
|
| 817 | - udp53 = socket_udp();
|
| 818 | - if (udp53 == -1)
|
| 819 | - strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
|
| 820 | - if (socket_bind4_reuse(udp53,myipincoming,53) == -1)
|
| 821 | - strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
|
| 822 | -
|
| 823 | - tcp53 = socket_tcp();
|
| 824 | - if (tcp53 == -1)
|
| 825 | - strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
|
| 826 | - if (socket_bind4_reuse(tcp53,myipincoming,53) == -1)
|
| 827 | - strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
|
| 828 | + len = str_len(x);
|
| 829 | + numio = pos = oldpos = 0;
|
| 830 | +
|
| 831 | + while (pos < len) {
|
| 832 | + if (pos) oldpos = pos + 1;
|
| 833 | + pos = oldpos + str_chr(x + oldpos,'/');
|
| 834 | + x[pos] = 0;
|
| 835 | + if (!str_len(x + oldpos)) continue;
|
| 836 | +
|
| 837 | + if (!ip4_scan(x + oldpos,iptmp))
|
| 838 | + strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos);
|
| 839 | +
|
| 840 | + inter = (struct interf *) alloc(sizeof(struct interf));
|
| 841 | +
|
| 842 | + if (interhead == 0) interhead = inter;
|
| 843 | + else if (interhead->next == 0) interhead->next = inter;
|
| 844 | + else {
|
| 845 | + for (itmp = interhead; itmp->next != 0; itmp = itmp->next);
|
| 846 | + itmp->next = inter;
|
| 847 | + }
|
| 848 | +
|
| 849 | + inter->next = 0;
|
| 850 | +
|
| 851 | + inter->udp53 = socket_udp();
|
| 852 | + if (inter->udp53 == -1)
|
| 853 | + strerr_die4sys(111,FATAL,"unable to create UDP socket for IP address ",x + oldpos,": ");
|
| 854 | + if (socket_bind4_reuse(inter->udp53,iptmp,53) == -1)
|
| 855 | + strerr_die4sys(111,FATAL,"unable to bind UDP socket for IP address ",x + oldpos,": ");
|
| 856 | +
|
| 857 | + inter->tcp53 = socket_tcp();
|
| 858 | + if (inter->tcp53 == -1)
|
| 859 | + strerr_die4sys(111,FATAL,"unable to create TCP socket for IP address ",x + oldpos,": ");
|
| 860 | + if (socket_bind4_reuse(inter->tcp53,iptmp,53) == -1)
|
| 861 | + strerr_die4sys(111,FATAL,"unable to bind TCP socket for IP address ",x + oldpos,": ");
|
| 862 | +
|
| 863 | + numio++;
|
| 864 | + log_listen(iptmp);
|
| 865 | + }
|
| 866 | +
|
| 867 | + if (interhead == 0)
|
| 868 | + strerr_die2x(111,FATAL,"no interfaces to listen on");
|
| 869 |
|
| 870 | droproot(FATAL);
|
| 871 |
|
| 872 | - socket_tryreservein(udp53,131072);
|
| 873 | + for (inter = interhead; inter != 0; inter = inter->next)
|
| 874 | + socket_tryreservein(inter->udp53,131072);
|
| 875 |
|
| 876 | byte_zero(seed,sizeof seed);
|
| 877 | read(0,seed,sizeof seed);
|
| 878 | @@ -430,17 +506,42 @@
|
| 879 | scan_ulong(x,&cachesize);
|
| 880 | if (!cache_init(cachesize))
|
| 881 | strerr_die3x(111,FATAL,"not enough memory for cache of size ",x);
|
| 882 | +#ifdef DUMPCACHE
|
| 883 | + x = env_get("SLURPCACHE");
|
| 884 | + if (x) {
|
| 885 | + int nb = cache_slurp(x);
|
| 886 | + if (nb < 0)
|
| 887 | + strerr_die4sys(111,FATAL,"unable to slurp cache ",x," : ");
|
| 888 | + else
|
| 889 | + log_slurp(nb);
|
| 890 | + }
|
| 891 | +#endif
|
| 892 |
|
| 893 | if (env_get("HIDETTL"))
|
| 894 | response_hidettl();
|
| 895 | if (env_get("FORWARDONLY"))
|
| 896 | query_forwardonly();
|
| 897 |
|
| 898 | + x = env_get("NXDSPECIAL");
|
| 899 | + if (x) {
|
| 900 | + if (!ip4_scan(x,nxdip))
|
| 901 | + strerr_die3x(111,FATAL,"unable to parse NXDSPECIAL IP address ",x);
|
| 902 | + query_nxdspecial(nxdip);
|
| 903 | + }
|
| 904 | +
|
| 905 | if (!roots_init())
|
| 906 | strerr_die2sys(111,FATAL,"unable to read servers: ");
|
| 907 |
|
| 908 | - if (socket_listen(tcp53,20) == -1)
|
| 909 | - strerr_die2sys(111,FATAL,"unable to listen on TCP socket: ");
|
| 910 | + for (inter = interhead; inter != 0; inter = inter->next)
|
| 911 | + if (socket_listen(inter->tcp53,20) == -1) {
|
| 912 | + iperr[ip4_fmt(iperr,inter->ip)] = 0;
|
| 913 | + strerr_die4sys(111,FATAL,"unable to listen on TCP socket for IP ",iperr,": ");
|
| 914 | + }
|
| 915 | +
|
| 916 | +#ifdef DUMPCACHE
|
| 917 | + sig_catch(sig_alarm,do_dump);
|
| 918 | +#endif
|
| 919 | + sig_catch(sig_hangup, hup_me);
|
| 920 |
|
| 921 | log_startup();
|
| 922 | doit();
|
| 923 | diff -ruN djbdns-1.05-dist/dnsfilter.c djbdns-1.05/dnsfilter.c
|
| 924 | |
| 925 | |
| 926 | @@ -41,6 +41,7 @@
|
| 927 | iopause_fd *inio;
|
| 928 | int flag0 = 1;
|
| 929 |
|
| 930 | +int opt_replace = 0;
|
| 931 | iopause_fd *io;
|
| 932 | int iolen;
|
| 933 |
|
| 934 | @@ -51,12 +52,16 @@
|
| 935 | void errout(int i)
|
| 936 | {
|
| 937 | int j;
|
| 938 | -
|
| 939 | - if (!stralloc_copys(&x[i].middle,":")) nomem();
|
| 940 | - if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
|
| 941 | - for (j = 0;j < x[i].middle.len;++j)
|
| 942 | - if (x[i].middle.s[j] == ' ')
|
| 943 | - x[i].middle.s[j] = '-';
|
| 944 | +
|
| 945 | + if (opt_replace)
|
| 946 | + x[i].middle.len=0;
|
| 947 | + else {
|
| 948 | + if (!stralloc_copys(&x[i].middle,":")) nomem();
|
| 949 | + if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
|
| 950 | + for (j = 0;j < x[i].middle.len;++j)
|
| 951 | + if (x[i].middle.s[j] == ' ')
|
| 952 | + x[i].middle.s[j] = '-';
|
| 953 | + }
|
| 954 | }
|
| 955 |
|
| 956 | int main(int argc,char **argv)
|
| 957 | @@ -69,7 +74,7 @@
|
| 958 | int j;
|
| 959 | int r;
|
| 960 |
|
| 961 | - while ((opt = getopt(argc,argv,"c:l:")) != opteof)
|
| 962 | + while ((opt = getopt(argc,argv,"c:l:r")) != opteof)
|
| 963 | switch(opt) {
|
| 964 | case 'c':
|
| 965 | scan_ulong(optarg,&u);
|
| 966 | @@ -83,8 +88,11 @@
|
| 967 | if (u > 1000000) u = 1000000;
|
| 968 | xmax = u;
|
| 969 | break;
|
| 970 | + case 'r':
|
| 971 | + opt_replace = 1;
|
| 972 | + break;
|
| 973 | default:
|
| 974 | - strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ]");
|
| 975 | + strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ] [-r]");
|
| 976 | }
|
| 977 |
|
| 978 | x = (struct line *) alloc(xmax * sizeof(struct line));
|
| 979 | @@ -140,8 +148,13 @@
|
| 980 | else if (r == 1) {
|
| 981 | if (dns_name_packet(&x[i].middle,x[i].dt.packet,x[i].dt.packetlen) == -1)
|
| 982 | errout(i);
|
| 983 | - if (x[i].middle.len)
|
| 984 | - if (!stralloc_cats(&x[i].left,"=")) nomem();
|
| 985 | + if (x[i].middle.len) {
|
| 986 | + if (opt_replace) {
|
| 987 | + if (!stralloc_copys(&x[i].left, "")) nomem();
|
| 988 | + } else {
|
| 989 | + if (!stralloc_cats(&x[i].left, "=")) nomem();
|
| 990 | + }
|
| 991 | + }
|
| 992 | x[i].flagactive = 0;
|
| 993 | --numactive;
|
| 994 | }
|
| 995 | diff -ruN djbdns-1.05-dist/hasdevtcp.h djbdns-1.05/hasdevtcp.h
|
| 996 | |
| 997 | |
| 998 | @@ -0,0 +1 @@
|
| 999 | +/* sysdep: -devtcp */
|
| 1000 | diff -ruN djbdns-1.05-dist/hassgact.h djbdns-1.05/hassgact.h
|
| 1001 | |
| 1002 | |
| 1003 | @@ -0,0 +1,2 @@
|
| 1004 | +/* sysdep: +sigaction */
|
| 1005 | +#define HASSIGACTION 1
|
| 1006 | diff -ruN djbdns-1.05-dist/hassgact.h1 djbdns-1.05/hassgact.h1
|
| 1007 | |
| 1008 | |
| 1009 | @@ -0,0 +1 @@
|
| 1010 | +/* sysdep: -sigaction */
|
| 1011 | diff -ruN djbdns-1.05-dist/hassgact.h2 djbdns-1.05/hassgact.h2
|
| 1012 | |
| 1013 | |
| 1014 | @@ -0,0 +1,2 @@
|
| 1015 | +/* sysdep: +sigaction */
|
| 1016 | +#define HASSIGACTION 1
|
| 1017 | diff -ruN djbdns-1.05-dist/hassgprm.h djbdns-1.05/hassgprm.h
|
| 1018 | |
| 1019 | |
| 1020 | @@ -0,0 +1,2 @@
|
| 1021 | +/* sysdep: +sigprocmask */
|
| 1022 | +#define HASSIGPROCMASK 1
|
| 1023 | diff -ruN djbdns-1.05-dist/hassgprm.h1 djbdns-1.05/hassgprm.h1
|
| 1024 | |
| 1025 | |
| 1026 | @@ -0,0 +1 @@
|
| 1027 | +/* sysdep: -sigprocmask */
|
| 1028 | diff -ruN djbdns-1.05-dist/hassgprm.h2 djbdns-1.05/hassgprm.h2
|
| 1029 | |
| 1030 | |
| 1031 | @@ -0,0 +1,2 @@
|
| 1032 | +/* sysdep: +sigprocmask */
|
| 1033 | +#define HASSIGPROCMASK 1
|
| 1034 | diff -ruN djbdns-1.05-dist/hasshsgr.h djbdns-1.05/hasshsgr.h
|
| 1035 | |
| 1036 | |
| 1037 | @@ -0,0 +1 @@
|
| 1038 | +/* sysdep: -shortsetgroups */
|
| 1039 | diff -ruN djbdns-1.05-dist/iopause.h djbdns-1.05/iopause.h
|
| 1040 | |
| 1041 | |
| 1042 | @@ -0,0 +1,18 @@
|
| 1043 | +#ifndef IOPAUSE_H
|
| 1044 | +#define IOPAUSE_H
|
| 1045 | +
|
| 1046 | +/* sysdep: +poll */
|
| 1047 | +#define IOPAUSE_POLL
|
| 1048 | +
|
| 1049 | +#include <sys/types.h>
|
| 1050 | +#include <poll.h>
|
| 1051 | +
|
| 1052 | +typedef struct pollfd iopause_fd;
|
| 1053 | +#define IOPAUSE_READ POLLIN
|
| 1054 | +#define IOPAUSE_WRITE POLLOUT
|
| 1055 | +
|
| 1056 | +#include "taia.h"
|
| 1057 | +
|
| 1058 | +extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *);
|
| 1059 | +
|
| 1060 | +#endif
|
| 1061 | diff -ruN djbdns-1.05-dist/log.c djbdns-1.05/log.c
|
| 1062 | |
| 1063 | |
| 1064 | @@ -88,12 +88,39 @@
|
| 1065 | }
|
| 1066 | }
|
| 1067 |
|
| 1068 | +void log_reread(void)
|
| 1069 | +{
|
| 1070 | + string("rereading servers configuration");
|
| 1071 | + line();
|
| 1072 | +}
|
| 1073 | +
|
| 1074 | void log_startup(void)
|
| 1075 | {
|
| 1076 | string("starting");
|
| 1077 | line();
|
| 1078 | }
|
| 1079 |
|
| 1080 | +void log_listen(const char addr[4])
|
| 1081 | +{
|
| 1082 | + string("listening on ");
|
| 1083 | + ip(addr);
|
| 1084 | + line();
|
| 1085 | +}
|
| 1086 | +
|
| 1087 | +#ifdef DUMPCACHE
|
| 1088 | +void log_slurp(int nb)
|
| 1089 | +{
|
| 1090 | + string("slurp "); number(nb);
|
| 1091 | + line();
|
| 1092 | +}
|
| 1093 | +
|
| 1094 | +void log_dump(int err)
|
| 1095 | +{
|
| 1096 | + string("dump err "); number(err);
|
| 1097 | + line();
|
| 1098 | +}
|
| 1099 | +#endif
|
| 1100 | +
|
| 1101 | void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
|
| 1102 | {
|
| 1103 | string("query "); number(*qnum); space();
|
| 1104 | diff -ruN djbdns-1.05-dist/log.h djbdns-1.05/log.h
|
| 1105 | |
| 1106 | |
| 1107 | @@ -4,6 +4,12 @@
|
| 1108 | #include "uint64.h"
|
| 1109 |
|
| 1110 | extern void log_startup(void);
|
| 1111 | +extern void log_listen(const char *);
|
| 1112 | +#ifdef DUMPCACHE
|
| 1113 | +extern void log_slurp(int);
|
| 1114 | +extern void log_dump(int);
|
| 1115 | +#endif
|
| 1116 | +extern void log_reread(void);
|
| 1117 |
|
| 1118 | extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
|
| 1119 | extern void log_querydrop(uint64 *);
|
| 1120 | diff -ruN djbdns-1.05-dist/okclient.c djbdns-1.05/okclient.c
|
| 1121 | |
| 1122 | |
| 1123 | @@ -1,5 +1,6 @@
|
| 1124 | #include <sys/types.h>
|
| 1125 | #include <sys/stat.h>
|
| 1126 | +#include "env.h"
|
| 1127 | #include "str.h"
|
| 1128 | #include "ip4.h"
|
| 1129 | #include "okclient.h"
|
| 1130 | @@ -10,6 +11,14 @@
|
| 1131 | {
|
| 1132 | struct stat st;
|
| 1133 | int i;
|
| 1134 | + static int init_done=0;
|
| 1135 | + if (!init_done) {
|
| 1136 | + if (env_get("OKCLIENT")) {
|
| 1137 | + init_done=1;
|
| 1138 | + } else
|
| 1139 | + init_done=2;
|
| 1140 | + }
|
| 1141 | + if (init_done==1) return 1;
|
| 1142 |
|
| 1143 | fn[0] = 'i';
|
| 1144 | fn[1] = 'p';
|
| 1145 | diff -ruN djbdns-1.05-dist/parsetype.c djbdns-1.05/parsetype.c
|
| 1146 | |
| 1147 | |
| 1148 | @@ -24,6 +24,8 @@
|
| 1149 | else if (case_equals(s,"key")) byte_copy(type,2,DNS_T_KEY);
|
| 1150 | else if (case_equals(s,"aaaa")) byte_copy(type,2,DNS_T_AAAA);
|
| 1151 | else if (case_equals(s,"axfr")) byte_copy(type,2,DNS_T_AXFR);
|
| 1152 | + else if (case_equals(s,"srv")) byte_copy(type,2,DNS_T_SRV);
|
| 1153 | + else if (case_equals(s,"naptr")) byte_copy(type,2,DNS_T_NAPTR);
|
| 1154 | else
|
| 1155 | return 0;
|
| 1156 |
|
| 1157 | diff -ruN djbdns-1.05-dist/printrecord.c djbdns-1.05/printrecord.c
|
| 1158 | |
| 1159 | |
| 1160 | @@ -82,6 +82,56 @@
|
| 1161 | if (!stralloc_catulong0(out,ch,0)) return 0;
|
| 1162 | }
|
| 1163 | }
|
| 1164 | + else if (byte_equal(misc,2,DNS_T_SRV)) {
|
| 1165 | + if (!stralloc_cats(out," SRV ")) return 0;
|
| 1166 | + pos = dns_packet_copy(buf,len,pos,misc,2); if (!pos) return 0;
|
| 1167 | + uint16_unpack_big(misc,&u16);
|
| 1168 | + if (!stralloc_catulong0(out,u16,0)) return 0;
|
| 1169 | + if (!stralloc_cats(out," ")) return 0;
|
| 1170 | + pos = dns_packet_copy(buf,len,pos,misc,2); if (!pos) return 0;
|
| 1171 | + uint16_unpack_big(misc,&u16);
|
| 1172 | + if (!stralloc_catulong0(out,u16,0)) return 0;
|
| 1173 | + if (!stralloc_cats(out," ")) return 0;
|
| 1174 | + pos = dns_packet_copy(buf,len,pos,misc,2); if (!pos) return 0;
|
| 1175 | + uint16_unpack_big(misc,&u16);
|
| 1176 | + if (!stralloc_catulong0(out,u16,0)) return 0;
|
| 1177 | + if (!stralloc_cats(out," ")) return 0;
|
| 1178 | + pos = dns_packet_getname(buf,len,pos,&d); if (!pos) return 0;
|
| 1179 | + if (!dns_domain_todot_cat(out,d)) return 0;
|
| 1180 | + }
|
| 1181 | + else if (byte_equal(misc,2,DNS_T_NAPTR)) {
|
| 1182 | + char str[255];
|
| 1183 | + unsigned int oldpos;
|
| 1184 | + if (!stralloc_cats(out," NAPTR ")) return 0;
|
| 1185 | + pos = dns_packet_copy(buf,len,pos,misc,2); if (!pos) return 0;
|
| 1186 | + uint16_unpack_big(misc,&u16);
|
| 1187 | + if (!stralloc_catulong0(out,u16,0)) return 0;
|
| 1188 | + if (!stralloc_cats(out," ")) return 0;
|
| 1189 | + pos = dns_packet_copy(buf,len,pos,misc,2); if (!pos) return 0;
|
| 1190 | + uint16_unpack_big(misc,&u16);
|
| 1191 | + if (!stralloc_catulong0(out,u16,0)) return 0;
|
| 1192 | + if (!stralloc_cats(out," ")) return 0;
|
| 1193 | + pos = dns_packet_copy(buf,len,pos,&ch,1); if (!pos) return 0;
|
| 1194 | + pos = dns_packet_copy(buf,len,pos,str,ch); if (!pos) return 0;
|
| 1195 | + if (!stralloc_cats(out,"\"")) return 0;
|
| 1196 | + if (!stralloc_catb(out,str,ch)) return 0;
|
| 1197 | + if (!stralloc_cats(out,"\" ")) return 0;
|
| 1198 | + pos = dns_packet_copy(buf,len,pos,&ch,1); if (!pos) return 0;
|
| 1199 | + pos = dns_packet_copy(buf,len,pos,str,ch); if (!pos) return 0;
|
| 1200 | + if (!stralloc_cats(out,"\"")) return 0;
|
| 1201 | + if (!stralloc_catb(out,str,ch)) return 0;
|
| 1202 | + if (!stralloc_cats(out,"\" ")) return 0;
|
| 1203 | + pos = dns_packet_copy(buf,len,pos,&ch,1); if (!pos) return 0;
|
| 1204 | + pos = dns_packet_copy(buf,len,pos,str,ch); if (!pos) return 0;
|
| 1205 | + if (!stralloc_cats(out,"\"")) return 0;
|
| 1206 | + if (!stralloc_catb(out,str,ch)) return 0;
|
| 1207 | + if (!stralloc_cats(out,"\" ")) return 0;
|
| 1208 | + pos = dns_packet_getname(buf,len,pos,&d); if (!pos) return 0;
|
| 1209 | + oldpos = out->len;
|
| 1210 | + if (!dns_domain_todot_cat(out,d)) return 0;
|
| 1211 | + if (out->len == oldpos)
|
| 1212 | + if (!stralloc_cats(out,".")) return 0;
|
| 1213 | + }
|
| 1214 | else {
|
| 1215 | if (!stralloc_cats(out," ")) return 0;
|
| 1216 | uint16_unpack_big(misc,&u16);
|
| 1217 | diff -ruN djbdns-1.05-dist/prot.c djbdns-1.05/prot.c
|
| 1218 | |
| 1219 | |
| 1220 | @@ -1,5 +1,7 @@
|
| 1221 | #include "hasshsgr.h"
|
| 1222 | #include "prot.h"
|
| 1223 | +#include <grp.h>
|
| 1224 | +#include <unistd.h>
|
| 1225 |
|
| 1226 | int prot_gid(int gid)
|
| 1227 | {
|
| 1228 | diff -ruN djbdns-1.05-dist/query.c djbdns-1.05/query.c
|
| 1229 | |
| 1230 | |
| 1231 | @@ -20,6 +20,15 @@
|
| 1232 | flagforwardonly = 1;
|
| 1233 | }
|
| 1234 |
|
| 1235 | +static int flagnxdspecial = 0;
|
| 1236 | +static char nxdip[4];
|
| 1237 | +
|
| 1238 | +void query_nxdspecial(const char ip[4])
|
| 1239 | +{
|
| 1240 | + byte_copy(nxdip,4,ip);
|
| 1241 | + flagnxdspecial = 1;
|
| 1242 | +}
|
| 1243 | +
|
| 1244 | static void cachegeneric(const char type[2],const char *d,const char *data,unsigned int datalen,uint32 ttl)
|
| 1245 | {
|
| 1246 | unsigned int len;
|
| 1247 | @@ -246,6 +255,7 @@
|
| 1248 | case_lowerb(key + 2,dlen);
|
| 1249 | cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
|
| 1250 | if (cached) {
|
| 1251 | + soattl = rcode = 0;
|
| 1252 | log_cachednxdomain(d);
|
| 1253 | goto NXDOMAIN;
|
| 1254 | }
|
| 1255 | @@ -695,7 +705,12 @@
|
| 1256 | NXDOMAIN:
|
| 1257 | if (z->level) goto LOWERLEVEL;
|
| 1258 | if (!rqa(z)) goto DIE;
|
| 1259 | - response_nxdomain();
|
| 1260 | + if (flagnxdspecial && typematch(DNS_T_A,dtype)) {
|
| 1261 | + if (!response_rstart(d,DNS_T_A,rcode == 3 ? soattl : ttl)) goto DIE;
|
| 1262 | + if (!response_addbytes(nxdip,4)) goto DIE;
|
| 1263 | + response_rfinish(RESPONSE_ANSWER);
|
| 1264 | + } else
|
| 1265 | + response_nxdomain();
|
| 1266 | cleanup(z);
|
| 1267 | return 1;
|
| 1268 | }
|
| 1269 | diff -ruN djbdns-1.05-dist/query.h djbdns-1.05/query.h
|
| 1270 | |
| 1271 | |
| 1272 | @@ -28,5 +28,6 @@
|
| 1273 | extern int query_get(struct query *,iopause_fd *,struct taia *);
|
| 1274 |
|
| 1275 | extern void query_forwardonly(void);
|
| 1276 | +extern void query_nxdspecial(const char *);
|
| 1277 |
|
| 1278 | #endif
|
| 1279 | diff -ruN djbdns-1.05-dist/seek_set.c djbdns-1.05/seek_set.c
|
| 1280 | |
| 1281 | |
| 1282 | @@ -1,4 +1,5 @@
|
| 1283 | #include <sys/types.h>
|
| 1284 | +#include <unistd.h>
|
| 1285 | #include "seek.h"
|
| 1286 |
|
| 1287 | #define SET 0 /* sigh */
|
| 1288 | diff -ruN djbdns-1.05-dist/select.h djbdns-1.05/select.h
|
| 1289 | |
| 1290 | |
| 1291 | @@ -0,0 +1,11 @@
|
| 1292 | +#ifndef SELECT_H
|
| 1293 | +#define SELECT_H
|
| 1294 | +
|
| 1295 | +/* sysdep: +sysselect */
|
| 1296 | +
|
| 1297 | +#include <sys/types.h>
|
| 1298 | +#include <sys/time.h>
|
| 1299 | +#include <sys/select.h>
|
| 1300 | +extern int select();
|
| 1301 | +
|
| 1302 | +#endif
|
| 1303 | diff -ruN djbdns-1.05-dist/server.c djbdns-1.05/server.c
|
| 1304 | |
| 1305 | |
| 1306 | @@ -11,6 +11,8 @@
|
| 1307 | #include "qlog.h"
|
| 1308 | #include "response.h"
|
| 1309 | #include "dns.h"
|
| 1310 | +#include "alloc.h"
|
| 1311 | +#include "iopause.h"
|
| 1312 |
|
| 1313 | extern char *fatal;
|
| 1314 | extern char *starting;
|
| 1315 | @@ -25,6 +27,44 @@
|
| 1316 |
|
| 1317 | static char *q;
|
| 1318 |
|
| 1319 | +
|
| 1320 | +static void hex(unsigned char c)
|
| 1321 | +{
|
| 1322 | + buffer_put(buffer_2,"0123456789abcdef" + (c >> 4),1);
|
| 1323 | + buffer_put(buffer_2,"0123456789abcdef" + (c & 15),1);
|
| 1324 | +}
|
| 1325 | +
|
| 1326 | +static void put_ip(const char i[4])
|
| 1327 | +{
|
| 1328 | + hex(i[0]);
|
| 1329 | + hex(i[1]);
|
| 1330 | + hex(i[2]);
|
| 1331 | + hex(i[3]);
|
| 1332 | +}
|
| 1333 | +
|
| 1334 | +static void string(const char *s)
|
| 1335 | +{
|
| 1336 | + buffer_puts(buffer_2,s);
|
| 1337 | +}
|
| 1338 | +
|
| 1339 | +static void line(void)
|
| 1340 | +{
|
| 1341 | + string("\n");
|
| 1342 | + buffer_flush(buffer_2);
|
| 1343 | +}
|
| 1344 | +
|
| 1345 | +void log_listen(const char addr[4])
|
| 1346 | +{
|
| 1347 | + string("listening on ");
|
| 1348 | + put_ip(addr);
|
| 1349 | + line();
|
| 1350 | +}
|
| 1351 | +
|
| 1352 | +void nomem()
|
| 1353 | +{
|
| 1354 | + strerr_die2x(111,fatal,"out of memory");
|
| 1355 | +}
|
| 1356 | +
|
| 1357 | static int doit(void)
|
| 1358 | {
|
| 1359 | unsigned int pos;
|
| 1360 | @@ -51,6 +91,13 @@
|
| 1361 | response[3] &= ~128;
|
| 1362 | if (!(header[2] & 1)) response[2] &= ~1;
|
| 1363 |
|
| 1364 | + if ((header[2] & 126) == 0x24) /* NOTIFY + AA */
|
| 1365 | + if (byte_equal(qtype,2,DNS_T_SOA)) {
|
| 1366 | + response[2] |= 0x20; /* NOTIFY */
|
| 1367 | + qlog(ip,port,header,q,qtype," N ");
|
| 1368 | + return 1;
|
| 1369 | + }
|
| 1370 | +
|
| 1371 | if (header[2] & 126) goto NOTIMP;
|
| 1372 | if (byte_equal(qtype,2,DNS_T_AXFR)) goto NOTIMP;
|
| 1373 |
|
| 1374 | @@ -59,7 +106,12 @@
|
| 1375 | qlog(ip,port,header,q,qtype," - ");
|
| 1376 | return 0;
|
| 1377 | }
|
| 1378 | - qlog(ip,port,header,q,qtype," + ");
|
| 1379 | +
|
| 1380 | + if ((response[2] & 4) && (response[3] & 3))
|
| 1381 | + qlog(ip,port,header,q,qtype," X ");
|
| 1382 | + else
|
| 1383 | + qlog(ip,port,header,q,qtype," + ");
|
| 1384 | +
|
| 1385 | return 1;
|
| 1386 |
|
| 1387 | NOTIMP:
|
| 1388 | @@ -82,35 +134,75 @@
|
| 1389 | int main()
|
| 1390 | {
|
| 1391 | char *x;
|
| 1392 | - int udp53;
|
| 1393 | + int *udp53;
|
| 1394 | + unsigned int off;
|
| 1395 | + unsigned int cnt;
|
| 1396 | + iopause_fd *iop;
|
| 1397 |
|
| 1398 | x = env_get("IP");
|
| 1399 | if (!x)
|
| 1400 | strerr_die2x(111,fatal,"$IP not set");
|
| 1401 | - if (!ip4_scan(x,ip))
|
| 1402 | - strerr_die3x(111,fatal,"unable to parse IP address ",x);
|
| 1403 | -
|
| 1404 | - udp53 = socket_udp();
|
| 1405 | - if (udp53 == -1)
|
| 1406 | - strerr_die2sys(111,fatal,"unable to create UDP socket: ");
|
| 1407 | - if (socket_bind4_reuse(udp53,ip,53) == -1)
|
| 1408 | - strerr_die2sys(111,fatal,"unable to bind UDP socket: ");
|
| 1409 | + off=0;
|
| 1410 | + cnt=0;
|
| 1411 | + while (x[off]) {
|
| 1412 | + unsigned int l;
|
| 1413 | + char dummy[4];
|
| 1414 | + l=ip4_scan(x+off,dummy);
|
| 1415 | + if (!l)
|
| 1416 | + strerr_die3x(111,fatal,"unable to parse IP address ",x+off);
|
| 1417 | + cnt++;
|
| 1418 | + if (!x[off+l]) break;
|
| 1419 | + if (x[off+l]!='/')
|
| 1420 | + strerr_die3x(111,fatal,"unable to parse IP address ",x+off);
|
| 1421 | + off+=l+1;
|
| 1422 | + }
|
| 1423 | + udp53=(int *) alloc(sizeof(int) *cnt);
|
| 1424 | + if (!udp53) nomem();
|
| 1425 | + iop=(iopause_fd *) alloc(sizeof(*iop) * cnt);
|
| 1426 | + if (!iop) nomem();
|
| 1427 | +
|
| 1428 | + off=0;
|
| 1429 | + cnt=0;
|
| 1430 | + while (x[off]) {
|
| 1431 | + unsigned int l;
|
| 1432 | + l=ip4_scan(x+off,ip);
|
| 1433 | + udp53[cnt] = socket_udp();
|
| 1434 | + if (udp53[cnt] == -1)
|
| 1435 | + strerr_die2sys(111,fatal,"unable to create UDP socket: ");
|
| 1436 | + if (socket_bind4_reuse(udp53[cnt],ip,53) == -1)
|
| 1437 | + strerr_die2sys(111,fatal,"unable to bind UDP socket: ");
|
| 1438 | + ndelay_off(udp53[cnt]);
|
| 1439 | + socket_tryreservein(udp53[cnt],65536);
|
| 1440 | + iop[cnt].fd=udp53[cnt];
|
| 1441 | + iop[cnt].events=IOPAUSE_READ;
|
| 1442 | + log_listen(ip);
|
| 1443 | + cnt++;
|
| 1444 | + if (!x[off+l]) break;
|
| 1445 | + off+=l+1;
|
| 1446 | + }
|
| 1447 |
|
| 1448 | droproot(fatal);
|
| 1449 |
|
| 1450 | initialize();
|
| 1451 | -
|
| 1452 | - ndelay_off(udp53);
|
| 1453 | - socket_tryreservein(udp53,65536);
|
| 1454 |
|
| 1455 | buffer_putsflush(buffer_2,starting);
|
| 1456 | -
|
| 1457 | +
|
| 1458 | for (;;) {
|
| 1459 | - len = socket_recv4(udp53,buf,sizeof buf,ip,&port);
|
| 1460 | - if (len < 0) continue;
|
| 1461 | - if (!doit()) continue;
|
| 1462 | - if (response_len > 512) response_tc();
|
| 1463 | - socket_send4(udp53,response,response_len,ip,port);
|
| 1464 | - /* may block for buffer space; if it fails, too bad */
|
| 1465 | + struct taia stamp;
|
| 1466 | + struct taia deadline;
|
| 1467 | + unsigned int i;
|
| 1468 | + taia_now(&stamp);
|
| 1469 | + taia_uint(&deadline,300);
|
| 1470 | + taia_add(&deadline,&deadline,&stamp);
|
| 1471 | + iopause(iop,cnt,&deadline,&stamp);
|
| 1472 | + for (i=0;i<cnt;i++)
|
| 1473 | + if (iop[i].revents) {
|
| 1474 | + len = socket_recv4(udp53[i],buf,sizeof buf,ip,&port);
|
| 1475 | + if (len < 0) continue;
|
| 1476 | + if (!doit()) continue;
|
| 1477 | + if (response_len > 512) response_tc();
|
| 1478 | + socket_send4(udp53[i],response,response_len,ip,port);
|
| 1479 | + /* may block for buffer space; if it fails, too bad */
|
| 1480 | + }
|
| 1481 | }
|
| 1482 | }
|
| 1483 | diff -ruN djbdns-1.05-dist/sig.c djbdns-1.05/sig.c
|
| 1484 | |
| 1485 | |
| 1486 | @@ -0,0 +1,12 @@
|
| 1487 | +#include <signal.h>
|
| 1488 | +#include "sig.h"
|
| 1489 | +
|
| 1490 | +int sig_alarm = SIGALRM;
|
| 1491 | +int sig_child = SIGCHLD;
|
| 1492 | +int sig_cont = SIGCONT;
|
| 1493 | +int sig_hangup = SIGHUP;
|
| 1494 | +int sig_pipe = SIGPIPE;
|
| 1495 | +int sig_term = SIGTERM;
|
| 1496 | +
|
| 1497 | +void (*sig_defaulthandler)() = SIG_DFL;
|
| 1498 | +void (*sig_ignorehandler)() = SIG_IGN;
|
| 1499 | diff -ruN djbdns-1.05-dist/sig.h djbdns-1.05/sig.h
|
| 1500 | |
| 1501 | |
| 1502 | @@ -0,0 +1,25 @@
|
| 1503 | +#ifndef SIG_H
|
| 1504 | +#define SIG_H
|
| 1505 | +
|
| 1506 | +extern int sig_alarm;
|
| 1507 | +extern int sig_child;
|
| 1508 | +extern int sig_cont;
|
| 1509 | +extern int sig_hangup;
|
| 1510 | +extern int sig_pipe;
|
| 1511 | +extern int sig_term;
|
| 1512 | +
|
| 1513 | +extern void (*sig_defaulthandler)();
|
| 1514 | +extern void (*sig_ignorehandler)();
|
| 1515 | +
|
| 1516 | +extern void sig_catch(int,void (*)());
|
| 1517 | +#define sig_ignore(s) (sig_catch((s),sig_ignorehandler))
|
| 1518 | +#define sig_uncatch(s) (sig_catch((s),sig_defaulthandler))
|
| 1519 | +
|
| 1520 | +extern void sig_block(int);
|
| 1521 | +extern void sig_unblock(int);
|
| 1522 | +extern void sig_blocknone(void);
|
| 1523 | +extern void sig_pause(void);
|
| 1524 | +
|
| 1525 | +extern void sig_dfl(int);
|
| 1526 | +
|
| 1527 | +#endif
|
| 1528 | diff -ruN djbdns-1.05-dist/sig_block.c djbdns-1.05/sig_block.c
|
| 1529 | |
| 1530 | |
| 1531 | @@ -0,0 +1,38 @@
|
| 1532 | +#include <signal.h>
|
| 1533 | +#include "sig.h"
|
| 1534 | +#include "hassgprm.h"
|
| 1535 | +
|
| 1536 | +void sig_block(int sig)
|
| 1537 | +{
|
| 1538 | +#ifdef HASSIGPROCMASK
|
| 1539 | + sigset_t ss;
|
| 1540 | + sigemptyset(&ss);
|
| 1541 | + sigaddset(&ss,sig);
|
| 1542 | + sigprocmask(SIG_BLOCK,&ss,(sigset_t *) 0);
|
| 1543 | +#else
|
| 1544 | + sigblock(1 << (sig - 1));
|
| 1545 | +#endif
|
| 1546 | +}
|
| 1547 | +
|
| 1548 | +void sig_unblock(int sig)
|
| 1549 | +{
|
| 1550 | +#ifdef HASSIGPROCMASK
|
| 1551 | + sigset_t ss;
|
| 1552 | + sigemptyset(&ss);
|
| 1553 | + sigaddset(&ss,sig);
|
| 1554 | + sigprocmask(SIG_UNBLOCK,&ss,(sigset_t *) 0);
|
| 1555 | +#else
|
| 1556 | + sigsetmask(sigsetmask(~0) & ~(1 << (sig - 1)));
|
| 1557 | +#endif
|
| 1558 | +}
|
| 1559 | +
|
| 1560 | +void sig_blocknone(void)
|
| 1561 | +{
|
| 1562 | +#ifdef HASSIGPROCMASK
|
| 1563 | + sigset_t ss;
|
| 1564 | + sigemptyset(&ss);
|
| 1565 | + sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0);
|
| 1566 | +#else
|
| 1567 | + sigsetmask(0);
|
| 1568 | +#endif
|
| 1569 | +}
|
| 1570 | diff -ruN djbdns-1.05-dist/sig_catch.c djbdns-1.05/sig_catch.c
|
| 1571 | |
| 1572 | |
| 1573 | @@ -0,0 +1,16 @@
|
| 1574 | +#include <signal.h>
|
| 1575 | +#include "sig.h"
|
| 1576 | +#include "hassgact.h"
|
| 1577 | +
|
| 1578 | +void sig_catch(int sig,void (*f)())
|
| 1579 | +{
|
| 1580 | +#ifdef HASSIGACTION
|
| 1581 | + struct sigaction sa;
|
| 1582 | + sa.sa_handler = f;
|
| 1583 | + sa.sa_flags = 0;
|
| 1584 | + sigemptyset(&sa.sa_mask);
|
| 1585 | + sigaction(sig,&sa,(struct sigaction *) 0);
|
| 1586 | +#else
|
| 1587 | + signal(sig,f); /* won't work under System V, even nowadays---dorks */
|
| 1588 | +#endif
|
| 1589 | +}
|
| 1590 | diff -ruN djbdns-1.05-dist/sig_pause.c djbdns-1.05/sig_pause.c
|
| 1591 | |
| 1592 | |
| 1593 | @@ -0,0 +1,14 @@
|
| 1594 | +#include <signal.h>
|
| 1595 | +#include "sig.h"
|
| 1596 | +#include "hassgprm.h"
|
| 1597 | +
|
| 1598 | +void sig_pause(void)
|
| 1599 | +{
|
| 1600 | +#ifdef HASSIGPROCMASK
|
| 1601 | + sigset_t ss;
|
| 1602 | + sigemptyset(&ss);
|
| 1603 | + sigsuspend(&ss);
|
| 1604 | +#else
|
| 1605 | + sigpause(0);
|
| 1606 | +#endif
|
| 1607 | +}
|
| 1608 | diff -ruN djbdns-1.05-dist/tinydns-data.c djbdns-1.05/tinydns-data.c
|
| 1609 | |
| 1610 | |
| 1611 | @@ -159,11 +159,7 @@
|
| 1612 | die_datatmp();
|
| 1613 | }
|
| 1614 |
|
| 1615 | -buffer b;
|
| 1616 | -char bspace[1024];
|
| 1617 | -
|
| 1618 | static stralloc line;
|
| 1619 | -int match = 1;
|
| 1620 | unsigned long linenum = 0;
|
| 1621 |
|
| 1622 | #define NUMFIELDS 15
|
| 1623 | @@ -171,6 +167,8 @@
|
| 1624 |
|
| 1625 | static char *d1;
|
| 1626 | static char *d2;
|
| 1627 | +static char *contact;
|
| 1628 | +
|
| 1629 | char dptr[DNS_NAME4_DOMAIN];
|
| 1630 |
|
| 1631 | char strnum[FMT_ULONG];
|
| 1632 | @@ -181,7 +179,7 @@
|
| 1633 | strerr_die4x(111,FATAL,"unable to parse data line ",strnum,why);
|
| 1634 | }
|
| 1635 |
|
| 1636 | -int main()
|
| 1637 | +int load(const char *fname)
|
| 1638 | {
|
| 1639 | int fddata;
|
| 1640 | int i;
|
| 1641 | @@ -196,20 +194,20 @@
|
| 1642 | char type[2];
|
| 1643 | char soa[20];
|
| 1644 | char buf[4];
|
| 1645 | + char naptr[4];
|
| 1646 | + char srv[6];
|
| 1647 | + int match;
|
| 1648 | + buffer b;
|
| 1649 | + char bspace[1024];
|
| 1650 |
|
| 1651 | - umask(022);
|
| 1652 | -
|
| 1653 | - fddata = open_read("data");
|
| 1654 | + fddata = open_read(fname);
|
| 1655 | if (fddata == -1)
|
| 1656 | - strerr_die2sys(111,FATAL,"unable to open data: ");
|
| 1657 | + strerr_die4sys(111,FATAL,"unable to open ",fname,": ");
|
| 1658 | defaultsoa_init(fddata);
|
| 1659 |
|
| 1660 | buffer_init(&b,buffer_unixread,fddata,bspace,sizeof bspace);
|
| 1661 |
|
| 1662 | - fdcdb = open_trunc("data.tmp");
|
| 1663 | - if (fdcdb == -1) die_datatmp();
|
| 1664 | - if (cdb_make_start(&cdb,fdcdb) == -1) die_datatmp();
|
| 1665 | -
|
| 1666 | + match = 1;
|
| 1667 | while (match) {
|
| 1668 | ++linenum;
|
| 1669 | if (getln(&b,&line,&match,'\n') == -1)
|
| 1670 | @@ -247,6 +245,11 @@
|
| 1671 | die_datatmp();
|
| 1672 | break;
|
| 1673 |
|
| 1674 | + case 'D':
|
| 1675 | + if (!dns_domain_fromdot(&contact,f[0].s,f[0].len)) nomem();
|
| 1676 | + if (f[0].len == 0) contact = NULL;
|
| 1677 | + break;
|
| 1678 | +
|
| 1679 | case 'Z':
|
| 1680 | if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
|
| 1681 |
|
| 1682 | @@ -298,8 +301,13 @@
|
| 1683 | if (line.s[0] == '.') {
|
| 1684 | rr_start(DNS_T_SOA,ttl ? TTL_NEGATIVE : 0,ttd,loc);
|
| 1685 | rr_addname(d2);
|
| 1686 | - rr_add("\12hostmaster",11);
|
| 1687 | - rr_addname(d1);
|
| 1688 | + if (!contact) {
|
| 1689 | + rr_add("\12hostmaster",11);
|
| 1690 | + rr_addname(d1);
|
| 1691 | + } else {
|
| 1692 | + rr_addname(contact);
|
| 1693 | + }
|
| 1694 | +
|
| 1695 | rr_add(defaultsoa,20);
|
| 1696 | rr_finish(d1);
|
| 1697 | }
|
| 1698 | @@ -369,6 +377,43 @@
|
| 1699 | rr_finish(d2);
|
| 1700 | }
|
| 1701 | break;
|
| 1702 | +
|
| 1703 | + case 'S':
|
| 1704 | + if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
|
| 1705 | + if (!stralloc_0(&f[6])) nomem();
|
| 1706 | + if (!scan_ulong(f[6].s,&ttl)) ttl = TTL_POSITIVE;
|
| 1707 | + ttdparse(&f[7],ttd);
|
| 1708 | + locparse(&f[8],loc);
|
| 1709 | +
|
| 1710 | + if (!stralloc_0(&f[1])) nomem();
|
| 1711 | +
|
| 1712 | + if (byte_chr(f[2].s,f[2].len,'.') >= f[2].len) {
|
| 1713 | + if (!stralloc_cats(&f[2],".srv.")) nomem();
|
| 1714 | + if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem();
|
| 1715 | + }
|
| 1716 | + if (!dns_domain_fromdot(&d2,f[2].s,f[2].len)) nomem();
|
| 1717 | +
|
| 1718 | + if (!stralloc_0(&f[4])) nomem();
|
| 1719 | + if (!scan_ulong(f[4].s,&u)) u = 0;
|
| 1720 | + uint16_pack_big(srv,u);
|
| 1721 | + if (!stralloc_0(&f[5])) nomem();
|
| 1722 | + if (!scan_ulong(f[5].s,&u)) u = 0;
|
| 1723 | + uint16_pack_big(srv + 2,u);
|
| 1724 | + if (!stralloc_0(&f[3])) nomem();
|
| 1725 | + if (!scan_ulong(f[3].s,&u)) nomem();
|
| 1726 | + uint16_pack_big(srv + 4,u);
|
| 1727 | +
|
| 1728 | + rr_start(DNS_T_SRV,ttl,ttd,loc);
|
| 1729 | + rr_add(srv,6);
|
| 1730 | + rr_addname(d2);
|
| 1731 | + rr_finish(d1);
|
| 1732 | +
|
| 1733 | + if (ip4_scan(f[1].s,ip)) {
|
| 1734 | + rr_start(DNS_T_A,ttl,ttd,loc);
|
| 1735 | + rr_add(ip,4);
|
| 1736 | + rr_finish(d2);
|
| 1737 | + }
|
| 1738 | + break;
|
| 1739 |
|
| 1740 | case '^': case 'C':
|
| 1741 | if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
|
| 1742 | @@ -441,10 +486,61 @@
|
| 1743 | rr_finish(d1);
|
| 1744 | break;
|
| 1745 |
|
| 1746 | + case 'N':
|
| 1747 | + if (!dns_domain_fromdot(&d1,f[0].s,f[0].len)) nomem();
|
| 1748 | + if (!dns_domain_fromdot(&d2,f[6].s,f[6].len)) nomem();
|
| 1749 | + if (!stralloc_0(&f[7])) nomem();
|
| 1750 | + if (!scan_ulong(f[7].s,&ttl)) ttl = TTL_POSITIVE;
|
| 1751 | + ttdparse(&f[8],ttd);
|
| 1752 | + locparse(&f[9],loc);
|
| 1753 | +
|
| 1754 | + if (!stralloc_0(&f[1])) nomem();
|
| 1755 | + if (!scan_ulong(f[1].s,&u)) u = 0;
|
| 1756 | + uint16_pack_big(naptr,u);
|
| 1757 | + if (!stralloc_0(&f[2])) nomem();
|
| 1758 | + if (!scan_ulong(f[2].s,&u)) u = 0;
|
| 1759 | + uint16_pack_big(naptr + 2,u);
|
| 1760 | +
|
| 1761 | + txtparse(&f[3]); if (f[3].len > 255)
|
| 1762 | + syntaxerror(": it is not allowed more than 255 chars in a label");
|
| 1763 | + txtparse(&f[4]); if (f[4].len > 255)
|
| 1764 | + syntaxerror(": it is not allowed more than 255 chars in a label");
|
| 1765 | + txtparse(&f[5]); if (f[5].len > 255)
|
| 1766 | + syntaxerror(": it is not allowed more than 255 chars in a label");
|
| 1767 | +
|
| 1768 | + rr_start(DNS_T_NAPTR,ttl,ttd,loc);
|
| 1769 | + rr_add(naptr,4);
|
| 1770 | +
|
| 1771 | + ch = f[3].len; rr_add(&ch,1);
|
| 1772 | + rr_add(f[3].s, f[3].len);
|
| 1773 | + ch = f[4].len; rr_add(&ch,1);
|
| 1774 | + rr_add(f[4].s, f[4].len);
|
| 1775 | + ch = f[5].len; rr_add(&ch,1);
|
| 1776 | + rr_add(f[5].s, f[5].len);
|
| 1777 | +
|
| 1778 | + rr_addname(d2);
|
| 1779 | + rr_finish(d1);
|
| 1780 | + break;
|
| 1781 | +
|
| 1782 | default:
|
| 1783 | syntaxerror(": unrecognized leading character");
|
| 1784 | }
|
| 1785 | }
|
| 1786 | + close(fddata);
|
| 1787 | +}
|
| 1788 | +
|
| 1789 | +int main(int argc, char **argv)
|
| 1790 | +{
|
| 1791 | + umask(022);
|
| 1792 | + fdcdb = open_trunc("data.tmp");
|
| 1793 | + if (fdcdb == -1) die_datatmp();
|
| 1794 | + if (cdb_make_start(&cdb,fdcdb) == -1) die_datatmp();
|
| 1795 | +
|
| 1796 | + if (argc == 1)
|
| 1797 | + load("data");
|
| 1798 | + while(--argc) {
|
| 1799 | + load(argv[argc]);
|
| 1800 | + }
|
| 1801 |
|
| 1802 | if (cdb_make_finish(&cdb) == -1) die_datatmp();
|
| 1803 | if (fsync(fdcdb) == -1) die_datatmp();
|
| 1804 | diff -ruN djbdns-1.05-dist/trysgact.c djbdns-1.05/trysgact.c
|
| 1805 | |
| 1806 | |
| 1807 | @@ -0,0 +1,10 @@
|
| 1808 | +#include <signal.h>
|
| 1809 | +
|
| 1810 | +main()
|
| 1811 | +{
|
| 1812 | + struct sigaction sa;
|
| 1813 | + sa.sa_handler = 0;
|
| 1814 | + sa.sa_flags = 0;
|
| 1815 | + sigemptyset(&sa.sa_mask);
|
| 1816 | + sigaction(0,&sa,(struct sigaction *) 0);
|
| 1817 | +}
|
| 1818 | diff -ruN djbdns-1.05-dist/trysgprm.c djbdns-1.05/trysgprm.c
|
| 1819 | |
| 1820 | |
| 1821 | @@ -0,0 +1,10 @@
|
| 1822 | +#include <signal.h>
|
| 1823 | +
|
| 1824 | +main()
|
| 1825 | +{
|
| 1826 | + sigset_t ss;
|
| 1827 | +
|
| 1828 | + sigemptyset(&ss);
|
| 1829 | + sigaddset(&ss,SIGCHLD);
|
| 1830 | + sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0);
|
| 1831 | +}
|
| 1832 | diff -ruN djbdns-1.05-dist/uint32.h djbdns-1.05/uint32.h
|
| 1833 | |
| 1834 | |
| 1835 | @@ -0,0 +1,11 @@
|
| 1836 | +#ifndef UINT32_H
|
| 1837 | +#define UINT32_H
|
| 1838 | +
|
| 1839 | +typedef unsigned long uint32;
|
| 1840 | +
|
| 1841 | +extern void uint32_pack(char *,uint32);
|
| 1842 | +extern void uint32_pack_big(char *,uint32);
|
| 1843 | +extern void uint32_unpack(const char *,uint32 *);
|
| 1844 | +extern void uint32_unpack_big(const char *,uint32 *);
|
| 1845 | +
|
| 1846 | +#endif
|
| 1847 | diff -ruN djbdns-1.05-dist/uint64.h djbdns-1.05/uint64.h
|
| 1848 | |
| 1849 | |
| 1850 | @@ -0,0 +1,8 @@
|
| 1851 | +#ifndef UINT64_H
|
| 1852 | +#define UINT64_H
|
| 1853 | +
|
| 1854 | +/* sysdep: -ulong64 */
|
| 1855 | +
|
| 1856 | +typedef unsigned long long uint64;
|
| 1857 | +
|
| 1858 | +#endif
|