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
|
diff -u -r ntp-dev-4.2.7p250/config.h.in ntp-dev-4.2.7p250.dnssec/config.h.in
--- ntp-dev-4.2.7p250/config.h.in 2012-01-15 06:36:59.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/config.h.in 2012-01-16 12:27:05.000000000 -0500
@@ -359,6 +359,9 @@
/* Use Rendezvous/DNS-SD registration */
#undef HAVE_DNSREGISTRATION
+/* Perform local DNSSEC Validation using dnsval */
+#undef HAVE_DNSVAL
+
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
@@ -1503,6 +1506,28 @@
/* Must we have a CTTY for fsetown? */
#undef USE_FSETOWNCTTY
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# undef _ALL_SOURCE
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# undef _GNU_SOURCE
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
/* Can we use SIGPOLL for tty IO? */
#undef USE_TTY_SIGPOLL
@@ -1555,9 +1580,6 @@
/* enable thread safety */
#undef _THREAD_SAFE
-/* Define to 500 only on HP-UX. */
-#undef _XOPEN_SOURCE
-
/* Are we _special_? */
#undef __APPLE_USE_RFC_3542
@@ -1566,28 +1588,6 @@
# undef __CHAR_UNSIGNED__
#endif
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# undef _ALL_SOURCE
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# undef _GNU_SOURCE
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# undef _POSIX_PTHREAD_SEMANTICS
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# undef _TANDEM_SOURCE
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
-#endif
-
-
/* deviant */
#undef adjtimex
diff -u -r ntp-dev-4.2.7p250/configure.ac ntp-dev-4.2.7p250.dnssec/configure.ac
--- ntp-dev-4.2.7p250/configure.ac 2011-10-21 14:30:06.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/configure.ac 2012-01-16 12:27:05.000000000 -0500
@@ -199,6 +199,28 @@
;;
esac
+dnl
+dnl Check for DNSSEC support
+dnl
+AC_ARG_WITH(
+ [dnsval],
+ AS_HELP_STRING([--with-dnsval], [- Enable local DNSSEC validation using dnsval]),
+ want_dnssec=$withval,
+ want_dnssec=no)
+case "$want_dnssec" in
+ yes)
+ if test "x$ac_cv_header_pthread_h" != xyes; then
+ AC_MSG_ERROR(["Configured needs to be fine-tuned for non-pthread support"])
+ fi
+ AC_CHECK_LIB([val-threads],
+ [val_getaddrinfo],
+ [LIBS="-lval-threads -lsres -lcrypto $LIBS"
+ AC_DEFINE([HAVE_DNSVAL], [1], [Perform local DNSSEC Validation using dnsval])],
+ [AC_MSG_ERROR(["Can't find required libraries for DNSSEC support"])],
+ [-lsres -lcrypto])
+ ;;
+esac
+
AC_CHECK_HEADERS([bstring.h])
AC_CHECK_HEADER(
[dns_sd.h],
diff -u -r ntp-dev-4.2.7p250/include/ntp_intres.h ntp-dev-4.2.7p250.dnssec/include/ntp_intres.h
--- ntp-dev-4.2.7p250/include/ntp_intres.h 2011-02-21 04:08:19.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/include/ntp_intres.h 2012-01-16 12:27:05.000000000 -0500
@@ -19,6 +19,14 @@
extern int getaddrinfo_sometime(const char *, const char *,
const struct addrinfo *, int,
gai_sometime_callback, void *);
+#ifdef HAVE_DNSVAL
+extern int getaddrinfo_sometime_blocking(const char *, const char *,
+ const struct addrinfo *, int,
+ gai_sometime_callback, void *);
+extern int getaddrinfo_sometime_nonblocking(const char *, const char *,
+ const struct addrinfo *, int,
+ gai_sometime_callback, void *);
+#endif
/*
* In gai_sometime_callback routines, the resulting addrinfo list is
* only available until the callback returns. To hold on to the list
diff -u -r ntp-dev-4.2.7p250/include/ntpd.h ntp-dev-4.2.7p250.dnssec/include/ntpd.h
--- ntp-dev-4.2.7p250/include/ntpd.h 2011-12-18 06:01:47.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/include/ntpd.h 2012-01-16 12:27:05.000000000 -0500
@@ -569,4 +569,3 @@
extern struct refclock * const refclock_conf[];
extern u_char num_refclock_conf;
#endif
-
diff -u -r ntp-dev-4.2.7p250/libntp/decodenetnum.c ntp-dev-4.2.7p250.dnssec/libntp/decodenetnum.c
--- ntp-dev-4.2.7p250/libntp/decodenetnum.c 2011-11-03 15:17:26.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/libntp/decodenetnum.c 2012-01-16 12:27:05.000000000 -0500
@@ -11,6 +11,10 @@
#include <netinet/in.h>
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntp.h"
#include "ntp_stdlib.h"
#include "ntp_assert.h"
@@ -34,6 +38,9 @@
char *pp;
char *np;
char name[80];
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
NTP_REQUIRE(num != NULL);
NTP_REQUIRE(strlen(num) < sizeof(name));
@@ -69,9 +76,21 @@
}
ZERO(hints);
hints.ai_flags = Z_AI_NUMERICHOST;
+#ifdef HAVE_DNSVAL
+ err = val_getaddrinfo(NULL, cp, "ntp", &hints, &ai, &val_status);
+#else
err = getaddrinfo(cp, "ntp", &hints, &ai);
+#endif
if (err != 0)
return 0;
+#ifdef HAVE_DNSVAL
+ if (val_istrusted(val_status)) {
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ return 0;
+ }
+#endif
NTP_INSIST(ai->ai_addrlen <= sizeof(*netnum));
ZERO(*netnum);
memcpy(netnum, ai->ai_addr, ai->ai_addrlen);
diff -u -r ntp-dev-4.2.7p250/libntp/ntp_intres.c ntp-dev-4.2.7p250.dnssec/libntp/ntp_intres.c
--- ntp-dev-4.2.7p250/libntp/ntp_intres.c 2011-04-21 02:04:48.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/libntp/ntp_intres.c 2012-01-16 12:27:05.000000000 -0500
@@ -92,6 +92,10 @@
# endif
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntp.h"
#include "ntp_debug.h"
#include "ntp_malloc.h"
@@ -186,6 +190,22 @@
#endif
} dnsworker_ctx;
+#ifdef HAVE_DNSVAL
+/* callback data structure associated with the asynchronous
+ * lookup function provided by dnsval. The memory for this
+ * structure is allocated before the callback is invoked
+ * and freed in the callback routine
+ */
+struct dnsval_gai_data {
+ int retry;
+ const char * node;
+ const char * service;
+ const struct addrinfo * hints;
+ gai_sometime_callback callback;
+ void * context;
+};
+#endif
+
/* === variables === */
dnschild_ctx ** dnschild_contexts; /* parent */
@@ -224,9 +244,133 @@
static void getnameinfo_sometime_complete(blocking_work_req,
void *, size_t,
void *);
+#ifdef HAVE_DNSVAL
+static int dnsval_gai_callback(void *callback_data,
+ int, struct addrinfo *,
+ val_status_t);
+#endif
/* === functions === */
+
+#ifdef HAVE_DNSVAL
+int
+getaddrinfo_sometime(
+ const char * node,
+ const char * service,
+ const struct addrinfo * hints,
+ int retry,
+ gai_sometime_callback callback,
+ void * context
+ )
+{
+#ifdef HAVE_SIGNALED_IO
+ /*
+ * If we're using signaled IO, we won't be able to call select() on
+ * dnsval's descriptors, so use the blocking version of the lookup routine
+ */
+ return getaddrinfo_sometime_blocking(node,service,hints,retry,callback,context);
+#else
+ return getaddrinfo_sometime_nonblocking(node,service,hints,retry,callback,context);
+#endif
+}
+
+/*
+ * Use the asynchronous lookup functionality from dnsval to resolve
+ * the name and perform DNSSEC validation of the response, and then
+ * invoke the provided callback completion function.
+ */
+int
+getaddrinfo_sometime_nonblocking(
+ const char * node,
+ const char * service,
+ const struct addrinfo * hints,
+ int retry,
+ gai_sometime_callback callback,
+ void * context
+ )
+{
+ int retval;
+ val_gai_callback dnsval_cb = &dnsval_gai_callback;
+ val_gai_status *status = NULL;
+
+ struct dnsval_gai_data *dnsval_cbdata =
+ emalloc_zero(sizeof(struct dnsval_gai_data));
+ dnsval_cbdata->node = node;
+ dnsval_cbdata->service = service;
+ dnsval_cbdata->hints = hints;
+ dnsval_cbdata->retry = retry;
+ dnsval_cbdata->callback = callback;
+ dnsval_cbdata->context = context;
+
+ retval = val_getaddrinfo_submit(NULL, node, service, hints,
+ dnsval_cb, dnsval_cbdata, 0, &status);
+ if (retval != VAL_NO_ERROR) {
+ msyslog(LOG_ERR, "unable to perform asynchronous getaddrinfo request using dnsval.");
+ errno = EFAULT;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+dnsval_gai_callback(
+ void *dnsval_cbdata,
+ int eai_retval,
+ struct addrinfo *res,
+ val_status_t val_status)
+{
+ struct addrinfo *ai = NULL;
+ struct dnsval_gai_data *gd;
+
+ if (!dnsval_cbdata) {
+ return 1;
+ }
+ gd = (struct dnsval_gai_data *)dnsval_cbdata;
+
+ /* XXX Need to properly handle retries */
+
+ /* Extract the result only if DNSSEC validation was successful */
+ if (VAL_GETADDRINFO_HAS_STATUS(eai_retval)) {
+ if (val_istrusted(val_status)) {
+ ai = res;
+ } else {
+ msyslog(LOG_INFO,
+ "DNS response for %s failed validation", gd->node);
+ }
+ }
+
+ (gd->callback)(eai_retval, eai_retval,
+ gd->context,
+ gd->node,
+ gd->service,
+ gd->hints,
+ ai);
+
+ if (res) {
+ freeaddrinfo(res);
+ }
+
+ free(dnsval_cbdata);
+ return 0;
+}
+
+
+/*
+ * getaddrinfo_sometime_blocking - uses blocking child to call getaddrinfo then
+ * invokes provided callback completion function.
+ */
+int
+getaddrinfo_sometime_blocking(
+ const char * node,
+ const char * service,
+ const struct addrinfo * hints,
+ int retry,
+ gai_sometime_callback callback,
+ void * context
+ )
+#else
/*
* getaddrinfo_sometime - uses blocking child to call getaddrinfo then
* invokes provided callback completion function.
@@ -240,6 +384,7 @@
gai_sometime_callback callback,
void * context
)
+#endif
{
blocking_gai_req * gai_req;
u_int idx;
@@ -319,6 +464,9 @@
size_t resp_octets;
char * cp;
time_t time_now;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
gai_req = (void *)((char *)req + sizeof(*req));
node = (char *)gai_req + sizeof(*gai_req);
@@ -349,8 +497,22 @@
fflush(stdout);
#endif
ai_res = NULL;
+#ifdef HAVE_DNSVAL
+ gai_resp->retcode = val_getaddrinfo(NULL, node, service, &gai_req->hints,
+ &ai_res, &val_status);
+ if (gai_resp->retcode == 0 && !val_istrusted(val_status)) {
+ if (ai_res) {
+ freeaddrinfo(ai_res);
+ }
+ gai_resp->retcode = EAI_FAIL;
+ TRACE(2, ("DNSSEC validation failed for node %s serv %s fam %d flags %x\n",
+ node, service, gai_req->hints.ai_family,
+ gai_req->hints.ai_flags));
+ }
+#else
gai_resp->retcode = getaddrinfo(node, service, &gai_req->hints,
&ai_res);
+#endif
gai_resp->retry = gai_req->retry;
#ifdef EAI_SYSTEM
if (EAI_SYSTEM == gai_resp->retcode)
@@ -618,7 +780,6 @@
}
#endif /* TEST_BLOCKING_WORKER */
-
int
getnameinfo_sometime(
sockaddr_u * psau,
@@ -671,7 +832,6 @@
return 0;
}
-
int
blocking_getnameinfo(
blocking_child * c,
diff -u -r ntp-dev-4.2.7p250/libntp/ntp_rfc2553.c ntp-dev-4.2.7p250.dnssec/libntp/ntp_rfc2553.c
--- ntp-dev-4.2.7p250/libntp/ntp_rfc2553.c 2011-05-08 04:11:52.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/libntp/ntp_rfc2553.c 2012-01-16 12:27:05.000000000 -0500
@@ -76,6 +76,9 @@
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
#include "ntp_rfc2553.h"
#include "ntpd.h"
@@ -268,7 +271,15 @@
struct hostent **Addresses
)
{
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+ *Addresses = val_gethostbyname(NULL, name, &val_status);
+ if (!val_istrusted(val_status)) {
+ return NO_RECOVERY;
+ }
+#else
*Addresses = gethostbyname(name);
+#endif
return (h_errno);
}
#endif
@@ -539,7 +550,6 @@
/*
* Look for a name
*/
-
errval = DNSlookup_name(nodename, AF_INET, &hp);
if (hp == NULL) {
diff -u -r ntp-dev-4.2.7p250/libntp/numtohost.c ntp-dev-4.2.7p250.dnssec/libntp/numtohost.c
--- ntp-dev-4.2.7p250/libntp/numtohost.c 2011-04-05 03:35:33.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/libntp/numtohost.c 2012-01-16 12:27:05.000000000 -0500
@@ -8,6 +8,10 @@
#include <netinet/in.h> /* ntohl */
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntp_fp.h"
#include "ntp_stdlib.h"
#include "lib_strbuf.h"
@@ -23,6 +27,9 @@
{
char *bp;
struct hostent *hp;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/*
* This is really gross, but saves lots of hanging looking for
@@ -30,10 +37,17 @@
* addresses on the loopback network except for the loopback
* host itself.
*/
+#ifdef HAVE_DNSVAL
+ if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
+ && (ntohl(netnum) != LOOPBACKHOST))
+ || ((hp = val_gethostbyaddr(NULL, (char *)&netnum, sizeof netnum, AF_INET, &val_status))
+ == 0) || !val_istrusted(val_status))
+#else
if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
&& (ntohl(netnum) != LOOPBACKHOST))
|| ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
== 0))
+#endif
return numtoa(netnum);
LIB_GETBUF(bp);
diff -u -r ntp-dev-4.2.7p250/libntp/socktohost.c ntp-dev-4.2.7p250.dnssec/libntp/socktohost.c
--- ntp-dev-4.2.7p250/libntp/socktohost.c 2011-03-06 05:04:46.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/libntp/socktohost.c 2012-01-16 12:27:05.000000000 -0500
@@ -14,6 +14,10 @@
#include <stdio.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntp_fp.h"
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
@@ -36,13 +40,22 @@
sockaddr_u addr;
size_t octets;
int a_info;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/* reverse the address to purported DNS name */
LIB_GETBUF(pbuf);
gni_flags = NI_DGRAM | NI_NAMEREQD;
+#ifdef HAVE_DNSVAL
+ if (val_getnameinfo(NULL, &sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH,
+ NULL, 0, gni_flags, &val_status) || !val_istrusted(val_status))
+ return stoa(sock); /* use address */
+#else
if (getnameinfo(&sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH,
NULL, 0, gni_flags))
return stoa(sock); /* use address */
+#endif
TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf));
@@ -57,7 +70,11 @@
hints.ai_flags = 0;
alist = NULL;
+#ifdef HAVE_DNSVAL
+ a_info = val_getaddrinfo(NULL, pbuf, svc, &hints, &alist, &val_status);
+#else
a_info = getaddrinfo(pbuf, svc, &hints, &alist);
+#endif
if (a_info == EAI_NONAME
#ifdef EAI_NODATA
|| a_info == EAI_NODATA
@@ -67,18 +84,41 @@
#ifdef AI_ADDRCONFIG
hints.ai_flags |= AI_ADDRCONFIG;
#endif
- a_info = getaddrinfo(pbuf, svc, &hints, &alist);
+#ifdef HAVE_DNSVAL
+ if (alist) {
+ freeaddrinfo(alist);
+ }
+ a_info = val_getaddrinfo(NULL, pbuf, svc, &hints, &alist, &val_status);
+#else
+ a_info = getaddrinfo(pbuf, svc, &hints, &alist);
+#endif
}
#ifdef AI_ADDRCONFIG
/* Some older implementations don't like AI_ADDRCONFIG. */
if (a_info == EAI_BADFLAGS) {
hints.ai_flags &= ~AI_ADDRCONFIG;
- a_info = getaddrinfo(pbuf, svc, &hints, &alist);
+#ifdef HAVE_DNSVAL
+ if (alist) {
+ freeaddrinfo(alist);
+ }
+ a_info = val_getaddrinfo(NULL, pbuf, svc, &hints, &alist, &val_status);
+#else
+ a_info = getaddrinfo(pbuf, svc, &hints, &alist);
+#endif
}
#endif
if (a_info)
goto forward_fail;
+#ifdef HAVE_DNSVAL
+ if (!val_istrusted(val_status)) {
+ if (alist) {
+ freeaddrinfo(alist);
+ }
+ goto forward_fail;
+ }
+#endif
+
NTP_INSIST(alist != NULL);
for (ai = alist; ai != NULL; ai = ai->ai_next) {
diff -u -r ntp-dev-4.2.7p250/ntpd/cmd_args.c ntp-dev-4.2.7p250.dnssec/ntpd/cmd_args.c
--- ntp-dev-4.2.7p250/ntpd/cmd_args.c 2011-10-10 01:48:29.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/ntpd/cmd_args.c 2012-01-16 12:27:05.000000000 -0500
@@ -5,6 +5,10 @@
# include <config.h>
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntpd.h"
#include "ntp_stdlib.h"
#include "ntp_config.h"
@@ -75,6 +79,16 @@
if (HAVE_OPT( PANICGATE ))
allow_panic = TRUE;
+#ifdef HAVE_DNSVAL
+ if (HAVE_OPT( PANICGATE )) {
+ /* Disable DNSSEC Validation */
+ if (VAL_NO_ERROR != val_context_setqflags(NULL, VAL_CTX_FLAG_SET, VAL_QUERY_IGNORE_SKEW)) {
+ msyslog(LOG_ERR, "Failed to create DNSSEC validator context.");
+ exit(1);
+ }
+ msyslog(LOG_NOTICE, "DNSSEC clock-skew tolerance enabled.");
+ }
+#endif
#ifdef HAVE_DROPROOT
if (HAVE_OPT( JAILDIR )) {
diff -u -r ntp-dev-4.2.7p250/ntpd/ntp_config.c ntp-dev-4.2.7p250.dnssec/ntpd/ntp_config.c
--- ntp-dev-4.2.7p250/ntpd/ntp_config.c 2011-12-18 06:01:48.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpd/ntp_config.c 2012-01-16 12:27:05.000000000 -0500
@@ -33,6 +33,10 @@
#include <isc/net.h>
#include <isc/result.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntp.h"
#include "ntpd.h"
#include "ntp_io.h"
@@ -1664,6 +1668,9 @@
sockaddr_u *final_addr;
struct addrinfo *ptr;
int gai_err;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
final_addr = emalloc(sizeof(*final_addr));
@@ -1672,15 +1679,34 @@
addr_prefix, curr_addr_num++);
printf("Selecting ip address %s for hostname %s\n",
addr_string, addr->address);
+#ifdef HAVE_DNSVAL
+ gai_err = val_getaddrinfo(NULL, addr_string, "ntp", NULL, &ptr, &val_status);
+#else
gai_err = getaddrinfo(addr_string, "ntp", NULL, &ptr);
+#endif
} else {
+#ifdef HAVE_DNSVAL
+ gai_err = val_getaddrinfo(NULL, addr->address, "ntp", NULL, &ptr, &val_status);
+#else
gai_err = getaddrinfo(addr->address, "ntp", NULL, &ptr);
+#endif
}
if (gai_err) {
fprintf(stderr, "ERROR!! Could not get a new address\n");
exit(1);
}
+
+#ifdef HAVE_DNSVAL
+ if (!val_istrusted(val_status)) {
+ fprintf(stderr, "ERROR!! DNSSEC validation for address failed\n");
+ if (ptr) {
+ freeaddrinfo(ptr);
+ }
+ exit(1);
+ }
+#endif
+
memcpy(final_addr, ptr->ai_addr, ptr->ai_addrlen);
fprintf(stderr, "Successful in setting ip address of simulated server to: %s\n",
stoa(final_addr));
@@ -2221,6 +2247,9 @@
#else
"mssntp restrict bit ignored, this ntpd was configured without --enable-ntp-signd.";
#endif
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/* Configure the mru options */
my_opt = HEAD_PFIFO(ptree->mru_opts);
@@ -2459,16 +2488,36 @@
hints.ai_protocol = IPPROTO_UDP;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_family = my_node->addr->type;
+
+#ifdef HAVE_DNSVAL
+ rc = val_getaddrinfo(NULL, my_node->addr->address,
+ "ntp", &hints,
+ &ai_list, &val_status);
+#else
rc = getaddrinfo(my_node->addr->address,
"ntp", &hints,
&ai_list);
- if (rc) {
+#endif
+
+ if (rc) {
msyslog(LOG_ERR,
"restrict: ignoring line %d, address/host '%s' unusable.",
my_node->line_no,
my_node->addr->address);
continue;
}
+#ifdef HAVE_DNSVAL
+ if (!val_istrusted(val_status)) {
+ msyslog(LOG_ERR,
+ "restrict: ignoring line %d, address/host '%s' could not be validated.",
+ my_node->line_no,
+ my_node->addr->address);
+ if (ai_list) {
+ freeaddrinfo(ai_list);
+ }
+ continue;
+ }
+#endif
NTP_INSIST(ai_list != NULL);
pai = ai_list;
NTP_INSIST(pai->ai_addr != NULL);
diff -u -r ntp-dev-4.2.7p250/ntpd/ntp_loopfilter.c ntp-dev-4.2.7p250.dnssec/ntpd/ntp_loopfilter.c
--- ntp-dev-4.2.7p250/ntpd/ntp_loopfilter.c 2011-12-18 06:01:47.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpd/ntp_loopfilter.c 2012-01-16 12:27:05.000000000 -0500
@@ -8,6 +8,10 @@
# include <config.h>
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_unixtime.h"
@@ -136,6 +140,7 @@
static void stop_kern_loop(void);
#endif /* KERNEL_PLL */
+
/*
* Clock state machine control flags
*/
@@ -178,6 +183,7 @@
#endif /* SIGSYS */
#endif /* KERNEL_PLL */
+
/*
* init_loopfilter - initialize loop filter data
*/
@@ -445,6 +451,19 @@
* startup until the initial transient has subsided.
*/
default:
+#ifdef HAVE_DNSVAL
+ if (allow_panic) {
+ /* Enable DNSSEC Validation */
+ if (VAL_NO_ERROR != val_context_setqflags(NULL, VAL_CTX_FLAG_RESET, VAL_QUERY_IGNORE_SKEW)) {
+ /* something didn't work right, log and keep trying */
+ msyslog(LOG_NOTICE, "DNSSEC clock-skew tolerance could not be disabled. Panic correction still in effect.");
+ } else {
+ msyslog(LOG_NOTICE, "DNSSEC clock-skew tolerance disabled.");
+ allow_panic = FALSE;
+ }
+ }
+ else /* fall-through */
+#endif
allow_panic = FALSE;
if (freq_cnt == 0) {
diff -u -r ntp-dev-4.2.7p250/ntpd/ntpd.c ntp-dev-4.2.7p250.dnssec/ntpd/ntpd.c
--- ntp-dev-4.2.7p250/ntpd/ntpd.c 2012-01-15 06:06:40.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpd/ntpd.c 2012-01-16 12:27:05.000000000 -0500
@@ -977,6 +977,9 @@
# ifndef HAVE_SIGNALED_IO
rdfdes = activefds;
# if !defined(VMS) && !defined(SYS_VXWORKS)
+# ifdef HAVE_DNSVAL
+ val_async_select_info(NULL, &rdfdes, &maxactivefd, NULL);
+# endif
nfound = select(maxactivefd + 1, &rdfdes, NULL,
NULL, NULL);
# else /* VMS, VxWorks */
@@ -986,11 +989,18 @@
t1.tv_sec = 1;
t1.tv_usec = 0;
+# ifdef HAVE_DNSVAL
+ val_async_select_info(NULL, &rdfdes, &maxactivefd, &t1);
+# endif
nfound = select(maxactivefd + 1,
&rdfdes, NULL, NULL,
&t1);
}
# endif /* VMS, VxWorks */
+
+# ifdef HAVE_DNSVAL
+ val_async_check_wait(NULL, &rdfdes, &maxactivefd, NULL, 0);
+# endif
if (nfound > 0) {
l_fp ts;
@@ -1008,7 +1018,6 @@
}
# endif /* DEBUG */
# else /* HAVE_SIGNALED_IO */
-
wait_for_signal();
# endif /* HAVE_SIGNALED_IO */
if (alarm_flag) { /* alarmed? */
diff -u -r ntp-dev-4.2.7p250/ntpd/refclock_nmea.c ntp-dev-4.2.7p250.dnssec/ntpd/refclock_nmea.c
--- ntp-dev-4.2.7p250/ntpd/refclock_nmea.c 2012-01-06 06:07:50.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpd/refclock_nmea.c 2012-01-16 12:27:05.000000000 -0500
@@ -30,6 +30,10 @@
#include <stdio.h>
#include <ctype.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_unixtime.h"
@@ -1663,6 +1667,9 @@
struct addrinfo ai_hint; /* resolution hint */
struct addrinfo *ai_list; /* resolution result */
struct addrinfo *ai; /* result scan ptr */
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
fd = -1;
@@ -1689,8 +1696,21 @@
ZERO(ai_hint);
ai_hint.ai_protocol = IPPROTO_TCP;
ai_hint.ai_socktype = SOCK_STREAM;
+
+#ifdef HAVE_DNSVAL
+ if (val_getaddrinfo(NULL, host, port, &ai_hint, &ai_list, &val_status))
+ return fd;
+
+ if (!val_istrusted(val_status)) {
+ if (ai_list) {
+ freeaddrinfo(ai_list);
+ }
+ return fd;
+ }
+#else
if (getaddrinfo(host, port, &ai_hint, &ai_list))
return fd;
+#endif
for (ai = ai_list; ai && (fd == -1); ai = ai->ai_next) {
sh = socket(ai->ai_family, ai->ai_socktype,
Only in ntp-dev-4.2.7p250.dnssec/ntpd: refclock_nmea.c.orig
diff -u -r ntp-dev-4.2.7p250/ntpdate/ntpdate.c ntp-dev-4.2.7p250.dnssec/ntpdate/ntpdate.c
--- ntp-dev-4.2.7p250/ntpdate/ntpdate.c 2012-01-06 06:07:57.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpdate/ntpdate.c 2012-01-16 12:27:05.000000000 -0500
@@ -48,6 +48,10 @@
#include <arpa/inet.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#ifdef SYS_VXWORKS
# include "ioLib.h"
# include "sockLib.h"
@@ -1351,6 +1355,9 @@
/* Service name */
char service[5];
sockaddr_u addr;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
strlcpy(service, "ntp", sizeof(service));
@@ -1364,8 +1371,13 @@
printf("Looking for host %s and service %s\n", serv, service);
#endif
+#ifdef HAVE_DNSVAL
+ error = val_getaddrinfo(NULL, serv, service, &hints, &addrResult, &val_status);
+ if (error != 0 || !val_istrusted(val_status)) {
+#else
error = getaddrinfo(serv, service, &hints, &addrResult);
if (error != 0) {
+#endif
/* Conduct more refined error analysis */
if (error == EAI_FAIL || error == EAI_AGAIN){
/* Name server is unusable. Exit after failing on the
@@ -1679,6 +1691,9 @@
int rc;
int optval = 1;
int check_ntp_port_in_use = !debug && !simple_query && !unpriv_port;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/*
* Init buffer free list and stat counters
@@ -1699,7 +1714,15 @@
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_DGRAM;
+#ifdef HAVE_DNSVAL
+ if (val_getaddrinfo(NULL, NULL, service, &hints, &res, &val_status) != 0 ||
+ !val_istrusted(val_status)) {
+ if (res) {
+ freeaddrinfo(res);
+ }
+#else
if (getaddrinfo(NULL, service, &hints, &res) != 0) {
+#endif
msyslog(LOG_ERR, "getaddrinfo() failed: %m");
exit(1);
/*NOTREACHED*/
diff -u -r ntp-dev-4.2.7p250/ntpdc/ntpdc.c ntp-dev-4.2.7p250.dnssec/ntpdc/ntpdc.c
--- ntp-dev-4.2.7p250/ntpdc/ntpdc.c 2012-01-15 06:06:40.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpdc/ntpdc.c 2012-01-16 12:27:05.000000000 -0500
@@ -19,6 +19,10 @@
#include <isc/net.h>
#include <isc/result.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntpdc.h"
#include "ntp_select.h"
#include "ntp_stdlib.h"
@@ -396,6 +400,9 @@
register const char *cp;
char name[LENHOSTNAME];
char service[5];
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/*
* We need to get by the [] if they were entered
@@ -429,7 +436,11 @@
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = Z_AI_NUMERICHOST;
+#ifdef HAVE_DNSVAL
+ a_info = val_getaddrinfo(NULL, hname, service, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, service, &hints, &ai);
+#endif
if (a_info == EAI_NONAME
#ifdef EAI_NODATA
|| a_info == EAI_NODATA
@@ -439,12 +450,26 @@
#ifdef AI_ADDRCONFIG
hints.ai_flags |= AI_ADDRCONFIG;
#endif
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ a_info = val_getaddrinfo(NULL, hname, service, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, service, &hints, &ai);
+#endif
}
/* Some older implementations don't like AI_ADDRCONFIG. */
if (a_info == EAI_BADFLAGS) {
hints.ai_flags = AI_CANONNAME;
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ a_info = val_getaddrinfo(NULL, hname, service, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, service, &hints, &ai);
+#endif
}
if (a_info != 0) {
fprintf(stderr, "%s\n", gai_strerror(a_info));
@@ -453,6 +478,15 @@
return 0;
}
+#ifdef HAVE_DNSVAL
+ if (!val_istrusted(val_status)) {
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ return 0;
+ }
+#endif
+
/*
* getaddrinfo() has returned without error so ai should not
* be NULL.
@@ -1423,6 +1457,9 @@
)
{
struct addrinfo hints, *ai = NULL;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
ZERO(hints);
hints.ai_flags = AI_CANONNAME;
@@ -1436,10 +1473,20 @@
*/
if (decodenetnum(hname, num)) {
if (fullhost != NULL)
+#ifdef HAVE_DNSVAL
+ val_getnameinfo(NULL, &num->sa, SOCKLEN(num), fullhost,
+ LENHOSTNAME, NULL, 0, 0, &val_status);
+#else
getnameinfo(&num->sa, SOCKLEN(num), fullhost,
LENHOSTNAME, NULL, 0, 0);
+#endif
return 1;
+#ifdef HAVE_DNSVAL
+ } else if (val_getaddrinfo(NULL, hname, "ntp", &hints, &ai, &val_status) == 0 &&
+ val_istrusted(val_status)) {
+#else
} else if (getaddrinfo(hname, "ntp", &hints, &ai) == 0) {
+#endif
NTP_INSIST(sizeof(*num) >= ai->ai_addrlen);
memcpy(num, ai->ai_addr, ai->ai_addrlen);
if (fullhost != NULL) {
@@ -1447,12 +1494,31 @@
strlcpy(fullhost, ai->ai_canonname,
LENHOSTNAME);
else
+#ifdef HAVE_DNSVAL
+ if (0 == val_getnameinfo(NULL, &num->sa, SOCKLEN(num),
+ fullhost, LENHOSTNAME, NULL,
+ 0, 0, &val_status) && !val_istrusted(val_status)) {
+ memset(&num->sa, 0, sizeof(num->sa));
+ }
+#else
getnameinfo(&num->sa, SOCKLEN(num),
fullhost, LENHOSTNAME, NULL,
0, 0);
+#endif
+ }
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
}
+
+#endif
return 1;
}
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+#endif
fprintf(stderr, "***Can't find host %s\n", hname);
return 0;
Only in ntp-dev-4.2.7p250.dnssec/ntpdc: ntpdc.c.orig
diff -u -r ntp-dev-4.2.7p250/ntpq/ntpq.c ntp-dev-4.2.7p250.dnssec/ntpq/ntpq.c
--- ntp-dev-4.2.7p250/ntpq/ntpq.c 2012-01-15 06:06:40.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/ntpq/ntpq.c 2012-01-16 12:36:10.000000000 -0500
@@ -20,6 +20,10 @@
#include <isc/net.h>
#include <isc/result.h>
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
+
#include "ntpq.h"
#include "ntp_stdlib.h"
#include "ntp_unixtime.h"
@@ -521,6 +525,9 @@
size_t octets;
register const char *cp;
char name[LENHOSTNAME];
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
/*
* We need to get by the [] if they were entered
@@ -554,7 +561,11 @@
hints.ai_flags = Z_AI_NUMERICHOST;
ai = NULL;
+#ifdef HAVE_DNSVAL
+ a_info = val_getaddrinfo(NULL, hname, svc, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, svc, &hints, &ai);
+#endif
if (a_info == EAI_NONAME
#ifdef EAI_NODATA
|| a_info == EAI_NODATA
@@ -564,19 +575,42 @@
#ifdef AI_ADDRCONFIG
hints.ai_flags |= AI_ADDRCONFIG;
#endif
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ a_info = val_getaddrinfo(NULL, hname, svc, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, svc, &hints, &ai);
+#endif
}
#ifdef AI_ADDRCONFIG
/* Some older implementations don't like AI_ADDRCONFIG. */
if (a_info == EAI_BADFLAGS) {
hints.ai_flags &= ~AI_ADDRCONFIG;
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ a_info = val_getaddrinfo(NULL, hname, svc, &hints, &ai, &val_status);
+#else
a_info = getaddrinfo(hname, svc, &hints, &ai);
+#endif
}
#endif
if (a_info != 0) {
fprintf(stderr, "%s\n", gai_strerror(a_info));
return 0;
}
+#ifdef HAVE_DNSVAL
+ if (!val_istrusted(val_status)) {
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+ fprintf(stderr, "%s\n", "DNSSEC Validation failed.");
+ return 0;
+ }
+#endif
INSIST(ai != NULL);
ZERO(addr);
@@ -1706,6 +1740,9 @@
)
{
struct addrinfo hints, *ai = NULL;
+#ifdef HAVE_DNSVAL
+ val_status_t val_status;
+#endif
ZERO(hints);
hints.ai_flags = AI_CANONNAME;
@@ -1719,10 +1756,20 @@
*/
if (decodenetnum(hname, num)) {
if (fullhost != NULL)
+#ifdef HAVE_DNSVAL
+ val_getnameinfo(NULL, &num->sa, SOCKLEN(num), fullhost,
+ LENHOSTNAME, NULL, 0, 0, &val_status);
+#else
getnameinfo(&num->sa, SOCKLEN(num), fullhost,
LENHOSTNAME, NULL, 0, 0);
+#endif
return 1;
+#ifdef HAVE_DNSVAL
+ } else if (val_getaddrinfo(NULL, hname, "ntp", &hints, &ai, &val_status) == 0 &&
+ val_istrusted(val_status)) {
+#else
} else if (getaddrinfo(hname, "ntp", &hints, &ai) == 0) {
+#endif
INSIST(sizeof(*num) >= ai->ai_addrlen);
memcpy(num, ai->ai_addr, ai->ai_addrlen);
if (fullhost != NULL) {
@@ -1730,13 +1777,24 @@
strlcpy(fullhost, ai->ai_canonname,
LENHOSTNAME);
else
+#ifdef HAVE_DNSVAL
+ val_getnameinfo(NULL, &num->sa, SOCKLEN(num),
+ fullhost, LENHOSTNAME, NULL,
+ 0, 0, &val_status);
+#else
getnameinfo(&num->sa, SOCKLEN(num),
fullhost, LENHOSTNAME, NULL,
0, 0);
+#endif
}
freeaddrinfo(ai);
return 1;
}
+#ifdef HAVE_DNSVAL
+ if (ai) {
+ freeaddrinfo(ai);
+ }
+#endif
fprintf(stderr, "***Can't find host %s\n", hname);
return 0;
Only in ntp-dev-4.2.7p250.dnssec/ntpq: ntpq.c.orig
diff -u -r ntp-dev-4.2.7p250/sntp/config.h.in ntp-dev-4.2.7p250.dnssec/sntp/config.h.in
--- ntp-dev-4.2.7p250/sntp/config.h.in 2012-01-15 06:36:48.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/sntp/config.h.in 2012-01-16 12:27:05.000000000 -0500
@@ -74,6 +74,9 @@
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
+/* Perform local DNSSEC Validation using dnsval */
+#undef HAVE_DNSVAL
+
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
#undef HAVE_DOPRNT
@@ -786,6 +789,28 @@
/* What type to use for setsockopt */
#undef TYPEOF_IP_MULTICAST_LOOP
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# undef _ALL_SOURCE
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# undef _GNU_SOURCE
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
/* Can we use SIGPOLL for tty IO? */
#undef USE_TTY_SIGPOLL
@@ -838,9 +863,6 @@
/* enable thread safety */
#undef _THREAD_SAFE
-/* Define to 500 only on HP-UX. */
-#undef _XOPEN_SOURCE
-
/* Are we _special_? */
#undef __APPLE_USE_RFC_3542
@@ -849,28 +871,6 @@
# undef __CHAR_UNSIGNED__
#endif
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# undef _ALL_SOURCE
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# undef _GNU_SOURCE
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# undef _POSIX_PTHREAD_SEMANTICS
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# undef _TANDEM_SOURCE
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
-#endif
-
-
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
diff -u -r ntp-dev-4.2.7p250/sntp/configure.ac ntp-dev-4.2.7p250.dnssec/sntp/configure.ac
--- ntp-dev-4.2.7p250/sntp/configure.ac 2011-08-09 04:02:45.000000000 -0400
+++ ntp-dev-4.2.7p250.dnssec/sntp/configure.ac 2012-01-16 12:27:05.000000000 -0500
@@ -102,6 +102,28 @@
dnl AC_SEARCH_LIBS([inet_pton], [nsl])
AC_SEARCH_LIBS([openlog], [gen syslog])
+dnl
+dnl Check for DNSSEC support
+dnl
+AC_ARG_WITH(
+ [dnsval],
+ AS_HELP_STRING([--with-dnsval], [- Enable local DNSSEC validation using dnsval]),
+ want_dnssec=$withval,
+ want_dnssec=no)
+case "$want_dnssec" in
+ yes)
+ if test "x$ac_cv_header_pthread_h" != xyes; then
+ AC_MSG_ERROR(["Configured needs to be fine-tuned for non-pthread support"])
+ fi
+ AC_CHECK_LIB([val-threads],
+ [val_getaddrinfo],
+ [LIBS="-lval-threads -lsres -lcrypto $LIBS"
+ AC_DEFINE([HAVE_DNSVAL], [1], [Perform local DNSSEC Validation using dnsval])],
+ [AC_MSG_ERROR(["Can't find required libraries for DNSSEC support"])],
+ [-lsres -lcrypto])
+ ;;
+esac
+
# Checks for header files.
AC_CHECK_HEADERS([netdb.h string.h strings.h syslog.h])
diff -u -r ntp-dev-4.2.7p250/sntp/main.c ntp-dev-4.2.7p250.dnssec/sntp/main.c
--- ntp-dev-4.2.7p250/sntp/main.c 2012-01-08 18:03:10.000000000 -0500
+++ ntp-dev-4.2.7p250.dnssec/sntp/main.c 2012-01-16 12:27:05.000000000 -0500
@@ -7,6 +7,9 @@
#ifdef WORK_THREAD
# include <event2/thread.h>
#endif
+#ifdef HAVE_DNSVAL
+#include <validator/validator.h>
+#endif
#include "main.h"
#include "ntp_libopts.h"
@@ -267,6 +270,29 @@
for (i = 0; i < argc; ++i)
handle_lookup(argv[i], CTX_UCST);
+/*
+ * If we used getaddrinfo_sometime() [non-blocking] instead of
+ * getaddrinfo_sometime_blocking() to issue the queries then the following
+ * code block would need to be uncommented. The issue with using the
+ * non-blocking lookup routine is that it cannot be used effectively in
+ * conjunction with libevent. That is, we'd need to wait for all DNS lookups
+ * to complete before we are able to send NTP packets out.
+ * The better approach would be to instrument libevent to use dnsval's
+ * async validation routines internally.
+ */
+#if 0
+#if HAVE_DNSVAL
+ do {
+ fd_set fds;
+ int numfds;
+
+ FD_ZERO(&fds); /* clear fd_set */
+ numfds = 0; /* no FDs yet */
+ val_async_select(NULL, &fds, &numfds, NULL, 0);
+ val_async_check_wait(NULL, &fds, &numfds, NULL, 0);
+ } while (n_pending_dns > 0);
+#endif
+#endif
event_base_dispatch(base);
event_base_free(base);
@@ -417,8 +443,22 @@
}
++n_pending_dns;
+#ifdef HAVE_DNSVAL
+ /*
+ * It is possible to use getaddrinfo_sometime() [non-blocking] in
+ * place of getaddrinfo_sometime_blocking() too.
+ * If we did so, we'd have to manage the descriptors
+ * associated with the DNS lookup within sntp itself.
+ * But this approach is sub-optimal when used in
+ * conjunction with libevent.
+ * Also See the ifdef 0 block in sntp_main().
+ */
+ getaddrinfo_sometime_blocking(name, "123", &hints, 0,
+ &sntp_name_resolved, ctx);
+#else
getaddrinfo_sometime(name, "123", &hints, 0,
&sntp_name_resolved, ctx);
+#endif
}
|