diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-05-22 00:47:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-05-22 00:47:52 +0000 |
commit | f574c55aa56261d8fc3ce601af6d42c4ebc83fb8 (patch) | |
tree | cf686e53be1725a85c2b49d468ffae9daa548f68 | |
parent | 0d3f8bb38bb58b0a4742f327f9fe73684d125f20 (diff) |
bind 4.9.6, 4.9.7 comming soon.
33 files changed, 481 insertions, 208 deletions
diff --git a/usr.sbin/named/Makefile b/usr.sbin/named/Makefile index 95f9c8221a7..7c6203c8862 100644 --- a/usr.sbin/named/Makefile +++ b/usr.sbin/named/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.6 1997/09/21 11:43:59 deraadt Exp $ +# $OpenBSD: Makefile,v 1.7 1998/05/22 00:47:12 millert Exp $ SUBDIR= named named-xfer ndc reload restart dig nslookup \ host dnsquery addr -VER= 4.9.5-P1 +VER= 4.9.6-REL .include <bsd.subdir.mk> diff --git a/usr.sbin/named/conf/portability.h b/usr.sbin/named/conf/portability.h index 64228a0d813..ad6e8621db2 100644 --- a/usr.sbin/named/conf/portability.h +++ b/usr.sbin/named/conf/portability.h @@ -1,7 +1,7 @@ /* portability.h - include or define things that aren't present on all systems * vixie@decwrl 26dec92 [new] * - * $Id: portability.h,v 1.2 1997/03/12 10:41:47 downsj Exp $ + * $From: portability.h,v 8.21 1997/06/01 20:34:27 vixie Exp $ */ /* @@ -189,7 +189,8 @@ #endif #if defined(_POSIX_SOURCE) || defined(__sgi) || defined(__ultrix) || \ - defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || defined(sun) + defined(__hpux) || (defined(BSD) && (BSD >= 199103)) || \ + defined(sun) || defined(__m88k__) # define USE_POSIX #endif @@ -606,6 +607,16 @@ extern u_long htonl __P((u_long)), ntohl __P((u_long)); #endif /* + * Motorola FH40.43 and FH40.44 need specific macros for + * get/settimeofday as only one argument seems to be accepted + * by the compiler. NULL generates compile errors + */ +#if defined(__m88k__) && defined(__unix__) +# define gettimeofday(tp, tzp) gettimeofday(tp) +# define settimeofday(tp, tzp) settimeofday(tp) +#endif + +/* * We need to know the IPv6 address family number even on IPv4-only systems. * Note that this is NOT a protocol constant, and that if the system has its * own AF_INET6, different from ours below, all of BIND's libraries and diff --git a/usr.sbin/named/include/netdb.h b/usr.sbin/named/include/netdb.h index b1aed8b8158..a4d246b1eb3 100644 --- a/usr.sbin/named/include/netdb.h +++ b/usr.sbin/named/include/netdb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netdb.h,v 1.2 1997/03/12 11:21:14 downsj Exp $ */ +/* $OpenBSD: netdb.h,v 1.3 1998/05/22 00:47:15 millert Exp $ */ /* * ++Copyright++ 1980, 1983, 1988, 1993 @@ -57,7 +57,7 @@ /* * @(#)netdb.h 8.1 (Berkeley) 6/2/93 - * $From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $ + * $From: netdb.h,v 8.8 1997/06/01 20:34:32 vixie Exp $ */ #ifndef _NETDB_H_ @@ -169,4 +169,12 @@ struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent(); #endif /* __GNU_LIBRARY__ */ #endif /* sun */ +/* + * The Motorola kernel will only support 64 characters for hostname + * also defined in /usr/ucbinclude/netdb.h + */ +#ifdef __m88k__ +#define MAXHOSTNAMELEN 64 +#endif + #endif /* !_NETDB_H_ */ diff --git a/usr.sbin/named/include/resolv.h b/usr.sbin/named/include/resolv.h index 0f4d7bf8dc2..f6bdaef9a2a 100644 --- a/usr.sbin/named/include/resolv.h +++ b/usr.sbin/named/include/resolv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolv.h,v 1.2 1997/03/12 11:21:15 downsj Exp $ */ +/* $OpenBSD: resolv.h,v 1.3 1998/05/22 00:47:17 millert Exp $ */ /* * ++Copyright++ 1983, 1987, 1989, 1993 @@ -57,7 +57,7 @@ /* * @(#)resolv.h 8.1 (Berkeley) 6/2/93 - * $From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $ + * $From: resolv.h,v 8.18 1997/06/01 20:34:32 vixie Exp $ */ #ifndef _RESOLV_H_ @@ -227,7 +227,6 @@ extern const struct res_sym __p_type_syms[]; #define dn_count_labels __dn_count_labels #define dn_comp __dn_comp #define res_randomid __res_randomid -#define res_send __res_send #define res_isourserver __res_isourserver #define res_nameinquery __res_nameinquery #define res_queriesmatch __res_queriesmatch @@ -240,6 +239,7 @@ extern const struct res_sym __p_type_syms[]; #define res_search __res_search #define res_querydomain __res_querydomain #define res_mkquery __res_mkquery +#define res_send __res_send #endif __BEGIN_DECLS diff --git a/usr.sbin/named/libresolv/gethnamaddr.c b/usr.sbin/named/libresolv/gethnamaddr.c index aa93b257643..e60164b728d 100644 --- a/usr.sbin/named/libresolv/gethnamaddr.c +++ b/usr.sbin/named/libresolv/gethnamaddr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethnamaddr.c,v 1.1 1997/03/12 10:42:02 downsj Exp $ */ +/* $OpenBSD: gethnamaddr.c,v 1.2 1998/05/22 00:47:18 millert Exp $ */ /* * ++Copyright++ 1985, 1988, 1993 @@ -58,9 +58,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: gethnamaddr.c,v 8.20 1996/09/28 06:51:07 vixie Exp $"; +static char rcsid[] = "$From: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: gethnamaddr.c,v 1.1 1997/03/12 10:42:02 downsj Exp $"; +static char rcsid[] = "$OpenBSD: gethnamaddr.c,v 1.2 1998/05/22 00:47:18 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -216,6 +216,10 @@ getanswer(answer, anslen, qname, qtype) * (i.e., with the succeeding search-domain tacked on). */ n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + h_errno = NO_RECOVERY; + return (NULL); + } host.h_name = bp; bp += n; buflen -= n; @@ -260,11 +264,15 @@ getanswer(answer, anslen, qname, qtype) /* Store alias. */ *ap++ = bp; n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + continue; + } bp += n; buflen -= n; /* Get canonical name. */ n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen) { + if (n > buflen || n >= MAXHOSTNAMELEN) { had_error++; continue; } @@ -276,14 +284,14 @@ getanswer(answer, anslen, qname, qtype) } if (qtype == T_PTR && type == T_CNAME) { n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !res_hnok(tbuf)) { + if (n < 0 || !res_dnok(tbuf)) { had_error++; continue; } cp += n; /* Get canonical name. */ n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen) { + if (n > buflen || n >= MAXHOSTNAMELEN) { had_error++; continue; } @@ -324,6 +332,10 @@ getanswer(answer, anslen, qname, qtype) n = -1; if (n != -1) { n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + break; + } bp += n; buflen -= n; } @@ -332,6 +344,10 @@ getanswer(answer, anslen, qname, qtype) host.h_name = bp; if (_res.options & RES_USE_INET6) { n = strlen(bp) + 1; /* for the \0 */ + if (n >= MAXHOSTNAMELEN) { + had_error++; + break; + } bp += n; buflen -= n; map_v4v6_hostent(&host, &bp, &buflen); @@ -399,8 +415,8 @@ getanswer(answer, anslen, qname, qtype) # endif /*RESOLVSORT*/ if (!host.h_name) { n = strlen(qname) + 1; /* for the \0 */ - if (n > buflen) - goto try_again; + if (n > buflen || n >= MAXHOSTNAMELEN) + goto no_recovery; strcpy(bp, qname); host.h_name = bp; bp += n; @@ -411,8 +427,8 @@ getanswer(answer, anslen, qname, qtype) h_errno = NETDB_SUCCESS; return (&host); } - try_again: - h_errno = TRY_AGAIN; + no_recovery: + h_errno = NO_RECOVERY; return (NULL); } @@ -512,7 +528,8 @@ gethostbyname2(name, af) if (!isdigit(*cp) && *cp != '.') break; } - if (isxdigit(name[0]) || name[0] == ':') + if ((isxdigit(name[0]) && strchr(name, ':') != NULL) || + name[0] == ':') for (cp = name;; ++cp) { if (!*cp) { if (*--cp == '.') @@ -721,8 +738,7 @@ _gethtent() if (!(cp = strpbrk(p, " \t"))) goto again; *cp++ = '\0'; - if ((_res.options & RES_USE_INET6) && - inet_pton(AF_INET6, p, host_addr) > 0) { + if (inet_pton(AF_INET6, p, host_addr) > 0) { af = AF_INET6; len = IN6ADDRSZ; } else if (inet_pton(AF_INET, p, host_addr) > 0) { @@ -759,12 +775,6 @@ _gethtent() *cp++ = '\0'; } *q = NULL; - if (_res.options & RES_USE_INET6) { - char *bp = hostbuf; - int buflen = sizeof hostbuf; - - map_v4v6_hostent(&host, &bp, &buflen); - } h_errno = NETDB_SUCCESS; return (&host); } diff --git a/usr.sbin/named/libresolv/getnetent.c b/usr.sbin/named/libresolv/getnetent.c index b80ada5f94b..96b0e648773 100644 --- a/usr.sbin/named/libresolv/getnetent.c +++ b/usr.sbin/named/libresolv/getnetent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetent.c,v 1.1 1997/03/12 10:42:03 downsj Exp $ */ +/* $OpenBSD: getnetent.c,v 1.2 1998/05/22 00:47:19 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -46,9 +46,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: getnetent.c,v 8.3 1996/08/05 08:31:35 vixie Exp $"; +static char rcsid[] = "$From: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: getnetent.c,v 1.1 1997/03/12 10:42:03 downsj Exp $"; +static char rcsid[] = "$OpenBSD: getnetent.c,v 1.2 1998/05/22 00:47:19 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -128,7 +128,7 @@ getnetent() if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) return (NULL); again: - p = fgets(line, BUFSIZ, netf); + p = fgets(line, sizeof line, netf); if (p == NULL) return (NULL); if (*p == '#') diff --git a/usr.sbin/named/libresolv/getnetnamadr.c b/usr.sbin/named/libresolv/getnetnamadr.c index 924bbb1dbb1..5ed407d6d5c 100644 --- a/usr.sbin/named/libresolv/getnetnamadr.c +++ b/usr.sbin/named/libresolv/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.1 1997/03/12 10:42:04 downsj Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.2 1998/05/22 00:47:20 millert Exp $ */ /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro * Dep. Matematica Universidade de Coimbra, Portugal, Europe @@ -44,9 +44,9 @@ #if 0 static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; -static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; +static char rcsid[] = "$From: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.1 1997/03/12 10:42:04 downsj Exp $"; +static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.2 1998/05/22 00:47:20 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -108,7 +108,7 @@ getnetanswer(answer, anslen, net_i) char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap, *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0; static struct netent net_entry; -static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; +static char *net_aliases[MAXALIASES], netbuf[PACKETSZ]; /* * find first satisfactory answer diff --git a/usr.sbin/named/libresolv/res_comp.c b/usr.sbin/named/libresolv/res_comp.c index a40c00763da..1f71dd70105 100644 --- a/usr.sbin/named/libresolv/res_comp.c +++ b/usr.sbin/named/libresolv/res_comp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_comp.c,v 1.1 1997/03/12 10:42:08 downsj Exp $ */ +/* $OpenBSD: res_comp.c,v 1.2 1998/05/22 00:47:21 millert Exp $ */ /* * ++Copyright++ 1985, 1993 @@ -58,9 +58,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: res_comp.c,v 8.11 1996/12/02 09:17:22 vixie Exp $"; +static char rcsid[] = "$From: res_comp.c,v 8.12 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_comp.c,v 1.1 1997/03/12 10:42:08 downsj Exp $"; +static char rcsid[] = "$OpenBSD: res_comp.c,v 1.2 1998/05/22 00:47:21 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -100,7 +100,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) register char *dn; register int n, c; char *eom; - int len = -1, checked = 0; + int len = -1, checked = 0, octets = 0; dn = exp_dn; cp = comp_dn; @@ -114,6 +114,9 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) */ switch (n & INDIR_MASK) { case 0: + octets += (n + 1); + if (octets > MAXCDNAME) + return (-1); if (dn != exp_dn) { if (dn >= eom) return (-1); @@ -185,6 +188,8 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) dn = (u_char *)exp_dn; cp = comp_dn; + if (length > MAXCDNAME) + length = MAXCDNAME; eob = cp + length; lpp = cpp = NULL; if (dnptrs != NULL) { diff --git a/usr.sbin/named/libresolv/res_debug.c b/usr.sbin/named/libresolv/res_debug.c index ffce419c111..e09e12fb379 100644 --- a/usr.sbin/named/libresolv/res_debug.c +++ b/usr.sbin/named/libresolv/res_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_debug.c,v 1.1 1997/03/12 10:42:09 downsj Exp $ */ +/* $OpenBSD: res_debug.c,v 1.2 1998/05/22 00:47:22 millert Exp $ */ /* * ++Copyright++ 1985, 1990, 1993 @@ -80,9 +80,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; +static char rcsid[] = "$From: res_debug.c,v 8.20 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_debug.c,v 1.1 1997/03/12 10:42:09 downsj Exp $"; +static char rcsid[] = "$OpenBSD: res_debug.c,v 1.2 1998/05/22 00:47:22 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -1136,40 +1136,47 @@ static u_int8_t precsize_aton(strptr) char **strptr; { - unsigned int mval = 0, cmval = 0; u_int8_t retval = 0; - register char *cp; - register int exponent; - register int mantissa; + char *cp; + int exponent = 0; + int mantissa = 0; cp = *strptr; + while (isdigit(*cp)) { + if (mantissa == 0) + mantissa = *cp - '0'; + else + exponent++; + cp++; + } - while (isdigit(*cp)) - mval = mval * 10 + (*cp++ - '0'); - - if (*cp == '.') { /* centimeters */ + if (*cp == '.') { cp++; if (isdigit(*cp)) { - cmval = (*cp++ - '0') * 10; + if (mantissa == 0) + mantissa = *cp - '0'; + else + exponent++; + cp++; + if (isdigit(*cp)) { - cmval += (*cp++ - '0'); + if (mantissa == 0) + mantissa = *cp - '0'; + else + exponent++; + cp++; } + else + exponent++; } } - cmval = (mval * 100) + cmval; - - for (exponent = 0; exponent < 9; exponent++) - if (cmval < poweroften[exponent+1]) - break; - - mantissa = cmval / poweroften[exponent]; - if (mantissa > 9) - mantissa = 9; + else + exponent += 2; + if (mantissa == 0) + exponent = 0; retval = (mantissa << 4) | exponent; - *strptr = cp; - return (retval); } diff --git a/usr.sbin/named/libresolv/res_init.c b/usr.sbin/named/libresolv/res_init.c index c128e346290..8629d5370e9 100644 --- a/usr.sbin/named/libresolv/res_init.c +++ b/usr.sbin/named/libresolv/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.2 1997/03/14 03:40:33 downsj Exp $ */ +/* $OpenBSD: res_init.c,v 1.3 1998/05/22 00:47:24 millert Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -58,9 +58,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; +static char rcsid[] = "$From: res_init.c,v 8.8 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_init.c,v 1.2 1997/03/14 03:40:33 downsj Exp $"; +static char rcsid[] = "$OpenBSD: res_init.c,v 1.3 1998/05/22 00:47:24 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -165,7 +165,7 @@ res_init() register FILE *fp; register char *cp, **pp; register int n; - char buf[BUFSIZ]; + char buf[MAXDNAME]; int nserv = 0; /* number of nameserver records read from file */ int haveenv = 0; int havesearch = 0; @@ -438,7 +438,6 @@ res_init() return (0); } -/* ARGSUSED */ static void res_setoptions(options, source) char *options, *source; diff --git a/usr.sbin/named/libresolv/res_query.c b/usr.sbin/named/libresolv/res_query.c index 852572b1bec..ad91c0374c2 100644 --- a/usr.sbin/named/libresolv/res_query.c +++ b/usr.sbin/named/libresolv/res_query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_query.c,v 1.2 1997/03/14 03:40:34 downsj Exp $ */ +/* $OpenBSD: res_query.c,v 1.3 1998/05/22 00:47:25 millert Exp $ */ /* * ++Copyright++ 1988, 1993 @@ -58,9 +58,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; +static char rcsid[] = "$From: res_query.c,v 8.10 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_query.c,v 1.2 1997/03/14 03:40:34 downsj Exp $"; +static char rcsid[] = "$OpenBSD: res_query.c,v 1.3 1998/05/22 00:47:25 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -329,7 +329,7 @@ res_querydomain(name, domain, class, type, answer, anslen) { char nbuf[MAXDNAME]; const char *longname = nbuf; - int n; + int n, d; if ((_res.options & RES_INIT) == 0 && res_init() == -1) { h_errno = NETDB_INTERNAL; @@ -345,15 +345,26 @@ res_querydomain(name, domain, class, type, answer, anslen) * Check for trailing '.'; * copy without '.' if present. */ - n = strlen(name) - 1; - if (n != (0 - 1) && name[n] == '.' && n < sizeof(nbuf) - 1) { - bcopy(name, nbuf, n); + n = strlen(name); + if (n >= MAXDNAME) { + h_errno = NO_RECOVERY; + return (-1); + } + n--; + if (n >= 0 && name[n] == '.') { + strncpy(nbuf, name, n); nbuf[n] = '\0'; } else longname = name; - } else - sprintf(nbuf, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain); - + } else { + n = strlen(name); + d = strlen(domain); + if (n + d + 1 >= MAXDNAME) { + h_errno = NO_RECOVERY; + return (-1); + } + sprintf(nbuf, "%s.%s", name, domain); + } return (res_query(longname, class, type, answer, anslen)); } @@ -387,8 +398,8 @@ hostalias(name) break; for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) ; - strncpy(abuf, cp1, sizeof(abuf) - 1); abuf[sizeof(abuf) - 1] = *cp2 = '\0'; + strncpy(abuf, cp1, sizeof(abuf) - 1); fclose(fp); return (abuf); } diff --git a/usr.sbin/named/libresolv/res_send.c b/usr.sbin/named/libresolv/res_send.c index 437477a3306..436bb8cb9d6 100644 --- a/usr.sbin/named/libresolv/res_send.c +++ b/usr.sbin/named/libresolv/res_send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_send.c,v 1.1 1997/03/12 10:42:11 downsj Exp $ */ +/* $OpenBSD: res_send.c,v 1.2 1998/05/22 00:47:26 millert Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -58,9 +58,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$From: res_send.c,v 8.12 1996/10/08 04:51:06 vixie Exp $"; +static char rcsid[] = "$From: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_send.c,v 1.1 1997/03/12 10:42:11 downsj Exp $"; +static char rcsid[] = "$OpenBSD: res_send.c,v 1.2 1998/05/22 00:47:26 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -607,7 +607,14 @@ read_len: if ((long) timeout.tv_sec <= 0) timeout.tv_sec = 1; timeout.tv_usec = 0; + /* XXX - kernel can deal with > FD_SETSIZE */ + if (s+1 > FD_SETSIZE) { + Perror(stderr, "s+1 > FD_SETSIZE", EMFILE); + res_close(); + goto next_ns; + } wait: + /* XXX - kernel can deal with > FD_SETSIZE */ FD_ZERO(&dsmask); FD_SET(s, &dsmask); n = select(s+1, &dsmask, (fd_set *)NULL, diff --git a/usr.sbin/named/man/dig.1 b/usr.sbin/named/man/dig.1 index eb897404005..ae591d0882f 100644 --- a/usr.sbin/named/man/dig.1 +++ b/usr.sbin/named/man/dig.1 @@ -1,5 +1,5 @@ -.\" $OpenBSD: dig.1,v 1.5 1998/03/16 11:02:03 d Exp $ -.\" $From: dig.1,v 8.1 1994/12/15 06:24:10 vixie Exp $ +.\" $OpenBSD: dig.1,v 1.6 1998/05/22 00:47:27 millert Exp $ +.\" $From: dig.1,v 8.2 1997/06/01 20:34:33 vixie Exp $ .\" .\" ++Copyright++ 1993 .\" - diff --git a/usr.sbin/named/named/Makefile b/usr.sbin/named/named/Makefile index 54a0ddfb8f3..debd0c37640 100644 --- a/usr.sbin/named/named/Makefile +++ b/usr.sbin/named/named/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.2 1997/03/12 10:42:20 downsj Exp $ +# $OpenBSD: Makefile,v 1.3 1998/05/22 00:47:29 millert Exp $ # $NetBSD: Makefile,v 1.1 1996/02/02 15:28:00 mrg Exp $ # from: $Id: Makefile,v 8.1 1994/12/15 06:23:45 vixie Exp @@ -15,7 +15,9 @@ CFLAGS+=${INCLUDE} ${CONFIG} LDADD= ${LIBRESOLV} makeversionc: - (sed -e "s|%VERSION%|${VER}|" \ + (u=root d=`pwd` h=localhost t=`date +%c`; \ + sed -e "s|%WHEN%|$${t}|" -e "s|%VERSION%|"${VER}"|" \ + -e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \ < ${.CURDIR}/Version.c > ${.CURDIR}/version.c) .include <bsd.prog.mk> diff --git a/usr.sbin/named/named/Version.c b/usr.sbin/named/named/Version.c index 5170d4fbd6e..043336d91c5 100644 --- a/usr.sbin/named/named/Version.c +++ b/usr.sbin/named/named/Version.c @@ -1,20 +1,21 @@ -/* $OpenBSD: Version.c,v 1.2 1997/03/12 10:42:20 downsj Exp $ */ +/* $OpenBSD: Version.c,v 1.3 1998/05/22 00:47:30 millert Exp $ */ /* * @(#)Version.c 4.9 (Berkeley) 7/21/90 - * $From: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $ + * $From: Version.c,v 8.2 1997/06/01 20:34:34 vixie Exp $ */ #ifndef lint #if 0 -char sccsid[] = "@(#)named %VERSION%"; -char rcsid[] = "$From: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $"; +char sccsid[] = "@(#)named %VERSION% %WHEN% %WHOANDWHERE%"; +char rcsid[] = "$From: Version.c,v 8.2 1997/06/01 20:34:34 vixie Exp $"; #else -char rcsid[] = "$OpenBSD: Version.c,v 1.2 1997/03/12 10:42:20 downsj Exp $"; +char rcsid[] = "$OpenBSD: Version.c,v 1.3 1998/05/22 00:47:30 millert Exp $"; #endif #endif /* not lint */ -char Version[] = "named %VERSION%"; +char Version[] = "named %VERSION% %WHEN%\n\t%WHOANDWHERE%"; +char ShortVersion[] = "%VERSION%"; #ifdef COMMENT diff --git a/usr.sbin/named/named/db_defs.h b/usr.sbin/named/named/db_defs.h index 75dfee0dc0b..50a7568c959 100644 --- a/usr.sbin/named/named/db_defs.h +++ b/usr.sbin/named/named/db_defs.h @@ -1,8 +1,8 @@ -/* $OpenBSD: db_defs.h,v 1.2 1997/03/12 10:42:21 downsj Exp $ */ +/* $OpenBSD: db_defs.h,v 1.3 1998/05/22 00:47:31 millert Exp $ */ /* * from db.h 4.16 (Berkeley) 6/1/90 - * $From: db_defs.h,v 8.5 1996/08/27 08:33:23 vixie Exp $ + * $From: db_defs.h,v 8.6 1997/06/01 20:34:34 vixie Exp $ */ /* @@ -78,6 +78,9 @@ */ struct databuf { struct databuf *d_next; /* linked list */ +#ifdef STATS + struct nameser *d_ns; /* NS from whence this came */ +#endif u_int32_t d_ttl; /* time to live */ /* if d_zone == DB_Z_CACHE, then * d_ttl is actually the time when @@ -93,13 +96,10 @@ struct databuf { int16_t d_class; /* class number */ int16_t d_type; /* type number */ int16_t d_size; /* size of data area */ + u_int32_t d_rcnt; #ifdef NCACHE unsigned d_rcode :4; /* rcode added for negative caching */ #endif - unsigned d_rcnt :12; -#ifdef STATS - struct nameser *d_ns; /* NS from whence this came */ -#endif u_int16_t d_nstime; /* NS response time, milliseconds */ u_char d_data[sizeof(char*)]; /* malloc'd (padded) */ }; diff --git a/usr.sbin/named/named/db_func.h b/usr.sbin/named/named/db_func.h index bb5b8956748..43486481f1b 100644 --- a/usr.sbin/named/named/db_func.h +++ b/usr.sbin/named/named/db_func.h @@ -1,8 +1,8 @@ -/* $OpenBSD: db_func.h,v 1.2 1997/03/12 10:42:22 downsj Exp $ */ +/* $OpenBSD: db_func.h,v 1.3 1998/05/22 00:47:32 millert Exp $ */ /* db_proc.h - prototypes for functions in db_*.c * - * $From: db_func.h,v 8.12 1996/09/22 00:13:10 vixie Exp $ + * $From: db_func.h,v 8.13 1997/06/01 20:34:34 vixie Exp $ */ /* ++from db_update.c++ */ @@ -13,6 +13,7 @@ extern int db_update __P((char name[], struct hashbuf *htp)), db_cmp __P((struct databuf *,struct databuf *)), findMyZone __P((struct namebuf *np, int class)); +extern void fixttl __P((struct databuf *dp)); /* --from db_update.c-- */ /* ++from db_reload.c++ */ diff --git a/usr.sbin/named/named/db_load.c b/usr.sbin/named/named/db_load.c index 6e0d9463dfb..1a777a45909 100644 --- a/usr.sbin/named/named/db_load.c +++ b/usr.sbin/named/named/db_load.c @@ -1,11 +1,11 @@ -/* $OpenBSD: db_load.c,v 1.3 1997/04/27 23:09:43 deraadt Exp $ */ +/* $OpenBSD: db_load.c,v 1.4 1998/05/22 00:47:33 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)db_load.c 4.38 (Berkeley) 3/2/91"; -static char rcsid[] = "$From: db_load.c,v 8.31 1996/12/18 04:09:48 vixie Exp $"; +static char rcsid[] = "$From: db_load.c,v 8.32 1997/06/01 20:34:34 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: db_load.c,v 1.3 1997/04/27 23:09:43 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: db_load.c,v 1.4 1998/05/22 00:47:33 millert Exp $"; #endif #endif /* not lint */ @@ -329,6 +329,13 @@ db_load(filename, in_origin, zp, def_domain) n = n * 10 + (*cp++ - '0'); } while (isdigit(*cp)); + if (*cp != '\0') { + errs++; + syslog(LOG_INFO, + "%s: Line %d: bad TTL: %s.\n", + filename, lineno, buf); + break; + } if (zp->z_type == Z_CACHE) { /* this allows the cache entry to age */ /* while sitting on disk (powered off) */ @@ -1994,7 +2001,7 @@ get_netlist(fp, netlistp, allow, print_tag) char *print_tag; { struct netinfo *ntp, **end; - char buf[BUFSIZ], *maskp; + char buf[MAXDNAME], *maskp; struct in_addr ina; for (end = netlistp; *end; end = &(**end).next) diff --git a/usr.sbin/named/named/db_lookup.c b/usr.sbin/named/named/db_lookup.c index e1fed218445..500eaebd35c 100644 --- a/usr.sbin/named/named/db_lookup.c +++ b/usr.sbin/named/named/db_lookup.c @@ -1,11 +1,11 @@ -/* $OpenBSD: db_lookup.c,v 1.2 1997/03/12 10:42:24 downsj Exp $ */ +/* $OpenBSD: db_lookup.c,v 1.3 1998/05/22 00:47:34 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)db_lookup.c 4.18 (Berkeley) 3/21/91"; -static char rcsid[] = "$Id: db_lookup.c,v 1.2 1997/03/12 10:42:24 downsj Exp $"; +static char rcsid[] = "$From: db_lookup.c,v 8.9 1996/09/22 00:13:10 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: db_lookup.c,v 1.2 1997/03/12 10:42:24 downsj Exp $"; +static char rcsid[] = "$OpenBSD: db_lookup.c,v 1.3 1998/05/22 00:47:34 millert Exp $"; #endif #endif /* not lint */ diff --git a/usr.sbin/named/named/db_secure.c b/usr.sbin/named/named/db_secure.c index fd3a4e7e774..2cc7c065feb 100644 --- a/usr.sbin/named/named/db_secure.c +++ b/usr.sbin/named/named/db_secure.c @@ -1,10 +1,10 @@ -/* $OpenBSD: db_secure.c,v 1.2 1997/03/12 10:42:25 downsj Exp $ */ +/* $OpenBSD: db_secure.c,v 1.3 1998/05/22 00:47:36 millert Exp $ */ #ifndef LINT #if 0 static char rcsid[] = "$From: db_secure.c,v 8.6 1996/05/17 09:10:46 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: db_secure.c,v 1.2 1997/03/12 10:42:25 downsj Exp $"; +static char rcsid[] = "$OpenBSD: db_secure.c,v 1.3 1998/05/22 00:47:36 millert Exp $"; #endif #endif @@ -35,7 +35,7 @@ build_secure_netlist(zp) struct zoneinfo *zp; { struct netinfo *ntp = NULL, **netlistp, **end; - char buf[BUFSIZ]; + char buf[MAXDNAME]; struct hashbuf *htp; struct namebuf *snp; struct databuf *dp; @@ -71,7 +71,7 @@ build_secure_netlist(zp) continue; } bzero(buf, sizeof(buf)); - bcopy(dp->d_data+1, buf, dp->d_size-1); + bcopy(dp->d_data+1, buf, MIN(dp->d_size, sizeof(buf))-1); maskptr=strchr(buf, MASK_SEP); if (maskptr) { *maskptr++ = 0; diff --git a/usr.sbin/named/named/db_update.c b/usr.sbin/named/named/db_update.c index bd4d6464330..a34e3210535 100644 --- a/usr.sbin/named/named/db_update.c +++ b/usr.sbin/named/named/db_update.c @@ -1,11 +1,11 @@ -/* $OpenBSD: db_update.c,v 1.2 1997/03/12 10:42:26 downsj Exp $ */ +/* $OpenBSD: db_update.c,v 1.3 1998/05/22 00:47:37 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)db_update.c 4.28 (Berkeley) 3/21/91"; -static char rcsid[] = "$From: db_update.c,v 8.18 1996/10/08 04:51:03 vixie Exp $"; +static char rcsid[] = "$From: db_update.c,v 8.19 1997/06/01 20:34:34 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: db_update.c,v 1.2 1997/03/12 10:42:26 downsj Exp $"; +static char rcsid[] = "$OpenBSD: db_update.c,v 1.3 1998/05/22 00:47:37 millert Exp $"; #endif #endif /* not lint */ @@ -77,8 +77,6 @@ static char rcsid[] = "$OpenBSD: db_update.c,v 1.2 1997/03/12 10:42:26 downsj Ex #include "named.h" -static void fixttl __P((struct databuf *)); - /* int * isRefByNS(name, htp) * recurse through all of `htp' looking for NS RR's that refer to `name'. @@ -643,7 +641,7 @@ db_update(name, odp, newdp, flags, htp) return (OK); } -static void +void fixttl(dp) register struct databuf *dp; { diff --git a/usr.sbin/named/named/ns_forw.c b/usr.sbin/named/named/ns_forw.c index 7a41cde8a6d..c3d30749d46 100644 --- a/usr.sbin/named/named/ns_forw.c +++ b/usr.sbin/named/named/ns_forw.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_forw.c,v 1.3 1997/04/27 23:09:43 deraadt Exp $ */ +/* $OpenBSD: ns_forw.c,v 1.4 1998/05/22 00:47:38 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_forw.c 4.32 (Berkeley) 3/3/91"; static char rcsid[] = "$From: ns_forw.c,v 8.19 1996/12/02 09:27:36 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: ns_forw.c,v 1.3 1997/04/27 23:09:43 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ns_forw.c,v 1.4 1998/05/22 00:47:38 millert Exp $"; #endif #endif /* not lint */ @@ -567,6 +567,13 @@ nslookup(nsp, qp, syslogdname, sysloginfo) qs->nsdata = dp; qs->nretry = 0; /* + * If this A RR has no RTT, initialize its RTT to a + * small random value. + */ + if (dp->d_nstime == 0) + dp->d_nstime = 1 + + (int)(25.0*rand()/(RAND_MAX + 1.0)); + /* * if we are being asked to fwd a query whose * nameserver list includes our own name/address(es), * then we have detected a lame delegation and rather diff --git a/usr.sbin/named/named/ns_glob.h b/usr.sbin/named/named/ns_glob.h index e67df41024f..87eaed92a68 100644 --- a/usr.sbin/named/named/ns_glob.h +++ b/usr.sbin/named/named/ns_glob.h @@ -1,8 +1,8 @@ -/* $OpenBSD: ns_glob.h,v 1.2 1997/03/12 10:42:30 downsj Exp $ */ +/* $OpenBSD: ns_glob.h,v 1.3 1998/05/22 00:47:39 millert Exp $ */ /* * from ns.h 4.33 (Berkeley) 8/23/90 - * $From: ns_glob.h,v 8.11 1996/11/11 06:36:49 vixie Exp $ + * $From: ns_glob.h,v 8.12 1997/06/01 20:34:34 vixie Exp $ */ /* @@ -250,6 +250,7 @@ DECL const char sendtoStr[] INIT("sendto"); /* defined in version.c, can't use DECL/INIT */ extern char Version[]; +extern char ShortVersion[]; /* max value of xfers_running */ DECL int max_xfers_running INIT(MAX_XFERS_RUNNING); diff --git a/usr.sbin/named/named/ns_init.c b/usr.sbin/named/named/ns_init.c index 7f87972bea5..316702df4dd 100644 --- a/usr.sbin/named/named/ns_init.c +++ b/usr.sbin/named/named/ns_init.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_init.c,v 1.4 1997/06/10 20:04:34 deraadt Exp $ */ +/* $OpenBSD: ns_init.c,v 1.5 1998/05/22 00:47:40 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_init.c 4.38 (Berkeley) 3/21/91"; -static char rcsid[] = "$From: ns_init.c,v 8.24 1996/12/02 09:17:21 vixie Exp $"; +static char rcsid[] = "$From: ns_init.c,v 8.25 1997/06/01 20:34:34 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: ns_init.c,v 1.4 1997/06/10 20:04:34 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ns_init.c,v 1.5 1998/05/22 00:47:40 millert Exp $"; #endif #endif /* not lint */ @@ -239,7 +239,7 @@ boot_read(filename, includefile) int includefile; { register struct zoneinfo *zp; - char buf[BUFSIZ], obuf[BUFSIZ], *source; + char buf[MAXDNAME], obuf[MAXDNAME], *source; FILE *fp; int type; int class; @@ -564,7 +564,8 @@ boot_read(filename, includefile) if (!source) { /* * We will always transfer this zone again - * after a reload. + * after a reload. Note that _PATH_TMPDIR + * is not writable by normal users on OpenBSD. */ sprintf(buf, "%s/NsTmpXXXXXXXXXX", _PATH_TMPDIR); @@ -583,21 +584,25 @@ boot_read(filename, includefile) (strcmp(source, zp->z_source) || (stat(zp->z_source, &f_time) == -1 || (zp->z_ftime != f_time.st_mtime)))) { - dprintf(1, (ddt, "backup file changed\n")); + dprintf(1, (ddt, + "backup file changed or missing\n")); free(zp->z_source); zp->z_source = NULL; - zp->z_flags &= ~Z_AUTH; zp->z_serial = 0; /* force xfer */ + if (zp->z_flags & Z_AUTH) { + zp->z_flags &= ~Z_AUTH; #ifdef CLEANCACHE - remove_zone(hashtab, zp - zones, 1); + remove_zone(hashtab, zp - zones, 1); #else - remove_zone(hashtab, zp - zones); + remove_zone(hashtab, zp - zones); #endif - /* - * reload parent so that NS records are - * present during the zone transfer. - */ - do_reload(zp->z_origin, zp->z_type, zp->z_class); + /* + * reload parent so that NS records are + * present during the zone transfer. + */ + do_reload(zp->z_origin, zp->z_type, + zp->z_class); + } } if (zp->z_source) free(source); @@ -681,7 +686,7 @@ static void get_forwarders(fp) FILE *fp; { - char buf[BUFSIZ]; + char buf[MAXDNAME]; register struct fwdinfo *fip = NULL, *ftp = NULL; #ifdef SLAVE_FORWARD diff --git a/usr.sbin/named/named/ns_main.c b/usr.sbin/named/named/ns_main.c index 27f59ff84e0..c4bcd7b0019 100644 --- a/usr.sbin/named/named/ns_main.c +++ b/usr.sbin/named/named/ns_main.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_main.c,v 1.10 1998/04/25 14:05:08 d Exp $ */ +/* $OpenBSD: ns_main.c,v 1.11 1998/05/22 00:47:41 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91"; -static char rcsid[] = "$From: ns_main.c,v 8.24 1996/11/26 10:11:22 vixie Exp $"; +static char rcsid[] = "$From: ns_main.c,v 8.25 1997/06/01 20:34:34 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: ns_main.c,v 1.10 1998/04/25 14:05:08 d Exp $"; +static char rcsid[] = "$OpenBSD: ns_main.c,v 1.11 1998/05/22 00:47:41 millert Exp $"; #endif #endif /* not lint */ @@ -182,7 +182,7 @@ main(argc, argv, envp) const int on = 1; int rfd, size, len; time_t lasttime, maxctime; - u_char buf[BUFSIZ]; + u_char buf[PACKETSZ]; #ifdef NeXT int old_sigmask; #endif @@ -873,7 +873,7 @@ main(argc, argv, envp) malloc(rbufsize)) ) { sp->s_buf = buf; - sp->s_size = sizeof(buf); + sp->s_bufsize=sizeof(buf); } else { sp->s_bufsize = rbufsize; } @@ -906,6 +906,12 @@ main(argc, argv, envp) sp->s_bufp += n; sp->s_size -= n; } + + if (sp->s_size > 0 && + (n == -1) && + (errno == PORT_WOULDBLK)) + continue; + /* * we don't have enough memory for the query. * if we have a query id, then we will send an @@ -926,8 +932,10 @@ main(argc, argv, envp) (void) writemsg(sp->s_rfd, sp->s_buf, HFIXEDSZ); } + sqrm(sp); continue; } + /* * If the message is too short to contain a valid * header, try to send back an error, and drop the @@ -948,10 +956,9 @@ main(argc, argv, envp) (void) writemsg(sp->s_rfd, sp->s_buf, HFIXEDSZ); } + sqrm(sp); continue; } - if ((n == -1) && (errno == PORT_WOULDBLK)) - continue; if (n <= 0) { sqrm(sp); continue; diff --git a/usr.sbin/named/named/ns_ncache.c b/usr.sbin/named/named/ns_ncache.c index f9d84c57d32..c55335d988a 100644 --- a/usr.sbin/named/named/ns_ncache.c +++ b/usr.sbin/named/named/ns_ncache.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ns_ncache.c,v 1.2 1997/03/12 10:42:32 downsj Exp $ */ +/* $OpenBSD: ns_ncache.c,v 1.3 1998/05/22 00:47:42 millert Exp $ */ /************************************************************************** * ns_ncache.c @@ -71,7 +71,7 @@ cache_n_resp(msg, msglen) u_int16_t atype; u_char *tp = cp; u_char *cp1; - u_char data[BUFSIZ+MAXDNAME]; + u_char data[MAXDNAME*2 + INT32SZ*5]; size_t len = sizeof data; /* we store NXDOMAIN as T_SOA regardless of the query type */ diff --git a/usr.sbin/named/named/ns_req.c b/usr.sbin/named/named/ns_req.c index 1d5c8c0d257..038aa86dc9a 100644 --- a/usr.sbin/named/named/ns_req.c +++ b/usr.sbin/named/named/ns_req.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_req.c,v 1.4 1998/03/31 00:16:30 deraadt Exp $ */ +/* $OpenBSD: ns_req.c,v 1.5 1998/05/22 00:47:44 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_req.c 4.47 (Berkeley) 7/1/91"; -static char rcsid[] = "$From: ns_req.c,v 8.27 1996/10/08 04:51:03 vixie Exp $"; +static char rcsid[] = "$From: ns_req.c,v 8.28 1997/06/01 20:34:34 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: ns_req.c,v 1.4 1998/03/31 00:16:30 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ns_req.c,v 1.5 1998/05/22 00:47:44 millert Exp $"; #endif #endif /* not lint */ @@ -503,7 +503,7 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from) PUTLONG(0, *cpp); /* TTL */ tp = *cpp; /* Temp RdLength */ PUTSHORT(0, *cpp); - copyCharString(cpp, Version); + copyCharString(cpp, ShortVersion); PUTSHORT((*cpp) - (tp + INT16SZ), tp); /* Real RdLength */ *msglenp = *cpp - msg; /* Total message length */ return (Finish); @@ -1704,7 +1704,7 @@ doaxfr(np, rfp, top, class) struct namebuf *tnp; /* top namebuf */ struct databuf *tdp; /* top databuf */ struct namebuf **npp, **nppend; - u_char msg[PACKETSZ]; + u_char msg[64*1024]; u_char *cp; const char *fname; char dname[MAXDNAME]; @@ -2020,8 +2020,8 @@ startxfr(qsp, np, soa, soalen, class, dname) */ setsockopt(qsp->s_rfd, SOL_SOCKET, SO_LINGER, (char *)&ll, sizeof ll); - close(qsp->s_rfd); #endif + close(qsp->s_rfd); _exit(0); /* NOTREACHED */ } diff --git a/usr.sbin/named/named/ns_resp.c b/usr.sbin/named/named/ns_resp.c index 3dee212bbfb..8dee880acd2 100644 --- a/usr.sbin/named/named/ns_resp.c +++ b/usr.sbin/named/named/ns_resp.c @@ -1,11 +1,11 @@ -/* $OpenBSD: ns_resp.c,v 1.3 1997/04/27 23:09:45 deraadt Exp $ */ +/* $OpenBSD: ns_resp.c,v 1.4 1998/05/22 00:47:45 millert Exp $ */ #if !defined(lint) && !defined(SABER) #if 0 static char sccsid[] = "@(#)ns_resp.c 4.65 (Berkeley) 3/3/91"; -static char rcsid[] = "$From: ns_resp.c,v 8.37 1996/12/02 09:17:21 vixie Exp $"; +static char rcsid[] = "$From: ns_resp.c,v 8.38 1997/06/01 20:34:34 vixie Exp vixie $"; #else -static char rcsid[] = "$OpenBSD: ns_resp.c,v 1.3 1997/04/27 23:09:45 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ns_resp.c,v 1.4 1998/05/22 00:47:45 millert Exp $"; #endif #endif /* not lint */ @@ -132,6 +132,7 @@ struct flush_set { int fs_class; u_int fs_cred; struct db_list *fs_list; + struct db_list *fs_last; }; static void rrsetadd __P((struct flush_set *, char *, @@ -142,7 +143,18 @@ static int rrsetcmp __P((char *, struct db_list *)), check_root __P((void)), check_ns __P((void)), rrextract __P((u_char *, int, u_char *, - struct databuf **, char *, int)); + struct databuf **, char *, int, + char **)); + +static void add_related_additional __P((char *)); +static void free_related_additional __P((void)); +static int related_additional __P((char *)); +static void maybe_free __P((char **)); + +#define MAX_RELATED 100 + +static int num_related = 0; +static char *related[MAX_RELATED]; #ifdef LAME_LOGGING static char * @@ -236,11 +248,11 @@ ns_resp(msg, msglen) struct flush_set *flushset; struct sockaddr_in *nsa; struct databuf *nsp[NSMAX]; - int i, c, n, qdcount, ancount, aucount, nscount, arcount; + int i, c, n, qdcount, ancount, aucount, nscount, arcount, arfirst; int qtype, qclass, dbflags; int restart; /* flag for processing cname response */ int validanswer; - int cname, lastwascname; + int cname, lastwascname, externalcname; int count, founddata, foundname; int buflen; int newmsglen; @@ -256,6 +268,9 @@ ns_resp(msg, msglen) struct namebuf *np; struct netinfo *lp; struct fwdinfo *fwd; + char *tname = NULL; + + free_related_additional(); nameserIncr(from_addr.sin_addr, nssRcvdR); nsp[0] = NULL; @@ -695,7 +710,8 @@ ns_resp(msg, msglen) /* * Add the info received in the response to the data base. */ - c = ancount + aucount + arcount; + arfirst = ancount + aucount; + c = arfirst + arcount; /* -ve $ing non-existence of record, must handle non-authoritative * NOERRORs with c == 0. @@ -759,7 +775,8 @@ ns_resp(msg, msglen) nscount = 0; cname = 0; lastwascname = 0; - strncpy(aname, qname, sizeof aname); + externalcname = 0; + strncpy(aname, qname, sizeof aname-1); aname[sizeof aname-1] = '\0'; if (count) { @@ -775,12 +792,14 @@ ns_resp(msg, msglen) struct databuf *dp; int type; + maybe_free(&tname); if (cp >= eom) { formerrmsg = outofDataFinal; goto formerr; } - n = rrextract(msg, msglen, cp, &dp, name, sizeof name); + n = rrextract(msg, msglen, cp, &dp, name, sizeof name, &tname); if (n < 0) { + maybe_free(&tname); formerrmsg = outofDataFinal; goto formerr; } @@ -790,16 +809,24 @@ ns_resp(msg, msglen) type = dp->d_type; if (i < ancount) { /* Answer section. */ - if (strcasecmp(name, aname) != 0) { - syslog(LOG_DEBUG, "wrong ans. name (%s != %s)", - name, aname); + if (externalcname || (strcasecmp(name, aname) != 0)) { + if (!externalcname) + syslog(LOG_DEBUG, + "wrong ans. name (%s != %s)", + name, aname); + else + dprintf(3, (ddt, + "ignoring answer '%s' after external cname\n", + name)); db_free(dp); continue; } if (type == T_CNAME && qtype != T_CNAME && qtype != T_ANY) { - strncpy(aname, (char *)dp->d_data, sizeof aname); + strncpy(aname, (char *)dp->d_data, sizeof aname-1); aname[sizeof aname-1] = '\0'; + if (!samedomain(aname, qp->q_domain)) + externalcname = 1; cname = 1; lastwascname = 1; } else { @@ -807,27 +834,95 @@ ns_resp(msg, msglen) lastwascname = 0; } + if (tname != NULL) { + add_related_additional(tname); + tname = NULL; + } + dp->d_cred = (hp->aa && !strcasecmp(name, qname)) ? DB_C_AUTH : DB_C_ANSWER; } else { /* After answer section. */ if (lastwascname) { + dprintf(3, (ddt, + "last was cname, ignoring auth. and add.\n")); db_free(dp); break; } - if (i < ancount + aucount && type == T_NS) { + if (i < arfirst) { /* Authority section. */ - if (!samedomain(aname, name) || - (!cname && !samedomain(name, qp->q_domain)) - ) { + switch (type) { + case T_NS: + case T_SOA: + if (!samedomain(aname, name)){ + syslog(LOG_DEBUG, + "bad referral (%s !< %s)", + aname[0] ? aname : ".", + name[0] ? name : "."); + db_free(dp); + continue; + } else if (!samedomain(name, + qp->q_domain)) { + if (!externalcname) + syslog(LOG_DEBUG, + "bad referral (%s !< %s)", + name[0] ? name : ".", + qp->q_domain[0] ? + qp->q_domain : "."); + db_free(dp); + continue; + } + if (type == T_NS) { + nscount++; + add_related_additional(tname); + tname = NULL; + } + break; + case T_NXT: + case T_SIG: + break; + default: syslog(LOG_DEBUG, - "bad referral (%s !< %s)", - name, qp->q_domain); + "invalid RR type '%s' in authority section (name = '%s') from %s", + p_type(type), name, + sin_ntoa(&from_addr)); + db_free(dp); + continue; + } + } else { + /* Additional section. */ + switch (type) { + case T_A: + case T_AAAA: + if (externalcname || + !samedomain(name, qp->q_domain)) { + dprintf(3, (ddt, + "ignoring additional info '%s' type %s\n", + name, p_type(type))); + db_free(dp); + continue; + } + if (!related_additional(name)) { + syslog(LOG_DEBUG, + "unrelated additional info '%s' type %s from %s", + name, p_type(type), + sin_ntoa(&from_addr)); + db_free(dp); + continue; + } + break; + case T_KEY: + case T_SIG: + break; + default: + syslog(LOG_DEBUG, + "invalid RR type '%s' in additional section (name = '%s') from %s", + p_type(type), name, + sin_ntoa(&from_addr)); db_free(dp); continue; } - nscount++; } dp->d_cred = (qp->q_flags & Q_PRIMING) ? DB_C_ANSWER @@ -835,6 +930,7 @@ ns_resp(msg, msglen) } rrsetadd(flushset, name, dp); } + maybe_free(&tname); if (flushset) { rrsetupdate(flushset, dbflags); for (i = 0; i < count; i++) @@ -842,7 +938,7 @@ ns_resp(msg, msglen) free(flushset[i].fs_name); free((char*)flushset); } - if (lastwascname) + if (lastwascname && !externalcname) syslog(LOG_DEBUG, "%s (%s)", danglingCname, aname); if (cp > eom) { @@ -1109,7 +1205,11 @@ ns_resp(msg, msglen) qp->q_fwd = fwdtab; getname(np, tmpdomain, sizeof tmpdomain); + if (qp->q_domain != NULL) + free(qp->q_domain); qp->q_domain = strdup(tmpdomain); + if (qp->q_domain == NULL) + panic(ENOMEM, "ns_resp: strdup failed"); if ((n = nslookup(nsp, qp, dname, "ns_resp")) <= 0) { if (n < 0) { @@ -1155,17 +1255,20 @@ ns_resp(msg, msglen) qp->q_cmsglen = qp->q_msglen; } else if (qp->q_msg) (void) free(qp->q_msg); - if ((qp->q_msg = (u_char *)malloc(BUFSIZ)) == NULL) { + if ((qp->q_msg = (u_char *)malloc(PACKETSZ)) == NULL) { syslog(LOG_NOTICE, "resp: malloc error\n"); goto servfail; } n = res_mkquery(QUERY, dname, qclass, qtype, - NULL, 0, NULL, qp->q_msg, BUFSIZ); + NULL, 0, NULL, qp->q_msg, PACKETSZ); if (n < 0) { syslog(LOG_INFO, "resp: res_mkquery(%s) failed", dname); goto servfail; } + if (qp->q_name != NULL) + free(qp->q_name); + qp->q_name = savestr(dname); qp->q_msglen = n; hp = (HEADER *) qp->q_msg; hp->rd = 0; @@ -1264,29 +1367,35 @@ ns_resp(msg, msglen) (void) send_msg((u_char *)hp, (qp->q_cmsglen ? qp->q_cmsglen : qp->q_msglen), qp); timeout: + if (qp->q_stream != QSTREAM_NULL) + sqrm(qp->q_stream); qremove(qp); free_nsp(nsp); return; } static int -rrextract(msg, msglen, rrp, dpp, dname, namelen) +rrextract(msg, msglen, rrp, dpp, dname, namelen, tnamep) u_char *msg; int msglen; u_char *rrp; struct databuf **dpp; char *dname; int namelen; + char **tnamep; { register u_char *cp; register int n; int class, type, dlen, n1; u_int32_t ttl; u_char *cp1; - u_char data[BUFSIZ]; + u_char data[MAXDNAME*2 + INT32SZ*5]; register HEADER *hp = (HEADER *)msg; enum context context; + if (tnamep != NULL) + *tnamep = NULL; + *dpp = NULL; cp = rrp; if ((n = dn_expand(msg, msg + msglen, cp, dname, namelen)) < 0) { @@ -1371,6 +1480,8 @@ rrextract(msg, msglen, rrp, dpp, dname, namelen) cp += n; cp1 = data; n = strlen((char *)data) + 1; + if (tnamep != NULL && (type == T_NS || type == T_MB)) + *tnamep = strdup((char *)cp1); break; case T_SOA: @@ -1478,7 +1589,7 @@ rrextract(msg, msglen, rrp, dpp, dname, namelen) if (type == T_SRV) { /* Grab weight and port. */ - bcopy(cp, data, INT16SZ*2); + bcopy(cp, cp1, INT16SZ*2); cp1 += INT16SZ*2; cp += INT16SZ*2; } @@ -1497,6 +1608,9 @@ rrextract(msg, msglen, rrp, dpp, dname, namelen) } cp += n; + if (tnamep != NULL) + *tnamep = strdup((char *)cp1); + /* compute end of data */ cp1 += strlen((char *)cp1) + 1; /* compute size of data */ @@ -1656,12 +1770,12 @@ doupdate(msg, msglen, rrp, zone, savens, flags, cred) int class, type; struct databuf *dp; char dname[MAXDNAME]; - u_char data[BUFSIZ+MAX_MD5RSA_KEY_BYTES]; dprintf(3, (ddt, "doupdate(zone %d, savens %#lx, flags %#lx)\n", zone, (u_long)savens, (u_long)flags)); - if ((n = rrextract(msg, msglen, rrp, &dp, dname, sizeof(dname))) == -1) + if ((n = rrextract(msg, msglen, rrp, &dp, dname, sizeof(dname), NULL)) + == -1) return (-1); if (!dp) return (-1); @@ -1682,7 +1796,7 @@ doupdate(msg, msglen, rrp, zone, savens, flags, cred) } #endif if (!bogus && - ((temp = strrchr((char *)data, '.')) != NULL) && + ((temp = strrchr((char *)dp->d_data, '.')) != NULL) && !strcasecmp(temp, ".arpa") ) bogus++; @@ -1697,7 +1811,7 @@ doupdate(msg, msglen, rrp, zone, savens, flags, cred) "bogus root NS")) syslog(LOG_NOTICE, "bogus root NS %s rcvd from %s on query for \"%s\"", - data, sin_ntoa(&from_addr), qname); + dp->d_data, sin_ntoa(&from_addr), qname); db_free(dp); return (cp - rrp); } @@ -1707,7 +1821,7 @@ doupdate(msg, msglen, rrp, zone, savens, flags, cred) "bogus nonroot NS")) syslog(LOG_INFO, "bogus nonroot NS %s rcvd from %s on query for \"%s\"", - data, sin_ntoa(&from_addr), qname); + dp->d_data, sin_ntoa(&from_addr), qname); db_free(dp); return (cp - rrp); } @@ -2029,17 +2143,19 @@ sysquery(dname, class, type, nss, nsc, opcode) qp->q_flags |= Q_SYSTEM; getname(np, tmpdomain, sizeof tmpdomain); + if (qp->q_domain != NULL) + free(qp->q_domain); qp->q_domain = strdup(tmpdomain); - if (!qp->q_domain) + if (qp->q_domain == NULL) panic(ENOMEM, "ns_resp: strdup failed"); - if ((qp->q_msg = (u_char *)malloc(BUFSIZ)) == NULL) { + if ((qp->q_msg = (u_char *)malloc(PACKETSZ)) == NULL) { syslog(LOG_NOTICE, "sysquery: malloc failed"); goto err2; } n = res_mkquery(opcode, dname, class, type, NULL, 0, NULL, - qp->q_msg, BUFSIZ); + qp->q_msg, PACKETSZ); if (n < 0) { syslog(LOG_INFO, "sysquery: res_mkquery(%s) failed", dname); goto err2; @@ -2738,19 +2854,25 @@ rrsetadd(flushset, name, dp) fs->fs_type = dp->d_type; fs->fs_cred = dp->d_cred; fs->fs_list = NULL; + fs->fs_last = NULL; } dbl = (struct db_list *)malloc(sizeof(struct db_list)); if (!dbl) panic(-1, "rrsetadd: out of memory"); - dbl->db_next = fs->fs_list; + dbl->db_next = NULL; dbl->db_dp = dp; - fs->fs_list = dbl; + if (fs->fs_last == NULL) + fs->fs_list = dbl; + else + fs->fs_last->db_next = dbl; + fs->fs_last = dbl; } static int -ttlcheck(name,dbl) +ttlcheck(name,dbl,update) char *name; struct db_list *dbl; + int update; { int type = dbl->db_dp->d_type; int class = dbl->db_dp->d_class; @@ -2774,6 +2896,9 @@ ttlcheck(name,dbl) if (!match(dp, class, type)) continue; if (first) { + /* we can't update zone data so return early */ + if (dp->d_zone != 0) + return(0); ttl = dp->d_ttl; first = 0; } else if (ttl != dp->d_ttl) { @@ -2801,6 +2926,19 @@ ttlcheck(name,dbl) } dbp = dbp->db_next; } + + /* update ttl if required */ + if (update) { + for (dp = np->n_data; dp != NULL; dp = dp->d_next) { + if (!match(dp, class, type)) + continue; + if (dp->d_ttl > ttl) + break; + dp->d_ttl = ttl; + fixttl(dp); + } + } + return(1); } @@ -2881,8 +3019,8 @@ rrsetupdate(flushset, flags) while (fs->fs_name) { dprintf(1,(ddt, "rrsetupdate: %s\n", fs->fs_name[0] ? fs->fs_name : ".")); - if ((n = rrsetcmp(fs->fs_name,fs->fs_list)) && - ttlcheck(fs->fs_name,fs->fs_list)) { + if ((n = rrsetcmp(fs->fs_name, fs->fs_list)) && + ttlcheck(fs->fs_name, fs->fs_list, 0)) { if (n > 0) flushrrset(fs); @@ -2899,6 +3037,8 @@ rrsetupdate(flushset, flags) free((char *)odbp); } } else { + if (n == 0) + (void)ttlcheck(fs->fs_name, fs->fs_list, 1); dbp = fs->fs_list; while (dbp) { db_free(dbp->db_dp); @@ -2984,3 +3124,49 @@ delete_stale(np) } } } + + +static void +add_related_additional(name) + char *name; +{ + int i; + + if (num_related >= MAX_RELATED - 1) + return; + for (i = 0; i < num_related; i++) + if (strcasecmp(name, related[i]) == 0) + return; + related[num_related++] = name; +} + +static void +free_related_additional() { + int i; + + for (i = 0; i < num_related; i++) + free(related[i]); + num_related = 0; +} + +static int +related_additional(name) + char *name; +{ + int i; + + for (i = 0; i < num_related; i++) + if (strcasecmp(name, related[i]) == 0) + return (1); + return (0); +} + +static void +maybe_free(tname) + char **tname; +{ + if (tname == NULL || *tname == NULL) + return; + free(*tname); + *tname = NULL; +} diff --git a/usr.sbin/named/named/ns_validate.c b/usr.sbin/named/named/ns_validate.c index 1e5e63a979e..e412f25a5d3 100644 --- a/usr.sbin/named/named/ns_validate.c +++ b/usr.sbin/named/named/ns_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ns_validate.c,v 1.2 1997/03/12 10:42:37 downsj Exp $ */ +/* $OpenBSD: ns_validate.c,v 1.3 1998/05/22 00:47:46 millert Exp $ */ /************************************************************************** * ns_validate.c (was security.c in original ISI contribution) @@ -611,7 +611,7 @@ dovalidate(msg, msglen, rrp, zone, flags, qdomain, server, VCode) u_int32_t ttl; char dname[MAXDNAME]; u_char *cp1; - u_char data[BUFSIZ]; + u_char data[MAXDNAME*2 + INT32SZ*5]; register HEADER *hp = (HEADER *) msg; dprintf(2, (ddt, "dovalidate(zone %d, flags %x)\n", diff --git a/usr.sbin/named/named/storage.c b/usr.sbin/named/named/storage.c index b412a1cd3a7..e63a9645897 100644 --- a/usr.sbin/named/named/storage.c +++ b/usr.sbin/named/named/storage.c @@ -1,4 +1,4 @@ -/* $OpenBSD: storage.c,v 1.2 1997/03/12 10:42:38 downsj Exp $ */ +/* $OpenBSD: storage.c,v 1.3 1998/05/22 00:47:47 millert Exp $ */ /* * ++Copyright++ 1985, 1989 @@ -88,7 +88,7 @@ extern void panic __P((int, const char *)); * All rights reserved. */ #ifndef lint -static char RCSid[] = "$Id: storage.c,v 1.2 1997/03/12 10:42:38 downsj Exp $"; +static char RCSid[] = "$From: storage.c,v 8.2 1996/08/05 08:31:30 vixie Exp $"; #endif #undef malloc diff --git a/usr.sbin/named/named/tree.h b/usr.sbin/named/named/tree.h index cd354004295..75e89500cef 100644 --- a/usr.sbin/named/named/tree.h +++ b/usr.sbin/named/named/tree.h @@ -1,11 +1,11 @@ -/* $OpenBSD: tree.h,v 1.2 1997/03/12 10:42:39 downsj Exp $ */ +/* $OpenBSD: tree.h,v 1.3 1998/05/22 00:47:49 millert Exp $ */ /* tree.h - declare structures used by tree library * * vix 22jan93 [revisited; uses RCS, ANSI, POSIX; has bug fixes] * vix 27jun86 [broken out of tree.c] * - * $Id: tree.h,v 1.2 1997/03/12 10:42:39 downsj Exp $ + * $From: tree.h,v 8.1 1994/12/15 06:24:14 vixie Exp $ */ diff --git a/usr.sbin/named/named/version.c b/usr.sbin/named/named/version.c index 7fa5ada4dcd..700cef0c140 100644 --- a/usr.sbin/named/named/version.c +++ b/usr.sbin/named/named/version.c @@ -1,20 +1,21 @@ -/* $OpenBSD: version.c,v 1.2 1997/03/12 10:42:39 downsj Exp $ */ +/* $OpenBSD: version.c,v 1.3 1998/05/22 00:47:50 millert Exp $ */ /* * @(#)Version.c 4.9 (Berkeley) 7/21/90 - * $From: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $ + * $From: Version.c,v 8.2 1997/06/01 20:34:34 vixie Exp $ */ #ifndef lint #if 0 -char sccsid[] = "@(#)named 4.9.5-P1"; -char rcsid[] = "$From: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $"; +char sccsid[] = "@(#)named 4.9.6-REL Thu May 21 18:38:36 1998 root@localhost:/usr/src/usr.sbin/named/named/obj"; +char rcsid[] = "$From: Version.c,v 8.2 1997/06/01 20:34:34 vixie Exp $"; #else -char rcsid[] = "$OpenBSD: version.c,v 1.2 1997/03/12 10:42:39 downsj Exp $"; +char rcsid[] = "$OpenBSD: version.c,v 1.3 1998/05/22 00:47:50 millert Exp $"; #endif #endif /* not lint */ -char Version[] = "named 4.9.5-P1"; +char Version[] = "named 4.9.6-REL Thu May 21 18:38:36 1998\n\troot@localhost:/usr/src/usr.sbin/named/named/obj"; +char ShortVersion[] = "4.9.6-REL"; #ifdef COMMENT diff --git a/usr.sbin/named/nslookup/send.c b/usr.sbin/named/nslookup/send.c index a61f3ceed69..2232dd18596 100644 --- a/usr.sbin/named/nslookup/send.c +++ b/usr.sbin/named/nslookup/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.2 1997/03/12 10:42:50 downsj Exp $ */ +/* $OpenBSD: send.c,v 1.3 1998/05/22 00:47:51 millert Exp $ */ /* * ++Copyright++ 1985, 1989 @@ -58,9 +58,9 @@ #ifndef lint #if 0 static char sccsid[] = "@(#)send.c 5.18 (Berkeley) 3/2/91"; -static char rcsid[] = "$From: send.c,v 8.1 1994/12/15 06:24:31 vixie Exp $"; +static char rcsid[] = "$From: send.c,v 8.2 1997/06/01 20:34:40 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: send.c,v 1.2 1997/03/12 10:42:50 downsj Exp $"; +static char rcsid[] = "$OpenBSD: send.c,v 1.3 1998/05/22 00:47:51 millert Exp $"; #endif #endif /* not lint */ @@ -338,8 +338,7 @@ wait: * timeout */ if (_res.options & RES_DEBUG) - printf("timeout (%d secs)\n", - timeout.tv_sec); + printf("timeout\n"); #if BSD >= 43 gotsomewhere = 1; #endif |