Commit Graph

78 Commits

Author SHA1 Message Date
lukem 3f8b92b0b3 * factor out SIGINFO setting into a handler that is always active (but only
prints out info if bytes > 0). only set the handler if SIGINFO is defined
* hijack SIGQUIT to be the same as SIGINFO (foreign ports have this, and it's
  annoying to have SIGQUIT dump core on netbsd when it prints info on other
  systems)
* in {recv,send}request(), factor a lot of duplicated code out into a
  `cleanup' section at the end
* rework shell() a bit
1999-10-05 13:05:39 +00:00
lukem f45505380a add TNFi copyright to all files i've done more than a minor amount of work to... 1999-10-05 01:16:11 +00:00
lukem 4309cfaab3 enhancments from Marc Horowitz <marc@mit.edu> to improve connection timeouts:
* implement xsignal_restart(), which only sets the SA_RESTART flag if
  specifically requested
* xsignal() is now a wrapper to xsignal_restart(). INFO, USR1, USR2 and WINCH
  are restartable, ALRM, INT, PIPE and QUIT are not.
* improve getreply()'s timeout code to take advantage of the above.

other changes:
* improve wording of how globbing works for `classic' URLs (host:path).
  suggested by John Refling <johnr@imageworks.com> in relation to PRs
  [bin/8519] and [bin/8520]
* always compile in the `edit' command even if NO_EDITCOMPLETE defined.
  it's just a no-op in the latter case, which is more consistent to
  the users.
* always compile in about: support (i.e, remove NO_ABOUT).
  i'm entitled to some vanity in this program...
* clean up some whitespace
1999-10-05 00:54:07 +00:00
lukem 670c7ebebd restart_point is a global; no need for it here 1999-10-01 09:23:32 +00:00
lukem fcb1a22a1c If EPSV or EPRT fails, disable epsv4 for the rest of the current connection.
the disabled state can be overridden by toggling epsv4.

(I got sick of the errors about EPSV not being supported on almost
every server I connect to. This way we retain support for epsv4, but
it's not so whiny after the first failure...)
1999-10-01 08:01:12 +00:00
lukem ad70c1982e prefix the global variables in ftp_var.h with GLOBAL, which defaults
to "extern" if it's not set. define GLOBAL to (empty) in main.c.
this effectively moves all the globals into main.c whilst retaining
namespace access to them in other source files.
(global vars in header files confuse foreign linkers)
1999-10-01 06:55:44 +00:00
lukem 25790d921d * In the !NI_NUMERICHOST case (i.e, getaddrinfo() challenged systems), portnum
should be in host order. found/fixed by Matthias Pfaller <leo@dachau.marco.de>
* parse_url(): improve checking of portnum, and add an extra argument to pass
  back the parsed portnum to the caller (reduces a bit of code duplication)
* Move the KAME/WIDE copyrights after the BSD/TNFi ones. Since there was
  significantly less code added under the former, it's only fair on the latter.
1999-09-30 23:51:26 +00:00
lukem c4a3ce23de in empty(), FD_ZERO(&rmask) not (&cin). (hi christos! :)
fixes abort_remote() when __USE_SELECT is defined.
thanks to simonb@netbsd.org for reporting this bug
1999-09-30 06:35:13 +00:00
lukem 9f5bda2e21 * consistentnly use memset(a,0,c); there were some cases of memset(a,'\0',c)
* remove explicit extern int h_errno; it's in <netdb.h>
* add <termios.h> back to util.c; it contains struct winsize on some systems
1999-09-29 00:44:01 +00:00
lukem 8c29ac4ade remove debugging cruft 1999-09-28 07:51:05 +00:00
lukem 256fc138f1 * add new commands:
lpage	page local files
	pdir	as dir, but through your $PAGER
	pls	as ls, but through your $PAGER
* implement docase() (a la dotrans() et al) and use appropriately, rototilling
  some duplicated code
* globulize(): modify to return a pointer to the strdup()ed result in all cases,
  and hack the code that calls it to take this into account
* replace strcpy() and strncpy() with strlcpy()
* put(), getit(): use some aptly named local vars instead of argv[...]
* delint
1999-09-28 06:47:38 +00:00
lukem 70c01ac44a * idle(): rename to idlecmd(). certain linux distributions have an incompatible
prototype for idle() in <unistd.h> (which i thought was against namespace
  and sensibility guidelines, but...)
* consistently use xsignal() instead of signal(). we get known behaviour
  in all cases (SA_RESTART), which is good for some borken foreign systems.
* remove signal.h from most files; it's unnecessary now
* fetch_url(): use `long chunksize' instead of ssize_t; it's more portable, and
  we're setting chunksize with strtol() anyway
* xsignal(): only use SA_RESTART if it exists. SunOS 4.x doesn't have it
  but has the inverse (SA_INTERRUPT). the original function i was inspired
  from had this support (lib/signal.c, W. Richard Stevens' `UNP 2nd ed Vol 1').
* remove <termios.h> from util.c; it should be unnecessary now
1999-09-27 23:09:42 +00:00
lukem a222db7c70 * use %lld instead of %qd to print out (long long) vars.
(slightly more portable; e.g, solaris supports this)
* remove some fluff (lint)
1999-09-24 14:28:14 +00:00
lukem ec4e414dc8 fix a couple of thinkos in my recent work:
* abort_remote(): replace borken MIN(4,BUFSIZ) with just BUFSIZ; it
  should have been MAX(4,BUFSIZ), but it's probably safe to assume that
  BUFSIZ is at least 3... (fix from simonb)
* auth_url(): use the correct variable when calculating a buffer size.
1999-09-24 06:57:37 +00:00
lukem 700e3c1ec7 * add support for `xferbuf', which sets both `sndbuf' and `rcvbuf'
* document the above three commands
* rototill the way the sndbuf and rcvbuf work. remove resetsockbufsize()
* use the appropriate socket buffer size as the size of the buffer that
  the read()/write() loops use. speeds up things in some cases.
1999-09-22 07:18:31 +00:00
lukem 5d3667b758 replace snprintf() with strlcpy(), strlcat(), or direct assignment
where appropriate. (strlc*() are easier to port to foriegn systems).

XXX; there's still a few snprintf's in the progress meter stuff to convert
1999-09-22 03:01:53 +00:00
lukem 84e2c387e7 * protect more of the AF_INET6 stuff with #ifdef INET6 (for portability)
* in the main data moving loops only call the initial gettimeofday() if
  rate throttling is enabled (saves a system call per loop when not
  throttling).
1999-09-21 13:17:22 +00:00
mycroft a502b0ee92 warn()->warnx() in a couple of places. 1999-09-14 22:49:14 +00:00
itojun a4e46e8ae8 sync with recent kAME.
- avoid s6_addr{8,16,32} which are nonstanard.
1999-09-03 04:29:57 +00:00
itojun b59b162709 ftpd(8): Copy sin6_scope_id from control connection to active data
connection destination, hoping this to help ftpd's behavior with
scoped IPv6 addresses.
I'm not sure if it is the right way, but it is the best way available to us.
LPRT or EPRT command gives no information about which interface (or scope)
to be used for new data connection.

ftp(1): On data connection establishment, warn if scoped address is used.
If peer (ftp daemon) does not handle scoped address, data connection
may not work right.

This seems to be sort of protocol spec hole, not implementation issue.
1999-09-01 05:03:41 +00:00
christos 2cec9705c5 make ftp work again with the traditional gethostbyname/getservbyname
interfaces.
1999-08-29 22:21:57 +00:00
itojun 31055e9319 cleanup EPSV return code checking part.
remove debug fputs() left by mistake.
1999-07-20 17:52:03 +00:00
itojun a382c0c34d avoid false warnings on 22x reply code checks. previous code was too picky.
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
1999-07-17 22:39:18 +00:00
itojun 1e44889b75 implement more fallback case for EPSV. BSDI ftpd is very broken
that it returns status 228 against EPSV, where it must return status
of 229.

separate PASV and LPSV processing.

PR: 7976
1999-07-13 21:43:31 +00:00
itojun 940276557f add epsv4 command, which enable/disable the use of EPSV/EPRT.
this is mainly for (hypothetical) ftp server which disconnect clients
that use EPSV/EPRT.  I've never seen any ftp server like this, but
epsv4 command may be of use when such an ftp server is found.
1999-07-11 20:37:39 +00:00
christos 17e6e111b9 oops, need to declare tos. 1999-07-11 00:41:59 +00:00
christos 5d5741e3ba Kludge around non 4.4BSD systems that don't have a length field in struct
sockaddr*.
1999-07-10 20:46:42 +00:00
christos 2107d6d2da remove unused variable 1999-07-10 19:41:01 +00:00
itojun 2091d363f0 free dynamically allocated storage on error. 1999-07-03 05:49:57 +00:00
itojun 81ed739f62 clearify socket/connect loop. 1999-07-03 05:44:11 +00:00
itojun d1a8e792f7 add dual-stack (IPv4/v6) support. hope I broke no other part... 1999-07-02 08:07:40 +00:00
lukem a3f3aa25fd make a pointers static again (that were made automatic as part of the
xfer rate stuff, but i never completed the changes that didn't need it
set).
fixes a coredump noticed on current-users@ by Chan Yiu Wah <c5666305@hkstar.com>
1999-07-02 05:41:45 +00:00
lukem e25749a582 [fear this; more ftp hacking from lukem :-]
features:
---------
* transfer rate throttling with the new `rate' command. syntax:
	rate direction [max [incr]]
  where direction is `all', `get' or `put'.
  if max is not supplied, the current settings are displayed.
  if max is supplied, then transfers in the given direction will
  be throttled to this value.
  if incr is supplied, the increment for the `on-the-fly' scaling
  will be set to that, otherwise `1024' is used.
  currently implemented for binary get, binary put, and url fetches.
  not yet supported for ascii get or put, or local file copies.
* on-the-fly scaling of the throttle based on signals:
    - SIGUSR1 raises the throttle rate by the increment for that direction
    - SIGUSR2 lowers the throttle rate by the increment for that direction
* -T dir,max[,incr] option to set rate from the command line
* `k', `m', `g' suffix support for bytecounts in the `hash', `rate',
  `rcvbuf' and `sndbuf' commands)

bug fixes and code mods:
------------------------
* fix up ftp_login() so that ruserpass() is always called, even for
  command-line url fetches.
* implement strsuftoi(), which parses a given number into a int with
  suffix support. replaces getsockbufsize()
* implement parserate(), which does the argv parsing for -T and rate
* save and restore errno in signal handlers (may not be necessary, but
  it doesn't hurt)

notes:
------
the rate command has had reasonable testing, but I'd like feedback
if it doesn't do the right thing, especially from people on slower
(i.e, modem) links.
I haven't tested the rate throttle against a http server which does
`transfer-encoding: chunked' because I couldn't find a server to
test against.
1999-06-29 10:43:16 +00:00
christos 35bc148b21 rework empty() to work with both select and poll and abstract it better. 1999-06-24 14:50:56 +00:00
lukem f7540e6f75 * fix gate mode to login as `user@realhost' rather than using PASSERVE;
the latter only seemed to work for TIS Gauntlet and not TIS fwtk.
  thanks to simonb@netbsd.org for testing this. fixes [bin/5556].
* if EOF (e.g, ^D) is entered at a username/password/account prompt which
  happens to use fgets(), exit the login rather than treating EOF as CR.
* don't use the comma operator where separate statements are valid
* always use snprintf to copy stuff into malloced buffers, just in case
  typos creep in and mean that the buffer ends up being overflowed
1999-06-02 02:03:57 +00:00
lukem 25bacdd4ea print the "xxx bare linefeeds" message after the progressmeter. noted by dan@ 1999-05-04 14:12:37 +00:00
lukem f55d4712e3 * make parsing of ftp:// urls more RFC 1738 compliant;
- the path is split on `/', and each directory is CWD-ed into separately.
      (from [standards/7484] by Alan Barrett <apb@iafrica.com>)
    - support a trailing `;type=X' suffix, where X is a,i, or d.  (d isn't
      implemented, but it is recognised)
    - the only non-compliant behaviour is that empty directories sections
      (e.g `//') aren't run as `CWD ' - as a lot of ftpds don't like that.
      Instead, treat this as a no-op.
* don't support globbing for ftp urls, since that's technically not
  RFC compliant.
* fix a couple of man-page nits
1999-04-28 13:35:40 +00:00
lukem 48923b69bf support restart during proxy transfers (the traditional ftp command, not the
http proxy). seems to work with my limited testing (i'm not a big user of
proxy).  bug noted by Jorgen Lundman <lundman@argonaut.com> in [bin/5948]
1999-02-19 16:29:27 +00:00
lukem 0bd80459cb * -v enables verbose & progress, -V disables both
* set setvbuf(ttyout, NULL, _IOLBF, 0) and remove a bunch of fflush(ttyout).
* use fwrite() instead of write() for progressmeter (don't intermix stdio
  with non stdio ops)
1999-01-24 02:39:29 +00:00
lukem a877181317 Fall back from passive to active if connect() fails. (from openbsd) 1999-01-05 23:33:44 +00:00
lukem 688446255e * implement xsignal(); same semantics as signal() but uses sigaction
with an explicit SA_RESTART. (needed for portability)
* use xsignal() for SIGALRM and SIGINFO handlers
1998-08-08 06:46:01 +00:00
lukem 4a8ec5494d features:
* support $no_proxy, which is a comma or space separated list of
  host[:port] elements for which proxying is to be disabled.
  (asked for by cgd in [bin/5027])
* if $FTPANONPASS is defined, use that as the anon ftp password
  (instead of "`whoami`@")
* allow http URL's without a filename as long as an output file
  is specified.

other stuff:
* implement parse_url(), which breaks up a URL into its bits, and use.
* simplify url_get() and auto_fetch() to use parse_url() and to not
  modify the supplied URL or a copy of it.
* implement xmalloc() and xstrdup(); error-checked malloc()/strdup()
* add more consistency to messages, quoting strings in output as `%s'
1998-08-03 01:49:25 +00:00
thorpej 7a12770f94 Add "sndbuf" and "rcvbuf" commands for setting the socket buffer sizes,
which in turn can allow the use of larger TCP windows.  This is a work in
progress; there is not yet support for specifying global defaults or
user prefrences on a host/network basis.
1998-07-10 04:39:03 +00:00
lukem 9a6e9b2ce7 some fixes & enhancements from openbsd's ftp, with extra fixes by me:
* default to passive with active fallback. $FTPMODE modifies this behaviour.
  -A forces active connection.
* support '-o outfile' for auto-fetched files. outfile can be a file,
  `-' (for stdout), or '|command' (to output each file through command).
* support '-r waittime', which retries the connection after waittime seconds
  if it fails.
* fix 'page file' when restart is non-zero.
* try all ip-addresses of a host in a http fetch (as the normal ftp fetch
  does).

XXX: a ``broken pipe'' error sometimes occurs with -o '|command';
i haven't tracked this down yet.
1998-06-04 08:28:35 +00:00
pk 44c785c1cd Restore `preserve' value when we no longer need the modified version. 1998-05-20 09:43:41 +00:00
christos 9160dcee94 - add <signal.h> since we are using signals.
- add <sys/time.h> since we are using utimes
- don't require quad_t to exist to compile.
1998-05-20 00:54:52 +00:00
kleink 650b9ca681 Need <time.h> for asctime() and localtime() prototypes. 1998-04-01 21:07:03 +00:00
lukem 7ee412ebee * ensure buffer for username is initialised, so ^D on username prompt
doesn't use garbage for the username.  from "Soren S. Jorvang" <soren@t.dk>
  in [bin/4559]
* use in_port_t for ports, and USHRT_MAX instead of 0xffff
  (from millert@openbsd.org)
* use `NULL' instead of `(.... *)0' where appropriate.
1998-01-18 14:23:33 +00:00
lukem d067f3bbd2 * in recvrequest(), ignore restart_point unless "RETR"ieving. fixes problems
where a remote completion or `mget' would confuse the client a `restart'
  had been issued beforehand. now, `restart' is remembered until an operation
  that can actually use it is invoked.
* in sendrequest(), don't reset restart_point upon entry. fixes `restart'
  for `put' operations.
* if `restart' is invoked with no arguments, print current setting instead
  of displaying a usage
* consistently use printf("%qd", (long long)restart_point) when displaying
  restart_point
* use strto[lq]() instead of atol() when parsing `mark' and `restart' values
* remove unnecessary strlen()s when result of previous snprintf() will do
* replace a few malloc()/strcpy()s with strdup()s
* use SECSPERHOUR instead of '3600'
1997-11-01 14:36:49 +00:00
mycroft b66f8512e6 Use S_IS*(), not S_IF*. 1997-10-19 19:09:05 +00:00