33 logmsg(
WHO,111,FATAL,
"out of memory");
37 logmsg(
WHO,111,FATAL,
"truncated request");
41 logmsg(
WHO,111,FATAL,
"unable to write to network");
45 logmsg(
WHO,111,FATAL,
"unable to read from network");
49 logmsg(
WHO,111,FATAL,
"unable to locate information in data.cdb");
53 logmsg(
WHO,111,FATAL,
"unable to read data.cdb");
57 logmsg(
WHO,111,FATAL,B(
"unable to read data.cdb: ",
"format error"));
104 logmsg(
WHO,111,FATAL,
"disallowed zone transfer request");
151int build(stralloc *sa,
char *q,
int flagsoa,
char id[2])
153 unsigned int rdatapos;
183 if (!stralloc_copyb(sa,
id,2))
nomem();
184 if (!stralloc_catb(sa,
"\204\000\0\0\0\1\0\0\0\0",10))
nomem();
187 if ((misc[0] ==
'=' + 1) || (misc[0] ==
'*' + 1)) {
190 if (byte_diff(recordloc,2,
clientloc))
return 0;
192 if (misc[0] ==
'*') {
193 if (flagsoa)
return 0;
194 if (!stralloc_catb(sa,
"\1*",2))
nomem();
201 if (byte_diff(ttd,8,
"\0\0\0\0\0\0\0\0")) {
202 tai_unpack(ttd,&cutoff);
203 if (byte_equal(ttl,4,
"\0\0\0\0")) {
204 if (tai_less(&cutoff,&
now))
return 0;
205 uint32_pack_big(ttl,2);
208 if (!tai_less(&cutoff,&
now))
return 0;
212 if (!stralloc_catb(sa,ttl,4))
nomem();
213 if (!stralloc_catb(sa,
"\0\0",2))
nomem();
220 if (!stralloc_catb(sa,misc,20))
nomem();
227 if (!stralloc_catb(sa,misc,2))
nomem();
234 uint16_pack_big(sa->s + rdatapos - 2,sa->len - rdatapos);
241static stralloc message;
261 r = cdb_findnext(&c,zone,
zonelen);
264 dlen = cdb_datalen(&c);
267 if (
build(&soa,zone,1,
id))
break;
271 print(soa.s,soa.len);
278 uint32_unpack(num,&eod);
279 while (pos < 2048) {
get_cdb(num,4); pos += 4; }
284 uint32_unpack(num,&klen);
286 uint32_unpack(num,&
dlen);
297 if ((klen > 1) && (key[0] == 0))
continue;
301 if (!
build(&message,q,0,
id))
continue;
302 print(message.s,message.len);
305 print(soa.s,soa.len);
313 r = timeoutread(60,0,
buf,
len);
314 if (r == 0) _exit(0);
324static char seed[128];
337 axfr = env_get(
"AXFR");
339 x = env_get(
"TCP6REMOTEIP");
340 if (!
x)
x = env_get(
"TCPREMOTEIP");
341 if (
x && ip6_scan(
x,
ip))
346 x = env_get(
"TCP6REMOTEPORT");
348 x = env_get(
"TCPREMOTEPORT");
355 if (
len >
MSGSIZE) logmsg(
WHO,111,FATAL,
"excessively large request");
359 if (header[2] & 254) logmsg(
WHO,111,FATAL,
"bogus query");
360 if (header[4] || (header[5] != 1)) logmsg(
WHO,111,FATAL,
"bogus query");
368 logmsg(
WHO,111,FATAL,
"bogus query: bad class");
374 fdcdb = open_read(
"data.cdb");
385 if (!(header[2] & 1))
response[2] &= ~1;
ssize_t safewrite(int fd, char *buf, size_t len)
void dns_copy(char *buf, unsigned int len)
int respond(char *, char *, char *)
void get_cdb(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 *server)
void d(const char *home, const char *subdir, int uid, int gid, int mode)
void qlog(const char[16], uint16, const char[2], const char *, const char[2], const char *)
void response_id(const char[2])
unsigned int response_len
int response_query(const char *, const char[2], const char[2])