2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-04 16:45:24 +00:00

Improved formatting of #ifdef DEBUG messages (left out \n's when puts calls

were changed to fputs to stderr).
Fix memory leak when doing axfr's.
Improvements to host program; most options and types fully supported.
Add (currently non-functional) -C option to host to check all SOA's
on authorative servers.  (Will require some notable changes to dighost.c
to make this a functional option.)

Issues stil needing resolution:
	IPv6 queries are not currently sent.
	Memory leak on ^C while waiting for UDP recv or TCP connect.
	A few more dig options need supporting.
	Support IXFR under dig (and maybe host).
	Support signatures (TSIG) under dig (and maybe host).
This commit is contained in:
Michael Sawyer
2000-04-27 23:20:29 +00:00
parent 140d926224
commit 1d2f2d7c9a
3 changed files with 125 additions and 48 deletions

View File

@@ -126,14 +126,14 @@ check_next_lookup(dig_lookup_t *lookup) {
isc_boolean_t still_working=ISC_FALSE; isc_boolean_t still_working=ISC_FALSE;
#ifdef DEBUG #ifdef DEBUG
fputs("In check_next_lookup",stderr); fputs("In check_next_lookup\n",stderr);
#endif #endif
for (query = ISC_LIST_HEAD(lookup->q); for (query = ISC_LIST_HEAD(lookup->q);
query != NULL; query != NULL;
query = ISC_LIST_NEXT(query, link)) { query = ISC_LIST_NEXT(query, link)) {
if (query->working) { if (query->working) {
#ifdef DEBUG #ifdef DEBUG
fputs("Still have a worker.",stderr); fputs("Still have a worker.\n",stderr);
#endif #endif
still_working=ISC_TRUE; still_working=ISC_TRUE;
} }
@@ -144,7 +144,7 @@ check_next_lookup(dig_lookup_t *lookup) {
next = ISC_LIST_NEXT(lookup, link); next = ISC_LIST_NEXT(lookup, link);
if (next == NULL) { if (next == NULL) {
#ifdef DEBUG #ifdef DEBUG
fputs("Shutting Down.",stderr); fputs("Shutting Down.\n",stderr);
#endif #endif
isc_app_shutdown(); isc_app_shutdown();
return; return;

View File

@@ -15,8 +15,6 @@
* SOFTWARE. * SOFTWARE.
*/ */
#define MEMDEBUG
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
@@ -238,7 +236,6 @@ setup_libs(void) {
result = isc_socketmgr_create (mctx, &socketmgr); result = isc_socketmgr_create (mctx, &socketmgr);
check_result(result, "isc_socketmgr_create"); check_result(result, "isc_socketmgr_create");
isc_buffer_init(&b, ".", 1); isc_buffer_init(&b, ".", 1);
isc_buffer_add(&b, 1); isc_buffer_add(&b, 1);
dns_name_init(&rootorg, NULL); dns_name_init(&rootorg, NULL);
@@ -377,7 +374,7 @@ cancel_lookup(dig_lookup_t *lookup) {
dig_query_t *query; dig_query_t *query;
#ifdef DEBUG #ifdef DEBUG
fputs("Cancelling all queries", stderr); fputs("Cancelling all queries\n", stderr);
#endif #endif
if (!lookup->pending) if (!lookup->pending)
return; return;
@@ -405,6 +402,9 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE); REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
#ifdef DEBUG
fputs ("Buffer Allocate connect_timeout\n",stderr);
#endif
result = isc_buffer_allocate(mctx, &b, 256); result = isc_buffer_allocate(mctx, &b, 256);
check_result(result, "isc_buffer_allocate"); check_result(result, "isc_buffer_allocate");
for (q = ISC_LIST_HEAD(lookup->q); for (q = ISC_LIST_HEAD(lookup->q);
@@ -442,7 +442,7 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) {
UNUSED(task); UNUSED(task);
#ifdef DEBUG #ifdef DEBUG
fputs("In tcp_length_done", stderr); fputs("In tcp_length_done\n", stderr);
#endif #endif
REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE); REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
sevent = (isc_socketevent_t *)event; sevent = (isc_socketevent_t *)event;
@@ -457,6 +457,9 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) {
return; return;
} }
if (sevent->result != ISC_R_SUCCESS) { if (sevent->result != ISC_R_SUCCESS) {
#ifdef DEBUG
fputs ("Buffer Allocate connect_timeout\n",stderr);
#endif
result = isc_buffer_allocate(mctx, &b, 256); result = isc_buffer_allocate(mctx, &b, 256);
check_result(result, "isc_buffer_allocate"); check_result(result, "isc_buffer_allocate");
result = isc_sockaddr_totext(&query->sockaddr, b); result = isc_sockaddr_totext(&query->sockaddr, b);
@@ -500,7 +503,8 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
if (!query->lookup->pending) { if (!query->lookup->pending) {
#ifdef DEBUG #ifdef DEBUG
fputs("Ignoring launch_next_query because !pending.", stderr); fputs("Ignoring launch_next_query because !pending.\n",
stderr);
#endif #endif
isc_socket_detach(&query->sock); isc_socket_detach(&query->sock);
query->working = ISC_FALSE; query->working = ISC_FALSE;
@@ -523,7 +527,7 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
check_result(result, "isc_socket_recvv"); check_result(result, "isc_socket_recvv");
sendcount++; sendcount++;
#ifdef DEBUG #ifdef DEBUG
fputs("Sending a request.", stderr); fputs("Sending a request.\n", stderr);
#endif #endif
result = isc_socket_sendv(query->sock, &query->sendlist, task, result = isc_socket_sendv(query->sock, &query->sendlist, task,
send_done, query); send_done, query);
@@ -552,9 +556,12 @@ connect_done(isc_task_t *task, isc_event_t *event) {
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
#ifdef DEBUG #ifdef DEBUG
fputs("In connect_done.", stderr); fputs("In connect_done.\n", stderr);
#endif #endif
if (sevent->result != ISC_R_SUCCESS) { if (sevent->result != ISC_R_SUCCESS) {
#ifdef DEBUG
fputs ("Buffer Allocate connect_timeout\n",stderr);
#endif
result = isc_buffer_allocate(mctx, &b, 256); result = isc_buffer_allocate(mctx, &b, 256);
check_result(result, "isc_buffer_allocate"); check_result(result, "isc_buffer_allocate");
result = isc_sockaddr_totext(&query->sockaddr, b); result = isc_sockaddr_totext(&query->sockaddr, b);
@@ -584,7 +591,7 @@ msg_contains_soa(dns_message_t *msg, dig_query_t *query) {
0, &name, NULL); 0, &name, NULL);
if (result == ISC_R_SUCCESS) { if (result == ISC_R_SUCCESS) {
#ifdef DEBUG #ifdef DEBUG
fputs("Found SOA", stderr); fputs("Found SOA\n", stderr);
#endif #endif
return (ISC_TRUE); return (ISC_TRUE);
} else { } else {
@@ -625,7 +632,13 @@ recv_done(isc_task_t *task, isc_event_t *event) {
#endif #endif
query->working = ISC_FALSE; query->working = ISC_FALSE;
query->waiting_connect = ISC_FALSE; query->waiting_connect = ISC_FALSE;
#ifdef DEBUG
fputs ("Starting the cancel\n",stderr);
#endif
cancel_lookup(query->lookup); cancel_lookup(query->lookup);
#ifdef DEBUG
fputs ("Starting the check\n",stderr);
#endif
check_next_lookup(query->lookup); check_next_lookup(query->lookup);
isc_event_free(&event); isc_event_free(&event);
return; return;
@@ -652,7 +665,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
} }
#ifdef DEBUG #ifdef DEBUG
if (query->lookup->pending) if (query->lookup->pending)
fputs("Still pending.", stderr); fputs("Still pending.\n", stderr);
#endif #endif
if (query->lookup->doing_xfr) { if (query->lookup->doing_xfr) {
if (!query->first_soa_rcvd) { if (!query->first_soa_rcvd) {
@@ -660,8 +673,10 @@ recv_done(isc_task_t *task, isc_event_t *event) {
puts("; Transfer failed. " puts("; Transfer failed. "
"Didn't start with SOA answer."); "Didn't start with SOA answer.");
query->working = ISC_FALSE; query->working = ISC_FALSE;
cancel_lookup(query->lookup);
check_next_lookup (query->lookup); check_next_lookup (query->lookup);
isc_event_free (&event); isc_event_free (&event);
dns_message_destroy (&msg);
return; return;
} }
else { else {
@@ -675,6 +690,7 @@ recv_done(isc_task_t *task, isc_event_t *event) {
query->working = ISC_FALSE; query->working = ISC_FALSE;
check_next_lookup(query->lookup); check_next_lookup(query->lookup);
isc_event_free(&event); isc_event_free(&event);
dns_message_destroy (&msg);
return; return;
} }
else { else {
@@ -742,7 +758,7 @@ do_lookup_tcp(dig_lookup_t *lookup) {
isc_result_t result; isc_result_t result;
#ifdef DEBUG #ifdef DEBUG
fputs("Starting a TCP lookup", stderr); fputs("Starting a TCP lookup\n", stderr);
#endif #endif
lookup->pending = ISC_TRUE; lookup->pending = ISC_TRUE;
isc_interval_set(&lookup->interval, timeout, 0); isc_interval_set(&lookup->interval, timeout, 0);
@@ -774,7 +790,7 @@ do_lookup_udp(dig_lookup_t *lookup) {
isc_result_t result; isc_result_t result;
#ifdef DEBUG #ifdef DEBUG
fputs("Starting a UDP lookup.", stderr); fputs("Starting a UDP lookup.\n", stderr);
#endif #endif
lookup->pending = ISC_TRUE; lookup->pending = ISC_TRUE;
isc_interval_set(&lookup->interval, timeout, 0); isc_interval_set(&lookup->interval, timeout, 0);

View File

@@ -77,7 +77,8 @@ extern isc_buffer_t rootbuf;
extern int sendcount; extern int sendcount;
isc_boolean_t short_form=ISC_TRUE, isc_boolean_t short_form=ISC_TRUE,
filter=ISC_FALSE; filter=ISC_FALSE,
showallsoa=ISC_FALSE;
static char *opcodetext[] = { static char *opcodetext[] = {
"QUERY", "QUERY",
@@ -118,6 +119,50 @@ static char *rcodetext[] = {
"BADVERS" "BADVERS"
}; };
static char *rtypetext[] = {
"zero", /* 0 */
"has address", /* 1 */
"name server", /* 2 */
"MD", /* 3 */
"MF", /* 4 */
"is an alias for", /* 5 */
"start of authority", /* 6 */
"MB", /* 7 */
"MG", /* 8 */
"MR", /* 9 */
"NULL", /* 10 */
"has well known services", /* 11 */
"domain name pointer", /* 12 */
"host information", /* 13 */
"MINFO", /* 14 */
"mail is handled by", /* 15 */
"text", /* 16 */
"RP", /* 17 */
"AFSDB", /* 18 */
"x25 address", /* 19 */
"isdn address", /* 20 */
"RT" /* 21 */
"NSAP", /* 22 */
"NSAP_PTR", /* 23 */
"has signature", /* 24 */
"has key", /* 25 */
"PX", /* 26 */
"GPOS", /* 27 */
"has AAAA address", /* 28 */
"LOC", /* 29 */
"has next record", /* 30 */
"has 31 record", /* 31 */
"has 32 record", /* 32 */
"SRV", /* 33 */
"has 34 record", /* 34 */
"NAPTR", /* 35 */
"KX", /* 36 */
"CERT", /* 37 */
"has v6 address", /* 38 */
"DNAME", /* 39 */
"has 40 record", /* 40 */
"has optional information"}; /* 41 */
void void
check_next_lookup (dig_lookup_t *lookup) { check_next_lookup (dig_lookup_t *lookup) {
dig_lookup_t *next; dig_lookup_t *next;
@@ -165,15 +210,23 @@ show_usage() {
} }
static void static void
say_message(char *host, char *msg, dns_rdata_t *rdata, isc_buffer_t *target) { say_message(dns_name_t *name, char *msg, dns_rdata_t *rdata) {
isc_region_t r; isc_buffer_t *b, *b2;
isc_region_t r, r2;
isc_result_t result; isc_result_t result;
result = dns_rdata_totext( rdata, NULL, target); isc_buffer_allocate(mctx, &b, BUFSIZE);
isc_buffer_allocate(mctx, &b2, BUFSIZE);
result = dns_name_totext(name, ISC_TRUE, b);
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
result = dns_rdata_totext(rdata, NULL, b2);
check_result(result, "dns_rdata_totext"); check_result(result, "dns_rdata_totext");
isc_buffer_usedregion(target, &r); isc_buffer_usedregion(b2, &r2);
printf ( "%s %s %.*s\n", host, msg, (int)r.length, printf ( "%.*s %s %.*s\n", (int)r.length, (char *)r.base,
(char *)r.base); msg, (int)r2.length, (char *)r2.base);
isc_buffer_free(&b);
isc_buffer_free(&b2);
} }
@@ -191,6 +244,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
char t[4096]; char t[4096];
isc_boolean_t first; isc_boolean_t first;
isc_boolean_t no_rdata; isc_boolean_t no_rdata;
char *rtt;
if (sectionid == DNS_SECTION_QUESTION) if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE; no_rdata = ISC_TRUE;
@@ -237,24 +291,19 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
loopresult = dns_rdataset_first(rdataset); loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) { while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata); dns_rdataset_current(rdataset, &rdata);
if (rdata.type == dns_rdatatype_a) { if (rdata.type <= 41)
say_message ("Something", rtt=rtypetext[rdata.type];
"has address", else if (rdata.type == 103)
&rdata, rtt="unspecified data";
&target); else if (rdata.type == 249)
} else if rtt="key";
(rdata.type == dns_rdatatype_mx) { else if (rdata.type == 250)
say_message ("Something", rtt="signature";
"mail server", else
&rdata, rtt="unknown";
&target); say_message(print_name,
} else if rtypetext[rdata.type],
(rdata.type == dns_rdatatype_ns) { &rdata);
say_message ("Something",
"name server",
&rdata,
&target);
}
loopresult = dns_rdataset_next( loopresult = dns_rdataset_next(
rdataset); rdataset);
} }
@@ -311,6 +360,11 @@ printmessage(dns_message_t *msg, isc_boolean_t headers) {
dns_name_t *tsigname; dns_name_t *tsigname;
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
if (msg->rcode != 0) {
printf ("Host not found: %d(%s)\n",
msg->rcode, rcodetext[msg->rcode]);
return (ISC_R_SUCCESS);
}
if (!short_form) { if (!short_form) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n", printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
opcodetext[msg->opcode], rcodetext[msg->rcode], opcodetext[msg->opcode], rcodetext[msg->rcode],
@@ -413,11 +467,12 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
char hostname[MXNAME]; char hostname[MXNAME];
char servname[MXNAME]; char servname[MXNAME];
char querytype[32]="a"; char querytype[32]="a";
char queryclass[32]="in";
dig_server_t *srv; dig_server_t *srv;
dig_lookup_t *lookup; dig_lookup_t *lookup;
int c; int c;
while ((c = isc_commandline_parse(argc, argv,"lvwrdt:a")) != EOF) { while ((c = isc_commandline_parse(argc, argv,"lvwrdt:aC")) != EOF) {
switch (c) { switch (c) {
case 'l': case 'l':
tcp_mode = ISC_TRUE; tcp_mode = ISC_TRUE;
@@ -435,6 +490,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
case 't': case 't':
strncpy (querytype, isc_commandline_argument, 32); strncpy (querytype, isc_commandline_argument, 32);
break; break;
case 'c':
strncpy (queryclass, isc_commandline_argument, 32);
break;
case 'a': case 'a':
strcpy (querytype, "any"); strcpy (querytype, "any");
short_form = ISC_FALSE; short_form = ISC_FALSE;
@@ -444,6 +502,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
thing! */ thing! */
timeout = 32767; timeout = 32767;
break; break;
case 'C':
showallsoa = ISC_TRUE;
break;
} }
} }
if (isc_commandline_index >= argc) { if (isc_commandline_index >= argc) {
@@ -469,7 +530,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->pending = ISC_FALSE; lookup->pending = ISC_FALSE;
strncpy (lookup->textname, hostname, MXNAME); strncpy (lookup->textname, hostname, MXNAME);
strncpy (lookup->rttext, querytype, 32); strncpy (lookup->rttext, querytype, 32);
strcpy (lookup->rctext,"in"); strncpy (lookup->rctext,queryclass, 32);
lookup->namespace[0]=0; lookup->namespace[0]=0;
lookup->sendspace[0]=0; lookup->sendspace[0]=0;
lookup->sendmsg=NULL; lookup->sendmsg=NULL;