summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-10-08 15:11:21 +0000
committerjoerg <joerg@pkgsrc.org>2008-10-08 15:11:21 +0000
commit33cbc91d9638e7a16d3fce7ceb093295934b6f5c (patch)
tree11c61428bbeb9ee83fe15f58c53138c60d2e2714
parent4a4eb76528787e6f957d40ba50deb7c8d590fd00 (diff)
downloadpkgsrc-33cbc91d9638e7a16d3fce7ceb093295934b6f5c.tar.gz
libfetch-2.18:
Change FTP backend to use passive mode by default and fallback to active mode on syntax errors as discussed with and suggested by Luke Mewburn. Retire 'p' now and introduce 'a' flag to get the old default behavior.
-rw-r--r--net/libfetch/Makefile4
-rw-r--r--net/libfetch/files/fetch.312
-rw-r--r--net/libfetch/files/fetch.cat358
-rw-r--r--net/libfetch/files/ftp.c14
4 files changed, 52 insertions, 36 deletions
diff --git a/net/libfetch/Makefile b/net/libfetch/Makefile
index 5130389b405..01f90727bfb 100644
--- a/net/libfetch/Makefile
+++ b/net/libfetch/Makefile
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.20 2008/10/06 23:37:56 joerg Exp $
+# $NetBSD: Makefile,v 1.21 2008/10/08 15:11:21 joerg Exp $
#
-DISTNAME= libfetch-2.17
+DISTNAME= libfetch-2.18
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/net/libfetch/files/fetch.3 b/net/libfetch/files/fetch.3
index c22091b9b21..2c87a21731e 100644
--- a/net/libfetch/files/fetch.3
+++ b/net/libfetch/files/fetch.3
@@ -24,7 +24,7 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $
-.\" $NetBSD: fetch.3,v 1.9 2008/10/06 12:58:29 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.10 2008/10/08 15:11:21 joerg Exp $
.\"
.Dd April 25, 2008
.Dt FETCH 3
@@ -358,10 +358,14 @@ and
.Fn fetchPutFTP
implement the FTP protocol as described in RFC 959.
.Pp
+By default
+.Nm libfetch
+will attempt to use passive mode first and only fallback to active mode
+if the server reports a syntax error.
If the
-.Ql p
-(passive) flag is specified, a passive (rather than active) connection
-will be attempted.
+.Ql a
+(active) flag is specified, a passive connection is not tried and active mode
+is used directly.
.Pp
If the
.Ql l
diff --git a/net/libfetch/files/fetch.cat3 b/net/libfetch/files/fetch.cat3
index 7031a66409d..63156b90ad8 100644
--- a/net/libfetch/files/fetch.cat3
+++ b/net/libfetch/files/fetch.cat3
@@ -126,7 +126,7 @@ DDEESSCCRRIIPPTTIIOONN
ffeettcchhPPaarrsseeUURRLL() takes a URL in the form of a null-terminated string and
splits it into its components function according to the Common Internet
- Scheme Syntax detailed in RFC1738. A regular expression which produces
+ Scheme Syntax detailed in RFC 1738. A regular expression which produces
this syntax is:
<scheme>:(//(<user>(:<pwd>)?@)?<host>(:<port>)?)?/(<document>)?
@@ -140,7 +140,7 @@ DDEESSCCRRIIPPTTIIOONN
the URL automatically. This is not done by ffeettcchhMMaakkeeUURRLL().
ffeettcchhCCooppyyUURRLL() copies an existing _u_r_l structure.
- ffeettcchhMMaakkeeUURRLL(), ffeettcchhPPaarrsseeUURRLL() and ffeettcchhCCooppyyUURRLL() return a pointer to a
+ ffeettcchhMMaakkeeUURRLL(), ffeettcchhPPaarrsseeUURRLL(), and ffeettcchhCCooppyyUURRLL() return a pointer to a
_u_r_l structure, which is defined as follows in <_f_e_t_c_h_._h>:
#define URL_SCHEMELEN 16
@@ -159,7 +159,7 @@ DDEESSCCRRIIPPTTIIOONN
size_t length;
};
- The pointer returned by ffeettcchhMMaakkeeUURRLL(), ffeettcchhCCooppyyUURRLL() and
+ The pointer returned by ffeettcchhMMaakkeeUURRLL(), ffeettcchhCCooppyyUURRLL(), and
ffeettcchhPPaarrsseeUURRLL() should be freed using ffeettcchhFFrreeeeUURRLL().
ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), and ffeettcchhPPuuttUURRLL() constitute the recom-
@@ -201,23 +201,23 @@ DDEESSCCRRIIPPTTIIOONN
struct url *urls;
};
- The list should be initialised by calling ffeettcchhIInniittUURRLLLLiisstt() and the
+ The list should be initialized by calling ffeettcchhIInniittUURRLLLLiisstt() and the
entries be freed by calling ffeettcchhFFrreeeeUURRLLLLiisstt().
ffeettcchhSSttrriinnggiiffyyUURRLL() returns the URL as string. ffeettcchhUUnnqquuootteePPaatthh()
returns the path name part of the URL with any quoting undone. Query
arguments and fragment identifiers are not included.
ffeettcchhUUnnqquuootteeFFiilleennaammee() returns the last component of the path name as
- returned by ffeettcchhUUnnqquuootteePPaatthh(). ffeettcchhSSttrriinnggiiffyyUURRLL(), ffeettcchhUUnnqquuootteePPaatthh()
+ returned by ffeettcchhUUnnqquuootteePPaatthh(). ffeettcchhSSttrriinnggiiffyyUURRLL(), ffeettcchhUUnnqquuootteePPaatthh(),
and ffeettcchhUUnnqquuootteeFFiilleennaammee() return a string that should be deallocated
with ffrreeee() after use.
- ffeettcchhXXGGeett(), ffeettcchhGGeett(), ffeettcchhPPuutt() and ffeettcchhSSttaatt() are similar to
- ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), ffeettcchhPPuuttUURRLL() and ffeettcchhSSttaattUURRLL(), except
+ ffeettcchhXXGGeett(), ffeettcchhGGeett(), ffeettcchhPPuutt(), and ffeettcchhSSttaatt() are similar to
+ ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), ffeettcchhPPuuttUURRLL(), and ffeettcchhSSttaattUURRLL(), except
that they expect a pre-parsed URL in the form of a pointer to a _s_t_r_u_c_t
_u_r_l rather than a string.
- All of the ffeettcchhXXGGeettXXXXXX(), ffeettcchhGGeettXXXXXX() and ffeettcchhPPuuttXXXXXX() functions
+ All of the ffeettcchhXXGGeettXXXXXX(), ffeettcchhGGeettXXXXXX(), and ffeettcchhPPuuttXXXXXX() functions
return a pointer to a stream which can be used to read or write data from
or to the requested document, respectively. Note that although the
implementation details of the individual access methods vary, it can gen-
@@ -226,9 +226,9 @@ DDEESSCCRRIIPPTTIIOONN
of the ffeettcchhPPuuttXXXXXX() functions is write-only.
FFIILLEE SSCCHHEEMMEE
- ffeettcchhXXGGeettFFiillee(), ffeettcchhGGeettFFiillee() and ffeettcchhPPuuttFFiillee() provide access to doc-
- uments which are files in a locally mounted file system. Only the <docu-
- ment> component of the URL is used.
+ ffeettcchhXXGGeettFFiillee(), ffeettcchhGGeettFFiillee(), and ffeettcchhPPuuttFFiillee() provide access to
+ documents which are files in a locally mounted file system. Only the
+ <document> component of the URL is used.
ffeettcchhXXGGeettFFiillee() and ffeettcchhGGeettFFiillee() do not accept any flags.
@@ -238,16 +238,18 @@ FFIILLEE SSCCHHEEMMEE
them.
FFTTPP SSCCHHEEMMEE
- ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP() and ffeettcchhPPuuttFFTTPP() implement the FTP proto-
- col as described in RFC959.
+ ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP(), and ffeettcchhPPuuttFFTTPP() implement the FTP proto-
+ col as described in RFC 959.
- If the `p' (passive) flag is specified, a passive (rather than active)
- connection will be attempted.
+ By default lliibbffeettcchh will attempt to use passive mode first and only fall-
+ back to active mode if the server reports a syntax error. If the `a'
+ (active) flag is specified, a passive connection is not tried and active
+ mode is used directly.
If the `l' (low) flag is specified, data sockets will be allocated in the
low (or default) port range instead of the high port range (see ip(4)).
- If the `d' (direct) flag is specified, ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP() and
+ If the `d' (direct) flag is specified, ffeettcchhXXGGeettFFTTPP(), ffeettcchhGGeettFFTTPP(), and
ffeettcchhPPuuttFFTTPP() will use a direct connection even if a proxy server is
defined.
@@ -256,11 +258,11 @@ FFTTPP SSCCHHEEMMEE
mous@<hostname>".
HHTTTTPP SSCCHHEEMMEE
- The ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP() and ffeettcchhPPuuttHHTTTTPP() functions imple-
+ The ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP(), and ffeettcchhPPuuttHHTTTTPP() functions imple-
ment the HTTP/1.1 protocol. With a little luck, there is even a chance
- that they comply with RFC2616 and RFC2617.
+ that they comply with RFC 2616 and RFC 2617.
- If the `d' (direct) flag is specified, ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP()
+ If the `d' (direct) flag is specified, ffeettcchhXXGGeettHHTTTTPP(), ffeettcchhGGeettHHTTTTPP(),
and ffeettcchhPPuuttHHTTTTPP() will use a direct connection even if a proxy server is
defined.
@@ -338,7 +340,7 @@ RREETTUURRNN VVAALLUUEESS
and message, e.g. "File is not available (404 Not Found)"
EENNVVIIRROONNMMEENNTT
- FETCH_BIND_ADDRESS Specifies a hostname or IP address to which sockets
+ FETCH_BIND_ADDRESS Specifies a host name or IP address to which sockets
used for outgoing connections will be bound.
FTP_LOGIN Default FTP login if none was provided in the URL.
@@ -437,24 +439,24 @@ EEXXAAMMPPLLEESS
NO_PROXY=localhost,127.0.0.1
SSEEEE AALLSSOO
- fetch(1), ftpio(3), ip(4)
+ ftp(1), ip(4)
- J. Postel and J. K. Reynolds, _F_i_l_e _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l, October 1985,
- RFC959.
+ J. Postel and J. K. Reynolds, _F_i_l_e _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l, October 1985, RFC
+ 959.
- P. Deutsch, A. Emtage, and A. Marine., _H_o_w _t_o _U_s_e _A_n_o_n_y_m_o_u_s _F_T_P, May
- 1994, RFC1635.
+ P. Deutsch, A. Emtage, and A. Marine, _H_o_w _t_o _U_s_e _A_n_o_n_y_m_o_u_s _F_T_P, May 1994,
+ RFC 1635.
T. Berners-Lee, L. Masinter, and M. McCahill, _U_n_i_f_o_r_m _R_e_s_o_u_r_c_e _L_o_c_a_t_o_r_s
- _(_U_R_L_), December 1994, RFC1738.
+ _(_U_R_L_), December 1994, RFC 1738.
R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and
T. Berners-Lee, _H_y_p_e_r_t_e_x_t _T_r_a_n_s_f_e_r _P_r_o_t_o_c_o_l _-_- _H_T_T_P_/_1_._1, January 1999,
- RFC2616.
+ RFC 2616.
J. Franks, P. Hallam-Baker, J. Hostetler, S. Lawrence, P. Leach, A.
Luotonen, and L. Stewart, _H_T_T_P _A_u_t_h_e_n_t_i_c_a_t_i_o_n_: _B_a_s_i_c _a_n_d _D_i_g_e_s_t _A_c_c_e_s_s
- _A_u_t_h_e_n_t_i_c_a_t_i_o_n, June 1999, RFC2617.
+ _A_u_t_h_e_n_t_i_c_a_t_i_o_n, June 1999, RFC 2617.
HHIISSTTOORRYY
The ffeettcchh library first appeared in FreeBSD 3.0.
diff --git a/net/libfetch/files/ftp.c b/net/libfetch/files/ftp.c
index e9fe2de2e5f..65de349e243 100644
--- a/net/libfetch/files/ftp.c
+++ b/net/libfetch/files/ftp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.23 2008/10/06 12:58:29 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.24 2008/10/08 15:11:21 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -629,7 +629,7 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
/* check flags */
low = CHECK_FLAG('l');
- pasv = CHECK_FLAG('p');
+ pasv = !CHECK_FLAG('a');
verbose = CHECK_FLAG('v');
/* passive mode */
@@ -651,6 +651,8 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
if (sa.ss_family == AF_INET6)
unmappedaddr((struct sockaddr_in6 *)&sa, &l);
+retry_mode:
+
/* open data socket */
if ((sd = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
fetch_syserr();
@@ -723,6 +725,14 @@ ftp_transfer(conn_t *conn, const char *oper, const char *file, const char *op_ar
goto ouch;
}
break;
+ case FTP_SYNTAX_ERROR:
+ if (verbose)
+ fetch_info("passive mode failed");
+ /* Close socket and retry with passive mode. */
+ pasv = 0;
+ close(sd);
+ sd = -1;
+ goto retry_mode;
}
/* seek to required offset */