diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-07-14 14:48:48 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-07-14 14:48:48 +0000 |
commit | 28cfc2e4e3b35c093b61089422cf0347e7df0890 (patch) | |
tree | 2ee8d2c09004b443d3d6d34b5ef03a78cfdc0de1 /libexec/ftpd | |
parent | 360daa1c380cde584c12fbc861a2b4ebcda22f3a (diff) |
let root create the data socket. fixes PR 4287.
ok millert@ henning@
Diffstat (limited to 'libexec/ftpd')
-rw-r--r-- | libexec/ftpd/ftpd.c | 6 | ||||
-rw-r--r-- | libexec/ftpd/monitor.c | 43 | ||||
-rw-r--r-- | libexec/ftpd/monitor.h | 3 |
3 files changed, 46 insertions, 6 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index 06e05a0f3b3..f012c297560 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.166 2005/05/24 02:24:57 moritz Exp $ */ +/* $OpenBSD: ftpd.c,v 1.167 2005/07/14 14:48:47 moritz Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -70,7 +70,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)ftpd.c 8.4 (Berkeley) 4/16/94"; #else static const char rcsid[] = - "$OpenBSD: ftpd.c,v 1.166 2005/05/24 02:24:57 moritz Exp $"; + "$OpenBSD: ftpd.c,v 1.167 2005/07/14 14:48:47 moritz Exp $"; #endif #endif /* not lint */ @@ -1306,7 +1306,7 @@ getdatasock(char *mode) if (data >= 0) return (fdopen(data, mode)); sigprocmask (SIG_BLOCK, &allsigs, NULL); - s = socket(ctrl_addr.su_family, SOCK_STREAM, 0); + s = monitor_socket(ctrl_addr.su_family); if (s < 0) goto bad; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, diff --git a/libexec/ftpd/monitor.c b/libexec/ftpd/monitor.c index 94ac4b7b319..3b7c112160b 100644 --- a/libexec/ftpd/monitor.c +++ b/libexec/ftpd/monitor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor.c,v 1.10 2005/05/24 02:24:57 moritz Exp $ */ +/* $OpenBSD: monitor.c,v 1.11 2005/07/14 14:48:47 moritz Exp $ */ /* * Copyright (c) 2004 Moritz Jodeit <moritz@openbsd.org> @@ -39,6 +39,7 @@ enum monitor_command { CMD_USER, CMD_PASS, + CMD_SOCKET, CMD_BIND }; @@ -249,7 +250,7 @@ handle_cmds(void) { enum monitor_command cmd; enum auth_ret auth; - int err, s, slavequit, serrno; + int err, s, slavequit, serrno, domain; pid_t preauth_slave_pid; size_t len; struct sockaddr sa; @@ -324,6 +325,25 @@ handle_cmds(void) /* NOTREACHED */ } break; + case CMD_SOCKET: + debugmsg("CMD_SOCKET received"); + + if (state != POSTAUTH) + fatalx("CMD_SOCKET received in invalid state"); + + recv_data(fd_slave, &domain, sizeof(domain)); + if (domain != AF_INET && domain != AF_INET6) + fatalx("monitor received invalid addr family"); + + s = socket(domain, SOCK_STREAM, 0); + serrno = errno; + + send_fd(fd_slave, s); + if (s == -1) + send_data(fd_slave, &serrno, sizeof(serrno)); + else + close(s); + break; case CMD_BIND: debugmsg("CMD_BIND received"); @@ -459,6 +479,25 @@ monitor_pass(char *pass) } int +monitor_socket(int domain) +{ + enum monitor_command cmd; + int s, serrno; + + cmd = CMD_SOCKET; + send_data(fd_monitor, &cmd, sizeof(cmd)); + send_data(fd_monitor, &domain, sizeof(domain)); + + s = recv_fd(fd_monitor); + if (s == -1) { + recv_data(fd_monitor, &serrno, sizeof(serrno)); + errno = serrno; + } + + return (s); +} + +int monitor_bind(int s, struct sockaddr *name, socklen_t namelen) { enum monitor_command cmd; diff --git a/libexec/ftpd/monitor.h b/libexec/ftpd/monitor.h index 42313ecbe1e..2c6012d4e1a 100644 --- a/libexec/ftpd/monitor.h +++ b/libexec/ftpd/monitor.h @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor.h,v 1.3 2004/12/20 14:58:57 moritz Exp $ */ +/* $OpenBSD: monitor.h,v 1.4 2005/07/14 14:48:47 moritz Exp $ */ /* * Copyright (c) 2004 Moritz Jodeit <moritz@openbsd.org> @@ -31,6 +31,7 @@ int monitor_init(void); int monitor_post_auth(void); void monitor_user(char *); int monitor_pass(char *); +int monitor_socket(int); int monitor_bind(int, struct sockaddr *, socklen_t); void kill_slave(void); |