Commit Graph

176 Commits

Author SHA1 Message Date
christos b5f76c451f Add -b <buflen> to specify the buffer size. 2024-02-18 22:29:56 +00:00
lukem 55c16b26b6 add timeout for ssl connect
Implement a timeout for SSL connection setup, using -q QUITTIME,
defaulting to 60 seconds.
SSL_connect(3) (unlike connect(2)) doesn't timeout by default.

Adapt ssl error messages destination: if unexpected error
from local API, use warn()/warnx() to stderr;
if expected error from a network operation (e.g., timeouts),
use fprintf to ttyout (which might be stdout).

Consistently use ftp_poll() instead of select();
ssl.c (using select()) was added 7 years after the
previous uses of select() were converted to poll().

Check EAGAIN as well as existing EINTR error from ftp_poll(),
for portability.
2023-05-05 15:46:06 +00:00
lukem e6d740a8e7 ftp: remove unnecessary variable assignments
Remove assignment to error in initconn(); it's not tested anywhere after the
initial use, so no need to set it before goto bad.

(Looks like copypasta from the initial addition of the code in rev 1.48.)
2021-08-26 06:23:24 +00:00
lukem 819e578d6a ftp: validate address from PASV and LPSV response
Fail if the server's response to PASV or LPSV contains an IP address
that doesn't match that of the control connection.
(EPSV already only uses the port portion of the server's response,
per RFC 2428).

Previously a hostile server could cause ftp to open a data connection elsewhere.

Many other ftp implementations have had a similar change for many years,
including those in popular browsers (before they deprecated FTP ...)

Thanks to Simon Josefsson notifying me about
  https://lists.gnu.org/archive/html/bug-inetutils/2021-06/msg00002.html
2021-08-26 06:16:29 +00:00
lukem 689eea59e5 set SO_KEEPALIVE on control connection
Attempt to prevent timeouts of the control connection by setting SO_KEEPALIVE.
This matches the equivalent behaviour in ftpd.

Note: This is a much simpler change than adding a background polling event
to invoke "STAT" (or "NOOP") on the control connection during a transfer.
(It's unclear from RFC 959 whether "NOOP" is even permitted during a transfer).

PR bin/56129
2021-06-03 10:11:00 +00:00
lukem 920389c199 ftp: don't use restartable signals
Refactor to not rely upon restartable signals (SA_RESTART),
possibly fixing intermittent failures with -q QUITTIME.

ftp transfers: handle EINTR/EAGAIN in copy_bytes(),
instead of relying upon restartable signals.

http/https transfers: Explicitly print an error similar to
progressmeter() when timing-out for -Q QUITTIME in fetch_wait(),
and set errno to ETIMEDOUT so that the warn() in fetch_url()
prints a more accurate error message.

PR/55857
2021-01-06 04:43:14 +00:00
lukem 123e840f8b ftp.c: improve signal handler restoration
Only invoke the old signal handler if it's a real signal handler
and not SIG_IGN, SIG_DFL, SIG_HOLD, or SIG_ERR, using new static
function issighandler().
Avoids an intermittent race condition with a null pointer
dereference via (*SIG_DFL)().
Bug class reported by Joyu Liao from Juniper Networks.

Use SIG_ERR instead of NULL as the indicator that a signal handler
hasn't been changed, so that SIG_DFL (equivalent to NULL)
will be restored.
2020-07-11 02:19:31 +00:00
lukem 31aae2d731 ftp: exit if lostpeer invoked by a signal
lostpeer() calls too many async-unsafe functions (both directly
and indirectly) to close and cleanup the remote connections,
so just exit after the cleanup if invoked by a signal.

Reported in private mail by Qi Hou.
May also resolve a crash reported by Thomas Klausner.
2020-06-08 01:33:27 +00:00
mrg a6590737cd - add justquit() that always exits. use it to avoid unreachable code. 2019-02-04 04:09:13 +00:00
joerg 740128222b When using data outside the signed char range, it is better to
consistently use an unsigned char buffer.
2016-10-04 15:06:31 +00:00
tron ce945c29d6 (Hopefully) fix build without IPv6 support 2015-12-13 14:06:13 +00:00
tron 0d7f9f570d Use the proper format "[IPv6 address]:port" when reporting connection
attempts to IPv6 endpoints.
2015-12-11 08:37:31 +00:00
is 706521afb9 As discussed on tech-net@: Don't display expected EHOSTUNREACH for all but
the last connect attempts in terse mode.
2012-07-04 06:09:37 +00:00
lukem 2c9a7b42f6 Move determination of socket buffer sizes from startup to the first
time a socket is used, as the previous logic assumed AF_INET sockets
were available (which they may not be in an IPv6-only system).
Per discussion with Maxim Konovalov and the FreeBSD problem 162661.
2011-12-10 05:53:58 +00:00
joerg 6818646ac8 Use __dead 2011-09-16 15:39:25 +00:00
christos 51a4285889 fix gcc-4.5 warnings 2011-08-14 12:58:15 +00:00
lukem 3f853671ff Back to using 'RFC xxxx' instead of 'RFCxxxx' 2010-03-05 07:41:10 +00:00
jld 882877eb33 Unbreak the build by adding curly braces to placate the empty-body warning. 2009-04-15 03:42:33 +00:00
lukem 3d4efc3511 Fix numerous WARNS=4 issues (-Wcast-qual -Wsign-compare). 2009-04-12 10:18:52 +00:00
lukem d8b47884a2 fix -Wshadow issues 2009-04-12 07:07:41 +00:00
skd 315d173b9f Add epsv6 and epsv to disable extended passive mode for ipv6 or both ipv4 and ipv6 respectively. This hack is due to our friends a Juniper Networks who break
epsv in ipv6.  Should be fixed in ScreenOS 6.2.X.
2008-05-10 00:05:31 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
lukem b81e94d02a Use the service name to getaddrinfo() (along with the host name), so that
features such as DNS Service Discovery have a better chance of working.
Suggested by David Young <dyoung>.

Display the service name in various status & error messages.

Don't getservbyname() the :port component of a URL; RFC 3986 says it's
just an unsigned number, not a service name.
2008-04-22 12:59:33 +00:00
lukem d4aed48135 Rename HAVE_STRUCT_SOCKADDR_SA_LEN to HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
to accurately reflect the structure member being used.
2007-12-05 00:15:25 +00:00
lukem 6470c9506d Replace HAVE_SOCKADDR_SA_LEN with defined(HAVE_STRUCT_SOCKADDR_SA_LEN) 2007-07-22 05:02:50 +00:00
lukem f4f2ed1c79 Display times in RFC2822 form rather than using ctime(3), since
the former is more explicit about the timezone offset.
2007-05-24 05:05:18 +00:00
lukem c007c5280e * Modify parse_url() to consistently strip the leading `/' off ftp URLs.
Fixes PR 17617.
* Use 'RFCnnnn' (with leading 0) instead of 'RFC nnnn', to be
  consistent with the style in the RFC index.
* Refer to RFC3916 instead of 1738 or 2732.
* Expand the list of supported RFCs in ftp(1) to contain the document
  name as well.
2007-05-15 23:54:18 +00:00
lukem 82552a7668 Implement copy_bytes() to copy bytes from one fd to another via the
provided buffer, with optional rate-limiting and hash-mark printing,
using one loop and handle short writes.
Refactor sendrequest() and recvrequest() to use copy_data().
Addresses PR 15943.
2007-05-10 05:17:10 +00:00
lukem bab591a531 fix rev 1.144: initconn() may be called with verbose==-1 (e.g., during remote
completion), so only print out the successful EPSV response if verbose>0.
2007-04-18 01:50:45 +00:00
lukem 8a06b9bff0 * Implement -s srcaddr; uses srcaddr as the local IP address for all
connections.
  Based on code in the version of ftp that FreeBSD had before they
  replaced it with lukemftp.
* Move error message handling into ftp_connect() rather than in the
  caller, so that more specific error reporting can occur.
* Improve consistency of various warning and error messages.
2007-04-17 05:52:03 +00:00
lukem 31835c3a13 Replace a "while" with an "if" since the code path only gets executed once. 2007-04-16 00:43:43 +00:00
lukem 00e5aa03ea whitespace pedantry 2007-04-12 04:18:22 +00:00
lukem ea73350dac Suppress printing non-COMPLETE reply strings from EPSV and EPRT, as we're
going to fall back to PASV / PORT (respectively) if the former fail,
and this avoids printing a failure reply followed by a success reply.
Should fix a problem with the emacs ftp wrapper.
2007-04-11 05:03:25 +00:00
christos 748af04e26 gcc4 does not care about &foo; use volatile instead. From Anon Ymous 2006-12-13 18:04:08 +00:00
christos f2640eb139 simplify 421 printing code (jani at xeebioneurope dot de) 2006-10-23 19:53:24 +00:00
elad 3bd9466e80 PR/32855: der Mouse: [dM] ftp -q is broken (or misdocumented)
Patch applied, thanks!
2006-10-07 10:49:14 +00:00
mrg 084c052803 quell GCC 4.1 uninitialised variable warnings.
XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
2006-05-10 21:53:14 +00:00
christos 61e04d677f Coverity CID 874: Don't check local; it cannot be NULL. 2006-04-28 20:06:50 +00:00
christos fc5177078a Coverity CID 875: local is not allowed to be NULL; don't check for it. 2006-04-28 20:05:43 +00:00
christos 76fc0d5b65 rename debug to ftp_debug. grr libssh. 2006-01-31 20:05:35 +00:00
christos e22794108e Rename xfoo() to ftp_foo() to avoid collisions with libssh. Don't ask. 2006-01-31 20:01:23 +00:00
christos b232679f19 Add NO_USAGE and NO_DEBUG so that we can fit in the floppies again. 2005-06-29 02:31:19 +00:00
lukem ddc3d4ca5a Implement:
int getline(FILE *stream, char *buf, size_t buflen, const char **errormsg)
	Read a line from the FILE stream into buf/buflen using fgets(), so up
	to buflen-1 chars will be read and the result will be NUL terminated.
	If the line has a trailing newline it will be removed.
	If the line is too long, excess characters will be read until
	newline/EOF/error.
	Various -ve return values indicate different errors, and errormsg
	will be changed to an error description if it's not NULL.

Convert to use getline() instead of fgets() whenever reading user input
to ensure that an overly long input line doesn't leave excess characters
for the next input operation to accidentally use as input.

Zero out the password & account after we've finished with it.

Consistently use getpass(3) (i.e, character echo suppressed) when
reading the account data.  For some reason, historically the "login"
code suppressed echo for Account: yet the "user" command did not!

Display the hostname in the "getaddrinfo failed" warning.

Appease some -Wcast-qual warnings.  Fixing all of these requires
significant code refactoring.  (mmm, legacy code).
2005-06-10 00:18:46 +00:00
lukem c7115c2b93 * Only print the "Trying <address>..." message if verbose and
there's more than one struct addrinfo in the getaddrinfo() result.
* Don't use non-standard "u_int".
2005-06-01 12:10:14 +00:00
lukem 7f321b8850 Fix some cast issues highlighted by Scott Reynolds using gcc 4 on OSX.4 2005-05-14 15:26:43 +00:00
lukem 8b69a0f5ac * Correct the "optlen" argument passed to getsockopt(3) and setsockopt(3)
in various places.  Fixes a problem noted by Allen Briggs.
* Improve warning printed when connect(2) for the data channel fails.
2005-05-13 05:03:49 +00:00
lukem 9ffae1bf46 Use socklen_t instead of int as the 5th argument to getsockopt().
Improve invocation of setsockopt() and associated failure messages.
2005-05-11 02:29:12 +00:00
lukem b7856deff5 typo in previous 2005-04-11 05:47:56 +00:00
lukem a2fc7ddaf6 gratuitous whitespace cleanup (before someone else jumps the gun...) 2005-04-11 01:49:31 +00:00
lukem 50ff8d4548 Implement a timeout on the accept(2) in dataconn() and the
connect(2) in xconnect() by temporarily setting O_NONBLOCK
on the socket and using xpoll() to wait for the operation
to succeed.
The timeout used is the '-q quittime' argument (defaults to
60s for accept(2), and the system default for connect(2)).
Idea inspired by discussion with Chuck Cranor.
This may (indirectly) fix various problems with timeouts
in active mode through broken firewalls.

Implement xpoll() as a wrapper around poll(2), to make it
easier to replace on systems without a functional poll(2).
Unconditionally use xpoll() instead of conditionally using
select(2) or poll(2).
2005-04-11 01:43:31 +00:00