31 logmsg(
WHO,111,FATAL,
"out of memory");
35 logmsg(
WHO,111,FATAL,
"truncated request");
39 logmsg(
WHO,111,FATAL,
"unable to write to network");
43 logmsg(
WHO,111,FATAL,
"unable to read from network");
47 logmsg(
WHO,111,FATAL,
"unable to locate information in data.cdb");
51 logmsg(
WHO,111,FATAL,
"unable to read data.cdb");
55 logmsg(
WHO,111,FATAL,B(
"unable to read data.cdb: ",
"format error"));
102 logmsg(
WHO,111,FATAL,
"disallowed zone transfer request");
149 int build(stralloc *sa,
char *q,
int flagsoa,
char id[2])
151 unsigned int rdatapos;
164 if (!stralloc_copyb(sa,
id,2))
nomem();
165 if (!stralloc_catb(sa,
"\204\000\0\0\0\1\0\0\0\0",10))
nomem();
167 if ((misc[0] ==
'=' + 1) || (misc[0] ==
'*' + 1)) {
170 if (byte_diff(recordloc,2,
clientloc))
return 0;
172 if (misc[0] ==
'*') {
173 if (flagsoa)
return 0;
174 if (!stralloc_catb(sa,
"\1*",2))
nomem();
181 if (byte_diff(ttd,8,
"\0\0\0\0\0\0\0\0")) {
182 tai_unpack(ttd,&cutoff);
183 if (byte_equal(ttl,4,
"\0\0\0\0")) {
184 if (tai_less(&cutoff,&
now))
return 0;
185 uint32_pack_big(ttl,2);
188 if (!tai_less(&cutoff,&
now))
return 0;
192 if (!stralloc_catb(sa,ttl,4))
nomem();
193 if (!stralloc_catb(sa,
"\0\0",2))
nomem();
200 if (!stralloc_catb(sa,misc,20))
nomem();
207 if (!stralloc_catb(sa,misc,2))
nomem();
214 uint16_pack_big(sa->s + rdatapos - 2,sa->len - rdatapos);
221 static stralloc message;
241 r = cdb_findnext(&c,zone,
zonelen);
244 dlen = cdb_datalen(&c);
247 if (
build(&soa,zone,1,
id))
break;
251 print(soa.s,soa.len);
257 get(num,4); pos += 4;
258 uint32_unpack(num,&eod);
259 while (pos < 2048) {
get(num,4); pos += 4; }
263 get(num,4); pos += 4;
264 uint32_unpack(num,&klen);
265 get(num,4); pos += 4;
266 uint32_unpack(num,&
dlen);
277 if ((klen > 1) && (key[0] == 0))
continue;
281 if (!
build(&message,q,0,
id))
continue;
282 print(message.s,message.len);
285 print(soa.s,soa.len);
293 r = timeoutread(60,0,
buf,
len);
294 if (r == 0) _exit(0);
304 static char seed[128];
317 axfr = env_get(
"AXFR");
319 x = env_get(
"TCP6REMOTEIP");
320 if (!
x)
x = env_get(
"TCPREMOTEIP");
321 if (
x && ip6_scan(
x,
ip))
326 x = env_get(
"TCP6REMOTEPORT");
328 x = env_get(
"TCPREMOTEPORT");
335 if (
len >
MSGSIZE) logmsg(
WHO,111,FATAL,
"excessively large request");
339 if (header[2] & 254) logmsg(
WHO,111,FATAL,
"bogus query");
340 if (header[4] || (header[5] != 1)) logmsg(
WHO,111,FATAL,
"bogus query");
348 logmsg(
WHO,111,FATAL,
"bogus query: bad class");
354 fdcdb = open_read(
"data.cdb");
365 if (!(header[2] & 1))
response[2] &= ~1;
void get(char *buf, unsigned int len)
void netread(char *buf, unsigned int len)
int respond(char *, char *, char *)
int 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 copy(char *buf, unsigned int len)
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 *)
int dns_domain_fromdot(char **, const char *, unsigned int)
int dns_domain_suffix(const char *, const char *)
unsigned int dns_domain_length(const char *)
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)
void dns_random_init(const char *)
void droproot(const char *fatal)
void d(const char *home, const char *subdir, int uid, int gid, int mode)
void qlog(const char ip[16], uint16 port, const char id[2], const char *q, const char qtype[2], const char *result)
void response_id(const char id[2])
unsigned int response_len
int response_query(const char *q, const char qtype[2], const char qclass[2])