Commit Graph

135 Commits

Author SHA1 Message Date
jnemeth c287edd2a0 Coverity CID 3610: derefencing NULL pointer. 2006-05-23 23:59:48 +00:00
christos 69f8117233 Coverity CID 873: Only align if we printed a string. 2006-04-28 20:07:57 +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 b771909d19 forgot to remove the file pointer from the macro. 2005-06-29 05:00:30 +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 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 943e24eb27 tab cleanup 2005-05-19 03:14:52 +00:00
lukem dc6635b518 Use size_t instead of int where appropriate. 2005-05-19 03:05:04 +00:00
lukem 947172fa2b Some const cleanups. 2005-05-19 02:55:37 +00:00
dsl 4ed2a0cea6 Helps if the definition of xconnect() matches its declaration.... 2005-05-14 18:56:45 +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 1a090f24c2 correct a comment 2005-05-07 16:19:13 +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
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 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 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
agc 89aaa1bb64 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22365, verified by myself.
2003-08-07 11:13:06 +00:00
lukem 90bb61be44 * 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.
* Improve formatting of features[] debug dump.
2003-07-31 06:57:07 +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 c84f3c0dd2 crank dates 2003-02-28 09:54:51 +00:00
jhawk 401927b1d5 Abstract out progress bar support into progressbar.[ch], for inclusion
in external programs (conditionalized on -DSTANDALONE_PROGRESS).

The following moved from util.c to progressbar.c:
  alarmtimer(), progressmeter(), psummary(), ptransfer(),
  xsignal(), xsignal_restart()

The following moved from extern.h and ftp_var.h to progressbar.h:
  STALLTIME, verbose, fromatty, progress, quit_time, ttywidth
2003-01-21 16:08:06 +00:00
christos 8bb1db1740 Add a -q <quit-time> flag to abort a transfer if it has stalled for <quit-time>
seconds. Ok'd by luke.
2002-08-27 13:11:02 +00:00
yamt ebba433f59 make an auto const variable static. 2002-06-08 14:44:07 +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 eda0427e63 update copyrights 2001-12-26 09:40:15 +00:00
cgd a8ec668ddf convert to use getprogname() 2001-02-19 23:03:42 +00:00
lukem 83a00b2109 - display a limited progress bar (containing bytes xferred and xfer rate)
when the file size is unknown
- disable progress bar during remglob()
2001-02-19 20:02:42 +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 52b579665e always include <netdb.h>, not just when INET6 is defined.
resolves PR [bin/10970] by Richard Earnshaw <rearnsha@cambridge.arm.com>>
2000-09-08 11:54:53 +00:00
lukem 872f81b081 - in progressmeter() perform the check for foregroundproc() a little earlier
- removed unused variable `items' in list_vertical()
2000-08-27 06:31: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 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 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 2c9a4cf5d0 convert to ANSI KNF 2000-05-01 10:35:16 +00:00
lukem d16e624b57 * Add support for `fget localfile', which reads a list of filenames to
retrieve from localfile.  Based on work by Darren Reed.
* Crank version.
* Update copyright dates.
2000-05-01 09:44:53 +00:00
itojun f70ccb3744 allow IPv6 extended numeric address in host part.
(draft-ietf-ipngwg-scopedaddr-format-01.txt)
fixes PR 9616.
2000-04-24 05:59:39 +00:00
lukem 031f2ed4b1 s/strtoq/strtoll/ (the latter is standardised) 2000-04-13 08:13:30 +00:00
lukem 7044ee274b define private type `sigfunc' as
typedef void (*sigfunc) __P((int));
and replace use of sig_t and void (*)(int).

certain other OSes define sig_t differently to that (they add extra arguments),
and it causes problems due to function mismatches, etc...
2000-01-31 22:01:03 +00:00
lukem 0ac52b3131 roll back to using sscanf() instead of strptime() to parse `yyyymmddhhmmss'
strings, since the latter technically can't parse dates without non
alphanumerics between the elements (even though netbsd's strptime() copes).
2000-01-26 11:31:55 +00:00
lukem d2196602e3 put spaces between the % specifiers in the strptime format string 2000-01-26 10:15:40 +00:00
lukem ec9eefea83 be harsher about workaround 2000-01-25 06:45:18 +00:00
lukem 852392d00d work around lame ftpd's that don't return a correct post-Y2K date in
the output of `MDTM'.

obviously the programmer of aforementioned lame ftpd's did something like
	"19%02d", tm->tm_year
instead of
	"%04d", tm->tm_year + TM_YEAR_BASE

fixes [bin/9289] by jbernard@mines.edu
2000-01-25 06:11:00 +00:00
itojun 05e574f6a9 fix memory leak in fetch_url (no freeaddrinfo was there).
sync with recent KAME.
1999-12-03 06:10:01 +00:00