From 1a343b52c8323fbdb6cc6c89e9b74e6fe2e8a95a Mon Sep 17 00:00:00 2001 From: John Marino Date: Fri, 2 Nov 2012 18:59:00 +0100 Subject: [PATCH] libfetch: Change FTP default to passive mode 1. The caller can select active mode using "P" flag. 2. If the "p" passive flag is also present, it takes precedence over "P" so the connection will be attempted in passive mode. Taken-from: FreeBSD SVN 225810 (27 SEP 2011) Taken-from: FreeBSD SVN 225812 (27 SEP 2011) --- lib/libfetch/fetch.3 | 27 +++++++++++++++++++-------- lib/libfetch/ftp.c | 13 +++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3 index 6d412b5905..169bae1f90 100644 --- a/lib/libfetch/fetch.3 +++ b/lib/libfetch/fetch.3 @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav +.\" Copyright (c) 1998-2011 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -23,10 +23,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libfetch/fetch.3,v 1.66 2008/12/15 08:27:44 murray Exp $ -.\" $DragonFly: src/lib/libfetch/fetch.3,v 1.5 2007/11/23 23:16:36 swildner Exp $ +.\" $FreeBSD$ .\" -.Dd May 10, 2009 +.Dd November 3, 2012 .Dt FETCH 3 .Os .Sh NAME @@ -319,9 +318,19 @@ and implement the FTP protocol as described in RFC 959. .Pp If the +.Ql P +(not passive) flag is specified, an active (rather than passive) +connection will be attempted. +.Pp +The .Ql p -(passive) flag is specified, a passive (rather than active) connection -will be attempted. +flag is supported for compatibility with earlier versions where active +connections were the default. +It has precedence over the +.Ql P +flag, so if both are specified, +.Nm +will use a passive connection. .Pp If the .Ql l @@ -476,9 +485,11 @@ connections will be bound. .It Ev FTP_LOGIN Default FTP login if none was provided in the URL. .It Ev FTP_PASSIVE_MODE -If set to anything but +If set to .Ql no , -forces the FTP code to use passive mode. +forces the FTP code to use active mode. +If set to any other value, forces passive mode even if the application +requested active mode. .It Ev FTP_PASSWORD Default FTP password if the remote server requests one and none was provided in the URL. diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c index 7e6e7d34c7..0dbf53d57c 100644 --- a/lib/libfetch/ftp.c +++ b/lib/libfetch/ftp.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav + * Copyright (c) 1998-2011 Dag-Erling Smørgrav * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +24,6 @@ * 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. - * - * $FreeBSD: src/lib/libfetch/ftp.c,v 1.102 2008/02/08 09:48:48 des Exp $ */ /* @@ -40,7 +38,7 @@ * * Major Changelog: * - * Dag-Erling Coïdan Smørgrav + * Dag-Erling Smørgrav * 9 Jun 1998 * * Incorporated into libfetch @@ -633,13 +631,12 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, /* check flags */ low = CHECK_FLAG('l'); - pasv = CHECK_FLAG('p'); + pasv = CHECK_FLAG('p') || !CHECK_FLAG('P'); verbose = CHECK_FLAG('v'); /* passive mode */ - if (!pasv) - pasv = ((s = getenv("FTP_PASSIVE_MODE")) != NULL && - strncasecmp(s, "no", 2) != 0); + if ((s = getenv("FTP_PASSIVE_MODE")) != NULL) + pasv = (strncasecmp(s, "no", 2) != 0); /* isolate filename */ filename = ftp_filename(file, &filenamelen, &type); -- 2.41.0