Commit Graph

513 Commits

Author SHA1 Message Date
jmc 3f5fc9a18d Need to #ifdef around declaration of ch with NO_EDITCOMPLETE so this compiles
on rescue/miniroot's
2005-06-10 18:24:15 +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 cc5aca9af5 copyright maintenance 2005-06-09 16:38:29 +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
he d316ef3d77 Printf field widths and size_t don't always mix well, so cast to int.
Fixes build problem for alpha.
2005-05-20 07:26:01 +00:00
jdc 9c9b601a23 Make this compile on sparc64 (size_t != int). 2005-05-20 06:13:23 +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 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 1a090f24c2 correct a comment 2005-05-07 16:19:13 +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
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
wiz aa3d6fa3ca If we mark up RFC, then avoid using "command modifier" for it. 2005-02-20 20:54:01 +00:00
jmc 51da0bca2c As dsl points out, sysinst uses the progress bar so put it back on SMALLPROG 2005-02-11 15:13:28 +00:00
simonb 3cebd9325e White space nit- don't put a space before/after increment/decrement
operators.
2005-02-11 06:21:21 +00:00
jmc dc984029fd White space nit 2005-02-10 16:00:38 +00:00
jmc 5f0e6eb14f Fix compilation issues for NO_PROGRESS 2005-02-10 16:00:28 +00:00
jmc c55ede16a2 Add NO_PROGRESS for -DSMALL 2005-02-10 16:00:06 +00:00
christos 199b39279a Factor out common string processing code eliminating static buffers,
making functions that should be static be static, and cleaning up
const usage. Added a guard against buffer overflow, but the domap function
is a bit too complicated for me to tackle right now. I will leave it
to the author; hi luke!
2005-02-09 23:17:27 +00:00
lukem 44ad084298 preempt wizd; crank date 2005-01-15 21:28:16 +00:00
lukem 349815e5ed Expand description of http_proxy by suggesting the use of RFC 1738 '%xx'
encoding for "unsafe URL" characters in usernames and passwords.
2005-01-15 21:27:46 +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 7157011597 Only compile in IPv6 support if ${USE_INET6} != "no"
MKINET6 is for providing IPv6 infrastructure.
USE_INET6 is for compiling IPv6 support into the programs (needs MKINET6).
2005-01-10 02:58:58 +00:00
lukem 9683394bbb fix copyright year 2005-01-04 23:59:11 +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
wiz 5dfef2f2bd Fix typo. 2004-12-01 12:03:55 +00:00
dsl e833833eb1 Add (unsigned char) cast to ctype functions 2004-10-30 17:29:47 +00:00
wiz 8041597c55 Drop trailing whitespace. 2004-10-07 08:51:08 +00:00
dan 232ea9516c pre-empt wizd (bump date for previous.) 2004-10-07 07:47:31 +00:00
dan 54f2ee2a02 Note potentially surprising file-saving behaviour in case of HTTP redirects 2004-10-07 07:44:17 +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 64ab1ddb13 Don't unnecessarily display a 401/407 error when running with -V.
Fix from PR [bin/18535] by Jeremy Reed.
2004-07-20 11:22:27 +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
wiz ec6bd375e2 Add -q to usage. From Kouichirou Hiratsuka in PR 26199. 2004-07-09 12:12:27 +00:00
kleink 98fe2fbcd7 Fix an inversed test for NO_STATUS in rev. 1.103; fixes the real issue
behind PR bin/25842.
2004-06-06 13:53:28 +00:00
pooka a7fd6646a7 make this compile without NO_STATUS
fixes bin/25842 by Jukka Salmi
2004-06-06 13:37:16 +00:00
christos 4c77cb2cb2 Save approximately 8K by not including http authentication, extended status
messages and help strings when the appropriate options are set.
2004-06-06 01:37:41 +00:00
christos ce9f2915a6 PR/25566: Anders Magnusson: ftp(1) do not like large TCP windows.
Limit it to 8M.
2004-05-14 18:39: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
lukem aacb86f622 whitespace consistency tweak 2004-04-10 12:02:43 +00:00
hubertf 849866f9c1 Allow custom text printed before (left of) the progress bar from progress(1):
miyu# cat openoffice-linux-1.1.0.tgz | progress -z -p 'Bytes written: ' dd of=/dev/null bs=1m
	Bytes written:    193 MB   13.83 MB/s 0+195211 records in
and:
	miyu# progress -f openoffice-linux-1.1.0.tgz -z -p 'Bytes written: ' dd of=/dev/null bs=1m
	Bytes written:  28% |******                | 57919 KB   14.12 MB/s    00:09 ETA

OK'd by lukem.
2004-03-09 17:04:24 +00:00
lukem 69e6f0aa33 -n is ignored for auto-fetch transfers 2003-12-19 03:46:02 +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 037eb18f90 correct URL syntax in comment 2003-12-04 12:51:18 +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 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 8d51fbf035 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@comp.chem.msu.su>.
2003-07-31 07:06:41 +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 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
salo 0f5a0c156d netbsd.org->NetBSD.org 2003-07-26 20:34:11 +00:00
lukem 9cfea6f679 tweak copyright; the stuff jason did in util.c wasn't migrated to this file. 2003-07-17 12:06:18 +00:00
itojun 032ed69f9a strlcpy 2003-07-12 13:23:55 +00:00
lukem 7d830fa777 tweak previous; no need to have .Sm on and then just .Sm off 2003-07-09 08:09:04 +00:00
wiz b93a29cdaa Fixes to make these man page look nice with groff-1.19. 2003-06-30 19:12:31 +00:00
wiz 80cc7b7a7b Quote punctuation so macro works on it (another one). 2003-06-26 17:48:37 +00:00
wiz e6ebf10cb2 Quote punctuation so macro works on it. 2003-06-26 17:47: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
wiz d75f1336b3 Uppercase URL. 2003-05-14 14:30:59 +00:00
grant 7d55c4c504 fix a bogus error message when given a HTTP URL with a trailing
slash.
2003-03-07 08:13:48 +00:00
lukem c84f3c0dd2 crank dates 2003-02-28 09:54:51 +00:00
lukem e7d3948066 crank version 2003-02-28 09:54:20 +00:00
lukem a44810ddeb Crank dates on TNF copyright.
Remove UCB & WIDE copyrights; the progressbar functionality was
written entirely by me under the TNF copyright.
2003-02-28 09:53:49 +00:00
lukem 7106b560a6 add a cast to appease SUNWspro cc. noted by grant@ 2003-02-28 04:06:55 +00:00
wiz 990562bfef .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
2003-02-25 10:34:36 +00:00
grant 2ceb845887 The correct capitalisation of 'NetBSD.org' is (you
guessed it) 'NetBSD.org'.

some mdoc fixes.
2003-02-14 15:59:16 +00:00
grant d36ebd361d change a couple #ifdef's so /usr/bin/progress doesn't stomp all over
the tty if it's not in the foreground.

ok'd by jhawk.
2003-02-12 15:18:28 +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
wiz 9be5fcf7bc Bump date for last. 2003-01-20 08:08:34 +00:00
toddpw fb9b804063 Add a "macdef" example and a short section explaining that you may need to
use it to disable extended passive mode when your firewall is obnoxious.
This did in fact solve a problem I was having with a firewall at work, and
the status message was taken directly from a problem session fixed by this.
2003-01-20 03:20:42 +00:00
lukem d348d3d723 tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
2002-11-30 03:10:53 +00:00
lukem b81a1d9903 - if SMALLPROG is defined, add -DNO_EDITCOMPLETE -DNO_ABOUT,
and don't bother linking with -ledit -ltermcap
- if SMALLPROG is not defined or SMALLPROG_INET6 is defined, add -DINET6
2002-10-17 06:16:48 +00:00
wiz 20fb5b240f Typo and Americanism. From Adrian Mrva. 2002-10-02 15:56:27 +00:00
grant be8ae688ae New sentence, new line. 2002-09-30 11:08:56 +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
lukem a791673973 Improve description of help text for "passive".
Noted by Yar Tikhiy <yar at FreeBSD.org> in private email.
2002-07-29 04:24:47 +00:00
itojun 374ba6170a strdup -> xstrdup (handle malloc error right) 2002-07-12 03:05:13 +00:00
lukem 4b9ba774c6 Various improvements in wording and marking,
from Alan Barrett <apb@cequrux.com>, with a bit of tweaking from me.
2002-07-07 10:40:31 +00:00
lukem f7f117dc43 highlight that for ftp:// auto-fetches, read access is required on
intermediate directories because ftp(1) obeys RFC1738.  for [bin/15419]
2002-07-04 06:39:28 +00:00
yamt ebba433f59 make an auto const variable static. 2002-06-08 14:44:07 +00:00
lukem 29559300fb - use setprogname()
- only support -6 if INET6 is defined
2002-06-05 13:51:54 +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 964e8f45d1 Fix description for "form", "mode", and "struct" commands.
Inspired by [bin/16736] from Steve McClellan <steve.mcclellan@radisys.com>
2002-05-18 03:00:13 +00:00
lukem 3bf21f2fec Use "r+" instead of "r+w", since the latter is not standard.
Noted by <Steve.McClellan@radisys.com> in private email.
2002-05-07 02:04:09 +00:00
lukem 32b641335c Handle URLs without files correctly (e.g, when using '-o -').
Fix from Anders Dinsen <anders@dinsen.net> in [bin/13768]
2002-05-06 15:03:30 +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