summaryrefslogtreecommitdiffstats
path: root/contrib/bind/named/ns_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/named/ns_main.c')
-rw-r--r--contrib/bind/named/ns_main.c132
1 files changed, 76 insertions, 56 deletions
diff --git a/contrib/bind/named/ns_main.c b/contrib/bind/named/ns_main.c
index bac7d5a..6fff4cc 100644
--- a/contrib/bind/named/ns_main.c
+++ b/contrib/bind/named/ns_main.c
@@ -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 8.17 1996/08/05 08:31:30 vixie Exp $";
+static char rcsid[] = "$Id: ns_main.c,v 8.24 1996/11/26 10:11:22 vixie Exp $";
#endif /* not lint */
/*
@@ -173,13 +173,6 @@ main(argc, argv, envp)
int rfd, size, len;
time_t lasttime, maxctime;
u_char buf[BUFSIZ];
-#ifdef POSIX_SIGNALS
- struct sigaction sact;
-#else
-#ifndef SYSV
- struct sigvec vec;
-#endif
-#endif
#ifdef NeXT
int old_sigmask;
#endif
@@ -196,6 +189,9 @@ main(argc, argv, envp)
#ifdef IP_OPTIONS
u_char ip_opts[50]; /* arbitrary size */
#endif
+#ifdef RLIMIT_NOFILE
+ struct rlimit rl;
+#endif
local_ns_port = ns_port = htons(NAMESERVER_PORT);
@@ -304,7 +300,10 @@ main(argc, argv, envp)
n = 0;
#if defined(DEBUG) && defined(LOG_PERROR)
if (debug)
- n = LOG_PERROR;
+ n |= LOG_PERROR;
+#endif
+#ifdef LOG_NOWAIT
+ n |= LOG_NOWAIT;
#endif
#ifdef LOG_DAEMON
openlog("named", LOG_PID|LOG_CONS|LOG_NDELAY|n, LOGFAC);
@@ -312,6 +311,14 @@ main(argc, argv, envp)
openlog("named", LOG_PID);
#endif
+#ifdef RLIMIT_NOFILE
+ rl.rlim_cur = rl.rlim_max = FD_SETSIZE;
+ if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
+ syslog(LOG_ERR, "setrlimit(RLIMIT_FSIZE,FD_SETSIZE): %m");
+#endif
+ /* check that udp checksums are on */
+ ns_udp();
+
#ifdef WANT_PIDFILE
/* tuck my process id away */
#ifdef PID_FIX
@@ -344,10 +351,21 @@ main(argc, argv, envp)
** Open stream port.
*/
for (n = 0; ; n++) {
+ int fd;
if ((vs = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
syslog(LOG_ERR, "socket(SOCK_STREAM): %m");
exit(1);
}
+#ifdef F_DUPFD
+ /*
+ * leave a space for stdio to work in
+ */
+ if ((fd = fcntl(vs, F_DUPFD, 20)) != -1) {
+ close(vs);
+ vs = fd;
+ } else
+ syslog(LOG_NOTICE, "fcntl(vs, F_DUPFD, 20): %m");
+#endif
if (setsockopt(vs, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
sizeof(on)) != 0)
{
@@ -395,6 +413,7 @@ main(argc, argv, envp)
setsignal(SIGIOT, -1, setstatsflg);
setsignal(SIGUSR1, -1, setIncrDbgFlg);
setsignal(SIGUSR2, -1, setNoDbgFlg);
+ setsignal(SIGHUP, -1, onhup);
#if defined(SIGWINCH) && defined(QRYLOG)
setsignal(SIGWINCH, -1, setQrylogFlg);
@@ -427,7 +446,6 @@ main(argc, argv, envp)
setsignal(SIGALRM, SIGCHLD, maint_alarm);
setsignal(SIGCHLD, SIGALRM, reapchild);
setsignal(SIGPIPE, -1, (SIG_FN (*)())SIG_IGN);
- setsignal(SIGHUP, -1, onhup);
#if defined(SIGXFSZ)
/* Wierd DEC Hesiodism, harmless. */
@@ -438,12 +456,6 @@ main(argc, argv, envp)
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 */
- setsignal(SIGTERM, -1, onintr);
-#endif
-
#ifdef XSTATS
/* Catch SIGTERM so we can write stats before exiting. */
setsignal(SIGTERM, -1, onintr);
@@ -562,22 +574,6 @@ main(argc, argv, envp)
ddt = 0;
}
#endif
-#ifdef ALLOW_UPDATES
- if (needToExit) {
- struct zoneinfo *zp;
- sigblock(~0); /*
- * Block all blockable signals
- * to ensure a consistant
- * state during final dump
- */
- dprintf(1, (ddt, "Received shutdown signal\n"));
- for (zp = zones; zp < &zones[nzones]; zp++) {
- if (zp->z_flags & Z_CHANGED)
- zonedump(zp);
- }
- exit(0);
- }
-#endif /* ALLOW_UPDATES */
#ifdef XSTATS
if (needToExit) {
ns_logstats();
@@ -675,6 +671,8 @@ main(argc, argv, envp)
ntohs(from_addr.sin_port),
dqp->dq_dfd, n,
ctimel(tt.tv_sec)));
+ if (n < HFIXEDSZ)
+ break;
#ifdef DEBUG
if (debug >= 10)
fp_nquery(buf, n, ddt);
@@ -790,10 +788,12 @@ main(argc, argv, envp)
sp->s_bufp = (u_char *)&sp->s_tempsize;
FD_SET(rfd, &mask);
FD_SET(rfd, &tmpmask);
- dprintf(1, (ddt,
- "\nTCP connection from [%s].%d (fd %d)\n",
- inet_ntoa(sp->s_from.sin_addr),
- ntohs(sp->s_from.sin_port), rfd));
+#ifdef DEBUG
+ if (debug)
+ syslog(LOG_DEBUG,
+ "IP/TCP connection from %s (fd %d)\n",
+ sin_ntoa(&sp->s_from), rfd);
+#endif
}
if (streamq)
dprintf(3, (ddt, "streamq = 0x%lx\n",
@@ -871,8 +871,8 @@ main(argc, argv, envp)
* if we have a query id, then we will send an
* error back to the user.
*/
- if (sp->s_bufsize == 0 &&
- (sp->s_bufp - sp->s_buf > INT16SZ)) {
+ if (sp->s_bufsize == 0) {
+ if (sp->s_bufp - sp->s_buf > INT16SZ) {
HEADER *hp;
hp = (HEADER *)sp->s_buf;
@@ -885,7 +885,30 @@ main(argc, argv, envp)
hp->rcode = SERVFAIL;
(void) writemsg(sp->s_rfd, sp->s_buf,
HFIXEDSZ);
- continue;
+ }
+ continue;
+ }
+ /*
+ * If the message is too short to contain a valid
+ * header, try to send back an error, and drop the
+ * message.
+ */
+ if (sp->s_bufp - sp->s_buf < HFIXEDSZ) {
+ if (sp->s_bufp - sp->s_buf > INT16SZ) {
+ HEADER *hp;
+
+ hp = (HEADER *)sp->s_buf;
+ hp->qr = 1;
+ hp->ra = (NoRecurse == 0);
+ hp->ancount = 0;
+ hp->qdcount = 0;
+ hp->nscount = 0;
+ hp->arcount = 0;
+ hp->rcode = SERVFAIL;
+ (void) writemsg(sp->s_rfd, sp->s_buf,
+ HFIXEDSZ);
+ }
+ continue;
}
if ((n == -1) && (errno == PORT_WOULDBLK))
continue;
@@ -937,7 +960,9 @@ getnetconf()
exit(1);
}
ntp = NULL;
-#if defined(AF_LINK) && !defined(RISCOS_BSD) && !defined(M_UNIX)
+#if defined(AF_LINK) && \
+ !defined(RISCOS_BSD) && !defined(M_UNIX) && \
+ !defined(sgi) && !defined(sun) && !defined(NO_SA_LEN)
#define my_max(a, b) (a > b ? a : b)
#define my_size(p) my_max((p).sa_len, sizeof(p))
#else
@@ -1168,6 +1193,7 @@ opensocket(dqp)
{
int m, n;
int on = 1;
+ int fd;
/*
* Open datagram sockets bound to interface address.
@@ -1176,6 +1202,16 @@ opensocket(dqp)
syslog(LOG_ERR, "socket(SOCK_DGRAM): %m - exiting");
exit(1);
}
+#ifdef F_DUPFD
+ /*
+ * leave a space for stdio to work in
+ */
+ if ((fd = fcntl(dqp->dq_dfd, F_DUPFD, 20)) != -1) {
+ close(dqp->dq_dfd);
+ dqp->dq_dfd = fd;
+ } else
+ syslog(LOG_NOTICE, "fcntl(dfd, F_DUPFD, 20): %m");
+#endif
dprintf(1, (ddt, "dqp->dq_addr %s d_dfd %d\n",
inet_ntoa(dqp->dq_addr), dqp->dq_dfd));
if (setsockopt(dqp->dq_dfd, SOL_SOCKET, SO_REUSEADDR,
@@ -1252,22 +1288,6 @@ maint_alarm()
}
-#ifdef ALLOW_UPDATES
-/*
- * Signal handler to schedule shutdown. Just set flag, to ensure a consistent
- * state during dump.
- */
-static SIG_FN
-onintr()
-{
- int save_errno = errno;
-
- resignal(SIGTERM, -1, onintr);
- needToExit = 1;
- errno = save_errno;
-}
-#endif /* ALLOW_UPDATES */
-
#ifdef XSTATS
/*
* Signal handler to write log information
OpenPOWER on IntegriCloud