diff --git a/dist/pf/libexec/ftp-proxy/ftp-proxy.c b/dist/pf/libexec/ftp-proxy/ftp-proxy.c index c6fde32d1e26..b746a96f8aa8 100644 --- a/dist/pf/libexec/ftp-proxy/ftp-proxy.c +++ b/dist/pf/libexec/ftp-proxy/ftp-proxy.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftp-proxy.c,v 1.5 2004/07/09 08:27:38 enami Exp $ */ +/* $NetBSD: ftp-proxy.c,v 1.6 2004/11/11 09:50:00 yamt Exp $ */ /* $OpenBSD: ftp-proxy.c,v 1.35 2004/03/14 21:51:44 dhartmei Exp $ */ /* @@ -1086,7 +1086,7 @@ main(int argc, char *argv[]) memset(&client_iob, 0, sizeof(client_iob)); memset(&server_iob, 0, sizeof(server_iob)); - if (pf && pf_get_proxy_env(0, &real_server_sa, &client_iob.sa) == -1) + if (pf && get_proxy_env(0, &real_server_sa, &client_iob.sa) == -1) exit(EX_PROTOCOL); if (ipf && ipf_get_proxy_env(0, &real_server_sa, &client_iob.sa) == -1) exit(EX_PROTOCOL); @@ -1101,7 +1101,7 @@ main(int argc, char *argv[]) drop_privs(); /* - * We check_host after *_get_proxy_env so that checks are done + * We check_host after get_proxy_env so that checks are done * against the original destination endpoint, not the endpoint * of our side of the rdr. This allows the use of tcpwrapper * rules to restrict destinations as well as sources of connections diff --git a/dist/pf/libexec/ftp-proxy/pf.c b/dist/pf/libexec/ftp-proxy/pf.c deleted file mode 100644 index 3c15ae9008a7..000000000000 --- a/dist/pf/libexec/ftp-proxy/pf.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $NetBSD: pf.c,v 1.1 2004/06/30 13:29:43 darrenr Exp $ */ -/* $OpenBSD: util.c,v 1.18 2004/01/22 16:10:30 beck Exp $ */ - -/* - * Copyright (c) 1996-2001 - * Obtuse Systems Corporation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Obtuse Systems nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE OBTUSE SYSTEMS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OBTUSE - * SYSTEMS CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "util.h" - - -int -pf_get_proxy_env(int connected_fd, struct sockaddr_in *real_server_sa_ptr, - struct sockaddr_in *client_sa_ptr) -{ - struct pfioc_natlook natlook; - socklen_t slen; - int fd; - - slen = sizeof(*real_server_sa_ptr); - if (getsockname(connected_fd, (struct sockaddr *)real_server_sa_ptr, - &slen) != 0) { - syslog(LOG_ERR, "getsockname() failed (%m)"); - return(-1); - } - slen = sizeof(*client_sa_ptr); - if (getpeername(connected_fd, (struct sockaddr *)client_sa_ptr, - &slen) != 0) { - syslog(LOG_ERR, "getpeername() failed (%m)"); - return(-1); - } - - /* - * Build up the pf natlook structure. - * Just for IPv4 right now - */ - memset((void *)&natlook, 0, sizeof(natlook)); - natlook.af = AF_INET; - natlook.saddr.addr32[0] = client_sa_ptr->sin_addr.s_addr; - natlook.daddr.addr32[0] = real_server_sa_ptr->sin_addr.s_addr; - natlook.proto = IPPROTO_TCP; - natlook.sport = client_sa_ptr->sin_port; - natlook.dport = real_server_sa_ptr->sin_port; - natlook.direction = PF_OUT; - - /* - * Open the pf device and lookup the mapping pair to find - * the original address we were supposed to connect to. - */ - fd = open("/dev/pf", O_RDWR); - if (fd == -1) { - syslog(LOG_ERR, "cannot open /dev/pf (%m)"); - exit(EX_UNAVAILABLE); - } - - if (ioctl(fd, DIOCNATLOOK, &natlook) == -1) { - syslog(LOG_INFO, - "pf nat lookup failed %s:%hu (%m)", - inet_ntoa(client_sa_ptr->sin_addr), - ntohs(client_sa_ptr->sin_port)); - close(fd); - return(-1); - } - close(fd); - - /* - * Now jam the original address and port back into the into - * destination sockaddr_in for the proxy to deal with. - */ - memset((void *)real_server_sa_ptr, 0, sizeof(struct sockaddr_in)); - real_server_sa_ptr->sin_port = natlook.rdport; - real_server_sa_ptr->sin_addr.s_addr = natlook.rdaddr.addr32[0]; - real_server_sa_ptr->sin_len = sizeof(struct sockaddr_in); - real_server_sa_ptr->sin_family = AF_INET; - return(0); -} diff --git a/dist/pf/libexec/ftp-proxy/util.c b/dist/pf/libexec/ftp-proxy/util.c index cfb7b6786f83..4dc2aad9aabf 100644 --- a/dist/pf/libexec/ftp-proxy/util.c +++ b/dist/pf/libexec/ftp-proxy/util.c @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.3 2004/06/30 13:29:43 darrenr Exp $ */ +/* $NetBSD: util.c,v 1.4 2004/11/11 09:50:00 yamt Exp $ */ /* $OpenBSD: util.c,v 1.18 2004/01/22 16:10:30 beck Exp $ */ /* @@ -74,6 +74,73 @@ debuglog(int debug_level, const char *fmt, ...) va_end(ap); } +int +get_proxy_env(int connected_fd, struct sockaddr_in *real_server_sa_ptr, + struct sockaddr_in *client_sa_ptr) +{ + struct pfioc_natlook natlook; + socklen_t slen; + int fd; + + slen = sizeof(*real_server_sa_ptr); + if (getsockname(connected_fd, (struct sockaddr *)real_server_sa_ptr, + &slen) != 0) { + syslog(LOG_ERR, "getsockname() failed (%m)"); + return(-1); + } + slen = sizeof(*client_sa_ptr); + if (getpeername(connected_fd, (struct sockaddr *)client_sa_ptr, + &slen) != 0) { + syslog(LOG_ERR, "getpeername() failed (%m)"); + return(-1); + } + + /* + * Build up the pf natlook structure. + * Just for IPv4 right now + */ + memset((void *)&natlook, 0, sizeof(natlook)); + natlook.af = AF_INET; + natlook.saddr.addr32[0] = client_sa_ptr->sin_addr.s_addr; + natlook.daddr.addr32[0] = real_server_sa_ptr->sin_addr.s_addr; + natlook.proto = IPPROTO_TCP; + natlook.sport = client_sa_ptr->sin_port; + natlook.dport = real_server_sa_ptr->sin_port; + natlook.direction = PF_OUT; + + /* + * Open the pf device and lookup the mapping pair to find + * the original address we were supposed to connect to. + */ + fd = open("/dev/pf", O_RDWR); + if (fd == -1) { + syslog(LOG_ERR, "cannot open /dev/pf (%m)"); + exit(EX_UNAVAILABLE); + } + + if (ioctl(fd, DIOCNATLOOK, &natlook) == -1) { + syslog(LOG_INFO, + "pf nat lookup failed %s:%hu (%m)", + inet_ntoa(client_sa_ptr->sin_addr), + ntohs(client_sa_ptr->sin_port)); + close(fd); + return(-1); + } + close(fd); + + /* + * Now jam the original address and port back into the into + * destination sockaddr_in for the proxy to deal with. + */ + memset((void *)real_server_sa_ptr, 0, sizeof(struct sockaddr_in)); + real_server_sa_ptr->sin_port = natlook.rdport; + real_server_sa_ptr->sin_addr.s_addr = natlook.rdaddr.addr32[0]; + real_server_sa_ptr->sin_len = sizeof(struct sockaddr_in); + real_server_sa_ptr->sin_family = AF_INET; + return(0); +} + + /* * Transfer one unit of data across a pair of sockets * diff --git a/dist/pf/libexec/ftp-proxy/util.h b/dist/pf/libexec/ftp-proxy/util.h index 03b955fafc36..98382a7022ae 100644 --- a/dist/pf/libexec/ftp-proxy/util.h +++ b/dist/pf/libexec/ftp-proxy/util.h @@ -54,7 +54,7 @@ struct csiob { extern int telnet_getline(struct csiob *iobp, struct csiob *telnet_passthrough); -extern int pf_get_proxy_env(int fd, struct sockaddr_in *server_sa_ptr, +extern int get_proxy_env(int fd, struct sockaddr_in *server_sa_ptr, struct sockaddr_in *client_sa_ptr); extern int ipf_get_proxy_env(int fd, struct sockaddr_in *server_sa_ptr, struct sockaddr_in *client_sa_ptr); diff --git a/libexec/ftp-proxy/Makefile b/libexec/ftp-proxy/Makefile index 7ba7c187cfe7..2086bb05e66c 100644 --- a/libexec/ftp-proxy/Makefile +++ b/libexec/ftp-proxy/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.5 2004/10/14 00:14:52 christos Exp $ +# $NetBSD: Makefile,v 1.6 2004/11/11 09:49:59 yamt Exp $ # $OpenBSD: Makefile,v 1.4 2003/11/20 23:23:09 avsm Exp $ # @(#)Makefile 8.2 (Berkeley) 4/4/94 PROG= ftp-proxy -SRCS= ftp-proxy.c getline.c util.c ipf.c pf.c +SRCS= ftp-proxy.c getline.c util.c ipf.c MAN= ftp-proxy.8 WARNS?= 2