1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
|
/*
* Copyright (c) 1985, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char Version[] = "@(#)info.c e07@nikhef.nl (Eric Wassenaar) 991527";
#endif
#include "host.h"
#include "glob.h"
/*
** GET_HOSTINFO -- Principal routine to query about given name
** -----------------------------------------------------------
**
** Returns:
** TRUE if requested info was obtained successfully.
** FALSE otherwise.
**
** This is the equivalent of the resolver module res_search().
**
** In this program RES_DEFNAMES is always on, and RES_DNSRCH
** is off by default. This means that single names without dot
** are always, and only, tried within the own default domain,
** and compound names are assumed to be already fully qualified.
**
** The default BIND behavior can be simulated by turning on
** RES_DNSRCH with -R. The given name, whether or not compound,
** is then first tried within the possible search domains.
**
** Note. In the latter case, the search terminates in case the
** specified name exists but does not have the desired type.
** The BIND behavior is to continue the search. This can be
** simulated with the undocumented option -B.
*/
bool
get_hostinfo(name, qualified)
input char *name; /* name to query about */
input bool qualified; /* assume fully qualified if set */
{
register char **domain;
register char *cp;
int dot; /* number of dots in query name */
bool result; /* result status of action taken */
char oldnamebuf[2*MAXDNAME+2];
char *oldname; /* saved actual name when NO_DATA */
int nodata = 0; /* NO_DATA status during DNSRCH */
int nquery = 0; /* number of extra search queries */
/*
* Single dot means root zone.
*/
if (sameword(name, "."))
qualified = TRUE;
/*
* Names known to be fully qualified are just tried ``as is''.
*/
if (qualified)
{
result = get_domaininfo(name, (char *)NULL);
return(result);
}
/*
* Count number of dots. Move to the end of the name.
*/
for (dot = 0, cp = name; *cp != '\0'; cp++)
if (*cp == '.')
dot++;
/*
* Check for aliases of single name.
* Note that the alias is supposed to be fully qualified.
*/
if (dot == 0 && (cp = (char *)hostalias(name)) != NULL)
{
if (verbose)
printf("Aliased %s to %s\n", name, cp);
result = get_domaininfo(cp, (char *)NULL);
return(result);
}
/*
* Trailing dot means absolute (fully qualified) address.
*/
if (dot != 0 && cp[-1] == '.')
{
cp[-1] = '\0';
result = get_domaininfo(name, (char *)NULL);
cp[-1] = '.';
return(result);
}
/*
* Append own default domain and other search domains if appropriate.
*/
if ((dot == 0 && bitset(RES_DEFNAMES, _res.options)) ||
(dot != 0 && bitset(RES_DNSRCH, _res.options)))
{
for (domain = _res.dnsrch; *domain; domain++)
{
result = get_domaininfo(name, *domain);
if (result)
return(result);
/* keep count of extra search queries */
nquery++;
/* in case nameserver not present */
if (errno == ECONNREFUSED)
return(FALSE);
/* if no further search desired (single name) */
if (!bitset(RES_DNSRCH, _res.options))
break;
/* if name exists but has not requested type */
if (h_errno == NO_DATA || h_errno == NO_RREC)
{
if (bindcompat)
{
/* remember status and search up */
oldname = strcpy(oldnamebuf, realname);
nodata = h_errno;
continue;
}
return(FALSE);
}
/* retry only if name does not exist at all */
if (h_errno != HOST_NOT_FOUND && h_errno != NO_HOST)
break;
}
}
/*
* Single name lookup failed.
*/
if (dot == 0)
{
/* unclear what actual name should be */
if (nquery != 1)
realname = NULL;
/* restore nodata status from search */
if (bindcompat && nodata)
{
realname = strcpy(realnamebuf, oldname);
seth_errno(nodata);
}
/* set status in case we never queried */
if (!bitset(RES_DEFNAMES, _res.options))
seth_errno(HOST_NOT_FOUND);
return(FALSE);
}
/*
* Rest means fully qualified.
*/
result = get_domaininfo(name, (char *)NULL);
/* restore nodata status from search */
if (!result && bindcompat && nodata)
{
realname = strcpy(realnamebuf, oldname);
seth_errno(nodata);
}
return(result);
}
/*
** GET_DOMAININFO -- Fetch and print desired info about name in domain
** -------------------------------------------------------------------
**
** Returns:
** TRUE if requested info was obtained successfully.
** FALSE otherwise.
**
** Side effects:
** Sets global variable ``realname'' to actual name queried.
**
** This is the equivalent of the resolver module res_querydomain().
**
** Things get a little complicated in case RES_DNSRCH is on.
** If we get an answer but the data is corrupted, an error will be
** returned and NO_RECOVERY will be set. This will terminate the
** extra search loop, but a compound name will still be tried as-is.
** The same holds if the query times out or we have a server failure,
** in which case an error will be returned and TRY_AGAIN will be set.
** For now we take this for granted. Normally RES_DNSRCH is disabled.
** In this default case we do only one query and we have no problem.
*/
bool
get_domaininfo(name, domain)
input char *name; /* name to query about */
input char *domain; /* domain to which name is relative */
{
char namebuf[2*MAXDNAME+2]; /* buffer to store full domain name */
querybuf answer;
register int n;
bool result; /* result status of action taken */
/*
* Show what we are about to query.
*/
if (verbose)
{
if (domain == NULL || domain[0] == '\0')
printf("Trying %s", name);
else
printf("Trying %s within %s", name, domain);
if (server && (verbose > 1))
printf(" at server %s", server);
printf(" ...\n");
}
/*
* Construct the actual domain name.
* A null domain means the given name is already fully qualified.
* If the composite name is too long, res_mkquery() will fail.
*/
if (domain == NULL || domain[0] == '\0')
(void) sprintf(namebuf, "%.*s", MAXDNAME, name);
else
(void) sprintf(namebuf, "%.*s.%.*s",
MAXDNAME, name, MAXDNAME, domain);
name = namebuf;
/*
* Fetch the desired info.
*/
n = get_info(&answer, name, querytype, queryclass);
result = (n < 0) ? FALSE : TRUE;
/* may have extra information on negative answers */
if (n < 0 && n != -1)
n = -n;
/*
* Print the relevant data.
* If we got a positive answer, the data may still be corrupted.
*/
if (n > 0 && !print_info(&answer, n, name, querytype, queryclass, TRUE))
result = FALSE;
/*
* Remember the actual name that was queried.
* Must be at the end to avoid clobbering during recursive calls.
*/
realname = strcpy(realnamebuf, name);
return(result);
}
/*
** GET_INFO -- Basic routine to issue a nameserver query
** -----------------------------------------------------
**
** Returns:
** Real length of answer buffer, if obtained. Negative length if
** query failed, or -1 if no answer (h_errno is set appropriately).
**
** This is the equivalent of the resolver module res_query().
*/
int
get_info(answerbuf, name, type, class)
output querybuf *answerbuf; /* location of buffer to store answer */
input char *name; /* full name to query about */
input int type; /* specific resource record type */
input int class; /* specific resource record class */
{
querybuf query;
HEADER *bp;
int ancount;
register int n;
/*
* Construct query, and send it to the nameserver.
* res_send() will fail if no nameserver responded. In the BIND version the
* possible values for errno are ECONNREFUSED and ETIMEDOUT. If we did get
* an answer, errno should be reset, since res_send() may have left an errno
* in case it has used datagrams. Our private version of res_send() will leave
* also other error statuses, and will clear errno if an answer was obtained.
*/
seterrno(0); /* reset before querying nameserver */
n = res_mkquery(QUERY, name, class, type, (qbuf_t *)NULL, 0,
(rrec_t *)NULL, (qbuf_t *)&query, sizeof(querybuf));
if (n < 0)
{
if (debug)
printf("%sres_mkquery failed\n", dbprefix);
seth_errno(NO_RECOVERY);
return(-1);
}
n = res_send((qbuf_t *)&query, n, (qbuf_t *)answerbuf, sizeof(querybuf));
if (n < 0)
{
if (debug)
printf("%sres_send failed\n", dbprefix);
seth_errno(TRY_AGAIN);
return(-1);
}
seterrno(0); /* reset after we got an answer */
if (n < HFIXEDSZ)
{
pr_error("answer length %s too short after %s query for %s",
dtoa(n), pr_type(type), name);
seth_errno(NO_RECOVERY);
return(-1);
}
/*
* Analyze the status of the answer from the nameserver.
*/
if ((verbose > print_level) || debug)
print_answer(answerbuf, n);
bp = (HEADER *)answerbuf;
ancount = ntohs((u_short)bp->ancount);
if (bp->rcode != NOERROR || ancount == 0)
{
switch (bp->rcode)
{
case NXDOMAIN:
/* distinguish between authoritative or not */
seth_errno(bp->aa ? HOST_NOT_FOUND : NO_HOST);
break;
case NOERROR:
/* distinguish between authoritative or not */
seth_errno(bp->aa ? NO_DATA : NO_RREC);
break;
case SERVFAIL:
seth_errno(SERVER_FAILURE); /* instead of TRY_AGAIN */
break;
case REFUSED:
seth_errno(QUERY_REFUSED); /* instead of NO_RECOVERY */
break;
default:
seth_errno(NO_RECOVERY); /* FORMERR NOTIMP NOCHANGE */
break;
}
n = querysize(n);
return(-n);
}
/* valid answer received, avoid buffer overrun */
seth_errno(0);
n = querysize(n);
return(n);
}
/*
** PRINT_INFO -- Check resource records in answer and print relevant data
** ----------------------------------------------------------------------
**
** Returns:
** TRUE if answer buffer was processed successfully.
** FALSE otherwise.
**
** Side effects:
** Will recurse on MAILB records if appropriate.
** See also side effects of the print_rrec() routine.
*/
bool
print_info(answerbuf, answerlen, name, type, class, regular)
input querybuf *answerbuf; /* location of answer buffer */
input int answerlen; /* length of answer buffer */
input char *name; /* full name we are querying about */
input int type; /* record type we are querying about */
input int class; /* record class we are querying about */
input bool regular; /* set if this is a regular lookup */
{
HEADER *bp;
int qdcount, ancount, nscount, arcount;
u_char *msg, *eom;
register u_char *cp;
bp = (HEADER *)answerbuf;
qdcount = ntohs((u_short)bp->qdcount);
ancount = ntohs((u_short)bp->ancount);
nscount = ntohs((u_short)bp->nscount);
arcount = ntohs((u_short)bp->arcount);
msg = (u_char *)answerbuf;
eom = (u_char *)answerbuf + answerlen;
cp = (u_char *)answerbuf + HFIXEDSZ;
/*
* Skip the query section in the response (present only in normal queries).
*/
if (qdcount)
{
while (qdcount > 0 && cp < eom) /* process all records */
{
cp = skip_qrec(name, type, class, cp, msg, eom);
if (cp == NULL)
return(FALSE);
qdcount--;
}
if (qdcount)
{
pr_error("invalid qdcount after %s query for %s",
pr_type(type), name);
seth_errno(NO_RECOVERY);
return(FALSE);
}
}
/*
* Process the actual answer section in the response.
* During zone transfers, this is the only section available.
*/
if (ancount)
{
if ((type != T_AXFR) && verbose && !bp->aa)
printf("The following answer is not authoritative:\n");
while (ancount > 0 && cp < eom)
{
/* reset for each record during zone listings */
soaname = NULL, subname = NULL, adrname = NULL, address = 0;
print_level++;
cp = print_rrec(name, type, class, cp, msg, eom, regular);
print_level--;
if (cp == NULL)
return(FALSE);
ancount--;
/* update zone information during zone listings */
if (type == T_AXFR)
update_zone(name);
/* we trace down CNAME chains ourselves */
if (regular && !verbose && cname)
return(TRUE);
/* recursively expand MR/MG records into MB records */
if (regular && mailmode && mname)
(void) get_recursive(&mname);
}
if (ancount)
{
pr_error("invalid ancount after %s query for %s",
pr_type(type), name);
seth_errno(NO_RECOVERY);
return(FALSE);
}
}
/*
* The nameserver and additional info section are normally not processed.
* Both sections shouldn't exist in zone transfers.
*/
if (!verbose || exclusive)
return(TRUE);
if (nscount)
{
printf("Authority information:\n");
while (nscount > 0 && cp < eom)
{
print_level++;
cp = print_rrec(name, type, class, cp, msg, eom, FALSE);
print_level--;
if (cp == NULL)
return(FALSE);
nscount--;
}
if (nscount)
{
pr_error("invalid nscount after %s query for %s",
pr_type(type), name);
seth_errno(NO_RECOVERY);
return(FALSE);
}
}
if (arcount)
{
printf("Additional information:\n");
while (arcount > 0 && cp < eom)
{
print_level++;
cp = print_rrec(name, type, class, cp, msg, eom, FALSE);
print_level--;
if (cp == NULL)
return(FALSE);
arcount--;
}
if (arcount)
{
pr_error("invalid arcount after %s query for %s",
pr_type(type), name);
seth_errno(NO_RECOVERY);
return(FALSE);
}
}
/* all sections were processed successfully */
return(TRUE);
}
/*
** PRINT_DATA -- Output resource record data if this record is wanted
** ------------------------------------------------------------------
**
** Returns:
** None.
**
** Inputs:
** The global variable ``doprint'' is set by print_rrec()
** if we need to print the data.
*/
static bool doprint; /* indicates whether or not to print */
void /*VARARGS1*/
print_data(fmt, a, b, c, d)
input char *fmt; /* format of message */
input char *a, *b, *c, *d; /* optional arguments */
{
/* if (doprint) */
{
if (!suppress)
printf(fmt, a, b, c, d);
if (logfile != NULL)
(void) fprintf(logfile, fmt, a, b, c, d);
}
}
#define doprintf(x)\
{\
if (doprint)\
{\
print_data x ;\
}\
}
/*
** PRINT_RREC -- Decode single resource record and output relevant data
** --------------------------------------------------------------------
**
** Returns:
** Pointer to position in answer buffer after current record.
** NULL if there was a format error in the current record.
**
** Outputs:
** Sets ``doprint'' appropriately for use by print_data().
**
** Side effects:
** Updates resource record statistics in record_stats[].
** Sets ``soaname'' if this is an SOA record.
** Sets ``subname'' if this is an NS record.
** Sets ``adrname'' if this is an A record.
** Sets ``address'' if this is an A record.
** Sets ``cname'' if this is a valid CNAME record.
** Sets ``mname'' if this is a valid MAILB record.
** These variables must have been cleared before calling
** print_info() and may be checked afterwards.
*/
/* print domain names after certain conversions */
#define pr_name(x) pr_domain(x, listing)
/* check the LHS record name of these records for invalid characters */
#define test_valid(t) (((t == T_A) && !reverse) || t == T_MX || t == T_AAAA)
/* check the RHS domain name of these records for canonical host names */
#define test_canon(t) (t == T_NS || t == T_MX)
/* an ordinary PTR record in a reverse zone */
#define test_ptr(t,s) (((t == T_PTR) && reverse) && !zeroname(s))
/* an ordinary A record in a forward zone */
#define test_adr(t,a) (((t == T_A) && !reverse) && !fakeaddr(a))
u_char *
print_rrec(name, qtype, qclass, cp, msg, eom, regular)
input char *name; /* full name we are querying about */
input int qtype; /* record type we are querying about */
input int qclass; /* record class we are querying about */
register u_char *cp; /* current position in answer buf */
input u_char *msg, *eom; /* begin and end of answer buf */
input bool regular; /* set if this is a regular lookup */
{
char rname[MAXDNAME+1]; /* record name in LHS */
char dname[MAXDNAME+1]; /* domain name in RHS */
int type, class, ttl, dlen; /* fixed values in every record */
u_char *eor; /* predicted position of next record */
bool classmatch; /* set if we want to see this class */
bool listing; /* set if this is a zone listing */
char *host = listhost; /* contacted host for zone listings */
char *dumpmsg = NULL; /* set if data should be dumped */
register int n, c;
struct in_addr inaddr;
struct protoent *protocol;
struct servent *service;
/*
* Pickup the standard values present in each resource record.
*/
n = expand_name(name, T_NONE, cp, msg, eom, rname);
if (n < 0)
return(NULL);
cp += n;
n = 3*INT16SZ + INT32SZ;
if (check_size(rname, T_NONE, cp, msg, eom, n) < 0)
return(NULL);
type = _getshort(cp);
cp += INT16SZ;
class = _getshort(cp);
cp += INT16SZ;
ttl = _getlong(cp);
cp += INT32SZ;
dlen = _getshort(cp);
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eom, dlen) < 0)
return(NULL);
eor = cp + dlen;
/*
* Decide whether or not to print this resource record.
*/
listing = (qtype == T_AXFR || qtype == T_IXFR) ? TRUE : FALSE;
if (listing)
{
classmatch = want_class(class, queryclass);
doprint = classmatch && want_type(type, querytype);
}
else
{
classmatch = want_class(class, C_ANY);
doprint = classmatch && want_type(type, T_ANY);
}
if (doprint && exclusive && !indomain(rname, name, TRUE))
doprint = FALSE;
if (doprint && exclusive && fakename(rname))
doprint = FALSE;
if (doprint && wildcards && !in_string(rname, '*'))
doprint = FALSE;
#ifdef justfun
if (namelen && (strlength(rname) < namelen))
doprint = FALSE;
#endif
/*
* Print name and common values, if appropriate.
*/
doprintf(("%-20s", pr_name(rname)))
if (verbose || ttlprint)
doprintf(("\t%s", dtoa(ttl)))
if (verbose || classprint || (class != qclass))
doprintf(("\t%s", pr_class(class)))
doprintf(("\t%s", pr_type(type)))
/*
* Update resource record statistics for zone listing.
*/
if (listing && classmatch)
{
if (type >= T_FIRST && type <= T_LAST)
record_stats[type]++;
}
/*
* Save the domain name of an SOA or NS or A record for zone listing.
*/
if (listing && classmatch)
{
if (type == T_A)
adrname = strcpy(adrnamebuf, rname);
else if (type == T_NS)
subname = strcpy(subnamebuf, rname);
else if (type == T_SOA)
soaname = strcpy(soanamebuf, rname);
}
/*
* Print type specific data, if appropriate.
*/
switch (type)
{
case T_A:
if (class == C_IN || class == C_HS)
{
if (dlen == INADDRSZ)
{
bcopy((char *)cp, (char *)&inaddr, INADDRSZ);
address = inaddr.s_addr;
doprintf(("\t%s", inet_ntoa(inaddr)))
cp += INADDRSZ;
break;
}
#ifdef obsolete
if (dlen == INADDRSZ + 1 + INT16SZ)
{
bcopy((char *)cp, (char *)&inaddr, INADDRSZ);
address = inaddr.s_addr;
doprintf(("\t%s", inet_ntoa(inaddr)))
cp += INADDRSZ;
n = *cp++;
doprintf((" ; proto = %s", dtoa(n)))
n = _getshort(cp);
doprintf((", port = %s", dtoa(n)))
cp += INT16SZ;
break;
}
#endif
address = 0;
break;
}
address = 0;
cp += dlen;
break;
case T_MX:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_NS:
case T_PTR:
case T_CNAME:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
break;
case T_HINFO:
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t\"%s\"", stoa(cp, n, TRUE)))
cp += n;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t\"%s\"", stoa(cp, n, TRUE)))
cp += n;
break;
case T_SOA:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
n = 5*INT32SZ;
if (check_size(rname, type, cp, msg, eor, n) < 0)
break;
doprintf((" ("))
n = _getlong(cp);
doprintf(("\n\t\t\t%s", utoa(n)))
doprintf(("\t;serial (version)"))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t;refresh period (%s)", pr_time(n, FALSE)))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t;retry interval (%s)", pr_time(n, FALSE)))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t;expire time (%s)", pr_time(n, FALSE)))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t;default ttl (%s)", pr_time(n, FALSE)))
cp += INT32SZ;
doprintf(("\n\t\t\t)"))
break;
case T_WKS:
if (check_size(rname, type, cp, msg, eor, INADDRSZ) < 0)
break;
bcopy((char *)cp, (char *)&inaddr, INADDRSZ);
doprintf(("\t%s", inet_ntoa(inaddr)))
cp += INADDRSZ;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
protocol = getprotobynumber(n);
if (protocol != NULL)
doprintf((" %s", protocol->p_name))
else
doprintf((" %s", dtoa(n)))
doprintf((" ("))
n = 0;
while (cp < eor)
{
c = *cp++;
do
{
if (c & 0200)
{
int port;
port = htons((u_short)n);
if (protocol != NULL)
service = getservbyport(port, protocol->p_name);
else
service = NULL;
if (service != NULL)
doprintf((" %s", service->s_name))
else
doprintf((" %s", dtoa(n)))
}
c <<= 1;
} while (++n & 07);
}
doprintf((" )"))
break;
#ifdef obsolete
case T_TXT:
/* if (dlen > 0) */
{
doprintf(("\t\"%s\"", stoa(cp, dlen, TRUE)))
cp += dlen;
}
break;
#endif
case T_TXT:
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t\"%s\"", stoa(cp, n, TRUE)))
cp += n;
while (cp < eor)
{
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" \"%s\"", stoa(cp, n, TRUE)))
cp += n;
}
break;
case T_MINFO:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_MB:
case T_MG:
case T_MR:
case T_MD:
case T_MF:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
break;
case T_UID:
case T_GID:
if (dlen == INT32SZ)
{
n = _getlong(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT32SZ;
}
break;
case T_UINFO:
doprintf(("\t\"%s\"", stoa(cp, dlen, TRUE)))
cp += dlen;
break;
case T_RP:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_RT:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_AFSDB:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_X25:
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t%s", stoa(cp, n, FALSE)))
cp += n;
break;
case T_ISDN:
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t%s", stoa(cp, n, FALSE)))
cp += n;
if (cp < eor)
{
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", stoa(cp, n, FALSE)))
cp += n;
}
break;
case T_NSAP:
doprintf(("\t0x%s", nsap_ntoa(cp, dlen)))
cp += dlen;
break;
case T_NSAPPTR:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
break;
case T_PX:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_GPOS:
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t%s", stoa(cp, n, FALSE)))
cp += n;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t%s", stoa(cp, n, FALSE)))
cp += n;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf(("\t%s", stoa(cp, n, FALSE)))
cp += n;
break;
case T_LOC:
if ((n = *cp) != T_LOC_VERSION)
{
pr_error("invalid version %s in %s record for %s",
dtoa(n), pr_type(type), rname);
cp += dlen;
break;
}
n = INT32SZ + 3*INT32SZ;
if (check_size(rname, type, cp, msg, eor, n) < 0)
break;
c = _getlong(cp);
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\t%s ", pr_spherical(n, "N", "S")))
cp += INT32SZ;
n = _getlong(cp);
doprintf((" %s ", pr_spherical(n, "E", "W")))
cp += INT32SZ;
n = _getlong(cp);
doprintf((" %sm ", pr_vertical(n, "", "-")))
cp += INT32SZ;
doprintf((" %sm", pr_precision((c >> 16) & 0xff)))
doprintf((" %sm", pr_precision((c >> 8) & 0xff)))
doprintf((" %sm", pr_precision((c >> 0) & 0xff)))
break;
case T_UNSPEC:
case T_NULL:
cp += dlen;
break;
case T_AAAA:
if (dlen == IPNGSIZE)
{
doprintf(("\t%s", ipng_ntoa(cp)))
cp += IPNGSIZE;
}
break;
case T_SIG:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
if (n >= T_FIRST && n <= T_LAST)
doprintf(("\t%s", pr_type(n)))
else
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", dtoa(n)))
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", dtoa(n)))
n = 3*INT32SZ + INT16SZ;
if (check_size(rname, type, cp, msg, eor, n) < 0)
break;
doprintf((" ("))
n = _getlong(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t\t;original ttl"))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", pr_date(n)))
doprintf(("\t;signature expiration"))
cp += INT32SZ;
n = _getlong(cp);
doprintf(("\n\t\t\t%s", pr_date(n)))
doprintf(("\t;signature inception"))
cp += INT32SZ;
n = _getshort(cp);
doprintf(("\n\t\t\t%s", dtoa(n)))
doprintf(("\t\t;key tag"))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\n\t\t\t%s", pr_name(dname)))
cp += n;
if (cp < eor)
{
register char *buf;
register int size;
n = eor - cp;
buf = base_ntoa(cp, n);
size = strlength(buf);
cp += n;
while ((n = (size > 64) ? 64 : size) > 0)
{
doprintf(("\n\t%s", stoa((u_char *)buf, n, FALSE)))
buf += n; size -= n;
}
}
doprintf(("\n\t\t\t)"))
break;
case T_KEY:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t0x%s", xtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", dtoa(n)))
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", dtoa(n)))
if (cp < eor)
{
register char *buf;
register int size;
n = eor - cp;
buf = base_ntoa(cp, n);
size = strlength(buf);
cp += n;
doprintf((" ("))
while ((n = (size > 64) ? 64 : size) > 0)
{
doprintf(("\n\t%s", stoa((u_char *)buf, n, FALSE)))
buf += n; size -= n;
}
doprintf(("\n\t\t\t)"))
}
break;
case T_NXT:
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf(("\t%s", pr_name(dname)))
cp += n;
n = 0;
while (cp < eor)
{
c = *cp++;
do
{
if (c & 0200)
{
if (n >= T_FIRST && n <= T_LAST)
doprintf((" %s", pr_type(n)))
else
doprintf((" %s", dtoa(n)))
}
c <<= 1;
} while (++n & 07);
}
break;
case T_SRV:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf((" %s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf((" %s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_NAPTR:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf((" %s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" \"%s\"", stoa(cp, n, TRUE)))
cp += n;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" \"%s\"", stoa(cp, n, TRUE)))
cp += n;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" \"%s\"", stoa(cp, n, TRUE)))
cp += n;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_KX:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
n = expand_name(rname, type, cp, msg, eom, dname);
if (n < 0)
break;
doprintf((" %s", pr_name(dname)))
cp += n;
break;
case T_CERT:
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf(("\t%s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, INT16SZ) < 0)
break;
n = _getshort(cp);
doprintf((" %s", dtoa(n)))
cp += INT16SZ;
if (check_size(rname, type, cp, msg, eor, 1) < 0)
break;
n = *cp++;
doprintf((" %s", dtoa(n)))
if (cp < eor)
{
register char *buf;
register int size;
n = eor - cp;
buf = base_ntoa(cp, n);
size = strlength(buf);
cp += n;
doprintf((" ("))
while ((n = (size > 64) ? 64 : size) > 0)
{
doprintf(("\n\t%s", stoa((u_char *)buf, n, FALSE)))
buf += n; size -= n;
}
doprintf(("\n\t\t\t)"))
}
break;
case T_EID:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_NIMLOC:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_ATMA:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_A6:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_DNAME:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_SINK:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_OPT:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_ADDRS:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_TKEY:
dumpmsg = "not implemented";
cp += dlen;
break;
case T_TSIG:
dumpmsg = "not implemented";
cp += dlen;
break;
default:
dumpmsg = "unknown type";
cp += dlen;
break;
}
/* dump the data portion if necessary */
if ((dumpmsg != NULL) || dumpdata)
dump_rrec(eor - dlen, dlen, dumpmsg);
/*
* End of specific data type processing.
* Terminate resource record printout.
*/
doprintf(("\n"))
/*
* Check whether we have reached the exact end of this resource record.
* If not, we cannot be sure that the record has been decoded correctly,
* and therefore the subsequent tests will be skipped.
* Maybe we should hex dump the entire record.
*/
if (cp != eor)
{
pr_error("size error in %s record for %s, off by %s",
pr_type(type), rname, dtoa(cp - eor));
/* we believe value of dlen; should perhaps return(NULL) */
return(eor);
}
/*
* Save the CNAME alias for cname chain tracing.
* Save the MR or MG alias for MB chain tracing.
* These features can be enabled only in normal mode.
*/
if (regular && classmatch)
{
if (type == T_CNAME)
cname = strcpy(cnamebuf, dname);
else if (type == T_MR || type == T_MG)
mname = strcpy(mnamebuf, dname);
}
/*
* Suppress the subsequent checks in quiet mode.
* This can safely be done as there are no side effects.
* It may speedup things, and nothing would be printed anyway.
* Also suppress the checks if explicitly requested in quick mode.
*/
if (quiet || quick)
return(cp);
/*
* Check for resource records with a zero ttl value. They are not cached.
* This may lead to problems, e.g. when retrieving MX records and there
* exists only a zero-ttl CNAME record pointing to a zero-ttl A record.
* Certain resource records always have a zero ttl value.
*/
if ((ttl == 0) && (type != T_SIG))
{
pr_warning("%s %s record has zero ttl",
rname, pr_type(type));
}
/*
* In zone listings, resource records with the same name/type/class
* must have the same ttl value. Maintain and check list of record info.
* This is done on a per-zone basis.
*/
if (listing && !check_ttl(rname, type, class, ttl))
{
pr_warning("%s %s records have different ttl within %s from %s",
rname, pr_type(type), name, host);
}
/*
* Check validity of 'host' related domain names in certain resource records.
* These include LHS record names and RHS domain names of selected records.
* By default underscores are not reported during deep recursive listings.
*/
if (test_valid(type) && !valid_name(rname, TRUE, FALSE, underskip))
{
pr_warning("%s %s record has illegal name",
rname, pr_type(type));
}
if (test_canon(type) && !valid_name(dname, FALSE, FALSE, underskip))
{
pr_warning("%s %s host %s has illegal name",
rname, pr_type(type), dname);
}
if (test_ptr(type, rname) && !valid_name(dname, FALSE, FALSE, underskip))
{
pr_warning("%s %s host %s has illegal name",
rname, pr_type(type), dname);
}
/*
* The RHS of various resource records should refer to a canonical host name,
* i.e. it should exist and have an A record and not be a CNAME.
* By default this test is suppressed during deep recursive zone listings.
* Results are cached globally, not on a per-zone basis.
*/
if (!canonskip && test_canon(type) && ((n = check_canon(dname)) != 0))
{
/* only report definitive target host failures */
if (n == HOST_NOT_FOUND)
pr_warning("%s %s host %s does not exist",
rname, pr_type(type), dname);
else if (n == NO_DATA)
pr_warning("%s %s host %s has no A record",
rname, pr_type(type), dname);
else if (n == HOST_NOT_CANON)
pr_warning("%s %s host %s is not canonical",
rname, pr_type(type), dname);
/* authoritative failure to find nameserver target host */
if (type == T_NS && (n == NO_DATA || n == HOST_NOT_FOUND))
{
if (server == NULL)
errmsg("%s has lame delegation to %s",
rname, dname);
}
}
/*
* On request, check the RHS of a PTR record when processing a reverse zone,
* which should refer to a canonical host name, i.e. it should exist and
* have an A record and not be a CNAME. Results are not cached in this case.
* Currently this option has effect here only during zone listings.
* Note that this does not check CIDR delegations as mentioned in RFC 2317,
* where PTR records are replaced with CNAME records.
* Also note that this may generate warnings for PTR records for host 0 or
* host 255 entries, indicating network names as suggested by RFC 1101.
*/
if (addrmode && test_ptr(type, rname) && ((n = canonical(dname)) != 0))
{
/* only report definitive target host failures */
if (n == HOST_NOT_FOUND)
pr_warning("%s %s host %s does not exist",
rname, pr_type(type), dname);
else if (n == NO_DATA)
pr_warning("%s %s host %s has no A record",
rname, pr_type(type), dname);
else if (n == HOST_NOT_CANON)
pr_warning("%s %s host %s is not canonical",
rname, pr_type(type), dname);
}
/*
* On request, reverse map the address of an A record, and verify that
* it is registered and maps back to the name of the A record.
* Currently this option has effect here only during zone listings.
* Note that in reverse zones there are usually no A records, except
* perhaps to specify a network mask as suggested in RFC 1101.
*/
if (addrmode && test_adr(type, address))
{
host = mapreverse(rname, inaddr);
if (host == NULL)
pr_warning("%s address %s is not registered",
rname, inet_ntoa(inaddr));
else if (host != rname)
pr_warning("%s address %s maps to %s",
rname, inet_ntoa(inaddr), host);
}
/*
* On request, check the target in CNAME records for existence.
*/
if (cnamecheck && (type == T_CNAME) && ((n = anyrecord(dname)) != 0))
{
/* only report definitive target host failures */
if (n == HOST_NOT_FOUND)
pr_warning("%s %s target %s does not exist",
rname, pr_type(type), dname);
else if (n == NO_DATA)
pr_warning("%s %s target %s has no ANY record",
rname, pr_type(type), dname);
}
/*
* This record was processed successfully.
*/
return(cp);
}
/*
** DUMP_RREC -- Print data of resource record in hex and ascii
** -----------------------------------------------------------
**
** Returns:
** None.
*/
static char ascbuf[] = "................";
static char hexbuf[] = "XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX";
void
dump_rrec(cp, size, comment)
input u_char *cp; /* current position in answer buf */
input int size; /* number of bytes to extract */
input char *comment; /* additional comment text */
{
register int c;
register int n;
register int i;
if (comment != NULL)
doprintf(("\t# (\t; %s", comment))
while ((n = (size > 16) ? 16 : size) > 0)
{
for (i = 0; i < n; i++, cp++)
{
ascbuf[i] = is_print(*cp) ? *cp : '.';
c = ((int)(*cp) >> 4) & 0x0f;
hexbuf[i*3+0] = hexdigit(c);
c = ((int)(*cp) >> 0) & 0x0f;
hexbuf[i*3+1] = hexdigit(c);
}
for (size -= n; i < 16; i++)
{
ascbuf[i] = ' ';
hexbuf[i*3+0] = ' ';
hexbuf[i*3+1] = ' ';
}
if (comment != NULL)
doprintf(("\n\t%s ; %s", hexbuf, ascbuf))
else
doprintf(("\n%s\t%s ; %s", dbprefix, hexbuf, ascbuf))
}
if (comment != NULL)
doprintf(("\n\t)"))
}
/*
** SKIP_QREC -- Skip the query record in the nameserver answer buffer
** ------------------------------------------------------------------
**
** Returns:
** Pointer to position in answer buffer after current record.
** NULL if there was a format error in the current record.
*/
u_char *
skip_qrec(name, qtype, qclass, cp, msg, eom)
input char *name; /* full name we are querying about */
input int qtype; /* record type we are querying about */
input int qclass; /* record class we are querying about */
register u_char *cp; /* current position in answer buf */
input u_char *msg, *eom; /* begin and end of answer buf */
{
char rname[MAXDNAME+1]; /* record name in LHS */
int type, class; /* fixed values in query record */
register int n;
/*
* Pickup the standard values present in the query section.
*/
n = expand_name(name, T_NONE, cp, msg, eom, rname);
if (n < 0)
return(NULL);
cp += n;
n = 2*INT16SZ;
if (check_size(rname, T_NONE, cp, msg, eom, n) < 0)
return(NULL);
type = _getshort(cp);
cp += INT16SZ;
class = _getshort(cp);
cp += INT16SZ;
#ifdef lint
if (verbose)
printf("%-20s\t%s\t%s\n",
rname, pr_class(class), pr_type(type));
#endif
/*
* The values in the answer should match those in the query.
* If there is a mismatch, we just signal an error, but don't abort.
* For regular queries there is exactly one record in the query section.
*/
if (!sameword(rname, name))
pr_error("invalid answer name %s after %s query for %s",
rname, pr_type(qtype), name);
if (type != qtype)
pr_error("invalid answer type %s after %s query for %s",
pr_type(type), pr_type(qtype), name);
if (class != qclass)
pr_error("invalid answer class %s after %s query for %s",
pr_class(class), pr_type(qtype), name);
return(cp);
}
/*
** GET_RECURSIVE -- Wrapper for get_hostinfo() during recursion
** ------------------------------------------------------------
**
** Returns:
** TRUE if requested info was obtained successfully.
** FALSE otherwise.
*/
bool
get_recursive(name)
input char **name; /* name to query about */
{
static int level = 0; /* recursion level */
char newnamebuf[MAXDNAME+1];
char *newname; /* new name to look up */
bool result; /* result status of action taken */
int save_errno;
int save_herrno;
if (level > MAXCHAIN)
{
errmsg("Recursion too deep");
return(FALSE);
}
/* save local copy, and reset indicator */
newname = strcpy(newnamebuf, *name);
*name = NULL;
save_errno = errno;
save_herrno = h_errno;
level++;
result = get_hostinfo(newname, TRUE);
level--;
seterrno(save_errno);
seth_errno(save_herrno);
return(result);
}
|