History log of /freebsd-9.3-release/lib/libfetch/ftp.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 236103 26-May-2012 des

MFH r225813,r225814,r226537: cosmetic


# 226015 04-Oct-2011 des

MFH r225810 r225812: make passive mode the default.

Approved by: re (kib)


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 221822 12-May-2011 des

Increase WARNS to 4.


# 217505 17-Jan-2011 des

Fix a bug related to connection caching which could cause a crash after
a STAT command.

PR: kern/153748 (different patch)
Submitted by: Mark Johnston <markjdb@gmail.com>
MFC after: 2 weeks


# 199801 25-Nov-2009 attilio

Fix a socket leak in ftp_request() after that a connection is established.

Submitted by: Sandvine Incorporated
Reviewed by: des, emaste
Sponsored by: Sandvine Incorporated
MFC: 1 week


# 176105 08-Feb-2008 des

Use memcpy(3) instead of the BSD-specific bcopy(3).

Submitted by: Joerg Sonnenberger <joerg@britannica.bec.de>
MFC after: 2 weeks


# 175611 23-Jan-2008 des

Fix a regression introduced in rev 1.99: replace fclose(f) with a comment
explaining why f cannot possibly be a valid FILE * at this point.

MFC after: 1 day


# 174761 18-Dec-2007 des

As several people pointed out, I did all the ctype casts the wrong
way (not for the first time...)

Noticed by: bde, ru ++
MFC after: 1 week


# 174752 18-Dec-2007 des

Add support for the NO_PROXY / no_proxy environment variable as used by
lynx, curl etc. Note that this patch differs significantly from that
in the PR, as the submitter refined it after submitting the PR.

PR: 110388
Submitted by: Alexander Pohoyda <alexander.pohoyda@gmx.net>
MFC after: 3 weeks


# 174751 18-Dec-2007 des

Old patch I had lying around: correctly cast the argument to is*().
IWBNI gcc could warn about this the way it warns about printf() abuse.

MFC after: 1 week


# 174588 14-Dec-2007 des

Clean up namespace violations.

MFC after: 1 week


# 168960 22-Apr-2007 njl

Add back the original behavior of changing the entire directory path at
once (CWD a/b/c vs. 3 CWDs). If an error occurs, we fall back to the default
method of a single CWD per directory element. Since this is technically
a violation of the basic FTP RFC, this behavior is under a compile-time
option FTP_COMBINE_CWDS and is off by default. It should work with most
Unix-based FTP daemons and can save latency.

MFC after: 2 weeks


# 159566 13-Jun-2006 des

Respect FETCH_BIND_ADDRESS when opening the data connection.

PR: misc/98872


# 159565 13-Jun-2006 des

Fix a bug introduced in rev 1.92, where, when changing from one directory
to another, the first CWD after a string of CDUPs would incorrectly include
a slash before the directory name.

Reported by: obrien
PR: bin/83278


# 154550 19-Jan-2006 des

In order to maintain interoperability with certain broken FTP servers,
ignore a MODE failure if and only if the mode we attempted to set was S
(which is supposed to be the default).

PR: bin/91973


# 148986 12-Aug-2005 des

Change directory one level at a time, and use CDUP to back out. This is a
work in progress; it partially fixed bin/83278 and is a prerequisite to
fixing bin/83277.

PR: bin/83277, bin/83278


# 135546 21-Sep-2004 des

Update copyright years.


# 119558 29-Aug-2003 des

Forced commit to note the following about the previous commit:

PR: bin/55950
Submitted by: Andre Albsmeier <andre.albsmeier@siemens.com>
MFC after: 3 days


# 119557 29-Aug-2003 des

Don't close a FILE * which we know is bogus.


# 119123 19-Aug-2003 des

Some servers respond to RETR in active mode with 125 (connection already
open) rather than 150 (opening connection). There's no reason why we
shouldn't accept that.

PR: misc/42172
MFC in: 3 days


# 112420 19-Mar-2003 mtm

The flags passed in to _ftp_get_proxy may be null

Approved by: des, markm (mentor)(implicit)


# 112081 11-Mar-2003 des

Don't parse the proxy URL unless we're actually going to use it. No real
functional difference, but debugging output will be less confusing.


# 109967 28-Jan-2003 des

style(9): add parentheses to sizeof even when not strictly required.

MFC after: 3 days


# 109697 22-Jan-2003 des

Hook in the .netrc code + don't use pointers as if they were booleans.


# 105903 24-Oct-2002 njl

The FTP connection caching needs a better interface -- connections are
closed through _fetch_close() which is the only one who knows the connection
REALLY was closed (since ref -> 0). However, FTP keeps its own local
cached_connection and checks if it is valid by comparing it to NULL. This
is bogus since it may have been freed elsewhere by _fetch_close().

This change checks if we are closing the cached_connection and the ref is 1
(soon to be 0). If so, set cached_connection to NULL so we don't
accidentally reuse it. The REAL fix should be to move connection caching
to the common.c level (_fetch_* functions) and NULL the cache(s) in
_fetch_close(). Then all layers could benefit from caching.


# 105511 20-Oct-2002 tjr

When recycling a cached connection, increment the reference count so that
the heap block does not get freed and reused. This should fix the
pkg_add -r crashes that have been happening for months.


# 103459 17-Sep-2002 fenner

Make _fetch_connect() always set the error code.
Tell ftp that _fetch_connect() always sets the error code (http already knew)


# 99253 02-Jul-2002 ume

Cope with 2292bis-01 getaddrinfo (no NI_WITHSCOPEID, always attach
scope identifier).

Approved by: des
MFC after: 3 weeks


# 98117 11-Jun-2002 des

Add a reference count to struct fetchconn so we don't prematurely close and
free a cached FTP connection.


# 97866 05-Jun-2002 des

Wrap everything in struct connection, and enforce timeouts everywhere
(except for DNS operations). Always use funopen() for HTTP, to support
both timeouts and SSL.


# 97856 05-Jun-2002 des

First step towards SSL support: wrap connections in a 'struct connection'
which contains the socket descriptor, the input buffer and (yet unused)
SSL state variables. This has the neat side effect of greatly improving
reentrance (though we're not *quite* there yet) and opening the door to
HTTP connection caching.

This commit is inspired by email conversations with and patches from
Henry Whincup <henry@techiebod.com> last fall.


# 93150 25-Mar-2002 phk

Modernize my email address


# 90267 05-Feb-2002 des

Reindent, and add parentheses to return statements. Some functions in
ftp.c and http.c now have exceedingly long lines due to deep nesting;
this will be corrected by reorganizing the code in a later revision.


# 89589 20-Jan-2002 des

Mark uploads as O_WRONLY, not O_RDONLY.

PR: misc/34043
MFC after: 2 weeks


# 88769 01-Jan-2002 des

Remove VT100 escapes from debugging messages now that they're enabled by
default.

PR: 32988
MFC after: 3 days


# 87315 03-Dec-2001 des

Reorganize to reduce code duplication.


# 85093 18-Oct-2001 des

Tons of type, style and warning fixes that have been rotting in my tree for
ages - some of which wouldn't be necessary if gcc wasn't broken or TPTB were
willing to do something (-fno-builtin) about it.


# 84203 30-Sep-2001 dillon

Add __FBSDID()s to libfetch


# 81985 20-Aug-2001 brian

Handle snprintf() returning < 0 (not just -1)

MFC after: 2 weeks


# 81978 20-Aug-2001 brian

Handle snrintf overflows.

Spotted by: bde


# 81972 20-Aug-2001 brian

Handle snprintf() returning -1.

MFC after: 2 weeks


# 78071 11-Jun-2001 des

Don't call _ftp_closefn() upon EOF in _ftp_readfn(); just return 0. This
fixes a bug in pkg_add(1) (which nobody noticed because of another bug).


# 77238 26-May-2001 des

Add rudimentary support for an authentication callback function.


# 77234 26-May-2001 des

Plug memory leak.

PR: 27506


# 75891 23-Apr-2001 archie

Apply 'const' liberally.

Fix some other minor glitches.


# 75292 07-Apr-2001 des

If the server's reply to the SIZE command is unparseable, reset us->size
to -1 so the caller will know it's invalid. This is an MFC candidate.


# 74716 23-Mar-2001 des

Use high port range by default, and replace the 'h' option with an 'l' option
that forces the ftp code to use the low (default) port range instead.


# 73934 07-Mar-2001 des

Don't remember an EINTR, since the caller may want to restart the call.


# 73932 07-Mar-2001 des

Support lower-case versions of the proxy environment variables.

PR: bin/25494


# 70795 08-Jan-2001 des

Use "anonymous" rather than "ftp" as login name for anonymous ftp.

Rather than have a separate (misnamed) FTP_ANONYMOUS_PASSWORD constant, use
FTP_ANONYMOUS_USER (i.e. "anonymous") to construct the anonymous ftp password
if getlogin() fails.


# 70273 22-Dec-2000 des

Check the FTP_LOGIN environment variable before falling back on
FTP_ANONYMOUS_USER.


# 69670 06-Dec-2000 des

Somewhere along the line, I misunderstood the whole FTP_PASSIVE_MODE debate
and had libfetch selecting passive mode even when FTP_PASSIVE_MODE was not
set at all, which is really quite surprising unless you know about it. So
change it to the agreed default behaviour of selecting passive mode if
FTP_PASSIVE_MODE is set, but not "no".


# 69272 27-Nov-2000 des

Fix old-style proxy specs: default to FTP if FTP_PROXY was set; only default
to HTTP if HTTP_PROXY was used instead.


# 69044 22-Nov-2000 des

Don't go haywire if the server closes the connection in the middle of a
multiline response (proper fix this time).


# 69043 22-Nov-2000 des

Revert previous commit, it was somewhat hasty.


# 69041 22-Nov-2000 des

Don't go haywire if the server closes the connection during a multiline
response.


# 68551 10-Nov-2000 des

Use the documented (and historical) defaults. Centralize the decision logic
in order to avoid this bug in the future.

Submitted by: se


# 67892 29-Oct-2000 des

Use CHECK_FLAG


# 67890 29-Oct-2000 des

Stricter error checking in the I/O functions.


# 67810 28-Oct-2000 des

Fix this my way. David had absolutely no call overriding MAINTAINER without
even giving me 24 hours to read his mail and find the bug.


# 67807 28-Oct-2000 obrien

Repeat after me, "check to see that a pointer isn't NULL before
dereferenceing it". This fixes ``pkg_add -r''.


# 67707 27-Oct-2000 des

MFS: don't expect result code until you close the data connection


# 67430 22-Oct-2000 des

Use funopen() instead of fdopen(). This fixes three problems:

- ftpTimeout was not honored when reading actual data, as opposed to
talking protocol

- connection caching was broken because _ftp_cached_connect() would see
the result of the transfer instead of the result of the NOOP.

- if the RETR succeeded, but an error occurred later (as can happen
when talking to a proxy), the error would not be detected.

There still remains to register an atexit(3) callback to close the cached
connection gracefully instead of just dropping it on the floor.


# 67259 17-Oct-2000 des

Argh! Fix passive mode selection (again)


# 67055 13-Oct-2000 des

Use the right user name


# 67043 12-Oct-2000 des

Rework proxy handling so that proxies can be specified as URLs.
As a side effect, remove a lot of duplicate and now redundant code.


# 64883 21-Aug-2000 des

Grok 125 replies to passive RETR. This fixes an interoperability bug with
Microsoft FTP Service.

Reported by: asmodai, eivind


# 63910 27-Jul-2000 des

Don't fail if _ftp_stat() reports a protocol error, since that most likely
means that the server doesn't understand SIZE or MDTM, which should not be a
hard failure.

Submitted by: ume


# 63847 25-Jul-2000 des

If the server reports the size as 0, treat it as unknown. This works around
a bug in some ftp servers (most notably ftp.vmunix.com) which report the
size of a file correctly in ascii mode, but report it as 0 in binary mode.

Reported by: asmodai

Also remove an unneeded initialization.


# 63842 25-Jul-2000 des

Centralize the default port finding code.
Work around YA Apache bug: don't send port in Host: header if it's the
default port.


# 63713 21-Jul-2000 des

The decision to use an HTTP proxy for FTP documents belongs in the FTP code


# 63712 21-Jul-2000 des

Don't send port number to proxy unless it's not the standard FTP port


# 63585 20-Jul-2000 des

Fix the case where the file name is preceded by a lone slash.


# 63392 18-Jul-2000 des

Don't take a failure to stat a file to mean that it doesn't exist, as it may
be a dynamically created file, e.g. a tarball on servers that support sending
tarballs of directories.


# 63340 17-Jul-2000 des

Introduce fetchXGet*(), which combine the functionalities of fetchGet*() and
fetchStat*(). In most cases, either fetchGet*() or fetchXGet*() is a wrapper
around the other; in all cases, calling fetchGet*() is identical to calling
fetchXGet*() with the second argument set to NULL.


# 63336 17-Jul-2000 des

Use a symbolic constant instead of hardcoding 999


# 62982 11-Jul-2000 des

Use fetch_putln()


# 62964 11-Jul-2000 des

Clean up the debugging output


# 62888 10-Jul-2000 ume

Make EPSV work again. Separate parsing code of 229 replies from
the code for 227 and 228.

Submitted by: des


# 62814 08-Jul-2000 des

Don't assume the remote address in a 227 reply is enclosed in parentheses.


# 62256 29-Jun-2000 des

Make restart work in active mode, too.

PR: bin/18688
Submitted by: Rudolf Cejka <cejkar@dcse.fee.vutbr.cz>


# 62215 28-Jun-2000 des

Handle multiline replies properly, instead of kinda-right.


# 61866 20-Jun-2000 des

Back out wes' commit with extreme prejudice.


# 61838 20-Jun-2000 wes

Add implementation of fetchListFTP.

Reviewed by: silence


# 60951 26-May-2000 des

Honor FTP_PASSIVE_MODE so caller doesn't need to.


# 60791 22-May-2000 ume

Use $FTP_PASSWORD for FTP password. If $FTP_PASSWORD is not
found, `yourname@yourhost' is used.


# 60737 20-May-2000 ume

IPv6 support.


# 60707 19-May-2000 des

Better handling of some boundary conditions.

Submitted by: ume


# 60582 15-May-2000 des

Initialize the struct url_stat at the beginning of fetchStatFTP().


# 60383 11-May-2000 des

Add workaround for ftpds with the Y2K MDTM bug


# 60188 07-May-2000 des

Implement restart.
Use sizeof more consistently.
Outline sanity checking of server port spec.


# 56635 26-Jan-2000 des

Fix timestamp handling.

Submitted by: bde


# 55557 07-Jan-2000 des

More old uncommitted patches: implement timeouts at the protocol level.
Currently only supported for ftp connections.


# 55544 07-Jan-2000 des

Patches I've had lying around for several months:
* Add the 'h' ftp flag (allocate local port in high range)
* Add the 'd' flag (use direct connection even if proxy is defined)
* Make sure flags != NULL before calling strchr().
* Minor changes to some comments.


# 50476 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 41989 21-Dec-1998 des

Implement and document file list retrieval.


# 41923 18-Dec-1998 des

Don't specify a language to compile_et.
Rename fetchConnect to _fetch_connect since it's internal.


# 41869 16-Dec-1998 des

Implement and document fetchStatFTP.
Update description of struct url_stat in the man page.
Clean up error handling in ftp.c.


# 41863 16-Dec-1998 des

Remove unused header files. Fix a few shadowing bugs. Improve error reporting.


# 41862 16-Dec-1998 des

Add verbose flag, and support functions.
Brucify the Makefile.
Differentiate atime and mtime in fetch*Stat().
Fix a few pointer bugs.
Tweak some error messages.
Don't #include sys/param.h and stdio.h in fetch.h.
Document that sys/param.h and stdio.h must be #included before fetch.h.


# 40975 06-Nov-1998 des

Second of a series of cleanups to libfetch.

This commit introduces the following features:

a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.

b) the use of the com_err(3) facilities to report errors.

It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.

Changed files, in alphabetical order:

Makefile:
Don't generate macros in {ftp,http}err.c.

Generate category fields for the error message lists.

Compile the error table.

Install fetch_err.h along with fetch.h.

common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.

Add categories to the _netdb_errlist table.

Report errors through the Common Error library.

common.h:
Add the DEBUG macros.

Add prototype for fetchConnect().

Remove the prototype for _fetch_errstring(), which is local to common.c

Add a categroy field to struct fetcherr, and define constants for
error categories.

Define macros for _{url,netdb,ftp,http}_seterr().

errors.et: (new file)
List error categories.

fetch.3:
Document the fetchStat*() functions.

Move the "unimplemented functionality" comments from NOTES to BUGS.

Document that applications which use libfetch must also use
libcom_err, and list existing error codes.

Undocument fetchLastErr{Code,String}.

Remove the (empty) DIAGNOSTICS section.

Mention Eugene Skepner in the AUTHORS section.

fetch.c:
Move the DEBUG macros to common.c

Add fetchStat() and fetchStatURL().

Generate error messages for URL parser errors, and fix a minor bug
in the parser.

Use 'struct url' instead of 'url_t'.

Remove fetchLastErr{Code,String}.

fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.

Define struct url_stat (used by fetchStat()).

Add prototypes for fetchStat*().

Remove the declarations for fetchLastErr{Code,String}.

Include fetch_err.h.

fetch_err.et: (new file)
Error table for libfetch.

file.c:
Add fetchStatFile().

Use 'struct url' instead of 'url_t'.

ftp.c:
Add fetchStatFTP().

Use 'struct url' instead of 'url_t'.

Don't use fetchLastErrCode.

ftp.errors:
Add categories to all error messages.

http.c:
Add fetchStatHTTP().

Use 'struct url' instead of 'url_t'.

Don't use fetchLastErr{Code,Text}.

http.errors:
Add categories to all error messages.

Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner


# 40939 05-Nov-1998 des

First of a series of cleanups to libfetch. Changed files, in
alphabetical order:

Makefile:
Add common.c to SRCS.

Make debugging easier by making 'CFLAGS += -DNDEBUG' conditional on DEBUG

Don't declare struct {ftp,http}err in {ftp,http}err.c; use struct fetcherr
instead.

README:
Remove the todo list, which is out of date anyway.

common.c: (new file)
Gather utility functions in this file.

Merge the error reporting functions intp _fetch_errstring(),
_fetch_seterr() and _fetch_syserr().

Set fetchLastErrCode and fetchLastErrText appropriately when fetchConnect
fails.

common.h: (new file)
Gather internal prototypes and structures in this files.

fetch.3:
Undocument fetchFreeURL().

Document a few more known bugs.

Document fetchLastErrCode and fetchLastErrText.

fetch.c:
Add descriptive comments to all functions that lacked them.

Move fetchConnect() to common.c.

Obviate the need for fetchFreeURL(), and remove it.

fetch.h:
Modify struct url_t so the document part is at the end.

ftp.c:
Remove code that is duplicated elsewhere.

http.c:
Remove code that is duplicated elsewhere.

Prompted by: jkh


# 38394 17-Aug-1998 des

Commit a bunch of patches that have been accumulating:

- Fix the README to reflect the new status of the ftp code.
- Change tons of 'if (xxx < 0)' to 'if (xxx == -1)'
- Add two new interface functions
- Fix the Makefile so it actually works (yay!)

Now the manpage is lagging even further behind... :( Next on the todo
list is to clean up the http code.


# 37608 12-Jul-1998 des

Base64 code (and the MIT copyright) moved to http.c
FTP STORe and APPEnd added.
FTP proxy support added (untested).


# 37573 11-Jul-1998 des

FTP retrieve works.


# 37571 11-Jul-1998 des

Too many changes to list. Basically, FTP is nearly there and error
reporting is kinda sorted out. Now HTTP needs to catch up...


# 37536 09-Jul-1998 des

This commit was generated by cvs2svn to compensate for changes in r37535,
which included commits to RCS files with non-trunk default branches.


# 37535 09-Jul-1998 des

Imported libfetch into the tree. It compiles, but there's still some
work to do. I especially need help with the man page.