dighost.c revision 827572e191fad1326c624593bf35d8eb1928f607
94d102893aeb8ecea49dcda64e742835ffe0c102Bob Halley * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Copyright (C) 2000-2003 Internet Software Consortium.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and/or distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * PERFORMANCE OF THIS SOFTWARE.
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley/* $Id: dighost.c,v 1.307 2008/01/17 21:46:33 marka Exp $ */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Notice to programmers: Do not use this code as an example of how to
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * use the ISC library to perform DNS lookups. Dig and Host both operate
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * on the request level, since they allow fine-tuning of output and are
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * intended as debugging tools. As a result, they perform many of the
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * functions which could be better handled using the dns_resolver
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * functions in most applications.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyunsigned int timeout = 0;
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleystatic void initialize_idn(void);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleystatic isc_result_t output_filter(isc_buffer_t *buffer,
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley unsigned int used_org,
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleystatic idn_result_t append_textname(char *name, const char *origin,
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleystatic void idn_check_result(idn_result_t r, const char *msg);
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley * Exit Codes:
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 0 Everything went well, including things like NXDOMAIN
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 1 Usage error
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 7 Got too many RR's or Names
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 8 Couldn't open batch file
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 9 No reply from server
577179503f2eb7695ec668d8eeb41889a150e28fBob Halley *\li 10 Internal error
577179503f2eb7695ec668d8eeb41889a150e28fBob Halleyunsigned int digestbits = 0;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleydns_rdataset_t * sigchase_scanname(dns_rdatatype_t type,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleydns_rdataset_t * chase_scanname_section(dns_message_t *msg,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t advanced_rrsearch(dns_rdataset_t **rdataset,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t sigchase_verify_sig_key(dns_name_t *name,
3740b569ae76295b941d57a724a43beb75b533baBob Halleyisc_result_t sigchase_verify_sig(dns_name_t *name,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyvoid print_rdata(dns_rdata_t *rdata, isc_mem_t *mctx);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyvoid dup_name(dns_name_t *source, dns_name_t* target,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyvoid free_name(dns_name_t *name, isc_mem_t *mctx);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyvoid dump_database_section(dns_message_t *msg, int section);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleydns_rdataset_t * search_type(dns_name_t *name, dns_rdatatype_t type,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t contains_trusted_key(dns_name_t *name,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t prove_nx_type(dns_message_t * msg, dns_name_t *name,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t prove_nx(dns_message_t * msg, dns_name_t * name,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleystatic void nameFromString(const char *str, dns_name_t *p_ret);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyint inf_name(dns_name_t * name1, dns_name_t * name2);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t opentmpkey(isc_mem_t *mctx, const char *file,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyisc_result_t removetmpkey(isc_mem_t *mctx, const char *file);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleyisc_result_t grandfather_pb_test(dns_name_t * zone_name,
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley * the current name is the parent name when we follow delegation
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * the child name is used for delegation (NS DS responses in AUTHORITY section)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleystruct_tk_list tk_list = { {NULL, NULL, NULL, NULL, NULL}, 0};
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Apply and clear locks at the event level in global task.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Can I get rid of these using shutdown events? XXX
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley debug("unlock_lookup %s:%d", __FILE__, __LINE__);\
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley "isc_mutex_unlock");\
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyconnect_timeout(isc_task_t *task, isc_event_t *event);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleylaunch_next_query(dig_query_t *query, isc_boolean_t include_question);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleystatic void *
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley while (*s != '\0') {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (*s == '.')
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley unsigned int len;
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley * Append 'len' bytes of 'text' at '*p', failing with
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * ISC_R_NOSPACE if that would advance p past 'end'.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyappend(const char *text, int len, char **p, char *end) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyreverse_octets(const char *in, char **p, char *end) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyget_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (r > 0) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley /* This is a valid IPv6 address. */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley unsigned int options = 0;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_byaddr_createptrname2(&addr, options, name);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Not a valid IPv6 address. Assume IPv4.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * If 'strict' is not set, construct the
38d2d0e9326a2f70b5893302b89a26978b539405Bob Halley * in-addr.arpa name by blindly reversing
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * octets whether or not they look like integers,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * so that this can be used for RFC2317 names
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (strict && inet_pton(AF_INET, value, &addr.type.in) != 1)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley /* Append .in-addr.arpa. and a terminating NUL. */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleycheck_result(isc_result_t result, const char *msg) {
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley * Create a server structure, which is part of the lookup structure.
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley * This is little more than a linked list of servers to query in hopes
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * of finding the answer the user is looking for
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleymake_server(const char *servname, const char *userarg) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley srv = isc_mem_allocate(mctx, sizeof(struct dig_server));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Create a copy of the server list from the lwres configuration structure.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * The dest list must have already had ISC_LIST_INIT applied.
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halleycopy_server_list(lwres_conf_t *confdata, dig_serverlist_t *dest) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley lwres_net_ntop(af, confdata->nameservers[i].address,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley while (s != NULL) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley for (i = 0; i < count; i++) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyadd_nameserver(lwres_conf_t *confdata, const char *addr, int af) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (confdata->nsnext >= LWRES_CONFMAXNAMESERVERS)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley confdata->nameservers[i].family = LWRES_ADDRTYPE_V4;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley confdata->nameservers[i].family = LWRES_ADDRTYPE_V6;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (lwres_net_pton(af, addr, &confdata->nameservers[i].address) == 1) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Produce a cloned server list. The dest list must have already had
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * ISC_LIST_INIT applied.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyclone_server_list(dig_serverlist_t src, dig_serverlist_t *dest) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley newsrv = make_server(srv->servername, srv->userarg);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Create an empty lookup structure, which holds all the information needed
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * to get an answer to a user's question. This structure contains two
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * linked lists: the server list (servers to query) and the query list
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * (outstanding queries which have been made to the listed servers).
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Clone a lookup, perhaps copying the server list. This does not clone
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * the query list, since it will be regenerated by the setup_lookup()
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * function, nor does it queue up the new lookup for processing.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Caution: If you don't clone the servers, you MUST clone the server
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * list seperately from somewhere else, or construct it by hand.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyclone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley strncpy(looknew->textname, lookold->textname, MXNAME);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley strncpy(looknew->textnamesigchase, lookold->textnamesigchase, MXNAME);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley strncpy(looknew->cmdline, lookold->cmdline, MXNAME);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->identify_previous_line = lookold->identify_previous_line;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->servfail_stops = lookold->servfail_stops;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->trace_root_sigchase = lookold->trace_root_sigchase;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->rdtype_sigchaseset = lookold->rdtype_sigchaseset;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->rdtype_sigchase = lookold->rdtype_sigchase;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->qrdtype_sigchase = lookold->qrdtype_sigchase;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->rdclass_sigchase = lookold->rdclass_sigchase;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->rdclass_sigchaseset = lookold->rdclass_sigchaseset;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->ns_search_only = lookold->ns_search_only;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->section_question = lookold->section_question;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->section_answer = lookold->section_answer;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->section_authority = lookold->section_authority;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley looknew->section_additional = lookold->section_additional;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Requeue a lookup for further processing, perhaps copying the server
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * list. The new lookup structure is returned to the caller, and is
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * queued for processing. If servers are not cloned in the requeue, they
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * must be added before allowing the current event to complete, since the
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * completion of the event may result in the next entry on the lookup
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * queue getting run.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleyrequeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley debug("before insertion, init@%p -> %p, new@%p -> %p",
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley lookold, lookold->link.next, looknew, looknew->link.next);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley debug("after insertion, init -> %p, new = %p, new -> %p",
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley unsigned char *secretstore;
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley result = isc_buffer_allocate(mctx, &namebuf, MXNAME);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley secretstore = isc_mem_allocate(mctx, secretsize);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_buffer_init(&secretbuf, secretstore, secretsize);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = isc_base64_decodestring(keysecret, &secretbuf);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_tsigkey_create(&keyname, hmacname, secretstore,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dst_key_fromnamedfile(keyfile, DST_TYPE_PRIVATE | DST_TYPE_KEY,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley fprintf(stderr, "Couldn't read key from %s: %s\n",
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley printf(";; Couldn't create key %s: bad algorithm\n",
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_tsigkey_createfromkey(dst_key_name(dstkey), hmacname,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley search = isc_mem_allocate(mctx, sizeof(*search));
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley search = make_searchlist_entry(confdata->search[i]);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Setup the system as a whole, reading key information and resolv.conf
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley lwresult = lwres_context_create(&lwctx, mctx, mem_alloc, mem_free, 1);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley if (lwresult != LWRES_R_SUCCESS && lwresult != LWRES_R_NOTFOUND)
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley /* Make the search list */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley else { /* No search list. Use the domain name if any */
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley domain = make_searchlist_entry(lwconf->domainname);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley ISC_LIST_INITANDAPPEND(search_list, domain, link);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley /* If we don't find a nameserver fall back to localhost */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley lwresult = add_nameserver(lwconf, "127.0.0.1", AF_INET);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley lwresult = add_nameserver(lwconf, "::1", AF_INET6);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley else if (keysecret[0] != 0)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley /* Setup the list of messages for +sigchase */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley while ((search = ISC_LIST_HEAD(search_list)) != NULL) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Override the search list derived from resolv.conf by 'domain'.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Setup the ISC and DNS libraries for use by the system.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = isc_taskmgr_create(mctx, 1, 0, &taskmgr);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = isc_task_create(taskmgr, 0, &global_task);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = isc_mempool_create(mctx, COMMSIZE, &commctx);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * 6 and 2 set as reasonable parameters for 3 or 4 nameserver
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Add EDNS0 option record to a message. Currently, the only supported
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * options are UDP buffer size and the DO bit.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyadd_opt(dns_message_t *msg, isc_uint16_t udpsize, isc_uint16_t edns,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_message_gettemprdataset(msg, &rdataset);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley check_result(result, "dns_message_gettemprdataset");
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_message_gettemprdatalist(msg, &rdatalist);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley check_result(result, "dns_message_gettemprdatalist");
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley check_result(result, "dns_message_gettemprdata");
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Add a question section to a message, asking for the specified name,
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * type, and class.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleyadd_question(dns_message_t *message, dns_name_t *name,
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley dns_rdataclass_t rdclass, dns_rdatatype_t rdtype)
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley result = dns_message_gettemprdataset(message, &rdataset);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley check_result(result, "dns_message_gettemprdataset()");
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_rdataset_makequestion(rdataset, rdclass, rdtype);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Check if we're done with all the queued lookups, which is true iff
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * all sockets, sends, and recvs are accounted for (counters == 0),
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * and the lookup list is empty.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * If we are done, pass control back out to dighost_shutdown() (which is
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * part of dig.c, host.c, or nslookup.c) to either shutdown the system as
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * a whole or reseed the lookup list.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley debug("list %s", ISC_LIST_EMPTY(lookup_list) ? "empty" : "full");
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley if (ISC_LIST_EMPTY(lookup_list) && current_lookup == NULL &&
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Clear out a query when we're done with it. WARNING: This routine
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * WILL invalidate the query pointer.
b5b97de45a561784bd88fb8fa7e1464a28ad9a44Bob Halley ISC_LIST_DEQUEUE(query->recvlist, &query->recvbuf,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley ISC_LIST_DEQUEUE(query->lengthlist, &query->lengthbuf,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Try and clear out a lookup if we're done with it. Return ISC_TRUE if
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * the lookup was successfully cleared. If ISC_TRUE is returned, the
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * lookup pointer has been invalidated.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley while (q != NULL) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * At this point, we know there are no queries on the lookup,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * so can make it go away also.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley while (s != NULL) {
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley debug("freeing server %p belonging to %p", s, lookup);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * If we can, start the next lookup in the queue running.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * This assumes that the lookup on the head of the queue hasn't been
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * started yet. It also removes the lookup from the head of the queue,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * setting the current_lookup pointer pointing to it.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * If there's a current lookup running, we really shouldn't get
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Put the current lookup somewhere so cancel_all can find it
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley ISC_LIST_DEQUEUE(lookup_list, current_lookup, link);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley "+sigchase option is disabled\n");
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley nameFromString(current_lookup->textname, &query_name);
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley * Verifier que la temp est bien la plus basse
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley ": +sigchase option is disable\n");
86131d8d7aaf1bb8b8bfc7819985d05ea369b708Bob Halley result = dns_name_totext(dst_key_name(trustedkey),
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * If we can, clear the current lookup and start the next one running.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * This calls try_clear_lookup, so may invalidate the lookup pointer.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * Create and queue a new lookup as a followup to the current lookup,
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * based on the supplied message and section. This is used in trace and
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * name server search modes to start a new lookup using servers from
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * NS records in a reply. Returns the number of followup lookups made.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleyfollowup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section)
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley isc_boolean_t horizontal = ISC_FALSE, bad = ISC_FALSE;
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley debug("following up %s", query->lookup->textname);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley for (result = dns_message_firstname(msg, section);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley result = dns_message_findtype(name, dns_rdatatype_soa,
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley result = dns_message_findtype(name, dns_rdatatype_ns, 0,
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley if (query->lookup->trace && !query->lookup->trace_root) {
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley unsigned int nlabels;
9192e92f7d0f4e78385a1d5f9b6607cc5bf0e42aBob Halley domain = dns_fixedname_name(&query->lookup->fdomain);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley dns_name_format(&ns.name, namestr, sizeof(namestr));
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley /* Initialize lookup if we've not yet */
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley ISC_LIST_APPEND(lookup->my_server_list, srv, link);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley (query->lookup->trace || query->lookup->ns_search_only))
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley return (followup_lookup(msg, query, DNS_SECTION_AUTHORITY));
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * Randomize the order the nameserver will be tried.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley for (i = numLookups; i > 0; i--) {
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley while (j-- > 0)
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley ISC_LIST_DEQUEUE(lookup->my_server_list, srv, link);
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * Create and queue a new lookup using the next origin from the search
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * list, read in setup_system().
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halley * Return ISC_TRUE iff there was another searchlist entry.
95c86af1e92dae4ff837a39e7e2dcb7308dd9cceBob Halleynext_origin(dns_message_t *msg, dig_query_t *query) {
if (!usesearch)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
int len;
isc_buffer_t b;
#ifdef WITH_IDN
#ifdef WITH_IDN
lookup_counter = 0;
#ifdef WITH_IDN
* is TRUE or we got a domain line in the resolv.conf file.
#ifdef WITH_IDN
#ifdef WITH_IDN
sizeof(utf8_origin));
sizeof(utf8_textname));
#ifdef WITH_IDN
DNS_SECTION_QUESTION, 0);
extrabytes = 0;
ISC_TRUE);
dig_lookup_t *l;
sendcount--;
b != NULL;
dig_lookup_t *l;
unsigned int local_timeout;
if (timeout == 0)
l, &l->timer);
dig_lookup_t *l;
if (specified_source &&
sockcount++;
if (specified_source)
sockcount++;
if (specified_source) {
link);
recvcount++;
sendcount++;
if (!l->tcp_mode)
if (!l->tcp_mode) {
l->retries--;
l->retries);
l->retries--;
cancel_lookup(l);
cancel_lookup(l);
dig_lookup_t *l;
recvcount--;
sizeof(sockstr));
sockcount--;
if (length == 0) {
recvcount++;
dig_lookup_t *l;
sockcount--;
if (include_question)
recvcount++;
sendcount++;
dig_lookup_t *l;
sockcount--;
sockcount--;
static isc_boolean_t
return (ISC_TRUE);
&name);
return (ISC_TRUE);
goto next_rdata;
goto next_rdata;
goto doexit;
goto next_rdata;
goto doexit;
goto doexit;
goto next_rdata;
goto doexit;
goto next_rdata;
goto doexit;
return (ISC_FALSE);
return (ISC_TRUE);
#ifdef DIG_SIGCHASE
dig_lookup_t *n, *l;
unsigned int parseflags;
unsigned int msgflags;
#ifdef DIG_SIGCHASE
isc_region_t r;
recvcount--;
sockcount--;
if (!l->tcp_mode &&
sizeof(buf1));
sizeof(buf2));
if (l->tcp_mode) {
if (fail) {
if (!match) {
recvcount++;
&l->querysig);
if (l->msgcounter != 0)
l->msgcounter++;
#ifdef DIG_SIGCHASE
if (!l->sigchase) {
parseflags = 0;
if (l->besteffort) {
hex_dump(b);
cancel_lookup(l);
cancel_lookup(l);
if (l->tcp_mode)
unsigned int local_timeout;
if (timeout == 0) {
if (l->tcp_mode)
NULL,
&l->interval,
#ifdef DIG_SIGCHASE
if (!do_sigchase)
} else if (l->trace) {
if (!l->ns_search_only)
if (!l->trace_root)
} else if (count == 0)
if (l->trace_root) {
#ifdef DIG_SIGCHASE
if (!do_sigchase)
#ifdef DIG_SIGCHASE
if (do_sigchase) {
sizeof(dig_message_t));
link);
isc_buffer_usedregion(b, &r);
sizeof(dig_message_t));
link);
#ifdef DIG_SIGCHASE
if (l->pending)
if (l->doing_xfr) {
if (!docancel)
if (docancel) {
cancel_lookup(l);
#ifdef DIG_SIGCHASE
if (!l->sigchase)
#ifdef DIG_SIGCHASE
if (!do_sigchase)
cancel_lookup(l);
#ifdef DIG_SIGCHASE
if (do_sigchase)
int count;
start_lookup();
cancel_all(void) {
dig_lookup_t *l, *n;
if (free_now) {
while (q != NULL) {
q, current_lookup);
clear_query(q);
q = nq;
while (l != NULL) {
try_clear_lookup(l);
destroy_libs(void) {
#ifdef DIG_SIGCHASE
void * ptr;
#ifdef WITH_IDN
#ifdef WITH_IDN
if (is_dst_up) {
#ifdef DIG_SIGCHASE
#if DIG_SIGCHASE_TD
#if DIG_SIGCHASE_BU
if (memdebugging != 0)
#ifdef WITH_IDN
initialize_idn(void) {
idn_result_t r;
#ifdef HAVE_SETLOCALE
if (r != idn_success)
idn_result_tostring(r));
static isc_result_t
return (ISC_R_SUCCESS);
fromlen++;
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
tolen--;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
static idn_result_t
return idn_success;
return idn_buffer_overflow;
return idn_success;
if (r != idn_success) {
#ifdef DIG_SIGCHASE
isc_region_t r;
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
dump_database(void) {
== ISC_R_SUCCESS)
== ISC_R_SUCCESS)
== ISC_R_SUCCESS)
return (rdataset);
return (rdataset);
return (rdataset);
return (NULL);
int section)
return (rdataset);
return (NULL);
== ISC_R_SUCCESS)
return (rdataset);
== ISC_R_SUCCESS)
rdataset =
return (rdataset);
== ISC_R_SUCCESS)
rdataset =
return (rdataset);
return (NULL);
isc_region_t r;
return (temp);
return (NULL);
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
return (NULL);
return (NULL);
for (i= 0; i < MAX_TRUSTED_KEY; i++) {
char alphnum[] =
int tempnamekeylen;
return (ISC_R_NOMEMORY);
return (result);
int tempnamelen;
int tempnamekeylen;
char *cp;
return (ISC_R_NOMEMORY);
goto cleanup;
cp++;
return (ISC_R_FAILURE);
x = cp--;
x = cp--;
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
*fp = f;
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
filename);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
#if DIG_SIGCHASE_TD
dig_server_t *s;
void *ptr;
while (s != NULL) {
s, lookup);
ptr = s;
#define __FOLLOW_GLUE__
#ifdef __FOLLOW_GLUE__
isc_region_t r;
#ifdef __FOLLOW_GLUE__
dns_rdatatype_any, &true);
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
dns_rdatatype_any, &true);
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
dns_rdata_reset(&a);
return (ISC_R_SUCCESS);
int orderp;
unsigned int nlabelsp;
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_FAILURE);
dns_rdatatype_any, &true);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
isc_region_t r;
isc_buffer_usedregion(b, &r);
isc_buffer_free(&b);
return (ISC_R_FAILURE);
== ISC_TRUE) {
mctx)
== ISC_R_SUCCESS) {
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (result);
return (ISC_R_NOTFOUND);
return (result);
&newdsrdata) == 0) {
mctx);
return (result);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
if (tmplookedup)
return (ISC_R_FAILURE);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
#if DIG_SIGCHASE_TD
== ISC_R_SUCCESS) {
have_answer = true;
&name);
if (have_answer) {
goto cleanandgo;
goto cleanandgo;
if (!delegation_follow) {
mctx);
mctx);
goto cleanandgo;
if (have_response) {
goto cleanandgo;
goto cleanandgo;
&tmp_name);
if (have_response)
goto finalstep;
if (have_delegation_ns) {
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
goto cleanandgo;
#if DIG_SIGCHASE_BU
!= ISC_R_SUCCESS) {
return (ISC_R_ADDRNOTAVAIL);
dns_rdatatype_any, &true);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTFOUND);
dns_rdatatype_ds, &true);
mctx);
int ret;
#if DIG_SIGCHASE_TD
#if DIG_SIGCHASE_BU
unsigned int nblabel1;
unsigned int nblabel2;
int min_lum_label;
if (ret < 0)
else if (ret > 0)
!= ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
== ISC_R_SUCCESS);
return (ISC_R_FAILURE);
return (ISC_R_FAILURE);
return (ret);
!= ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
return (ret);
return (ISC_R_SUCCESS);
return (ret);