Commit Graph

58 Commits

Author SHA1 Message Date
lukem af2c479f62 If a file upload (via -u) fails, return an non-zero exit value based on the
index of the file that caused the problem (a la auto-fetch retrieval).
Problem noted by A P Garcia in private email.
2006-07-26 14:28:11 +00:00
lukem c114b2eb28 Don't clear the trailing character on the auth_url() username;
we now use getline() and that newline strips for us.
Problem found & fixed by Mark Davies.
2005-08-21 16:16:33 +00:00
lukem dccca90900 Revert back to using an int (instead of size_t) for holding a value that may
be negative.
Fixes progressbar display on terminals <43 columns wide.
Bug noted and solution suggested by Gavan Fantom.
2005-07-19 00:41:05 +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 e2240cac60 * fetch_ftp(): preserve 'anonftp' across a disconnect() so that multiple
ftp auto-fetches on the same command line login automatically.
* auto_fetch(): use an initialized volatile int to appease IRIX cc.
2005-05-29 05:56:56 +00:00
lukem 4011dcc7ab formatbuf(): fix %m and %M to use the hostname, not the username. 2005-05-27 14:35:50 +00:00
lukem bed2c16589 Improve method used in fileindir() to determine if `file' is in or under `dir':
realpath(3) on non-NetBSD systems may fail if the target filename doesn't
exist, so instead use realpath(3) on the parent directory of `file'.
Per discussion with Todd Eigenschink.
2005-05-26 02:59:34 +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 9607ad079e Prevent an overly-long input line causing a core dump when editing is enabled.
Issue noted by Ryoji Kanai in FreeBSD Problem Report # 77158.
2005-05-10 22:59:52 +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
lukem ec95ee57f7 In fetch_url(), don't call freeaddrinfo(res0) too early, as we use pointers
to its contents later in the function.
Problem found by Onno van der Linden.
2005-04-10 03:13:23 +00:00
lukem f851795088 Fix ftp url reget when globs are being used.
Provided by Mathieu Arnold <mat@FreeBSD.org>.
2005-01-12 22:37:41 +00:00
lukem b918fc0803 Forbid filenames returned from mget that aren't in (or below) the
current directory.
The previous behaviour (of trusting the remote server's response when
retrieving the list of files to mget with prompting disabled) has been
in ftp ~forever, and has been a "known issue" for a long time.
Recently an advisory was published by D.J. Bernstein on behalf of
Yosef Klein warning of the problems with the previous behaviour, so
to alleviate concern I've fixed this with a sledgehammer.

Remember the local cwd after any operation which may change it.
Use "remotecwd" instead of "remotepwd".
2005-01-03 09:50:09 +00:00
lukem a76c6e6173 * Always decode %xx in a url's user & pass components.
* Only remember {WWW,Proxy}-Authenticate "Basic" challenges; no point
  in tracking any others since ftp doesn't support them.
* Improve the parsing of HTTP responses.
2004-12-10 06:44:15 +00:00
lukem d2c6dcc183 Don't base64 encode the trailing NUL in the HTTP basic auth response.
Problem noted by Eric Haszlakiewicz.
2004-08-08 13:52:04 +00:00
lukem 85e3997a42 Slightly rework SIGINT handling; if we're exiting the auto-fetch stuff
and sigint_raised is non-zero, reset the handler for SIGINT to SIG_DFL
and raise(SIGINT) so that the appropriate wait(3) status is setup.
Based on solution proposed by Ognyan Kulev.
This should really fix PR [pkg/26351].
2004-07-21 00:09:14 +00:00
lukem 635e66e7d8 Improve parsing of HTTP response headers to be more RFC2616 compliant, and
skip LWS (linear white space; CR, LF, space, tab) and the end of lines and
between the field name and the field value.  This still isn't 100% compliant,
since we don't support "multi line" responses at this time.
This should fix PR [bin/22611] from TAMURA Kent (although I can't easily
find a http server to reproduce the problem against.)

Fix a minor memory leak when parsing HTTP response headers.
2004-07-20 12:46:51 +00:00
lukem 34f004270e Ensure that "mname" is set in ls() and mls() so that an aborted confirm()
prints the correct name.
Problem highlighted & suggested fix from PR [bin/17766] by Steve McClellan.
2004-07-20 11:05:20 +00:00
lukem 1aa9c35970 If an ftp auto-fetch transfer is interrupted by SIGINT (usually ^C),
exit with 130 instead of 1 (or rarely, 0).
This allows an ftp auto-fetch in a shell loop to correctly terminate the loop.
Should fix PR [pkg/26351], and possibly others.
2004-07-20 10:40:21 +00:00
lukem f619a0eb00 Fix bug in Christos' recent cleanup which broke the "help" and "rhelp" commands. 2004-07-15 08:50:10 +00:00
lukem f3c773016a If connect(2) in xconnect() fails with EINTR, call select(2) on the socket
until it's writable or it fails with something other than EINTR.
This matches the behaviour in SUSv3, and prevents the problem when
pressing ^T (SIGINFO, which is marked as restartable) during connection
setup would cause ftp to fail with EADDRINUSE or EALREADY when the
second connect(2) was attempted on the same socket.
Problem found and solution provided by Maxime Henrion <mux@freebsd.org>.
2004-04-10 12:21:39 +00:00
lukem d11f9c3d61 Don't warn about "ignored setsockopt" failures unless debugging is
enabled.  Suggested by Todd Vierling.

Allow empty passwords in ftp://user:@host/file auto-fetch URLs,
per RFC 1738.  Requested by Simon Poole.

Update version.
2003-12-10 12:34:28 +00:00
lukem 462f170e30 crank version for:
* Work around broken ftp servers (notably ProFTPd) that can't even follow
  RFC 2389, and skip any amount of whitespace before a FEATure response.
  The RFC says 'single space' yet ProFTPd puts two.
  Noted by DervishD <raul@pleyades.net>.
* Improve formatting of features[] debug dump.
* Invalidate remote directory completion cache if any command which
  may change the remote contents completes successfully, including:
  del, mdel, ren, mkdir, rmdir, quote, and all upload commands
  Patch from Yar Tikhiy <yar@freebsd.org>.
2003-07-31 07:13:01 +00:00
lukem 6f5fbdb6de * $FTPUSERAGENT overrides the HTTP User-Agent header.
Based on patch from Douwe Kiela.
* Add about:tnftp
* Fix URL in about:netbsd
* Crank version
2003-07-31 05:23:59 +00:00
lukem 9f376c42d4 Don't coredump when printing '%n' in the prompt if there's no username yet.
Fix from Maxim Konovalov <maxim at freebsd dot org>.
2003-06-15 13:49:46 +00:00
lukem e7d3948066 crank version 2003-02-28 09:54:20 +00:00
lukem 3f4d453aef - when showing the final progress bar, replace "00:00 ETA" with the
elapsed time.  (suggested by simonb)
- actually display transfer stats after a URL fetch. (bug introduced a
  *long* time ago)
- update copyright & version
2002-06-05 10:20:46 +00:00
lukem f801eb939e - Only send port number in HTTP/1.1 Host: request if port != 80.
Fixes [bin/15415] from Takahiro Kambe <taca@sky.yamashina.kyoto.jp>
- Fix bad mode passed by mls() to recvrequest().
  Fixes [bin/16642] from <steve.mcclellan@radisys.com>
2002-05-06 14:36:41 +00:00
lukem eda0427e63 update copyrights 2001-12-26 09:40:15 +00:00
lukem 5a651467dc Add -4 to force IPv4 and -6 to force IPv6 address usage.
From Hajimu UMEMOTO, via Mike Heffner of FreeBSD.

(FreeBSD has imported NetBSD's ftp as their ftp client;
Mike is sending back some of their local changes).
2001-12-23 12:23:01 +00:00
lukem 049774ffb3 Large file ASCII mode support by using fseeko() instead of fseek().
From Andrey A. Chernov of FreeBSD, via Mike Heffner.
2001-12-20 05:45:37 +00:00
lukem 8ec0002acd invoke cmdtab.c_handler()s with argv[0] == c_name instead of the
supplied name. that way the full (unambiguous) name is displayed in
error messages and usage strings.
2000-12-15 02:22:50 +00:00
itojun 75e162d7c2 cope with 2553bis getnameinfo (always attach scope id)
getnameinfo error check.
2000-11-24 13:01:24 +00:00
lukem ecd3d78091 - implement "mreget"; as per "mget" but uses "reget" instead of "get"
- add -N netrc and $NETRC, as methods to select an alternative .netrc file
- cache local user name and home directory for further use
- in mget(), use docase() instead of a local version to do the case
  conversion.
2000-11-15 00:10:59 +00:00
lukem 0aa81b3ec3 explicitly use SOCK_STREAM with socket() instead of res->ai_socktype,
because it appears that linux with glibc doesn't set the latter
correctly after one of getaddrinfo() or getnameinfo().
2000-09-28 12:29:23 +00:00
lukem e3cdb47e47 * implement parseport(), which takes a string and attempts to convert
it to a numeric port number
* use parseport() in parse_url() and hookup()
* don't try and lookup the port number using getaddrinfo(), as it's too hard
  to separate a failed host name lookup from a failed service name lookup.
  this was causing lossage on systems that don't have `http' in services(5)
  (such as solaris), but only crept in when we started using getaddrinfo()
  unconditionally.
2000-08-06 08:51:22 +00:00
lukem 29d497f491 - rename NO_QUAD to NO_LONG_LONG, QUAD* -> LL* and add ULL* (unsigned)
equivalents. name change suggested by Klaus Klein <kjk@netbsd.org>
- change defined(BSD4_4) || HAVE_SIN_LEN tests into HAVE_SOCKADDR_SA_LEN,
  and set the latter if BSD4_4 exists
2000-08-01 22:47:25 +00:00
lukem 8c77deb113 - we can't just rename BSD4_4 -> HAVE_SIN_LEN, since bsd systems define BSD4_4;
change tests to test for either defined(BSD4_4) or HAVE_SIN_LEN
- more KNF
2000-07-31 00:56:07 +00:00
lukem 241987dc61 clean up NO_QUAD support: create helper #defines and use as appropriate:
#define		NOQUAD		! NOQUAD
	-------		------		- ------
	QUADF		"%ld"		"%lld"
	QUADFP(x)	"%" x "ld"	"%" x "lld"
	QUADT		long		long long
	STRTOL(x,y,z)	strtol(x,y,z)	strtoll(x,y,z)
2000-07-30 04:42:37 +00:00
lukem 6ac5c69c3e rename "opts" to "remopts", so people used to "o host" don't get bitten... 2000-07-28 12:01:40 +00:00
lukem 7816d2586e add support for FEAT and OPTS commands with `features' and `opts'.
(from RFC 2389).

add support for MLST & MLSD (machine parseble listings) with 'mlst', 'mlsd'
and 'pmlsd' (mlsd |$PAGER) commands.  (from draft-ietf-ftpext-mlst-11)

rename remotesyst() to getremoteinfo(), and modify to parse the result from
FEAT (if supported), and take into account the support for the various
extensions such as MDTM, SIZE, REST (STREAM), MLSD, and FEAT/OPTS.
put each feature into one of the following categories:
	- known to work (explicit FEAT)
	- unknown but assume works until explicit failure, when it's
	  then tagged as `known not to work'.
	- known not to work (FEAT succeeded but didn't return anything,
	  or was unknown and then explicit failure)
assign results into features[] matrix.

add support to getreply() so that an optional callback will be called
for each line received from the server except for the first and last.
this is used in FEAT (and MLST) parsing.

modify various commands to check if REST (STREAM), MDTM and SIZE are
explicitly or implicitly supported before using.

fix `syst' when verbose is off.

minor knf (indent goto labels by one space, etc).

simply various command usage handlers by assuming that argv != NULL except
for quit() and disconnect().
2000-07-18 07:16:52 +00:00
lukem 040253276f * migrate the SYST parsing from setpeer() into a separate remotesyst().
call remotesyst() only when login has been successful
  some servers don't let you run SYST until you've successfully logged in.
* in fetch_ftp(), always call setpeer() with autologin disabled, and use
  the following ftp_login() to DTRT.
  this prevents ftp from trying to login a second time if the first autologin
  fails when connecting to a remote site anonymously using autofetch.
* reset unix_proxy and unix_server in cleanuppeer()
* missed a function conversion in the KNF sweep...
2000-06-15 13:08:23 +00:00
lukem f970de1382 from itojun: better fix for previous (doesn't need in_addr_t or u_int32_t) 2000-06-11 15:15:52 +00:00
lukem f48d57e2d2 portability fixes for lukemftp:
* initconn(): use in_addr_t instead of u_int32_t when manipulating IPv6
  addresses (and assume anything with ipv6 has in_addr_t; if not, i'll
  add an autoconf test for it)
* ai_unmapped(): not all systems have sin_len; so only set #ifdef BSD4_4
* fix some lint
2000-06-11 02:12:05 +00:00
lukem 71c4464e3e - fix ai_unmapped() to be a no-op in the !def INET6 case
- display `(-INET6)' at the end of the version string if !def INET6
- clarify in the man page that IPv6 support may not be present (for lukemftp :)
2000-06-05 09:22:52 +00:00
lukem 413a4004df Add support for 'ftp -u url file ...', to upload a list of files to given url.
Mostly based on [bin/10019] by Scott Aaron Bamford <sab@ansic.net>
2000-05-31 14:23:57 +00:00
lukem bd22f3362b Change `ls' to use the `LIST' and not `NLST' FTP protocol command.
Now that after many years on not caring we find certain popular
ftp servers are starting to obey RFC959 to the letter of the law
and will only return a list of filenames (not directories or
other filetypes) in the output of `NLST', then `LIST' is more useful
in this case. (Note that the aforementioned pedanticness means that
filename completion isn't as useful as it could be...)
Fixes [bin/8937] by David A. Gatwood <dgatwood@deepspace.mklinux.org>
2000-05-28 07:53:30 +00:00