summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/faithd/faithd.c66
-rw-r--r--usr.sbin/faithd/faithd.h6
-rw-r--r--usr.sbin/faithd/ftp.c189
-rw-r--r--usr.sbin/faithd/prefix.c8
-rw-r--r--usr.sbin/faithd/rsh.c25
-rw-r--r--usr.sbin/faithd/tcp.c15
6 files changed, 197 insertions, 112 deletions
diff --git a/usr.sbin/faithd/faithd.c b/usr.sbin/faithd/faithd.c
index 5ecec25c634..b37fb32f108 100644
--- a/usr.sbin/faithd/faithd.c
+++ b/usr.sbin/faithd/faithd.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: faithd.c,v 1.12 2001/05/01 07:40:04 itojun Exp $ */
-/* $KAME: faithd.c,v 1.39 2001/04/25 11:20:42 itojun Exp $ */
+/* $OpenBSD: faithd.c,v 1.13 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: faithd.c,v 1.40 2001/07/02 14:36:48 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -97,7 +97,7 @@ struct myaddrs {
struct sockaddr *addr;
};
struct myaddrs *myaddrs = NULL;
-static char *service;
+static const char *service;
#ifdef USE_ROUTE
static int sockfd = 0;
#endif
@@ -184,19 +184,19 @@ inetd_main(int argc, char **argv)
sockfd = socket(PF_ROUTE, SOCK_RAW, PF_UNSPEC);
if (sockfd < 0) {
- exit_failure("socket(PF_ROUTE): %s", ERRSTR);
+ exit_failure("socket(PF_ROUTE): %s", strerror(errno));
/*NOTREACHED*/
}
#endif
melen = sizeof(me);
if (getsockname(STDIN_FILENO, (struct sockaddr *)&me, &melen) < 0) {
- exit_failure("getsockname: %s", ERRSTR);
+ exit_failure("getsockname: %s", strerror(errno));
/*NOTREACHED*/
}
fromlen = sizeof(from);
if (getpeername(STDIN_FILENO, (struct sockaddr *)&from, &fromlen) < 0) {
- exit_failure("getpeername: %s", ERRSTR);
+ exit_failure("getpeername: %s", strerror(errno));
/*NOTREACHED*/
}
if (getnameinfo((struct sockaddr *)&me, melen, NULL, 0,
@@ -224,7 +224,7 @@ inetd_main(int argc, char **argv)
error = setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &on,
sizeof(on));
if (error < 0) {
- exit_failure("setsockopt(SO_OOBINLINE): %s", ERRSTR);
+ exit_failure("setsockopt(SO_OOBINLINE): %s", strerror(errno));
/*NOTREACHED*/
}
@@ -336,13 +336,14 @@ daemon_main(int argc, char **argv)
s_wld = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s_wld == -1)
- exit_stderr("socket: %s", ERRSTR);
+ exit_stderr("socket: %s", strerror(errno));
#ifdef IPV6_FAITH
if (res->ai_family == AF_INET6) {
error = setsockopt(s_wld, IPPROTO_IPV6, IPV6_FAITH, &on, sizeof(on));
if (error == -1)
- exit_stderr("setsockopt(IPV6_FAITH): %s", ERRSTR);
+ exit_stderr("setsockopt(IPV6_FAITH): %s",
+ strerror(errno));
}
#endif
#ifdef FAITH4
@@ -350,31 +351,32 @@ daemon_main(int argc, char **argv)
if (res->ai_family == AF_INET) {
error = setsockopt(s_wld, IPPROTO_IP, IP_FAITH, &on, sizeof(on));
if (error == -1)
- exit_stderr("setsockopt(IP_FAITH): %s", ERRSTR);
+ exit_stderr("setsockopt(IP_FAITH): %s",
+ strerror(errno));
}
#endif
#endif /* FAITH4 */
error = setsockopt(s_wld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (error == -1)
- exit_stderr("setsockopt(SO_REUSEADDR): %s", ERRSTR);
+ exit_stderr("setsockopt(SO_REUSEADDR): %s", strerror(errno));
error = setsockopt(s_wld, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on));
if (error == -1)
- exit_stderr("setsockopt(SO_OOBINLINE): %s", ERRSTR);
+ exit_stderr("setsockopt(SO_OOBINLINE): %s", strerror(errno));
error = bind(s_wld, (struct sockaddr *)res->ai_addr, res->ai_addrlen);
if (error == -1)
- exit_stderr("bind: %s", ERRSTR);
+ exit_stderr("bind: %s", strerror(errno));
error = listen(s_wld, 5);
if (error == -1)
- exit_stderr("listen: %s", ERRSTR);
+ exit_stderr("listen: %s", strerror(errno));
#ifdef USE_ROUTE
sockfd = socket(PF_ROUTE, SOCK_RAW, PF_UNSPEC);
if (sockfd < 0) {
- exit_stderr("socket(PF_ROUTE): %s", ERRSTR);
+ exit_stderr("socket(PF_ROUTE): %s", strerror(errno));
/*NOTREACHED*/
}
#endif
@@ -426,7 +428,7 @@ again:
if (error < 0) {
if (errno == EINTR)
goto again;
- exit_failure("select: %s", ERRSTR);
+ exit_failure("select: %s", strerror(errno));
/*NOTREACHED*/
}
@@ -440,7 +442,7 @@ again:
s_src = accept(s_wld, (struct sockaddr *)&srcaddr,
&len);
if (s_src == -1) {
- exit_failure("socket: %s", ERRSTR);
+ exit_failure("socket: %s", strerror(errno));
/*NOTREACHED*/
}
@@ -487,7 +489,7 @@ play_child(int s_src, struct sockaddr *srcaddr)
error = getsockname(s_src, (struct sockaddr *)&dstaddr6, &len);
if (error == -1) {
- exit_failure("getsockname: %s", ERRSTR);
+ exit_failure("getsockname: %s", strerror(errno));
/*NOTREACHED*/
}
@@ -508,7 +510,8 @@ play_child(int s_src, struct sockaddr *srcaddr)
dup2(0, 2);
}
execv(serverpath, serverarg);
- syslog(LOG_ERR, "execv %s: %s", serverpath, ERRSTR);
+ syslog(LOG_ERR, "execv %s: %s", serverpath,
+ strerror(errno));
_exit(EXIT_FAILURE);
} else {
close(s_src);
@@ -586,38 +589,38 @@ play_child(int s_src, struct sockaddr *srcaddr)
break;
}
if (s_dst < 0) {
- exit_failure("socket: %s", ERRSTR);
+ exit_failure("socket: %s", strerror(errno));
/*NOTREACHED*/
}
if (conf->src.a.ss_family) {
- if (bind(s_dst, (struct sockaddr *)&conf->src.a,
+ if (bind(s_dst, (const struct sockaddr *)&conf->src.a,
conf->src.a.ss_len) < 0) {
- exit_failure("bind: %s", ERRSTR);
+ exit_failure("bind: %s", strerror(errno));
/*NOTREACHED*/
}
}
error = setsockopt(s_dst, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on));
if (error < 0) {
- exit_failure("setsockopt(SO_OOBINLINE): %s", ERRSTR);
+ exit_failure("setsockopt(SO_OOBINLINE): %s", strerror(errno));
/*NOTREACHED*/
}
error = setsockopt(s_src, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
if (error < 0) {
- exit_failure("setsockopt(SO_SNDTIMEO): %s", ERRSTR);
+ exit_failure("setsockopt(SO_SNDTIMEO): %s", strerror(errno));
/*NOTREACHED*/
}
error = setsockopt(s_dst, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
if (error < 0) {
- exit_failure("setsockopt(SO_SNDTIMEO): %s", ERRSTR);
+ exit_failure("setsockopt(SO_SNDTIMEO): %s", strerror(errno));
/*NOTREACHED*/
}
error = connect(s_dst, sa4, sa4->sa_len);
if (error < 0) {
- exit_failure("connect: %s", ERRSTR);
+ exit_failure("connect: %s", strerror(errno));
/*NOTREACHED*/
}
@@ -660,7 +663,7 @@ faith_prefix(struct sockaddr *dst)
mib[3] = IPV6CTL_FAITH_PREFIX;
size = sizeof(struct in6_addr);
if (sysctl(mib, 4, &faith_prefix, &size, NULL, 0) < 0) {
- exit_failure("sysctl: %s", ERRSTR);
+ exit_failure("sysctl: %s", strerror(errno));
/*NOTREACHED*/
}
@@ -756,7 +759,8 @@ map4to6(struct sockaddr_in *dst4, struct sockaddr_in6 *dst6)
hints.ai_protocol = 0;
if ((ai_errno = getaddrinfo(host, serv, &hints, &res)) != 0) {
- syslog(LOG_INFO, "%s %s: %s", host, serv, gai_strerror(ai_errno));
+ syslog(LOG_INFO, "%s %s: %s", host, serv,
+ gai_strerror(ai_errno));
return 0;
}
@@ -794,7 +798,7 @@ start_daemon(void)
#endif
if (daemon(0, 0) == -1)
- exit_stderr("daemon: %s", ERRSTR);
+ exit_stderr("daemon: %s", strerror(errno));
#ifdef SA_NOCLDWAIT
memset(&sa, 0, sizeof(sa));
@@ -804,13 +808,13 @@ start_daemon(void)
sigaction(SIGCHLD, &sa, (struct sigaction *)0);
#else
if (signal(SIGCHLD, sig_child) == SIG_ERR) {
- exit_failure("signal CHLD: %s", ERRSTR);
+ exit_failure("signal CHLD: %s", strerror(errno));
/*NOTREACHED*/
}
#endif
if (signal(SIGTERM, sig_terminate) == SIG_ERR) {
- exit_failure("signal TERM: %s", ERRSTR);
+ exit_failure("signal TERM: %s", strerror(errno));
/*NOTREACHED*/
}
}
diff --git a/usr.sbin/faithd/faithd.h b/usr.sbin/faithd/faithd.h
index 1da3bf3cbc4..cf0521cdba5 100644
--- a/usr.sbin/faithd/faithd.h
+++ b/usr.sbin/faithd/faithd.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: faithd.h,v 1.5 2000/10/06 02:46:59 itojun Exp $ */
-/* $KAME: faithd.h,v 1.6 2000/10/05 22:20:37 itojun Exp $ */
+/* $OpenBSD: faithd.h,v 1.6 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: faithd.h,v 1.7 2001/07/02 14:36:48 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -68,6 +68,4 @@ extern void exit_failure __P((const char *, ...))
#define UC(b) (((int)b)&0xff)
-#define ERRSTR strerror(errno)
-
#define FAITH_TIMEOUT (30 * 60) /*second*/
diff --git a/usr.sbin/faithd/ftp.c b/usr.sbin/faithd/ftp.c
index b02bae41a0a..b5b6b0ea341 100644
--- a/usr.sbin/faithd/ftp.c
+++ b/usr.sbin/faithd/ftp.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ftp.c,v 1.4 2000/09/16 10:33:45 itojun Exp $ */
-/* $KAME: ftp.c,v 1.10 2000/09/14 00:23:39 itojun Exp $ */
+/* $OpenBSD: ftp.c,v 1.5 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: ftp.c,v 1.13 2001/09/05 01:10:30 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -84,25 +84,39 @@ ftp_relay(int ctl6, int ctl4)
syslog(LOG_INFO, "starting ftp control connection");
for (;;) {
+ int maxfd = 0;
+
FD_ZERO(&readfds);
FD_SET(ctl4, &readfds);
FD_SET(ctl6, &readfds);
- if (0 <= port4)
+ if (0 <= port4) {
FD_SET(port4, &readfds);
- if (0 <= port6)
+ if (port4 > maxfd)
+ maxfd = port4;
+ }
+ if (0 <= port6) {
FD_SET(port6, &readfds);
+ if (port6 > maxfd)
+ maxfd = port6;
+ }
#if 0
- if (0 <= wport4)
+ if (0 <= wport4) {
FD_SET(wport4, &readfds);
- if (0 <= wport6)
+ if (wport4 > maxfd)
+ maxfd = wport4;
+ }
+ if (0 <= wport6) {
FD_SET(wport6, &readfds);
+ if (wport6 > maxfd)
+ maxfd = wport6;
+ }
#endif
tv.tv_sec = FAITH_TIMEOUT;
tv.tv_usec = 0;
- error = select(256, &readfds, NULL, NULL, &tv);
+ error = select(maxfd + 1, &readfds, NULL, NULL, &tv);
if (error == -1)
- exit_failure("select: %s", ERRSTR);
+ exit_failure("select: %s", strerror(errno));
else if (error == 0)
exit_failure("connection timeout");
@@ -207,7 +221,7 @@ ftp_relay(int ctl6, int ctl4)
}
bad:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
}
static int
@@ -337,7 +351,7 @@ ftp_copy(int src, int dst)
}
bad:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
/*NOTREACHED*/
return 0; /* to make gcc happy */
}
@@ -349,6 +363,8 @@ ftp_copyresult(int src, int dst, enum state state)
int n;
char *param;
int code;
+ char *a, *p;
+ int i;
/* OOB data handling */
error = ioctl(src, SIOCATMARK, &atmark);
@@ -374,10 +390,6 @@ ftp_copyresult(int src, int dst, enum state state)
/*
* parse argument
*/
- {
- char *p;
- int i;
-
p = rbuf;
for (i = 0; i < 3; i++) {
if (!isdigit(*p)) {
@@ -399,7 +411,6 @@ ftp_copyresult(int src, int dst, enum state state)
param++;
if (!*param)
param = NULL;
- }
switch (state) {
case NONE:
@@ -407,16 +418,17 @@ ftp_copyresult(int src, int dst, enum state state)
if (ftp_activeconn() < 0) {
n = snprintf(rbuf, sizeof(rbuf),
"425 Cannot open data connetion\r\n");
+ if (n < 0 || n >= sizeof(rbuf))
+ n = 0;
}
}
- write(dst, rbuf, n);
+ if (n)
+ write(dst, rbuf, n);
return n;
case LPRT:
case EPRT:
/* expecting "200 PORT command successful." */
if (code == 200) {
- char *p;
-
p = strstr(rbuf, "PORT");
if (p) {
p[0] = (state == LPRT) ? 'L' : 'E';
@@ -432,8 +444,6 @@ ftp_copyresult(int src, int dst, enum state state)
case PORT:
/* expecting "200 EPRT command successful." */
if (code == 200) {
- char *p;
-
p = strstr(rbuf, "EPRT");
if (p) {
p[0] = 'P';
@@ -465,7 +475,6 @@ passivefail0:
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
u_short port;
- char *p;
/*
* PASV result -> LPSV/EPSV result
@@ -504,7 +513,9 @@ passivefail0:
passivefail:
n = snprintf(sbuf, sizeof(sbuf),
"500 could not translate from PASV\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ if (n)
+ write(src, sbuf, n);
return n;
}
#ifdef IPV6_FAITH
@@ -513,7 +524,7 @@ passivefail:
error = setsockopt(wport6, IPPROTO_IPV6, IPV6_FAITH,
&on, sizeof(on));
if (error == -1)
- exit_failure("setsockopt(IPV6_FAITH): %s", ERRSTR);
+ exit_failure("setsockopt(IPV6_FAITH): %s", strerror(errno));
}
#endif
error = bind(wport6, (struct sockaddr *)sin6, sin6->sin6_len);
@@ -554,8 +565,6 @@ passivefail:
sin6->sin6_port = port;
if (state == LPSV) {
- char *a, *p;
-
a = (char *)&sin6->sin6_addr;
p = (char *)&sin6->sin6_port;
n = snprintf(sbuf, sizeof(sbuf),
@@ -565,14 +574,20 @@ passivefail:
UC(a[8]), UC(a[9]), UC(a[10]), UC(a[11]),
UC(a[12]), UC(a[13]), UC(a[14]), UC(a[15]),
2, UC(p[0]), UC(p[1]));
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
passivemode = 1;
return n;
} else {
n = snprintf(sbuf, sizeof(sbuf),
"229 Entering Extended Passive Mode (|||%d|)\r\n",
ntohs(sin6->sin6_port));
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
passivemode = 1;
return n;
}
@@ -590,7 +605,6 @@ passivefail1:
{
u_short port;
- char *p;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
@@ -625,7 +639,10 @@ passivefail1:
passivefail2:
n = snprintf(sbuf, sizeof(sbuf),
"500 could not translate from EPSV\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
#ifdef IP_FAITH
@@ -634,7 +651,7 @@ passivefail2:
error = setsockopt(wport6, IPPROTO_IP, IP_FAITH,
&on, sizeof(on));
if (error == -1)
- exit_error("setsockopt(IP_FAITH): %s", ERRSTR);
+ exit_error("setsockopt(IP_FAITH): %s", strerror(errno));
}
#endif
error = bind(wport6, (struct sockaddr *)sin, sin->sin_len);
@@ -683,7 +700,10 @@ passivefail2:
"227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n",
UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
UC(p[0]), UC(p[1]));
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
passivemode = 1;
return n;
}
@@ -692,7 +712,7 @@ passivefail2:
}
bad:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
/*NOTREACHED*/
return 0; /* to make gcc happy */
}
@@ -703,12 +723,13 @@ ftp_copycommand(int src, int dst, enum state *state)
int error, atmark;
int n;
unsigned int af, hal, ho[16], pal, po[2];
- char *a, *p;
+ char *a, *p, *q;
char cmd[5], *param;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
enum state nstate;
char ch;
+ int i;
/* OOB data handling */
error = ioctl(src, SIOCATMARK, &atmark);
@@ -739,10 +760,6 @@ ftp_copycommand(int src, int dst, enum state *state)
/*
* parse argument
*/
- {
- char *p, *q;
- int i;
-
p = rbuf;
q = cmd;
for (i = 0; i < 4; i++) {
@@ -766,7 +783,6 @@ ftp_copycommand(int src, int dst, enum state *state)
param++;
if (!*param)
param = NULL;
- }
*state = NONE;
@@ -785,7 +801,10 @@ ftp_copycommand(int src, int dst, enum state *state)
if (epsvall) {
n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
cmd);
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
@@ -799,7 +818,10 @@ ftp_copycommand(int src, int dst, enum state *state)
if (n != 21 || af != 6 || hal != 16|| pal != 2) {
n = snprintf(sbuf, sizeof(sbuf),
"501 illegal parameter to LPRT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
@@ -820,7 +842,10 @@ sendport:
lprtfail:
n = snprintf(sbuf, sizeof(sbuf),
"500 could not translate to PORT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
if (((struct sockaddr *)&data4)->sa_family != AF_INET)
@@ -862,7 +887,10 @@ lprtfail:
n = snprintf(sbuf, sizeof(sbuf), "PORT %d,%d,%d,%d,%d,%d\r\n",
UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
UC(p[0]), UC(p[1]));
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
*state = nstate;
passivemode = 0;
return n;
@@ -884,7 +912,10 @@ lprtfail:
if (epsvall) {
n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
cmd);
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
@@ -897,7 +928,10 @@ lprtfail:
eprtparamfail:
n = snprintf(sbuf, sizeof(sbuf),
"501 illegal parameter to EPRT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
*p++ = '\0';
@@ -918,7 +952,10 @@ eprtparamfail:
if (n != 1 || af != 2) {
n = snprintf(sbuf, sizeof(sbuf),
"501 unsupported address family to EPRT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
memset(&hints, 0, sizeof(hints));
@@ -928,13 +965,19 @@ eprtparamfail:
if (error) {
n = snprintf(sbuf, sizeof(sbuf),
"501 EPRT: %s\r\n", gai_strerror(error));
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
if (res->ai_next) {
n = snprintf(sbuf, sizeof(sbuf),
"501 EPRT: %s resolved to multiple addresses\r\n", hostp);
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
@@ -956,13 +999,19 @@ eprtparamfail:
if (epsvall) {
n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n",
cmd);
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
/* transmit PASV */
n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n");
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
*state = LPSV;
passivemode = 0; /* to be set to 1 later */
return n;
@@ -977,7 +1026,10 @@ eprtparamfail:
wport4 = wport6 = port4 = port6 = -1;
n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n");
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
*state = EPSV;
passivemode = 0; /* to be set to 1 later */
return n;
@@ -988,7 +1040,10 @@ eprtparamfail:
*/
epsvall = 1;
n = snprintf(sbuf, sizeof(sbuf), "200 EPSV ALL command successful.\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
#ifdef FAITH4
} else if (strcmp(cmd, "PORT") == 0 && param) {
@@ -1011,7 +1066,10 @@ eprtparamfail:
if (n != 6) {
n = snprintf(sbuf, sizeof(sbuf),
"501 illegal parameter to PORT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
@@ -1031,7 +1089,10 @@ eprtparamfail:
portfail:
n = snprintf(sbuf, sizeof(sbuf),
"500 could not translate to EPRT\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
}
if (((struct sockaddr *)&data4)->sa_family != AF_INET6)
@@ -1072,7 +1133,10 @@ portfail:
goto portfail;
}
n = snprintf(sbuf, sizeof(sbuf), "EPRT |%d|%s|%s|\r\n", af, host, serv);
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
*state = nstate;
passivemode = 0;
return n;
@@ -1091,7 +1155,10 @@ portfail:
/* transmit EPSV */
n = snprintf(sbuf, sizeof(sbuf), "EPSV\r\n");
- write(dst, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(dst, sbuf, n);
*state = PASV;
passivemode = 0; /* to be set to 1 later */
return n;
@@ -1101,7 +1168,10 @@ portfail:
* reject PORT/PASV
*/
n = snprintf(sbuf, sizeof(sbuf), "502 %s not implemented.\r\n", cmd);
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
return n;
#endif /* FAITH4 */
} else if (passivemode
@@ -1118,7 +1188,10 @@ portfail:
if (ftp_passiveconn() < 0) {
n = snprintf(sbuf, sizeof(sbuf), "425 Cannot open data connetion\r\n");
- write(src, sbuf, n);
+ if (n < 0 || n >= sizeof(sbuf))
+ n = 0;
+ if (n)
+ write(src, sbuf, n);
} else {
/* simply relay the command */
write(dst, rbuf, n);
@@ -1134,7 +1207,7 @@ portfail:
}
bad:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
/*NOTREACHED*/
return 0; /* to make gcc happy */
}
diff --git a/usr.sbin/faithd/prefix.c b/usr.sbin/faithd/prefix.c
index 4c124f54845..50da30aec83 100644
--- a/usr.sbin/faithd/prefix.c
+++ b/usr.sbin/faithd/prefix.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: prefix.c,v 1.1 2001/02/15 17:37:33 itojun Exp $ */
-/* $KAME: prefix.c,v 1.8 2000/11/24 06:16:56 itojun Exp $ */
+/* $OpenBSD: prefix.c,v 1.2 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: prefix.c,v 1.9 2001/07/02 14:36:49 itojun Exp $ */
/*
* Copyright (C) 2000 WIDE Project.
@@ -136,8 +136,8 @@ prefix_string(prefix)
static char buf[NI_MAXHOST + 20];
char hbuf[NI_MAXHOST];
- if (getnameinfo((struct sockaddr *)&prefix->a, prefix->a.ss_len, hbuf,
- sizeof(hbuf), NULL, 0, niflags))
+ if (getnameinfo((const struct sockaddr *)&prefix->a, prefix->a.ss_len,
+ hbuf, sizeof(hbuf), NULL, 0, niflags))
return NULL;
snprintf(buf, sizeof(buf), "%s/%d", hbuf, prefix->l);
return buf;
diff --git a/usr.sbin/faithd/rsh.c b/usr.sbin/faithd/rsh.c
index d7cdc1282e2..0d3faa8bb19 100644
--- a/usr.sbin/faithd/rsh.c
+++ b/usr.sbin/faithd/rsh.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: rsh.c,v 1.4 2001/02/15 17:37:33 itojun Exp $ */
-/* $KAME: rsh.c,v 1.5 2001/02/15 17:28:04 itojun Exp $ */
+/* $OpenBSD: rsh.c,v 1.5 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: rsh.c,v 1.7 2001/09/05 01:10:30 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -66,9 +66,9 @@ rsh_relay(int s_src, int s_dst)
FD_SET(s_src, &readfds);
tv.tv_sec = FAITH_TIMEOUT;
tv.tv_usec = 0;
- error = select(256, &readfds, NULL, NULL, &tv);
+ error = select(s_src + 1, &readfds, NULL, NULL, &tv);
if (error == -1)
- exit_failure("select %d: %s", s_src, ERRSTR);
+ exit_failure("select %d: %s", s_src, strerror(errno));
else if (error == 0)
exit_failure("connection timeout");
@@ -101,7 +101,7 @@ relay(int src, int dst)
switch (n) {
case -1:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
case 0:
if (s_rcv == src) {
/* half close */
@@ -168,18 +168,27 @@ rsh_dual_relay(int s_src, int s_dst)
syslog(LOG_INFO, "starting rsh control connection");
for (;;) {
+ int maxfd = 0;
+
FD_ZERO(&readfds);
if (half == NO)
FD_SET(s_src, &readfds);
FD_SET(s_dst, &readfds);
+ if (s_dst > maxfd)
+ maxfd = s_dst;
FD_SET(s_ctl, &readfds);
+ if (s_ctl > maxfd)
+ maxfd = s_ctl;
FD_SET(s_ctl6, &readfds);
+ if (s_ctl6 > maxfd)
+ maxfd = s_ctl6;
+
tv.tv_sec = FAITH_TIMEOUT;
tv.tv_usec = 0;
- error = select(256, &readfds, NULL, NULL, &tv);
+ error = select(maxfd + 1, &readfds, NULL, NULL, &tv);
if (error == -1)
- exit_failure("select 4 sockets: %s", ERRSTR);
+ exit_failure("select 4 sockets: %s", strerror(errno));
else if (error == 0)
exit_failure("connection timeout");
@@ -207,5 +216,5 @@ rsh_dual_relay(int s_src, int s_dst)
/* NOTREACHED */
bad:
- exit_failure(ERRSTR);
+ exit_failure("%s", strerror(errno));
}
diff --git a/usr.sbin/faithd/tcp.c b/usr.sbin/faithd/tcp.c
index 1c660cf2ab6..1fbb996f475 100644
--- a/usr.sbin/faithd/tcp.c
+++ b/usr.sbin/faithd/tcp.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: tcp.c,v 1.5 2000/10/06 02:46:59 itojun Exp $ */
-/* $KAME: tcp.c,v 1.5 2000/09/29 03:48:31 sakane Exp $ */
+/* $OpenBSD: tcp.c,v 1.6 2001/09/05 01:31:33 itojun Exp $ */
+/* $KAME: tcp.c,v 1.6 2001/07/02 14:36:49 itojun Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -178,7 +178,7 @@ send_data(int s_rcv, int s_snd, const char *service, int direction)
return;
retry_or_err:
if (errno != EAGAIN)
- exit_failure("writing relay data failed: %s", ERRSTR);
+ exit_failure("writing relay data failed: %s", strerror(errno));
FD_SET(s_snd, &writefds);
}
@@ -209,7 +209,7 @@ relay(int s_rcv, int s_snd, const char *service, int direction)
if (error == -1) {
if (errno == EINTR)
continue;
- exit_failure("select: %s", ERRSTR);
+ exit_failure("select: %s", strerror(errno));
} else if (error == 0) {
readfds = oreadfds;
writefds = owritefds;
@@ -236,7 +236,7 @@ relay(int s_rcv, int s_snd, const char *service, int direction)
goto oob_read_retry;
exit_failure("reading oob data failed"
": %s",
- ERRSTR);
+ strerror(errno));
}
}
}
@@ -250,7 +250,7 @@ relay(int s_rcv, int s_snd, const char *service, int direction)
if (errno == EINTR)
goto relaydata_read_retry;
exit_failure("reading relay data failed: %s",
- ERRSTR);
+ strerror(errno));
/* NOTREACHED */
case 0:
/* to close opposite-direction relay process */
@@ -281,7 +281,8 @@ tcp_relay(int s_src, int s_dst, const char *service)
cpid = fork();
switch (cpid) {
case -1:
- exit_failure("tcp_relay: can't fork grand child: %s", ERRSTR);
+ exit_failure("tcp_relay: can't fork grand child: %s",
+ strerror(errno));
/* NOTREACHED */
case 0:
/* child process: relay going traffic */