diff --git a/contrib/bind/CHANGES b/contrib/bind/CHANGES index 4a1f47de2698..80fb7bc7eb40 100644 --- a/contrib/bind/CHANGES +++ b/contrib/bind/CHANGES @@ -1,4 +1,315 @@ - --- 8.2.4-REL released --- (Wed May 9 14:36:23 PDT 2001) + + --- 8.3.1-REL released --- (Thu Jan 31 21:28:59 PST 2002) + +1332. [func] "allow-query" is now supported for forward zones. + #define FORWARD_ALLOWS in bin/named/named.h to enable. + +1331. [bug] rrsetadd() should explictly attach to the databuf + rather than inheriting the reference count. + +1330. [bug] potential reference after free. + +1329. [port] linux: ensure that CC is correctly propgated to + probe_ipv6. + +1328. [port] linux: res_init.c failed to compile on certian older + machines. + +1327. [contrib] add mysqlBind reference. + +1326. [bug] named-xfer could incorrectly report a fopen() failure + as a fdopen() failure. + +1325. [bug] if fdopen() failed empty files could be left behind. + +1324. [bug] certian bad delegations could result in a DNS storm. + +1323. [bug] cached NXDOMAIN/NODATA responses were being ignored + when when fetching missing additional data. + + + --- 8.3.0-REL released --- (Fri Jan 11 04:00:00 PST 2002) + +1323. [bug] don't assume statp->_u._ext.ext is valid unless + RES_INIT is set when calling res_*init(). + +1322. [bug] call res_ndestroy() if RES_INIT is set when + res_*init() is called. + +1321. [cleanup] YPKLUDGE in no longer default. + +1320. [port] winnt: namespace collision #undef the system's EV_ERR. + +1319. [port] winnt: make __res_nopt() visible externally. + +1318. [port] Tru64 UNIX V5.1 can return spurious EINVAL on + close() after connect() failure. + +1317. [bug] NULL used where zero was required. + + --- 8.3.0-RC2 released --- (Wed Jan 2 17:14:23 PST 2002) + +1316. [bug] memory leak when a ixfr update or a re-applied update + was rejected. + +1315. [bug] the wrong options level check-names value was used + when merging ixfr updates. + +1314. [bug] corrupt update / ixfr updates should result in + merge errors being reported. + +1313. [bug] set current_serial in db_ixfr.c:ixfr_getdelta(). + +1312. [bug] use serial space arithmetic when selecting deltas for + IXFR. + +1311. [contrib] mdnkit update to 2.2.3 + +1310. [bug] TSIG signed IXFR's wern't correctly verified. + +1309. [port] winnt: re-order fclose/unlink so that the unlink + succeeds. + +1308. [doc] miscellaneous nroff fixes. + +1307. [func] preferred-glue can now be used to partially order + the additional section. + +1306. [bug] It was possible to trigger an INSIST failure with + certian EDNS responses. + +1305. [bug] named-xfer could return a false up-to-date status. + +1304. [bug] "named-xfer -x" didn't attempt to use the specified + address for all possible masters if earlier connects + failed. + +1303. [contrib] nslint upgraded from 2.0.2 to 2.1a3 (by author). + +1302. [bug] res_nametotype() and res_nametoclass() were broken. + +1301. [bug] "ndc reload zone" without class was broken. + +1300. [port] Tru64 UNIX 5.1 does not like __align as a element name. + +1299. [bug] host failed to handle "." in search list correctly. + +1298. [bug] max-ixfr-log-size default was unreasonable. + +1297. [bug] read buffer overflows. + +1296. [protocol] NAPTR additional section processing. + + --- 8.3.0-RC1 released --- (Wed Nov 21 20:41:32 PST 2001) + +1295. [bug] be more aggressive at dropping messages from certian + well known ports. + +1294. [bug] hint zones and root stub zones were not being removed + correctly. + +1293. [port] MPE/iX workaround recvfrom() not supporting larger + address buffers required for IPv6. + +1292. [bug] memory leak: free_flushset(). + +1291. [func] accept and generate EDNS0 queries. + +1290. [func] allow initial notifies on startup to be suppressed. + [Kenneth Karoliussen, kenneth@activeisp.com] + +1289. [func] allow keys to be specified in the masters clause. + +1288. [func] named-xfer report if response was signed. + +1287. [bug] named-xfer could report false TSIG failures under + certian conditions. + +1286. [bug] don't allow rtt estimates to drop to zero. + +1285. [bug] non-answering servers rtt estimates were not always + penalised. + +1284. [bug] struct __res_state was still broken after #1265. + +1283. [port] addition platform support for _r functions. + +1282. [port] pw->pw_class is platform dependant. + +1281. [port] namespace collision: dprintf -> res_dprintf, + ERR -> EV_ERR, OK -> EV_OK. + +1280. [cleanup] gai_strerror() re-written. + +1279. [bug] non-glue was not being reported on reload. + +1278. [bug] Remove the INSIST at the end if zone_maint(). + +1277. [func] hostname.bind/txt/chaos now returns the name of + the machine hosting the nameserver. This is useful + in diagnosing problems with anycast servers. + +1276. [bug] dns_ho.c:add_hostent() was not returning the amount + of memory consumed resulting in garbage address + being returned. Alignment calculations were + wasting space. We wern't suppressing duplicate + addresses. + +1275. [port] sunos: old sprintf. + +1274. [port] MPE/iX C.70 + +1273. [bug] host was sorting multiple RRs into the wrong order + prior to verifying. + + --- 8.3.0-T2A released --- (Thu Sep 27 18:15:00 PDT 2001) + +1272. [bug] "ndc trace 0" should behave like "ndc notrace". + +1271. [func] inet_{cidr,net}_{pton,ntop}() now have IPv6 support. + +1270. [bug] AXFR style IXFR responses were not handled properly, + transfer-format single-answer. + +1269. [bug] misc: more string format fixes, open va_end(), + call exit() with positive values, include . + +1268. [func] Resolver, dig: "DNSSEC OK" (DO) support. + +1267. [port] HP e3000 MPE is big-endian. + +1266. [func] dig +[no]tr: use relative names when printing + out a zone transfer ([NO]TRuncate). + +1265. [bug] struct __res_state to large on 64 bit arch. + +1264. [port] winnt: pass the root zone as "." to named-xfer + rather than "". + +1263. [port] #1227 broke sunos. + +1262. [func] log type as well as class for denied queries. + +1261. [bug] get*by*() failed to check if res_init() had been + called. + +1260. [func] resolver option: no-tld-query. disables trying + unqualified as a tld. no_tld_query is also supported + for FreeBSD compatability. + +1259. [func] enable NOADDITIONAL code by default. + +1258. [func] treat class ANY as class IN for access control for + non-xfr queries. + +1257. [func] increase nameserver chaining distance from 1 to 3 + (NS_MAX_DISTANCE). + +1256. [bug] increased loop avoidance with well known ports. + +1255. [bug] cached NXDOMAIN responses were being ignored when + selecting servers to query. + +1254. [support] improved support for parallel make. + +1253. [port] winnt: support for change #1218 + +1252. [port] winnt: the stat structure does not have st_blksize. + +1251. [bug] AXFR style IXFR responses were not handled properly. + +1250. [doc] document support-ixfr. + +1249. [func] add support gcc's format string checking. + +1248. [bug] string formats. + +1247. [bug] dig -t axfr attempted to use UDP not TCP. + +1246. [doc] miscellaneous nroff fixes. + +1245. [port] winnt: named-xfer failures. improved recvfrom() + emulation. + +1244. [port] winnt: bug in tracking "file" file descriptors + extend "file" file descriptors support to 2048. + +1243. [cleanup] defining REPORT_ERRORS in lib/dst caused compile time + errors. + +1242. [bug] inet_pton() failed to reject octal input. + +1241. [bug] memory leaks: zone forwarder table, server key list, + global forwarder table, query tsig info, unused + channels, key names, xfr tsig info. + +1240. [bug] restore message if ns_forw() fails. + +1239. [bug] call res_ndestroy() in net_data_destroy(). + +1238. [func] named-bootconf now supports HP's "no-round-robin". + +1237. [bug] buffer overrun, access mode read. + +1236. [bug] ignore white space after address of nameserver. + +1235. [port] solaris 2.4: use ioctl(FIONBIO) rather than fcntl(). + + --- 8.3.0-T1A released --- (Wed Jun 20 19:05:01 PDT 2001) + +1234. [bug] memory leak with "use-id-pool no;". + +1233. [func] res_setservers(), res_getservers(). + +1232. [bug] don't assume the forwarder has dropped bogus records. + +1231. [bug] always restart a query if we dropped records when + parsing. + +1230. [func] report the address the server learnt the record from + in lame server messages. + +1229. [func] opaque rdata support for unknown types. + +1228. [protocol] IXFR don't test for AA, don't check that the question + is returned. + +1227. [port] solaris: sys_nerr and sys_errlist do not exist when + compiling in 64 bit mode. + +1226. [placeholder] + +1225. [bug] don't send cross class additional records. + +1224. [bug] use after realloc(), non portable pointer arithmetic in + grmerge(). + +1223. [bug] allow all KEY records in parent zone at bottom of zone + cut. + +1222. [bug] HMAC-MD5 key files are now mode 0600. + +1221. [port] aix: 4.3.3.0 (4.3.2.0?) and later have strndup(). + +1220. [port] winnt: isc_movefile() and syslog() updated. + +1219. [bug] winnt: zone transfers could fail. + +1218. [func] add IPv6 transport support to the resolver from the + KAME project. Includes initial bitstring support. + +1217. [bug] #1186 broke the command-line programs that relied on + the fact that HMAC-MD5 keys have keyid 0. + +1216. [bug] #1180 completely broke inet_nsap_addr(), + inet_nsap_ntoa() still didn't emit the leading 0x. + +1215. [bug] long UNIX domain control socket names were not being + printed in full. + +1214. [bug] getrgnam()/getgrgid() leaked memory. + +1213. [bug] #1199 introduced a reference after free bug. 1212. [bug] some function declarations wern't protected by __BEGIN_DECL/__END_DECL in resolv.h. @@ -9,7 +320,8 @@ 1209. [port] winnt: issues. - --- 8.2.4-T2B released --- (Thu May 3 05:48:14 PDT 2001) +1208. [func] close "dynamic" file channels when debug is set to + zero allowing them to be removed and re-opened. 1207. [contrib] new h2n from author. @@ -23,10 +335,21 @@ 1202. [bug] memory leak: dynamic update was leaking. +1201. [bug] ISO/IEC 9945-1 versions of getpwuid_r(), getpwnam_r(), + getgrgid_r() and getgrnam_r() were not ISO/IEC 9945-1 + compliant. + 1200. [bug] memory leak: when following CNAMES from of req_query(). 1199. [bug] memory leak: when defining keys. +1198. [func] reference count all databuf activity. + +1197. [func] deallocate-on-exit yes; will call abort() if there + is still active memory. + +1196. [func] memactive(): report if there is still active memory. + 1195. [bug] memory leak: include in named.conf leaked file name. 1194. [port] MPE/IX port updated by Mark Bixby of the diff --git a/contrib/bind/INSTALL b/contrib/bind/INSTALL index ed7157c57fdf..42f94b04ef7a 100644 --- a/contrib/bind/INSTALL +++ b/contrib/bind/INSTALL @@ -203,6 +203,10 @@ Operating System Notes Read src/port/next/README.FIRST before trying to build. + MPE/iX IPv6 is *not* supported. src/port/mpe/recvfrom.c needs to + be re-written to support IPv6 if and when the OS supports + IPv6. + Certain older versions of FreeBSD, NetBSD and BSD/OS These systems have a /bin/sh based on "ash", which doesn't diff --git a/contrib/bind/Makefile b/contrib/bind/Makefile index 45d4b0b1ce11..3596dd4f9b28 100644 --- a/contrib/bind/Makefile +++ b/contrib/bind/Makefile @@ -1,4 +1,4 @@ -## Copyright (c) 1996,1999 by Internet Software Consortium, Inc. +## Copyright (c) 1996,1999 by Internet Software Consortium. ## ## Permission to use, copy, modify, and distribute this software for any ## purpose with or without fee is hereby granted, provided that the above @@ -13,58 +13,56 @@ ## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ## SOFTWARE. -# $Id: Makefile,v 1.10 2000/11/13 02:26:12 vixie Exp $ +# $Id: Makefile,v 8.52 2000/11/21 12:54:37 marka Exp $ -# This is just for making distributions. For the real Makefile, cd src. +TOP= +SUBDIRS= include port lib bin -all clean depend: FRC - @echo go to the ./src directory, you cannot make '"'$@'"' here. - @false +SH=sh -tar: bind-doc.tar.gz bind-src.tar.gz bind-contrib.tar.gz +default: all -pgp: bind-doc.tar.gz.asc bind-src.tar.gz.asc bind-contrib.tar.gz.asc +all clean depend install distclean:: FRC + @set -e; \ + version=`cat ${TOP}Version`; \ + systype=`${SH} ${TOP}port/systype ${TOP}.systype`; \ + if [ $$systype = "unknown" ]; then \ + echo "There is no BIND port for this system in this kit."; \ + else \ + settings=`${SH} ${TOP}port/settings ${TOP}.settings \ + < ${TOP}port/$$systype/Makefile.set`; \ + PATH=`pwd`/port/$$systype/bin:$$PATH; export PATH; \ + for x in ${SUBDIRS}; do \ + ( cd $$x; pwd; \ + eval "${MAKE} $$settings ${MARGS} SYSTYPE=$$systype \ + VER=$$version \ + $@"; \ + ) || exit 1; \ + done \ + fi -bind-doc.tar.gz: Makefile - cd doc/bog; make clean file.psf file.lst - cd doc/man; make clean all - cd doc/man; make MANROFF="groff -t" OUT_EXT=psf clean all - tar cf - Makefile doc | gzip > bind-doc.tar.gz - cd doc/man; make clean - cd doc/man; make MANROFF="groff -t" OUT_EXT=psf clean +clean distclean:: + rm -f .systype .settings -bind-src.tar.gz: Makefile - cd src; make distclean - cd src/bin/nslookup; make commands.c - cd src/bin/named; make ns_parser.c - tar cf - Makefile src | gzip > bind-src.tar.gz +links: FRC + @set -e; mkdir ${DST}; cd ${DST}; pwd; ln -s ${SRC} SRC; \ + ln -s SRC/Version .; cp SRC/Makefile .; chmod +w Makefile; \ + systype=`${SH} SRC/port/systype`; \ + for x in ${SUBDIRS} ; do \ + ( mkdir $$x; cd $$x; pwd; ln -s ../SRC/$$x SRC; \ + cp SRC/Makefile Makefile; chmod +w Makefile; \ + ${MAKE} ${MARGS} SYSTYPE=$$systype links; \ + ) || exit 1; \ + done -bind-contrib.tar.gz: Makefile - tar cf - Makefile contrib | gzip > bind-contrib.tar.gz +stdlinks: FRC + if [ ! -d /var/obj ]; then \ + mkdir /var/obj; \ + fi + ${MAKE} ${MARGS} SRC=`pwd` DST=/var/obj/bind links -bind-doc.tar.gz.asc: bind-doc.tar.gz - rm -f bind-doc.tar.gz.asc - pgp -u pgpkey@isc.org -sba bind-doc.tar.gz - chmod o+r bind-doc.tar.gz.asc - -bind-src.tar.gz.asc: bind-src.tar.gz - rm -f bind-src.tar.gz.asc - pgp -u pgpkey@isc.org -sba bind-src.tar.gz - chmod o+r bind-src.tar.gz.asc - -bind-contrib.tar.gz.asc: bind-contrib.tar.gz - rm -f bind-contrib.tar.gz.asc - pgp -u pgpkey@isc.org -sba bind-contrib.tar.gz - chmod o+r bind-contrib.tar.gz.asc - -noesw: src/Version src/lib/Makefile src/lib/dst/Makefile \ - src/lib/cylink/. src/lib/dnssafe/. - perl -pi.BAK -e 's/$$/-NOESW/' src/Version - perl -pi.BAK -e 's/ cylink dnssafe//' src/lib/Makefile - perl -pi.BAK -e 's:-I../cylink::' src/lib/dst/Makefile - perl -pi.BAK -e 's:-I../dnssafe::' src/lib/dst/Makefile - perl -pi.BAK -e 's/-DCYLINK_DSS//' src/lib/dst/Makefile - perl -pi.BAK -e 's/-DDNSSAFE//' src/lib/dst/Makefile - rm -rf src/lib/cylink src/lib/dnssafe +uplinks: FRC + @set -e; systype=`${SH} ${TOP}port/systype`; pwd=`pwd`; \ + ${MAKE} ${MARGS} SRC=../`basename $$pwd` "DST=../$$systype" links FRC: diff --git a/contrib/bind/README b/contrib/bind/README index 2a8efb348429..45f37a43b016 100644 --- a/contrib/bind/README +++ b/contrib/bind/README @@ -10,9 +10,23 @@ artifacts including BIND, INN, and DHCP. Note that BIND 8 is in "end-of-life", having been replaced by BIND 9. See http://www.isc.org/ for more details. +BIND 8.3.1 Highlights + Critical bug fix to prevent DNS storms. If you have BIND 8.3.0 you + need to upgrade. + +BIND 8.3.0 Highlights + IPv6 transport support in resolver (from KAME). + Opaque rdata support. + EDNS0 support. + Glue ordering to help non-ENDS0 aware clients (servers) cope with + larger responses as a result of IPv6 by allowing A records to be added + first to the additional section. IPv6 capable clients are expected to + use EDNS0 to allow larger responses to be sent. + Bug Fixes, includes BIND 8.2.5 changes. + BIND 8.2.4 Highlights NSAP processing was not RFC 1706 compliant. NOTE: OLD MASTER FILES - NEED TO BE CORRECTED (0x added to NSAP) AND CACHE FILES REMOVED. + NEED TO BE CORRECTED AND CACHE FILES REMOVED. Fixes long-standing protocol incompatibility in DNSSEC support. Avoids fwd'ing to root name servers if response will be rejected. new port/cygwin contributed by s_c_biggs@bigfoot.com. diff --git a/contrib/bind/Version b/contrib/bind/Version index a2b632db9af9..067312ac29cf 100644 --- a/contrib/bind/Version +++ b/contrib/bind/Version @@ -1 +1 @@ -8.2.4-REL +8.3.1-REL diff --git a/contrib/bind/bin/Makefile b/contrib/bind/bin/Makefile index 5b56413f9b05..575470fc6c1d 100644 --- a/contrib/bind/bin/Makefile +++ b/contrib/bind/bin/Makefile @@ -13,7 +13,7 @@ ## ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ## SOFTWARE. -# $Id: Makefile,v 8.30 2000/12/23 08:02:48 vixie Exp $ +# $Id: Makefile,v 8.31 2001/08/14 05:57:57 marka Exp $ DESTDIR= CC= cc @@ -64,10 +64,10 @@ CPPFLAGS= -I${PORTINCL} -I${INCL} SUBDIRS = addr nslookup dig dnsquery host named named-xfer ndc nsupdate \ mkservdb irpd dnskeygen named-bootconf -all: ${SUBDIRS} - -${SUBDIRS}: FRC - @(cd $@; pwd; ${MAKE} ${MARGS}) || exit 1 +all: + @for x in ${SUBDIRS}; do \ + (cd $$x; pwd; ${MAKE} ${MARGS} $@) || exit 1; \ + done install depend tags clean distclean:: @for x in ${SUBDIRS}; do \ diff --git a/contrib/bind/bin/dig/dig.c b/contrib/bind/bin/dig/dig.c index f8030fd5d53d..037a495e1447 100644 --- a/contrib/bind/bin/dig/dig.c +++ b/contrib/bind/bin/dig/dig.c @@ -1,5 +1,5 @@ #ifndef lint -static const char rcsid[] = "$Id: dig.c,v 8.46 2001/04/01 17:35:01 vixie Exp $"; +static const char rcsid[] = "$Id: dig.c,v 8.51 2001/12/19 02:25:17 marka Exp $"; #endif /* @@ -188,9 +188,15 @@ static const char rcsid[] = "$Id: dig.c,v 8.46 2001/04/01 17:35:01 vixie Exp $"; #define VERSION 83 #define VSTRING "8.3" -#define PRF_DEF 0x2ff9 -#define PRF_MIN 0xA930 -#define PRF_ZONE 0x24f9 +#define PRF_DEF (RES_PRF_STATS | RES_PRF_CMD | RES_PRF_QUES | \ + RES_PRF_ANS | RES_PRF_AUTH | RES_PRF_ADD | \ + RES_PRF_HEAD1 | RES_PRF_HEAD2 | RES_PRF_TTLID | \ + RES_PRF_HEADX | RES_PRF_REPLY | RES_PRF_TRUNC) +#define PRF_MIN (RES_PRF_QUES | RES_PRF_ANS | RES_PRF_HEAD1 | \ + RES_PRF_HEADX | RES_PRF_REPLY | RES_PRF_TRUNC) +#define PRF_ZONE (RES_PRF_STATS | RES_PRF_CMD | RES_PRF_QUES | \ + RES_PRF_ANS | RES_PRF_AUTH | RES_PRF_ADD | \ + RES_PRF_TTLID | RES_PRF_REPLY | RES_PRF_TRUNC) #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 256 @@ -219,7 +225,7 @@ int queryType, queryClass; extern int StringToClass(), StringToType(); /* subr.c */ #if defined(BSD) && BSD >= 199006 && !defined(RISCOS_BSD) FILE *yyin = NULL; -void yyrestart(FILE *f) { } +void yyrestart(FILE *f) { UNUSED(f); } #endif char *pager = NULL; /* end of nslookup stuff */ @@ -448,13 +454,21 @@ main(int argc, char **argv) { printf("; no arg for -t?\n"); else if ((tmp = atoi(*argv)) || *argv[0]=='0') { - queryType = tmp; - qtypeSet++; + if (ns_t_xfr_p(tmp)) { + xfr = tmp; + } else { + queryType = tmp; + qtypeSet++; + } } else if ((tmp = StringToType(*argv, 0, NULL) ) != 0) { - queryType = tmp; - qtypeSet++; + if (ns_t_xfr_p(tmp)) { + xfr = tmp; + } else { + queryType = tmp; + qtypeSet++; + } } else { printf( "; invalid type specified\n" @@ -832,6 +846,7 @@ main(int argc, char **argv) { if (n < 0) { fflush(stderr); printf(";; res_nmkquery: buffer too small\n\n"); + fflush(stdout); continue; } if (queryType == T_IXFR) { @@ -857,6 +872,13 @@ main(int argc, char **argv) { bytes_out = n = cpp - packet; }; +#if defined(RES_USE_EDNS0) && defined(RES_USE_DNSSEC) + if (n > 0 && + (res.options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0) + bytes_out = n = res_nopt(&res, n, packet, + sizeof(packet), 4096); +#endif + eecode = 0; if (res.pfcode & RES_PRF_HEAD1) fp_resstat(&res, stdout); @@ -954,14 +976,15 @@ where: server,\n\ d-opt is of the form ``+keyword=value'' where keyword is one of:\n\ [no]debug [no]d2 [no]recurse retry=# time=# [no]ko [no]vc\n\ [no]defname [no]search domain=NAME [no]ignore [no]primary\n\ - [no]aaonly [no]cmd [no]stats [no]Header [no]header\n\ + [no]aaonly [no]cmd [no]stats [no]Header [no]header [no]trunc\n\ [no]ttlid [no]cl [no]qr [no]reply [no]ques [no]answer\n\ - [no]author [no]addit pfdef pfmin pfset=# pfand=# pfor=#\n\ + [no]author [no]addit [no]dnssec pfdef pfmin\n\ + pfset=# pfand=# pfor=#\n\ ", stderr); fputs("\ notes: defname and search don't work; use fully-qualified names.\n\ this is DiG version " VSTRING "\n\ - $Id: dig.c,v 8.46 2001/04/01 17:35:01 vixie Exp $\n\ + $Id: dig.c,v 8.51 2001/12/19 02:25:17 marka Exp $\n\ ", stderr); } @@ -1000,6 +1023,10 @@ setopt(const char *string) { res.options |= RES_DEFNAMES; } else if (strncmp(option, "nodef", 5) == 0) { res.options &= ~RES_DEFNAMES; + } else if (strncmp(option, "dn", 2) == 0) { /* dnssec */ + res.options |= RES_USE_DNSSEC; + } else if (strncmp(option, "nodn", 4) == 0) { + res.options &= ~RES_USE_DNSSEC; } else if (strncmp(option, "sea", 3) == 0) { /* search list */ res.options |= RES_DNSRCH; } else if (strncmp(option, "nosea", 5) == 0) { @@ -1075,6 +1102,10 @@ setopt(const char *string) { res.pfcode |= RES_PRF_TTLID; } else if (strncmp(option, "nott", 4) == 0) { res.pfcode &= ~RES_PRF_TTLID; + } else if (strncmp(option, "tr", 2) == 0) { /* TTL & ID */ + res.pfcode |= RES_PRF_TRUNC; + } else if (strncmp(option, "notr", 4) == 0) { + res.pfcode &= ~RES_PRF_TRUNC; } else if (strncmp(option, "he", 2) == 0) { /* head flags stats */ res.pfcode |= RES_PRF_HEAD2; } else if (strncmp(option, "nohe", 4) == 0) { @@ -1191,14 +1222,14 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, static int answerLen = 0; querybuf buf; - int msglen, amtToRead, numRead, result = 0, sockFD, len; + int msglen, amtToRead, numRead, result, sockFD, len; int count, type, class, rlen, done, n; - int numAnswers = 0, numRecords = 0, soacnt = 0; + int numAnswers, numRecords, soacnt; u_char *cp, tmp[NS_INT16SZ]; char dname[2][NS_MAXDNAME]; enum { NO_ERRORS, ERR_READING_LEN, ERR_READING_MSG, ERR_PRINTING } - error = NO_ERRORS; - pid_t zpid; + error; + pid_t zpid = -1; u_char *newmsg; int newmsglen; ns_tcp_tsig_state tsig_state; @@ -1302,7 +1333,7 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, sockFD = -1; return (e); } - if (connect(sockFD, (struct sockaddr *)sin, sizeof *sin) < 0) { + if (connect(sockFD, (const struct sockaddr *)sin, sizeof *sin) < 0) { int e = errno; perror(";; connect"); @@ -1325,7 +1356,8 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, (void) close(sockFD); sockFD = -1; return (e); - } + } else if (key) + free (newmsg); /* * If we're compressing, push a gzip into the pipeline. @@ -1336,8 +1368,6 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, if (pipe(z) < 0) { int e = errno; - if (key) - free (newmsg); perror(";; pipe"); (void) close(sockFD); @@ -1347,8 +1377,6 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, zpid = vfork(); if (zpid < 0) { int e = errno; - if (key) - free (newmsg); perror(";; fork"); (void) close(sockFD); @@ -1370,6 +1398,11 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, (void) dup2(z[rd], sockFD); (void) close(z[rd]); } + result = 0; + numAnswers = 0; + numRecords = 0; + soacnt = 0; + error = NO_ERRORS; dname[0][0] = '\0'; for (done = 0; !done; (void)NULL) { @@ -1538,10 +1571,6 @@ printZone(ns_type xfr, const char *zone, const struct sockaddr_in *sin, WCOREDUMP(status) ? 't' : 'f'); } - /* XXX This should probably happen sooner than here */ - if (key) - free (newmsg); - switch (error) { case NO_ERRORS: return (0); @@ -1604,9 +1633,12 @@ print_axfr(FILE *file, const u_char *msg, size_t msglen) { fprintf(file, "$ORIGIN %s.\n", origin); if (strcmp(name, ".") == 0) strcpy(origin, name); - strcpy(name_ctx, "@"); + if (res.pfcode & RES_PRF_TRUNC) + strcpy(name_ctx, "@"); } - if (ns_sprintrr(&handle, &rr, name_ctx, origin, + if (ns_sprintrr(&handle, &rr, + (res.pfcode & RES_PRF_TRUNC) ? name_ctx : NULL, + (res.pfcode & RES_PRF_TRUNC) ? origin : NULL, buf, sizeof buf) < 0) { fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno)); return (FORMERR); diff --git a/contrib/bind/bin/dnskeygen/dnskeygen.c b/contrib/bind/bin/dnskeygen/dnskeygen.c index 593fb00dfd2e..06f09c478358 100644 --- a/contrib/bind/bin/dnskeygen/dnskeygen.c +++ b/contrib/bind/bin/dnskeygen/dnskeygen.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: dnskeygen.c,v 1.11.2.1 2001/04/26 02:56:06 marka Exp $"; +static const char rcsid[] = "$Id: dnskeygen.c,v 1.14 2001/09/25 04:50:14 marka Exp $"; #endif /* not lint */ /* @@ -37,7 +37,7 @@ static const char rcsid[] = "$Id: dnskeygen.c,v 1.11.2.1 2001/04/26 02:56:06 mar #define PATH_SEP '/' #endif -static void usage(char *str, int full); +static void usage(const char *str, int full); static short dsa_sizes[] = {512, 576, 640, 704, 768, 832, 896, 960, 1024, 0}; static char *prog; @@ -274,9 +274,10 @@ main(int argc, char **argv) { } static void -usage(char *str, int flag){ +usage(const char *str, int flag) { int i; - printf ("\nNo key generated\n"); + + printf("\nNo key generated\n"); if (*str != '\0') printf("Usage:%s: %s\n",prog, str); printf("Usage:%s -{DHR} [-F] -{zhu} [-ac] [-p ]" @@ -316,7 +317,5 @@ usage(char *str, int flag){ printf("\n"); } - exit (-3); + exit (3); } - - diff --git a/contrib/bind/bin/dnsquery/dnsquery.c b/contrib/bind/bin/dnsquery/dnsquery.c index e8abd3ec1265..c9fed3cdc13d 100644 --- a/contrib/bind/bin/dnsquery/dnsquery.c +++ b/contrib/bind/bin/dnsquery/dnsquery.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: dnsquery.c,v 8.15 2000/12/23 08:14:32 vixie Exp $"; +static const char rcsid[] = "$Id: dnsquery.c,v 8.16 2001/09/25 04:50:15 marka Exp $"; #endif /* not lint */ /* @@ -66,7 +66,7 @@ main(int argc, char *argv[]) { /* if no args, exit */ if (argc == 1) { fprintf(stderr, "Usage: %s [-h] host [-n ns] [-t type] [-c class] [-r retry] [-p period] [-s] [-v] [-d] [-a]\n", argv[0]); - exit(-1); + exit(1); } /* handle args */ @@ -82,7 +82,7 @@ main(int argc, char *argv[]) { case 'h' : if (strlen(optarg) >= sizeof(name)) { fprintf(stderr, "Domain name too long (%s)\n", optarg); - exit(-1); + exit(1); } else strcpy(name, optarg); break; @@ -96,7 +96,7 @@ main(int argc, char *argv[]) { class = proto_class; else { fprintf(stderr, "Bad class (%s)\n", optarg); - exit(-1); + exit(1); } } break; @@ -110,7 +110,7 @@ main(int argc, char *argv[]) { type = proto_type; else { fprintf(stderr, "Bad type (%s)\n", optarg); - exit(-1); + exit(1); } } break; @@ -135,7 +135,7 @@ main(int argc, char *argv[]) { fprintf(stderr, "res_ninit() failed\n" ); - exit(-1); + exit(1); } if (nameservers >= MAXNS) break; (void) inet_aton(optarg, @@ -146,7 +146,7 @@ main(int argc, char *argv[]) { fprintf(stderr, "Bad nameserver (%s)\n", optarg); - exit(-1); + exit(1); } memcpy(&q_nsaddr[nameservers], q_nsname->h_addr, INADDRSZ); @@ -158,14 +158,14 @@ main(int argc, char *argv[]) { default : fprintf(stderr, "\tUsage: %s [-n ns] [-h host] [-t type] [-c class] [-r retry] [-p period] [-s] [-v] [-d] [-a]\n", argv[0]); - exit(-1); + exit(1); } } if (optind < argc) { if (strlen(argv[optind]) >= sizeof(name)) { fprintf(stderr, "Domain name too long (%s)\n", argv[optind]); - exit(-1); + exit(1); } else { strcpy(name, argv[optind]); } @@ -176,7 +176,7 @@ main(int argc, char *argv[]) { if (!(res.options & RES_INIT)) if (res_ninit(&res) == -1) { fprintf(stderr, "res_ninit() failed\n"); - exit(-1); + exit(1); } /* @@ -208,13 +208,13 @@ main(int argc, char *argv[]) { if (n < 0) { fprintf(stderr, "Query failed (h_errno = %d) : %s\n", h_errno, h_errlist[h_errno]); - exit(-1); + exit(1); } } else if ((n = res_nsearch(&res, name, class, type, answer, len)) < 0) { fprintf(stderr, "Query failed (h_errno = %d) : %s\n", h_errno, h_errlist[h_errno]); - exit(-1); + exit(1); } res_pquery(&res, answer, n, stdout); exit(0); diff --git a/contrib/bind/bin/host/host.c b/contrib/bind/bin/host/host.c index 6ec63dfba57e..eb285642cf8a 100644 --- a/contrib/bind/bin/host/host.c +++ b/contrib/bind/bin/host/host.c @@ -1,5 +1,5 @@ #ifndef lint -static const char rcsid[] = "$Id: host.c,v 8.43.2.2 2001/08/09 14:04:45 marka Exp $"; +static const char rcsid[] = "$Id: host.c,v 8.49 2001/12/17 04:24:37 marka Exp $"; #endif /* not lint */ /* @@ -119,7 +119,7 @@ static const char copyright[] = #define PATH_SEP '/' #endif #define SIG_RDATA_BY_NAME 18 -#define NS_HEADERDATA_SIZE 10 +#define NS_HEADERDATA_SIZE 10 /* type + class + ttl + rdlen */ #define NUMNS 8 #define NUMNSADDR 16 @@ -354,7 +354,7 @@ main(int argc, char **argv) { printf ("%s for %s not found, last verified key %s\n", chase_step & SD_SIG ? "Key" : "Signature", chase_step & SD_SIG ? chase_signer : chase_domain, - chase_lastgoodkey ? chase_lastgoodkey : "None"); + chase_lastgoodkey[0] ? chase_lastgoodkey : "None"); } } if (!getdomain[0] && cname) { @@ -611,7 +611,8 @@ getinfo(const char *name, const char *domain, int type) { int n; char host[NS_MAXDNAME]; - if (domain == NULL) + if (domain == NULL || + (domain[0] == '.' && domain[1] == '\0')) sprintf(host, "%.*s", NS_MAXDNAME, name); else sprintf(host, "%.*s.%.*s", @@ -647,7 +648,7 @@ printinfo(const querybuf *answer, const u_char *eom, int filter, int isls, /* * Find first satisfactory answer. */ - hp = (HEADER *) answer; + hp = (const HEADER *) answer; ancount = ntohs(hp->ancount); qdcount = ntohs(hp->qdcount); nscount = ntohs(hp->nscount); @@ -725,12 +726,12 @@ printinfo(const querybuf *answer, const u_char *eom, int filter, int isls, if (nscount) { printf("For authoritative answers, see:\n"); while (--nscount >= 0 && cp && cp < eom) - cp = (u_char *)pr_rr(cp, answer->qb2, stdout, filter); + cp = pr_rr(cp, answer->qb2, stdout, filter); } if (arcount) { printf("Additional information:\n"); while (--arcount >= 0 && cp && cp < eom) - cp = (u_char *)pr_rr(cp, answer->qb2, stdout, filter); + cp = pr_rr(cp, answer->qb2, stdout, filter); } /* restore sigchase value */ @@ -740,7 +741,8 @@ printinfo(const querybuf *answer, const u_char *eom, int filter, int isls, return (1); } -void print_hex_field (u_int8_t field[], int length, int width, char *pref) +static void print_hex_field (u_int8_t field[], int length, int width, + const char *pref) { /* Prints an arbitrary bit field, from one address for some number of bytes. Output is formatted via the width, and includes the raw @@ -772,7 +774,7 @@ void print_hex_field (u_int8_t field[], int length, int width, char *pref) } while (start < length); } -void memswap (void *s1, void *s2, size_t n) +static void memswap (void *s1, void *s2, size_t n) { void *tmp; @@ -789,23 +791,6 @@ void memswap (void *s1, void *s2, size_t n) free (tmp); } -void print_hex (u_int8_t field[], int length) -{ - /* Prints the hex values of a field...not as pretty as the print_hex_field. - */ - int i, start, stop; - - start=0; - do - { - stop=length; - for (i = start; i < stop; i++) - printf ("%02x ", (u_char) field[i]); - start = stop; - if (start < length) printf ("\n"); - } while (start < length); -} - /* * Print resource record fields in human readable form. */ @@ -826,7 +811,8 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { u_char canonrr[MY_PACKETSZ]; size_t canonrr_len = 0; - if ((cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name))) == NULL) + cp = pr_cdname(cp, msg, name, sizeof(name)); + if (cp == NULL) return (NULL); /* compression error */ strcpy(thisdomain, name); @@ -895,7 +881,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { const u_char *startrdata = cp; u_char cdname[NS_MAXCDNAME]; - cp = (u_char *)pr_cdname(cp, msg, name, sizeof name); + cp = pr_cdname(cp, msg, name, sizeof name); if (doprint) fprintf(file, "%c%s", punc, name); @@ -944,7 +930,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { const u_char *startname = cp; u_char cdname[NS_MAXCDNAME]; - cp = (u_char *)pr_cdname(cp, msg, name, sizeof name); + cp = pr_cdname(cp, msg, name, sizeof name); if (doprint) fprintf(file, "\t%s", name); @@ -961,7 +947,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { } startname = cp; - cp = (u_char *)pr_cdname(cp, msg, name, sizeof name); + cp = pr_cdname(cp, msg, name, sizeof name); if (doprint) fprintf(file, " %s", name); @@ -1020,7 +1006,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { fprintf(file," "); } cp += sizeof(u_short); - cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name)); + cp = pr_cdname(cp, msg, name, sizeof(name)); if (doprint) fprintf(file, "%s", name); @@ -1056,7 +1042,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { if (doprint) fprintf(file," %d", ns_get16(cp)); cp += sizeof(u_short); - cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name)); + cp = pr_cdname(cp, msg, name, sizeof(name)); if (doprint) fprintf(file, " %s", name); break; @@ -1098,14 +1084,14 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { } cp += n; /* replacement */ - cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name)); + cp = pr_cdname(cp, msg, name, sizeof(name)); if (doprint) fprintf(file, "%s", name); break; case ns_t_minfo: case ns_t_rp: - cp = (u_char *)pr_cdname(cp, msg, name, sizeof name); + cp = pr_cdname(cp, msg, name, sizeof name); if (doprint) { if (type == ns_t_rp) { char *p; @@ -1116,7 +1102,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { } fprintf(file, "%c%s", punc, name); } - cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name)); + cp = pr_cdname(cp, msg, name, sizeof(name)); if (doprint) fprintf(file, " %s", name); break; @@ -1201,7 +1187,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { u_char cdname[NS_MAXCDNAME]; size_t bitmaplen; - cp = (u_char *) pr_cdname(cp, msg, name, sizeof name); + cp = pr_cdname(cp, msg, name, sizeof name); if (doprint) fprintf(file, "%c%s", punc, name); bitmaplen = dlen - (cp - startrdata); @@ -1265,7 +1251,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { fprintf(file, " %d", ns_get16(cp)); cp += sizeof(u_short); /* signer's name */ - cp = (u_char *)pr_cdname(cp, msg, name, sizeof(name)); + cp = pr_cdname(cp, msg, name, sizeof(name)); if (doprint && verbose) fprintf(file, " %s", name); else if (doprint && !verbose) @@ -1299,7 +1285,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { SIG_RDATA_BY_NAME); memcpy(chase_sigrdata + SIG_RDATA_BY_NAME, cdname, n); - chase_sigrdata_len += SIG_RDATA_BY_NAME + n; + chase_sigrdata_len = SIG_RDATA_BY_NAME + n; memcpy(chase_signature, cp, len); chase_signature_len = len; @@ -1376,10 +1362,14 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { /* sort rr's (qsort() is too slow) */ for (i = 0; i < NUMRR && chase_rr[i].len; i++) - for (j = i + 1; i < NUMRR && chase_rr[j].len; j++) - if (memcmp(chase_rr[i].data, chase_rr[j].data, MY_PACKETSZ) > 0) - memswap(&chase_rr[i], &chase_rr[j], sizeof(rrstruct)); - + for (j = i + 1; j < NUMRR && chase_rr[j].len; + j++) + if (memcmp(chase_rr[i].data, + chase_rr[j].data, + MY_PACKETSZ) < 0) + memswap(&chase_rr[i], + &chase_rr[j], + sizeof(rrstruct)); /* append rr's to sigrdata */ for (i = 0; i < NUMRR && chase_rr[i].len; i++) @@ -1392,6 +1382,7 @@ pr_rr(const u_char *cp, const u_char *msg, FILE *file, int filter) { /* print rr-data and signature */ if (verbose) { + fprintf(file, "\n"); print_hex_field(chase_sigrdata, chase_sigrdata_len, 21,"DATA: "); diff --git a/contrib/bind/bin/irpd/irpd.c b/contrib/bind/bin/irpd/irpd.c index e03276f33853..6dee58e8c007 100644 --- a/contrib/bind/bin/irpd/irpd.c +++ b/contrib/bind/bin/irpd/irpd.c @@ -37,7 +37,7 @@ seem to be so for getnetbyaddr #endif #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irpd.c,v 1.10 2000/12/23 08:14:33 vixie Exp $"; +static const char rcsid[] = "$Id: irpd.c,v 1.13 2001/09/25 04:50:17 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -114,7 +114,7 @@ static const char rcsid[] = "$Id: irpd.c,v 1.10 2000/12/23 08:14:33 vixie Exp $" do{ if ((nd)->field == 0) { \ (nd)->field = (*(nd)->irs->field ## _map)(nd->irs); \ if ((nd)->field == 0) { \ - char *msg = "net_data " #field " initialization failed"; \ + const char *msg = "net_data " #field " initialization failed"; \ ctl_response(sess, respcode, msg, CTL_EXIT, NULL, \ NULL, NULL, NULL, 0); \ return; \ @@ -149,103 +149,111 @@ static struct net_data *get_net_data(struct ctl_sess *sess); static void irpd_gethostbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_gethostbyname2(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); + static void irpd_gethostbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_gethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_sethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getpwnam(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getpwuid(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getnetbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getnetbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getgrnam(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getgrgid(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getservbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_getservbyport(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_getservent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setservent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getprotobyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_getprotobynumber(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, + void *uctx); static void irpd_getprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_getnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_innetgr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_setnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_endnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_quit(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_help(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_accept(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void irpd_abort(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); static void response_done(struct ctl_sctx *ctx, struct ctl_sess *sess, void *uap); @@ -266,59 +274,59 @@ static int main_needs_exit = 0; static evContext ev; struct ctl_verb verbs [] = { - { "gethostbyname", irpd_gethostbyname }, - { "gethostbyname2", irpd_gethostbyname2 }, - { "gethostbyaddr", irpd_gethostbyaddr }, - { "gethostent", irpd_gethostent }, - { "sethostent", irpd_sethostent }, + { "gethostbyname", irpd_gethostbyname, NULL }, + { "gethostbyname2", irpd_gethostbyname2, NULL }, + { "gethostbyaddr", irpd_gethostbyaddr, NULL }, + { "gethostent", irpd_gethostent, NULL }, + { "sethostent", irpd_sethostent, NULL }, #ifdef WANT_IRS_PW - { "getpwnam", irpd_getpwnam }, - { "getpwuid", irpd_getpwuid }, - { "getpwent", irpd_getpwent }, - { "setpwent", irpd_setpwent }, + { "getpwnam", irpd_getpwnam, NULL }, + { "getpwuid", irpd_getpwuid, NULL }, + { "getpwent", irpd_getpwent, NULL }, + { "setpwent", irpd_setpwent, NULL }, #endif - { "getnetbyname", irpd_getnetbyname }, - { "getnetbyaddr", irpd_getnetbyaddr }, - { "getnetent", irpd_getnetent }, - { "setnetent", irpd_setnetent }, + { "getnetbyname", irpd_getnetbyname, NULL }, + { "getnetbyaddr", irpd_getnetbyaddr, NULL }, + { "getnetent", irpd_getnetent, NULL }, + { "setnetent", irpd_setnetent, NULL }, #ifdef WANT_IRS_GR - { "getgrnam", irpd_getgrnam }, - { "getgrgid", irpd_getgrgid }, - { "getgrent", irpd_getgrent }, - { "setgrent", irpd_setgrent }, + { "getgrnam", irpd_getgrnam, NULL }, + { "getgrgid", irpd_getgrgid, NULL }, + { "getgrent", irpd_getgrent, NULL }, + { "setgrent", irpd_setgrent, NULL }, #endif - { "getservbyname", irpd_getservbyname }, - { "getservbyport", irpd_getservbyport }, - { "getservent", irpd_getservent }, - { "setservent", irpd_setservent }, + { "getservbyname", irpd_getservbyname, NULL }, + { "getservbyport", irpd_getservbyport, NULL }, + { "getservent", irpd_getservent, NULL }, + { "setservent", irpd_setservent, NULL }, - { "getprotobyname", irpd_getprotobyname }, - { "getprotobynumber", irpd_getprotobynumber }, - { "getprotoent", irpd_getprotoent }, - { "setprotoent", irpd_setprotoent }, + { "getprotobyname", irpd_getprotobyname, NULL }, + { "getprotobynumber", irpd_getprotobynumber, NULL }, + { "getprotoent", irpd_getprotoent, NULL }, + { "setprotoent", irpd_setprotoent, NULL }, - { "getnetgrent", irpd_getnetgrent }, - { "innetgr", irpd_innetgr }, - { "setnetgrent", irpd_setnetgrent }, - { "endnetgrent", irpd_endnetgrent }, - { "quit", irpd_quit }, - { "help", irpd_help }, + { "getnetgrent", irpd_getnetgrent, NULL }, + { "innetgr", irpd_innetgr, NULL }, + { "setnetgrent", irpd_setnetgrent, NULL }, + { "endnetgrent", irpd_endnetgrent, NULL }, + { "quit", irpd_quit, NULL }, + { "help", irpd_help, NULL }, - { "", irpd_accept }, /* For connection setups. */ + { "", irpd_accept, NULL }, /* For connection setups. */ /* abort is a verb expected by the ctl library. Is called when the * client drops the connection unexpectedly. */ - { "abort", irpd_abort }, + { "abort", irpd_abort, NULL }, - { NULL, NULL } + { NULL, NULL, NULL } }; /* * An empty string causes the library to use the compiled in * defaults and to ignore any external files. */ -char *conffile = ""; +const char *conffile = ""; /* Public. */ @@ -332,7 +340,7 @@ main(int argc, char **argv) { struct sockaddr_in iaddr; short port = IRPD_PORT; char *prog = argv[0]; - char *sockname = IRPD_PATH; + const char *sockname = IRPD_PATH; char *p; int ch; size_t socksize; @@ -420,11 +428,11 @@ main(int argc, char **argv) { /* * static void - * simple_response(struct ctl_sess *sess, u_int code, char *msg); + * simple_response(struct ctl_sess *sess, u_int code, const char *msg); * Send back a simple, one-line response to the client. */ static void -simple_response(struct ctl_sess *sess, u_int code, char *msg) { +simple_response(struct ctl_sess *sess, u_int code, const char *msg) { struct response_buff *b = newbuffer(strlen(msg) + 1); if (b == 0) @@ -485,18 +493,24 @@ do_gethostbyname2(struct ctl_sess *sess, struct net_data *nd, * static void * irpd_gethostbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETHOSTBYNAME verb. */ static void irpd_gethostbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { char hname[MAXHOSTNAMELEN]; struct arg_s *args; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ho, sess, IRPD_GETHOST_ERROR); @@ -523,19 +537,25 @@ irpd_gethostbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_gethostbyname2(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETHOSTBYNAME2 verb. */ static void irpd_gethostbyname2(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { char hname[MAXHOSTNAMELEN]; struct arg_s *args; int af; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ho, sess, IRPD_GETHOST_ERROR); @@ -572,13 +592,13 @@ irpd_gethostbyname2(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_gethostbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETHOSTBYADDR verb. */ static void irpd_gethostbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct hostent *ho; char haddr[MAXHOSTNAMELEN]; @@ -588,6 +608,12 @@ irpd_gethostbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, int addrlen; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ho, sess, IRPD_GETHOST_ERROR); @@ -640,17 +666,24 @@ irpd_gethostbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_gethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETHOSTENT verb */ static void irpd_gethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct hostent *ho; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ho, sess, IRPD_GETHOST_ERROR); @@ -664,16 +697,23 @@ irpd_gethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_sethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the SETHOSTENT verb */ static void irpd_sethostent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ho, sess, IRPD_GETHOST_ERROR); @@ -716,19 +756,25 @@ send_pwent(struct ctl_sess *sess, struct passwd *pw) { * static void * irpd_getpwnam(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETPWNAM verb */ static void irpd_getpwnam(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct passwd *pw; char username[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pw, sess, IRPD_GETUSER_ERROR); @@ -758,19 +804,25 @@ irpd_getpwnam(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getpwuid(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETPWUID verb. */ static void irpd_getpwuid(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct passwd *pw; char userid[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pw, sess, IRPD_GETUSER_ERROR); @@ -819,17 +871,24 @@ irpd_getpwuid(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implemtnation of the GETPWENT verb. */ static void irpd_getpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct passwd *pw; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pw, sess, IRPD_GETUSER_ERROR); @@ -842,16 +901,23 @@ irpd_getpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implemtnation of the SETPWENT verb. */ static void irpd_setpwent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pw, sess, IRPD_GETUSER_ERROR); @@ -893,13 +959,13 @@ send_nwent(struct ctl_sess *sess, struct nwent *nw) { * static void * irpd_getnetbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of GETNETBYNAME verb. */ static void irpd_getnetbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct netent *ne; @@ -907,6 +973,12 @@ irpd_getnetbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, char netname[MAXNETNAMELEN]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, nw, sess, IRPD_GETNET_ERROR); @@ -947,12 +1019,12 @@ irpd_getnetbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getnetbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); */ static void irpd_getnetbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct netent *ne; struct nwent *nw; @@ -964,6 +1036,12 @@ irpd_getnetbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, int bits; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, nw, sess, IRPD_GETUSER_ERROR); @@ -1038,18 +1116,25 @@ irpd_getnetbyaddr(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETNETENT verb. */ static void irpd_getnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct netent *ne; struct nwent *nw; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, nw, sess, IRPD_GETNET_ERROR); @@ -1068,16 +1153,23 @@ irpd_getnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the SETNETENT verb. */ static void irpd_setnetent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, nw, sess, IRPD_GETNET_ERROR); @@ -1119,19 +1211,25 @@ send_grent(struct ctl_sess *sess, struct group *gr) { * static void * irpd_getgrnam(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETGRNAM verb. */ static void irpd_getgrnam(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct group *gr; char groupname[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, gr, sess, IRPD_GETGROUP_ERROR); @@ -1161,19 +1259,25 @@ irpd_getgrnam(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getgrgid(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implentation of the GETGRGID verb. */ static void irpd_getgrgid(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct group *gr; char groupid[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, gr, sess, IRPD_GETGROUP_ERROR); @@ -1222,17 +1326,24 @@ irpd_getgrgid(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the GETGRENT verb. */ static void irpd_getgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct group *gr; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, gr, sess, IRPD_GETGROUP_ERROR); @@ -1245,16 +1356,23 @@ irpd_getgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Implementation of the SETGRENT verb. */ static void irpd_setgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, gr, sess, IRPD_GETGROUP_ERROR); @@ -1290,7 +1408,7 @@ send_servent(struct ctl_sess *sess, struct servent *serv) { static void irpd_getservbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct servent *serv; @@ -1298,6 +1416,12 @@ irpd_getservbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, char protoname[10]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, sv, sess, IRPD_GETSERVICE_ERROR); @@ -1335,13 +1459,13 @@ irpd_getservbyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getservbyport(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the GETSERVBYPORT verb. */ static void irpd_getservbyport(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct servent *sv; @@ -1349,6 +1473,12 @@ irpd_getservbyport(struct ctl_sctx *ctx, struct ctl_sess *sess, char protoname[10]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, sv, sess, IRPD_GETSERVICE_ERROR); @@ -1405,17 +1535,24 @@ irpd_getservbyport(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getservent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the GETSERVENT verb. */ static void irpd_getservent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct servent *sv; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, sv, sess, IRPD_GETSERVICE_ERROR); @@ -1428,16 +1565,23 @@ irpd_getservent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setservent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the SETSERVENT verb. */ static void irpd_setservent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, sv, sess, IRPD_GETSERVICE_ERROR); @@ -1479,19 +1623,25 @@ send_prent(struct ctl_sess *sess, struct protoent *pr) { * static void * irpd_getprotobyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the GETPROTOBYNAME verb. */ static void irpd_getprotobyname(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct protoent *pr; char protoname[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pr, sess, IRPD_GETPROTO_ERROR); @@ -1520,20 +1670,26 @@ irpd_getprotobyname(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getprotobynumber(struct ctl_sctx *ctx, * struct ctl_sess *sess, const struct ctl_verb *verb, - * const char *rest, u_int respflags, void *respctx, + * const char *rest, u_int respflags, const void *respctx, * void *uctx); * Handle the GETPROTOBYNUMBER verb. */ static void irpd_getprotobynumber(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct protoent *pr; char protonum[64]; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pr, sess, IRPD_GETPROTO_ERROR); @@ -1582,17 +1738,24 @@ irpd_getprotobynumber(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_getprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the GETPROTOENT verb. */ static void irpd_getprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct protoent *pr; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pr, sess, IRPD_GETPROTO_ERROR); @@ -1605,16 +1768,23 @@ irpd_getprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the SETPROTOENT verb. */ static void irpd_setprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, pr, sess, IRPD_GETPROTO_ERROR); @@ -1630,7 +1800,9 @@ irpd_setprotoent(struct ctl_sctx *ctx, struct ctl_sess *sess, * user" response. */ static void -send_ngent(struct ctl_sess *sess, char *host, char *user, char *domain) { +send_ngent(struct ctl_sess *sess, const char *host, const char *user, + const char *domain) +{ struct response_buff *b = newbuffer(0); if (irp_marshall_ng(host, user, domain, &b->buff, @@ -1651,16 +1823,22 @@ send_ngent(struct ctl_sess *sess, char *host, char *user, char *domain) { * static void * irpd_getnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the GETNETGRENT verb. */ static void irpd_getnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ng, sess, IRPD_GETNETGR_ERROR); @@ -1669,7 +1847,7 @@ irpd_getnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, simple_response(sess, IRPD_GETNETGR_ERROR, "GETNETGRENT"); } else { - char *host, *user, *domain; + const char *host, *user, *domain; if (getnetgrent_p(&host, &user, &domain, netdata) == 1) { send_ngent(sess, host, user, domain); @@ -1684,20 +1862,26 @@ irpd_getnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_innetgr(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the INNETGR verb. */ static void irpd_innetgr(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct net_data *netdata = get_net_data(sess); - char *host; - char *user; - char *domain; + const char *host; + const char *user; + const char *domain; + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ng, sess, IRPD_GETNETGR_ERROR); @@ -1741,17 +1925,23 @@ irpd_innetgr(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_setnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the SETNETGRENT verb. */ static void irpd_setnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct arg_s *args; struct net_data *netdata = get_net_data(sess); + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + INSIST(netdata != NULL); ND_INIT(netdata, ng, sess, IRPD_GETNETGR_ERROR); @@ -1773,15 +1963,21 @@ irpd_setnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_endnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the ENDNETGRENT verb. */ static void irpd_endnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + + UNUSED(ctx); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); INSIST(netdata != NULL); @@ -1801,14 +1997,21 @@ irpd_endnetgrent(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_quit(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the QUIT verb. */ static void irpd_quit(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ctl_response(sess, irpd_quit_ok, "See ya!", CTL_EXIT, NULL, 0 , NULL, NULL, 0); } @@ -1817,17 +2020,24 @@ irpd_quit(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_help(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle the HELP verb. */ static void irpd_help(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { /* XXX should make this do something better (like include required * arguments. */ + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ctl_sendhelp(sess, 231); } @@ -1835,27 +2045,33 @@ irpd_help(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_accept(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle a new connection. */ static void irpd_accept(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { - struct sockaddr *sa = respctx; + const struct sockaddr *sa = respctx; char raddr[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; int reject = 1; int response; - char *respmsg = NULL; + const char *respmsg = NULL; + + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(uctx); if (sa->sa_family == AF_UNIX) { syslog (LOG_INFO, "New AF_UNIX connection"); reject = 0; } else if (sa->sa_family == AF_INET) { - struct sockaddr_in *sin = respctx; - static long localhost; - static long zero; + const struct sockaddr_in *sin = respctx; + static unsigned long localhost; + static unsigned long zero; if (localhost == 0) { /* yes, this could be done with simple arithmetic... */ @@ -1915,15 +2131,22 @@ irpd_accept(struct ctl_sctx *ctx, struct ctl_sess *sess, * static void * irpd_abort(struct ctl_sctx *ctx, struct ctl_sess *sess, * const struct ctl_verb *verb, const char *rest, - * u_int respflags, void *respctx, void *uctx); + * u_int respflags, const void *respctx, void *uctx); * Handle a dropped connection. */ static void irpd_abort(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct net_data *netdata = get_net_data(sess); + + UNUSED(ctx); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); if (netdata != NULL) net_data_destroy(netdata); @@ -1937,6 +2160,8 @@ irpd_abort(struct ctl_sctx *ctx, struct ctl_sess *sess, */ static void response_done(struct ctl_sctx *ctx, struct ctl_sess *sess, void *uap) { + UNUSED(ctx); + UNUSED(sess); release_buffer(uap); } @@ -1971,8 +2196,9 @@ logger(enum ctl_severity sev, const char *fmt, ...) { fprintf(stderr, "irpd: "); vfprintf(stderr, fmt, ap); #else - if (vsprintf(buffer, fmt, ap) > (sizeof (buffer) - 1)) { + if (vsprintf(buffer, fmt, ap) > (int)(sizeof (buffer) - 1)) { syslog(LOG_CRIT, "Buffer overrun in logger"); + va_end(ap); abort(); } syslog(level, "%s", buffer); @@ -2080,7 +2306,7 @@ split_string(const char *string) { if (*p == '\0') break; - iovs[c].iov_base = (void *)p; + DE_CONST(p, iovs[c].iov_base); while (*p && !isspace(*p)) { p++; diff --git a/contrib/bind/bin/mkservdb/mkservdb.c b/contrib/bind/bin/mkservdb/mkservdb.c index b3b758cb6b5f..a0a593399d78 100644 --- a/contrib/bind/bin/mkservdb/mkservdb.c +++ b/contrib/bind/bin/mkservdb/mkservdb.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: mkservdb.c,v 1.9 2001/01/26 06:54:11 vixie Exp $"; +static const char rcsid[] = "$Id: mkservdb.c,v 1.10 2001/06/18 14:42:46 marka Exp $"; #endif /* not lint */ /* @@ -69,9 +69,9 @@ main(int argc, char **argv) { DB *db; DBT key; DBT data; - char *filename = _PATH_SERVICES; - char *tmpdatabase = _PATH_SERVICES_DB_TMP; - char *database = _PATH_SERVICES_DB; + const char *filename = _PATH_SERVICES; + const char *tmpdatabase = _PATH_SERVICES_DB_TMP; + const char *database = _PATH_SERVICES_DB; char dbuf[1024]; char kbuf[512]; u_short *ports; @@ -152,7 +152,7 @@ main(int argc, char **argv) { if (sv->s_aliases != NULL) for (n = 0; sv->s_aliases[n] != NULL; n++) if ((p + strlen(sv->s_aliases[n]) + 1) - dbuf - <= sizeof dbuf) { + <= (int)sizeof dbuf) { strcpy(p, sv->s_aliases[n]); p += strlen(p) + 1; } diff --git a/contrib/bind/bin/named-bootconf/named-bootconf.sh b/contrib/bind/bin/named-bootconf/named-bootconf.sh index 3952b14ecae1..0a6e3272802f 100644 --- a/contrib/bind/bin/named-bootconf/named-bootconf.sh +++ b/contrib/bind/bin/named-bootconf/named-bootconf.sh @@ -143,6 +143,11 @@ while read CMD ARGS; do no-recursion ) echo " recursion no;" >>$OPTIONFILE ;; + no-round-robin ) # HP extention + echo " rrset-order {" >>$OPTIONFILE + echo " class ANY type ANY name \"*\" order fixed;" >>$OPTIONFILE + echo " };" >>$OPTIONFILE + ;; esac done rm -f $COMMENTFILE diff --git a/contrib/bind/bin/named-bootconf/test.boot b/contrib/bind/bin/named-bootconf/test.boot new file mode 100644 index 000000000000..2b001e4ab041 --- /dev/null +++ b/contrib/bind/bin/named-bootconf/test.boot @@ -0,0 +1,30 @@ +directory /var/named +forwarders 1.2.3.4 1.2.3.5 +limit datasize 10000000 +limit files 1000 +limit transfers-in 100 +limit transfers-per-ns 20 +; no-round-robin in HP specific +options no-round-robin fake-iquery forward-only no-fetch-glue no-recursion +slave +tcplist 10.0.0.1 +xfrnets 10.0.0.2 +cache . rootservers +primary example.net example.net.db +secondary example.com 127.0.0.1 example.com.db +stub example.org 127.0.0.1 example.org.db +primary/IN example.net example.net.db +secondary/IN example.com 127.0.0.1 example.com.db +stub/IN example.org 127.0.0.1 example.org.db +secondary/IN example.com 127.0.0.1 +stub/IN example.org 127.0.0.1 +primary/CHAOS example.net example.net.db +secondary/CHAOS example.com 127.0.0.1 example.com.db +stub/CHAOS example.org 127.0.0.1 example.org.db +secondary/CHAOS example.com 127.0.0.1 +stub/CHAOS example.org 127.0.0.1 +primary/HS example.net example.net.db +secondary/HS example.com 127.0.0.1 example.com.db +stub/HS example.org 127.0.0.1 example.org.db +secondary/HS example.com 127.0.0.1 +stub/HS example.org 127.0.0.1 diff --git a/contrib/bind/bin/named-xfer/named-xfer.c b/contrib/bind/bin/named-xfer/named-xfer.c index 1a08f7b2211c..b18b163a5f40 100644 --- a/contrib/bind/bin/named-xfer/named-xfer.c +++ b/contrib/bind/bin/named-xfer/named-xfer.c @@ -130,7 +130,7 @@ char copyright[] = #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)named-xfer.c 4.18 (Berkeley) 3/7/91"; -static const char rcsid[] = "$Id: named-xfer.c,v 8.105.2.1 2001/04/26 02:56:09 marka Exp $"; +static const char rcsid[] = "$Id: named-xfer.c,v 8.120 2002/01/29 06:54:52 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -215,7 +215,7 @@ static int getzone(struct zoneinfo *, u_int32_t, int), writemsg(int, const u_char *, int); static int ixfr_log(const u_char *msg, int len, int *delete, FILE *file, struct sockaddr_in *sin, - char *domain, u_int32_t *serial_no, int *); + u_int32_t *serial_no, int *); static SIG_FN read_alarm(void); static SIG_FN term_handler(void); static const char *soa_zinfo(struct zoneinfo *, u_char *, u_char*), @@ -288,7 +288,8 @@ init_xfer_logging() { return (1); } -void cleanup_for_exit(void) { +static void +cleanup_for_exit(void) { #ifdef DEBUG if (!debug) #endif @@ -322,7 +323,7 @@ main(int argc, char *argv[]) { struct in_addr axfr_src; char *dbfile = NULL, *tracefile = NULL, *tm = NULL, *tsigfile = NULL; char *ixfrfile = NULL; - int dbfd, ddtd, result, c, ixfd; + int dbfd, ddtd, result, c, ixfd = -1; u_int32_t serial_no = 0; u_int port = htons(NAMESERVER_PORT); struct stat statbuf; @@ -495,12 +496,16 @@ main(int argc, char *argv[]) { if (!quiet) syslog(LOG_ERR, "can't [f]chmod tmpfile (%s): %s\n", tmpname, strerror(errno)); + close(dbfd); + unlink(tmpname); exit(XFER_FAIL); } if ((dbfp = fdopen(dbfd, "r+")) == NULL) { perror(tmpname); if (!quiet) syslog(LOG_ERR, "can't fdopen tmpfile (%s)", tmpname); + close(dbfd); + unlink(tmpname); exit(XFER_FAIL); } if (ixfrfile) { @@ -547,9 +552,13 @@ main(int argc, char *argv[]) { #endif { perror(ddtfile); + close(ddtd); + unlink(ddtfile); debug = 0; } else if ((ddt = fdopen(ddtd, "w")) == NULL) { perror(ddtfile); + close(ddtd); + unlink(ddtfile); debug = 0; } else setvbuf(ddt, NULL, _IOLBF, 0); @@ -751,7 +760,7 @@ main(int argc, char *argv[]) { return (0); /* Make gcc happy. */ } -static char *UsageText[] = { +static const char *UsageText[] = { "\t-z zone_to_transfer\n", "\t-f db_file\n", "\t[-i ixfr_file]\n", @@ -770,11 +779,11 @@ static char *UsageText[] = { static void usage(const char *msg) { - char * const *line; + const char **line; fprintf(stderr, "Usage error: %s\n", msg); fprintf(stderr, "Usage: %s\n", ProgName); - for (line = UsageText; *line; line++) + for (line = UsageText; *line; line++) fputs(*line, stderr); exit(XFER_FAIL); } @@ -853,6 +862,179 @@ char prev_origin[MAXDNAME]; /* from most recent $ORIGIN line */ char prev_dname[MAXDNAME] = { DEF_DNAME }; /* from previous record */ char prev_ns_dname[MAXDNAME] = { DEF_DNAME }; /* from most recent NS record */ +/* + * TSIG state + */ +static int tsig_signed; +static ns_tcp_tsig_state tsig_state; + +static int +make_query(int fd, struct zoneinfo *zp, int type, u_int32_t serial_no, + DST_KEY *tsig_key, u_char *buf, u_int bufsize) +{ + HEADER *hp; + u_char *cp; + int n, ret; + time_t timesigned = 0; + + n = res_nmkquery(&res, QUERY, zp->z_origin, curclass, + type, NULL, 0, NULL, buf, bufsize); + if (n < 0) { + if (!quiet) + syslog(LOG_INFO, "zone %s: res_nmkquery %s failed", + p_type(query_type), zp->z_origin); + return (n); + } + + if (type == T_IXFR) { + hp = (HEADER *) buf; + cp = buf; + dprintf(1, "len = %d\n", n); + hp->nscount = htons(1+ntohs(hp->nscount)); + cp += n; + n = dn_comp(zp->z_origin, cp, bufsize - (cp - buf), NULL, NULL); + if (n < 0) + return (n); + cp += n; + if (cp + 3 * INT16SZ + 6 * INT32SZ + 2 > buf + bufsize) + return (-1); + PUTSHORT(T_SOA, cp); /* type */ + PUTSHORT(C_IN, cp); /* class */ + PUTLONG(0, cp); /* ttl */ + PUTSHORT(22, cp); /* dlen */ + *cp++ = 0; /* mname */ + *cp++ = 0; /* rname */ + PUTLONG(serial_no, cp); + PUTLONG(0xDEAD, cp); /* Refresh */ + PUTLONG(0xBEEF, cp); /* Retry */ + PUTLONG(0xABCD, cp); /* Expire */ + PUTLONG(0x1776, cp); /* Min TTL */ + n = cp - buf; + dprintf(1, "len = %d\n", cp-buf); + } + + tsig_signed = 0; + if (tsig_key != NULL) { + int siglen; + u_char sig[64]; + + siglen = sizeof(sig); + ret = ns_sign(buf, &n, bufsize, NOERROR, tsig_key, + NULL, 0, sig, &siglen, timesigned); + if (ret == 0) { + tsig_signed = 1; + ns_verify_tcp_init(tsig_key, sig, siglen, &tsig_state); + } + } + + if (debug) + res_pquery(&res, buf, n, ddt); + + if (writemsg(fd, buf, n) < 0) { + syslog(LOG_INFO, "writemsg: %m"); + return (-1); + } + + return (n); +} + +static u_int +readandverify(int fd, u_char **bufp, u_int *bufsizep, + struct sockaddr_in *sin, char *z_origin, int sig_req) +{ + u_char *buf = *bufp; + u_char *newbuf; + u_int bufsize = *bufsizep; + u_int len; + + if (netread(fd, (char *)buf, INT16SZ, XFER_TIMER) < 0) + return (0); + + if ((len = ns_get16(buf)) == 0) + return (0); + + if (len > bufsize) { + newbuf = realloc(buf, len); + if (newbuf == NULL) { + syslog(LOG_INFO, "realloc(%u) failed\n", len); + return (0); + } + *bufp = buf = newbuf; + *bufsizep = bufsize = len; + } + + if (netread(fd, (char *)buf, len, XFER_TIMER) < 0) + return (0); + +#ifdef DEBUG + if (debug >= 3) { + (void)fprintf(ddt,"len = %d\n", len); + res_pquery(&res, buf, len, ddt); + } + if (fp) + res_pquery(&res, buf, len, fp); +#endif + + if (tsig_signed) { + int ret; + + ret = ns_verify_tcp(buf, (int *)&len, &tsig_state, sig_req); + if (ret != 0) { + syslog(LOG_NOTICE, "%s [%s] %s %s: %s (%d)\n", + "TSIG verification from server", + inet_ntoa(sin->sin_addr), "zone", z_origin, + tsig_rcode(ret), ret); + return (0); + } + } + + return (len); +} + +static void +print_comment(int s, struct sockaddr_in *sin, int check_serial, + u_int32_t serial_no, DST_KEY *tsig_key) +{ + struct sockaddr_in local; + ISC_SOCKLEN_T locallen; + const char *l, *nl; + + gettime(&tt); + locallen = sizeof local; + if (getsockname(s, (struct sockaddr *)&local, &locallen) < 0) + memset(&local, 0, sizeof local); + + for (l = Version; l; l = nl) { + size_t len; + if ((nl = strchr(l, '\n')) != NULL) { + len = nl - l; + nl = nl + 1; + } else { + len = strlen(l); + nl = NULL; + } + while (isspace((unsigned char) *l)) + l++; + if (*l) + fprintf(dbfp, "; BIND version %.*s\n", (int)len, l); + } + + fprintf(dbfp, check_serial ? + "; zone '%s' last serial %u\n" : + "; zone '%s' first transfer\n", + domain, serial_no); + fprintf(dbfp, "; from %s:%d", + inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); + fprintf(dbfp, " (local %s) using %s at %s", + inet_ntoa(local.sin_addr), (methode == ISIXFR) ? "IXFR":"AXFR", + ctimel(tt.tv_sec)); + if (tsig_signed != 0) + fprintf(dbfp, "; TSIG verified: key %s.\n", + tsig_key->dk_key_name); + else + fprintf(dbfp, "; NOT TSIG verified\n"); +} + static int getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { HEADER *hp; @@ -861,34 +1043,30 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { int was_ixfr = 0; u_int cnt; u_char *cp, *nmp, *eom, *tmp ; - u_char *buf = NULL, *cpp = NULL; + u_char *buf = NULL; u_char *bp; u_int bufsize = 0; u_char *buf2 = NULL; u_int buf2size = 0; char name2[MAXDNAME]; struct sockaddr_in sin; - struct sockaddr_in local; - int locallen; #ifdef POSIX_SIGNALS struct sigaction sv, osv; #else struct sigvec sv, osv; #endif - int qdcount, ancount, aucount, arcount, class, type; + int qdcount, ancount, aucount, arcount, class = 0, type = 0; const char *badsoa_msg = "Nil"; struct sockaddr_in my_addr; char my_addr_text[30]; - int alen, ret, tsig_req; + ISC_SOCKLEN_T alen; + int tsig_req; DST_KEY *tsig_key; - ns_tcp_tsig_state tsig_state; - int tsig_signed = 0; - u_char sig[64]; - int siglen; int ixfr_first = 1; int loop_cnt = 0; - time_t timesigned; u_int32_t query_serial = serial_no; + int first_soa_printed; + struct in_addr z_axfr_src; #ifdef DEBUG if (debug) { @@ -932,14 +1110,15 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { if ((l = strlen(zone_top)) != 0 && zone_top[l - 1] == '.') zone_top[l - 1] = '\0'; strcpy(prev_origin, zone_top); + for (cnt = 0; cnt < zp->z_addrcnt; cnt++) { methode = servermethode[cnt]; sin.sin_addr = zp->z_addr[cnt]; dprintf(3, "address [%s] %s\n", inet_ntoa(sin.sin_addr), (methode == ISIXFR) ? "IXFR":"AXFR"); - } + for (cnt = 0; cnt < zp->z_addrcnt; cnt++) { methode = ISNOTIXFR; curclass = zp->z_class; @@ -950,6 +1129,8 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { if (check_serial && tmpiname != NULL) methode = servermethode[cnt]; error = 0; + tsig_signed = 0; + z_axfr_src = zp->z_axfr_src; if (buf == NULL) { if ((buf = (u_char *)malloc(2 * PACKETSZ)) == NULL) { syslog(LOG_INFO, "malloc(%u) failed", @@ -959,17 +1140,20 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { } bufsize = 2 * PACKETSZ; } + tsig_key = tsig_key_from_addr(sin.sin_addr); + try_again: + first_soa_printed = 0; if ((s = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0) { syslog(LOG_INFO, "socket: %m"); error++; break; } - if (zp->z_axfr_src.s_addr != 0) { + if (z_axfr_src.s_addr != 0) { memset(&sin, 0, sizeof sin); sin.sin_family = AF_INET; sin.sin_port = 0; /* "ANY" */ - sin.sin_addr = zp->z_axfr_src; + sin.sin_addr = z_axfr_src; dprintf(2, "binding to address [%s]\n", inet_ntoa(sin.sin_addr)); if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) @@ -981,166 +1165,60 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { sin.sin_port = port; sin.sin_addr = zp->z_addr[cnt]; dprintf(2, "connecting to server #%d [%s].%d\n", - cnt+1, inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); + cnt + 1, inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - if (zp->z_axfr_src.s_addr != 0) { + if (z_axfr_src.s_addr != 0) { dprintf(2, "connect failed, trying w/o -x"); - zp->z_axfr_src.s_addr = 0; + z_axfr_src.s_addr = 0; (void) my_close(s); goto try_again; } if (!quiet) syslog(LOG_INFO, "connect(%s) for zone %s failed: %s", - inet_ntoa(sin.sin_addr), zp->z_origin, strerror(errno)); + inet_ntoa(sin.sin_addr), zp->z_origin, + strerror(errno)); error++; (void) my_close(s); continue; } - if (methode == ISIXFR && was_ixfr == 0) { - hp = (HEADER *) buf; - cpp = buf; - n = res_nmkquery(&res, QUERY, zp->z_origin, curclass, - T_IXFR, NULL, 0, NULL, buf, bufsize); - dprintf(1, "len = %d\n", n); - if (n < 0) { - if (!quiet) - syslog(LOG_INFO, - "zone %s: dn_comp for ixfr failed", - zp->z_origin); - (void) my_close(s); -#ifdef POSIX_SIGNALS - sigaction(SIGALRM, - &osv, - (struct sigaction*)0); -#else - sigvec(SIGALRM, - &osv, - (struct sigvec *)0); -#endif - return (XFER_FAIL); - } - hp->nscount = htons(1+ntohs(hp->nscount)); - cpp += n; - n = dn_comp(zp->z_origin, cpp, bufsize-(cpp-buf), - NULL, NULL); - if (n > 0) - cpp += n; - PUTSHORT(T_SOA, cpp); /* type */ - PUTSHORT(C_IN, cpp); /* class */ - PUTLONG(0, cpp); /* ttl */ - PUTSHORT(22, cpp); /* dlen */ - *cpp++ = 0; /* mname */ - *cpp++ = 0; /* rname */ - PUTLONG(serial_no, cpp); - PUTLONG(0xDEAD, cpp); /* Refresh */ - PUTLONG(0xBEEF, cpp); /* Retry */ - PUTLONG(0xABCD, cpp); /* Expire */ - PUTLONG(0x1776, cpp); /* Min TTL */ - n = cpp-buf; - dprintf(1, "len = %d\n", cpp-buf); - if (debug) - res_pquery(&res, buf, n, ddt); - } - else { - n = res_nmkquery(&res, QUERY, zp->z_origin, curclass, - T_SOA, NULL, 0, NULL, buf, bufsize); + + query_type = (methode == ISIXFR && was_ixfr == 0) ? + T_IXFR : T_SOA; + + n = make_query(s, zp, query_type, serial_no, tsig_key, + buf, bufsize); + if (n < 0) { - if (!quiet) - syslog(LOG_INFO, - "zone %s: res_nmkquery T_SOA failed", - zp->z_origin); (void) my_close(s); #ifdef POSIX_SIGNALS - (void) sigaction(SIGALRM, &osv, (struct sigaction *)0); + (void) sigaction(SIGALRM, &osv, + (struct sigaction *)0); #else - (void) sigvec(SIGALRM, &osv, (struct sigvec *)0); + (void) sigvec(SIGALRM, &osv, + (struct sigvec *)0); #endif return (XFER_FAIL); } - } - /* - * Append TSIG to SOA query if desired - */ - tsig_key = tsig_key_from_addr(sin.sin_addr); - if (tsig_key != NULL) { - siglen = sizeof(sig); - ret = ns_sign(buf, &n, bufsize, NOERROR, tsig_key, - NULL, 0, sig, &siglen, timesigned); - if (ret == 0) - tsig_signed = 1; - } /* - * Send length & message for SOA query + * Get out your butterfly net and catch the answer. */ - if (writemsg(s, buf, n) < 0) { - syslog(LOG_INFO, "writemsg: %m"); - error++; - (void) my_close(s); - continue; - } - /* - * Get out your butterfly net and catch the SOA - */ - - if (netread(s, (char *)buf, INT16SZ, - (soa_cnt == 0) ?400 :XFER_TIMER) < 0) { - (void) my_close(s); + len = readandverify(s, &buf, &bufsize, &sin, zp->z_origin, 1); + if (len == 0) { + my_close(s); error++; continue; } - if ((len = ns_get16(buf)) == 0) { - (void) my_close(s); - continue; - } - if (len > bufsize) { - if ((buf = (u_char *)realloc(buf, len)) == NULL) { - syslog(LOG_INFO, - "malloc(%u) failed for SOA from server [%s], zone %s\n", - len, - inet_ntoa(sin.sin_addr), - zp->z_origin); - (void) my_close(s); - continue; - } - bufsize = len; - } - if (netread(s, (char *)buf, len, XFER_TIMER) < 0) { - error++; - (void) my_close(s); - continue; - } - /* - * Verify the TSIG if expected - */ - if (tsig_signed != 0) { - ret = ns_verify(buf, (int *)&len, tsig_key, sig, siglen, - NULL, NULL, ×igned, 0); - if (ret != 0) { - syslog(LOG_NOTICE, - "SOA TSIG verification from server [%s], zone %s: %s (%d)\n", - inet_ntoa(sin.sin_addr), zp->z_origin, - tsig_rcode(ret), ret); - error++; - continue; - } - } - -#ifdef DEBUG - if (debug >= 3) { - (void)fprintf(ddt,"len = %d\n", len); - res_pquery(&res, buf, len, ddt); - } -#endif - if (((methode == ISIXFR) && (ixfp == NULL)) && was_ixfr == 0) { + + if (query_type == T_IXFR && ixfp == NULL) { delete_soa = 1; ixfr_soa = 0; if ((ixfp = fopen(tmpiname, "w+")) == NULL) { perror(tmpiname); if (!quiet) syslog(LOG_ERR, - "can't fdopen ixfr log (%s)", + "can't fopen ixfr log (%s)", tmpname); exit(XFER_FAIL); } @@ -1158,16 +1236,18 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { * 3) not an answer to our question * 4) both the number of answers and authority count < 1) */ - if (hp->rcode != NOERROR || !hp->aa || qdcount != 1 || + if (hp->rcode != NOERROR || + (query_type == T_SOA && (!hp->aa || qdcount != 1)) || (ancount < 1 && aucount < 1)) { #ifndef SYSLOG_42BSD syslog(LOG_NOTICE, - "[%s] %s for %s, SOA query got rcode %d, aa %d, ancount %d, aucount %d", + "[%s] %s for %s, %s query got rcode %d, aa %d, ancount %d, aucount %d", inet_ntoa(sin.sin_addr), (hp->aa ? (qdcount==1 ?"no SOA found" :"bad response") : "not authoritative"), zp->z_origin[0] != '\0' ? zp->z_origin : ".", + p_type(query_type), hp->rcode, hp->aa, ancount, aucount); #endif error++; @@ -1179,9 +1259,9 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { badsoa_msg = "too short"; badsoa: syslog(LOG_INFO, - "malformed SOA from [%s], zone %s: %s", - inet_ntoa(sin.sin_addr), zp->z_origin, - badsoa_msg); + "malformed %s from [%s], zone %s: %s", + p_type(query_type), inet_ntoa(sin.sin_addr), + zp->z_origin, badsoa_msg); error++; (void) my_close(s); continue; @@ -1211,7 +1291,7 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { NS_GET16(type, tmp); NS_GET16(class, tmp); if (class != curclass || - ((type != T_SOA) && (type != T_IXFR) && (type != T_AXFR)) || + ((type != T_SOA) && (type != T_IXFR) && (type != T_AXFR)) || ns_samename(zp->z_origin, name2) != 1) { syslog(LOG_INFO, @@ -1233,6 +1313,7 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { u_char *cp4, *ocp = tmp; u_short type, class, dlen, olen = len; u_int32_t ttl; + n = dn_expand(buf, eom, tmp, name2, sizeof name2); if (n < 0) { badsoa_msg = "aname error"; @@ -1258,39 +1339,41 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { goto badsoa; } if (type == T_SOA) { - if (was_ixfr) { - methode = ISNOTIXFR; - break; - } - if ((methode == ISIXFR) && (loop_cnt == 0)) { - soa_cnt++; - badsoa_msg = soa_zinfo(&zp_finish, tmp, eom); - if (badsoa_msg) - goto badsoa; - if (ixfp) - if (ixfr_log(buf, len, &delete_soa, ixfp, - &sin, domain, &serial_no, - &ixfr_first) < 0) { - error++; - break; - } - } else { - if (methode == ISIXFR) { - check_serial = 0; - soa_cnt++; + if (was_ixfr) { + methode = ISNOTIXFR; + break; + } + if ((methode == ISIXFR) && (loop_cnt == 0)) { + soa_cnt++; + badsoa_msg = soa_zinfo(&zp_finish, tmp, + eom); + if (badsoa_msg) + goto badsoa; + if (ixfp && ixfr_log(buf, len, + &delete_soa, + ixfp, &sin, + &serial_no, + &ixfr_first) < 0) { + error++; + break; + } + } else { + if (methode == ISIXFR) { + check_serial = 0; + soa_cnt++; + break; + } break; } - break; - } } if ((loop_cnt >= 1) && (soa_cnt < 2)) { - dprintf(1, + dprintf(1, "server %s %d rejected IXFR and responded with AXFR\n", - inet_ntoa(sin.sin_addr), soa_cnt); - methode = ISNOTIXFR; - check_serial = 0; - was_ixfr++; - tmp = bp; + inet_ntoa(sin.sin_addr), soa_cnt); + methode = ISNOTIXFR; + check_serial = 0; + was_ixfr++; + tmp = bp; break; } /* Skip to next record, if any. */ @@ -1298,153 +1381,129 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { name2, p_type(type)); tmp = cp4 + dlen; loop_cnt++; - if (ancount == 1 && loop_cnt == 1) - { + if (loop_cnt == 1) { - badsoa_msg = soa_zinfo(&zp_start, bp, eom); - if (badsoa_msg) - goto badsoa; - if (zp_start.z_serial == serial_no) { - (void) my_close(s); - dprintf(1, "zone up-to-date, serial %u\n", - zp_start.z_serial); - if (ixfp) { - (void) unlink (tmpiname); - (void) fclose(ixfp); - ixfp = NULL; - } - return (XFER_UPTODATE); - } - if (buf2 == NULL) { - if ((buf2 = (u_char *)malloc(2 * PACKETSZ)) == NULL) { - syslog(LOG_INFO, "malloc(%u) failed", 2 * PACKETSZ); - error++; - break; - } - buf2size = 2 * PACKETSZ; - } - if (netread(s, (char *)buf2, INT16SZ, XFER_TIMER) < 0) { - (void) my_close(s); - error++; - tmp = bp; - check_serial = 0; - break; - } - if ((len = ns_get16(buf2)) == 0) { - (void) my_close(s); - tmp = bp; - check_serial = 0; - break; - } - if (len > buf2size) { - if ((buf2 = (u_char *)realloc(buf2, len)) == NULL) { - syslog(LOG_INFO, - "malloc(%u) failed for SOA from server [%s], zone %s\n", - len, - inet_ntoa(sin.sin_addr), - zp->z_origin); - (void) my_close(s); - tmp = bp; - check_serial = 0; - break; - } - buf2size = len; - } - if (netread(s, (char *)buf2, len, XFER_TIMER) < 0) { - error++; - (void) my_close(s); - tmp = bp; - check_serial = 0; - break; - } - /* - * Verify the TSIG if expected - */ - if (tsig_signed != 0) { - ret = ns_verify(buf, (int *)&len, tsig_key, sig, siglen, - NULL, NULL, ×igned, 0); - if (ret != 0) { - syslog(LOG_NOTICE, - "SOA TSIG verification from server [%s], zone %s: %s (%d)\n", - inet_ntoa(sin.sin_addr), zp->z_origin, - tsig_rcode(ret), ret); - error++; - (void) my_close(s); - tmp = bp; - check_serial = 0; - break; - } - } -#ifdef DEBUG - if (debug >= 3) { - (void)fprintf(ddt,"len = %d\n", len); - res_pquery(&res, buf2, len, ddt); + badsoa_msg = soa_zinfo(&zp_start, bp, eom); + if (badsoa_msg) + goto badsoa; + if (check_serial && + !SEQ_GT(zp_start.z_serial, query_serial)) { + (void) my_close(s); + dprintf(1, + "zone up-to-date, serial %u\n", + zp_start.z_serial); + if (ixfp) { + (void) fclose(ixfp); + (void) unlink (tmpiname); + ixfp = NULL; + } + return (XFER_UPTODATE); + } } -#endif - hp = (HEADER *) buf2; - qdcount = ntohs(hp->qdcount); - ancount = ntohs(hp->ancount); - aucount = ntohs(hp->nscount); - arcount = ntohs(hp->arcount); + if (ancount == 1 && loop_cnt == 1) { + if (buf2 == NULL) { + if ((buf2 = (u_char *)malloc(2 * PACKETSZ)) == NULL) { + syslog(LOG_INFO, + "malloc(%u) failed", + 2 * PACKETSZ); + error++; + break; + } + buf2size = 2 * PACKETSZ; + } + len = readandverify(s, &buf2, &buf2size, &sin, + zp->z_origin, 0); + if (len == 0) { + error++; + tmp = bp; + check_serial = 0; + break; + } + + hp = (HEADER *) buf2; + qdcount = ntohs(hp->qdcount); + ancount = ntohs(hp->ancount); + aucount = ntohs(hp->nscount); + arcount = ntohs(hp->arcount); - tmp = buf2 + HFIXEDSZ; - eom = buf2 + len; - /* Query Section. */ - if (qdcount > 1) { - badsoa_msg = "question error"; - goto badsoa; - } - n = dn_expand(buf2, eom, tmp, name2, sizeof name2); - if (n < 0) { - badsoa_msg = "qname error"; - goto badsoa; - } - tmp += n; + tmp = buf2 + HFIXEDSZ; + eom = buf2 + len; + /* Query Section. */ + if (qdcount > 1) { + badsoa_msg = "question error"; + goto badsoa; + } else if (qdcount == 1) { + n = dn_skipname(tmp, eom); + if (n < 0) { + badsoa_msg = "qname error"; + goto badsoa; + } + tmp += n; + if (tmp + 2 * INT16SZ > eom) { + badsoa_msg = "query error"; + goto badsoa; + } + tmp += 2 * INT16SZ; + } + /* answer section */ + if (ancount < 1) { + badsoa_msg = "empty answer"; + goto badsoa; + } + n = dn_expand(buf2, eom, tmp, name2, + sizeof name2); + if (n < 0) { + badsoa_msg = "qname error"; + goto badsoa; + } + tmp += n; bp = tmp; - if (tmp + 2 * INT16SZ > eom) { - badsoa_msg = "query error"; - goto badsoa; - } - NS_GET16(type, tmp); - NS_GET16(class, tmp); - if (class != curclass || - ns_samename(zp->z_origin, name2) != 1) - { - syslog(LOG_INFO, + if (tmp + 2 * INT16SZ > eom) { + badsoa_msg = "query error"; + goto badsoa; + } + NS_GET16(type, tmp); + NS_GET16(class, tmp); + if (class != curclass || + ns_samename(zp->z_origin, name2) != 1) + { + syslog(LOG_INFO, "wrong query in resp from [%s], zone %s: [%s %s %s]\n", - inet_ntoa(sin.sin_addr), zp->z_origin, - name2, p_class(class), p_type(type)); - error++; - (void) my_close(s); - tmp = bp; - check_serial = 0; - break; - } + inet_ntoa(sin.sin_addr), zp->z_origin, + name2, p_class(class), p_type(type)); + error++; + tmp = bp; + check_serial = 0; + break; + } if (type == T_SOA) { - ixfr_single_answer_mode = 1; - if (ixfp) - if (ixfr_log(buf2, len, &delete_soa, ixfp, - &sin, domain, &serial_no, - &ixfr_first) < 0) { - error++; - break; - } - free(buf); - buf = buf2; - bufsize = buf2size; - break; - } - else { - methode = ISNOTIXFR; - was_ixfr++; - check_serial = 0; - cp = buf + HFIXEDSZ; - n = print_output(zp, serial_no, buf, olen, ocp, 3); + ixfr_single_answer_mode = 1; + if (ixfp && + ixfr_log(buf2, len, &delete_soa, ixfp, + &sin, &serial_no, + &ixfr_first) < 0) { + error++; + break; + } + free(buf); buf = buf2; - bufsize = buf2size; + bufsize = buf2size; + buf2 = NULL; break; - } - } + } else { + methode = ISNOTIXFR; + was_ixfr++; + check_serial = 0; + cp = buf + HFIXEDSZ; + n = print_output(zp, serial_no, buf, olen, ocp, 3); + first_soa_printed = 1; + free(buf); + buf = buf2; + buf2 = NULL; + bufsize = buf2size; + break; + } + } if (loop_cnt > 1) { tmp = bp; check_serial = 0; @@ -1452,9 +1511,11 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { } } while (1); - if (error != 0) { - return (XFER_FAIL); - } + if (error != 0) { + (void) my_close(s); + continue; + } + if (ns_samename(zp->z_origin, name2) != 1) { syslog(LOG_INFO, "wrong answer in resp from [%s], zone %s: [%s %s %s]\n", @@ -1464,57 +1525,27 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { (void) my_close(s); continue; } - if (loop_cnt < 1) { - badsoa_msg = soa_zinfo(&zp_start, tmp, eom); - if (badsoa_msg) - goto badsoa; - } + if (loop_cnt < 1) { + badsoa_msg = soa_zinfo(&zp_start, tmp, eom); + if (badsoa_msg) + goto badsoa; + } if (methode == ISNOTIXFR) { - if (SEQ_GT(zp_start.z_serial, serial_no) || !check_serial) { - const char *l, *nl, *t; - - if (soa_cnt) { - goto axfr_response; - } - dprintf(1, "need update, serial %u\n", - zp_start.z_serial); - soa_cnt = 0; - hp = (HEADER *) buf; - ns_cnt = 0; - gettime(&tt); - locallen = sizeof local; - if (getsockname(s, (struct sockaddr *)&local, - &locallen) < 0) { - memset(&local, 0, sizeof local); - } - for (l = Version; l; l = nl) { - size_t len; - if ((nl = strchr(l, '\n')) != NULL) { - len = nl - l; - nl = nl + 1; - } else { - len = strlen(l); - nl = NULL; + if (SEQ_GT(zp_start.z_serial, serial_no) || + !check_serial) { + if (soa_cnt) { + if (!first_soa_printed) + soa_cnt = 0; + goto axfr_response; } - while (isspace((unsigned char) *l)) - l++; - if (*l) - fprintf(dbfp, "; BIND version %.*s\n", - (int)len, l); - } - fprintf(dbfp, check_serial? - "; zone '%s' last serial %u\n": - "; zone '%s' first transfer\n", - domain, serial_no); - t = strdup(inet_ntoa(sin.sin_addr)); - if (t == NULL) - return (XFER_FAIL); - fprintf(dbfp, "; from %s:%d (local %s) using %s at %s", - t, ntohs(sin.sin_port), - inet_ntoa(local.sin_addr), - (methode == ISIXFR) ? "IXFR":"AXFR", - ctimel(tt.tv_sec)); - free((void *)t); + dprintf(1, "need update, serial %u\n", + zp_start.z_serial); + soa_cnt = 0; + hp = (HEADER *) buf; + ns_cnt = 0; + print_comment(s, &sin, check_serial, + serial_no, tsig_key); + for (;;) { if ((soa_cnt == 0) || (zp->z_type == Z_STUB)) { if (zp->z_type == Z_STUB) { @@ -1527,33 +1558,24 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { query_type = T_IXFR; else query_type = xfr_qtype; - n = res_nmkquery(&res, QUERY, - zp->z_origin, - curclass, query_type, - NULL, 0, - NULL, buf, bufsize); + n = make_query(s, zp, query_type, + serial_no, tsig_key, + buf, bufsize); syslog(LOG_INFO, "send %s query %d to %s", - (query_type == T_IXFR) ? "IXFR" : - (query_type == T_AXFR) ? "AXFR" : - (query_type == ns_t_zxfr) ? "ZXFR" : - (query_type == T_SOA) ? "SOA" : "NS", + p_type(query_type), cnt, inet_ntoa(sin.sin_addr)); dprintf(1, "send %s query to %s\n", - (query_type == T_IXFR) ? "IXFR" : - (query_type == T_AXFR) ? "AXFR" : - (query_type == ns_t_zxfr) ? "ZXFR" : - (query_type == T_SOA) ? "SOA" : "NS", + p_type(query_type), inet_ntoa(sin.sin_addr)); dprintf(1,"bufsize = %d\n", bufsize); if (n < 0) { if (!quiet) { if (zp->z_type == Z_STUB) syslog(LOG_INFO, - (query_type == T_SOA) - ? "zone %s: res_nmkquery T_SOA failed" - : "zone %s: res_nmkquery T_NS failed", + "zone %s: res_nmkquery %s failed", + p_type(query_type), zp->z_origin); else syslog(LOG_INFO, @@ -1571,93 +1593,21 @@ getzone(struct zoneinfo *zp, u_int32_t serial_no, int port) { #endif return (XFER_FAIL); } - cpp = buf + n; - /* - * Append TSIG to AXFR query if desired - */ - if (tsig_signed != 0) { - siglen = sizeof(sig); - ns_sign(buf, &n, bufsize, - NOERROR, tsig_key, - NULL, 0, sig, &siglen, - timesigned); - cpp = buf + n; - ns_verify_tcp_init(tsig_key, - sig, siglen, - &tsig_state); - } - /* - * Send length & msg for zone transfer - */ - if (writemsg(s, buf, cpp - buf) < 0) { - syslog(LOG_INFO, - "writemsg: %m"); - error++; - (void) my_close(s); - break; - } } /*XXX ZXFR*/ receive: /* * Receive length & response */ - if (netread(s, (char *)buf, INT16SZ, - (soa_cnt == 0) ?300 :XFER_TIMER) - < 0) { + tsig_req = (soa_cnt == 0); + len = readandverify(s, &buf, &bufsize, &sin, + zp->z_origin, tsig_req); + if (len == 0) { error++; break; } - if ((len = ns_get16(buf)) == 0) - break; - if (len > bufsize) { - buf = (u_char *)realloc(buf, len); - if (buf == NULL) { - syslog(LOG_INFO, - "malloc(%u) failed for packet from server [%s], zone %s\n", - len, - inet_ntoa(sin.sin_addr), - zp->z_origin); - error++; - break; - } - bufsize = len; - } hp = (HEADER *)buf; eom = buf + len; - if (netread(s, (char *)buf, len, XFER_TIMER) - < 0) { - error++; - break; - } -#ifdef DEBUG - if (debug >= 3) { - (void)fprintf(ddt,"len = %d\n", len); - res_pquery(&res, buf, len, ddt); - } - if (fp) - res_pquery(&res, buf, len, fp); -#endif - /* - * Verify the TSIG if expected - */ - if (tsig_signed != 0) { - tsig_req = (soa_cnt == 0); - ret = ns_verify_tcp(buf, (int *)&len, - &tsig_state, - tsig_req); - eom = buf + len; - - if (ret != 0) { - syslog(LOG_NOTICE, - "TSIG verification from server [%s], zone %s: %s (%d)\n", - inet_ntoa(sin.sin_addr), - zp->z_origin, - tsig_rcode(ret), ret); - error++; - break; - } - } if (len < HFIXEDSZ) { badrec: error++; @@ -1673,8 +1623,8 @@ receive: sin_addr), ntohs(my_addr.sin_port) ); - if ((hp->rcode == REFUSED) && - (len >= HFIXEDSZ)) { + if ((len >= HFIXEDSZ) && + (hp->rcode == REFUSED)) { syslog(LOG_INFO, "[%s] transfer refused from [%s], zone %s\n", my_addr_text, @@ -1692,7 +1642,7 @@ receive: axfr_response: if (query_type == T_IXFR) if (hp->rcode != NOERROR) { - dprintf(1, + dprintf(1, "server %s did not support IXFR\n", inet_ntoa(sin.sin_addr)); methode = ISNOTIXFR; @@ -1700,11 +1650,12 @@ axfr_response: }; cp = buf + HFIXEDSZ; if (ntohs(hp->qdcount) == 1) { - if ((query_type == T_IXFR) && (methode == ISIXFR)) { - dprintf(1, - "server %s rejected IXFR and responded with AXFR\n", + if ((query_type == T_IXFR) && + (methode == ISIXFR)) { + dprintf(1, + "server %s rejected IXFR and responded with AXFR\n", inet_ntoa(sin.sin_addr)); - methode = ISNOTIXFR; + methode = ISNOTIXFR; } n = dn_skipname(cp, eom); if ((n == -1) || @@ -1793,15 +1744,12 @@ axfr_response: } else { ancount = ntohs(hp->ancount); if (query_type == T_IXFR && - methode == ISIXFR) { - if (ixfr_log(buf, len, - &delete_soa, ixfp, - &sin, domain, - &serial_no, - &ixfr_first) < 0){ - error++; - break; - } + methode == ISIXFR && + ixfr_log(buf, len, &delete_soa, + ixfp, &sin, &serial_no, + &ixfr_first) < 0 ){ + error++; + break; } for (n = cnt = 0; cnt < (u_int)ancount; @@ -1834,54 +1782,54 @@ axfr_response: break; if ((soa_cnt == -1) && (methode == ISIXFR)) break; - } - (void) my_close(s); - if (error == 0) { + } + (void) my_close(s); + if (error == 0) { #ifdef POSIX_SIGNALS - (void) sigaction(SIGALRM, &osv, - (struct sigaction *)0); + (void) sigaction(SIGALRM, &osv, + (struct sigaction *)0); #else - (void) sigvec(SIGALRM, &osv, - (struct sigvec *)0); + (void) sigvec(SIGALRM, &osv, + (struct sigvec *)0); #endif + if (ixfp) { + (void) fclose(ixfp); + ixfp = NULL; + } + return (XFER_SUCCESSAXFR); + } if (ixfp) { (void) fclose(ixfp); ixfp = NULL; } - return (XFER_SUCCESSAXFR); - } - if (ixfp) { - (void) fclose(ixfp); - ixfp = NULL; - } - dprintf(2, "error receiving zone transfer\n"); - } else if (zp_start.z_serial == serial_no) { - (void) my_close(s); - dprintf(1, "zone up-to-date, serial %u\n", - zp_start.z_serial); - if (ixfp) { - (void) unlink (tmpiname); - (void) fclose(ixfp); - ixfp = NULL; - } - return (XFER_UPTODATE); - } else { - (void) my_close(s); + dprintf(2, "error receiving zone transfer\n"); + } else if (zp_start.z_serial == serial_no) { + (void) my_close(s); + dprintf(1, "zone up-to-date, serial %u\n", + zp_start.z_serial); + if (ixfp) { + (void) fclose(ixfp); + (void) unlink (tmpiname); + ixfp = NULL; + } + return (XFER_UPTODATE); + } else { + (void) my_close(s); if (!quiet) syslog(LOG_NOTICE, "serial from [%s], zone %s: %u lower than current: %u\n", inet_ntoa(sin.sin_addr), zp->z_origin, zp_start.z_serial, serial_no); - return (XFER_FAIL); - } + return (XFER_FAIL); + } } else { if (zp_finish.z_serial == query_serial) { (void) my_close(s); dprintf(1, "zone up-to-date, serial %u\n", zp_start.z_serial); if (ixfp) { - (void) unlink (tmpiname); (void) fclose(ixfp); + (void) unlink (tmpiname); ixfp = NULL; } return (XFER_UPTODATE); @@ -1898,21 +1846,15 @@ axfr_response: zp_finish.z_serial, query_serial); if (ixfp) { (void) fclose(ixfp); - ixfp = NULL; (void) unlink (tmpiname); + ixfp = NULL; } if (was_ixfr == 0) { was_ixfr++; - n = res_nmkquery(&res, QUERY, - zp->z_origin, - curclass, T_AXFR, - NULL, 0, - NULL, buf, bufsize); + n = make_query(s, zp, T_AXFR, + serial_no, tsig_key, + buf, bufsize); if (n < 0) { - if (!quiet) - syslog(LOG_INFO, - "zone %s: res_nmkquery T_SOA failed", - zp->z_origin); (void) my_close(s); #ifdef POSIX_SIGNALS (void) sigaction(SIGALRM, &osv, @@ -1923,34 +1865,11 @@ axfr_response: #endif return (XFER_FAIL); } - /* - * Append TSIG to SOA query if desired - */ - tsig_key = tsig_key_from_addr(sin.sin_addr); - if (tsig_key != NULL) { - siglen = sizeof(sig); - ret = ns_sign(buf, &n, bufsize, - NOERROR, - tsig_key, NULL, - 0, sig, &siglen, - timesigned); - if (ret == 0) - tsig_signed = 1; - } - - /* - * Send length & message for AXFR query - */ - if (writemsg(s, buf, n) < 0) - syslog(LOG_INFO, - "writemsg: %m"); - else { - methode = ISNOTIXFR; - check_serial = 0; - soa_cnt = 0; - was_ixfr = 0; - goto receive; - } + methode = ISNOTIXFR; + check_serial = 0; + soa_cnt = 0; + was_ixfr = 0; + goto receive; } (void) my_close(s); return (XFER_FAIL); @@ -1959,70 +1878,23 @@ axfr_response: methode = ISNOTIXFR; check_serial = 0; soa_cnt = 0; - goto axfr_response; + goto axfr_response; } dprintf(1, "We have an IXFR\n"); - loop_cnt = 0; + loop_cnt = 0; while (SEQ_GT(zp_finish.z_serial, serial_no)) { /* * Receive length & response */ - if (netread(s, (char *)buf, INT16SZ, - (soa_cnt == 0) ?300 :XFER_TIMER) - < 0) { + tsig_req = (soa_cnt == 0); + len = readandverify(s, &buf, &bufsize, &sin, + zp->z_origin, 1); + if (len == 0) { error++; break; } - if ((len = ns_get16(buf)) == 0) - break; - if (len > bufsize) { - buf = (u_char *)realloc(buf, len); - if (buf == NULL) { - syslog(LOG_INFO, - "malloc(%u) failed for packet from server [%s], zone %s\n", - len, - inet_ntoa(sin.sin_addr), - zp->z_origin); - error++; - break; - } - bufsize = len; - } hp = (HEADER *)buf; eom = buf + len; - if (netread(s, (char *)buf, len, XFER_TIMER) - < 0) { - error++; - break; - } -#ifdef DEBUG - if (debug >= 3) { - (void)fprintf(ddt,"len = %d\n", len); - res_pquery(&res, buf, len, ddt); - } - if (fp) - res_pquery(&res, buf, len, fp); -#endif - /* - * Verify the TSIG if expected - */ - if (tsig_signed != 0) { - tsig_req = (soa_cnt == 0); - ret = ns_verify_tcp(buf, (int *)&len, - &tsig_state, - tsig_req); - eom = buf + len; - - if (ret != 0) { - syslog(LOG_NOTICE, - "TSIG verification from server [%s], zone %s: %s (%d)\n", - inet_ntoa(sin.sin_addr), - zp->z_origin, - tsig_rcode(ret), ret); - error++; - break; - } - } if (len < HFIXEDSZ) { error++; alen = sizeof my_addr; @@ -2049,20 +1921,19 @@ axfr_response: } break; } - if (ixfp) { - if (ixfr_log(buf, len, &delete_soa, ixfp, - &sin, domain, &serial_no, - &ixfr_first) < 0) { - error++; - break; - } - } + if (ixfp && + ixfr_log(buf, len, &delete_soa, ixfp, + &sin, &serial_no, &ixfr_first) < 0) + { + error++; + break; + } } (void) my_close(s); if (!error) { fprintf(ixfp, "update:\t{add} "); if (soa_buf) - fputs(soa_buf, ixfp); + fputs(soa_buf, ixfp); fprintf(ixfp, "[END_DELTA]\n"); return (XFER_SUCCESSIXFR); } @@ -2074,9 +1945,9 @@ axfr_response: (void) sigvec(SIGALRM, &osv, (struct sigvec *)0); #endif if (ixfp) { - (void) unlink (tmpiname); - (void) my_fclose(ixfp); - ixfp = 0; + (void) my_fclose(ixfp); + (void) unlink (tmpiname); + ixfp = NULL; } if (!error) return (XFER_TIMEOUT); @@ -2103,7 +1974,8 @@ netread(int fd, char *buf, int len, int timeout) { static const char setitimerStr[] = "setitimer: %m"; struct itimerval ival, zeroival; struct sockaddr_in sa; - int n, salen; + int n; + ISC_SOCKLEN_T salen; #if defined(NETREAD_BROKEN) int retries = 0; #endif @@ -2112,7 +1984,7 @@ netread(int fd, char *buf, int len, int timeout) { ival = zeroival; ival.it_value.tv_sec = timeout; while (len > 0) { -#ifndef WINNT +#ifndef _WIN32 if (setitimer(ITIMER_REAL, &ival, NULL) < 0) { syslog(LOG_INFO, setitimerStr); return (-1); @@ -2153,8 +2025,13 @@ netread(int fd, char *buf, int len, int timeout) { } buf += n; len -= n; +#if defined(NETREAD_BROKEN) + /* Reset the retry counter if we are successfully reading. */ + if(n > 0) + retries = 0; +#endif } -#ifndef WINNT +#ifndef _WIN32 if (setitimer(ITIMER_REAL, &zeroival, NULL) < 0) { syslog(LOG_INFO, setitimerStr); return (-1); @@ -2175,7 +2052,7 @@ writemsg(int rfd, const u_char *msg, int msglen) { __putshort(msglen, len); iov[0].iov_base = (char *)len; iov[0].iov_len = INT16SZ; - iov[1].iov_base = (char *)msg; + DE_CONST(msg, iov[1].iov_base); iov[1].iov_len = msglen; ret = writev(rfd, iov, 2); if (ret != INT16SZ + msglen) { @@ -2243,7 +2120,7 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, u_char *cp; HEADER *hp = (HEADER *) msg; u_int32_t ttl, tmpnum; - int i, j, tab, result, n1, n; + int i, j, longname, result, n1, n; u_int class, type, dlen; char data[MAXDATA]; u_char *cp1, *cp2, *temp_ptr, *eom, *rr_type_ptr; @@ -2540,10 +2417,10 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, break; default: - syslog(LOG_INFO, "\"%s %s %s\" - unknown type (%d)", - dname, p_class(class), p_type(type), type); - hp->rcode = NOTIMP; - return (-1); + cp1 = cp; + n = dlen; + cp += n; + break; } if (n > MAXDATA) { @@ -2689,7 +2566,7 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, } if ((!soa_cnt || soa_cnt > 2) && methode == ISNOTIXFR) { - char *gripe; + const char *gripe; if (!soa_cnt) gripe = "got RR before first SOA"; @@ -2729,7 +2606,7 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, (void) fprintf(dbfp, "; Ignoring extra info about %s, invalid after NS delegation.\n", dname); ignore = "; "; - } else if (class != zp->z_class) { + } else if (class != (unsigned)zp->z_class) { (void) fprintf(dbfp, "; Ignoring info about %s, not class %s\n", dname, p_class(zp->z_class)); ignore = "; "; @@ -2764,7 +2641,8 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, (void) strcpy(prev_origin, origin); (void) fprintf(dbfp, "%s$ORIGIN %s.\n", ignore, origin); } - tab = 0; + + longname = 0; if (ns_samename(prev_dname, dname) != 1) { /* @@ -2790,17 +2668,16 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, (void) fprintf(dbfp, "%s.%s.\t", ignore, origin); /* ??? */ } else { - char *backslash; + const char *backslash; backslash = (*dname == '@' || *dname == '$') ? "\\" : ""; (void) fprintf(dbfp, "%s%s%s\t", ignore, backslash, dname); } - if (strlen(dname) < (size_t)8) - tab = 1; + if (strlen(dname) > (size_t)8) + longname = 1; } else { (void) fprintf(dbfp, "%s\t", ignore); - tab = 1; } (void) fprintf(dbfp, "%d\t", (int) ttl); @@ -3116,10 +2993,15 @@ print_output(struct zoneinfo *zp, u_int32_t serial_no, u_char *msg, } default: - cp1 = cp + n; - while (cp < cp1) - fprintf(dbfp, "0x%02X ", *cp++ & 0xFF); - (void) fprintf(dbfp, "???\n"); + fprintf (dbfp, "\\# %u", n); + if (n > 0) { + fputs(" ( ", dbfp); + isc_puthexstring(dbfp, cp1, n, + (longname ? 28 : 40), 48, + "\n\t\t\t\t"); + fputs(" )\n", dbfp); + } + } if (ferror(dbfp)) { syslog(LOG_ERR, "%s: %m", tmpname); @@ -3180,7 +3062,7 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file, int *delete) ns_rr rr; const unsigned char *cp; const unsigned char *eom; - u_int32_t serial; + u_int32_t serial = 0; time_t now; time(&now); @@ -3203,7 +3085,7 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file, int *delete) } else if (rrnum > 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1)) putc('\n', file); - return (serial); + break; } if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1)) fprintf(file, ";; %s SECTION:\n", @@ -3216,7 +3098,7 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file, int *delete) else { int print_record = 1; if (rr.type == ns_t_soa) { - print_record = 0; + print_record = 0; *delete = !*delete; cp = ns_rr_rdata(rr); eom = cp + ns_rr_rdlen(rr); @@ -3277,8 +3159,8 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file, int *delete) return(-1); } fputs(buf, file); - fputc('\n', file); - } + fputc('\n', file); + } } } @@ -3289,8 +3171,7 @@ do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file, int *delete) static int ixfr_log(const u_char *msg, int len, int *delete, FILE *file, - struct sockaddr_in *sin, char *domain, u_int32_t *serial_no, - int *first_rr) + struct sockaddr_in *sin, u_int32_t *serial_no, int *first_rr) { ns_msg handle; ns_type type; @@ -3337,8 +3218,8 @@ ixfr_log(const u_char *msg, int len, int *delete, FILE *file, (*first_rr)++; } new_serial = do_section(&handle, ns_s_an, RES_PRF_ANS, file, delete); - if (type == T_SOA && SEQ_GT(new_serial, *serial_no) && (*delete)) - *serial_no = new_serial; + if (type == T_SOA && SEQ_GT(new_serial, *serial_no) && (*delete)) + *serial_no = new_serial; return (1); } @@ -3363,4 +3244,3 @@ tsig_rcode(int rcode) { } return ("FORMERR"); } - diff --git a/contrib/bind/bin/named/db_defs.h b/contrib/bind/bin/named/db_defs.h index f18acae2b7fd..72aa19fa1874 100644 --- a/contrib/bind/bin/named/db_defs.h +++ b/contrib/bind/bin/named/db_defs.h @@ -1,6 +1,6 @@ /* * from db.h 4.16 (Berkeley) 6/1/90 - * $Id: db_defs.h,v 8.41 2001/02/08 02:05:50 marka Exp $ + * $Id: db_defs.h,v 8.46 2001/11/17 15:16:46 marka Exp $ */ /* @@ -111,7 +111,14 @@ * indicate what the union is being used for. This should require less * memory than making d_addr a union of struct in6_addr and struct in_addr. */ +#ifdef CHECK_MAGIC +#define DATABUF_MAGIC (('D'<<24)|('A'<<16)|('T'<<8)|'A') +#endif + struct databuf { +#ifdef CHECK_MAGIC + u_int32_t d_magic; /* magic number */ +#endif struct databuf *d_next; /* linked list */ struct in_addr d_addr; /* NS from whence this came */ u_int32_t d_ttl; /* time to live */ @@ -130,6 +137,7 @@ struct databuf { unsigned d_clev :6; unsigned d_rcode :4; /* rcode for negative caching */ unsigned d_mark :3; /* place to mark data */ + unsigned d_noedns :1; /* this server does not support edns */ int16_t d_type; /* type number */ int16_t d_size; /* size of data area */ u_int32_t d_rcnt; @@ -184,11 +192,14 @@ struct namebuf { struct databuf *n_data; /* data records */ struct namebuf *n_parent; /* parent domain */ struct hashbuf *n_hash; /* hash table for children */ - char _n_name[sizeof(void*)]; /* Counted str (dynamic). */ + union { + char _n_name[sizeof(void*)]; + unsigned char _n_len[sizeof(void*)]; + } _n; /* Counted str (dynamic). */ }; #define NAMESIZE(n) (sizeof(struct namebuf) - sizeof(void*) + 1 + n + 1) -#define NAMELEN(nb) (((u_char *)((nb)._n_name))[0]) -#define NAME(nb) ((nb)._n_name + 1) +#define NAMELEN(nb) ((((nb)._n._n_len))[0]) +#define NAME(nb) ((nb)._n._n_name + 1) struct hashbuf { int h_size; /* size of hash table */ @@ -211,6 +222,7 @@ struct tsig_record { u_int8_t sig[TSIG_SIG_SIZE]; struct dst_key *key; int siglen; + int tsig_size; }; struct sig_record { @@ -227,7 +239,7 @@ struct dnode { struct databuf *dp; struct dnode *dn_next; int line; - char *file; + const char *file; }; typedef struct dnode * dlist; @@ -280,6 +292,7 @@ struct db_rrset { #endif #define CNAMEANDOTHER (-12) #define DNSSECFAIL (-13) /* db_set_update */ +#define NONGLUE (-14) /* * getnum() options diff --git a/contrib/bind/bin/named/db_dump.c b/contrib/bind/bin/named/db_dump.c index a35071954e58..26daa6f2abc0 100644 --- a/contrib/bind/bin/named/db_dump.c +++ b/contrib/bind/bin/named/db_dump.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_dump.c 4.33 (Berkeley) 3/3/91"; -static const char rcsid[] = "$Id: db_dump.c,v 8.49 2001/02/06 06:42:19 marka Exp $"; +static const char rcsid[] = "$Id: db_dump.c,v 8.51 2001/06/18 14:42:49 marka Exp $"; #endif /* not lint */ /* @@ -120,6 +120,7 @@ static const char rcsid[] = "$Id: db_dump.c,v 8.49 2001/02/06 06:42:19 marka Exp #include #include +#include #include "port_after.h" @@ -177,7 +178,8 @@ zt_dump(FILE *fp) { fprintf(fp, ";; ++zone table++\n"); for (zp = &zones[0]; zp < &zones[nzones]; zp++) { - char *pre, buf[64]; + const char *pre; + char buf[64]; u_int cnt; if (!zp->z_origin) @@ -230,7 +232,7 @@ fwd_dump(FILE *fp) { } int -db_dump(struct hashbuf *htp, FILE *fp, int zone, char *origin) { +db_dump(struct hashbuf *htp, FILE *fp, int zone, const char *origin) { struct databuf *dp = NULL; struct namebuf *np; struct namebuf **npp, **nppend; @@ -621,9 +623,14 @@ db_dump(struct hashbuf *htp, FILE *fp, int zone, char *origin) { break; default: - fprintf(fp, "%s?d_type=%d?", - sep, dp->d_type); - sep = " "; + fprintf(fp, "\\# %u", dp->d_size); + if (dp->d_size != 0) { + fputs(" ( ", fp); + isc_puthexstring(fp, dp->d_data, + dp->d_size, 40, 48, + "\n\t\t\t\t"); + fputs(" ) ", fp); + } } if (dp->d_cred < DB_C_ZONE) { fprintf(fp, "%sCr=%s", diff --git a/contrib/bind/bin/named/db_func.h b/contrib/bind/bin/named/db_func.h index d01de88f756c..7e7e05e37ea8 100644 --- a/contrib/bind/bin/named/db_func.h +++ b/contrib/bind/bin/named/db_func.h @@ -90,7 +90,7 @@ /* db_proc.h - prototypes for functions in db_*.c * - * $Id: db_func.h,v 8.44 2000/12/02 23:28:33 vixie Exp $ + * $Id: db_func.h,v 8.46 2001/06/18 14:42:51 marka Exp $ */ /* ++from db_update.c++ */ @@ -113,7 +113,7 @@ struct hashbuf * savehash(struct hashbuf *); /* --from db_save.c-- */ /* ++from db_dump.c++ */ -int db_dump(struct hashbuf *, FILE *, int, char *), +int db_dump(struct hashbuf *, FILE *, int, const char *), zt_dump(FILE *); void doadump(void); /* --from db_dump.c-- */ @@ -142,7 +142,7 @@ int parse_sec_rdata(char *inp, int inp_len, int inp_full, char *domain, u_int32_t ttl, int type, enum context context, enum transport transport, - char **errmsg); + const char **errmsg); /* --from db_load.c-- */ /* ++from db_glue.c++ */ @@ -165,7 +165,7 @@ struct namebuf * rm_name(struct namebuf *, struct namebuf **, struct namebuf *); void rm_hash(struct hashbuf *); -void db_freedata(struct databuf *); +void db_detach(struct databuf **); void db_lame_add(char *zone, char *server, time_t when); time_t db_lame_find(char *zone, struct databuf *dp); void db_lame_clean(void); @@ -203,7 +203,7 @@ int db_set_update(char *name, struct databuf *dp, /* --from db_sec.c-- */ /* ++from db_tsig.c++ */ -char * tsig_alg_name(int value); +const char * tsig_alg_name(int value); int tsig_alg_value(char *name); struct dst_key * tsig_key_from_addr(struct in_addr addr); struct tsig_record * new_tsig(struct dst_key *key, u_char *sig, int siglen); diff --git a/contrib/bind/bin/named/db_glue.c b/contrib/bind/bin/named/db_glue.c index ba5980284391..e984db11ee4c 100644 --- a/contrib/bind/bin/named/db_glue.c +++ b/contrib/bind/bin/named/db_glue.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_glue.c 4.4 (Berkeley) 6/1/90"; -static const char rcsid[] = "$Id: db_glue.c,v 8.42 2000/12/23 08:14:35 vixie Exp $"; +static const char rcsid[] = "$Id: db_glue.c,v 8.46 2001/11/25 23:52:19 marka Exp $"; #endif /* not lint */ /* @@ -145,8 +145,8 @@ destroyservicelist() { for (slp = servicelist; slp != NULL; slp = slp_next) { slp_next = slp->next; - freestr(slp->name); - freestr(slp->proto); + slp->name = freestr(slp->name); + slp->proto = freestr(slp->proto); memput(slp, sizeof *slp); } servicelist = NULL; @@ -183,7 +183,7 @@ destroyprotolist() { for (plp = protolist; plp != NULL; plp = plp_next) { plp_next = plp->next; - freestr(plp->name); + plp->name = freestr(plp->name); memput(plp, sizeof *plp); } protolist = NULL; @@ -354,31 +354,7 @@ rm_datum(struct databuf *dp, struct namebuf *np, struct databuf *pdp, } else dp->d_next = NULL; dp->d_flags &= ~DB_F_ACTIVE; - DRCNTDEC(dp); - if (dp->d_rcnt) { -#ifdef DEBUG - int32_t ii; -#endif - - switch(dp->d_type) { - case T_NS: - ns_debug(ns_log_db, 3, "rm_datum: %s rcnt = %d", - dp->d_data, dp->d_rcnt); - break; -#ifdef DEBUG - case T_A: - memcpy(&ii, dp->d_data, sizeof ii); - ns_debug(ns_log_db, 3, - "rm_datum: %08.8X rcnt = %d", - ii, dp->d_rcnt); - break; -#endif - default: - ns_debug(ns_log_db, 3, - "rm_datum: rcnt = %d", dp->d_rcnt); - } - } else - db_freedata(dp); + db_detach(&dp); return (ndp); } @@ -393,10 +369,10 @@ rm_name(struct namebuf *np, struct namebuf **pp, struct namebuf *pnp) { const char *msg; /* verify */ - if ( (np->n_data && (msg = "data")) - || (np->n_hash && (msg = "hash")) + if ( (np->n_data != NULL && (msg = "data") != NULL) + || (np->n_hash != NULL && (msg = "hash") != NULL) ) { - ns_panic(ns_log_db, 1, "rm_name(%#x(%s)): non-nil %s pointer", + ns_panic(ns_log_db, 1, "rm_name(%p(%s)): non-nil %s pointer", np, NAME(*np), msg); } @@ -463,7 +439,7 @@ nhash(const char *name) { return (hval); } -void +static void db_freedata(struct databuf *dp) { int bytes = DATASIZE(dp->d_size); @@ -476,9 +452,28 @@ db_freedata(struct databuf *dp) { if (dp->d_next != NULL) panic("db_free: d_next != NULL", NULL); dp->d_flags |= DB_F_FREE; +#ifdef CHECK_MAGIC + dp->d_magic = 0; +#endif memput(dp, bytes); } +void +db_detach(struct databuf **dpp) { + struct databuf *dp; + + INSIST(dpp != NULL && *dpp != NULL); + dp = *dpp; +#ifdef CHECK_MAGIC + INSIST(dp->d_magic == DATABUF_MAGIC); +#endif + + DRCNTDEC(dp); + if (dp->d_rcnt == 0) + db_freedata(dp); + *dpp = NULL; +} + struct lame_hash { struct lame_hash *next; char *zone; @@ -550,9 +545,9 @@ db_lame_add(char *zone, char *server, time_t when) { this->zone = savestr(zone, 0); if (this->server == NULL || this->zone == NULL) { if (this->server != NULL) - freestr(this->server); + this->server = freestr(this->server); if (this->zone != NULL) - freestr(this->zone); + this->zone = freestr(this->zone); memput(this, sizeof *this); return; } @@ -602,8 +597,8 @@ db_lame_clean(void) { this = lame_hash[i]; while (this != NULL) { if (this->when < tt.tv_sec) { - freestr(this->zone); - freestr(this->server); + this->zone = freestr(this->zone); + this->server = freestr(this->server); if (last != NULL) { last->next = this->next; memput(this, sizeof *this); @@ -635,8 +630,8 @@ db_lame_destroy(void) { while (this != NULL) { last = this; this = this->next; - freestr(last->zone); - freestr(last->server); + last->zone = freestr(last->zone); + last->server = freestr(last->server); memput(last, sizeof *this); } } diff --git a/contrib/bind/bin/named/db_ixfr.c b/contrib/bind/bin/named/db_ixfr.c index e51507537d57..231db12aa08a 100644 --- a/contrib/bind/bin/named/db_ixfr.c +++ b/contrib/bind/bin/named/db_ixfr.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static char rcsid[] = "$Id: db_ixfr.c,v 8.23.2.2 2001/05/03 03:53:18 marka Exp $"; +static char rcsid[] = "$Id: db_ixfr.c,v 8.31 2002/01/02 04:47:10 marka Exp $"; #endif /* @@ -52,6 +52,7 @@ static char rcsid[] = "$Id: db_ixfr.c,v 8.23.2.2 2001/05/03 03:53:18 marka E #include #include #include +#include #include "port_after.h" @@ -108,25 +109,29 @@ ixfr_get_change_list(struct zoneinfo *zp, case DBIXFR_ERROR: ns_warning(ns_log_db, "Logical error in %s: unlinking", zp->z_ixfr_base); + if (fp != NULL) { + (void) my_fclose(fp); + fp = NULL; + } unlink(zp->z_ixfr_base); goto cleanup; case DBIXFR_FOUND_RR: - ns_debug(ns_log_default, 4, "ixfr_getdelta DBIXFR_FOUND_RR (%s)", - zp->z_origin); + ns_debug(ns_log_default, 4, + "ixfr_getdelta DBIXFR_FOUND_RR (%s)", + zp->z_origin); if (EMPTY(*dlhead)) { /* skip updates prior to the one we want */ uprec = HEAD(dl->d_changes); INSIST(uprec != NULL); - if ((uprec->r_zone < from_serial) || - (uprec->r_zone > to_serial)) + if (SEQ_LT(uprec->r_zone, from_serial) || + SEQ_GT(uprec->r_zone, to_serial)) { while ((uprec = HEAD(dl->d_changes)) != NULL) { UNLINK(dl->d_changes, uprec, r_link); if (uprec->r_dp != NULL) - db_freedata(uprec->r_dp); - uprec->r_dp = NULL; + db_detach(&uprec->r_dp); res_freeupdrec(uprec); } memput(dl, sizeof *dl); @@ -174,7 +179,7 @@ ixfr_get_change_list(struct zoneinfo *zp, UNLINK(dl->d_changes, uprec, r_link); if (uprec->r_dp != NULL) - db_freedata(uprec->r_dp); + db_detach(&uprec->r_dp); uprec->r_dp = NULL; res_freeupdrec(uprec); } @@ -373,8 +378,9 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, char data[MAXDATA], dnbuf[MAXDNAME], sclass[3]; char *dname, *cp, *cp1; char buf[MAXDATA]; - u_int32_t serial, ttl; - u_int32_t current_serial; + long unsigned lutmp; + u_int32_t serial = 0, ttl; + u_int32_t current_serial = 0; int nonempty_lineno = -1, prev_pktdone = 0, cont = 0, inside_next = 0; int id; @@ -384,7 +390,6 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, enum transport transport; struct map *mp; int zonelist[MAXDNAME]; - struct databuf *dp; struct in_addr ina; int datasize; ns_updrec * rrecp; @@ -395,7 +400,19 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, err = 0; transport = primary_trans; lineno = 1; + zonenum = 0; + + /* + * Look for serial if "first" call othewise use new_serial to + * for current_serial. + */ + if (*old_serial == *new_serial && *old_serial == 0) + current_serial = 0; + else + current_serial = *new_serial; + for (;;) { + dname = NULL; if (!getword(buf, sizeof buf, fp, 0)) { if (lineno == (nonempty_lineno + 1) && !(feof(fp))) { /* @@ -475,13 +492,15 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, class = zp->z_class; n = 0; data[0] = '\0'; + opcode = -1; switch (section) { case S_ZONE: cp = fgets(buf, sizeof buf, fp); if (!cp) *buf = '\0'; n = sscanf(cp, "origin %s class %s serial %lu", - origin, sclass, &serial); + origin, sclass, &lutmp); + serial = lutmp; if (current_serial == 0) current_serial = serial; else if (current_serial != serial) { @@ -501,8 +520,7 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, dname = origin; type = T_SOA; - class = sym_ston(__p_class_syms, sclass, - &success); + class = res_nametoclass(sclass, &success); if (!success) { err++; break; @@ -522,7 +540,6 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, err++; break; } - opcode = -1; if (buf[0] == '{') { n = strlen(buf); for (i = 0; (u_int32_t) i < n; i++) @@ -567,8 +584,7 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, int success; int maybe_class; - maybe_class = sym_ston(__p_class_syms, - buf, &success); + maybe_class = res_nametoclass(buf, &success); if (success) { class = maybe_class; (void) getword(buf, sizeof buf, fp, 1); @@ -579,8 +595,7 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, int success; int maybe_type; - maybe_type = sym_ston(__p_type_syms, - buf, &success); + maybe_type = res_nametotype(buf, &success); if (success) { type = maybe_type; @@ -817,7 +832,7 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, case ns_t_nxt: case ns_t_key: case ns_t_cert:{ - char *errmsg = NULL; + const char *errmsg = NULL; n = parse_sec_rdata(buf, sizeof(buf), 1, (u_char *) data, @@ -833,7 +848,38 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, break; } default: - err++; + if (strcmp(buf, "\\#") != 0) { + err++; + break; + } + if (!getword(buf, sizeof buf, fp, 0) || + !isdigit((unsigned char)buf[0])) { + err++; + break; + } + n = strtoul(buf, &cp, 10); + if (n > 0xffff || *cp != '\0') { + err++; + break; + } + multiline = 0; + i = isc_gethexstring((u_char *)data, + sizeof(data), n, fp, + &multiline); + if (i == -1) { + err++; + break; + } + if (multiline) { + c = getnonblank(fp, zp->z_updatelog, 1); + if (c != ')') { + ungetc(c, fp); + err++; + break; + } + multiline = 0; + } + endline(fp); } if (section == S_PREREQ) { ttl = 0; @@ -880,6 +926,7 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, } rrecp = res_mkupdrec(section, dname, class, type, ttl); if (section != S_ZONE) { + struct databuf *dp; dp = savedata(class, type, ttl, (u_char *) data, n); dp->d_zone = zonenum; dp->d_cred = DB_C_ZONE; @@ -904,13 +951,13 @@ ixfr_getdelta(struct zoneinfo *zp, FILE *fp, const char *filename, char *origin, opcode == ADD) || (opcode == DELETE && arp->r_opcode == ADD)) && - arp->r_dp->d_type == dp->d_type && - arp->r_dp->d_class == dp->d_class && - arp->r_dp->d_ttl == dp->d_ttl && + arp->r_dp->d_type == rrecp->r_dp->d_type && + arp->r_dp->d_class == rrecp->r_dp->d_class && + arp->r_dp->d_ttl == rrecp->r_dp->d_ttl && ns_samename(arp->r_dname, dname) == 1 && - db_cmp(arp->r_dp, dp) == 0) { - db_freedata(dp); - db_freedata(arp->r_dp); + db_cmp(arp->r_dp, rrecp->r_dp) == 0) { + db_detach(&rrecp->r_dp); + db_detach(&arp->r_dp); UNLINK(*listuprec, arp, r_link); res_freeupdrec(arp); res_freeupdrec(rrecp); diff --git a/contrib/bind/bin/named/db_load.c b/contrib/bind/bin/named/db_load.c index 87bdaedbaaff..12d01979ceff 100644 --- a/contrib/bind/bin/named/db_load.c +++ b/contrib/bind/bin/named/db_load.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_load.c 4.38 (Berkeley) 3/2/91"; -static const char rcsid[] = "$Id: db_load.c,v 8.113.2.1 2001/05/03 03:26:48 marka Exp $"; +static const char rcsid[] = "$Id: db_load.c,v 8.121 2001/11/12 21:22:22 marka Exp $"; #endif /* not lint */ /* @@ -130,6 +130,7 @@ static const char rcsid[] = "$Id: db_load.c,v 8.113.2.1 2001/05/03 03:26:48 mark #include #include #include +#include #include "port_after.h" @@ -149,15 +150,16 @@ static int get_nxt_types(u_char *, FILE *, const char *); static int parse_sig_rr(char *, int, u_char *, int, FILE *, struct zoneinfo *, char *, u_int32_t , - enum context , enum transport , char **); + enum context, enum transport, + const char **); static int parse_key_rr(char *, int, u_char *, int, FILE *, - struct zoneinfo *, char *, enum context, - enum transport, char **); + const char **); -static int parse_cert_rr(char *, int, u_char *, int, FILE *, char **); -static int parse_nxt_rr(char *, int, u_char *, int, FILE *, +static int parse_cert_rr(char *, int, u_char *, int, FILE *, + const char **); +static int parse_nxt_rr(char *, u_char *, int, FILE *, struct zoneinfo *, char *, enum context, - enum transport, char **); + enum transport, const char **); static int wordtouint32_error = 0; @@ -237,7 +239,7 @@ db_load(const char *filename, const char *in_origin, char buf[MAXDATA]; char genlhs[MAXDNAME], genrhs[MAXDNAME]; u_char data[MAXDATA]; - int data_size = sizeof(data); + unsigned int data_size = sizeof(data); int c, someclass, class, type, dbflags, dataflags, multiline = 0; int slineno, i, errs, didinclude, ininclude, escape, success; u_int32_t ttl, n, serial; @@ -404,7 +406,7 @@ db_load(const char *filename, const char *in_origin, ERRTOZ("$GENERATE missing LHS"); if (!getword(buf, sizeof(buf), fp, 0)) ERRTOZ("GENERATE missing TYPE"); - type = sym_ston(__p_type_syms, buf, &success); + type = res_nametotype(buf, &success); if (success == 0 || type == ns_t_any) { ns_info(ns_log_load, "%s: Line %d: $GENERATE unknown type: %s.", @@ -509,9 +511,10 @@ db_load(const char *filename, const char *in_origin, empty_from, &rrcount, lineno, filename); if (c != OK) { - if (c == CNAMEANDOTHER) + if (c == CNAMEANDOTHER || c == NONGLUE) errs++; } + db_detach(&dp); } endline(fp); continue; @@ -578,7 +581,7 @@ db_load(const char *filename, const char *in_origin, } /* Parse class (IN, etc) */ - someclass = sym_ston(__p_class_syms, buf, &success); + someclass = res_nametoclass(buf, &success); if (success && someclass != zp->z_class) { ns_info(ns_log_load, "%s: Line %d: wrong class: %s.", @@ -593,7 +596,7 @@ db_load(const char *filename, const char *in_origin, } /* Parse RR type (A, MX, etc) */ - type = sym_ston(__p_type_syms, buf, &success); + type = res_nametotype(buf, &success); if (success == 0 || type == ns_t_any) { ns_info(ns_log_load, "%s: Line %d: Unknown type: %s.", @@ -635,8 +638,52 @@ db_load(const char *filename, const char *in_origin, case ns_t_ptr: escape = 1; break; - default: + case ns_t_a: + case ns_t_md: + case ns_t_mf: + case ns_t_null: + case ns_t_hinfo: + case ns_t_mx: + case ns_t_txt: + case ns_t_afsdb: + case ns_t_x25: + case ns_t_isdn: + case ns_t_rt: + case ns_t_nsap: + case ns_t_nsap_ptr: + case ns_t_px: + case ns_t_gpos: + case ns_t_aaaa: + case ns_t_loc: + case ns_t_eid: + case ns_t_nimloc: + case ns_t_srv: + case ns_t_atma: + case ns_t_naptr: + case ns_t_kx: + case ns_t_dname: + case ns_t_sink: escape = 0; + break; + case ns_t_opt: + case ns_t_tkey: + case ns_t_tsig: + case ns_t_ixfr: + case ns_t_axfr: + case ns_t_mailb: + case ns_t_maila: + case ns_t_any: + case ns_t_zxfr: + escape = 0; + ns_info(ns_log_load, + "%s: Line %d: meta type: %s.", + filename, lineno, p_type(type)); + errs++; + break; + case ns_t_a6: /* not implemented */ + default: + escape = 1; + break; } if (!getword(buf, sizeof buf, fp, escape)) break; @@ -710,7 +757,8 @@ db_load(const char *filename, const char *in_origin, ns_notice(ns_log_load, "%s:%d: WARNING: new serial number < old (%lu < %lu)", filename , lineno, - zp->z_serial, serial); + (unsigned long)zp->z_serial, + (unsigned long)serial); } if (getttl(fp, filename, lineno, &n, &multiline) <= 0) { @@ -1004,7 +1052,7 @@ db_load(const char *filename, const char *in_origin, case ns_t_key: case ns_t_cert: case ns_t_sig: { - char *errmsg = NULL; + const char *errmsg = NULL; int ret; if (ttl == USE_MINIMUM) /* no ttl set */ ttl = 0; @@ -1043,9 +1091,28 @@ db_load(const char *filename, const char *in_origin, endline(fp); break; - default: - goto err; + if (strcmp(buf, "\\#") != 0) + goto err; + if (!getword(buf, sizeof buf, fp, 0) || + !isdigit((unsigned char)buf[0])) + ERRTO("opaque length"); + n = strtoul(buf, &cp, 10); + if (n > 0xffff || *cp != '\0') + ERRTO("opaque length"); + multiline = 0; + i = isc_gethexstring(data, sizeof(data), n, fp, + &multiline); + if (i == -1) + ERRTO("opaque data read failed"); + if (multiline) { + buf[0] = getnonblank(fp, filename, 1); + buf[1] = '\0'; + if (buf[0] != ')') + ERRTO("\")\" expected"); + multiline = 0; + } + endline(fp); } /* * Ignore data outside the zone. @@ -1072,8 +1139,9 @@ db_load(const char *filename, const char *in_origin, &fcachetab : &hashtab, empty_from, &rrcount, lineno, filename); - if (c == CNAMEANDOTHER) + if (c == CNAMEANDOTHER || c == NONGLUE) errs++; + db_detach(&dp); continue; case ERRTOK: @@ -1091,7 +1159,7 @@ db_load(const char *filename, const char *in_origin, (dataflags & DB_F_HINT) ? &fcachetab : &hashtab, empty_from, &rrcount, lineno, filename); if (c != OK) { - if (c == CNAMEANDOTHER) + if (c == CNAMEANDOTHER || c == NONGLUE) errs++; } @@ -1130,7 +1198,7 @@ db_load(const char *filename, const char *in_origin, while (filenames) { fn = filenames; filenames = filenames->next; - freestr(fn->name); + fn->name = freestr(fn->name); memput(fn, sizeof *fn); } if (errs != 0) { @@ -1155,7 +1223,8 @@ db_load(const char *filename, const char *in_origin, zp->z_ftime = 0; } #ifdef BIND_NOTIFY - if (errs == 0 && (!ininclude) && + if (errs == 0 && (!ininclude) && (initial_configuration == 0 || + !NS_OPTION_P(OPTION_SUPNOTIFY_INITIAL)) && (zp->z_type == z_master || zp->z_type == z_slave)) ns_notify(zp->z_origin, zp->z_class, ns_t_soa); #endif @@ -1332,6 +1401,7 @@ getword(char *buf, size_t size, FILE *fp, int preserve) { if (preserve == 1) break; case '\\': + case '#': case '.': case '0': case '1': @@ -1994,7 +2064,7 @@ get_nxt_types(u_char *data, FILE *fp, const char *filename) { continue; /* Parse RR type (A, MX, etc) */ - type = sym_ston(__p_type_syms, (char *)b, &success); + type = res_nametotype((char *)b, &success); if ((!success) || type == ns_t_any) { errs++; ns_info(ns_log_db, @@ -2064,7 +2134,8 @@ fixup_soa(const char *fn, struct zoneinfo *zp) { static int parse_sig_rr(char *buf, int buf_len, u_char *data, int data_size, FILE *fp, struct zoneinfo *zp, char *domain, u_int32_t ttl, - enum context domain_ctx, enum transport transport, char **errmsg) + enum context domain_ctx, enum transport transport, + const char **errmsg) { /* The SIG record looks like this in the db file: Name Cl SIG RRtype Algid [OTTL] Texp Tsig Kfoot Signer Sig @@ -2097,7 +2168,7 @@ parse_sig_rr(char *buf, int buf_len, u_char *data, int data_size, u_int32_t origTTL; enum context context; time_t now; - char *errtype = "SIG error"; + const char *errtype = "SIG error"; int i, my_buf_size = MAXDATA, errs = 0; @@ -2122,7 +2193,7 @@ parse_sig_rr(char *buf, int buf_len, u_char *data, int data_size, if (buf && buf_len == 0) if (!getmlword((char*)buf, my_buf_size, fp, 0)) ERRTO("SIG record doesn't specify type"); - sig_type = sym_ston(__p_type_syms, buf, &success); + sig_type = res_nametotype(buf, &success); if (!success || sig_type == ns_t_any) { /* * We'll also accept a numeric RR type, @@ -2324,9 +2395,9 @@ parse_sig_rr(char *buf, int buf_len, u_char *data, int data_size, } static int -parse_nxt_rr(char *buf, int buf_len, u_char *data, int data_size, - FILE *fp, struct zoneinfo *zp, char *domain, enum context context, - enum transport transport, char **errmsg) +parse_nxt_rr(char *buf, u_char *data, int data_size, FILE *fp, + struct zoneinfo *zp, char *domain, enum context context, + enum transport transport, const char **errmsg) { /* The NXT record looks like: @@ -2364,7 +2435,7 @@ parse_nxt_rr(char *buf, int buf_len, u_char *data, int data_size, static int parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, - FILE *fp, char **errmsg) + FILE *fp, const char **errmsg) { /* Cert record looks like: * Type Key_tag Alg Cert @@ -2375,7 +2446,7 @@ parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, */ u_char *cp; u_int32_t cert_type, key_tag, alg; - char *errtype = "CERT parse error"; + const char *errtype = "CERT parse error"; int certlen, i, n, success; i = 0; @@ -2386,6 +2457,8 @@ parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, if (wordtouint32_error || cert_type > 0xFFFF) ERRTO("CERT type out of range"); } + if (i + INT16SZ > data_size) + ERRTO("CERT no space"); PUTSHORT((u_int16_t)cert_type, cp); i += INT16SZ; @@ -2396,6 +2469,8 @@ parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, if (wordtouint32_error || key_tag > 0xFFFF) ERRTO("CERT KEY tag out of range"); + if (i + INT16SZ > data_size) + ERRTO("CERT no space"); PUTSHORT((u_int16_t)key_tag, cp); i += INT16SZ; @@ -2408,7 +2483,8 @@ parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, if (wordtouint32_error || alg > 0xFF) ERRTO("CERT KEY alg out of range"); } - + if (i + 1 > data_size) + ERRTO("CERT no space"); data[i++] = (u_char)alg; if (!getallwords(buf, buf_len, fp, 0)) { @@ -2431,8 +2507,7 @@ parse_cert_rr(char *buf, int buf_len, u_char *data, int data_size, static int parse_key_rr(char *buf, int buf_len, u_char *data, int data_size, - FILE *fp, struct zoneinfo *zp, char *domain, enum context context, - enum transport transport, char **errmsg) + FILE *fp, const char **errmsg) { /* The KEY record looks like this in the db file: * Name Cl KEY Flags Proto Algid PublicKeyData @@ -2449,7 +2524,7 @@ parse_key_rr(char *buf, int buf_len, u_char *data, int data_size, u_int32_t al, pr; int nk, klen,i, n; u_int32_t keyflags; - char *errtype = "KEY error"; + const char *errtype = "KEY error"; u_char *cp, *expstart; u_int expbytes, modbytes; @@ -2636,7 +2711,7 @@ int parse_sec_rdata(char *buf, int buf_len, int buf_full, u_char *data, int data_size, FILE *fp, struct zoneinfo *zp, char *domain, u_int32_t ttl, int type, enum context context, - enum transport transport, char **errmsg) + enum transport transport, const char **errmsg) { int ret = -1; @@ -2653,11 +2728,10 @@ parse_sec_rdata(char *buf, int buf_len, int buf_full, u_char *data, domain, ttl, context, transport, errmsg); break; case ns_t_key: - ret = parse_key_rr(buf, buf_len, data, data_size, fp, zp, - domain, context, transport, errmsg); + ret = parse_key_rr(buf, buf_len, data, data_size, fp, errmsg); break; case ns_t_nxt: - ret = parse_nxt_rr(buf, buf_len, data, data_size, fp, zp, + ret = parse_nxt_rr(buf, data, data_size, fp, zp, domain, context, transport, errmsg); break; case ns_t_cert: @@ -2673,4 +2747,3 @@ parse_sec_rdata(char *buf, int buf_len, int buf_full, u_char *data, endline(fp); return (ret); } - diff --git a/contrib/bind/bin/named/db_lookup.c b/contrib/bind/bin/named/db_lookup.c index 00b3d8db4eab..77089dabcf60 100644 --- a/contrib/bind/bin/named/db_lookup.c +++ b/contrib/bind/bin/named/db_lookup.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_lookup.c 4.18 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: db_lookup.c,v 8.26 2000/04/21 06:54:03 vixie Exp $"; +static const char rcsid[] = "$Id: db_lookup.c,v 8.27 2001/06/18 14:42:55 marka Exp $"; #endif /* not lint */ /* @@ -258,7 +258,7 @@ match(struct databuf *dp, int class, int type) { return (0); if (dp->d_type != type && dp->d_type != T_SIG && type != T_ANY) return (0); - if (type != T_SIG && dp->d_type == T_SIG && SIG_COVERS(dp) != type) + if (type != T_SIG && dp->d_type == T_SIG && (int)SIG_COVERS(dp) != type) return (0); return (1); } diff --git a/contrib/bind/bin/named/db_save.c b/contrib/bind/bin/named/db_save.c index 2c8833c97943..2153e04a327a 100644 --- a/contrib/bind/bin/named/db_save.c +++ b/contrib/bind/bin/named/db_save.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_save.c 4.16 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: db_save.c,v 8.28 2000/11/29 06:55:48 marka Exp $"; +static const char rcsid[] = "$Id: db_save.c,v 8.29 2001/04/25 13:53:09 marka Exp $"; #endif /* not lint */ /* @@ -158,6 +158,10 @@ savedata(class, type, ttl, data, size) dp->d_rcode = NOERROR; dp->d_addr.s_addr = htonl(0); dp->d_nstime = 0; + dp->d_rcnt = 1; +#ifdef CHECK_MAGIC + dp->d_magic = DATABUF_MAGIC; +#endif memcpy(dp->d_data, data, dp->d_size); return (dp); } diff --git a/contrib/bind/bin/named/db_sec.c b/contrib/bind/bin/named/db_sec.c index 9fb24fb846e3..2d3425dbf4a8 100644 --- a/contrib/bind/bin/named/db_sec.c +++ b/contrib/bind/bin/named/db_sec.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: db_sec.c,v 8.32 2000/12/23 08:14:36 vixie Exp $"; +static const char rcsid[] = "$Id: db_sec.c,v 8.35 2001/06/18 14:42:57 marka Exp $"; #endif /* not lint */ /* @@ -139,7 +139,7 @@ static struct zpubkey * tree_srch_pubkey (const char *name) { struct zpubkey tkey, *key; - tkey.zpk_name = (char *) name; + DE_CONST(name, tkey.zpk_name); if (trusted_keys == NULL) { tree_init(&trusted_keys); return (NULL); @@ -270,7 +270,7 @@ convert_databuf(struct databuf *dp, struct converted_databuf *cdp) { case ns_t_soa: case ns_t_minfo: case ns_t_rp: - if (eob - bp < strlen((char *)cp) + 1) + if (eob - bp < (int)strlen((char *)cp) + 1) return (-1); if (ns_name_pton((char *)cp, buf, sizeof buf) < 0) return (-1); @@ -280,7 +280,7 @@ convert_databuf(struct databuf *dp, struct converted_databuf *cdp) { bp += len; cp += strlen((char *)cp) + 1; - if (eob - bp < strlen((char *)cp) + 1) + if (eob - bp < (int)strlen((char *)cp) + 1) return (-1); if (ns_name_pton((char *)cp, buf, sizeof buf) < 0) return (-1); @@ -307,7 +307,7 @@ convert_databuf(struct databuf *dp, struct converted_databuf *cdp) { case ns_t_mr: case ns_t_ptr: case ns_t_nxt: - if (eob - bp < strlen((char *)cp) + 1) + if (eob - bp < (int)strlen((char *)cp) + 1) return (-1); if (ns_name_pton((char *)cp, buf, sizeof buf) < 0) return (-1); @@ -343,7 +343,7 @@ convert_databuf(struct databuf *dp, struct converted_databuf *cdp) { bp += INT16SZ; cp += INT16SZ; - if (eob - bp < strlen((char *)cp) + 1) + if (eob - bp < (int)strlen((char *)cp) + 1) return (-1); if (ns_name_pton((char *)cp, buf, sizeof buf) < 0) return (-1); @@ -354,7 +354,7 @@ convert_databuf(struct databuf *dp, struct converted_databuf *cdp) { cp += strlen((char *)cp) + 1; if (dp->d_type == ns_t_px) { - if (eob - bp < strlen((char *)cp) + 1) + if (eob - bp < (int)strlen((char *)cp) + 1) return (-1); if (ns_name_pton((char *)cp, buf, sizeof buf) < 0) return (-1); @@ -473,7 +473,7 @@ rrset_trim_sigs(struct db_rrset *rrset) { } } -int +static int verify_set(struct db_rrset *rrset) { DST_KEY *key = NULL; struct sig_record *sigdata; @@ -527,13 +527,13 @@ verify_set(struct db_rrset *rrset) { * Don't verify a set if the SIG inception time is in * the future. This should be fixed before 2038 (BEW) */ - if (ntohl(sigdata->sig_time_n) > now) + if ((time_t)ntohl(sigdata->sig_time_n) > now) continue; /* An expired set is dropped, but the data is not. */ - if (ntohl(sigdata->sig_exp_n) < now) { - db_freedata(sigdp); - sigdn->dp = NULL; + if ((time_t)ntohl(sigdata->sig_exp_n) < now) { + db_detach(&sigdn->dp); + sigdp = NULL; continue; } @@ -715,8 +715,8 @@ verify_set(struct db_rrset *rrset) { if (ret < 0) { dnssec_failed++; - db_freedata(sigdp); - sigdn->dp = NULL; + db_detach(&sigdn->dp); + sigdp = NULL; } else dnssec_succeeded++; @@ -746,40 +746,27 @@ end: } static void -rrset_free_partial(struct db_rrset *rrset, int free_data, struct dnode *start) { +rrset_free(struct db_rrset *rrset) { struct dnode *dnp; - int found_start = 0; ns_debug(ns_log_default, 5, "rrset_free(%s)", rrset->rr_name); - if (start == NULL) - found_start = 1; - while (rrset->rr_list) { dnp = rrset->rr_list; - if (dnp == start) - found_start = 1; rrset->rr_list = rrset->rr_list->dn_next; - if (dnp->dp != NULL && free_data == 1 && found_start == 1) - db_freedata(dnp->dp); + if (dnp->dp != NULL) + db_detach(&dnp->dp); memput(dnp, sizeof(struct dnode)); } while (rrset->rr_sigs) { dnp = rrset->rr_sigs; - if (dnp == start) - found_start = 1; rrset->rr_sigs = rrset->rr_sigs->dn_next; - if (dnp->dp != NULL && free_data == 1 && found_start == 1) - db_freedata(dnp->dp); + if (dnp->dp != NULL) + db_detach(&dnp->dp); memput(dnp, sizeof(struct dnode)); } } -static void -rrset_free(struct db_rrset *rrset, int free_data) { - rrset_free_partial(rrset, free_data, NULL); -} - /* * This is called when we have an rrset with SIGs and no other data. * Returns 1 if we either found the necessary data or if the SIG can be added @@ -838,7 +825,6 @@ rrset_db_update(struct db_rrset *rrset, int flags, struct hashbuf **htpp, struct sockaddr_in from, int *rrcount) { struct dnode *dnp; - struct databuf *dp; int ret; /* If we have any unattached SIG records that are DNSSEC signatures, @@ -848,57 +834,51 @@ rrset_db_update(struct db_rrset *rrset, int flags, struct hashbuf **htpp, */ if (rrset->rr_list == NULL) { if (attach_data(rrset) == 0) { - rrset_free(rrset, 1); + rrset_free(rrset); return (OK); } if (rrset->rr_list != NULL && verify_set(rrset) == DB_S_FAILED) { - rrset_free(rrset, 1); + rrset_free(rrset); return (OK); } } for (dnp = rrset->rr_list; dnp != NULL; dnp = dnp->dn_next) { - dp = dnp->dp; - ret = db_update(rrset->rr_name, dp, dp, NULL, + ret = db_update(rrset->rr_name, dnp->dp, dnp->dp, NULL, flags, (*htpp), from); if (ret != OK) { /* XXX Probably should do rollback. */ - db_err(ret, rrset->rr_name, dp->d_type, + db_err(ret, rrset->rr_name, dnp->dp->d_type, dnp->file, dnp->line); if (ret != DATAEXISTS) { - rrset_free_partial(rrset, 1, dnp); + rrset_free(rrset); return (ret); } - db_freedata(dp); } if (rrcount != NULL) (*rrcount)++; - dnp->dp = NULL; } for (dnp = rrset->rr_sigs; dnp != NULL; dnp = dnp->dn_next) { - dp = dnp->dp; - if (dp == NULL) /* verifyset() can remove sigs */ + if (dnp->dp == NULL) /* verifyset() can remove sigs */ continue; - ret = db_update(rrset->rr_name, dp, dp, NULL, + ret = db_update(rrset->rr_name, dnp->dp, dnp->dp, NULL, flags, (*htpp), from); if (ret != OK) { /* XXX Probably should do rollback. */ - db_err(ret, rrset->rr_name, dp->d_type, + db_err(ret, rrset->rr_name, dnp->dp->d_type, dnp->file, dnp->line); if (ret != DATAEXISTS) { - rrset_free_partial(rrset, 1, dnp); + rrset_free(rrset); return (ret); } - db_freedata(dp); } if (rrcount != NULL) (*rrcount)++; - dnp->dp = NULL; } - rrset_free(rrset, 0); + rrset_free(rrset); return (OK); } @@ -927,7 +907,7 @@ add_to_rrset_list(struct db_rrset **rrsets, char *name, struct databuf *dp, while (rrset != NULL) { if (rrset->rr_type != ns_t_nxt || dp->d_type != ns_t_nxt) { if (dp->d_type == ns_t_sig) { - if (SIG_COVERS(dp) == rrset->rr_type) + if ((int)SIG_COVERS(dp) == rrset->rr_type) break; } else { if (dp->d_type == rrset->rr_type) @@ -942,10 +922,7 @@ add_to_rrset_list(struct db_rrset **rrsets, char *name, struct databuf *dp, if (rrset != NULL) { if ((dp->d_type == ns_t_sig && rr_in_set(dp, rrset->rr_sigs)) || (dp->d_type != ns_t_sig && rr_in_set(dp, rrset->rr_list))) - { - db_freedata(dp); return (DATAEXISTS); - } } else { rrset = (struct db_rrset *) memget(sizeof(struct db_rrset)); if (rrset == NULL) @@ -968,6 +945,7 @@ add_to_rrset_list(struct db_rrset **rrsets, char *name, struct databuf *dp, "add_to_rrset_list: memget failed(%s)", name); memset(dnp, 0, sizeof(struct dnode)); dnp->dp = dp; + DRCNTINC(dnp->dp); if (dp->d_type == ns_t_sig) { if (rrset->rr_sigs != NULL) { struct dnode *fdnp; @@ -995,7 +973,7 @@ add_to_rrset_list(struct db_rrset **rrsets, char *name, struct databuf *dp, } else rrset->rr_list = dnp; } - dnp->file = (char *) file; + dnp->file = file; dnp->line = line; return (0); } @@ -1035,10 +1013,10 @@ update_rrset_list(struct db_rrset **rrsets, int flags, struct hashbuf **htpp, result = tresult; } else { - rrset_free(rrset, 1); + rrset_free(rrset); result = DNSSECFAIL; } - freestr(rrset->rr_name); + rrset->rr_name = freestr(rrset->rr_name); next = rrset->rr_next; memput(rrset, sizeof(struct db_rrset)); rrset = next; diff --git a/contrib/bind/bin/named/db_tsig.c b/contrib/bind/bin/named/db_tsig.c index e8e81f970352..5f7b670e56f5 100644 --- a/contrib/bind/bin/named/db_tsig.c +++ b/contrib/bind/bin/named/db_tsig.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: db_tsig.c,v 8.6 2000/04/21 06:54:04 vixie Exp $"; +static const char rcsid[] = "$Id: db_tsig.c,v 8.7 2001/06/18 14:42:59 marka Exp $"; #endif /* not lint */ /* @@ -110,7 +110,7 @@ typedef struct { #define TSIG_ALG_MD5 "HMAC-MD5.SIG-ALG.REG.INT" #define TSIG_ALG_MD5_SHORT "hmac-md5" -char * +const char * tsig_alg_name(int value) { if (value == KEY_HMAC_MD5) return(TSIG_ALG_MD5); diff --git a/contrib/bind/bin/named/db_update.c b/contrib/bind/bin/named/db_update.c index d742fe927e4f..494a0de67a46 100644 --- a/contrib/bind/bin/named/db_update.c +++ b/contrib/bind/bin/named/db_update.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)db_update.c 4.28 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: db_update.c,v 8.46 2001/02/08 02:05:51 marka Exp $"; +static const char rcsid[] = "$Id: db_update.c,v 8.50 2001/10/24 23:53:09 marka Exp $"; #endif /* not lint */ /* @@ -117,7 +117,7 @@ isRefByNS(const char *name, struct hashbuf *htp) { dp->d_class == C_HS) && dp->d_type == T_NS && !dp->d_rcode && - ns_samename(name, (char *)dp->d_data) == 1) { + ns_samename(name, (const char *)dp->d_data) == 1) { return (1); } } @@ -227,7 +227,7 @@ db_update(const char *name, struct databuf *tmpdp; #endif - ns_debug(ns_log_db, 3, "db_update(%s, %#x, %#x, %#x, 0%o, %#x)%s", + ns_debug(ns_log_db, 3, "db_update(%s, %p, %p, %p, 0%o, %p)%s", name, odp, newdp, savedpp, flags, htp, (odp && (odp->d_flags&DB_F_HINT)) ? " hint" : ""); np = nlookup(name, &htp, &fname, newdp != NULL); @@ -267,9 +267,21 @@ db_update(const char *name, if (newdp && zn && !(flags & DB_NOTAUTH)) { if (nlabels(zones[zn].z_origin) > newdp->d_clev) { - ns_debug(ns_log_db, 5, - "attempted update child zone %s, %s", - zones[zn].z_origin, name); + if ((!ISVALIDGLUE(newdp) && + zones[newdp->d_zone].z_type == Z_PRIMARY) || + (newdp->d_type == T_NS && + !ns_samename(name, zones[zn].z_origin))) { + ns_info(ns_log_db, + "domain %s %s record in zone %s should be in zone %s", + name, p_type(newdp->d_type), + zones[newdp->d_zone].z_origin, + zones[zn].z_origin); + return (NONGLUE); + } else + ns_debug(ns_log_db, 5, + "attempted update child zone %s, %s %s", + zones[zn].z_origin, name, + p_type(newdp->d_type)); return (AUTH); } } @@ -319,11 +331,10 @@ db_update(const char *name, dp, dp, NULL, (flags|DB_NOHINTS), fcachetab, from) - != OK) { + != OK) ns_debug(ns_log_db, 3, - "db_update: hint %#x freed", dp); - db_freedata(dp); - } + "db_update: hint %p freed", dp); + db_detach(&dp); } if (odp != NULL) { @@ -749,7 +760,7 @@ db_update(const char *name, * response source address here if flags&NOTAUTH. */ fixttl(newdp); - ns_debug(ns_log_db, 3, "db_update: adding%s %#x", + ns_debug(ns_log_db, 3, "db_update: adding%s %p", (newdp->d_flags&DB_F_HINT) ? " hint":"", newdp); if (newdp->d_zone == DB_Z_CACHE && @@ -840,7 +851,8 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { case T_MG: case T_MR: /* Only a domain name */ - if (ns_samename((char *)dp1->d_data, (char *)dp2->d_data) == 1) + if (ns_samename((const char *)dp1->d_data, + (const char *)dp2->d_data) == 1) return (0); else return (1); @@ -852,9 +864,9 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { if (memcmp(dp1->d_data, dp2->d_data, NS_SIG_SIGNER)) return (1); len = NS_SIG_SIGNER + - strlen((char *)dp1->d_data + NS_SIG_SIGNER); - if (ns_samename((char *)dp1->d_data + NS_SIG_SIGNER, - (char *)dp2->d_data + NS_SIG_SIGNER) != 1) + strlen((const char *)dp1->d_data + NS_SIG_SIGNER); + if (ns_samename((const char *)dp1->d_data + NS_SIG_SIGNER, + (const char *)dp2->d_data + NS_SIG_SIGNER) != 1) return (1); return (memcmp(dp1->d_data + len, dp2->d_data + len, @@ -862,9 +874,10 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { case T_NXT: /* First a domain name, then binary data */ - if (ns_samename((char *)dp1->d_data, (char *)dp2->d_data) != 1) + if (ns_samename((const char *)dp1->d_data, + (const char *)dp2->d_data) != 1) return (1); - len = strlen((char *)dp1->d_data)+1; + len = strlen((const char *)dp1->d_data)+1; return (memcmp(dp1->d_data + len, dp2->d_data + len, dp1->d_size - len)); @@ -877,7 +890,7 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { len2 = *cp2; if (len != len2) return (1); - if (strncasecmp((char *)++cp1, (char *)++cp2, len)) + if (strncasecmp((const char *)++cp1, (const char *)++cp2, len)) return (1); cp1 += len; cp2 += len; @@ -885,21 +898,23 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { len2 = *cp2; if (len != len2) return (1); - return (strncasecmp((char *)++cp1, (char *)++cp2, len)); + return (strncasecmp((const char *)++cp1, (const char *)++cp2, + len)); case T_SOA: case T_MINFO: case T_RP: - if (ns_samename((char *)dp1->d_data, (char *)dp2->d_data) != 1) + if (ns_samename((const char *)dp1->d_data, + (const char *)dp2->d_data) != 1) return (1); - cp1 = dp1->d_data + strlen((char *)dp1->d_data) + 1; - cp2 = dp2->d_data + strlen((char *)dp2->d_data) + 1; - if (ns_samename((char *)cp1, (char *)cp2) != 1) + cp1 = dp1->d_data + strlen((const char *)dp1->d_data) + 1; + cp2 = dp2->d_data + strlen((const char *)dp2->d_data) + 1; + if (ns_samename((const char *)cp1, (const char *)cp2) != 1) return (1); if (dp1->d_type != T_SOA) return (0); - cp1 += strlen((char *)cp1) + 1; - cp2 += strlen((char *)cp2) + 1; + cp1 += strlen((const char *)cp1) + 1; + cp2 += strlen((const char *)cp2) + 1; return (memcmp(cp1, cp2, INT32SZ * 5)); case T_NAPTR: { @@ -937,7 +952,7 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { cp1 += t1; cp2 += t2; /* Replacement */ - if (ns_samename((char *)cp1, (char *)cp2) != 1) + if (ns_samename((const char *)cp1, (const char *)cp2) != 1) return (1); /* they all checked out! */ @@ -958,7 +973,7 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { if (*cp1++ != *cp2++ || *cp1++ != *cp2++) /* port */ return (1); } - if (ns_samename((char *)cp1, (char *)cp2) != 1) + if (ns_samename((const char *)cp1, (const char *)cp2) != 1) return (1); return (0); @@ -967,11 +982,11 @@ db_cmp(const struct databuf *dp1, const struct databuf *dp2) { cp2 = dp2->d_data; if (*cp1++ != *cp2++ || *cp1++ != *cp2++) /* cmp prio */ return (1); - if (ns_samename((char *)cp1, (char *)cp2) != 1) + if (ns_samename((const char *)cp1, (const char *)cp2) != 1) return (1); - cp1 += strlen((char *)cp1) + 1; - cp2 += strlen((char *)cp2) + 1; - if (ns_samename((char *)cp1, (char *)cp2) != 1) + cp1 += strlen((const char *)cp1) + 1; + cp2 += strlen((const char *)cp2) + 1; + if (ns_samename((const char *)cp1, (const char *)cp2) != 1) return (1); return (0); diff --git a/contrib/bind/bin/named/named.conf b/contrib/bind/bin/named/named.conf index d423b343df2c..08ef27d82e91 100644 --- a/contrib/bind/bin/named/named.conf +++ b/contrib/bind/bin/named/named.conf @@ -14,6 +14,16 @@ // watch out for ";" -- it's important! +key sample_key { // for TSIG + algorithm hmac-md5; // hmac-md5 is the supported algorithm + secret "abcdefgh"; // base 64 encoded secret +}; + +key key2 { + algorithm hmac-md5; + secret "87654321"; +}; + options { directory "."; // use current directory named-xfer "/usr/libexec/named-xfer"; // _PATH_XFER @@ -42,7 +52,7 @@ options { // notify on a zone-by-zone // basis in the "zone" statement // see (below) - max-serial-queries 4; // number of parallel SOA queries + serial-queries 4; // number of parallel SOA queries // we can have outstanding for master // zone change testing purposes auth-nxdomain yes; // always set AA on NXDOMAIN. @@ -194,7 +204,7 @@ zone "slave.demo.zone" { ixfr-base "slave.demo.zone.ixfr"; // File name for IXFR transaction log file masters { 1.2.3.4; // where to zone transfer from - 5.6.7.8; + 5.6.7.8 key key2; }; transfer-source 10.0.0.53; // fixes multihoming problems check-names warn; @@ -250,16 +260,6 @@ zone "non-default-acl.demo.zone" { }; }; -key sample_key { // for TSIG - algorithm hmac-md5; // hmac-md5 is the supported algorithm - secret "abcdefgh"; // base 64 encoded secret -}; - -key key2 { - algorithm hmac-md5; - secret "87654321"; -}; - acl key_acl { key sample_key; }; // a request signed with sample_key server 1.2.3.4 { diff --git a/contrib/bind/bin/named/named.h b/contrib/bind/bin/named/named.h index 29a79fad28d7..023767c42648 100644 --- a/contrib/bind/bin/named/named.h +++ b/contrib/bind/bin/named/named.h @@ -16,7 +16,7 @@ */ /* - * $Id: named.h,v 8.28 2001/02/12 05:56:15 marka Exp $ + * $Id: named.h,v 8.31 2002/02/01 00:05:38 marka Exp $ */ /* Options. Change them at your peril. */ @@ -28,7 +28,7 @@ #define TRACEROOT #define XFRNETS #define QRYLOG -#define YPKLUDGE +#undef YPKLUDGE #define RENICE #define BIND_IXFR #define BIND_NOTIFY @@ -45,6 +45,8 @@ #define STRICT_RFC2308 #undef BIND_ZXFR #undef LOG_TSIG_BUG +#define NOADDITIONAL +#undef FORWARD_ALLOWS /* enable allow-query for forward zones. */ #include #include diff --git a/contrib/bind/bin/named/ns_config.c b/contrib/bind/bin/named/ns_config.c index c4bca960be14..2d59a6298afd 100644 --- a/contrib/bind/bin/named/ns_config.c +++ b/contrib/bind/bin/named/ns_config.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_config.c,v 8.121 2001/02/08 02:05:53 marka Exp $"; +static const char rcsid[] = "$Id: ns_config.c,v 8.133 2002/02/01 00:05:39 marka Exp $"; #endif /* not lint */ /* @@ -89,7 +89,6 @@ static int default_logging_installed; static int options_installed = 0; static int logging_installed = 0; static int default_options_installed; -static int initial_configuration = 1; static char **logging_categories; static char *current_pid_filename = NULL; @@ -102,7 +101,7 @@ static symbol_table zone_symbol_table; void free_zone_timerinfo(struct zoneinfo *zp) { if (zp->z_timerinfo != NULL) { - freestr(zp->z_timerinfo->name); + zp->z_timerinfo->name = freestr(zp->z_timerinfo->name); memput(zp->z_timerinfo, sizeof *zp->z_timerinfo); zp->z_timerinfo = NULL; } else @@ -125,17 +124,13 @@ free_zone_contents(struct zoneinfo *zp, int undefine_sym) { strerror(errno)); } if (zp->z_origin != NULL) - freestr(zp->z_origin); - zp->z_origin = NULL; + zp->z_origin = freestr(zp->z_origin); if (zp->z_source != NULL) - freestr(zp->z_source); - zp->z_source = NULL; + zp->z_source = freestr(zp->z_source); if (zp->z_ixfr_base != NULL) - freestr(zp->z_ixfr_base); - zp->z_ixfr_base = NULL; + zp->z_ixfr_base = freestr(zp->z_ixfr_base); if (zp->z_ixfr_tmp != NULL) - freestr(zp->z_ixfr_tmp); - zp->z_ixfr_tmp = NULL; + zp->z_ixfr_tmp = freestr(zp->z_ixfr_tmp); if (zp->z_update_acl != NULL) free_ip_match_list(zp->z_update_acl); zp->z_update_acl = NULL; @@ -147,8 +142,7 @@ free_zone_contents(struct zoneinfo *zp, int undefine_sym) { zp->z_transfer_acl = NULL; #ifdef BIND_UPDATE if (zp->z_updatelog != NULL) - freestr(zp->z_updatelog); - zp->z_updatelog = NULL; + zp->z_updatelog = freestr(zp->z_updatelog); #endif /* BIND_UPDATE */ #ifdef BIND_NOTIFY if (zp->z_also_notify != NULL) @@ -156,6 +150,9 @@ free_zone_contents(struct zoneinfo *zp, int undefine_sym) { zp->z_notify_count * sizeof *zp->z_also_notify); zp->z_also_notify = NULL; #endif + if (zp->z_fwdtab != NULL) + free_forwarders(zp->z_fwdtab); + zp->z_fwdtab = NULL; block_signals(); if (LINKED(zp, z_reloadlink)) UNLINK(reloadingzones, zp, z_reloadlink); @@ -189,7 +186,7 @@ find_zone(const char *name, int class) { } static struct zoneinfo * -new_zone(int class, int type) { +new_zone(void) { struct zoneinfo *zp; if (EMPTY(freezones)) @@ -303,9 +300,16 @@ validate_zone(struct zoneinfo *zp) { if (zp->z_query_acl) { if (zp->z_type != z_master && zp->z_type != z_slave && +#ifdef FORWARD_ALLOWS + zp->z_type != z_forward && +#endif zp->z_type != z_stub) { ns_error(ns_log_config, +#ifdef FORWARD_ALLOWS + "'allow-query' option for hint zone '%s'", +#else "'allow-query' option for non-{master,slave,stub} zone '%s'", +#endif zp->z_origin); return (0); } @@ -472,7 +476,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { * any data that was dynamically allocated. */ if (zp->z_origin != NULL) - freestr(zp->z_origin); + (void)freestr(zp->z_origin); zp->z_origin = new_zp->z_origin; new_zp->z_origin = NULL; zp->z_maintain_ixfr_base = new_zp->z_maintain_ixfr_base; @@ -480,8 +484,10 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { zp->z_class = new_zp->z_class; zp->z_type = new_zp->z_type; zp->z_checknames = new_zp->z_checknames; - for (i = 0; i < new_zp->z_addrcnt; i++) + for (i = 0; i < new_zp->z_addrcnt; i++) { zp->z_addr[i] = new_zp->z_addr[i]; + zp->z_keys[i] = new_zp->z_keys[i]; + } zp->z_addrcnt = new_zp->z_addrcnt; if (zp->z_update_acl) free_ip_match_list(zp->z_update_acl); @@ -529,7 +535,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { zp->z_dumpintvl = new_zp->z_dumpintvl; zp->z_deferupdcnt = new_zp->z_deferupdcnt; if (zp->z_updatelog) - freestr(zp->z_updatelog); + (void)freestr(zp->z_updatelog); zp->z_updatelog = new_zp->z_updatelog; new_zp->z_updatelog = NULL; #endif /* BIND_UPDATE */ @@ -554,7 +560,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { /* File has changed, or hasn't been loaded yet. */ if (zp->z_source) { - freestr(zp->z_source); + zp->z_source = freestr(zp->z_source); ns_stopxfrs(zp); purge_zone(zp->z_origin, fcachetab, zp->z_class); } @@ -562,12 +568,12 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { new_zp->z_source = NULL; if (zp->z_ixfr_base) - freestr(zp->z_ixfr_base); + (void)freestr(zp->z_ixfr_base); zp->z_ixfr_base = new_zp->z_ixfr_base; new_zp->z_ixfr_base = NULL; if (zp->z_ixfr_tmp) - freestr(zp->z_ixfr_tmp); + (void)freestr(zp->z_ixfr_tmp); zp->z_ixfr_tmp = new_zp->z_ixfr_tmp; new_zp->z_ixfr_tmp = NULL; @@ -597,17 +603,17 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { primary_reload: #endif /* BIND_UPDATE */ if (zp->z_source != NULL) - freestr(zp->z_source); + (void)freestr(zp->z_source); zp->z_source = new_zp->z_source; new_zp->z_source = NULL; if (zp->z_ixfr_base != NULL) - freestr(zp->z_ixfr_base); + (void)freestr(zp->z_ixfr_base); zp->z_ixfr_base = new_zp->z_ixfr_base; new_zp->z_ixfr_base = NULL; if (zp->z_ixfr_tmp != NULL) - freestr(zp->z_ixfr_tmp); + (void)freestr(zp->z_ixfr_tmp); zp->z_ixfr_tmp = new_zp->z_ixfr_tmp; new_zp->z_ixfr_tmp = NULL; @@ -649,8 +655,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { ((!reconfiging) && zonefile_changed_p(zp)))) { ns_debug(ns_log_config, 1, "backup file changed or missing"); - freestr(zp->z_source); - zp->z_source = NULL; + zp->z_source = freestr(zp->z_source); zp->z_serial = 0; /* force xfer */ ns_stopxfrs(zp); /* @@ -674,7 +679,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { } if (zp->z_ixfr_base != NULL) - freestr(zp->z_ixfr_base); + (void)freestr(zp->z_ixfr_base); zp->z_ixfr_base = new_zp->z_ixfr_base; new_zp->z_ixfr_base = NULL; @@ -727,7 +732,7 @@ update_zone_info(struct zoneinfo *zp, struct zoneinfo *new_zp) { void end_zone(zone_config zh, int should_install) { struct zoneinfo *zp, *new_zp; - char *zname; + const char *zname; symbol_value value; new_zp = zh.opaque; @@ -753,11 +758,11 @@ end_zone(zone_config zh, int should_install) { zp = NULL; } if (zp == NULL) { - zp = new_zone(new_zp->z_class, new_zp->z_type); + zp = new_zone(); INSIST(zp != NULL); value.integer = (zp - zones); - define_symbol(zone_symbol_table, savestr(new_zp->z_origin, 1), - new_zp->z_class, value, SYMBOL_FREE_KEY); + define_symbol(zone_symbol_table, new_zp->z_origin, + new_zp->z_class, value, 0); } ns_debug(ns_log_config, 5, "zone '%s', type = %d, class = %d", zname, new_zp->z_type, new_zp->z_class); @@ -930,7 +935,7 @@ set_zone_query_acl(zone_config zh, ip_match_list iml) { zp = zh.opaque; INSIST(zp != NULL); - /* Fail if checknames already set for this zone */ + /* Fail if allow-query acl already set for this zone */ if (zp->z_query_acl != NULL) return (0); zp->z_query_acl = iml; @@ -960,7 +965,7 @@ set_zone_transfer_acl(zone_config zh, ip_match_list iml) { zp = zh.opaque; INSIST(zp != NULL); - /* Fail if checknames already set for this zone */ + /* Fail if allow-transfer acl already set for this zone */ if (zp->z_transfer_acl != NULL) return (0); zp->z_transfer_acl = iml; @@ -974,7 +979,7 @@ set_zone_transfer_time_in(zone_config zh, long max_time) { zp = zh.opaque; INSIST(zp != NULL); - /* Fail if checknames already set for this zone */ + /* Fail if max-transfer-time-in already set for this zone */ if (zp->z_max_transfer_time_in) return (0); zp->z_max_transfer_time_in = max_time; @@ -1013,13 +1018,14 @@ set_trusted_key(const char *name, const int flags, const int proto, } int -add_zone_master(zone_config zh, struct in_addr address) { +add_zone_master(zone_config zh, struct in_addr address, struct dst_key * key) { struct zoneinfo *zp; zp = zh.opaque; INSIST(zp != NULL); zp->z_addr[zp->z_addrcnt] = address; + zp->z_keys[zp->z_addrcnt] = key; zp->z_addrcnt++; if (zp->z_addrcnt >= NSMAX) { ns_warning(ns_log_config, "NSMAX reached for zone '%s'", @@ -1084,12 +1090,17 @@ add_zone_notify(zone_config zh, struct in_addr address) { options new_options() { options op; + char hostname[256]; op = (options)memget(sizeof (struct options)); if (op == NULL) panic("memget failed in new_options()", NULL); op->version = savestr(ShortVersion, 1); + if (gethostname(hostname, sizeof(hostname)) == 0) + op->hostname = savestr(hostname, 1); + else + op->hostname = NULL; op->directory = savestr(".", 1); op->pid_filename = savestr(_PATH_PIDFILE, 1); op->named_xfer = savestr(_PATH_XFER, 1); @@ -1136,8 +1147,9 @@ new_options() { op->max_host_stats = 0; op->lame_ttl = NTTL; op->heartbeat_interval = 3600; - op->max_log_size_ixfr = 20; + op->max_log_size_ixfr = 0; op->minroots = MINROOTS; + op->preferred_glue = 0; return (op); } @@ -1145,20 +1157,22 @@ void free_options(options op) { INSIST(op != NULL); + if (op->hostname) + op->hostname = freestr(op->hostname); if (op->version) - freestr(op->version); + op->version = freestr(op->version); if (op->directory) - freestr(op->directory); + op->directory = freestr(op->directory); if (op->pid_filename) - freestr(op->pid_filename); + op->pid_filename = freestr(op->pid_filename); if (op->named_xfer) - freestr(op->named_xfer); + op->named_xfer = freestr(op->named_xfer); if (op->dump_filename) - freestr(op->dump_filename); + op->dump_filename = freestr(op->dump_filename); if (op->stats_filename) - freestr(op->stats_filename); + op->stats_filename = freestr(op->stats_filename); if (op->memstats_filename) - freestr(op->memstats_filename); + op->memstats_filename = freestr(op->memstats_filename); #ifdef BIND_NOTIFY if (op->also_notify) free_also_notify(op); @@ -1197,6 +1211,7 @@ set_boolean_option(u_int *op_flags, int bool_opt, int value) { case OPTION_FORWARD_ONLY: case OPTION_FAKE_IQUERY: case OPTION_NONOTIFY: + case OPTION_SUPNOTIFY_INITIAL: case OPTION_NONAUTH_NXDOMAIN: case OPTION_MULTIPLE_CNAMES: case OPTION_USE_IXFR: @@ -1290,7 +1305,7 @@ ns_rlimit(enum limit limit, u_long limit_value) { struct rlimit limits, old_limits; int rlimit = -1; int fdlimit = evHighestFD(ev) + 1; - char *name; + const char *name; rlimit_type value; if (limit_value == ULONG_MAX) { @@ -1337,7 +1352,7 @@ ns_rlimit(enum limit limit, u_long limit_value) { name = "max number of open files"; if (value == 0) limits = initial_num_files; - if (value > fdlimit) + if ((int)value > fdlimit) limits.rlim_cur = limits.rlim_max = value = fdlimit; break; default: @@ -1455,8 +1470,10 @@ write_open(char *filename) { return (NULL); (void) fchown(fd, user_id, group_id); stream = fdopen(fd, "w"); - if (stream == NULL) + if (stream == NULL) { + (void)unlink(filename); (void)close(fd); + } return (stream); } @@ -1470,8 +1487,7 @@ update_pid_file() { /* XXX */ ns_debug(ns_log_default, 1, "update_pid_file()"); if (current_pid_filename != NULL) { (void)unlink(current_pid_filename); - freestr(current_pid_filename); - current_pid_filename = NULL; + current_pid_filename = freestr(current_pid_filename); } current_pid_filename = savestr(server_options->pid_filename, 0); if (current_pid_filename == NULL) { @@ -1521,6 +1537,11 @@ static void periodic_getnetconf(evContext ctx, void *uap, struct timespec due, struct timespec inter) { + UNUSED(ctx); + UNUSED(uap); + UNUSED(due); + UNUSED(inter); + getnetconf(1); } @@ -1709,11 +1730,11 @@ use_default_options() { * rrset order types */ static struct res_sym order_table [] = { - { unknown_order, " unknown " }, /* can't match */ - { fixed_order, "fixed" }, - { cyclic_order, "cyclic" }, - { random_order, "random" }, - { unknown_order, NULL } + { unknown_order, " unknown ", NULL }, /* can't match */ + { fixed_order, "fixed", NULL }, + { cyclic_order, "cyclic", NULL }, + { random_order, "random", NULL }, + { unknown_order, NULL, NULL } }; /* @@ -1759,7 +1780,7 @@ free_rrset_order_list(rrset_order_list rol) { for (roe = rol->first; roe != NULL; roe = next_element) { next_element = roe->next; - freestr(roe->name); + roe->name = freestr(roe->name); memput(roe, sizeof (*roe)); } memput(rol, sizeof (*rol)); @@ -1778,6 +1799,7 @@ add_to_rrset_order_list(rrset_order_list rol, rrset_order_element roe) { rol->first = roe; } +#ifdef notyet /* XXX this isn't being used yet, but it probably should be. Where? */ void dprint_rrset_order_list(int category, rrset_order_list rol, int indent, @@ -1799,7 +1821,7 @@ dprint_rrset_order_list(int category, rrset_order_list rol, int indent, roe->name, p_order(roe->order)); } } - +#endif rrset_order_element new_rrset_order_element(int class, int type, char *name, enum ordering order) @@ -1986,7 +2008,7 @@ add_to_ip_match_list(ip_match_list iml, ip_match_element ime) { void dprint_ip_match_list(int category, ip_match_list iml, int indent, - char *allow, char *deny) { + const char *allow, const char *deny) { ip_match_element ime; char spaces[40+1]; char addr_text[sizeof "255.255.255.255"]; @@ -2083,6 +2105,7 @@ ip_match_addr_or_key(ip_match_list iml, struct in_addr address, continue; } default: + indirect = 0; panic("unexpected ime type in ip_match_addr_or_key()", NULL); } @@ -2278,7 +2301,6 @@ find_forwarder(struct in_addr address) { struct fwddata *fdp; struct fwddata **fdpp = NULL; - struct databuf *ns, *nsdata; register int i; for (i = 0; i < fwddata_count; i++) { @@ -2299,28 +2321,19 @@ find_forwarder(struct in_addr address) if (!fdp) panic("memget failed in find_forwarder", NULL); + memset(&fdp->fwdaddr, 0, sizeof(fdp->fwdaddr)); fdp->fwdaddr.sin_family = AF_INET; fdp->fwdaddr.sin_addr = address; fdp->fwdaddr.sin_port = ns_port; - ns = fdp->ns = (struct databuf *)memget(sizeof(*ns)); - if (!ns) + fdp->ns = savedata(C_IN, T_NS, 0, NULL, 0); + if (!fdp->ns) panic("memget failed in find_forwarder", NULL); - memset(ns, 0, sizeof(*ns)); - nsdata = fdp->nsdata = (struct databuf *)memget(sizeof(*nsdata)); - if (!nsdata) + fdp->nsdata = savedata(C_IN, T_A, 0, NULL, 0); + if (!fdp->nsdata) panic("memget failed in find_forwarder", NULL); - memset(nsdata, 0, sizeof(*nsdata)); - - ns->d_type = T_NS; - ns->d_class = C_IN; - ns->d_rcnt = 1; - - nsdata->d_type = T_A; - nsdata->d_class = C_IN; - nsdata->d_nstime = 1 + (int)(25.0*rand()/(RAND_MAX + 1.0)); - nsdata->d_rcnt = 1; + fdp->nsdata->d_nstime = 1 + (int)(25.0*rand()/(RAND_MAX + 1.0)); fdp->ref_count = 1; @@ -2480,7 +2493,7 @@ set_zone_forward(zone_config zh) { void add_zone_forwarder(zone_config zh, struct in_addr address) { struct zoneinfo *zp; - char *zname; + const char *zname; zp = zh.opaque; INSIST(zp != NULL); @@ -2507,9 +2520,8 @@ free_forwarders(struct fwdinfo *fwdtab) { fwddata[i] = NULL; break; } - memput(ftp->fwddata->ns, sizeof *ftp->fwddata->ns); - memput(ftp->fwddata->nsdata, - sizeof *ftp->fwddata->nsdata); + db_detach(&ftp->fwddata->ns); + db_detach(&ftp->fwddata->nsdata); memput(ftp->fwddata, sizeof *ftp->fwddata); } memput(ftp, sizeof *ftp); @@ -2543,7 +2555,8 @@ new_server(struct in_addr address) { static void free_server(server_info si) { - /* Don't free key; it'll be done when the auth table is freed. */ + if (si->key_list) + free_key_info_list(si->key_list); memput(si, sizeof *si); } @@ -2999,7 +3012,7 @@ use_default_logging() { static void init_default_log_channels() { u_int flags; - char *name; + const char *name; FILE *stream; syslog_channel = log_new_syslog_channel(0, log_info, ISC_FACILITY); @@ -3072,7 +3085,8 @@ shutdown_logging() { log_free_context(log_ctx); for (s = category_constants; s != NULL && s->name != NULL; s++) - freestr(logging_categories[s->number]); + logging_categories[s->number] = + freestr(logging_categories[s->number]); size = ns_log_max_category * (sizeof (char *)); memput(logging_categories, size); logging_categories = NULL; @@ -3108,11 +3122,15 @@ shutdown_configuration() { server_options = NULL; } if (current_pid_filename != NULL) - freestr(current_pid_filename); + current_pid_filename = freestr(current_pid_filename); free_nameserver_info(); free_secretkey_info(); free_symbol_table(zone_symbol_table); parser_shutdown(); + if (fwddata != NULL) + memput(fwddata, fwddata_count * sizeof *fwddata); + fwddata = NULL; + fwddata_count = 0; config_initialized = 0; } diff --git a/contrib/bind/bin/named/ns_ctl.c b/contrib/bind/bin/named/ns_ctl.c index 1950b07fc917..ee77634d6569 100644 --- a/contrib/bind/bin/named/ns_ctl.c +++ b/contrib/bind/bin/named/ns_ctl.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_ctl.c,v 8.39 2000/12/19 23:31:38 marka Exp $"; +static const char rcsid[] = "$Id: ns_ctl.c,v 8.46 2001/12/19 11:53:48 marka Exp $"; #endif /* not lint */ /* @@ -91,55 +91,56 @@ static void propagate_changes(const control, control); static void install(control); static void install_inet(control); static void install_unix(control); -static void logger(enum ctl_severity, const char *fmt, ...); +static void logger(enum ctl_severity, const char *fmt, ...) + ISC_FORMAT_PRINTF(2,3); static void verb_connect(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_getpid(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void getpid_closure(struct ctl_sctx *, struct ctl_sess *, void *); static void verb_status(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void status_closure(struct ctl_sctx *, struct ctl_sess *, void *); static void verb_stop(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_exec(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_reload(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_reconfig(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_dumpdb(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_stats(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_trace(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void trace_closure(struct ctl_sctx *, struct ctl_sess *, void *); static void verb_notrace(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_querylog(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_help(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); static void verb_quit(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, - const char *, u_int, void *, void *); + const char *, u_int, const void *, void *); /* Private data. */ @@ -226,7 +227,7 @@ ns_ctl_new_inet(struct in_addr saddr, u_int sport, ip_match_list allow) { #ifndef NO_SOCKADDR_UN control -ns_ctl_new_unix(char *path, mode_t mode, uid_t owner, gid_t group) { +ns_ctl_new_unix(const char *path, mode_t mode, uid_t owner, gid_t group) { control new = new_control(); INIT_LINK(new, link); @@ -525,11 +526,11 @@ install_unix(control ctl) { if (slash != path) *slash = '\0'; else { - freestr(path); + (void)freestr(path); path = savestr("/", 1); } } else { - freestr(path); + (void)freestr(path); path = savestr(".", 1); } if (mkdir(path, ctl->var.v_unix.mode) < 0) { @@ -567,7 +568,7 @@ install_unix(control ctl) { } } #ifdef NEED_SECURE_DIRECTORY - freestr(path); + (void)freestr(path); #endif } #endif @@ -581,7 +582,8 @@ logger(enum ctl_severity ctlsev, const char *format, ...) { case ctl_debug: logsev = log_debug(5); break; case ctl_warning: logsev = log_warning; break; case ctl_error: logsev = log_error; break; - default: panic("invalid ctlsev in logger", NULL); + default: logsev = 0; + panic("invalid ctlsev in logger", NULL); } if (!log_ctx_valid) return; @@ -593,13 +595,18 @@ logger(enum ctl_severity ctlsev, const char *format, ...) { static void verb_connect(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { - const struct sockaddr *sa = (struct sockaddr *)respctx; + const struct sockaddr *sa = (const struct sockaddr *)respctx; control nsctl = (control)uctx; + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + if (sa->sa_family == AF_INET) { - const struct sockaddr_in *in = (struct sockaddr_in *)sa; + const struct sockaddr_in *in = (const struct sockaddr_in *)sa; const ip_match_list acl = nsctl->var.v_inet.allow; if (!ip_address_allowed(acl, in->sin_addr)) { @@ -615,10 +622,17 @@ verb_connect(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_getpid(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { char *msg = memget(MAX_STR_LEN); + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (msg == NULL) { ctl_response(sess, 503, "(out of memory)", 0, NULL, NULL, NULL, NULL, 0); @@ -632,6 +646,9 @@ static void getpid_closure(struct ctl_sctx *sctx, struct ctl_sess *sess, void *uap) { char *msg = uap; + UNUSED(sctx); + UNUSED(sess); + memput(msg, MAX_STR_LEN); } @@ -656,10 +673,17 @@ struct pvt_status { static void verb_status(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct pvt_status *pvt = ctl_getcsctx(sess); + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (pvt == NULL) { pvt = memget(sizeof *pvt); if (pvt == NULL) { @@ -717,6 +741,9 @@ static void status_closure(struct ctl_sctx *sctx, struct ctl_sess *sess, void *uap) { struct pvt_status *pvt = ctl_getcsctx(sess); + UNUSED(sctx); + UNUSED(uap); + memput(pvt, sizeof *pvt); ctl_setcsctx(sess, NULL); } @@ -724,8 +751,15 @@ status_closure(struct ctl_sctx *sctx, struct ctl_sess *sess, void *uap) { static void verb_stop(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ns_need(main_need_exit); ctl_response(sess, 250, "Shutdown initiated.", 0, NULL, NULL, NULL, NULL, 0); @@ -734,10 +768,16 @@ verb_stop(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_exec(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { struct stat sb; + UNUSED(ctl); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (rest != NULL && *rest != '\0') { if (stat(rest, &sb) < 0) { ctl_response(sess, 503, strerror(errno), @@ -764,14 +804,21 @@ verb_exec(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_reload(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { static const char spaces[] = " \t"; struct zoneinfo *zp; char *tmp = NULL, *x; + const char *cl; const char *msg; int class, code, success; + UNUSED(ctl); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + /* If there are no args, this is a classic reload of the config. */ if (rest == NULL || *rest == '\0') { ns_need(main_need_reload); @@ -787,9 +834,8 @@ verb_reload(struct ctl_sctx *ctl, struct ctl_sess *sess, *x++ = '\0'; x += strspn(x, spaces); } - if (x == NULL || *x == '\0') - x = "in"; - class = sym_ston(__p_class_syms, x, &success); + cl = (x == NULL || *x == '\0') ? "in" : x; + class = res_nametoclass(cl, &success); if (!success) { code = 507; msg = "unrecognized class"; @@ -833,14 +879,20 @@ verb_reload(struct ctl_sctx *ctl, struct ctl_sess *sess, respond: ctl_response(sess, code, msg, 0, NULL, NULL, NULL, NULL, 0); if (tmp != NULL) - freestr(tmp); + (void)freestr(tmp); } static void verb_reconfig(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (strcmp(rest, "-noexpired") != 0) ns_need(main_need_reconfig); else @@ -852,8 +904,15 @@ verb_reconfig(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_dumpdb(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ns_need(main_need_dump); ctl_response(sess, 250, "Database dump initiated.", 0, NULL, NULL, NULL, NULL, 0); @@ -862,8 +921,14 @@ verb_dumpdb(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_stats(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (rest != NULL && strcmp(rest, "clear") == 0) { ns_need(main_need_statsdumpandclear); ctl_response(sess, 250, "Statistics dump and clear initiated.", @@ -878,22 +943,31 @@ verb_stats(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_trace(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { int i = atoi(rest); char *msg = memget(MAX_STR_LEN); + UNUSED(ctl); + UNUSED(verb); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + if (msg == NULL) { ctl_response(sess, 503, "(out of memory)", 0, NULL, NULL, NULL, NULL, 0); return; } - if (i > 0) + if (isdigit(*(const unsigned char *)rest) && i >= 0) desired_debug = i; else desired_debug++; ns_need(main_need_debug); - sprintf(msg, "Debug level: %d", desired_debug); + if (desired_debug == 0) + sprintf(msg, "Debugging turned off."); + else + sprintf(msg, "Debug level: %d", desired_debug); ctl_response(sess, 250, msg, 0, NULL, trace_closure, msg, NULL, 0); } @@ -901,14 +975,24 @@ static void trace_closure(struct ctl_sctx *sctx, struct ctl_sess *sess, void *uap) { char *msg = uap; + UNUSED(sctx); + UNUSED(sess); + memput(msg, MAX_STR_LEN); } static void verb_notrace(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + desired_debug = 0; ns_need(main_need_debug); ctl_response(sess, 250, "Debugging turned off.", @@ -918,11 +1002,18 @@ verb_notrace(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_querylog(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { static const char on[] = "Query logging is now on.", off[] = "Query logging is now off."; + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + toggle_qrylog(); ctl_response(sess, 250, qrylog ? on : off, 0, NULL, NULL, NULL, NULL, 0); @@ -931,16 +1022,30 @@ verb_querylog(struct ctl_sctx *ctl, struct ctl_sess *sess, static void verb_help(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ctl_sendhelp(sess, 214); } static void verb_quit(struct ctl_sctx *ctl, struct ctl_sess *sess, const struct ctl_verb *verb, const char *rest, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { + UNUSED(ctl); + UNUSED(verb); + UNUSED(rest); + UNUSED(respflags); + UNUSED(respctx); + UNUSED(uctx); + ctl_response(sess, 221, "End of control session.", CTL_EXIT, NULL, NULL, NULL, NULL, 0); } diff --git a/contrib/bind/bin/named/ns_defs.h b/contrib/bind/bin/named/ns_defs.h index 64aecce8cdff..86a81b645b13 100644 --- a/contrib/bind/bin/named/ns_defs.h +++ b/contrib/bind/bin/named/ns_defs.h @@ -1,6 +1,6 @@ /* * from ns.h 4.33 (Berkeley) 8/23/90 - * $Id: ns_defs.h,v 8.105 2001/04/01 22:41:24 marka Exp $ + * $Id: ns_defs.h,v 8.115 2002/01/29 03:59:35 marka Exp $ */ /* @@ -147,6 +147,7 @@ #define MAX_SYNCDELAY 3 /* Presumed timeout in use by our clients. */ #define MAX_SYNCDRAIN 100000 /* How long we'll spin in drain_all_rcvbuf. */ #define MAX_SYNCSTORE 500 +#define NS_MAX_DISTANCE 3 /* maximum nameserver chaining before failure */ /* maximum time to cache negative answers */ #define DEFAULT_MAX_NCACHE_TTL (3*60*60) @@ -176,27 +177,30 @@ typedef enum need { } main_need; /* What global options are set? */ -#define OPTION_NORECURSE 0x0001 /* Don't recurse even if asked. */ -#define OPTION_NOFETCHGLUE 0x0002 /* Don't fetch missing glue. */ -#define OPTION_FORWARD_ONLY 0x0004 /* Don't use NS RR's, just forward. */ -#define OPTION_FAKE_IQUERY 0x0008 /* Fake up bogus response to IQUERY. */ +#define OPTION_NORECURSE 0x00000001 /* Don't recurse even if asked. */ +#define OPTION_NOFETCHGLUE 0x00000002 /* Don't fetch missing glue. */ +#define OPTION_FORWARD_ONLY 0x00000004 /* Don't use NS RR's, just forward. */ +#define OPTION_FAKE_IQUERY 0x00000008 /* Fake up bogus response to IQUERY. */ #ifdef BIND_NOTIFY -#define OPTION_NONOTIFY 0x0010 /* Turn off notify */ +#define OPTION_NONOTIFY 0x00000010 /* Turn off notify */ +#define OPTION_SUPNOTIFY_INITIAL 0x00000020 /* Supress initial notify */ #endif -#define OPTION_NONAUTH_NXDOMAIN 0x0020 /* Generate non-auth NXDOMAINs? */ -#define OPTION_MULTIPLE_CNAMES 0x0040 /* Allow a name to have multiple - * CNAME RRs */ -#define OPTION_HOSTSTATS 0x0080 /* Maintain per-host statistics? */ -#define OPTION_DEALLOC_ON_EXIT 0x0100 /* Deallocate everything on exit? */ -#define OPTION_NODIALUP 0x0200 /* Turn off dialup support */ -#define OPTION_NORFC2308_TYPE1 0x0400 /* Prevent type1 respones (RFC 2308) - * to cached negative respones */ -#define OPTION_USE_ID_POOL 0x0800 /* Use the memory hogging query ID */ -#define OPTION_TREAT_CR_AS_SPACE 0x1000 /* Treat CR in zone files as space */ -#define OPTION_USE_IXFR 0x2000 /* Use by delault ixfr in zone transfer */ -#define OPTION_MAINTAIN_IXFR_BASE 0x4000 /* Part of IXFR file name logic. */ -#define OPTION_HITCOUNT 0x8000 /* Keep track of each time an RR gets - * hit in the database */ +#define OPTION_NONAUTH_NXDOMAIN 0x00000040 /* Generate non-auth NXDOMAINs? */ +#define OPTION_MULTIPLE_CNAMES 0x00000080 /* Allow a name to have multiple + * CNAME RRs */ +#define OPTION_HOSTSTATS 0x00000100 /* Maintain per-host statistics? */ +#define OPTION_DEALLOC_ON_EXIT 0x00000200 /* Deallocate everything on exit? */ +#define OPTION_NODIALUP 0x00000400 /* Turn off dialup support */ +#define OPTION_NORFC2308_TYPE1 0x00000800 /* Prevent type1 respones (RFC 2308) + * to cached negative respones */ +#define OPTION_USE_ID_POOL 0x00001000 /* Use the memory hogging query ID */ +#define OPTION_TREAT_CR_AS_SPACE 0x00002000 /* Treat CR in zone files as + * space */ +#define OPTION_USE_IXFR 0x00004000 /* Use by default ixfr in zone + * transfer */ +#define OPTION_MAINTAIN_IXFR_BASE 0x00008000 /* Part of IXFR file name logic. */ +#define OPTION_HITCOUNT 0x00010000 /* Keep track of each time an + * RR gets hit in the database */ #define DEFAULT_OPTION_FLAGS (OPTION_NODIALUP|OPTION_NONAUTH_NXDOMAIN|\ OPTION_USE_ID_POOL|OPTION_NORFC2308_TYPE1) @@ -236,6 +240,7 @@ typedef enum need { /* Sequence space arithmetic. */ #define SEQ_GT(a,b) ((int32_t)((a)-(b)) > 0) +#define SEQ_LT(a,b) ((int32_t)((a)-(b)) < 0) #define NS_OPTION_P(option) ((server_options == NULL) ? \ (panic(panic_msg_no_options, NULL), 0) : \ @@ -332,6 +337,7 @@ struct zoneinfo { time_t z_ftime; /* modification time of source file */ struct in_addr z_axfr_src; /* bind() the axfr socket to this */ struct in_addr z_addr[NSMAX]; /* list of master servers for zone */ + struct dst_key * z_keys[NSMAX]; /* tsig key associated with master */ u_char z_addrcnt; /* number of entries in z_addr[] */ struct in_addr z_xaddr[NSMAX]; /* list of master servers for xfer */ u_char z_xaddrcnt; /* number of entries in z_xaddr[] */ @@ -442,7 +448,8 @@ struct qserv { struct databuf *nsdata; /* databuf for server address */ struct timeval stime; /* time first query started */ unsigned int forwarder:1; /* this entry is for a forwarder */ - unsigned int nretry:31; /* # of times addr retried */ + unsigned int noedns:1; /* don't try edns */ + unsigned int nretry:30; /* # of times addr retried */ u_int32_t serial; /* valid if Q_ZSERIAL */ }; @@ -461,6 +468,10 @@ struct qinfo { q_cmsglen, /* len of cname message */ q_cmsgsize; /* allocated size of cname message */ int16_t q_dfd; /* UDP file descriptor */ + int16_t q_udpsize; /* UDP message size */ + int q_distance; /* distance this query is from the + * original query that the server + * received. */ time_t q_time; /* time to retry */ time_t q_expire; /* time to expire */ struct qinfo *q_next; /* rexmit list (sorted by time) */ @@ -470,6 +481,7 @@ struct qinfo { #ifdef notyet struct nameser *q_ns[NSMAX]; /* name servers */ #endif + struct dst_key *q_keys[NSMAX]; /* keys to use with this address */ u_char q_naddr; /* number of addr's in q_addr */ u_char q_curaddr; /* last addr sent to */ u_char q_nusedns; /* number of elements in q_usedns[] */ @@ -497,6 +509,7 @@ struct qinfo { #define Q_PRIMING 0x02 /* generated during priming phase */ #define Q_ZSERIAL 0x04 /* getting zone serial for xfer test */ #define Q_USEVC 0x08 /* forward using tcp not udp */ +#define Q_EDNS 0x10 /* add edns opt record to answer */ #define Q_NEXTADDR(qp,n) (&(qp)->q_addr[n].ns_addr) @@ -731,7 +744,8 @@ typedef struct rrset_order_list { typedef struct options { - u_int flags; + u_int32_t flags; + char *hostname; char *version; char *directory; char *dump_filename; @@ -775,6 +789,7 @@ typedef struct options { u_int max_host_stats; u_int lame_ttl; int minroots; + u_int16_t preferred_glue; } *options; typedef struct key_list_element { @@ -832,8 +847,8 @@ typedef struct server_info { */ struct ns_sym { - int number; /* Identifying number, like ns_log_default */ - char * name; /* Its symbolic name, like "default" */ + int number; /* Identifying number, like ns_log_default */ + const char * name; /* Its symbolic name, like "default" */ }; /* @@ -877,7 +892,7 @@ typedef struct log_config { } *log_config; struct map { - char * token; + const char * token; int val; }; @@ -908,3 +923,5 @@ enum req_action { Finish, Refuse, Return }; #define INIT(x) #define DECL extern #endif + +#define EDNS_MESSAGE_SZ 4096 diff --git a/contrib/bind/bin/named/ns_forw.c b/contrib/bind/bin/named/ns_forw.c index dac65253357b..f62ba20ee752 100644 --- a/contrib/bind/bin/named/ns_forw.c +++ b/contrib/bind/bin/named/ns_forw.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_forw.c 4.32 (Berkeley) 3/3/91"; -static const char rcsid[] = "$Id: ns_forw.c,v 8.78 2000/12/23 08:14:37 vixie Exp $"; +static const char rcsid[] = "$Id: ns_forw.c,v 8.89 2002/01/29 03:59:36 marka Exp $"; #endif /* not lint */ /* @@ -133,10 +133,10 @@ ns_forw(struct databuf *nsp[], u_char *msg, int msglen, HEADER *hp; u_int16_t id; int sendto_errno = 0; - int n, has_tsig, oldqlen; - u_char *oldqbuf; - u_char *smsg; - int smsglen, smsgsize, siglen; + int n, has_tsig, oldqlen = 0; + u_char *oldqbuf = NULL; + u_char *smsg = NULL; + int smsglen, smsgsize = 0, siglen; u_char sig[TSIG_SIG_SIZE]; DST_KEY *key; @@ -225,39 +225,50 @@ ns_forw(struct databuf *nsp[], u_char *msg, int msglen, if (debug >= 10) res_pquery(&res, msg, msglen, log_get_stream(packet_channel)); #endif - key = tsig_key_from_addr(nsa->sin_addr); - if (key != NULL) { - smsgsize = qp->q_msglen + TSIG_BUF_SIZE; + key = qp->q_keys[0]; + if (key == NULL) + key = qp->q_keys[0] = tsig_key_from_addr(nsa->sin_addr); + if (key != NULL || !qp->q_addr[0].noedns) { + smsgsize = qp->q_msglen + TSIG_BUF_SIZE + 11; smsg = memget(smsgsize); if (smsg == NULL) ns_panic(ns_log_default, 1, "ns_forw: memget failed"); smsglen = qp->q_msglen; siglen = sizeof(sig); memcpy(smsg, qp->q_msg, qp->q_msglen); + } + + if (!qp->q_addr[0].noedns) + smsglen += ns_add_opt(smsg, smsg + smsglen, smsgsize, 0, 0, + EDNS_MESSAGE_SZ, 0, NULL, 0); + + if (key != NULL) { n = ns_sign(smsg, &smsglen, smsgsize, NOERROR, key, NULL, 0, sig, &siglen, 0); if (n == 0) { - oldqbuf = qp->q_msg; - oldqlen = qp->q_msglen; - qp->q_msglen = smsglen; - qp->q_msg = smsg; - hp = (HEADER *) qp->q_msg; has_tsig = 1; + free_tsig(qp->q_nstsig); qp->q_nstsig = new_tsig(key, sig, siglen); - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; INSIST(0); } - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; } + if (smsg != NULL) { + oldqbuf = qp->q_msg; + oldqlen = qp->q_msglen; + qp->q_msglen = smsglen; + qp->q_msg = smsg; + hp = (HEADER *) qp->q_msg; + } + if (qp->q_flags & Q_USEVC) { if (tcp_send(qp) != NOERROR) { if (!haveComplained(ina_ulong(nsa->sin_addr), @@ -269,15 +280,16 @@ ns_forw(struct databuf *nsp[], u_char *msg, int msglen, } else if (sendto(ds, (char *)qp->q_msg, qp->q_msglen, 0, (struct sockaddr *)nsa, sizeof(struct sockaddr_in)) < 0) { - sendto_errno = errno; + sendto_errno = errno; if (!haveComplained(ina_ulong(nsa->sin_addr), (u_long)sendtoStr)) ns_info(ns_log_default, "ns_forw: sendto(%s): %s", sin_ntoa(*nsa), strerror(errno)); nameserIncr(nsa->sin_addr, nssSendtoErr); } - if (has_tsig == 1) { - memput(qp->q_msg, smsgsize); + + if (smsgsize != 0) { + memput(smsg, smsgsize); qp->q_msg = oldqbuf; qp->q_msglen = oldqlen; hp = (HEADER *) qp->q_msg; @@ -456,8 +468,8 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, int oldn, naddr, class, found_arr, potential_ns, lame_ns; time_t curtime; - ns_debug(ns_log_default, 3, "nslookup(nsp=%#x, qp=%#x, \"%s\")", - nsp, qp, syslogdname); + ns_debug(ns_log_default, 3, "nslookup(nsp=%p, qp=%p, \"%s\", d=%d)", + nsp, qp, syslogdname, qp->q_distance); lame_ns = potential_ns = 0; naddr = n = qp->q_naddr; @@ -494,7 +506,7 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, tmphtp = ((nsdp->d_flags & DB_F_HINT) ?fcachetab :hashtab); np = nlookup(dname, &tmphtp, &fname, 0); if (np == NULL) { - ns_debug(ns_log_default, 3, "%s: not found %s %#x", + ns_debug(ns_log_default, 3, "%s: not found %s %p", dname, fname, np); found_arr = 0; goto need_sysquery; @@ -520,6 +532,8 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, complaint, dname, dp, nsdp); goto skipserver; } + if (dp->d_rcode == NXDOMAIN && dp->d_class == class) + goto skipserver; if (dp->d_type != T_A || dp->d_class != class) continue; if (dp->d_rcode) { @@ -587,9 +601,11 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, qs->ns_addr.sin_family = AF_INET; qs->ns_addr.sin_port = ns_port; qs->ns_addr.sin_addr = nsa; + qp->q_keys[n] = NULL; qs->ns = nsdp; qs->nsdata = dp; qs->forwarder = 0; + qs->noedns = dp->d_noedns; qs->nretry = 0; /* * If this A RR has no RTT, initialize its RTT to a @@ -615,7 +631,8 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, * gdonl mar96 */ if (aIsUs(nsa)) { - static char *complaint = "contains our address"; + static const char *complaint = + "contains our address"; nslookupComplain(sysloginfo, syslogdname, complaint, dname, dp, nsdp); continue; @@ -632,7 +649,7 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, if (memcmp(&qp->q_from, &qs->ns_addr, sizeof(qp->q_from)) == 0) { - static char *complaint = "forwarding loop"; + static const char *complaint = "forwarding loop"; nslookupComplain(sysloginfo, syslogdname, complaint, dname, dp, nsdp); continue; @@ -668,9 +685,10 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, need_sysquery: if (found_arr == 0) { potential_ns++; - if (!(qp->q_flags & Q_SYSTEM)) - (void) sysquery(dname, class, T_A, NULL, 0, - ns_port, QUERY); + if (qp->q_distance < NS_MAX_DISTANCE) + (void) sysquery(dname, class, T_A, NULL, NULL, + 0, ns_port, QUERY, + qp->q_distance + 1); } skipserver: (void)NULL; @@ -678,7 +696,7 @@ nslookup(struct databuf *nsp[], struct qinfo *qp, ns_debug(ns_log_default, 3, "nslookup: %d ns addrs total", n); qp->q_naddr = n; if (n == 0 && potential_ns == 0 && !NS_ZFWDTAB(qp->q_fzone)) { - static char *complaint = "No possible A RRs"; + static const char *complaint = "No possible A RRs"; if (lame_ns != 0) complaint = "All possible A RR's lame"; if (sysloginfo && syslogdname && @@ -784,7 +802,7 @@ qcomp(struct qserv *qs1, struct qserv *qs2) { strcpy(t, inet_ntoa(qs1->ns_addr.sin_addr)); ns_debug(ns_log_default, 10, - "qcomp(%s, %s) %lu (%lu) - %lu (%lu) = %lu", + "qcomp(%s, %s) %u (%u) - %u (%u) = %u", t, inet_ntoa(qs2->ns_addr.sin_addr), rtt1, rttr1, rtt2, rttr2, rtt1 - rtt2); } @@ -813,7 +831,7 @@ void schedretry(struct qinfo *qp, time_t t) { struct qinfo *qp1, *qp2; - ns_debug(ns_log_default, 4, "schedretry(%#x, %ld sec)", qp, (long)t); + ns_debug(ns_log_default, 4, "schedretry(%p, %ld sec)", qp, (long)t); if (qp->q_time) ns_debug(ns_log_default, 4, "WARNING: schedretry(%#lx, %ld) q_time already %ld", @@ -885,22 +903,28 @@ reset_retrytimer() { void retrytimer(evContext ctx, void *uap, struct timespec due, struct timespec ival) { + + UNUSED(ctx); + UNUSED(uap); + UNUSED(due); + UNUSED(ival); + retry_timer_set = 0; - retry(retryqp); + retry(retryqp, 0); } /* * Retry is called to retransmit query 'qp'. */ void -retry(struct qinfo *qp) { - int n, has_tsig, oldqlen; +retry(struct qinfo *qp, int samehost) { + int n, has_tsig, oldqlen = 0; HEADER *hp; struct sockaddr_in *nsa; int sendto_errno = 0; - u_char *oldqbuf; - u_char *smsg; - int smsglen, smsgsize, siglen; + u_char *oldqbuf = NULL; + u_char *smsg = NULL; + int smsglen, smsgsize = 0, siglen; u_char sig[TSIG_SIG_SIZE]; DST_KEY *key; @@ -923,7 +947,15 @@ retry(struct qinfo *qp) { /* Try next address. */ n = qp->q_curaddr; + if (samehost) { + qp->q_addr[n].nretry++; + if (qp->q_addr[n].nretry < MAXRETRY) + goto found; + qp->q_addr[n].nretry--; + } + if (qp->q_naddr > 0) { + qp->q_addr[n].noedns = 1; ++qp->q_addr[n].nretry; do { if (++n >= (int)qp->q_naddr) @@ -970,7 +1002,7 @@ retry(struct qinfo *qp) { } ns_debug(ns_log_default, 5, "give up"); if ((qp->q_flags & Q_SYSTEM) == 0) { - n = ((HEADER *)qp->q_cmsg ? qp->q_cmsglen : qp->q_msglen); + n = (qp->q_cmsg ? qp->q_cmsglen : qp->q_msglen); hp->id = qp->q_id; hp->qr = 1; hp->ra = (NS_OPTION_P(OPTION_NORECURSE) == 0); @@ -1015,24 +1047,29 @@ retry(struct qinfo *qp) { res_pquery(&res, qp->q_msg, qp->q_msglen, log_get_stream(packet_channel)); #endif - key = tsig_key_from_addr(nsa->sin_addr); - if (key != NULL) { - smsgsize = qp->q_msglen + TSIG_BUF_SIZE; + key = qp->q_keys[n]; + if (key == NULL) + key = qp->q_keys[n] = tsig_key_from_addr(nsa->sin_addr); + if (key != NULL || !qp->q_addr[n].noedns) { + smsgsize = qp->q_msglen + TSIG_BUF_SIZE + 11; smsg = memget(smsgsize); smsglen = qp->q_msglen; siglen = sizeof(sig); memcpy(smsg, qp->q_msg, qp->q_msglen); + } + + if (!qp->q_addr[n].noedns) + smsglen += ns_add_opt(smsg, smsg + smsglen, smsgsize, 0, 0, + EDNS_MESSAGE_SZ, 0, NULL, 0); + + if (key != NULL) { n = ns_sign(smsg, &smsglen, smsgsize, NOERROR, key, NULL, 0, sig, &siglen, 0); if (n == 0) { - oldqbuf = qp->q_msg; - oldqlen = qp->q_msglen; - qp->q_msglen = smsglen; - qp->q_msg = smsg; has_tsig = 1; + free_tsig(qp->q_nstsig); qp->q_nstsig = new_tsig(key, sig, siglen); - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; @@ -1044,6 +1081,13 @@ retry(struct qinfo *qp) { qp->q_nstsig = NULL; } + if (smsg != NULL) { + oldqbuf = qp->q_msg; + oldqlen = qp->q_msglen; + qp->q_msglen = smsglen; + qp->q_msg = smsg; + } + if (qp->q_flags & Q_USEVC) { if (tcp_send(qp) != NOERROR) ns_debug(ns_log_default, 3, @@ -1057,8 +1101,8 @@ retry(struct qinfo *qp) { ns_debug(ns_log_default, 3, "error resending msg: %s", strerror(errno)); } - if (has_tsig == 1) { - memput(qp->q_msg, smsgsize); + if (smsgsize != 0) { + memput(smsg, smsgsize); qp->q_msg = oldqbuf; qp->q_msglen = oldqlen; } @@ -1171,33 +1215,14 @@ qnew(const char *name, int class, int type, int forward) { } void -ns_freeqns(struct qinfo *qp, char *where) { - static const char freed[] = "freed", busy[] = "busy"; - const char *result; - struct databuf *dp; - int i; +ns_freeqns(struct qinfo *qp) { + unsigned int i; - for (i = 0 ; i < (int)qp->q_naddr ; i++) { - dp = qp->q_addr[i].ns; - if (dp) { - DRCNTDEC(dp); - result = (dp->d_rcnt) ? busy : freed; - ns_debug(ns_log_default, 3, "%s: ns %s rcnt %d (%s)", - where, dp->d_data, dp->d_rcnt, result); - if (result == freed) - db_freedata(dp); - } - dp = qp->q_addr[i].nsdata; - if (dp) { - DRCNTDEC(dp); - result = (dp->d_rcnt) ? busy : freed; - ns_debug(ns_log_default, 3, - "%s: nsdata %s rcnt %d (%s)", - where, inet_ntoa(ina_get(dp->d_data)), - dp->d_rcnt, result); - if (result == freed) - db_freedata(dp); - } + for (i = 0 ; i < qp->q_naddr ; i++) { + if (qp->q_addr[i].ns != NULL) + db_detach(&qp->q_addr[i].ns); + if (qp->q_addr[i].nsdata != NULL) + db_detach(&qp->q_addr[i].nsdata); } } @@ -1214,14 +1239,14 @@ ns_freeqry(struct qinfo *qp) { if (qp->q_cmsg != NULL) memput(qp->q_cmsg, qp->q_cmsgsize); if (qp->q_domain != NULL) - freestr(qp->q_domain); + qp->q_domain = freestr(qp->q_domain); if (qp->q_name != NULL) - freestr(qp->q_name); + qp->q_name = freestr(qp->q_name); if (qp->q_tsig != NULL) memput(qp->q_tsig, sizeof(struct tsig_record)); if (qp->q_nstsig != NULL) memput(qp->q_nstsig, sizeof(struct tsig_record)); - ns_freeqns(qp, "ns_freeqry"); + ns_freeqns(qp); if (nsqhead == qp) nsqhead = qp->q_link; else { @@ -1245,7 +1270,7 @@ nsfwdadd(struct qinfo *qp, struct fwdinfo *fwd) { n = qp->q_naddr; while (fwd != NULL && n < NSMAX) { qs = qp->q_addr; - for (i = 0; i < (u_int)n; i++, qs++) + for (i = 0; i < n; i++, qs++) if (ina_equal(qs->ns_addr.sin_addr, fwd->fwddata->fwdaddr.sin_addr)) goto nextfwd; @@ -1253,6 +1278,7 @@ nsfwdadd(struct qinfo *qp, struct fwdinfo *fwd) { qs->ns = fwd->fwddata->ns; qs->nsdata = fwd->fwddata->nsdata; qs->forwarder = 1; + qs->noedns = fwd->fwddata->nsdata->d_noedns; qs->nretry = 0; n++; nextfwd: @@ -1260,7 +1286,7 @@ nsfwdadd(struct qinfo *qp, struct fwdinfo *fwd) { } /* Update the refcounts before the sort. */ - for (i = qp->q_naddr; i < (u_int)n; i++) { + for (i = qp->q_naddr; i < n; i++) { DRCNTINC(qp->q_addr[i].nsdata); DRCNTINC(qp->q_addr[i].ns); } diff --git a/contrib/bind/bin/named/ns_func.h b/contrib/bind/bin/named/ns_func.h index ef9780f59ed3..501aa01f413a 100644 --- a/contrib/bind/bin/named/ns_func.h +++ b/contrib/bind/bin/named/ns_func.h @@ -90,43 +90,43 @@ /* ns_func.h - declarations for ns_*.c's externally visible functions * - * $Id: ns_func.h,v 8.105 2001/02/16 04:46:12 marka Exp $ + * $Id: ns_func.h,v 8.115 2002/01/29 03:59:38 marka Exp $ */ /* ++from ns_glue.c++ */ struct in_addr ina_get(const u_char *data); const char * sin_ntoa(struct sockaddr_in); int ns_wouldlog(int category, int level); -void ns_debug(int, int, const char *, ...); -void ns_info(int, const char *, ...); -void ns_notice(int, const char *, ...); -void ns_warning(int, const char *, ...); -void ns_error(int, const char *, ...); -void ns_critical(int, const char *, ...); -void ns_panic(int, int, const char *, ...); -void ns_assertion_failed(char *file, int line, - assertion_type type, char *cond, - int print_errno); +void ns_debug(int, int, const char *, ...) ISC_FORMAT_PRINTF(3, 4); +void ns_info(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +void ns_notice(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +void ns_warning(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +void ns_error(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +void ns_critical(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +void ns_panic(int, int, const char *, ...) ISC_FORMAT_PRINTF(3, 4); +void ns_assertion_failed(const char *file, int line, + assertion_type type, + const char *cond, int print_errno); void panic(const char *, const void *); void gettime(struct timeval *); int nlabels(const char *); int my_close(int); int my_fclose(FILE *); -void __freestr(char *); +void * __freestr(char *); char * __newstr(size_t, int); char * __savestr(const char *, int); -char * checked_ctime(const time_t *t); -char * ctimel(long); -void __freestr_record(char *, char *, int); -char * __newstr_record(size_t, int, char *, int); -char * __savestr_record(const char *, int, char *, int); +const char * checked_ctime(const time_t *t); +const char * ctimel(long); +void * __freestr_record(char *, const char *, int); +char * __newstr_record(size_t, int, const char *, int); +char * __savestr_record(const char *, int, const char *, int); u_char * ina_put(struct in_addr ina, u_char *data); u_char * savebuf(const u_char *, size_t, int); -void dprintf(int level, const char *format, ...); +void dprintf(int level, const char *format, ...) ISC_FORMAT_PRINTF(2, 3); #ifdef DEBUG_STRINGS char * debug_newstr(size_t, int, const char *, int); char * debug_savestr(const char *, int, const char *, int); -void debug_freestr(char *, const char *, int); +void * debug_freestr(char *, const char *, int); #define newstr(l, n) debug_newstr((l), (n), __FILE__, __LINE__) #define savestr(s, n) debug_savestr((s), (n), __FILE__, __LINE__) #define freestr(s) debug_freestr((s), __FILE__, __LINE__) @@ -159,7 +159,8 @@ void prime_cache(void); void delete_all(struct namebuf *, int, int); int delete_stale(struct namebuf *); struct qinfo * sysquery(const char *, int, int, - struct in_addr *, int, u_int16_t, int); + struct in_addr *, struct dst_key **keys, + int, u_int16_t, int, int); int doupdate(u_char *, u_char *, struct databuf **, int, int, int, u_int, struct sockaddr_in); int send_msg(u_char *, int, struct qinfo *); @@ -174,6 +175,14 @@ int trunc_adjust(u_char *, int, int); /* --from ns_resp.c-- */ /* ++from ns_req.c++ */ +int ns_get_opt(u_char *msg, u_char *eom, + u_int8_t *versionp, u_int16_t *rcodep, + u_int16_t *flagp, u_int16_t *bufsizep, + u_char **optionsp, size_t *optsizep); +int ns_add_opt(u_char *msg, u_char *cp, size_t buflen, + u_int8_t version, u_int16_t rcode, + u_int16_t size, u_int16_t flags, + u_char *options, size_t optlen); void ns_req(u_char *, int, int, struct qstream *, struct sockaddr_in, @@ -192,6 +201,7 @@ int doaddauth(HEADER *, u_char *, int, int findZonePri(const struct zoneinfo *, const struct sockaddr_in); #endif +int drop_port(u_int16_t); /* --from ns_req.c-- */ /* ++from ns_xfr.c++ */ @@ -212,8 +222,8 @@ void ns_ctl_shutdown(void); void ns_ctl_defaults(controls *); void ns_ctl_add(controls *, control); control ns_ctl_new_inet(struct in_addr, u_int, ip_match_list); -#ifndef WINNT -control ns_ctl_new_unix(char *, mode_t, uid_t, gid_t); +#ifndef NO_SOCKADDR_UN +control ns_ctl_new_unix(const char *, mode_t, uid_t, gid_t); #endif void ns_ctl_install(controls *); /* --from ns_ctl.c-- */ @@ -249,10 +259,10 @@ void unsched(struct qinfo *); void reset_retrytimer(void); void retrytimer(evContext ctx, void *uap, struct timespec due, struct timespec ival); -void retry(struct qinfo *); +void retry(struct qinfo *, int); void qflush(void); void qremove(struct qinfo *); -void ns_freeqns(struct qinfo *, char *); +void ns_freeqns(struct qinfo *); void ns_freeqry(struct qinfo *); void freeComplaints(void); void nsfwdadd(struct qinfo *, struct fwdinfo *); @@ -267,7 +277,7 @@ void sq_remove(struct qstream *); void sq_flushw(struct qstream *); void sq_flush(struct qstream *allbut); void dq_remove_gen(time_t gen); -void dq_remove_all(); +void dq_remove_all(void); void sq_done(struct qstream *); void ns_setproctitle(char *, int); void getnetconf(int); @@ -386,8 +396,7 @@ int merge_logs(struct zoneinfo *zp, char *logname); int zonedump(struct zoneinfo *zp, int isixfr); void dynamic_about_to_exit(void); enum req_action req_update(HEADER *hp, u_char *cp, u_char *eom, - u_char *msg, struct qstream *qsp, - int dfd, struct sockaddr_in from, + u_char *msg, struct sockaddr_in from, struct tsig_record *in_tsig); void rdata_dump(struct databuf *dp, FILE *fp); /* --from ns_update.c-- */ @@ -422,7 +431,8 @@ int set_zone_transfer_source(zone_config, struct in_addr); int set_zone_pubkey(zone_config, const int, const int, const int, const char *); int set_zone_transfer_time_in(zone_config, long); -int add_zone_master(zone_config, struct in_addr); +int add_zone_master(zone_config, struct in_addr, + struct dst_key *); #ifdef BIND_NOTIFY int add_zone_notify(zone_config, struct in_addr); #endif @@ -453,8 +463,8 @@ ip_match_element new_ip_match_localhost(void); ip_match_element new_ip_match_localnets(void); void ip_match_negate(ip_match_element); void add_to_ip_match_list(ip_match_list, ip_match_element); -void dprint_ip_match_list(int, ip_match_list, int, char *, - char *); +void dprint_ip_match_list(int, ip_match_list, int, + const char *, const char *); int ip_match_address(ip_match_list, struct in_addr); int ip_match_addr_or_key(ip_match_list, struct in_addr, struct dst_key *key); @@ -503,10 +513,10 @@ time_t load_configuration(const char *); /* --from ns_config.c-- */ /* ++from parser.y++ */ -ip_match_list lookup_acl(char *); -void define_acl(char *, ip_match_list); +ip_match_list lookup_acl(const char *); +void define_acl(const char *, ip_match_list); struct dst_key *lookup_key(char *); -void define_key(char *, struct dst_key *); +void define_key(const char *, struct dst_key *); time_t parse_configuration(const char *); void parser_initialize(void); void parser_shutdown(void); diff --git a/contrib/bind/bin/named/ns_glob.h b/contrib/bind/bin/named/ns_glob.h index 8f4628a8a833..7f382d5ee499 100644 --- a/contrib/bind/bin/named/ns_glob.h +++ b/contrib/bind/bin/named/ns_glob.h @@ -1,6 +1,6 @@ /* * from ns.h 4.33 (Berkeley) 8/23/90 - * $Id: ns_glob.h,v 8.56 2000/12/02 18:39:25 vixie Exp $ + * $Id: ns_glob.h,v 8.57 2001/11/12 21:22:26 marka Exp $ */ /* @@ -342,3 +342,4 @@ DECL int loading INIT(0); DECL int xfers_running INIT(0); DECL int xfers_deferred INIT(0); DECL int qserials_running INIT(0); +DECL int initial_configuration INIT(1); diff --git a/contrib/bind/bin/named/ns_glue.c b/contrib/bind/bin/named/ns_glue.c index a4bd0f1ed95e..3d73c1891bc1 100644 --- a/contrib/bind/bin/named/ns_glue.c +++ b/contrib/bind/bin/named/ns_glue.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_glue.c,v 8.20 2001/02/16 04:46:14 marka Exp $"; +static const char rcsid[] = "$Id: ns_glue.c,v 8.24 2002/01/07 02:54:37 marka Exp $"; #endif /* not lint */ /* @@ -179,8 +179,8 @@ ns_panic(int category, int dump_core, const char *format, ...) { } void -ns_assertion_failed(char *file, int line, assertion_type type, char *cond, - int print_errno) +ns_assertion_failed(const char *file, int line, assertion_type type, + const char *cond, int print_errno) { ns_panic(ns_log_insist, 1, "%s:%d: %s(%s)%s%s failed.", file, line, assertion_type_to_text(type), cond, @@ -277,7 +277,11 @@ my_close(int fd) { s = close(fd); } while (s < 0 && errno == EINTR); - if (s < 0 && errno != EBADF) + /* + * Tru64 UNIX V5.1 can return a spurious EINVAL after connect() + * failures. + */ + if (s < 0 && errno != EBADF && errno != EINVAL) ns_info(ns_log_default, "close(%d) failed: %s", fd, strerror(errno)); else @@ -328,9 +332,10 @@ __savestr(const char *str, int needpanic) { return (__savestr_record(str, needpanic, __FILE__, __LINE__)); } -void +void * __freestr(char *str) { __freestr_record(str, __FILE__, __LINE__); + return (NULL); } #ifdef DEBUG_STRINGS @@ -364,7 +369,7 @@ debug_freestr(char *str, const char *file, int line) { len += 3; /* 2 length bytes + NUL. */ printf("%s:%d: freestr %d %s\n", file, line, len, str); __freestr_record(str, file, line); - return; + return (NULL); } #endif /* DEBUG_STRINGS */ @@ -372,7 +377,7 @@ debug_freestr(char *str, const char *file, int line) { * Return a counted string buffer big enough for a string of length 'len'. */ char * -__newstr_record(size_t len, int needpanic, char *file, int line) { +__newstr_record(size_t len, int needpanic, const char *file, int line) { u_char *buf, *bp; REQUIRE(len <= 65536); @@ -393,7 +398,7 @@ __newstr_record(size_t len, int needpanic, char *file, int line) { * Save a NUL terminated string and return a pointer to it. */ char * -__savestr_record(const char *str, int needpanic, char *file, int line) { +__savestr_record(const char *str, int needpanic, const char *file, int line) { char *buf; size_t len; @@ -410,8 +415,8 @@ __savestr_record(const char *str, int needpanic, char *file, int line) { return (buf); } -void -__freestr_record(char *str, char *file, int line) { +void * +__freestr_record(char *str, const char *file, int line) { u_char *buf, *bp; size_t len; @@ -419,11 +424,12 @@ __freestr_record(char *str, char *file, int line) { bp = buf; NS_GET16(len, bp); __memput_record(buf, 2/*Len*/ + len + 1/*Nul*/, file, line); + return (NULL); } -char * +const char * checked_ctime(const time_t *t) { - char *ctime_result; + const char *ctime_result; ctime_result = ctime(t); if (ctime_result == NULL) { @@ -438,7 +444,7 @@ checked_ctime(const time_t *t) { * Since the fields in a "struct timeval" are longs, and the argument to ctime * is a pointer to a time_t (which might not be a long), here's a bridge. */ -char * +const char * ctimel(long l) { time_t t = (time_t)l; diff --git a/contrib/bind/bin/named/ns_init.c b/contrib/bind/bin/named/ns_init.c index 553f047e60d7..773192b99ae4 100644 --- a/contrib/bind/bin/named/ns_init.c +++ b/contrib/bind/bin/named/ns_init.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_init.c 4.38 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: ns_init.c,v 8.73 2001/04/20 00:21:40 vixie Exp $"; +static const char rcsid[] = "$Id: ns_init.c,v 8.76 2001/12/19 01:41:51 marka Exp $"; #endif /* not lint */ /* @@ -294,7 +294,10 @@ do_reload(const char *domain, int type, int class, int mark) { * Clean up any leftover data. */ ns_stopxfrs(zp); - purge_zone(domain, hashtab, class); + if (type == z_hint || (type == z_stub && *domain == 0)) + purge_zone(domain, fcachetab, class); + else + purge_zone(domain, hashtab, class); /* * Reload @@ -534,9 +537,9 @@ ns_nameok(const struct qinfo *qry, const char *name, int class, if (severity == warn) ok = 1; if (s != NULL) - freestr(s); + (void)freestr(s); if (o != NULL) - freestr(o); + (void)freestr(o); } return (ok); } diff --git a/contrib/bind/bin/named/ns_ixfr.c b/contrib/bind/bin/named/ns_ixfr.c index c013717f3af3..f14019e776f0 100644 --- a/contrib/bind/bin/named/ns_ixfr.c +++ b/contrib/bind/bin/named/ns_ixfr.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_ixfr.c,v 8.26.2.2 2001/08/10 03:00:08 marka Exp $"; +static const char rcsid[] = "$Id: ns_ixfr.c,v 8.31 2002/01/02 05:15:20 marka Exp $"; #endif /* not lint */ /* @@ -232,8 +232,7 @@ sx_send_ixfr(struct qstream *qsp) { if (sx_addrr(qsp, rp->r_dname, rp->r_dp) < 0) goto cleanup; - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); foundsoa = 1; break; } @@ -268,8 +267,7 @@ sx_send_ixfr(struct qstream *qsp) { sx_addrr(qsp, rp->r_dname, rp->r_dp) < 0) goto cleanup; - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); } rp = NEXT(rp, r_link); } @@ -292,8 +290,7 @@ sx_send_ixfr(struct qstream *qsp) { if (sx_addrr(qsp, rp->r_dname, rp->r_dp) < 0) goto cleanup; - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); foundsoa = 1; break; } @@ -332,8 +329,7 @@ sx_send_ixfr(struct qstream *qsp) { if (sx_addrr(qsp, rp->r_dname, rp->r_dp) < 0) goto cleanup; - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); } rp = NEXT(rp, r_link); } @@ -344,10 +340,8 @@ sx_send_ixfr(struct qstream *qsp) { /* clean up old update */ while ((rp = HEAD(dp->d_changes)) != NULL) { UNLINK(dp->d_changes, rp, r_link); - if (rp->r_dp != NULL) { - db_freedata(rp->r_dp); - rp->r_dp = NULL; - } + if (rp->r_dp != NULL) + db_detach(&rp->r_dp); res_freeupdrec(rp); } memput(dp, sizeof (*dp)); @@ -379,8 +373,7 @@ sx_send_ixfr(struct qstream *qsp) { while ((rp = HEAD(dp->d_changes)) != NULL) { UNLINK(dp->d_changes, rp, r_link); if (rp->r_dp != NULL) - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); res_freeupdrec(rp); } memput(dp, sizeof *dp); @@ -432,9 +425,8 @@ ixfr_log_maint(struct zoneinfo *zp) { return (-1); } (void) my_fclose(db_fp); - ns_debug(ns_log_default, 3, "%s, size %d blk %d", - zp->z_source, db_sb.st_size, - db_sb.st_size); + ns_debug(ns_log_default, 3, "%s, size %ld", + zp->z_source, (long)db_sb.st_size); /* open up the zone ixfr log */ if ((from_fp = fopen(zp->z_ixfr_base, "r")) == NULL) { @@ -449,10 +441,8 @@ ixfr_log_maint(struct zoneinfo *zp) { (void) my_fclose(from_fp); return (-1); } - ns_debug(ns_log_default, 3, "%s, size %d max %d\n", - zp->z_ixfr_base, - sb.st_size, - zp->z_max_log_size_ixfr); + ns_debug(ns_log_default, 3, "%s, size %ld max %ld\n", zp->z_ixfr_base, + (long)sb.st_size, (long)zp->z_max_log_size_ixfr); if (zp->z_max_log_size_ixfr) { if (sb.st_size > zp->z_max_log_size_ixfr) seek = sb.st_size - @@ -467,7 +457,7 @@ ixfr_log_maint(struct zoneinfo *zp) { else seek = 0; } - ns_debug(ns_log_default, 3, "seek: %d", seek); + ns_debug(ns_log_default, 3, "seek: %ld", (long)seek); if (seek < 1) { ns_debug(ns_log_default, 3, "%s does not need to be reduced", zp->z_ixfr_base); @@ -489,7 +479,7 @@ ixfr_log_maint(struct zoneinfo *zp) { (void) strcat(tmpname, ".XXXXXX"); if ((fd = mkstemp(tmpname)) == -1) { - ns_warning(ns_log_db, "can't make tmpfile (%s): %s", + ns_warning(ns_log_db, "can't make tmpfile (%s): %s", tmpname, strerror(errno)); memput(tmpname, len); (void) my_fclose(from_fp); @@ -536,7 +526,8 @@ ixfr_log_maint(struct zoneinfo *zp) { break; } if (found) { - ns_debug(ns_log_default, 1, "ixfr_log_maint(): found [END_DELTA]"); + ns_debug(ns_log_default, 1, + "ixfr_log_maint(): found [END_DELTA]"); fprintf(to_fp, "%s", LogSignature); @@ -557,7 +548,8 @@ ixfr_log_maint(struct zoneinfo *zp) { (void) my_fclose(from_fp); if (error == 0) { if (isc_movefile(tmpname, zp->z_ixfr_base) == -1) { - ns_warning(ns_log_default, "can not rename %s to %s :%s", + ns_warning(ns_log_default, + "can not rename %s to %s :%s", tmpname, zp->z_ixfr_base, strerror(errno)); } if ((from_fp = fopen(zp->z_ixfr_base, "r")) == NULL) { @@ -576,25 +568,23 @@ ixfr_log_maint(struct zoneinfo *zp) { if (sb.st_size <= 0) (void) unlink(zp->z_ixfr_base); else if (chmod(zp->z_ixfr_base, 0644) < 0) - ns_error(ns_log_update, - "chmod(%s,%o) failed, pressing on: %s", - zp->z_source, sb.st_mode, - strerror(errno)); + ns_error(ns_log_update, + "chmod(%s,%o) failed, pressing on: %s", + zp->z_source, sb.st_mode, strerror(errno)); (void) my_fclose(from_fp); } (void) unlink(tmpname); memput(tmpname, len); - zp->z_serial_ixfr_start = 0; /* signal to read for lowest serial number */ + /* signal to read for lowest serial number */ + zp->z_serial_ixfr_start = 0; - ns_debug(ns_log_default, 3, "%s, size %d max %d\n", - zp->z_ixfr_base, - sb.st_size, - zp->z_max_log_size_ixfr); + ns_debug(ns_log_default, 3, "%s, size %ld max %ld\n", zp->z_ixfr_base, + (long)sb.st_size, (long)zp->z_max_log_size_ixfr); if (error) return(-1); else - return (0); + return (0); } diff --git a/contrib/bind/bin/named/ns_lexer.c b/contrib/bind/bin/named/ns_lexer.c index bb2d11f39a92..4a6f820832be 100644 --- a/contrib/bind/bin/named/ns_lexer.c +++ b/contrib/bind/bin/named/ns_lexer.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_lexer.c,v 8.22 2000/11/29 06:55:58 marka Exp $"; +static const char rcsid[] = "$Id: ns_lexer.c,v 8.28 2001/12/28 04:07:47 marka Exp $"; #endif /* not lint */ /* @@ -140,6 +140,10 @@ token_to_text(int token, YYSTYPE lval) { static char where[MAXPATHLEN + 100]; static char message[20480]; +static void +parser_complain(int is_warning, int print_last_token, const char *format, + va_list args) ISC_FORMAT_PRINTF(3, 0); + static void parser_complain(int is_warning, int print_last_token, const char *format, va_list args) @@ -199,7 +203,7 @@ parser_error(int print_last_token, const char *format, ...) { void yyerror(const char *message) { - parser_error(1, message); + parser_error(1, "%s", message); } /* @@ -207,7 +211,7 @@ yyerror(const char *message) { */ struct keyword { - char *name; + const char *name; int token; }; @@ -265,6 +269,7 @@ static struct keyword keywords[] = { #endif /* HITCOUNTS */ {"host-statistics", T_HOSTSTATS}, {"host-statistics-max", T_HOSTSTATSMAX}, + {"hostname", T_HOSTNAME}, {"if-no-answer", T_IF_NO_ANSWER}, {"if-no-domain", T_IF_NO_DOMAIN}, {"ignore", T_IGNORE}, @@ -303,6 +308,7 @@ static struct keyword keywords[] = { {"perm", T_PERM}, {"pid-file", T_PIDFILE}, {"port", T_PORT}, + {"preferred-glue", T_PREFERRED_GLUE}, {"print-category", T_PRINT_CATEGORY}, {"print-severity", T_PRINT_SEVERITY}, {"print-time", T_PRINT_TIME}, @@ -324,6 +330,9 @@ static struct keyword keywords[] = { {"statistics-interval", T_STATS_INTERVAL}, {"stub", T_STUB}, {"support-ixfr", T_SUPPORT_IXFR}, +#ifdef BIND_NOTIFY + {"suppress-initial-notify", T_NOTIFY_INITIAL}, +#endif {"syslog", T_SYSLOG}, {"topology", T_TOPOLOGY}, {"transfer-format", T_TRANSFER_FORMAT}, @@ -474,7 +483,7 @@ scan_to_comment_end(int c_plus_plus_style) { } } -int +static int get_next_char(int comment_ok) { int c, nc; @@ -518,7 +527,7 @@ get_next_char(int comment_ok) { return (c); } -void +static void put_back_char(int c) { if (c == EOF) current_file->flags |= LEX_EOF; diff --git a/contrib/bind/bin/named/ns_lexer.h b/contrib/bind/bin/named/ns_lexer.h index 7a22b8e3ff73..394338cfdc1f 100644 --- a/contrib/bind/bin/named/ns_lexer.h +++ b/contrib/bind/bin/named/ns_lexer.h @@ -30,8 +30,8 @@ #define SYM_LOGGING 0x04 #define SYM_SYSLOG 0x08 -int parser_warning(int, const char *, ...); -int parser_error(int, const char *, ...); +int parser_warning(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); +int parser_error(int, const char *, ...) ISC_FORMAT_PRINTF(2, 3); void yyerror(const char *); void lexer_begin_file(const char *, FILE *); void lexer_end_file(void); diff --git a/contrib/bind/bin/named/ns_main.c b/contrib/bind/bin/named/ns_main.c index 1d7bfe8596da..23cf249167a0 100644 --- a/contrib/bind/bin/named/ns_main.c +++ b/contrib/bind/bin/named/ns_main.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91"; -static const char rcsid[] = "$Id: ns_main.c,v 8.145 2001/03/16 12:07:57 marka Exp $"; +static const char rcsid[] = "$Id: ns_main.c,v 8.155 2001/11/16 05:37:27 marka Exp $"; #endif /* not lint */ /* @@ -233,14 +233,14 @@ usage() { exit(1); } -static char bad_p_option[] = +static const char bad_p_option[] = "-p remote/local obsolete; use 'listen-on' in config file to specify local"; -static char bad_directory[] = "chdir failed for directory '%s': %s"; +static const char bad_directory[] = "chdir failed for directory '%s': %s"; /*ARGSUSED*/ int -main(int argc, char *argv[], char *envp[]) { +main(int argc, char *argv[]) { int n; char *p; int ch; @@ -281,7 +281,7 @@ main(int argc, char *argv[], char *envp[]) { case 'b': case 'c': if (conffile != NULL) - freestr(conffile); + (void)freestr(conffile); conffile = savestr(optarg, 1); break; @@ -367,7 +367,7 @@ main(int argc, char *argv[], char *envp[]) { case 'g': if (group_name != NULL) - freestr(group_name); + (void)freestr(group_name); group_name = savestr(optarg, 1); if (only_digits(group_name)) group_id = atoi(group_name); @@ -394,7 +394,7 @@ main(int argc, char *argv[], char *envp[]) { if (argc) { if (conffile != NULL) - freestr(conffile); + (void)freestr(conffile); conffile = savestr(*argv, 1); argc--, argv++; } @@ -431,8 +431,7 @@ main(int argc, char *argv[], char *envp[]) { } #else fprintf(stderr, "warning: chroot() not available\n"); - freestr(chroot_dir); - chroot_dir = NULL; + chroot_dir = freestr(chroot_dir); #endif } @@ -608,13 +607,17 @@ stream_accept(evContext lev, void *uap, int rfd, interface *ifp = uap; struct qstream *sp; struct iovec iov; - int len, n; + ISC_SOCKLEN_T len; + int n; const int on = 1; #ifdef IP_OPTIONS /* XXX */ u_char ip_opts[IP_OPT_BUF_SIZE]; #endif const struct sockaddr_in *la, *ra; + UNUSED(lalen); + UNUSED(ralen); + la = (const struct sockaddr_in *)lav; ra = (const struct sockaddr_in *)rav; @@ -714,7 +717,7 @@ stream_accept(evContext lev, void *uap, int rfd, #ifndef CANNOT_SET_SNDBUF if (setsockopt(rfd, SOL_SOCKET, SO_SNDBUF, - (char*)&sbufsize, sizeof sbufsize) < 0) { + (const char*)&sbufsize, sizeof sbufsize) < 0) { ns_info(ns_log_default, "setsockopt(rfd, SO_SNDBUF, %d): %s", sbufsize, strerror(errno)); (void) close(rfd); @@ -722,13 +725,21 @@ stream_accept(evContext lev, void *uap, int rfd, } #endif if (setsockopt(rfd, SOL_SOCKET, SO_KEEPALIVE, - (char *)&on, sizeof on) < 0) { + (const char *)&on, sizeof on) < 0) { ns_info(ns_log_default, "setsockopt(rfd, KEEPALIVE): %s", strerror(errno)); (void) close(rfd); return; } +#ifdef USE_FIONBIO_IOCTL + if (ioctl(ifp->dfd, FIONBIO, (char *) &on) == -1) { + ns_info(ns_log_default, "ioctl(rfd, FIONBIO): %s", + strerror(errno)); + (void) close(rfd); + return; + } +#else if ((n = fcntl(rfd, F_GETFL, 0)) == -1) { ns_info(ns_log_default, "fcntl(rfd, F_GETFL): %s", strerror(errno)); @@ -741,6 +752,7 @@ stream_accept(evContext lev, void *uap, int rfd, (void) close(rfd); return; } +#endif /* * We don't like IP options. Turn them off if the connection came in @@ -830,6 +842,12 @@ tcp_send(struct qinfo *qp) { sq_remove(sp); return (SERVFAIL); } +#ifdef USE_FIONBIO_IOCTL + if (ioctl(sp->s_rfd, FIONBIO, (char *) &on) == -1) { + sq_remove(sp); + return (SERVFAIL); + } +#else if ((n = fcntl(sp->s_rfd, F_GETFL, 0)) == -1) { sq_remove(sp); return (SERVFAIL); @@ -838,6 +856,7 @@ tcp_send(struct qinfo *qp) { sq_remove(sp); return (SERVFAIL); } +#endif if (sq_openw(sp, qp->q_msglen + INT16SZ) == -1) { sq_remove(sp); return (SERVFAIL); @@ -872,6 +891,12 @@ stream_send(evContext lev, void *uap, int fd, const void *la, int lalen, const void *ra, int ralen) { struct qstream *sp = uap; + UNUSED(lev); + UNUSED(la); + UNUSED(lalen); + UNUSED(ra); + UNUSED(ralen); + ns_debug(ns_log_default, 1, "stream_send"); sp->flags &= ~STREAM_CONNECT_EV; @@ -923,6 +948,8 @@ stream_getlen(evContext lev, void *uap, int fd, int bytes) { struct qstream *sp = uap; struct iovec iov; + UNUSED(fd); + sp->flags &= ~STREAM_READ_EV; if (bytes != INT16SZ) { /* @@ -979,7 +1006,7 @@ stream_getlen(evContext lev, void *uap, int fd, int bytes) { if (evRead(lev, sp->s_rfd, &iov, 1, stream_getmsg, sp, &sp->evID_r) == -1) ns_panic(ns_log_default, 1, "evRead(fd %d): %s", - (void *)sp->s_rfd, strerror(errno)); + sp->s_rfd, strerror(errno)); sp->flags |= STREAM_READ_EV; } @@ -987,6 +1014,9 @@ static void stream_getmsg(evContext lev, void *uap, int fd, int bytes) { struct qstream *sp = uap; + UNUSED(lev); + UNUSED(fd); + sp->flags &= ~STREAM_READ_EV; if (bytes == -1) { ns_info(ns_log_default, "stream_getmsg(%s): %s", @@ -999,8 +1029,10 @@ stream_getmsg(evContext lev, void *uap, int fd, int bytes) { sp->s_time = tt.tv_sec; if (ns_wouldlog(ns_log_default,5)) { - ns_debug(ns_log_default, 5, "sp %#x rfd %d size %d time %d next %#x", - sp, sp->s_rfd, sp->s_size, sp->s_time, sp->s_next); + ns_debug(ns_log_default, 5, + "sp %p rfd %d size %d time %ld next %p", + sp, sp->s_rfd, sp->s_size, (long)sp->s_time, + sp->s_next); ns_debug(ns_log_default, 5, "\tbufsize %d bytes %d", sp->s_bufsize, bytes); } @@ -1034,13 +1066,16 @@ static void datagram_read(evContext lev, void *uap, int fd, int evmask) { interface *ifp = uap; struct sockaddr_in from; - int from_len = sizeof from; + ISC_SOCKLEN_T from_len = sizeof from; int n, nudp; union { HEADER h; /* Force alignment of 'buf'. */ - u_char buf[PACKETSZ+1]; + u_char buf[EDNS_MESSAGE_SZ+1]; } u; + UNUSED(lev); + UNUSED(evmask); + tt = evTimeVal(evNowTime()); nudp = 0; @@ -1088,16 +1123,16 @@ datagram_read(evContext lev, void *uap, int fd, int evmask) { sin_ntoa(from), fd, n); } - if (n > PACKETSZ) { + if (n > EDNS_MESSAGE_SZ) { /* * The message is too big. It's probably a response to * one of our questions, so we truncate it and press on. */ - n = trunc_adjust(u.buf, PACKETSZ, PACKETSZ); + n = trunc_adjust(u.buf, EDNS_MESSAGE_SZ, EDNS_MESSAGE_SZ); ns_debug(ns_log_default, 1, "truncated oversize UDP packet"); } - dispatch_message(u.buf, n, PACKETSZ, NULL, from, fd, ifp); + dispatch_message(u.buf, n, EDNS_MESSAGE_SZ, NULL, from, fd, ifp); if (++nudp < nudptrans) goto more; } @@ -1106,8 +1141,11 @@ static void savedg_waitfunc(evContext ctx, void *uap, const void *tag) { savedg *dg = (savedg *)uap; + UNUSED(ctx); + UNUSED(tag); + if (!EMPTY(iflist) && HEAD(iflist)->gen == dg->gen) { - u_char buf[PACKETSZ]; + u_char buf[EDNS_MESSAGE_SZ]; memcpy(buf, dg->buf, dg->buflen); dispatch_message(buf, dg->buflen, sizeof buf, NULL, @@ -1222,8 +1260,7 @@ getnetconf(int periodic_scan) { for (;;) { buf = memget(bufsiz); if (!buf) - ns_panic(ns_log_default, 1, - "memget(interface)", NULL); + ns_panic(ns_log_default, 1, "memget(interface)"); ifc.ifc_len = bufsiz; ifc.ifc_buf = buf; #ifdef IRIX_EMUL_IOCTL_SIOCGIFCONF @@ -1244,7 +1281,7 @@ getnetconf(int periodic_scan) { * buffer we will grow it just in case and * retry. */ - if (ifc.ifc_len + 2 * sizeof(ifreq) < bufsiz) + if ((int)(ifc.ifc_len + 2 * sizeof(ifreq)) < bufsiz) break; } #endif @@ -1345,7 +1382,7 @@ getnetconf(int periodic_scan) { ifp = (interface *)memget(sizeof *ifp); if (!ifp) ns_panic(ns_log_default, 1, - "memget(interface)", NULL); + "memget(interface)"); memset(ifp, 0, sizeof *ifp); INIT_LINK(ifp, link); APPEND(iflist, ifp, link); @@ -1491,8 +1528,8 @@ static int opensocket_d(interface *ifp) { struct sockaddr_in nsa; const int on = 1; - int m, n; - int fd; + ISC_SOCKLEN_T m; + int n; memset(&nsa, 0, sizeof nsa); nsa.sin_family = AF_INET; @@ -1509,6 +1546,14 @@ opensocket_d(interface *ifp) { close(ifp->dfd); return (-1); } +#ifdef USE_FIONBIO_IOCTL + if (ioctl(ifp->dfd, FIONBIO, (char *) &on) == -1) { + ns_info(ns_log_default, "ioctl(ifp->dfd, FIONBIO): %s", + strerror(errno)); + (void) close(ifp->dfd); + return (-1); + } +#else if ((n = fcntl(ifp->dfd, F_GETFL, 0)) == -1) { ns_info(ns_log_default, "fcntl(ifp->dfd, F_GETFL): %s", strerror(errno)); @@ -1521,6 +1566,7 @@ opensocket_d(interface *ifp) { (void) close(ifp->dfd); return (-1); } +#endif if (fcntl(ifp->dfd, F_SETFD, 1) < 0) { ns_error(ns_log_default, "F_SETFD: %s", strerror(errno)); close(ifp->dfd); @@ -1529,7 +1575,7 @@ opensocket_d(interface *ifp) { ns_debug(ns_log_default, 1, "ifp->addr %s d_dfd %d", sin_ntoa(nsa), ifp->dfd); if (setsockopt(ifp->dfd, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof(on)) != 0) { + (const char *)&on, sizeof(on)) != 0) { ns_notice(ns_log_default, "setsockopt(REUSEADDR): %s", strerror(errno)); /* XXX press on regardless, this is not too serious. */ @@ -1540,12 +1586,12 @@ opensocket_d(interface *ifp) { && (m == sizeof n) && (n < drbufsize)) { (void) setsockopt(ifp->dfd, SOL_SOCKET, SO_RCVBUF, - (char *)&drbufsize, sizeof drbufsize); + (const char *)&drbufsize, sizeof drbufsize); } #endif /* SO_RCVBUF */ #ifndef CANNOT_SET_SNDBUF if (setsockopt(ifp->dfd, SOL_SOCKET, SO_SNDBUF, - (char*)&dsbufsize, sizeof dsbufsize) < 0) { + (const char*)&dsbufsize, sizeof dsbufsize) < 0) { ns_info(ns_log_default, "setsockopt(dfd=%d, SO_SNDBUF, %d): %s", ifp->dfd, dsbufsize, strerror(errno)); @@ -1583,10 +1629,10 @@ drain_rcvbuf(evContext ctx, interface *ifp, int fd, int *mread, int *mstore) { for (; *mread > 0; (*mread)--) { union { HEADER h; - u_char buf[PACKETSZ+1]; + u_char buf[EDNS_MESSAGE_SZ+1]; } u; struct sockaddr_in from; - int from_len = sizeof from; + ISC_SOCKLEN_T from_len = sizeof from; savedg *dg; int n; @@ -1595,7 +1641,7 @@ drain_rcvbuf(evContext ctx, interface *ifp, int fd, int *mread, int *mstore) { if (n <= 0) break; /* Socket buffer assumed empty. */ drop++; /* Pessimistic assumption. */ - if (n > PACKETSZ) + if (n > EDNS_MESSAGE_SZ) continue; /* Oversize message - EDNS0 needed. */ if (from.sin_family != AF_INET) continue; /* Not IPv4 - IPv6 needed. */ @@ -1655,7 +1701,6 @@ opensocket_s(interface *ifp) { struct sockaddr_in nsa; const int on = 1; int n; - int fd; memset(&nsa, 0, sizeof nsa); nsa.sin_family = AF_INET; @@ -1683,7 +1728,7 @@ opensocket_s(interface *ifp) { return (-1); } if (setsockopt(ifp->sfd, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof on) != 0) { + (const char *)&on, sizeof on) != 0) { ns_notice(ns_log_default, "setsockopt(REUSEADDR): %s", strerror(errno)); /* Consider that your first warning of trouble to come. */ @@ -1728,7 +1773,8 @@ opensocket_f() { static interface *prev_ifp; struct sockaddr_in nsa; const int on = 1; - int n, need_close; + ISC_SOCKLEN_T n; + int need_close; interface *ifp; need_close = 0; @@ -1786,7 +1832,7 @@ opensocket_f() { if (fcntl(ds, F_SETFD, 1) < 0) ns_panic(ns_log_default, 1, "F_SETFD: %s", strerror(errno)); if (setsockopt(ds, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof on) != 0) { + (const char *)&on, sizeof on) != 0) { ns_notice(ns_log_default, "setsockopt(REUSEADDR): %s", strerror(errno)); /* XXX press on regardless, this is not too serious. */ @@ -1816,7 +1862,7 @@ opensocket_f() { if (evSelectFD(ev, ds, EV_READ, datagram_read, NULL, &ds_evID) == -1) ns_panic(ns_log_default, 1, "evSelectFD(fd %d): %s", - (void *)ds, strerror(errno)); + ds, strerror(errno)); /* XXX: should probably use a different FileFunc that only accepts * responses, since requests on this socket make no sense. */ @@ -1833,6 +1879,8 @@ setdebug(int new_debug) { debug = new_debug; log_option(log_ctx, LOG_OPTION_DEBUG, debug); log_option(log_ctx, LOG_OPTION_LEVEL, debug); + if (old_debug && !debug) + log_close_debug_channels(log_ctx); evSetDebug(ev, debug, log_get_stream(eventlib_channel)); if (debug) { if (!old_debug) @@ -2017,6 +2065,8 @@ static void sq_writable(evContext ctx, void *uap, int fd, int evmask) { struct qstream *qs = uap; + UNUSED(ctx); + INSIST(evmask & EV_WRITE); INSIST(fd == qs->s_rfd); if (sq_dowrite(qs) < 0) { @@ -2118,7 +2168,7 @@ sq_done(struct qstream *sp) { if (evRead(ev, sp->s_rfd, &iov, 1, stream_getlen, sp, &sp->evID_r) == -1) ns_panic(ns_log_default, 1, "evRead(fd %d): %s", - (void *)sp->s_rfd, strerror(errno)); + sp->s_rfd, strerror(errno)); sp->flags |= STREAM_READ_EV; } @@ -2359,7 +2409,7 @@ nsid_hash(u_char *data, size_t len) { * fast. */ while (len-- > 0) { - HASHROTATE(nsid_hash_state); + nsid_hash_state = HASHROTATE(nsid_hash_state); nsid_hash_state += *data++; } } @@ -2566,8 +2616,7 @@ nsid_init(void) { nsid_vtable = memget(NSID_SHUFFLE_TABLE_SIZE * (sizeof(u_int16_t)) ); if (!nsid_vtable) - ns_panic(ns_log_default, 1, "memget(nsid_vtable)", - NULL); + ns_panic(ns_log_default, 1, "memget(nsid_vtable)"); for (i = 0; i < NSID_SHUFFLE_TABLE_SIZE; i++) { nsid_vtable[i] = nsid_state; nsid_state = (((u_long) nsid_a1 * nsid_state) + nsid_c1) @@ -2579,7 +2628,7 @@ nsid_init(void) { nsid_algorithm = NSID_USE_POOL; nsid_pool = memget(0x10000 * (sizeof(u_int16_t))); if (!nsid_pool) - ns_panic(ns_log_default, 1, "memget(nsid_pool)", NULL); + ns_panic(ns_log_default, 1, "memget(nsid_pool)"); for (i = 0; ; i++) { nsid_pool[i] = nsid_state; nsid_state = (((u_long) nsid_a1 * nsid_state) + nsid_c1) & 0xFFFF; @@ -2632,8 +2681,10 @@ nsid_next() { nsid_state = 0; else nsid_state++; - } else - ns_panic(ns_log_default, 1, "Unknown ID algorithm", NULL); + } else { + id = 0; /* silence compiler */ + ns_panic(ns_log_default, 1, "Unknown ID algorithm"); + } /* Now lets obfuscate ... */ id = (((u_long) nsid_a2 * id) + nsid_c2) & 0xFFFF; @@ -2682,11 +2733,17 @@ deallocate_everything(void) { if (nsid_pool != NULL) memput(nsid_pool, 0x10000 * (sizeof(u_int16_t))); nsid_pool = NULL; + if (nsid_vtable != NULL) + memput(nsid_vtable, NSID_SHUFFLE_TABLE_SIZE * + (sizeof(u_int16_t))); + nsid_vtable = NULL; irs_destroy(); if (f != NULL) { memstats(f); (void)fclose(f); } + if (memactive()) + abort(); } static void @@ -2753,7 +2810,7 @@ toggle_qrylog(void) { static void wild(void) { - ns_panic(ns_log_default, 1, "wild need", NULL); + ns_panic(ns_log_default, 1, "wild need"); } /* @@ -2803,7 +2860,7 @@ handle_needs(void) { INSIST_ERR(evDo(ev, (void *)handle_needs) != -1); return; } - ns_panic(ns_log_default, 1, "ns_handle_needs: queued == 0", NULL); + ns_panic(ns_log_default, 1, "ns_handle_needs: queued == 0"); } static void @@ -2812,6 +2869,8 @@ need_waitfunc(evContext ctx, void *uap, const void *tag) { time_t begin; long syncdelay; + UNUSED(tag); + begin = time(NULL); (*hand)(); syncdelay = time(NULL) - begin; diff --git a/contrib/bind/bin/named/ns_maint.c b/contrib/bind/bin/named/ns_maint.c index 8220e51242ca..0408936ef4e0 100644 --- a/contrib/bind/bin/named/ns_maint.c +++ b/contrib/bind/bin/named/ns_maint.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_maint.c 4.39 (Berkeley) 3/2/91"; -static const char rcsid[] = "$Id: ns_maint.c,v 8.122.2.4 2001/08/10 03:00:11 marka Exp $"; +static const char rcsid[] = "$Id: ns_maint.c,v 8.131 2001/11/12 04:49:32 marka Exp $"; #endif /* not lint */ /* @@ -267,11 +267,8 @@ zone_maint(struct zoneinfo *zp) { break; } - /* - * It is essential that we never try to set a timer in the past - * or for now because doing so could cause an infinite loop. - */ - INSIST(zp->z_time == 0 || zp->z_time > tt.tv_sec); + if (zp->z_time != 0 && zp->z_time < tt.tv_sec) + zp->z_time = tt.tv_sec; sched_zone_maint(zp); } @@ -282,6 +279,10 @@ do_zone_maint(evContext ctx, void *uap, struct timespec due, ztimer_info zti = uap; struct zoneinfo *zp; + UNUSED(ctx); + UNUSED(due); + UNUSED(inter); + INSIST(zti != NULL); ns_debug(ns_log_maint, 1, "do_zone_maint for zone %s (class %s)", @@ -403,6 +404,10 @@ ns_cleancache(evContext ctx, void *uap, { int deleted; + UNUSED(ctx); + UNUSED(due); + UNUSED(inter); + gettime(&tt); INSIST(uap == NULL); deleted = clean_cache(hashtab, 0); @@ -416,6 +421,10 @@ ns_heartbeat(evContext ctx, void *uap, struct timespec due, { struct zoneinfo *zp; + UNUSED(ctx); + UNUSED(due); + UNUSED(inter); + gettime(&tt); INSIST(uap == NULL); @@ -515,9 +524,9 @@ qserial_query(struct zoneinfo *zp) { } qp = sysquery(zp->z_origin, zp->z_class, T_SOA, - zp->z_addr, zp->z_addrcnt, + zp->z_addr, zp->z_keys, zp->z_addrcnt, ntohs(zp->z_port) ? zp->z_port : ns_port, - QUERY); + QUERY, 0); if (qp == NULL) { ns_debug(ns_log_default, 1, "qserial_query(%s): sysquery FAILED", @@ -572,7 +581,7 @@ qserial_answer(struct qinfo *qp) { qs = &qp->q_addr[n]; ns_debug(ns_log_default, 1, "qserial_answer(%s): [%s] -> %lu", zp->z_origin, inet_ntoa(qs->ns_addr.sin_addr), - qs->serial); + (unsigned long)qs->serial); /* Don't consider serials which weren't set by a response. */ if (qs->serial == 0) continue; @@ -607,7 +616,7 @@ qserial_answer(struct qinfo *qp) { ns_debug(ns_log_default, 1, "qserial_answer after sort: [%s] -> %lu", inet_ntoa(qs->ns_addr.sin_addr), - qs->serial); + (unsigned long)qs->serial); } } @@ -647,18 +656,28 @@ qserial_answer(struct qinfo *qp) { * 1: Tsig info successfully written. */ static int -write_tsig_info(struct in_addr addr, char *name, int *fd) { +write_tsig_info(struct zoneinfo *zp, struct in_addr addr, char *name, int *fd) { server_info si; - DST_KEY *dst_key; + DST_KEY *dst_key = NULL; int tsig_fd = *fd; char tsig_str[1024], secret_buf64[172]; u_char secret_buf[128]; int secret_len, len; + int i; - si = find_server(addr); - if (si == NULL || si->key_list == NULL || si->key_list->first == NULL) - return(0); - dst_key = si->key_list->first->key; + for (i = 0; i < zp->z_addrcnt ; i++) + if (memcmp(&addr, &zp->z_addr[i], sizeof(addr)) == 0) { + dst_key = zp->z_keys[i]; + break; + } + + if (dst_key == NULL) { + si = find_server(addr); + if (si == NULL || si->key_list == NULL || + si->key_list->first == NULL) + return(0); + dst_key = si->key_list->first->key; + } if (tsig_fd == -1) { *fd = tsig_fd = mkstemp(name); if (tsig_fd < 0) { @@ -679,7 +698,7 @@ write_tsig_info(struct in_addr addr, char *name, int *fd) { if (len == -1) return (-1); /* We need snprintf! */ - if (strlen(dst_key->dk_key_name) + len + sizeof("XXX.XXX.XXX.XXX"), + if (strlen(dst_key->dk_key_name) + len + sizeof("XXX.XXX.XXX.XXX") + sizeof("123") + 5 > sizeof(tsig_str)) return (-1); sprintf(tsig_str, "%s\n%s\n%d\n%s\n", @@ -707,7 +726,7 @@ write_tsigs(struct zoneinfo *zp, char *tsig_name) { if (aIsUs(a) && ns_port == zp->z_port) continue; - tsig_ret = write_tsig_info(a, tsig_name, &tsig_fd); + tsig_ret = write_tsig_info(zp, a, tsig_name, &tsig_fd); switch (tsig_ret) { case -1: goto error; @@ -757,7 +776,8 @@ supports_ixfr(struct zoneinfo *zp) { */ static void startxfer(struct zoneinfo *zp) { - char *argv[NSMAX*2 + 20], argv_ns[NSMAX][MAXDNAME]; + char *argv[NSMAX*2 + 20]; + char argv_ns[NSMAX][MAXDNAME]; int argc = 0, argc_ns = 0, i; pid_t pid; u_int cnt; @@ -773,50 +793,50 @@ startxfer(struct zoneinfo *zp) { zp->z_origin[0] != '\0' ? zp->z_origin : "."); argv[argc++] = server_options->named_xfer; - argv[argc++] = "-z"; - argv[argc++] = zp->z_origin; - argv[argc++] = "-f"; + DE_CONST("-z", argv[argc++]); + DE_CONST(*zp->z_origin ? zp->z_origin : ".", argv[argc++]); + DE_CONST("-f", argv[argc++]); argv[argc++] = zp->z_source; #ifdef BIND_IXFR if (supports_ixfr(zp) && zp->z_ixfr_tmp != NULL) { - argv[argc++] = "-i"; + DE_CONST("-i", argv[argc++]); argv[argc++] = zp->z_ixfr_tmp; } #endif if (zp->z_serial != 0) { - argv[argc++] = "-s"; + DE_CONST("-s", argv[argc++]); sprintf(serial_str, "%u", zp->z_serial); argv[argc++] = serial_str; } if (zp->z_axfr_src.s_addr != 0 || server_options->axfr_src.s_addr != 0) { - argv[argc++] = "-x"; + DE_CONST("-x", argv[argc++]); argv[argc++] = strcpy(src_str, inet_ntoa( (zp->z_axfr_src.s_addr != 0) ? zp->z_axfr_src : server_options->axfr_src)); } - argv[argc++] = "-C"; + DE_CONST("-C", argv[argc++]); sprintf(class_str, "%d", zp->z_class); argv[argc++] = class_str; if (zp->z_flags & Z_SYSLOGGED) - argv[argc++] = "-q"; - argv[argc++] = "-P"; + DE_CONST("-q", argv[argc++]); + DE_CONST("-P", argv[argc++]); sprintf(port_str, "%d", ntohs(zp->z_port) != 0 ? zp->z_port : ns_port); argv[argc++] = port_str; #ifdef STUBS if (zp->z_type == Z_STUB) - argv[argc++] = "-S"; + DE_CONST("-S", argv[argc++]); #endif #ifdef DEBUG if (debug) { - argv[argc++] = "-d"; + DE_CONST("-d", argv[argc++]); sprintf(debug_str, "%d", debug); argv[argc++] = debug_str; - argv[argc++] = "-l"; - argv[argc++] = _PATH_XFERDDT; + DE_CONST("-l", argv[argc++]); + DE_CONST(_PATH_XFERDDT, argv[argc++]); if (debug > 5) { - argv[argc++] = "-t"; - argv[argc++] = _PATH_XFERTRACE; + DE_CONST("-t", argv[argc++]); + DE_CONST(_PATH_XFERTRACE, argv[argc++]); } } #endif @@ -840,7 +860,7 @@ startxfer(struct zoneinfo *zp) { return; } if (tsig_ret != 0) { - argv[argc++] = "-T"; + DE_CONST("-T", argv[argc++]); argv[argc++] = tsig_name; } @@ -867,9 +887,9 @@ startxfer(struct zoneinfo *zp) { if (si != NULL && (si->flags & SERVER_INFO_SUPPORT_IXFR) != 0) - argv[argc++] = "ixfr"; + DE_CONST("ixfr", argv[argc++]); else - argv[argc++] = "axfr"; + DE_CONST("axfr", argv[argc++]); } #endif } @@ -985,8 +1005,9 @@ printzoneinfo(int zonenum, int category, int level) { if (zp->z_type == z_master && (zp->z_flags & Z_DYNAMIC) != 0) { ns_debug(category, level, "\tdumpintvl %lu, soaincrintvl %lu deferupdcnt %lu", - zp->z_dumpintvl, zp->z_soaincrintvl, - zp->z_deferupdcnt); + (unsigned long)zp->z_dumpintvl, + (unsigned long)zp->z_soaincrintvl, + (unsigned long)zp->z_deferupdcnt); if (zp->z_soaincrtime) ns_debug(category, level, "\tz_soaincrtime %lu (now %lu, left: %lu)", @@ -1240,9 +1261,8 @@ valid_glue(struct databuf *dp, char *name, int belowcut) { ns_samedomain((char*)dp->d_data, zones[dp->d_zone].z_origin)) return (1); - /* NOKEY is in parent zone otherwise child zone */ - if (dp->d_type == T_KEY && dp->d_size == 4 && - (dp->d_data[0] & 0xc3) == 0xc1) + /* KEY RRset may be in the parent */ + if (dp->d_type == T_KEY) return (1); /* NXT & KEY records may be signed */ @@ -1593,10 +1613,11 @@ endxfer() { zp->z_xferpid = XFER_ISAXFR; if (exitstatus == XFER_SUCCESSAXFRIXFRFILE) { zp->z_xferpid = XFER_ISAXFRIXFR; + if (zp->z_ixfr_tmp != NULL) + isc_movefile( + zp->z_ixfr_tmp, + zp->z_source); } - if (zp->z_ixfr_tmp != NULL) - isc_movefile(zp->z_ixfr_tmp, - zp->z_source); /* XXX should incorporate loadxfer() */ zp->z_flags |= Z_NEED_RELOAD; zp->z_flags &= ~Z_SYSLOGGED; diff --git a/contrib/bind/bin/named/ns_ncache.c b/contrib/bind/bin/named/ns_ncache.c index 2b8bb6bd7788..5667f367f935 100644 --- a/contrib/bind/bin/named/ns_ncache.c +++ b/contrib/bind/bin/named/ns_ncache.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_ncache.c,v 8.27 2000/04/21 06:54:09 vixie Exp $"; +static const char rcsid[] = "$Id: ns_ncache.c,v 8.29 2001/06/18 14:43:16 marka Exp $"; #endif /* not lint */ /* @@ -121,7 +121,7 @@ cache_n_resp(u_char *msg, int msglen, struct sockaddr_in from, while (ancount--) { u_int32_t ttl; - u_int atype, aclass; + int atype, aclass; n = dn_skipname(cp, eom); if (n < 0) { @@ -257,14 +257,14 @@ cache_n_resp(u_char *msg, int msglen, struct sockaddr_in from, flags = DB_NOTAUTH|DB_NOHINTS; } - if ((n = db_update(dname, dp, dp, NULL, flags, hashtab, from)) != OK) { + n = db_update(dname, dp, dp, NULL, flags, hashtab, from); + if (n != OK) ns_debug(ns_log_ncache, 1, "db_update failed (%d), cache_n_resp()", n); - db_freedata(dp); - return; - } - ns_debug(ns_log_ncache, 4, - "ncache succeeded: [%s %s %s] rcode:%d ttl:%ld", - dname, p_type(type), p_class(class), - dp->d_rcode, (long)(dp->d_ttl - tt.tv_sec)); + else + ns_debug(ns_log_ncache, 4, + "ncache succeeded: [%s %s %s] rcode:%d ttl:%ld", + dname, p_type(type), p_class(class), + dp->d_rcode, (long)(dp->d_ttl - tt.tv_sec)); + db_detach(&dp); } diff --git a/contrib/bind/bin/named/ns_notify.c b/contrib/bind/bin/named/ns_notify.c index 20fd700abac7..cde636a60488 100644 --- a/contrib/bind/bin/named/ns_notify.c +++ b/contrib/bind/bin/named/ns_notify.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_notify.c,v 8.14 2001/04/01 18:38:36 vixie Exp $"; +static const char rcsid[] = "$Id: ns_notify.c,v 8.18 2001/11/12 04:49:33 marka Exp $"; #endif /* not lint */ /* @@ -146,7 +146,7 @@ ns_notify(const char *dname, ns_class class, ns_type type) { evConsTime(0, 0), &ni->timer) < 0) { ns_error(ns_log_notify, "evSetTimer() failed: %s", strerror(errno)); - freestr(ni->name); + ni->name = freestr(ni->name); memput(ni, sizeof *ni); return; } @@ -168,7 +168,7 @@ notify_afterload() { while ((ni = HEAD(loading_notifies)) != NULL) { UNLINK(loading_notifies, ni, link); ns_notify(ni->name, ni->class, ni->type); - freestr(ni->name); + ni->name = freestr(ni->name); memput(ni, sizeof *ni); } } @@ -262,8 +262,8 @@ sysnotify(const char *dname, ns_class class, ns_type type) { for (i = 0; i < zp->z_notify_count; i++) { ns_debug(ns_log_notify, 4, "notifying %s", inet_ntoa(*also_addr)); - sysquery(dname, class, type, also_addr, 1, ns_port, - NS_NOTIFY_OP); + sysquery(dname, class, type, also_addr, NULL, 1, + ns_port, NS_NOTIFY_OP, 0); also_addr++; } nns += zp->z_notify_count; @@ -275,8 +275,8 @@ sysnotify(const char *dname, ns_class class, ns_type type) { for (i = 0; i < server_options->notify_count; i++) { ns_debug(ns_log_notify, 3, "notifying %s", inet_ntoa(*also_addr)); - sysquery(dname, class, type, also_addr, - 1, ns_port, ns_o_notify); + sysquery(dname, class, type, also_addr, NULL, 1, + ns_port, ns_o_notify, 0); also_addr++; } nns += server_options->notify_count; @@ -387,14 +387,14 @@ sysnotify_ns(const char *dname, const char *aname, if (!is_us && !cname && !NS_OPTION_P(OPTION_NOFETCHGLUE)) { struct qinfo *qp; - qp = sysquery(aname, class, ns_t_a, 0, 0, ns_port, - ns_o_query); + qp = sysquery(aname, class, ns_t_a, NULL, NULL, 0, + ns_port, ns_o_query, 0); if (qp != NULL) qp->q_notifyzone = zn; } return; } - sysquery(dname, class, type, nss, nsc, ns_port, ns_o_notify); + sysquery(dname, class, type, nss, NULL, nsc, ns_port, ns_o_notify, 0); (*nns)++; *na += nsc; } @@ -413,7 +413,7 @@ free_notify(struct notify *ni) { evClearTimer(ev, ni->timer); evInitID(&ni->timer); } - freestr(ni->name); + ni->name = freestr(ni->name); memput(ni, sizeof *ni); } @@ -424,6 +424,10 @@ notify_timer(evContext ctx, void *uap, { struct notify *ni = uap; + UNUSED(ctx); + UNUSED(due); + UNUSED(inter); + INSIST(evTestID(ni->timer)); evInitID(&ni->timer); INSIST(LINKED(ni, link)); diff --git a/contrib/bind/bin/named/ns_parser.y b/contrib/bind/bin/named/ns_parser.y index ed49549a20a3..0fe9dc78cfe0 100644 --- a/contrib/bind/bin/named/ns_parser.y +++ b/contrib/bind/bin/named/ns_parser.y @@ -1,6 +1,6 @@ %{ #if !defined(lint) && !defined(SABER) -static char rcsid[] = "$Id: ns_parser.y,v 8.63.2.4 2001/04/30 08:03:02 marka Exp $"; +static char rcsid[] = "$Id: ns_parser.y,v 8.78 2001/12/28 04:07:48 marka Exp $"; #endif /* not lint */ /* @@ -65,6 +65,7 @@ static symbol_table symtab; #define AUTH_TABLE_SIZE 397 /* should always be prime */ static symbol_table authtab = NULL; +static symbol_table channeltab = NULL; static zone_config current_zone; static int should_install; @@ -94,7 +95,7 @@ static int chan_versions; static u_long chan_max_size; static log_channel lookup_channel(char *); -static void define_channel(char *, log_channel); +static void define_channel(const char *, log_channel); static char *canonical_name(char *); int yyparse(); @@ -132,7 +133,7 @@ int yyparse(); %token T_DIRECTORY T_PIDFILE T_NAMED_XFER %token T_DUMP_FILE T_STATS_FILE T_MEMSTATS_FILE %token T_FAKE_IQUERY T_RECURSION T_FETCH_GLUE -%token T_HITCOUNT +%token T_HITCOUNT T_PREFERRED_GLUE %token T_QUERY_SOURCE T_LISTEN_ON T_PORT T_ADDRESS %token T_RRSET_ORDER T_ORDER T_NAME T_CLASS %token T_CONTROLS T_INET T_UNIX T_PERM T_OWNER T_GROUP T_ALLOW @@ -143,14 +144,16 @@ int yyparse(); %type maybe_wild_addr %token T_DATASIZE T_STACKSIZE T_CORESIZE %token T_DEFAULT T_UNLIMITED -%token T_FILES T_VERSION +%token T_FILES T_VERSION T_HOSTNAME %token T_HOSTSTATS T_HOSTSTATSMAX T_DEALLOC_ON_EXIT %token T_TRANSFERS_IN T_TRANSFERS_OUT T_TRANSFERS_PER_NS %token T_TRANSFER_FORMAT T_MAX_TRANSFER_TIME_IN %token T_SERIAL_QUERIES T_ONE_ANSWER T_MANY_ANSWERS %type transfer_format -%token T_NOTIFY T_AUTH_NXDOMAIN T_MULTIPLE_CNAMES T_USE_IXFR T_MAINTAIN_IXFR_BASE -%token T_CLEAN_INTERVAL T_INTERFACE_INTERVAL T_STATS_INTERVAL T_MAX_LOG_SIZE_IXFR +%token T_NOTIFY T_NOTIFY_INITIAL T_AUTH_NXDOMAIN +%token T_MULTIPLE_CNAMES T_USE_IXFR T_MAINTAIN_IXFR_BASE +%token T_CLEAN_INTERVAL T_INTERFACE_INTERVAL T_STATS_INTERVAL +%token T_MAX_LOG_SIZE_IXFR %token T_HEARTBEAT T_USE_ID_POOL %token T_MAX_NCACHE_TTL T_HAS_OLD_CLIENTS T_RFC2308_TYPE1 %token T_LAME_TTL T_MIN_ROOTS @@ -268,7 +271,7 @@ statement: include_stmt include_stmt: T_INCLUDE L_QSTRING L_EOS { lexer_begin_file($2, NULL); - freestr($2); + (void)freestr($2); } ; @@ -298,48 +301,59 @@ options: option L_EOS ; option: /* Empty */ + | T_HOSTNAME L_QSTRING + { + if (current_options->hostname != NULL) + (void)freestr(current_options->hostname); + current_options->hostname = $2; + } | T_VERSION L_QSTRING { if (current_options->version != NULL) - freestr(current_options->version); + (void)freestr(current_options->version); current_options->version = $2; } | T_DIRECTORY L_QSTRING { if (current_options->directory != NULL) - freestr(current_options->directory); + (void)freestr(current_options->directory); current_options->directory = $2; } | T_NAMED_XFER L_QSTRING { if (current_options->named_xfer != NULL) - freestr(current_options->named_xfer); + (void)freestr(current_options->named_xfer); current_options->named_xfer = $2; } | T_PIDFILE L_QSTRING { if (current_options->pid_filename != NULL) - freestr(current_options->pid_filename); + (void)freestr(current_options->pid_filename); current_options->pid_filename = $2; } | T_STATS_FILE L_QSTRING { if (current_options->stats_filename != NULL) - freestr(current_options->stats_filename); + (void)freestr(current_options->stats_filename); current_options->stats_filename = $2; } | T_MEMSTATS_FILE L_QSTRING { if (current_options->memstats_filename != NULL) - freestr(current_options->memstats_filename); + (void)freestr(current_options->memstats_filename); current_options->memstats_filename = $2; } | T_DUMP_FILE L_QSTRING { if (current_options->dump_filename != NULL) - freestr(current_options->dump_filename); + (void)freestr(current_options->dump_filename); current_options->dump_filename = $2; } + | T_PREFERRED_GLUE L_STRING + { + current_options->preferred_glue = + strcasecmp($2, "aaaa") ? T_A : T_AAAA; + } | T_FAKE_IQUERY yea_or_nay { set_global_boolean_option(current_options, @@ -365,6 +379,14 @@ option: /* Empty */ set_global_boolean_option(current_options, OPTION_NONOTIFY, !$2); } + | T_NOTIFY_INITIAL yea_or_nay + { + if (initial_configuration && $2) + ns_notice(ns_log_default, + "suppressing initial notifies"); + set_global_boolean_option(current_options, + OPTION_SUPNOTIFY_INITIAL, $2); + } | T_HOSTSTATS yea_or_nay { set_global_boolean_option(current_options, @@ -428,8 +450,7 @@ option: /* Empty */ else { add_listen_on(current_options, $2, $4); value.pointer = NULL; - define_symbol(symtab, savestr(port_string, 1), - SYM_PORT, value, SYMBOL_FREE_KEY); + define_symbol(symtab, port_string, SYM_PORT, value, 0); } } @@ -600,6 +621,20 @@ control: /* Empty */ { ns_ctl_add(¤t_controls, ns_ctl_new_inet($2, $4, $7)); } + | T_INET maybe_wild_addr + T_ALLOW '{' address_match_list '}' + T_KEYS '{' dummy_key_list '}' + { + parser_warning(0, "Ignoring BIND 9 inet control clause"); + free_ip_match_list($5); + } + | T_INET maybe_wild_addr T_PORT in_port + T_ALLOW '{' address_match_list '}' + T_KEYS '{' dummy_key_list '}' + { + parser_warning(0, "Ignoring BIND 9 inet control clause"); + free_ip_match_list($7); + } | T_UNIX L_QSTRING T_PERM L_NUMBER T_OWNER L_NUMBER T_GROUP L_NUMBER { #ifndef NO_SOCKADDR_UN @@ -644,7 +679,7 @@ ordering_class: /* nothing */ parser_error(0, "unknown class '%s'; using ANY", $2); $$ = C_ANY; } - freestr($2); + (void)freestr($2); } ; @@ -667,7 +702,7 @@ ordering_type: /* nothing */ $2); } } - freestr($2); + (void)freestr($2); } ordering_name: /* nothing */ @@ -678,7 +713,7 @@ ordering_name: /* nothing */ { if (strcmp(".",$2) == 0 || strcmp("*.",$2) == 0) { $$ = savestr("*", 1); - freestr($2); + (void)freestr($2); } else { $$ = $2 ; } @@ -702,7 +737,7 @@ rrset_ordering_element: ordering_class ordering_type ordering_name T_ORDER L_STR $5, p_order(o)); } - freestr($5); + (void)freestr($5); $$ = new_rrset_order_element($1, $2, $3, o); } @@ -859,7 +894,7 @@ size_spec: any_string /* 0 means "use default" */ $$ = 0; } - freestr($1); + (void)freestr($1); } | L_NUMBER { @@ -966,7 +1001,6 @@ logging_opt: T_CATEGORY category if (lookup_channel($2) != NULL) { parser_error(0, "can't redefine channel '%s'", $2); - freestr($2); } else { switch (chan_type) { case log_file: @@ -978,8 +1012,7 @@ logging_opt: T_CATEGORY category chan_max_size); log_set_file_owner(current_channel, user_id, group_id); - freestr(chan_name); - chan_name = NULL; + chan_name = freestr(chan_name); break; case log_syslog: current_channel = @@ -1000,6 +1033,7 @@ logging_opt: T_CATEGORY category "couldn't create channel"); define_channel($2, current_channel); } + (void)freestr($2); } ; @@ -1013,7 +1047,7 @@ channel_severity: any_string parser_error(0, "unknown severity '%s'", $1); chan_level = log_debug(99); } - freestr($1); + (void)freestr($1); } | T_DEBUG { @@ -1087,7 +1121,7 @@ maybe_syslog_facility: /* nothing */ { $$ = LOG_DAEMON; } parser_error(0, "unknown facility '%s'", $1); $$ = LOG_DAEMON; } - freestr($1); + (void)freestr($1); } ; @@ -1149,7 +1183,7 @@ channel: channel_name } else parser_error(0, "unknown channel '%s'", $1); } - freestr($1); + (void)freestr($1); } ; @@ -1174,7 +1208,7 @@ category: category_name $1); $$ = -1; } - freestr($1); + (void)freestr($1); } ; @@ -1197,9 +1231,8 @@ server_stmt: T_SERVER L_IPADDR parser_error(0, "cannot redefine server '%s'", ip_printable); else - define_symbol(symtab, savestr(ip_printable, 1), - SYM_SERVER, value, - SYMBOL_FREE_KEY); + define_symbol(symtab, ip_printable, SYM_SERVER, value, + 0); current_server = begin_server($2); } '{' server_info_list '}' @@ -1279,6 +1312,7 @@ address_match_element: address_match_simple else $$ = new_ip_match_key(dst_key); (void)freestr(key_name); + freestr($2); } ; @@ -1329,7 +1363,7 @@ address_match_simple: L_IPADDR * we give it a name and treat it like any other acl. */ sprintf(name, "__internal_%p", $2); - define_acl(savestr(name, 1), $2); + define_acl(name, $2); $$ = new_ip_match_indirect($2); } ; @@ -1344,7 +1378,7 @@ address_name: any_string $$ = NULL; } else $$ = new_ip_match_indirect(iml); - freestr($1); + (void)freestr($1); } ; @@ -1369,9 +1403,9 @@ key_ref: any_string $$ = NULL; } else $$ = dst_key; - freestr(key_name); + key_name = freestr(key_name); } - freestr($1); + (void)freestr($1); } ; @@ -1389,6 +1423,13 @@ key_list: key_list_element L_EOS | error ; +dummy_key_list_element: key_ref; + +dummy_key_list: dummy_key_list_element L_EOS + | dummy_key_list dummy_key_list_element L_EOS + | error + ; + key_stmt: T_SEC_KEY { current_algorithm = NULL; @@ -1425,15 +1466,12 @@ key_stmt: T_SEC_KEY } } if (key_name != NULL) - freestr(key_name); - key_name = NULL; + key_name = freestr(key_name); if (current_algorithm != NULL) - freestr(current_algorithm); - current_algorithm = NULL; + current_algorithm = freestr(current_algorithm); if (current_secret != NULL) - freestr(current_secret); - current_secret = NULL; - freestr($3); + current_secret = freestr(current_secret); + (void)freestr($3); } ; @@ -1468,9 +1506,9 @@ acl_stmt: T_ACL any_string '{' address_match_list '}' { if (lookup_acl($2) != NULL) { parser_error(0, "can't redefine ACL '%s'", $2); - freestr($2); } else define_acl($2, $4); + (void)freestr($2); } ; @@ -1506,12 +1544,11 @@ zone_stmt: T_ZONE L_QSTRING optional_class p_class($3)); } else { should_install = 1; - define_symbol(symtab, savestr(zone_name, 1), - sym_type, value, - SYMBOL_FREE_KEY); + define_symbol(symtab, zone_name, sym_type, + value, 0); } } - freestr($2); + (void)freestr($2); current_zone = begin_zone(zone_name, $3); } optional_zone_options_list @@ -1538,7 +1575,7 @@ optional_class: /* Empty */ /* the zone validator will give the error */ $$ = C_NONE; } - freestr($1); + (void)freestr($1); } ; @@ -1688,7 +1725,11 @@ master_in_addr_list: master_in_addr L_EOS master_in_addr: L_IPADDR { - add_zone_master(current_zone, $1); + add_zone_master(current_zone, $1, NULL); + } + | L_IPADDR T_SEC_KEY key_ref + { + add_zone_master(current_zone, $1, $3); } ; @@ -1788,7 +1829,7 @@ in_port: L_NUMBER if ($1 < 0 || $1 > 65535) { parser_warning(0, "invalid IP port number '%d'; setting port to 0", - $1); + (int)$1); $1 = 0; } else $$ = htons($1); @@ -1827,26 +1868,26 @@ init_acls() { ime = new_ip_match_pattern(address, 0); iml = new_ip_match_list(); add_to_ip_match_list(iml, ime); - define_acl(savestr("any", 1), iml); + define_acl("any", iml); /* ACL "none" */ ime = new_ip_match_pattern(address, 0); ip_match_negate(ime); iml = new_ip_match_list(); add_to_ip_match_list(iml, ime); - define_acl(savestr("none", 1), iml); + define_acl("none", iml); /* ACL "localhost" */ ime = new_ip_match_localhost(); iml = new_ip_match_list(); add_to_ip_match_list(iml, ime); - define_acl(savestr("localhost", 1), iml); + define_acl("localhost", iml); /* ACL "localnets" */ ime = new_ip_match_localnets(); iml = new_ip_match_list(); add_to_ip_match_list(iml, ime); - define_acl(savestr("localnets", 1), iml); + define_acl("localnets", iml); } static void @@ -1861,6 +1902,9 @@ free_sym_value(int type, void *value) { case SYM_KEY: free_key_info(value); break; + case SYM_CHANNEL: + INSIST(log_free_channel(value) == 0); + break; default: ns_panic(ns_log_parser, 1, "unhandled case in free_sym_value()"); @@ -1873,25 +1917,26 @@ static log_channel lookup_channel(char *name) { symbol_value value; - if (lookup_symbol(symtab, name, SYM_CHANNEL, &value)) + if (lookup_symbol(channeltab, name, SYM_CHANNEL, &value)) return ((log_channel)(value.pointer)); return (NULL); } static void -define_channel(char *name, log_channel channel) { +define_channel(const char *name, log_channel channel) { symbol_value value; value.pointer = channel; - define_symbol(symtab, name, SYM_CHANNEL, value, SYMBOL_FREE_KEY); + INSIST(log_inc_references(channel) == 0); + define_symbol(channeltab, name, SYM_CHANNEL, value, SYMBOL_FREE_VALUE); } static void define_builtin_channels() { - define_channel(savestr("default_syslog", 1), syslog_channel); - define_channel(savestr("default_debug", 1), debug_channel); - define_channel(savestr("default_stderr", 1), stderr_channel); - define_channel(savestr("null", 1), null_channel); + define_channel("default_syslog", syslog_channel); + define_channel("default_debug", debug_channel); + define_channel("default_stderr", stderr_channel); + define_channel("null", null_channel); } static void @@ -1903,6 +1948,9 @@ parser_setup() { if (authtab != NULL) free_symbol_table(authtab); authtab = new_symbol_table(AUTH_TABLE_SIZE, free_sym_value); + if (channeltab != NULL) + free_symbol_table(channeltab); + channeltab = new_symbol_table(AUTH_TABLE_SIZE, free_sym_value); init_acls(); define_builtin_channels(); INIT_LIST(current_controls); @@ -1924,7 +1972,7 @@ parser_cleanup() { */ ip_match_list -lookup_acl(char *name) { +lookup_acl(const char *name) { symbol_value value; if (lookup_symbol(authtab, name, SYM_ACL, &value)) @@ -1933,15 +1981,14 @@ lookup_acl(char *name) { } void -define_acl(char *name, ip_match_list iml) { +define_acl(const char *name, ip_match_list iml) { symbol_value value; INSIST(name != NULL); INSIST(iml != NULL); value.pointer = iml; - define_symbol(authtab, name, SYM_ACL, value, - SYMBOL_FREE_KEY|SYMBOL_FREE_VALUE); + define_symbol(authtab, name, SYM_ACL, value, SYMBOL_FREE_VALUE); ns_debug(ns_log_parser, 7, "acl %s", name); dprint_ip_match_list(ns_log_parser, iml, 2, "allow ", "deny "); } @@ -1956,7 +2003,7 @@ lookup_key(char *name) { } void -define_key(char *name, struct dst_key *dst_key) { +define_key(const char *name, struct dst_key *dst_key) { symbol_value value; INSIST(name != NULL); @@ -1996,5 +2043,7 @@ void parser_shutdown(void) { if (authtab != NULL) free_symbol_table(authtab); + if (channeltab != NULL) + free_symbol_table(channeltab); lexer_shutdown(); } diff --git a/contrib/bind/bin/named/ns_parseutil.c b/contrib/bind/bin/named/ns_parseutil.c index 4a26337d95f9..3619dc7ae0cb 100644 --- a/contrib/bind/bin/named/ns_parseutil.c +++ b/contrib/bind/bin/named/ns_parseutil.c @@ -66,8 +66,7 @@ new_symbol_table(int size_guess, free_function free_value) { void free_symbol(symbol_table st, symbol_entry ste) { - if (ste->flags & SYMBOL_FREE_KEY) - freestr(ste->key); + ste->key = freestr(ste->key); if (ste->flags & SYMBOL_FREE_VALUE) (st->free_value)(ste->type, ste->value.pointer); } @@ -147,7 +146,7 @@ lookup_symbol(symbol_table st, const char *key, int type, } void -define_symbol(symbol_table st, char *key, int type, symbol_value value, +define_symbol(symbol_table st, const char *key, int type, symbol_value value, unsigned int flags) { int hash; symbol_entry ste; @@ -161,7 +160,7 @@ define_symbol(symbol_table st, char *key, int type, symbol_value value, ste = (symbol_entry)memget(sizeof *ste); if (ste == NULL) panic("memget failed in define_symbol()", NULL); - ste->key = key; + ste->key = savestr(key, 1); ste->type = type; ste->value = value; ste->flags = flags; @@ -171,7 +170,7 @@ define_symbol(symbol_table st, char *key, int type, symbol_value value, ns_debug(ns_log_parser, 7, "redefined symbol %s type %d", key, type); free_symbol(st, ste); - ste->key = key; + ste->key = savestr(key, 1); ste->value = value; ste->flags = flags; } diff --git a/contrib/bind/bin/named/ns_parseutil.h b/contrib/bind/bin/named/ns_parseutil.h index 77fc878881b5..efb5c8f4b7e3 100644 --- a/contrib/bind/bin/named/ns_parseutil.h +++ b/contrib/bind/bin/named/ns_parseutil.h @@ -22,7 +22,6 @@ * Symbol Table */ -#define SYMBOL_FREE_KEY 0x01 #define SYMBOL_FREE_VALUE 0x02 typedef union symbol_value { @@ -52,8 +51,8 @@ void free_symbol_table(symbol_table); void dprint_symbol_table(int, symbol_table); int lookup_symbol(symbol_table, const char *, int, symbol_value *); -void define_symbol(symbol_table, char *, int, symbol_value, - unsigned int); +void define_symbol(symbol_table, const char *, int, + symbol_value, unsigned int); void undefine_symbol(symbol_table, char *, int type); /* diff --git a/contrib/bind/bin/named/ns_req.c b/contrib/bind/bin/named/ns_req.c index 252ddbd803cb..66958818bb7d 100644 --- a/contrib/bind/bin/named/ns_req.c +++ b/contrib/bind/bin/named/ns_req.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_req.c 4.47 (Berkeley) 7/1/91"; -static const char rcsid[] = "$Id: ns_req.c,v 8.138.2.4 2001/08/10 03:00:14 marka Exp $"; +static const char rcsid[] = "$Id: ns_req.c,v 8.162 2002/02/01 00:05:36 marka Exp $"; #endif /* not lint */ /* @@ -153,17 +153,143 @@ static enum req_action req_query(HEADER *hp, u_char **cpp, u_char *eom, int *buflenp, int *msglenp, u_char *msg, int dfd, int *ra, struct sockaddr_in from, - struct tsig_record *in_tsig); + struct tsig_record *in_tsig, + u_int16_t udpsize); static enum req_action req_iquery(HEADER *hp, u_char **cpp, u_char *eom, - int *buflenp, u_char *msg, - struct sockaddr_in from); + int *buflenp, struct sockaddr_in from); #ifdef BIND_NOTIFY static enum req_action req_notify(HEADER *hp, u_char **cpp, u_char *eom, u_char *msg,struct sockaddr_in from); #endif +/* + * See if there is a OPT record at the end of the message. + * + * Results: + * -1 FORMERR + * 0 last RR is not a OPT record + * n>0 lenght of OPT record + */ +int +ns_get_opt(u_char *msg, u_char *eom, + u_int8_t *versionp, u_int16_t *rcodep, u_int16_t *flagp, + u_int16_t *bufsizep, u_char **optionsp, size_t *optsizep) +{ + HEADER *hp = (HEADER *) msg; + u_char *start, *options, *cp; + u_int8_t version; + u_int16_t rdlen, type, bufsize, flags, optsize, rcode; + int i, n, root; + + if (msg == NULL || eom == NULL || (msg + HFIXEDSZ) > eom) + return (-1); + + if (ntohs(hp->arcount) == 0) + return (0); + + cp = msg + HFIXEDSZ; + n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount)); + if (n < 0) + return (-1); + cp += n; + n = ns_skiprr(cp, eom, ns_s_an, ntohs(hp->ancount)); + if (n < 0) + return (-1); + cp += n; + n = ns_skiprr(cp, eom, ns_s_ns, ntohs(hp->nscount)); + if (n < 0) + return (-1); + cp += n; + i = ntohs(hp->arcount); + while (i-- > 0) { + start = cp; + if (cp >= eom) + return (-1); + root = (*cp == 0); + n = dn_skipname(cp, eom); + if (n < 0) + return (-1); + cp += n; + if (cp + (2 + 2 + 4 + 2) > eom) + return (-1); + GETSHORT(type, cp); + if (type != ns_t_opt) { + cp += INT16SZ + INT32SZ; /* class, ttl */ + GETSHORT(rdlen, cp); + if (cp + rdlen > eom) + return (-1); + cp += rdlen; + continue; + } + /* We have the OPT record. Check it out in detail. */ + if (!root) + return (-1); + GETSHORT(bufsize, cp); + rcode = (*cp++ <<4) + hp->rcode ; + version = *cp++; + GETSHORT(flags, cp); + GETSHORT(rdlen, cp); + /* ensure options are well formed */ + options = cp; + optsize = rdlen; + while (rdlen != 0) { + u_int16_t code; + u_int16_t len; + + if (rdlen < 4) + return (-1); + GETSHORT(code, cp); + GETSHORT(len, cp); + rdlen -= 4; + if (len > rdlen) + return (-1); + cp += len; + rdlen -= len; + } + /* Everything checks out. */ + if (versionp != NULL) + *versionp = version; + if (rcodep != NULL) + *rcodep = rcode; + if (flagp != NULL) + *flagp = flags; + if (bufsizep != NULL) + *bufsizep = bufsize; + if (optionsp != NULL) + *optionsp = options; + if (optsizep != NULL) + *optsizep = optsize; + return (cp - start); + } + /* OPT not found */ + return (0); +} + +int +ns_add_opt(u_char *msg, u_char *cp, size_t buflen, u_int8_t version, + u_int16_t rcode, u_int16_t size, u_int16_t flags, + u_char *options, size_t optlen) +{ + HEADER *hp = (HEADER *) msg; + + if ((cp + 1 + 2 + 2 + 4 + 2 + optlen) > (msg + buflen)) + return (-1); + + *cp++ = 0; /* "." */ + PUTSHORT(ns_t_opt, cp); /* type */ + PUTSHORT(size, cp); /* class (udp size) */ + *cp++ = (rcode >> 4) & 0xff; /* ttl (rcode + version + flags) */ + hp->rcode = rcode & 0xf; + *cp++ = version; + PUTSHORT(flags, cp); + PUTSHORT(optlen, cp); /* rdlen */ + memcpy(cp, options, optlen); /* options */ + hp->arcount = htons(ntohs(hp->arcount) + 1); + return (1 + 2 + 2 + 4 + 2 + optlen); +} + /* * Process request using database; assemble and send response. */ @@ -173,8 +299,8 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, { HEADER *hp = (HEADER *) msg; u_char *cp, *eom; - enum req_action action; - int n, ra, has_tsig, tsig_size, sig2len; + enum req_action action = Return; + int n, ra, has_tsig, tsig_size = 0, opt_size = 0, sig2len; u_char *tsigstart; u_char sig[TSIG_SIG_SIZE], sig2[TSIG_SIG_SIZE]; struct tsig_record *in_tsig = NULL; @@ -182,8 +308,13 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, int msglen_orig = msglen; int buflen_orig = buflen; int siglen = sizeof sig; - DST_KEY *key; + DST_KEY *key = NULL; time_t tsig_time; + int opt = 0; + u_int8_t version = 0; + u_int16_t rcode = ns_r_noerror; + u_int16_t udpsize = 0; + int drop; #ifdef DEBUG if (debug > 3) { @@ -192,6 +323,10 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, } #endif + drop = drop_port(ntohs(from.sin_port)); + if (qsp == NULL && drop == 1) + return; + tsigstart = ns_find_tsig(msg, msg + msglen); if (tsigstart == NULL) has_tsig = 0; @@ -260,6 +395,7 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, in_tsig->siglen = siglen; memcpy(in_tsig->sig, sig, siglen); tsig_size = msglen_orig - msglen; + in_tsig->tsig_size = tsig_size; } else if (has_tsig) { action = Finish; in_tsig = memget(sizeof(struct tsig_record)); @@ -268,6 +404,7 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, in_tsig->key = NULL; in_tsig->siglen = 0; tsig_size = msg + msglen - tsigstart; + in_tsig->tsig_size = tsig_size; msglen = tsigstart - msg; } @@ -275,6 +412,30 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, nsid_hash((u_char *)&tt, sizeof(tt)); nsid_hash(msg, (msglen > 512) ? 512 : msglen); + if (error == NOERROR) { + + opt = ns_get_opt(msg, msg + msglen, &version, + NULL, NULL, &udpsize, NULL, NULL); + if (opt < 0) { + rcode = ns_r_formerr; + action = Finish; + } else if (opt == 0) { + if (qsp == NULL && buflen > PACKETSZ) + buflen_orig = buflen = PACKETSZ; + } else if (opt > 0) { + if (version != 0) { + rcode = ns_r_badvers; + action = Finish; + } + opt_size = 11; + if (udpsize < 512) + udpsize = 512; + if (qsp == NULL && buflen > udpsize) + buflen_orig = buflen = udpsize; + } + } else if (qsp == NULL && buflen > PACKETSZ) + buflen_orig = buflen = PACKETSZ; + /* * It's not a response so these bits have no business * being set. will later simplify work if we can @@ -290,6 +451,8 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, if (error == NOERROR) hp->rcode = ns_r_noerror; + if (rcode == ns_r_noerror) + rcode = hp->rcode; cp = msg + HFIXEDSZ; eom = msg + msglen; buflen -= HFIXEDSZ; @@ -297,16 +460,17 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, free_addinfo(); /* sets addcount to zero */ dnptrs[0] = NULL; - if (error == NOERROR) { + if (error == NOERROR && rcode == ns_r_noerror) { switch (hp->opcode) { case ns_o_query: action = req_query(hp, &cp, eom, qsp, &buflen, &msglen, - msg, dfd, &ra, from, in_tsig); + msg, dfd, &ra, from, + in_tsig, udpsize); break; case ns_o_iquery: - action = req_iquery(hp, &cp, eom, &buflen, msg, from); + action = req_iquery(hp, &cp, eom, &buflen, from); break; #ifdef BIND_NOTIFY @@ -317,8 +481,7 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, #ifdef BIND_UPDATE case ns_o_update: - action = req_update(hp, cp, eom, msg, qsp, dfd, from, - in_tsig); + action = req_update(hp, cp, eom, msg, from, in_tsig); break; #endif /* BIND_UPDATE */ @@ -334,6 +497,7 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, hp->rcode = ns_r_notimpl; action = Finish; } + rcode = hp->rcode; } if (in_tsig != NULL) { @@ -341,6 +505,13 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, in_tsig = NULL; } + /* + * Loop advoidance. + */ + if (qsp == NULL && drop == 2 && + (hp->rcode == FORMERR || hp->rcode == NOTIMP)) + action = Return; + /* * Vector via internal opcode. */ @@ -348,7 +519,7 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, case Return: return; case Refuse: - hp->rcode = ns_r_refused; + rcode = hp->rcode = ns_r_refused; cp = eom; /*FALLTHROUGH*/ case Finish: @@ -365,13 +536,14 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, hp->qr = 1; /* set Response flag */ hp->ra = ra; /* init above, may be modified by req_query */ - if (!hp->tc && has_tsig > 0 && buflen < tsig_size) + if (!hp->tc && (has_tsig > 0 || opt > 0) && + buflen < (tsig_size + opt_size)) hp->tc = 1; /* * If there was a format error, then we don't know what the msg has. */ - if (hp->rcode == ns_r_formerr) { + if (hp->rcode == ns_r_formerr || rcode == ns_r_badvers) { hp->qdcount = htons(0); hp->ancount = htons(0); hp->nscount = htons(0); @@ -380,44 +552,67 @@ ns_req(u_char *msg, int msglen, int buflen, struct qstream *qsp, } /* - * If the query had a TSIG and the message is truncated or there was - * a TSIG error, build a new message with no data and a TSIG. + * If the query had a TSIG / OPT and the message is truncated or + * there was a TSIG error, build a new message with no data and a + * TSIG / OPT. */ - if ((hp->tc || error != NOERROR) && has_tsig > 0) { + if ((hp->tc || error != NOERROR) && (has_tsig > 0 || opt > 0)) { sign_again: hp->ancount = htons(0); hp->nscount = htons(0); hp->arcount = htons(0); cp = msg + HFIXEDSZ; cp += ns_skiprr(cp, msg + msglen, ns_s_qd, ntohs(hp->qdcount)); - sig2len = sizeof sig2; - msglen = cp - msg; - buflen = buflen_orig - msglen; - n = ns_sign(msg, &msglen, msglen + buflen, error, key, - sig, siglen, sig2, &sig2len, tsig_time); - if (n == NS_TSIG_ERROR_NO_SPACE && ntohs(hp->qdcount) != 0) { - hp->qdcount = htons(0); - goto sign_again; + if (opt > 0) { + n = ns_add_opt(msg, cp, buflen_orig, 0, + rcode, EDNS_MESSAGE_SZ, 0, NULL, 0); + if (n < 0) { + hp->qdcount = htons(0); + goto sign_again; + } + cp += n; + } + if (has_tsig > 0) { + sig2len = sizeof sig2; + msglen = cp - msg; + buflen = buflen_orig - msglen; + n = ns_sign(msg, &msglen, msglen + buflen, error, key, + sig, siglen, sig2, &sig2len, tsig_time); + if (n == NS_TSIG_ERROR_NO_SPACE && + ntohs(hp->qdcount) != 0) { + hp->qdcount = htons(0); + goto sign_again; + } + if (n != 0) + ns_info(ns_log_default, + "ns_req: unable to sign response"); + cp = msg + msglen; } - if (n != 0) - ns_info(ns_log_default, - "ns_req: unable to sign response"); - cp = msg + msglen; } - /* Either the message is not truncated or there was no TSIG */ + /* Either the message is not truncated or there was no TSIG & OPT */ else { /* * Reserve space for tsig if required. */ - if (has_tsig > 0) - buflen -= tsig_size; + if (has_tsig > 0 || opt_size != 0) + buflen -= tsig_size + opt_size; + INSIST(buflen >= 0); + msglen = cp - msg; n = doaddinfo(hp, cp, buflen); cp += n; buflen -= n; + msglen += n; + if (opt > 0) { + buflen += opt_size; + n = ns_add_opt(msg, cp, msglen + buflen, 0, + rcode, EDNS_MESSAGE_SZ, 0, NULL, 0); + INSIST(n > 0); + cp += n; + buflen -= n; + } if (has_tsig > 0) { buflen += tsig_size; sig2len = sizeof sig2; - msglen = cp - msg; n = ns_sign(msg, &msglen, msglen + buflen, error, key, sig, siglen, sig2, &sig2len, tsig_time); if (n != 0) { @@ -608,16 +803,42 @@ req_notify(HEADER *hp, u_char **cpp, u_char *eom, u_char *msg, } #endif /*BIND_NOTIFY*/ +static int +add_bind(HEADER *hp, u_char **cpp, u_char *msg, int *msglenp, + const char *label, const char *data) +{ + u_char *tp; + + hp->ancount = htons(1); + hp->nscount = htons(0); + hp->arcount = htons(0); + hp->rcode = ns_r_noerror; + hp->aa = 1; + hp->ra = 0; + copyCharString(cpp, label); /* Name */ + copyCharString(cpp, "BIND"); + *(*cpp)++ = 0x00; + PUTSHORT(T_TXT, *cpp); /* Type */ + PUTSHORT(C_CHAOS, *cpp); /* Class */ + PUTLONG(0, *cpp); /* TTL */ + tp = *cpp; /* Temp RdLength */ + PUTSHORT(0, *cpp); + copyCharString(cpp, data); + PUTSHORT((*cpp) - (tp + INT16SZ), tp); /* Real RdLength */ + *msglenp = *cpp - msg; /* Total message length */ + return (Finish); +} static enum req_action req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, int *buflenp, int *msglenp, u_char *msg, int dfd, int *ra, - struct sockaddr_in from, struct tsig_record *in_tsig) + struct sockaddr_in from, struct tsig_record *in_tsig, + u_int16_t udpsize) { int n, class, type, count, zone, foundname, founddata, omsglen, cname; int recursion_blocked_by_acl; u_int16_t id; - u_int32_t serial_ixfr; + u_int32_t serial_ixfr = 0; int ixfr_found; int ixfr_error = 0; char dnbuf2[MAXDNAME]; @@ -631,6 +852,8 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, struct zoneinfo *zp; struct databuf *dp; DST_KEY *in_key = (in_tsig != NULL) ? in_tsig->key : NULL; + int access_class; + int adjustlen = 0; nameserIncr(from.sin_addr, nssRcvdQ); @@ -648,14 +871,19 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, /* valid queries have one question and zero answers */ if ((ntohs(hp->qdcount) != 1) - || ntohs(hp->ancount) != 0 - || ntohs(hp->arcount) != 0) { + || ntohs(hp->ancount) != 0) { ns_debug(ns_log_default, 1, "FORMERR Query header counts wrong"); hp->rcode = ns_r_formerr; return (Finish); } + if (ntohs(hp->arcount) != 0) { + ns_debug(ns_log_default, 1, "Ignoring addition section"); + hp->arcount = htons(0); + adjustlen = 1; + } + /* * Get domain name, class, and type. */ @@ -680,8 +908,9 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, GETSHORT(type, *cpp); GETSHORT(class, *cpp); if (*cpp < eom && type != ns_t_ixfr) { - ns_debug(ns_log_default, 6, - "message length > received message"); + if (!adjustlen) + ns_debug(ns_log_default, 6, + "message length > received message"); *msglenp = *cpp - msg; } @@ -748,7 +977,7 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, } GETLONG(serial_ixfr, *cpp); /* ignore other soa counters */ - if ((*cpp + (4 * INT32SZ)) < eom) + if ((*cpp + (4 * INT32SZ)) < eom && !adjustlen) ns_debug(ns_log_default, 6, "ixfr: message length > received message"); /* Reset msglenp to cover just the question. */ @@ -838,9 +1067,15 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, /* * Begin Access Control Point */ - zone = DB_Z_CACHE; + + /* + * Map class ANY to to class IN for the purpose of access control. + */ + access_class = (class == C_ANY && !ns_t_xfr_p(type)) ? C_IN : class; + if (np) { +#ifndef FORWARD_ALLOWS struct namebuf *access_np; /* @@ -855,13 +1090,35 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, for (access_np = np; access_np != NULL; access_np = np_parent(access_np)) { dp = access_np->n_data; - while (dp && dp->d_class != class) + while (dp && dp->d_class != access_class) dp = dp->d_next; if (dp != NULL) { zone = dp->d_zone; break; } } +#else + /* + * Try looking for forward zone. It can be deeper than + * any entry in the cache. + */ + if (zone == DB_Z_CACHE) { + char *s = dname; + int escape = 0; + while ((zp = find_zone(s, access_class)) == NULL) { + if (*s == '\0') + break; + while (*s != '\0' && (escape || *s != '.')) { + escape = escape ? 0 : (*s == '\\'); + s++; + } + if (*s == '.') + s++; + } + if (zp != NULL) + zone = zp - zones; + } +#endif } zp = &zones[zone]; @@ -941,8 +1198,9 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, for (access_np = np; access_np != NULL; access_np = np_parent(access_np)) { dp = access_np->n_data; - while (dp && (dp->d_class != class || - dp->d_zone == DB_Z_CACHE)) + while (dp && + (dp->d_class != access_class || + dp->d_zone == DB_Z_CACHE)) dp = dp->d_next; if (dp != NULL) { zone = dp->d_zone; @@ -961,9 +1219,9 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, } } ns_notice(ns_log_security, - "denied query from %s for \"%s\" %s", + "denied query from %s for \"%s\" %s/%s", sin_ntoa(from), *dname ? dname : ".", - p_class(class)); + p_type(type), p_class(class)); nameserIncr(from.sin_addr, nssRcvdUQ); return (Refuse); } @@ -1054,28 +1312,18 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, * Yow! */ if (class == ns_c_chaos && type == ns_t_txt && - ns_samename(dnbuf, "VERSION.BIND") == 1) { - u_char *tp; + ns_samename(dnbuf, "VERSION.BIND") == 1 && + server_options->version != NULL && + server_options->version[0] != '\0') + return (add_bind(hp, cpp, msg, msglenp, + "VERSION", server_options->version)); - hp->ancount = htons(1); - hp->nscount = htons(0); - hp->arcount = htons(0); - hp->rcode = ns_r_noerror; - hp->aa = 1; - hp->ra = 0; - copyCharString(cpp, "VERSION"); /* Name */ - copyCharString(cpp, "BIND"); - *(*cpp)++ = 0x00; - PUTSHORT(T_TXT, *cpp); /* Type */ - PUTSHORT(C_CHAOS, *cpp); /* Class */ - PUTLONG(0, *cpp); /* TTL */ - tp = *cpp; /* Temp RdLength */ - PUTSHORT(0, *cpp); - copyCharString(cpp, server_options->version); - PUTSHORT((*cpp) - (tp + INT16SZ), tp); /* Real RdLength */ - *msglenp = *cpp - msg; /* Total message length */ - return (Finish); - } + if (class == ns_c_chaos && type == ns_t_txt && + ns_samename(dnbuf, "HOSTNAME.BIND") == 1 && + server_options->hostname != NULL && + server_options->hostname[0] != '\0') + return (add_bind(hp, cpp, msg, msglenp, + "HOSTNAME", server_options->hostname)); /* * If we don't know anything about the requested name, @@ -1365,8 +1613,9 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, if (n < 0) { ns_info(ns_log_default, "res_mkquery(%s) failed", dname); - hp->rcode = ns_r_servfail; + memcpy(msg, omsg, omsglen); memput(omsg, omsglen); + hp->rcode = ns_r_servfail; free_nsp(nsp); return (Finish); } @@ -1375,7 +1624,9 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, n = ns_forw(nsp, msg, *msglenp, from, qsp, dfd, &qp, dname, class, type, np, 0, in_tsig); if (n != FW_OK && cname) { + memcpy(msg, omsg, omsglen); memput(omsg, omsglen); + *msglenp = omsglen; omsg = NULL; } switch (n) { @@ -1387,6 +1638,11 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, qp->q_cmsgsize = omsglen; qp->q_id = id; } + if (udpsize != 0) { + qp->q_flags |= Q_EDNS; + qp->q_udpsize = udpsize; + } else + qp->q_udpsize = PACKETSZ; break; case FW_DUP: break; /* Duplicate request dropped */ @@ -1441,7 +1697,7 @@ req_query(HEADER *hp, u_char **cpp, u_char *eom, struct qstream *qsp, static enum req_action req_iquery(HEADER *hp, u_char **cpp, u_char *eom, int *buflenp, - u_char *msg, struct sockaddr_in from) + struct sockaddr_in from) { u_int rdata_offset; size_t alen; @@ -1561,7 +1817,7 @@ req_iquery(HEADER *hp, u_char **cpp, u_char *eom, int *buflenp, *buflenp -= INT16SZ; hp->qdcount = htons(1); - if (alen > *buflenp) { + if ((int)alen > *buflenp) { hp->tc = 1; return (Finish); } @@ -1578,6 +1834,10 @@ int stale(struct databuf *dp) { struct zoneinfo *zp = &zones[dp->d_zone]; +#ifdef CHECK_MAGIC + INSIST(dp->d_magic == DATABUF_MAGIC); +#endif + switch (zp->z_type) { case z_master: @@ -1662,6 +1922,7 @@ make_rr(const char *name, struct databuf *dp, u_char *buf, int32_t n; int16_t type = dp->d_type; u_int32_t ttl; + u_char naptr_flag; ns_debug(ns_log_default, 5, "make_rr(%s, %lx, %lx, %d, %d) %d zone %d ttl %lu", @@ -1801,6 +2062,7 @@ make_rr(const char *name, struct databuf *dp, u_char *buf, buflen -= n + 1; if (buflen < 0) goto cleanup; + naptr_flag = (n == 1) ? *cp1 : 0; *cp++ = n; memcpy(cp, cp1, n); cp += n; @@ -1839,6 +2101,14 @@ make_rr(const char *name, struct databuf *dp, u_char *buf, if (n < 0) goto cleanup; cp += n; + if (doadd && *cp1 != 0) { + if (naptr_flag == 's' || naptr_flag == 'S') + addname((char*)cp1, name, type, T_SRV, + dp->d_class); + if (naptr_flag == 'a' || naptr_flag == 'A') + addname((char*)cp1, name, type, T_A, + dp->d_class); + } /* save data length */ n = (u_int16_t)((cp - sp) - INT16SZ); @@ -2022,8 +2292,9 @@ doaddinfo(HEADER *hp, u_char *msg, int msglen) { const char *fname; register int n, count; register int ns_logging; - int finishedA = 0; - int save_addcount = addcount; + int pass = 0; + int i, doadd; + if (!addcount) return (0); @@ -2043,15 +2314,18 @@ doaddinfo(HEADER *hp, u_char *msg, int msglen) { count = 0; cp = msg; loop: - for (ap = addinfo; --addcount >= 0; ap++) { + for (ap = addinfo, i = 0; i < addcount; ap++, i++) { int foundany = 0, foundcname = 0, save_count = count, save_msglen = msglen; u_char *save_cp = cp; - if ((finishedA == 1 && ap->a_type == T_A) || - (finishedA == 0 && ap->a_type == T_KEY)) + if ((pass != 0 && + (pass != 1 || server_options->preferred_glue == 0) && + ap->a_type == T_A) || + (pass != 0 && ap->a_type == T_SRV) || + (pass != 2 && ap->a_type == T_KEY)) continue; if (ns_logging) ns_debug(ns_log_default, 3, @@ -2066,35 +2340,52 @@ loop: /* look for the data */ (void)delete_stale(np); for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_rcode) + if (dp->d_rcode == NXDOMAIN) { + if (dp->d_class == ap->a_class) + foundany++; continue; + } if ((match(dp, (int)ap->a_class, T_CNAME) && - dp->d_type == T_CNAME) || - (match(dp, C_IN, T_CNAME) && dp->d_type == T_CNAME)) { foundcname++; break; } + if (pass == 0 && ap->a_type == T_A && + server_options->preferred_glue != 0 && + !match(dp, (int)ap->a_class, + server_options->preferred_glue)) { + continue; + } + if (pass != 0 && ap->a_type == T_A && + server_options->preferred_glue != 0 && + match(dp, (int)ap->a_class, + server_options->preferred_glue)) { + continue; + } if (ap->a_type == T_A && !match(dp, (int)ap->a_class, T_A) && - !match(dp, C_IN, T_A) && !match(dp, (int)ap->a_class, T_AAAA) && - !match(dp, C_IN, T_AAAA) && - !match(dp, (int)ap->a_class, ns_t_a6) && - !match(dp, C_IN, ns_t_a6)) { + !match(dp, (int)ap->a_class, ns_t_a6)) { continue; } if (ap->a_type == T_KEY && - !match(dp, (int)ap->a_class, T_KEY) && - !match(dp, C_IN, T_KEY)) + !match(dp, (int)ap->a_class, T_KEY)) + continue; + if (ap->a_type == T_SRV && + !match(dp, (int)ap->a_class, T_SRV)) continue; foundany++; + if (dp->d_rcode) + continue; /* * Should be smart and eliminate duplicate * data here. XXX */ - if ((n = make_rr(ap->a_dname, dp, cp, msglen, 0, + doadd = 0; + if (ap->a_type == T_SRV) + doadd = 1; + if ((n = make_rr(ap->a_dname, dp, cp, msglen, doadd, dnptrs, dnptrs_end, 0)) < 0) { /* truncation in the additional-data section * is not all that serious. we do not set TC, @@ -2130,7 +2421,8 @@ loop: (ap->a_type == T_A || ap->a_type == T_AAAA)) { /* ask a real server for this info */ (void) sysquery(ap->a_dname, (int)ap->a_class, - ap->a_type, NULL, 0, ns_port, QUERY); + ap->a_type, NULL, NULL, 0, ns_port, + QUERY, 0); } if (foundcname) { if (!haveComplained(nhash(ap->a_dname), @@ -2141,15 +2433,15 @@ loop: p_type(ap->a_rtype), ap->a_dname); } } - freestr(ap->a_dname); - freestr(ap->a_rname); } - if (finishedA == 0) { - finishedA = 1; - addcount = save_addcount; + if (pass++ < 2) goto loop; /* now do the KEYs... */ - } hp->arcount = htons((u_int16_t)count); + for (ap = addinfo, i = 0; i < addcount; ap++, i++) { + ap->a_dname = freestr(ap->a_dname); + ap->a_rname = freestr(ap->a_rname); + } + addcount = 0; return (cp - msg); } @@ -2188,27 +2480,16 @@ free_addinfo() { struct addinfo *ap; for (ap = addinfo; --addcount >= 0; ap++) { - freestr(ap->a_dname); - freestr(ap->a_rname); + ap->a_dname = freestr(ap->a_dname); + ap->a_rname = freestr(ap->a_rname); } addcount = 0; } void free_nsp(struct databuf **nsp) { - while (*nsp) { - DRCNTDEC(*nsp); - if ((*nsp)->d_rcnt) - ns_debug(ns_log_default, 3, "free_nsp: %s rcnt %d", - (*nsp)->d_data, (*nsp)->d_rcnt); - else { - ns_debug(ns_log_default, 3, - "free_nsp: %s rcnt %d delayed", - (*nsp)->d_data, (*nsp)->d_rcnt); - db_freedata(*nsp); /* delayed free */ - } - *nsp++ = NULL; - } + while (*nsp) + db_detach(nsp++); } static void @@ -2218,3 +2499,20 @@ copyCharString(u_char **dst, const char *src) { memcpy(*dst, src, len); *dst += len; } + +/* + * Questionable source ports for queries / responses. + */ +int +drop_port(u_int16_t port) { + switch (port) { + case 7: /* echo */ + case 13: /* daytime */ + case 19: /* chargen */ + case 37: /* time */ + return (1); + case 464: /* kpasswd */ + return (2); + } + return (0); +} diff --git a/contrib/bind/bin/named/ns_resp.c b/contrib/bind/bin/named/ns_resp.c index 31c233a0f8a7..ea62674a37f6 100644 --- a/contrib/bind/bin/named/ns_resp.c +++ b/contrib/bind/bin/named/ns_resp.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_resp.c 4.65 (Berkeley) 3/3/91"; -static const char rcsid[] = "$Id: ns_resp.c,v 8.152 2001/02/13 23:28:31 marka Exp $"; +static const char rcsid[] = "$Id: ns_resp.c,v 8.172 2002/01/31 00:06:41 marka Exp $"; #endif /* not lint */ /* @@ -182,7 +182,9 @@ static int rrsetcmp(char *, struct db_list *, struct hashbuf *), struct sockaddr_in, char **); static void mark_bad(struct qinfo *qp, struct sockaddr_in from); static void mark_lame(struct qinfo *qp, struct sockaddr_in from); -static void fast_retry(struct qinfo *qp, struct sockaddr_in from); +static int mark_noedns(struct qinfo *qp, struct sockaddr_in from); +static void fast_retry(struct qinfo *qp, struct sockaddr_in from, + int samehost); static void add_related_additional(char *); static void free_related_additional(void); static int related_additional(char *); @@ -198,11 +200,12 @@ static char *related[MAX_RELATED]; static char * learntFrom(struct qinfo *qp, struct sockaddr_in *server) { static char *buf = NULL; - char *a, *ns, *na; + const char *a, *ns, *na; struct databuf *db; int i; char nsbuf[20]; char abuf[20]; + static const char fmt[] = " '%s': learnt (A=%s,NS=%s)"; a = ns = na = ""; @@ -243,23 +246,11 @@ learntFrom(struct qinfo *qp, struct sockaddr_in *server) { if (*na == '\0') na = "\".\""; - if (NS_OPTION_P(OPTION_HOSTSTATS)) { - static const char fmt[] = " '%s': learnt (A=%s,NS=%s)"; - - buf = newstr(sizeof fmt + strlen(na) + strlen(a) + strlen(ns), - 0); - if (buf == NULL) - return (NULL); - sprintf(buf, fmt, na, a, ns); - } else { - static const char fmt[] = " '%s'"; - - buf = newstr(sizeof fmt + strlen(na), 0); - if (buf == NULL) - return (NULL); - sprintf(buf, fmt, na); - } + buf = newstr(sizeof fmt + strlen(na) + strlen(a) + strlen(ns), 0); + if (buf == NULL) + return (NULL); + sprintf(buf, fmt, na, a, ns); return (buf); } @@ -289,7 +280,7 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) char *dname, tmpdomain[MAXDNAME]; const char *fname; const char *formerrmsg = "brain damage"; - u_char newmsg[PACKETSZ]; + u_char newmsg[EDNS_MESSAGE_SZ]; u_char **dpp, *tp; time_t rtrip; struct hashbuf *htp; @@ -299,10 +290,10 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) int forcecmsg = 0; char *tname = NULL; int sendto_errno = 0; - int has_tsig, oldqlen; - u_char *oldqbuf; - u_char *smsg; - int smsglen, smsgsize, siglen; + int has_tsig, oldqlen = 0; + u_char *oldqbuf = NULL; + u_char *smsg = NULL; + int smsglen, smsgsize = 0, siglen; u_char sig[TSIG_SIG_SIZE]; time_t tsig_time; DST_KEY *key; @@ -419,25 +410,34 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) && hp->opcode != NS_NOTIFY_OP #endif )) { + int noedns = 1; ns_debug(ns_log_default, 2, "resp: error (ret %d, op %d), dropped", hp->rcode, hp->opcode); switch (hp->rcode) { case SERVFAIL: nameserIncr(from.sin_addr, nssRcvdFail); + noedns = mark_noedns(qp, from); break; case FORMERR: nameserIncr(from.sin_addr, nssRcvdFErr); + noedns = mark_noedns(qp, from); + break; + case NOTIMP: + nameserIncr(from.sin_addr, nssRcvdErr); + noedns = mark_noedns(qp, from); break; default: nameserIncr(from.sin_addr, nssRcvdErr); break; } if (ns_samename(qp->q_name, qp->q_domain) == 1 && - hp->rcode == SERVFAIL && hp->opcode == QUERY) + hp->rcode == SERVFAIL && hp->opcode == QUERY && + noedns) mark_lame(qp, from); - mark_bad(qp, from); - fast_retry(qp, from); + if (noedns) + mark_bad(qp, from); + fast_retry(qp, from, noedns ? 0 : 1); return; } @@ -540,6 +540,8 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) (1 - ALPHA) * rtrip; if (t > 65535) t = 65535; + else if (t == 0) + t = 1; ns->d_nstime = (u_int16_t)t; } @@ -580,15 +582,17 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) continue; if (qs->stime.tv_sec) { if (ns2->d_nstime == 0) - t = (rtrip * BETA); + t = (rtrip * BETA) + 1; else t = ns2->d_nstime * BETA + - (1 - ALPHA) * rtrip; + (1 - ALPHA) * rtrip + 1; } else t = ns2->d_nstime * GAMMA; if (t > 65535) t = 65535; + else if (t == 0) + t = 1; ns2->d_nstime = (u_int16_t)t; if (ns_wouldlog(ns_log_default, 2)) { ns_debug(ns_log_default, 2, @@ -688,7 +692,7 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) } qs->serial = serial; } - retry(qp); + retry(qp, 0); return; } @@ -702,7 +706,7 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) #endif ) { u_char *tp; - int type, class, dlen; + int type, class = 0, dlen; int foundns, foundsoa; #ifdef DEBUG if (debug > 0) @@ -778,7 +782,7 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) (learnt_from == NULL) ? "" : learnt_from); if (learnt_from != NULL) - freestr(learnt_from); + learnt_from = freestr(learnt_from); } else if (fwd != NULL) { if (!haveComplained(ina_ulong(from.sin_addr), (u_long)nonRecursiveForwarder)) @@ -787,7 +791,7 @@ ns_resp(u_char *msg, int msglen, struct sockaddr_in from, struct qstream *qsp) sin_ntoa(from)); } - fast_retry(qp, from); + fast_retry(qp, from, 0); return; } } @@ -833,7 +837,10 @@ tcp_retry: nsa = Q_NEXTADDR(qp, 0); - key = tsig_key_from_addr(nsa->sin_addr); + key = qp->q_keys[0]; + if (key != NULL) + key = qp->q_keys[0] = + tsig_key_from_addr(nsa->sin_addr); if (key != NULL) { smsgsize = qp->q_msglen + TSIG_BUF_SIZE; smsg = memget(smsgsize); @@ -849,17 +856,16 @@ tcp_retry: qp->q_msglen = smsglen; qp->q_msg = smsg; has_tsig = 1; + free_tsig(qp->q_nstsig); qp->q_nstsig = new_tsig(key, sig, siglen); - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; INSIST(0); } - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; @@ -871,7 +877,7 @@ tcp_retry: * failed, but we'll try to press on because * there isn't anything else to do. */ - retry(qp); + retry(qp, 0); if (has_tsig == 1) { memput(qp->q_msg, smsgsize); @@ -892,14 +898,14 @@ tcp_retry: /* mark this server as bad */ mark_bad(qp, from); /* try another server, it may have a bigger write buffer */ - retry(qp); + retry(qp, 0); return; } tp = cp; restart = 0; - validanswer = 0; + validanswer = -1; nscount = 0; soacount = 0; cname = 0; @@ -958,7 +964,8 @@ tcp_retry: ns_debug(ns_log_resp_checks, 3, "ignoring answer '%s' after external cname", name); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } if (type == T_CNAME && @@ -969,7 +976,8 @@ tcp_retry: cname++; lastwascname = 1; } else { - validanswer = 1; + if (validanswer) + validanswer = 1; lastwascname = 0; } @@ -986,7 +994,8 @@ tcp_retry: if (lastwascname) { ns_debug(ns_log_resp_checks, 3, "last was cname, ignoring auth. and add."); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; break; } if (i < arfirst) { @@ -1000,19 +1009,21 @@ tcp_retry: aname[0] ? aname : ".", name[0] ? name : ".", sin_ntoa(from)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; - } else if (fwd == NULL && - !ns_samedomain(name, + } else if (!ns_samedomain(name, qp->q_domain)) { - if (!externalcname) + if (fwd == NULL && + !externalcname) ns_info(ns_log_resp_checks, "bad referral (%s !< %s) from %s", name[0] ? name : ".", qp->q_domain[0] ? qp->q_domain : ".", sin_ntoa(from)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } if (type == T_NS) { @@ -1036,7 +1047,8 @@ tcp_retry: "invalid RR type '%s' in authority section (name = '%s') from %s", p_type(type), name, sin_ntoa(from)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } dp->d_cred = (hp->aa && (cname == 0)) ? @@ -1048,12 +1060,14 @@ tcp_retry: switch (type) { case T_A: case T_AAAA: + case T_SRV: if (externalcname || !ns_samedomain(name, qp->q_domain)) { ns_debug(ns_log_resp_checks, 3, "ignoring additional info '%s' type %s", name, p_type(type)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } if (!related_additional(name)) { @@ -1061,9 +1075,14 @@ tcp_retry: "unrelated additional info '%s' type %s from %s", name, p_type(type), sin_ntoa(from)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } + if (type == T_SRV && tname != NULL) { + add_related_additional(tname); + tname = NULL; + } break; case T_KEY: /* XXX check? */ @@ -1076,12 +1095,20 @@ tcp_retry: * it might be a transaction signature. */ break; + case ns_t_opt: + /* + * OPT does not get cached. + */ + db_detach(&dp); + validanswer = 0; + continue; default: ns_info(ns_log_resp_checks, "invalid RR type '%s' in additional section (name = '%s') from %s", p_type(type), name, sin_ntoa(from)); - db_freedata(dp); + db_detach(&dp); + validanswer = 0; continue; } dp->d_cred = (qp->q_flags & Q_PRIMING) @@ -1094,6 +1121,7 @@ tcp_retry: ++db_total_hits; #endif /* HITCOUNTS */ rrsetadd(flushset, name, dp); + db_detach(&dp); } free_related_additional(); freestr_maybe(&tname); @@ -1121,7 +1149,7 @@ tcp_retry: if ((qp->q_flags & Q_PRIMING) && !check_root()) { /* mark server as bad */ mark_bad(qp, from); - fast_retry(qp, from); + fast_retry(qp, from, 0); return; } ns_debug(ns_log_default, 3, @@ -1138,7 +1166,7 @@ tcp_retry: return; } - if (ancount && count && !validanswer) { + if (ancount && count && validanswer != 1) { /* * Everything passed validation but we didn't get the * final answer. The response must have contained @@ -1212,10 +1240,10 @@ tcp_retry: */ if (qp->q_cmsglen != 0) { ns_debug(ns_log_default, 1, "Cname second pass"); - newmsglen = MIN(PACKETSZ, qp->q_cmsglen); + newmsglen = MIN(EDNS_MESSAGE_SZ, qp->q_cmsglen); memcpy(newmsg, qp->q_cmsg, newmsglen); } else { - newmsglen = MIN(PACKETSZ, msglen); + newmsglen = MIN(EDNS_MESSAGE_SZ, msglen); memcpy(newmsg, msg, newmsglen); } hp = (HEADER *) newmsg; @@ -1398,13 +1426,13 @@ tcp_retry: /* Reset the query control structure */ - ns_freeqns(qp, "ns_resp"); + ns_freeqns(qp); qp->q_naddr = 0; qp->q_curaddr = 0; nsfwdadd(qp, NS_ZFWDTAB(qp->q_fzone)); if (qp->q_domain != NULL) - freestr(qp->q_domain); + (void)freestr(qp->q_domain); getname(np, tmpdomain, sizeof tmpdomain); qp->q_domain = savestr(tmpdomain, 1); @@ -1471,7 +1499,7 @@ tcp_retry: goto servfail; } if (qp->q_name != NULL) - freestr(qp->q_name); + (void)freestr(qp->q_name); qp->q_name = savestr(dname, 1); qp->q_msglen = n; hp = (HEADER *) qp->q_msg; @@ -1497,36 +1525,46 @@ tcp_retry: res_pquery(&res, qp->q_msg, qp->q_msglen, log_get_stream(packet_channel)); #endif - key = tsig_key_from_addr(nsa->sin_addr); - if (key != NULL) { - smsgsize = qp->q_msglen + TSIG_BUF_SIZE; + key = qp->q_keys[0]; + if (key == NULL) + key = qp->q_keys[0] = tsig_key_from_addr(nsa->sin_addr); + if (key != NULL || !qp->q_addr[0].noedns) { + smsgsize = qp->q_msglen + TSIG_BUF_SIZE + 11; smsg = memget(smsgsize); smsglen = qp->q_msglen; siglen = sizeof(sig); memcpy(smsg, qp->q_msg, qp->q_msglen); + } + + if (!qp->q_addr[0].noedns) + smsglen += ns_add_opt(smsg, smsg + smsglen, smsgsize, 0, 0, + EDNS_MESSAGE_SZ, 0, NULL, 0); + if (key != NULL) { n = ns_sign(smsg, &smsglen, smsgsize, NOERROR, key, NULL, 0, sig, &siglen, 0); if (n == 0) { - oldqbuf = qp->q_msg; - oldqlen = qp->q_msglen; - qp->q_msglen = smsglen; - qp->q_msg = smsg; has_tsig = 1; + free_tsig(qp->q_nstsig); qp->q_nstsig = new_tsig(key, sig, siglen); - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; INSIST(0); } - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; } + if (smsg != NULL) { + oldqbuf = qp->q_msg; + oldqlen = qp->q_msglen; + qp->q_msglen = smsglen; + qp->q_msg = smsg; + } + if (qp->q_flags & Q_USEVC) { if (tcp_send(qp) != NOERROR) { if (!haveComplained(ina_ulong(nsa->sin_addr), @@ -1546,8 +1584,9 @@ tcp_retry: sin_ntoa(*nsa), strerror(errno)); nameserIncr(nsa->sin_addr, nssSendtoErr); } - if (has_tsig == 1) { - memput(qp->q_msg, smsgsize); + + if (smsgsize != 0) { + memput(smsg, smsgsize); qp->q_msg = oldqbuf; qp->q_msglen = oldqlen; } @@ -1570,7 +1609,7 @@ tcp_retry: if (!haveComplained(ina_ulong(from.sin_addr), (u_long)formerrmsg)) ns_info(ns_log_resp_checks, "Malformed response from %s (%s)", sin_ntoa(from), formerrmsg); - fast_retry(qp, from); + fast_retry(qp, from, 0); free_nsp(nsp); return; @@ -1682,7 +1721,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ); GETSHORT(type, cp); GETSHORT(class, cp); - if (class > CLASS_MAX) { + if (type != ns_t_opt && class > CLASS_MAX) { ns_debug(ns_log_default, 3, "bad class in rrextract"); hp->rcode = FORMERR; return (-1); @@ -1867,6 +1906,9 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, } cp += n; + if (tnamep != NULL && *cp1 != 0) + *tnamep = savestr((char *)cp1, 1); + /* compute end of data */ cp1 += strlen((char *)cp1) + 1; /* compute size of data */ @@ -1959,7 +2001,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, break; case T_SIG: { - u_long origTTL, exptime, signtime, timetilexp, now; + u_int32_t origTTL, exptime, signtime, timetilexp, now; u_int8_t alg; /* Check signature time, expiration, and adjust TTL. */ @@ -1978,8 +2020,8 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, /* Don't let bogus name servers increase the signed TTL */ if (ttl > origTTL) { ns_debug(ns_log_default, 3, - "shrinking SIG TTL from %d to origTTL %d", - ttl, origTTL); + "shrinking SIG TTL from %lu to origTTL %lu", + (unsigned long)ttl, (unsigned long)origTTL); ttl = origTTL; } @@ -2020,7 +2062,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, /* then the signer's name */ n = dn_expand(msg, eom, cp, (char *)cp1, (sizeof data) - 18); - if (n < 0 || n + NS_SIG_SIGNER > dlen) { + if (n < 0 || n + NS_SIG_SIGNER > (int)dlen) { hp->rcode = FORMERR; return (-1); } @@ -2031,7 +2073,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, Its size is the total data length, minus what we copied. */ n = dlen - (NS_SIG_SIGNER + n); - if (n > (sizeof data) - (cp1 - (u_char *)data)) { + if (n > (int)(sizeof data) - (cp1 - (u_char *)data)) { hp->rcode = FORMERR; return (-1); /* out of room! */ } @@ -2072,7 +2114,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, * because we always have to look at the 0 bit to see if * this is a "different format" NXT or not. */ - if (n < 0 || n >= dlen) { + if (n < 0 || n >= (int)dlen) { hp->rcode = FORMERR; return (-1); } @@ -2109,7 +2151,7 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, return (-1); } } - if (n2 > sizeof data - n1) { + if (n2 > (int)(sizeof data - n1)) { hp->rcode = FORMERR; return (-1); } @@ -2123,8 +2165,11 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, break; default: + /* treat as opaque data */ ns_debug(ns_log_default, 3, "unknown type %d", type); - return ((cp - rrp) + dlen); + cp1 = cp; + n = dlen; + cp += n; } if (cp > eom) { @@ -2147,6 +2192,8 @@ rrextract(u_char *msg, int msglen, u_char *rrp, struct databuf **dpp, } ttl += tt.tv_sec; + if (type == ns_t_opt) + class = 0; /* Lie. */ *dpp = savedata(class, type, ttl, cp1, n); return (cp - rrp); } @@ -2155,14 +2202,23 @@ int send_msg(u_char *msg, int msglen, struct qinfo *qp) { HEADER *hp = (HEADER *) msg; u_char *oldmsg; - int oldlen; + int oldlen = 0; int msgsize; int ret; + int trunc; + int adjust = 0; if (qp->q_flags & Q_SYSTEM) return (1); - if (!qp->q_stream && (msglen > PACKETSZ)) - msglen = trunc_adjust(msg, msglen, PACKETSZ); + + trunc = (qp->q_stream != NULL) ? 65535 : qp->q_udpsize; + if (qp->q_tsig != NULL) + adjust += qp->q_tsig->tsig_size; + if ((qp->q_flags & Q_EDNS) != 0) + adjust += 11; + if (msglen > trunc - adjust) + msglen = trunc_adjust(msg, msglen, trunc - adjust); + if (ns_wouldlog(ns_log_default, 1)) { ns_debug(ns_log_default, 1, "send_msg -> %s (%s %d) id=%d", sin_ntoa(qp->q_from), @@ -2187,21 +2243,25 @@ send_msg(u_char *msg, int msglen, struct qinfo *qp) { (u_long)qp->q_next, (u_long)qp->q_link); } } - if (debug >= 6) - res_pquery(&res, msg, msglen, log_get_stream(packet_channel)); #endif /* DEBUG */ + if (adjust != 0) { + oldmsg = msg; + oldlen = msglen; + msgsize = msglen + adjust; + msg = memget(msgsize); + memcpy(msg, oldmsg, oldlen); + } else + msgsize = msglen; /* silence compiler */ + + if ((qp->q_flags & Q_EDNS) != 0) + msglen += ns_add_opt(msg, msg + msglen, msgsize, 0, + hp->rcode, EDNS_MESSAGE_SZ, 0, NULL, 0); + if (qp->q_tsig != NULL) { u_char sig[TSIG_SIG_SIZE]; int siglen = sizeof(sig); - oldmsg = msg; - oldlen = msglen; - - msgsize = msglen + TSIG_BUF_SIZE; - msg = memget(msgsize); - memcpy(msg, oldmsg, oldlen); - ret = ns_sign(msg, &msglen, msgsize, NOERROR, qp->q_tsig->key, qp->q_tsig->sig, qp->q_tsig->siglen, sig, &siglen, 0); @@ -2210,22 +2270,19 @@ send_msg(u_char *msg, int msglen, struct qinfo *qp) { INSIST(0); } } + +#ifdef DEBUG + if (debug >= 6) + res_pquery(&res, msg, msglen, log_get_stream(packet_channel)); +#endif /* DEBUG */ if (qp->q_stream == NULL) { /* - * Don't send FORMERR to these well known ports - * (loop avoidance). + * Don't send FORMERR to certian well known ports. */ - switch (ntohs(qp->q_from.sin_port)) { - case 7: /* echo */ - case 13: /* daytime */ - case 19: /* chargen */ - case 37: /* time */ - if (hp->rcode == FORMERR) + if (hp->rcode == FORMERR && + drop_port(ntohs(qp->q_from.sin_port))) return (-1); - default: - break; - } if (sendto(qp->q_dfd, (char*)msg, msglen, 0, (struct sockaddr *)&qp->q_from, sizeof(qp->q_from)) < 0) { @@ -2244,8 +2301,8 @@ send_msg(u_char *msg, int msglen, struct qinfo *qp) { } else writestream(qp->q_stream, (u_char*)msg, msglen); - if (qp->q_tsig != NULL) - memput(msg, oldlen + TSIG_BUF_SIZE); + if (adjust != 0) + memput(msg, oldlen + adjust); return (0); } @@ -2266,7 +2323,8 @@ prime_cache(void) { priming, root); if (!priming && !root) { struct qinfo *qp = sysquery("", ns_c_in, ns_t_ns, - NULL, 0, ns_port, ns_o_query); + NULL, NULL, 0, ns_port, + ns_o_query, 0); if (qp != NULL) { qp->q_flags |= (Q_SYSTEM | Q_PRIMING); @@ -2278,7 +2336,8 @@ prime_cache(void) { struct qinfo * sysquery(const char *dname, int class, int type, - struct in_addr *nss, int nsc, u_int16_t port, int opcode) + struct in_addr *nss, struct dst_key **keys, int nsc, + u_int16_t port, int opcode, int distance) { struct qinfo *qp, *oqp; HEADER *hp; @@ -2292,18 +2351,20 @@ sysquery(const char *dname, int class, int type, const char *fname; int n, count; int sendto_errno = 0; - u_char *oldqbuf; - int oldqlen, has_tsig; - u_char *smsg; - int smsglen, smsgsize, siglen; + u_char *oldqbuf = NULL; + int oldqlen = 0, has_tsig; + u_char *smsg = NULL; + int smsglen, smsgsize = 0, siglen; u_char sig[TSIG_SIG_SIZE]; DST_KEY *key; nsp[0] = NULL; - ns_debug(ns_log_default, 3, "sysquery(%s, %d, %d, %#x, %d, %d)", - dname, class, type, nss, nsc, ntohs(port)); + ns_debug(ns_log_default, 3, "sysquery(%s, %d, %d, %p, %p, %d, %d)", + dname, class, type, nss, keys, nsc, ntohs(port)); qp = qnew(dname, class, type, (nss != NULL && nsc != 0) ? 0 : 1); + qp->q_distance = distance; + if (nss != NULL && nsc != 0) np = NULL; else if (!NS_ZOPTION_P(qp->q_fzone, OPTION_FORWARD_ONLY)) { @@ -2396,10 +2457,13 @@ sysquery(const char *dname, int class, int type, qs->ns_addr.sin_family = AF_INET; qs->ns_addr.sin_addr = nss[i]; qs->ns_addr.sin_port = port; + if (keys != NULL) + qp->q_keys[i] = keys[i]; qs->ns = NULL; qs->nsdata = NULL; qs->stime = tt; qs->forwarder = 0; + qs->noedns = 1; /* XXXMPA */ qs->nretry = 0; } qp->q_naddr = nsc; @@ -2451,7 +2515,7 @@ sysquery(const char *dname, int class, int type, } getname(np, tmpdomain, sizeof tmpdomain); if (qp->q_domain != NULL) - freestr(qp->q_domain); + (void)freestr(qp->q_domain); qp->q_domain = savestr(tmpdomain, 1); goto fetch_a; } @@ -2476,37 +2540,47 @@ sysquery(const char *dname, int class, int type, log_get_stream(packet_channel)); #endif - key = tsig_key_from_addr(nsa->sin_addr); - if (key != NULL) { - smsgsize = qp->q_msglen + TSIG_BUF_SIZE; + key = qp->q_keys[0]; + if (key == NULL) + key = qp->q_keys[0] = tsig_key_from_addr(nsa->sin_addr); + if (key != NULL || !qp->q_addr[0].noedns) { + smsgsize = qp->q_msglen + TSIG_BUF_SIZE + 11; smsg = memget(smsgsize); smsglen = qp->q_msglen; siglen = sizeof(sig); memcpy(smsg, qp->q_msg, qp->q_msglen); + } + + if (!qp->q_addr[0].noedns) + smsglen += ns_add_opt(smsg, smsg + smsglen, smsgsize, 0, 0, + EDNS_MESSAGE_SZ, 0, NULL, 0); + + if (key != NULL) { n = ns_sign(smsg, &smsglen, smsgsize, NOERROR, key, NULL, 0, sig, &siglen, 0); if (n == 0) { - oldqbuf = qp->q_msg; - oldqlen = qp->q_msglen; - qp->q_msglen = smsglen; - qp->q_msg = smsg; has_tsig = 1; - qp->q_nstsig = new_tsig(key, sig, siglen); /* BEW? */ - - } - else { + free_tsig(qp->q_nstsig); + qp->q_nstsig = new_tsig(key, sig, siglen); + } else { INSIST(0); has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; } - } - else { + } else { has_tsig = 0; free_tsig(qp->q_nstsig); qp->q_nstsig = NULL; } + if (smsgsize != 0) { + oldqbuf = qp->q_msg; + oldqlen = qp->q_msglen; + qp->q_msglen = smsglen; + qp->q_msg = smsg; + } + if (sendto(qp->q_dfd, (char*)qp->q_msg, qp->q_msglen, 0, (struct sockaddr *)nsa, sizeof(struct sockaddr_in)) < 0) { @@ -2517,8 +2591,9 @@ sysquery(const char *dname, int class, int type, sin_ntoa(*nsa), strerror(errno)); nameserIncr(nsa->sin_addr, nssSendtoErr); } - if (has_tsig == 1) { - memput(qp->q_msg, smsgsize); + + if (smsgsize != 0) { + memput(smsg, smsgsize); qp->q_msg = oldqbuf; qp->q_msglen = oldqlen; } @@ -2626,8 +2701,8 @@ check_ns() { ns_debug(ns_log_default, 3, "check_ns: %s: not found %s %#lx", dname, fname, (u_long)tnp); - sysquery(dname, dp->d_class, T_A, NULL, - 0, ns_port, QUERY); + sysquery(dname, dp->d_class, T_A, NULL, NULL, + 0, ns_port, QUERY, 0); continue; } /* look for name server addresses */ @@ -2660,8 +2735,8 @@ check_ns() { "Root NS %s -> CNAME %s", NAME(*np), NAME(*tnp)); else - sysquery(dname, dp->d_class, T_A, NULL, - 0, ns_port, QUERY); + sysquery(dname, dp->d_class, T_A, NULL, NULL, + 0, ns_port, QUERY, 0); } } @@ -2718,7 +2793,7 @@ findns(struct namebuf **npp, int class, break; } while (np != NULL) { - ns_debug(ns_log_default, 5, "findns: np %#x '%s'", np, + ns_debug(ns_log_default, 5, "findns: np %p '%s'", np, NAME(*np)); /* Look first for SOA records. */ #ifdef ADDAUTH @@ -2776,10 +2851,8 @@ findns(struct namebuf **npp, int class, * them here as we just got them from the * cache. */ - while (nspp > &nsp[0]) { - nspp--; - DRCNTDEC(*nspp); - } + while (nspp > &nsp[0]) + db_detach(--nspp); nsp[0] = NULL; goto try_parent; } @@ -3232,7 +3305,7 @@ wanted(const struct databuf *dp, int class, int type) { #ifdef DEBUG strcpy(pclass, p_class(class)); strcpy(ptype, p_type(type)); - ns_debug(ns_log_default, 3, "wanted(%#x, %s %s) [%s %s]", + ns_debug(ns_log_default, 3, "wanted(%p, %s %s) [%s %s]", dp, pclass, ptype, p_class(dp->d_class), p_type(dp->d_type)); #endif @@ -3312,7 +3385,7 @@ wantedsig(const struct databuf *dp, int class, int type) { #ifdef DEBUG strcpy(pclass, p_class(class)); strcpy(ptype, p_type(type)); - ns_debug(ns_log_default, 3, "wantedtsig(%#x, %s %s) [%s %s]", + ns_debug(ns_log_default, 3, "wantedtsig(%p, %s %s) [%s %s]", dp, pclass, ptype, p_class(dp->d_class), p_type(dp->d_type)); #endif @@ -3400,6 +3473,7 @@ rrsetadd(struct flush_set *flushset, const char *name, struct databuf *dp) { panic("rrsetadd: out of memory", NULL); dbl->db_next = NULL; dbl->db_dp = dp; + DRCNTINC(dbl->db_dp); if (fs->fs_last == NULL) fs->fs_list = dbl; else @@ -3664,6 +3738,7 @@ rrsetupdate(struct flush_set * flushset, int flags, struct sockaddr_in from, n); odbp = dbp; dbp = dbp->db_next; + db_detach(&odbp->db_dp); memput(odbp, sizeof *odbp); } ns_debug(ns_log_default, 3, @@ -3674,7 +3749,7 @@ rrsetupdate(struct flush_set * flushset, int flags, struct sockaddr_in from, (void)ttlcheck(fs->fs_name,fs->fs_list, 1); dbp = fs->fs_list; while (dbp) { - db_freedata(dbp->db_dp); + db_detach(&dbp->db_dp); odbp = dbp; dbp = dbp->db_next; memput(odbp, sizeof *odbp); @@ -3704,15 +3779,23 @@ flushrrset(struct flush_set * fs, struct sockaddr_in from) { from); ns_debug(ns_log_default, 3, "flushrrset: %d", n); } while (n == OK); - db_freedata(dp); + db_detach(&dp); } static void free_flushset(struct flush_set *flushset, int flushset_size) { struct flush_set *fs; + struct db_list *dbl; - for (fs = flushset; fs->fs_name != NULL; fs++) - freestr(fs->fs_name); + for (fs = flushset; fs->fs_name != NULL; fs++) { + fs->fs_name = freestr(fs->fs_name); + while ((dbl = fs->fs_list) != NULL) { + fs->fs_list = dbl->db_next; + dbl->db_next = NULL; + db_detach(&dbl->db_dp); + memput(dbl, sizeof(*dbl)); + } + } memput(flushset, flushset_size); } @@ -3727,7 +3810,7 @@ void delete_all(struct namebuf *np, int class, int type) { struct databuf *dp, *pdp; - ns_debug(ns_log_default, 3, "delete_all(%#x:\"%s\" %s %s)", + ns_debug(ns_log_default, 3, "delete_all(%p:\"%s\" %s %s)", np, NAME(*np), p_class(class), p_type(type)); pdp = NULL; dp = np->n_data; @@ -3849,6 +3932,22 @@ trunc_adjust(u_char *msg, int msglen, int outlen) { /* * mark the server "from" bad in the qp structure so it won't be retried. */ +static int +mark_noedns(struct qinfo *qp, struct sockaddr_in from) { + int i; + + for (i = 0; i < (int)qp->q_naddr; i++) + if (ina_equal(qp->q_addr[i].ns_addr.sin_addr, from.sin_addr)) { + if (qp->q_addr[i].noedns) + return (1); + if (qp->q_addr[i].nsdata) + qp->q_addr[i].nsdata->d_noedns = 1; + qp->q_addr[i].noedns = 1; + break; + } + return (0); +} + static void mark_bad(struct qinfo *qp, struct sockaddr_in from) { int i; @@ -3878,10 +3977,10 @@ mark_lame(struct qinfo *qp, struct sockaddr_in from) { * wrong interface an a multihomed server. */ static void -fast_retry(struct qinfo *qp, struct sockaddr_in from) { +fast_retry(struct qinfo *qp, struct sockaddr_in from, int samehost) { if (ina_equal(qp->q_addr[qp->q_curaddr].ns_addr.sin_addr, from.sin_addr)) - retry(qp); + retry(qp, samehost); } static void @@ -3892,7 +3991,7 @@ add_related_additional(char *name) { return; for (i = 0; i < num_related; i++) if (ns_samename(name, related[i]) == 1) { - freestr(name); + (void)freestr(name); return; } related[num_related++] = name; @@ -3903,7 +4002,7 @@ free_related_additional() { int i; for (i = 0; i < num_related; i++) - freestr(related[i]); + related[i] = freestr(related[i]); num_related = 0; } @@ -3921,8 +4020,7 @@ static void freestr_maybe(char **tname) { if (tname == NULL || *tname == NULL) return; - freestr(*tname); - *tname = NULL; + *tname = freestr(*tname); } /* diff --git a/contrib/bind/bin/named/ns_signal.c b/contrib/bind/bin/named/ns_signal.c index f5a6e24a00d4..0820bfae9c34 100644 --- a/contrib/bind/bin/named/ns_signal.c +++ b/contrib/bind/bin/named/ns_signal.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91"; -static const char rcsid[] = "$Id: ns_signal.c,v 8.13 2000/07/11 07:10:12 vixie Exp $"; +static const char rcsid[] = "$Id: ns_signal.c,v 8.14 2001/06/18 14:43:25 marka Exp $"; #endif /* not lint */ /* @@ -162,28 +162,43 @@ static int blocked = 0; static SIG_FN onhup(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_reload); } static SIG_FN onintr(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_exit); } static SIG_FN setdumpflg(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_dump); } #ifdef DEBUG static SIG_FN setIncrDbgFlg(int sig) { + + UNUSED(sig); + desired_debug++; ns_need_unsafe(main_need_debug); } static SIG_FN setNoDbgFlg(int sig) { + + UNUSED(sig); + desired_debug = 0; ns_need_unsafe(main_need_debug); } @@ -192,12 +207,18 @@ setNoDbgFlg(int sig) { #if defined(QRYLOG) && defined(SIGWINCH) static SIG_FN setQrylogFlg(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_qrylog); } #endif /*QRYLOG && SIGWINCH*/ static SIG_FN setstatsflg(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_statsdump); } @@ -207,6 +228,8 @@ discard_pipe(int sig) { int saved_errno = errno; struct sigaction sa; + UNUSED(sig); + memset(&sa, 0, sizeof sa); sa.sa_mask = mask; sa.sa_handler = discard_pipe; @@ -214,11 +237,16 @@ discard_pipe(int sig) { ns_error(ns_log_os, "sigaction failed in discard_pipe: %s", strerror(errno)); errno = saved_errno; +#else + UNUSED(sig); #endif } static SIG_FN setreapflg(int sig) { + + UNUSED(sig); + ns_need_unsafe(main_need_reap); } @@ -226,7 +254,7 @@ setreapflg(int sig) { void init_signals(void) { - int sh; + size_t sh; /* The mask of all our handlers will block all our other handlers. */ (void)sigemptyset(&mask); diff --git a/contrib/bind/bin/named/ns_sort.c b/contrib/bind/bin/named/ns_sort.c index 3b3f31edffbb..6489c4d12dce 100644 --- a/contrib/bind/bin/named/ns_sort.c +++ b/contrib/bind/bin/named/ns_sort.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_sort.c 4.10 (Berkeley) 3/3/91"; -static const char rcsid[] = "$Id: ns_sort.c,v 8.6 2000/04/21 06:54:13 vixie Exp $"; +static const char rcsid[] = "$Id: ns_sort.c,v 8.8 2001/09/25 04:50:22 marka Exp $"; #endif /* not lint */ /* @@ -183,6 +183,7 @@ static const char rcsid[] = "$Id: ns_sort.c,v 8.6 2000/04/21 06:54:13 vixie Exp #include #include #include +#include #include #include @@ -240,6 +241,7 @@ sort_response(u_char *cp, u_char *eom, int ancount, struct sockaddr_in *from) { indirect = 1; break; default: + indirect = 0; panic("unexpected ime type in ip_match_address()", NULL); } @@ -282,6 +284,7 @@ sort_response(u_char *cp, u_char *eom, int ancount, struct sockaddr_in *from) { iml = imematch->next->u.indirect.list; break; default: + iml = NULL; panic("unexpected ime type in ip_match_address()", NULL); } @@ -303,9 +306,9 @@ sort_response(u_char *cp, u_char *eom, int ancount, struct sockaddr_in *from) { static int sort_rr(u_char *cp, u_char *eom, int ancount, ip_match_list iml) { - int type, class, dlen, n, c, distance, closest; + int type, class, dlen, n, c, distance, closest = 0; struct in_addr inaddr; - u_char *rr1 = NULL, *rrbest, *cpstart; + u_char *rr1 = NULL, *rrbest = NULL, *cpstart; rr1 = NULL; cpstart = cp; @@ -384,6 +387,7 @@ ip_match_address_elt(ip_match_list iml, struct in_addr address, indirect = 1; break; default: + indirect = 0; panic("unexpected ime type in ip_match_address()", NULL); } diff --git a/contrib/bind/bin/named/ns_stats.c b/contrib/bind/bin/named/ns_stats.c index 0af3e2f3e172..3c5abb1f0670 100644 --- a/contrib/bind/bin/named/ns_stats.c +++ b/contrib/bind/bin/named/ns_stats.c @@ -1,6 +1,6 @@ #if !defined(lint) && !defined(SABER) static const char sccsid[] = "@(#)ns_stats.c 4.10 (Berkeley) 6/27/90"; -static const char rcsid[] = "$Id: ns_stats.c,v 8.32.2.1 2001/08/09 14:04:49 marka Exp $"; +static const char rcsid[] = "$Id: ns_stats.c,v 8.34 2001/08/09 13:17:21 marka Exp $"; #endif /* not lint */ /* @@ -381,6 +381,11 @@ ns_logstats(evContext ctx, void *uap, struct timespec due, #ifdef HAVE_GETRUSAGE # define tv_float(tv) ((tv).tv_sec + ((tv).tv_usec / 1000000.0)) + UNUSED(ctx); + UNUSED(uap); + UNUSED(due); + UNUSED(inter); + getrusage(RUSAGE_SELF, &usage); getrusage(RUSAGE_CHILDREN, &childu); diff --git a/contrib/bind/bin/named/ns_update.c b/contrib/bind/bin/named/ns_update.c index 4ad697bc28d0..774bd2c96567 100644 --- a/contrib/bind/bin/named/ns_update.c +++ b/contrib/bind/bin/named/ns_update.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_update.c,v 8.91.2.2 2001/04/30 03:20:46 marka Exp $"; +static const char rcsid[] = "$Id: ns_update.c,v 8.103 2002/01/03 00:25:02 marka Exp $"; #endif /* not lint */ /* @@ -105,7 +105,7 @@ static struct map m_opcode[] = { #define M_CLASS_CNT m_class_cnt #define M_TYPE_CNT m_type_cnt -static char *opcodes[] = { +static const char *opcodes[] = { "delete", "add", "", @@ -734,53 +734,59 @@ prescan_nameok(ns_updrec *ur, int *rcodep, u_int16_t zclass, u_int16_t type = ur->r_type; char *cp = (char *)ur->r_dp->d_data; enum context context; + enum transport transport; /* We don't care about deletes */ if (ur->r_class != zclass) return (1); - context = ns_ownercontext(type, primary_trans); - if (!ns_nameok(NULL, owner, class, zp, primary_trans, context, owner, + if (zp->z_type == Z_PRIMARY) + transport = primary_trans; + else + transport = secondary_trans; + + context = ns_ownercontext(type, transport); + if (!ns_nameok(NULL, owner, class, zp, transport, context, owner, inaddr_any)) goto refused; switch (type) { case ns_t_soa: context = hostname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; cp += strlen(cp) + 1; context = mailname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_rp: context = mailname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; cp += strlen(cp) + 1; context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_minfo: context = mailname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; cp += strlen(cp) + 1; context = mailname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_ns: context = hostname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; @@ -789,13 +795,13 @@ prescan_nameok(ns_updrec *ur, int *rcodep, u_int16_t zclass, case ns_t_mg: case ns_t_mr: context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_ptr: context = ns_ptrcontext(owner); - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; @@ -812,7 +818,7 @@ prescan_nameok(ns_updrec *ur, int *rcodep, u_int16_t zclass, /* Pattern (txt) */ cp += (*cp&0xff) + 1; context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; @@ -825,18 +831,18 @@ prescan_nameok(ns_updrec *ur, int *rcodep, u_int16_t zclass, case ns_t_kx: cp += 2; context = hostname_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_px: cp += 2; context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; cp += strlen(cp) + 1; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; @@ -852,13 +858,13 @@ prescan_nameok(ns_updrec *ur, int *rcodep, u_int16_t zclass, */ cp += 18; context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; case ns_t_nxt: context = domain_ctx; - if (!ns_nameok(NULL, cp, class, zp, primary_trans, context, owner, + if (!ns_nameok(NULL, cp, class, zp, transport, context, owner, inaddr_any)) goto refused; break; @@ -977,7 +983,7 @@ process_updates(const ns_updque *updlist, int *rcodep, ns_debug(ns_log_update, 3, "process_update: record section=%s, dname=%s, \ -class=%s, type=%s, ttl=%d, dp=0x%0x", +class=%s, type=%s, ttl=%d, dp=%p", p_section(section, ns_o_update), dname, p_class(class), p_type(type), ttl, rdp); @@ -1048,7 +1054,7 @@ class=%s, type=%s, ttl=%d, dp=0x%0x", n); } else { ns_debug(ns_log_update, 3, - "process_updates: added databuf 0x%0x", + "process_updates: added databuf %p", dp); dp->d_mark = D_MARK_ADDED; numupdated++; @@ -1135,8 +1141,8 @@ class=%s, type=%s, ttl=%d, dp=0x%0x", static enum req_action req_update_private(HEADER *hp, u_char *cp, u_char *eom, u_char *msg, - struct qstream *qsp, int dfd, struct sockaddr_in from, - struct tsig_record *in_tsig, ns_updque *curupd) + struct sockaddr_in from, struct tsig_record *in_tsig, + ns_updque *curupd) { char dnbuf[MAXDNAME], *dname; u_int zocount, prcount, upcount, adcount, class, type, dlen; @@ -1340,7 +1346,6 @@ req_update_private(HEADER *hp, u_char *cp, u_char *eom, u_char *msg, dp->d_secure = DB_S_INSECURE; /* should be UNCHECKED */ dp->d_clev = nlabels(zp->z_origin); /* XXX - also record in dp->d_ns, which host this came from */ - DRCNTINC(dp); rrecp->r_dp = dp; /* Append the current record to the end of list of records. */ APPEND(*curupd, rrecp, r_link); @@ -1380,7 +1385,8 @@ void free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { ns_updrec *rrecp, *first_rrecp, *next_rrecp; struct databuf *dp, *tmpdp; - char *dname, *msg; + char *dname; + const char *msg; if (rcode == NOERROR) { first_rrecp = HEAD(*updlist); @@ -1389,7 +1395,7 @@ free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { first_rrecp = TAIL(*updlist); msg = "free_rrecp: update transaction aborted, rolling back"; } - ns_debug(ns_log_update, 1, msg); + ns_debug(ns_log_update, 1, "%s", msg); for (rrecp = first_rrecp; rrecp != NULL; rrecp = next_rrecp) { if (rcode == NOERROR) next_rrecp = NEXT(rrecp, r_link); @@ -1397,12 +1403,8 @@ free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { next_rrecp = PREV(rrecp, r_link); UNLINK(*updlist, rrecp, r_link); if (rrecp->r_section != S_UPDATE) { - if (rrecp->r_dp) { - DRCNTDEC(rrecp->r_dp); - if (rrecp->r_dp->d_rcnt == 0) - db_freedata(rrecp->r_dp); - rrecp->r_dp = NULL; - } + if (rrecp->r_dp) + db_detach(&rrecp->r_dp); INSIST(rrecp->r_deldp == NULL); res_freeupdrec(rrecp); continue; @@ -1428,24 +1430,12 @@ free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { dname, p_type(dp->d_type)); } else { ns_debug(ns_log_update, 3, - "free_rrecp: deleted databuf 0x%0x", + "free_rrecp: deleted databuf %p", dp); - /* - * XXXRTH - * - * We used to db_freedata() here, - * but I removed it because 'dp' was - * part of a hashtab before we called - * db_update(), and since our delete - * has succeeded, it should have been - * freed. - */ } } } - DRCNTDEC(dp); - if (dp->d_rcnt == 0) - db_freedata(dp); + db_detach(&dp); /* Process deleted databuf's. */ dp = rrecp->r_deldp; @@ -1464,13 +1454,11 @@ free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { dname, p_type(tmpdp->d_type)); } else { ns_debug(ns_log_update, 3, - "free_rrecp: added back databuf 0x%0x", + "free_rrecp: added back databuf %p", tmpdp); } } - DRCNTDEC(tmpdp); - if (tmpdp->d_rcnt == 0) - db_freedata(tmpdp); + db_detach(&tmpdp); } res_freeupdrec(rrecp); } @@ -1478,15 +1466,13 @@ free_rrecp(ns_updque *updlist, int rcode, struct sockaddr_in from) { enum req_action req_update(HEADER *hp, u_char *cp, u_char *eom, u_char *msg, - struct qstream *qsp, int dfd, struct sockaddr_in from, - struct tsig_record *in_tsig) + struct sockaddr_in from, struct tsig_record *in_tsig) { enum req_action ret; ns_updque curupd; INIT_LIST(curupd); - ret = req_update_private(hp, cp, eom, msg, qsp, dfd, from, - in_tsig, &curupd); + ret = req_update_private(hp, cp, eom, msg, from, in_tsig, &curupd); free_rrecp(&curupd, ret == Refuse ? ns_r_refused : hp->rcode, from); if (ret == Finish) { hp->qdcount = hp->ancount = hp->nscount = hp->arcount = 0; @@ -1628,13 +1614,13 @@ rdata_expand(const u_char *msg, const u_char *eom, const u_char *cp, cp += SIG_HDR_SIZE; cp1 += SIG_HDR_SIZE; n = dn_expand(msg, eom, cp, (char *)cp1, size); - if (n < 0 || n + SIG_HDR_SIZE > dlen) + if (n < 0 || n + SIG_HDR_SIZE > (int)dlen) return (0); cp += n; n1 = dlen - n - SIG_HDR_SIZE; n = strlen((char *)cp1) + 1; cp1 += n; - if (size < n1) + if ((int)size < n1) return (0); memcpy(cp1, cp, n1); cp1 += n1; @@ -1665,14 +1651,16 @@ rdata_expand(const u_char *msg, const u_char *eom, const u_char *cp, if (n1 < 4 || n1 > 16) return (0); } - if (n1 > size) + if (n1 > (int)size) return (0); memcpy(cp1, cp, n1); cp1 += n1; return (cp1 - cp1init); default: - ns_debug(ns_log_update, 3, "unknown type %d", type); - return (0); + if (size < dlen) + return (0); + memcpy(cp1, cp, dlen); + return (dlen); } } @@ -1917,7 +1905,13 @@ rdata_dump(struct databuf *dp, FILE *fp) { break; } default: - fprintf(fp, "\t;?d_type=%d?", dp->d_type); + fprintf(fp, "\\# %u", dp->d_size); + if (dp->d_size) { + fputs(" ( ", fp); + isc_puthexstring(fp, dp->d_data, dp->d_size, + 28, 48, "\n\t\t\t\t"); + fputs(" )", fp); + } } } @@ -1937,7 +1931,7 @@ findzone(const char *dname, int class, int depth, int *zonelist, int maxzones){ int escaped, found, done; ns_debug(ns_log_update, 4, "findzone(dname=%s, class=%d, depth=%d, \ -zonelist=0x%x, maxzones=%d)", +zonelist=%p, maxzones=%d)", dname, class, depth, zonelist, maxzones); #ifdef DEBUG if (debug >= 5) { @@ -2068,7 +2062,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { u_int32_t serial, ttl, old_serial, new_serial; char *dname, *cp, *cp1; int type, class; - int i, c, section, opcode, matches, zonenum, err, multiline; + int i, c, section, opcode, matches, zonenum = 0, err, multiline; int nonempty_lineno = -1, prev_pktdone = 0, cont = 0, inside_next = 0; int id, rcode = NOERROR; u_int32_t n; @@ -2082,6 +2076,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { int datasize; unsigned long l; ns_updque curupd; + unsigned long lutmp; empty_from.sin_family = AF_INET; empty_from.sin_addr.s_addr = htonl(INADDR_ANY); @@ -2151,6 +2146,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { INIT_LIST(curupd); for (;;) { err = 0; + dname = NULL; if (!getword(buf, sizeof buf, fp, 0)) { if (lineno == (nonempty_lineno + 1) && !(feof(fp))) { /* @@ -2223,6 +2219,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { if (!EMPTY(curupd)) { n = process_updates(&curupd, &rcode, empty_from); + free_rrecp(&curupd, rcode, empty_from); if (n > 0) ns_info(ns_log_update, "successfully merged update id %d from log file %s", @@ -2234,7 +2231,6 @@ merge_logs(struct zoneinfo *zp, char *logname) { fclose(fp); return(-1); } - free_rrecp(&curupd, rcode, empty_from); } prev_pktdone = 0; if (feof(fp)) @@ -2270,7 +2266,8 @@ merge_logs(struct zoneinfo *zp, char *logname) { if (!cp) *buf = '\0'; n = sscanf(cp, "origin %s class %s serial %lu", - origin, sclass, &serial); + origin, sclass, &lutmp); + serial = lutmp; if (n != 3 || ns_samename(origin, zp->z_origin) != 1) err++; if (cp) @@ -2288,8 +2285,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { dname = origin; type = T_SOA; - class = sym_ston(__p_class_syms, sclass, - &success); + class = res_nametoclass(sclass, &success); if (!success) { err++; break; @@ -2355,9 +2351,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { int success; int maybe_class; - maybe_class = sym_ston(__p_class_syms, - buf, - &success); + maybe_class = res_nametoclass(buf, &success); if (success) { class = maybe_class; (void) getword(buf, @@ -2370,9 +2364,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { int success; int maybe_type; - maybe_type = sym_ston(__p_type_syms, - buf, - &success); + maybe_type = res_nametotype(buf, &success); if (success) { type = maybe_type; @@ -2618,7 +2610,7 @@ merge_logs(struct zoneinfo *zp, char *logname) { case ns_t_nxt: case ns_t_cert: { - char * errmsg = NULL; + const char * errmsg = NULL; int s; s = parse_sec_rdata(buf, sizeof(buf), @@ -2637,7 +2629,40 @@ merge_logs(struct zoneinfo *zp, char *logname) { break; } default: - err++; + if (strcmp(buf, "\\#") != 0) { + err++; + break; + } + if (!getword(buf, sizeof buf, fp, 0) || + !isdigit((unsigned char)buf[0])) { + err++; + break; + } + n = strtoul(buf, &cp, 10); + if (n > 0xffff || *cp != '\0') { + err++; + break; + } + multiline = 0; + i = isc_gethexstring((u_char *)data, + sizeof(data), + n, fp, &multiline); + if (i == -1) { + err++; + break; + } + if (multiline) { + c = getnonblank(fp, + zp->z_updatelog, + 1); + if (c != ')') { + ungetc(c, fp); + err++; + break; + } + multiline = 0; + } + endline(fp); } if (section == S_PREREQ) { ttl = 0; @@ -2687,12 +2712,12 @@ merge_logs(struct zoneinfo *zp, char *logname) { err++; } if (err) { - inside_next = 0; ns_debug(ns_log_update, 1, "merge of update id %d failed due to error at line %d", id, lineno); free_rrecp(&curupd, FORMERR, empty_from); - continue; + fclose(fp); + return(-1); } rrecp = res_mkupdrec(section, dname, class, type, ttl); if (section != S_ZONE) { @@ -2701,7 +2726,6 @@ merge_logs(struct zoneinfo *zp, char *logname) { dp->d_cred = DB_C_ZONE; dp->d_clev = nlabels(zp->z_origin); dp->d_secure = DB_S_INSECURE; /* should be UNCHECKED */ - DRCNTINC(dp); rrecp->r_dp = dp; } else { rrecp->r_zone = zonenum; diff --git a/contrib/bind/bin/named/ns_xfr.c b/contrib/bind/bin/named/ns_xfr.c index 836195bff05d..ab23b6bf6782 100644 --- a/contrib/bind/bin/named/ns_xfr.c +++ b/contrib/bind/bin/named/ns_xfr.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ns_xfr.c,v 8.64 2001/02/15 00:18:46 marka Exp $"; +static const char rcsid[] = "$Id: ns_xfr.c,v 8.67 2001/07/10 05:06:50 marka Exp $"; #endif /* not lint */ /* @@ -107,7 +107,7 @@ ns_xfr(struct qstream *qsp, struct namebuf *znp, * write() data from us. */ (void) setsockopt(qsp->s_rfd, SOL_SOCKET, SO_SNDBUF, - (char *)&sndbuf, sizeof sndbuf); + (const char *)&sndbuf, sizeof sndbuf); #endif #ifdef SO_SNDLOWAT /* @@ -115,7 +115,7 @@ ns_xfr(struct qstream *qsp, struct namebuf *znp, * an XFER_BUFSIZE block of data. */ (void) setsockopt(qsp->s_rfd, SOL_SOCKET, SO_SNDLOWAT, - (char *)&sndlowat, sizeof sndlowat); + (const char *)&sndlowat, sizeof sndlowat); #endif if (sq_openw(qsp, 64*1024) == -1) { ns_error(ns_log_xfer_out, "ns_xfr: out of memory"); @@ -263,8 +263,7 @@ ns_freexfr(struct qstream *qsp) { while ((rp = HEAD(dp->d_changes)) != NULL) { UNLINK(dp->d_changes, rp, r_link); if (rp->r_dp != NULL) - db_freedata(rp->r_dp); - rp->r_dp = NULL; + db_detach(&rp->r_dp); res_freeupdrec(rp); } memput(dp, sizeof *dp); @@ -274,6 +273,10 @@ ns_freexfr(struct qstream *qsp) { } while (qsp->xfr.lev) qsp->xfr.lev = sx_freelev(qsp->xfr.lev); + if (qsp->xfr.tsig_state != NULL) { + memput(qsp->xfr.tsig_state, sizeof(ns_tcp_tsig_state)); + qsp->xfr.tsig_state = NULL; + } zones[qsp->xfr.zone].z_numxfrs--; qsp->flags &= ~(STREAM_AXFR | STREAM_AXFRIXFR); } @@ -416,7 +419,7 @@ sx_addrr(struct qstream *qsp, const char *dname, struct databuf *dp) { * side effects: * if progress was made, header and pointers will be advanced. */ -int +static int sx_soarr(struct qstream *qsp) { struct databuf *dp; int added_soa = 0; @@ -840,11 +843,8 @@ static struct qs_x_lev * sx_freelev(struct qs_x_lev *lev) { struct qs_x_lev *next = lev->next; - if (lev->dp) { - DRCNTDEC(lev->dp); - if (lev->dp->d_rcnt == 0) - db_freedata(lev->dp); - } + if (lev->dp) + db_detach(&lev->dp); memput(lev, sizeof *lev); return (next); } @@ -853,10 +853,7 @@ static struct databuf * db_next(struct databuf *dp) { struct databuf *next = dp->d_next; - DRCNTDEC(dp); - if (dp->d_rcnt == 0) - db_freedata(dp); - + db_detach(&dp); if (next) DRCNTINC(next); diff --git a/contrib/bind/bin/ndc/ndc.c b/contrib/bind/bin/ndc/ndc.c index 9daf69f5ddaa..aa0e4a373046 100644 --- a/contrib/bind/bin/ndc/ndc.c +++ b/contrib/bind/bin/ndc/ndc.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ndc.c,v 1.16.2.1 2001/04/26 02:56:10 marka Exp $"; +static const char rcsid[] = "$Id: ndc.c,v 1.21 2001/12/19 23:16:23 marka Exp $"; #endif /* not lint */ /* @@ -60,7 +60,7 @@ typedef void (*closure)(void *, const char *, int); static const char * program = "amnesia"; static enum { e_channel, e_signals } mode = e_channel; -static char * channel = _PATH_NDCSOCK; +static const char * channel = _PATH_NDCSOCK; static const char helpfmt[] = "\t%-16s\t%s\n"; static const char * pidfile = _PATH_PIDFILE; static sockaddr_t client, server; @@ -77,23 +77,23 @@ static int builtincmd(void); static void command(void); static int running(int, pid_t *); static void command_channel(void); -static void channel_loop(char *, int, closure, void *); +static void channel_loop(const char *, int, closure, void *); static void getpid_closure(void *, const char *, int); static void banner(struct ctl_cctx *, void *, const char *, u_int); static void done(struct ctl_cctx *, void *, const char *, u_int); -static void logger(enum ctl_severity, const char *fmt, ...); +static void logger(enum ctl_severity, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3); static void command_signals(void); static void stop_named(pid_t); static void start_named(const char *, int); static int fgetpid(const char *, pid_t *); -static int get_sockaddr(char *, sockaddr_t *); +static int get_sockaddr(const char *, sockaddr_t *); static size_t impute_addrlen(const struct sockaddr *); static void vtrace(const char *, va_list); -static void trace(const char *, ...); -static void result(const char *, ...); -static void fatal(const char *, ...); -static void verror(const char *, va_list); -static void error(const char *, ...); +static void trace(const char *, ...) ISC_FORMAT_PRINTF(1, 2); +static void result(const char *, ...) ISC_FORMAT_PRINTF(1, 2); +static void fatal(const char *, ...) ISC_FORMAT_PRINTF(1, 2); +static void verror(const char *, va_list) ISC_FORMAT_PRINTF(1, 0); +static void error(const char *, ...) ISC_FORMAT_PRINTF(1, 2); static void usage(const char *fmt, ...) { @@ -114,7 +114,7 @@ usage(const char *fmt, ...) { /* Public. */ int -main(int argc, char *argv[], char *envp[]) { +main(int argc, char *argv[]) { char *p; int ch; @@ -402,7 +402,7 @@ struct args { }; static void -channel_loop(char *cmdtext, int show, closure cl, void *ua) { +channel_loop(const char *cmdtext, int show, closure cl, void *ua) { struct ctl_cctx *ctl; struct sockaddr *client_addr; struct args a; @@ -457,6 +457,8 @@ static void done(struct ctl_cctx *ctl, void *uap, const char *msg, u_int flags) { struct args *a = uap; + UNUSED(ctl); + if (msg == NULL) { trace("EOF"); doneflag = 1; @@ -488,6 +490,7 @@ logger(enum ctl_severity ctlsev, const char *format, ...) { verror(format, args); break; default: + va_end(args); abort(); } va_end(args); @@ -507,7 +510,7 @@ static struct cmdsig { { "querylog", SIGWINCH, "toggle query logging" }, { "qrylog", SIGWINCH, "alias for querylog" }, #endif - { NULL, 0 } + { NULL, 0, NULL } }; static void @@ -599,15 +602,15 @@ fgetpid(const char *f, pid_t *pid) { long t; for (try = 0; try < 5; try++) { - trace("pidfile is \"%s\" (try #%d)", pidfile, try + 1); - if ((fp = fopen(pidfile, "r")) == NULL) + trace("pidfile is \"%s\" (try #%d)", f, try + 1); + if ((fp = fopen(f, "r")) == NULL) trace("pid file (%s) unavailable - %s", - pidfile, strerror(errno)); + f, strerror(errno)); else if (fscanf(fp, "%ld\n", &t) != 1) - trace("pid file (%s) format is bad", pidfile); + trace("pid file (%s) format is bad", f); else if (*pid = (pid_t)t, fclose(fp), kill(*pid, 0) < 0) trace("pid file (%s) contains unusable pid (%d) - %s", - pidfile, *pid, strerror(errno)); + f, *pid, strerror(errno)); else { trace("pid is %ld", (long)*pid); return (1); @@ -619,7 +622,7 @@ fgetpid(const char *f, pid_t *pid) { } static int -get_sockaddr(char *name, sockaddr_t *addr) { +get_sockaddr(const char *name, sockaddr_t *addr) { char *slash; #ifndef NO_SOCKADDR_UN @@ -651,7 +654,7 @@ get_sockaddr(char *name, sockaddr_t *addr) { static size_t impute_addrlen(const struct sockaddr *sa) { - if (sa == 0) + if (sa == NULL) return (0); switch (sa->sa_family) { case AF_INET: @@ -663,6 +666,7 @@ impute_addrlen(const struct sockaddr *sa) { default: abort(); } + /*NOTREACHED*/ } static void diff --git a/contrib/bind/bin/nslookup/debug.c b/contrib/bind/bin/nslookup/debug.c index 9b30977f4df6..5dcf927ad6ae 100644 --- a/contrib/bind/bin/nslookup/debug.c +++ b/contrib/bind/bin/nslookup/debug.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)debug.c 5.26 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: debug.c,v 8.17 2000/11/08 06:47:31 marka Exp $"; +static const char rcsid[] = "$Id: debug.c,v 8.19 2001/09/25 04:50:26 marka Exp $"; #endif /* not lint */ /* @@ -80,6 +80,7 @@ static const char rcsid[] = "$Id: debug.c,v 8.17 2000/11/08 06:47:31 marka Exp $ #include #include #include +#include #include "port_after.h" @@ -113,12 +114,12 @@ Fprint_query(const u_char *msg, const u_char *eom, int printHeader, FILE *file) const u_char *cp; const HEADER *hp; int n; - u_int class, type; + u_int class, type = 0; /* * Print header fields. */ - hp = (HEADER *)msg; + hp = (const HEADER *)msg; cp = msg + HFIXEDSZ; if (printHeader || (res.options & RES_DEBUG2)) { fprintf(file," HEADER:\n"); @@ -162,9 +163,9 @@ Fprint_query(const u_char *msg, const u_char *eom, int printHeader, FILE *file) cp = Print_cdname(cp, msg, eom, file); if (cp == NULL) return; - type = ns_get16((u_char*)cp); + type = ns_get16((const u_char*)cp); cp += INT16SZ; - class = ns_get16((u_char*)cp); + class = ns_get16((const u_char*)cp); cp += INT16SZ; fprintf(file,", type = %s", p_type(type)); fprintf(file,", class = %s\n", p_class(class)); @@ -217,7 +218,7 @@ Fprint_query(const u_char *msg, const u_char *eom, int printHeader, FILE *file) fprintf(file,"\n------------\n"); } -const u_char * +static const u_char * Print_cdname_sub(const u_char *cp, const u_char *msg, const u_char *eom, FILE *file, int format) { @@ -323,16 +324,16 @@ Print_rr(const u_char *ocp, const u_char *msg, const u_char *eom, FILE *file) { case T_MX: BOUNDS_CHECK(cp, INT16SZ); - fprintf(file,"\tpreference = %u",ns_get16((u_char*)cp)); + fprintf(file,"\tpreference = %u",ns_get16((const u_char*)cp)); cp += INT16SZ; fprintf(file,", mail exchanger = "); goto doname; case T_NAPTR: BOUNDS_CHECK(cp, 2 * INT16SZ); - fprintf(file, "\torder = %u",ns_get16((u_char*)cp)); + fprintf(file, "\torder = %u",ns_get16((const u_char*)cp)); cp += INT16SZ; - fprintf(file,", preference = %u\n", ns_get16((u_char*)cp)); + fprintf(file,", preference = %u\n", ns_get16((const u_char*)cp)); cp += INT16SZ; /* Flags */ BOUNDS_CHECK(cp, 1); @@ -364,11 +365,11 @@ Print_rr(const u_char *ocp, const u_char *msg, const u_char *eom, FILE *file) { case T_SRV: BOUNDS_CHECK(cp, 3 * INT16SZ); - fprintf(file, "\tpriority = %u",ns_get16((u_char*)cp)); + fprintf(file, "\tpriority = %u",ns_get16((const u_char*)cp)); cp += INT16SZ; - fprintf(file,", weight = %u", ns_get16((u_char*)cp)); + fprintf(file,", weight = %u", ns_get16((const u_char*)cp)); cp += INT16SZ; - fprintf(file,", port= %u\n", ns_get16((u_char*)cp)); + fprintf(file,", port= %u\n", ns_get16((const u_char*)cp)); cp += INT16SZ; fprintf(file,"\thost = "); @@ -376,7 +377,7 @@ Print_rr(const u_char *ocp, const u_char *msg, const u_char *eom, FILE *file) { case T_PX: BOUNDS_CHECK(cp, INT16SZ); - fprintf(file,"\tpreference = %u",ns_get16((u_char*)cp)); + fprintf(file,"\tpreference = %u",ns_get16((const u_char*)cp)); cp += INT16SZ; fprintf(file,", RFC 822 = "); cp = Print_cdname(cp, msg, eom, file); @@ -395,14 +396,14 @@ Print_rr(const u_char *ocp, const u_char *msg, const u_char *eom, FILE *file) { case T_RT: BOUNDS_CHECK(cp, INT16SZ); - fprintf(file,"\tpreference = %u",ns_get16((u_char*)cp)); + fprintf(file,"\tpreference = %u",ns_get16((const u_char*)cp)); cp += INT16SZ; fprintf(file,", router = "); goto doname; case T_AFSDB: BOUNDS_CHECK(cp, INT16SZ); - fprintf(file,"\tsubtype = %d",ns_get16((u_char*)cp)); + fprintf(file,"\tsubtype = %d",ns_get16((const u_char*)cp)); cp += INT16SZ; fprintf(file,", DCE/AFS server = "); goto doname; @@ -469,18 +470,18 @@ Print_rr(const u_char *ocp, const u_char *msg, const u_char *eom, FILE *file) { return (NULL); /* compression error */ } BOUNDS_CHECK(cp, 5 * INT32SZ); - fprintf(file,"\n\tserial = %lu", ns_get32((u_char*)cp)); + fprintf(file,"\n\tserial = %lu", ns_get32((const u_char*)cp)); cp += INT32SZ; - ttl = ns_get32((u_char*)cp); + ttl = ns_get32((const u_char*)cp); fprintf(file,"\n\trefresh = %lu (%s)", ttl, p_time(ttl)); cp += INT32SZ; - ttl = ns_get32((u_char*)cp); + ttl = ns_get32((const u_char*)cp); fprintf(file,"\n\tretry = %lu (%s)", ttl, p_time(ttl)); cp += INT32SZ; - ttl = ns_get32((u_char*)cp); + ttl = ns_get32((const u_char*)cp); fprintf(file,"\n\texpire = %lu (%s)", ttl, p_time(ttl)); cp += INT32SZ; - ttl = ns_get32((u_char*)cp); + ttl = ns_get32((const u_char*)cp); fprintf(file, "\n\tminimum ttl = %lu (%s)\n", ttl, p_time(ttl)); cp += INT32SZ; diff --git a/contrib/bind/bin/nslookup/getinfo.c b/contrib/bind/bin/nslookup/getinfo.c index 8b5cf384a923..68e3d75209c1 100644 --- a/contrib/bind/bin/nslookup/getinfo.c +++ b/contrib/bind/bin/nslookup/getinfo.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)getinfo.c 5.26 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: getinfo.c,v 8.18 2001/02/27 06:03:40 vixie Exp $"; +static const char rcsid[] = "$Id: getinfo.c,v 8.20 2001/06/20 12:30:33 marka Exp $"; #endif /* not lint */ /* @@ -88,8 +88,6 @@ static const char rcsid[] = "$Id: getinfo.c,v 8.18 2001/02/27 06:03:40 vixie Exp #include "res.h" -extern char *res_skip(); - static char *addr_list[MAXADDRS + 1]; static char *host_aliases[MAXALIASES]; @@ -148,7 +146,7 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) Boolean isServer; { register HEADER *headerPtr; - register u_char *cp; + register const u_char *cp; querybuf answer; char **aliasPtr; u_char *eom, *bp; @@ -157,7 +155,7 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) char *dnamePtr; int type, class; int qdcount, ancount, arcount, nscount, buflen; - int origClass; + int origClass = 0; int numAliases = 0; int numAddresses = 0; int n, i, j; @@ -238,8 +236,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) if (queryType != T_A && !(iquery && queryType == T_PTR)) { while (--ancount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (u_char *)&answer, eom, stdout)) == NULL) { + if ((cp = Print_rr(cp, (u_char *)&answer, + eom, stdout)) == NULL) { return(ERROR); } } @@ -391,7 +389,7 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) printf("Authoritative answers can be found from:\n"); } - cp = (u_char *)res_skip((char *) &answer, 2, eom); + cp = res_skip((u_char *)&answer, 2, eom); numServers = 0; if (queryType != T_A) { @@ -399,8 +397,8 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) * If we don't need to save the record, just print it. */ while (--nscount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (u_char *) &answer, eom, stdout)) == NULL) { + if ((cp = Print_rr(cp, (u_char *) &answer, + eom, stdout)) == NULL) { return(ERROR); } } @@ -476,15 +474,15 @@ GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) /* * Additional resource records contain addresses of servers. */ - cp = (u_char *)res_skip((char *) &answer, 3, eom); + cp = res_skip((u_char*)&answer, 3, eom); if (queryType != T_A) { /* * If we don't need to save the record, just print it. */ while (--arcount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (u_char *) &answer, eom, stdout)) == NULL) { + if ((cp = Print_rr(cp, (u_char *) &answer, + eom, stdout)) == NULL) { return(ERROR); } } @@ -592,7 +590,7 @@ GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer) struct in_addr *nsAddrPtr; int queryClass; int queryType; - char *name; + const char *name; HostInfo *hostPtr; Boolean isServer; { @@ -698,13 +696,14 @@ GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer) struct in_addr *nsAddrPtr; int queryClass; int queryType; - char *name, *domain; + const char *name; + char *domain; HostInfo *hostPtr; Boolean isServer; { querybuf buf; char nbuf[2*MAXDNAME+2]; - char *longname = nbuf; + const char *longname = nbuf; int n; if (domain == NULL) { @@ -713,7 +712,7 @@ GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer) * copy without '.' if present. */ n = strlen(name) - 1; - if (name[n] == '.' && n < sizeof(nbuf) - 1) { + if (name[n] == '.' && n < (int)sizeof(nbuf) - 1) { memcpy(nbuf, name, n); nbuf[n] = '\0'; } else diff --git a/contrib/bind/bin/nslookup/list.c b/contrib/bind/bin/nslookup/list.c index 863d43356f71..c910230f5337 100644 --- a/contrib/bind/bin/nslookup/list.c +++ b/contrib/bind/bin/nslookup/list.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)list.c 5.23 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: list.c,v 8.25 2000/12/23 08:14:46 vixie Exp $"; +static const char rcsid[] = "$Id: list.c,v 8.26 2001/06/18 14:43:38 marka Exp $"; #endif /* not lint */ /* @@ -434,7 +434,7 @@ ListSubr(int qtype, char *domain, char *cmd) { strcpy(origin, name); strcpy(name_ctx, "@"); } - if (qtype == T_ANY || ns_rr_type(rr) == qtype) { + if (qtype == T_ANY || (int)ns_rr_type(rr) == qtype) { if (ns_sprintrr(&handle, &rr, name_ctx, origin, buf, sizeof buf) < 0) { perror("ns_sprintrr"); diff --git a/contrib/bind/bin/nslookup/main.c b/contrib/bind/bin/nslookup/main.c index b27b4180f435..6827c095dc65 100644 --- a/contrib/bind/bin/nslookup/main.c +++ b/contrib/bind/bin/nslookup/main.c @@ -77,7 +77,7 @@ char copyright[] = #ifndef lint static const char sccsid[] = "@(#)main.c 5.42 (Berkeley) 3/3/91"; -static const char rcsid[] = "$Id: main.c,v 8.16 2000/12/23 08:14:47 vixie Exp $"; +static const char rcsid[] = "$Id: main.c,v 8.20 2001/06/20 12:40:06 marka Exp $"; #endif /* not lint */ /* @@ -168,7 +168,7 @@ int queryClass = C_IN; * Stuff for Interrupt (control-C) signal handler. */ -extern SIG_FN IntrHandler(); +extern SIG_FN IntrHandler(int); FILE *filePtr; jmp_buf env; @@ -176,10 +176,10 @@ jmp_buf env; /* * Browser command for help. */ -char *pager; +const char *pager; -static void CvtAddrToPtr(); -static void ReadRC(); +static void CvtAddrToPtr(char *name); +static void ReadRC(void); /* * Forward declarations. @@ -188,6 +188,7 @@ static void LocalServer(HostInfo *defaultPtr); static void res_re_init(void); static void res_dnsrch(char *cp); static void Usage(void); +static void ShowOptions(void); /* ****************************************************************************** @@ -381,7 +382,7 @@ main(int argc, char **argv) { } -void +static void LocalServer(defaultPtr) HostInfo *defaultPtr; { @@ -436,10 +437,10 @@ Usage(void) { Boolean IsAddr(host, addrPtr) - char *host; + const char *host; struct in_addr *addrPtr; /* If return TRUE, contains IP address */ { - register char *cp; + register const char *cp; if (isdigit(host[0])) { /* Make sure it has only digits and dots. */ @@ -1028,7 +1029,7 @@ SetOption(option) /* * Fake a reinitialization when the domain is changed. */ -void +static void res_re_init(void) { register char *cp, **pp; int n; @@ -1050,7 +1051,7 @@ res_re_init(void) { #define SRCHLIST_SEP '/' -void +static void res_dnsrch(char *cp) { char **pp; int n; @@ -1093,8 +1094,8 @@ res_dnsrch(char *cp) { ****************************************************************************** */ -void -ShowOptions() +static void +ShowOptions(void) { register char **cp; @@ -1144,7 +1145,7 @@ ShowOptions() */ void -PrintHelp() +PrintHelp(void) { char cmd[PATH_MAX]; @@ -1193,7 +1194,7 @@ CvtAddrToPtr(name) */ static void -ReadRC() +ReadRC(void) { register FILE *fp; register char *cp; diff --git a/contrib/bind/bin/nslookup/res.h b/contrib/bind/bin/nslookup/res.h index 2a07b179404c..79f863332faa 100644 --- a/contrib/bind/bin/nslookup/res.h +++ b/contrib/bind/bin/nslookup/res.h @@ -55,7 +55,7 @@ /* * @(#)res.h 5.10 (Berkeley) 6/1/90 - * $Id: res.h,v 8.7 2000/12/23 08:14:47 vixie Exp $ + * $Id: res.h,v 8.9 2001/06/20 12:30:34 marka Exp $ */ /* @@ -169,7 +169,6 @@ extern struct __res_state res; */ /* XXX need prototypes */ -extern Boolean IsAddr(); void Print_query(const u_char *msg, const u_char *eom, int printHeader); void Fprint_query(const u_char *msg, const u_char *eom, int printHeader, FILE *file); @@ -186,14 +185,14 @@ extern char *Malloc(); extern void NsError(); extern void PrintServer(); extern void PrintHostInfo(); -extern void ShowOptions(); extern void FreeHostInfoPtr(); extern FILE *OpenFile(); -extern char *res_skip(); extern int pickString(const char *, char *, size_t); -extern int GetHostInfoByName(); +extern int GetHostInfoByName(struct in_addr *, int, int, const char *, + HostInfo *, Boolean); extern int GetHostInfoByAddr(); -extern int GetHostDomain(); +extern int GetHostDomain(struct in_addr *, int, int, const char *, char *, + HostInfo *, Boolean); extern int matchString(const char *, const char *); extern int StringToType(char *, int, FILE *); extern int StringToClass(char *, int, FILE *); @@ -208,3 +207,17 @@ void ListHost_close(void); int SetOption(char *); int LookupHost(char *, Boolean); int LookupHostWithServer(char *, Boolean); +const char * DecodeType(int); +const char * DecodeError(int); +FILE * OpenFile(char *, char *, size_t); +void PrintHostInfo(FILE *, const char *, HostInfo *); +char * Calloc(int, int); +char * Malloc(int); +SIG_FN IntrHandler(int); +int ListSubr(int, char *, char *); +void FreeHostInfoPtr(HostInfo *); +unsigned char * res_skip(unsigned char *, int, unsigned char *); +extern Boolean IsAddr(const char *, struct in_addr *); +void PrintHelp(void); +int GetHostInfoByAddr(struct in_addr *, struct in_addr *, HostInfo *); + diff --git a/contrib/bind/bin/nslookup/send.c b/contrib/bind/bin/nslookup/send.c index 6af8873dbe5b..ecbd75de6e8a 100644 --- a/contrib/bind/bin/nslookup/send.c +++ b/contrib/bind/bin/nslookup/send.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)send.c 5.18 (Berkeley) 3/2/91"; -static const char rcsid[] = "$Id: send.c,v 8.10 2000/12/23 08:14:47 vixie Exp $"; +static const char rcsid[] = "$Id: send.c,v 8.12 2001/07/03 06:27:12 marka Exp $"; #endif /* not lint */ /* @@ -123,14 +123,15 @@ int SendRequest(struct in_addr *nsAddrPtr, const u_char *buf, int buflen, u_char *answer, u_int anslen, int *trueLenPtr) { - int n, try, v_circuit, resplen, salen; + int n, try, v_circuit, resplen; + ISC_SOCKLEN_T salen; int gotsomewhere = 0, connected = 0; int connreset = 0; u_short id, len; u_char *cp; fd_set dsmask; struct timeval timeout; - const HEADER *hp = (HEADER *) buf; + const HEADER *hp = (const HEADER *) buf; HEADER *anhp = (HEADER *) answer; struct iovec iov[2]; int terrno = ETIMEDOUT; @@ -183,7 +184,7 @@ SendRequest(struct in_addr *nsAddrPtr, const u_char *buf, int buflen, __putshort(buflen, (u_char *)&len); iov[0].iov_base = (caddr_t)&len; iov[0].iov_len = INT16SZ; - iov[1].iov_base = (caddr_t)buf; + DE_CONST(buf, iov[1].iov_base); iov[1].iov_len = buflen; if (writev(s, iov, 2) != INT16SZ + buflen) { terrno = errno; @@ -224,7 +225,7 @@ SendRequest(struct in_addr *nsAddrPtr, const u_char *buf, int buflen, continue; } cp = answer; - if ((resplen = ns_get16((u_char*)cp)) > anslen) { + if ((resplen = ns_get16((u_char*)cp)) > (int)anslen) { if (res.options & RES_DEBUG) fprintf(stderr, "response truncated\n"); len = anslen; diff --git a/contrib/bind/bin/nslookup/skip.c b/contrib/bind/bin/nslookup/skip.c index 5318ef657c23..4077523b2b35 100644 --- a/contrib/bind/bin/nslookup/skip.c +++ b/contrib/bind/bin/nslookup/skip.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)skip.c 5.12 (Berkeley) 3/21/91"; -static const char rcsid[] = "$Id: skip.c,v 8.5 1999/10/13 16:39:20 vixie Exp $"; +static const char rcsid[] = "$Id: skip.c,v 8.7 2001/06/20 12:30:35 marka Exp $"; #endif /* not lint */ /* @@ -84,8 +84,9 @@ static const char rcsid[] = "$Id: skip.c,v 8.5 1999/10/13 16:39:20 vixie Exp $"; #include #include "port_after.h" +#include "res.h" -char *res_skip_rr(); +static unsigned char *res_skip_rr(unsigned char *cp, unsigned char *eom); /* @@ -109,13 +110,13 @@ char *res_skip_rr(); ******************************************************************************* */ -char * +unsigned char * res_skip(msg, numFieldsToSkip, eom) - char *msg; + unsigned char *msg; int numFieldsToSkip; - char *eom; + unsigned char *eom; { - register char *cp; + register unsigned char *cp; register HEADER *hp; register int tmp; register int n; @@ -132,7 +133,7 @@ res_skip(msg, numFieldsToSkip, eom) n = ntohs(hp->qdcount); if (n > 0) { while (--n >= 0 && cp < eom) { - tmp = dn_skipname((u_char *)cp, (u_char *)eom); + tmp = dn_skipname(cp, eom); if (tmp == -1) return(NULL); cp += tmp; cp += INT16SZ; /* type */ @@ -193,15 +194,15 @@ res_skip(msg, numFieldsToSkip, eom) ******************************************************************************* */ -char * +static unsigned char * res_skip_rr(cp, eom) - char *cp; - char *eom; + unsigned char *cp; + unsigned char *eom; { int tmp; int dlen; - if ((tmp = dn_skipname((u_char *)cp, (u_char *)eom)) == -1) + if ((tmp = dn_skipname(cp, eom)) == -1) return (NULL); /* compression error */ cp += tmp; if ((cp + RRFIXEDSZ) > eom) @@ -209,7 +210,7 @@ res_skip_rr(cp, eom) cp += INT16SZ; /* type */ cp += INT16SZ; /* class */ cp += INT32SZ; /* ttl */ - dlen = ns_get16((u_char*)cp); + dlen = ns_get16(cp); cp += INT16SZ; /* dlen */ cp += dlen; if (cp > eom) diff --git a/contrib/bind/bin/nslookup/subr.c b/contrib/bind/bin/nslookup/subr.c index 44708b3b29bc..854e09013c57 100644 --- a/contrib/bind/bin/nslookup/subr.c +++ b/contrib/bind/bin/nslookup/subr.c @@ -53,7 +53,7 @@ #ifndef lint static const char sccsid[] = "@(#)subr.c 5.24 (Berkeley) 3/2/91"; -static const char rcsid[] = "$Id: subr.c,v 8.14 2000/12/23 08:14:48 vixie Exp $"; +static const char rcsid[] = "$Id: subr.c,v 8.15 2001/06/18 14:43:45 marka Exp $"; #endif /* not lint */ /* @@ -120,7 +120,7 @@ static const char rcsid[] = "$Id: subr.c,v 8.14 2000/12/23 08:14:48 vixie Exp $" */ SIG_FN -IntrHandler() +IntrHandler(int sig) { extern jmp_buf env; #if defined(BSD) && BSD >= 199006 && !defined(RISCOS_BSD) && !defined(__osf__) @@ -129,6 +129,8 @@ IntrHandler() #endif extern void ListHost_close(void); + UNUSED(sig); + SendRequest_close(); ListHost_close(); if (filePtr != NULL && filePtr != stdout) { @@ -233,7 +235,7 @@ Calloc(num, size) void PrintHostInfo(file, title, hp) FILE *file; - char *title; + const char *title; register HostInfo *hp; { register char **cp; @@ -387,21 +389,21 @@ OpenFile(string, file, size) */ const struct res_sym error_syms[] = { - { NOERROR, "Success" }, - { FORMERR, "Format error" }, - { SERVFAIL, "Server failed" }, - { NXDOMAIN, "Non-existent host/domain" }, - { NOTIMP, "Not implemented" }, - { REFUSED, "Query refused" }, + { NOERROR, "Success", NULL }, + { FORMERR, "Format error", NULL }, + { SERVFAIL, "Server failed", NULL }, + { NXDOMAIN, "Non-existent host/domain", NULL }, + { NOTIMP, "Not implemented", NULL }, + { REFUSED, "Query refused", NULL }, #ifdef NOCHANGE - { NOCHANGE, "No change" }, + { NOCHANGE, "No change", NULL }, #endif - { TIME_OUT, "Timed out" }, - { NO_INFO, "No information" }, - { ERROR, "Unspecified error" }, - { NONAUTH, "Non-authoritative answer" }, - { NO_RESPONSE, "No response from server" }, - { 0, NULL } + { TIME_OUT, "Timed out", NULL }, + { NO_INFO, "No information", NULL }, + { ERROR, "Unspecified error", NULL }, + { NONAUTH, "Non-authoritative answer", NULL }, + { NO_RESPONSE, "No response from server", NULL }, + { 0, NULL, NULL } }; const char * diff --git a/contrib/bind/bin/nsupdate/nsupdate.c b/contrib/bind/bin/nsupdate/nsupdate.c index 3363654c472f..c8e8ce8df12d 100644 --- a/contrib/bind/bin/nsupdate/nsupdate.c +++ b/contrib/bind/bin/nsupdate/nsupdate.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: nsupdate.c,v 8.26 2000/12/23 08:14:48 vixie Exp $"; +static const char rcsid[] = "$Id: nsupdate.c,v 8.27 2001/06/18 14:43:46 marka Exp $"; #endif /* not lint */ /* @@ -390,7 +390,7 @@ main(int argc, char **argv) { exit (1); } r_dname = dnbuf; - r_ttl = (r_opcode == ADD) ? -1 : 0; + r_ttl = (r_opcode == ADD) ? (~0U) : 0; r_type = -1; r_class = C_IN; /* default to IN */ r_size = 0; @@ -493,7 +493,7 @@ main(int argc, char **argv) { r_size = endp - cp + 1; break; case ADD: - if (r_ttl == -1) { + if (r_ttl == ~0U) { fprintf (stderr, "ttl must be specified for record to be added: %s\n", buf); exit (1); diff --git a/contrib/bind/conf/recursive/keep-running b/contrib/bind/conf/recursive/keep-running new file mode 100755 index 000000000000..3261c5ced166 --- /dev/null +++ b/contrib/bind/conf/recursive/keep-running @@ -0,0 +1,11 @@ +#!/bin/sh + +trap "" 1 +sleep 60 +while :; do + /usr/sbin/named -f >> /var/log/named 2>&1 < /dev/null + /usr/ucb/logger -p emerg "named restart" + sleep 32 +done + +exit diff --git a/contrib/bind/conf/recursive/named-res1.conf b/contrib/bind/conf/recursive/named-res1.conf new file mode 100644 index 000000000000..40bce4dff943 --- /dev/null +++ b/contrib/bind/conf/recursive/named-res1.conf @@ -0,0 +1,57 @@ +options { + directory "/var/named"; + listen-on { 204.152.184.67; 127.0.0.1; }; + query-source address 204.152.184.67 port 53; + pid-file "/var/run/named-res1.pid"; +}; + +controls { + unix "/var/run/ndc-res1" perm 0600 owner 0 group 0; +}; + +zone "." { + type hint; + file "root.cache"; +}; + +zone "localhost" { + type master; + file "pri/localhost"; +}; + +zone "0.0.127.in-addr.arpa" { + type master; + file "pri/127.0.0"; +}; + +zone "pa.vix.com" { + type stub; + file "stub/pa.vix.com"; + masters { 204.152.184.64; }; +}; + +zone "184.152.204.in-addr.arpa" { + type stub; + file "stub/204.152.184"; + masters { 204.152.184.64; }; +}; + +zone "rc.vix.com" { + type stub; + file "stub/rc.vix.com"; + masters { 204.152.187.21; }; +}; + +zone "186.152.204.in-addr.arpa" { + type stub; + file "stub/204.152.186"; + masters { 204.152.187.21; }; +}; + +zone "187.152.204.in-addr.arpa" { + type stub; + file "stub/204.152.187"; + masters { 204.152.187.21; }; +}; + +include "named.conf.rfc1918-stubs"; diff --git a/contrib/bind/conf/recursive/named.conf.rfc1918-stubs b/contrib/bind/conf/recursive/named.conf.rfc1918-stubs new file mode 100644 index 000000000000..28b3a703f4be --- /dev/null +++ b/contrib/bind/conf/recursive/named.conf.rfc1918-stubs @@ -0,0 +1,174 @@ +acl rfc1918_query { + 10.0.0.0/8 ; + 127.0.0.1 ; + 172.16.0.0/12 ; + 192.168.0.0/16 ; + 204.152.184.0/21 ; +} ; + +acl rfc1918_transfer { + rfc1918_query ; +} ; + +// RFC 1918 zones +// +zone "10.in-addr.arpa" { + type stub ; + file "stub/10" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "16.172.in-addr.arpa" { + type stub ; + file "stub/172.16" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "17.172.in-addr.arpa" { + type stub ; + file "stub/172.17" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "18.172.in-addr.arpa" { + type stub ; + file "stub/172.18" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "19.172.in-addr.arpa" { + type stub ; + file "stub/172.19" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "20.172.in-addr.arpa" { + type stub ; + file "stub/172.20" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "21.172.in-addr.arpa" { + type stub ; + file "stub/172.21" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "22.172.in-addr.arpa" { + type stub ; + file "stub/172.22" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "23.172.in-addr.arpa" { + type stub ; + file "stub/172.23" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "24.172.in-addr.arpa" { + type stub ; + file "stub/172.24" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "25.172.in-addr.arpa" { + type stub ; + file "stub/172.25" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "26.172.in-addr.arpa" { + type stub ; + file "stub/172.26" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "27.172.in-addr.arpa" { + type stub ; + file "stub/172.27" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "28.172.in-addr.arpa" { + type stub ; + file "stub/172.28" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "29.172.in-addr.arpa" { + type stub ; + file "stub/172.29" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "30.172.in-addr.arpa" { + type stub ; + file "stub/172.30" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "31.172.in-addr.arpa" { + type stub ; + file "stub/172.31" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "168.192.in-addr.arpa" { + type stub ; + file "stub/192.168" ; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +} ; + +zone "local.isc.org" { + type stub; + file "stub/local.isc.org"; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +}; + +zone "local.mibh.net" { + type stub; + file "stub/local.mibh.net"; + masters {204.152.184.64; }; + allow-query { rfc1918_query ; } ; + allow-transfer { rfc1918_transfer ; } ; +}; + diff --git a/contrib/bind/conf/recursive/pri/127.0.0 b/contrib/bind/conf/recursive/pri/127.0.0 new file mode 100644 index 000000000000..3525050064ef --- /dev/null +++ b/contrib/bind/conf/recursive/pri/127.0.0 @@ -0,0 +1,12 @@ +; 0.0.127.in-addr.arpa +$TTL 3600 +@ in soa localhost. postmaster.localhost. ( + 1993050801 ;serial + 3600 ;refresh + 1800 ;retry + 604800 ;expiration + 3600 ) ;minimum + + ns localhost. + +1 ptr localhost. diff --git a/contrib/bind/conf/recursive/pri/localhost b/contrib/bind/conf/recursive/pri/localhost new file mode 100644 index 000000000000..b104be869413 --- /dev/null +++ b/contrib/bind/conf/recursive/pri/localhost @@ -0,0 +1,12 @@ +; localhost. +$TTL 3600 +@ in soa localhost. postmaster.localhost. ( + 1993050801 ;serial + 3600 ;refresh + 1800 ;retry + 604800 ;expiration + 3600 ) ;minimum + + ns localhost. + + a 127.0.0.1 diff --git a/contrib/bind/conf/recursive/root.cache b/contrib/bind/conf/recursive/root.cache new file mode 100644 index 000000000000..a8cbfe9e1f96 --- /dev/null +++ b/contrib/bind/conf/recursive/root.cache @@ -0,0 +1,45 @@ + +; <<>> DiG 8.2 <<>> @f.root-servers.net . ns +; (1 server found) +;; res options: init recurs defnam dnsrch +;; got answer: +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10 +;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13 +;; QUERY SECTION: +;; ., type = NS, class = IN + +;; ANSWER SECTION: +. 6D IN NS G.ROOT-SERVERS.NET. +. 6D IN NS J.ROOT-SERVERS.NET. +. 6D IN NS K.ROOT-SERVERS.NET. +. 6D IN NS L.ROOT-SERVERS.NET. +. 6D IN NS M.ROOT-SERVERS.NET. +. 6D IN NS A.ROOT-SERVERS.NET. +. 6D IN NS H.ROOT-SERVERS.NET. +. 6D IN NS B.ROOT-SERVERS.NET. +. 6D IN NS C.ROOT-SERVERS.NET. +. 6D IN NS D.ROOT-SERVERS.NET. +. 6D IN NS E.ROOT-SERVERS.NET. +. 6D IN NS I.ROOT-SERVERS.NET. +. 6D IN NS F.ROOT-SERVERS.NET. + +;; ADDITIONAL SECTION: +G.ROOT-SERVERS.NET. 5w6d16h IN A 192.112.36.4 +J.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.10 +K.ROOT-SERVERS.NET. 5w6d16h IN A 193.0.14.129 +L.ROOT-SERVERS.NET. 5w6d16h IN A 198.32.64.12 +M.ROOT-SERVERS.NET. 5w6d16h IN A 202.12.27.33 +A.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.4 +H.ROOT-SERVERS.NET. 5w6d16h IN A 128.63.2.53 +B.ROOT-SERVERS.NET. 5w6d16h IN A 128.9.0.107 +C.ROOT-SERVERS.NET. 5w6d16h IN A 192.33.4.12 +D.ROOT-SERVERS.NET. 5w6d16h IN A 128.8.10.90 +E.ROOT-SERVERS.NET. 5w6d16h IN A 192.203.230.10 +I.ROOT-SERVERS.NET. 5w6d16h IN A 192.36.148.17 +F.ROOT-SERVERS.NET. 5w6d16h IN A 192.5.5.241 + +;; Total query time: 10 msec +;; FROM: power.rc.vix.com to SERVER: f.root-servers.net 192.5.5.241 +;; WHEN: Thu Jun 3 14:55:57 1999 +;; MSG SIZE sent: 17 rcvd: 436 + diff --git a/contrib/bind/conf/workstation/named.conf b/contrib/bind/conf/workstation/named.conf new file mode 100644 index 000000000000..24c0c51ca95f --- /dev/null +++ b/contrib/bind/conf/workstation/named.conf @@ -0,0 +1,36 @@ +options { + directory "/var/named"; +}; + +zone "." { + type hint; + file "root.cache"; +}; + +zone "localhost" { + type master; + file "pri/localhost"; +}; + +zone "0.0.127.in-addr.arpa" { + type master; + file "pri/127.0.0"; +}; + +zone "rc.vix.com" { + type stub; + file "stub/rc.vix.com"; + masters { 204.152.187.21; }; +}; + +zone "186.152.204.in-addr.arpa" { + type stub; + file "stub/204.152.186"; + masters { 204.152.187.21; }; +}; + +zone "187.152.204.in-addr.arpa" { + type stub; + file "stub/204.152.187"; + masters { 204.152.187.21; }; +}; diff --git a/contrib/bind/conf/workstation/pri/127.0.0 b/contrib/bind/conf/workstation/pri/127.0.0 new file mode 100644 index 000000000000..3525050064ef --- /dev/null +++ b/contrib/bind/conf/workstation/pri/127.0.0 @@ -0,0 +1,12 @@ +; 0.0.127.in-addr.arpa +$TTL 3600 +@ in soa localhost. postmaster.localhost. ( + 1993050801 ;serial + 3600 ;refresh + 1800 ;retry + 604800 ;expiration + 3600 ) ;minimum + + ns localhost. + +1 ptr localhost. diff --git a/contrib/bind/conf/workstation/pri/localhost b/contrib/bind/conf/workstation/pri/localhost new file mode 100644 index 000000000000..b104be869413 --- /dev/null +++ b/contrib/bind/conf/workstation/pri/localhost @@ -0,0 +1,12 @@ +; localhost. +$TTL 3600 +@ in soa localhost. postmaster.localhost. ( + 1993050801 ;serial + 3600 ;refresh + 1800 ;retry + 604800 ;expiration + 3600 ) ;minimum + + ns localhost. + + a 127.0.0.1 diff --git a/contrib/bind/conf/workstation/root.cache b/contrib/bind/conf/workstation/root.cache new file mode 100644 index 000000000000..a8cbfe9e1f96 --- /dev/null +++ b/contrib/bind/conf/workstation/root.cache @@ -0,0 +1,45 @@ + +; <<>> DiG 8.2 <<>> @f.root-servers.net . ns +; (1 server found) +;; res options: init recurs defnam dnsrch +;; got answer: +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10 +;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13 +;; QUERY SECTION: +;; ., type = NS, class = IN + +;; ANSWER SECTION: +. 6D IN NS G.ROOT-SERVERS.NET. +. 6D IN NS J.ROOT-SERVERS.NET. +. 6D IN NS K.ROOT-SERVERS.NET. +. 6D IN NS L.ROOT-SERVERS.NET. +. 6D IN NS M.ROOT-SERVERS.NET. +. 6D IN NS A.ROOT-SERVERS.NET. +. 6D IN NS H.ROOT-SERVERS.NET. +. 6D IN NS B.ROOT-SERVERS.NET. +. 6D IN NS C.ROOT-SERVERS.NET. +. 6D IN NS D.ROOT-SERVERS.NET. +. 6D IN NS E.ROOT-SERVERS.NET. +. 6D IN NS I.ROOT-SERVERS.NET. +. 6D IN NS F.ROOT-SERVERS.NET. + +;; ADDITIONAL SECTION: +G.ROOT-SERVERS.NET. 5w6d16h IN A 192.112.36.4 +J.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.10 +K.ROOT-SERVERS.NET. 5w6d16h IN A 193.0.14.129 +L.ROOT-SERVERS.NET. 5w6d16h IN A 198.32.64.12 +M.ROOT-SERVERS.NET. 5w6d16h IN A 202.12.27.33 +A.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.4 +H.ROOT-SERVERS.NET. 5w6d16h IN A 128.63.2.53 +B.ROOT-SERVERS.NET. 5w6d16h IN A 128.9.0.107 +C.ROOT-SERVERS.NET. 5w6d16h IN A 192.33.4.12 +D.ROOT-SERVERS.NET. 5w6d16h IN A 128.8.10.90 +E.ROOT-SERVERS.NET. 5w6d16h IN A 192.203.230.10 +I.ROOT-SERVERS.NET. 5w6d16h IN A 192.36.148.17 +F.ROOT-SERVERS.NET. 5w6d16h IN A 192.5.5.241 + +;; Total query time: 10 msec +;; FROM: power.rc.vix.com to SERVER: f.root-servers.net 192.5.5.241 +;; WHEN: Thu Jun 3 14:55:57 1999 +;; MSG SIZE sent: 17 rcvd: 436 + diff --git a/contrib/bind/conf/workstation/stub/README b/contrib/bind/conf/workstation/stub/README new file mode 100644 index 000000000000..3e53a2e76212 --- /dev/null +++ b/contrib/bind/conf/workstation/stub/README @@ -0,0 +1 @@ +this file is only here so that cvs will let the directory exist diff --git a/contrib/bind/include/arpa/nameser.h b/contrib/bind/include/arpa/nameser.h index 3129a10faeb8..955719a1cc18 100644 --- a/contrib/bind/include/arpa/nameser.h +++ b/contrib/bind/include/arpa/nameser.h @@ -49,7 +49,7 @@ */ /* - * $Id: nameser.h,v 8.41 2000/12/23 08:14:50 vixie Exp $ + * $Id: nameser.h,v 8.46 2001/11/16 05:37:33 marka Exp $ */ #ifndef _ARPA_NAMESER_H_ @@ -119,7 +119,7 @@ typedef struct __ns_msg { const u_char *_sections[ns_s_max]; ns_sect _sect; int _rrnum; - const u_char *_ptr; + const u_char *_msg_ptr; } ns_msg; /* Private data structure - do not use from outside library. */ @@ -203,7 +203,9 @@ typedef enum __ns_rcode { ns_r_notauth = 9, /* Not authoritative for zone */ ns_r_notzone = 10, /* Zone of record different from zone section */ ns_r_max = 11, - /* The following are TSIG extended errors */ + /* The following are EDNS extended rcodes */ + ns_r_badvers = 16, + /* The following are TSIG errors */ ns_r_badsig = 16, ns_r_badkey = 17, ns_r_badtime = 18 @@ -425,11 +427,16 @@ typedef enum __ns_cert_types { #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) #define NS_NXT_MAX 127 +/* + * EDNS0 extended flags, host order. + */ +#define NS_OPT_DNSSEC_OK 0x8000U + /* * Inline versions of get/put short/long. Pointer is advanced. */ #define NS_GET16(s, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ + register const u_char *t_cp = (const u_char *)(cp); \ (s) = ((u_int16_t)t_cp[0] << 8) \ | ((u_int16_t)t_cp[1]) \ ; \ @@ -437,7 +444,7 @@ typedef enum __ns_cert_types { } while (0) #define NS_GET32(l, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ + register const u_char *t_cp = (const u_char *)(cp); \ (l) = ((u_int32_t)t_cp[0] << 24) \ | ((u_int32_t)t_cp[1] << 16) \ | ((u_int32_t)t_cp[2] << 8) \ diff --git a/contrib/bind/include/arpa/nameser_compat.h b/contrib/bind/include/arpa/nameser_compat.h index 292669d0c3b7..a32485ad96a9 100644 --- a/contrib/bind/include/arpa/nameser_compat.h +++ b/contrib/bind/include/arpa/nameser_compat.h @@ -32,7 +32,7 @@ /* * from nameser.h 8.1 (Berkeley) 6/2/93 - * $Id: nameser_compat.h,v 8.11 1999/01/02 08:00:58 vixie Exp $ + * $Id: nameser_compat.h,v 8.13 2001/09/24 02:20:25 marka Exp $ */ #ifndef _ARPA_NAMESER_COMPAT_ @@ -64,6 +64,7 @@ defined(apollo) || defined(__convex__) || defined(_CRAY) || \ defined(__hppa) || defined(__hp9000) || \ defined(__hp9000s300) || defined(__hp9000s700) || \ + defined(__hp3000s900) || defined(MPE) || \ defined (BIT_ZERO_ON_LEFT) || defined(m68k) || \ (defined(__Lynx__) && \ (defined(__68k__) || defined(__sparc__) || defined(__powerpc__))) @@ -207,6 +208,7 @@ typedef struct { #define T_SRV ns_t_srv #define T_ATMA ns_t_atma #define T_NAPTR ns_t_naptr +#define T_A6 ns_t_a6 #define T_TSIG ns_t_tsig #define T_IXFR ns_t_ixfr #define T_AXFR ns_t_axfr diff --git a/contrib/bind/include/irs.h b/contrib/bind/include/irs.h index 2cb3a1b268ba..8e232adc2f49 100644 --- a/contrib/bind/include/irs.h +++ b/contrib/bind/include/irs.h @@ -16,7 +16,7 @@ */ /* - * $Id: irs.h,v 8.5 2000/12/23 08:14:49 vixie Exp $ + * $Id: irs.h,v 8.6 2001/05/29 05:47:00 marka Exp $ */ #ifndef _IRS_H_INCLUDED @@ -30,6 +30,7 @@ #include #include #include +#include /* * This is the group map class. @@ -114,6 +115,8 @@ struct irs_ho { struct __res_state * (*res_get) __P((struct irs_ho *)); void (*res_set) __P((struct irs_ho *, res_state, void (*)(void *))); + struct addrinfo *(*addrinfo) __P((struct irs_ho *, const char *, + const struct addrinfo *)); }; /* @@ -138,8 +141,8 @@ struct irs_nw { struct irs_ng { void * private; void (*close) __P((struct irs_ng *)); - int (*next) __P((struct irs_ng *, char **, char **, - char **)); + int (*next) __P((struct irs_ng *, const char **, + const char **, const char **)); int (*test) __P((struct irs_ng *, const char *, const char *, const char *, const char *)); @@ -261,6 +264,12 @@ extern struct hostent *gethostent_p __P((struct net_data *net_data)); extern void sethostent_p __P((int stayopen, struct net_data *net_data)); extern void endhostent_p __P((struct net_data *net_data)); +extern struct hostent *getipnodebyname_p __P((const char *name, int af, + int flags, int *errp, + struct net_data *net_data)); +extern struct hostent *getipnodebyaddr_p __P((const void *addr, size_t len, + int af, int *errp, + struct net_data *net_data)); extern struct netent *getnetent_p __P((struct net_data *net_data)); extern struct netent *getnetbyname_p __P((const char *name, @@ -279,8 +288,8 @@ extern int innetgr_p __P((const char *netgroup, const char *user, const char *domain, struct net_data *net_data)); -extern int getnetgrent_p __P((char **host, char **user, - char **domain, +extern int getnetgrent_p __P((const char **host, const char **user, + const char **domain, struct net_data *net_data)); extern struct protoent *getprotoent_p __P((struct net_data *net_data)); diff --git a/contrib/bind/include/isc/assertions.h b/contrib/bind/include/isc/assertions.h index fdce88290256..0964f63c187f 100644 --- a/contrib/bind/include/isc/assertions.h +++ b/contrib/bind/include/isc/assertions.h @@ -16,7 +16,7 @@ */ /* - * $Id: assertions.h,v 8.3 2000/07/17 07:53:59 vixie Exp $ + * $Id: assertions.h,v 8.4 2001/05/29 05:47:07 marka Exp $ */ #ifndef ASSERTIONS_H @@ -26,12 +26,12 @@ typedef enum { assert_require, assert_ensure, assert_insist, assert_invariant } assertion_type; -typedef void (*assertion_failure_callback)(char *, int, assertion_type, char *, - int); +typedef void (*assertion_failure_callback)(const char *, int, assertion_type, + const char *, int); extern assertion_failure_callback __assertion_failed; void set_assertion_failure_callback(assertion_failure_callback f); -char *assertion_type_to_text(assertion_type type); +const char *assertion_type_to_text(assertion_type type); #ifdef CHECK_ALL #define CHECK_REQUIRE 1 diff --git a/contrib/bind/include/isc/ctl.h b/contrib/bind/include/isc/ctl.h index 3c6e565ff9e7..008e7a62e753 100644 --- a/contrib/bind/include/isc/ctl.h +++ b/contrib/bind/include/isc/ctl.h @@ -19,7 +19,7 @@ */ /* - * $Id: ctl.h,v 8.9 1999/08/08 20:16:45 vixie Exp $ + * $Id: ctl.h,v 8.11 2001/08/10 02:40:49 marka Exp $ */ #include @@ -46,7 +46,7 @@ typedef void (*ctl_logfunc)(enum ctl_severity, const char *fmt, ...); typedef void (*ctl_verbfunc)(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, const char *rest, - u_int respflags, void *respctx, void *uctx); + u_int respflags, const void *respctx, void *uctx); typedef void (*ctl_srvrdone)(struct ctl_sctx *, struct ctl_sess *, void *); @@ -62,7 +62,12 @@ struct ctl_verb { #define ctl_logger __ctl_logger +#ifdef __GNUC__ +void ctl_logger(enum ctl_severity, const char *, ...) + __attribute__((__format__(__printf__, 2, 3))); +#else void ctl_logger(enum ctl_severity, const char *, ...); +#endif /* Client symbols. */ @@ -94,7 +99,7 @@ struct ctl_sctx * ctl_server(evContext, const struct sockaddr *, size_t, ctl_logfunc, void *); void ctl_endserver(struct ctl_sctx *); void ctl_response(struct ctl_sess *, u_int, - const char *, u_int, void *, + const char *, u_int, const void *, ctl_srvrdone, void *, const char *, size_t); void ctl_sendhelp(struct ctl_sess *, u_int); diff --git a/contrib/bind/include/isc/eventlib.h b/contrib/bind/include/isc/eventlib.h index 6b9b077f5a93..5b98516f0f7f 100644 --- a/contrib/bind/include/isc/eventlib.h +++ b/contrib/bind/include/isc/eventlib.h @@ -18,7 +18,7 @@ /* eventlib.h - exported interfaces for eventlib * vix 09sep95 [initial] * - * $Id: eventlib.h,v 1.22 1999/08/18 22:09:04 vixie Exp $ + * $Id: eventlib.h,v 1.23 2001/05/29 05:47:09 marka Exp $ */ #ifndef _EVENTLIB_H @@ -106,7 +106,7 @@ int evHighestFD __P((evContext ctx)); int evListen __P((evContext ctx, int fd, int maxconn, evConnFunc func, void *uap, evConnID *id)); -int evConnect __P((evContext ctx, int fd, void *ra, int ralen, +int evConnect __P((evContext ctx, int fd, const void *ra, int ralen, evConnFunc func, void *uap, evConnID *id)); int evCancelConn __P((evContext ctx, evConnID id)); int evHold __P((evContext, evConnID)); diff --git a/contrib/bind/include/isc/irpmarshall.h b/contrib/bind/include/isc/irpmarshall.h index d8afe325b99e..30cef41109bc 100644 --- a/contrib/bind/include/isc/irpmarshall.h +++ b/contrib/bind/include/isc/irpmarshall.h @@ -16,7 +16,7 @@ */ /* - * $Id: irpmarshall.h,v 8.1 1999/01/18 07:46:47 vixie Exp $ + * $Id: irpmarshall.h,v 8.2 2001/05/29 05:47:10 marka Exp $ */ #ifndef _IRPMARSHALL_H_INCLUDED @@ -57,7 +57,8 @@ int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len); int irp_unmarshall_ho(struct hostent *ho, char *buffer); int irp_marshall_ng(const char *host, const char *user, const char *domain, char **buffer, size_t *len); -int irp_unmarshall_ng(char **host, char **user, char **domain, char *buffer); +int irp_unmarshall_ng(const char **host, const char **user, + const char **domain, char *buffer); int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len); int irp_unmarshall_nw(struct nwent *ne, char *buffer); int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len); diff --git a/contrib/bind/include/isc/logging.h b/contrib/bind/include/isc/logging.h index 3d3d3132a09e..6d6976f1a8ee 100644 --- a/contrib/bind/include/isc/logging.h +++ b/contrib/bind/include/isc/logging.h @@ -72,6 +72,7 @@ typedef struct log_channel *log_channel; #define log_dec_references __log_dec_references #define log_get_channel_type __log_get_channel_type #define log_free_channel __log_free_channel +#define log_close_debug_channels __log_close_debug_channels FILE * log_open_stream(log_channel); int log_close_stream(log_channel); @@ -81,7 +82,12 @@ int log_check_channel(log_context, int, log_channel); int log_check(log_context, int, int); void log_vwrite(log_context, int, int, const char *, va_list args); +#ifdef __GNUC__ +void log_write(log_context, int, int, const char *, ...) + __attribute__((__format__(__printf__, 4, 5))); +#else void log_write(log_context, int, int, const char *, ...); +#endif int log_new_context(int, char **, log_context *); void log_free_context(log_context); int log_add_channel(log_context, int, log_channel); @@ -89,7 +95,7 @@ int log_remove_channel(log_context, int, log_channel); int log_option(log_context, int, int); int log_category_is_active(log_context, int); log_channel log_new_syslog_channel(unsigned int, int, int); -log_channel log_new_file_channel(unsigned int, int, char *, +log_channel log_new_file_channel(unsigned int, int, const char *, FILE *, unsigned int, unsigned long); int log_set_file_owner(log_channel, uid_t, gid_t); @@ -98,5 +104,6 @@ int log_inc_references(log_channel); int log_dec_references(log_channel); log_channel_type log_get_channel_type(log_channel); int log_free_channel(log_channel); +void log_close_debug_channels(log_context); #endif /* !LOGGING_H */ diff --git a/contrib/bind/include/isc/memcluster.h b/contrib/bind/include/isc/memcluster.h index b6f4191fd5ca..bcf69b25b667 100644 --- a/contrib/bind/include/isc/memcluster.h +++ b/contrib/bind/include/isc/memcluster.h @@ -34,6 +34,7 @@ #endif /*MEMCLUSTER_RECORD*/ #endif /*MEMCLUSTER_DEBUG*/ #define memstats __memstats +#define memactive __memactive int meminit(size_t, size_t); void * __memget(size_t); @@ -43,5 +44,6 @@ void __memput_debug(void *, size_t, const char *, int); void * __memget_record(size_t, const char *, int); void __memput_record(void *, size_t, const char *, int); void memstats(FILE *); +int memactive(void); #endif /* MEMCLUSTER_H */ diff --git a/contrib/bind/include/isc/misc.h b/contrib/bind/include/isc/misc.h index 3a94d3f54223..4de1ceeb029b 100644 --- a/contrib/bind/include/isc/misc.h +++ b/contrib/bind/include/isc/misc.h @@ -16,16 +16,24 @@ */ /* - * $Id: misc.h,v 8.4 2000/12/23 08:14:52 vixie Exp $ + * $Id: misc.h,v 8.5 2001/06/18 06:40:43 marka Exp $ */ #ifndef _ISC_MISC_H #define _ISC_MISC_H +#include + #define bitncmp __bitncmp /*#define isc_movefile __isc_movefile */ extern int bitncmp(const void *l, const void *r, int n); extern int isc_movefile(const char *, const char *); +extern int isc_gethexstring(unsigned char *, size_t, int, FILE *, + int *); +extern void isc_puthexstring(FILE *, const unsigned char *, size_t, + size_t, size_t, const char *); +extern void isc_tohex(const unsigned char *, size_t, char *); + #endif /*_ISC_MISC_H*/ diff --git a/contrib/bind/include/netdb.h b/contrib/bind/include/netdb.h index 4ffefada1436..ecfb145dc049 100644 --- a/contrib/bind/include/netdb.h +++ b/contrib/bind/include/netdb.h @@ -86,17 +86,19 @@ /* * @(#)netdb.h 8.1 (Berkeley) 6/2/93 - * $Id: netdb.h,v 8.15 1999/09/18 06:23:46 vixie Exp $ + * $Id: netdb.h,v 8.17 2001/06/18 14:43:48 marka Exp $ */ #ifndef _NETDB_H_ #define _NETDB_H_ #include +#include #if (!defined(BSD)) || (BSD < 199306) # include #endif #include +#include #include #include @@ -116,10 +118,10 @@ #define _PATH_SERVICES "/etc/services" #endif -#ifdef _REENTRANT __BEGIN_DECLS extern int * __h_errno __P((void)); __END_DECLS +#ifdef _REENTRANT #define h_errno (*__h_errno()) #else extern int h_errno; @@ -236,10 +238,17 @@ struct addrinfo { #define NI_NAMEREQD 0x00000004 #define NI_NUMERICSERV 0x00000008 #define NI_DGRAM 0x00000010 +#define NI_WITHSCOPEID 0x00000020 +#define NI_NUMERICSCOPE 0x00000040 + +/* + * Scope delimit character + */ +#define SCOPE_DELIMITER '%' #ifdef _REENTRANT -#if defined (__hpux) || defined(__osf__) +#if defined (__hpux) || defined(__osf__) || defined(_AIX) #define _MAXALIASES 35 #define _MAXLINELEN 1024 #define _MAXADDRS 35 @@ -334,10 +343,13 @@ void endhostent __P((void)); void endnetent __P((void)); void endprotoent __P((void)); void endservent __P((void)); +void freehostent __P((struct hostent *)); struct hostent *gethostbyaddr __P((const char *, int, int)); struct hostent *gethostbyname __P((const char *)); struct hostent *gethostbyname2 __P((const char *, int)); struct hostent *gethostent __P((void)); +struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); +struct hostent *getipnodebyname __P((const char *, int, int, int *)); struct netent *getnetbyaddr __P((unsigned long, int)); struct netent *getnetbyname __P((const char *)); struct netent *getnetent __P((void)); @@ -359,20 +371,24 @@ int getaddrinfo __P((const char *, const char *, int getnameinfo __P((const struct sockaddr *, size_t, char *, size_t, char *, size_t, int)); void freeaddrinfo __P((struct addrinfo *)); -char *gai_strerror __P((int)); +const char *gai_strerror __P((int)); struct hostent *getipnodebyname __P((const char *, int, int, int *)); struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); void freehostent __P((struct hostent *)); #ifdef _REENTRANT -#if defined(__hpux) || defined(__osf__) +#if defined(__hpux) || defined(__osf__) || defined(_AIX) int gethostbyaddr_r __P((const char *, int, int, struct hostent *, struct hostent_data *)); int gethostbyname_r __P((const char *, struct hostent *, struct hostent_data *)); int gethostent_r __P((struct hostent *, struct hostent_data *)); +#if defined(_AIX) +void sethostent_r __P((int, struct hostent_data *)); +#else int sethostent_r __P((int, struct hostent_data *)); +#endif #if defined(__hpux) int endhostent_r __P((struct hostent_data *)); #else @@ -419,8 +435,8 @@ int endservent_r __P((struct servent_data *)); #else void endservent_r __P((struct servent_data *)); #endif -#endif -#if defined(sun) || defined(bsdi) +#else + /* defined(sun) || defined(bsdi) */ struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *, char *, int, int *)); struct hostent *gethostbyname_r __P((const char *, struct hostent *, diff --git a/contrib/bind/include/netgroup.h b/contrib/bind/include/netgroup.h new file mode 100644 index 000000000000..30efb9414413 --- /dev/null +++ b/contrib/bind/include/netgroup.h @@ -0,0 +1,17 @@ +#ifndef netgroup_h +#define netgroup_h + +int getnetgrent(const char **machinep, const char **userp, + const char **domainp); + +int getnetgrent_r(char **machinep, char **userp, char **domainp, + char *buffer, int buflen); + +void setnetgrent(const char *netgroup); + +void endnetgrent(void); + +int innetgr(const char *netgroup, const char *machine, + const char *user, const char *domain); + +#endif diff --git a/contrib/bind/include/resolv.h b/contrib/bind/include/resolv.h index 75578ff57b62..fb5185e9e158 100644 --- a/contrib/bind/include/resolv.h +++ b/contrib/bind/include/resolv.h @@ -50,7 +50,7 @@ /* * @(#)resolv.h 8.1 (Berkeley) 6/2/93 - * $Id: resolv.h,v 8.32.2.1 2001/05/17 03:01:30 marka Exp $ + * $Id: resolv.h,v 8.44 2001/12/19 01:44:19 marka Exp $ */ #ifndef _RESOLV_H_ @@ -63,7 +63,9 @@ # include #endif #include +#include #include +#include /* * Revision information. This is the release date in YYYYMMDD format. @@ -113,14 +115,14 @@ __END_DECLS typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } res_sendhookact; -typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr_in * const *ns, +typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr * const *ns, const u_char **query, int *querylen, u_char *ans, int anssiz, int *resplen)); -typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr_in *ns, +typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr *ns, const u_char *query, int querylen, u_char *ans, @@ -128,9 +130,9 @@ typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr_in *ns, int *resplen)); struct res_sym { - int number; /* Identifying number, like T_MX */ - char * name; /* Its symbolic name, like "MX" */ - char * humanname; /* Its fun name, like "mail exchanger" */ + int number; /* Identifying number, like T_MX */ + const char * name; /* Its symbolic name, like "MX" */ + const char * humanname; /* Its fun name, like "mail exchanger" */ }; /* @@ -149,6 +151,8 @@ struct res_sym { #define RES_DFLRETRY 2 /* Default #/tries. */ #define RES_MAXTIME 65535 /* Infinity, in milliseconds. */ +struct __res_state_ext; + struct __res_state { int retrans; /* retransmition time interval */ int retry; /* number of times to retransmit */ @@ -174,23 +178,38 @@ struct __res_state { int _vcsock; /* PRIVATE: for res_send VC i/o */ u_int _flags; /* PRIVATE: see below */ union { - char pad[52]; /* On an i386 this means 512b total. */ + /* On an 32-bit arch this means 512b total. */ + char pad[72 - 3*sizeof (int) - 2*sizeof (void *)]; struct { u_int16_t nscount; u_int16_t nstimes[MAXNS]; /* ms. */ int nssocks[MAXNS]; - struct sockaddr_in nsaddrs[MAXNS]; + struct __res_state_ext *ext; /* extention for IPv6 */ } _ext; } _u; }; typedef struct __res_state *res_state; +union res_sockaddr_union { + struct sockaddr_in sin; +#ifdef IN6ADDR_ANY_INIT + struct sockaddr_in6 sin6; +#endif +#ifdef ISC_ALIGN64 + int64_t __align64; /* 64bit alignment */ +#else + int32_t __align32; /* 32bit alignment */ +#endif + char __space[128]; /* max size */ +}; + /* * Resolver flags (used to be discrete per-module statics ints). */ #define RES_F_VC 0x00000001 /* socket is TCP */ #define RES_F_CONN 0x00000002 /* socket is connected */ +#define RES_F_EDNS0ERR 0x00000004 /* EDNS0 caused errors */ /* res_findzonecut() options */ #define RES_EXHAUSTIVE 0x00000001 /* always do all queries */ @@ -216,6 +235,14 @@ typedef struct __res_state *res_state; #define RES_NOCHECKNAME 0x00008000 /* do not check names for sanity. */ #define RES_KEEPTSIG 0x00010000 /* do not strip TSIG records */ #define RES_BLAST 0x00020000 /* blast all recursive servers */ +#define RES_NO_NIBBLE 0x00040000 /* disable IPv6 nibble mode reverse */ +#define RES_NO_BITSTRING 0x00080000 /* disable IPv6 bitstring mode reverse */ +#define RES_NOTLDQUERY 0x00100000 /* don't unqualified name as a tld */ +#define RES_USE_DNSSEC 0x00200000 /* use DNSSEC using OK bit in OPT */ +/* KAME extensions: use higher bit to avoid conflict with ISC use */ +#define RES_USE_DNAME 0x10000000 /* use DNAME */ +#define RES_USE_A6 0x20000000 /* use A6 */ +#define RES_USE_EDNS0 0x40000000 /* use EDNS0 if configured */ #define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) @@ -237,7 +264,8 @@ typedef struct __res_state *res_state; #define RES_PRF_QUERY 0x00001000 #define RES_PRF_REPLY 0x00002000 #define RES_PRF_INIT 0x00004000 -/* 0x00008000 */ +#define RES_PRF_TRUNC 0x00008000 +/* 0x00010000 */ /* Things involving an internal (static) resolver context. */ #ifdef _REENTRANT @@ -345,6 +373,12 @@ extern const struct res_sym __p_rcode_syms[]; #define sym_ntop __sym_ntop #define sym_ntos __sym_ntos #define sym_ston __sym_ston +#define res_nopt __res_nopt +#define res_ndestroy __res_ndestroy +#define res_nametoclass __res_nametoclass +#define res_nametotype __res_nametotype +#define res_setservers __res_setservers +#define res_getservers __res_getservers __BEGIN_DECLS int res_hnok __P((const char *)); int res_ownok __P((const char *)); @@ -360,6 +394,10 @@ const char * loc_ntoa __P((const u_char *binary, char *ascii)); int dn_skipname __P((const u_char *, const u_char *)); void putlong __P((u_int32_t, u_char *)); void putshort __P((u_int16_t, u_char *)); +#ifndef __ultrix__ +u_int16_t _getshort __P((const u_char *src)); +u_int32_t _getlong __P((const u_char *src)); +#endif const char * p_class __P((int)); const char * p_time __P((u_int32_t)); const char * p_type __P((int)); @@ -406,6 +444,24 @@ int res_nsendsigned __P((res_state, const u_char *, int, int res_findzonecut __P((res_state, const char *, ns_class, int, char *, size_t, struct in_addr *, int)); void res_nclose __P((res_state)); +int res_nopt __P((res_state, int, u_char *, int, int)); +void res_send_setqhook __P((res_send_qhook hook)); +void res_send_setrhook __P((res_send_rhook hook)); +int __res_vinit __P((res_state, int)); +void res_destroyservicelist __P((void)); +const char * res_servicename __P((u_int16_t port, const char *proto)); +const char * res_protocolname __P((int num)); +void res_destroyprotolist __P((void)); +void res_buildprotolist __P((void)); +const char * res_get_nibblesuffix __P((res_state)); +const char * res_get_bitstringsuffix __P((res_state)); +void res_ndestroy __P((res_state)); +u_int16_t res_nametoclass __P((const char *buf, int *success)); +u_int16_t res_nametotype __P((const char *buf, int *success)); +void res_setservers __P((res_state, + const union res_sockaddr_union *, int)); +int res_getservers __P((res_state, + union res_sockaddr_union *, int)); __END_DECLS #endif /* !_RESOLV_H_ */ diff --git a/contrib/bind/lib/Makefile b/contrib/bind/lib/Makefile index 1de1d01169c8..489169ff6544 100644 --- a/contrib/bind/lib/Makefile +++ b/contrib/bind/lib/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 8.25 2000/12/23 08:02:56 vixie Exp $ +# $Id: Makefile,v 8.26 2001/08/14 05:57:58 marka Exp $ SUBDIRS = resolv irs isc bsd inet nameser dst cylink dnssafe @@ -60,6 +60,9 @@ LIBTS = ${TOP}/lib/libbind.ts LIBR = libbind_r.${A} LIBRTS = ${TOP}/lib/libbindr.ts +.NOTPARALLEL: +.NO_PARALLEL: + all depend clean install distclean:: @for x in ${SUBDIRS}; do \ (cd $$x; pwd; ${MAKE} ${MARGS} $@) || exit 1; \ diff --git a/contrib/bind/lib/dst/Makefile b/contrib/bind/lib/dst/Makefile index a5518bd757ab..5503afa9f23f 100644 --- a/contrib/bind/lib/dst/Makefile +++ b/contrib/bind/lib/dst/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 1.18 2000/12/23 08:02:58 vixie Exp $ +# $Id: Makefile,v 1.19 2001/08/14 05:58:03 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -64,7 +64,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} ${CRYPTINCL} ${CRYPTFLAGS} -c $*.c -o ${THREADED}/$*.${O} -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ -o ${THREADED}/$*.out && \ diff --git a/contrib/bind/lib/dst/bsafe_link.c b/contrib/bind/lib/dst/bsafe_link.c index ec072b3774d1..7c9e481e5df9 100644 --- a/contrib/bind/lib/dst/bsafe_link.c +++ b/contrib/bind/lib/dst/bsafe_link.c @@ -1,5 +1,5 @@ #if defined(BSAFE) || defined(DNSSAFE) -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/bsafe_link.c,v 1.12 2001/04/05 21:59:59 bwelling Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/bsafe_link.c,v 1.15 2001/09/25 04:50:28 marka Exp $"; /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -118,7 +118,7 @@ static void *dst_bsafe_free_key_structure(void *key); * BSAFE/DNSSAFE related functions */ int -dst_bsafe_init() +dst_bsafe_init(void) { if (dst_t_func[KEY_RSA] != NULL) return (1); @@ -327,7 +327,8 @@ dst_bsafe_verify(const int mode, DST_KEY *dkey, void **context, if (ret == 0 && (status = B_DecryptUpdate(rsaEncryptor, work_area, &u_bytes, 0, - (u_char *) signature, sig_len, + (const u_char *) signature, + sig_len, NULL_PTR, NULL_SURRENDER))) ret = VERIFY_FINAL_FAILURE; @@ -385,24 +386,28 @@ dst_bsafe_to_dns_key(const DST_KEY *in_key, u_char *out_str, public = (B_KEY_OBJ)((RSA_Key *) in_key->dk_KEY_struct)->rk_Public_Key; n = B_GetKeyInfo((POINTER *) &pub, public, KI_RSAPublic); - - if (out_len < pub->exponent.len) /* not enough space */ + if (n != 0) return (-1); - if (pub->exponent.len < 256) /* key exponent is <= 2040 bits */ + + if (pub->exponent.len < 256) { /* key exponent is <= 2040 bits */ + if ((unsigned int)out_len < pub->exponent.len + 1) + return (-1); *op++ = (u_int8_t) pub->exponent.len; - else { /* key exponent is > 2040 bits */ + } else { /* key exponent is > 2040 bits */ u_int16_t e = (u_int16_t) pub->exponent.len; - *op++ = 0; /* 3 byte lenght field */ + if ((unsigned int)out_len < pub->exponent.len + 3) + return (-1); + *op++ = 0; /* 3 byte length field */ dst_s_put_int16(op, e); op += sizeof(e); n = 2; } - n += pub->exponent.len; - memcpy(op, pub->exponent.data, n); - op += n; n++; + memcpy(op, pub->exponent.data, pub->exponent.len); + op += pub->exponent.len; + n += pub->exponent.len; - if ((out_len - n) > pub->modulus.len) { + if ((unsigned int)(out_len - n) >= pub->modulus.len) { /*copy exponent */ memcpy(op, pub->modulus.data, pub->modulus.len); n += pub->modulus.len; @@ -612,7 +617,6 @@ dst_bsafe_key_from_file_format(DST_KEY *d_key, const char *buff, int status; char s[RAW_KEY_SIZE]; int len, s_len = sizeof(s); - int tag = -1; const char *p = buff; RSA_Key *b_key; A_RSA_KEY *public; @@ -1041,7 +1045,7 @@ dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj, if (digest_obj == NULL || *digest_obj == NULL) { printf("NO digest obj\n"); - exit(-33); + exit(33); } if ((mode & SIG_MODE_INIT) && @@ -1050,8 +1054,7 @@ dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj, return (SIGN_INIT_FAILURE); if ((mode & SIG_MODE_UPDATE) && data && (len > 0) && - (status = B_DigestUpdate(*digest_obj, (u_char *) data, len, - NULL_SURRENDER))) + (status = B_DigestUpdate(*digest_obj, data, len, NULL_SURRENDER))) return (SIGN_UPDATE_FAILURE); if (mode & SIG_MODE_FINAL) { @@ -1080,13 +1083,13 @@ T_malloc(unsigned int len) } int -T_memcmp(POINTER firstBlock, POINTER secondBlock, unsigned int len) +T_memcmp(CPOINTER firstBlock, CPOINTER secondBlock, unsigned int len) { return (memcmp(firstBlock, secondBlock, len)); } void -T_memcpy(POINTER output, POINTER input, unsigned int len) +T_memcpy(POINTER output, CPOINTER input, unsigned int len) { memcpy(output, input, len); } diff --git a/contrib/bind/lib/dst/cylink_link.c b/contrib/bind/lib/dst/cylink_link.c index 60097f51e653..6c2bdaede0b5 100644 --- a/contrib/bind/lib/dst/cylink_link.c +++ b/contrib/bind/lib/dst/cylink_link.c @@ -1,5 +1,5 @@ #ifdef CYLINK_DSS -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/cylink_link.c,v 1.8 2001/04/05 22:00:00 bwelling Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/cylink_link.c,v 1.9 2001/05/29 05:48:05 marka Exp $"; /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -147,7 +147,7 @@ dst_cylink_sign(const int mode, DST_KEY *dkey, void **context, SHAInit(ctx); if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - status = SHAUpdate(ctx, (u_char *) data, len); + status = SHAUpdate(ctx, data, len); if (status != SUCCESS) return (SIGN_UPDATE_FAILURE); } @@ -228,7 +228,7 @@ dst_cylink_verify(const int mode, DST_KEY *dkey, void **context, SHAInit(ctx); if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - status = SHAUpdate(ctx, (u_char *) data, len); + status = SHAUpdate(ctx, data, len); if (status != SUCCESS) return (VERIFY_UPDATE_FAILURE); } @@ -576,6 +576,8 @@ dst_cylink_generate_keypair(DST_KEY *key, int nothing) DSA_Key *dsa; u_char rand[SHA_LENGTH]; + UNUSED(nothing); + if (key == NULL || key->dk_alg != KEY_DSA) return (0); diff --git a/contrib/bind/lib/dst/dst_api.c b/contrib/bind/lib/dst/dst_api.c index a79dcf1ee730..cc2a7e4814cc 100644 --- a/contrib/bind/lib/dst/dst_api.c +++ b/contrib/bind/lib/dst/dst_api.c @@ -1,5 +1,5 @@ #ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/dst_api.c,v 1.17.2.2 2001/07/26 01:58:06 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/dst_api.c,v 1.20 2001/07/26 01:20:08 marka Exp $"; #endif /* @@ -62,8 +62,8 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/dst_api.c, /* static variables */ static int done_init = 0; dst_func *dst_t_func[DST_MAX_ALGS]; -char *key_file_fmt_str = "Private-key-format: v%s\nAlgorithm: %d (%s)\n"; -char *dst_path = ""; +const char *key_file_fmt_str = "Private-key-format: v%s\nAlgorithm: %d (%s)\n"; +const char *dst_path = ""; /* internal I/O functions */ static DST_KEY *dst_s_read_public_key(const char *in_name, @@ -109,12 +109,14 @@ dst_init() } else if (stat(s, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) { EREPORT(("%s is not a valid directory\n", s)); } else { - dst_path = (char *) malloc(len + 2); - memcpy(dst_path, s, len + 1); - if (dst_path[strlen(dst_path) - 1] != '/') { - dst_path[strlen(dst_path) + 1] = 0; - dst_path[strlen(dst_path)] = '/'; + char *tmp; + tmp = (char *) malloc(len + 2); + memcpy(tmp, s, len + 1); + if (tmp[strlen(tmp) - 1] != '/') { + tmp[strlen(tmp) + 1] = 0; + tmp[strlen(tmp)] = '/'; } + dst_path = tmp; } } memset(dst_t_func, 0, sizeof(dst_t_func)); @@ -555,7 +557,7 @@ dst_s_read_public_key(const char *in_name, const u_int16_t in_id, int in_alg) enckey[--len] = '\0'; /* remove leading spaces */ - for (notspace = (char *) enckey; isspace(*notspace); len--) + for (notspace = (char *) enckey; isspace((*notspace)&0xff); len--) notspace++; dlen = b64_pton(notspace, deckey, sizeof(deckey)); @@ -589,6 +591,7 @@ dst_s_write_public_key(const DST_KEY *key) u_char out_key[RAW_KEY_SIZE]; char enc_key[RAW_KEY_SIZE]; int len = 0; + int mode; memset(out_key, 0, sizeof(out_key)); if (key == NULL) { @@ -604,8 +607,10 @@ dst_s_write_public_key(const DST_KEY *key) key->dk_key_name, key->dk_id, PUBLIC_KEY)); return (0); } + /* XXX in general this should be a check for symmetric keys */ + mode = (key->dk_alg == KEY_HMAC_MD5) ? 0600 : 0644; /* create public key file */ - if ((fp = dst_s_fopen(filename, "w+", 0644)) == NULL) { + if ((fp = dst_s_fopen(filename, "w+", mode)) == NULL) { EREPORT(("DST_write_public_key: open of file:%s failed (errno=%d)\n", filename, errno)); return (0); diff --git a/contrib/bind/lib/dst/dst_internal.h b/contrib/bind/lib/dst/dst_internal.h index 66bfed4066a9..0825109f5e97 100644 --- a/contrib/bind/lib/dst/dst_internal.h +++ b/contrib/bind/lib/dst/dst_internal.h @@ -65,13 +65,14 @@ typedef struct dst_key { #ifdef REPORT_ERRORS #define EREPORT(str) printf str #else -#define EREPORT(str) +#define EREPORT(str) (void)0 #endif /* use our own special macro to FRRE memory */ #ifndef SAFE_FREE -#define SAFE_FREE(a) if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;} +#define SAFE_FREE(a) \ +do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0) #define SAFE_FREE2(a,s) if (a != NULL && s > 0){memset(a,0, s);free(a); a=NULL;} #endif @@ -98,22 +99,22 @@ typedef struct dst_func { } dst_func; extern dst_func *dst_t_func[DST_MAX_ALGS]; -extern char *key_file_fmt_str; -extern char *dst_path; +extern const char *key_file_fmt_str; +extern const char *dst_path; #ifndef DST_HASH_SIZE #define DST_HASH_SIZE 20 /* RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */ #endif -int dst_bsafe_init(); +int dst_bsafe_init(void); -int dst_rsaref_init(); +int dst_rsaref_init(void); -int dst_hmac_md5_init(); +int dst_hmac_md5_init(void); -int dst_cylink_init(); +int dst_cylink_init(void); -int dst_eay_dss_init(); +int dst_eay_dss_init(void); /* support functions */ /* base64 to bignum conversion routines */ @@ -158,6 +159,10 @@ void dst_s_put_int32( u_int8_t *buf, const u_int32_t val); #else # define DUMP(a,b,c,d) #endif +void +dst_s_dump(const int mode, const u_char *data, const int size, + const char *msg); + #endif /* DST_INTERNAL_H */ diff --git a/contrib/bind/lib/dst/eay_dss_link.c b/contrib/bind/lib/dst/eay_dss_link.c index 0cc01a84f381..b5c7caab830e 100644 --- a/contrib/bind/lib/dst/eay_dss_link.c +++ b/contrib/bind/lib/dst/eay_dss_link.c @@ -1,5 +1,5 @@ #ifdef EAY_DSS -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/eay_dss_link.c,v 1.5 2001/04/05 22:00:03 bwelling Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/eay_dss_link.c,v 1.6 2001/05/29 05:48:09 marka Exp $"; /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -44,6 +44,7 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/eay_dss_li #include "port_after.h" + static int dst_eay_dss_sign(const int mode, DST_KEY *dkey, void **context, const u_char *data, const int len, u_char *signature, const int sig_len); @@ -71,7 +72,7 @@ static int dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2); * EAY DSS related functions */ int -dst_eay_dss_init() +dst_eay_dss_init(void) { if (dst_t_func[KEY_DSA] != NULL) return (1); @@ -608,8 +609,21 @@ dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2) return (0); } #else +#include "port_before.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dst_internal.h" +#include "port_after.h" int -dst_eay_dss_init() +dst_eay_dss_init(void) { return (0); } diff --git a/contrib/bind/lib/dst/hmac_link.c b/contrib/bind/lib/dst/hmac_link.c index 1b930880ef6f..12e22a8b24e4 100644 --- a/contrib/bind/lib/dst/hmac_link.c +++ b/contrib/bind/lib/dst/hmac_link.c @@ -1,6 +1,6 @@ #ifdef HMAC_MD5 #ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link.c,v 1.8 1999/10/15 21:30:07 vixie Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link.c,v 1.9 2001/05/29 05:48:10 marka Exp $"; #endif /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -103,7 +103,7 @@ dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context, } if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) - MD5Update(ctx, (u_char *)data, len); + MD5Update(ctx, data, len); if (mode & SIG_MODE_FINAL) { if (signature == NULL || sig_len < MD5_LEN) @@ -169,7 +169,7 @@ dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context, MD5Update(ctx, key->hk_ipad, HMAC_LEN); } if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) - MD5Update(ctx, (u_char *)data, len); + MD5Update(ctx, data, len); if (mode & SIG_MODE_FINAL) { u_char digest[MD5_LEN]; @@ -229,7 +229,7 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen) if (keylen > HMAC_LEN) { u_char tk[MD5_LEN]; MD5Init(&ctx); - MD5Update(&ctx, (u_char *)key, keylen); + MD5Update(&ctx, key, keylen); MD5Final(tk, &ctx); memset((void *) &ctx, 0, sizeof(ctx)); key = tk; @@ -431,6 +431,8 @@ dst_hmac_md5_generate_key(DST_KEY *key, const int nothing) u_char *buff; int i, n, size; + i = nothing; + if (key == NULL || key->dk_alg != KEY_HMAC_MD5) return (0); size = (key->dk_key_size + 7) / 8; /* convert to bytes */ diff --git a/contrib/bind/lib/dst/md5.h b/contrib/bind/lib/dst/md5.h index c8b1580364b2..c886d17bb009 100644 --- a/contrib/bind/lib/dst/md5.h +++ b/contrib/bind/lib/dst/md5.h @@ -80,7 +80,7 @@ typedef struct MD5state_st #ifndef NOPROTO void MD5_Init(MD5_CTX *c); -void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len); +void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len); void MD5_Final(unsigned char *md, MD5_CTX *c); unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md); #else diff --git a/contrib/bind/lib/dst/md5_dgst.c b/contrib/bind/lib/dst/md5_dgst.c index 82e5a3829a0c..78882d1c9588 100644 --- a/contrib/bind/lib/dst/md5_dgst.c +++ b/contrib/bind/lib/dst/md5_dgst.c @@ -56,11 +56,13 @@ * [including the GNU Public Licence.] */ -#include #ifdef USE_MD5 /* Added by ogud@tis.com 1998/1/26 */ +#include +#include #include "md5_locl.h" +#include -char *MD5_version="MD5 part of SSLeay 0.8.1 19-Jul-1997"; +const char *MD5_version="MD5 part of SSLeay 0.8.1 19-Jul-1997"; /* Implemented from RFC1321 The MD5 Message-Digest Algorithm */ @@ -90,7 +92,7 @@ MD5_CTX *c; void MD5_Update(c, data, len) MD5_CTX *c; -register unsigned char *data; +register const unsigned char *data; unsigned long len; { register ULONG *p; diff --git a/contrib/bind/lib/dst/prandom.c b/contrib/bind/lib/dst/prandom.c index 031da2e8894e..2236fe84014f 100644 --- a/contrib/bind/lib/dst/prandom.c +++ b/contrib/bind/lib/dst/prandom.c @@ -1,5 +1,5 @@ #ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/prandom.c,v 1.10 2001/02/12 23:13:46 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/prandom.c,v 1.12 2001/07/26 01:20:09 marka Exp $"; #endif /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -119,9 +119,9 @@ static int unix_cmd(dst_work *work); static int digest_file(dst_work *work); static void force_hash(dst_work *work, prand_hash *hash); -static int do_hash(dst_work *work, prand_hash *hash, u_char *input, +static int do_hash(dst_work *work, prand_hash *hash, const u_char *input, int size); -static int my_digest(dst_work *tmp, u_char *input, int size); +static int my_digest(dst_work *tmp, const u_char *input, int size); static prand_hash *get_hmac_key(int step, int block); static int own_random(dst_work *work); @@ -257,11 +257,10 @@ do_ls(dst_work *work) else if (i==1) /* if starting a new round cut what we accept */ d_round += (tv.tv_sec - d_round)/2; - if (buf.st_atime < d_round) + if (buf.st_atime < (time_t)d_round) return (0); - EREPORT(("do_ls i %d filled %4d in_temp %4d\n", - i-1, work->filled, work->in_temp)); + EREPORT(("do_ls i %d filled %4d\n", i-1, work->filled)); memcpy(tmp_buff, &buf, sizeof(buf)); tb_i += sizeof(buf); @@ -322,8 +321,7 @@ unix_cmd(dst_work *work) if (cmds[cmd_index] == NULL) cmd_index = 0; - EREPORT(("unix_cmd() i %d filled %4d in_temp %4d\n", - cmd_index, work->filled, work->in_temp)); + EREPORT(("unix_cmd() i %d filled %4d\n", cmd_index, work->filled)); pipe = popen(cmds[cmd_index++], "r"); /* execute the command */ while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0) { @@ -334,7 +332,7 @@ unix_cmd(dst_work *work) cnt += do_time(work); } while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0) - NULL; /* drain the pipe */ + (void)NULL; /* drain the pipe */ pclose(pipe); return (cnt); /* read how many bytes where read in */ } @@ -377,7 +375,7 @@ digest_file(dst_work *work) } if (access(name, R_OK) || stat(name, &st)) return (0); /* no such file or not allowed to read it */ - if (strncmp(name, "/proc/", 6) && st.st_mtime < f_round) + if (strncmp(name, "/proc/", 6) && st.st_mtime < (time_t)f_round) return(0); /* file has not changed recently enough */ if (dst_sign_data(SIG_MODE_INIT, work->file_digest, &ctx, NULL, 0, NULL, 0)) { @@ -401,7 +399,7 @@ digest_file(dst_work *work) } else if (i > 0) my_digest(work, buf, i); - my_digest(work, (u_char *)name, strlen(name)); + my_digest(work, (const u_char *)name, strlen(name)); return (no + strlen(name)); } @@ -439,9 +437,10 @@ force_hash(dst_work *work, prand_hash *hash) * */ static int -do_hash(dst_work *work, prand_hash *hash, u_char *input, int size) +do_hash(dst_work *work, prand_hash *hash, const u_char *input, int size) { - u_char *tmp = input, *tp; + const u_char *tmp = input; + u_char *save = NULL, *tp; int i, cnt = size, n, needed, avail, dig, tmp_size = 0; if (cnt <= 0 || input == NULL) @@ -449,7 +448,7 @@ do_hash(dst_work *work, prand_hash *hash, u_char *input, int size) if (hash->step > 1) { /* if using subset of input data */ tmp_size = size / hash->step + 2; - tp = tmp = malloc(tmp_size); + tmp = tp = save = malloc(tmp_size); for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++) *(tp++) = input[i]; /* calcutate the starting point in the next input set */ @@ -466,13 +465,13 @@ do_hash(dst_work *work, prand_hash *hash, u_char *input, int size) if (hash->digested >= hash->block) force_hash(work, hash); if (work->needed < work->filled) { - if (tmp != input) - SAFE_FREE2(tmp, tmp_size); + if (tmp_size > 0) + SAFE_FREE2(save, tmp_size); return (1); } } if (tmp_size > 0) - SAFE_FREE2(tmp, tmp_size); + SAFE_FREE2(save, tmp_size); return (0); } @@ -482,7 +481,7 @@ do_hash(dst_work *work, prand_hash *hash, u_char *input, int size) * if work-block needs more data, keep filling with the rest of the input. */ static int -my_digest(dst_work *work, u_char *input, int size) +my_digest(dst_work *work, const u_char *input, int size) { int i, full = 0; @@ -603,8 +602,8 @@ own_random(dst_work *work) * proceed while needed */ while (work->filled < work->needed) { - EREPORT(("own_random r %08x b %6d t %6d f %6d\n", - ran_val, bytes, work->in_temp, work->filled)); + EREPORT(("own_random r %08x b %6d f %6d\n", + ran_val, bytes, work->filled)); /* pick a random number in the range of 0..7 based on that random number * perform some operations that yield random data */ @@ -840,8 +839,10 @@ dst_s_semi_random(u_char *output, int size) i = dst_sign_data(SIG_MODE_ALL, my_key, NULL, (u_char *) counter, hb_size, semi_old, sizeof(semi_old)); +#ifdef REPORT_ERRORS if (i != hb_size) EREPORT(("HMAC SIGNATURE FAILURE %d\n", i)); +#endif cnt++; if (size - out < i) /* Not all data is needed */ semi_loc = i = size - out; diff --git a/contrib/bind/lib/dst/rsaref_link.c b/contrib/bind/lib/dst/rsaref_link.c index a45b6f75e633..8e09b862ef87 100644 --- a/contrib/bind/lib/dst/rsaref_link.c +++ b/contrib/bind/lib/dst/rsaref_link.c @@ -1,5 +1,5 @@ #ifdef RSAREF -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/rsaref_link.c,v 1.9 2001/04/05 22:00:04 bwelling Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/rsaref_link.c,v 1.10 2001/05/29 05:48:15 marka Exp $"; /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -740,6 +740,19 @@ dst_rsaref_init_random_struct(R_RANDOM_STRUCT * randomstruct) #else +#include "port_before.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dst_internal.h" +#include "port_after.h" int /* rsaref is not available */ dst_rsaref_init() { diff --git a/contrib/bind/lib/dst/support.c b/contrib/bind/lib/dst/support.c index 2dd2a8c17726..6cc0bd112500 100644 --- a/contrib/bind/lib/dst/support.c +++ b/contrib/bind/lib/dst/support.c @@ -1,4 +1,4 @@ -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,v 1.9.2.1 2001/06/06 21:45:17 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,v 1.11 2001/05/29 05:48:16 marka Exp $"; /* @@ -241,7 +241,7 @@ dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len) /* compute id */ if (dns_key_rdata[3] == KEY_RSA) /* Algorithm RSA */ - return dst_s_get_int16((u_char *) + return dst_s_get_int16((const u_char *) &dns_key_rdata[rdata_len - 3]); else if (dns_key_rdata[3] == KEY_HMAC_MD5) /* compatibility */ @@ -393,7 +393,7 @@ dst_s_build_filename(char *filename, const char *name, u_int16_t id, return (-1); my_id = id; sprintf(filename, "K%s+%03d+%05d.%s", name, alg, my_id, - (char *) suffix); + (const char *) suffix); if (strrchr(filename, '/')) return (-1); if (strrchr(filename, '\\')) @@ -420,7 +420,7 @@ dst_s_fopen(const char *filename, const char *mode, int perm) { FILE *fp; char pathname[PATH_MAX]; - int plen = sizeof(pathname); + size_t plen = sizeof(pathname); if (*dst_path != '\0') { strcpy(pathname, dst_path); @@ -444,6 +444,8 @@ void dst_s_dump(const int mode, const u_char *data, const int size, const char *msg) { + UNUSED(data); + if (size > 0) { #ifdef LONG_TEST static u_char scratch[1000]; diff --git a/contrib/bind/lib/inet/Makefile b/contrib/bind/lib/inet/Makefile index 1876bb693f8e..a448e61f809a 100644 --- a/contrib/bind/lib/inet/Makefile +++ b/contrib/bind/lib/inet/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 8.21 2000/12/23 08:02:59 vixie Exp $ +# $Id: Makefile,v 8.23 2001/08/14 05:58:05 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -45,12 +45,14 @@ THREADED= threaded SRCS= nsap_addr.c inet_addr.c inet_ntop.c inet_pton.c \ inet_ntoa.c inet_neta.c inet_net_ntop.c inet_net_pton.c \ inet_cidr_ntop.c inet_cidr_pton.c \ - inet_lnaof.c inet_makeaddr.c inet_netof.c inet_network.c + inet_lnaof.c inet_makeaddr.c inet_netof.c inet_network.c \ + inet_data.c OBJS= nsap_addr.${O} inet_addr.${O} inet_ntop.${O} inet_pton.${O} \ inet_ntoa.${O} inet_neta.${O} inet_net_ntop.${O} inet_net_pton.${O} \ inet_cidr_ntop.${O} inet_cidr_pton.${O} \ - inet_lnaof.${O} inet_makeaddr.${O} inet_netof.${O} inet_network.${O} + inet_lnaof.${O} inet_makeaddr.${O} inet_netof.${O} inet_network.${O} \ + inet_data.${O} all: ${LIBBIND} @@ -62,7 +64,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \ -o ${THREADED}/$*.${O} -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ diff --git a/contrib/bind/lib/inet/inet_addr.c b/contrib/bind/lib/inet/inet_addr.c index 3b54aa84797e..b68190ccc236 100644 --- a/contrib/bind/lib/inet/inet_addr.c +++ b/contrib/bind/lib/inet/inet_addr.c @@ -70,7 +70,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; -static const char rcsid[] = "$Id: inet_addr.c,v 8.11 1999/10/13 16:39:25 vixie Exp $"; +static const char rcsid[] = "$Id: inet_addr.c,v 8.12 2001/05/29 05:48:18 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -121,7 +121,7 @@ inet_aton(const char *cp, struct in_addr *addr) { * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ - if (!isdigit(c)) + if (!isdigit((unsigned char)c)) return (0); val = 0; base = 10; digit = 0; if (c == '0') { @@ -134,15 +134,16 @@ inet_aton(const char *cp, struct in_addr *addr) { } } for (;;) { - if (isascii(c) && isdigit(c)) { + if (isascii(c) && isdigit((unsigned char)c)) { if (base == 8 && (c == '8' || c == '9')) return (0); val = (val * base) + (c - '0'); c = *++cp; digit = 1; - } else if (base == 16 && isascii(c) && isxdigit(c)) { + } else if (base == 16 && isascii(c) && + isxdigit((unsigned char)c)) { val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); c = *++cp; digit = 1; } else @@ -165,7 +166,7 @@ inet_aton(const char *cp, struct in_addr *addr) { /* * Check for trailing characters. */ - if (c != '\0' && (!isascii(c) || !isspace(c))) + if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c))) return (0); /* * Did we get a valid digit? diff --git a/contrib/bind/lib/inet/inet_cidr_ntop.c b/contrib/bind/lib/inet/inet_cidr_ntop.c index 08352abf2a17..0acff763cdde 100644 --- a/contrib/bind/lib/inet/inet_cidr_ntop.c +++ b/contrib/bind/lib/inet/inet_cidr_ntop.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.4 1999/10/07 20:44:02 vixie Exp $"; +static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.7 2001/09/28 05:19:36 marka Exp $"; #endif #include "port_before.h" @@ -24,6 +24,7 @@ static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.4 1999/10/07 20:44:02 vix #include #include #include +#include #include #include @@ -41,6 +42,8 @@ static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.4 1999/10/07 20:44:02 vix static char * inet_cidr_ntop_ipv4 __P((const u_char *src, int bits, char *dst, size_t size)); +static char * inet_cidr_ntop_ipv6 __P((const u_char *src, int bits, + char *dst, size_t size)); /* * char * @@ -61,12 +64,34 @@ inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { case AF_INET: return (inet_cidr_ntop_ipv4(src, bits, dst, size)); + case AF_INET6: + return (inet_cidr_ntop_ipv6(src, bits, dst, size)); default: errno = EAFNOSUPPORT; return (NULL); } } +static int +decoct(const u_char *src, int bytes, char *dst, size_t size) { + char *odst = dst; + char *t; + int b; + + for (b = 1; b <= bytes; b++) { + if (size < sizeof "255.") + return (0); + t = dst; + dst += SPRINTF((dst, "%u", *src++)); + if (b != bytes) { + *dst++ = '.'; + *dst = '\0'; + } + size -= (size_t)(dst - t); + } + return (dst - odst); +} + /* * static char * * inet_cidr_ntop_ipv4(src, bits, dst, size) @@ -83,9 +108,9 @@ inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) { static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { char *odst = dst; - char *t; size_t len = 4; - int b, tb; + size_t b; + size_t bytes; if ((bits < -1) || (bits > 32)) { errno = EINVAL; @@ -94,25 +119,21 @@ inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { /* Find number of significant bytes in address. */ if (bits == -1) - len = 3; + len = 4; else - for (len = 0,b = 1 ; b < 4; b++) + for (len = 1, b = 1 ; b < 4; b++) if (*(src + b)) - len = b; + len = b + 1; /* Format whole octets plus nonzero trailing octets. */ - tb = (bits <= 0) ? 1 : (bits - 1); - for (b = 0; b <= (tb / 8) || (b <= len); b++) { - if (size < sizeof "255.") - goto emsgsize; - t = dst; - dst += SPRINTF((dst, "%u", *src++)); - if (b + 1 <= (tb / 8) || (b + 1 <= len)) { - *dst++ = '.'; - *dst = '\0'; - } - size -= (size_t)(dst - t); - } + bytes = (((bits <= 0) ? 1 : bits) + 7) / 8; + if (len > bytes) + bytes = len; + b = decoct(src, bytes, dst, size); + if (b == 0) + goto emsgsize; + dst += b; + size -= b; if (bits != -1) { /* Format CIDR /width. */ @@ -127,3 +148,112 @@ inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { errno = EMSGSIZE; return (NULL); } + +static char * +inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255/128"]; + char *tp; + struct { int base, len; } best, cur; + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + if ((bits < -1) || (bits > 128)) { + errno = EINVAL; + return (NULL); + } + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + best.base = -1; + cur.base = -1; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && (best.len == 6 || + (best.len == 7 && words[7] != 0x0001) || + (best.len == 5 && words[5] == 0xffff))) { + int n; + + if (src[15] || bits == -1 || bits > 120) + n = 4; + else if (src[14] || bits > 112) + n = 3; + else + n = 2; + n = decoct(src+12, n, tp, sizeof tmp - (tp - tmp)); + if (n == 0) { + errno = EMSGSIZE; + return (NULL); + } + tp += strlen(tp); + break; + } + tp += SPRINTF((tp, "%x", words[i])); + } + + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp = '\0'; + + if (bits != -1) + tp += SPRINTF((tp, "/%u", bits)); + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) { + errno = EMSGSIZE; + return (NULL); + } + strcpy(dst, tmp); + return (dst); +} diff --git a/contrib/bind/lib/inet/inet_cidr_pton.c b/contrib/bind/lib/inet/inet_cidr_pton.c index 9ead90b242d7..b8a72262c0ca 100644 --- a/contrib/bind/lib/inet/inet_cidr_pton.c +++ b/contrib/bind/lib/inet/inet_cidr_pton.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.4 2000/12/23 08:14:53 vixie Exp $"; +static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.7 2001/09/28 04:21:28 marka Exp $"; #endif #include "port_before.h" @@ -24,6 +24,7 @@ static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.4 2000/12/23 08:14:53 vix #include #include #include +#include #include #include @@ -42,8 +43,12 @@ static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.4 2000/12/23 08:14:53 vix #endif static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst, + int *bits, int ipv6)); +static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, int *bits)); +static int getbits(const char *, int ipv6); + /* * int * inet_cidr_pton(af, src, dst, *bits) @@ -65,16 +70,19 @@ int inet_cidr_pton(int af, const char *src, void *dst, int *bits) { switch (af) { case AF_INET: - return (inet_cidr_pton_ipv4(src, dst, bits)); + return (inet_cidr_pton_ipv4(src, dst, bits, 0)); + case AF_INET6: + return (inet_cidr_pton_ipv6(src, dst, bits)); default: errno = EAFNOSUPPORT; return (-1); } } +static const char digits[] = "0123456789"; + static int -inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits) { - static const char digits[] = "0123456789"; +inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { const u_char *odst = dst; int n, ch, tmp, bits; size_t size = 4; @@ -101,30 +109,17 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits) { /* Get the prefix length if any. */ bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - INSIST(n >= 0 && n <= 9); - bits *= 10; - bits += n; - } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); - if (ch != '\0') + if (ch == '/' && dst > odst) { + bits = getbits(src, ipv6); + if (bits == -2) goto enoent; - if (bits > 32) - goto emsgsize; - } - - /* Firey death and destruction unless we prefetched EOS. */ - if (ch != '\0') + } else if (ch != '\0') goto enoent; /* Prefix length can default to /32 only if all four octets spec'd. */ if (bits == -1) { if (dst - odst == 4) - bits = 32; + bits = ipv6 ? 128 : 32; else goto enoent; } @@ -134,7 +129,7 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits) { goto enoent; /* If prefix length overspecifies mantissa, life is bad. */ - if ((bits / 8) > (dst - odst)) + if (((bits - (ipv6 ? 96 : 0)) / 8) > (dst - odst)) goto enoent; /* Extend address to four octets. */ @@ -152,3 +147,129 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits) { errno = EMSGSIZE; return (-1); } + +static int +inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + u_int val; + int bits; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + return (0); + curtok = src; + saw_xdigit = 0; + val = 0; + bits = -1; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if (val > 0xffff) + return (0); + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + return (0); + colonp = tp; + continue; + } else if (*src == '\0') { + return (0); + } + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + saw_xdigit = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { + tp += NS_INADDRSZ; + saw_xdigit = 0; + break; /* '\0' was seen by inet_pton4(). */ + } + if (ch == '/') { + bits = getbits(src, 1); + if (bits == -2) + goto enoent; + break; + } + goto enoent; + } + if (saw_xdigit) { + if (tp + NS_INT16SZ > endp) + goto emsgsize; + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const int n = tp - colonp; + int i; + + if (tp == endp) + goto enoent; + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + + memcpy(dst, tmp, NS_IN6ADDRSZ); + + *pbits = bits; + return (0); + + enoent: + errno = ENOENT; + return (-1); + + emsgsize: + errno = EMSGSIZE; + return (-1); +} + +int +getbits(const char *src, int ipv6) { + int bits = 0; + char *cp, ch; + + if (*src == '\0') /* syntax */ + return (-2); + do { + ch = *src++; + cp = strchr(digits, ch); + if (cp == NULL) /* syntax */ + return (-2); + bits *= 10; + bits += cp - digits; + if (bits == 0 && *src != '\0') /* no leading zeros */ + return (-2); + if (bits > (ipv6 ? 128 : 32)) /* range error */ + return (-2); + } while (*src != '\0'); + + return (bits); +} diff --git a/contrib/bind/lib/inet/inet_data.c b/contrib/bind/lib/inet/inet_data.c new file mode 100644 index 000000000000..47b6d9bf6579 --- /dev/null +++ b/contrib/bind/lib/inet/inet_data.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1995-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$Id: inet_data.c,v 1.2 2001/06/20 22:06:36 marka Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include "port_before.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "port_after.h" + +const struct in6_addr isc_in6addr_any = IN6ADDR_ANY_INIT; +const struct in6_addr isc_in6addr_loopback = IN6ADDR_LOOPBACK_INIT; diff --git a/contrib/bind/lib/inet/inet_net_ntop.c b/contrib/bind/lib/inet/inet_net_ntop.c index d8b837782f40..b38a6ca39658 100644 --- a/contrib/bind/lib/inet/inet_net_ntop.c +++ b/contrib/bind/lib/inet/inet_net_ntop.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.7 2001/01/25 19:55:59 vixie Exp $"; +static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.8 2001/09/27 15:08:36 marka Exp $"; #endif #include "port_before.h" @@ -41,6 +41,8 @@ static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.7 2001/01/25 19:55:59 vixi static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, char *dst, size_t size)); +static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits, + char *dst, size_t size)); /* * char * @@ -63,6 +65,8 @@ inet_net_ntop(af, src, bits, dst, size) switch (af) { case AF_INET: return (inet_net_ntop_ipv4(src, bits, dst, size)); + case AF_INET6: + return (inet_net_ntop_ipv6(src, bits, dst, size)); default: errno = EAFNOSUPPORT; return (NULL); @@ -98,6 +102,7 @@ inet_net_ntop_ipv4(src, bits, dst, size) errno = EINVAL; return (NULL); } + if (bits == 0) { if (size < sizeof "0") goto emsgsize; @@ -142,3 +147,131 @@ inet_net_ntop_ipv4(src, bits, dst, size) errno = EMSGSIZE; return (NULL); } + +/* + * static char * + * inet_net_ntop_ipv6(src, bits, fakebits, dst, size) + * convert IPv6 network number from network to presentation format. + * generates CIDR style result always. Picks the shortest representation + * unless the IP is really IPv4. + * always prints specified number of bits (bits). + * return: + * pointer to dst, or NULL if an error occurred (check errno). + * note: + * network byte order assumed. this means 192.5.5.240/28 has + * 0x11110000 in its fourth octet. + * author: + * Vadim Kogan (UCB), June 2001 + * Original version (IPv4) by Paul Vixie (ISC), July 1996 + */ + +static char * +inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { + u_int m; + int b; + int p; + int zero_s, zero_l, tmp_zero_s, tmp_zero_l; + int i; + int is_ipv4 = 0; + unsigned char inbuf[16]; + char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")]; + char *cp; + int words; + u_char *s; + + if (bits < 0 || bits > 128) { + errno = EINVAL; + return (NULL); + } + + cp = outbuf; + + if (bits == 0) { + *cp++ = ':'; + *cp++ = ':'; + *cp = '\0'; + } else { + /* Copy src to private buffer. Zero host part. */ + p = (bits + 7) / 8; + memcpy(inbuf, src, p); + memset(inbuf + p, 0, 16 - p); + b = bits % 8; + if (b != 0) { + m = ~0 << (8 - b); + inbuf[p-1] &= m; + } + + s = inbuf; + + /* how many words need to be displayed in output */ + words = (bits + 15) / 16; + if (words == 1) + words = 2; + + /* Find the longest substring of zero's */ + zero_s = zero_l = tmp_zero_s = tmp_zero_l = 0; + for (i = 0; i < (words * 2); i += 2) { + if ((s[i] | s[i+1]) == 0) { + if (tmp_zero_l == 0) + tmp_zero_s = i / 2; + tmp_zero_l++; + } else { + if (tmp_zero_l && zero_l < tmp_zero_l) { + zero_s = tmp_zero_s; + zero_l = tmp_zero_l; + tmp_zero_l = 0; + } + } + } + + if (tmp_zero_l && zero_l < tmp_zero_l) { + zero_s = tmp_zero_s; + zero_l = tmp_zero_l; + } + + if (zero_l != words && zero_s == 0 && ((zero_l == 6) || + ((zero_l == 5 && s[10] == 0xff && s[11] == 0xff) || + ((zero_l == 7 && s[14] != 0 && s[15] != 1))))) + is_ipv4 = 1; + + /* Format whole words. */ + for (p = 0; p < words; p++) { + if (zero_l != 0 && p >= zero_s && p < zero_s + zero_l) { + /* Time to skip some zeros */ + if (p == zero_s) + *cp++ = ':'; + if (p == words - 1) + *cp++ = ':'; + s++; + s++; + continue; + } + + if (is_ipv4 && p > 5 ) { + *cp++ = (p == 6) ? ':' : '.'; + cp += SPRINTF((cp, "%u", *s++)); + /* we can potentially drop the last octet */ + if (p != 7 || bits > 120) { + *cp++ = '.'; + cp += SPRINTF((cp, "%u", *s++)); + } + } else { + if (cp != outbuf) + *cp++ = ':'; + cp += SPRINTF((cp, "%x", *s * 256 + s[1])); + s += 2; + } + } + } + /* Format CIDR /width. */ + SPRINTF((cp, "/%u", bits)); + if (strlen(outbuf) + 1 > size) + goto emsgsize; + strcpy(dst, outbuf); + + return (dst); + +emsgsize: + errno = EMSGSIZE; + return (NULL); +} diff --git a/contrib/bind/lib/inet/inet_net_pton.c b/contrib/bind/lib/inet/inet_net_pton.c index 4d265b2742c6..ff62a8bec3fc 100644 --- a/contrib/bind/lib/inet/inet_net_pton.c +++ b/contrib/bind/lib/inet/inet_net_pton.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vixie Exp $"; +static const char rcsid[] = "$Id: inet_net_pton.c,v 1.13 2001/09/27 15:08:38 marka Exp $"; #endif #include "port_before.h" @@ -24,6 +24,7 @@ static const char rcsid[] = "$Id: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vix #include #include #include +#include #include #include @@ -41,38 +42,6 @@ static const char rcsid[] = "$Id: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vix # define SPRINTF(x) ((size_t)sprintf x) #endif -static int inet_net_pton_ipv4 __P((const char *src, u_char *dst, - size_t size)); - -/* - * static int - * inet_net_pton(af, src, dst, size) - * convert network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not a valid network specification. - * author: - * Paul Vixie (ISC), June 1996 - */ -int -inet_net_pton(af, src, dst, size) - int af; - const char *src; - void *dst; - size_t size; -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (-1); - } -} - /* * static int * inet_net_pton_ipv4(src, dst, size) @@ -90,20 +59,16 @@ inet_net_pton(af, src, dst, size) * Paul Vixie (ISC), June 1996 */ static int -inet_net_pton_ipv4(src, dst, size) - const char *src; - u_char *dst; - size_t size; -{ - static const char - xdigits[] = "0123456789abcdef", - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; +inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { + static const char xdigits[] = "0123456789abcdef"; + static const char digits[] = "0123456789"; + int n, ch, tmp = 0, dirty, bits; const u_char *odst = dst; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { + && isascii((unsigned char)(src[1])) + && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ if (size <= 0) goto emsgsize; @@ -158,7 +123,8 @@ inet_net_pton_ipv4(src, dst, size) goto enoent; bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { + if (ch == '/' && isascii((unsigned char)(src[0])) && + isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ ch = *src++; /* Skip over the /. */ bits = 0; @@ -213,3 +179,221 @@ inet_net_pton_ipv4(src, dst, size) errno = EMSGSIZE; return (-1); } + +static int +getbits(const char *src, int *bitsp) { + static const char digits[] = "0123456789"; + int n; + int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /* no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 128) /* range */ + return (0); + continue; + } + return (0); + } + if (n == 0) + return (0); + *bitsp = val; + return (1); +} + +static int +getv4(const char *src, u_char *dst, int *bitsp) { + static const char digits[] = "0123456789"; + u_char *odst = dst; + int n; + u_int val; + char ch; + + val = 0; + n = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + pch = strchr(digits, ch); + if (pch != NULL) { + if (n++ != 0 && val == 0) /* no leading zeros */ + return (0); + val *= 10; + val += (pch - digits); + if (val > 255) /* range */ + return (0); + continue; + } + if (ch == '.' || ch == '/') { + if (dst - odst > 3) /* too many octets? */ + return (0); + *dst++ = val; + if (ch == '/') + return (getbits(src, bitsp)); + val = 0; + n = 0; + continue; + } + return (0); + } + if (n == 0) + return (0); + if (dst - odst > 3) /* too many octets? */ + return (0); + *dst++ = val; + return (1); +} + +static int +inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + u_int val; + int digits; + int bits; + size_t bytes; + int words; + int ipv4; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + goto enoent; + curtok = src; + saw_xdigit = 0; + val = 0; + digits = 0; + bits = -1; + ipv4 = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if (++digits > 4) + goto enoent; + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + goto enoent; + colonp = tp; + continue; + } else if (*src == '\0') + goto enoent; + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + saw_xdigit = 0; + digits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + getv4(curtok, tp, &bits) > 0) { + tp += NS_INADDRSZ; + saw_xdigit = 0; + ipv4 = 1; + break; /* '\0' was seen by inet_pton4(). */ + } + if (ch == '/' && getbits(src, &bits) > 0) + break; + goto enoent; + } + if (saw_xdigit) { + if (tp + NS_INT16SZ > endp) + goto enoent; + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (bits == -1) + bits = 128; + + words = (bits + 15) / 16; + if (words < 2) + words = 2; + if (ipv4) + words = 8; + endp = tmp + 2 * words; + + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const int n = tp - colonp; + int i; + + if (tp == endp) + goto enoent; + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + goto enoent; + + bytes = (bits + 7) / 8; + if (bytes > size) + goto emsgsize; + memcpy(dst, tmp, bytes); + return (bits); + + enoent: + errno = ENOENT; + return (-1); + + emsgsize: + errno = EMSGSIZE; + return (-1); +} + +/* + * int + * inet_net_pton(af, src, dst, size) + * convert network number from presentation to network format. + * accepts hex octets, hex strings, decimal octets, and /CIDR. + * "size" is in bytes and describes "dst". + * return: + * number of bits, either imputed classfully or specified with /CIDR, + * or -1 if some failure occurred (check errno). ENOENT means it was + * not a valid network specification. + * author: + * Paul Vixie (ISC), June 1996 + */ +int +inet_net_pton(int af, const char *src, void *dst, size_t size) { + switch (af) { + case AF_INET: + return (inet_net_pton_ipv4(src, dst, size)); + case AF_INET6: + return (inet_net_pton_ipv6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (-1); + } +} diff --git a/contrib/bind/lib/inet/inet_network.c b/contrib/bind/lib/inet/inet_network.c index d26369cf1641..9090d135f51c 100644 --- a/contrib/bind/lib/inet/inet_network.c +++ b/contrib/bind/lib/inet/inet_network.c @@ -65,7 +65,7 @@ again: if (*cp == 'x' || *cp == 'X') base = 16, cp++; while ((c = *cp) != 0) { - if (isdigit(c)) { + if (isdigit((unsigned char)c)) { if (base == 8 && (c == '8' || c == '9')) return (INADDR_NONE); val = (val * base) + (c - '0'); @@ -73,8 +73,9 @@ again: digit = 1; continue; } - if (base == 16 && isxdigit(c)) { - val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + if (base == 16 && isxdigit((unsigned char)c)) { + val = (val << 4) + + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); cp++; digit = 1; continue; @@ -89,7 +90,7 @@ again: *pp++ = val, cp++; goto again; } - if (*cp && !isspace(*cp)) + if (*cp && !isspace(*cp&0xff)) return (INADDR_NONE); *pp++ = val; n = pp - parts; diff --git a/contrib/bind/lib/inet/inet_ntop.c b/contrib/bind/lib/inet/inet_ntop.c index d588e9f0a426..e05812ed9803 100644 --- a/contrib/bind/lib/inet/inet_ntop.c +++ b/contrib/bind/lib/inet/inet_ntop.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_ntop.c,v 1.10 2001/01/25 20:21:10 vixie Exp $"; +static const char rcsid[] = "$Id: inet_ntop.c,v 1.11 2001/09/27 15:12:57 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -175,8 +175,9 @@ inet_ntop6(src, dst, size) if (i != 0) *tp++ = ':'; /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + if (i == 6 && best.base == 0 && (best.len == 6 || + (best.len == 7 && words[7] != 0x0001) || + (best.len == 5 && words[5] == 0xffff))) { if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) return (NULL); tp += strlen(tp); diff --git a/contrib/bind/lib/inet/inet_pton.c b/contrib/bind/lib/inet/inet_pton.c index 0a2927de39a2..a6b0a7129066 100644 --- a/contrib/bind/lib/inet/inet_pton.c +++ b/contrib/bind/lib/inet/inet_pton.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_pton.c,v 1.7 1999/10/13 16:39:28 vixie Exp $"; +static const char rcsid[] = "$Id: inet_pton.c,v 1.8 2001/07/16 03:22:24 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -95,10 +95,12 @@ inet_pton4(src, dst) if ((pch = strchr(digits, ch)) != NULL) { u_int new = *tp * 10 + (pch - digits); + if (saw_digit && *tp == 0) + return (0); if (new > 255) return (0); *tp = new; - if (! saw_digit) { + if (!saw_digit) { if (++octets > 4) return (0); saw_digit = 1; diff --git a/contrib/bind/lib/inet/nsap_addr.c b/contrib/bind/lib/inet/nsap_addr.c index da388dc3700d..7198b9d4d2c8 100644 --- a/contrib/bind/lib/inet/nsap_addr.c +++ b/contrib/bind/lib/inet/nsap_addr.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nsap_addr.c,v 8.11 2001/03/26 07:04:30 marka Exp $"; +static const char rcsid[] = "$Id: nsap_addr.c,v 8.12 2001/05/28 07:37:46 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -46,6 +46,7 @@ inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) { if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X')) return (0); + ascii += 2; while ((c = *ascii++) != '\0' && len < (u_int)maxlen) { if (c == '.' || c == '+' || c == '/') @@ -88,8 +89,8 @@ inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { start = tmpbuf; } - *ascii = '0'; - *ascii = 'x'; + *ascii++ = '0'; + *ascii++ = 'x'; if (binlen > 255) binlen = 255; diff --git a/contrib/bind/lib/irs/Makefile b/contrib/bind/lib/irs/Makefile index 4784ccfd44de..0c4e46d5e2a6 100644 --- a/contrib/bind/lib/irs/Makefile +++ b/contrib/bind/lib/irs/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 8.21 2000/12/23 08:02:59 vixie Exp $ +# $Id: Makefile,v 8.24 2001/08/14 05:58:07 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -83,7 +83,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} -(${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \ -o ${THREADED}/$*.${O} ; \ ${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ diff --git a/contrib/bind/lib/irs/dns.c b/contrib/bind/lib/irs/dns.c index 66bdbf56f0d5..3feed265b5e8 100644 --- a/contrib/bind/lib/irs/dns.c +++ b/contrib/bind/lib/irs/dns.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns.c,v 1.15 2000/02/28 07:52:16 vixie Exp $"; +static const char rcsid[] = "$Id: dns.c,v 1.16 2001/05/29 05:48:26 marka Exp $"; #endif /* @@ -59,6 +59,8 @@ irs_dns_acc(const char *options) { struct irs_acc *acc; struct dns_p *dns; + UNUSED(options); + if (!(acc = memget(sizeof *acc))) { errno = ENOMEM; return (NULL); diff --git a/contrib/bind/lib/irs/dns_gr.c b/contrib/bind/lib/irs/dns_gr.c index 64cbe9b4dcf4..a62234556a68 100644 --- a/contrib/bind/lib/irs/dns_gr.c +++ b/contrib/bind/lib/irs/dns_gr.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_gr.c,v 1.19 1999/01/18 07:46:48 vixie Exp $"; +static const char rcsid[] = "$Id: dns_gr.c,v 1.20 2001/05/29 05:48:27 marka Exp $"; #endif /* @@ -146,6 +146,9 @@ gr_close(struct irs_gr *this) { static struct group * gr_next(struct irs_gr *this) { + + UNUSED(this); + return (NULL); } @@ -164,6 +167,9 @@ gr_bygid(struct irs_gr *this, gid_t gid) { static void gr_rewind(struct irs_gr *this) { + + UNUSED(this); + /* NOOP */ } @@ -171,6 +177,11 @@ static int gr_list(struct irs_gr *this, const char *name, gid_t basegid, gid_t *groups, int *ngroups) { + UNUSED(this); + UNUSED(name); + UNUSED(basegid); + UNUSED(groups); + *ngroups = 0; /* There's some way to do this in Hesiod. */ return (-1); @@ -178,6 +189,8 @@ gr_list(struct irs_gr *this, const char *name, static void gr_minimize(struct irs_gr *this) { + + UNUSED(this); /* NOOP */ } diff --git a/contrib/bind/lib/irs/dns_ho.c b/contrib/bind/lib/irs/dns_ho.c index 8b2df772ef16..e340f0201d83 100644 --- a/contrib/bind/lib/irs/dns_ho.c +++ b/contrib/bind/lib/irs/dns_ho.c @@ -52,7 +52,7 @@ /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_ho.c,v 1.28 2000/04/20 07:47:54 vixie Exp $"; +static const char rcsid[] = "$Id: dns_ho.c,v 1.33 2001/10/05 04:30:21 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -94,11 +94,7 @@ static const char rcsid[] = "$Id: dns_ho.c,v 1.28 2000/04/20 07:47:54 vixie Exp #define MAXALIASES 35 #define MAXADDRS 35 -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (1024*64) #define BOUNDS_CHECK(ptr, count) \ if ((ptr) + (count) > eom) { \ @@ -106,6 +102,26 @@ static const char rcsid[] = "$Id: dns_ho.c,v 1.28 2000/04/20 07:47:54 vixie Exp continue; \ } else (void)0 +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +struct dns_res_target { + struct dns_res_target *next; + querybuf qbuf; /* query buffer */ + u_char *answer; /* buffer to put answer */ + int anslen; /* size of answer buffer */ + int qclass, qtype; /* class and type of query */ + int action; /* condition whether query is really issued */ + char qname[MAXDNAME +1]; /* domain name */ +#if 0 + int n; /* result length */ +#endif +}; +enum {RESTGT_DOALWAYS, RESTGT_AFTERFAILURE, RESTGT_IGNORE}; +enum {RESQRY_SUCCESS, RESQRY_FAIL}; + struct pvt { struct hostent host; char * h_addr_ptrs[MAXADDRS + 1]; @@ -141,6 +157,8 @@ static struct __res_state * ho_res_get(struct irs_ho *this); static void ho_res_set(struct irs_ho *this, struct __res_state *res, void (*free_res)(void *)); +static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, + const struct addrinfo *pai); static void map_v4v6_hostent(struct hostent *hp, char **bp, int *len); @@ -148,7 +166,20 @@ static void addrsort(res_state, char **, int); static struct hostent * gethostans(struct irs_ho *this, const u_char *ansbuf, int anslen, const char *qname, int qtype, - int af, int size); + int af, int size, + struct addrinfo **ret_aip, + const struct addrinfo *pai); +static int add_hostent(struct pvt *pvt, char *bp, char **hap, + struct addrinfo *ai); +static const u_char * ar_head(const u_char *, int, const u_char *, + const u_char *, struct pvt *, + int (*)(const char *)); +static struct addrinfo * a6_expand(const u_char *, const u_char *, int, + const u_char *, const u_char *, + const struct in6_addr *, int, + const struct addrinfo *, + struct pvt *, int (*)(const char *), int *); +static const char *dname_subst(const char *, const char *, const char *); static int init(struct irs_ho *this); /* Exports. */ @@ -158,6 +189,8 @@ irs_dns_ho(struct irs_acc *this) { struct irs_ho *ho; struct pvt *pvt; + UNUSED(this); + if (!(pvt = memget(sizeof *pvt))) { errno = ENOMEM; return (NULL); @@ -180,6 +213,7 @@ irs_dns_ho(struct irs_acc *this) { ho->minimize = ho_minimize; ho->res_get = ho_res_get; ho->res_set = ho_res_set; + ho->addrinfo = ho_addrinfo; return (ho); } @@ -214,24 +248,50 @@ ho_byname(struct irs_ho *this, const char *name) { } static struct hostent * -ho_byname2(struct irs_ho *this, const char *name, int af) { +ho_byname2(struct irs_ho *this, const char *name, int af) +{ struct pvt *pvt = (struct pvt *)this->private; - int n, size, type; - u_char buf[MAXPACKET]; + struct hostent *hp = NULL; + int n, size; char tmp[NS_MAXDNAME]; const char *cp; + struct addrinfo ai; + struct dns_res_target q, q2, *p; + int querystate = RESQRY_FAIL; if (init(this) == -1) return (NULL); + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + switch (af) { case AF_INET: size = INADDRSZ; - type = T_A; + q.qclass = C_IN; + q.qtype = T_A; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.action = RESTGT_DOALWAYS; break; case AF_INET6: size = IN6ADDRSZ; - type = T_AAAA; + q.qclass = C_IN; + q.qtype = ns_t_a6; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.next = &q2; +#ifdef RES_USE_A6 + if ((pvt->res->options & RES_USE_A6) == 0) + q.action = RESTGT_IGNORE; + else +#endif + q.action = RESTGT_DOALWAYS; + q2.qclass = C_IN; + q2.qtype = T_AAAA; + q2.answer = q2.qbuf.buf; + q2.anslen = sizeof(q2.qbuf); + q2.action = RESTGT_AFTERFAILURE; break; default: RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL); @@ -248,30 +308,62 @@ ho_byname2(struct irs_ho *this, const char *name, int af) { tmp, sizeof tmp))) name = cp; - if ((n = res_nsearch(pvt->res, name, C_IN, type, - buf, sizeof buf)) < 0) - return (NULL); - return (gethostans(this, buf, n, name, type, af, size)); + for (p = &q; p; p = p->next) { + switch(p->action) { + case RESTGT_DOALWAYS: + break; + case RESTGT_AFTERFAILURE: + if (querystate == RESQRY_SUCCESS) + continue; + break; + case RESTGT_IGNORE: + continue; + } + + if ((n = res_nsearch(pvt->res, name, p->qclass, p->qtype, + p->answer, p->anslen)) < 0) { + querystate = RESQRY_FAIL; + continue; + } + + memset(&ai, 0, sizeof(ai)); + ai.ai_family = af; + if ((hp = gethostans(this, p->answer, n, name, p->qtype, + af, size, NULL, + (const struct addrinfo *)&ai)) != NULL) + return(hp); /* no more loop is necessary */ + + querystate = RESQRY_FAIL; + continue; + } + + return(hp); /* should be NULL */ } static struct hostent * -ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { +ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) +{ struct pvt *pvt = (struct pvt *)this->private; const u_char *uaddr = addr; - char qbuf[MAXDNAME+1], *qp; - u_char buf[MAXPACKET]; + char *qp; struct hostent *hp; + struct addrinfo ai; + struct dns_res_target q, q2, *p; int n, size; + int querystate = RESQRY_FAIL; if (init(this) == -1) return (NULL); + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + if (af == AF_INET6 && len == IN6ADDRSZ && (!memcmp(uaddr, mapped, sizeof mapped) || (!memcmp(uaddr, tunnelled, sizeof tunnelled) && memcmp(&uaddr[sizeof tunnelled], v6local, sizeof(v6local))))) { /* Unmap. */ - addr = (char *)addr + sizeof mapped; + addr = (const char *)addr + sizeof mapped; uaddr += sizeof mapped; af = AF_INET; len = INADDRSZ; @@ -279,9 +371,31 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { switch (af) { case AF_INET: size = INADDRSZ; + q.qclass = C_IN; + q.qtype = T_PTR; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.action = RESTGT_DOALWAYS; break; case AF_INET6: size = IN6ADDRSZ; + q.qclass = C_IN; + q.qtype = T_PTR; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.next = &q2; + if ((pvt->res->options & RES_NO_BITSTRING) != 0) + q.action = RESTGT_IGNORE; + else + q.action = RESTGT_DOALWAYS; + q2.qclass = C_IN; + q2.qtype = T_PTR; + q2.answer = q2.qbuf.buf; + q2.anslen = sizeof(q2.qbuf); + if ((pvt->res->options & RES_NO_NIBBLE) != 0) + q2.action = RESTGT_IGNORE; + else + q2.action = RESTGT_AFTERFAILURE; break; default: errno = EAFNOSUPPORT; @@ -295,49 +409,93 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { } switch (af) { case AF_INET: - (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", + qp = q.qname; + (void) sprintf(qp, "%u.%u.%u.%u.in-addr.arpa", (uaddr[3] & 0xff), (uaddr[2] & 0xff), (uaddr[1] & 0xff), (uaddr[0] & 0xff)); break; case AF_INET6: - qp = qbuf; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - qp += SPRINTF((qp, "%x.%x.", - uaddr[n] & 0xf, - (uaddr[n] >> 4) & 0xf)); + if (q.action != RESTGT_IGNORE) { + qp = q.qname; + qp += SPRINTF((qp, "\\[x")); + for (n = 0; n < IN6ADDRSZ; n++) + qp += SPRINTF((qp, "%02x", uaddr[n])); + SPRINTF((qp, "/128].%s", + res_get_bitstringsuffix(pvt->res))); + } + if (q2.action != RESTGT_IGNORE) { + qp = q2.qname; + for (n = IN6ADDRSZ - 1; n >= 0; n--) { + qp += SPRINTF((qp, "%x.%x.", + uaddr[n] & 0xf, + (uaddr[n] >> 4) & 0xf)); + } + strcpy(qp, res_get_nibblesuffix(pvt->res)); } - strcpy(qp, "ip6.int"); break; default: abort(); } - n = res_nquery(pvt->res, qbuf, C_IN, T_PTR, buf, sizeof buf); - if (n < 0) - return (NULL); - hp = gethostans(this, buf, n, qbuf, T_PTR, af, size); - if (!hp) - return (NULL); /* H_ERRNO was set by gethostans() */ - memcpy(pvt->host_addr, addr, len); - pvt->h_addr_ptrs[0] = (char *)pvt->host_addr; - pvt->h_addr_ptrs[1] = NULL; - if (af == AF_INET && (pvt->res->options & RES_USE_INET6)) { - map_v4v6_address((char*)pvt->host_addr, (char*)pvt->host_addr); - pvt->host.h_addrtype = AF_INET6; - pvt->host.h_length = IN6ADDRSZ; + + for (p = &q; p; p = p->next) { + switch(p->action) { + case RESTGT_DOALWAYS: + break; + case RESTGT_AFTERFAILURE: + if (querystate == RESQRY_SUCCESS) + continue; + break; + case RESTGT_IGNORE: + continue; + } + + if ((n = res_nquery(pvt->res, p->qname, p->qclass, p->qtype, + p->answer, p->anslen)) < 0) { + querystate = RESQRY_FAIL; + continue; + } + + memset(&ai, 0, sizeof(ai)); + ai.ai_family = af; + hp = gethostans(this, p->answer, n, p->qname, T_PTR, af, size, + NULL, (const struct addrinfo *)&ai); + if (!hp) { + querystate = RESQRY_FAIL; + continue; + } + + memcpy(pvt->host_addr, addr, len); + pvt->h_addr_ptrs[0] = (char *)pvt->host_addr; + pvt->h_addr_ptrs[1] = NULL; + if (af == AF_INET && (pvt->res->options & RES_USE_INET6)) { + map_v4v6_address((char*)pvt->host_addr, + (char*)pvt->host_addr); + pvt->host.h_addrtype = AF_INET6; + pvt->host.h_length = IN6ADDRSZ; + } + + RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS); + return (hp); /* no more loop is necessary. */ } - RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS); - return (hp); + + return(NULL); /* H_ERRNO was set by subroutines */ } static struct hostent * ho_next(struct irs_ho *this) { + + UNUSED(this); + return (NULL); } static void ho_rewind(struct irs_ho *this) { + + UNUSED(this); + /* NOOP */ } @@ -367,6 +525,495 @@ ho_res_get(struct irs_ho *this) { return (pvt->res); } +/* XXX */ +extern struct addrinfo *addr2addrinfo __P((const struct addrinfo *, + const char *)); + +static struct addrinfo * +ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) +{ + struct pvt *pvt = (struct pvt *)this->private; + int n; + char tmp[NS_MAXDNAME]; + const char *cp; + struct dns_res_target q, q2, q3, *p; + struct addrinfo sentinel, *cur; + int querystate = RESQRY_FAIL; + + if (init(this) == -1) + return (NULL); + + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + memset(&q3, 0, sizeof(q3)); + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + switch (pai->ai_family) { + case AF_UNSPEC: + /* prefer IPv6 */ + q.qclass = C_IN; + q.qtype = ns_t_a6; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.next = &q2; +#ifdef RES_USE_A6 + if ((pvt->res->options & RES_USE_A6) == 0) + q.action = RESTGT_IGNORE; + else +#endif + q.action = RESTGT_DOALWAYS; + q2.qclass = C_IN; + q2.qtype = T_AAAA; + q2.answer = q2.qbuf.buf; + q2.anslen = sizeof(q2.qbuf); + q2.next = &q3; + /* try AAAA only when A6 query fails */ + q2.action = RESTGT_AFTERFAILURE; + q3.qclass = C_IN; + q3.qtype = T_A; + q3.answer = q3.qbuf.buf; + q3.anslen = sizeof(q3.qbuf); + q3.action = RESTGT_DOALWAYS; + break; + case AF_INET: + q.qclass = C_IN; + q.qtype = T_A; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.action = RESTGT_DOALWAYS; + break; + case AF_INET6: + q.qclass = C_IN; + q.qtype = ns_t_a6; + q.answer = q.qbuf.buf; + q.anslen = sizeof(q.qbuf); + q.next = &q2; +#ifdef RES_USE_A6 + if ((pvt->res->options & RES_USE_A6) == 0) + q.action = RESTGT_IGNORE; + else +#endif + q.action = RESTGT_DOALWAYS; + q2.qclass = C_IN; + q2.qtype = T_AAAA; + q2.answer = q2.qbuf.buf; + q2.anslen = sizeof(q2.qbuf); + q2.action = RESTGT_AFTERFAILURE; + break; + default: + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* better error? */ + return(NULL); + } + + /* + * if there aren't any dots, it could be a user-level alias. + * this is also done in res_nquery() since we are not the only + * function that looks up host names. + */ + if (!strchr(name, '.') && (cp = res_hostalias(pvt->res, name, + tmp, sizeof tmp))) + name = cp; + + for (p = &q; p; p = p->next) { + struct addrinfo *ai; + + switch(p->action) { + case RESTGT_DOALWAYS: + break; + case RESTGT_AFTERFAILURE: + if (querystate == RESQRY_SUCCESS) + continue; + break; + case RESTGT_IGNORE: + continue; + } + + if ((n = res_nsearch(pvt->res, name, p->qclass, p->qtype, + p->answer, p->anslen)) < 0) { + querystate = RESQRY_FAIL; + continue; + } + (void)gethostans(this, p->answer, n, name, p->qtype, + pai->ai_family, /* XXX: meaningless */ + 0, &ai, pai); + if (ai) { + querystate = RESQRY_SUCCESS; + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + else + querystate = RESQRY_FAIL; + } + + return(sentinel.ai_next); +} + +static const u_char * +ar_head(cp, count, msg, eom, pvt, name_ok) + const u_char *cp, *msg, *eom; + int count; + struct pvt *pvt; + int (*name_ok)(const char *); +{ + int n; + char buf[1024]; /* XXX */ + + while (count-- > 0 && cp < eom) { + n = dn_expand(msg, eom, cp, buf, sizeof(buf)); + if (n < 0 || !maybe_ok(pvt->res, buf, name_ok)) + goto end; + cp += n; /* name */ + if (cp + 3 * INT16SZ + INT32SZ >= eom) + goto end; + cp += INT16SZ; /* type */ + cp += INT16SZ + INT32SZ; /* class, TTL */ + n = ns_get16(cp); + cp += n + INT16SZ; /* len */ + } + return(cp); + + end: + return(eom); /* XXX */ +} + +/* XXX: too many arguments */ +static struct addrinfo * +a6_expand(const u_char *ansbuf, const u_char *a6p, + int a6len, const u_char *arp, const u_char *eom, + const struct in6_addr *in6, int plen, const struct addrinfo *pai, + struct pvt *pvt, int (*name_ok)(const char *), int *errorp) +{ + struct in6_addr a; + int n, pbyte, plen1, pbyte1, error = 0; + const u_char *cp; + struct addrinfo sentinel, *cur; + char pname[1024], buf[1024]; /* XXX */ + + *errorp = NETDB_SUCCESS; + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + /* + * Validate A6 parameters. + */ + if (a6len == 0) { /* an A6 record must contain at least 1 byte. */ + error = NO_RECOVERY; + goto bad; + } + /* prefix length check. */ + if ((plen1 = *a6p) > 128) { + error = NO_RECOVERY; + goto bad; + } + if (plen1 > plen) { + /* + * New length must not be greater than old one. + * Ignore the record as specified in RFC 2874 + * Section 3.1.2. + */ + return(NULL); /* just ignore. */ + } + /* boundary check for new plen and prefix addr */ + pbyte1 = (plen1 & ~7) / 8; + if ((int)sizeof(struct in6_addr) - pbyte1 > a6len - 1) { + error = NO_RECOVERY; + goto bad; + } + + /* + * merge the new prefix portion. + * <--- plen(bits) ---> + * <--- pbyte ---><-b-> + * 000000000000000pppppxxxxxxxxxxx(= in6, 0: unknown, x: known, p: pad) + * PP++++++++(+ should be merged. P: padding, must be 0) + * <-- plen1--> + * <-pbyte1-> + * ^a6p+1 + * The result should be: + * 0000000000PP++++++++xxxxxxxxxxx(= a) + */ + pbyte = (plen & ~7) / 8; + a = *in6; + if (pbyte > pbyte1) { + /* N.B. the case of "pbyte1 == 128" is implicitly excluded. */ + int b = plen % 8; /* = the length of "pp..." above */ + u_char c_hi, c_lo; + + memcpy(&a.s6_addr[pbyte1], a6p + 1, pbyte - pbyte1); + if (b > 0) { + c_hi = a6p[pbyte - pbyte1 + 1]; + c_lo = in6->s6_addr[pbyte]; + a.s6_addr[pbyte] = + (c_hi & (0xff << (8 - b))) | + ((0x00ff >> b) & c_lo); + } + } + +#if 0 /* for debug */ + if ((pvt->res->options & RES_DEBUG) != 0) { + u_char ntopbuf[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET6, &a, ntopbuf, sizeof(ntopbuf)); + printf("a6_expand: %s\\%d\n", ntopbuf, plen1); + } +#endif + + if (plen1 == 0) { + /* Here is the end of A6 chain. make addrinfo, then return. */ + return(addr2addrinfo(pai, (const char *)&a)); + } + + /* + * Expand the new prefix name. Since the prefix name must not be + * compressed (RFC 2874 Section 3.1.1), we could use ns_name_ntop() + * here if it had a stricter boundary check. + */ + cp = a6p + 1 + (sizeof(*in6) - pbyte1); + n = dn_expand(ansbuf, eom, cp, pname, sizeof(pname)); + if (n < 0 || !maybe_ok(pvt->res, pname, name_ok)) { + error = NO_RECOVERY; + goto bad; + } + if (cp + n != a6p + a6len) { /* length mismatch */ + error = NO_RECOVERY; + goto bad; + } + + /* + * we need (more) additional section records, but no one is + * available, which possibly means a malformed answer. + */ + if (arp == NULL) { + error = NO_RECOVERY; /* we can't resolve the chain. */ + goto bad; + } + + /* + * Loop thru the rest of the buffer, searching for the next A6 record + * that has the same owner name as the prefix name. If found, then + * recursively call this function to expand the whole A6 chain. + */ + plen = plen1; + for (cp = arp; cp != NULL && cp < eom; cp += n) { + int class, type; + + n = dn_expand(ansbuf, eom, cp, buf, sizeof(buf)); + if (n < 0 || !maybe_ok(pvt->res, buf, name_ok)) { + error = NO_RECOVERY; + goto bad; + } + cp += n; /* name */ + if (cp + 3 * INT16SZ + INT32SZ > eom) { + error = NO_RECOVERY; + goto bad; + } + type = ns_get16(cp); + cp += INT16SZ; /* type */ + class = ns_get16(cp); + cp += INT16SZ + INT32SZ; /* class, TTL */ + n = ns_get16(cp); + cp += INT16SZ; /* len */ + if (cp + n > eom) { + error = NO_RECOVERY; + goto bad; + } + if (class != C_IN || type != ns_t_a6) { + /* we are only interested in A6 records. skip others */ + continue; + } + + if (ns_samename(buf, pname) != 1) { + continue; + } + + /* Proceed to the next record in the chain. */ + cur->ai_next = a6_expand(ansbuf, cp, n, cp + n, eom, + (const struct in6_addr *)&a, + plen, pai, pvt, name_ok, &error); + if (error != NETDB_SUCCESS) + goto bad; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + + return(sentinel.ai_next); + + bad: + *errorp = error; + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return(NULL); +} + +static const char * +dname_subst(const char *qname0, const char *owner0, const char *target) { + char owner[MAXDNAME]; + static char qname[MAXDNAME]; + const char blabelhead[] = "\\[x"; /* we can assume hex strings */ + int qlen, olen; + int bufsiz = sizeof(qname); + + /* make local copies, which are canonicalized. */ + if (ns_makecanon(qname0, qname, sizeof(qname)) < 0 || + ns_makecanon(owner0, owner, sizeof(owner)) < 0) + return(NULL); + qlen = strlen(qname); + olen = strlen(owner); + /* from now on, do not refer to qname0 nor owner0. */ + + /* + * check if QNAME is a subdomain of OWNER. + * XXX: currently, we only handle the following two cases: + * (A) none of the labels are bitlabels, or + * (B) both of the head labels are bitlabels (and the following + * labels are NOT bitlabels). + * If we pass the check, then subtract the remaining part from QNAME. + * ex. (A) qname=www.foo.com,owner=foo.com => new qname=www. + * (B) qname=\[x3ffe0501/32].foo.com,owner=\[x3ffe/16].foo.com + * => new qname=\[x0501/16]. + */ + if (ns_samedomain(qname, owner)) { /* check (A) */ + /* at this point, qlen must not be smaller than olen */ + qname[qlen - olen] = 0; + bufsiz -= (qlen - olen); + } else { /* check (B) */ + char *parent0, *parent1; + /* the following 3 have enough size to store 1 bitlabel */ + u_char qlabel[64], olabel[64], newlabel[64]; + int qlabellen, olabellen; + + if (strncmp(qname, blabelhead, 3) != 0 || + strncmp(owner, blabelhead, 3) != 0) + return(NULL); + /* + * Both two begin with bitlabels. The succeeding parts + * must exact match. + */ + if ((parent0 = strchr(qname, '.')) == NULL || + (parent1 = strchr(owner, '.')) == NULL) + return(NULL); + + /* ns_samename allows names to begin with '.' */ + if (ns_samename(parent0, parent1) != 1) + return(NULL); + + /* cut the upper domain parts off. */ + *(parent0 + 1) = 0; + *(parent1 + 1) = 0; + /* convert the textual form into binary one. */ + if (ns_name_pton(qname, qlabel, sizeof(qlabel)) < 0 || + ns_name_pton(owner, olabel, sizeof(olabel)) < 0) + return(NULL); + if ((qlabellen = *(qlabel + 1)) == 0) + qlabellen = 256; + if ((olabellen = *(olabel + 1)) == 0) + olabellen = 256; + if (olabellen > qlabellen) + return(NULL); /* owner does not contain qname. */ + else { + int qplen = (qlabellen + 7) / 8; + int oplen = (olabellen + 7) / 8; + int sft = olabellen % 8; + int nllen, n; + u_char *qp, *op, *np; + + /* skip ELT and Count. */ + qp = qlabel + 2; + op = olabel + 2; + + /* check if olabel is a "subdomain" of qlabel. */ + if (memcmp(qp, op, oplen - 1) != 0) + return(NULL); + if (sft > 0) { + /* compare trailing bits (between 1 and 7) */ + if ((qp[qplen - 1] & (0xff << sft)) != + op[qplen - 1]) + return(NULL); + } + + /* OK, get remaining bits from qlabel. */ + np = newlabel; + if (olabellen == qlabellen) { + /* + * Two names (including bitlabels) are exactly + * same. Discard the whole names. + * XXX: ns_samename() above should exclude + * this case... + */ + qname[0] = 0; + goto maketarget; + } + *np++ = 0x41; /* XXX hardcoding */ + *np++ = nllen = (qlabellen - olabellen); + if (sft == 0) { + /* + * No alignment issue. can just use memcpy. + * Note that the "else" part below contains + * this case. We separate the two cases just + * for efficiency. + * We assume that ns_name_pton above ensures + * QP does not contain trailing garbages. + */ + memcpy(np, qp + oplen, qplen - oplen); + np += qplen - oplen; + *np = 0; + } else { + /* + * copy the lower (8-SFT) bits of QP to the + * upper (8-SFT) bits of NP, then copy the + * upper SFT bits of QP+1 to the lower SFT bits + * of NP, and so on... + * if QP is xxxyyyyy zzzwww..., then + * NP would be yyyyyzzz ... + * Again, we assume QP does not contain + * trailing garbages. + */ + qp += (oplen - 1); + while (nllen > 0) { + *np = (*qp << sft) & 0xff; + if ((nllen -= (8 - sft)) <= 0) + break; /* done */ + qp++; + *np |= ((*qp >> sft) & 0xff); + np++; + nllen -= sft; + } + *++np = 0; + } + + /* + * make a new bitlabel with the remaining bits. + * Note that there's no buffer boundary issue, since + * qlabel, olabel, and newlabel all have the same size. + * ns_name_ntop() must not return 0, since we have + * a non-empty bitlabel. + */ + if ((n = ns_name_ntop(newlabel, qname, sizeof(qname))) + <= 0) + return(NULL); + bufsiz -= n; + if (qname[n - 1] != '.') { /* XXX no trailing dot */ + qname[n - 1] = '.'; + qname[n] = 0; + bufsiz--; + } + + } + } + + maketarget: + /* + * Finally, append the remaining part (maybe empty) to the new target. + */ + if (bufsiz < (int)strlen(target)) /* bufsiz takes care of the \0. */ + return(NULL); + strcat(qname, target); + + return((const char *)qname); +} + static void ho_res_set(struct irs_ho *this, struct __res_state *res, void (*free_res)(void *)) { @@ -386,23 +1033,37 @@ ho_res_set(struct irs_ho *this, struct __res_state *res, static struct hostent * gethostans(struct irs_ho *this, const u_char *ansbuf, int anslen, const char *qname, int qtype, - int af, int size) + int af, int size, /* meaningless for addrinfo cases */ + struct addrinfo **ret_aip, const struct addrinfo *pai) { struct pvt *pvt = (struct pvt *)this->private; int type, class, buflen, ancount, qdcount, n, haveanswer, had_error; + int error = NETDB_SUCCESS, arcount; int (*name_ok)(const char *); const HEADER *hp; const u_char *eom; + const u_char *eor; const u_char *cp; - const char *tname, **tap; + const char *tname; + const char *hname; char *bp, **ap, **hap; char tbuf[MAXDNAME+1]; + struct addrinfo sentinel, *cur, ai; + const u_char *arp = NULL; + + if (pai == NULL) abort(); + if (ret_aip != NULL) + *ret_aip = NULL; + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; tname = qname; eom = ansbuf + anslen; switch (qtype) { + case ns_t_a6: case T_A: case T_AAAA: + case T_ANY: /* use T_ANY only for T_A/T_AAAA lookup */ name_ok = res_hnok; break; case T_PTR: @@ -414,7 +1075,7 @@ gethostans(struct irs_ho *this, pvt->host.h_addrtype = af; pvt->host.h_length = size; - pvt->host.h_name = NULL; + hname = pvt->host.h_name = NULL; /* * Find first satisfactory answer. @@ -423,9 +1084,10 @@ gethostans(struct irs_ho *this, RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); return (NULL); } - hp = (HEADER *)ansbuf; + hp = (const HEADER *)ansbuf; ancount = ntohs(hp->ancount); qdcount = ntohs(hp->qdcount); + arcount = ntohs(hp->arcount); bp = pvt->hostbuf; buflen = sizeof pvt->hostbuf; cp = ansbuf + HFIXEDSZ; @@ -443,7 +1105,8 @@ gethostans(struct irs_ho *this, RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); return (NULL); } - if (qtype == T_A || qtype == T_AAAA) { + if (qtype == T_A || qtype == T_AAAA || + qtype == ns_t_a6 || qtype == T_ANY) { /* res_nsend() has already verified that the query name is the * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). @@ -454,9 +1117,10 @@ gethostans(struct irs_ho *this, return (NULL); } pvt->host.h_name = bp; + hname = bp; bp += n; buflen -= n; - /* The qname can be abbreviated, but h_name is now absolute. */ + /* The qname can be abbreviated, but hname is now absolute. */ qname = pvt->host.h_name; } ap = pvt->host_aliases; @@ -486,10 +1150,12 @@ gethostans(struct irs_ho *this, cp += n; continue; } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { + eor = cp + n; + if ((qtype == T_A || qtype == T_AAAA || qtype == ns_t_a6 || + qtype == T_ANY) && type == T_CNAME) { if (ap >= &pvt->host_aliases[MAXALIASES-1]) continue; - n = dn_expand(ansbuf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(ansbuf, eor, cp, tbuf, sizeof tbuf); if (n < 0 || !maybe_ok(pvt->res, tbuf, name_ok)) { had_error++; continue; @@ -508,17 +1174,78 @@ gethostans(struct irs_ho *this, } strcpy(bp, tbuf); pvt->host.h_name = bp; + hname = bp; bp += n; buflen -= n; continue; } + if (type == ns_t_dname) { + const char *t0, *t; + + /* + * just replace the query target; do not update the + * alias list. (Or should we?) + */ + t0 = (qtype == T_PTR) ? tname : hname; + + n = dn_expand(ansbuf, eor, cp, tbuf, sizeof(tbuf)); + if (n < 0 || !maybe_dnok(pvt->res, tbuf)) { + had_error++; + continue; + } +#ifdef RES_USE_DNAME + if ((pvt ->res->options & RES_USE_DNAME) == 0) { + cp += n; + continue; + } +#endif + if ((t = dname_subst(t0, bp, tbuf)) == NULL) { + cp += n; + continue; + } +#if 0 /* for debug */ + if ((pvt->res->options & RES_DEBUG) != 0) { + printf("DNAME owner=%s, target=%s, next=%s\n", + bp, tbuf, t); + } +#endif + cp += n; + + n = strlen(t) + 1; /* for the \0 */ + if (n > buflen) { + had_error++; + continue; + } + strcpy(bp, t); + if (qtype == T_PTR) + tname = bp; + else + hname = bp; + bp += n; + buflen -= n; + + continue; + } if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(ansbuf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(ansbuf, eor, cp, tbuf, sizeof tbuf); if (n < 0 || !maybe_dnok(pvt->res, tbuf)) { had_error++; continue; } cp += n; +#ifdef RES_USE_DNAME + if ((pvt->res->options & RES_USE_DNAME) != 0) +#endif + { + /* + * We may be able to check this regardless + * of the USE_DNAME bit, but we add the check + * for now since the DNAME support is + * experimental. + */ + if (ns_samename(tname, bp) != 1) + continue; + } /* Get canonical name. */ n = strlen(tbuf) + 1; /* for the \0 */ if (n > buflen) { @@ -531,25 +1258,38 @@ gethostans(struct irs_ho *this, buflen -= n; continue; } - if (type != qtype) { + if (qtype == T_ANY) { + if (!(type == T_A || type == T_AAAA || + type == ns_t_a6)) { + cp += n; + continue; + } + } else if (type != qtype) { cp += n; continue; } switch (type) { case T_PTR: + if (ret_aip != NULL) { + /* addrinfo never needs T_PTR */ + cp += n; + continue; + } if (ns_samename(tname, bp) != 1) { cp += n; continue; } - n = dn_expand(ansbuf, eom, cp, bp, buflen); + n = dn_expand(ansbuf, eor, cp, bp, buflen); if (n < 0 || !maybe_hnok(pvt->res, bp) || n >= MAXHOSTNAMELEN) { had_error++; break; } cp += n; - if (!haveanswer) + if (!haveanswer) { pvt->host.h_name = bp; + hname = bp; + } else if (ap < &pvt->host_aliases[MAXALIASES-1]) *ap++ = bp; else @@ -560,16 +1300,91 @@ gethostans(struct irs_ho *this, buflen -= n; } break; + case ns_t_a6: { + struct in6_addr in6; + struct addrinfo ai; + +#ifdef RES_USE_A6 + if ((pvt->res->options & RES_USE_A6) == 0) { + cp += n; + continue; + } +#endif + + if (ns_samename(hname, bp) != 1) { + cp += n; + continue; + } + + /* + * search for the top of the additional section. + * once found, keep it for the case where we have + * more than one A6 record. + * XXX: however, we may not need this part. + */ + if (arp == NULL && arcount > 0) { + int nscount = ntohs(hp->nscount); + + arp = ar_head(cp + n, nscount + ancount - 1, + ansbuf, eom, pvt, name_ok); + } + + /* recursively collect the whole A6 chain */ + ai = *pai; /* XXX: we can't override constant pai */ + ai.ai_family = AF_INET6; + memset(&in6, 0, sizeof(in6)); /* just for safety */ + cur->ai_next = a6_expand(ansbuf, cp, n, arp, eom, + &in6, 128, + (const struct addrinfo *)&ai, + pvt, name_ok, &error); + if (error != NETDB_SUCCESS) { +#ifdef DEBUG + /* in this case, cur->ai_next must be NULL. */ + if (cur->ai_next != NULL) + abort(); +#endif + had_error++; + continue; + } + + /* + * We don't bother even if cur->ai_next is NULL unless + * the expansion failed by a fatal error. The list + * can be NULL if the given A6 is incomplete, but we + * may have another complete A6 chain in this answer. + * See the last paragraph of RFC 2874 Section 3.1.4. + */ + if (cur->ai_next == NULL) { + cp += n; + continue; /* no error, no answer */ + } + goto convertinfo; + } /* FALLTHROUGH */ case T_A: case T_AAAA: - if (ns_samename(pvt->host.h_name, bp) != 1) { + if (ns_samename(hname, bp) != 1) { cp += n; continue; } - if (n != pvt->host.h_length) { + if (type == T_A && n != INADDRSZ) { cp += n; continue; } + if (type == T_AAAA && n != IN6ADDRSZ) { + cp += n; + continue; + } + + /* make addrinfo. don't overwrite constant PAI */ + ai = *pai; + ai.ai_family = (type == T_AAAA) ? AF_INET6 : AF_INET; + cur->ai_next = addr2addrinfo( + (const struct addrinfo *)&ai, + (const char *)cp); + if (cur->ai_next == NULL) + had_error++; + + convertinfo: /* convert addrinfo into hostent form */ if (!haveanswer) { int nn; @@ -580,34 +1395,44 @@ gethostans(struct irs_ho *this, continue; } pvt->host.h_name = bp; + hname = bp; bp += nn; buflen -= nn; } /* Ensure alignment. */ - bp += sizeof(align) - ((u_long)bp % sizeof(align)); + bp = (char *)(((u_long)bp + (sizeof(align) - 1)) & + ~(sizeof(align) - 1)); /* Avoid overflows. */ if (bp + n >= &pvt->hostbuf[sizeof pvt->hostbuf]) { had_error++; continue; } - if (hap >= &pvt->h_addr_ptrs[MAXADDRS-1]) { - cp += n; - continue; + if (ret_aip) { /* need addrinfo. keep it. */ + while (cur && cur->ai_next) + cur = cur->ai_next; + } else if (cur->ai_next) { /* need hostent */ + struct addrinfo *aip = cur->ai_next; + + for (aip = cur->ai_next; aip; + aip = aip->ai_next) { + int m; + + m = add_hostent(pvt, bp, hap, aip); + if (m < 0) { + had_error++; + break; + } + if (m == 0) + continue; + if (hap < &pvt->h_addr_ptrs[MAXADDRS-1]) + hap++; + + bp += m; + } + + freeaddrinfo(cur->ai_next); + cur->ai_next = NULL; } - /* Suppress duplicates. */ - for (tap = (const char **)pvt->h_addr_ptrs; - *tap != NULL; - tap++) - if (memcmp(*tap, cp, n) == 0) - break; - if (*tap != NULL) { - cp += n; - continue; - } - /* Store address. */ - memcpy(*hap++ = bp, cp, n); - *hap = NULL; - bp += n; cp += n; break; default: @@ -617,27 +1442,94 @@ gethostans(struct irs_ho *this, haveanswer++; } if (haveanswer) { - *ap = NULL; + if (ret_aip == NULL) { + *ap = NULL; + *hap = NULL; - if (pvt->res->nsort && haveanswer > 1 && qtype == T_A) - addrsort(pvt->res, pvt->h_addr_ptrs, haveanswer); - if (!pvt->host.h_name) { - n = strlen(qname) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) - goto no_recovery; - strcpy(bp, qname); - pvt->host.h_name = bp; - bp += n; - buflen -= n; + if (pvt->res->nsort && haveanswer > 1 && qtype == T_A) + addrsort(pvt->res, pvt->h_addr_ptrs, + haveanswer); + if (pvt->host.h_name == NULL) { + n = strlen(qname) + 1; /* for the \0 */ + if (n > buflen || n >= MAXHOSTNAMELEN) + goto no_recovery; + strcpy(bp, qname); + pvt->host.h_name = bp; + bp += n; + buflen -= n; + } + if (pvt->res->options & RES_USE_INET6) + map_v4v6_hostent(&pvt->host, &bp, &buflen); + RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS); + return (&pvt->host); + } else { + if ((pai->ai_flags & AI_CANONNAME) != 0) { + if (pvt->host.h_name == NULL) { + sentinel.ai_next->ai_canonname = + strdup(qname); + } + else { + sentinel.ai_next->ai_canonname = + strdup(pvt->host.h_name); + } + } + *ret_aip = sentinel.ai_next; + return(NULL); } - if (pvt->res->options & RES_USE_INET6) - map_v4v6_hostent(&pvt->host, &bp, &buflen); - RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS); - return (&pvt->host); } no_recovery: - RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); - return (NULL); + if (sentinel.ai_next) { + /* this should be impossible, but check it for safety */ + freeaddrinfo(sentinel.ai_next); + } + if (error == NETDB_SUCCESS) + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); + else + RES_SET_H_ERRNO(pvt->res, error); + return(NULL); +} + +static int +add_hostent(struct pvt *pvt, char *bp, char **hap, struct addrinfo *ai) +{ + int addrlen; + char *addrp; + const char **tap; + char *obp = bp; + + switch(ai->ai_addr->sa_family) { + case AF_INET6: + addrlen = IN6ADDRSZ; + addrp = (char *)&((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; + break; + case AF_INET: + addrlen = INADDRSZ; + addrp = (char *)&((struct sockaddr_in *)ai->ai_addr)->sin_addr; + break; + default: + return(-1); /* abort? */ + } + + /* Ensure alignment. */ + bp = (char *)(((u_long)bp + (sizeof(align) - 1)) & + ~(sizeof(align) - 1)); + /* Avoid overflows. */ + if (bp + addrlen >= &pvt->hostbuf[sizeof pvt->hostbuf]) + return(-1); + if (hap >= &pvt->h_addr_ptrs[MAXADDRS-1]) + return(0); /* fail, but not treat it as an error. */ + + /* Suppress duplicates. */ + for (tap = (const char **)pvt->h_addr_ptrs; + *tap != NULL; + tap++) + if (memcmp(*tap, addrp, addrlen) == 0) + break; + if (*tap != NULL) + return (0); + + memcpy(*hap = bp, addrp, addrlen); + return((bp + addrlen) - obp); } static void @@ -649,7 +1541,10 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp) { hp->h_addrtype = AF_INET6; hp->h_length = IN6ADDRSZ; for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); + int i = (u_long)*bpp % sizeof(align); + + if (i != 0) + i = sizeof(align) - i; if (*lenp < (i + IN6ADDRSZ)) { /* Out of memory. Truncate address list here. */ diff --git a/contrib/bind/lib/irs/dns_nw.c b/contrib/bind/lib/irs/dns_nw.c index 66ef66489444..8e0e965397c5 100644 --- a/contrib/bind/lib/irs/dns_nw.c +++ b/contrib/bind/lib/irs/dns_nw.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_nw.c,v 1.19 1999/10/15 19:49:10 vixie Exp $"; +static const char rcsid[] = "$Id: dns_nw.c,v 1.21 2001/11/30 00:36:53 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -56,11 +56,7 @@ static const char rcsid[] = "$Id: dns_nw.c,v 1.19 1999/10/15 19:49:10 vixie Exp #define MAXALIASES 35 -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) struct pvt { struct nwent net; @@ -109,6 +105,8 @@ irs_dns_nw(struct irs_acc *this) { struct irs_nw *nw; struct pvt *pvt; + UNUSED(this); + if (!(pvt = memget(sizeof *pvt))) { errno = ENOMEM; return (NULL); @@ -185,11 +183,15 @@ nw_byaddr(struct irs_nw *this, void *net, int len, int af) { static struct nwent * nw_next(struct irs_nw *this) { + + UNUSED(this); + return (NULL); } static void nw_rewind(struct irs_nw *this) { + UNUSED(this); /* NOOP */ } @@ -539,7 +541,7 @@ normalize_name(char *name) { /* Make lower case. */ for (t = name; *t; t++) - if (isascii(*t) && isupper(*t)) + if (isascii((unsigned char)*t) && isupper((unsigned char)*t)) *t = tolower(*t); /* Remove trailing dots. */ diff --git a/contrib/bind/lib/irs/dns_pr.c b/contrib/bind/lib/irs/dns_pr.c index 77c6a93754ef..64de35a75f8e 100644 --- a/contrib/bind/lib/irs/dns_pr.c +++ b/contrib/bind/lib/irs/dns_pr.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_pr.c,v 1.14 1999/09/04 22:06:14 vixie Exp $"; +static const char rcsid[] = "$Id: dns_pr.c,v 1.15 2001/05/29 05:48:31 marka Exp $"; #endif /* Imports */ @@ -152,17 +152,20 @@ pr_bynumber(struct irs_pr *this, int num) { static struct protoent * pr_next(struct irs_pr *this) { + UNUSED(this); errno = ENODEV; return (NULL); } static void pr_rewind(struct irs_pr *this) { + UNUSED(this); /* NOOP */ } static void pr_minimize(struct irs_pr *this) { + UNUSED(this); /* NOOP */ } @@ -201,7 +204,7 @@ parse_hes_list(struct irs_pr *this, char **hes_list) { /* Skip blank lines. */ p = cp; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (!*p) continue; @@ -213,14 +216,14 @@ parse_hes_list(struct irs_pr *this, char **hes_list) { p = pvt->prbuf; pvt->proto.p_name = p; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (!*p) continue; *p++ = '\0'; pvt->proto.p_proto = atoi(p); - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (*p) *p++ = '\0'; @@ -237,7 +240,7 @@ parse_hes_list(struct irs_pr *this, char **hes_list) { pvt->proto.p_aliases = new; } pvt->proto.p_aliases[num++] = p; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (*p) *p++ = '\0'; diff --git a/contrib/bind/lib/irs/dns_pw.c b/contrib/bind/lib/irs/dns_pw.c index 5344c6e39b5d..b3f7e056875f 100644 --- a/contrib/bind/lib/irs/dns_pw.c +++ b/contrib/bind/lib/irs/dns_pw.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_pw.c,v 1.18 1999/09/04 22:06:14 vixie Exp $"; +static const char rcsid[] = "$Id: dns_pw.c,v 1.19 2001/05/29 05:48:32 marka Exp $"; #endif #include "port_before.h" @@ -133,17 +133,20 @@ pw_byuid(struct irs_pw *this, uid_t uid) { static struct passwd * pw_next(struct irs_pw *this) { + UNUSED(this); errno = ENODEV; return (NULL); } static void pw_rewind(struct irs_pw *this) { + UNUSED(this); /* NOOP */ } static void pw_minimize(struct irs_pw *this) { + UNUSED(this); /* NOOP */ } diff --git a/contrib/bind/lib/irs/dns_sv.c b/contrib/bind/lib/irs/dns_sv.c index e6cb2df3b2aa..b3244a74840e 100644 --- a/contrib/bind/lib/irs/dns_sv.c +++ b/contrib/bind/lib/irs/dns_sv.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_sv.c,v 1.19 2000/03/30 22:53:56 vixie Exp $"; +static const char rcsid[] = "$Id: dns_sv.c,v 1.20 2001/05/29 05:48:33 marka Exp $"; #endif /* Imports */ @@ -66,10 +66,12 @@ static struct servent * sv_byport(struct irs_sv *, int, const char *); static struct servent * sv_next(struct irs_sv *); static void sv_rewind(struct irs_sv *); static void sv_minimize(struct irs_sv *); +#ifdef SV_RES_SETGET static struct __res_state * sv_res_get(struct irs_sv *); static void sv_res_set(struct irs_sv *, struct __res_state *, void (*)(void *)); +#endif static struct servent * parse_hes_list(struct irs_sv *, char **, const char *); @@ -105,8 +107,13 @@ irs_dns_sv(struct irs_acc *this) { sv->rewind = sv_rewind; sv->close = sv_close; sv->minimize = sv_minimize; +#ifdef SV_RES_SETGET + sv->res_get = sv_res_get; + sv->res_set = sv_res_set; +#else sv->res_get = NULL; /* sv_res_get; */ sv->res_set = NULL; /* sv_res_set; */ +#endif return (sv); } @@ -161,12 +168,14 @@ sv_byport(struct irs_sv *this, int port, const char *proto) { static struct servent * sv_next(struct irs_sv *this) { + UNUSED(this); errno = ENODEV; return (NULL); } static void sv_rewind(struct irs_sv *this) { + UNUSED(this); /* NOOP */ } @@ -189,7 +198,7 @@ parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) { /* Check to make sure the protocol matches. */ p = cp; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (!*p) continue; @@ -197,7 +206,7 @@ parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) { proto_len = strlen(proto); if (strncasecmp(++p, proto, proto_len) != 0) continue; - if (p[proto_len] && !isspace(p[proto_len])) + if (p[proto_len] && !isspace(p[proto_len]&0xff)) continue; } /* OK, we've got a live one. Let's parse it for real. */ @@ -207,21 +216,21 @@ parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) { p = pvt->svbuf; pvt->serv.s_name = p; - while (*p && !isspace(*p)) + while (*p && !isspace(*p&0xff)) p++; if (!*p) continue; *p++ = '\0'; pvt->serv.s_proto = p; - while (*p && !isspace(*p)) + while (*p && !isspace(*p&0xff)) p++; if (!*p) continue; *p++ = '\0'; pvt->serv.s_port = htons((u_short) atoi(p)); - while (*p && !isspace(*p)) + while (*p && !isspace(*p&0xff)) p++; if (*p) *p++ = '\0'; @@ -238,7 +247,7 @@ parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) { pvt->serv.s_aliases = new; } pvt->serv.s_aliases[num++] = p; - while (*p && !isspace(*p)) + while (*p && !isspace(*p&0xff)) p++; if (*p) *p++ = '\0'; @@ -265,9 +274,11 @@ parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) { static void sv_minimize(struct irs_sv *this) { + UNUSED(this); /* NOOP */ } +#ifdef SV_RES_SETGET static struct __res_state * sv_res_get(struct irs_sv *this) { struct pvt *pvt = (struct pvt *)this->private; @@ -284,3 +295,4 @@ sv_res_set(struct irs_sv *this, struct __res_state * res, __hesiod_res_set(dns->hes_ctx, res, free_res); } +#endif diff --git a/contrib/bind/lib/irs/gai_strerror.c b/contrib/bind/lib/irs/gai_strerror.c index f56c6f544a71..c487e6855159 100644 --- a/contrib/bind/lib/irs/gai_strerror.c +++ b/contrib/bind/lib/irs/gai_strerror.c @@ -1,45 +1,86 @@ /* -%%% copyright-cmetz-97 -This software is Copyright 1997-1998 by Craig Metz, All Rights Reserved. -The Inner Net License Version 2 applies to this software. -You should have received a copy of the license with this software. If -you didn't get a copy, you may request one from . - -*/ + * Copyright (c) 2001 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ #include #include -#include #include -char * -gai_strerror(int errnum) { - switch(errnum) { - case 0: - return "no error"; - case EAI_BADFLAGS: - return "invalid value for ai_flags"; - case EAI_NONAME: - return "name or service is not known"; - case EAI_AGAIN: - return "temporary failure in name resolution"; - case EAI_FAIL: - return "non-recoverable failure in name resolution"; - case EAI_NODATA: - return "no address associated with name"; - case EAI_FAMILY: - return "ai_family not supported"; - case EAI_SOCKTYPE: - return "ai_socktype not supported"; - case EAI_SERVICE: - return "service not supported for ai_socktype"; - case EAI_ADDRFAMILY: - return "address family for name not supported"; - case EAI_MEMORY: - return "memory allocation failure"; - case EAI_SYSTEM: - return "system error"; - default: - return "unknown error"; - }; +#ifdef DO_PTHREADS +#include +#include +#endif + +static const char *gai_errlist[] = { + "no error", + "address family not supported for name",/* EAI_ADDRFAMILY */ + "temporary failure", /* EAI_AGAIN */ + "invalid flags", /* EAI_BADFLAGS */ + "permanent failure", /* EAI_FAIL */ + "address family not supported", /* EAI_FAMILY */ + "memory failure", /* EAI_MEMORY */ + "no address", /* EAI_NODATA */ + "unknown name or service", /* EAI_NONAME */ + "service not supported for socktype", /* EAI_SERVICE */ + "socktype not supported", /* EAI_SOCKTYPE */ + "system failure", /* EAI_SYSTEM */ + "bad hints", /* EAI_BADHINTS */ + "bad protocol", /* EAI_PROTOCOL */ + + "unknown error" /* Must be last. */ +}; + +static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist)); + +#define EAI_BUFSIZE 128 + +const char * +gai_strerror(int ecode) { +#ifndef DO_PTHREADS + static char buf[EAI_BUFSIZE]; +#else /* DO_PTHREADS */ + static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + static pthread_key_t key; + static int once = 0; + char *buf; +#endif + + if (ecode >= 0 && ecode < (gai_nerr - 1)) + return (gai_errlist[ecode]); + +#ifdef DO_PTHREADS + if (!once) { + pthread_mutex_lock(&lock); + if (!once++) + pthread_key_create(&key, free); + pthread_mutex_unlock(&lock); + } + + buf = pthread_getspecific(key); + if (buf == NULL) { + buf = malloc(EAI_BUFSIZE); + if (buf == NULL) + return ("unknown error"); + pthread_setspecific(key, buf); + } +#endif + /* + * XXX This really should be snprintf(buf, EAI_BUFSIZE, ...). + * It is safe until message catalogs are used. + */ + sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode); + return (buf); } diff --git a/contrib/bind/lib/irs/gen.c b/contrib/bind/lib/irs/gen.c index fe410881595e..5ba7d52a7291 100644 --- a/contrib/bind/lib/irs/gen.c +++ b/contrib/bind/lib/irs/gen.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen.c,v 1.25 1999/10/13 16:39:29 vixie Exp $"; +static const char rcsid[] = "$Id: gen.c,v 1.26 2001/05/29 05:48:35 marka Exp $"; #endif /* @@ -399,7 +399,10 @@ init_map_rules(struct gen_p *irs, const char *conf_file) { char *tmp; int n; - for (tmp = line; isascii(*tmp) && isspace(*tmp); tmp++) + for (tmp = line; + isascii((unsigned char)*tmp) && + isspace((unsigned char)*tmp); + tmp++) (void)NULL; if (*tmp == '#' || *tmp == '\n' || *tmp == '\0') continue; diff --git a/contrib/bind/lib/irs/gen_gr.c b/contrib/bind/lib/irs/gen_gr.c index 14dfa2d4ae3e..4b1b282fe0c8 100644 --- a/contrib/bind/lib/irs/gen_gr.c +++ b/contrib/bind/lib/irs/gen_gr.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_gr.c,v 1.22 2000/07/11 05:51:56 vixie Exp $"; +static const char rcsid[] = "$Id: gen_gr.c,v 1.25 2001/06/07 02:12:26 marka Exp $"; #endif /* Imports */ @@ -324,8 +324,9 @@ gr_res_set(struct irs_gr *this, struct __res_state *res, static void grmerge(struct irs_gr *this, const struct group *src, int preserve) { struct pvt *pvt = (struct pvt *)this->private; - char *cp, **m, **p; - int n, ndst, nnew, memadj; + char *cp, **m, **p, *oldmembuf; + int n, ndst, nnew; + size_t used; if (!preserve) { pvt->group.gr_gid = src->gr_gid; @@ -372,15 +373,25 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { /* No work to do. */ return; } - cp = realloc(pvt->membuf, pvt->membufsize + n); + used = preserve ? pvt->membufsize : 0; + cp = malloc(used + n); if (!cp) { /* No harm done, no work done. */ return; } - memadj = cp - pvt->membuf; + if (used != 0) + memcpy(cp, pvt->membuf, used); + oldmembuf = pvt->membuf; pvt->membuf = cp; - cp += pvt->membufsize; - pvt->membufsize += n; + pvt->membufsize = used + n; + cp += used; + + /* + * Adjust group.gr_mem. + */ + if (pvt->membuf != oldmembuf) + for (m = pvt->group.gr_mem; *m; m++) + *m = pvt->membuf + (*m - oldmembuf); /* * Add new elements. @@ -393,8 +404,10 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { cp += strlen(cp) + 1; } if (preserve) { - pvt->group.gr_name += memadj; - pvt->group.gr_passwd += memadj; + pvt->group.gr_name = pvt->membuf + + (pvt->group.gr_name - oldmembuf); + pvt->group.gr_passwd = pvt->membuf + + (pvt->group.gr_passwd - oldmembuf); } else { pvt->group.gr_name = cp; strcpy(cp, src->gr_name); @@ -403,6 +416,8 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { strcpy(cp, src->gr_passwd); cp += strlen(src->gr_passwd) + 1; } + if (oldmembuf != NULL) + free(oldmembuf); INSIST(cp >= pvt->membuf && cp <= &pvt->membuf[pvt->membufsize]); } diff --git a/contrib/bind/lib/irs/gen_ho.c b/contrib/bind/lib/irs/gen_ho.c index 9e7a4292a55b..12ed7cd075f9 100644 --- a/contrib/bind/lib/irs/gen_ho.c +++ b/contrib/bind/lib/irs/gen_ho.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: gen_ho.c,v 1.15 1999/10/13 16:39:29 vixie Exp $"; +static const char rcsid[] = "$Id: gen_ho.c,v 1.16 2001/05/29 05:48:36 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -68,6 +68,8 @@ static struct __res_state * ho_res_get(struct irs_ho *this); static void ho_res_set(struct irs_ho *this, struct __res_state *res, void (*free_res)(void *)); +static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, + const struct addrinfo *pai); static int init(struct irs_ho *this); @@ -102,6 +104,7 @@ irs_gen_ho(struct irs_acc *this) { ho->minimize = ho_minimize; ho->res_get = ho_res_get; ho->res_set = ho_res_set; + ho->addrinfo = ho_addrinfo; return (ho); } @@ -328,6 +331,51 @@ ho_res_set(struct irs_ho *this, struct __res_state *res, } } +static struct addrinfo * +ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) +{ + struct pvt *pvt = (struct pvt *)this->private; + struct irs_rule *rule; + struct addrinfo *rval = NULL; + struct irs_ho *ho; + int therrno = NETDB_INTERNAL; + int softerror = 0; + + if (init(this) == -1) + return (NULL); + + for (rule = pvt->rules; rule; rule = rule->next) { + ho = rule->inst->ho; + RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL); + errno = 0; + if (ho->addrinfo == NULL) /* for safety */ + continue; + rval = (*ho->addrinfo)(ho, name, pai); + if (rval != NULL) + return (rval); + if (softerror == 0 && + pvt->res->res_h_errno != HOST_NOT_FOUND && + pvt->res->res_h_errno != NETDB_INTERNAL) { + softerror = 1; + therrno = pvt->res->res_h_errno; + } + if (rule->flags & IRS_CONTINUE) + continue; + /* + * See the comments in ho_byname() explaining + * the interpretation of TRY_AGAIN and ECONNREFUSED. + */ + if (pvt->res->res_h_errno != TRY_AGAIN || + errno != ECONNREFUSED) + break; + } + if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND) + RES_SET_H_ERRNO(pvt->res, therrno); + if (rval) + freeaddrinfo(rval); + return (NULL); +} + static int init(struct irs_ho *this) { struct pvt *pvt = (struct pvt *)this->private; diff --git a/contrib/bind/lib/irs/gen_ng.c b/contrib/bind/lib/irs/gen_ng.c index 064d61647508..c28b51076b3b 100644 --- a/contrib/bind/lib/irs/gen_ng.c +++ b/contrib/bind/lib/irs/gen_ng.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_ng.c,v 1.14 1999/10/13 16:39:29 vixie Exp $"; +static const char rcsid[] = "$Id: gen_ng.c,v 1.15 2001/05/29 05:48:38 marka Exp $"; #endif /* Imports */ @@ -52,7 +52,8 @@ struct pvt { /* Forward */ static void ng_close(struct irs_ng *); -static int ng_next(struct irs_ng *, char **, char **, char **); +static int ng_next(struct irs_ng *, const char **, + const char **, const char **); static int ng_test(struct irs_ng *, const char *, const char *, const char *, const char *); @@ -103,7 +104,9 @@ ng_close(struct irs_ng *this) { } static int -ng_next(struct irs_ng *this, char **host, char **user, char **domain) { +ng_next(struct irs_ng *this, const char **host, const char **user, + const char **domain) +{ struct pvt *pvt = (struct pvt *)this->private; struct irs_ng *ng; diff --git a/contrib/bind/lib/irs/gen_p.h b/contrib/bind/lib/irs/gen_p.h index b8210b0af252..35ef4396f29d 100644 --- a/contrib/bind/lib/irs/gen_p.h +++ b/contrib/bind/lib/irs/gen_p.h @@ -16,7 +16,7 @@ */ /* - * $Id: gen_p.h,v 1.10 1999/01/18 07:46:50 vixie Exp $ + * $Id: gen_p.h,v 1.11 2001/05/29 05:48:39 marka Exp $ */ /* Notes: @@ -90,7 +90,7 @@ struct irs_rule { * This is the private data for a search access class. */ struct gen_p { - const char * options; + char * options; struct irs_rule * map_rules[(int)irs_nmap]; struct irs_inst accessors[(int)irs_nacc]; struct __res_state * res; diff --git a/contrib/bind/lib/irs/getaddrinfo.c b/contrib/bind/lib/irs/getaddrinfo.c index f95a68195d61..f2c533d611c5 100644 --- a/contrib/bind/lib/irs/getaddrinfo.c +++ b/contrib/bind/lib/irs/getaddrinfo.c @@ -1,505 +1,1225 @@ -/*- - * Copyright (c) 1997 Berkeley Software Design, Inc. All rights reserved. - * The Berkeley Software Design Inc. software License Agreement specifies - * the terms and conditions for redistribution. - * - * BSDI $Id: getaddrinfo.c,v 8.3 1999/06/11 01:25:58 vixie Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SA(addr) ((struct sockaddr *)(addr)) -#define SIN(addr) ((struct sockaddr_in *)(addr)) -#define SIN6(addr) ((struct sockaddr_in6 *)(addr)) -#define SUN(addr) ((struct sockaddr_un *)(addr)) - -static struct addrinfo - *ai_reverse(struct addrinfo *oai), - *ai_clone(struct addrinfo *oai, int family), - *ai_alloc(int family, int addrlen); -#ifdef AF_LOCAL -static int get_local(const char *name, int socktype, struct addrinfo **res); -#endif - -static int add_ipv4(const char *hostname, int flags, struct addrinfo **aip, - int socktype, int port); -static int add_ipv6(const char *hostname, int flags, struct addrinfo **aip, - int socktype, int port); -static void set_order(int, int (**)()); - -#define FOUND_IPV4 0x1 -#define FOUND_IPV6 0x2 -#define FOUND_MAX 2 - -int -getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res) -{ - struct servent *sp; - char *proto; - int family, socktype, flags, protocol; - struct addrinfo *ai, *ai_list; - int port, err, i; - int (*net_order[FOUND_MAX+1])(); - - if (hostname == NULL && servname == NULL) - return (EAI_NONAME); - - proto = NULL; - if (hints != NULL) { - if (hints->ai_flags & ~(AI_MASK)) - return (EAI_BADFLAGS); - if (hints->ai_addrlen || hints->ai_canonname || - hints->ai_addr || hints->ai_next) { - errno = EINVAL; - return (EAI_SYSTEM); - } - family = hints->ai_family; - socktype = hints->ai_socktype; - protocol = hints->ai_protocol; - flags = hints->ai_flags; - switch (family) { - case AF_UNSPEC: - switch (hints->ai_socktype) { - case SOCK_STREAM: proto = "tcp"; break; - case SOCK_DGRAM: proto = "udp"; break; - } - break; - case AF_INET: - case AF_INET6: - switch (hints->ai_socktype) { - case 0: break; - case SOCK_STREAM: proto = "tcp"; break; - case SOCK_DGRAM: proto = "udp"; break; - case SOCK_RAW: break; - default: return (EAI_SOCKTYPE); - } - break; -#ifdef AF_LOCAL - case AF_LOCAL: - switch (hints->ai_socktype) { - case 0: break; - case SOCK_STREAM: break; - case SOCK_DGRAM: break; - default: return (EAI_SOCKTYPE); - } - break; -#endif - default: - return (EAI_FAMILY); - } - } else { - protocol = 0; - family = 0; - socktype = 0; - flags = 0; - } - -#ifdef AF_LOCAL - /* - * First, deal with AF_LOCAL. If the family was not set, - * then assume AF_LOCAL if the first character of the - * hostname/servname is '/'. - */ - - if (hostname && - (family == AF_LOCAL || (family == 0 && *hostname == '/'))) - return (get_local(hostname, socktype, res)); - - if (servname && - (family == AF_LOCAL || (family == 0 && *servname == '/'))) - return (get_local(servname, socktype, res)); -#endif - - /* - * Ok, only AF_INET and AF_INET6 left. - */ - ai_list = NULL; - - /* - * First, look up the service name (port) if it was - * requested. If the socket type wasn't specified, then - * try and figure it out. - */ - if (servname) { - char *e; - - port = strtol(servname, &e, 10); - if (*e == '\0') { - if (socktype == 0) - return (EAI_SOCKTYPE); - if (port < 0 || port > 65535) - return (EAI_SERVICE); - port = htons(port); - } else { - sp = getservbyname(servname, proto); - if (sp == NULL) - return (EAI_SERVICE); - port = sp->s_port; - if (socktype == 0) { - if (strcmp(sp->s_proto, "tcp")) - socktype = SOCK_STREAM; - else if (strcmp(sp->s_proto, "udp")) - socktype = SOCK_DGRAM; - } - } - } else - port = 0; - - /* - * Next, deal with just a service name, and no hostname. - * (we verified that one of them was non-null up above). - */ - if (hostname == NULL && (flags & AI_PASSIVE) != 0) { - if (family == AF_INET || family == 0) { - ai = ai_alloc(AF_INET, sizeof(struct sockaddr_in)); - if (ai == NULL) - return (EAI_MEMORY); - ai->ai_socktype = socktype; - ai->ai_protocol = protocol; - SIN(ai->ai_addr)->sin_port = port; - ai->ai_next = ai_list; - ai_list = ai; - } - - if (family == AF_INET6 || family == 0) { - ai = ai_alloc(AF_INET6, sizeof(struct sockaddr_in6)); - if (ai == NULL) { - freeaddrinfo(ai_list); - return (EAI_MEMORY); - } - ai->ai_socktype = socktype; - ai->ai_protocol = protocol; - SIN6(ai->ai_addr)->sin6_port = port; - ai->ai_next = ai_list; - ai_list = ai; - } - - *res = ai_list; - return (0); - } - - /* - * If the family isn't specified or AI_NUMERICHOST specified, - * check first to see if it * is a numeric address. - * Though the gethostbyname2() routine - * will recognize numeric addresses, it will only recognize - * the format that it is being called for. Thus, a numeric - * AF_INET address will be treated by the AF_INET6 call as - * a domain name, and vice versa. Checking for both numerics - * here avoids that. - */ - if (hostname != NULL && - (family == 0 || (flags & AI_NUMERICHOST) != 0)) { - char abuf[sizeof(struct in6_addr)]; - char nbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx00")]; - int addrsize, addroff; - - if (inet_aton(hostname, (struct in_addr *)abuf)) { - if (family == AF_INET6) { - /* Convert to a V4 mapped address */ - struct in6_addr *a6 = (struct in6_addr *)abuf; - memcpy(&a6->s6_addr[12], &a6->s6_addr[0], 4); - memset(&a6->s6_addr[10], 0xff, 2); - memset(&a6->s6_addr[0], 0, 10); - goto inet6_addr; - } - addrsize = sizeof(struct in_addr); - addroff = (char *)(&SIN(0)->sin_addr) - (char *)0; - family = AF_INET; - goto common; - - } else if (inet_pton(AF_INET6, hostname, abuf)) { - if (family && family != AF_INET6) - return (EAI_NONAME); - inet6_addr: - addrsize = sizeof(struct in6_addr); - addroff = (char *)(&SIN6(0)->sin6_addr) - (char *)0; - family = AF_INET6; - - common: - if ((ai = ai_clone(ai_list, family)) == NULL) - return (EAI_MEMORY); - ai_list = ai; - ai->ai_socktype = socktype; - SIN(ai->ai_addr)->sin_port = port; - memcpy((char *)ai->ai_addr + addroff, abuf, addrsize); - if (flags & AI_CANONNAME) { - inet_ntop(family, abuf, nbuf, sizeof(nbuf)); - ai->ai_canonname = strdup(nbuf); - } - goto done; - } else if ((flags & AI_NUMERICHOST) != 0){ - return (EAI_NONAME); - } - } - - set_order(family, net_order); - for (i = 0; i < FOUND_MAX; i++) { - if (net_order[i] == NULL) - break; - if ((err = (net_order[i])(hostname, flags, &ai_list, - socktype, port)) != 0) - return(err); - } - - if (ai_list == NULL) - return (EAI_NODATA); - -done: - ai_list = ai_reverse(ai_list); - - *res = ai_list; - return (0); -} - -static void -set_order(family, net_order) - int family; - int (**net_order)(); -{ - char *order, *tok; - int found; - - if (family) { - switch (family) { - case AF_INET: - *net_order++ = add_ipv4; - break; - case AF_INET6: - *net_order++ = add_ipv6; - break; - } - } else { - order = getenv("NET_ORDER"); - found = 0; - while (order != NULL) { - /* We ignore any unknown names. */ - tok = strsep(&order, ":"); - if (strcasecmp(tok, "inet6") == 0) { - if ((found & FOUND_IPV6) == 0) - *net_order++ = add_ipv6; - found |= FOUND_IPV6; - } else if (strcasecmp(tok, "inet") == 0 || - strcasecmp(tok, "inet4") == 0) { - if ((found & FOUND_IPV4) == 0) - *net_order++ = add_ipv4; - found |= FOUND_IPV4; - } - } - - /* Add in anything that we didn't find */ - if ((found & FOUND_IPV4) == 0) - *net_order++ = add_ipv4; - if ((found & FOUND_IPV6) == 0) - *net_order++ = add_ipv6; - } - *net_order = NULL; - return; -} - -static char v4_loop[4] = { 127, 0, 0, 1 }; - -static int -add_ipv4(const char *hostname, int flags, struct addrinfo **aip, - int socktype, int port) -{ - struct addrinfo *ai; - struct hostent *hp; - char **addr; - - if (hostname == NULL && (flags & AI_PASSIVE) == 0) { - if ((ai = ai_clone(*aip, AF_INET)) == NULL) { - freeaddrinfo(*aip); - return(EAI_MEMORY); - } - - *aip = ai; - ai->ai_socktype = socktype; - SIN(ai->ai_addr)->sin_port = port; - memcpy(&SIN(ai->ai_addr)->sin_addr, v4_loop, 4); - } else if ((hp = gethostbyname2(hostname, AF_INET)) != NULL) { - for (addr = hp->h_addr_list; *addr; addr++) { - if ((ai = ai_clone(*aip, hp->h_addrtype)) == NULL) { - freeaddrinfo(*aip); - return(EAI_MEMORY); - } - *aip = ai; - ai->ai_socktype = socktype; - - /* We get IPv6 addresses if RES_USE_INET6 is set */ - if (hp->h_addrtype == AF_INET6) { - SIN6(ai->ai_addr)->sin6_port = port; - memcpy(&SIN6(ai->ai_addr)->sin6_addr, *addr, - hp->h_length); - } else { - SIN(ai->ai_addr)->sin_port = port; - memcpy(&SIN(ai->ai_addr)->sin_addr, *addr, - hp->h_length); - } - if (flags & AI_CANONNAME) - ai->ai_canonname = strdup(hp->h_name); - } - } - return(0); -} - -static char v6_loop[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; - -static int -add_ipv6(const char *hostname, int flags, struct addrinfo **aip, - int socktype, int port) -{ - struct addrinfo *ai; - struct hostent *hp; - char **addr; - - if (hostname == NULL && (flags & AI_PASSIVE) == 0) { - if ((ai = ai_clone(*aip, AF_INET6)) == NULL) { - freeaddrinfo(*aip); - return(EAI_MEMORY); - } - - *aip = ai; - ai->ai_socktype = socktype; - SIN6(ai->ai_addr)->sin6_port = port; - memcpy(&SIN6(ai->ai_addr)->sin6_addr, v6_loop, 16); - } else if ((hp = gethostbyname2(hostname, AF_INET6)) != NULL) { - for (addr = hp->h_addr_list; *addr; addr++) { - if ((ai = ai_clone(*aip, AF_INET6)) == NULL) { - freeaddrinfo(*aip); - return (EAI_MEMORY); - } - *aip = ai; - ai->ai_socktype = socktype; - SIN6(ai->ai_addr)->sin6_port = port; - memcpy(&SIN6(ai->ai_addr)->sin6_addr, *addr, - hp->h_length); - if (flags & AI_CANONNAME) - ai->ai_canonname = strdup(hp->h_name); - } - } - return (0); -} - -void -freeaddrinfo(struct addrinfo *ai) { - struct addrinfo *ai_next; - - while (ai != NULL) { - ai_next = ai->ai_next; - if (ai->ai_addr) - free(ai->ai_addr); - if (ai->ai_canonname) - free(ai->ai_canonname); - free(ai); - ai = ai_next; - } -} - -#ifdef AF_LOCAL -static int -get_local(const char *name, int socktype, struct addrinfo **res) { - struct addrinfo *ai; - struct sockaddr_un *sun; - - if (socktype == 0) - return (EAI_SOCKTYPE); - - if ((ai = ai_alloc(AF_LOCAL, sizeof(*sun))) == NULL) - return (EAI_MEMORY); - - sun = SUN(ai->ai_addr); - strncpy(sun->sun_path, name, sizeof(sun->sun_path)); - - ai->ai_socktype = socktype; - /* - * ai->ai_flags, ai->ai_protocol, ai->ai_canonname, - * and ai->ai_next were initialized to zero. - */ - - *res = ai; - return (0); -} -#endif +/* $KAME: getaddrinfo.c,v 1.14 2001/01/06 09:41:15 jinmei Exp $ */ /* - * Allocate an addrinfo structure, and a sockaddr structure - * of the specificed length. We initialize: - * ai_addrlen - * ai_family - * ai_addr - * ai_addr->sa_family - * ai_addr->sa_len (HAVE_SA_LEN) - * and everything else is initialized to zero. + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project 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 BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ -static struct addrinfo * -ai_alloc(int family, int addrlen) { - struct addrinfo *ai; - if ((ai = (struct addrinfo *)calloc(1, sizeof(*ai))) == NULL) - return (NULL); +/* + * Issues to be discussed: + * - Thread safe-ness must be checked. + * - Return values. There are nonstandard return values defined and used + * in the source code. This is because RFC2553 is silent about which error + * code must be returned for which situation. + * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2 + * says to use inet_aton() to convert IPv4 numeric to binary (allows + * classful form as a result). + * current code - disallow classful form for IPv4 (due to use of inet_pton). + * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is + * invalid. + * current code - SEGV on freeaddrinfo(NULL) + * Note: + * - We use getipnodebyname() just for thread-safeness. There's no intent + * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to + * getipnodebyname(). + * - The code filters out AFs that are not supported by the kernel, + * when globbing NULL hostname (to loopback, or wildcard). Is it the right + * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG + * in ai_flags? + * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. + * (1) what should we do against numeric hostname (2) what should we do + * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? + * non-loopback address configured? global address configured? + * - To avoid search order issue, we have a big amount of code duplicate + * from gethnamaddr.c and some other places. The issues that there's no + * lower layer function to lookup "IPv4 or IPv6" record. Calling + * gethostbyname2 from getaddrinfo will end up in wrong search order, as + * follows: + * - The code makes use of following calls when asked to resolver with + * ai_family = PF_UNSPEC: + * getipnodebyname(host, AF_INET6); + * getipnodebyname(host, AF_INET); + * This will result in the following queries if the node is configure to + * prefer /etc/hosts than DNS: + * lookup /etc/hosts for IPv6 address + * lookup DNS for IPv6 address + * lookup /etc/hosts for IPv4 address + * lookup DNS for IPv4 address + * which may not meet people's requirement. + * The right thing to happen is to have underlying layer which does + * PF_UNSPEC lookup (lookup both) and return chain of addrinfos. + * This would result in a bit of code duplicate with _dns_ghbyname() and + * friends. + */ - if ((ai->ai_addr = SA(calloc(1, addrlen))) == NULL) { - free(ai); - return (NULL); - } - ai->ai_addrlen = addrlen; - ai->ai_family = family; - ai->ai_addr->sa_family = family; -#ifdef HAVE_SA_LEN - ai->ai_addr->sa_len = addrlen; +#include "port_before.h" + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "port_after.h" + +#include "irs_data.h" + +/* + * if we enable it, we will see duplicated addrinfo entries on reply if both + * AAAA and A6 records are found. disable it for default installation. + */ +#undef T_A6 + +#define SUCCESS 0 +#define ANY 0 +#define YES 1 +#define NO 0 + +static const char in_addrany[] = { 0, 0, 0, 0 }; +static const char in6_addrany[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +static const char in_loopback[] = { 127, 0, 0, 1 }; +static const char in6_loopback[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 +}; + +static const struct afd { + int a_af; + int a_addrlen; + int a_socklen; + int a_off; + const char *a_addrany; + const char *a_loopback; + int a_scoped; +} afdl [] = { + {PF_INET6, sizeof(struct in6_addr), + sizeof(struct sockaddr_in6), + offsetof(struct sockaddr_in6, sin6_addr), + in6_addrany, in6_loopback, 1}, + {PF_INET, sizeof(struct in_addr), + sizeof(struct sockaddr_in), + offsetof(struct sockaddr_in, sin_addr), + in_addrany, in_loopback, 0}, + {0, 0, 0, 0, NULL, NULL, 0}, +}; + +struct explore { + int e_af; + int e_socktype; + int e_protocol; + const char *e_protostr; + int e_wild; +#define WILD_AF(ex) ((ex)->e_wild & 0x01) +#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) +#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) +}; + +static const struct explore explore[] = { +#if 0 + { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, #endif - return (ai); + { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, + { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, + { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, + { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, + { -1, 0, 0, NULL, 0 }, +}; + +#define PTON_MAX 16 + +#define MAXPACKET (1024*64) + +typedef union { + HEADER hdr; + u_char buf[MAXPACKET]; +} querybuf; + +static int str_isnumber __P((const char *)); +static int explore_fqdn __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int explore_copy __P((const struct addrinfo *, const struct addrinfo *, + struct addrinfo **)); +static int explore_null __P((const struct addrinfo *, + const char *, struct addrinfo **)); +static int explore_numeric __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int explore_numeric_scope __P((const struct addrinfo *, const char *, + const char *, struct addrinfo **)); +static int get_canonname __P((const struct addrinfo *, + struct addrinfo *, const char *)); +static struct addrinfo *get_ai __P((const struct addrinfo *, + const struct afd *, const char *)); +static struct addrinfo *copy_ai __P((const struct addrinfo *)); +static int get_portmatch __P((const struct addrinfo *, const char *)); +static int get_port __P((const struct addrinfo *, const char *, int)); +static const struct afd *find_afd __P((int)); +static int addrconfig __P((int)); +static int ip6_str2scopeid __P((char *, struct sockaddr_in6 *)); +static struct net_data *init __P((void)); + +struct addrinfo *hostent2addrinfo __P((struct hostent *, + const struct addrinfo *)); +struct addrinfo *addr2addrinfo __P((const struct addrinfo *, + const char *)); + +#if 0 +static const char *ai_errlist[] = { + "Success", + "Address family for hostname not supported", /* EAI_ADDRFAMILY */ + "Temporary failure in name resolution", /* EAI_AGAIN */ + "Invalid value for ai_flags", /* EAI_BADFLAGS */ + "Non-recoverable failure in name resolution", /* EAI_FAIL */ + "ai_family not supported", /* EAI_FAMILY */ + "Memory allocation failure", /* EAI_MEMORY */ + "No address associated with hostname", /* EAI_NODATA */ + "hostname nor servname provided, or not known", /* EAI_NONAME */ + "servname not supported for ai_socktype", /* EAI_SERVICE */ + "ai_socktype not supported", /* EAI_SOCKTYPE */ + "System error returned in errno", /* EAI_SYSTEM */ + "Invalid value for hints", /* EAI_BADHINTS */ + "Resolved protocol is unknown", /* EAI_PROTOCOL */ + "Unknown error", /* EAI_MAX */ +}; +#endif + +/* XXX macros that make external reference is BAD. */ + +#define GET_AI(ai, afd, addr) \ +do { \ + /* external reference: pai, error, and label free */ \ + (ai) = get_ai(pai, (afd), (addr)); \ + if ((ai) == NULL) { \ + error = EAI_MEMORY; \ + goto free; \ + } \ +} while (/*CONSTCOND*/0) + +#define GET_PORT(ai, serv) \ +do { \ + /* external reference: error and label free */ \ + error = get_port((ai), (serv), 0); \ + if (error != 0) \ + goto free; \ +} while (/*CONSTCOND*/0) + +#define GET_CANONNAME(ai, str) \ +do { \ + /* external reference: pai, error and label free */ \ + error = get_canonname(pai, (ai), (str)); \ + if (error != 0) \ + goto free; \ +} while (/*CONSTCOND*/0) + +#define ERR(err) \ +do { \ + /* external reference: error, and label bad */ \ + error = (err); \ + goto bad; \ + /*NOTREACHED*/ \ +} while (/*CONSTCOND*/0) + +#define MATCH_FAMILY(x, y, w) \ + ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) +#define MATCH(x, y, w) \ + ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) + +#if 0 /* bind8 has its own version */ +char * +gai_strerror(ecode) + int ecode; +{ + if (ecode < 0 || ecode > EAI_MAX) + ecode = EAI_MAX; + return ai_errlist[ecode]; +} +#endif + +void +freeaddrinfo(ai) + struct addrinfo *ai; +{ + struct addrinfo *next; + + do { + next = ai->ai_next; + if (ai->ai_canonname) + free(ai->ai_canonname); + /* no need to free(ai->ai_addr) */ + free(ai); + ai = next; + } while (ai); +} + +static int +str_isnumber(p) + const char *p; +{ + char *ep; + + if (*p == '\0') + return NO; + ep = NULL; + (void)strtoul(p, &ep, 10); + if (ep && *ep == '\0') + return YES; + else + return NO; +} + +int +getaddrinfo(hostname, servname, hints, res) + const char *hostname, *servname; + const struct addrinfo *hints; + struct addrinfo **res; +{ + struct addrinfo sentinel; + struct addrinfo *cur; + int error = 0; + struct addrinfo ai, ai0, *afai; + struct addrinfo *pai; + const struct explore *ex; + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + pai = &ai; + pai->ai_flags = 0; + pai->ai_family = PF_UNSPEC; + pai->ai_socktype = ANY; + pai->ai_protocol = ANY; + pai->ai_addrlen = 0; + pai->ai_canonname = NULL; + pai->ai_addr = NULL; + pai->ai_next = NULL; + + if (hostname == NULL && servname == NULL) + return EAI_NONAME; + if (hints) { + /* error check for hints */ + if (hints->ai_addrlen || hints->ai_canonname || + hints->ai_addr || hints->ai_next) + ERR(EAI_BADHINTS); /* xxx */ + if (hints->ai_flags & ~AI_MASK) + ERR(EAI_BADFLAGS); + switch (hints->ai_family) { + case PF_UNSPEC: + case PF_INET: + case PF_INET6: + break; + default: + ERR(EAI_FAMILY); + } + memcpy(pai, hints, sizeof(*pai)); + + /* + * if both socktype/protocol are specified, check if they + * are meaningful combination. + */ + if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) { + for (ex = explore; ex->e_af >= 0; ex++) { + if (pai->ai_family != ex->e_af) + continue; + if (ex->e_socktype == ANY) + continue; + if (ex->e_protocol == ANY) + continue; + if (pai->ai_socktype == ex->e_socktype && + pai->ai_protocol != ex->e_protocol) { + ERR(EAI_BADHINTS); + } + } + } + } + + /* + * post-2553: AI_ALL and AI_V4MAPPED are effective only against + * AF_INET6 query. They needs to be ignored if specified in other + * occassions. + */ + switch (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) { + case AI_V4MAPPED: + case AI_ALL | AI_V4MAPPED: + if (pai->ai_family != AF_INET6) + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); + break; + case AI_ALL: +#if 1 + /* illegal */ + ERR(EAI_BADFLAGS); +#else + pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); + break; +#endif + } + + /* + * check for special cases. (1) numeric servname is disallowed if + * socktype/protocol are left unspecified. (2) servname is disallowed + * for raw and other inet{,6} sockets. + */ + if (MATCH_FAMILY(pai->ai_family, PF_INET, 1) +#ifdef PF_INET6 + || MATCH_FAMILY(pai->ai_family, PF_INET6, 1) +#endif + ) { + ai0 = *pai; /* backup *pai */ + + if (pai->ai_family == PF_UNSPEC) { +#ifdef PF_INET6 + pai->ai_family = PF_INET6; +#else + pai->ai_family = PF_INET; +#endif + } + error = get_portmatch(pai, servname); + if (error) + ERR(error); + + *pai = ai0; + } + + ai0 = *pai; + + /* NULL hostname, or numeric hostname */ + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; + + if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) + continue; + if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex))) + continue; + if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) + continue; + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + continue; + + if (hostname == NULL) { + /* + * filter out AFs that are not supported by the kernel + * XXX errno? + */ + if (!addrconfig(pai->ai_family)) + continue; + error = explore_null(pai, servname, &cur->ai_next); + } else + error = explore_numeric_scope(pai, hostname, servname, + &cur->ai_next); + + if (error) + goto free; + + while (cur && cur->ai_next) + cur = cur->ai_next; + } + + /* + * XXX + * If numreic representation of AF1 can be interpreted as FQDN + * representation of AF2, we need to think again about the code below. + */ + if (sentinel.ai_next) + goto good; + + if (pai->ai_flags & AI_NUMERICHOST) + ERR(EAI_NONAME); + if (hostname == NULL) + ERR(EAI_NONAME); + + /* + * hostname as alphabetical name. + * We'll make sure that + * - if returning addrinfo list is empty, return non-zero error + * value (already known one or EAI_NONAME). + * - otherwise, + * + if we haven't had any errors, return 0 (i.e. success). + * + if we've had an error, free the list and return the error. + * without any assumption on the behavior of explore_fqdn(). + */ + + /* first, try to query DNS for all possible address families. */ + *pai = ai0; + error = explore_fqdn(pai, hostname, servname, &afai); + if (error) { + if (afai != NULL) + freeaddrinfo(afai); + goto free; + } + if (afai == NULL) { + error = EAI_NONAME; /* we've had no errors. */ + goto free; + } + + /* + * we would like to prefer AF_INET6 than AF_INET, so we'll make an + * outer loop by AFs. + */ + for (ex = explore; ex->e_af >= 0; ex++) { + *pai = ai0; + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + + if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) + continue; + if (!MATCH(pai->ai_socktype, ex->e_socktype, + WILD_SOCKTYPE(ex))) { + continue; + } + if (!MATCH(pai->ai_protocol, ex->e_protocol, + WILD_PROTOCOL(ex))) { + continue; + } + +#ifdef AI_ADDRCONFIG + /* + * If AI_ADDRCONFIG is specified, check if we are + * expected to return the address family or not. + */ + if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && + !addrconfig(pai->ai_family)) + continue; +#endif + + if (pai->ai_family == PF_UNSPEC) + pai->ai_family = ex->e_af; + if (pai->ai_socktype == ANY && ex->e_socktype != ANY) + pai->ai_socktype = ex->e_socktype; + if (pai->ai_protocol == ANY && ex->e_protocol != ANY) + pai->ai_protocol = ex->e_protocol; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + continue; + + if ((error = explore_copy(pai, afai, &cur->ai_next)) != 0) { + freeaddrinfo(afai); + goto free; + } + + while (cur && cur->ai_next) + cur = cur->ai_next; + } + + freeaddrinfo(afai); /* afai must not be NULL at this point. */ + + /* we must not have got any errors. */ + if (error != 0) /* just for diagnosis */ + abort(); + + if (sentinel.ai_next) { +good: + *res = sentinel.ai_next; + return(SUCCESS); + } else { + /* + * All the process succeeded, but we've had an empty list. + * This can happen if the given hints do not match our + * candidates. + */ + error = EAI_NONAME; + } + +free: +bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + *res = NULL; + return(error); +} + +/* + * FQDN hostname, DNS lookup + */ +static int +explore_fqdn(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + struct addrinfo *result; + struct addrinfo *cur; + struct net_data *net_data = init(); + struct irs_ho *ho; + int error = 0; + char tmp[NS_MAXDNAME]; + const char *cp; + + result = NULL; + + /* + * if the servname does not match socktype/protocol, ignore it. + */ + if (get_portmatch(pai, servname) != 0) + return(0); + + if (!net_data || !(ho = net_data->ho)) + return(0); +#if 0 /* XXX (notyet) */ + if (net_data->ho_stayopen && net_data->ho_last && + net_data->ho_last->h_addrtype == af) { + if (ns_samename(name, net_data->ho_last->h_name) == 1) + return (net_data->ho_last); + for (hap = net_data->ho_last->h_aliases; hap && *hap; hap++) + if (ns_samename(name, *hap) == 1) + return (net_data->ho_last); + } +#endif + if (!strchr(hostname, '.') && + (cp = res_hostalias(net_data->res, hostname, + tmp, sizeof(tmp)))) + hostname = cp; + result = (*ho->addrinfo)(ho, hostname, pai); + if (!net_data->ho_stayopen) { + (*ho->minimize)(ho); + } + if (result == NULL) { + int e = h_errno; + + switch(e) { + case NETDB_INTERNAL: + error = EAI_SYSTEM; + break; + case TRY_AGAIN: + error = EAI_AGAIN; + break; + case NO_RECOVERY: + error = EAI_FAIL; + break; + case HOST_NOT_FOUND: + case NO_DATA: + error = EAI_NONAME; + break; + default: + case NETDB_SUCCESS: /* should be impossible... */ + error = EAI_NONAME; + break; + } + goto free; + } + + for (cur = result; cur; cur = cur->ai_next) { + GET_PORT(cur, servname); /* XXX: redundant lookups... */ + /* canonname should already be filled. */ + } + + *res = result; + + return(0); + +free: + if (result) + freeaddrinfo(result); + return error; +} + +static int +explore_copy(pai, src0, res) + const struct addrinfo *pai; /* seed */ + const struct addrinfo *src0; /* source */ + struct addrinfo **res; +{ + int error; + struct addrinfo sentinel, *cur; + const struct addrinfo *src; + + error = 0; + sentinel.ai_next = NULL; + cur = &sentinel; + + for (src = src0; src != NULL; src = src->ai_next) { + if (src->ai_family != pai->ai_family) + continue; + + cur->ai_next = copy_ai(src); + if (!cur->ai_next) { + error = EAI_MEMORY; + goto fail; + } + + cur->ai_next->ai_socktype = pai->ai_socktype; + cur->ai_next->ai_protocol = pai->ai_protocol; + cur = cur->ai_next; + } + + *res = sentinel.ai_next; + return 0; + +fail: + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * hostname == NULL. + * passive socket -> anyaddr (0.0.0.0 or ::) + * non-passive socket -> localhost (127.0.0.1 or ::1) + */ +static int +explore_null(pai, servname, res) + const struct addrinfo *pai; + const char *servname; + struct addrinfo **res; +{ + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + if (pai->ai_flags & AI_PASSIVE) { + GET_AI(cur->ai_next, afd, afd->a_addrany); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "anyaddr"); + */ + GET_PORT(cur->ai_next, servname); + } else { + GET_AI(cur->ai_next, afd, afd->a_loopback); + /* xxx meaningless? + * GET_CANONNAME(cur->ai_next, "localhost"); + */ + GET_PORT(cur->ai_next, servname); + } + cur = cur->ai_next; + + *res = sentinel.ai_next; + return 0; + +free: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * numeric hostname + */ +static int +explore_numeric(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ + const struct afd *afd; + struct addrinfo *cur; + struct addrinfo sentinel; + int error; + char pton[PTON_MAX]; + + *res = NULL; + sentinel.ai_next = NULL; + cur = &sentinel; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + switch (afd->a_af) { +#if 0 /*X/Open spec*/ + case AF_INET: + if (inet_aton(hostname, (struct in_addr *)pton) == 1) { + if (pai->ai_family == afd->a_af || + pai->ai_family == PF_UNSPEC /*?*/) { + GET_AI(cur->ai_next, afd, pton); + GET_PORT(cur->ai_next, servname); + while (cur && cur->ai_next) + cur = cur->ai_next; + } else + ERR(EAI_FAMILY); /*xxx*/ + } + break; +#endif + default: + if (inet_pton(afd->a_af, hostname, pton) == 1) { + if (pai->ai_family == afd->a_af || + pai->ai_family == PF_UNSPEC /*?*/) { + GET_AI(cur->ai_next, afd, pton); + GET_PORT(cur->ai_next, servname); + while (cur && cur->ai_next) + cur = cur->ai_next; + } else + ERR(EAI_FAMILY); /*xxx*/ + } + break; + } + + *res = sentinel.ai_next; + return 0; + +free: +bad: + if (sentinel.ai_next) + freeaddrinfo(sentinel.ai_next); + return error; +} + +/* + * numeric hostname with scope + */ +static int +explore_numeric_scope(pai, hostname, servname, res) + const struct addrinfo *pai; + const char *hostname; + const char *servname; + struct addrinfo **res; +{ +#ifndef SCOPE_DELIMITER + return explore_numeric(pai, hostname, servname, res); +#else + const struct afd *afd; + struct addrinfo *cur; + int error; + char *cp, *hostname2 = NULL, *scope, *addr; + struct sockaddr_in6 *sin6; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return 0; + + if (!afd->a_scoped) + return explore_numeric(pai, hostname, servname, res); + + cp = strchr(hostname, SCOPE_DELIMITER); + if (cp == NULL) + return explore_numeric(pai, hostname, servname, res); + + /* + * Handle special case of + */ + hostname2 = strdup(hostname); + if (hostname2 == NULL) + return EAI_MEMORY; + /* terminate at the delimiter */ + hostname2[cp - hostname] = '\0'; + addr = hostname2; + scope = cp + 1; + + error = explore_numeric(pai, addr, servname, res); + if (error == 0) { + int scopeid; + + for (cur = *res; cur; cur = cur->ai_next) { + if (cur->ai_family != AF_INET6) + continue; + sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr; + if ((scopeid = ip6_str2scopeid(scope, sin6)) == -1) { + free(hostname2); + return(EAI_NONAME); /* XXX: is return OK? */ + } +#ifdef HAVE_SIN6_SCOPE_ID + sin6->sin6_scope_id = scopeid; +#endif + } + } + + free(hostname2); + + return error; +#endif +} + +static int +get_canonname(pai, ai, str) + const struct addrinfo *pai; + struct addrinfo *ai; + const char *str; +{ + if ((pai->ai_flags & AI_CANONNAME) != 0) { + ai->ai_canonname = (char *)malloc(strlen(str) + 1); + if (ai->ai_canonname == NULL) + return EAI_MEMORY; + strcpy(ai->ai_canonname, str); + } + return 0; } static struct addrinfo * -ai_clone(struct addrinfo *oai, int family) { +get_ai(pai, afd, addr) + const struct addrinfo *pai; + const struct afd *afd; + const char *addr; +{ + char *p; struct addrinfo *ai; - ai = ai_alloc(family, ((family == AF_INET6) ? - sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))); + ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) + + (afd->a_socklen)); + if (ai == NULL) + return NULL; - if (ai == NULL) { - freeaddrinfo(oai); - return (NULL); - } - if (oai == NULL) - return (ai); - - ai->ai_flags = oai->ai_flags; - ai->ai_socktype = oai->ai_socktype; - ai->ai_protocol = oai->ai_protocol; - ai->ai_canonname = NULL; - ai->ai_next = oai; - return (ai); + memcpy(ai, pai, sizeof(struct addrinfo)); + ai->ai_addr = (struct sockaddr *)(void *)(ai + 1); + memset(ai->ai_addr, 0, (size_t)afd->a_socklen); +#ifdef HAVE_SA_LEN + ai->ai_addr->sa_len = afd->a_socklen; +#endif + ai->ai_addrlen = afd->a_socklen; + ai->ai_addr->sa_family = ai->ai_family = afd->a_af; + p = (char *)(void *)(ai->ai_addr); + memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen); + return ai; } +/* XXX need to malloc() the same way we do from other functions! */ static struct addrinfo * -ai_reverse(struct addrinfo *oai) { - struct addrinfo *nai, *tai; +copy_ai(pai) + const struct addrinfo *pai; +{ + struct addrinfo *ai; + size_t l; - nai = NULL; + l = sizeof(*ai) + pai->ai_addrlen; + if ((ai = (struct addrinfo *)malloc(l)) == NULL) + return NULL; + memset(ai, 0, l); + memcpy(ai, pai, sizeof(*ai)); + ai->ai_addr = (struct sockaddr *)(void *)(ai + 1); + memcpy(ai->ai_addr, pai->ai_addr, pai->ai_addrlen); - while (oai) { - /* grab one off the old list */ - tai = oai; - oai = oai->ai_next; - /* put it on the front of the new list */ - tai->ai_next = nai; - nai = tai; + if (pai->ai_canonname) { + l = strlen(pai->ai_canonname) + 1; + if ((ai->ai_canonname = malloc(l)) == NULL) { + free(ai); + return NULL; + } +#ifdef HAVE_STRLCPY + strlcpy(ai->ai_canonname, pai->ai_canonname, l); +#else + strncpy(ai->ai_canonname, pai->ai_canonname, l); +#endif + } else { + /* just to make sure */ + ai->ai_canonname = NULL; } - return (nai); + + ai->ai_next = NULL; + + return ai; +} + +static int +get_portmatch(const struct addrinfo *ai, const char *servname) { + + /* get_port does not touch first argument. when matchonly == 1. */ + /* LINTED const cast */ + return get_port((const struct addrinfo *)ai, servname, 1); +} + +static int +get_port(const struct addrinfo *ai, const char *servname, int matchonly) { + const char *proto; + struct servent *sp; + int port; + int allownumeric; + + if (servname == NULL) + return 0; + switch (ai->ai_family) { + case AF_INET: +#ifdef AF_INET6 + case AF_INET6: +#endif + break; + default: + return 0; + } + + switch (ai->ai_socktype) { + case SOCK_RAW: + return EAI_SERVICE; + case SOCK_DGRAM: + case SOCK_STREAM: + allownumeric = 1; + break; + case ANY: + allownumeric = 0; + break; + default: + return EAI_SOCKTYPE; + } + + if (str_isnumber(servname)) { + if (!allownumeric) + return EAI_SERVICE; + port = htons(atoi(servname)); + if (port < 0 || port > 65535) + return EAI_SERVICE; + } else { + switch (ai->ai_socktype) { + case SOCK_DGRAM: + proto = "udp"; + break; + case SOCK_STREAM: + proto = "tcp"; + break; + default: + proto = NULL; + break; + } + + if ((sp = getservbyname(servname, proto)) == NULL) + return EAI_SERVICE; + port = sp->s_port; + } + + if (!matchonly) { + switch (ai->ai_family) { + case AF_INET: + ((struct sockaddr_in *)(void *) + ai->ai_addr)->sin_port = port; + break; + case AF_INET6: + ((struct sockaddr_in6 *)(void *) + ai->ai_addr)->sin6_port = port; + break; + } + } + + return 0; +} + +static const struct afd * +find_afd(af) + int af; +{ + const struct afd *afd; + + if (af == PF_UNSPEC) + return NULL; + for (afd = afdl; afd->a_af; afd++) { + if (afd->a_af == af) + return afd; + } + return NULL; +} + +/* + * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend + * will take care of it. + * the semantics of AI_ADDRCONFIG is not defined well. we are not sure + * if the code is right or not. + */ +static int +addrconfig(af) + int af; +{ + int s; + + /* XXX errno */ + s = socket(af, SOCK_DGRAM, 0); + if (s < 0) { + if (errno != EMFILE) + return 0; + } else + close(s); + return 1; +} + +/* convert a string to a scope identifier. XXX: IPv6 specific */ +static int +ip6_str2scopeid(scope, sin6) + char *scope; + struct sockaddr_in6 *sin6; +{ + int scopeid; + struct in6_addr *a6 = &sin6->sin6_addr; + char *ep; + + /* empty scopeid portion is invalid */ + if (*scope == '\0') + return -1; + +#ifdef USE_IFNAMELINKID + if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) { + /* + * Using interface names as link indices can be allowed + * only when we can assume a one-to-one mappings between + * links and interfaces. See comments in getnameinfo.c. + */ + scopeid = if_nametoindex(scope); + if (scopeid == 0) + goto trynumeric; + return(scopeid); + } +#endif + + /* still unclear about literal, allow numeric only - placeholder */ + if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6)) + goto trynumeric; + if (IN6_IS_ADDR_MC_ORGLOCAL(a6)) + goto trynumeric; + else + goto trynumeric; /* global */ + + /* try to convert to a numeric id as a last resort */ +trynumeric: + scopeid = (int)strtoul(scope, &ep, 10); + if (*ep == '\0') + return scopeid; + else + return -1; +} + +struct addrinfo * +hostent2addrinfo(hp, pai) + struct hostent *hp; + const struct addrinfo *pai; +{ + int i, af, error = 0; + char **aplist = NULL, *ap; + struct addrinfo sentinel, *cur; + const struct afd *afd; + + af = hp->h_addrtype; + if (pai->ai_family != AF_UNSPEC && af != pai->ai_family) + return(NULL); + + afd = find_afd(af); + if (afd == NULL) + return(NULL); + + aplist = hp->h_addr_list; + + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + for (i = 0; (ap = aplist[i]) != NULL; i++) { +#if 0 /* the trick seems too much */ + af = hp->h_addr_list; + if (af == AF_INET6 && + IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ap)) { + af = AF_INET; + ap = ap + sizeof(struct in6_addr) + - sizeof(struct in_addr); + } + afd = find_afd(af); + if (afd == NULL) + continue; +#endif /* 0 */ + + GET_AI(cur->ai_next, afd, ap); + + /* GET_PORT(cur->ai_next, servname); */ + if ((pai->ai_flags & AI_CANONNAME) != 0) { + /* + * RFC2553 says that ai_canonname will be set only for + * the first element. we do it for all the elements, + * just for convenience. + */ + GET_CANONNAME(cur->ai_next, hp->h_name); + } + while (cur && cur->ai_next) /* no need to loop, actually. */ + cur = cur->ai_next; + continue; + + free: + if (cur->ai_next) + freeaddrinfo(cur->ai_next); + cur->ai_next = NULL; + /* continue, without tht pointer CUR advanced. */ + } + + return(sentinel.ai_next); +} + +struct addrinfo * +addr2addrinfo(pai, cp) + const struct addrinfo *pai; + const char *cp; +{ + const struct afd *afd; + + afd = find_afd(pai->ai_family); + if (afd == NULL) + return(NULL); + + return(get_ai(pai, afd, cp)); +} + +static struct net_data * +init() +{ + struct net_data *net_data; + + if (!(net_data = net_data_init(NULL))) + goto error; + if (!net_data->ho) { + net_data->ho = (*net_data->irs->ho_map)(net_data->irs); + if (!net_data->ho || !net_data->res) { +error: + errno = EIO; + if (net_data && net_data->res) + RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL); + return (NULL); + } + + (*net_data->ho->res_set)(net_data->ho, net_data->res, NULL); + } + + return (net_data); } diff --git a/contrib/bind/lib/irs/getgrent.c b/contrib/bind/lib/irs/getgrent.c index 866e8c52cdc2..f6eea13c0081 100644 --- a/contrib/bind/lib/irs/getgrent.c +++ b/contrib/bind/lib/irs/getgrent.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getgrent.c,v 1.19 1999/10/13 16:39:30 vixie Exp $"; +static const char rcsid[] = "$Id: getgrent.c,v 1.20 2001/05/29 05:48:41 marka Exp $"; #endif /* Imports */ @@ -36,6 +36,8 @@ static int __bind_irs_gr_unneeded; #include #include #include +#include +#include #include @@ -80,14 +82,14 @@ setgroupent(int stayopen) { #ifdef SETGRENT_VOID void -setgrent() { +setgrent(void) { struct net_data *net_data = init(); - return (setgrent_p(net_data)); + setgrent_p(net_data); } #else int -setgrent() { +setgrent(void) { struct net_data *net_data = init(); return (setgrent_p(net_data)); @@ -102,7 +104,7 @@ endgrent() { } int -getgrouplist(const char *name, gid_t basegid, gid_t *groups, int *ngroups) { +getgrouplist(GETGROUPLIST_ARGS) { struct net_data *net_data = init(); return (getgrouplist_p(name, basegid, groups, ngroups, net_data)); @@ -142,7 +144,7 @@ getgrgid_p(gid_t gid, struct net_data *net_data) { if (!net_data || !(gr = net_data->gr)) return (NULL); if (net_data->gr_stayopen && net_data->gr_last && - net_data->gr_last->gr_gid == gid) + (gid_t)net_data->gr_last->gr_gid == gid) return (net_data->gr_last); net_data->gr_last = (*gr->bygid)(gr, gid); if (!net_data->gr_stayopen) diff --git a/contrib/bind/lib/irs/getgrent_r.c b/contrib/bind/lib/irs/getgrent_r.c index df055db4fa21..641a2b2faa7f 100644 --- a/contrib/bind/lib/irs/getgrent_r.c +++ b/contrib/bind/lib/irs/getgrent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getgrent_r.c,v 8.4 1999/01/18 07:46:51 vixie Exp $"; +static const char rcsid[] = "$Id: getgrent_r.c,v 8.7 2001/11/01 08:02:08 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,7 +26,17 @@ static const char rcsid[] = "$Id: getgrent_r.c,v 8.4 1999/01/18 07:46:51 vixie E #include #include #include +#include +#if (defined(POSIX_GETGRNAM_R) || defined(POSIX_GETGRGID_R)) && \ + defined(_POSIX_PTHREAD_SEMANTICS) + /* turn off solaris remapping in */ +#define _UNIX95 +#undef _POSIX_PTHREAD_SEMANTICS #include +#define _POSIX_PTHREAD_SEMANTICS 1 +#else +#include +#endif #include #include @@ -50,7 +60,7 @@ getgrnam_r(const char *name, struct group *gptr, if (ge == NULL) { *result = NULL; - return (-1); + return (0); } res = copy_group(ge, gptr, buf, buflen); @@ -75,11 +85,11 @@ getgrnam_r(const char *name, struct group *gptr, /* POSIX 1003.1c */ #ifdef POSIX_GETGRGID_R int -__posix_getgrgid_r(const gid_t gid, struct group *gptr, +__posix_getgrgid_r(gid_t gid, struct group *gptr, char *buf, int buflen, struct group **result) { #else /* POSIX_GETGRGID_R */ int -getgrgid_r(const gid_t gid, struct group *gptr, +getgrgid_r(gid_t gid, struct group *gptr, char *buf, size_t buflen, struct group **result) { #endif /* POSIX_GETGRGID_R */ struct group *ge = getgrgid(gid); @@ -87,7 +97,7 @@ getgrgid_r(const gid_t gid, struct group *gptr, if (ge == NULL) { *result = NULL; - return (-1); + return (0); } res = copy_group(ge, gptr, buf, buflen); @@ -97,7 +107,7 @@ getgrgid_r(const gid_t gid, struct group *gptr, #ifdef POSIX_GETGRGID_R struct group * -getgrgid_r(const gid_t gid, struct group *gptr, +getgrgid_r(gid_t gid, struct group *gptr, char *buf, int buflen) { struct group *ge = getgrgid(gid); int res; @@ -181,7 +191,7 @@ copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) { if (len > buflen) { errno = ERANGE; - return (-1); + return (ERANGE); } /* copy group id */ diff --git a/contrib/bind/lib/irs/gethostent.c b/contrib/bind/lib/irs/gethostent.c index 5aa46c578965..586fa492a372 100644 --- a/contrib/bind/lib/irs/gethostent.c +++ b/contrib/bind/lib/irs/gethostent.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gethostent.c,v 1.28 2001/03/01 05:47:44 marka Exp $"; +static const char rcsid[] = "$Id: gethostent.c,v 1.29 2001/05/29 05:48:44 marka Exp $"; #endif /* Imports */ @@ -215,10 +215,6 @@ endhostent_p(struct net_data *net_data) { (*ho->minimize)(ho); } -#if !defined(HAS_INET6_STRUCTS) || defined(MISSING_IN6ADDR_ANY) -static const struct in6_addr in6addr_any; -#endif - #ifndef IN6_IS_ADDR_V4COMPAT static const unsigned char in6addr_compat[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -299,7 +295,7 @@ getipnodebyname(const char *name, int af, int flags, int *error_num) { char *addr_list[2]; char *aliases[1]; - he.h_name = (char *)name; + DE_CONST(name, he.h_name); he.h_addr_list = addr_list; he.h_addr_list[0] = (v4 == 1) ? (char *)&in4 : (char *)&in6; he.h_addr_list[1] = NULL; @@ -379,8 +375,10 @@ getipnodebyaddr(const void *src, size_t len, int af, int *error_num) { /* * Lookup IPv4 and IPv4 mapped/compatible addresses */ - if ((af == AF_INET6 && IN6_IS_ADDR_V4COMPAT((struct in6_addr *)src)) || - (af == AF_INET6 && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src)) || + if ((af == AF_INET6 && + IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src)) || + (af == AF_INET6 && + IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src)) || (af == AF_INET)) { const char *cp = src; @@ -405,7 +403,7 @@ getipnodebyaddr(const void *src, size_t len, int af, int *error_num) { /* * Lookup IPv6 address. */ - if (memcmp((struct in6_addr *)src, &in6addr_any, 16) == 0) { + if (memcmp((const struct in6_addr *)src, &in6addr_any, 16) == 0) { *error_num = HOST_NOT_FOUND; return (NULL); } @@ -491,7 +489,7 @@ scan_interfaces(int *have_v4, int *have_v6) { struct in_addr in4; struct in6_addr in6; char *buf = NULL, *cp, *cplim; - static int bufsiz = 4095; + static unsigned int bufsiz = 4095; int s, cpsize, n; /* Set to zero. Used as loop terminators below. */ @@ -571,7 +569,7 @@ scan_interfaces(int *have_v4, int *have_v6) { #else cpsize = sizeof lifreq.lifr_name; /* XXX maybe this should be a hard error? */ - if (ioctl(s, SOICGLIFADDR, (char *)&lifreq) < 0) + if (ioctl(s, SIOCGLIFADDR, (char *)&lifreq) < 0) continue; #endif switch (lifreq.lifr_addr.ss_family) { @@ -816,6 +814,7 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { return (NULL); } pvt = net_data->ho_data; +#ifndef __bsdi__ /* * Unlike its forebear(inet_aton), our friendly inet_pton() is strict * in its interpretation of its input, and it will only return "1" if @@ -825,6 +824,15 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { * This means "telnet 0xdeadbeef" and "telnet 127.1" are dead now. */ if (inet_pton(af, name, pvt->addr) != 1) { +#else + /* BSDI XXX + * We put this back to inet_aton -- we really want the old behavior + * Long live 127.1... + */ + if ((af != AF_INET || + inet_aton(name, (struct in_addr *)pvt->addr) != 1) && + inet_pton(af, name, pvt->addr) != 1) { +#endif RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND); return (NULL); } diff --git a/contrib/bind/lib/irs/gethostent_r.c b/contrib/bind/lib/irs/gethostent_r.c index dab8639c8f30..e8017ac96c6e 100644 --- a/contrib/bind/lib/irs/gethostent_r.c +++ b/contrib/bind/lib/irs/gethostent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: gethostent_r.c,v 8.5 2000/07/11 05:46:35 vixie Exp $"; +static const char rcsid[] = "$Id: gethostent_r.c,v 8.7 2001/11/01 08:02:09 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,6 +26,7 @@ static const char rcsid[] = "$Id: gethostent_r.c,v 8.5 2000/07/11 05:46:35 vixie #include #include #include +#include #include #include #include @@ -39,26 +40,50 @@ copy_hostent(struct hostent *, struct hostent *, HOST_R_COPY_ARGS); HOST_R_RETURN gethostbyname_r(const char *name, struct hostent *hptr, HOST_R_ARGS) { struct hostent *he = gethostbyname(name); +#ifdef HOST_R_SETANSWER + int n = 0; +#endif HOST_R_ERRNO; +#ifdef HOST_R_SETANSWER + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + *answerp = NULL; + else + *answerp = hptr; + + return (n); +#else if (he == NULL) return (HOST_R_BAD); return (copy_hostent(he, hptr, HOST_R_COPY)); +#endif } HOST_R_RETURN gethostbyaddr_r(const char *addr, int len, int type, struct hostent *hptr, HOST_R_ARGS) { struct hostent *he = gethostbyaddr(addr, len, type); +#ifdef HOST_R_SETANSWER + int n = 0; +#endif HOST_R_ERRNO; +#ifdef HOST_R_SETANSWER + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + *answerp = NULL; + else + *answerp = hptr; + + return (n); +#else if (he == NULL) return (HOST_R_BAD); return (copy_hostent(he, hptr, HOST_R_COPY)); +#endif } /* @@ -70,13 +95,25 @@ gethostbyaddr_r(const char *addr, int len, int type, HOST_R_RETURN gethostent_r(struct hostent *hptr, HOST_R_ARGS) { struct hostent *he = gethostent(); +#ifdef HOST_R_SETANSWER + int n = 0; +#endif HOST_R_ERRNO; +#ifdef HOST_R_SETANSWER + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + *answerp = NULL; + else + *answerp = hptr; + + return (n); +#else if (he == NULL) return (HOST_R_BAD); return (copy_hostent(he, hptr, HOST_R_COPY)); +#endif } HOST_R_SET_RETURN @@ -96,7 +133,7 @@ HOST_R_END_RETURN #ifdef HOST_R_ENT_ARGS endhostent_r(HOST_R_ENT_ARGS) #else -endhostent_r() +endhostent_r(void) #endif { endhostent(); @@ -222,6 +259,6 @@ copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) { } #endif /* !HOSTENT_DATA */ #else /* HOST_R_RETURN */ - static int gethostent_r_unknown_systemm = 0; + static int gethostent_r_unknown_system = 0; #endif /* HOST_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ diff --git a/contrib/bind/lib/irs/getnameinfo.c b/contrib/bind/lib/irs/getnameinfo.c index 9f186f3522a8..0e86cc152304 100644 --- a/contrib/bind/lib/irs/getnameinfo.c +++ b/contrib/bind/lib/irs/getnameinfo.c @@ -1,8 +1,6 @@ /* * Issues to be discussed: * - Thread safe-ness must be checked - * - Return values. There seems to be no standard for return value (RFC2133) - * but INRIA implementation returns EAI_xxx defined for getaddrinfo(). */ /* @@ -50,14 +48,10 @@ #include #include #include +#include #include -#define SUCCESS 0 -#define ANY 0 -#define YES 1 -#define NO 0 - /* * Note that a_off will be dynamically adjusted so that to be consistent * with the definition of sockaddr_in{,6}. @@ -66,30 +60,30 @@ static struct afd { int a_af; int a_addrlen; - int a_socklen; + size_t a_socklen; int a_off; } afdl [] = { /* first entry is linked last... */ {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), - 4 /*XXX*/}, + offsetof(struct sockaddr_in, sin_addr)}, {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6), - 8 /*XXX*/}, - {0, 0, 0}, + offsetof(struct sockaddr_in6, sin6_addr)}, + {0, 0, 0, 0}, }; struct sockinet { +#ifdef HAVE_SA_LEN u_char si_len; +#endif u_char si_family; u_short si_port; }; -#define ENI_NOSOCKET 0 -#define ENI_NOSERVNAME 1 -#define ENI_NOHOSTNAME 2 -#define ENI_MEMORY 3 -#define ENI_SYSTEM 4 -#define ENI_FAMILY 5 -#define ENI_SALEN 6 +static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *, + size_t, int)); +#ifdef HAVE_SIN6_SCOPE_ID +static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int)); +#endif int getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) @@ -106,82 +100,60 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) struct hostent *hp; u_short port; #ifdef HAVE_SA_LEN - int len; + size_t len; #endif int family, i; - char *addr, *p; + const char *addr; + char *p; u_char pfx; - static int firsttime = 1; - static char numserv[512]; - static char numaddr[512]; - - - /* dynamically adjust a_off */ - if (firsttime) { - struct afd *p; - u_char *q; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - - for (p = &afdl[0]; p->a_af; p++) { - switch (p->a_af) { - case PF_INET: - q = (u_char *)&sin.sin_addr.s_addr; - p->a_off = q - (u_char *)&sin; - break; - case PF_INET6: - q = (u_char *)&sin6.sin6_addr.s6_addr; - p->a_off = q - (u_char *)&sin6; - break; - default: - break; - } - } - firsttime = 0; - } + char numserv[512]; + char numaddr[512]; if (sa == NULL) - return ENI_NOSOCKET; + return EAI_FAIL; #ifdef HAVE_SA_LEN len = sa->sa_len; - if (len != salen) return ENI_SALEN; + if (len != salen) return EAI_FAIL; #endif - + family = sa->sa_family; for (i = 0; afdl[i].a_af; i++) if (afdl[i].a_af == family) { afd = &afdl[i]; goto found; } - return ENI_FAMILY; - + return EAI_FAMILY; + found: - if (salen != afd->a_socklen) return ENI_SALEN; - - port = ((struct sockinet *)sa)->si_port; /* network byte order */ - addr = (char *)sa + afd->a_off; + if (salen != afd->a_socklen) return EAI_FAIL; + + port = ((const struct sockinet *)sa)->si_port; /* network byte order */ + addr = (const char *)sa + afd->a_off; if (serv == NULL || servlen == 0) { - /* what we should do? */ + /* + * rfc2553bis says that serv == NULL or servlen == 0 means that + * the caller does not want the result. + */ } else if (flags & NI_NUMERICSERV) { - snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); + sprintf(numserv, "%d", ntohs(port)); if (strlen(numserv) > servlen) - return ENI_MEMORY; + return EAI_MEMORY; strcpy(serv, numserv); } else { sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp"); if (sp) { if (strlen(sp->s_name) + 1 > servlen) - return ENI_MEMORY; + return EAI_MEMORY; strcpy(serv, sp->s_name); } else - return ENI_NOSERVNAME; + return EAI_NONAME; } switch (sa->sa_family) { case AF_INET: - if (ntohl(*(u_long *)addr) >> IN_CLASSA_NSHIFT == 0) + if (ntohl(*(const u_long *)addr) >> IN_CLASSA_NSHIFT == 0) flags |= NI_NUMERICHOST; break; case AF_INET6: @@ -191,14 +163,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) break; } if (host == NULL || hostlen == 0) { - /* what should we do? */ + /* + * rfc2553bis says that host == NULL or hostlen == 0 means that + * the caller does not want the result. + */ } else if (flags & NI_NUMERICHOST) { - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) - return ENI_SYSTEM; - if (strlen(numaddr) + 1 > hostlen) - return ENI_MEMORY; - strcpy(host, numaddr); + goto numeric; } else { hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); @@ -208,18 +178,130 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) if (p) *p = '\0'; } if (strlen(hp->h_name) + 1 > hostlen) - return ENI_MEMORY; + return EAI_MEMORY; strcpy(host, hp->h_name); } else { if (flags & NI_NAMEREQD) - return ENI_NOHOSTNAME; - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) - return ENI_NOHOSTNAME; - if (strlen(numaddr) + 1 > hostlen) - return ENI_MEMORY; - strcpy(host, numaddr); + return EAI_NONAME; + numeric: + switch(afd->a_af) { + case AF_INET6: + { + int error; + + if ((error = ip6_parsenumeric(sa, addr, host, + hostlen, + flags)) != 0) + return(error); + break; + } + + default: + if (inet_ntop(afd->a_af, addr, numaddr, + sizeof(numaddr)) == NULL) + return EAI_NONAME; + if (strlen(numaddr) + 1 > hostlen) + return EAI_MEMORY; + strcpy(host, numaddr); + } } } - return SUCCESS; + return(0); } + +static int +ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host, + size_t hostlen, int flags) +{ + size_t numaddrlen; + char numaddr[512]; + +#ifndef HAVE_SIN6_SCOPE_ID + UNUSED(sa); + UNUSED(flags); +#endif + + if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) + == NULL) + return EAI_SYSTEM; + + numaddrlen = strlen(numaddr); + if (numaddrlen + 1 > hostlen) /* don't forget terminator */ + return EAI_MEMORY; + strcpy(host, numaddr); + +#ifdef HAVE_SIN6_SCOPE_ID + if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { + char scopebuf[MAXHOSTNAMELEN]; /* XXX */ + int scopelen; + + /* ip6_sa2str never fails */ + scopelen = ip6_sa2str((const struct sockaddr_in6 *)sa, + scopebuf, sizeof(scopebuf), flags); + + if (scopelen + 1 + numaddrlen + 1 > hostlen) + return EAI_MEMORY; + + /* construct */ + memcpy(host + numaddrlen + 1, scopebuf, + scopelen); + host[numaddrlen] = SCOPE_DELIMITER; + host[numaddrlen + 1 + scopelen] = '\0'; + } +#endif + + return 0; +} + +#ifdef HAVE_SIN6_SCOPE_ID +/* ARGSUSED */ +static int +ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, + size_t bufsiz, int flags) +{ +#ifdef USE_IFNAMELINKID + unsigned int ifindex = (unsigned int)sa6->sin6_scope_id; + const struct in6_addr *a6 = &sa6->sin6_addr; +#endif + char tmp[64]; + +#ifdef NI_NUMERICSCOPE + if (flags & NI_NUMERICSCOPE) { + sprintf(tmp, "%u", sa6->sin6_scope_id); + if (bufsiz != 0) { + strncpy(buf, tmp, bufsiz - 1); + buf[bufsiz - 1] = '\0'; + } + return(strlen(tmp)); + } +#endif + +#ifdef USE_IFNAMELINKID + /* + * For a link-local address, convert the index to an interface + * name, assuming a one-to-one mapping between links and interfaces. + * Note, however, that this assumption is stronger than the + * specification of the scoped address architecture; the + * specficication says that more than one interfaces can belong to + * a single link. + */ + + /* if_indextoname() does not take buffer size. not a good api... */ + if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) && + bufsiz >= IF_NAMESIZE) { + char *p = if_indextoname(ifindex, buf); + if (p) { + return(strlen(p)); + } + } +#endif + + /* last resort */ + sprintf(tmp, "%u", sa6->sin6_scope_id); + if (bufsiz != 0) { + strncpy(buf, tmp, bufsiz - 1); + buf[bufsiz - 1] = '\0'; + } + return(strlen(tmp)); +} +#endif diff --git a/contrib/bind/lib/irs/getnetent.c b/contrib/bind/lib/irs/getnetent.c index 52aebe399893..49810b73e65a 100644 --- a/contrib/bind/lib/irs/getnetent.c +++ b/contrib/bind/lib/irs/getnetent.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getnetent.c,v 1.18 2000/12/23 08:14:53 vixie Exp $"; +static const char rcsid[] = "$Id: getnetent.c,v 1.19 2001/05/29 05:48:47 marka Exp $"; #endif /* Imports */ @@ -259,10 +259,11 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL); return (NULL); } - if (!isascii(name[0]) || !isdigit(name[0])) + if (!isascii((unsigned char)(name[0])) || + !isdigit((unsigned char)(name[0]))) return (NULL); for (cp = name; *cp; ++cp) - if (!isascii(*cp) || (!isdigit(*cp) && *cp != '.')) + if (!isascii(*cp) || (!isdigit((unsigned char)*cp) && *cp != '.')) return (NULL); if (*--cp == '.') return (NULL); diff --git a/contrib/bind/lib/irs/getnetent_r.c b/contrib/bind/lib/irs/getnetent_r.c index b78b45a74e34..1472eb550b02 100644 --- a/contrib/bind/lib/irs/getnetent_r.c +++ b/contrib/bind/lib/irs/getnetent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetent_r.c,v 8.4 1999/01/18 07:46:52 vixie Exp $"; +static const char rcsid[] = "$Id: getnetent_r.c,v 8.6 2001/11/01 08:02:11 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,6 +26,7 @@ static const char rcsid[] = "$Id: getnetent_r.c,v 8.4 1999/01/18 07:46:52 vixie #include #include #include +#include #include #include #include @@ -39,11 +40,22 @@ copy_netent(struct netent *, struct netent *, NET_R_COPY_ARGS); NET_R_RETURN getnetbyname_r(const char *name, struct netent *nptr, NET_R_ARGS) { struct netent *ne = getnetbyname(name); +#ifdef NET_R_SETANSWER + int n = 0; + if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = ne; + if (ne == NULL) + *h_errnop = h_errno; + return (n); +#else if (ne == NULL) return (NET_R_BAD); return (copy_netent(ne, nptr, NET_R_COPY)); +#endif } #ifndef GETNETBYADDR_ADDR_T @@ -52,11 +64,23 @@ getnetbyname_r(const char *name, struct netent *nptr, NET_R_ARGS) { NET_R_RETURN getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_ARGS) { struct netent *ne = getnetbyaddr(addr, type); +#ifdef NET_R_SETANSWER + int n = 0; + + if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = ne; + if (ne == NULL) + *h_errnop = h_errno; + return (n); +#else if (ne == NULL) return (NET_R_BAD); return (copy_netent(ne, nptr, NET_R_COPY)); +#endif } /* @@ -68,11 +92,23 @@ getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_AR NET_R_RETURN getnetent_r(struct netent *nptr, NET_R_ARGS) { struct netent *ne = getnetent(); +#ifdef NET_R_SETANSWER + int n = 0; + + if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = ne; + if (ne == NULL) + *h_errnop = h_errno; + return (n); +#else if (ne == NULL) return (NET_R_BAD); return (copy_netent(ne, nptr, NET_R_COPY)); +#endif } NET_R_SET_RETURN @@ -117,7 +153,7 @@ copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) { len += strlen(ne->n_name) + 1; len += numptr * sizeof(char*); - if (len > buflen) { + if (len > (int)buflen) { errno = ERANGE; return (NET_R_BAD); } @@ -186,6 +222,6 @@ copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) { } #endif /* !NETENT_DATA */ #else /* NET_R_RETURN */ - static int getnetent_r_unknown_systemm = 0; + static int getnetent_r_unknown_system = 0; #endif /* NET_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ diff --git a/contrib/bind/lib/irs/getnetgrent.c b/contrib/bind/lib/irs/getnetgrent.c index 8c5f5f894a66..e966ea6b6234 100644 --- a/contrib/bind/lib/irs/getnetgrent.c +++ b/contrib/bind/lib/irs/getnetgrent.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetgrent.c,v 1.14 1999/10/07 20:44:03 vixie Exp $"; +static const char rcsid[] = "$Id: getnetgrent.c,v 1.15 2001/05/29 05:48:49 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -70,7 +70,7 @@ innetgr(const char *netgroup, const char *host, } int -getnetgrent(char **host, char **user, char **domain) { +getnetgrent(const char **host, const char **user, const char **domain) { struct net_data *net_data = init(); return (getnetgrent_p(host, user, domain, net_data)); @@ -109,7 +109,7 @@ innetgr_p(const char *netgroup, const char *host, } int -getnetgrent_p(char **host, char **user, char **domain, +getnetgrent_p(const char **host, const char **user, const char **domain, struct net_data *net_data ) { struct irs_ng *ng; diff --git a/contrib/bind/lib/irs/getnetgrent_r.c b/contrib/bind/lib/irs/getnetgrent_r.c index e0c366c05bbb..adae817e1303 100644 --- a/contrib/bind/lib/irs/getnetgrent_r.c +++ b/contrib/bind/lib/irs/getnetgrent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.4 1999/01/18 07:46:52 vixie Exp $"; +static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.6 2001/11/01 08:02:12 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,15 +26,18 @@ static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.4 1999/01/18 07:46:52 vixi #include #include #include +#include #include #include +#include +#include #include #ifdef NGR_R_RETURN static NGR_R_RETURN -copy_protoent(char **, char **, char **, char *, char *, char *, - NGR_R_COPY_ARGS); +copy_protoent(char **, char **, char **, const char *, const char *, + const char *, NGR_R_COPY_ARGS); NGR_R_RETURN innetgr_r(const char *netgroup, const char *host, const char *user, @@ -51,7 +54,7 @@ innetgr_r(const char *netgroup, const char *host, const char *user, NGR_R_RETURN getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS) { - char *mp, *up, *dp; + const char *mp, *up, *dp; int res = getnetgrent(&mp, &up, &dp); if (res != 1) @@ -69,14 +72,27 @@ setnetgrent_r(const char *netgroup) #endif { setnetgrent(netgroup); +#ifdef NGR_R_PRIVATE + *buf = NULL; +#endif #ifdef NGR_R_SET_RESULT return (NGR_R_SET_RESULT); #endif } NGR_R_END_RETURN -endnetgrent_r(NGR_R_ENT_ARGS) { +#ifdef NGR_R_ENT_ARGS +endnetgrent_r(NGR_R_ENT_ARGS) +#else +endnetgrent_r(void) +#endif +{ endnetgrent(); +#ifdef NGR_R_PRIVATE + if (*buf != NULL) + free(*buf); + *buf = NULL; +#endif NGR_R_END_RESULT(NGR_R_OK); } @@ -84,9 +100,10 @@ endnetgrent_r(NGR_R_ENT_ARGS) { static int copy_protoent(char **machinep, char **userp, char **domainp, - char *mp, char *up, char *dp, NGR_R_COPY_ARGS) { + const char *mp, const char *up, const char *dp, + NGR_R_COPY_ARGS) { char *cp; - int i, n; + int n; int len; /* Find out the amount of space required to store the answer. */ @@ -95,12 +112,20 @@ copy_protoent(char **machinep, char **userp, char **domainp, if (up != NULL) len += strlen(up) + 1; if (dp != NULL) len += strlen(dp) + 1; - if (len > buflen) { +#ifdef NGR_R_PRIVATE + free(*buf); + *buf = malloc(len); + if (*buf == NULL) + return(NGR_R_BAD); + cp = *buf; +#else + if (len > (int)buflen) { errno = ERANGE; return (NGR_R_BAD); } - cp = buf; +#endif + if (mp != NULL) { n = strlen(mp) + 1; diff --git a/contrib/bind/lib/irs/getprotoent.c b/contrib/bind/lib/irs/getprotoent.c index e3bfc371c06b..724b0ada63ac 100644 --- a/contrib/bind/lib/irs/getprotoent.c +++ b/contrib/bind/lib/irs/getprotoent.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getprotoent.c,v 1.15 1999/10/13 16:39:31 vixie Exp $"; +static const char rcsid[] = "$Id: getprotoent.c,v 1.16 2001/11/01 07:34:33 marka Exp $"; #endif /* Imports */ @@ -33,6 +33,7 @@ static const char rcsid[] = "$Id: getprotoent.c,v 1.15 1999/10/13 16:39:31 vixie #include #include #include +#include #include diff --git a/contrib/bind/lib/irs/getprotoent_r.c b/contrib/bind/lib/irs/getprotoent_r.c index e5c54d7d06c7..fc3b17ef9469 100644 --- a/contrib/bind/lib/irs/getprotoent_r.c +++ b/contrib/bind/lib/irs/getprotoent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getprotoent_r.c,v 8.4 1999/01/18 07:46:52 vixie Exp $"; +static const char rcsid[] = "$Id: getprotoent_r.c,v 8.6 2001/11/01 08:02:14 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,6 +26,7 @@ static const char rcsid[] = "$Id: getprotoent_r.c,v 8.4 1999/01/18 07:46:52 vixi #include #include #include +#include #include #include #include @@ -38,21 +39,41 @@ copy_protoent(struct protoent *, struct protoent *, PROTO_R_COPY_ARGS); PROTO_R_RETURN getprotobyname_r(const char *name, struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotobyname(name); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } PROTO_R_RETURN getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotobynumber(proto); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } /* @@ -64,11 +85,21 @@ getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) { PROTO_R_RETURN getprotoent_r(struct protoent *pptr, PROTO_R_ARGS) { struct protoent *pe = getprotoent(); +#ifdef PROTO_R_SETANSWER + int n = 0; + if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = pptr; + + return (n); +#else if (pe == NULL) return (PROTO_R_BAD); return (copy_protoent(pe, pptr, PROTO_R_COPY)); +#endif } PROTO_R_SET_RETURN @@ -113,7 +144,7 @@ copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) { len += strlen(pe->p_name) + 1; len += numptr * sizeof(char*); - if (len > buflen) { + if (len > (int)buflen) { errno = ERANGE; return (PROTO_R_BAD); } @@ -180,6 +211,6 @@ copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) { } #endif /* PROTOENT_DATA */ #else /* PROTO_R_RETURN */ - static int getprotoent_r_unknown_systemm = 0; + static int getprotoent_r_unknown_system = 0; #endif /* PROTO_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ diff --git a/contrib/bind/lib/irs/getpwent_r.c b/contrib/bind/lib/irs/getpwent_r.c index 761fa459d565..ee2d8a7cf967 100644 --- a/contrib/bind/lib/irs/getpwent_r.c +++ b/contrib/bind/lib/irs/getpwent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getpwent_r.c,v 8.3 1999/01/08 19:24:33 vixie Exp $"; +static const char rcsid[] = "$Id: getpwent_r.c,v 8.6 2001/11/01 08:02:15 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -27,7 +27,19 @@ static const char rcsid[] = "$Id: getpwent_r.c,v 8.3 1999/01/08 19:24:33 vixie E #include #include #include +#if (defined(POSIX_GETPWNAM_R) || defined(POSIX_GETPWUID_R)) +#if defined(_POSIX_PTHREAD_SEMANTICS) + /* turn off solaris remapping in */ +#undef _POSIX_PTHREAD_SEMANTICS #include +#define _POSIX_PTHREAD_SEMANTICS 1 +#else +#define _UNIX95 1 +#include +#endif +#else +#include +#endif #include #ifdef PASS_R_RETURN @@ -50,7 +62,7 @@ getpwnam_r(const char *login, struct passwd *pwptr, if (pw == NULL) { *result = NULL; - return (-1); + return (0); } res = copy_passwd(pw, pwptr, buf, buflen); @@ -87,7 +99,7 @@ getpwuid_r(uid_t uid, struct passwd *pwptr, if (pw == NULL) { *result = NULL; - return (-1); + return (0); } res = copy_passwd(pw, pwptr, buf, buflen); @@ -142,7 +154,12 @@ setpassent_r(int stayopen) } PASS_R_SET_RETURN -setpwent_r(PASS_R_ENT_ARGS) { +#ifdef PASS_R_ENT_ARGS +setpwent_r(PASS_R_ENT_ARGS) +#else +setpwent_r(void) +#endif +{ setpwent(); #ifdef PASS_R_SET_RESULT @@ -151,7 +168,12 @@ setpwent_r(PASS_R_ENT_ARGS) { } PASS_R_END_RETURN -endpwent_r(PASS_R_ENT_ARGS) { +#ifdef PASS_R_ENT_ARGS +endpwent_r(PASS_R_ENT_ARGS) +#else +endpwent_r(void) +#endif +{ endpwent(); PASS_R_END_RESULT(PASS_R_OK); @@ -177,8 +199,8 @@ fgetpwent_r(FILE *f, struct passwd *pwptr, PASS_R_COPY_ARGS) { static int copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) { char *cp; - int i, n; - int numptr, len; + int n; + int len; /* Find out the amount of space required to store the answer. */ len = strlen(pw->pw_name) + 1; @@ -192,7 +214,7 @@ copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) { if (len > buflen) { errno = ERANGE; - return (-1); + return (ERANGE); } /* copy fixed atomic values*/ @@ -248,6 +270,6 @@ copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) { return (0); } #else /* PASS_R_RETURN */ - static int getpwent_r_unknown_systemm = 0; + static int getpwent_r_unknown_system = 0; #endif /* PASS_R_RETURN */ #endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */ diff --git a/contrib/bind/lib/irs/getservent.c b/contrib/bind/lib/irs/getservent.c index d2b8b5048ef8..d63ae1d90618 100644 --- a/contrib/bind/lib/irs/getservent.c +++ b/contrib/bind/lib/irs/getservent.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getservent.c,v 1.16 1999/10/13 16:39:31 vixie Exp $"; +static const char rcsid[] = "$Id: getservent.c,v 1.17 2001/11/01 07:33:16 marka Exp $"; #endif /* Imports */ @@ -33,6 +33,7 @@ static const char rcsid[] = "$Id: getservent.c,v 1.16 1999/10/13 16:39:31 vixie #include #include #include +#include #include diff --git a/contrib/bind/lib/irs/getservent_r.c b/contrib/bind/lib/irs/getservent_r.c index 4da9dc20945c..b4897ae952db 100644 --- a/contrib/bind/lib/irs/getservent_r.c +++ b/contrib/bind/lib/irs/getservent_r.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getservent_r.c,v 8.3 1999/01/08 19:24:36 vixie Exp $"; +static const char rcsid[] = "$Id: getservent_r.c,v 8.5 2001/11/01 08:02:16 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -26,6 +26,7 @@ static const char rcsid[] = "$Id: getservent_r.c,v 8.3 1999/01/08 19:24:36 vixie #include #include #include +#include #include #include #include @@ -40,22 +41,42 @@ SERV_R_RETURN getservbyname_r(const char *name, const char *proto, struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservbyname(name, proto); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } SERV_R_RETURN getservbyport_r(int port, const char *proto, struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservbyport(port, proto); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } /* @@ -67,11 +88,21 @@ getservbyport_r(int port, const char *proto, SERV_R_RETURN getservent_r(struct servent *sptr, SERV_R_ARGS) { struct servent *se = getservent(); +#ifdef SERV_R_SETANSWER + int n = 0; + + if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0) + *answerp = NULL; + else + *answerp = sptr; + return (n); +#else if (se == NULL) return (SERV_R_BAD); return (copy_servent(se, sptr, SERV_R_COPY)); +#endif } SERV_R_SET_RETURN @@ -119,7 +150,7 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { len += strlen(se->s_proto) + 1; len += numptr * sizeof(char*); - if (len > buflen) { + if (len > (int)buflen) { errno = ERANGE; return (SERV_R_BAD); } @@ -201,6 +232,6 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { } #endif /* !SERVENT_DATA */ #else /*SERV_R_RETURN */ - static int getservent_r_unknown_systemm = 0; + static int getservent_r_unknown_system = 0; #endif /*SERV_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ diff --git a/contrib/bind/lib/irs/hesiod.c b/contrib/bind/lib/irs/hesiod.c index 40826eb8895c..2b0891150675 100644 --- a/contrib/bind/lib/irs/hesiod.c +++ b/contrib/bind/lib/irs/hesiod.c @@ -1,5 +1,5 @@ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: hesiod.c,v 1.21 2000/02/28 14:51:08 vixie Exp $"; +static const char rcsid[] = "$Id: hesiod.c,v 1.22 2001/05/29 05:48:55 marka Exp $"; #endif /* @@ -259,6 +259,8 @@ void hesiod_free_list(void *context, char **list) { char **p; + UNUSED(context); + for (p = list; *p; p++) free(*p); free(list); diff --git a/contrib/bind/lib/irs/irp.c b/contrib/bind/lib/irs/irp.c index a6c8f4ff9916..fa28b3fdb8b3 100644 --- a/contrib/bind/lib/irs/irp.c +++ b/contrib/bind/lib/irs/irp.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irp.c,v 8.6 2000/02/04 08:28:33 vixie Exp $"; +static const char rcsid[] = "$Id: irp.c,v 8.8 2001/09/25 04:50:29 marka Exp $"; #endif /* Imports */ @@ -84,6 +84,8 @@ irs_irp_acc(const char *options) { struct irs_acc *acc; struct irp_p *irp; + UNUSED(options); + if (!(acc = memget(sizeof *acc))) { errno = ENOMEM; return (NULL); @@ -387,9 +389,9 @@ irs_irp_read_response(struct irp_p *pvt, char *text, size_t textlen) { code = 0; } else if (text != NULL && textlen > 0) { p = line; - while (isspace(*p)) p++; - while (isdigit(*p)) p++; - while (isspace(*p)) p++; + while (isspace((unsigned char)*p)) p++; + while (isdigit((unsigned char)*p)) p++; + while (isspace((unsigned char)*p)) p++; strncpy(text, p, textlen - 1); p[textlen - 1] = '\0'; } @@ -537,7 +539,8 @@ irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) { va_start(ap, fmt); todo = vsprintf(buffer, fmt, ap); - if (todo > sizeof buffer - 2) { + va_end(ap); + if (todo > (int)sizeof(buffer) - 3) { syslog(LOG_CRIT, "memory overrun in irs_irp_send_command()"); exit(1); } @@ -559,7 +562,6 @@ irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) { } todo -= i; } - va_end(ap); return (0); } diff --git a/contrib/bind/lib/irs/irp_gr.c b/contrib/bind/lib/irs/irp_gr.c index 4e2a28cba990..c235e19020a9 100644 --- a/contrib/bind/lib/irs/irp_gr.c +++ b/contrib/bind/lib/irs/irp_gr.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_gr.c,v 8.1 1999/01/18 07:46:53 vixie Exp $"; +static const char rcsid[] = "$Id: irp_gr.c,v 8.3 2001/05/29 05:48:57 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -285,7 +285,7 @@ gr_bygid(struct irs_gr *this, gid_t gid) { int code; char text[256]; - if (gr->gr_name != NULL && gr->gr_gid == gid) { + if (gr->gr_name != NULL && (gid_t)gr->gr_gid == gid) { return (gr); } @@ -397,6 +397,9 @@ free_group(struct group *gr) { for (p = gr->gr_mem ; p != NULL && *p != NULL ; p++) free(*p); + if (gr->gr_mem) + free(gr->gr_mem); + if (p != NULL) free(p); } diff --git a/contrib/bind/lib/irs/irp_ho.c b/contrib/bind/lib/irs/irp_ho.c index 7bfd0e2ba701..21240177272b 100644 --- a/contrib/bind/lib/irs/irp_ho.c +++ b/contrib/bind/lib/irs/irp_ho.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_ho.c,v 8.2 1999/10/13 16:39:31 vixie Exp $"; +static const char rcsid[] = "$Id: irp_ho.c,v 8.3 2001/05/29 05:48:59 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -79,7 +79,8 @@ static void ho_rewind(struct irs_ho *this); static void ho_minimize(struct irs_ho *this); static void free_host(struct hostent *ho); - +static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, + const struct addrinfo *pai); /* Public. */ @@ -121,6 +122,7 @@ irs_irp_ho(struct irs_acc *this) { ho->next = ho_next; ho->rewind = ho_rewind; ho->minimize = ho_minimize; + ho->addrinfo = ho_addrinfo; return (ho); } @@ -416,3 +418,12 @@ free_host(struct hostent *ho) { } } +/* dummy */ +static struct addrinfo * +ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) +{ + UNUSED(this); + UNUSED(name); + UNUSED(pai); + return(NULL); +} diff --git a/contrib/bind/lib/irs/irp_ng.c b/contrib/bind/lib/irs/irp_ng.c index e96f66c5889c..b3cf0f4b60f6 100644 --- a/contrib/bind/lib/irs/irp_ng.c +++ b/contrib/bind/lib/irs/irp_ng.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irp_ng.c,v 8.2 1999/10/13 16:39:31 vixie Exp $"; +static const char rcsid[] = "$Id: irp_ng.c,v 8.3 2001/05/29 05:49:00 marka Exp $"; #endif /* Imports */ @@ -52,7 +52,8 @@ struct pvt { static void ng_rewind(struct irs_ng *, const char*); static void ng_close(struct irs_ng *); -static int ng_next(struct irs_ng *, char **, char **, char **); +static int ng_next(struct irs_ng *, const char **, const char **, + const char **); static int ng_test(struct irs_ng *, const char *, const char *, const char *, const char *); @@ -158,7 +159,8 @@ ng_rewind(struct irs_ng *this, const char *group) { /* - * int ng_next(struct irs_ng *this, char **host, char **user, char **domain) + * int ng_next(struct irs_ng *this, const char **host, const char **user, + * const char **domain) * * Notes: * @@ -167,7 +169,9 @@ ng_rewind(struct irs_ng *this, const char *group) { */ static int -ng_next(struct irs_ng *this, char **host, char **user, char **domain) { +ng_next(struct irs_ng *this, const char **host, const char **user, + const char **domain) +{ struct pvt *pvt = (struct pvt *)this->private; int code; char *body = NULL; @@ -224,6 +228,8 @@ ng_test(struct irs_ng *this, const char *name, char text[256]; int rval = 0; + UNUSED(name); + if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) { return (0); } diff --git a/contrib/bind/lib/irs/irp_p.h b/contrib/bind/lib/irs/irp_p.h index adf81746e8a0..0f68b28973ea 100644 --- a/contrib/bind/lib/irs/irp_p.h +++ b/contrib/bind/lib/irs/irp_p.h @@ -16,7 +16,7 @@ */ /* - * $Id: irp_p.h,v 8.1 1999/01/18 07:46:54 vixie Exp $ + * $Id: irp_p.h,v 8.2 2001/08/10 02:40:52 marka Exp $ */ #ifndef _IRP_P_H_INCLUDED @@ -53,7 +53,7 @@ char *irs_irp_read_body(struct irp_p *pvt, size_t *size); int irs_irp_get_full_response(struct irp_p *pvt, int *code, char *text, size_t textlen, char **body, size_t *bodylen); -int irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...); +int irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3); extern int irp_log_errors; diff --git a/contrib/bind/lib/irs/irp_pw.c b/contrib/bind/lib/irs/irp_pw.c index f23cb734c24a..b659caa244e8 100644 --- a/contrib/bind/lib/irs/irp_pw.c +++ b/contrib/bind/lib/irs/irp_pw.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_pw.c,v 8.1 1999/01/18 07:46:54 vixie Exp $"; +static const char rcsid[] = "$Id: irp_pw.c,v 8.2 2001/11/01 07:29:26 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Extern */ @@ -340,8 +340,10 @@ free_passwd(struct passwd *pw) { if (pw->pw_passwd != NULL) free(pw->pw_passwd); +#ifdef HAVE_PW_CLASS if (pw->pw_class != NULL) free(pw->pw_class); +#endif if (pw->pw_gecos != NULL) free(pw->pw_gecos); diff --git a/contrib/bind/lib/irs/irpmarshall.c b/contrib/bind/lib/irs/irpmarshall.c index 240bb08908e6..6331ce1106da 100644 --- a/contrib/bind/lib/irs/irpmarshall.c +++ b/contrib/bind/lib/irs/irpmarshall.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irpmarshall.c,v 8.6 2000/11/13 05:08:08 vixie Exp $"; +static const char rcsid[] = "$Id: irpmarshall.c,v 8.7 2001/05/29 05:49:01 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #if 0 @@ -139,7 +139,7 @@ irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) { char pwGid[24]; char pwChange[24]; char pwExpire[24]; - char *pwClass; + const char *pwClass; const char *fieldsep = COLONSTR; if (pw == NULL || len == NULL) { @@ -1228,8 +1228,8 @@ irp_marshall_ng(const char *host, const char *user, const char *domain, /* - * int irp_unmarshall_ng(char **host, char **user, char **domain, - * char *buffer) + * int irp_unmarshall_ng(const char **host, const char **user, + * const char **domain, char *buffer) * * notes: * @@ -1243,20 +1243,24 @@ irp_marshall_ng(const char *host, const char *user, const char *domain, */ int -irp_unmarshall_ng(char **host, char **user, char **domain, char *buffer) { +irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp, + char *buffer) +{ char *p, *q; char fieldsep = ','; int myerrno = EINVAL; + char *host, *user, *domain; - if (user == NULL || host == NULL || domain == NULL || buffer == NULL) { + if (userp == NULL || hostp == NULL || + domainp == NULL || buffer == NULL) { errno = EINVAL; return (-1); } - *host = *user = *domain = NULL; + host = user = domain = NULL; p = buffer; - while (isspace(*p)) { + while (isspace((unsigned char)*p)) { p++; } if (*p != '(') { @@ -1269,7 +1273,7 @@ irp_unmarshall_ng(char **host, char **user, char **domain, char *buffer) { if (!*q) { goto error; } else if (q > p + 1) { - *host = strndup(p, q - p); + host = strndup(p, q - p); } p = q + 1; @@ -1282,7 +1286,7 @@ irp_unmarshall_ng(char **host, char **user, char **domain, char *buffer) { if (!*q) { goto error; } - *user = strndup(p, q - p); + user = strndup(p, q - p); } else { p++; } @@ -1296,17 +1300,20 @@ irp_unmarshall_ng(char **host, char **user, char **domain, char *buffer) { if (!*q) { goto error; } - *domain = strndup(p, q - p); + domain = strndup(p, q - p); } + *hostp = host; + *userp = user; + *domainp = domain; return (0); error: errno = myerrno; - if (*host != NULL) free(*host); - if (*user != NULL) free(*user); - if (*domain != NULL) free(*domain); + if (host != NULL) free(host); + if (user != NULL) free(user); + if (domain != NULL) free(domain); return (-1); } @@ -1847,7 +1854,7 @@ getfield(char **res, size_t reslen, char **ptr, char delim) { if (*res == NULL) { *res = strndup(*ptr, q - *ptr); } else { - if (q - *ptr + 1 > reslen) { /* to big for res */ + if ((size_t)(q - *ptr + 1) > reslen) { /* to big for res */ errno = EINVAL; return (NULL); } else { diff --git a/contrib/bind/lib/irs/irs_data.c b/contrib/bind/lib/irs/irs_data.c index 8446c6b851cc..000da0c7b153 100644 --- a/contrib/bind/lib/irs/irs_data.c +++ b/contrib/bind/lib/irs/irs_data.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irs_data.c,v 1.15 2000/12/23 08:14:54 vixie Exp $"; +static const char rcsid[] = "$Id: irs_data.c,v 1.19 2001/08/20 07:08:41 marka Exp $"; #endif #include "port_before.h" @@ -30,6 +30,7 @@ static const char rcsid[] = "$Id: irs_data.c,v 1.15 2000/12/23 08:14:54 vixie Ex #include #include +#include #include #ifdef DO_PTHREADS @@ -67,7 +68,7 @@ void net_data_destroy(void *p) { struct net_data *net_data = p; - res_nclose(net_data->res); + res_ndestroy(net_data->res); if (net_data->gr != NULL) { (*net_data->gr->close)(net_data->gr); net_data->gr = NULL; @@ -152,7 +153,8 @@ net_data_create(const char *conf_file) { if (net_data->res == NULL) return (NULL); - if (res_ninit(net_data->res) == -1) + if ((net_data->res->options & RES_INIT) == 0 && + res_ninit(net_data->res) == -1) return (NULL); return (net_data); @@ -165,6 +167,7 @@ net_data_minimize(struct net_data *net_data) { res_nclose(net_data->res); } +#ifdef _REENTRANT struct __res_state * __res_state(void) { /* NULL param here means use the default config file. */ @@ -174,6 +177,7 @@ __res_state(void) { return (&_res); } +#endif int * __h_errno(void) { diff --git a/contrib/bind/lib/irs/lcl.c b/contrib/bind/lib/irs/lcl.c index 16e167f23169..ed9e6b43e381 100644 --- a/contrib/bind/lib/irs/lcl.c +++ b/contrib/bind/lib/irs/lcl.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: lcl.c,v 1.16 2000/02/28 07:52:16 vixie Exp $"; +static const char rcsid[] = "$Id: lcl.c,v 1.17 2001/05/29 05:49:02 marka Exp $"; #endif /* Imports */ @@ -55,6 +55,8 @@ irs_lcl_acc(const char *options) { struct irs_acc *acc; struct lcl_p *lcl; + UNUSED(options); + if (!(acc = memget(sizeof *acc))) { errno = ENOMEM; return (NULL); diff --git a/contrib/bind/lib/irs/lcl_gr.c b/contrib/bind/lib/irs/lcl_gr.c index acb85ee4fac6..7536c278a623 100644 --- a/contrib/bind/lib/irs/lcl_gr.c +++ b/contrib/bind/lib/irs/lcl_gr.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_gr.c,v 1.25 1999/10/13 17:11:19 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_gr.c,v 1.26 2001/05/29 05:49:03 marka Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -129,6 +129,8 @@ irs_lcl_gr(struct irs_acc *this) { struct irs_gr *gr; struct pvt *pvt; + UNUSED(this); + if (!(gr = memget(sizeof *gr))) { errno = ENOMEM; return (NULL); @@ -313,7 +315,7 @@ grscan(struct irs_gr *this, int search, gid_t gid, const char *name) { continue; } pvt->group.gr_gid = atoi(p); - if (search && name == NULL && pvt->group.gr_gid != gid) + if (search && name == NULL && (gid_t)pvt->group.gr_gid != gid) continue; /* We want this record. */ diff --git a/contrib/bind/lib/irs/lcl_ho.c b/contrib/bind/lib/irs/lcl_ho.c index 59392076d745..e9685a383484 100644 --- a/contrib/bind/lib/irs/lcl_ho.c +++ b/contrib/bind/lib/irs/lcl_ho.c @@ -52,7 +52,7 @@ /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_ho.c,v 1.25 1999/10/13 17:11:19 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_ho.c,v 1.26 2001/05/29 05:49:04 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -83,6 +83,7 @@ static const char rcsid[] = "$Id: lcl_ho.c,v 1.25 1999/10/13 17:11:19 vixie Exp #include "irs_p.h" #include "dns_p.h" +#include "lcl_p.h" #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) @@ -136,6 +137,8 @@ static struct __res_state * ho_res_get(struct irs_ho *this); static void ho_res_set(struct irs_ho *this, struct __res_state *res, void (*free_res)(void *)); +static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, + const struct addrinfo *pai); static size_t ns_namelen(const char *); static int init(struct irs_ho *this); @@ -153,6 +156,8 @@ irs_lcl_ho(struct irs_acc *this) { struct irs_ho *ho; struct pvt *pvt; + UNUSED(this); + if (!(pvt = memget(sizeof *pvt))) { errno = ENOMEM; return (NULL); @@ -174,6 +179,7 @@ irs_lcl_ho(struct irs_acc *this) { ho->minimize = ho_minimize; ho->res_get = ho_res_get; ho->res_set = ho_res_set; + ho->addrinfo = ho_addrinfo; return (ho); } @@ -257,7 +263,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { (!memcmp(uaddr, mapped, sizeof mapped) || !memcmp(uaddr, tunnelled, sizeof tunnelled))) { /* Unmap. */ - addr = (u_char *)addr + sizeof mapped; + addr = (const u_char *)addr + sizeof mapped; uaddr += sizeof mapped; af = AF_INET; len = INADDRSZ; @@ -479,6 +485,73 @@ ho_res_set(struct irs_ho *this, struct __res_state *res, pvt->free_res = free_res; } +struct lcl_res_target { + struct lcl_res_target *next; + int family; +}; + +/* XXX */ +extern struct addrinfo *hostent2addrinfo __P((struct hostent *, + const struct addrinfo *pai)); + +static struct addrinfo * +ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) +{ + struct pvt *pvt = (struct pvt *)this->private; + struct hostent *hp; + struct lcl_res_target q, q2, *p; + struct addrinfo sentinel, *cur; + + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + switch(pai->ai_family) { + case AF_UNSPEC: /* INET6 then INET4 */ + q.family = AF_INET6; + q.next = &q2; + q2.family = AF_INET; + break; + case AF_INET6: + q.family = AF_INET6; + break; + case AF_INET: + q.family = AF_INET; + break; + default: + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */ + return(NULL); + } + + for (p = &q; p; p = p->next) { + struct addrinfo *ai; + + hp = (*this->byname2)(this, name, p->family); + if (hp == NULL) { + /* byname2 should've set an appropriate error */ + continue; + } + if ((hp->h_name == NULL) || (hp->h_name[0] == 0) || + (hp->h_addr_list[0] == NULL)) { + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); + continue; + } + + ai = hostent2addrinfo(hp, pai); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + } + + if (sentinel.ai_next == NULL) + RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND); + + return(sentinel.ai_next); +} + /* Private. */ static size_t diff --git a/contrib/bind/lib/irs/lcl_ng.c b/contrib/bind/lib/irs/lcl_ng.c index 03acbf609ae2..239b63ed0dc5 100644 --- a/contrib/bind/lib/irs/lcl_ng.c +++ b/contrib/bind/lib/irs/lcl_ng.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: lcl_ng.c,v 1.16 1999/10/13 16:39:32 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_ng.c,v 1.17 2001/05/29 05:49:05 marka Exp $"; #endif /* Imports */ @@ -39,6 +39,7 @@ static const char rcsid[] = "$Id: lcl_ng.c,v 1.16 1999/10/13 16:39:32 vixie Exp #include "port_after.h" #include "irs_p.h" +#include "lcl_p.h" /* Definitions */ @@ -88,7 +89,8 @@ struct pvt { static void ng_rewind(struct irs_ng *, const char*); static void ng_close(struct irs_ng *); -static int ng_next(struct irs_ng *, char **, char **, char **); +static int ng_next(struct irs_ng *, const char **, + const char **, const char **); static int ng_test(struct irs_ng *, const char *, const char *, const char *, const char *); @@ -104,6 +106,8 @@ struct irs_ng * irs_lcl_ng(struct irs_acc *this) { struct irs_ng *ng; struct pvt *pvt; + + UNUSED(this); if (!(ng = memget(sizeof *ng))) { errno = ENOMEM; @@ -174,7 +178,9 @@ ng_rewind(struct irs_ng *this, const char *group) { * Get the next netgroup off the list. */ static int -ng_next(struct irs_ng *this, char **host, char **user, char **domain) { +ng_next(struct irs_ng *this, const char **host, const char **user, + const char **domain) +{ struct pvt *pvt = (struct pvt *)this->private; if (pvt->nextgrp) { @@ -194,7 +200,7 @@ static int ng_test(struct irs_ng *this, const char *name, const char *host, const char *user, const char *domain) { - char *ng_host, *ng_user, *ng_domain; + const char *ng_host, *ng_user, *ng_domain; ng_rewind(this, name); while (ng_next(this, &ng_host, &ng_user, &ng_domain)) @@ -350,7 +356,7 @@ parse_netgrp(struct irs_ng *this, const char *group) { static struct linelist * read_for_group(struct irs_ng *this, const char *group) { struct pvt *pvt = (struct pvt *)this->private; - char *pos, *spos, *linep, *olinep; + char *pos, *spos, *linep = NULL, *olinep; int len, olen, cont; struct linelist *lp; char line[LINSIZ + 1]; diff --git a/contrib/bind/lib/irs/lcl_nw.c b/contrib/bind/lib/irs/lcl_nw.c index 0d41ec409e97..457621b8443d 100644 --- a/contrib/bind/lib/irs/lcl_nw.c +++ b/contrib/bind/lib/irs/lcl_nw.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_nw.c,v 1.21 1999/10/15 19:49:10 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_nw.c,v 1.22 2001/05/29 05:49:07 marka Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -122,6 +122,8 @@ irs_lcl_nw(struct irs_acc *this) { struct irs_nw *nw; struct pvt *pvt; + UNUSED(this); + if (!(pvt = memget(sizeof *pvt))) { errno = ENOMEM; return (NULL); diff --git a/contrib/bind/lib/irs/lcl_pw.c b/contrib/bind/lib/irs/lcl_pw.c index 2655677b0f51..31c1ed015ac6 100644 --- a/contrib/bind/lib/irs/lcl_pw.c +++ b/contrib/bind/lib/irs/lcl_pw.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_pw.c,v 1.19 1999/01/18 07:46:57 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_pw.c,v 1.20 2001/05/29 05:49:08 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Extern */ @@ -119,6 +119,8 @@ struct irs_pw * irs_lcl_pw(struct irs_acc *this) { struct irs_pw *pw; struct pvt *pvt; + + UNUSED(this); if (!(pw = memget(sizeof *pw))) { errno = ENOMEM; diff --git a/contrib/bind/lib/irs/lcl_sv.c b/contrib/bind/lib/irs/lcl_sv.c index 7e5bec9f4d51..d94366b7c035 100644 --- a/contrib/bind/lib/irs/lcl_sv.c +++ b/contrib/bind/lib/irs/lcl_sv.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_sv.c,v 1.20 1999/10/07 20:44:03 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_sv.c,v 1.22 2001/06/18 14:43:59 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -122,6 +122,8 @@ struct irs_sv * irs_lcl_sv(struct irs_acc *this) { struct irs_sv *sv; struct pvt *pvt; + + UNUSED(this); if ((sv = memget(sizeof *sv)) == NULL) { errno = ENOMEM; @@ -287,13 +289,10 @@ sv_next(struct irs_sv *this) { struct pvt *pvt = (struct pvt *)this->private; #ifdef IRS_LCL_SV_DB - if (pvt->dbh != NULL) - NULL; - else + if (pvt->dbh == NULL && pvt->sv.fp == NULL) +#else + if (pvt->sv.fp == NULL) #endif - if (pvt->sv.fp != NULL) - NULL; - else sv_rewind(this); #ifdef IRS_LCL_SV_DB @@ -395,7 +394,7 @@ sv_db_rec(struct lcl_sv *sv, DBT *key, DBT *data) { return (NULL); sv->serv.s_port = ((u_short *)key->data)[1]; n = strlen(p) + 1; - if (n > sizeof(sv->line)) { + if ((size_t)n > sizeof(sv->line)) { n = sizeof(sv->line); } memcpy(sv->line, p, n); diff --git a/contrib/bind/lib/irs/nis.c b/contrib/bind/lib/irs/nis.c index e19068af5954..aa10fba3c28e 100644 --- a/contrib/bind/lib/irs/nis.c +++ b/contrib/bind/lib/irs/nis.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis.c,v 1.14 2000/02/28 07:52:16 vixie Exp $"; +static const char rcsid[] = "$Id: nis.c,v 1.15 2001/05/29 05:49:11 marka Exp $"; #endif /* Imports */ @@ -63,6 +63,8 @@ irs_nis_acc(const char *options) { struct irs_acc *acc; char *domain; + UNUSED(options); + if (yp_get_default_domain(&domain) != 0) return (NULL); if (!(nis = memget(sizeof *nis))) { diff --git a/contrib/bind/lib/irs/nis_gr.c b/contrib/bind/lib/irs/nis_gr.c index 713437a64af6..b4e09453c4cd 100644 --- a/contrib/bind/lib/irs/nis_gr.c +++ b/contrib/bind/lib/irs/nis_gr.c @@ -49,7 +49,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_gr.c,v 1.20 1999/01/30 00:53:16 vixie Exp $"; +static const char rcsid[] = "$Id: nis_gr.c,v 1.21 2001/05/29 05:49:12 marka Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -217,7 +217,7 @@ gr_byname(struct irs_gr *this, const char *name) { int r; nisfree(pvt, do_val); - r = yp_match(pvt->nis_domain, group_byname, (char *)name, strlen(name), + r = yp_match(pvt->nis_domain, group_byname, name, strlen(name), &pvt->curval_data, &pvt->curval_len); if (r != 0) { errno = ENOENT; @@ -252,6 +252,7 @@ gr_rewind(struct irs_gr *this) { static void gr_minimize(struct irs_gr *this) { + UNUSED(this); /* NOOP */ } @@ -260,7 +261,7 @@ gr_minimize(struct irs_gr *this) { static struct group * makegroupent(struct irs_gr *this) { struct pvt *pvt = (struct pvt *)this->private; - int num_members = 0; + unsigned int num_members = 0; char *cp, **new; u_long t; diff --git a/contrib/bind/lib/irs/nis_ho.c b/contrib/bind/lib/irs/nis_ho.c index 07d2274c5f05..72a8d17a5e90 100644 --- a/contrib/bind/lib/irs/nis_ho.c +++ b/contrib/bind/lib/irs/nis_ho.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_ho.c,v 1.16 1999/10/13 16:39:32 vixie Exp $"; +static const char rcsid[] = "$Id: nis_ho.c,v 1.18 2001/06/18 14:44:00 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -103,6 +103,8 @@ static struct __res_state * ho_res_get(struct irs_ho *this); static void ho_res_set(struct irs_ho *this, struct __res_state *res, void (*free_res)(void *)); +static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, + const struct addrinfo *pai); static struct hostent * makehostent(struct irs_ho *this); static void nisfree(struct pvt *, enum do_what); @@ -138,6 +140,7 @@ irs_nis_ho(struct irs_acc *this) { ho->minimize = ho_minimize; ho->res_set = ho_res_set; ho->res_get = ho_res_get; + ho->addrinfo = ho_addrinfo; return (ho); } @@ -175,13 +178,17 @@ static struct hostent * ho_byname2(struct irs_ho *this, const char *name, int af) { struct pvt *pvt = (struct pvt *)this->private; int r; + char *tmp; + + UNUSED(af); if (init(this) == -1) return (NULL); nisfree(pvt, do_val); - r = yp_match(pvt->nis_domain, hosts_byname, (char *)name, strlen(name), - &pvt->curval_data, &pvt->curval_len); + DE_CONST(name, tmp); + r = yp_match(pvt->nis_domain, hosts_byname, tmp, + strlen(tmp), &pvt->curval_data, &pvt->curval_len); if (r != 0) { RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND); return (NULL); @@ -203,7 +210,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { (!memcmp(uaddr, mapped, sizeof mapped) || !memcmp(uaddr, tunnelled, sizeof tunnelled))) { /* Unmap. */ - addr = (u_char *)addr + sizeof mapped; + addr = (const u_char *)addr + sizeof mapped; uaddr += sizeof mapped; af = AF_INET; len = INADDRSZ; @@ -307,6 +314,72 @@ ho_res_set(struct irs_ho *this, struct __res_state *res, pvt->free_res = free_res; } +struct nis_res_target { + struct nis_res_target *next; + int family; +}; + +/* XXX */ +extern struct addrinfo *hostent2addrinfo __P((struct hostent *, + const struct addrinfo *pai)); + +static struct addrinfo * +ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) +{ + struct pvt *pvt = (struct pvt *)this->private; + struct hostent *hp; + struct nis_res_target q, q2, *p; + struct addrinfo sentinel, *cur; + + memset(&q, 0, sizeof(q2)); + memset(&q2, 0, sizeof(q2)); + memset(&sentinel, 0, sizeof(sentinel)); + cur = &sentinel; + + switch(pai->ai_family) { + case AF_UNSPEC: /* INET6 then INET4 */ + q.family = AF_INET6; + q.next = &q2; + q2.family = AF_INET; + break; + case AF_INET6: + q.family = AF_INET6; + break; + case AF_INET: + q.family = AF_INET; + break; + default: + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */ + return(NULL); + } + + for (p = &q; p; p = p->next) { + struct addrinfo *ai; + + hp = (*this->byname2)(this, name, p->family); + if (hp == NULL) { + /* byname2 should've set an appropriate error */ + continue; + } + if ((hp->h_name == NULL) || (hp->h_name[0] == 0) || + (hp->h_addr_list[0] == NULL)) { + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); + continue; + } + ai = hostent2addrinfo(hp, pai); + if (ai) { + cur->ai_next = ai; + while (cur && cur->ai_next) + cur = cur->ai_next; + } + } + + if (sentinel.ai_next == NULL) + RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND); + + return(sentinel.ai_next); +} + /* Private */ static struct hostent * diff --git a/contrib/bind/lib/irs/nis_ng.c b/contrib/bind/lib/irs/nis_ng.c index 88d97ff56b74..a42d9940f688 100644 --- a/contrib/bind/lib/irs/nis_ng.c +++ b/contrib/bind/lib/irs/nis_ng.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_ng.c,v 1.16 1999/01/18 07:46:58 vixie Exp $"; +static const char rcsid[] = "$Id: nis_ng.c,v 1.17 2001/05/29 05:49:14 marka Exp $"; #endif /* Imports */ @@ -78,7 +78,8 @@ static /*const*/ char netgroup_map[] = "netgroup"; /* Forward */ static void ng_close(struct irs_ng *); -static int ng_next(struct irs_ng *, char **, char **, char **); +static int ng_next(struct irs_ng *, const char **, + const char **, const char **); static int ng_test(struct irs_ng *, const char *, const char *, const char *, const char *); @@ -129,14 +130,14 @@ ng_close(struct irs_ng *this) { } static int -ng_next(struct irs_ng *this, char **host, char **user, char **domain) { +ng_next(struct irs_ng *this, const char **host, const char **user, const char **domain) { struct pvt *pvt = (struct pvt *)this->private; if (!pvt->cur) return (0); - *host = (/*const*/ char *)pvt->cur->host; - *user = (/*const*/ char *)pvt->cur->user; - *domain = (/*const*/ char *)pvt->cur->domain; + *host = pvt->cur->host; + *user = pvt->cur->user; + *domain = pvt->cur->domain; pvt->cur = pvt->cur->next; return (1); } @@ -178,6 +179,7 @@ ng_rewind(struct irs_ng *this, const char *name) { static void ng_minimize(struct irs_ng *this) { + UNUSED(this); /* NOOP */ } @@ -188,13 +190,15 @@ add_group_to_list(struct pvt *pvt, const char *name, int len) { char *vdata, *cp, *np; struct tmpgrp *tmp; int vlen, r; + char *nametmp; /* Don't add the same group to the list more than once. */ for (tmp = pvt->tmp; tmp; tmp = tmp->next) if (!strcmp(tmp->name, name)) return; - r = yp_match(pvt->nis_domain, netgroup_map, (char *)name, len, + DE_CONST(name, nametmp); + r = yp_match(pvt->nis_domain, netgroup_map, nametmp, len, &vdata, &vlen); if (r == 0) { cp = vdata; diff --git a/contrib/bind/lib/irs/nis_nw.c b/contrib/bind/lib/irs/nis_nw.c index 72ec391277b0..bc659f3bfa64 100644 --- a/contrib/bind/lib/irs/nis_nw.c +++ b/contrib/bind/lib/irs/nis_nw.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_nw.c,v 1.15 1999/01/18 07:46:58 vixie Exp $"; +static const char rcsid[] = "$Id: nis_nw.c,v 1.16 2001/05/29 05:49:15 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -187,6 +187,7 @@ static struct nwent * nw_byname(struct irs_nw *this, const char *name, int af) { struct pvt *pvt = (struct pvt *)this->private; int r; + char *tmp; if (init(this) == -1) return (NULL); @@ -197,8 +198,9 @@ nw_byname(struct irs_nw *this, const char *name, int af) { return (NULL); } nisfree(pvt, do_val); - r = yp_match(pvt->nis_domain, networks_byname, (char *)name, - strlen(name), &pvt->curval_data, &pvt->curval_len); + DE_CONST(name, tmp); + r = yp_match(pvt->nis_domain, networks_byname, tmp, + strlen(tmp), &pvt->curval_data, &pvt->curval_len); if (r != 0) { RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND); return (NULL); diff --git a/contrib/bind/lib/irs/nis_pr.c b/contrib/bind/lib/irs/nis_pr.c index 8dff084bdc2b..bc0907571bf3 100644 --- a/contrib/bind/lib/irs/nis_pr.c +++ b/contrib/bind/lib/irs/nis_pr.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_pr.c,v 1.13 1999/01/18 07:46:59 vixie Exp $"; +static const char rcsid[] = "$Id: nis_pr.c,v 1.14 2001/05/29 05:49:16 marka Exp $"; #endif /* Imports */ @@ -132,10 +132,12 @@ static struct protoent * pr_byname(struct irs_pr *this, const char *name) { struct pvt *pvt = (struct pvt *)this->private; int r; + char *tmp; nisfree(pvt, do_val); - r = yp_match(pvt->nis_domain, protocols_byname, (char *)name, - strlen(name), &pvt->curval_data, &pvt->curval_len); + DE_CONST(name, tmp); + r = yp_match(pvt->nis_domain, protocols_byname, tmp, + strlen(tmp), &pvt->curval_data, &pvt->curval_len); if (r != 0) { errno = ENOENT; return (NULL); @@ -204,6 +206,7 @@ pr_rewind(struct irs_pr *this) { static void pr_minimize(struct irs_pr *this) { + UNUSED(this); /* NOOP */ } @@ -220,9 +223,9 @@ makeprotoent(struct irs_pr *this) { pvt->prbuf = pvt->curval_data; pvt->curval_data = NULL; - for (p = pvt->prbuf; *p && *p != '#'; p++) - NULL; - while (p > pvt->prbuf && isspace(p[-1])) + for (p = pvt->prbuf; *p && *p != '#';) + p++; + while (p > pvt->prbuf && isspace((unsigned char)(p[-1]))) p--; *p = '\0'; @@ -230,16 +233,16 @@ makeprotoent(struct irs_pr *this) { n = m = 0; pvt->proto.p_name = p; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (!*p) return (NULL); *p++ = '\0'; - while (*p && isspace(*p)) + while (*p && isspace((unsigned char)*p)) p++; pvt->proto.p_proto = atoi(p); - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; *p++ = '\0'; @@ -255,7 +258,7 @@ makeprotoent(struct irs_pr *this) { pvt->proto.p_aliases = t; } pvt->proto.p_aliases[n++] = p; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) p++; if (*p) *p++ = '\0'; diff --git a/contrib/bind/lib/irs/nis_pw.c b/contrib/bind/lib/irs/nis_pw.c index ce90f203bf26..1d345a5349f3 100644 --- a/contrib/bind/lib/irs/nis_pw.c +++ b/contrib/bind/lib/irs/nis_pw.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_pw.c,v 1.16 1999/01/30 00:53:16 vixie Exp $"; +static const char rcsid[] = "$Id: nis_pw.c,v 1.17 2001/05/29 05:49:18 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -169,9 +169,11 @@ static struct passwd * pw_byname(struct irs_pw *this, const char *name) { struct pvt *pvt = (struct pvt *)this->private; int r; + char *tmp; nisfree(pvt, do_val); - r = yp_match(pvt->nis_domain, passwd_byname, name, strlen(name), + DE_CONST(name, tmp); + r = yp_match(pvt->nis_domain, passwd_byname, tmp, strlen(tmp), &pvt->curval_data, &pvt->curval_len); if (r != 0) { errno = ENOENT; @@ -206,6 +208,7 @@ pw_rewind(struct irs_pw *this) { static void pw_minimize(struct irs_pw *this) { + UNUSED(this); /* NOOP */ } @@ -226,7 +229,9 @@ makepasswdent(struct irs_pw *this) { pvt->passwd.pw_name = cp; if (!(cp = strchr(cp, ':'))) goto cleanup; +#ifdef HAS_PW_CLASS pvt->passwd.pw_class = cp; /* Needs to point at a \0. */ +#endif *cp++ = '\0'; pvt->passwd.pw_passwd = cp; diff --git a/contrib/bind/lib/irs/nis_sv.c b/contrib/bind/lib/irs/nis_sv.c index 8810fd267f0e..40bfda5c28f2 100644 --- a/contrib/bind/lib/irs/nis_sv.c +++ b/contrib/bind/lib/irs/nis_sv.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_sv.c,v 1.14 1999/01/18 07:46:59 vixie Exp $"; +static const char rcsid[] = "$Id: nis_sv.c,v 1.15 2001/05/29 05:49:19 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -205,6 +205,7 @@ sv_next(struct irs_sv *this) { static void sv_minimize(struct irs_sv *this) { + UNUSED(this); /* NOOP */ } @@ -242,7 +243,7 @@ makeservent(struct irs_sv *this) { pvt->serv.s_port = htons((u_short) atoi(p)); pvt->serv.s_proto = NULL; - while (*p && !isspace(*p)) + while (*p && !isspace((unsigned char)*p)) if (*p++ == '/') pvt->serv.s_proto = p; if (!pvt->serv.s_proto) diff --git a/contrib/bind/lib/irs/nul_ng.c b/contrib/bind/lib/irs/nul_ng.c index cc5c80177c59..1a61d8c78bbc 100644 --- a/contrib/bind/lib/irs/nul_ng.c +++ b/contrib/bind/lib/irs/nul_ng.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nul_ng.c,v 1.10 1999/01/18 07:46:59 vixie Exp $"; +static const char rcsid[] = "$Id: nul_ng.c,v 1.11 2001/05/29 05:49:20 marka Exp $"; #endif /* @@ -49,7 +49,8 @@ static const char rcsid[] = "$Id: nul_ng.c,v 1.10 1999/01/18 07:46:59 vixie Exp /* Forward. */ static void ng_close(struct irs_ng *); -static int ng_next(struct irs_ng *, char **, char **, char **); +static int ng_next(struct irs_ng *, const char **, + const char **, const char **); static int ng_test(struct irs_ng *, const char *, const char *, const char *, const char *); @@ -62,6 +63,8 @@ struct irs_ng * irs_nul_ng(struct irs_acc *this) { struct irs_ng *ng; + UNUSED(this); + if (!(ng = memget(sizeof *ng))) { errno = ENOMEM; return (NULL); @@ -85,7 +88,13 @@ ng_close(struct irs_ng *this) { /* ARGSUSED */ static int -ng_next(struct irs_ng *this, char **host, char **user, char **domain) { +ng_next(struct irs_ng *this, const char **host, const char **user, + const char **domain) +{ + UNUSED(this); + UNUSED(host); + UNUSED(user); + UNUSED(domain); errno = ENOENT; return (-1); } @@ -94,16 +103,24 @@ static int ng_test(struct irs_ng *this, const char *name, const char *user, const char *host, const char *domain) { + UNUSED(this); + UNUSED(name); + UNUSED(user); + UNUSED(host); + UNUSED(domain); errno = ENODEV; return (-1); } static void ng_rewind(struct irs_ng *this, const char *netgroup) { + UNUSED(this); + UNUSED(netgroup); /* NOOP */ } static void ng_minimize(struct irs_ng *this) { + UNUSED(this); /* NOOP */ } diff --git a/contrib/bind/lib/irs/util.c b/contrib/bind/lib/irs/util.c index 1d097c6b8561..e37f4d98986e 100644 --- a/contrib/bind/lib/irs/util.c +++ b/contrib/bind/lib/irs/util.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: util.c,v 1.11 2000/02/04 08:28:33 vixie Exp $"; +static const char rcsid[] = "$Id: util.c,v 1.12 2001/05/29 05:49:21 marka Exp $"; #endif #include "port_before.h" @@ -89,7 +89,7 @@ make_group_list(struct irs_gr *this, const char *name, */ (*this->rewind)(this); while ((grp = (*this->next)(this)) != NULL) { - if (grp->gr_gid == basegid) + if ((gid_t)grp->gr_gid == basegid) continue; for (i = 0; grp->gr_mem[i]; i++) { if (!strcmp(grp->gr_mem[i], name)) { diff --git a/contrib/bind/lib/isc/Makefile b/contrib/bind/lib/isc/Makefile index 78453657d31c..0127c6d10c5d 100644 --- a/contrib/bind/lib/isc/Makefile +++ b/contrib/bind/lib/isc/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 8.28 2000/12/23 08:03:00 vixie Exp $ +# $Id: Makefile,v 8.30 2001/08/14 05:58:08 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -48,14 +48,14 @@ SRCS= tree.c base64.c bitncmp.c assertions.c \ ctl_p.c ctl_srvr.c ctl_clnt.c \ eventlib.c ev_connects.c ev_files.c \ ev_timers.c ev_streams.c ev_waits.c \ - movefile.c + hex.c movefile.c OBJS= tree.${O} base64.${O} bitncmp.${O} assertions.${O} \ memcluster.${O} logging.${O} heap.${O} \ ctl_p.${O} ctl_srvr.${O} ctl_clnt.${O} \ eventlib.${O} ev_connects.${O} ev_files.${O} \ ev_timers.${O} ev_streams.${O} ev_waits.${O} \ - movefile.${O} + hex.${O} movefile.${O} all: ${LIBBIND} @@ -67,7 +67,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \ -o ${THREADED}/$*.${O} -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ diff --git a/contrib/bind/lib/isc/assertions.c b/contrib/bind/lib/isc/assertions.c index b53cc0ab69c6..704801cf3bb1 100644 --- a/contrib/bind/lib/isc/assertions.c +++ b/contrib/bind/lib/isc/assertions.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: assertions.c,v 8.3 1999/01/08 19:25:14 vixie Exp $"; +static const char rcsid[] = "$Id: assertions.c,v 8.4 2001/05/29 05:49:22 marka Exp $"; #endif #include "port_before.h" @@ -34,7 +34,8 @@ static const char rcsid[] = "$Id: assertions.c,v 8.3 1999/01/08 19:25:14 vixie E * Forward. */ -static void default_assertion_failed(char *, int, assertion_type, char *, int); +static void default_assertion_failed(const char *, int, assertion_type, + const char *, int); /* * Public. @@ -50,9 +51,9 @@ set_assertion_failure_callback(assertion_failure_callback f) { __assertion_failed = f; } -char * +const char * assertion_type_to_text(assertion_type type) { - char *result; + const char *result; switch (type) { case assert_require: @@ -78,8 +79,8 @@ assertion_type_to_text(assertion_type type) { */ static void -default_assertion_failed(char *file, int line, assertion_type type, char *cond, - int print_errno) +default_assertion_failed(const char *file, int line, assertion_type type, + const char *cond, int print_errno) { fprintf(stderr, "%s:%d: %s(%s)%s%s failed.\n", file, line, assertion_type_to_text(type), cond, diff --git a/contrib/bind/lib/isc/assertions.mdoc b/contrib/bind/lib/isc/assertions.mdoc index 3d8d103e727c..863829acb126 100644 --- a/contrib/bind/lib/isc/assertions.mdoc +++ b/contrib/bind/lib/isc/assertions.mdoc @@ -1,4 +1,4 @@ -.\" $Id: assertions.mdoc,v 8.2 1999/01/08 19:25:15 vixie Exp $ +.\" $Id: assertions.mdoc,v 8.3 2001/08/08 07:50:20 marka Exp $ .\" .\"Copyright (c) 1997,1999 by Internet Software Consortium. .\" @@ -75,9 +75,9 @@ macro. If this macro's value is when .Dq "" is included, then assertions of that type will not be checked. E.g. - +.Pp .Dl #define CHECK_ENSURE 0 - +.Pp will disable checking of .Fn ENSURE and @@ -93,8 +93,7 @@ assertion types should be checked. specifies the function to call when an assertion fails. .Pp When an -.li -assertion_failure_callback +.Fn assertion_failure_callback is called, the .Fa filename and @@ -109,7 +108,7 @@ assert_ensure assert_insist assert_invariant .Ed - +.Pp and may be used by the callback to determine the type of the failing assertion. .Fa condition @@ -127,8 +126,13 @@ For example, returns the string .Dq REQUIRE . .Sh SEE ALSO -Bertrand Meyer, -.Sy Object-Oriented Software Construction, -2nd edition, Prentice\-Hall, 1997, ISBN 0\-13\-629155\-4, chapter 11. +.Rs +.%A Bertrand Meyer +.%B Object-Oriented Software Construction, 2nd edition +.%Q Prentice\-Hall +.%D 1997 +.%O ISBN 0\-13\-629155\-4 +.%P chapter 11 +.Re .Sh AUTHOR Bob Halley (ISC). diff --git a/contrib/bind/lib/isc/bitncmp.c b/contrib/bind/lib/isc/bitncmp.c index 8dadca067c92..c86db6278016 100644 --- a/contrib/bind/lib/isc/bitncmp.c +++ b/contrib/bind/lib/isc/bitncmp.c @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: bitncmp.c,v 1.6 1999/01/08 19:25:20 vixie Exp $"; +static const char rcsid[] = "$Id: bitncmp.c,v 1.7 2001/05/29 05:49:23 marka Exp $"; #endif #include "port_before.h" @@ -51,8 +51,8 @@ bitncmp(const void *l, const void *r, int n) { if (x) return (x); - lb = ((u_char *)l)[b]; - rb = ((u_char *)r)[b]; + lb = ((const u_char *)l)[b]; + rb = ((const u_char *)r)[b]; for (b = n % 8; b > 0; b--) { if ((lb & 0x80) != (rb & 0x80)) { if (lb & 0x80) diff --git a/contrib/bind/lib/isc/bitncmp.mdoc b/contrib/bind/lib/isc/bitncmp.mdoc index 4fa12e8c95f4..d3cff2e52308 100644 --- a/contrib/bind/lib/isc/bitncmp.mdoc +++ b/contrib/bind/lib/isc/bitncmp.mdoc @@ -1,4 +1,4 @@ -.\" $Id: bitncmp.mdoc,v 8.2 1999/01/08 19:25:21 vixie Exp $ +.\" $Id: bitncmp.mdoc,v 8.3 2001/08/08 07:50:21 marka Exp $ .\" .\"Copyright (c) 1996,1999 by Internet Software Consortium. .\" @@ -41,7 +41,7 @@ is lexicographically less than, equal to, or greater than when taken to be unsigned characters (this behaviour is just like that of .Xr memcmp 3 ) . .Pp -.Sy NOTE: +.Sy NOTE : .Fn Bitncmp assumes .Sy network byte order ; @@ -52,7 +52,7 @@ this means that the fourth octet of .Fn Bitncmp returns values in the manner of .Xr memcmp 3 : -.Bd -filled -offset indent +.Bd -ragged -offset indent +1 if .Dq Fa 1 is greater than @@ -75,7 +75,7 @@ where and .Dq Fa r are both interpreted as strings of unsigned characters (through bit -.Dq Fa n .) +.Dq Fa n . ) .Sh SEE ALSO .Xr memcmp 3 . .Sh AUTHOR diff --git a/contrib/bind/lib/isc/ctl_clnt.c b/contrib/bind/lib/isc/ctl_clnt.c index 4e19d2c119e6..56e50981dfb8 100644 --- a/contrib/bind/lib/isc/ctl_clnt.c +++ b/contrib/bind/lib/isc/ctl_clnt.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_clnt.c,v 8.15 2000/11/14 01:10:36 vixie Exp $"; +static const char rcsid[] = "$Id: ctl_clnt.c,v 8.17 2001/06/06 00:33:35 marka Exp $"; #endif /* not lint */ /* @@ -55,8 +55,9 @@ static const char rcsid[] = "$Id: ctl_clnt.c,v 8.15 2000/11/14 01:10:36 vixie Ex /* Macros. */ #define donefunc_p(ctx) ((ctx).donefunc != NULL) -#define arpacode_p(line) (isdigit(line[0]) && isdigit(line[1]) && \ - isdigit(line[2])) +#define arpacode_p(line) (isdigit((unsigned char)(line[0])) && \ + isdigit((unsigned char)(line[1])) && \ + isdigit((unsigned char)(line[2]))) #define arpacont_p(line) (line[3] == '-') #define arpadone_p(line) (line[3] == ' ' || line[3] == '\t' || \ line[3] == '\r' || line[3] == '\0') @@ -135,6 +136,7 @@ ctl_client(evContext lev, const struct sockaddr *cap, size_t cap_len, static const char me[] = "ctl_client"; static const int on = 1; struct ctl_cctx *ctx; + struct sockaddr *captmp; if (logger == NULL) logger = ctl_logger; @@ -168,18 +170,19 @@ ctl_client(evContext lev, const struct sockaddr *cap, size_t cap_len, } if (cap != NULL) { if (setsockopt(ctx->sock, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof on) != 0) { + (const char *)&on, sizeof on) != 0) { (*ctx->logger)(ctl_warning, "%s: setsockopt(REUSEADDR): %s", me, strerror(errno)); } - if (bind(ctx->sock, cap, cap_len) < 0) { + DE_CONST(cap, captmp); + if (bind(ctx->sock, captmp, cap_len) < 0) { (*ctx->logger)(ctl_error, "%s: bind: %s", me, strerror(errno)); goto fatal; } } - if (evConnect(lev, ctx->sock, (struct sockaddr *)sap, sap_len, + if (evConnect(lev, ctx->sock, (const struct sockaddr *)sap, sap_len, conn_done, ctx, &ctx->coID) < 0) { (*ctx->logger)(ctl_error, "%s: evConnect(fd %d): %s", me, (void *)ctx->sock, strerror(errno)); @@ -219,7 +222,7 @@ ctl_command(struct ctl_cctx *ctx, const char *cmd, size_t len, { struct ctl_tran *tran; char *pc; - int n; + unsigned int n; switch (ctx->state) { case destroyed: @@ -243,7 +246,8 @@ ctl_command(struct ctl_cctx *ctx, const char *cmd, size_t len, memcpy(tran->outbuf.text, cmd, len); tran->outbuf.used = len; for (pc = tran->outbuf.text, n = 0; n < tran->outbuf.used; pc++, n++) - if (!isascii(*pc) || !isprint(*pc)) + if (!isascii((unsigned char)*pc) || + !isprint((unsigned char)*pc)) *pc = '\040'; start_write(ctx); return (0); @@ -274,6 +278,7 @@ start_write(struct ctl_cctx *ctx) { static const char me[] = "isc/ctl_clnt::start_write"; struct ctl_tran *tran; struct iovec iov[2], *iovp = iov; + char * tmp; REQUIRE(ctx->state == connecting || ctx->state == connected); /* If there is a write in progress, don't try to write more yet. */ @@ -297,7 +302,8 @@ start_write(struct ctl_cctx *ctx) { return; /* Marshall a newline-terminated message and clock it out. */ *iovp++ = evConsIovec(tran->outbuf.text, tran->outbuf.used); - *iovp++ = evConsIovec("\r\n", 2); + DE_CONST("\r\n", tmp); + *iovp++ = evConsIovec(tmp, 2); if (evWrite(ctx->ev, ctx->sock, iov, iovp - iov, write_done, tran, &ctx->wrID) < 0) { (*ctx->logger)(ctl_error, "%s: evWrite: %s", me, @@ -387,6 +393,12 @@ conn_done(evContext ev, void *uap, int fd, struct ctl_cctx *ctx = uap; struct ctl_tran *tran; + UNUSED(ev); + UNUSED(la); + UNUSED(lalen); + UNUSED(ra); + UNUSED(ralen); + ctx->coID.opaque = NULL; if (fd < 0) { (*ctx->logger)(ctl_error, "%s: evConnect: %s", me, @@ -416,6 +428,9 @@ write_done(evContext lev, void *uap, int fd, int bytes) { struct ctl_tran *tran = (struct ctl_tran *)uap; struct ctl_cctx *ctx = tran->ctx; + UNUSED(lev); + UNUSED(fd); + ctx->wrID.opaque = NULL; if (ctx->tiID.opaque != NULL) touch_timer(ctx); @@ -459,6 +474,8 @@ readable(evContext ev, void *uap, int fd, int evmask) { ssize_t n; char *eos; + UNUSED(ev); + REQUIRE(ctx != NULL); REQUIRE(fd >= 0); REQUIRE(evmask == EV_READ); @@ -574,6 +591,10 @@ timer(evContext ev, void *uap, struct timespec due, struct timespec itv) { static const char me[] = "isc/ctl_clnt::timer"; struct ctl_cctx *ctx = uap; + UNUSED(ev); + UNUSED(due); + UNUSED(itv); + ctx->tiID.opaque = NULL; (*ctx->logger)(ctl_error, "%s: timeout after %u seconds while %s", me, ctx->timeout.tv_sec, state_names[ctx->state]); diff --git a/contrib/bind/lib/isc/ctl_p.c b/contrib/bind/lib/isc/ctl_p.c index 7d9058c6b6e7..4f22f9fab1ed 100644 --- a/contrib/bind/lib/isc/ctl_p.c +++ b/contrib/bind/lib/isc/ctl_p.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_p.c,v 8.7 2000/02/04 08:28:33 vixie Exp $"; +static const char rcsid[] = "$Id: ctl_p.c,v 8.8 2001/05/29 05:49:26 marka Exp $"; #endif /* not lint */ /* @@ -104,11 +104,30 @@ ctl_sa_ntop(const struct sockaddr *sa, { static const char me[] = "ctl_sa_ntop"; static const char punt[] = "[0].-1"; - char tmp[sizeof "255.255.255.255"]; + char tmp[INET6_ADDRSTRLEN]; switch (sa->sa_family) { + case AF_INET6: { + const struct sockaddr_in6 *in6 = + (const struct sockaddr_in6 *) sa; + + if (inet_ntop(in6->sin6_family, &in6->sin6_addr, tmp, sizeof tmp) + == NULL) { + (*logger)(ctl_error, "%s: inet_ntop(%u %04x): %s", + me, in6->sin6_family, + in6->sin6_port, strerror(errno)); + return (punt); + } + if (strlen(tmp) + sizeof "[].65535" > size) { + (*logger)(ctl_error, "%s: buffer overflow", me); + return (punt); + } + (void) sprintf(buf, "[%s].%u", tmp, ntohs(in6->sin6_port)); + return (buf); + } case AF_INET: { - const struct sockaddr_in *in = (struct sockaddr_in *) sa; + const struct sockaddr_in *in = + (const struct sockaddr_in *) sa; if (inet_ntop(in->sin_family, &in->sin_addr, tmp, sizeof tmp) == NULL) { @@ -127,8 +146,9 @@ ctl_sa_ntop(const struct sockaddr *sa, } #ifndef NO_SOCKADDR_UN case AF_UNIX: { - const struct sockaddr_un *un = (struct sockaddr_un *) sa; - int x = sizeof un->sun_path; + const struct sockaddr_un *un = + (const struct sockaddr_un *) sa; + unsigned int x = sizeof un->sun_path; if (x > size) x = size; @@ -145,12 +165,18 @@ ctl_sa_ntop(const struct sockaddr *sa, void ctl_sa_copy(const struct sockaddr *src, struct sockaddr *dst) { switch (src->sa_family) { + case AF_INET6: + *((struct sockaddr_in6 *)dst) = + *((const struct sockaddr_in6 *)src); + break; case AF_INET: - *((struct sockaddr_in *)dst) = *((struct sockaddr_in *)src); + *((struct sockaddr_in *)dst) = + *((const struct sockaddr_in *)src); break; #ifndef NO_SOCKADDR_UN case AF_UNIX: - *((struct sockaddr_un *)dst) = *((struct sockaddr_un *)src); + *((struct sockaddr_un *)dst) = + *((const struct sockaddr_un *)src); break; #endif default: diff --git a/contrib/bind/lib/isc/ctl_p.h b/contrib/bind/lib/isc/ctl_p.h index 1ebb2542367a..42aade7d669d 100644 --- a/contrib/bind/lib/isc/ctl_p.h +++ b/contrib/bind/lib/isc/ctl_p.h @@ -4,7 +4,11 @@ struct ctl_buf { }; #define MAX_LINELEN 990 /* Like SMTP. */ +#ifndef NO_SOCKADDR_UN +#define MAX_NTOP PATH_MAX +#else #define MAX_NTOP (sizeof "[255.255.255.255].65535") +#endif #define allocated_p(Buf) ((Buf).text != NULL) #define buffer_init(Buf) ((Buf).text = 0, (Buf.used) = 0) diff --git a/contrib/bind/lib/isc/ctl_srvr.c b/contrib/bind/lib/isc/ctl_srvr.c index 9beea0d42355..91a2c1b0eede 100644 --- a/contrib/bind/lib/isc/ctl_srvr.c +++ b/contrib/bind/lib/isc/ctl_srvr.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_srvr.c,v 8.24 2000/11/14 01:10:37 vixie Exp $"; +static const char rcsid[] = "$Id: ctl_srvr.c,v 8.25 2001/05/29 05:49:27 marka Exp $"; #endif /* not lint */ /* @@ -92,7 +92,7 @@ struct ctl_sess { struct ctl_buf outbuf; const struct ctl_verb * verb; u_int helpcode; - void * respctx; + const void * respctx; u_int respflags; ctl_srvrdone donefunc; void * uap; @@ -139,7 +139,7 @@ static void ctl_morehelp(struct ctl_sctx *, struct ctl_sess *, const struct ctl_verb *, const char *, - u_int, void *, void *); + u_int, const void *, void *); static void ctl_signal_done(struct ctl_sctx *, struct ctl_sess *); @@ -152,7 +152,9 @@ static const char * state_names[] = { static const char space[] = " "; -static const struct ctl_verb fakehelpverb = { "fakehelp", ctl_morehelp }; +static const struct ctl_verb fakehelpverb = { + "fakehelp", ctl_morehelp , NULL +}; /* Public. */ @@ -225,7 +227,7 @@ ctl_server(evContext lev, const struct sockaddr *sap, size_t sap_len, if (sap->sa_family != AF_UNIX) #endif if (setsockopt(ctx->sock, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof on) != 0) { + (const char *)&on, sizeof on) != 0) { (*ctx->logger)(ctl_warning, "%s: setsockopt(REUSEADDR): %s", me, strerror(errno)); @@ -234,7 +236,7 @@ ctl_server(evContext lev, const struct sockaddr *sap, size_t sap_len, char tmp[MAX_NTOP]; save_errno = errno; (*ctx->logger)(ctl_error, "%s: bind: %s: %s", - me, ctl_sa_ntop((struct sockaddr *)sap, + me, ctl_sa_ntop((const struct sockaddr *)sap, tmp, sizeof tmp, ctx->logger), strerror(save_errno)); close(ctx->sock); @@ -295,8 +297,8 @@ ctl_endserver(struct ctl_sctx *ctx) { */ void ctl_response(struct ctl_sess *sess, u_int code, const char *text, - u_int flags, void *respctx, ctl_srvrdone donefunc, void *uap, - const char *body, size_t bodylen) + u_int flags, const void *respctx, ctl_srvrdone donefunc, + void *uap, const char *body, size_t bodylen) { static const char me[] = "ctl_response"; struct iovec iov[3], *iovp = iov; @@ -327,13 +329,18 @@ ctl_response(struct ctl_sess *sess, u_int code, const char *text, sess->outbuf.used = SPRINTF((sess->outbuf.text, "%03d%c%s\r\n", code, (flags & CTL_MORE) != 0 ? '-' : ' ', text)); - for (pc = sess->outbuf.text, n = 0; n < sess->outbuf.used-2; pc++, n++) - if (!isascii(*pc) || !isprint(*pc)) + for (pc = sess->outbuf.text, n = 0; + n < (int)sess->outbuf.used-2; pc++, n++) + if (!isascii((unsigned char)*pc) || + !isprint((unsigned char)*pc)) *pc = '\040'; *iovp++ = evConsIovec(sess->outbuf.text, sess->outbuf.used); if (body != NULL) { - *iovp++ = evConsIovec((char *)body, bodylen); - *iovp++ = evConsIovec(".\r\n", 3); + char *tmp; + DE_CONST(body, tmp); + *iovp++ = evConsIovec(tmp, bodylen); + DE_CONST(".\r\n", tmp); + *iovp++ = evConsIovec(tmp, 3); } (*ctx->logger)(ctl_debug, "%s: [%d] %s", me, sess->outbuf.used, sess->outbuf.text); @@ -369,7 +376,8 @@ ctl_sendhelp(struct ctl_sess *sess, u_int code) { sess->helpcode = code; sess->verb = &fakehelpverb; - ctl_morehelp(ctx, sess, NULL, me, CTL_MORE, (void *)ctx->verbs, NULL); + ctl_morehelp(ctx, sess, NULL, me, CTL_MORE, + (const void *)ctx->verbs, NULL); } void * @@ -397,6 +405,10 @@ ctl_accept(evContext lev, void *uap, int fd, struct ctl_sess *sess = NULL; char tmp[MAX_NTOP]; + UNUSED(lev); + UNUSED(lalen); + UNUSED(ralen); + if (fd < 0) { (*ctx->logger)(ctl_error, "%s: accept: %s", me, strerror(errno)); @@ -404,7 +416,7 @@ ctl_accept(evContext lev, void *uap, int fd, } if (ctx->cur_sess == ctx->max_sess) { (*ctx->logger)(ctl_error, "%s: %s: too many control sessions", - me, ctl_sa_ntop((struct sockaddr *)rav, + me, ctl_sa_ntop((const struct sockaddr *)rav, tmp, sizeof tmp, ctx->logger)); (void) close(fd); @@ -432,11 +444,11 @@ ctl_accept(evContext lev, void *uap, int fd, sess->rdtiID.opaque = NULL; sess->respctx = NULL; sess->csctx = NULL; - if (((struct sockaddr *)rav)->sa_family == AF_UNIX) - ctl_sa_copy((struct sockaddr *)lav, + if (((const struct sockaddr *)rav)->sa_family == AF_UNIX) + ctl_sa_copy((const struct sockaddr *)lav, (struct sockaddr *)&sess->sa); else - ctl_sa_copy((struct sockaddr *)rav, + ctl_sa_copy((const struct sockaddr *)rav, (struct sockaddr *)&sess->sa); sess->donefunc = NULL; buffer_init(sess->inbuf); @@ -447,7 +459,7 @@ ctl_accept(evContext lev, void *uap, int fd, (*ctx->logger)(ctl_debug, "%s: %s: accepting (fd %d)", me, address_expr, sess->sock); (*ctx->connverb->func)(ctx, sess, ctx->connverb, "", 0, - (struct sockaddr *)rav, ctx->uctx); + (const struct sockaddr *)rav, ctx->uctx); } static void @@ -614,6 +626,10 @@ ctl_wrtimeout(evContext lev, void *uap, struct ctl_sess *sess = uap; struct ctl_sctx *ctx = sess->ctx; char tmp[MAX_NTOP]; + + UNUSED(lev); + UNUSED(due); + UNUSED(itv); REQUIRE(sess->state == writing); sess->wrtiID.opaque = NULL; @@ -638,6 +654,10 @@ ctl_rdtimeout(evContext lev, void *uap, struct ctl_sctx *ctx = sess->ctx; char tmp[MAX_NTOP]; + UNUSED(lev); + UNUSED(due); + UNUSED(itv); + REQUIRE(sess->state == reading); sess->rdtiID.opaque = NULL; (*ctx->logger)(ctl_warning, "%s: %s: timeout, closing", @@ -699,6 +719,9 @@ ctl_writedone(evContext lev, void *uap, int fd, int bytes) { char tmp[MAX_NTOP]; int save_errno = errno; + UNUSED(lev); + UNUSED(uap); + REQUIRE(sess->state == writing); REQUIRE(fd == sess->sock); REQUIRE(sess->wrtiID.opaque != NULL); @@ -731,9 +754,14 @@ ctl_writedone(evContext lev, void *uap, int fd, int bytes) { static void ctl_morehelp(struct ctl_sctx *ctx, struct ctl_sess *sess, const struct ctl_verb *verb, const char *text, - u_int respflags, void *respctx, void *uctx) + u_int respflags, const void *respctx, void *uctx) { - struct ctl_verb *this = respctx, *next = this + 1; + const struct ctl_verb *this = respctx, *next = this + 1; + + UNUSED(ctx); + UNUSED(verb); + UNUSED(text); + UNUSED(uctx); REQUIRE(!lastverb_p(this)); REQUIRE((respflags & CTL_MORE) != 0); diff --git a/contrib/bind/lib/isc/ev_connects.c b/contrib/bind/lib/isc/ev_connects.c index 537866503d05..5be432abf198 100644 --- a/contrib/bind/lib/isc/ev_connects.c +++ b/contrib/bind/lib/isc/ev_connects.c @@ -20,7 +20,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_connects.c,v 8.27 2000/11/14 01:10:37 vixie Exp $"; +static const char rcsid[] = "$Id: ev_connects.c,v 8.32 2001/07/03 13:26:35 marka Exp $"; #endif /* Import. */ @@ -30,6 +30,7 @@ static const char rcsid[] = "$Id: ev_connects.c,v 8.27 2000/11/14 01:10:37 vixie #include #include +#include #include @@ -77,7 +78,12 @@ evListen(evContext opaqueCtx, int fd, int maxconn, * incorrectly. */ if ((mode & PORT_NONBLOCK) == 0) { +#ifdef USE_FIONBIO_IOCTL + int on = 1; + OK(ioctl(fd, FIONBIO, (char *)&on)); +#else OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK)); +#endif new->flags |= EV_CONN_BLOCK; } OK(listen(fd, maxconn)); @@ -103,7 +109,7 @@ evListen(evContext opaqueCtx, int fd, int maxconn, } int -evConnect(evContext opaqueCtx, int fd, void *ra, int ralen, +evConnect(evContext opaqueCtx, int fd, const void *ra, int ralen, evConnFunc func, void *uap, evConnID *id) { evContext_p *ctx = opaqueCtx.opaque; @@ -160,8 +166,14 @@ evCancelConn(evContext opaqueCtx, evConnID id) { if (mode == -1) { if (errno != EBADF) return (-1); - } else + } else { +#ifdef USE_FIONBIO_IOCTL + int on = 1; + OK(ioctl(this->fd, FIONBIO, (char *)&on)); +#else OK(fcntl(this->fd, F_SETFL, mode | PORT_NONBLOCK)); +#endif + } } /* Unlink from ctx->conns. */ @@ -275,7 +287,8 @@ listener(evContext opaqueCtx, void *uap, int fd, int evmask) { struct sockaddr_un un; #endif } la, ra; - int new, lalen = 0, ralen; + int new; + ISC_SOCKLEN_T lalen = 0, ralen; REQUIRE((evmask & EV_READ) != 0); ralen = sizeof ra; @@ -309,13 +322,15 @@ connector(evContext opaqueCtx, void *uap, int fd, int evmask) { struct sockaddr_un un; #endif } la, ra; - int lalen, ralen; + ISC_SOCKLEN_T lalen, ralen; char buf[1]; void *conn_uap; evConnFunc conn_func; evConnID id; int socket_errno = 0; - int optlen; + ISC_SOCKLEN_T optlen; + + UNUSED(evmask); lalen = sizeof la; ralen = sizeof ra; diff --git a/contrib/bind/lib/isc/ev_files.c b/contrib/bind/lib/isc/ev_files.c index 434385c17008..c6bcab675614 100644 --- a/contrib/bind/lib/isc/ev_files.c +++ b/contrib/bind/lib/isc/ev_files.c @@ -20,7 +20,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_files.c,v 1.19 1999/10/07 20:44:04 vixie Exp $"; +static const char rcsid[] = "$Id: ev_files.c,v 1.21 2001/11/01 05:35:46 marka Exp $"; #endif #include "port_before.h" @@ -28,6 +28,7 @@ static const char rcsid[] = "$Id: ev_files.c,v 1.19 1999/10/07 20:44:04 vixie Ex #include #include +#include #include #include @@ -56,9 +57,9 @@ evSelectFD(evContext opaqueCtx, "evSelectFD(ctx %#x, fd %d, mask 0x%x, func %#x, uap %#x)\n", ctx, fd, eventmask, func, uap); if (eventmask == 0 || (eventmask & ~EV_MASK_ALL) != 0) - ERR(EINVAL); + EV_ERR(EINVAL); if (fd > ctx->highestFD) - ERR(EINVAL); + EV_ERR(EINVAL); OK(mode = fcntl(fd, F_GETFL, NULL)); /* side effect: validate fd. */ /* @@ -72,7 +73,12 @@ evSelectFD(evContext opaqueCtx, if (mode & PORT_NONBLOCK) FD_SET(fd, &ctx->nonblockBefore); else { +#ifdef USE_FIONBIO_IOCTL + int on = 1; + OK(ioctl(fd, FIONBIO, (char *)&on)); +#else OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK)); +#endif FD_CLR(fd, &ctx->nonblockBefore); } } @@ -84,7 +90,7 @@ evSelectFD(evContext opaqueCtx, * same context. */ if (id != NULL && FindFD(ctx, fd, eventmask) != NULL) - ERR(ETOOMANYREFS); + EV_ERR(ETOOMANYREFS); /* Allocate and fill. */ OKNEW(id); @@ -166,7 +172,7 @@ evDeselectFD(evContext opaqueCtx, evFileID opaqueID) { /* Get the mode. Unless the file has been closed, errors are bad. */ mode = fcntl(del->fd, F_GETFL, NULL); if (mode == -1 && errno != EBADF) - ERR(errno); + EV_ERR(errno); /* Remove from the list of files. */ if (del->prev != NULL) @@ -197,7 +203,12 @@ evDeselectFD(evContext opaqueCtx, evFileID opaqueID) { * this fcntl() fails since (a) we've already done the work * and (b) the caller didn't ask us anything about O_NONBLOCK. */ +#ifdef USE_FIONBIO_IOCTL + int off = 1; + (void) ioctl(del->fd, FIONBIO, (char *)&off); +#else (void) fcntl(del->fd, F_SETFL, mode & ~PORT_NONBLOCK); +#endif } /* diff --git a/contrib/bind/lib/isc/ev_streams.c b/contrib/bind/lib/isc/ev_streams.c index b25a666c355a..a3017205d6d2 100644 --- a/contrib/bind/lib/isc/ev_streams.c +++ b/contrib/bind/lib/isc/ev_streams.c @@ -20,7 +20,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_streams.c,v 8.21 1999/10/07 20:44:04 vixie Exp $"; +static const char rcsid[] = "$Id: ev_streams.c,v 8.22 2001/05/29 05:49:29 marka Exp $"; #endif #include "port_before.h" @@ -125,6 +125,8 @@ int evTimeRW(evContext opaqueCtx, evStreamID id, evTimerID timer) /*ARGSUSED*/ { evStream *str = id.opaque; + UNUSED(opaqueCtx); + str->timer = timer; str->flags |= EV_STR_TIMEROK; return (0); @@ -134,6 +136,8 @@ int evUntimeRW(evContext opaqueCtx, evStreamID id) /*ARGSUSED*/ { evStream *str = id.opaque; + UNUSED(opaqueCtx); + str->flags &= ~EV_STR_TIMEROK; return (0); } @@ -218,7 +222,7 @@ copyvec(evStream *str, const struct iovec *iov, int iocnt) { static void consume(evStream *str, size_t bytes) { while (bytes > 0) { - if (bytes < str->iovCur->iov_len) { + if (bytes < (size_t)str->iovCur->iov_len) { str->iovCur->iov_len -= bytes; str->iovCur->iov_base = (void *) ((u_char *)str->iovCur->iov_base + bytes); @@ -257,6 +261,8 @@ writable(evContext opaqueCtx, void *uap, int fd, int evmask) { evStream *str = uap; int bytes; + UNUSED(evmask); + bytes = writev(fd, str->iovCur, str->iovCurCount); if (bytes > 0) { if ((str->flags & EV_STR_TIMEROK) != 0) @@ -278,6 +284,8 @@ readable(evContext opaqueCtx, void *uap, int fd, int evmask) { evStream *str = uap; int bytes; + UNUSED(evmask); + bytes = readv(fd, str->iovCur, str->iovCurCount); if (bytes > 0) { if ((str->flags & EV_STR_TIMEROK) != 0) diff --git a/contrib/bind/lib/isc/ev_timers.c b/contrib/bind/lib/isc/ev_timers.c index e5e5684a5913..03436c601cae 100644 --- a/contrib/bind/lib/isc/ev_timers.c +++ b/contrib/bind/lib/isc/ev_timers.c @@ -20,7 +20,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_timers.c,v 1.30 2001/02/12 23:13:48 marka Exp $"; +static const char rcsid[] = "$Id: ev_timers.c,v 1.32 2001/11/01 05:35:47 marka Exp $"; #endif /* Import. */ @@ -201,7 +201,7 @@ evClearTimer(evContext opaqueCtx, evTimerID id) { } if (heap_element(ctx->timers, del->index) != del) - ERR(ENOENT); + EV_ERR(ENOENT); if (heap_delete(ctx->timers, del->index) < 0) return (-1); @@ -229,7 +229,7 @@ evResetTimer(evContext opaqueCtx, int result=0; if (heap_element(ctx->timers, timer->index) != timer) - ERR(ENOENT); + EV_ERR(ENOENT); old_due = timer->due; @@ -332,6 +332,9 @@ evTouchIdleTimer(evContext opaqueCtx, evTimerID id) { heap_context evCreateTimers(const evContext_p *ctx) { + + UNUSED(ctx); + return (heap_new(due_sooner, set_index, 2048)); } @@ -363,6 +366,9 @@ set_index(void *what, int index) { static void free_timer(void *what, void *uap) { evTimer *t = what; + + UNUSED(uap); + FREE(t); } @@ -388,6 +394,9 @@ idle_timeout(evContext opaqueCtx, evContext_p *ctx = opaqueCtx.opaque; idle_timer *this = uap; struct timespec idle; + + UNUSED(due); + UNUSED(inter); idle = evSubTime(ctx->lastEventTime, this->lastTouched); if (evCmpTime(idle, this->max_idle) >= 0) { diff --git a/contrib/bind/lib/isc/eventlib.c b/contrib/bind/lib/isc/eventlib.c index cea98ac933eb..0e527336ee07 100644 --- a/contrib/bind/lib/isc/eventlib.c +++ b/contrib/bind/lib/isc/eventlib.c @@ -20,7 +20,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: eventlib.c,v 1.45 2000/02/04 07:25:39 vixie Exp $"; +static const char rcsid[] = "$Id: eventlib.c,v 1.46 2001/11/01 05:35:48 marka Exp $"; #endif #include "port_before.h" @@ -193,7 +193,7 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { /* Ensure that exactly one of EV_POLL or EV_WAIT was specified. */ x = ((options & EV_POLL) != 0) + ((options & EV_WAIT) != 0); if (x != 1) - ERR(EINVAL); + EV_ERR(EINVAL); /* Get the time of day. We'll do this again after select() blocks. */ ctx->lastEventTime = evNowTime(); @@ -248,7 +248,7 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { /* Are there any events at all? */ if ((options & EV_WAIT) != 0 && !nextTimer && ctx->fdMax == -1) - ERR(ENOENT); + EV_ERR(ENOENT); /* Figure out what select()'s timeout parameter should be. */ if ((options & EV_POLL) != 0) { @@ -343,11 +343,11 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { } abort(); } - ERR(pselect_errno); + EV_ERR(pselect_errno); } if (x == 0 && (nextTimer == NULL || !timerPast) && (options & EV_POLL)) - ERR(EWOULDBLOCK); + EV_ERR(EWOULDBLOCK); ctx->fdCount = x; #ifdef EVENTLIB_TIME_CHECKS ctx->lastFdCount = x; diff --git a/contrib/bind/lib/isc/eventlib.mdoc b/contrib/bind/lib/isc/eventlib.mdoc index 202b1cb405e2..e95871cfd8af 100644 --- a/contrib/bind/lib/isc/eventlib.mdoc +++ b/contrib/bind/lib/isc/eventlib.mdoc @@ -1,4 +1,4 @@ -.\" $Id: eventlib.mdoc,v 1.20 1999/08/18 22:09:04 vixie Exp $ +.\" $Id: eventlib.mdoc,v 1.22 2001/12/28 04:24:22 marka Exp $ .\" .\"Copyright (c) 1995-1999 by Internet Software Consortium .\" @@ -70,17 +70,17 @@ .Sh SYNOPSIS .Fd #include .Ft typedef void -.Fn (*evConnFunc) "evContext ctx" "void *uap" "int fd" \ +.Fn \*(lp*evConnFunc\*(rp "evContext ctx" "void *uap" "int fd" \ "const void *la" "int lalen" "const void *ra" "int ralen" .Ft typedef void -.Fn (*evTimerFunc) "evContext ctx" "void *uap" \ +.Fn \*(lp*evTimerFunc\*(rp "evContext ctx" "void *uap" \ "struct timespec due" "struct timespec inter" .Ft typedef void -.Fn (*evFileFunc) "evContext ctx" "void *uap" "int fd" "int eventmask" +.Fn \*(lp*evFileFunc\*(rp "evContext ctx" "void *uap" "int fd" "int eventmask" .Ft typedef void -.Fn (*evStreamFunc) "evContext ctx" "void *uap" "int fd" "int bytes" +.Fn \*(lp*evStreamFunc\*(rp "evContext ctx" "void *uap" "int fd" "int bytes" .Ft typedef void -.Fn (*evWaitFunc) "evContext ctx" "void *uap" "const void *tag" +.Fn \*(lp*evWaitFunc\*(rp "evContext ctx" "void *uap" "const void *tag" .Ft int .Fn evCreate "evContext *ctx" .Ft int @@ -197,7 +197,7 @@ The function creates an event context which is needed by all the other functions in this library. All information used internally by this library is bound to this context, rather than to static storage. This makes the library -.Dq thread safe, +.Dq thread safe , and permits other library functions to use events without disrupting the application's use of events. .Pp @@ -325,7 +325,7 @@ The function adds two .Dq Fa struct timespec values and returns the result as a -.Dq Fa struct timespec. +.Dq Fa struct timespec . .Pp The function .Fn evSubTime @@ -334,7 +334,7 @@ subtracts its second argument from its first .Dq Fa struct timespec argument and returns the result as a -.Dq Fa struct timespec. +.Dq Fa struct timespec . .Pp The function .Fn evCmpTime @@ -384,15 +384,15 @@ argument. The event will be delivered at absolute time and then if time .Fa inter is not equal to -.Dq Fa evConsTime(0,0) , +.Dq Fn evConsTime 0 0 , subsequently at intervals equal to time .Fa inter . As a special case, specifying a .Fa due argument equal to -.Dq Fa evConsTime(0,0) +.Dq Fn evConsTime 0 0 means -.Dq due immediately. +.Dq due immediately . The .Fa opaqueID argument, if specified as a value other than @@ -406,9 +406,8 @@ Note that in a timer (which has an .Fa inter argument equal to -.Dq Fa evConsTime(0,0) -.\" putting the ) after the Dq Fa arg did not work well. --vix -) the user function +.Dq Fa evConsTime(0,0) ) +the user function .Fa func should deallocate any dynamic memory that is uniquely bound to the .Fa uap , @@ -711,7 +710,7 @@ initiates an outgoing connection on to destination address .Fa ra (whose length is -.Fa ralen ). +.Fa ralen ) . When the connection is complete, .Fa func will be called with @@ -719,7 +718,7 @@ will be called with as one of its arguments. The argument .Fa fd to -.Fn (*func)() +.Fn \*(lp*func\*(rp will be .Fa -1 if an error occurred that prevented this connection from completing diff --git a/contrib/bind/lib/isc/eventlib_p.h b/contrib/bind/lib/isc/eventlib_p.h index b4d7eccb0573..78f010016f7e 100644 --- a/contrib/bind/lib/isc/eventlib_p.h +++ b/contrib/bind/lib/isc/eventlib_p.h @@ -18,7 +18,7 @@ /* eventlib_p.h - private interfaces for eventlib * vix 09sep95 [initial] * - * $Id: eventlib_p.h,v 1.28 2000/02/04 08:28:34 vixie Exp $ + * $Id: eventlib_p.h,v 1.30 2001/11/01 05:35:50 marka Exp $ */ #ifndef _EVENTLIB_P_H @@ -43,8 +43,8 @@ #include #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) -#define ERR(e) return (errno = (e), -1) -#define OK(x) if ((x) < 0) ERR(errno); else (void)NULL +#define EV_ERR(e) return (errno = (e), -1) +#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ FILL(p); \ @@ -85,7 +85,7 @@ typedef struct evAccept { struct sockaddr_un un; #endif } la; - int lalen; + ISC_SOCKLEN_T lalen; union { struct sockaddr sa; struct sockaddr_in in; @@ -93,7 +93,7 @@ typedef struct evAccept { struct sockaddr_un un; #endif } ra; - int ralen; + ISC_SOCKLEN_T ralen; int ioErrno; evConn * conn; LINK(struct evAccept) link; diff --git a/contrib/bind/lib/isc/heap.mdoc b/contrib/bind/lib/isc/heap.mdoc index 6e0384db293f..4b60e91e87c0 100644 --- a/contrib/bind/lib/isc/heap.mdoc +++ b/contrib/bind/lib/isc/heap.mdoc @@ -1,4 +1,4 @@ -.\" $Id: heap.mdoc,v 8.6 2000/11/15 02:03:52 marka Exp $ +.\" $Id: heap.mdoc,v 8.7 2001/08/08 07:50:24 marka Exp $ .\" .\"Copyright (c) 1997,1999 by Internet Software Consortium. .\" @@ -15,7 +15,7 @@ .\"ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS .\"SOFTWARE. .\" -.Dd Jan 1, 1997 +.Dd January 1, 1997 .\"Os OPERATING_SYSTEM [version/release] .Os BSD 4 .Dt HEAP @SYSCALL_EXT@ @@ -52,10 +52,9 @@ These functions implement heap\-based priority queues. The user defines a priority scheme, and provides a function for comparison of the priority of heap elements -.Po see the description of the +(see the description of the .Ft heap_higher_priority_func -function pointer, below -.Pc . +function pointer, below). .Pp Each of the functions depends upon the .Ft heap_context @@ -163,9 +162,8 @@ into the appropriate place (priority\-wise) in the .Ft heap indicated by .Fa ctx -.Po a pointer to a -.Ft heap_context -.Pc . +(a pointer to a +.Ft heap_context ) . If .No non\- Ns Dv NULL , the user-defined @@ -189,7 +187,9 @@ element onward via the priority as determined by the user function pointed to by .Ft higher_priority function pointer -.Pq see description of Fn heap_new, No above . +(see description of +.Fn heap_new , +above). .Pp .Fn heap_increased .Pp @@ -233,7 +233,7 @@ a or if the .Fa higher_priority function pointer is -.Dv NULL; +.Dv NULL ; otherwise, a valid .Ft heap_context .Ns . @@ -347,14 +347,24 @@ please refer to .Sh SEE ALSO .Xr malloc 3 , .Xr realloc 3 . -.Pp -Cormen, Leiserson, and Rivest, -.Sy Introduction to Algorithms, -MIT Press / McGraw Hill, 1990, ISBN 0\-262\-03141\-8, chapter 7. -.Pp -Sedgewick, -.Sy Algorithms, -2nd ed'n, Addison\-Wesley, 1988, ISBN 0\-201\-06673\-4, chapter 11. +.Rs +.%A Cormen +.%A Leiserson +.%A Rivest +.%B Introduction to Algorithms +.%Q "MIT Press / McGraw Hill" +.%D 1990 +.%O ISBN 0\-262\-03141\-8 +.%P chapter 7 +.Re +.Rs +.%A Sedgewick +.%B Algorithms, 2nd ed'n +.%Q Addison\-Wesley +.%D 1988 +.%O ISBN 0\-201\-06673\-4 +.%P chapter 11 +.Re .\" .Sh STANDARDS .\" .Sh HISTORY .Sh AUTHORS diff --git a/contrib/bind/lib/isc/hex.c b/contrib/bind/lib/isc/hex.c new file mode 100644 index 000000000000..223979629896 --- /dev/null +++ b/contrib/bind/lib/isc/hex.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2001 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +static const char hex[17] = "0123456789abcdef"; + +int +isc_gethexstring(unsigned char *buf, size_t len, int count, FILE *fp, + int *multiline) +{ + int c, n; + unsigned char x; + char *s; + int result = count; + + x = 0; /* silence compiler */ + n = 0; + while (count > 0) { + c = fgetc(fp); + + if ((c == EOF) || + (c == '\n' && !*multiline) || + (c == '(' && *multiline) || + (c == ')' && !*multiline)) + goto formerr; + /* comment */ + if (c == ';') { + while ((c = fgetc(fp)) != EOF && c != '\n') + /* empty */ + if (c == '\n' && *multiline) + continue; + goto formerr; + } + /* white space */ + if (c == ' ' || c == '\t' || c == '\n' || c == '\r') + continue; + /* multiline */ + if ('(' == c || c == ')') { + *multiline = (c == '(' /*)*/); + continue; + } + if ((s = strchr(hex, tolower(c))) == NULL) + goto formerr; + x = (x<<4) | (s - hex); + if (++n == 2) { + if (len > 0) { + *buf++ = x; + len--; + } else + result = -1; + count--; + n = 0; + } + } + return (result); + + formerr: + if (c == '\n') + ungetc(c, fp); + return (-1); +} + +void +isc_puthexstring(FILE *fp, const unsigned char *buf, size_t buflen, + size_t len1, size_t len2, const char *sep) +{ + size_t i = 0; + + if (len1 < 4) + len1 = 4; + if (len2 < 4) + len2 = 4; + while (buflen > 0) { + fputc(hex[(buf[0]>>4)&0xf], fp); + fputc(hex[buf[0]&0xf], fp); + i += 2; + buflen--; + buf++; + if (i >= len1 && sep != NULL) { + fputs(sep, fp); + i = 0; + len1 = len2; + } + } +} + +void +isc_tohex(const unsigned char *buf, size_t buflen, char *t) { + while (buflen > 0) { + *t++ = hex[(buf[0]>>4)&0xf]; + *t++ = hex[buf[0]&0xf]; + buf++; + buflen--; + } + *t = '\0'; +} diff --git a/contrib/bind/lib/isc/logging.c b/contrib/bind/lib/isc/logging.c index 0d9037fedaaa..ca7ea04c0bcf 100644 --- a/contrib/bind/lib/isc/logging.c +++ b/contrib/bind/lib/isc/logging.c @@ -16,7 +16,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: logging.c,v 8.28 2000/12/23 08:14:54 vixie Exp $"; +static const char rcsid[] = "$Id: logging.c,v 8.31 2001/06/18 14:44:03 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -57,8 +57,9 @@ static const int syslog_priority[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static char *level_text[] = { "info: ", "notice: ", "warning: ", "error: ", - "critical: " }; +static const char *level_text[] = { + "info: ", "notice: ", "warning: ", "error: ", "critical: " +}; static void version_rename(log_channel chan) { @@ -177,6 +178,19 @@ log_close_stream(log_channel chan) { return (0); } +void +log_close_debug_channels(log_context lc) { + log_channel_list lcl; + int i; + + for (i = 0; i < lc->num_categories; i++) + for (lcl = lc->categories[i]; lcl != NULL; lcl = lcl->next) + if (lcl->channel->type == log_file && + lcl->channel->out.file.stream != NULL && + lcl->channel->flags & LOG_REQUIRE_DEBUG) + (void)log_close_stream(lcl->channel); +} + FILE * log_get_stream(log_channel chan) { if (chan == NULL || chan->type != log_file) { @@ -268,8 +282,8 @@ log_vwrite(log_context lc, int category, int level, const char *format, log_channel chan; struct timeval tv; struct tm *local_tm; - char *category_name; - char *level_str; + const char *category_name; + const char *level_str; char time_buf[256]; char level_buf[256]; @@ -582,7 +596,7 @@ log_new_syslog_channel(unsigned int flags, int level, int facility) { log_channel log_new_file_channel(unsigned int flags, int level, - char *name, FILE *stream, unsigned int versions, + const char *name, FILE *stream, unsigned int versions, unsigned long max_size) { log_channel chan; diff --git a/contrib/bind/lib/isc/logging.mdoc b/contrib/bind/lib/isc/logging.mdoc index 47d43129faba..8d8d27e918f0 100644 --- a/contrib/bind/lib/isc/logging.mdoc +++ b/contrib/bind/lib/isc/logging.mdoc @@ -1,4 +1,4 @@ -.\" $Id: logging.mdoc,v 8.4 2000/04/23 02:19:02 vixie Exp $ +.\" $Id: logging.mdoc,v 8.6 2001/12/28 04:24:23 marka Exp $ .\" .\"Copyright (c) 1995-1999 by Internet Software Consortium .\" @@ -212,7 +212,7 @@ Each category can have its own list of associated with it; we say that such a channel is .Dq in the particular category. -.Sy NOTE: +.Sy NOTE : Individual logging channels can appear in more than one category. .Pp A @@ -220,12 +220,12 @@ A is the set of all .Nm logging channels associated with the context's -.Nm categories; +.Nm categories ; thus, a particular .Nm category scheme is associated with a particular -.Nm logging context. -.Sy NOTE: +.Nm logging context . +.Sy NOTE : A logging channel may appear in more than one logging context, and in multiple categories within each logging context. .Pp @@ -325,8 +325,8 @@ type or .Dv log_file . .It Dv LOG_TRUNCATE -Truncate logging file when re-opened ( -.Fn log_open_stream +Truncate logging file when re-opened +.Fn ( log_open_stream will .Xr unlink 2 the file and then @@ -370,8 +370,8 @@ bit of the field of the logging channel structure is set), then any file with the .Dq current filename for the stream is -.X4 unlink 2 Ns -d . -.Sy NOTE: +.Xr unlink 2 Ns -d . +.Sy NOTE : If the logging file is .Em not a regular file, and either of the above operations (version numbering @@ -477,7 +477,7 @@ set and the message is not a debugging message (i.e., has a level greater than 0), then it will not be logged. Finally, if the message's priority is less important than the channel's logging level (the priority threshold), will not be logged. -.Sy NOTE: +.Sy NOTE : If a logging channel's flag has .Dv LOG_USE_CONTEXT_LEVEL set, it will use the logging context's priority, rather than its own. @@ -572,7 +572,7 @@ and .Dq Fa category_names which are supplied; the latter can be .Dv NULL . -.Sy NOTE: +.Sy NOTE : Since .Dq Fa category_names is used directly, it @@ -586,7 +586,7 @@ The function is used to free the opaque structure .Dq Va lc.opaque and its components. -.Sy NOTE: +.Sy NOTE : The .Dq Va opaque field of @@ -614,7 +614,7 @@ and is set to .Dv NULL . .Pp -.Sy NOTE: +.Sy NOTE : The function .Fn log_free_context does @@ -704,7 +704,9 @@ create a new channel of the type specified (thus, the difference in arguments); the .Dq Va type field of the new -.Dq Ft struct log_channel +.Do +.Ft struct log_channel +.Dc is always set to the appropriate value. .Pp The @@ -807,7 +809,8 @@ c) if any of or .Xr fdopen 3 fails -.Po Va errno +.Po +.Va errno is set by the call which failed .Pc . If some value other than @@ -862,7 +865,8 @@ is or .Fa category is invalid (negative or greater than or equal to -.Va lcp->num_categories ), with +.Va lcp->num_categories ) , +with .Va errno set to .Dv EINVAL ; @@ -897,7 +901,7 @@ is .Dv NULL , b) .Fa option -specifies an unknown logging option ; +specifies an unknown logging option; in either case, .Va errno is set to diff --git a/contrib/bind/lib/isc/memcluster.c b/contrib/bind/lib/isc/memcluster.c index d565c0506b9d..fcba1a3aa823 100644 --- a/contrib/bind/lib/isc/memcluster.c +++ b/contrib/bind/lib/isc/memcluster.c @@ -24,7 +24,7 @@ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: memcluster.c,v 8.20 2001/02/13 23:14:54 marka Exp $"; +static const char rcsid[] = "$Id: memcluster.c,v 8.23 2001/06/18 14:44:05 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -67,7 +67,7 @@ typedef struct { const char * file; int line; #endif - int size; + size_t size; fence_t fencepost; #endif } memcluster_element; @@ -173,6 +173,10 @@ __memget_record(size_t size, const char *file, int line) { #endif void *ret; +#if !defined(MEMCLUSTER_RECORD) + UNUSED(file); + UNUSED(line); +#endif if (freelists == NULL) if (meminit(0, 0) == -1) return (NULL); @@ -335,12 +339,19 @@ __memput_record(void *mem, size_t size, const char *file, int line) { size_t new_size = quantize(size); #if defined (DEBUGGING_MEMCLUSTER) memcluster_element *e; + memcluster_element *el; #ifdef MEMCLUSTER_RECORD - memcluster_element *prev, *el; + memcluster_element *prev; #endif - int fp; + fence_t fp; char *p; #endif + +#if !defined (MEMCLUSTER_RECORD) + UNUSED(file); + UNUSED(line); +#endif + REQUIRE(freelists != NULL); if (size == 0) { @@ -473,7 +484,7 @@ memstats(FILE *out) { for (i = 1; i <= max_size; i++) { if ((e = activelists[i]) != NULL) while (e != NULL) { - fprintf(out, "%s:%d %#p:%d\n", + fprintf(out, "%s:%d %p:%d\n", e->file != NULL ? e->file : "", e->line, (char *)e + sizeof *e, e->size); @@ -483,6 +494,18 @@ memstats(FILE *out) { #endif } +int +memactive(void) { + size_t i; + + if (stats == NULL) + return (0); + for (i = 1; i <= max_size; i++) + if (stats[i].gets != 0) + return (1); + return (0); +} + /* Private. */ /* @@ -515,7 +538,7 @@ quantize(size_t size) { #if defined(DEBUGGING_MEMCLUSTER) static void check(unsigned char *a, int value, size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) INSIST(a[i] == value); } diff --git a/contrib/bind/lib/isc/memcluster.mdoc b/contrib/bind/lib/isc/memcluster.mdoc index 82bfd71a852b..c4c458806353 100644 --- a/contrib/bind/lib/isc/memcluster.mdoc +++ b/contrib/bind/lib/isc/memcluster.mdoc @@ -1,4 +1,4 @@ -.\" $Id: memcluster.mdoc,v 8.2 1999/01/08 19:25:46 vixie Exp $ +.\" $Id: memcluster.mdoc,v 8.3 2001/08/08 07:50:27 marka Exp $ .\" .\"Copyright (c) 1995-1999 by Internet Software Consortium .\" @@ -20,7 +20,7 @@ .\"Os OPERATING_SYSTEM [version/release] .Os BSD 4 .\"Dt DOCUMENT_TITLE [section number] [volume] -.Dt memcluster 3 +.Dt MEMCLUSTER 3 .Sh NAME .Nm meminit , .Nm memget , @@ -192,7 +192,8 @@ the the value as mentioned in the .Sx INTERNALS subsection, above, the block is placed at the head of the free list of -.Va new_size Ns No -sized blocks. +.Va new_size Ns -sized +blocks. If the given .Fa size is zero or negative, then @@ -276,7 +277,7 @@ is generally equal to .Fa size , which has these implications: -.Bl -enum -offset -indent means that, for +.Bl -enum -offset indent .It For .Fa size diff --git a/contrib/bind/lib/isc/tree.c b/contrib/bind/lib/isc/tree.c index 90ba146670aa..65025e4a774d 100644 --- a/contrib/bind/lib/isc/tree.c +++ b/contrib/bind/lib/isc/tree.c @@ -1,5 +1,5 @@ #ifndef LINT -static const char rcsid[] = "$Id: tree.c,v 8.9 1999/01/08 19:25:47 vixie Exp $"; +static const char rcsid[] = "$Id: tree.c,v 8.10 2001/11/01 05:33:46 marka Exp $"; #endif /* @@ -101,7 +101,7 @@ tree_init(tree **ppr_tree) { } tree_t -tree_srch(tree **ppr_tree, int (*pfi_compare)(), tree_t p_user) { +tree_srch(tree **ppr_tree, int (*pfi_compare)(tree_t, tree_t), tree_t p_user) { ENTER("tree_srch") if (*ppr_tree) { @@ -128,7 +128,7 @@ tree_srch(tree **ppr_tree, int (*pfi_compare)(), tree_t p_user) { } tree_t -tree_add(tree **ppr_tree, int (*pfi_compare)(), +tree_add(tree **ppr_tree, int (*pfi_compare)(tree_t, tree_t), tree_t p_user, void (*pfv_uar)()) { int i_balance = FALSE; @@ -140,7 +140,7 @@ tree_add(tree **ppr_tree, int (*pfi_compare)(), } int -tree_delete(tree **ppr_p, int (*pfi_compare)(), +tree_delete(tree **ppr_p, int (*pfi_compare)(tree_t, tree_t), tree_t p_user, void (*pfv_uar)()) { int i_balance = FALSE, i_uar_called = FALSE; @@ -151,7 +151,7 @@ tree_delete(tree **ppr_p, int (*pfi_compare)(), } int -tree_trav(tree **ppr_tree, int (*pfi_uar)()) { +tree_trav(tree **ppr_tree, int (*pfi_uar)(tree_t)) { ENTER("tree_trav") if (!*ppr_tree) @@ -167,7 +167,7 @@ tree_trav(tree **ppr_tree, int (*pfi_uar)()) { } void -tree_mung(tree **ppr_tree, void (*pfv_uar)()) { +tree_mung(tree **ppr_tree, void (*pfv_uar)(tree_t)) { ENTER("tree_mung") if (*ppr_tree) { tree_mung(&(**ppr_tree).left, pfv_uar); @@ -182,7 +182,7 @@ tree_mung(tree **ppr_tree, void (*pfv_uar)()) { static tree * sprout(tree **ppr, tree_t p_data, int *pi_balance, - int (*pfi_compare)(), void (*pfv_delete)()) + int (*pfi_compare)(tree_t, tree_t), void (*pfv_delete)(tree_t)) { tree *p1, *p2, *sub; int cmp; @@ -335,8 +335,8 @@ sprout(tree **ppr, tree_t p_data, int *pi_balance, } static int -delete(tree **ppr_p, int (*pfi_compare)(), tree_t p_user, - void (*pfv_uar)(), int *pi_balance, int *pi_uar_called) +delete(tree **ppr_p, int (*pfi_compare)(tree_t, tree_t), tree_t p_user, + void (*pfv_uar)(tree_t), int *pi_balance, int *pi_uar_called) { tree *pr_q; int i_comp, i_ret; @@ -390,7 +390,7 @@ delete(tree **ppr_p, int (*pfi_compare)(), tree_t p_user, static void del(tree **ppr_r, int *pi_balance, tree **ppr_q, - void (*pfv_uar)(), int *pi_uar_called) + void (*pfv_uar)(tree_t), int *pi_uar_called) { ENTER("del") diff --git a/contrib/bind/lib/isc/tree.mdoc b/contrib/bind/lib/isc/tree.mdoc index 422344ebae32..43d1b7eb5592 100644 --- a/contrib/bind/lib/isc/tree.mdoc +++ b/contrib/bind/lib/isc/tree.mdoc @@ -1,4 +1,4 @@ -.\" $Id: tree.mdoc,v 8.2 1999/01/08 19:25:48 vixie Exp $ +.\" $Id: tree.mdoc,v 8.3 2001/08/08 07:50:28 marka Exp $ .\" .\"Copyright (c) 1995-1999 by Internet Software Consortium .\" @@ -32,15 +32,15 @@ .Ft void * .Fn tree_srch "void **tree" "int (*compare)()" "void *data" .Ft void -.Fn tree_add(tree, compare, data, del_uar) "void **tree" "int (*compare)()" \ +.Fn tree_add "void **tree" "int (*compare)()" \ "void *data" "void (*del_uar)()" .Ft int -.Fn tree_delete(tree, compare, data, del_uar) "void **tree" "int (*compare)()" \ +.Fn tree_delete "void **tree" "int (*compare)()" \ "void *data" "void (*del_uar)()" .Ft int -.Fn tree_trav(tree, trav_uar) "void **tree" "int (*trav_uar)()" +.Fn tree_trav "void **tree" "int (*trav_uar)()" .Ft void -.Fn tree_mung(tree, del_uar) "void **tree" "void (*del_uar)()" +.Fn tree_mung "void **tree" "void (*del_uar)()" .Sh DESCRIPTION These functions create and manipulate a balanced binary (AVL) tree. Each node of the tree contains the expected left & right subtree pointers, a short int @@ -88,19 +88,19 @@ returns 0. inserts or replaces a node in the specified tree. The tree specified by .Dq Fa tree is searched as in -.Fn tree_srch, +.Fn tree_srch , and if a node is found to match -.Dq Fa data, +.Dq Fa data , then the .Fn del_uar function, if non\-\s-2NULL\s+2, is called with the address of the user data block for the node (this routine should deallocate any dynamic memory which is referenced exclusively by the node); the user data pointer for the node is then replaced by the value of -.Dq Fa data. +.Dq Fa data . If no node is found to match, a new node is added (which may or may not cause a transparent rebalance operation), with a user data pointer equal to -.Dq Fa data. +.Dq Fa data . A rebalance may or may not occur, depending on where the node is added and what the rest of the tree looks like. .Fn Tree_add @@ -110,7 +110,7 @@ pointer unless catastrophe occurs in which case it will return \s-2NULL\s+2. .Pp .Fn Tree_delete deletes a node from -.Dq Fa tree. +.Dq Fa tree . A rebalance may or may not occur, depending on where the node is removed from and what the rest of the tree looks like. .Fn Tree_delete @@ -118,7 +118,7 @@ returns TRUE if a node was deleted, FALSE otherwise. .Pp .Fn Tree_trav traverses all of -.Dq Fa tree, +.Dq Fa tree , calling .Fn trav_uar with the address of each user data block. If @@ -132,7 +132,7 @@ will return TRUE. .Pp .Fn Tree_mung deletes every node in -.Dq Fa tree, +.Dq Fa tree , calling .Fn del_uar (if it is not \s-2NULL\s+2) with the user data address from each node (see diff --git a/contrib/bind/lib/nameser/Makefile b/contrib/bind/lib/nameser/Makefile index 1ab67ef39701..f283e1cdec8b 100644 --- a/contrib/bind/lib/nameser/Makefile +++ b/contrib/bind/lib/nameser/Makefile @@ -15,7 +15,7 @@ # SOFTWARE. # -# $Id: Makefile,v 8.21 2000/12/23 08:03:02 vixie Exp $ +# $Id: Makefile,v 8.22 2001/08/14 05:58:09 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -60,7 +60,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \ -o ${THREADED}/$*.${O} -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ diff --git a/contrib/bind/lib/nameser/ns_date.c b/contrib/bind/lib/nameser/ns_date.c index da593a5a1f3e..d4ec49e03501 100644 --- a/contrib/bind/lib/nameser/ns_date.c +++ b/contrib/bind/lib/nameser/ns_date.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_date.c,v 1.2 1999/10/13 16:39:35 vixie Exp $"; +static const char rcsid[] = "$Id: ns_date.c,v 1.3 2001/05/29 05:49:34 marka Exp $"; #endif /* Import. */ @@ -116,7 +116,7 @@ datepart(const char *buf, int size, int min, int max, int *errp) { int i; for (i = 0; i < size; i++) { - if (!isdigit(buf[i])) + if (!isdigit((unsigned char)(buf[i]))) *errp = 1; result = (result * 10) + buf[i] - '0'; } diff --git a/contrib/bind/lib/nameser/ns_name.c b/contrib/bind/lib/nameser/ns_name.c index 2424eed3d089..cf371b660126 100644 --- a/contrib/bind/lib/nameser/ns_name.c +++ b/contrib/bind/lib/nameser/ns_name.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_name.c,v 8.15 2000/03/30 22:53:46 vixie Exp $"; +static const char rcsid[] = "$Id: ns_name.c,v 8.17 2001/10/03 14:34:32 marka Exp $"; #endif #include "port_before.h" @@ -30,13 +30,43 @@ static const char rcsid[] = "$Id: ns_name.c,v 8.15 2000/03/30 22:53:46 vixie Exp #include #include #include +#include +#include #include "port_after.h" +#ifdef SPRINTF_CHAR +# define SPRINTF(x) strlen(sprintf/**/x) +#else +# define SPRINTF(x) ((size_t)sprintf x) +#endif + +#define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */ +#define DNS_LABELTYPE_BITSTRING 0x41 + /* Data. */ static const char digits[] = "0123456789"; +static const char digitvalue[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/ + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/ +}; + /* Forward. */ static int special(int); @@ -44,6 +74,10 @@ static int printable(int); static int dn_find(const u_char *, const u_char *, const u_char * const *, const u_char * const *); +static int encode_bitsring(const char **, const char *, + char **, char **, const char *); +static int labellen(const u_char *); +static int decode_bitstring(const char **, char *, const char *); /* Public. */ @@ -57,18 +91,20 @@ static int dn_find(const u_char *, const u_char *, * All other domains are returned in non absolute form */ int -ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { +ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) +{ const u_char *cp; char *dn, *eom; u_char c; u_int n; + int l; cp = src; dn = dst; eom = dst + dstsiz; while ((n = *cp++) != 0) { - if ((n & NS_CMPRSFLGS) != 0) { + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Some kind of compression pointer. */ errno = EMSGSIZE; return (-1); @@ -80,11 +116,31 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { } *dn++ = '.'; } - if (dn + n >= eom) { + if ((l = labellen(cp - 1)) < 0) { + errno = EMSGSIZE; /* XXX */ + return(-1); + } + if (dn + l >= eom) { errno = EMSGSIZE; return (-1); } - for ((void)NULL; n > 0; n--) { + if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) { + int m; + + if (n != DNS_LABELTYPE_BITSTRING) { + /* XXX: labellen should reject this case */ + errno = EINVAL; + return(-1); + } + if ((m = decode_bitstring((const char **)&cp, dn, eom)) < 0) + { + errno = EMSGSIZE; + return(-1); + } + dn += m; + continue; + } + for ((void)NULL; l > 0; l--) { c = *cp++; if (special(c)) { if (dn + 1 >= eom) { @@ -138,9 +194,10 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) { */ int -ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { +ns_name_pton(const char *src, u_char *dst, size_t dstsiz) +{ u_char *label, *bp, *eom; - int c, n, escaped; + int c, n, escaped, e = 0; char *cp; escaped = 0; @@ -150,7 +207,31 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { while ((c = *src++) != 0) { if (escaped) { - if ((cp = strchr(digits, c)) != NULL) { + if (c == '[') { /* start a bit string label */ + if ((cp = strchr(src, ']')) == NULL) { + errno = EINVAL; /* ??? */ + return(-1); + } + if ((e = encode_bitsring(&src, + cp + 2, + (char **)&label, + (char **)&bp, + (const char *)eom)) + != 0) { + errno = e; + return(-1); + } + escaped = 0; + label = bp++; + if ((c = *src++) == 0) + goto done; + else if (c != '.') { + errno = EINVAL; + return(-1); + } + continue; + } + else if ((cp = strchr(digits, c)) != NULL) { n = (cp - digits) * 100; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { @@ -218,6 +299,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { errno = EMSGSIZE; return (-1); } + done: if (label >= eom) { errno = EMSGSIZE; return (-1); @@ -247,28 +329,34 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { */ int -ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) { +ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) +{ const u_char *cp; u_char *dn, *eom; u_char c; u_int n; + int l; cp = src; dn = dst; eom = dst + dstsiz; while ((n = *cp++) != 0) { - if ((n & NS_CMPRSFLGS) != 0) { + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* Some kind of compression pointer. */ errno = EMSGSIZE; return (-1); } *dn++ = n; - if (dn + n >= eom) { + if ((l = labellen(cp - 1)) < 0) { errno = EMSGSIZE; return (-1); } - for ((void)NULL; n > 0; n--) { + if (dn + l >= eom) { + errno = EMSGSIZE; + return (-1); + } + for ((void)NULL; l > 0; l--) { c = *cp++; if (isupper(c)) *dn++ = tolower(c); @@ -292,7 +380,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, { const u_char *srcp, *dstlim; u_char *dstp; - int n, len, checked; + int n, len, checked, l; len = -1; checked = 0; @@ -308,16 +396,21 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, /* Check for indirection. */ switch (n & NS_CMPRSFLGS) { case 0: + case NS_TYPE_ELT: /* Limit checks. */ - if (dstp + n + 1 >= dstlim || srcp + n >= eom) { + if ((l = labellen(srcp - 1)) < 0) { + errno = EMSGSIZE; + return(-1); + } + if (dstp + l + 1 >= dstlim || srcp + l >= eom) { errno = EMSGSIZE; return (-1); } - checked += n + 1; + checked += l + 1; *dstp++ = n; - memcpy(dstp, srcp, n); - dstp += n; - srcp += n; + memcpy(dstp, srcp, l); + dstp += l; + srcp += l; break; case NS_CMPRSFLGS: @@ -397,17 +490,23 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, /* make sure the domain we are about to add is legal */ l = 0; do { + int l0; + n = *srcp; - if ((n & NS_CMPRSFLGS) != 0) { + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { errno = EMSGSIZE; return (-1); } - l += n + 1; + if ((l0 = labellen(srcp)) < 0) { + errno = EINVAL; + return(-1); + } + l += l0 + 1; if (l > MAXCDNAME) { errno = EMSGSIZE; return (-1); } - srcp += n + 1; + srcp += l0 + 1; } while (n != 0); /* from here on we need to reset compression pointer array on error */ @@ -435,9 +534,11 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, } } /* copy label to buffer */ - if (n & NS_CMPRSFLGS) { /* Should not happen. */ + if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* Should not happen. */ goto cleanup; } + n = labellen(srcp); if (dstp + 1 + n >= eob) { goto cleanup; } @@ -527,9 +628,11 @@ ns_name_rollback(const u_char *src, const u_char **dnptrs, * 0 on success, -1 (with errno set) on failure. */ int -ns_name_skip(const u_char **ptrptr, const u_char *eom) { +ns_name_skip(const u_char **ptrptr, const u_char *eom) +{ const u_char *cp; u_int n; + int l; cp = *ptrptr; while (cp < eom && (n = *cp++) != 0) { @@ -538,6 +641,13 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) { case 0: /* normal case, n == len */ cp += n; continue; + case NS_TYPE_ELT: /* EDNS0 extended label */ + if ((l = labellen(cp - 1)) < 0) { + errno = EMSGSIZE; /* XXX */ + return(-1); + } + cp += l; + continue; case NS_CMPRSFLGS: /* indirection */ cp++; break; @@ -639,8 +749,11 @@ dn_find(const u_char *domain, const u_char *msg, */ switch (n & NS_CMPRSFLGS) { case 0: /* normal case, n == len */ + n = labellen(cp - 1); /* XXX */ + if (n != *dn++) goto next; + for ((void)NULL; n > 0; n--) if (mklower(*dn++) != mklower(*cp++)) @@ -651,7 +764,6 @@ dn_find(const u_char *domain, const u_char *msg, if (*dn) continue; goto next; - case NS_CMPRSFLGS: /* indirection */ cp = msg + (((n & 0x3f) << 8) | *cp); break; @@ -661,10 +773,169 @@ dn_find(const u_char *domain, const u_char *msg, return (-1); } } - next: + next: ; sp += *sp + 1; } } errno = ENOENT; return (-1); } + +static int +decode_bitstring(const char **cpp, char *dn, const char *eom) +{ + const char *cp = *cpp; + char *beg = dn, tc; + int b, blen, plen; + + if ((blen = (*cp & 0xff)) == 0) + blen = 256; + plen = (blen + 3) / 4; + plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); + if (dn + plen >= eom) + return(-1); + + cp++; + dn += SPRINTF((dn, "\\[x")); + for (b = blen; b > 7; b -= 8, cp++) + dn += SPRINTF((dn, "%02x", *cp & 0xff)); + if (b > 4) { + tc = *cp++; + dn += SPRINTF((dn, "%02x", tc & (0xff << (8 - b)))); + } else if (b > 0) { + tc = *cp++; + dn += SPRINTF((dn, "%1x", + ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); + } + dn += SPRINTF((dn, "/%d]", blen)); + + *cpp = cp; + return(dn - beg); +} + +static int +encode_bitsring(const char **bp, const char *end, char **labelp, + char ** dst, const char *eom) +{ + int afterslash = 0; + const char *cp = *bp; + char *tp, c; + const char *beg_blen; + char *end_blen = NULL; + int value = 0, count = 0, tbcount = 0, blen = 0; + + beg_blen = end_blen = NULL; + + /* a bitstring must contain at least 2 characters */ + if (end - cp < 2) + return(EINVAL); + + /* XXX: currently, only hex strings are supported */ + if (*cp++ != 'x') + return(EINVAL); + if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ + return(EINVAL); + + for (tp = *dst + 1; cp < end && tp < eom; cp++) { + switch((c = *cp)) { + case ']': /* end of the bitstring */ + if (afterslash) { + if (beg_blen == NULL) + return(EINVAL); + blen = (int)strtol(beg_blen, &end_blen, 10); + if (*end_blen != ']') + return(EINVAL); + } + if (count) + *tp++ = ((value << 4) & 0xff); + cp++; /* skip ']' */ + goto done; + case '/': + afterslash = 1; + break; + default: + if (afterslash) { + if (!isdigit(c&0xff)) + return(EINVAL); + if (beg_blen == NULL) { + + if (c == '0') { + /* blen never begings with 0 */ + return(EINVAL); + } + beg_blen = cp; + } + } else { + if (!isxdigit(c&0xff)) + return(EINVAL); + value <<= 4; + value += digitvalue[(int)c]; + count += 4; + tbcount += 4; + if (tbcount > 256) + return(EINVAL); + if (count == 8) { + *tp++ = value; + count = 0; + } + } + break; + } + } + done: + if (cp >= end || tp >= eom) + return(EMSGSIZE); + + /* + * bit length validation: + * If a is present, the number of digits in the + * MUST be just sufficient to contain the number of bits specified + * by the . If there are insignificant bits in a final + * hexadecimal or octal digit, they MUST be zero. + * RFC 2673, Section 3.2. + */ + if (blen > 0) { + int traillen; + + if (((blen + 3) & ~3) != tbcount) + return(EINVAL); + traillen = tbcount - blen; /* between 0 and 3 */ + if (((value << (8 - traillen)) & 0xff) != 0) + return(EINVAL); + } + else + blen = tbcount; + if (blen == 256) + blen = 0; + + /* encode the type and the significant bit fields */ + **labelp = DNS_LABELTYPE_BITSTRING; + **dst = blen; + + *bp = cp; + *dst = tp; + + return(0); +} + +static int +labellen(const u_char *lp) +{ + int bitlen; + u_char l = *lp; + + if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* should be avoided by the caller */ + return(-1); + } + + if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) { + if (l == DNS_LABELTYPE_BITSTRING) { + if ((bitlen = *(lp + 1)) == 0) + bitlen = 256; + return((bitlen + 7 ) / 8 + 1); + } + return(-1); /* unknwon ELT */ + } + return(l); +} diff --git a/contrib/bind/lib/nameser/ns_parse.c b/contrib/bind/lib/nameser/ns_parse.c index 6858a914b5c7..f3f92c68d7ce 100644 --- a/contrib/bind/lib/nameser/ns_parse.c +++ b/contrib/bind/lib/nameser/ns_parse.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_parse.c,v 8.15 2000/12/23 08:14:55 vixie Exp $"; +static const char rcsid[] = "$Id: ns_parse.c,v 8.17 2001/06/20 02:50:49 marka Exp $"; #endif /* Import. */ @@ -134,7 +134,7 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { int b; /* Make section right. */ - if (section < 0 || section >= ns_s_max) + if (section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); @@ -147,38 +147,38 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { if (rrnum < handle->_rrnum) setsection(handle, section); if (rrnum > handle->_rrnum) { - b = ns_skiprr(handle->_ptr, handle->_eom, section, + b = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); if (b < 0) return (-1); - handle->_ptr += b; + handle->_msg_ptr += b; handle->_rrnum = rrnum; } /* Do the parse. */ b = dn_expand(handle->_msg, handle->_eom, - handle->_ptr, rr->name, NS_MAXDNAME); + handle->_msg_ptr, rr->name, NS_MAXDNAME); if (b < 0) return (-1); - handle->_ptr += b; - if (handle->_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) + handle->_msg_ptr += b; + if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); - NS_GET16(rr->type, handle->_ptr); - NS_GET16(rr->rr_class, handle->_ptr); + NS_GET16(rr->type, handle->_msg_ptr); + NS_GET16(rr->rr_class, handle->_msg_ptr); if (section == ns_s_qd) { rr->ttl = 0; rr->rdlength = 0; rr->rdata = NULL; } else { - if (handle->_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) + if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) RETERR(EMSGSIZE); - NS_GET32(rr->ttl, handle->_ptr); - NS_GET16(rr->rdlength, handle->_ptr); - if (handle->_ptr + rr->rdlength > handle->_eom) + NS_GET32(rr->ttl, handle->_msg_ptr); + NS_GET16(rr->rdlength, handle->_msg_ptr); + if (handle->_msg_ptr + rr->rdlength > handle->_eom) RETERR(EMSGSIZE); - rr->rdata = handle->_ptr; - handle->_ptr += rr->rdlength; + rr->rdata = handle->_msg_ptr; + handle->_msg_ptr += rr->rdlength; } if (++handle->_rrnum > handle->_counts[(int)section]) setsection(handle, (ns_sect)((int)section + 1)); @@ -194,9 +194,9 @@ setsection(ns_msg *msg, ns_sect sect) { msg->_sect = sect; if (sect == ns_s_max) { msg->_rrnum = -1; - msg->_ptr = NULL; + msg->_msg_ptr = NULL; } else { msg->_rrnum = 0; - msg->_ptr = msg->_sections[(int)sect]; + msg->_msg_ptr = msg->_sections[(int)sect]; } } diff --git a/contrib/bind/lib/nameser/ns_print.c b/contrib/bind/lib/nameser/ns_print.c index 7348e1d93579..b23f805ac8b1 100644 --- a/contrib/bind/lib/nameser/ns_print.c +++ b/contrib/bind/lib/nameser/ns_print.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_print.c,v 8.22 2001/03/26 07:04:31 marka Exp $"; +static const char rcsid[] = "$Id: ns_print.c,v 8.24 2001/06/18 06:40:45 marka Exp $"; #endif /* Import. */ @@ -169,6 +169,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_mr: case ns_t_ns: case ns_t_ptr: + case ns_t_dname: T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); break; @@ -571,8 +572,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_cert: { u_int c_type, key_tag, alg; - int n, siz; - char base64_cert[8192], *leader, tmp[40]; + int n; + unsigned int siz; + char base64_cert[8192], tmp[40]; + const char *leader; c_type = ns_get16(rdata); rdata += NS_INT16SZ; key_tag = ns_get16(rdata); rdata += NS_INT16SZ; @@ -582,7 +585,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(addstr(tmp, len, &buf, &buflen)); siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_cert) * 3/4) { - char *str = "record too long to print"; + const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); } else { @@ -656,6 +659,45 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; } + case ns_t_a6: { + struct in6_addr a; + int pbyte, pbit; + + /* prefix length */ + if (rdlen == 0) goto formerr; + len = SPRINTF((tmp, "%d ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + pbit = *rdata; + if (pbit > 128) goto formerr; + pbyte = (pbit & ~7) / 8; + rdata++; + + /* address suffix: provided only when prefix len != 128 */ + if (pbit < 128) { + if (rdata + pbyte >= edata) goto formerr; + memset(&a, 0, sizeof(a)); + memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte); + (void) inet_ntop(AF_INET6, &a, buf, buflen); + addlen(strlen(buf), &buf, &buflen); + rdata += sizeof(a) - pbyte; + } + + /* prefix name: provided only when prefix len > 0 */ + if (pbit == 0) + break; + if (rdata >= edata) goto formerr; + T(addstr(" ", 1, &buf, &buflen)); + T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); + + break; + } + + case ns_t_opt: { + len = SPRINTF((tmp, "%u bytes", class)); + T(addstr(tmp, len, &buf, &buflen)); + break; + } + default: comment = "unknown RR type"; goto hexify; @@ -667,7 +709,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, int n, m; char *p; - len = SPRINTF((tmp, "\\#(\t\t; %s", comment)); + len = SPRINTF((tmp, "\\# %u (\t; %s", edata - rdata, comment)); T(addstr(tmp, len, &buf, &buflen)); while (rdata < edata) { p = tmp; diff --git a/contrib/bind/lib/nameser/ns_sign.c b/contrib/bind/lib/nameser/ns_sign.c index 05a038a148d2..d811411d348d 100644 --- a/contrib/bind/lib/nameser/ns_sign.c +++ b/contrib/bind/lib/nameser/ns_sign.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_sign.c,v 8.9 2000/12/23 08:14:57 vixie Exp $"; +static const char rcsid[] = "$Id: ns_sign.c,v 8.10 2001/05/29 05:49:39 marka Exp $"; #endif /* Import. */ @@ -233,7 +233,7 @@ ns_sign_tcp_init(void *k, const u_char *querysig, int querysiglen, state->key = k; if (state->key->dk_alg != KEY_HMAC_MD5) return (-ns_r_badkey); - if (querysiglen > sizeof(state->sig)) + if (querysiglen > (int)sizeof(state->sig)) return (-1); memcpy(state->sig, querysig, querysiglen); state->siglen = querysiglen; diff --git a/contrib/bind/lib/nameser/ns_verify.c b/contrib/bind/lib/nameser/ns_verify.c index 0f1991356986..9fd8782ac8f0 100644 --- a/contrib/bind/lib/nameser/ns_verify.c +++ b/contrib/bind/lib/nameser/ns_verify.c @@ -16,7 +16,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: ns_verify.c,v 8.13 2000/03/29 15:55:00 bwelling Exp $"; +static const char rcsid[] = "$Id: ns_verify.c,v 8.14 2001/05/29 05:49:40 marka Exp $"; #endif /* Import. */ @@ -37,6 +37,7 @@ static const char rcsid[] = "$Id: ns_verify.c,v 8.13 2000/03/29 15:55:00 bwellin #include #include #include +#include #include #include @@ -328,7 +329,7 @@ ns_verify_tcp_init(void *k, const u_char *querysig, int querysiglen, state->key = k; if (state->key->dk_alg != KEY_HMAC_MD5) return (-ns_r_badkey); - if (querysiglen > sizeof(state->sig)) + if (querysiglen > (int)sizeof(state->sig)) return (-1); memcpy(state->sig, querysig, querysiglen); state->siglen = querysiglen; @@ -341,7 +342,7 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, { HEADER *hp = (HEADER *)msg; u_char *recstart, *rdatastart, *sigstart; - int sigfieldlen, otherfieldlen; + unsigned int sigfieldlen, otherfieldlen; u_char *cp, *eom = msg + *msglen, *cp2; char name[MAXDNAME], alg[MAXDNAME]; u_char buf[MAXDNAME]; diff --git a/contrib/bind/lib/resolv/Makefile b/contrib/bind/lib/resolv/Makefile index bfb49ec05341..3f98a2072653 100644 --- a/contrib/bind/lib/resolv/Makefile +++ b/contrib/bind/lib/resolv/Makefile @@ -13,7 +13,7 @@ # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE. -# $Id: Makefile,v 8.35 2000/12/23 08:03:03 vixie Exp $ +# $Id: Makefile,v 8.36 2001/08/14 05:58:11 marka Exp $ # these are only appropriate for BSD 4.4 or derivatives, and are used in # development. normal builds will be done in the top level directory and @@ -63,7 +63,7 @@ ${LIBBIND}: ${OBJS} ${RANLIB} ${LIBBIND} .c.${O}: - if test ! -d ${THREADED} ; then mkdir ${THREADED} ; else true ; fi + mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED} ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \ -o ${THREADED}/$*.${O} -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \ diff --git a/contrib/bind/lib/resolv/herror.c b/contrib/bind/lib/resolv/herror.c index bf4cce698e96..82655976f334 100644 --- a/contrib/bind/lib/resolv/herror.c +++ b/contrib/bind/lib/resolv/herror.c @@ -50,7 +50,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: herror.c,v 8.11 1999/10/13 16:39:39 vixie Exp $"; +static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -89,20 +89,24 @@ int h_errno; void herror(const char *s) { struct iovec iov[4], *v = iov; - extern int * __h_errno(); + char *t; if (s != NULL && *s != '\0') { - v->iov_base = (/*noconst*/ char *)s; - v->iov_len = strlen(s); + DE_CONST(s, t); + v->iov_base = t; + v->iov_len = strlen(t); v++; - v->iov_base = ": "; + DE_CONST(": ", t); + v->iov_base = t; v->iov_len = 2; v++; } - v->iov_base = (char *)hstrerror(*__h_errno()); + DE_CONST(hstrerror(*__h_errno()), t); + v->iov_base = t; v->iov_len = strlen(v->iov_base); v++; - v->iov_base = "\n"; + DE_CONST("\n", t); + v->iov_base = t; v->iov_len = 1; writev(STDERR_FILENO, iov, (v - iov) + 1); } diff --git a/contrib/bind/lib/resolv/res_debug.c b/contrib/bind/lib/resolv/res_debug.c index cff647320c14..9b61e11b450f 100644 --- a/contrib/bind/lib/resolv/res_debug.c +++ b/contrib/bind/lib/resolv/res_debug.c @@ -95,7 +95,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_debug.c,v 8.38 2001/02/13 23:12:56 marka Exp $"; +static const char rcsid[] = "$Id: res_debug.c,v 8.45 2001/12/19 12:05:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -187,7 +187,12 @@ do_section(const res_state statp, ns_rr_name(rr), p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); - else { + else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { + u_int32_t ttl = ns_rr_ttl(rr); + fprintf(file, + "; EDNS: version: %u, udp=%u, flags=%04x\n", + (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); + } else { n = ns_sprintrr(handle, &rr, NULL, NULL, buf, buflen); if (n < 0) { @@ -356,32 +361,32 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) { * C_ANY, but you can't have any records of that class in the database.) */ const struct res_sym __p_class_syms[] = { - {C_IN, "IN"}, - {C_CHAOS, "CHAOS"}, - {C_HS, "HS"}, - {C_HS, "HESIOD"}, - {C_ANY, "ANY"}, - {C_NONE, "NONE"}, - {C_IN, (char *)0} + {C_IN, "IN", (char *)0}, + {C_CHAOS, "CHAOS", (char *)0}, + {C_HS, "HS", (char *)0}, + {C_HS, "HESIOD", (char *)0}, + {C_ANY, "ANY", (char *)0}, + {C_NONE, "NONE", (char *)0}, + {C_IN, (char *)0, (char *)0} }; /* * Names of message sections. */ const struct res_sym __p_default_section_syms[] = { - {ns_s_qd, "QUERY"}, - {ns_s_an, "ANSWER"}, - {ns_s_ns, "AUTHORITY"}, - {ns_s_ar, "ADDITIONAL"}, - {0, (char *)0} + {ns_s_qd, "QUERY", (char *)0}, + {ns_s_an, "ANSWER", (char *)0}, + {ns_s_ns, "AUTHORITY", (char *)0}, + {ns_s_ar, "ADDITIONAL", (char *)0}, + {0, (char *)0, (char *)0} }; const struct res_sym __p_update_section_syms[] = { - {S_ZONE, "ZONE"}, - {S_PREREQ, "PREREQUISITE"}, - {S_UPDATE, "UPDATE"}, - {S_ADDT, "ADDITIONAL"}, - {0, (char *)0} + {S_ZONE, "ZONE", (char *)0}, + {S_PREREQ, "PREREQUISITE", (char *)0}, + {S_UPDATE, "UPDATE", (char *)0}, + {S_ADDT, "ADDITIONAL", (char *)0}, + {0, (char *)0, (char *)0} }; const struct res_sym __p_key_syms[] = { @@ -536,7 +541,17 @@ sym_ntop(const struct res_sym *syms, int number, int *success) { */ const char * p_type(int type) { - return (sym_ntos(__p_type_syms, type, (int *)0)); + int success; + const char *result; + static char typebuf[20]; + + result = sym_ntos(__p_type_syms, type, &success); + if (success) + return (result); + if (type < 0 || type > 0xfff) + return ("BADTYPE"); + sprintf(typebuf, "TYPE%d", type); + return (typebuf); } /* @@ -562,7 +577,17 @@ p_section(int section, int opcode) { */ const char * p_class(int class) { - return (sym_ntos(__p_class_syms, class, (int *)0)); + int success; + const char *result; + static char classbuf[20]; + + result = sym_ntos(__p_class_syms, class, &success); + if (success) + return (result); + if (class < 0 || class > 0xfff) + return ("BADCLASS"); + sprintf(classbuf, "CLASS%d", class); + return (classbuf); } /* @@ -585,6 +610,24 @@ p_option(u_long option) { case RES_DNSRCH: return "dnsrch"; case RES_INSECURE1: return "insecure1"; case RES_INSECURE2: return "insecure2"; + case RES_NOALIASES: return "noaliases"; + case RES_USE_INET6: return "inet6"; +#ifdef RES_USE_EDNS0 /* KAME extension */ + case RES_USE_EDNS0: return "edns0"; +#endif +#ifdef RES_USE_A6 + case RES_USE_A6: return "a6"; +#endif +#ifdef RES_USE_DNAME + case RES_USE_DNAME: return "dname"; +#endif +#ifdef RES_USE_DNSSEC + case RES_USE_DNSSEC: return "dnssec"; +#endif +#ifdef RES_NOTLDQUERY + case RES_NOTLDQUERY: return "no-tld-query"; +#endif + /* XXX nonreentrant */ default: sprintf(nbuf, "?0x%lx?", (u_long)option); return (nbuf); @@ -651,14 +694,14 @@ precsize_aton(strptr) cp = *strptr; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) mval = mval * 10 + (*cp++ - '0'); if (*cp == '.') { /* centimeters */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { cmval = (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { cmval += (*cp++ - '0'); } } @@ -692,44 +735,44 @@ latlon2ul(latlonstrptr,which) cp = *latlonstrptr; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) deg = deg * 10 + (*cp++ - '0'); - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; - if (!(isdigit(*cp))) + if (!(isdigit((unsigned char)*cp))) goto fndhemi; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) min = min * 10 + (*cp++ - '0'); - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; - if (!(isdigit(*cp))) + if (!(isdigit((unsigned char)*cp))) goto fndhemi; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) secs = secs * 10 + (*cp++ - '0'); if (*cp == '.') { /* decimal seconds */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac = (*cp++ - '0') * 100; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac += (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { secsfrac += (*cp++ - '0'); } } } } - while (!isspace(*cp)) /* if any trailing garbage */ + while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ cp++; - while (isspace(*cp)) + while (isspace((unsigned char)*cp)) cp++; fndhemi: @@ -767,10 +810,10 @@ latlon2ul(latlonstrptr,which) cp++; /* skip the hemisphere */ - while (!isspace(*cp)) /* if any trailing garbage */ + while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ cp++; - while (isspace(*cp)) /* move to next field */ + while (isspace((unsigned char)*cp)) /* move to next field */ cp++; *latlonstrptr = cp; @@ -828,14 +871,14 @@ loc_aton(ascii, binary) if (*cp == '+') cp++; - while (isdigit(*cp)) + while (isdigit((unsigned char)*cp)) altmeters = altmeters * 10 + (*cp++ - '0'); if (*cp == '.') { /* decimal meters */ cp++; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { altfrac = (*cp++ - '0') * 10; - if (isdigit(*cp)) { + if (isdigit((unsigned char)*cp)) { altfrac += (*cp++ - '0'); } } @@ -843,10 +886,10 @@ loc_aton(ascii, binary) alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) @@ -854,10 +897,10 @@ loc_aton(ascii, binary) siz = precsize_aton(&cp); - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) @@ -865,10 +908,10 @@ loc_aton(ascii, binary) hp = precsize_aton(&cp); - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ cp++; - while (isspace(*cp) && (cp < maxcp)) + while (isspace((unsigned char)*cp) && (cp < maxcp)) cp++; if (cp >= maxcp) @@ -896,14 +939,15 @@ loc_ntoa(binary, ascii) const u_char *binary; char *ascii; { - static char *error = "?"; + static const char *error = "?"; static char tmpbuf[sizeof "1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"]; const u_char *cp = binary; int latdeg, latmin, latsec, latsecfrac; int longdeg, longmin, longsec, longsecfrac; - char northsouth, eastwest, *altsign; + char northsouth, eastwest; + const char *altsign; int altmeters, altfrac; const u_int32_t referencealt = 100000 * 100; @@ -975,24 +1019,24 @@ loc_ntoa(binary, ascii) altfrac = altval % 100; altmeters = (altval / 100); - if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL) - sizestr = error; - if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL) - hpstr = error; - if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) - vpstr = error; + sizestr = strdup(precsize_ntoa(sizeval)); + hpstr = strdup(precsize_ntoa(hpval)); + vpstr = strdup(precsize_ntoa(vpval)); sprintf(ascii, "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm", latdeg, latmin, latsec, latsecfrac, northsouth, longdeg, longmin, longsec, longsecfrac, eastwest, - altsign, altmeters, altfrac, sizestr, hpstr, vpstr); + altsign, altmeters, altfrac, + (sizestr != NULL) ? sizestr : error, + (hpstr != NULL) ? hpstr : error, + (vpstr != NULL) ? vpstr : error); - if (sizestr != error) + if (sizestr != NULL) free(sizestr); - if (hpstr != error) + if (hpstr != NULL) free(hpstr); - if (vpstr != error) + if (vpstr != NULL) free(vpstr); return (ascii); @@ -1048,3 +1092,47 @@ p_secstodate (u_long secs) { time->tm_hour, time->tm_min, time->tm_sec); return (output); } + +u_int16_t +res_nametoclass(const char *buf, int *successp) { + unsigned long result; + char *endptr; + int success; + + result = sym_ston(__p_class_syms, buf, &success); + if (success) + goto done; + + if (strncasecmp(buf, "CLASS", 5) != 0 || + !isdigit((unsigned char)buf[5])) + goto done; + result = strtoul(buf + 5, &endptr, 10); + if (*endptr == '\0' && result <= 0xffff) + success = 1; + done: + if (successp) + *successp = success; + return (result); +} + +u_int16_t +res_nametotype(const char *buf, int *successp) { + unsigned long result; + char *endptr; + int success; + + result = sym_ston(__p_type_syms, buf, &success); + if (success) + goto done; + + if (strncasecmp(buf, "type", 4) != 0 || + !isdigit((unsigned char)buf[4])) + goto done; + result = strtoul(buf + 4, &endptr, 10); + if (*endptr == '\0' && result <= 0xffff) + success = 1; + done: + if (successp) + *successp = success; + return (result); +} diff --git a/contrib/bind/lib/resolv/res_findzonecut.c b/contrib/bind/lib/resolv/res_findzonecut.c index 2e8df2cc18a0..02a28da9f304 100644 --- a/contrib/bind/lib/resolv/res_findzonecut.c +++ b/contrib/bind/lib/resolv/res_findzonecut.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_findzonecut.c,v 8.12 2000/11/22 01:20:44 marka Exp $"; +static const char rcsid[] = "$Id: res_findzonecut.c,v 8.15 2001/11/01 05:21:22 marka Exp $"; #endif /* not lint */ /* @@ -78,13 +78,13 @@ static void free_nsrr(rrset_ns *, rr_ns *); static rr_ns * find_ns(rrset_ns *, const char *); static int do_query(res_state, const char *, ns_class, ns_type, u_char *, ns_msg *); -static void dprintf(const char *, ...); +static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2); /* Macros. */ #define DPRINTF(x) do {\ int save_errno = errno; \ - if ((statp->options & RES_DEBUG) != 0) dprintf x; \ + if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \ errno = save_errno; \ } while (0) @@ -527,12 +527,14 @@ free_nsrrset(rrset_ns *nsrrsp) { static void free_nsrr(rrset_ns *nsrrsp, rr_ns *nsrr) { rr_a *arr; + char *tmp; while ((arr = HEAD(nsrr->addrs)) != NULL) { UNLINK(nsrr->addrs, arr, link); free(arr); } - free((char *)nsrr->name); + DE_CONST(nsrr->name, tmp); + free(tmp); UNLINK(*nsrrsp, nsrr, link); free(nsrr); } @@ -590,7 +592,7 @@ do_query(res_state statp, const char *dname, ns_class class, ns_type qtype, } static void -dprintf(const char *fmt, ...) { +res_dprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/contrib/bind/lib/resolv/res_init.c b/contrib/bind/lib/resolv/res_init.c index 8c63351e1cd2..8dc72f4682ff 100644 --- a/contrib/bind/lib/resolv/res_init.c +++ b/contrib/bind/lib/resolv/res_init.c @@ -70,7 +70,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$Id: res_init.c,v 8.19 2001/03/08 03:57:16 marka Exp $"; +static const char rcsid[] = "$Id: res_init.c,v 8.28 2002/01/30 01:07:35 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -85,14 +85,19 @@ static const char rcsid[] = "$Id: res_init.c,v 8.19 2001/03/08 03:57:16 marka Ex #include #include -#include #include #include #include #include +#include #include "port_after.h" +/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */ +#include + +#include "res_private.h" + /* Options. Should all be left alone. */ #define RESOLVSORT #define DEBUG @@ -164,6 +169,9 @@ __res_vinit(res_state statp, int preinit) { statp->id = res_randomid(); } + if ((statp->options & RES_INIT) != 0) + res_ndestroy(statp); + #ifdef USELOOPBACK statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); #else @@ -171,6 +179,9 @@ __res_vinit(res_state statp, int preinit) { #endif statp->nsaddr.sin_family = AF_INET; statp->nsaddr.sin_port = htons(NAMESERVER_PORT); +#ifdef HAVE_SA_LEN + statp->nsaddr.sin_len = sizeof(struct sockaddr_in); +#endif statp->nscount = 1; statp->ndots = 1; statp->pfcode = 0; @@ -179,6 +190,13 @@ __res_vinit(res_state statp, int preinit) { statp->qhook = NULL; statp->rhook = NULL; statp->_u._ext.nscount = 0; + statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext)); + if (statp->_u._ext.ext != NULL) { + memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext)); + statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; + strcpy(statp->_u._ext.ext->nsuffix, "ip6.int"); + strcpy(statp->_u._ext.ext->bsuffix, "ip6.arpa"); + } #ifdef RESOLVSORT statp->nsort = 0; #endif @@ -284,17 +302,36 @@ __res_vinit(res_state statp, int preinit) { } /* read nameservers to query */ if (MATCH(buf, "nameserver") && nserv < MAXNS) { - struct in_addr a; + struct addrinfo hints, *ai; + char sbuf[NI_MAXSERV]; + const size_t minsiz = + sizeof(statp->_u._ext.ext->nsaddrs[0]); cp = buf + sizeof("nameserver") - 1; while (*cp == ' ' || *cp == '\t') cp++; - if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { - statp->nsaddr_list[nserv].sin_addr = a; - statp->nsaddr_list[nserv].sin_family = AF_INET; - statp->nsaddr_list[nserv].sin_port = - htons(NAMESERVER_PORT); - nserv++; + cp[strcspn(cp, ";# \t\n")] = '\0'; + if ((*cp != '\0') && (*cp != '\n')) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + hints.ai_flags = AI_NUMERICHOST; + sprintf(sbuf, "%u", NAMESERVER_PORT); + if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 && + ai->ai_addrlen <= minsiz) { + if (statp->_u._ext.ext != NULL) { + memcpy(&statp->_u._ext.ext->nsaddrs[nserv], + ai->ai_addr, ai->ai_addrlen); + } + if (ai->ai_addrlen <= + sizeof(statp->nsaddr_list[nserv])) { + memcpy(&statp->nsaddr_list[nserv], + ai->ai_addr, ai->ai_addrlen); + } else + statp->nsaddr_list[nserv].sin_family = 0; + freeaddrinfo(ai); + nserv++; + } } continue; } @@ -310,7 +347,7 @@ __res_vinit(res_state statp, int preinit) { break; net = cp; while (*cp && !ISSORTMASK(*cp) && *cp != ';' && - isascii(*cp) && !isspace(*cp)) + isascii(*cp) && !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; @@ -320,7 +357,8 @@ __res_vinit(res_state statp, int preinit) { *cp++ = n; net = cp; while (*cp && *cp != ';' && - isascii(*cp) && !isspace(*cp)) + isascii(*cp) && + !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; @@ -346,8 +384,7 @@ __res_vinit(res_state statp, int preinit) { continue; } } - - if (nserv > 1) + if (nserv > 1) statp->nscount = nserv; #ifdef RESOLVSORT statp->nsort = nsort; @@ -404,9 +441,11 @@ __res_vinit(res_state statp, int preinit) { } static void -res_setoptions(res_state statp, const char *options, const char *source) { +res_setoptions(res_state statp, const char *options, const char *source) +{ const char *cp = options; int i; + struct __res_state_ext *ext = statp->_u._ext.ext; #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -449,6 +488,11 @@ res_setoptions(res_state statp, const char *options, const char *source) { } printf(";;\tdebug\n"); #endif + } else if (!strncmp(cp, "no_tld_query", + sizeof("no_tld_query") - 1) || + !strncmp(cp, "no-tld-query", + sizeof("no-tld-query") - 1)) { + statp->options |= RES_NOTLDQUERY; } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { statp->options |= RES_USE_INET6; } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) { @@ -456,9 +500,52 @@ res_setoptions(res_state statp, const char *options, const char *source) { } else if (!strncmp(cp, "no-check-names", sizeof("no-check-names") - 1)) { statp->options |= RES_NOCHECKNAME; - } else { + } +#ifdef RES_USE_EDNS0 + else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { + statp->options |= RES_USE_EDNS0; + } +#endif + else if (!strncmp(cp, "a6", sizeof("a6") - 1)) { + statp->options |= RES_USE_A6; + } + else if (!strncmp(cp, "dname", sizeof("dname") - 1)) { + statp->options |= RES_USE_DNAME; + } + else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) { + if (ext == NULL) + goto skip; + cp += sizeof("nibble:") - 1; + i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); + strncpy(ext->nsuffix, cp, i); + ext->nsuffix[i] = '\0'; + } + else if (!strncmp(cp, "bitstring:", sizeof("bitstring:") - 1)) { + if (ext == NULL) + goto skip; + cp += sizeof("bitstring:") - 1; + i = MIN(strcspn(cp, " \t"), sizeof(ext->bsuffix) - 1); + strncpy(ext->bsuffix, cp, i); + ext->bsuffix[i] = '\0'; + } + else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) { + cp += sizeof("v6revmode:") - 1; + if (!strncmp(cp, "nibble", sizeof("nibble") - 1)) { + statp->options &= ~RES_NO_NIBBLE; + statp->options |= RES_NO_BITSTRING; + } else if (!strncmp(cp, "bitstring", + sizeof("bitstring") - 1)) { + statp->options |= RES_NO_NIBBLE; + statp->options &= ~RES_NO_BITSTRING; + } else if (!strncmp(cp, "both", sizeof("both") - 1)) { + statp->options &= + ~(RES_NO_NIBBLE|RES_NO_BITSTRING); + } + } + else { /* XXX - print a warning here? */ } + skip: /* skip to next run of spaces */ while (*cp && *cp != ' ' && *cp != '\t') cp++; @@ -512,3 +599,123 @@ res_nclose(res_state statp) { } } } + +void +res_ndestroy(res_state statp) { + res_nclose(statp); + if (statp->_u._ext.ext != NULL) + free(statp->_u._ext.ext); + statp->options &= ~RES_INIT; + statp->_u._ext.ext = NULL; +} + +const char * +res_get_nibblesuffix(res_state statp) { + if (statp->_u._ext.ext) + return (statp->_u._ext.ext->nsuffix); + return ("ip6.int"); +} + +const char * +res_get_bitstringsuffix(res_state statp) { + if (statp->_u._ext.ext) + return (statp->_u._ext.ext->bsuffix); + return ("ip6.arpa"); +} + +void +res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) { + int i, nserv; + size_t size; + + /* close open servers */ + res_nclose(statp); + + /* cause rtt times to be forgotten */ + statp->_u._ext.nscount = 0; + + nserv = 0; + for (i = 0; i < cnt && nserv < MAXNS; i++) { + switch (set->sin.sin_family) { + case AF_INET: + size = sizeof(set->sin); + if (statp->_u._ext.ext) + memcpy(&statp->_u._ext.ext->nsaddrs[nserv], + &set->sin, size); + if (size <= sizeof(statp->nsaddr_list[nserv])) + memcpy(&statp->nsaddr_list[nserv], + &set->sin, size); + else + statp->nsaddr_list[nserv].sin_family = 0; + nserv++; + break; + +#ifdef HAS_INET6_STRUCTS + case AF_INET6: + size = sizeof(set->sin6); + if (statp->_u._ext.ext) + memcpy(&statp->_u._ext.ext->nsaddrs[nserv], + &set->sin6, size); + if (size <= sizeof(statp->nsaddr_list[nserv])) + memcpy(&statp->nsaddr_list[nserv], + &set->sin6, size); + else + statp->nsaddr_list[nserv].sin_family = 0; + nserv++; + break; +#endif + + default: + break; + } + set++; + } + statp->nscount = nserv; + +} + +int +res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) { + int i; + size_t size; + u_int16_t family; + + for (i = 0; i < statp->nscount && i < cnt; i++) { + if (statp->_u._ext.ext) + family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family; + else + family = statp->nsaddr_list[i].sin_family; + + switch (family) { + case AF_INET: + size = sizeof(set->sin); + if (statp->_u._ext.ext) + memcpy(&set->sin, + &statp->_u._ext.ext->nsaddrs[i], + size); + else + memcpy(&set->sin, &statp->nsaddr_list[i], + size); + break; + +#ifdef HAS_INET6_STRUCTS + case AF_INET6: + size = sizeof(set->sin6); + if (statp->_u._ext.ext) + memcpy(&set->sin6, + &statp->_u._ext.ext->nsaddrs[i], + size); + else + memcpy(&set->sin6, &statp->nsaddr_list[i], + size); + break; +#endif + + default: + set->sin.sin_family = 0; + break; + } + set++; + } + return (statp->nscount); +} diff --git a/contrib/bind/lib/resolv/res_mkquery.c b/contrib/bind/lib/resolv/res_mkquery.c index 17b1ccf401c8..7041227ac9ec 100644 --- a/contrib/bind/lib/resolv/res_mkquery.c +++ b/contrib/bind/lib/resolv/res_mkquery.c @@ -70,7 +70,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_mkquery.c,v 8.12 1999/10/13 16:39:40 vixie Exp $"; +static const char rcsid[] = "$Id: res_mkquery.c,v 8.14 2001/09/24 13:50:27 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -109,6 +109,8 @@ res_nmkquery(res_state statp, register int n; u_char *dnptrs[20], **dpp, **lastdnptr; + UNUSED(newrr_in); + #ifdef DEBUG if (statp->options & RES_DEBUG) printf(";; res_nmkquery(%s, %s, %s, %s)\n", @@ -154,7 +156,7 @@ res_nmkquery(res_state statp, * Make an additional record for completion domain. */ buflen -= RRFIXEDSZ; - n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr); + n = dn_comp((const char *)data, cp, buflen, dnptrs, lastdnptr); if (n < 0) return (-1); cp += n; @@ -197,3 +199,60 @@ res_nmkquery(res_state statp, } return (cp - buf); } + +#ifdef RES_USE_EDNS0 +/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */ +#ifndef T_OPT +#define T_OPT 41 +#endif + +int +res_nopt(statp, n0, buf, buflen, anslen) + res_state statp; + int n0; + u_char *buf; /* buffer to put query */ + int buflen; /* size of buffer */ + int anslen; /* answer buffer length */ +{ + register HEADER *hp; + register u_char *cp; + u_int16_t flags = 0; + +#ifdef DEBUG + if ((statp->options & RES_DEBUG) != 0) + printf(";; res_nopt()\n"); +#endif + + hp = (HEADER *) buf; + cp = buf + n0; + buflen -= n0; + + if (buflen < 1 + RRFIXEDSZ) + return -1; + + *cp++ = 0; /* "." */ + buflen--; + + __putshort(T_OPT, cp); /* TYPE */ + cp += INT16SZ; + __putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */ + cp += INT16SZ; + *cp++ = NOERROR; /* extended RCODE */ + *cp++ = 0; /* EDNS version */ + if (statp->options & RES_USE_DNSSEC) { +#ifdef DEBUG + if (statp->options & RES_DEBUG) + printf(";; res_opt()... ENDS0 DNSSEC\n"); +#endif + flags |= NS_OPT_DNSSEC_OK; + } + __putshort(flags, cp); + cp += INT16SZ; + __putshort(0, cp); /* RDLEN */ + cp += INT16SZ; + hp->arcount = htons(ntohs(hp->arcount) + 1); + buflen -= RRFIXEDSZ; + + return cp - buf; +} +#endif diff --git a/contrib/bind/lib/resolv/res_mkupdate.c b/contrib/bind/lib/resolv/res_mkupdate.c index ecf66dd9739f..6071360e0b51 100644 --- a/contrib/bind/lib/resolv/res_mkupdate.c +++ b/contrib/bind/lib/resolv/res_mkupdate.c @@ -21,7 +21,7 @@ */ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_mkupdate.c,v 1.25 2000/11/22 01:20:46 marka Exp $"; +static const char rcsid[] = "$Id: res_mkupdate.c,v 1.26 2001/05/29 05:49:47 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -328,7 +328,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { break; case T_WKS: { char bm[MAXPORT/8]; - int maxbm = 0; + unsigned int maxbm = 0; if (!getword_str(buf2, sizeof buf2, &startp, endp)) return (-1); @@ -890,7 +890,7 @@ struct valuelist { }; static struct valuelist *servicelist, *protolist; -void +static void res_buildservicelist() { struct servent *sp; struct valuelist *slp; @@ -936,7 +936,7 @@ res_destroyservicelist() { } void -res_buildprotolist() { +res_buildprotolist(void) { struct protoent *pp; struct valuelist *slp; @@ -965,7 +965,7 @@ res_buildprotolist() { } void -res_destroyprotolist() { +res_destroyprotolist(void) { struct valuelist *plp, *plp_next; for (plp = protolist; plp != NULL; plp = plp_next) { diff --git a/contrib/bind/lib/resolv/res_private.h b/contrib/bind/lib/resolv/res_private.h new file mode 100644 index 000000000000..2c7fa5e2a8ec --- /dev/null +++ b/contrib/bind/lib/resolv/res_private.h @@ -0,0 +1,20 @@ +#ifndef res_private_h +#define res_private_h + +struct __res_state_ext { + union res_sockaddr_union nsaddrs[MAXNS]; + struct sort_list { + int af; + union { + struct in_addr ina; + struct in6_addr in6a; + } addr, mask; + } sort_list[MAXRESOLVSORT]; + char nsuffix[64]; + char bsuffix[64]; +}; + +extern int +res_ourserver_p(const res_state statp, const struct sockaddr *sa); + +#endif diff --git a/contrib/bind/lib/resolv/res_query.c b/contrib/bind/lib/resolv/res_query.c index 3147f1ea19e1..61f5df9bc713 100644 --- a/contrib/bind/lib/resolv/res_query.c +++ b/contrib/bind/lib/resolv/res_query.c @@ -70,7 +70,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $"; +static const char rcsid[] = "$Id: res_query.c,v 8.23 2001/09/24 13:50:29 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -117,7 +117,11 @@ res_nquery(res_state statp, u_char buf[MAXPACKET]; HEADER *hp = (HEADER *) answer; int n; + u_int oflags; + oflags = statp->_flags; + +again: hp->rcode = NOERROR; /* default */ #ifdef DEBUG @@ -127,6 +131,11 @@ res_nquery(res_state statp, n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL, buf, sizeof(buf)); +#ifdef RES_USE_EDNS0 + if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 && + (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0) + n = res_nopt(statp, n, buf, sizeof(buf), anslen); +#endif if (n <= 0) { #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -137,6 +146,16 @@ res_nquery(res_state statp, } n = res_nsend(statp, buf, n, answer, anslen); if (n < 0) { +#ifdef RES_USE_EDNS0 + /* if the query choked with EDNS0, retry without EDNS0 */ + if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0 && + ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) { + statp->_flags |= RES_F_EDNS0ERR; + if (statp->options & RES_DEBUG) + printf(";; res_nquery: retry without EDNS0\n"); + goto again; + } +#endif #ifdef DEBUG if (statp->options & RES_DEBUG) printf(";; res_query: send error\n"); @@ -193,6 +212,7 @@ res_nsearch(res_state statp, int trailing_dot, ret, saved_herrno; int got_nodata = 0, got_servfail = 0, root_on_list = 0; int tried_as_is = 0; + int searched = 0; errno = 0; RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */ @@ -236,6 +256,7 @@ res_nsearch(res_state statp, for (domain = (const char * const *)statp->dnsrch; *domain && !done; domain++) { + searched = 1; if (domain[0][0] == '\0' || (domain[0][0] == '.' && domain[0][1] == '\0')) @@ -293,11 +314,11 @@ res_nsearch(res_state statp, } /* - * If the name has any dots at all, and no earlier 'as-is' query - * for the name, and "." is not on the search list, then try an as-is - * query now. + * If the query has not already been tried as is then try it + * unless RES_NOTLDQUERY is set and there were no dots. */ - if (statp->ndots && !(tried_as_is || root_on_list)) { + if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0) && + !(tried_as_is || root_on_list)) { ret = res_nquerydomain(statp, name, NULL, class, type, answer, anslen); if (ret > 0) @@ -383,17 +404,18 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { setbuf(fp, NULL); buf[sizeof(buf) - 1] = '\0'; while (fgets(buf, sizeof(buf), fp)) { - for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1) + for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1) ; if (!*cp1) break; *cp1 = '\0'; if (ns_samename(buf, name) == 1) { - while (isspace(*++cp1)) + while (isspace((unsigned char)*++cp1)) ; if (!*cp1) break; - for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) + for (cp2 = cp1 + 1; *cp2 && + !isspace((unsigned char)*cp2); ++cp2) ; *cp2 = '\0'; strncpy(dst, cp1, siz - 1); diff --git a/contrib/bind/lib/resolv/res_send.c b/contrib/bind/lib/resolv/res_send.c index ade9eaca4c27..6dfea59e22c2 100644 --- a/contrib/bind/lib/resolv/res_send.c +++ b/contrib/bind/lib/resolv/res_send.c @@ -70,7 +70,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_send.c,v 8.42 2001/03/07 06:48:03 marka Exp $"; +static const char rcsid[] = "$Id: res_send.c,v 8.48 2001/07/03 06:27:17 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -106,6 +106,7 @@ static const char rcsid[] = "$Id: res_send.c,v 8.42 2001/03/07 06:48:03 marka Ex /* Options. Leave them on. */ #define DEBUG #include "res_debug.h" +#include "res_private.h" #define EXT(res) ((res)->_u._ext) @@ -113,20 +114,25 @@ static const int highestFD = FD_SETSIZE - 1; /* Forward. */ +static int get_salen __P((const struct sockaddr *)); +static struct sockaddr * get_nsaddr __P((res_state, size_t)); static int send_vc(res_state, const u_char *, int, u_char *, int, int *, int); static int send_dg(res_state, const u_char *, int, u_char *, int, int *, int, int *, int *); static void Aerror(const res_state, FILE *, const char *, int, - struct sockaddr_in); + const struct sockaddr *, int); static void Perror(const res_state, FILE *, const char *, int); -static int sock_eq(struct sockaddr_in *, struct sockaddr_in *); +static int sock_eq(struct sockaddr *, struct sockaddr *); #ifdef NEED_PSELECT static int pselect(int, void *, void *, void *, struct timespec *, const sigset_t *); #endif +void res_pquery(const res_state, const u_char *, int, FILE *); + +static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV; /* Public. */ @@ -140,19 +146,38 @@ static int pselect(int, void *, void *, void *, * paul vixie, 29may94 */ int -res_ourserver_p(const res_state statp, const struct sockaddr_in *inp) { - struct sockaddr_in ina; +res_ourserver_p(const res_state statp, const struct sockaddr *sa) { + const struct sockaddr_in *inp, *srv; + const struct sockaddr_in6 *in6p, *srv6; int ns; - ina = *inp; - for (ns = 0; ns < statp->nscount; ns++) { - const struct sockaddr_in *srv = &statp->nsaddr_list[ns]; - - if (srv->sin_family == ina.sin_family && - srv->sin_port == ina.sin_port && - (srv->sin_addr.s_addr == INADDR_ANY || - srv->sin_addr.s_addr == ina.sin_addr.s_addr)) - return (1); + switch (sa->sa_family) { + case AF_INET: + inp = (const struct sockaddr_in *)sa; + for (ns = 0; ns < statp->nscount; ns++) { + srv = (struct sockaddr_in *)get_nsaddr(statp, ns); + if (srv->sin_family == inp->sin_family && + srv->sin_port == inp->sin_port && + (srv->sin_addr.s_addr == INADDR_ANY || + srv->sin_addr.s_addr == inp->sin_addr.s_addr)) + return (1); + } + break; + case AF_INET6: + if (EXT(statp).ext == NULL) + break; + in6p = (const struct sockaddr_in6 *)sa; + for (ns = 0; ns < statp->nscount; ns++) { + srv6 = (struct sockaddr_in6 *)get_nsaddr(statp, ns); + if (srv6->sin6_family == in6p->sin6_family && + srv6->sin6_port == in6p->sin6_port && + (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) || + IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr))) + return (1); + } + break; + default: + break; } return (0); } @@ -174,7 +199,7 @@ res_nameinquery(const char *name, int type, int class, const u_char *buf, const u_char *eom) { const u_char *cp = buf + HFIXEDSZ; - int qdcount = ntohs(((HEADER*)buf)->qdcount); + int qdcount = ntohs(((const HEADER*)buf)->qdcount); while (qdcount-- > 0) { char tname[MAXDNAME+1]; @@ -211,7 +236,7 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, const u_char *buf2, const u_char *eom2) { const u_char *cp = buf1 + HFIXEDSZ; - int qdcount = ntohs(((HEADER*)buf1)->qdcount); + int qdcount = ntohs(((const HEADER*)buf1)->qdcount); if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2) return (-1); @@ -220,11 +245,11 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, * Only header section present in replies to * dynamic update packets. */ - if ((((HEADER *)buf1)->opcode == ns_o_update) && - (((HEADER *)buf2)->opcode == ns_o_update)) + if ((((const HEADER *)buf1)->opcode == ns_o_update) && + (((const HEADER *)buf2)->opcode == ns_o_update)) return (1); - if (qdcount != ntohs(((HEADER*)buf2)->qdcount)) + if (qdcount != ntohs(((const HEADER*)buf2)->qdcount)) return (0); while (qdcount-- > 0) { char tname[MAXDNAME+1]; @@ -249,6 +274,7 @@ res_nsend(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz) { int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; + char abuf[NI_MAXHOST]; if (statp->nscount == 0) { errno = ESRCH; @@ -270,16 +296,34 @@ res_nsend(res_state statp, */ if (EXT(statp).nscount != 0) { int needclose = 0; + struct sockaddr_storage peer; + ISC_SOCKLEN_T peerlen; if (EXT(statp).nscount != statp->nscount) needclose++; else - for (ns = 0; ns < statp->nscount; ns++) - if (!sock_eq(&statp->nsaddr_list[ns], - &EXT(statp).nsaddrs[ns])) { + for (ns = 0; ns < statp->nscount; ns++) { + if (statp->nsaddr_list[ns].sin_family && + !sock_eq((struct sockaddr *)&statp->nsaddr_list[ns], + (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])) { needclose++; break; } + + if (EXT(statp).nssocks[ns] == -1) + continue; + peerlen = sizeof(peer); + if (getsockname(EXT(statp).nssocks[ns], + (struct sockaddr *)&peer, &peerlen) < 0) { + needclose++; + break; + } + if (!sock_eq((struct sockaddr *)&peer, + get_nsaddr(statp, ns))) { + needclose++; + break; + } + } if (needclose) { res_nclose(statp); EXT(statp).nscount = 0; @@ -291,9 +335,12 @@ res_nsend(res_state statp, */ if (EXT(statp).nscount == 0) { for (ns = 0; ns < statp->nscount; ns++) { - EXT(statp).nsaddrs[ns] = statp->nsaddr_list[ns]; EXT(statp).nstimes[ns] = RES_MAXTIME; EXT(statp).nssocks[ns] = -1; + if (!statp->nsaddr_list[ns].sin_family) + continue; + EXT(statp).ext->nsaddrs[ns].sin = + statp->nsaddr_list[ns]; } EXT(statp).nscount = statp->nscount; } @@ -304,19 +351,27 @@ res_nsend(res_state statp, */ if ((statp->options & RES_ROTATE) != 0 && (statp->options & RES_BLAST) == 0) { + union res_sockaddr_union inu; struct sockaddr_in ina; int lastns = statp->nscount - 1; int fd; u_int16_t nstime; + if (EXT(statp).ext != NULL) + inu = EXT(statp).ext->nsaddrs[0]; ina = statp->nsaddr_list[0]; fd = EXT(statp).nssocks[0]; - nstime = EXT(statp).nstimes[ns]; + nstime = EXT(statp).nstimes[0]; for (ns = 0; ns < lastns; ns++) { + if (EXT(statp).ext != NULL) + EXT(statp).ext->nsaddrs[ns] = + EXT(statp).ext->nsaddrs[ns + 1]; statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1]; EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1]; } + if (EXT(statp).ext != NULL) + EXT(statp).ext->nsaddrs[lastns] = inu; statp->nsaddr_list[lastns] = ina; EXT(statp).nssocks[lastns] = fd; EXT(statp).nstimes[lastns] = nstime; @@ -327,7 +382,10 @@ res_nsend(res_state statp, */ for (try = 0; try < statp->retry; try++) { for (ns = 0; ns < statp->nscount; ns++) { - struct sockaddr_in *nsap = &statp->nsaddr_list[ns]; + struct sockaddr *nsap; + int nsaplen; + nsap = get_nsaddr(statp, ns); + nsaplen = get_salen(nsap); same_ns: if (statp->qhook) { int done = 0, loops = 0; @@ -359,9 +417,12 @@ res_nsend(res_state statp, } while (!done); } - Dprint(statp->options & RES_DEBUG, + Dprint(((statp->options & RES_DEBUG) && + getnameinfo(nsap, nsaplen, abuf, sizeof(abuf), + NULL, 0, niflags) == 0), (stdout, ";; Querying server (# %d) address = %s\n", - ns + 1, inet_ntoa(nsap->sin_addr))); + ns + 1, abuf)); + if (v_circuit) { /* Use VC; at most one attempt per server. */ @@ -393,7 +454,7 @@ res_nsend(res_state statp, DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), - (stdout, ""), + (stdout, "%s", ""), ans, (resplen > anssiz) ? anssiz : resplen); /* @@ -454,18 +515,68 @@ res_nsend(res_state statp, /* Private */ +static int +get_salen(sa) + const struct sockaddr *sa; +{ + +#ifdef HAVE_SA_LEN + /* there are people do not set sa_len. be forgibing to them */ + if (sa->sa_len) + return sa->sa_len; +#endif + + if (sa->sa_family == AF_INET) + return sizeof(struct sockaddr_in); + else if (sa->sa_family == AF_INET) + return sizeof(struct sockaddr_in6); + else + return 0; /* unknown, die on connect */ +} + +/* + * pick appropriate nsaddr_list for use. see res_init() for initialization. + */ +static struct sockaddr * +get_nsaddr(statp, n) + res_state statp; + size_t n; +{ + + if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) { + /* + * - EXT(statp).ext->nsaddrs[n] holds an address that is larger + * than struct sockaddr, and + * - user code did not update statp->nsaddr_list[n]. + */ + return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n]; + } else { + /* + * - user code updated statp->nsaddr_list[n], or + * - statp->nsaddr_list[n] has the same content as + * EXT(statp).ext->nsaddrs[n]. + */ + return (struct sockaddr *)(void *)&statp->nsaddr_list[n]; + } +} + static int send_vc(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz, int *terrno, int ns) { - const HEADER *hp = (HEADER *) buf; + const HEADER *hp = (const HEADER *) buf; HEADER *anhp = (HEADER *) ans; - struct sockaddr_in *nsap = &statp->nsaddr_list[ns]; + struct sockaddr *nsap; + int nsaplen; int truncating, connreset, resplen, n; struct iovec iov[2]; u_short len; u_char *cp; + void *tmp; + + nsap = get_nsaddr(statp, ns); + nsaplen = get_salen(nsap); connreset = 0; same_ns: @@ -473,12 +584,12 @@ send_vc(res_state statp, /* Are we still talking to whom we want to talk to? */ if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { - struct sockaddr_in peer; - int size = sizeof peer; + struct sockaddr_storage peer; + ISC_SOCKLEN_T size = sizeof peer; if (getpeername(statp->_vcsock, (struct sockaddr *)&peer, &size) < 0 || - !sock_eq(&peer, nsap)) { + !sock_eq((struct sockaddr *)&peer, nsap)) { res_nclose(statp); statp->_flags &= ~RES_F_VC; } @@ -488,7 +599,7 @@ send_vc(res_state statp, if (statp->_vcsock >= 0) res_nclose(statp); - statp->_vcsock = socket(PF_INET, SOCK_STREAM, 0); + statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0); if (statp->_vcsock > highestFD) { res_nclose(statp); errno = ENOTSOCK; @@ -499,10 +610,10 @@ send_vc(res_state statp, return (-1); } errno = 0; - if (connect(statp->_vcsock, (struct sockaddr *)nsap, - sizeof *nsap) < 0) { + if (connect(statp->_vcsock, nsap, nsaplen) < 0) { *terrno = errno; - Aerror(statp, stderr, "connect/vc", errno, *nsap); + Aerror(statp, stderr, "connect/vc", errno, nsap, + nsaplen); res_nclose(statp); return (0); } @@ -514,7 +625,8 @@ send_vc(res_state statp, */ putshort((u_short)buflen, (u_char*)&len); iov[0] = evConsIovec(&len, INT16SZ); - iov[1] = evConsIovec((void*)buf, buflen); + DE_CONST(buf, tmp); + iov[1] = evConsIovec(tmp, buflen); if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) { *terrno = errno; Perror(statp, stderr, "write failed", errno); @@ -627,16 +739,20 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz, int *terrno, int ns, int *v_circuit, int *gotsomewhere) { - const HEADER *hp = (HEADER *) buf; + const HEADER *hp = (const HEADER *) buf; HEADER *anhp = (HEADER *) ans; - const struct sockaddr_in *nsap = &statp->nsaddr_list[ns]; + const struct sockaddr *nsap; + int nsaplen; struct timespec now, timeout, finish; fd_set dsmask; - struct sockaddr_in from; - int fromlen, resplen, seconds, n, s; + struct sockaddr_storage from; + ISC_SOCKLEN_T fromlen; + int resplen, seconds, n, s; + nsap = get_nsaddr(statp, ns); + nsaplen = get_salen(nsap); if (EXT(statp).nssocks[ns] == -1) { - EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0); + EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0); if (EXT(statp).nssocks[ns] > highestFD) { res_nclose(statp); errno = ENOTSOCK; @@ -658,9 +774,9 @@ send_dg(res_state statp, * error message is received. We can thus detect * the absence of a nameserver without timing out. */ - if (connect(EXT(statp).nssocks[ns], (struct sockaddr *)nsap, - sizeof *nsap) < 0) { - Aerror(statp, stderr, "connect(dg)", errno, *nsap); + if (connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) { + Aerror(statp, stderr, "connect(dg)", errno, nsap, + nsaplen); res_nclose(statp); return (0); } @@ -670,16 +786,15 @@ send_dg(res_state statp, } s = EXT(statp).nssocks[ns]; #ifndef CANNOT_CONNECT_DGRAM - if (send(s, (char*)buf, buflen, 0) != buflen) { + if (send(s, (const char*)buf, buflen, 0) != buflen) { Perror(statp, stderr, "send", errno); res_nclose(statp); return (0); } #else /* !CANNOT_CONNECT_DGRAM */ - if (sendto(s, (char*)buf, buflen, 0, - (struct sockaddr *)nsap, sizeof *nsap) != buflen) + if (sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen) { - Aerror(statp, stderr, "sendto", errno, *nsap); + Aerror(statp, stderr, "sendto", errno, nsap, nsaplen); res_nclose(statp); return (0); } @@ -720,7 +835,7 @@ send_dg(res_state statp, return (0); } errno = 0; - fromlen = sizeof(struct sockaddr_in); + fromlen = sizeof(from); resplen = recvfrom(s, (char*)ans, anssiz,0, (struct sockaddr *)&from, &fromlen); if (resplen <= 0) { @@ -753,7 +868,7 @@ send_dg(res_state statp, goto wait; } if (!(statp->options & RES_INSECURE1) && - !res_ourserver_p(statp, &from)) { + !res_ourserver_p(statp, (struct sockaddr *)&from)) { /* * response from wrong server? ignore it. * XXX - potential security hazard could @@ -765,6 +880,22 @@ send_dg(res_state statp, ans, (resplen > anssiz) ? anssiz : resplen); goto wait; } +#ifdef RES_USE_EDNS0 + if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0) { + /* + * Do not retry if the server do not understand EDNS0. + * The case has to be captured here, as FORMERR packet do not + * carry query section, hence res_queriesmatch() returns 0. + */ + DprintQ(statp->options & RES_DEBUG, + (stdout, "server rejected query with EDNS0:\n"), + ans, (resplen > anssiz) ? anssiz : resplen); + /* record the error */ + statp->_flags |= RES_F_EDNS0ERR; + res_nclose(statp); + return (0); + } +#endif if (!(statp->options & RES_INSECURE2) && !res_queriesmatch(buf, buf + buflen, ans, ans + anssiz)) { @@ -810,19 +941,24 @@ send_dg(res_state statp, static void Aerror(const res_state statp, FILE *file, const char *string, int error, - struct sockaddr_in address) + const struct sockaddr *address, int alen) { int save = errno; + char hbuf[NI_MAXHOST]; + char sbuf[NI_MAXSERV]; + + alen = alen; if ((statp->options & RES_DEBUG) != 0) { - char tmp[sizeof "255.255.255.255"]; - - fprintf(file, "res_send: %s ([%s].%u): %s\n", - string, - inet_ntop(address.sin_family, &address.sin_addr, - tmp, sizeof tmp), - ntohs(address.sin_port), - strerror(error)); + if (getnameinfo(address, alen, hbuf, sizeof(hbuf), + sbuf, sizeof(sbuf), niflags)) { + strncpy(hbuf, "?", sizeof(hbuf) - 1); + hbuf[sizeof(hbuf) - 1] = '\0'; + strncpy(sbuf, "?", sizeof(sbuf) - 1); + sbuf[sizeof(sbuf) - 1] = '\0'; + } + fprintf(file, "res_send: %s ([%s].%s): %s\n", + string, hbuf, sbuf, strerror(error)); } errno = save; } @@ -838,10 +974,29 @@ Perror(const res_state statp, FILE *file, const char *string, int error) { } static int -sock_eq(struct sockaddr_in *a1, struct sockaddr_in *a2) { - return ((a1->sin_family == a2->sin_family) && - (a1->sin_port == a2->sin_port) && - (a1->sin_addr.s_addr == a2->sin_addr.s_addr)); +sock_eq(struct sockaddr *a, struct sockaddr *b) { + struct sockaddr_in *a4, *b4; + struct sockaddr_in6 *a6, *b6; + + if (a->sa_family != b->sa_family) + return 0; + switch (a->sa_family) { + case AF_INET: + a4 = (struct sockaddr_in *)a; + b4 = (struct sockaddr_in *)b; + return a4->sin_port == b4->sin_port && + a4->sin_addr.s_addr == b4->sin_addr.s_addr; + case AF_INET6: + a6 = (struct sockaddr_in6 *)a; + b6 = (struct sockaddr_in6 *)b; + return a6->sin6_port == b6->sin6_port && +#ifdef HAVE_SIN6_SCOPE_ID + a6->sin6_scope_id == b6->sin6_scope_id && +#endif + IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr); + default: + return 0; + } } #ifdef NEED_PSELECT diff --git a/contrib/bind/lib/resolv/res_update.c b/contrib/bind/lib/resolv/res_update.c index 1434d5ce8765..54d3b155dd53 100644 --- a/contrib/bind/lib/resolv/res_update.c +++ b/contrib/bind/lib/resolv/res_update.c @@ -1,5 +1,5 @@ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_update.c,v 1.26 2001/03/05 04:03:00 marka Exp $"; +static const char rcsid[] = "$Id: res_update.c,v 1.31 2001/11/01 05:21:23 marka Exp $"; #endif /* not lint */ /* @@ -37,7 +37,6 @@ static const char rcsid[] = "$Id: res_update.c,v 1.26 2001/03/05 04:03:00 marka #include #include #include -#include #include #include #include @@ -45,8 +44,10 @@ static const char rcsid[] = "$Id: res_update.c,v 1.26 2001/03/05 04:03:00 marka #include #include +#include #include "port_after.h" +#include "res_private.h" /* * Separate a linked list of records into groups so that all records @@ -65,7 +66,7 @@ static const char rcsid[] = "$Id: res_update.c,v 1.26 2001/03/05 04:03:00 marka struct zonegrp { char z_origin[MAXDNAME]; ns_class z_class; - struct in_addr z_nsaddrs[MAXNS]; + union res_sockaddr_union z_nsaddrs[MAXNS]; int z_nscount; int z_flags; LIST(ns_updrec) z_rrlist; @@ -76,15 +77,15 @@ struct zonegrp { /* Forward. */ -static int nscopy(struct sockaddr_in *, const struct sockaddr_in *, int); -static int nsprom(struct sockaddr_in *, const struct in_addr *, int); -static void dprintf(const char *, ...); +static int nscopy(union res_sockaddr_union *, + const union res_sockaddr_union *, int); +static void res_dprintf(const char *, ...); /* Macros. */ #define DPRINTF(x) do {\ int save_errno = errno; \ - if ((statp->options & RES_DEBUG) != 0) dprintf x; \ + if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \ errno = save_errno; \ } while (0) @@ -97,12 +98,20 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { struct zonegrp *zptr, tgrp; LIST(struct zonegrp) zgrps; int nzones = 0, nscount = 0, n; - struct sockaddr_in nsaddrs[MAXNS]; + union res_sockaddr_union nsaddrs[MAXNS]; /* Thread all of the updates onto a list of groups. */ INIT_LIST(zgrps); for (rrecp = rrecp_in; rrecp; rrecp = LINKED(rrecp, r_link) ? NEXT(rrecp, r_link) : NULL) { + struct in_addr nsaddrs[MAXNS]; + int i; + /* XXX need to rewrite res_findzonecut */ + for (i = 0; i < MAXNS; i++) { + nsaddrs[i].s_addr = 0; + if (tgrp.z_nsaddrs[i].sin.sin_family == AF_INET) + nsaddrs[i] = tgrp.z_nsaddrs[i].sin.sin_addr; + } /* Find the origin for it if there is one. */ tgrp.z_class = rrecp->r_class; tgrp.z_nscount = @@ -110,7 +119,7 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { RES_EXHAUSTIVE, tgrp.z_origin, sizeof tgrp.z_origin, - tgrp.z_nsaddrs, MAXNS); + nsaddrs, MAXNS); if (tgrp.z_nscount <= 0) { DPRINTF(("res_findzonecut failed (%d)", tgrp.z_nscount)); @@ -157,8 +166,8 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { goto done; /* Temporarily replace the resolver's nameserver set. */ - nscount = nscopy(nsaddrs, statp->nsaddr_list, statp->nscount); - statp->nscount = nsprom(statp->nsaddr_list, + nscount = nscopy(nsaddrs, statp->_u._ext.ext->nsaddrs, statp->nscount); + statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs, zptr->z_nsaddrs, zptr->z_nscount); /* Send the update and remember the result. */ @@ -176,7 +185,7 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { nzones++; /* Restore resolver's nameserver set. */ - statp->nscount = nscopy(statp->nsaddr_list, nsaddrs, nscount); + statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs, nsaddrs, nscount); nscount = 0; } done: @@ -188,7 +197,7 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { free(zptr); } if (nscount != 0) - statp->nscount = nscopy(statp->nsaddr_list, nsaddrs, nscount); + statp->nscount = nscopy(statp->_u._ext.ext->nsaddrs, nsaddrs, nscount); return (nzones); } @@ -196,7 +205,9 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { /* Private. */ static int -nscopy(struct sockaddr_in *dst, const struct sockaddr_in *src, int n) { +nscopy(union res_sockaddr_union *dst, const union res_sockaddr_union *src, + int n) +{ int i; for (i = 0; i < n; i++) @@ -204,21 +215,8 @@ nscopy(struct sockaddr_in *dst, const struct sockaddr_in *src, int n) { return (n); } -static int -nsprom(struct sockaddr_in *dst, const struct in_addr *src, int n) { - int i; - - for (i = 0; i < n; i++) { - memset(&dst[i], 0, sizeof dst[i]); - dst[i].sin_family = AF_INET; - dst[i].sin_port = htons(NS_DEFAULTPORT); - dst[i].sin_addr = src[i]; - } - return (n); -} - static void -dprintf(const char *fmt, ...) { +res_dprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/contrib/bind/port/freebsd/Makefile.set b/contrib/bind/port/freebsd/Makefile.set index fe256bc74812..c1c9bcfc2122 100644 --- a/contrib/bind/port/freebsd/Makefile.set +++ b/contrib/bind/port/freebsd/Makefile.set @@ -1,5 +1,5 @@ 'CC=cc' -'CDEBUG=-O2 -g' +'CDEBUG=-O2 -g -W -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wformat' 'DESTBIN=/usr/bin' 'DESTSBIN=/usr/sbin' 'DESTEXEC=/usr/libexec' diff --git a/contrib/bind/port/freebsd/include/port_after.h b/contrib/bind/port/freebsd/include/port_after.h index a06bf69ce92f..4d923555bd6a 100644 --- a/contrib/bind/port/freebsd/include/port_after.h +++ b/contrib/bind/port/freebsd/include/port_after.h @@ -29,6 +29,10 @@ #if (!defined(BSD)) || (BSD < 199306) #include #endif +#include +#ifdef __KAME__ +#define HAS_INET6_STRUCTS +#endif #include /* @@ -71,7 +75,88 @@ struct sockaddr_in6 { struct in6_addr sin6_addr; /* IPv6 address */ u_int32_t sin6_scope_id; /* set of interfaces for a scope */ }; + +#ifndef IN6ADDR_ANY_INIT +#define IN6ADDR_ANY_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} +#endif +#ifndef IN6ADDR_LOOPBACK_INIT +#define IN6ADDR_LOOPBACK_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}} +#endif #endif /* HAS_INET6_STRUCTS */ + +#if defined(NEED_SOCKADDR_STORAGE) || !defined(HAS_INET6_STRUCTS) +#define __SS_MAXSIZE 128 +#define __SS_ALLIGSIZE (sizeof (long)) + +struct sockaddr_storage { +#ifdef HAVE_SA_LEN + u_int8_t ss_len; /* address length */ + u_int8_t ss_family; /* address family */ + char __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)]; + long __ss_align; + char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; +#else + u_int16_t ss_family; /* address family */ + char __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)]; + long __ss_align; + char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; +#endif +}; +#endif + + +#if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY) +#define in6addr_any isc_in6addr_any +extern const struct in6_addr in6addr_any; +#endif + +#ifndef IN6_ARE_ADDR_EQUAL +#define IN6_ARE_ADDR_EQUAL(a,b) \ + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) +#endif + +#ifndef IN6_IS_ADDR_UNSPECIFIED +#define IN6_IS_ADDR_UNSPECIFIED(a) \ + IN6_ARE_ADDR_EQUAL(a, &in6addr_any) +#endif + +#ifndef IN6_IS_ADDR_SITELOCAL +#define IN6_IS_ADDR_SITELOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) +#endif + +#ifndef IN6_IS_ADDR_MULTICAST +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) +#endif + +#ifndef __IPV6_ADDR_MC_SCOPE +#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) +#endif + +#ifndef __IPV6_ADDR_SCOPE_SITELOCAL +#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 +#endif + +#ifndef __IPV6_ADDR_SCOPE_ORGLOCAL +#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 +#endif + +#ifndef IN6_IS_ADDR_MC_SITELOCAL +#define IN6_IS_ADDR_MC_SITELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) +#endif + +#ifndef IN6_IS_ADDR_MC_ORGLOCAL +#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) +#endif + +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + #ifndef ISC_FACILITY #define ISC_FACILITY LOG_DAEMON #endif @@ -79,4 +164,11 @@ struct sockaddr_in6 { int isc__gettimeofday(struct timeval *tp, struct timezone *tzp); #define gettimeofday isc__gettimeofday +#define UNUSED(x) (x) = (x) +#define DE_CONST(konst, var) \ + do { \ + union { const void *k; void *v; } _u; \ + _u.k = konst; \ + var = _u.v; \ + } while (0) #endif /* ! PORT_AFTER_H */ diff --git a/contrib/bind/port/freebsd/include/port_before.h b/contrib/bind/port/freebsd/include/port_before.h index d90ba14aad3f..fe20b2a689bc 100644 --- a/contrib/bind/port/freebsd/include/port_before.h +++ b/contrib/bind/port/freebsd/include/port_before.h @@ -1,5 +1,6 @@ #define WANT_IRS_NIS #define WANT_IRS_PW +#define HAVE_PW_CLASS #define WANT_IRS_GR #define SIG_FN void #define HAS_PTHREADS @@ -22,9 +23,11 @@ #define GROUP_R_END_RETURN void #define GROUP_R_END_RESULT(x) /*empty*/ #define GROUP_R_ARGS char *buf, int buflen -#undef GROUP_R_ENT_ARGS /*empty*/ +#define GROUP_R_ENT_ARGS void #define GROUP_R_OK gptr #define GROUP_R_BAD NULL +#define GETGROUPLIST_ARGS const char *name, int basegid, int *groups, \ + int *ngroups #define HOST_R_RETURN struct hostent * #define HOST_R_SET_RETURN void @@ -55,7 +58,7 @@ #define NGR_R_SET_RETURN void #undef NGR_R_SET_RESULT /*empty*/ #define NGR_R_END_RETURN void -#undef NGR_R_END_RESULT /*empty*/ +#define NGR_R_END_RESULT(x) return #define NGR_R_ARGS char *buf, int buflen #undef NGR_R_ENT_ARGS /*empty*/ #define NGR_R_COPY buf, buflen @@ -100,3 +103,10 @@ #define SERV_R_BAD NULL #define IRS_LCL_SV_DB +#define ISC_SOCKLEN_T int +#ifdef __GNUC__ +#define ISC_FORMAT_PRINTF(fmt, args) \ + __attribute__((__format__(__printf__, fmt, args))) +#else +#define ISC_FORMAT_PRINTF(fmt, args) +#endif