dighost.c revision 66921d6dd259c4486a07aba19eee2b8349698575
938440694b33cd752e9e4b71a526368b4811c177Tinderbox User * Copyright (C) 2000, 2001 Internet Software Consortium.
d7201de09b85929a86b157f4b2d91667c68c6b52Automatic Updater * Permission to use, copy, modify, and distribute this software for any
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * purpose with or without fee is hereby granted, provided that the above
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * copyright notice and this permission notice appear in all copies.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9eae5f2a7a189353bd4fcbb939c2b61094b3bfe9Tatuya JINMEI 神明達哉/* $Id: dighost.c,v 1.183 2001/01/16 23:15:54 bwelling Exp $ */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Notice to programmers: Do not use this code as an example of how to
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * use the ISC library to perform DNS lookups. Dig and Host both operate
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * on the request level, since they allow fine-tuning of output and are
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * intended as debugging tools. As a result, they perform many of the
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * functions which could be better handled using the dns_resolver
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * functions in most applications.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#endif /* DNS_OPT_NEWCODES */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉unsigned int timeout = 0;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Exit Codes:
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * 0 Everything went well, including things like NXDOMAIN
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 1 Usage error
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 7 Got too many RR's or Names
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 8 Couldn't open batch file
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 9 No reply from server
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * 10 Internal error
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Apply and clear locks at the event level in global task.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Can I get rid of these using shutdown events? XXX
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 debug("lock_lookup %s:%d", __FILE__, __LINE__);\
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt "isc_mutex_unlock");\
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsrecv_done(isc_task_t *task, isc_event_t *event);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉connect_timeout(isc_task_t *task, isc_event_t *event);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 while (*s != '\0') {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (*s == '.')
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt unsigned int len;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉get_reverse(char *reverse, char *value, isc_boolean_t nibble) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (strspn(value, "0123456789.") == strlen(value)) {
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt if (n == 0) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 for (i = n - 1; i >= 0; i--) {
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt } else if (strspn(value, "0123456789abcdefABCDEF:")
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 n = inet_pton(AF_INET6, value, &addr.type.in6);
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews result = dns_byaddr_createptrname(&addr, nibble,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = dns_name_totext(name, ISC_FALSE, &b);
ea30861fe56a9205ad36e733abf3303e2471d0a2Mark Andrewscheck_result(isc_result_t result, const char *msg) {
b62c2acf81af75d100df24eeb31e939d1c8453d9Mark Andrews * Create a server structure, which is part of the lookup structure.
b62c2acf81af75d100df24eeb31e939d1c8453d9Mark Andrews * This is little more than a linked list of servers to query in hopes
b62c2acf81af75d100df24eeb31e939d1c8453d9Mark Andrews * of finding the answer the user is looking for
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Produce a cloned server list. The dest list must have already had
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * ISC_LIST_INIT applied.
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Create an empty lookup structure, which holds all the information needed
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * to get an answer to a user's question. This structure contains two
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * linked lists: the server list (servers to query) and the query list
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * (outstanding queries which have been made to the listed servers).
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt looknew->cmdline[0] = 0; /* Not copied in clone_lookup! */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt#endif /* DNS_OPT_NEWCODES_LIVE */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Clone a lookup, perhaps copying the server list. This does not clone
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * the query list, since it will be regenerated by the setup_lookup()
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * function, nor does it queue up the new lookup for processing.
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Caution: If you don't clone the servers, you MUST clone the server
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * list seperately from somewhere else, or construct it by hand.
#ifdef DNS_OPT_NEWCODES_LIVE
if (servers)
return (looknew);
return (looknew);
setup_text_key(void) {
int secretsize;
unsigned char *secretstore;
&secretbuf);
goto failure;
namebuf);
goto failure;
setup_file_key(void) {
int secretlen;
goto failure;
goto failure;
* Setup the system as a whole, reading key information and resolv.conf
setup_system(void) {
char *ptr;
char *input;
/* XXX Use lwres resolv.conf reader */
if (get_servers &&
ndots);
!= NULL) {
ptr);
__LINE__);
ptr,
MXNAME);
link);
(fixeddomain[0] == 0 )){
!= NULL) {
__LINE__);
ptr,
if (keyfile[0] != 0)
else if (keysecret[0] != 0)
setup_libs(void) {
#ifdef DNS_OPT_NEWCODES_LIVE
#ifdef DNS_OPT_NEWCODES_LIVE
unsigned int i, optsize = 0;
if (dnssec)
#ifdef DNS_OPT_NEWCODES_LIVE
* part of dig.c, host.c, or nslookup.c) to either shutdown the system as
check_if_done(void) {
sendcount == 0) {
link);
link);
sockcount--;
static isc_boolean_t
dig_server_t *s;
dig_query_t *q;
void *ptr;
if (debugging) {
while (q != NULL) {
q->servname);
return (ISC_FALSE);
while (s != NULL) {
s, lookup);
ptr = s;
return (ISC_TRUE);
start_lookup(void) {
if (cancel_now)
start_lookup();
isc_region_t r;
int len;
BUFSIZE);
NULL,
isc_buffer_usedregion(b, &r);
(char *)r.base);
if (!success) {
if (section ==
query->
query->
isc_buffer_free(&b);
static isc_boolean_t
return (ISC_FALSE);
if (!usesearch)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
int len;
isc_region_t r;
isc_buffer_t b;
lookup_counter = 0;
* is TRUE or we got a domain line in the resolv.conf file.
if (fixeddomain[0] != 0) {
sizeof(*fixedsearch));
isc_buffer_usedregion(&b, &r);
#ifndef DNS_OPT_NEWCODES_LIVE
#ifdef DNS_OPT_NEWCODES_LIVE
NULL);
MXNAME);
wirebuf);
optlist);
DNS_SECTION_QUESTION, 0);
ISC_TRUE);
sendcount--;
dig_lookup_t *l;
unsigned int local_timeout;
if (timeout == 0) {
NULL,
&l->interval,
l, &l->timer);
dig_lookup_t *l;
if (specified_source &&
sockcount++;
if (specified_source)
if (l->ns_search_only) {
sockcount++;
if (specified_source) {
link);
query);
recvcount++;
link);
sendcount++;
if (l->ns_search_only) {
if (!l->tcp_mode)
if (!l->tcp_mode) {
l->retries--;
l->retries);
cancel_lookup(l);
l->retries--;
cancel_lookup(l);
isc_region_t r;
dig_lookup_t *l;
recvcount--;
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
sockcount--;
length);
recvcount++;
dig_lookup_t *l;
sockcount--;
if (include_question) {
link);
recvcount++;
sendcount++;
dig_lookup_t *l;
isc_region_t r;
sockcount--;
isc_buffer_usedregion(b, &r);
sockcount--;
isc_buffer_free(&b);
static isc_boolean_t
isc_buffer_t b;
isc_region_t r;
return (ISC_TRUE);
&name);
return (ISC_TRUE);
goto next_rdata;
&soa,
mctx);
goto doexit;
goto next_rdata;
goto doexit;
goto doexit;
goto next_rdata;
goto doexit;
goto next_rdata;
goto doexit;
if (atlimit) {
isc_buffer_usedregion(&b, &r);
if (atlimit)
return (ISC_TRUE);
return (ISC_FALSE);
isc_region_t r;
dig_lookup_t *n, *l;
unsigned int local_timeout;
recvcount--;
|| cancel_now) {
&msg);
l->sendmsg,
l->querysig);
if (l->msgcounter != 0)
l->msgcounter++;
if (l->besteffort)
hex_dump(b);
cancel_lookup(l);
cancel_lookup(l);
l->servfail_stops) {
if (l->tcp_mode)
l->querysig);
&l->querysig);
l->doing_xfr ) {
if (timeout == 0) {
if (l->tcp_mode)
local_timeout, 0);
NULL,
&l->interval,
if ((l->trace)||
(l->ns_search_only)) {
ISC_TRUE);
MXNAME);
&ab);
(char *)r.base,
query);
l->trace_root)
ISC_TRUE);
&ab);
(char *)r.base,
query);
== ISC_R_SUCCESS) &&
l->ns_search_only &&
!l->trace_root ) {
if (l->pending)
if (l->doing_xfr) {
if (docancel) {
cancel_lookup(l);
&ab);
(char *)r.base,
query);
cancel_lookup(l);
sockcount--;
int result;
if (result != 0) {
port);
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
if (is_blocking) {
if (free_now) {
while (q != NULL) {
q, current_lookup);
clear_query (q);
q = nq;
while (l != NULL) {
try_clear_lookup(l);
destroy_libs(void) {
void *ptr;
dig_server_t *s;
dig_searchlist_t *o;
if (is_blocking) {
while (s != NULL) {
ptr = s;
while (o != NULL) {
ptr = o;
if (is_dst_up) {
if (memdebugging != 0)