~andreserl/ubuntu/lucid/bind9/bind9-apport-533601

« back to all changes in this revision

Viewing changes to bin/dig/host.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, LaMont Jones, Internet Software Consortium, Inc, localization folks
  • Date: 2008-08-02 14:20:20 UTC
  • mfrom: (1.2.1 upstream) (6.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080802142020-l1hon9jy8lbbjxmg
[LaMont Jones]

* default to using resolvconf if it is installed
* fix sonames and dependencies.  Closes: #149259, #492418
* Do not build-depend libcap2-dev on non-linux.  Closes: #493392
* drop unused query-loc manpage.  Closes: #492564
* lwresd: Deliver /etc/bind directory.  Closes: #490027
* fix query-source comment in default install

[Internet Software Consortium, Inc]

* 9.5.0-P2.  Closes: #492949

[localization folks]

* l10n: Spanish debconf translation.  Closes: #492425 (Ignacio Mondino)
* l10n: Swedish debconf templates.  Closes: #491369 (Martin Ågren)
* l10n: Japanese debconf translations.  Closes: #492048 (Hideki Yamane
  (Debian-JP))
* l10n: Finnish translation.  Closes: #490630 (Esko Arajärvi)
* l10n: Italian debconf translations.  Closes: #492587 (Alessandro Vietta)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
 
2
 * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3
3
 * Copyright (C) 2000-2003  Internet Software Consortium.
4
4
 *
5
 
 * Permission to use, copy, modify, and distribute this software for any
 
5
 * Permission to use, copy, modify, and/or distribute this software for any
6
6
 * purpose with or without fee is hereby granted, provided that the above
7
7
 * copyright notice and this permission notice appear in all copies.
8
8
 *
15
15
 * PERFORMANCE OF THIS SOFTWARE.
16
16
 */
17
17
 
18
 
/* $Id: host.c,v 1.76.2.5.2.13 2005/07/04 03:29:45 marka Exp $ */
 
18
/* $Id: host.c,v 1.116 2007/12/03 00:21:48 marka Exp $ */
 
19
 
 
20
/*! \file */
19
21
 
20
22
#include <config.h>
 
23
#include <stdlib.h>
21
24
#include <limits.h>
22
25
 
 
26
#ifdef HAVE_LOCALE_H
 
27
#include <locale.h>
 
28
#endif
 
29
 
 
30
#ifdef WITH_IDN
 
31
#include <idn/result.h>
 
32
#include <idn/log.h>
 
33
#include <idn/resconf.h>
 
34
#include <idn/api.h>
 
35
#endif
 
36
 
23
37
#include <isc/app.h>
24
38
#include <isc/commandline.h>
25
39
#include <isc/netaddr.h>
37
51
#include <dns/rdataclass.h>
38
52
#include <dns/rdataset.h>
39
53
#include <dns/rdatatype.h>
 
54
#include <dns/rdatastruct.h>
40
55
 
41
56
#include <dig/dig.h>
42
57
 
45
60
static int seen_error = -1;
46
61
static isc_boolean_t list_addresses = ISC_TRUE;
47
62
static dns_rdatatype_t list_type = dns_rdatatype_a;
 
63
static isc_boolean_t printed_server = ISC_FALSE;
48
64
 
49
65
static const char *opcodetext[] = {
50
66
        "QUERY",
112
128
show_usage(void) {
113
129
        fputs(
114
130
"Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]\n"
115
 
"            [-R number] hostname [server]\n"
116
 
"       -a is equivalent to -v -t *\n"
 
131
"            [-R number] [-m flag] hostname [server]\n"
 
132
"       -a is equivalent to -v -t ANY\n"
117
133
"       -c specifies query class for non-IN data\n"
118
134
"       -C compares SOA records on authoritative nameservers\n"
119
135
"       -d is equivalent to -v\n"
122
138
"       -N changes the number of dots allowed before root lookup is done\n"
123
139
"       -r disables recursive processing\n"
124
140
"       -R specifies number of retries for UDP packets\n"
 
141
"       -s a SERVFAIL response should stop query\n"
125
142
"       -t specifies the query type\n"
126
143
"       -T enables TCP/IP mode\n"
127
144
"       -v enables verbose output\n"
128
145
"       -w specifies to wait forever for a reply\n"
129
146
"       -W specifies how long to wait for a reply\n"
130
147
"       -4 use IPv4 query transport only\n"
131
 
"       -6 use IPv6 query transport only\n", stderr);
 
148
"       -6 use IPv6 query transport only\n"
 
149
"       -m set memory debugging flag (trace|record|usage)\n", stderr);
132
150
        exit(1);
133
151
}
134
152
 
351
369
        return (ISC_R_SUCCESS);
352
370
}
353
371
 
 
372
static void
 
373
chase_cnamechain(dns_message_t *msg, dns_name_t *qname) {
 
374
        isc_result_t result;
 
375
        dns_rdataset_t *rdataset;
 
376
        dns_rdata_cname_t cname;
 
377
        dns_rdata_t rdata = DNS_RDATA_INIT;
 
378
        unsigned int i = msg->counts[DNS_SECTION_ANSWER];
 
379
 
 
380
        while (i-- > 0) {
 
381
                rdataset = NULL;
 
382
                result = dns_message_findname(msg, DNS_SECTION_ANSWER, qname,
 
383
                                              dns_rdatatype_cname, 0, NULL,
 
384
                                              &rdataset);
 
385
                if (result != ISC_R_SUCCESS)
 
386
                        return;
 
387
                result = dns_rdataset_first(rdataset);
 
388
                check_result(result, "dns_rdataset_first");
 
389
                dns_rdata_reset(&rdata);
 
390
                dns_rdataset_current(rdataset, &rdata);
 
391
                result = dns_rdata_tostruct(&rdata, &cname, NULL);
 
392
                check_result(result, "dns_rdata_tostruct");
 
393
                dns_name_copy(&cname.cname, qname, NULL);
 
394
                dns_rdata_freestruct(&cname);
 
395
        }
 
396
}
 
397
 
354
398
isc_result_t
355
399
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
356
400
        isc_boolean_t did_flag = ISC_FALSE;
367
411
         */
368
412
        force_error = (seen_error == 1) ? 1 : 0;
369
413
        seen_error = 1;
370
 
        if (listed_server) {
 
414
        if (listed_server && !printed_server) {
371
415
                char sockstr[ISC_SOCKADDR_FORMATSIZE];
372
416
 
373
417
                printf("Using domain server:\n");
376
420
                                    sizeof(sockstr));
377
421
                printf("Address: %s\n", sockstr);
378
422
                printf("Aliases: \n\n");
 
423
                printed_server = ISC_TRUE;
379
424
        }
380
425
 
381
426
        if (msg->rcode != 0) {
382
427
                char namestr[DNS_NAME_FORMATSIZE];
383
428
                dns_name_format(query->lookup->name, namestr, sizeof(namestr));
384
 
                printf("Host %s not found: %d(%s)\n", namestr,
385
 
                       msg->rcode, rcodetext[msg->rcode]);
 
429
                printf("Host %s not found: %d(%s)\n",
 
430
                       (msg->rcode != dns_rcode_nxdomain) ? namestr :
 
431
                       query->lookup->textname, msg->rcode,
 
432
                       rcodetext[msg->rcode]);
386
433
                return (ISC_R_SUCCESS);
387
434
        }
388
435
 
389
436
        if (default_lookups && query->lookup->rdtype == dns_rdatatype_a) {
390
437
                char namestr[DNS_NAME_FORMATSIZE];
391
438
                dig_lookup_t *lookup;
 
439
                dns_fixedname_t fixed;
 
440
                dns_name_t *name;
392
441
 
393
442
                /* Add AAAA and MX lookups. */
394
 
 
395
 
                dns_name_format(query->lookup->name, namestr, sizeof(namestr));
 
443
                dns_fixedname_init(&fixed);
 
444
                name = dns_fixedname_name(&fixed);
 
445
                dns_name_copy(query->lookup->name, name, NULL);
 
446
                chase_cnamechain(msg, name);
 
447
                dns_name_format(name, namestr, sizeof(namestr));
396
448
                lookup = clone_lookup(query->lookup, ISC_FALSE);
397
449
                if (lookup != NULL) {
398
450
                        strncpy(lookup->textname, namestr,
522
574
        return (result);
523
575
}
524
576
 
 
577
static const char * optstring = "46ac:dilnm:rst:vwCDN:R:TW:";
 
578
 
 
579
static void
 
580
pre_parse_args(int argc, char **argv) {
 
581
        int c;
 
582
 
 
583
        while ((c = isc_commandline_parse(argc, argv, optstring)) != -1) {
 
584
                switch (c) {
 
585
                case 'm':
 
586
                        memdebugging = ISC_TRUE;
 
587
                        if (strcasecmp("trace", isc_commandline_argument) == 0)
 
588
                                isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
 
589
                        else if (!strcasecmp("record",
 
590
                                             isc_commandline_argument) == 0)
 
591
                                isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
 
592
                        else if (strcasecmp("usage",
 
593
                                            isc_commandline_argument) == 0)
 
594
                                isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
 
595
                        break;
 
596
 
 
597
                case '4': break;
 
598
                case '6': break;
 
599
                case 'a': break;
 
600
                case 'c': break;
 
601
                case 'd': break;
 
602
                case 'i': break;
 
603
                case 'l': break;
 
604
                case 'n': break;
 
605
                case 'r': break;
 
606
                case 's': break;
 
607
                case 't': break;
 
608
                case 'v': break;
 
609
                case 'w': break;
 
610
                case 'C': break;
 
611
                case 'D': break;
 
612
                case 'N': break;
 
613
                case 'R': break;
 
614
                case 'T': break;
 
615
                case 'W': break;
 
616
                default:
 
617
                        show_usage();
 
618
                }
 
619
        }
 
620
        isc_commandline_reset = ISC_TRUE;
 
621
        isc_commandline_index = 1;
 
622
}
 
623
 
525
624
static void
526
625
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
527
626
        char hostname[MXNAME];
538
637
 
539
638
        lookup = make_empty_lookup();
540
639
 
541
 
        while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:Dni46"))
542
 
               != EOF) {
 
640
        lookup->servfail_stops = ISC_FALSE;
 
641
        lookup->comments = ISC_FALSE;
 
642
 
 
643
        while ((c = isc_commandline_parse(argc, argv, optstring)) != -1) {
543
644
                switch (c) {
544
645
                case 'l':
545
646
                        lookup->tcp_mode = ISC_TRUE;
578
679
                            lookup->rdtype != dns_rdatatype_axfr)
579
680
                                lookup->rdtype = rdtype;
580
681
                        lookup->rdtypeset = ISC_TRUE;
 
682
#ifdef WITH_IDN
 
683
                        idnoptions = 0;
 
684
#endif
581
685
                        if (rdtype == dns_rdatatype_axfr) {
582
686
                                /* -l -t any -v */
583
687
                                list_type = dns_rdatatype_any;
585
689
                                lookup->tcp_mode = ISC_TRUE;
586
690
                        } else if (rdtype == dns_rdatatype_ixfr) {
587
691
                                lookup->ixfr_serial = serial;
588
 
                                list_type = rdtype;
 
692
                                lookup->tcp_mode = ISC_TRUE;
 
693
                                list_type = rdtype;
 
694
#ifdef WITH_IDN
 
695
                        } else if (rdtype == dns_rdatatype_a ||
 
696
                                   rdtype == dns_rdatatype_aaaa ||
 
697
                                   rdtype == dns_rdatatype_mx) {
 
698
                                idnoptions = IDN_ASCCHECK;
 
699
                                list_type = rdtype;
 
700
#endif
589
701
                        } else
590
702
                                list_type = rdtype;
591
703
                        list_addresses = ISC_FALSE;
623
735
                case 'n':
624
736
                        /* deprecated */
625
737
                        break;
 
738
                case 'm':
 
739
                        /* Handled by pre_parse_args(). */
 
740
                        break;
626
741
                case 'w':
627
742
                        /*
628
743
                         * The timer routines are coded such that
676
791
                        } else
677
792
                                fatal("can't find IPv6 networking");
678
793
                        break;
 
794
                case 's':
 
795
                        lookup->servfail_stops = ISC_TRUE;
 
796
                        break;
679
797
                }
680
798
        }
681
799
 
690
808
                set_nameserver(argv[isc_commandline_index+1]);
691
809
                debug("server is %s", argv[isc_commandline_index+1]);
692
810
                listed_server = ISC_TRUE;
693
 
        }
 
811
        } else
 
812
                check_ra = ISC_TRUE;
694
813
 
695
814
        lookup->pending = ISC_FALSE;
696
815
        if (get_reverse(store, sizeof(store), hostname,
721
840
        ISC_LIST_INIT(search_list);
722
841
        
723
842
        fatalexit = 1;
 
843
#ifdef WITH_IDN
 
844
        idnoptions = IDN_ASCCHECK;
 
845
#endif
724
846
 
725
847
        debug("main()");
726
848
        progname = argv[0];
 
849
        pre_parse_args(argc, argv);
727
850
        result = isc_app_start();
728
851
        check_result(result, "isc_app_start");
729
852
        setup_libs();
737
860
        isc_app_finish();
738
861
        return ((seen_error == 0) ? 0 : 1);
739
862
}
740