version 1.11, 2020/09/13 09:33:39 |
version 1.12, 2020/09/14 08:40:43 |
|
|
|
|
#include "dig.h" |
#include "dig.h" |
|
|
static isc_boolean_t short_form = ISC_TRUE, |
static int short_form = 1, |
tcpmode = ISC_FALSE, |
tcpmode = 0, |
identify = ISC_FALSE, stats = ISC_TRUE, |
identify = 0, stats = 1, |
comments = ISC_TRUE, section_question = ISC_TRUE, |
comments = 1, section_question = 1, |
section_answer = ISC_TRUE, section_authority = ISC_TRUE, |
section_answer = 1, section_authority = 1, |
section_additional = ISC_TRUE, recurse = ISC_TRUE, |
section_additional = 1, recurse = 1, |
aaonly = ISC_FALSE, nofail = ISC_TRUE; |
aaonly = 0, nofail = 1; |
|
|
static isc_boolean_t interactive; |
static int interactive; |
|
|
static isc_boolean_t in_use = ISC_FALSE; |
static int in_use = 0; |
static char defclass[MXRD] = "IN"; |
static char defclass[MXRD] = "IN"; |
static char deftype[MXRD] = "A"; |
static char deftype[MXRD] = "A"; |
static isc_event_t *global_event = NULL; |
static isc_event_t *global_event = NULL; |
|
|
isc_result_t result; |
isc_result_t result; |
isc_buffer_t *b = NULL; |
isc_buffer_t *b = NULL; |
unsigned int size = 1024; |
unsigned int size = 1024; |
isc_boolean_t done = ISC_FALSE; |
int done = 0; |
|
|
if (rdata->type < N_KNOWN_RRTYPES) |
if (rdata->type < N_KNOWN_RRTYPES) |
printf("%s", rtypetext[rdata->type]); |
printf("%s", rtypetext[rdata->type]); |
|
|
if (result == ISC_R_SUCCESS) { |
if (result == ISC_R_SUCCESS) { |
printf("%.*s\n", (int)isc_buffer_usedlength(b), |
printf("%.*s\n", (int)isc_buffer_usedlength(b), |
(char *)isc_buffer_base(b)); |
(char *)isc_buffer_base(b)); |
done = ISC_TRUE; |
done = 1; |
} else if (result != ISC_R_NOSPACE) |
} else if (result != ISC_R_NOSPACE) |
check_result(result, "dns_rdata_totext"); |
check_result(result, "dns_rdata_totext"); |
isc_buffer_free(&b); |
isc_buffer_free(&b); |
|
|
} |
} |
|
|
static isc_result_t |
static isc_result_t |
printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers, |
printsection(dig_query_t *query, dns_message_t *msg, int headers, |
dns_section_t section) { |
dns_section_t section) { |
isc_result_t result, loopresult; |
isc_result_t result, loopresult; |
dns_name_t *name; |
dns_name_t *name; |
|
|
} |
} |
|
|
static isc_result_t |
static isc_result_t |
detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers, |
detailsection(dig_query_t *query, dns_message_t *msg, int headers, |
dns_section_t section) { |
dns_section_t section) { |
isc_result_t result, loopresult; |
isc_result_t result, loopresult; |
dns_name_t *name; |
dns_name_t *name; |
|
|
} |
} |
|
|
static isc_result_t |
static isc_result_t |
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { |
printmessage(dig_query_t *query, dns_message_t *msg, int headers) { |
char servtext[ISC_SOCKADDR_FORMATSIZE]; |
char servtext[ISC_SOCKADDR_FORMATSIZE]; |
|
|
/* I've we've gotten this far, we've reached a server. */ |
/* I've we've gotten this far, we've reached a server. */ |
|
|
if (!short_form) { |
if (!short_form) { |
puts("------------"); |
puts("------------"); |
/* detailheader(query, msg);*/ |
/* detailheader(query, msg);*/ |
detailsection(query, msg, ISC_TRUE, DNS_SECTION_QUESTION); |
detailsection(query, msg, 1, DNS_SECTION_QUESTION); |
detailsection(query, msg, ISC_TRUE, DNS_SECTION_ANSWER); |
detailsection(query, msg, 1, DNS_SECTION_ANSWER); |
detailsection(query, msg, ISC_TRUE, DNS_SECTION_AUTHORITY); |
detailsection(query, msg, 1, DNS_SECTION_AUTHORITY); |
detailsection(query, msg, ISC_TRUE, DNS_SECTION_ADDITIONAL); |
detailsection(query, msg, 1, DNS_SECTION_ADDITIONAL); |
puts("------------"); |
puts("------------"); |
} |
} |
|
|
|
|
} |
} |
|
|
static void |
static void |
show_settings(isc_boolean_t full, isc_boolean_t serv_only) { |
show_settings(int full, int serv_only) { |
dig_server_t *srv; |
dig_server_t *srv; |
isc_sockaddr_t sockaddr; |
isc_sockaddr_t sockaddr; |
dig_searchlist_t *listent; |
dig_searchlist_t *listent; |
|
|
printf("\n"); |
printf("\n"); |
} |
} |
|
|
static isc_boolean_t |
static int |
testtype(char *typetext) { |
testtype(char *typetext) { |
isc_result_t result; |
isc_result_t result; |
isc_textregion_t tr; |
isc_textregion_t tr; |
|
|
tr.length = strlen(typetext); |
tr.length = strlen(typetext); |
result = dns_rdatatype_fromtext(&rdtype, &tr); |
result = dns_rdatatype_fromtext(&rdtype, &tr); |
if (result == ISC_R_SUCCESS) |
if (result == ISC_R_SUCCESS) |
return (ISC_TRUE); |
return (1); |
else { |
else { |
printf("unknown query type: %s\n", typetext); |
printf("unknown query type: %s\n", typetext); |
return (ISC_FALSE); |
return (0); |
} |
} |
} |
} |
|
|
static isc_boolean_t |
static int |
testclass(char *typetext) { |
testclass(char *typetext) { |
isc_result_t result; |
isc_result_t result; |
isc_textregion_t tr; |
isc_textregion_t tr; |
|
|
tr.length = strlen(typetext); |
tr.length = strlen(typetext); |
result = dns_rdataclass_fromtext(&rdclass, &tr); |
result = dns_rdataclass_fromtext(&rdclass, &tr); |
if (result == ISC_R_SUCCESS) |
if (result == ISC_R_SUCCESS) |
return (ISC_TRUE); |
return (1); |
else { |
else { |
printf("unknown query class: %s\n", typetext); |
printf("unknown query class: %s\n", typetext); |
return (ISC_FALSE); |
return (0); |
} |
} |
} |
} |
|
|
|
|
((l >= N) && (l < sizeof(A)) && (strncasecmp(opt, A, l) == 0)) |
((l >= N) && (l < sizeof(A)) && (strncasecmp(opt, A, l) == 0)) |
|
|
if (CHECKOPT("all", 3)) { |
if (CHECKOPT("all", 3)) { |
show_settings(ISC_TRUE, ISC_FALSE); |
show_settings(1, 0); |
} else if (strncasecmp(opt, "class=", 6) == 0) { |
} else if (strncasecmp(opt, "class=", 6) == 0) { |
if (testclass(&opt[6])) |
if (testclass(&opt[6])) |
strlcpy(defclass, &opt[6], sizeof(defclass)); |
strlcpy(defclass, &opt[6], sizeof(defclass)); |
|
|
} else if (strncasecmp(opt, "domain=", 7) == 0) { |
} else if (strncasecmp(opt, "domain=", 7) == 0) { |
strlcpy(domainopt, &opt[7], sizeof(domainopt)); |
strlcpy(domainopt, &opt[7], sizeof(domainopt)); |
set_search_domain(domainopt); |
set_search_domain(domainopt); |
usesearch = ISC_TRUE; |
usesearch = 1; |
} else if (strncasecmp(opt, "do=", 3) == 0) { |
} else if (strncasecmp(opt, "do=", 3) == 0) { |
strlcpy(domainopt, &opt[3], sizeof(domainopt)); |
strlcpy(domainopt, &opt[3], sizeof(domainopt)); |
set_search_domain(domainopt); |
set_search_domain(domainopt); |
usesearch = ISC_TRUE; |
usesearch = 1; |
} else if (strncasecmp(opt, "port=", 5) == 0) { |
} else if (strncasecmp(opt, "port=", 5) == 0) { |
set_port(&opt[5]); |
set_port(&opt[5]); |
} else if (strncasecmp(opt, "po=", 3) == 0) { |
} else if (strncasecmp(opt, "po=", 3) == 0) { |
|
|
} else if (strncasecmp(opt, "t=", 2) == 0) { |
} else if (strncasecmp(opt, "t=", 2) == 0) { |
set_timeout(&opt[2]); |
set_timeout(&opt[2]); |
} else if (CHECKOPT("recurse", 3)) { |
} else if (CHECKOPT("recurse", 3)) { |
recurse = ISC_TRUE; |
recurse = 1; |
} else if (CHECKOPT("norecurse", 5)) { |
} else if (CHECKOPT("norecurse", 5)) { |
recurse = ISC_FALSE; |
recurse = 0; |
} else if (strncasecmp(opt, "retry=", 6) == 0) { |
} else if (strncasecmp(opt, "retry=", 6) == 0) { |
set_tries(&opt[6]); |
set_tries(&opt[6]); |
} else if (strncasecmp(opt, "ret=", 4) == 0) { |
} else if (strncasecmp(opt, "ret=", 4) == 0) { |
set_tries(&opt[4]); |
set_tries(&opt[4]); |
} else if (CHECKOPT("defname", 3)) { |
} else if (CHECKOPT("defname", 3)) { |
usesearch = ISC_TRUE; |
usesearch = 1; |
} else if (CHECKOPT("nodefname", 5)) { |
} else if (CHECKOPT("nodefname", 5)) { |
usesearch = ISC_FALSE; |
usesearch = 0; |
} else if (CHECKOPT("vc", 2) == 0) { |
} else if (CHECKOPT("vc", 2) == 0) { |
tcpmode = ISC_TRUE; |
tcpmode = 1; |
} else if (CHECKOPT("novc", 4) == 0) { |
} else if (CHECKOPT("novc", 4) == 0) { |
tcpmode = ISC_FALSE; |
tcpmode = 0; |
} else if (CHECKOPT("debug", 3) == 0) { |
} else if (CHECKOPT("debug", 3) == 0) { |
short_form = ISC_FALSE; |
short_form = 0; |
showsearch = ISC_TRUE; |
showsearch = 1; |
} else if (CHECKOPT("nodebug", 5) == 0) { |
} else if (CHECKOPT("nodebug", 5) == 0) { |
short_form = ISC_TRUE; |
short_form = 1; |
showsearch = ISC_FALSE; |
showsearch = 0; |
} else if (CHECKOPT("d2", 2) == 0) { |
} else if (CHECKOPT("d2", 2) == 0) { |
debugging = ISC_TRUE; |
debugging = 1; |
} else if (CHECKOPT("nod2", 4) == 0) { |
} else if (CHECKOPT("nod2", 4) == 0) { |
debugging = ISC_FALSE; |
debugging = 0; |
} else if (CHECKOPT("search", 3) == 0) { |
} else if (CHECKOPT("search", 3) == 0) { |
usesearch = ISC_TRUE; |
usesearch = 1; |
} else if (CHECKOPT("nosearch", 5) == 0) { |
} else if (CHECKOPT("nosearch", 5) == 0) { |
usesearch = ISC_FALSE; |
usesearch = 0; |
} else if (CHECKOPT("sil", 3) == 0) { |
} else if (CHECKOPT("sil", 3) == 0) { |
/* deprecation_msg = ISC_FALSE; */ |
/* deprecation_msg = 0; */ |
} else if (CHECKOPT("fail", 3) == 0) { |
} else if (CHECKOPT("fail", 3) == 0) { |
nofail=ISC_FALSE; |
nofail=0; |
} else if (CHECKOPT("nofail", 5) == 0) { |
} else if (CHECKOPT("nofail", 5) == 0) { |
nofail=ISC_TRUE; |
nofail=1; |
} else if (strncasecmp(opt, "ndots=", 6) == 0) { |
} else if (strncasecmp(opt, "ndots=", 6) == 0) { |
set_ndots(&opt[6]); |
set_ndots(&opt[6]); |
} else { |
} else { |
|
|
rdclass = dns_rdataclass_in; |
rdclass = dns_rdataclass_in; |
} |
} |
lookup = make_empty_lookup(); |
lookup = make_empty_lookup(); |
if (get_reverse(store, sizeof(store), opt, lookup->ip6_int, ISC_TRUE) |
if (get_reverse(store, sizeof(store), opt, lookup->ip6_int, 1) |
== ISC_R_SUCCESS) { |
== ISC_R_SUCCESS) { |
strlcpy(lookup->textname, store, sizeof(lookup->textname)); |
strlcpy(lookup->textname, store, sizeof(lookup->textname)); |
lookup->rdtype = dns_rdatatype_ptr; |
lookup->rdtype = dns_rdatatype_ptr; |
lookup->rdtypeset = ISC_TRUE; |
lookup->rdtypeset = 1; |
} else { |
} else { |
strlcpy(lookup->textname, opt, sizeof(lookup->textname)); |
strlcpy(lookup->textname, opt, sizeof(lookup->textname)); |
lookup->rdtype = rdtype; |
lookup->rdtype = rdtype; |
lookup->rdtypeset = ISC_TRUE; |
lookup->rdtypeset = 1; |
} |
} |
lookup->rdclass = rdclass; |
lookup->rdclass = rdclass; |
lookup->rdclassset = ISC_TRUE; |
lookup->rdclassset = 1; |
lookup->trace = ISC_FALSE; |
lookup->trace = 0; |
lookup->trace_root = lookup->trace; |
lookup->trace_root = lookup->trace; |
lookup->ns_search_only = ISC_FALSE; |
lookup->ns_search_only = 0; |
lookup->identify = identify; |
lookup->identify = identify; |
lookup->recurse = recurse; |
lookup->recurse = recurse; |
lookup->aaonly = aaonly; |
lookup->aaonly = aaonly; |
|
|
lookup->section_answer = section_answer; |
lookup->section_answer = section_answer; |
lookup->section_authority = section_authority; |
lookup->section_authority = section_authority; |
lookup->section_additional = section_additional; |
lookup->section_additional = section_additional; |
lookup->new_search = ISC_TRUE; |
lookup->new_search = 1; |
if (nofail) |
if (nofail) |
lookup->servfail_stops = ISC_FALSE; |
lookup->servfail_stops = 0; |
ISC_LIST_INIT(lookup->q); |
ISC_LIST_INIT(lookup->q); |
ISC_LINK_INIT(lookup, link); |
ISC_LINK_INIT(lookup, link); |
ISC_LIST_APPEND(lookup_list, lookup, link); |
ISC_LIST_APPEND(lookup_list, lookup, link); |
|
|
printf("couldn't get address for '%s': %s\n", |
printf("couldn't get address for '%s': %s\n", |
arg, isc_result_totext(res)); |
arg, isc_result_totext(res)); |
} else { |
} else { |
check_ra = ISC_FALSE; |
check_ra = 0; |
show_settings(ISC_TRUE, ISC_TRUE); |
show_settings(1, 1); |
} |
} |
} else if (strcasecmp(ptr, "exit") == 0) { |
} else if (strcasecmp(ptr, "exit") == 0) { |
in_use = ISC_FALSE; |
in_use = 0; |
} else if (strcasecmp(ptr, "help") == 0 || |
} else if (strcasecmp(ptr, "help") == 0 || |
strcasecmp(ptr, "?") == 0) { |
strcasecmp(ptr, "?") == 0) { |
printf("The '%s' command is not yet implemented.\n", ptr); |
printf("The '%s' command is not yet implemented.\n", ptr); |
|
|
} else |
} else |
ptr = fgets(buf, COMMSIZE, stdin); |
ptr = fgets(buf, COMMSIZE, stdin); |
if (ptr == NULL) { |
if (ptr == NULL) { |
in_use = ISC_FALSE; |
in_use = 0; |
} else |
} else |
do_next_command(ptr); |
do_next_command(ptr); |
free(buf); |
free(buf); |
|
|
|
|
static void |
static void |
parse_args(int argc, char **argv) { |
parse_args(int argc, char **argv) { |
isc_boolean_t have_lookup = ISC_FALSE; |
int have_lookup = 0; |
|
|
usesearch = ISC_TRUE; |
usesearch = 1; |
for (argc--, argv++; argc > 0; argc--, argv++) { |
for (argc--, argv++; argc > 0; argc--, argv++) { |
debug("main parsing %s", argv[0]); |
debug("main parsing %s", argv[0]); |
if (argv[0][0] == '-') { |
if (argv[0][0] == '-') { |
|
|
} else if (argv[0][1] != 0) { |
} else if (argv[0][1] != 0) { |
setoption(&argv[0][1]); |
setoption(&argv[0][1]); |
} else |
} else |
have_lookup = ISC_TRUE; |
have_lookup = 1; |
} else { |
} else { |
if (!have_lookup) { |
if (!have_lookup) { |
have_lookup = ISC_TRUE; |
have_lookup = 1; |
in_use = ISC_TRUE; |
in_use = 1; |
addlookup(argv[0]); |
addlookup(argv[0]); |
} else { |
} else { |
isc_result_t res; |
isc_result_t res; |
|
|
if ((res = set_nameserver(argv[0]))) |
if ((res = set_nameserver(argv[0]))) |
fatal("couldn't get address for '%s': %s", |
fatal("couldn't get address for '%s': %s", |
argv[0], isc_result_totext(res)); |
argv[0], isc_result_totext(res)); |
check_ra = ISC_FALSE; |
check_ra = 0; |
} |
} |
} |
} |
} |
} |
|
|
nslookup_main(int argc, char **argv) { |
nslookup_main(int argc, char **argv) { |
isc_result_t result; |
isc_result_t result; |
|
|
interactive = ISC_TF(isatty(0)); |
interactive = isatty(0); |
|
|
ISC_LIST_INIT(lookup_list); |
ISC_LIST_INIT(lookup_list); |
ISC_LIST_INIT(server_list); |
ISC_LIST_INIT(server_list); |
ISC_LIST_INIT(root_hints_server_list); |
ISC_LIST_INIT(root_hints_server_list); |
ISC_LIST_INIT(search_list); |
ISC_LIST_INIT(search_list); |
|
|
check_ra = ISC_TRUE; |
check_ra = 1; |
|
|
/* setup dighost callbacks */ |
/* setup dighost callbacks */ |
dighost_printmessage = printmessage; |
dighost_printmessage = printmessage; |
|
|
|
|
parse_args(argc, argv); |
parse_args(argc, argv); |
|
|
setup_system(ISC_FALSE, ISC_FALSE); |
setup_system(0, 0); |
if (domainopt[0] != '\0') |
if (domainopt[0] != '\0') |
set_search_domain(domainopt); |
set_search_domain(domainopt); |
if (in_use) |
if (in_use) |
|
|
else |
else |
result = isc_app_onrun(global_task, getinput, NULL); |
result = isc_app_onrun(global_task, getinput, NULL); |
check_result(result, "isc_app_onrun"); |
check_result(result, "isc_app_onrun"); |
in_use = ISC_TF(!in_use); |
in_use = !in_use; |
|
|
(void)isc_app_run(); |
(void)isc_app_run(); |
|
|