Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/dist/bind/bin/named Pull up revisions 1.12-1.13 (reques...
details: https://anonhg.NetBSD.org/src/rev/946560d4d036
branches: netbsd-1-6
changeset: 528144:946560d4d036
user: lukem <lukem%NetBSD.org@localhost>
date: Fri Jun 28 11:33:26 2002 +0000
description:
Pull up revisions 1.12-1.13 (requested by itojun in ticket #387):
Update to BIND 8.3.3. Fixes buffer overrun in resolver code.
diffstat:
dist/bind/bin/named/ns_main.c | 269 +++++++++++++++++++++++++++--------------
1 files changed, 176 insertions(+), 93 deletions(-)
diffs (truncated from 674 to 300 lines):
diff -r ab19c91d64c5 -r 946560d4d036 dist/bind/bin/named/ns_main.c
--- a/dist/bind/bin/named/ns_main.c Fri Jun 28 11:33:06 2002 +0000
+++ b/dist/bind/bin/named/ns_main.c Fri Jun 28 11:33:26 2002 +0000
@@ -1,8 +1,8 @@
-/* $NetBSD: ns_main.c,v 1.11 2001/08/24 13:25:57 mrg Exp $ */
+/* $NetBSD: ns_main.c,v 1.11.2.1 2002/06/28 11:33:26 lukem Exp $ */
#if !defined(lint) && !defined(SABER)
static const char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91";
-static const char rcsid[] = "Id: ns_main.c,v 8.145 2001/03/16 12:07:57 marka Exp";
+static const char rcsid[] = "Id: ns_main.c,v 8.160 2002/06/24 07:06:55 marka Exp";
#endif /* not lint */
/*
@@ -101,8 +101,10 @@
#ifdef SVR4 /* XXX */
# include <sys/sockio.h>
#else
+#ifndef __hpux
# include <sys/mbuf.h>
#endif
+#endif
#include <netinet/in.h>
#include <net/route.h>
@@ -176,7 +178,7 @@
static u_int16_t nsid_state2;
static int nsid_algorithm;
-static int needs = 0, needs_exit = 0;
+static int needs = 0, needs_exit = 0, needs_restart = 0;
static handler handlers[main_need_num];
static void savedg_waitfunc(evContext, void*, const void*);
static void need_waitfunc(evContext, void *, const void *);
@@ -242,7 +244,7 @@
/*ARGSUSED*/
int
-main(int argc, char *argv[], char *envp[]) {
+main(int argc, char *argv[]) {
int n;
char *p;
int ch;
@@ -283,7 +285,7 @@
case 'b':
case 'c':
if (conffile != NULL)
- freestr(conffile);
+ (void)freestr(conffile);
conffile = savestr(optarg, 1);
break;
@@ -311,14 +313,7 @@
break;
case 'w':
- if (chdir(optarg) < 0) {
- syslog(LOG_CRIT, bad_directory, optarg,
- strerror(errno));
- fprintf(stderr, bad_directory, optarg,
- strerror(errno));
- fputc('\n', stderr);
- exit(1);
- }
+ working_dir = savestr(optarg, 1);
break;
#ifdef QRYLOG
case 'q':
@@ -369,7 +364,7 @@
case 'g':
if (group_name != NULL)
- freestr(group_name);
+ (void)freestr(group_name);
group_name = savestr(optarg, 1);
if (only_digits(group_name))
group_id = atoi(group_name);
@@ -396,7 +391,7 @@
if (argc) {
if (conffile != NULL)
- freestr(conffile);
+ (void)freestr(conffile);
conffile = savestr(*argv, 1);
argc--, argv++;
}
@@ -433,10 +428,22 @@
}
#else
fprintf(stderr, "warning: chroot() not available\n");
- freestr(chroot_dir);
- chroot_dir = NULL;
+ chroot_dir = freestr(chroot_dir);
#endif
}
+ /*
+ * Set working directory.
+ */
+ if (working_dir != NULL) {
+ if (chdir(working_dir) < 0) {
+ syslog(LOG_CRIT, bad_directory, working_dir,
+ strerror(errno));
+ fprintf(stderr, bad_directory, working_dir,
+ strerror(errno));
+ fputc('\n', stderr);
+ exit(1);
+ }
+ }
/* Establish global event context. */
evCreate(&ev);
@@ -553,7 +560,10 @@
else
INSIST_ERR(errno == EINTR);
}
- ns_info(ns_log_default, "named shutting down");
+ if (needs_restart)
+ ns_info(ns_log_default, "named restarting");
+ else
+ ns_info(ns_log_default, "named shutting down");
#ifdef BIND_UPDATE
dynamic_about_to_exit();
#endif
@@ -566,25 +576,56 @@
else
shutdown_configuration();
- /* Cleanup for system-dependent stuff */
- custom_shutdown();
+ if (needs_restart)
+ execvp(saved_argv[0], saved_argv);
+ else
+ /* Cleanup for system-dependent stuff */
+ custom_shutdown();
return (0);
}
static int
-ns_socket(int domain, int type, int protocol) {
- int fd;
+sq_closeone(void) {
+ struct qstream *sp, *nextsp;
+ struct qstream *candidate = NULL;
+ time_t lasttime, maxctime = 0;
+ int result = 0;
+ gettime(&tt);
+
+ for (sp = streamq; sp; sp = nextsp) {
+ nextsp = sp->s_next;
+ if (sp->s_refcnt)
+ continue;
+ lasttime = tt.tv_sec - sp->s_time;
+ if (lasttime >= VQEXPIRY) {
+ sq_remove(sp);
+ result = 1;
+ } else if (lasttime > maxctime) {
+ candidate = sp;
+ maxctime = lasttime;
+ }
+ }
+ if (candidate) {
+ sq_remove(candidate);
+ result = 1;
+ }
+ return (result);
+}
+
+static int
+ns_socket(int domain, int type, int protocol) {
+ int fd, tmp;
+
+ again:
fd = socket(domain, type, protocol);
- if (fd == -1)
- return (-1);
#ifdef F_DUPFD /* XXX */
/*
* Leave a space for stdio to work in.
*/
if (fd >= 0 && fd <= 20) {
- int new, tmp;
+ int new;
if ((new = fcntl(fd, F_DUPFD, 20)) == -1)
ns_notice(ns_log_default, "fcntl(fd, F_DUPFD, 20): %s",
strerror(errno));
@@ -594,6 +635,11 @@
fd = new;
}
#endif
+ tmp = errno;
+ if (errno == EMFILE)
+ if (sq_closeone())
+ goto again;
+ errno = tmp;
return (fd);
}
@@ -610,13 +656,17 @@
interface *ifp = uap;
struct qstream *sp;
struct iovec iov;
- int len, n;
+ ISC_SOCKLEN_T len;
+ int n;
const int on = 1;
#ifdef IP_OPTIONS /* XXX */
u_char ip_opts[IP_OPT_BUF_SIZE];
#endif
const struct sockaddr_in *la, *ra;
+ UNUSED(lalen);
+ UNUSED(ralen);
+
la = (const struct sockaddr_in *)lav;
ra = (const struct sockaddr_in *)rav;
@@ -679,25 +729,7 @@
* eventlib which will call us right back.
*/
if (streamq) {
- struct qstream *nextsp;
- struct qstream *candidate = NULL;
- time_t lasttime, maxctime = 0;
-
- for (sp = streamq; sp; sp = nextsp) {
- nextsp = sp->s_next;
- if (sp->s_refcnt)
- continue;
- gettime(&tt);
- lasttime = tt.tv_sec - sp->s_time;
- if (lasttime >= VQEXPIRY)
- sq_remove(sp);
- else if (lasttime > maxctime) {
- candidate = sp;
- maxctime = lasttime;
- }
- }
- if (candidate)
- sq_remove(candidate);
+ (void)sq_closeone();
return;
}
/* fall through */
@@ -716,7 +748,7 @@
#ifndef CANNOT_SET_SNDBUF
if (setsockopt(rfd, SOL_SOCKET, SO_SNDBUF,
- (char*)&sbufsize, sizeof sbufsize) < 0) {
+ (const char*)&sbufsize, sizeof sbufsize) < 0) {
ns_info(ns_log_default, "setsockopt(rfd, SO_SNDBUF, %d): %s",
sbufsize, strerror(errno));
(void) close(rfd);
@@ -724,13 +756,21 @@
}
#endif
if (setsockopt(rfd, SOL_SOCKET, SO_KEEPALIVE,
- (char *)&on, sizeof on) < 0) {
+ (const char *)&on, sizeof on) < 0) {
ns_info(ns_log_default, "setsockopt(rfd, KEEPALIVE): %s",
strerror(errno));
(void) close(rfd);
return;
}
+#ifdef USE_FIONBIO_IOCTL
+ if (ioctl(ifp->dfd, FIONBIO, (char *) &on) == -1) {
+ ns_info(ns_log_default, "ioctl(rfd, FIONBIO): %s",
+ strerror(errno));
+ (void) close(rfd);
+ return;
+ }
+#else
if ((n = fcntl(rfd, F_GETFL, 0)) == -1) {
ns_info(ns_log_default, "fcntl(rfd, F_GETFL): %s",
strerror(errno));
@@ -743,6 +783,7 @@
(void) close(rfd);
return;
}
+#endif
/*
* We don't like IP options. Turn them off if the connection came in
@@ -798,19 +839,20 @@
struct qstream *sp;
struct sockaddr_in src;
int on = 1, n;
+ int fd;
ns_debug(ns_log_default, 1, "tcp_send");
- if ((sp = sq_add()) == NULL) {
+ if ((fd = ns_socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) == -1)
+ return (SERVFAIL);
+ if (fd > evHighestFD(ev)) {
+ close(fd);
return (SERVFAIL);
}
- if ((sp->s_rfd = ns_socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) == -1) {
Home |
Main Index |
Thread Index |
Old Index