17 static int want(
const char *owner,
const char type[2])
31 if (byte_equal(type,2,
x))
33 uint16_unpack_big(
x + 8,&datalen);
42 static struct tai
now;
45 static char data[32767];
47 static unsigned int dpos;
51 static int find(
char *d,
int flagwild)
64 dlen = cdb_datalen(&c);
69 if ((ch ==
'=' + 1) || (ch ==
'*' + 1) || (ch ==
'6' + 1)) {
72 if (byte_diff(recordloc,2,
clientloc))
continue;
74 if (flagwild != (ch ==
'*'))
continue;
76 uint32_unpack_big(ttlstr,&ttl);
78 if (byte_diff(ttd,8,
"\0\0\0\0\0\0\0\0")) {
79 tai_unpack(ttd,&cutoff);
81 if (tai_less(&cutoff,&
now))
continue;
82 tai_sub(&cutoff,&cutoff,&
now);
83 newttl = tai_approx(&cutoff);
84 if (newttl <= 2.0) newttl = 2.0;
85 if (newttl >= 3600.0) newttl = 3600.0;
89 if (!tai_less(&cutoff,&
now))
continue;
95 static int dobytes(
unsigned int len)
98 if (
len > 20)
return 0;
111 static int doit(
char *q,
char qtype[2])
123 int flagauthoritative;
128 int addrnum,addr6num;
129 uint32 addrttl,addr6ttl;
137 flagauthoritative = 0;
139 while ((r = find(control,0))) {
140 if (r == -1)
return 0;
141 if (byte_equal(type,2,
DNS_T_SOA)) flagauthoritative = 1;
142 if (byte_equal(type,2,
DNS_T_NS)) flagns = 1;
145 if (!*control)
return 0;
150 if (!flagauthoritative) {
161 addrnum = addr6num = 0;
162 addrttl = addr6ttl = 0;
164 while ((r = find(wild,wild != q))) {
165 if (r == -1)
return 0;
167 if (flaggavesoa && byte_equal(type,2,
DNS_T_SOA))
continue;
168 if (byte_diff(type,2,qtype) && byte_diff(qtype,2,
DNS_T_ANY) && byte_diff(type,2,
DNS_T_CNAME))
continue;
173 if ((i < addrnum) && (addrnum < 8))
174 byte_copy(addr[addrnum],4,addr[i]);
177 if (addrnum < 1000000) ++addrnum;
184 if ((i < addr6num) && (addr6num < 8))
185 byte_copy(addr6[addr6num],16,addr6[i]);
188 if (addr6num < 1000000) ++addr6num;
195 else if (byte_equal(type,2,
DNS_T_MX)) {
196 if (!dobytes(2))
return 0;
202 if (!dobytes(20))
return 0;
209 for (i = 0; i < addrnum; ++i)
215 for (i = 0; i < addr6num; ++i)
222 if (flagfound)
break;
223 if (wild == control)
break;
236 if (flagauthoritative && (aupos == anpos)) {
238 while ((r = find(control,0))) {
239 if (r == -1)
return 0;
244 if (!dobytes(20))
return 0;
253 while ((r = find(control,0))) {
254 if (r == -1)
return 0;
266 while (bpos < arpos) {
277 while ((r = find(d1,0))) {
278 if (r == -1)
return 0;
279 if (byte_equal(type,2,
DNS_T_A)) {
281 if (!dobytes(4))
return 0;
286 if (!dobytes(16))
return 0;
292 uint16_unpack_big(
x + 8,&u16);
316 fd = open_read(
"data.cdb");
317 if (
fd == -1)
return 0;
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
void doname(stralloc *sa)
int find_client_loc(char loc[2], const char ip[16])
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, char *, unsigned int)
int dns_domain_equal(const char *, const char *)
unsigned int dns_random(unsigned int)
unsigned int dns_packet_skipname(const char *, unsigned int, unsigned int)
unsigned int dns_domain_length(const char *)
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)
void d(const char *home, const char *subdir, int uid, int gid, int mode)
int response_addbytes(const char *buf, unsigned int len)
int response_addname(const char *d)
unsigned int max_response_len
unsigned int response_len
void response_rfinish(int x)
void response_nxdomain(void)
int response_rstart(const char *d, const char type[2], uint32 ttl)
#define RESPONSE_AUTHORITY
#define RESPONSE_ADDITIONAL
int respond(char *q, char qtype[2], char ip[16])