26static char data[100 + IP6_FMT];
28static int doit(
char *q,
char qtype[2])
42 struct uint128_t ipnum6;
46 stralloc ipstring = {0};
49 flaga = byte_equal(qtype,2,
DNS_T_A);
52 if (byte_equal(qtype,2,
DNS_T_ANY)) flaga = flaga4 = flagtxt = 1;
53 if (!(flaga || flaga4) && !flagtxt)
goto REFUSE;
55 if (flaga || flagtxt) {
58 if (r != 4)
goto REFUSE;
59 uint32_unpack(reverseip4,&ipnum4);
60 uint32_pack_big(
ip4,ipnum4);
61 if (ip4_bytestring(&ipstring,
ip4,32) <= 0)
return 0;
63 for (i = 32; i > 0; --i) {
64 if (!stralloc_copys(&
tmp,
""))
return 0;
65 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
66 r = cdb_find(&c,
tmp.s,i);
67 if (r == -1)
return 0;
75 if (flaga4 || flagtxt) {
77 if (
dd6(q,
base,reverseip6) != 16)
goto REFUSE;
79 uint128_unpack(reverseip6,&ipnum6);
80 uint128_pack_big(
ip6,ipnum6);
81 if (ip6_bytestring(&ipstring,
ip6,128) <= 0)
return 0;
82 if (!stralloc_copys(&
tmp,
"^"))
return 0;
83 if (!stralloc_catb(&
tmp,ipstring.s,128))
return 0;
84 r = cdb_find(&c,
tmp.s,129);
87 uint64_unpack(reverseip6 + 8,&ipnum5);
88 uint64_pack_big(ip5,ipnum5);
89 if (ip6_bytestring(&ipstring,ip5,64) <= 0)
return 0;
91 for (i = 64; i > 0; --i) {
92 if (!stralloc_copys(&
tmp,
"^"))
return 0;
93 if (!stralloc_catb(&
tmp,ipstring.s,i))
return 0;
94 r = cdb_find(&c,
tmp.s,i);
95 if (r == -1)
return 0;
103 r = cdb_find(&c,
"",0);
104 if (r == -1)
return 0;
105 if (r && ((
dlen = cdb_datalen(&c)) >= 4)) {
107 if (cdb_read(&c,
data,
dlen,cdb_datapos(&c)) == -1)
return 0;
111 byte_copy(
data,
dlen,
"\177\0\0\2Listed $");
155 fd = open_read(
"data.cdb");
156 if (
fd == -1)
return 0;
158 result =
doit(q,qtype);
172 logmsg(
WHO,111,ERROR,
"$BASE not set");
174 logmsg(
WHO,111,FATAL,
"unable to parse $BASE");
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
int dd6(const char *q, const char *base, char ip[16])
int dd4(const char *q, const char *base, char ip[4])
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
int respond(char *q, char qtype[2], char ip[16])
int response_rstart(const char *, const char[2], uint32)
void response_rfinish(int)
int response_addbytes(const char *, unsigned int)
void response_nxdomain(void)