Round 1 of the conflict merge. It now compiles..

This commit is contained in:
Peter Wemm 1996-01-07 05:48:49 +00:00
parent e65f6bafb8
commit 34d59b1442
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=13300
26 changed files with 1367 additions and 1039 deletions

View File

@ -67,7 +67,7 @@ OBJS+= version.o
CLEANFILES+=version.c version.o
SUBDIR= tools xfer
VER = 4.9.3-BETA26-LOCAL
VER = 4.9.3-REL
version.c: ${.CURDIR}/Version.c ${.CURDIR}/Makefile ${SRCS}
(LC_TIME=; export LC_TIME; u=$${USER-root} d=`pwd |sed -e 's|/obj/|/src/|'` \

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)db_dump.c 4.33 (Berkeley) 3/3/91";
static char rcsid[] = "$Id: db_dump.c,v 1.3 1995/05/30 03:48:35 rgrimes Exp $";
static char rcsid[] = "$Id: db_dump.c,v 1.4 1995/08/20 21:18:14 peter Exp $";
#endif /* not lint */
/*
@ -306,8 +306,14 @@ zt_dump(fp)
char *pre, buf[64];
u_int cnt;
if (!zp->z_origin)
continue;
fprintf(fp, "; %s (type %d, class %d, source %s)\n",
zp->z_origin, zp->z_type, zp->z_class,
zp->z_origin
? (*zp->z_origin ? zp->z_origin : ".")
: "Nil",
zp->z_type, zp->z_class,
zp->z_source ? zp->z_source : "Nil");
fprintf(fp, ";\ttime=%ld, lastupdate=%ld, serial=%u,\n",
zp->z_time, zp->z_lastupdate, zp->z_serial);
@ -480,12 +486,12 @@ db_dump(htp, fp, zone, origin)
case T_HINFO:
case T_ISDN:
if (n = *cp++) {
if ((n = *cp++) != '\0') {
fprintf(fp, "\"%.*s\"", (int)n, cp);
cp += n;
} else
fprintf(fp, "\"\"");
if (n = *cp++)
if ((n = *cp++) != '\0')
fprintf(fp, " \"%.*s\"", (int)n, cp);
else
fprintf(fp, " \"\"");
@ -538,7 +544,7 @@ db_dump(htp, fp, zone, origin)
end = (u_char *)dp->d_data + dp->d_size;
(void) putc('"', fp);
while (cp < end) {
if (n = *cp++) {
if ((n = *cp++) != '\0') {
for (j = n ; j > 0 && cp < end ; j--)
if (*cp == '\n') {
(void) putc('\\', fp);

View File

@ -1,6 +1,6 @@
/* db_proc.h - prototypes for functions in db_*.c
*
* $Id: db_func.h,v 1.2 1995/05/30 03:48:36 rgrimes Exp $
* $Id: db_func.h,v 1.3 1995/08/20 21:18:16 peter Exp $
*/
/* ++from db_update.c++ */
@ -48,7 +48,7 @@ extern void endline __P((FILE *)),
get_netlist __P((FILE *, struct netinfo **,
int, char *)),
free_netlist __P((struct netinfo **));
extern int getword __P((char *, int, FILE *)),
extern int getword __P((char *, int, FILE *, int)),
getnum __P((FILE *, const char *, int)),
db_load __P((const char *, const char *,
struct zoneinfo *, const char *)),
@ -79,7 +79,6 @@ extern int servicenumber __P((char *)),
extern char *protocolname __P((int)),
*servicename __P((u_int16_t, char *)),
*savestr __P((const char *));
extern const char *inet_etoa __P((const struct sockaddr_in *));
#ifndef BSD
extern int getdtablesize __P((void));
#endif
@ -100,6 +99,8 @@ extern char * loc_ntoa __P((const u_char *binary, char *ascii));
#endif
extern char * ctimel __P((long));
extern struct in_addr data_inaddr __P((const u_char *data));
extern void setsignal __P((int, int, SIG_FN (*)())),
resignal __P((int, int, SIG_FN (*)()));
/* --from db_glue.c-- */
/* ++from db_lookup.c++ */

View File

@ -1,6 +1,6 @@
/*
* from db.h 4.16 (Berkeley) 6/1/90
* $Id: db_glob.h,v 1.1.1.1 1994/09/22 19:46:14 pst Exp $
* $Id: db_glob.h,v 1.2 1995/05/30 03:48:37 rgrimes Exp $
*/
/*
@ -65,8 +65,8 @@
/* ONE_WEEK maximum ttl */
DECL int max_cache_ttl INIT(7*24*60*60);
/* 5 minute minimum ttl */
DECL int min_cache_ttl INIT(5*60);
/* no minimum ttl */
DECL int min_cache_ttl INIT(0);
/* current line number */
DECL int lineno;

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)db_glue.c 4.4 (Berkeley) 6/1/90";
static char rcsid[] = "$Id: db_glue.c,v 1.3 1995/08/20 21:18:19 peter Exp $";
static char rcsid[] = "$Id: db_glue.c,v 1.4 1995/10/23 11:11:42 peter Exp $";
#endif /* not lint */
/*
@ -80,7 +80,8 @@ struct valuelist {
char *name;
char *proto;
int port;
} *servicelist, *protolist;
};
static struct valuelist *servicelist, *protolist;
#if defined(ultrix)
/* ultrix 4.0 has some icky packaging details. work around them here.
@ -98,13 +99,14 @@ const char *
sin_ntoa(sin)
const struct sockaddr_in *sin;
{
static char ret[sizeof("[111.222.333.444].55555")];
static char ret[sizeof "[111.222.333.444].55555"];
if (!sin)
strcpy(ret, "[sin_ntoa(NULL)]");
else
sprintf(ret, "[%s].%u",
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
inet_ntoa(sin->sin_addr),
ntohs(sin->sin_port));
return (ret);
}
@ -120,7 +122,7 @@ panic(err, msg)
syslog(LOG_CRIT, "%s - ABORT", msg);
else
syslog(LOG_CRIT, "%s: %s - ABORT", msg, strerror(err));
signal(SIGIOT, SIG_DFL);
signal(SIGIOT, SIG_DFL); /* no POSIX needed here. */
abort();
}
@ -137,9 +139,11 @@ buildservicelist()
#endif
while (sp = getservent()) {
slp = (struct valuelist *)malloc(sizeof(struct valuelist));
if (!slp)
panic(errno, "malloc(servent)");
slp->name = savestr(sp->s_name);
slp->proto = savestr(sp->s_proto);
slp->port = ntohs((u_int16_t)sp->s_port);
slp->port = ntohs((u_int16_t)sp->s_port); /* host byt order */
slp->next = servicelist;
slp->prev = NULL;
if (servicelist)
@ -162,8 +166,10 @@ buildprotolist()
#endif
while (pp = getprotoent()) {
slp = (struct valuelist *)malloc(sizeof(struct valuelist));
if (!slp)
panic(errno, "malloc(protoent)");
slp->name = savestr(pp->p_name);
slp->port = pp->p_proto;
slp->port = pp->p_proto; /* host byte order */
slp->next = protolist;
slp->prev = NULL;
if (protolist)
@ -191,7 +197,7 @@ findservice(s, list)
lp->next = *list;
*list = lp;
}
return (lp->port);
return (lp->port); /* host byte order */
}
if (sscanf(s, "%d", &n) != 1 || n <= 0)
n = -1;
@ -220,12 +226,12 @@ protocolnumber(p)
#if defined(__STDC__) || defined(__GNUC__)
static struct servent *
cgetservbyport(u_int16_t port,
cgetservbyport(u_int16_t port, /* net byte order */
char *proto)
#else
static struct servent *
cgetservbyport(port, proto)
u_int16_t port;
u_int16_t port; /* net byte order */
char *proto;
#endif
{
@ -233,9 +239,9 @@ cgetservbyport(port, proto)
register struct valuelist *lp = *list;
static struct servent serv;
port = htons(port);
port = ntohs(port);
for (; lp != NULL; lp = lp->next) {
if (port != (u_int16_t)lp->port)
if (port != (u_int16_t)lp->port) /* host byte order */
continue;
if (strcasecmp(lp->proto, proto) == 0) {
if (lp != *list) {
@ -257,14 +263,14 @@ cgetservbyport(port, proto)
static struct protoent *
cgetprotobynumber(proto)
register int proto;
register int proto; /* host byte order */
{
register struct valuelist **list = &protolist;
register struct valuelist *lp = *list;
static struct protoent prot;
for (; lp != NULL; lp = lp->next)
if (lp->port == proto) {
if (lp->port == proto) { /* host byte order */
if (lp != *list) {
lp->prev->next = lp->next;
if (lp->next)
@ -274,7 +280,7 @@ cgetprotobynumber(proto)
*list = lp;
}
prot.p_name = lp->name;
prot.p_proto = lp->port;
prot.p_proto = lp->port; /* host byte order */
return (&prot);
}
return (0);
@ -297,11 +303,11 @@ protocolname(num)
#if defined(__STDC__) || defined(__GNUC__)
char *
servicename(u_int16_t port, char *proto)
servicename(u_int16_t port, char *proto) /* host byte order */
#else
char *
servicename(port, proto)
u_int16_t port;
u_int16_t port; /* host byte order */
char *proto;
#endif
{
@ -428,27 +434,12 @@ savestr(str)
char *cp;
cp = (char *)malloc(strlen(str) + 1);
if (cp == NULL)
panic(errno, "savestr: malloc");
(void) strcpy(cp, str);
if (!cp)
panic(errno, "malloc(savestr)");
strcpy(cp, str);
return (cp);
}
/*
* Uniform formatting of IP/UDP addresses.
*/
const char *
inet_etoa(sin)
const struct sockaddr_in *sin;
{
static char retbuf[sizeof("[xxx.xxx.xxx.xxx].xxxxx")];
(void) sprintf(retbuf, "[%s].%u",
inet_ntoa(sin->sin_addr),
ntohs(sin->sin_port));
return (retbuf);
}
int
writemsg(rfd, msg, msglen)
int rfd;
@ -654,10 +645,8 @@ saveinv()
register struct invbuf *ip;
ip = (struct invbuf *) malloc(sizeof(struct invbuf));
if (ip == NULL) {
syslog(LOG_ERR, "saveinv: malloc: %m");
exit(1);
}
if (!ip)
panic(errno, "malloc(saveinv)");
ip->i_next = NULL;
bzero((char *)ip->i_dname, sizeof(ip->i_dname));
return (ip);
@ -1059,7 +1048,7 @@ loc_ntoa(binary,ascii)
const u_char *binary;
char *ascii;
{
char tmpbuf[255*3];
static char tmpbuf[255*3];
register char *cp;
register const u_char *rcp;
@ -1078,12 +1067,7 @@ loc_ntoa(binary,ascii)
char *sizestr, *hpstr, *vpstr;
rcp = binary;
if (ascii)
cp = ascii;
else {
ascii = tmpbuf;
cp = tmpbuf;
}
cp = (ascii != NULL) ? ascii : tmpbuf;
versionval = *rcp++;
@ -1193,3 +1177,48 @@ data_inaddr(data)
ret.s_addr = tmp;
return (ret);
}
/* Signal abstraction. */
void
setsignal(catch, block, handler)
int catch, block;
SIG_FN (*handler)();
{
#ifdef POSIX_SIGNALS
/* Modern system - preferred. */
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
if (block != -1)
sigaddset(&sa.sa_mask, block);
(void) sigaction(catch, &sa, NULL);
#else /*POSIX_SIGNALS*/
#ifdef SYSV
/* Ancient system - ugly. */
if (block != -1)
syslog(LOG_DEBUG, "danger - unable to block signal %d from %d",
block, catch);
(void) signal(catch, handler);
#else /*SYSV*/
/* BSD<=4.3 system - odd. */
struct sigvec sv;
bzero(&sv, sizeof sv);
sv.sv_handler = handler;
sv.sv_mask = sigmask(block);
(void) sigvec(catch, &sv, NULL);
#endif /*SYSV*/
#endif /*POSIX_SIGNALS*/
}
void
resignal(catch, block, handler)
int catch, block;
SIG_FN (*handler)();
{
#if !defined(POSIX_SIGNALS) && defined(SYSV)
/* Unreliable signals. Set it back up again. */
setsignal(catch, block, handler);
#endif
}

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)db_load.c 4.38 (Berkeley) 3/2/91";
static char rcsid[] = "$Id: db_load.c,v 1.3 1995/05/30 03:48:39 rgrimes Exp $";
static char rcsid[] = "$Id: db_load.c,v 1.4 1995/08/20 21:18:22 peter Exp $";
#endif /* not lint */
/*
@ -73,6 +73,7 @@ static char rcsid[] = "$Id: db_load.c,v 1.3 1995/05/30 03:48:39 rgrimes Exp $";
#include <ctype.h>
#include <netdb.h>
#include <resolv.h>
#include <errno.h>
#include "named.h"
@ -169,7 +170,7 @@ db_load(filename, in_origin, zp, def_domain)
struct zoneinfo *zp;
const char *def_domain;
{
static int read_soa, read_ns;
static int read_soa, read_ns, rrcount;
register char *cp;
register struct map *mp;
char domain[MAXDNAME];
@ -178,23 +179,25 @@ db_load(filename, in_origin, zp, def_domain)
char buf[MAXDATA];
char data[MAXDATA];
const char *cp1, *op;
int c, class, type, ttl, dbflags, dataflags, multiline;
int c, class, type, dbflags, dataflags, multiline;
u_int32_t ttl;
struct databuf *dp;
struct iso_addr *isoa;
FILE *fp;
int slineno, i, errs, didinclude, rrcount;
int slineno, i, errs, didinclude;
register u_int32_t n;
struct stat sb;
struct in_addr ina;
int escape;
#ifdef DO_WARN_SERIAL
u_int32_t serial;
#endif
errs = 0;
didinclude = 0;
rrcount = 0;
if (!def_domain) {
/* This is not the result of a $INCLUDE. */
rrcount = 0;
read_soa = 0;
read_ns = 0;
clev = db_getclev(in_origin);
@ -206,7 +209,7 @@ db_load(filename, in_origin, zp, def_domain)
(void) strcpy(origin, in_origin);
if ((fp = fopen(filename, "r")) == NULL) {
syslog(LOG_NOTICE, "%s: %m", filename);
syslog(LOG_WARNING, "%s: %m", filename);
dprintf(1, (ddt, "db_load: error opening file %s\n",
filename));
return (-1);
@ -225,7 +228,7 @@ db_load(filename, in_origin, zp, def_domain)
}
gettime(&tt);
if (fstat(fileno(fp), &sb) < 0) {
syslog(LOG_NOTICE, "%s: %m", filename);
syslog(LOG_WARNING, "%s: %m", filename);
sb.st_mtime = (int)tt.tv_sec;
}
slineno = lineno;
@ -239,10 +242,10 @@ db_load(filename, in_origin, zp, def_domain)
while ((c = gettoken(fp, filename)) != EOF) {
switch (c) {
case INCLUDE:
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 0))
/* file name*/
break;
if (!getword(tmporigin, sizeof(tmporigin), fp))
if (!getword(tmporigin, sizeof(tmporigin), fp, 1))
strcpy(tmporigin, origin);
else {
makename(tmporigin, origin);
@ -254,7 +257,7 @@ db_load(filename, in_origin, zp, def_domain)
case ORIGIN:
(void) strcpy((char *)buf, origin);
if (!getword(origin, sizeof(origin), fp))
if (!getword(origin, sizeof(origin), fp, 1))
break;
dprintf(3, (ddt, "db_load: origin %s, buf %s\n",
origin, buf));
@ -263,7 +266,7 @@ db_load(filename, in_origin, zp, def_domain)
continue;
case DNAME:
if (!getword(domain, sizeof(domain), fp))
if (!getword(domain, sizeof(domain), fp, 1))
break;
n = strlen(domain) - 1;
if (domain[n] == '.')
@ -283,13 +286,13 @@ db_load(filename, in_origin, zp, def_domain)
/* FALLTHROUGH */
case CURRENT:
gotdomain:
if (!getword((char *)buf, sizeof(buf), fp)) {
if (!getword((char *)buf, sizeof(buf), fp, 0)) {
if (c == CURRENT)
continue;
break;
}
cp = buf;
ttl = 0;
ttl = USE_MINIMUM;
if (isdigit(*cp)) {
n = 0;
do {
@ -311,14 +314,14 @@ db_load(filename, in_origin, zp, def_domain)
n += sb.st_mtime;
}
ttl = n;
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 0))
break;
}
for (mp = m_class; mp < m_class+M_CLASS_CNT; mp++)
if (!strcasecmp((char *)buf, mp->token)) {
class = mp->val;
(void) getword((char *)buf,
sizeof(buf), fp);
sizeof(buf), fp, 0);
break;
}
for (mp = m_type; mp < m_type+M_TYPE_CNT; mp++)
@ -339,7 +342,22 @@ db_load(filename, in_origin, zp, def_domain)
*/
if (type != T_UNSPEC) {
#endif
if (!getword((char *)buf, sizeof(buf), fp))
switch (type) {
case T_SOA:
case T_MINFO:
case T_RP:
case T_NS:
case T_CNAME:
case T_MB:
case T_MG:
case T_MR:
case T_PTR:
escape = 1;
break;
default:
escape = 0;
}
if (!getword((char *)buf, sizeof(buf), fp, escape))
break;
dprintf(3,
(ddt,
@ -377,7 +395,7 @@ db_load(filename, in_origin, zp, def_domain)
if (n == 0)
goto err;
n++;
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 0))
i = 0;
else {
endline(fp);
@ -418,7 +436,8 @@ db_load(filename, in_origin, zp, def_domain)
makename(data, origin);
cp = data + strlen((char *)data) + 1;
if (!getword((char *)cp,
(sizeof data) - (cp - data), fp))
(sizeof data) - (cp - data),
fp, 1))
goto err;
makename(cp, origin);
cp += strlen((char *)cp) + 1;
@ -593,7 +612,7 @@ db_load(filename, in_origin, zp, def_domain)
cp = data;
PUTSHORT((u_int16_t)n, cp);
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 1))
goto err;
(void) strcpy((char *)cp, (char *)buf);
makename(cp, origin);
@ -616,13 +635,13 @@ db_load(filename, in_origin, zp, def_domain)
cp = data;
PUTSHORT((u_int16_t)n, cp);
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 0))
goto err;
(void) strcpy((char *)cp, (char *)buf);
makename(cp, origin);
/* advance pointer to next field */
cp += strlen((char *)cp) +1;
if (!getword((char *)buf, sizeof(buf), fp))
if (!getword((char *)buf, sizeof(buf), fp, 0))
goto err;
(void) strcpy((char *)cp, (char *)buf);
makename(cp, origin);
@ -678,10 +697,10 @@ db_load(filename, in_origin, zp, def_domain)
while ((i = getc(fp), *cp = i, i != EOF)
&& *cp != '\n'
&& (n < MAXDATA)) {
cp++; n++;
cp++; n++;
}
if (*cp == '\n') /* leave \n for getword */
ungetc(*cp, fp);
ungetc(*cp, fp);
*cp = '\0';
/* now process the whole line */
n = loc_aton(buf, (u_char *)data);
@ -790,7 +809,8 @@ db_load(filename, in_origin, zp, def_domain)
msg = "no relevant RRs found";
if (msg != NULL) {
errs++;
syslog(LOG_NOTICE, "Zone \"%s\" (file %s): %s",
syslog(LOG_WARNING,
"Zone \"%s\" (file %s): %s",
zp->z_origin, filename, msg);
}
}
@ -834,7 +854,7 @@ gettoken(fp, src)
return (EOF);
case '$':
if (getword(op, sizeof(op), fp)) {
if (getword(op, sizeof(op), fp, 0)) {
if (!strcasecmp("include", op))
return (INCLUDE);
if (!strcasecmp("origin", op))
@ -872,52 +892,59 @@ gettoken(fp, src)
}
/* int
* getword(buf, size, fp)
* getword(buf, size, fp, preserve)
* get next word, skipping blanks & comments.
* '\' '\n' outside of "quotes" is considered a blank.
* parameters:
* buf - destination
* size - of destination
* fp - file to read from
* preserve - should we preserve \ before \\ and \.?
* return value:
* 0 = no word; perhaps EOL or EOF
* 1 = word was read
*/
int
getword(buf, size, fp)
getword(buf, size, fp, preserve)
char *buf;
int size;
FILE *fp;
int preserve;
{
register char *cp;
register char *cp = buf;
register int c;
empty_token = 0;
for (cp = buf; (c = getc(fp)) != EOF; ) {
empty_token = 0; /* XXX global side effect. */
while ((c = getc(fp)) != EOF) {
if (c == ';') {
/* Comment. Skip to end of line. */
while ((c = getc(fp)) != EOF && c != '\n')
;
NULL;
c = '\n';
}
if (c == '\n') {
/*
* Unescaped newline. It's a terminator unless we're
* already midway into a token.
*/
if (cp != buf)
ungetc(c, fp);
else
lineno++;
break;
}
if (isspace(c)) {
while (isspace(c = getc(fp)) && c != '\n')
;
ungetc(c, fp);
if (cp != buf) /* Trailing whitespace */
break;
continue; /* Leading whitespace */
}
if (c == '"') {
while ((c = getc(fp)) != EOF && c != '"' && c != '\n') {
/* "Quoted string." Gather the whole string here. */
while ((c = getc(fp)) != EOF && c!='"' && c!='\n') {
if (c == '\\') {
if ((c = getc(fp)) == EOF)
c = '\\';
if (preserve &&
(c == '\\' || c == '.')) {
if (cp >= buf+size-1)
break;
*cp++ = '\\';
}
if (c == '\n')
lineno++;
}
@ -925,24 +952,42 @@ getword(buf, size, fp)
break;
*cp++ = c;
}
/*
* Newline string terminators are
* not token terminators.
*/
if (c == '\n') {
lineno++;
break;
}
/* Sample following character, check for terminator. */
if ((c = getc(fp)) != EOF)
ungetc(c, fp);
if (c == EOF || isspace(c) || c == '\n') {
if (c == EOF || isspace(c)) {
*cp = '\0';
return (1);
}
else
continue;
continue;
}
if (c == '\\') {
/* Do escape processing. */
if ((c = getc(fp)) == EOF)
c = '\\';
if (c == '\n')
lineno++;
if (preserve && (c == '\\' || c == '.')) {
if (cp >= buf+size-1)
break;
*cp++ = '\\';
}
}
if (isspace(c)) {
/* Blank of some kind. Skip run. */
while (isspace(c = getc(fp)) && c != '\n')
NULL;
ungetc(c, fp);
/* Blank means terminator if the token is nonempty. */
if (cp != buf) /* Trailing whitespace */
break;
continue; /* Leading whitespace */
}
if (cp >= buf+size-1)
break;
@ -1166,8 +1211,8 @@ getprotocol(fp, src)
int k;
char b[MAXLEN];
(void) getword(b, sizeof(b), fp);
(void) getword(b, sizeof(b), fp, 0);
k = protocolnumber(b);
if (k == -1)
syslog(LOG_INFO, "%s: line %d: unknown protocol: %s.",
@ -1193,7 +1238,7 @@ getservices(n, data, fp, src)
bm[j] = 0;
maxl = 0;
bracket = 0;
while (getword(b, sizeof(b), fp) || bracket) {
while (getword(b, sizeof(b), fp, 0) || bracket) {
if (feof(fp) || ferror(fp))
break;
if (strlen(b) == 0)
@ -1260,14 +1305,16 @@ get_netlist(fp, netlistp, allow, print_tag)
;
ntp = NULL;
dprintf(1, (ddt, "get_netlist(%s)", print_tag));
while (getword(buf, sizeof(buf), fp)) {
while (getword(buf, sizeof(buf), fp, 0)) {
if (strlen(buf) == 0)
break;
if ((maskp = strchr(buf, '&')) != NULL)
*maskp++ = '\0';
dprintf(1, (ddt," %s", buf));
if (ntp == NULL) {
if (!ntp) {
ntp = (struct netinfo *)malloc(sizeof(struct netinfo));
if (!ntp)
panic(errno, "malloc(netinfo)");
}
if (!inet_aton(buf, &ntp->my_addr)) {
syslog(LOG_INFO, "%s contains bogus element (%s)",

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)db_lookup.c 4.18 (Berkeley) 3/21/91";
static char rcsid[] = "$Id: db_lookup.c,v 1.2 1995/05/30 03:48:40 rgrimes Exp $";
static char rcsid[] = "$Id: db_lookup.c,v 1.3 1995/08/20 21:18:24 peter Exp $";
#endif /* not lint */
/*
@ -90,12 +90,13 @@ nlookup(name, htpp, fname, insert)
register unsigned hval;
register struct hashbuf *htp;
struct namebuf *parent = NULL;
int escaped = 0;
htp = *htpp;
hval = 0;
*fname = "???";
for (cp = name; c = *cp++; ) {
if (c == '.') {
if (!escaped && (c == '.')) {
parent = np = nlookup(cp, htpp, fname, insert);
if (np == NULL)
return (NULL);
@ -116,6 +117,10 @@ nlookup(name, htpp, fname, insert)
}
hval <<= HASHSHIFT;
hval += (isupper(c) ? tolower(c) : c) & HASHMASK;
if (escaped)
escaped = 0;
else if (c == '\\')
escaped = 1;
}
cp--;
/*

View File

@ -1,5 +1,5 @@
#ifndef LINT
static char rcsid[] = "$Id: db_secure.c,v 1.2 1995/05/30 03:48:43 rgrimes Exp $";
static char rcsid[] = "$Id: db_secure.c,v 1.3 1995/08/20 21:18:29 peter Exp $";
#endif
/* this file was contributed by Gregory Neil Shapiro of WPI in August 1993 */
@ -11,6 +11,7 @@ static char rcsid[] = "$Id: db_secure.c,v 1.2 1995/05/30 03:48:43 rgrimes Exp $"
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <syslog.h>
#include <errno.h>
#include "named.h"
@ -74,18 +75,8 @@ build_secure_netlist(zp)
zp->z_origin, buf));
if (ntp == NULL) {
ntp = (struct netinfo *)malloc(sizeof(struct netinfo));
if (!ntp) {
dprintf(1, (ddt,
"build_secure_netlist (%s): malloc fail\n",
zp->z_origin));
syslog(LOG_NOTICE,
"build_secure_netlist (%s): Out of Memory",
zp->z_origin);
if (!securezone) {
zp->secure_nets = NULL;
}
return (1);
}
if (!ntp)
panic(errno, "malloc(netinfo)");
}
if (!inet_aton(buf, &ntp->my_addr)) {
syslog(LOG_INFO,
@ -148,7 +139,8 @@ build_secure_netlist(zp)
if (debug > 1) {
for (ntp = *netlistp; ntp != NULL; ntp = ntp->next) {
fprintf(ddt, "ntp x%lx addr x%lx mask x%lx",
(u_long)ntp, ntp->addr, ntp->mask);
(u_long)ntp, (u_long)ntp->addr,
(u_long)ntp->mask);
fprintf(ddt, " my_addr %#lx",
(u_long)ntp->my_addr.s_addr);
fprintf(ddt, " %s", inet_ntoa(ntp->my_addr));

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)db_update.c 4.28 (Berkeley) 3/21/91";
static char rcsid[] = "$Id: db_update.c,v 1.2 1995/05/30 03:48:44 rgrimes Exp $";
static char rcsid[] = "$Id: db_update.c,v 1.3 1995/08/20 21:18:31 peter Exp $";
#endif /* not lint */
/*
@ -343,12 +343,7 @@ db_update(name, odp, newdp, flags, htp)
if (!newdp || newdp->d_class != dp->d_class)
goto skip;
/* XXX:
* The next three clauses do not deal
* correctly with glue records. mpa.
*/
/* if the new data is authorative
/* if the new data is authorative
* remove any data for this domain with
* the same class that isn't as credable
*/
@ -360,12 +355,14 @@ db_update(name, odp, newdp, flags, htp)
*/
goto delete;
#if 0 /* caught by findMyZone() now. */
/* if we have authoritative data for a
* node, don't add in other data.
*/
if (dp->d_cred == DB_C_ZONE &&
newdp->d_cred < dp->d_cred)
return (AUTH);
#endif
/* if the new data is authoritative but
* but isn't as credible, reject it.

View File

@ -3,7 +3,7 @@
* vix 24mar92 [added size calcs, improved printout]
* vix 22mar92 [original work]
*
* $Id: dmalloc.c,v 1.2 1994/09/22 20:45:04 pst Exp $
* $Id: dmalloc.c,v 1.3 1995/05/30 03:48:45 rgrimes Exp $
*/
/*
@ -196,6 +196,8 @@ dmalloc(file, line, size)
c = findCaller(&Callers, file, line, TRUE);
d = (datum *) malloc(sizeof(datum) + size);
if (!d)
return (NULL);
d->size = size;
d->caller = ((char *)c) - memory;
c->calls++;

View File

@ -1,6 +1,6 @@
/*
* from ns.h 4.33 (Berkeley) 8/23/90
* $Id: ns_defs.h,v 1.2 1995/05/30 03:48:47 rgrimes Exp $
* $Id: ns_defs.h,v 1.3 1995/08/20 21:18:34 peter Exp $
*/
/*
@ -102,9 +102,17 @@
#define BETA 1.2 /* How much to penalize response time on failure */
#define GAMMA 0.98 /* How much to decay unused response times */
#define USE_MINIMUM 0xffffffff
/* sequence-space arithmetic */
#define SEQ_GT(a,b) ((int32_t)((a)-(b)) > 0)
/* wildcard predicate */
#define WILDCARD_P(str) (str[0] == '*' && str[1] == '\0')
/* cheap garbage collection */
#define FREE_ONCE(p) { if (p) { free(p); p = NULL; } }
/* these fields are ordered to maintain word-alignment;
* be careful about changing them.
*/
@ -167,6 +175,8 @@ struct notify {
#define Z_DYNADDONLY 0x0800 /* dynamic mode: add new data only */
#define Z_CHANGED 0x1000 /* zone has changed */
#endif /* ALLOW_UPDATES */
#define Z_XFER_ABORTED 0x2000 /* zone transfer has been aborted */
#define Z_XFER_GONE 0x4000 /* zone transfer process is gone */
/* named_xfer exit codes */
#define XFER_UPTODATE 0 /* zone is up-to-date */
@ -217,7 +227,7 @@ struct qinfo {
int16_t q_nqueries; /* # of queries required */
struct qstream *q_stream; /* TCP stream, null if UDP */
struct zoneinfo *q_zquery; /* Zone query is about (Q_ZSERIAL) */
#ifdef LAME_DELEGATION
#if defined(LAME_DELEGATION) || defined(VALIDATE)
char q_domain[MAXDNAME]; /* domain for servers we are querying */
#endif
#ifdef BIND_NOTIFY

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_forw.c 4.32 (Berkeley) 3/3/91";
static char rcsid[] = "$Id: ns_forw.c,v 1.3 1995/08/20 21:18:36 peter Exp $";
static char rcsid[] = "$Id: ns_forw.c,v 1.4 1995/10/23 11:11:44 peter Exp $";
#endif /* not lint */
/*
@ -119,7 +119,7 @@ ns_forw(nsp, msg, msglen, fp, qsp, dfd, qpp, dname, np)
}
qp = qnew();
#ifdef LAME_DELEGATION
#if defined(LAME_DELEGATION) || defined(VALIDATE)
getname(np, qp->q_domain, sizeof qp->q_domain);
#endif
qp->q_from = *fp; /* nslookup wants to know this */
@ -127,7 +127,7 @@ ns_forw(nsp, msg, msglen, fp, qsp, dfd, qpp, dname, np)
dprintf(2, (ddt, "forw: nslookup reports danger\n"));
qfree(qp);
return (FW_SERVFAIL);
} else if (n == 0 && !(forward_only && fwdtab)) {
} else if (n == 0 && !fwdtab) {
dprintf(2, (ddt, "forw: no nameservers found\n"));
qfree(qp);
return (FW_NOSERVER);
@ -139,9 +139,9 @@ ns_forw(nsp, msg, msglen, fp, qsp, dfd, qpp, dname, np)
qp->q_id = id;
qp->q_expire = tt.tv_sec + RETRY_TIMEOUT*2;
hp->id = qp->q_nsid = htons(nsid_next());
hp->ancount = 0;
hp->nscount = 0;
hp->arcount = 0;
hp->ancount = htons(0);
hp->nscount = htons(0);
hp->arcount = htons(0);
if ((qp->q_msg = (u_char *)malloc((unsigned)msglen)) == NULL) {
syslog(LOG_NOTICE, "forw: malloc: %m");
qfree(qp);
@ -251,16 +251,18 @@ haveComplained(tag1, tag2)
}
if (!r) {
cur = (struct complaint *)malloc(sizeof(struct complaint));
cur->tag1 = tag1;
cur->tag2 = tag2;
cur->expire = tt.tv_sec + INIT_REFRESH; /* "10 minutes" */
cur->next = NULL;
if (prev)
prev->next = cur;
else
List = cur;
if (cur) {
cur->tag1 = tag1;
cur->tag2 = tag2;
cur->expire = tt.tv_sec + INIT_REFRESH; /* "10:00" */
cur->next = NULL;
if (prev)
prev->next = cur;
else
List = cur;
}
}
return r;
return (r);
}
/* void
@ -272,21 +274,52 @@ haveComplained(tag1, tag2)
* complaint is a string describing what is wrong.
* dname and a_rr are the problematic other name server.
*/
void
nslookupComplain(sysloginfo, queryname, complaint, dname, a_rr)
static void
nslookupComplain(sysloginfo, queryname, complaint, dname, a_rr, nsdp)
const char *sysloginfo, *queryname, *complaint, *dname;
const struct databuf *a_rr;
const struct databuf *a_rr, *nsdp;
{
#ifdef STATS
char nsbuf[20];
char abuf[20];
#endif
char *a, *ns;
dprintf(2, (ddt, "NS '%s' %s\n", dname, complaint));
if (sysloginfo && queryname && !haveComplained(queryname, complaint))
{
char buf[999];
a = ns = (char *)NULL;
#ifdef STATS
if (nsdp) {
if (nsdp->d_ns) {
strcpy(nsbuf, inet_ntoa(nsdp->d_ns->addr));
ns = nsbuf;
} else {
ns = zones[nsdp->d_zone].z_origin;
}
}
if (a_rr->d_ns) {
strcpy(abuf, inet_ntoa(a_rr->d_ns->addr));
a = abuf;
} else {
a = zones[a_rr->d_zone].z_origin;
}
#endif
/* syslog only takes 5 params */
sprintf(buf, "%s: query(%s) %s (%s:%s)",
sysloginfo, queryname,
complaint, dname,
inet_ntoa(data_inaddr(a_rr->d_data)));
if ( a != NULL || ns != NULL)
sprintf(buf, "%s: query(%s) %s (%s:%s) learnt (A=%s:NS=%s)",
sysloginfo, queryname,
complaint, dname,
inet_ntoa(data_inaddr(a_rr->d_data)),
a ? a : "<Not Available>",
ns ? ns : "<Not Available>" );
else
sprintf(buf, "%s: query(%s) %s (%s:%s)",
sysloginfo, queryname,
complaint, dname,
inet_ntoa(data_inaddr(a_rr->d_data)));
syslog(LOG_INFO, buf);
}
}
@ -370,30 +403,34 @@ nslookup(nsp, qp, syslogdname, sysloginfo)
if (dp->d_type != T_A || dp->d_class != class)
continue;
if (data_inaddr(dp->d_data).s_addr == INADDR_ANY) {
syslog(LOG_INFO, "Bogus (0.0.0.0) A RR for %s",
dname);
static char *complaint = "Bogus (0.0.0.0) A RR";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp, nsdp);
continue;
}
#ifdef INADDR_LOOPBACK
if (ntohl(data_inaddr(dp->d_data).s_addr) ==
INADDR_LOOPBACK) {
syslog(LOG_INFO, "Bogus LOOPBACK A RR for %s",
dname);
static char *complaint = "Bogus LOOPBACK A RR";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp, nsdp);
continue;
}
#endif
#ifdef INADDR_BROADCAST
if (ntohl(data_inaddr(dp->d_data).s_addr) ==
INADDR_BROADCAST) {
syslog(LOG_INFO, "Bogus BROADCAST A RR for %s",
dname);
static char *complaint = "Bogus BROADCAST A RR";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp, nsdp);
continue;
}
#endif
#ifdef IN_MULTICAST
if (IN_MULTICAST(ntohl(data_inaddr(dp->d_data).s_addr))) {
syslog(LOG_INFO, "Bogus MULTICAST A RR for %s",
dname);
static char *complaint = "Bogus MULTICAST A RR";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp, nsdp);
continue;
}
#endif
@ -461,7 +498,7 @@ nslookup(nsp, qp, syslogdname, sysloginfo)
if (aIsUs(nsa)) {
static char *complaint = "contains our address";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp);
complaint, dname, dp, nsdp);
return (-1);
}
/*
@ -475,7 +512,7 @@ nslookup(nsp, qp, syslogdname, sysloginfo)
{
static char *complaint = "forwarding loop";
nslookupComplain(sysloginfo, syslogdname,
complaint, dname, dp);
complaint, dname, dp, nsdp);
return (-1);
}
#ifdef BOGUSNS

View File

@ -1,6 +1,6 @@
/*
* from ns.h 4.33 (Berkeley) 8/23/90
* $Id: ns_glob.h,v 1.3 1995/08/20 21:18:41 peter Exp $
* $Id: ns_glob.h,v 1.4 1995/10/23 11:11:45 peter Exp $
*/
/*
@ -108,6 +108,9 @@ DECL int cache_interval INIT(60*60);
DECL int stats_interval INIT(60*60);
#endif
/* need to process finished zone transfers */
DECL int needendxfer INIT(0);
/* need to reload secondary zone(s) */
DECL int needzoneload INIT(0);
@ -142,9 +145,12 @@ DECL int needToExit INIT(0);
DECL int qrylog INIT(0);
#endif /*QRYLOG*/
/* is this a root server that should therefore not recurse? */
/* should this server not recurse? */
DECL int NoRecurse INIT(0);
/* should this server never fetch glue? */
DECL int NoFetchGlue INIT(0);
/*
* We keep a list of favored networks headed by nettab.
* There are three (possibly empty) parts to this list, in this order:

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_init.c 4.38 (Berkeley) 3/21/91";
static char rcsid[] = "$Id: ns_init.c,v 1.3 1995/08/20 21:18:44 peter Exp $";
static char rcsid[] = "$Id: ns_init.c,v 1.4 1995/10/23 11:11:46 peter Exp $";
#endif /* not lint */
/*
@ -69,7 +69,6 @@ static char rcsid[] = "$Id: ns_init.c,v 1.3 1995/08/20 21:18:44 peter Exp $";
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include "named.h"
@ -101,7 +100,8 @@ ns_refreshtime(zp, timebase)
struct zoneinfo *zp;
time_t timebase;
{
register time_t half = ((zp->z_refresh + 1) / 2);
u_long refresh = (zp->z_refresh > 0) ? zp->z_refresh : INIT_REFRESH;
time_t half = (refresh + 1) / 2;
zp->z_time = timebase + half + (rand() % half);
}
@ -238,6 +238,8 @@ boot_read(filename, includefile)
if ((fp = fopen(filename, "r")) == NULL) {
syslog(LOG_ERR, "%s: %m", filename);
if (includefile)
return;
exit(1);
}
@ -246,7 +248,7 @@ boot_read(filename, includefile)
while (!feof(fp) && !ferror(fp)) {
/* read named.boot keyword and process args */
if (!getword(buf, sizeof(buf), fp)) {
if (!getword(buf, sizeof(buf), fp, 0)) {
/*
* This is a blank line, a commented line, or the
* '\n' of the previous line.
@ -254,7 +256,7 @@ boot_read(filename, includefile)
continue;
}
if (strcasecmp(buf, "directory") == 0) {
(void) getword(buf, sizeof(buf), fp);
(void) getword(buf, sizeof(buf), fp, 0);
if (chdir(buf) < 0) {
syslog(LOG_CRIT, "directory %s: %m\n",
buf);
@ -268,11 +270,11 @@ boot_read(filename, includefile)
max_xfers_running = getnum(fp, filename, GETNUM_NONE);
continue;
} else if (strcasecmp(buf, "limit") == 0) {
(void) getword(buf, sizeof(buf), fp);
(void) getword(buf, sizeof(buf), fp, 0);
ns_limit(buf, getnum(fp, filename, GETNUM_SCALED));
continue;
} else if (strcasecmp(buf, "options") == 0) {
while (getword(buf, sizeof(buf), fp))
while (getword(buf, sizeof(buf), fp, 0))
ns_option(buf);
continue;
} else if (strcasecmp(buf, "forwarders") == 0) {
@ -294,12 +296,12 @@ boot_read(filename, includefile)
#endif
#ifdef LOCALDOM
} else if (strcasecmp(buf, "domain") == 0) {
if (getword(buf, sizeof(buf), fp))
if (getword(buf, sizeof(buf), fp, 1))
localdomain = savestr(buf);
continue;
#endif
} else if (strcasecmp(buf, "include") == 0) {
if (getword(buf, sizeof(buf), fp))
if (getword(buf, sizeof(buf), fp, 0))
boot_read(buf, 1);
continue;
} else if (strncasecmp(buf, "cache", 5) == 0) {
@ -351,7 +353,7 @@ boot_read(filename, includefile)
/*
* read zone origin
*/
if (!getword(obuf, sizeof(obuf), fp)) {
if (!getword(obuf, sizeof(obuf), fp, 1)) {
syslog(LOG_NOTICE, "%s: line %d: missing origin\n",
filename, lineno);
continue;
@ -367,7 +369,7 @@ boot_read(filename, includefile)
/*
* Read source file or host address.
*/
if (!getword(buf, sizeof(buf), fp)) {
if (!getword(buf, sizeof(buf), fp, 0)) {
syslog(LOG_NOTICE, "%s: line %d: missing %s\n",
filename, lineno,
#ifdef STUBS
@ -404,7 +406,7 @@ boot_read(filename, includefile)
zp = (struct zoneinfo *)
malloc((64 + nzones)
* sizeof(struct zoneinfo));
if (zp == (struct zoneinfo *)0) {
if (!zp) {
syslog(LOG_NOTICE,
"no memory for more zones");
endline(fp);
@ -431,7 +433,7 @@ boot_read(filename, includefile)
source = savestr(buf);
dprintf(1, (ddt, ", source = %s\n", source));
zp->z_refresh = 0; /* by default, no dumping */
if (getword(buf, sizeof(buf), fp)) {
if (getword(buf, sizeof(buf), fp, 0)) {
#ifdef notyet
zp->z_refresh = atoi(buf);
if (zp->z_refresh <= 0) {
@ -481,7 +483,7 @@ boot_read(filename, includefile)
case Z_PRIMARY:
source = savestr(buf);
#ifdef ALLOW_UPDATES
if (getword(buf, sizeof(buf), fp)) {
if (getword(buf, sizeof(buf), fp, 0)) {
endline(fp);
flag = buf;
while (flag) {
@ -564,7 +566,7 @@ boot_read(filename, includefile)
dprintf(1, (ddt,
"\nns.h NSMAX reached\n"));
}
} while (getword(buf, sizeof(buf), fp));
} while (getword(buf, sizeof(buf), fp, 0));
dprintf(1, (ddt, "addrcnt = %d\n", zp->z_addrcnt));
if (!source) {
/*
@ -610,7 +612,8 @@ boot_read(filename, includefile)
** Force secondary to try transfer right away
** after SIGHUP.
*/
if (reloading) {
if (!(zp->z_flags & (Z_QSERIAL|Z_XFER_RUNNING))
&& reloading) {
zp->z_time = tt.tv_sec;
needmaint = 1;
}
@ -666,8 +669,10 @@ zoneinit(zp)
*/
zp->z_refresh = INIT_REFRESH;
zp->z_retry = INIT_REFRESH;
zp->z_time = tt.tv_sec;
needmaint = 1;
if (!(zp->z_flags & (Z_QSERIAL|Z_XFER_RUNNING))) {
zp->z_time = tt.tv_sec;
needmaint = 1;
}
} else {
zp->z_flags |= Z_AUTH;
}
@ -706,6 +711,8 @@ findzone(dname, class)
string as the zone name */
dZoneNameLen = strlen(dZoneName);
for (zoneNum = 1; zoneNum < nzones; zoneNum++) {
if (zones[zoneNum].z_type == Z_NIL)
continue;
zoneName = (zones[zoneNum]).z_origin;
zoneNameLen = strlen(zoneName);
/* The zone name may or may not end with a '.' */
@ -764,12 +771,15 @@ get_forwarders(fp)
}
#endif /* SLAVE_FORWARD */
while (getword(buf, sizeof(buf), fp)) {
while (getword(buf, sizeof(buf), fp, 0)) {
if (strlen(buf) == 0)
break;
dprintf(1, (ddt," %s",buf));
if (ftp == NULL)
if (!ftp) {
ftp = (struct fwdinfo *)malloc(sizeof(struct fwdinfo));
if (!ftp)
panic(errno, "malloc(fwdinfo)");
}
if (inet_aton(buf, &ftp->fwdaddr.sin_addr)) {
ftp->fwdaddr.sin_port = ns_port;
ftp->fwdaddr.sin_family = AF_INET;
@ -930,6 +940,8 @@ ns_option(name)
{
if (!strcasecmp(name, "no-recursion")) {
NoRecurse = 1;
} else if (!strcasecmp(name, "no-fetch-glue")) {
NoFetchGlue = 1;
#ifdef QRYLOG
} else if (!strcasecmp(name, "query-log")) {
qrylog = 1;

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91";
static char rcsid[] = "$Id: ns_main.c,v 1.4 1995/10/23 11:11:47 peter Exp $";
static char rcsid[] = "$Id: ns_main.c,v 1.5 1996/01/01 08:44:53 peter Exp $";
#endif /* not lint */
/*
@ -62,12 +62,12 @@ static char rcsid[] = "$Id: ns_main.c,v 1.4 1995/10/23 11:11:47 peter Exp $";
char copyright[] =
"@(#) Copyright (c) 1986, 1989, 1990 The Regents of the University of California.\n\
portions Copyright (c) 1993 Digital Equipment Corporation\n\
portions Copyright (c) 1993 Berkeley Network Software Consortium\n\
portions Copyright (c) 1995 Internet Software Consortium\n\
All rights reserved.\n";
#endif /* not lint */
/*
* Internet Name server (see rfc883 & others).
* Internet Name server (see RCF1035 & others).
*/
#include <sys/param.h>
@ -393,19 +393,14 @@ main(argc, argv, envp)
/*
* named would be terminated if one of these is sent and no handler.
*/
(void) signal(SIGINT, setdumpflg);
(void) signal(SIGQUIT, setchkptflg);
(void) signal(SIGIOT, setstatsflg);
#if defined(SIGUSR1) && defined(SIGUSR2)
(void) signal(SIGUSR1, setIncrDbgFlg);
(void) signal(SIGUSR2, setNoDbgFlg);
#else /* SIGUSR1&&SIGUSR2 */
(void) signal(SIGEMT, setIncrDbgFlg);
(void) signal(SIGFPE, setNoDbgFlg);
#endif /* SIGUSR1&&SIGUSR2 */
setsignal(SIGINT, -1, setdumpflg);
setsignal(SIGQUIT, -1, setchkptflg);
setsignal(SIGIOT, -1, setstatsflg);
setsignal(SIGUSR1, -1, setIncrDbgFlg);
setsignal(SIGUSR2, -1, setNoDbgFlg);
#if defined(SIGWINCH) && defined(QRYLOG)
(void) signal(SIGWINCH, setQrylogFlg);
setsignal(SIGWINCH, -1, setQrylogFlg);
#endif
/*
@ -432,50 +427,29 @@ main(argc, argv, envp)
time(&boottime);
resettime = boottime;
(void) signal(SIGHUP, onhup);
setsignal(SIGALRM, SIGCHLD, maint_alarm);
setsignal(SIGCHLD, SIGALRM, reapchild);
setsignal(SIGPIPE, -1, (SIG_FN (*)())SIG_IGN);
setsignal(SIGHUP, -1, onhup);
#if defined(SIGXFSZ)
(void) signal(SIGXFSZ, onhup); /* wierd DEC Hesiodism, harmless */
/* Wierd DEC Hesiodism, harmless. */
setsignal(SIGXFSZ, -1, onhup);
#endif
#if defined(POSIX_SIGNALS)
bzero((char *)&sact, sizeof(sact));
sact.sa_handler = maint_alarm;
sigemptyset(&sact.sa_mask);
sigaddset(&sact.sa_mask, SIGCHLD);
(void) sigaction(SIGALRM, &sact, (struct sigaction *)NULL);
sact.sa_handler = endxfer;
sigemptyset(&sact.sa_mask);
sigaddset(&sact.sa_mask, SIGALRM);
(void) sigaction(SIGCHLD, &sact, (struct sigaction *)NULL);
#else
#if defined(SYSV)
(void) signal(SIGCLD, (SIG_FN (*)()) endxfer);
(void) signal(SIGALRM, maint_alarm);
#else
bzero((char *)&vec, sizeof(vec));
vec.sv_handler = maint_alarm;
vec.sv_mask = sigmask(SIGCHLD);
(void) sigvec(SIGALRM, &vec, (struct sigvec *)NULL);
vec.sv_handler = endxfer;
vec.sv_mask = sigmask(SIGALRM);
(void) sigvec(SIGCHLD, &vec, (struct sigvec *)NULL);
#endif /* SYSV */
#endif /* POSIX_SIGNALS */
(void) signal(SIGPIPE, SIG_IGN);
#ifdef SIGSYS
(void) signal(SIGSYS, sigprof);
setsignal(SIGSYS, -1, sigprof);
#endif /* SIGSYS */
#ifdef ALLOW_UPDATES
/* Catch SIGTERM so we can dump the database upon shutdown if it
has changed since it was last dumped/booted */
(void) signal(SIGTERM, onintr);
setsignal(SIGTERM, -1, onintr);
#endif
#ifdef XSTATS
/* Catch SIGTERM so we can write stats before exiting. */
(void) signal(SIGTERM, onintr);
setsignal(SIGTERM, -1, onintr);
#endif
dprintf(1, (ddt, "database initialized\n"));
@ -621,6 +595,12 @@ main(argc, argv, envp)
needStatsDump = 0;
ns_stats();
}
if (needendxfer) {
holdsigchld();
needendxfer = 0; /* should be safe even if not held */
endxfer(); /* releases SIGCHLD */
}
releasesigchld();
if (needzoneload) {
needzoneload = 0;
loadxfer();
@ -849,11 +829,11 @@ main(argc, argv, envp)
}
if ((sp->s_bufp - (u_char *)&sp->s_tempsize) ==
INT16SZ) {
sp->s_size = htons(sp->s_tempsize);
sp->s_size = ntohs(sp->s_tempsize);
if (sp->s_bufsize == 0) {
if ( (sp->s_buf = (u_char *)
if (!(sp->s_buf = (u_char *)
malloc(rbufsize))
== NULL) {
) {
sp->s_buf = buf;
sp->s_size = sizeof(buf);
} else {
@ -957,7 +937,7 @@ getnetconf()
exit(1);
}
ntp = NULL;
#if defined(AF_LINK) && !defined(RISCOS_BSD)
#if defined(AF_LINK) && !defined(RISCOS_BSD) && !defined(M_UNIX)
#define my_max(a, b) (a > b ? a : b)
#define my_size(p) my_max((p).sa_len, sizeof(p))
#else
@ -1039,6 +1019,8 @@ getnetconf()
*/
if (ntp == NULL) {
ntp = (struct netinfo *)malloc(sizeof(struct netinfo));
if (!ntp)
panic(errno, "malloc(netinfo)");
}
ntp->my_addr = ((struct sockaddr_in *)
&ifreq.ifr_addr)->sin_addr;
@ -1113,10 +1095,8 @@ getnetconf()
* wildcard address.
*/
if (first) {
if (!(dqp = (struct qdatagram *)calloc(1, sizeof(*dqp)))) {
syslog(LOG_ERR, "getnetconf: malloc: %m");
exit(12);
}
if (!(dqp = (struct qdatagram *)calloc(1, sizeof(*dqp))))
panic(errno, "malloc(qdatagram)");
dqp->dq_next = datagramq;
datagramq = dqp;
dqp->dq_addr.s_addr = INADDR_ANY;
@ -1135,11 +1115,9 @@ getnetconf()
if (findnetinfo(ntp->my_addr))
continue;
ontp = (struct netinfo *)
malloc(sizeof(struct netinfo));
if (ontp == NULL) {
syslog(LOG_ERR, "getnetconf: malloc: %m");
exit(12);
}
malloc(sizeof(struct netinfo));
if (!ontp)
panic(errno, "malloc(netinfo)");
ontp->my_addr = ntp->my_addr;
ontp->mask = nm;
ontp->addr = ontp->my_addr.s_addr & nm;
@ -1251,9 +1229,8 @@ static SIG_FN
onhup()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGHUP, (SIG_FN (*)())onhup);
#endif /* SYSV */
resignal(SIGHUP, -1, onhup);
needreload = 1;
errno = save_errno;
}
@ -1268,9 +1245,8 @@ static SIG_FN
maint_alarm()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGALRM, (SIG_FN (*)())maint_alarm);
#endif /* SYSV */
resignal(SIGALRM, SIGCHLD, maint_alarm);
needmaint = 1;
errno = save_errno;
}
@ -1284,7 +1260,11 @@ maint_alarm()
static SIG_FN
onintr()
{
int save_errno = errno;
resignal(SIGTERM, -1, onintr);
needToExit = 1;
errno = save_errno;
}
#endif /* ALLOW_UPDATES */
@ -1295,7 +1275,11 @@ onintr()
static SIG_FN
onintr()
{
needToExit = 1;
int save_errno = errno;
resignal(SIGTERM, -1, onintr);
needToExit = 1; /* XXX variable reuse */
errno = save_errno;
}
#endif /* XSTATS */
@ -1309,9 +1293,8 @@ static SIG_FN
setdumpflg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGINT, (SIG_FN (*)())setdumpflg);
#endif /* SYSV */
resignal(SIGINT, -1, setdumpflg);
needToDoadump = 1;
errno = save_errno;
}
@ -1368,9 +1351,8 @@ static SIG_FN
setIncrDbgFlg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGUSR1, (SIG_FN (*)())setIncrDbgFlg);
#endif /* SYSV */
resignal(SIGUSR1, -1, setIncrDbgFlg);
#ifdef DEBUG
if (debug == 0) {
debug++;
@ -1392,9 +1374,8 @@ static SIG_FN
setNoDbgFlg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGUSR2, (SIG_FN (*)())setNoDbgFlg);
#endif /* SYSV */
resignal(SIGUSR2, -1, setNoDbgFlg);
setdebug(0);
errno = save_errno;
}
@ -1407,9 +1388,8 @@ static SIG_FN
setQrylogFlg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGWINCH, (SIG_FN (*)())setQrylogFlg);
#endif /* SYSV */
resignal(SIGWINCH, -1, setQrylogFlg);
qrylog = !qrylog;
syslog(LOG_NOTICE, "query log %s\n", qrylog ?"on" :"off");
errno = save_errno;
@ -1423,9 +1403,8 @@ static SIG_FN
setstatsflg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGIOT, (SIG_FN (*)())setstatsflg);
#endif /* SYSV */
resignal(SIGIOT, -1, setstatsflg);
needStatsDump = 1;
errno = save_errno;
}
@ -1434,9 +1413,8 @@ static SIG_FN
setchkptflg()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGQUIT, (SIG_FN (*)())setchkptflg);
#endif /* SYSV */
resignal(SIGQUIT, -1, setchkptflg);
needToChkpt = 1;
errno = save_errno;
}
@ -1453,9 +1431,8 @@ static SIG_FN
sigprof()
{
int save_errno = errno;
#if defined(SYSV)
(void)signal(SIGSYS, (SIG_FN (*)())sigprof);
#endif /* SYSV */
resignal(SIGSYS, -1, sigprof);
dprintf(1, (ddt, "sigprof()\n"));
if (fork() == 0)
{

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_maint.c 4.39 (Berkeley) 3/2/91";
static char rcsid[] = "$Id: ns_maint.c,v 1.3 1995/08/20 21:18:49 peter Exp $";
static char rcsid[] = "$Id: ns_maint.c,v 1.4 1995/10/23 11:11:48 peter Exp $";
#endif /* not lint */
/*
@ -143,7 +143,6 @@ ns_maint()
}
if (zp->z_flags & Z_XFER_RUNNING) {
abortxfer(zp);
ns_retrytime(zp, tt.tv_sec);
break;
}
qserial_query(zp);
@ -207,7 +206,7 @@ sched_maint()
* Schedule the next call to ns_maint.
* Don't visit any sooner than maint_interval.
*/
bzero((char *)&ival, sizeof (ival));
bzero((char *)&ival, sizeof ival);
if (next_refresh != 0) {
if (next_refresh == next_alarm && alarm_pending) {
dprintf(1, (ddt, "sched_maint: no schedule change\n"));
@ -269,8 +268,8 @@ markUpToDate(zp)
setting it to tt.tv_sec in order to avoid any
possible rounding problems in utimes(). */
if (stat(zp->z_source, &f_time) != -1)
zp->z_ftime = f_time.st_mtime;
/* XXX log if stat fails? XXX */
zp->z_ftime = f_time.st_mtime;
/* XXX log if stat fails? */
}
/*
@ -344,6 +343,57 @@ qserial_answer(qp, serial)
needmaint = 1;
}
/*
* Hold and release SIGCHLD
*/
#ifdef POSIX_SIGNALS
static sigset_t sset;
#else
#ifndef SYSV
static int omask;
#endif
#endif /* POSIX_SIGNALS */
void holdsigchld()
{
#ifdef POSIX_SIGNALS
sigemptyset(&sset);
sigaddset(&sset,SIGCHLD);
sigprocmask(SIG_BLOCK,&sset,NULL);
#else /* POSIX_SIGNALS */
#ifndef SYSV
omask = sigblock(sigmask(SIGCHLD));
#else /* SYSV */
/* XXX - out of luck? */
#endif /* SYSV */
#endif /* POSIX_SIGNALS */
}
void releasesigchld()
{
#ifdef POSIX_SIGNALS
sigprocmask(SIG_UNBLOCK,&sset,NULL);
#else
#ifndef SYSV
(void) sigsetmask(omask);
#endif
#endif /* POSIX_SIGNALS */
}
/* State of all running zone transfers */
static struct {
pid_t xfer_pid;
int xfer_state; /* see below */
#ifdef sequent
union wait xfer_status;
#else
int xfer_status;
#endif
} xferstatus[MAX_XFERS_RUNNING];
#define XFER_IDLE 0
#define XFER_RUNNING 1
#define XFER_DONE 2
/*
* Start an asynchronous zone transfer for a zone.
* Depends on current time being in tt.
@ -354,7 +404,7 @@ startxfer(zp)
struct zoneinfo *zp;
{
static char *argv[NSMAX + 20], argv_ns[NSMAX][MAXDNAME];
int argc = 0, argc_ns = 0, pid, omask;
int argc = 0, argc_ns = 0, pid, i;
unsigned int cnt;
char debug_str[10];
char serial_str[10];
@ -362,13 +412,10 @@ startxfer(zp)
#ifdef GEN_AXFR
char class_str[10];
#endif
#ifdef POSIX_SIGNALS
sigset_t sset;
#endif
dprintf(1, (ddt, "startxfer() %s\n", zp->z_origin));
argv[argc++] = "named-xfer";
argv[argc++] = _PATH_XFER;
argv[argc++] = "-z";
argv[argc++] = zp->z_origin;
argv[argc++] = "-f";
@ -405,21 +452,20 @@ startxfer(zp)
#endif
if (zp->z_xaddr.s_addr != 0) {
/* address was specified by the qserial logic, use it */
/* Address was specified by the qserial logic, use it. */
argv[argc++] = strcpy(argv_ns[argc_ns++],
inet_ntoa(zp->z_xaddr));
} else {
/*
* Copy the server ip addresses into argv, after converting
* to ascii and saving the static inet_ntoa result
* to ascii and saving the static inet_ntoa result.
*/
for (cnt = 0; cnt < zp->z_addrcnt; cnt++) {
struct in_addr a;
a = zp->z_addr[cnt];
if (aIsUs(a)
&& !haveComplained(zp->z_origin,
(char*)startxfer)) {
if (aIsUs(a) &&
!haveComplained(zp->z_origin, (char*)startxfer)) {
syslog(LOG_NOTICE,
"attempted to fetch zone %s from self (%s)",
zp->z_origin, inet_ntoa(a));
@ -435,56 +481,43 @@ startxfer(zp)
#ifdef DEBUG
#ifdef ECHOARGS
if (debug) {
int i;
for (i = 0; i < argc; i++)
for (i = 0; i < argc; i++)
fprintf(ddt, "Arg %d=%s\n", i, argv[i]);
}
#endif /* ECHOARGS */
#endif /* DEBUG */
gettime(&tt);
#ifndef SYSV
#if defined(POSIX_SIGNALS)
sigemptyset(&sset);
sigaddset(&sset,SIGCHLD);
sigprocmask(SIG_BLOCK,&sset,NULL);
#else
omask = sigblock(sigmask(SIGCHLD));
#endif
#endif
holdsigchld();
for (i = 0; i < MAX_XFERS_RUNNING; i++) {
if (xferstatus[i].xfer_pid == 0) {
xferstatus[i].xfer_state = XFER_RUNNING;
break;
}
}
if ((pid = vfork()) == -1) {
syslog(LOG_ERR, "xfer vfork: %m");
#ifndef SYSV
#if defined(POSIX_SIGNALS)
sigprocmask(SIG_UNBLOCK,&sset,NULL);
#else
(void) sigsetmask(omask);
#endif
#endif
releasesigchld();
zp->z_time = tt.tv_sec + 10;
return;
}
if (pid == 0) {
/* child */
/* Child. */
execv(_PATH_XFER, argv);
syslog(LOG_ERR, "can't exec %s: %m", _PATH_XFER);
_exit(XFER_FAIL); /* avoid duplicate buffer flushes */
_exit(XFER_FAIL); /* Avoid duplicate buffer flushes. */
}
/* parent */
/* Parent. */
xferstatus[i].xfer_pid = pid; /* XXX - small race condition here if we
* can't hold signals */
dprintf(1, (ddt, "started xfer child %d\n", pid));
zp->z_flags &= ~Z_NEED_XFER;
zp->z_flags |= Z_XFER_RUNNING;
zp->z_xferpid = pid;
xfers_running++;
zp->z_time = tt.tv_sec + MAX_XFER_TIME;
#ifndef SYSV
#if defined(POSIX_SIGNALS)
sigprocmask(SIG_UNBLOCK,&sset,NULL);
#else
(void) sigsetmask(omask);
#endif
#endif
releasesigchld();
}
const char *
@ -509,7 +542,7 @@ zoneTypeString(zp)
#ifdef DEBUG
void
printzoneinfo(zonenum)
int zonenum;
int zonenum;
{
struct timeval tt;
struct zoneinfo *zp = &zones[zonenum];
@ -517,13 +550,13 @@ int zonenum;
if (!debug)
return;
if (!zp->z_origin)
return;
fprintf(ddt, "printzoneinfo(%d):\n", zonenum);
gettime(&tt);
if (zp->z_origin != NULL && (zp->z_origin[0] == '\0'))
fprintf(ddt, "origin ='.'");
else
fprintf(ddt, "origin ='%s'", zp->z_origin);
fprintf(ddt, "origin ='%s'", zp->z_origin[0] ? zp->z_origin : ".");
#ifdef GEN_AXFR
fprintf(ddt, ", class = %d", zp->z_class);
#endif
@ -539,7 +572,7 @@ int zonenum;
if (zp->z_time) {
fprintf(ddt, ", now time : %lu sec", (u_long)tt.tv_sec);
fprintf(ddt, ", time left: %lu sec",
(int)(zp->z_time - tt.tv_sec));
(long)(zp->z_time - tt.tv_sec));
}
fprintf(ddt, "; flags %lx\n", (u_long)zp->z_flags);
}
@ -566,49 +599,50 @@ remove_zone(htp, zone)
struct namebuf **npp, **nppend;
nppend = htp->h_tab + htp->h_size;
for (npp = htp->h_tab; npp < nppend; npp++)
for (pnp = NULL, np = *npp; np != NULL; np = npn) {
for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
#ifdef CLEANCACHE
if (dp->d_zone == zone && (all || stale(dp)))
#else
if (dp->d_zone == zone)
#endif
dp = rm_datum(dp, np, pdp);
else {
pdp = dp;
dp = dp->d_next;
}
}
if (np->n_hash) {
/* call recursively to remove subdomains. */
for (npp = htp->h_tab; npp < nppend; npp++) {
for (pnp = NULL, np = *npp; np != NULL; np = npn) {
for (pdp = NULL, dp = np->n_data; dp != NULL; NULL) {
if (dp->d_zone == zone
#ifdef CLEANCACHE
remove_zone(np->n_hash, zone, all);
#else
remove_zone(np->n_hash, zone);
&& (all || stale(dp))
#endif
) {
dp = rm_datum(dp, np, pdp);
} else {
pdp = dp;
dp = dp->d_next;
}
} /*for(pdp)*/
/* if now empty, free it */
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
if (np->n_hash) {
/* call recursively to remove subdomains. */
remove_zone(np->n_hash, zone
#ifdef CLEANCACHE
, all
#endif
);
/* if now empty, free it */
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
}
}
}
if ((np->n_hash == NULL) && (np->n_data == NULL)) {
npn = rm_name(np, npp, pnp);
htp->h_cnt--;
} else {
npn = np->n_next;
pnp = np;
}
}
if ((np->n_hash == NULL) && (np->n_data == NULL)) {
npn = rm_name(np, npp, pnp);
htp->h_cnt--;
} else {
npn = np->n_next;
pnp = np;
}
} /*for(pnp)*/
} /*for(npp)*/
}
#ifdef PURGE_ZONE
static void purge_z_2();
static bottom_of_zone();
static void purge_z_2 __P((struct hashbuf *, int));
static bottom_of_zone __P((struct databuf *, int));
void
purge_zone(dname, htp, class)
@ -622,10 +656,11 @@ purge_zone(dname, htp, class)
struct hashbuf *phtp = htp;
dprintf(1, (ddt, "purge_zone(%s,%d)\n", dname, class));
if ((np = nlookup(dname, &phtp, &fname, 0)) && dname == fname) {
if ((np = nlookup(dname, &phtp, &fname, 0)) && dname == fname &&
!WILDCARD_P(dname)) {
for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
if (dp->d_class == class)
dp = rm_datum(dp, np, pdp);
dp = rm_datum(dp, np, pdp);
else {
pdp = dp;
dp = dp->d_next;
@ -633,48 +668,45 @@ purge_zone(dname, htp, class)
}
if (np->n_hash) {
purge_z_2(np->n_hash, class);
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
}
purge_z_2(np->n_hash, class);
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
}
}
/* remove entry from cache, if required */
if ((np->n_hash == NULL) && (np->n_data == NULL)) {
struct namebuf **npp, **nppend;
struct namebuf *npn, *pnp, *nnp;
struct namebuf **npp, **nppend;
struct namebuf *npn, *pnp, *nnp;
dprintf(3,(ddt, "purge_zone: cleaning cache\n"));
dprintf(3,(ddt, "purge_zone: cleaning cache\n"));
/* walk parent hashtable looking for ourself */
if (np->n_parent)
phtp = np->n_parent->n_hash;
else
phtp = htp; /* top / root zone */
/* walk parent hashtable looking for ourself */
if (np->n_parent)
phtp = np->n_parent->n_hash;
else
phtp = htp; /* top / root zone */
if (phtp) {
nppend = phtp->h_tab + phtp->h_size;
for (npp = phtp->h_tab; npp < nppend; npp++) {
for (pnp = NULL, nnp = *npp;
nnp != NULL;
nnp = npn
) {
if (nnp == np) {
dprintf(3,(ddt, "purge_zone: found our selves\n"));
npn = rm_name(nnp, npp, pnp);
phtp->h_cnt--;
} else {
npn = nnp->n_next;
pnp = nnp;
if (phtp) {
nppend = phtp->h_tab + phtp->h_size;
for (npp = phtp->h_tab; npp < nppend; npp++) {
for (pnp = NULL, nnp = *npp;
nnp != NULL;
nnp = npn) {
if (nnp == np) {
dprintf(3, (ddt,
"purge_zone: found our selves\n"
));
npn = rm_name(nnp,npp,pnp);
phtp->h_cnt--;
} else {
npn = nnp->n_next;
pnp = nnp;
}
}
}
}
}
}
}
}
}
@ -689,39 +721,38 @@ purge_z_2(htp, class)
struct namebuf **npp, **nppend;
nppend = htp->h_tab + htp->h_size;
for (npp = htp->h_tab; npp < nppend; npp++)
for (pnp = NULL, np = *npp; np != NULL; np = npn) {
if (!bottom_of_zone(np->n_data, class)) {
for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
if (dp->d_class == class)
dp = rm_datum(dp, np, pdp);
else {
pdp = dp;
dp = dp->d_next;
for (npp = htp->h_tab; npp < nppend; npp++) {
for (pnp = NULL, np = *npp; np != NULL; np = npn) {
if (!bottom_of_zone(np->n_data, class)) {
for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
if (dp->d_class == class)
dp = rm_datum(dp, np, pdp);
else {
pdp = dp;
dp = dp->d_next;
}
}
if (np->n_hash) {
/* call recursively to rm subdomains */
purge_z_2(np->n_hash, class);
/* if now empty, free it */
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
}
}
}
}
if (np->n_hash) {
/* call recursively to remove subdomains. */
purge_z_2(np->n_hash, class);
/* if now empty, free it */
if (np->n_hash->h_cnt == 0) {
free((char*)np->n_hash);
np->n_hash = NULL;
if ((np->n_hash == NULL) && (np->n_data == NULL)) {
npn = rm_name(np, npp, pnp);
htp->h_cnt--;
} else {
npn = np->n_next;
pnp = np;
}
}
}
if ((np->n_hash == NULL) && (np->n_data == NULL)) {
npn = rm_name(np, npp, pnp);
htp->h_cnt--;
} else {
npn = np->n_next;
pnp = np;
}
}
}
}
static int
@ -783,12 +814,51 @@ static void
abortxfer(zp)
struct zoneinfo *zp;
{
kill(zp->z_xferpid, SIGKILL);
syslog(LOG_NOTICE, "zone transfer timeout for \"%s\"; pid %lu killed",
zp->z_origin, (u_long)zp->z_xferpid);
ns_retrytime(zp, tt.tv_sec);
(void) nxfers(zp, -1);
xfers_running--;
if (zp->z_flags & (Z_XFER_GONE|Z_XFER_ABORTED)) {
int i;
for (i = 0; i < MAX_XFERS_RUNNING; i++) {
if (xferstatus[i].xfer_pid == zp->z_xferpid) {
xferstatus[i].xfer_pid = 0;
xferstatus[i].xfer_state = XFER_IDLE;
break;
}
}
if (zp->z_flags & Z_XFER_GONE)
syslog(LOG_WARNING,
"zone transfer timeout for \"%s\"; pid %lu missing",
zp->z_origin, (u_long)zp->z_xferpid);
else if (kill(zp->z_xferpid, SIGKILL) == -1)
syslog(LOG_WARNING,
"zone transfer timeout for \"%s\"; kill pid %lu: %m",
zp->z_origin, (u_long)zp->z_xferpid);
else
syslog(LOG_WARNING,
"zone transfer timeout for \"%s\"; second kill\
pid %lu - forgetting, processes may accumulate",
zp->z_origin, (u_long)zp->z_xferpid);
zp->z_xferpid = 0;
xfers_running--;
(void)nxfers(zp, -1);
zp->z_flags &= ~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
} else if (kill(zp->z_xferpid, SIGKILL) == -1) {
if (errno == ESRCH)
/* No warning on first time, it may have just exited */
zp->z_flags |= Z_XFER_GONE;
else {
syslog(LOG_WARNING,
"zone transfer timeout for \"%s\"; pid %lu kill failed %m",
zp->z_origin, (u_long)zp->z_xferpid);
zp->z_flags |= Z_XFER_ABORTED;
}
} else {
syslog(LOG_NOTICE,
"zone transfer timeout for \"%s\"; pid %lu killed",
zp->z_origin, (u_long)zp->z_xferpid);
zp->z_flags |= Z_XFER_ABORTED;
}
}
/*
@ -796,18 +866,19 @@ abortxfer(zp)
* (Note: also called when outgoing transfer completes.)
*/
SIG_FN
endxfer()
reapchild()
{
register struct zoneinfo *zp;
int exitstatus, pid, xfers, save_errno;
int pid, i, save_errno;
#if defined(sequent)
union wait status;
#else
int status;
#endif /* sequent */
#if defined(MUST_REARM_SIGS)
(void)signal(SIGCLD, (SIG_FN (*)()) reapchild);
#endif
save_errno = errno;
xfers = 0;
gettime(&tt);
#if defined(USE_WAITPID)
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
@ -815,18 +886,51 @@ endxfer()
{
pid = wait(&status);
#endif /* USE_WAITPID */
for (i = 0; i < MAX_XFERS_RUNNING; i++) {
if (xferstatus[i].xfer_pid == pid) {
xferstatus[i].xfer_status = status;
xferstatus[i].xfer_state = XFER_DONE;
needendxfer++;
break;
}
}
}
errno = save_errno;
}
/*
* Finish processing of of finished xfers
*/
void
endxfer()
{
register struct zoneinfo *zp;
int exitstatus, pid, i;
#if defined(sequent)
union wait status;
#else
int status;
#endif /* sequent */
gettime(&tt);
for (i = 0; i < MAX_XFERS_RUNNING; i++) {
if (xferstatus[i].xfer_state != XFER_DONE)
continue;
pid = xferstatus[i].xfer_pid;
status = xferstatus[i].xfer_status;
exitstatus = WIFEXITED(status) ?WEXITSTATUS(status) :0;
for (zp = zones; zp < &zones[nzones]; zp++) {
if (zp->z_xferpid != pid)
continue;
xfers++;
xfers_running--;
(void) nxfers(zp, -1);
zp->z_xferpid = 0;
zp->z_flags &= ~Z_XFER_RUNNING;
zp->z_flags &=
~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
dprintf(1, (ddt,
"\nendxfer: child %d zone %s returned status=%d termsig=%d\n",
"\nendxfer: child %d zone %s returned status=%d termsig=%d\n",
pid, zp->z_origin, exitstatus,
WIFSIGNALED(status) ?WTERMSIG(status) :-1
)
@ -845,6 +949,7 @@ endxfer()
break;
case XFER_SUCCESS:
/* XXX should incorporate loadxfer() */
zp->z_flags |= Z_NEED_RELOAD;
zp->z_flags &= ~Z_SYSLOGGED;
needzoneload++;
@ -855,7 +960,7 @@ endxfer()
zp->z_flags |= Z_SYSLOGGED;
syslog(LOG_NOTICE,
"zoneref: Masters for secondary zone \"%s\" unreachable",
zp->z_origin);
zp->z_origin);
}
ns_retrytime(zp, tt.tv_sec);
break;
@ -865,23 +970,23 @@ endxfer()
zp->z_flags |= Z_SYSLOGGED;
syslog(LOG_NOTICE,
"named-xfer for \"%s\" exited %d",
zp->z_origin, exitstatus);
zp->z_origin,
exitstatus);
}
/* FALLTHROUGH */
case XFER_FAIL:
zp->z_flags |= Z_SYSLOGGED;
ns_retrytime(zp, tt.tv_sec);
break;
} /*switch*/
}
break;
} /*if/else*/
} /*for*/
} /*while*/
}
}
xferstatus[i].xfer_state = XFER_IDLE;
xferstatus[i].xfer_pid = 0;
}
releasesigchld();
tryxfer();
#if defined(SYSV)
(void)signal(SIGCLD, (SIG_FN (*)()) endxfer);
#endif
errno = save_errno;
}
/*
@ -954,9 +1059,8 @@ tryxfer() {
* Reload zones whose transfers have completed.
*/
void
loadxfer()
{
register struct zoneinfo *zp;
loadxfer() {
register struct zoneinfo *zp;
gettime(&tt);
for (zp = zones; zp < &zones[nzones]; zp++) {
@ -964,11 +1068,11 @@ loadxfer()
dprintf(1, (ddt, "loadxfer() \"%s\"\n",
zp->z_origin[0] ? zp->z_origin : "."));
zp->z_flags &= ~(Z_NEED_RELOAD|Z_AUTH);
remove_zone(hashtab, zp - zones
#ifdef CLEANCACHE
remove_zone(hashtab, zp - zones, 1);
#else
remove_zone(hashtab, zp - zones);
, 1
#endif
);
#ifdef PURGE_ZONE
purge_zone(zp->z_origin, hashtab, zp->z_class);
#endif

View File

@ -53,7 +53,7 @@ cache_n_resp(msg, msglen)
dname, type, class));
#ifdef VALIDATE
Vcode = validate(dname, &from_addr, type, class, NULL, 0,
Vcode = validate(dname, dname, &from_addr, type, class, NULL, 0,
hp->rcode == NXDOMAIN ? NXDOMAIN : NOERROR_NODATA);
if (Vcode == INVALID || Vcode == VALID_NO_CACHE) {
/*Valid_no_cache should never occur but doesn't hurt to check*/

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_req.c 4.47 (Berkeley) 7/1/91";
static char rcsid[] = "$Id: ns_req.c,v 1.3 1995/08/20 21:18:54 peter Exp $";
static char rcsid[] = "$Id: ns_req.c,v 1.4 1995/10/23 11:11:50 peter Exp $";
#endif /* not lint */
/*
@ -133,6 +133,9 @@ ns_req(msg, msglen, buflen, qsp, from, dfd)
{
register HEADER *hp = (HEADER *) msg;
u_char *cp, *eom;
#ifdef DEBUG
const char *sortmsgtxt;
#endif
enum req_action action;
int n;
@ -227,10 +230,10 @@ ns_req(msg, msglen, buflen, qsp, from, dfd)
dprintf(1, (ddt, "ns_req: Opcode %d not implemented\n",
hp->opcode));
/* XXX - should syslog, limited by haveComplained */
hp->qdcount = 0;
hp->ancount = 0;
hp->nscount = 0;
hp->arcount = 0;
hp->qdcount = htons(0);
hp->ancount = htons(0);
hp->nscount = htons(0);
hp->arcount = htons(0);
hp->rcode = NOTIMP;
action = Finish;
}
@ -257,20 +260,23 @@ ns_req(msg, msglen, buflen, qsp, from, dfd)
*/
hp->qr = 1; /* set Response flag */
hp->ra = (NoRecurse == 0);
hp->ancount = htons(hp->ancount);
n = doaddinfo(hp, cp, buflen);
cp += n;
buflen -= n;
dprintf(1, (ddt, "ns_req: answer -> %s fd=%d id=%d size=%d %s\n",
sin_ntoa(from),
(qsp == QSTREAM_NULL) ?dfd :qsp->s_rfd,
ntohs(hp->id), cp - msg, local(from) == NULL ? "Remote" : "Local"));
#ifdef DEBUG
#ifdef SORT_RESPONSE
sortmsgtxt = local(from) == NULL ? "Remote" : "Local";
#else /*SORT*/
sortmsgtxt = "(not sorting)";
#endif /*SORT*/
dprintf(1, (ddt, "ns_req: answer -> %s fd=%d id=%d size=%d %s\n",
sin_ntoa(from), (qsp == QSTREAM_NULL) ? dfd : qsp->s_rfd,
ntohs(hp->id), cp - msg, sortmsgtxt));
if (debug >= 10)
fp_nquery(msg, cp - msg, ddt);
#endif
#endif /*DEBUG*/
if (qsp == QSTREAM_NULL) {
if (sendto(dfd, (char*)msg, cp - msg, 0,
(struct sockaddr *)from,
@ -328,14 +334,14 @@ req_notify(hp, cpp, eom, msg, from)
/* valid notify's have one question and zero answers */
if ((ntohs(hp->qdcount) != 1)
|| hp->ancount
|| hp->nscount
|| hp->arcount) {
|| ntohs(hp->ancount) != 0
|| ntohs(hp->nscount) != 0
|| ntohs(hp->arcount) != 0) {
dprintf(1, (ddt, "FORMERR Notify header counts wrong\n"));
hp->qdcount = 0;
hp->ancount = 0;
hp->nscount = 0;
hp->arcount = 0;
hp->qdcount = htons(0);
hp->ancount = htons(0);
hp->nscount = htons(0);
hp->arcount = htons(0);
hp->rcode = FORMERR;
return (Finish);
}
@ -460,14 +466,14 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
/* valid queries have one question and zero answers */
if ((ntohs(hp->qdcount) != 1)
|| hp->ancount
|| hp->nscount
|| hp->arcount) {
|| ntohs(hp->ancount) != 0
|| ntohs(hp->nscount) != 0
|| ntohs(hp->arcount) != 0) {
dprintf(1, (ddt, "FORMERR Query header counts wrong\n"));
hp->qdcount = 0;
hp->ancount = 0;
hp->nscount = 0;
hp->arcount = 0;
hp->qdcount = htons(0);
hp->ancount = htons(0);
hp->nscount = htons(0);
hp->arcount = htons(0);
hp->rcode = FORMERR;
return (Finish);
}
@ -550,7 +556,7 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
try_again:
dprintf(1, (ddt, "req: nlookup(%s) id %d type=%d class=%d\n",
dname, hp->id, type, class));
dname, ntohs(hp->id), type, class));
htp = hashtab; /* lookup relative to root */
if ((anp = np = nlookup(dname, &htp, &fname, 0)) == NULL)
fname = "";
@ -637,21 +643,21 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
*/
for (dp = np->n_data; dp ; dp = dp->d_next) {
if (!stale(dp) && (dp->d_rcode == NXDOMAIN) &&
(dp->d_class == class)) {
(dp->d_class == class)) {
#ifdef RETURNSOA
n = finddata(np, class, T_SOA, hp, &dname,
n = finddata(np, class, T_SOA, hp, &dname,
buflenp, &count);
if (n != 0 ) {
if (n != 0 ) {
if (hp->rcode == NOERROR_NODATA) {
/* this should not occur */
hp->rcode = NOERROR;
return (Finish);
/* this should not occur */
hp->rcode = NOERROR;
return (Finish);
}
*cpp += n;
*buflenp -= n;
*msglenp += n;
hp->nscount = htons((u_int16_t)count);
}
}
#endif
hp->rcode = NXDOMAIN;
hp->aa = 1;
@ -688,7 +694,7 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
*cpp += n;
*buflenp -= n;
*msglenp += n;
hp->ancount += count;
hp->ancount = htons(ntohs(hp->ancount) + (u_int16_t)count);
if (fname != dname && type != T_CNAME && type != T_ANY) {
if (cname++ >= MAXCNAMES) {
dprintf(3, (ddt,
@ -703,8 +709,10 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
"req: foundname=%d, count=%d, founddata=%d, cname=%d\n",
foundname, count, founddata, cname));
if ((lp = local(from)) != NULL)
#ifdef SORT_RESPONSE
if ((lp = local(from)) != NULL)
sort_response(answers, count, lp, *cpp);
#endif
#ifdef BIND_NOTIFY
if (type == T_SOA &&
from->sin_port == ns_port &&
@ -729,7 +737,6 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
}
#endif /*BIND_NOTIFY*/
if (type == T_AXFR) {
hp->ancount = htons(hp->ancount);
startxfr(qsp, np, msg, *cpp - msg, class, dname);
sqrm(qsp);
return (Return);
@ -737,14 +744,19 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
#ifdef notdef
/*
* If we found an authoritative answer,
* we're done.
* If we found an authoritative answer, we're done.
*/
if (hp->aa)
return (Finish);
#endif
fetchns:
/*
* If we're already out of room in the response, we're done.
*/
if (hp->tc)
return (Finish);
/*
* Look for name servers to refer to and fill in the authority
* section or record the address for forwarding the query
@ -758,9 +770,8 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
switch (findns(&np, class, nsp, &count, 0)) {
case NXDOMAIN:
/* We are authoritative for this np. */
if (!foundname) {
if (!foundname)
hp->rcode = NXDOMAIN;
}
dprintf(3, (ddt, "req: leaving (%s, rcode %d)\n",
dname, hp->rcode));
if (class != C_ANY) {
@ -774,7 +785,7 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
*cpp += n;
*buflenp -= n;
#ifdef ADDAUTH
} else if (hp->ancount) {
} else if (ntohs(hp->ancount) != 0) {
/* don't add NS records for NOERROR NODATA
as some servers can get confused */
#ifdef DATUMREFCNT
@ -789,7 +800,7 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
(type != T_NS || np != anp)
) {
n = add_data(np, nsp, *cpp,
*buflenp);
*buflenp, &count);
if (n < 0) {
hp->tc = 1;
n = (-n);
@ -826,14 +837,15 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
* never recursing, then add the nameserver references
* ("authority section") here and we're done.
*/
if (founddata || (!hp->rd) || NoRecurse) {
/* If the qtype was NS, and the np of the authority is
if (founddata || !hp->rd || NoRecurse) {
/*
* If the qtype was NS, and the np of the authority is
* the same as the np of the data, we don't need to add
* another copy of the answer here in the authority
* section.
*/
if (!founddata || type != T_NS || anp != np) {
n = add_data(np, nsp, *cpp, *buflenp);
n = add_data(np, nsp, *cpp, *buflenp, &count);
if (n < 0) {
hp->tc = 1;
n = (-n);
@ -867,7 +879,6 @@ req_query(hp, cpp, eom, qsp, buflenp, msglenp, msg, dfd, from)
return (Finish);
}
id = hp->id;
hp->ancount = htons(hp->ancount);
omsglen = *msglenp;
bcopy(msg, omsg, omsglen);
n = res_mkquery(QUERY, dname, class, type,
@ -973,16 +984,15 @@ req_iquery(hp, cpp, eom, buflenp, msg, from)
nameserIncr(from->sin_addr, nssRcvdIQ);
hp->ancount = htons(hp->ancount);
if ((hp->ancount != 1)
|| hp->qdcount
|| hp->nscount
|| hp->arcount) {
if (ntohs(hp->ancount) != 1
|| ntohs(hp->qdcount) != 0
|| ntohs(hp->nscount) != 0
|| ntohs(hp->arcount) != 0) {
dprintf(1, (ddt, "FORMERR IQuery header counts wrong\n"));
hp->qdcount = 0;
hp->ancount = 0;
hp->nscount = 0;
hp->arcount = 0;
hp->qdcount = htons(0);
hp->ancount = htons(0);
hp->nscount = htons(0);
hp->arcount = htons(0);
hp->rcode = FORMERR;
return (Finish);
}
@ -1187,8 +1197,8 @@ stale(dp)
case Z_CACHE:
if (dp->d_flags & DB_F_HINT || dp->d_ttl >= tt.tv_sec)
return (0);
dprintf(3, (ddt, "stale: ttl %d %d (x%lx)\n",
dp->d_ttl, dp->d_ttl - tt.tv_sec,
dprintf(3, (ddt, "stale: ttl %d %ld (x%lx)\n",
dp->d_ttl, (long)(dp->d_ttl - tt.tv_sec),
(u_long)dp->d_flags));
return (1);
@ -1215,10 +1225,10 @@ make_rr(name, dp, buf, buflen, doadd)
u_char *cp1, *sp;
struct zoneinfo *zp;
register int32_t n;
register int32_t ttl;
register u_int32_t ttl;
u_char **edp = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
dprintf(5, (ddt, "make_rr(%s, %lx, %lx, %d, %d) %d zone %d ttl %d\n",
dprintf(5, (ddt, "make_rr(%s, %lx, %lx, %d, %d) %d zone %d ttl %lu\n",
name, (u_long)dp, (u_long)buf,
buflen, doadd, dp->d_size, dp->d_zone, dp->d_ttl));
@ -1242,7 +1252,7 @@ make_rr(name, dp, buf, buflen, doadd)
ttl = 0;
}
} else {
if (dp->d_ttl)
if (dp->d_ttl != USE_MINIMUM)
ttl = dp->d_ttl;
else
ttl = zp->z_minimum; /* really default */
@ -1529,11 +1539,7 @@ doaddinfo(hp, msg, msglen)
/* Cache invalidate the address RR's */
delete_all(np, (int)ap->a_class, T_A);
}
if (
#if 0 /*XXX*/
!NoRecurse &&
#endif
!foundcname && (foundstale || !foundany)) {
if (!NoFetchGlue && !foundcname && (foundstale || !foundany)) {
/* ask a real server for this info */
(void) sysquery(ap->a_dname, (int)ap->a_class, T_A,
NULL, 0, QUERY);
@ -1582,7 +1588,7 @@ doaddauth(hp, cp, buflen, np, dp)
}
return (0);
}
hp->nscount = htons((u_int16_t)1);
hp->nscount = htons(ntohs(hp->nscount) + 1);
return (n);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)ns_sort.c 4.10 (Berkeley) 3/3/91";
static char rcsid[] = "$Id: ns_sort.c,v 1.2 1995/05/30 03:48:59 rgrimes Exp $";
static char rcsid[] = "$Id: ns_sort.c,v 1.3 1995/08/20 21:19:01 peter Exp $";
#endif /* not lint */
/*
@ -73,6 +73,7 @@ static char rcsid[] = "$Id: ns_sort.c,v 1.2 1995/05/30 03:48:59 rgrimes Exp $";
static int sort_rr __P((u_char *cp, int count, struct netinfo *ntp, u_char *eom));
#ifdef SORT_RESPONSE
struct netinfo *
local(from)
struct sockaddr_in *from;
@ -167,3 +168,4 @@ sort_rr(cp, count, ntp, eom)
}
return (0);
}
#endif

View File

@ -10,8 +10,11 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <syslog.h>
#include <errno.h>
#include <stdio.h>
@ -50,7 +53,7 @@ static int VQcount;
* VALID_NO_CACHE if the name is something we are authoritative for.
*
* pseudocode for function validate is as follows:
* validate(domain, server, type, class, data, dlen, rcode) {
* validate(domain, qdomain, server, type, class, data, dlen, rcode) {
*
* if (dname or a higher level name not found in cache)
* return INVALID;
@ -63,8 +66,10 @@ static int VQcount;
* if (data agrees with what we have)
* return VALID_NO_CACHE;
* else return INVALID;
*
* if (we are not authoritative) /findns() returned OK;/
*
* if (we are not authoritative) /findns() returned OK;/
* if (domain lives below the qdomain)
* return VALID_CACHE;
* if (address records for NS's found in cache){
* if ("server" = one of the addresses){
* return VALID_CACHE;
@ -88,15 +93,14 @@ static int VQcount;
* we have needs_prime_cache = 0;
*****************************************************************************/
int
validate(dname, server, type, class, data, dlen
validate(dname, qdomain, server, type, class, data, dlen
#ifdef NCACHE
,rcode
#endif
)
char *dname;
char *dname, *qdomain;
struct sockaddr_in *server;
int type;
int class;
int type, class;
char *data;
int dlen;
#ifdef NCACHE
@ -107,7 +111,7 @@ validate(dname, server, type, class, data, dlen
struct hashbuf *htp;
struct databuf *nsp[NSMAX];
int count;
char *fname;
const char *fname;
int exactmatch = 0;
struct fwdinfo *fwd;
@ -133,10 +137,8 @@ validate(dname, server, type, class, data, dlen
/* we were able to locate namebufs for this domain, or a parent domain,
* or ??? */
if (np == NULL) {
fname = (char *)malloc(1);
fname[0] = '\0';
}
if (np == NULL)
fname = "";
dprintf(5, (ddt,
"validate:namebuf found np:%#lx, d:\"%s\", f:\"%s\"\n",
(u_long)np, dname, fname));
@ -145,8 +147,6 @@ validate(dname, server, type, class, data, dlen
dnamep = np;
exactmatch = 1;
}
if (np == NULL && fname != NULL)
free((char *)fname);
switch (findns(&np, class, nsp, &count, 0)) {
case NXDOMAIN:
/** we are authoritative for this domain, lookup name
@ -216,12 +216,11 @@ validate(dname, server, type, class, data, dlen
return (INVALID);
case OK: /*proceed */
dprintf(5,
(ddt,
"validate:found ns records:calling check_addr_ns\n"));
dprintf(5, (ddt, "validate:found ns records\n"));
if (needs_prime_cache)
needs_prime_cache = 0;
if (check_addr_ns(nsp, server, dname)) {
if (samedomain(dname, qdomain) ||
check_addr_ns(nsp, server, dname)) {
#ifdef DATUMREFCNT
free_nsp(nsp);
#endif
@ -390,8 +389,8 @@ isvalid(np, type, class, data, dlen)
if (x != 0)
break;
td += (strlen(td) + 1);
tdp += (strlen(tdp) + 1);
tdp += (strlen((char *)tdp) + 1);
/* compare second string */
x = strncasecmp(td, (char *)tdp,
strlen((char *)td+1));
@ -436,9 +435,8 @@ check_addr_ns(nsp, server, dname)
struct in_addr *saddr = &(server->sin_addr);
struct databuf **nsdp;
dprintf(5, (ddt,
"check_addr_ns: s:[%s], db:0x%x, d:\"%s\"\n",
inet_ntoa(*saddr), nsp, dname));
dprintf(5, (ddt, "check_addr_ns: s:[%s], db:0x%lx, d:\"%s\"\n",
inet_ntoa(*saddr), (u_long)nsp, dname));
for(i = lastNA; i != firstNA; i = (i+1) % MAXNAMECACHE) {
if (!bcmp((char *)saddr,
@ -484,13 +482,13 @@ check_in_tables(nsp, server, syslogdname)
register struct namebuf *np;
register struct databuf *dp, *nsdp;
struct hashbuf *tmphtp;
char *dname, *fname;
const char *dname, *fname;
int class;
int qcomp();
dprintf(3, (ddt, "check_in_tables(nsp=x%x,qp=x%x,'%s')\n",
nsp, server, syslogdname));
dprintf(3, (ddt, "check_in_tables(nsp=x%lx, qp=x%x, '%s')\n",
(u_long)nsp, server, syslogdname));
while ((nsdp = *nsp++) != NULL) {
class = nsdp->d_class;
dname = (char *)nsdp->d_data;
@ -532,10 +530,10 @@ check_in_tables(nsp, server, syslogdname)
*************************************************************************/
void
store_name_addr(servername, serveraddr, syslogdname, sysloginfo)
char *servername;
const char *servername;
struct in_addr serveraddr;
char *syslogdname;
char *sysloginfo;
const char *syslogdname;
const char *sysloginfo;
{
int i;
@ -575,17 +573,13 @@ store_name_addr(servername, serveraddr, syslogdname, sysloginfo)
syslogdname);
#endif
free(nameaddrlist[i].nsname);
nameaddrlist[i].nsname =
(char *)malloc((unsigned)strlen(servername)+1);
strcpy(nameaddrlist[i].nsname, servername);
nameaddrlist[i].nsname = savestr(servername);
return;
}
}
/* we have to add this one to our cache */
nameaddrlist[firstNA].nsname =
(char *)malloc((unsigned)strlen(servername)+1);
strcpy(nameaddrlist[firstNA].nsname, servername);
nameaddrlist[firstNA].nsname = savestr(servername);
bcopy((char *)&serveraddr,
(char *)&(nameaddrlist[firstNA].ns_addr),
INADDRSZ);
@ -613,9 +607,10 @@ store_name_addr(servername, serveraddr, syslogdname, sysloginfo)
* delete/keep the record from the outgoing message.
*/
int
dovalidate(msg, msglen, rrp, zone, flags, server, VCode)
dovalidate(msg, msglen, rrp, zone, flags, qdomain, server, VCode)
u_char *msg, *rrp;
int msglen, zone, flags;
char *qdomain;
struct sockaddr_in *server;
int *VCode;
{
@ -783,7 +778,7 @@ dovalidate(msg, msglen, rrp, zone, flags, server, VCode)
return (-1);
}
*VCode = validate(dname, server, type, class,(char *)cp1, n
*VCode = validate(dname, qdomain, server, type, class,(char *)cp1, n
#ifdef NCACHE
,NOERROR
#endif
@ -821,12 +816,12 @@ stick_in_queue(dname, type, class, data)
if (validateQ == NULL) {
validateQ = (TO_Validate *)malloc(sizeof(TO_Validate));
if (!validateQ)
panic(errno, "malloc(validateQ)");
validateQ->type = type;
validateQ->class = class;
validateQ->dname = malloc((unsigned)strlen(dname)+1);
strcpy(validateQ->dname, dname);
validateQ->data = malloc((unsigned)strlen(data)+1);
strcpy(validateQ->data, data);
validateQ->dname = savestr(dname);
validateQ->data = savestr(data); /* XXX no \0 */
gettimeofday(&tp, &tzp);
validateQ->time = tp.tv_sec;
VQcount = 1;
@ -836,12 +831,12 @@ stick_in_queue(dname, type, class, data)
}
if (VQcount < MAXVQ) {
tempVQ =(TO_Validate *)malloc(sizeof(TO_Validate));
if (!tempVQ)
panic(errno, "malloc(tempVQ)");
tempVQ->type = type;
tempVQ->class = class;
tempVQ->dname = malloc((unsigned)strlen(dname)+1);
strcpy(tempVQ->dname, dname);
tempVQ->data = malloc((unsigned)strlen(data)+1);
strcpy(tempVQ->data, data);
tempVQ->dname = savestr(dname);
tempVQ->data = savestr(data); /* XXX no \0 */
gettimeofday(&tp,&tzp);
tempVQ->time = tp.tv_sec;
tempVQ->next = currentVQ->next;
@ -879,7 +874,8 @@ stick_in_queue(dname, type, class, data)
return;
}
#endif
#ifdef BAD_IDEA
/* removes any INVALID RR's from the msg being returned, updates msglen to
* reflect the new message length.
*/
@ -935,6 +931,8 @@ update_msg(msg, msglen, Vlist, c)
dprintf(2, (ddt, "update_msg: NEEDS updating:\n"));
RRlen = (int *)malloc((unsigned)c*sizeof(int));
if (!RRlen)
panic(errno, "malloc(RRlen)");
hp = (HEADER *)msg;
new_ancount = ancount = ntohs(hp->ancount);
new_nscount = nscount = ntohs(hp->nscount);
@ -945,7 +943,7 @@ update_msg(msg, msglen, Vlist, c)
/* skip the query section */
qlen = dn_expand(msg, eom, cp, qname, sizeof qname);
if (qlen <= 0) {
dprintf(2, (ddt, "dn_skipname() failed, bad record\n"));
dprintf(2, (ddt, "dn_expand() failed, bad record\n"));
goto badend;
}
cp +=qlen;
@ -1242,5 +1240,6 @@ update_msg(msg, msglen, Vlist, c)
free((char *)RRlen);
return (-1);
}
#endif /*BAD_IDEA*/
#endif /*VALIDATE*/

View File

@ -1,7 +1,7 @@
/* options.h - specify the conditionally-compiled features
* vix 28mar92 [moved out of the Makefile because they were getting too big]
*
* $Id: options.h,v 8.4 1995/06/29 09:25:56 vixie Exp $
* $Id: options.h,v 1.4 1995/08/20 21:19:08 peter Exp $
*/
/*
@ -95,7 +95,7 @@
#define DOTTED_SERIAL /* if you want to be able to specify dotted serial#s */
/*#define SENSIBLE_DOTS*//* if you want dotted serial#s to make numeric sense */
#define NCACHE /* negative caching (anant@isi.edu) */
/*#define VALIDATE*/ /* validation procedure (anant@isi.edu) (DO NOT USE!)*/
/*#define VALIDATE*/ /* validation procedure (anant@isi.edu) (BUGGY!)*/
/*#define SHORT_FNAMES*//* file names used in named-xfer need to be short */
#define RESOLVSORT /* allow sorting of addresses in gethostbyname (mpa) */
#define STUBS /* allow transfers of NS only for a zone (mpa) */
@ -105,7 +105,7 @@
#define SECURE_ZONES /* if you want to inhibit world access to zones (gns)*/
#define ROUND_ROBIN /* rotate databuf list after each access (mtr) */
#define ADDAUTH /* return NS and glue w/ authorative answers (mpa) */
/*#define RFC1535*/ /* use RFC 1535 default for "search" list (vix) */
#define RFC1535 /* use RFC 1535 default for "search" list (vix) */
#define GEN_AXFR /* distinct zones within each class */
#define DATUMREFCNT /* use reference counts on datums (mpa) */
#define LAME_DELEGATION /* lame delegations (original-del,reworked-bb&del)*/
@ -119,6 +119,7 @@
#define XSTATS /* extended statistics, syslogged periodically (bg) */
/*#define BIND_NOTIFY*/ /* experimental - do not enable in customer products */
/*#define LOC_RR*/ /* support for (draft) LOC record parsing (ckd) */
#define SORT_RESPONSE /* should we try to sort responses optimally? (vix) */
/*--------------------------------------------*
* no user-servicable parts beyond this point *

View File

@ -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 8.8 1995/06/29 09:25:56 vixie Exp $
* $Id: portability.h,v 1.3 1995/08/20 21:19:11 peter Exp $
*/
/*
@ -62,6 +62,7 @@
/* XXX: this file has become a hopeless morass, and will be redone someday. */
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/param.h>
#ifndef TIME_H_INCLUDED
@ -122,6 +123,7 @@
#ifdef NeXT
# define NEED_PUTENV
# define NEED_SETENV
# define inet_addr(a) __inet_addr(a)
#endif
#if defined(__sgi)
@ -133,6 +135,11 @@
# define BSD 43
#endif
#if defined(__osf__) && defined(__alpha)
# undef BSD
# define BSD 199103
#endif
#if defined(_AUX_SOURCE)
# define vfork fork
# define NEED_STRERROR
@ -319,7 +326,8 @@ extern int close(), setitimer(), recv(), sendto(), sigsetmask(),
#if !defined(bcopy) /* some machines have their own macros for this */
# if defined(USE_POSIX) || \
(defined(__STDC__) && !defined(sun) && !defined(sequent))
(defined(__STDC__) && !defined(sun) && !defined(sequent) \
&& !defined(M_UNIX))
/* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
* ideally we would change the code to use them and then
* define them in terms of bcopy et al if !defined(__STDC__)
@ -389,6 +397,14 @@ extern int bcmp();
# endif /*BSD*/
#endif
#if !defined(SIGUSR1) && !defined(SIGUSR2)
# define SIGUSR1 SIGEMT
# define SIGUSR2 SIGFPE
#endif
#if !defined(SIGCHLD)
# define SIGCHLD SIGCLD
#endif
#if !defined(ntohl) && !defined(htonl) && defined(BSD) && (BSD <= 43)
/* if these aren't null macros in netinet/in.h, extern them here. */
extern u_short htons(), ntohs();
@ -545,3 +561,7 @@ extern int putenv __P((char *));
#ifdef NEED_GETTIMEOFDAY
extern int gettimeofday __P((struct timeval *, struct _TIMEZONE *));
#endif
#if defined(SVR4) && defined(sun)
extern int gethostname __P((char *, size_t));
#endif

View File

@ -9,17 +9,19 @@ USAGE='echo \
PATH=%DESTSBIN%:/bin:/usr/bin:/usr/ucb:$PATH
PIDFILE=%PIDDIR%/named.pid
[ -f $PIDFILE ] || {
echo "$0: $PIDFILE does not exist"
exit 1
}
PID=`cat $PIDFILE`
PS=`%PS% $PID | tail -1 | grep $PID`
RUNNING=1
[ `echo $PS | wc -w` -ne 0 ] || {
PS="named (pid $PID?) not running"
if [ -f $PIDFILE ]
then
PID=`cat $PIDFILE`
PS=`%PS% $PID | tail -1 | grep $PID`
RUNNING=1
[ `echo $PS | wc -w` -ne 0 ] || {
PS="named (pid $PID?) not running"
RUNNING=0
}
else
PS="named (no pid file) not running"
RUNNING=0
}
fi
for ARG
do
@ -50,9 +52,13 @@ do
if [ -f /etc/sysconfig ]; then
. /etc/sysconfig
fi
rm -f $PIDFILE
# $namedflags is imported from /etc/sysconfig
if [ "X${namedflags}" != "XNO" ]; then
%INDOT%named ${namedflags} && echo Name Server Started
%INDOT%named ${namedflags} && {
sleep 5
echo Name Server Started
}
fi
;;
stop)
@ -62,6 +68,7 @@ do
}
kill $PID && {
sleep 5
rm -f $PIDFILE
echo Name Server Stopped
}
;;
@ -73,9 +80,13 @@ do
if [ -f /etc/sysconfig ]; then
. /etc/sysconfig
fi
rm -f $PIDFILE
# $namedflags is imported from /etc/sysconfig
if [ "X${namedflags}" != "XNO" ]; then
%INDOT%named ${namedflags} && echo Name Server Restarted
%INDOT%named ${namedflags} && {
sleep 5
echo Name Server Restarted
}
fi
;;
*) eval "$USAGE";;

View File

@ -10,7 +10,7 @@ BINDIR= /usr/libexec
MAN8= named-xfer.8
VER = 4.9.3-BETA26-LOCAL
VER = 4.9.3-REL
version.c: ${.CURDIR}/../Version.c ${.CURDIR}/Makefile ${SRCS}
(LC_TIME=; export LC_TIME; u=$${USER-root} d=`pwd |sed -e 's|/obj/|/src/|'` \

View File

@ -70,7 +70,7 @@ char copyright[] =
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)named-xfer.c 4.18 (Berkeley) 3/7/91";
static char rcsid[] = "$Id: named-xfer.c,v 1.3 1995/05/30 03:49:10 rgrimes Exp $";
static char rcsid[] = "$Id: named-xfer.c,v 1.4 1995/08/20 21:49:40 peter Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -97,7 +97,9 @@ static char rcsid[] = "$Id: named-xfer.c,v 1.3 1995/05/30 03:49:10 rgrimes Exp $
#include <resolv.h>
#include <stdio.h>
#include <syslog.h>
#include <math.h>
#if !defined(SVR4) || !defined(sun)
# include <math.h>
#endif
#include <ctype.h>
#include <signal.h>
@ -167,9 +169,9 @@ main(argc, argv)
closed += (close(fd) == 0);
#ifdef RENICE
nice (-40); /* this is the recommended procedure to */
nice (20); /* reset the priority of the current process */
nice (0); /* to "normal" (== 0) - see nice(3) */
nice(-40); /* this is the recommended procedure to */
nice(20); /* reset the priority of the current process */
nice(0); /* to "normal" (== 0) - see nice(3) */
#endif
#ifdef LOG_DAEMON
@ -195,7 +197,9 @@ main(argc, argv)
break;
case 'l':
ddtfile = (char *)malloc(strlen(optarg) +
sizeof(".XXXXXX") + 1);
sizeof(".XXXXXX") + 1);
if (!ddtfile)
panic(errno, "malloc(ddtfile)");
#ifdef SHORT_FNAMES
filenamecpy(ddtfile, optarg);
#else
@ -220,6 +224,8 @@ main(argc, argv)
dbfile = optarg;
tmpname = (char *)malloc((unsigned)strlen(optarg) +
sizeof(".XXXXXX") + 1);
if (!tmpname)
panic(errno, "malloc(tmpname)");
#ifdef SHORT_FNAMES
filenamecpy(tmpname, optarg);
#else
@ -399,6 +405,7 @@ main(argc, argv)
}
dprintf(1, (ddt, "addrcnt = %d\n", zp->z_addrcnt));
res_init();
_res.options &= ~(RES_DEFNAMES | RES_DNSRCH | RES_RECURSE);
result = getzone(zp, serial_no, port);
(void) my_fclose(dbfp);
@ -656,10 +663,13 @@ getzone(zp, serial_no, port)
goto tryagain;
}
#endif
syslog(LOG_INFO,
"%s from [%s], zone %s: rcode %d, aa %d, ancount %d, aucount %d\n",
"bad response to SOA query",
inet_ntoa(sin.sin_addr), zp->z_origin,
syslog(LOG_NOTICE,
"[%s] %s for %s, SOA 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 : ".",
hp->rcode, hp->aa, ancount, aucount);
error++;
(void) my_close(s);
@ -1110,7 +1120,7 @@ soa_zinfo(zp, cp, eom)
GETSHORT(class, cp);
GETLONG(ttl, cp);
cp += INT16SZ; /* dlen */
if (type != T_SOA || class != curclass || ttl == 0)
if (type != T_SOA || class != curclass)
return ("zinfo wrong typ/cla/ttl");
/* Skip master name and contact name, we can't validate them. */
if ((n = dn_skipname(cp, eom)) == -1)
@ -1403,7 +1413,7 @@ print_output(msg, msglen, rrp)
tab = 1;
}
if (ttl != 0 && ttl != minimum_ttl)
if (ttl != minimum_ttl)
(void) fprintf(dbfp, "%d\t", (int) ttl);
else if (tab)
(void) putc('\t', dbfp);