30 logmsg(
WHO,111,FATAL,
"out of memory");
34 logmsg(
WHO,111,FATAL,
"truncated request");
38 logmsg(
WHO,111,FATAL,
"unable to write to network");
42 logmsg(
WHO,111,FATAL,
"unable to read from network");
46 logmsg(
WHO,111,FATAL,
"unable to locate information in data.cdb");
50 logmsg(
WHO,111,FATAL,
"unable to read data.cdb");
54 logmsg(
WHO,111,FATAL,B(
"unable to read data.cdb: ",
"format error"));
101 logmsg(
WHO,111,FATAL,
"disallowed zone transfer request");
148int build(stralloc *sa,
char *q,
int flagsoa,
char id[2])
150 unsigned int rdatapos;
180 if (!stralloc_copyb(sa,
id,2))
nomem();
181 if (!stralloc_catb(sa,
"\204\000\0\0\0\1\0\0\0\0",10))
nomem();
184 if ((misc[0] ==
'=' + 1) || (misc[0] ==
'*' + 1)) {
187 if (byte_diff(recordloc,2,
clientloc))
return 0;
189 if (misc[0] ==
'*') {
190 if (flagsoa)
return 0;
191 if (!stralloc_catb(sa,
"\1*",2))
nomem();
198 if (byte_diff(ttd,8,
"\0\0\0\0\0\0\0\0")) {
199 tai_unpack(ttd,&cutoff);
200 if (byte_equal(ttl,4,
"\0\0\0\0")) {
201 if (tai_less(&cutoff,&
now))
return 0;
202 uint32_pack_big(ttl,2);
205 if (!tai_less(&cutoff,&
now))
return 0;
209 if (!stralloc_catb(sa,ttl,4))
nomem();
210 if (!stralloc_catb(sa,
"\0\0",2))
nomem();
217 if (!stralloc_catb(sa,misc,20))
nomem();
224 if (!stralloc_catb(sa,misc,2))
nomem();
231 uint16_pack_big(sa->s + rdatapos - 2,sa->len - rdatapos);
238static stralloc message;
258 r = cdb_findnext(&c,zone,
zonelen);
261 dlen = cdb_datalen(&c);
264 if (
build(&soa,zone,1,
id))
break;
268 print(soa.s,soa.len);
275 uint32_unpack(num,&eod);
276 while (pos < 2048) {
get_cdb(num,4); pos += 4; }
281 uint32_unpack(num,&klen);
283 uint32_unpack(num,&
dlen);
294 if ((klen > 1) && (key[0] == 0))
continue;
298 if (!
build(&message,q,0,
id))
continue;
299 print(message.s,message.len);
302 print(soa.s,soa.len);
310 r = timeoutread(60,0,
buf,
len);
311 if (r == 0) _exit(0);
321static char seed[128];
334 axfr = env_get(
"AXFR");
336 x = env_get(
"TCP6REMOTEIP");
337 if (!
x)
x = env_get(
"TCPREMOTEIP");
338 if (
x && ip6_scan(
x,
ip))
343 x = env_get(
"TCP6REMOTEPORT");
345 x = env_get(
"TCPREMOTEPORT");
352 if (
len >
MSGSIZE) logmsg(
WHO,111,FATAL,
"excessively large request");
356 if (header[2] & 254) logmsg(
WHO,111,FATAL,
"bogus query");
357 if (header[4] || (header[5] != 1)) logmsg(
WHO,111,FATAL,
"bogus query");
365 logmsg(
WHO,111,FATAL,
"bogus query: bad class");
371 fdcdb = open_read(
"data.cdb");
382 if (!(header[2] & 1))
response[2] &= ~1;
void dns_copy(char *buf, unsigned int len)
int respond(char *, char *, char *)
void get_cdb(char *buf, unsigned int len)
ssize_t safewrite(int fd, char *buf, unsigned int len)
int build(stralloc *sa, char *q, int flagsoa, char id[2])
void print(char *buf, unsigned int len)
void doname(stralloc *sa)
int find_clientloc(char clientloc[2], const char ip[16])
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
int dns_domain_equal(const char *dn1, const char *dn2)
unsigned int dns_domain_length(const char *dn)
int dns_domain_suffix(const char *big, const char *little)
unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
void dns_random_init(const char data[128])
void droproot(const char *fatal)
void d(const char *home, const char *subdir, int uid, int gid, int mode)
void qlog(const char *, uint16, const char *, const char *, const char *, const char *)
void response_id(const char *)
unsigned int response_len
int response_query(const char *, const char *, const char *)