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

1714. [bug] dig/host/nslookup were only trying the first

address when a nameserver was specified by name.
                        [RT #12286]
This commit is contained in:
Mark Andrews
2004-09-06 01:24:44 +00:00
parent 4f32995bf6
commit 3f79a8b6f1
6 changed files with 97 additions and 38 deletions

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dig.c,v 1.195 2004/09/03 03:55:20 marka Exp $ */
/* $Id: dig.c,v 1.196 2004/09/06 01:24:42 marka Exp $ */
#include <config.h>
#include <stdlib.h>
@@ -41,6 +41,8 @@
#include <dns/rdataclass.h>
#include <dns/result.h>
#include <bind9/getaddresses.h>
#include <dig/dig.h>
extern ISC_LIST(dig_lookup_t) lookup_list;
@@ -54,6 +56,7 @@ extern ISC_LIST(dig_searchlist_t) search_list;
isc_buffer_putstr(b, s); \
}
#define DIG_MAX_ADDRESSES 20
extern isc_boolean_t have_ipv4, have_ipv6, specified_source,
usesearch, qr;
@@ -83,6 +86,7 @@ extern isc_boolean_t debugging, memdebugging;
static char *batchname = NULL;
static FILE *batchfp = NULL;
static char *argv0;
static int addresscount = 0;
static char domainopt[DNS_NAME_MAXTEXT];
@@ -627,6 +631,15 @@ printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
remaining = sizeof(lookup->cmdline) -
strlen(lookup->cmdline) - 1;
strncat(lookup->cmdline, "\n", remaining);
if (first && addresscount != 0) {
snprintf(append, sizeof(append),
"; (%d server%s found)\n",
addresscount,
addresscount > 1 ? "s" : "");
strncat(lookup->cmdline, append, remaining);
remaining = sizeof(lookup->cmdline) -
strlen(lookup->cmdline) - 1;
}
if (first) {
snprintf(append, sizeof(append),
";; global options: %s %s\n",
@@ -1069,8 +1082,7 @@ static const char *single_dash_opts = "46dhimnv";
static const char *dash_opts = "46bcdfhikmnptvyx";
static isc_boolean_t
dash_option(char *option, char *next, dig_lookup_t **lookup,
isc_boolean_t *open_type_class, isc_boolean_t *firstarg,
int argc, char **argv)
isc_boolean_t *open_type_class)
{
char opt, *value, *ptr;
isc_result_t result;
@@ -1275,10 +1287,6 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
if (!(*lookup)->rdclassset)
(*lookup)->rdclass = dns_rdataclass_in;
(*lookup)->new_search = ISC_TRUE;
if (*lookup && *firstarg) {
printgreeting(argc, argv, *lookup);
*firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, *lookup, link);
} else {
fprintf(stderr, "Invalid IP address %s\n", value);
@@ -1325,13 +1333,36 @@ preparse_args(int argc, char **argv) {
}
}
static void
getaddresses(dig_lookup_t *lookup, const char *host) {
isc_result_t result;
isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES];
isc_netaddr_t netaddr;
unsigned int count, i;
dig_server_t *srv;
char tmp[ISC_NETADDR_FORMATSIZE];
result = bind9_getaddresses(host, 0, sockaddrs,
DIG_MAX_ADDRESSES, &count);
if (result != ISC_R_SUCCESS)
fatal("couldn't get address for '%s': %s",
host, isc_result_totext(result));
for (i = 0; i < count; i++) {
isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]);
isc_netaddr_format(&netaddr, tmp, sizeof(tmp));
srv = make_server(tmp, host);
ISC_LIST_APPEND(lookup->my_server_list, srv, link);
}
addresscount = count;
}
static void
parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
int argc, char **argv) {
isc_result_t result;
isc_textregion_t tr;
isc_boolean_t firstarg = ISC_TRUE;
dig_server_t *srv = NULL;
dig_lookup_t *lookup = NULL;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
@@ -1411,24 +1442,20 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
if (strncmp(rv[0], "%", 1) == 0)
break;
if (strncmp(rv[0], "@", 1) == 0) {
srv = make_server(&rv[0][1]);
ISC_LIST_APPEND(lookup->my_server_list,
srv, link);
getaddresses(lookup, &rv[0][1]);
} else if (rv[0][0] == '+') {
plus_option(&rv[0][1], is_batchfile,
lookup);
} else if (rv[0][0] == '-') {
if (rc <= 1) {
if (dash_option(&rv[0][1], NULL,
&lookup, &open_type_class,
&firstarg, argc, argv)) {
&lookup, &open_type_class)) {
rc--;
rv++;
}
} else {
if (dash_option(&rv[0][1], rv[1],
&lookup, &open_type_class,
&firstarg, argc, argv)) {
&lookup, &open_type_class)) {
rc--;
rv++;
}
@@ -1499,10 +1526,6 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
if (!config_only) {
lookup = clone_lookup(default_lookup,
ISC_TRUE);
if (firstarg) {
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
strncpy(lookup->textname, rv[0],
sizeof(lookup->textname));
lookup->textname[sizeof(lookup->textname)-1]=0;
@@ -1569,6 +1592,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, lookup, link);
} else if (!config_only && firstarg) {
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
}