2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Move recursive flag into lookup structure.

Fix bug in batch processing in host.
Add fixed origin code.
This commit is contained in:
Michael Sawyer
2000-05-03 20:27:13 +00:00
parent 7a9b47e4d0
commit e69ccf6d54
4 changed files with 105 additions and 23 deletions

View File

@@ -60,7 +60,8 @@ extern int h_errno;
extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list;
extern isc_boolean_t tcp_mode, recurse, have_ipv6, show_details;
extern isc_boolean_t tcp_mode, have_ipv6, show_details,
usesearch;
extern in_port_t port;
extern unsigned int timeout;
extern isc_mem_t *mctx;
@@ -75,6 +76,7 @@ extern isc_buffer_t rootbuf;
extern int sendcount;
extern int ndots;
extern int tries;
extern char fixeddomain[MXNAME];
#ifdef TWIDDLE
extern isc_boolean_t twiddle;
#endif
@@ -83,7 +85,7 @@ isc_boolean_t short_form = ISC_FALSE;
isc_boolean_t ns_search_only = ISC_FALSE;
isc_boolean_t comments = ISC_TRUE, section_question = ISC_TRUE,
section_answer = ISC_TRUE, section_authority = ISC_TRUE,
section_additional = ISC_TRUE;
section_additional = ISC_TRUE, recurse = ISC_TRUE;
static char *opcodetext[] = {
"QUERY",
@@ -136,11 +138,16 @@ show_usage() {
" -x dot-notation (shortcut for in-addr lookups)\n"
" -f filename (batch mode)\n"
" -p port (specify port number)\n"
" -t type (specify query type)\n"
" -c class (specify query class)\n"
" d-opt is of the form +keyword[=value], where keyword is:\n"
" +[no]vc (TCP mode)\n"
" +time=### (Set query timeout) [30]\n"
" +tries=### (Set number of UDP attempts) [2]\n"
" +[no]rec (Recursive mode)\n"
" +[no]tcp (TCP mode, alternate syntax)\n"
" +time=### (Set query timeout) [5]\n"
" +tries=### (Set number of UDP attempts) [3]\n"
" +domain=### (Set default domainname)\n"
" +[no]search (Set whether to use searchlist)\n"
" +[no]recursive (Recursive mode)\n"
" +[no]details (Show details of all requests)\n"
" +[no]nssearch (Search for info on all authorative\n"
" nameservers for the domain.)\n"
@@ -453,6 +460,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
int adrs[4];
for (argc--, argv++; argc > 0; argc--, argv++) {
debug ("Main parsing %s", argv[0]);
if ((strncmp(argv[0],"@",1) == 0)
&& (!is_batchfile)) {
srv=isc_mem_allocate(mctx, sizeof(struct dig_server));
@@ -466,6 +474,18 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else if ((strcmp(argv[0],"+novc") == 0)
&& (!is_batchfile)) {
tcp_mode = ISC_FALSE;
} else if ((strcmp(argv[0],"+tcp") == 0)
&& (!is_batchfile)) {
tcp_mode = ISC_TRUE;
} else if ((strcmp(argv[0],"+notcp") == 0)
&& (!is_batchfile)) {
tcp_mode = ISC_FALSE;
} else if (strncmp(argv[0],"+domain=",8) == 0) {
strncpy (fixeddomain, &argv[0][8], MXNAME);
} else if (strncmp(argv[0],"+sea",4) == 0) {
usesearch = ISC_TRUE;
} else if (strncmp(argv[0],"+nosea",6) == 0) {
usesearch = ISC_FALSE;
} else if (strncmp(argv[0],"+time=",6) == 0) {
timeout = atoi(&argv[0][6]);
if (timeout <= 0)
@@ -514,6 +534,30 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else if (strncmp(argv[0],"+twiddle",6) == 0) {
twiddle = ISC_TRUE;
#endif
} else if (strncmp(argv[0],"-c",2) == 0) {
if (have_host) {
if (argv[0][2]!=0) {
strncpy(lookup->rctext,&argv[0][2],
MXRD);
} else {
strncpy(lookup->rctext,argv[1],
MXRD);
argv++;
argc--;
}
}
} else if (strncmp(argv[0],"-t",2) == 0) {
if (have_host) {
if (argv[0][2]!=0) {
strncpy(lookup->rttext,&argv[0][2],
MXRD);
} else {
strncpy(lookup->rttext,argv[1],
MXRD);
argv++;
argc--;
}
}
} else if (strncmp(argv[0],"-f",2) == 0) {
if (argv[0][2]!=0) {
batchname=&argv[0][2];
@@ -564,6 +608,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->ns_search_only = ns_search_only;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
lookup->section_question = section_question;
@@ -578,7 +623,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
argv++;
argc--;
} else {
if (have_host) {
if (have_host) {
ENSURE(lookup != NULL);
if (isclass(argv[0])) {
strncpy(lookup->rctext,argv[0],
@@ -608,6 +653,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
lookup->section_question = section_question;
@@ -629,16 +675,17 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
fatal("Couldn't open specified batch file.");
}
while (fgets(batchline, MXNAME, fp) != 0) {
debug ("Batch line %s", batchline);
bargc=1;
bargv[bargc]=strtok(batchline, " \t");
bargv[bargc]=strtok(batchline, " \t\r\n");
while (bargv[bargc] != NULL) {
bargc++;
bargv[bargc]=strtok(NULL, " \t");
bargv[bargc]=strtok(NULL, " \t\r\n");
}
bargc--;
bargv[0]="dig";
debug("Parsing %d:%s",bargc,bargv[1]);
parse_args(ISC_TRUE, bargc, (char**)bargv);
debug("Batch parsing %d:%s",bargc,bargv[1]);
parse_args(ISC_TRUE, bargc+1, (char**)bargv);
}
}
if (lookup_list.head == NULL) {
@@ -658,6 +705,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
lookup->section_question = section_question;

View File

@@ -59,13 +59,13 @@ ISC_LIST(dig_lookup_t) lookup_list;
ISC_LIST(dig_server_t) server_list;
ISC_LIST(dig_searchlist_t) search_list;
isc_boolean_t tcp_mode = ISC_FALSE, recurse = ISC_TRUE, have_ipv6 = ISC_FALSE,
free_now = ISC_FALSE, show_details = ISC_FALSE;
isc_boolean_t tcp_mode = ISC_FALSE, have_ipv6 = ISC_FALSE,
free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE;
#ifdef TWIDDLE
isc_boolean_t twiddle = ISC_FALSE;
#endif
in_port_t port;
unsigned int timeout;
in_port_t port = 53;
unsigned int timeout = 5;
isc_mem_t *mctx = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_task_t *task = NULL;
@@ -77,7 +77,8 @@ char *rootspace[BUFSIZE];
isc_buffer_t rootbuf;
int sendcount = 0;
int ndots = -1;
int tries = 2;
int tries = 3;
char fixeddomain[MXNAME]="";
static void
free_lists(void);
@@ -238,6 +239,15 @@ setup_system(void) {
dig_lookup_t *l;
isc_boolean_t get_servers;
if (fixeddomain[0]!=0) {
search = isc_mem_allocate( mctx, sizeof(struct dig_server));
if (search == NULL)
fatal("Memory allocation failure.");
strncpy(search->origin, fixeddomain, MXNAME - 1);
ISC_LIST_PREPEND(search_list, search, link);
}
debug ("setup_system()");
id = getpid() << 8;
get_servers = (server_list.head == NULL);
@@ -278,7 +288,8 @@ setup_system(void) {
ndots);
}
}
} else if (strcasecmp(ptr,"search") == 0) {
} else if ((strcasecmp(ptr,"search") == 0)
&& usesearch){
while ((ptr = strtok(NULL, " \t\r\n"))
!= NULL) {
search = isc_mem_allocate(
@@ -297,6 +308,26 @@ setup_system(void) {
search,
link);
}
} else if ((strcasecmp(ptr,"domain") == 0) &&
(fixeddomain[0] == 0 )){
while ((ptr = strtok(NULL, " \t\r\n"))
!= NULL) {
search = isc_mem_allocate(
mctx, sizeof(struct
dig_server));
if (search == NULL)
fatal("Memory "
"allocation "
"failure.");
strncpy(search->
origin,
ptr,
MXNAME - 1);
ISC_LIST_PREPEND
(search_list,
search,
link);
}
}
}
@@ -453,6 +484,8 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
lookup->xfr_q = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_TRUE;
lookup->recurse = query->lookup->
recurse;
lookup->ns_search_only =
ISC_FALSE;
lookup->use_my_server_list =
@@ -549,6 +582,7 @@ next_origin(dns_message_t *msg, dig_query_t *query) {
lookup->xfr_q = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = query->lookup->identify;
lookup->recurse = query->lookup->recurse;
lookup->ns_search_only = query->lookup->ns_search_only;
lookup->use_my_server_list = query->lookup->use_my_server_list;
lookup->origin = ISC_LIST_NEXT(query->lookup->origin,link);
@@ -638,7 +672,7 @@ setup_lookup(dig_lookup_t *lookup) {
result = dns_name_fromtext(lookup->oname, &b, &rootorg,
ISC_FALSE, &lookup->onamebuf);
if (result != ISC_R_SUCCESS) {
dns_message_puttempname(lookup->sendmsg,
dns_message_puttempname(lookup->sendmsg,
&lookup->name);
dns_message_puttempname(lookup->sendmsg,
&lookup->oname);
@@ -697,8 +731,10 @@ setup_lookup(dig_lookup_t *lookup) {
lookup->sendmsg->id = id++;
lookup->sendmsg->opcode = dns_opcode_query;
if (recurse)
if (lookup->recurse) {
debug ("Recursive query");
lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD;
}
dns_message_addname(lookup->sendmsg, lookup->name,
DNS_SECTION_QUESTION);
@@ -941,7 +977,6 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) {
fatal ("Length of %X was longer than I can handle!",
length);
}
/* XXXMWS Fix the above. */
/*
* Even though the buffer was already init'ed, we need
* to redo it now, to force the length we want.
@@ -1418,8 +1453,6 @@ main(int argc, char **argv) {
for (i=0 ; i<p; i++);
#endif
setup_libs();
port = 53;
timeout = 10;
parse_args(ISC_FALSE, argc, argv);
setup_system();
lookup = ISC_LIST_HEAD(lookup_list);

View File

@@ -61,7 +61,6 @@ extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t tcp_mode,
recurse,
have_ipv6;
extern in_port_t port;
extern unsigned int timeout;
@@ -630,6 +629,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->xfr_q = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE;
lookup->recurse = recursion;
lookup->ns_search_only = showallsoa;
lookup->use_my_server_list = ISC_FALSE;
lookup->retries = tries;

View File

@@ -49,7 +49,8 @@ struct dig_lookup {
doing_xfr,
ns_search_only,
use_my_server_list,
identify;
identify,
recurse;
char textname[MXNAME]; /* Name we're going to be looking up */
char rttext[MXRD]; /* rdata type text */
char rctext[MXRD]; /* rdata class text */