djbdnscurve6 46
djbdnscurve6
Loading...
Searching...
No Matches
tinydns-data.c
Go to the documentation of this file.
1#include <unistd.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include "uint_t.h"
5#include "str.h"
6#include "byte.h"
7#include "fmt.h"
8#include "ip.h"
9#include "exit.h"
10#include "case.h"
11#include "scan.h"
12#include "buffer.h"
13#include "logmsg.h"
14#include "getln.h"
15#include "cdbmake.h"
16#include "stralloc.h"
17#include "readclose.h"
18#include "open.h"
19#include "dns.h"
20
21#define TTL_NS 259200
22#define TTL_POSITIVE 86400
23#define TTL_NEGATIVE 2560
24#define TXT_LABLEN 255
25
26#define WHO "tinydns-data"
27
28int rename(const char *,const char *); // keep compiler silent
29
30void die_datatmp(void)
31{
32 logmsg(WHO,111,FATAL,"unable to create data.tmp");
33}
34
35void nomem(void)
36{
37 logmsg(WHO,111,FATAL,"nomem");
38}
39
40void ttdparse(stralloc *sa,char ttd[8])
41{
42 unsigned int i;
43 char ch;
44
45 byte_zero(ttd,8);
46 for (i = 0; (i < 16) && (i < sa->len); ++i) {
47 ch = sa->s[i];
48 if ((ch >= '0') && (ch <= '9'))
49 ch -= '0';
50 else if ((ch >= 'a') && (ch <= 'f'))
51 ch -= 'a' - 10;
52 else
53 ch = 0;
54 if (!(i & 1)) ch <<= 4;
55 ttd[i >> 1] |= ch;
56 }
57}
58
59void locparse(stralloc *sa,char loc[2])
60{
61 loc[0] = (sa->len > 0) ? sa->s[0] : 0;
62 loc[1] = (sa->len > 1) ? sa->s[1] : 0;
63}
64
65/* input *s = IPv4/6 address
66 output out = IPv4/6 address byte string for lookup */
67
68void ipprefix_get(stralloc *out,char *s)
69{
70 char ip4[4];
71 char ip6[16];
72 unsigned int plen;
73
74 if (!stralloc_copys(out,"")) nomem();
75 if (!str_len(s)) return;
76
77 if (str_chr(s,':') < str_len(s)) {
78 ip6_cidr(s,ip6,&plen);
79 ip6_bytestring(out,ip6,plen);
80 } else if (str_chr(s,'.') < str_len(s)) {
81 ip4_cidr(s,ip4,&plen);
82 ip4_bytestring(out,ip4,plen);
83 }
84}
85
86void hexparse(stralloc *sa)
87{
88 char ch, lo;
89 unsigned int i;
90 unsigned int j;
91
92 j = 0;
93 i = 0;
94 while (i < sa->len) {
95 ch = sa->s[i++];
96 if ((ch >= '0') && (ch <= '9')) ch -= 48;
97 if ((ch >= 'a') && (ch <= 'f')) ch -= 87;
98 ch <<= 4;
99 lo = sa->s[i++];
100 if ((lo >= '0') && (lo <= '9')) lo -= 48;
101 if ((lo >= 'a') && (lo <= 'f')) lo -= 87;
102 ch += lo;
103 sa->s[j++] = ch;
104 }
105 sa->len = j;
106}
107
108void txtparse(stralloc *sa)
109{
110 char ch;
111 unsigned int i;
112 unsigned int j;
113
114 j = 0;
115 i = 0;
116 while (i < sa->len) {
117 ch = sa->s[i++];
118 if (ch == '\\') {
119 if (i >= sa->len) break;
120 ch = sa->s[i++];
121 if ((ch >= '0') && (ch <= '7')) {
122 ch -= '0';
123 if ((i < sa->len) && (sa->s[i] >= '0') && (sa->s[i] <= '7')) {
124 ch <<= 3;
125 ch += sa->s[i++] - '0';
126 if ((i < sa->len) && (sa->s[i] >= '0') && (sa->s[i] <= '7')) {
127 ch <<= 3;
128 ch += sa->s[i++] - '0';
129 }
130 }
131 }
132 }
133 sa->s[j++] = ch;
134 }
135 sa->len = j;
136}
137
138void textparse(stralloc *sa)
139{
140 char ch;
141 unsigned int i;
142 unsigned int j;
143
144 j = 0;
145 i = 0;
146 while (i < sa->len) {
147 ch = sa->s[i++];
148 if (ch >= ' ' && ch <= '~')
149 { sa->s[j] = ch; j++; }
150 }
151 sa -> s[j] = '\0';
152 sa->len = j ;
153}
154
155char defaultsoa[20];
156
158{
159 struct stat st;
160 if (fstat(fd,&st) == -1)
161 logmsg(WHO,111,FATAL,"unable to stat data");
162 uint32_pack_big(defaultsoa,st.st_mtime);
163 if (byte_equal(defaultsoa,4,"\0\0\0\0"))
164 defaultsoa[3] = 1;
165 byte_copy(defaultsoa + 4,16,"\0\0\100\000\0\0\010\000\0\020\000\000\0\0\012\000");
166}
167
169struct cdb_make cdb;
170static stralloc key;
171static stralloc ipstring;
172static stralloc result;
173
174void rr_add(const char *buf,unsigned int len)
175{
176 if (!stralloc_catb(&result,buf,len)) nomem();
177}
178
179void rr_addname(const char *d)
180{
182}
183
184void rr_start(const char type[2],unsigned long ttl,const char ttd[8],const char loc[2])
185{
186 char buf[4];
187 if (!stralloc_copyb(&result,type,2)) nomem();
188 if (byte_equal(loc,2,"\0\0"))
189 rr_add("=",1);
190 else {
191 rr_add(">",1);
192 rr_add(loc,2);
193 }
194 uint32_pack_big(buf,ttl);
195 rr_add(buf,4);
196 rr_add(ttd,8);
197}
198
199void rr_finish(const char *owner)
200{
201 if (byte_equal(owner,2,"\1*")) {
202 owner += 2;
203 result.s[2] -= 19;
204 }
205 if (!stralloc_copyb(&key,owner,dns_domain_length(owner))) nomem();
206 case_lowerb(key.s,key.len);
207 if (cdb_make_add(&cdb,key.s,key.len,result.s,result.len) == -1)
208 die_datatmp();
209}
210
211buffer b;
212char bspace[1024];
213
214static stralloc line;
215int match = 1;
216unsigned long linenum = 0;
217
218#define NUMFIELDS 15
219static stralloc f[NUMFIELDS];
220
221static char *d1;
222static char *d2;
225
226char strnum[FMT_ULONG];
227
228void syntaxerror(const char *why)
229{
230 strnum[fmt_dnum(strnum,linenum)] = 0;
231 logmsg(WHO,111,FATAL,B("unable to parse data line: ",strnum,why));
232}
233
234int main()
235{
236 int fddata;
237 int i;
238 int j;
239 int k;
240 unsigned char ch;
241 char ttd[8];
242 char loc[2];
243 char ip4[4];
244 char ip6[16];
245 char type[2];
246 char soa[20];
247 char buf[4];
248 uint32_t ttl, u;
249 unsigned char us, sl, ty;
250 umask(022);
251
252 fddata = open_read("data");
253 if (fddata == -1)
254 logmsg(WHO,111,FATAL,"unable to open data");
255
256 defaultsoa_init(fddata);
257 buffer_init(&b,buffer_unixread,fddata,bspace,sizeof(bspace));
258
259 fdcdb = open_trunc("data.tmp");
260 if (fdcdb == -1) die_datatmp();
261 if (cdb_make_start(&cdb,fdcdb) == -1) die_datatmp();
262
263 while (match) {
264 ++linenum;
265 if (getln(&b,&line,&match,'\n') == -1)
266 logmsg(WHO,111,FATAL,"unable to read line");
267
268 while (line.len) {
269 ch = line.s[line.len - 1];
270 if ((ch != ' ') && (ch != '\t') && (ch != '\n')) break;
271 --line.len;
272 }
273 if (!line.len) continue;
274 if (line.s[0] == '#') continue;
275 if (line.s[0] == '-') continue;
276
277 /* Tokenization of input fields; delimitor: | */
278
279 for (j = 1, i = 0; i < NUMFIELDS; ++i) {
280 if (j >= line.len) {
281 if (!stralloc_copys(&f[i],"")) nomem();
282 }
283 else {
284 k = byte_chr(line.s + j,line.len - j,'|');
285 if (!stralloc_copyb(&f[i],line.s + j,k)) nomem();
286 j += k + 1;
287 }
288 }
289
290 switch (line.s[0]) {
291
292 case '%': /* local extension */
293 locparse(&f[0],loc);
294 if (!stralloc_copyb(&key,"\0%",2)) nomem();
295 if (!stralloc_0(&f[1])) nomem();
296 ipprefix_get(&ipstring,f[1].s);
297 if (ipstring.len > 1)
298 if (!stralloc_catb(&key,ipstring.s,ipstring.len - 1)) nomem();
299 if (cdb_make_add(&cdb,key.s,key.len,loc,2) == -1)
300 die_datatmp();
301 break;
302
303 case 'Z': /* SOA records */
304 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
305
306 if (!stralloc_0(&f[3])) nomem();
307 if (!scan_dnum(f[3].s,&u)) uint32_unpack_big(defaultsoa,&u);
308 uint32_pack_big(soa,u);
309 if (!stralloc_0(&f[4])) nomem();
310 if (!scan_dnum(f[4].s,&u)) uint32_unpack_big(defaultsoa + 4,&u);
311 uint32_pack_big(soa + 4,u);
312 if (!stralloc_0(&f[5])) nomem();
313 if (!scan_dnum(f[5].s,&u)) uint32_unpack_big(defaultsoa + 8,&u);
314 uint32_pack_big(soa + 8,u);
315 if (!stralloc_0(&f[6])) nomem();
316 if (!scan_dnum(f[6].s,&u)) uint32_unpack_big(defaultsoa + 12,&u);
317 uint32_pack_big(soa + 12,u);
318 if (!stralloc_0(&f[7])) nomem();
319 if (!scan_dnum(f[7].s,&u)) uint32_unpack_big(defaultsoa + 16,&u);
320 uint32_pack_big(soa + 16,u);
321
322 if (!stralloc_0(&f[8])) nomem();
323 if (!scan_dnum(f[8].s,&ttl)) ttl = TTL_NEGATIVE;
324 ttdparse(&f[9],ttd);
325 locparse(&f[10],loc);
326
327 rr_start(DNS_T_SOA,ttl,ttd,loc);
328 if (dns_domain_fromdot(&d2,f[1].s,f[1].len) <= 0) nomem();
329 rr_addname(d2);
330 if (dns_domain_fromdot(&d2,f[2].s,f[2].len) <= 0) nomem();
331 rr_addname(d2);
332 rr_add(soa,20);
333 rr_finish(d1);
334 break;
335
336 case '.': case '&': /* NS records */
337 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
338 if (!stralloc_0(&f[3])) nomem();
339 if (!scan_dnum(f[3].s,&ttl)) ttl = TTL_NS;
340 ttdparse(&f[4],ttd);
341 locparse(&f[5],loc);
342
343 if (!stralloc_0(&f[1])) nomem();
344
345 if (byte_chr(f[2].s,f[2].len,'.') >= f[2].len) {
346 if (!stralloc_cats(&f[2],".ns.")) nomem();
347 if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem();
348 }
349 if (dns_domain_fromdot(&d2,f[2].s,f[2].len) <= 0) nomem();
350
351 if (line.s[0] == '.') {
352 rr_start(DNS_T_SOA,ttl ? TTL_NEGATIVE : 0,ttd,loc);
353 rr_addname(d2);
354 rr_add("\12hostmaster",11);
355 rr_addname(d1);
356 rr_add(defaultsoa,20);
357 rr_finish(d1);
358 }
359
360 rr_start(DNS_T_NS,ttl,ttd,loc);
361 rr_addname(d2);
362 rr_finish(d1);
363
364 if (byte_chr(f[1].s,f[1].len,':') < f[1].len) {
365 if (ip6_scan(f[1].s,ip6)) {
366 rr_start(DNS_T_AAAA,ttl,ttd,loc);
367 rr_add(ip6,16);
368 rr_finish(d2);
369 }
370 } else {
371 if (ip4_scan(f[1].s,ip4)) {
372 rr_start(DNS_T_A,ttl,ttd,loc);
373 rr_add(ip4,4);
374 rr_finish(d2);
375 }
376 }
377 break;
378
379 case '+': case '=': /* A records */
380 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
381 if (!stralloc_0(&f[2])) nomem();
382 if (!scan_dnum(f[2].s,&ttl)) ttl = TTL_POSITIVE;
383 ttdparse(&f[3],ttd);
384 locparse(&f[4],loc);
385
386 if (!stralloc_0(&f[1])) nomem();
387
388 if (ip4_scan(f[1].s,ip4)) {
389 rr_start(DNS_T_A,ttl,ttd,loc);
390 rr_add(ip4,4);
391 rr_finish(d1);
392
393 if (line.s[0] == '=') {
395 rr_start(DNS_T_PTR,ttl,ttd,loc);
396 rr_addname(d1);
398 }
399 }
400 break;
401
402 case ':': case '~': /* AAAA records */
403 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
404 if (!stralloc_0(&f[2])) nomem();
405 if (!scan_dnum(f[2].s,&ttl)) ttl = TTL_POSITIVE;
406 ttdparse(&f[3],ttd);
407 locparse(&f[4],loc);
408
409 if (!stralloc_0(&f[1])) nomem();
410
411 if (ip6_scan(f[1].s,ip6)) {
412 rr_start(DNS_T_AAAA,ttl,ttd,loc);
413 rr_add(ip6,16);
414 rr_finish(d1);
415
416 if (line.s[0] == ':') {
418 rr_start(DNS_T_PTR,ttl,ttd,loc);
419 rr_addname(d1);
421 }
422 }
423 break;
424
425 case '@': /* MX Records */
426 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
427 if (!stralloc_0(&f[4])) nomem();
428 if (!scan_dnum(f[4].s,&ttl)) ttl = TTL_POSITIVE;
429 ttdparse(&f[5],ttd);
430 locparse(&f[6],loc);
431
432 if (!stralloc_0(&f[1])) nomem();
433
434 if (byte_chr(f[2].s,f[2].len,'.') >= f[2].len) {
435 if (!stralloc_cats(&f[2],".mx.")) nomem();
436 if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem();
437 }
438 if (dns_domain_fromdot(&d2,f[2].s,f[2].len) <= 0) nomem();
439
440 if (!stralloc_0(&f[3])) nomem();
441 if (!scan_dnum(f[3].s,&u)) u = 0;
442
443 rr_start(DNS_T_MX,ttl,ttd,loc);
444 uint16_pack_big(buf,u);
445 rr_add(buf,2);
446 rr_addname(d2);
447 rr_finish(d1);
448
449 if (byte_chr(f[1].s,f[1].len,':') < f[1].len) {
450 if (ip6_scan(f[1].s,ip6))
451 if (!ip6_isv4mapped(ip6)) {
452 rr_start(DNS_T_AAAA,ttl,ttd,loc);
453 rr_add(ip6,16);
454 rr_finish(d2);
455 }
456 } else
457 if (ip4_scan(f[1].s,ip4)) {
458 rr_start(DNS_T_A,ttl,ttd,loc);
459 rr_add(ip4,4);
460 rr_finish(d2);
461 }
462 break;
463
464 case '^': case 'C': /* Pointer + CName Records */
465 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
466 if (dns_domain_fromdot(&d2,f[1].s,f[1].len) <= 0) nomem();
467 if (!stralloc_0(&f[2])) nomem();
468 if (!scan_dnum(f[2].s,&ttl)) ttl = TTL_POSITIVE;
469 ttdparse(&f[3],ttd);
470 locparse(&f[4],loc);
471
472 if (line.s[0] == 'C')
473 rr_start(DNS_T_CNAME,ttl,ttd,loc);
474 else
475 rr_start(DNS_T_PTR,ttl,ttd,loc);
476 rr_addname(d2);
477 rr_finish(d1);
478 break;
479
480 case '\'': /* TXT Records*/
481 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
482 if (!stralloc_0(&f[2])) nomem();
483 if (!scan_dnum(f[2].s,&ttl)) ttl = TTL_POSITIVE;
484 ttdparse(&f[3],ttd);
485 locparse(&f[4],loc);
486
487 rr_start(DNS_T_TXT,ttl,ttd,loc);
488
489 textparse(&f[1]);
490 i = 0;
491 while (i < f[1].len) {
492 k = f[1].len - i;
493 if (k > TXT_LABLEN) k = TXT_LABLEN;
494 ch = k;
495 rr_add(&ch,1);
496 rr_add(f[1].s + i,k);
497 i += k;
498 }
499 rr_finish(d1);
500 break;
501
502 case 'D': /* DKIM Records*/
503 /* Dfqdn|pubkey|selector|keytype|hash|service|type|ttl|timestamp|lo */
504 /* 0 1 2 3 4 5 6 7 8 9 */
505
506 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem(); // d1
507 if (!stralloc_0(&f[7])) nomem();
508 if (!scan_dnum(f[7].s,&ttl)) ttl = TTL_POSITIVE;
509 ttdparse(&f[8],ttd);
510 locparse(&f[9],loc);
511
512 /* The TXT Rdata stored in f[8], the domain name in f[9] */
513
514 // Basic
515 if (!stralloc_copys(&f[8],"v=DKIM1;")) nomem();
516 // Key tag
517 if (!f[3].len) {
518 if (!stralloc_cats(&f[8],"k=rsa;")) nomem();
519 } else {
520 if (!stralloc_cats(&f[8],"k=")) nomem();
521 if (!stralloc_catb(&f[8],f[3].s,f[3].len)) nomem();
522 if (!stralloc_cats(&f[8],";")) nomem();
523 }
524 // Hash tag
525 if (!f[4].len) {
526 if (!stralloc_cats(&f[8],"h=sha256;")) nomem();
527 } else {
528 if (!stralloc_cats(&f[8],"h=")) nomem();
529 if (!stralloc_catb(&f[8],f[4].s,f[4].len)) nomem();
530 if (!stralloc_cats(&f[8],";")) nomem();
531 }
532 // Service tag
533 if (f[5].len) {
534 if (!stralloc_cats(&f[8],"s=")) nomem();
535 if (!stralloc_catb(&f[8],f[5].s,f[5].len)) nomem();
536 if (!stralloc_cats(&f[8],";")) nomem();
537 }
538 // Type tag
539 if (f[6].len > 0) {
540 if (!stralloc_cats(&f[8],"t=")) nomem();
541 if (!stralloc_catb(&f[8],f[6].s,f[6].len)) nomem();
542 if (!stralloc_cats(&f[8],";")) nomem();
543 }
544 // Public key
545 if (!f[1].len) {
546 syntaxerror(": DKIM public key is required");
547 } else {
548 textparse(&f[1]);
549 if (!stralloc_cats(&f[8],"p=")) nomem();
550 if (!stralloc_catb(&f[8],f[1].s,f[1].len)) nomem();
551 }
552
553 /* The domain name: [selector]._domainkey.fqdn */
554
555 if (f[2].len > 0) {
556 if (!stralloc_copyb(&f[9],f[2].s,f[2].len)) nomem();
557 if (!stralloc_cats(&f[9],".")) nomem();
558 } else {
559 if (!stralloc_cats(&f[9],"default.")) nomem();
560 }
561 if (!stralloc_cats(&f[9],"_domainkey.")) nomem();
562 if (!stralloc_catb(&f[9],f[0].s,f[0].len)) nomem();
563
564 if (dns_domain_fromdot(&d2,f[9].s,f[9].len) <= 0) nomem(); // d2 - new record
565
566 rr_start(DNS_T_TXT,ttl,ttd,loc);
567 i = 0;
568 while (i < f[8].len) {
569 k = f[8].len - i;
570 if (k > TXT_LABLEN) k = TXT_LABLEN;
571 ch = k;
572 rr_add(&ch,1); // write length; new label
573 rr_add(f[8].s + i,k);
574 i += k;
575 }
576 rr_finish(d2);
577 break;
578
579 case '_': /* TLSA Records*/
580 /* _fqdn|u|s|fingerprint|x|port|proto|ttl|timestamp|lo */
581 /* 0 1 2 3 4 5 6 7 8 9 */
582
583 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem(); // d1
584 if (!stralloc_0(&f[7])) nomem();
585 if (!scan_dnum(f[7].s,&ttl)) ttl = TTL_POSITIVE;
586 ttdparse(&f[8],ttd);
587 locparse(&f[9],loc);
588
589 if (!stralloc_0(&f[1])) nomem(); // usage
590 if (!scan_dnum(f[1].s,&us)) us = 003;
591 if (!stralloc_0(&f[2])) nomem(); // selector
592 if (!scan_dnum(f[2].s,&sl)) sl = 001;
593 f[2].len = 0;
594 ty = 000; // type
595 if (f[3].len == 64) ty = 001;
596 if (f[3].len == 128) ty = 002;
597
598 if (f[4].len == 0 && f[5].len == 0 && f[6].len == 0) { // _25._tcp.mx.fqdn
599 if (!stralloc_copys(&f[2],"_25._tcp.mail.")) nomem();
600 if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem();
601 } else if (f[4].s[0] != '_') { // synthesize base domain
602 if (!stralloc_copys(&f[2],"_")) nomem();
603 if (f[5].len > 0) {
604 if (!stralloc_catb(&f[2],f[5].s,f[5].len)) nomem();
605 } else
606 if (!stralloc_cats(&f[2],"25")) nomem();
607 if (!stralloc_cats(&f[2],"._")) nomem();
608 if (f[6].len > 0) {
609 if (!stralloc_catb(&f[2],f[6].s,f[6].len)) nomem();
610 } else
611 if (!stralloc_cats(&f[2],"tcp")) nomem();
612 if (f[4].s[0] != '.')
613 if (!stralloc_cats(&f[2],".")) nomem();
614 if (!stralloc_catb(&f[2],f[4].s,f[4].len)) nomem();
615 if (!stralloc_cats(&f[2],".")) nomem();
616 if (!stralloc_catb(&f[2],f[0].s,f[0].len)) nomem();
617 } else
618 if (!stralloc_copy(&f[2],&f[4])) nomem();
619
620 if (dns_domain_fromdot(&d2,f[2].s,f[2].len) <= 0) nomem(); // d2 - new record
621
622 rr_start(DNS_T_TLSA,ttl,ttd,loc);
623
624 buf[0] = us;
625 rr_add(buf,1);
626 buf[0] = sl;
627 rr_add(buf,1);
628 buf[0] = ty;
629 rr_add(buf,1);
630
631 case_lowerb(f[3].s,f[3].len);
632 hexparse(&f[3]);
633 i = 0;
634 while (i < f[3].len) {
635 k = f[3].len - i;
636 if (k > TXT_LABLEN) k = TXT_LABLEN;
637 ch = k;
638 rr_add(&ch,1); // write length; new label
639 rr_add(f[3].s + i,k);
640 i += k;
641 }
642 rr_finish(d2);
643 break;
644
645 case 'O': /* Any other Records with Octal representation */
646 if (dns_domain_fromdot(&d1,f[0].s,f[0].len) <= 0) nomem();
647 if (!stralloc_0(&f[3])) nomem();
648 if (!scan_dnum(f[3].s,&ttl)) ttl = TTL_POSITIVE;
649 ttdparse(&f[4],ttd);
650 locparse(&f[5],loc);
651
652 if (!stralloc_0(&f[1])) nomem();
653 scan_dnum(f[1].s,&u);
654 uint16_pack_big(type,u);
655 if (byte_equal(type,2,DNS_T_AXFR))
656 syntaxerror(": type AXFR prohibited");
657 if (byte_equal(type,2,"\0\0"))
658 syntaxerror(": type 0 prohibited");
659 if (byte_equal(type,2,DNS_T_SOA))
660 syntaxerror(": type SOA prohibited");
661 if (byte_equal(type,2,DNS_T_NS))
662 syntaxerror(": type NS prohibited");
663 if (byte_equal(type,2,DNS_T_CNAME))
664 syntaxerror(": type CNAME prohibited");
665 if (byte_equal(type,2,DNS_T_PTR))
666 syntaxerror(": type PTR prohibited");
667 if (byte_equal(type,2,DNS_T_MX))
668 syntaxerror(": type MX prohibited");
669
670 txtparse(&f[2]);
671
672 rr_start(type,ttl,ttd,loc);
673 rr_add(f[2].s,f[2].len);
674 rr_finish(d1);
675 break;
676
677 default:
678 syntaxerror(": unrecognized leading character");
679 }
680 }
681
682 if (cdb_make_finish(&cdb) == -1) die_datatmp();
683 if (fsync(fdcdb) == -1) die_datatmp();
684 if (close(fdcdb) == -1) die_datatmp(); /* NFS stupidity */
685 if (rename("data.tmp","data.cdb") == -1)
686 logmsg(WHO,111,FATAL,"unable to move data.tmp to data.cdb");
687
688 _exit(0);
689}
char bspace[256]
Definition auto-str.c:4
buffer b
Definition auto-str.c:5
int fd
Definition axfr-get.c:103
int match
Definition axfr-get.c:127
#define WHO
Definition axfr-get.c:16
int fdcdb
Definition axfrdns.c:108
uint16 len
Definition axfrdns.c:319
char buf[MSGSIZE]
Definition axfrdns.c:318
#define TXT_LABLEN
Definition curve.c:15
#define DNS_NAME4_DOMAIN
Definition dns.h:162
#define DNS_T_A
Definition dns.h:56
#define DNS_T_TLSA
Definition dns.h:80
#define DNS_T_AXFR
Definition dns.h:84
#define DNS_T_TXT
Definition dns.h:63
#define DNS_T_PTR
Definition dns.h:60
#define DNS_T_SOA
Definition dns.h:59
#define DNS_T_NS
Definition dns.h:57
#define DNS_NAME6_DOMAIN
Definition dns.h:175
#define DNS_T_CNAME
Definition dns.h:58
#define DNS_T_AAAA
Definition dns.h:67
#define DNS_T_MX
Definition dns.h:62
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
Definition dns_dfd.c:6
unsigned int dns_domain_length(const char *dn)
Definition dns_domain.c:6
int dns_name4_domain(char name[DNS_NAME4_DOMAIN], const char ip[4])
Definition dns_nd.c:6
int dns_name6_domain(char name[DNS_NAME6_DOMAIN], const char ip[16])
Definition dns_nd.c:28
char ip6[16]
Definition dnsfilter.c:51
char ip4[4]
Definition dnsfilter.c:50
char strnum[FMT_ULONG]
Definition dnsmx.c:22
char type[2]
Definition dnsq.c:56
void owner(int uid, int gid)
struct cdb_make cdb
Definition rbldns-data.c:36
unsigned long linenum
Definition rbldns-data.c:40
void ipprefix_get(stralloc *out, char *s)
void textparse(stralloc *sa)
void die_datatmp(void)
void ttdparse(stralloc *sa, char ttd[8])
void rr_addname(const char *d)
void hexparse(stralloc *sa)
int rename(const char *, const char *)
char d4ptr[DNS_NAME4_DOMAIN]
void locparse(stralloc *sa, char loc[2])
#define TTL_POSITIVE
#define TTL_NEGATIVE
void nomem(void)
#define TTL_NS
char d6ptr[DNS_NAME6_DOMAIN]
void rr_add(const char *buf, unsigned int len)
#define NUMFIELDS
void syntaxerror(const char *why)
void txtparse(stralloc *sa)
void rr_start(const char type[2], unsigned long ttl, const char ttd[8], const char loc[2])
void defaultsoa_init(int fd)
int main()
char defaultsoa[20]
void rr_finish(const char *owner)