2
* Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
2
* Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
3
3
* Copyright (C) 2000-2003 Internet Software Consortium.
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.
136
144
" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
137
145
" (Use ixfr=version for type ixfr)\n"
138
146
" q-opt is one of:\n"
139
" -x dot-notation (shortcut for in-addr lookups)\n"
140
" -i (IP6.INT reverse IPv6 lookups)\n"
147
" -x dot-notation (shortcut for reverse lookups)\n"
148
" -i (use IP6.INT for IPv6 reverse lookups)\n"
141
149
" -f filename (batch mode)\n"
142
150
" -b address[#port] (bind to source address/port)\n"
143
151
" -p port (specify port number)\n"
152
" -q name (specify query name)\n"
144
153
" -t type (specify query type)\n"
145
154
" -c class (specify query class)\n"
146
155
" -k keyfile (specify tsig key file)\n"
147
" -y name:key (specify named base64 tsig key)\n"
156
" -y [hmac:]name:key (specify named base64 tsig key)\n"
148
157
" -4 (use IPv4 query transport only)\n"
149
158
" -6 (use IPv6 query transport only)\n"
150
159
" d-opt is of the form +keyword[=value], where keyword is:\n"
220
232
printf(";; WHEN: %s", ctime(&tnow));
221
233
if (query->lookup->doing_xfr) {
222
printf(";; XFR size: %u records (messages %u)\n",
223
query->rr_count, query->msg_count);
234
printf(";; XFR size: %u records (messages %u, "
235
"bytes %" ISC_PRINT_QUADFORMAT "u)\n",
236
query->rr_count, query->msg_count,
225
printf(";; MSG SIZE rcvd: %d\n", bytes);
239
printf(";; MSG SIZE rcvd: %u\n", bytes);
228
242
if (key != NULL) {
237
251
} else if (query->lookup->identify && !short_form) {
238
252
diff = isc_time_microdiff(&now, &query->time_sent);
239
printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
240
bytes, fromtext, query->servname,
253
printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
254
"from %s(%s) in %d ms\n\n",
255
query->lookup->doing_xfr ?
256
query->byte_count : (isc_uint64_t)bytes,
257
fromtext, query->servname,
367
384
else if (nottl || noclass)
368
385
result = dns_master_stylecreate(&style, styleflags,
369
386
24, 24, 32, 40, 80, 8, mctx);
371
388
result = dns_master_stylecreate(&style, styleflags,
372
389
24, 32, 40, 48, 80, 8, mctx);
373
390
check_result(result, "dns_master_stylecreate");
413
430
else if (nottl || noclass)
414
431
result = dns_master_stylecreate(&style, styleflags,
415
432
24, 24, 32, 40, 80, 8, mctx);
417
434
result = dns_master_stylecreate(&style, styleflags,
418
435
24, 32, 40, 48, 80, 8, mctx);
419
436
check_result(result, "dns_master_stylecreate");
629
* Reorder an argument list so that server names all come at the end.
630
* This is a bit of a hack, to allow batch-mode processing to properly
631
* handle the server options.
634
reorder_args(int argc, char *argv[]) {
639
debug("reorder_args()");
641
while (argv[end][0] == '@') {
646
debug("arg[end]=%s", argv[end]);
647
for (i = 1; i < end - 1; i++) {
648
if (argv[i][0] == '@') {
649
debug("arg[%d]=%s", i, argv[i]);
651
for (j = i + 1; j < end; j++) {
652
debug("Moving %s to %d", argv[j], j - 1);
653
argv[j - 1] = argv[j];
655
debug("moving %s to end, %d", ptr, end - 1);
664
654
static isc_uint32_t
665
655
parse_uint(char *arg, const char *desc, isc_uint32_t max) {
666
656
isc_result_t result;
859
861
goto invalid_option;
860
862
ndots = parse_uint(value, "ndots", MAXNDOTS);
862
case 's': /* nssearch */
863
FULLCHECK("nssearch");
864
lookup->ns_search_only = state;
866
lookup->trace_root = ISC_TRUE;
867
lookup->recurse = ISC_TRUE;
868
lookup->identify = ISC_TRUE;
869
lookup->stats = ISC_FALSE;
870
lookup->comments = ISC_FALSE;
871
lookup->section_additional = ISC_FALSE;
872
lookup->section_authority = ISC_FALSE;
873
lookup->section_question = ISC_FALSE;
874
lookup->rdtype = dns_rdatatype_ns;
875
lookup->rdtypeset = ISC_TRUE;
876
short_form = ISC_TRUE;
868
if (state && lookup->edns == -1)
870
lookup->nsid = state;
872
case 's': /* nssearch */
873
FULLCHECK("nssearch");
874
lookup->ns_search_only = state;
876
lookup->trace_root = ISC_TRUE;
877
lookup->recurse = ISC_TRUE;
878
lookup->identify = ISC_TRUE;
879
lookup->stats = ISC_FALSE;
880
lookup->comments = ISC_FALSE;
881
lookup->section_additional = ISC_FALSE;
882
lookup->section_authority = ISC_FALSE;
883
lookup->section_question = ISC_FALSE;
884
lookup->rdtype = dns_rdatatype_ns;
885
lookup->rdtypeset = ISC_TRUE;
886
short_form = ISC_TRUE;
880
894
goto invalid_option;
884
898
switch (cmd[1]) {
885
899
case 'r': /* qr */
928
942
FULLCHECK("search");
929
943
usesearch = state;
931
case 'h': /* short */
935
printcmd = ISC_FALSE;
936
lookup->section_additional = ISC_FALSE;
937
lookup->section_answer = ISC_TRUE;
938
lookup->section_authority = ISC_FALSE;
939
lookup->section_question = ISC_FALSE;
940
lookup->comments = ISC_FALSE;
941
lookup->stats = ISC_FALSE;
949
case 'r': /* short */
953
printcmd = ISC_FALSE;
954
lookup->section_additional = ISC_FALSE;
955
lookup->section_answer = ISC_TRUE;
956
lookup->section_authority = ISC_FALSE;
957
lookup->section_question = ISC_FALSE;
958
lookup->comments = ISC_FALSE;
959
lookup->stats = ISC_FALSE;
962
case 'w': /* showsearch */
963
FULLCHECK("showsearch");
944
971
#ifdef DIG_SIGCHASE
945
972
case 'i': /* sigchase */
946
FULLCHECK("sigchase");
973
FULLCHECK("sigchase");
947
974
lookup->sigchase = state;
948
975
if (lookup->sigchase)
949
976
lookup->dnssec = ISC_TRUE;
952
979
case 't': /* stats */
953
980
FULLCHECK("stats");
1051
* ISC_TRUE returned if value was used
1078
* #ISC_TRUE returned if value was used
1053
1080
static const char *single_dash_opts = "46dhimnv";
1054
1081
static const char *dash_opts = "46bcdfhikmnptvyx";
1055
1082
static isc_boolean_t
1056
1083
dash_option(char *option, char *next, dig_lookup_t **lookup,
1057
isc_boolean_t *open_type_class)
1084
isc_boolean_t *open_type_class, isc_boolean_t *need_clone,
1085
isc_boolean_t config_only, int argc, char **argv,
1086
isc_boolean_t *firstarg)
1059
char opt, *value, *ptr;
1088
char opt, *value, *ptr, *ptr2, *ptr3;
1060
1089
isc_result_t result;
1061
1090
isc_boolean_t value_from_next;
1062
1091
isc_textregion_t tr;
1190
1219
port = (in_port_t) parse_uint(value, "port number", MAXPORT);
1191
1220
return (value_from_next);
1224
(*lookup) = clone_lookup(default_lookup,
1226
*need_clone = ISC_TRUE;
1227
strncpy((*lookup)->textname, value,
1228
sizeof((*lookup)->textname));
1229
(*lookup)->textname[sizeof((*lookup)->textname)-1]=0;
1230
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
1231
(*lookup)->ns_search_only);
1232
(*lookup)->new_search = ISC_TRUE;
1234
printgreeting(argc, argv, *lookup);
1235
*firstarg = ISC_FALSE;
1237
ISC_LIST_APPEND(lookup_list, (*lookup), link);
1238
debug("looking up %s", (*lookup)->textname);
1240
return (value_from_next);
1193
1242
*open_type_class = ISC_FALSE;
1194
1243
if (strncasecmp(value, "ixfr=", 5) == 0) {
1233
1283
return (value_from_next);
1235
ptr = next_token(&value,":");
1285
ptr = next_token(&value,":"); /* hmac type or name */
1236
1286
if (ptr == NULL) {
1289
ptr2 = next_token(&value, ":"); /* name or secret */
1292
ptr3 = next_token(&value,":"); /* secret or NULL */
1294
if (strcasecmp(ptr, "hmac-md5") == 0) {
1295
hmacname = DNS_TSIG_HMACMD5_NAME;
1297
} else if (strncasecmp(ptr, "hmac-md5-", 9) == 0) {
1298
hmacname = DNS_TSIG_HMACMD5_NAME;
1299
digestbits = parse_uint(&ptr[9],
1300
"digest-bits [0..128]",
1302
digestbits = (digestbits + 7) & ~0x7U;
1303
} else if (strcasecmp(ptr, "hmac-sha1") == 0) {
1304
hmacname = DNS_TSIG_HMACSHA1_NAME;
1306
} else if (strncasecmp(ptr, "hmac-sha1-", 10) == 0) {
1307
hmacname = DNS_TSIG_HMACSHA1_NAME;
1308
digestbits = parse_uint(&ptr[10],
1309
"digest-bits [0..160]",
1311
digestbits = (digestbits + 7) & ~0x7U;
1312
} else if (strcasecmp(ptr, "hmac-sha224") == 0) {
1313
hmacname = DNS_TSIG_HMACSHA224_NAME;
1315
} else if (strncasecmp(ptr, "hmac-sha224-", 12) == 0) {
1316
hmacname = DNS_TSIG_HMACSHA224_NAME;
1317
digestbits = parse_uint(&ptr[12],
1318
"digest-bits [0..224]",
1320
digestbits = (digestbits + 7) & ~0x7U;
1321
} else if (strcasecmp(ptr, "hmac-sha256") == 0) {
1322
hmacname = DNS_TSIG_HMACSHA256_NAME;
1324
} else if (strncasecmp(ptr, "hmac-sha256-", 12) == 0) {
1325
hmacname = DNS_TSIG_HMACSHA256_NAME;
1326
digestbits = parse_uint(&ptr[12],
1327
"digest-bits [0..256]",
1329
digestbits = (digestbits + 7) & ~0x7U;
1330
} else if (strcasecmp(ptr, "hmac-sha384") == 0) {
1331
hmacname = DNS_TSIG_HMACSHA384_NAME;
1333
} else if (strncasecmp(ptr, "hmac-sha384-", 12) == 0) {
1334
hmacname = DNS_TSIG_HMACSHA384_NAME;
1335
digestbits = parse_uint(&ptr[12],
1336
"digest-bits [0..384]",
1338
digestbits = (digestbits + 7) & ~0x7U;
1339
} else if (strcasecmp(ptr, "hmac-sha512") == 0) {
1340
hmacname = DNS_TSIG_HMACSHA512_NAME;
1342
} else if (strncasecmp(ptr, "hmac-sha512-", 12) == 0) {
1343
hmacname = DNS_TSIG_HMACSHA512_NAME;
1344
digestbits = parse_uint(&ptr[12],
1345
"digest-bits [0..512]",
1347
digestbits = (digestbits + 7) & ~0x7U;
1349
fprintf(stderr, ";; Warning, ignoring "
1350
"invalid TSIG algorithm %s\n", ptr);
1351
return (value_from_next);
1356
hmacname = DNS_TSIG_HMACMD5_NAME;
1239
1359
strncpy(keynametext, ptr, sizeof(keynametext));
1240
1360
keynametext[sizeof(keynametext)-1]=0;
1241
ptr = next_token(&value, "");
1244
strncpy(keysecret, ptr, sizeof(keysecret));
1361
strncpy(keysecret, ptr2, sizeof(keysecret));
1245
1362
keysecret[sizeof(keysecret)-1]=0;
1246
1363
return (value_from_next);
1248
*lookup = clone_lookup(default_lookup, ISC_TRUE);
1366
*lookup = clone_lookup(default_lookup, ISC_TRUE);
1367
*need_clone = ISC_TRUE;
1249
1368
if (get_reverse(textname, sizeof(textname), value,
1250
1369
ip6_int, ISC_FALSE) == ISC_R_SUCCESS) {
1251
1370
strncpy((*lookup)->textname, textname,
1421
1554
} else if (rv[0][0] == '-') {
1423
1556
if (dash_option(&rv[0][1], NULL,
1424
&lookup, &open_type_class)) {
1557
&lookup, &open_type_class,
1558
&need_clone, config_only,
1559
argc, argv, &firstarg)) {
1429
1564
if (dash_option(&rv[0][1], rv[1],
1430
&lookup, &open_type_class)) {
1565
&lookup, &open_type_class,
1566
&need_clone, config_only,
1567
argc, argv, &firstarg)) {
1498
1637
if (!config_only) {
1499
lookup = clone_lookup(default_lookup,
1501
strncpy(lookup->textname, rv[0],
1639
lookup = clone_lookup(default_lookup,
1641
need_clone = ISC_TRUE;
1642
strncpy(lookup->textname, rv[0],
1502
1643
sizeof(lookup->textname));
1503
1644
lookup->textname[sizeof(lookup->textname)-1]=0;
1504
1645
lookup->trace_root = ISC_TF(lookup->trace ||
1505
1646
lookup->ns_search_only);
1506
1647
lookup->new_search = ISC_TRUE;
1649
printgreeting(argc, argv, lookup);
1650
firstarg = ISC_FALSE;
1507
1652
ISC_LIST_APPEND(lookup_list, lookup, link);
1508
1653
debug("looking up %s", lookup->textname);
1510
1655
/* XXX Error message */
1514
1660
* If we have a batchfile, seed the lookup list with the
1515
1661
* first entry, then trust the callback in dighost_shutdown
1544
1690
bargv[0] = argv[0];
1545
1691
argv0 = argv[0];
1547
reorder_args(bargc, (char **)bargv);
1693
for(i = 0; i < bargc; i++)
1694
debug("batch argv %d: %s", i, bargv[i]);
1548
1695
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
1552
1701
* If no lookup specified, search for root
1554
1703
if ((lookup_list.head == NULL) && !config_only) {
1555
lookup = clone_lookup(default_lookup, ISC_TRUE);
1705
lookup = clone_lookup(default_lookup, ISC_TRUE);
1706
need_clone = ISC_TRUE;
1556
1707
lookup->trace_root = ISC_TF(lookup->trace ||
1557
1708
lookup->ns_search_only);
1558
1709
lookup->new_search = ISC_TRUE;