History log of /openbsd-current/usr.bin/ftp/util.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.98 08-Mar-2023 guenther

Delete obsolete /* ARGSUSED */ lint comments.

ok miod@ millert@


Revision tags: OPENBSD_7_2_BASE
# 1.97 19-Sep-2022 millert

Remove now-unused connect_wait() function.


# 1.96 15-Sep-2022 millert

Use non-blocking connect() with ppoll() and timeout instead of alarm().
For hosts with multiple IP addrs this makes it possible to fall
over from an unresponsive IP to another. This also replaces the
other connect(2) + connect_wait() calls with timed_connect() so the
-w option now works for more that just http. OK sthen@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 02-Feb-2021 robert

introduce support for sending the If-Modified-Since header while
fetching over http(s) and use the timestamps from the remote server's
Last-Modified header if available when saving local files
this makes it possible to mirror files better with ftp(1)

the new timestamp behaviour can be disabled with the new '-u' flag

ok sthen@, input from sthen@ and gnezdo@


# 1.94 18-Oct-2020 naddy

Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

improved and ok jca@


Revision tags: OPENBSD_6_8_BASE
# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.97 19-Sep-2022 millert

Remove now-unused connect_wait() function.


# 1.96 15-Sep-2022 millert

Use non-blocking connect() with ppoll() and timeout instead of alarm().
For hosts with multiple IP addrs this makes it possible to fall
over from an unresponsive IP to another. This also replaces the
other connect(2) + connect_wait() calls with timed_connect() so the
-w option now works for more that just http. OK sthen@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 02-Feb-2021 robert

introduce support for sending the If-Modified-Since header while
fetching over http(s) and use the timestamps from the remote server's
Last-Modified header if available when saving local files
this makes it possible to mirror files better with ftp(1)

the new timestamp behaviour can be disabled with the new '-u' flag

ok sthen@, input from sthen@ and gnezdo@


# 1.94 18-Oct-2020 naddy

Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

improved and ok jca@


Revision tags: OPENBSD_6_8_BASE
# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.96 15-Sep-2022 millert

Use non-blocking connect() with ppoll() and timeout instead of alarm().
For hosts with multiple IP addrs this makes it possible to fall
over from an unresponsive IP to another. This also replaces the
other connect(2) + connect_wait() calls with timed_connect() so the
-w option now works for more that just http. OK sthen@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.95 02-Feb-2021 robert

introduce support for sending the If-Modified-Since header while
fetching over http(s) and use the timestamps from the remote server's
Last-Modified header if available when saving local files
this makes it possible to mirror files better with ftp(1)

the new timestamp behaviour can be disabled with the new '-u' flag

ok sthen@, input from sthen@ and gnezdo@


# 1.94 18-Oct-2020 naddy

Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

improved and ok jca@


Revision tags: OPENBSD_6_8_BASE
# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.95 02-Feb-2021 robert

introduce support for sending the If-Modified-Since header while
fetching over http(s) and use the timestamps from the remote server's
Last-Modified header if available when saving local files
this makes it possible to mirror files better with ftp(1)

the new timestamp behaviour can be disabled with the new '-u' flag

ok sthen@, input from sthen@ and gnezdo@


# 1.94 18-Oct-2020 naddy

Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

improved and ok jca@


Revision tags: OPENBSD_6_8_BASE
# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.94 18-Oct-2020 naddy

Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

improved and ok jca@


Revision tags: OPENBSD_6_8_BASE
# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.93 06-Jul-2020 deraadt

in 2014 I added this annotation: /* XXX floating point printf in signal handler */
our snprintf is reentrant safe except for floating point.
Break the double apart into integer.integer notation, to avoid that.
ok kettenis millert


Revision tags: OPENBSD_6_7_BASE
# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.92 18-Nov-2019 deraadt

various knf and whitespace; ok jca


Revision tags: OPENBSD_6_6_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.90 28-Jun-2019 deraadt

mkstemp() returns -1 on failure


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.89 16-May-2019 florian

Revert suni'ls ftp rewrite for now.
We are juggling too many things at the moment and we can't deal with
the differences in behaviour right now.


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.88 12-May-2019 jasper

add rcs ids


# 1.87 12-May-2019 kmos

Move us from old ftp(1) to Sunil's new ftp(1). The necessary modifications
have been made to make it behave. Any new misbehaviors can be fixed in tree.

OK florian@ deraadt@ "Have you committed ftp yet?"


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD


# 1.86 23-Dec-2017 cheloha

Use the monotonic clock for logging progress in cdio(1) and ftp(1).

Keeps the progress log from blipping or stalling if, e.g., the
system time is changed in the midst of a rip or a transfer.

ok tb@ jca@


Revision tags: OPENBSD_6_2_BASE
# 1.85 05-Sep-2017 jca

Avoid a possible leak in progressmeter

From Scott Cheloha, ok bluhm@


Revision tags: OPENBSD_6_1_BASE
# 1.84 21-Jan-2017 krw

Nuke whitespace foolish enough to expose itself during the great
"warning:" rectification.


# 1.83 20-Jan-2017 krw

#ifndef SMALL around a couple of non-SMALL labels.

ok deraadt@


# 1.82 11-Jan-2017 zhuk

Don't attempt to read .netrc when we already force anonymous FTP (-a).

Patch from Anton Lindqvist via tech@, thanks!

okay deraadt@


# 1.81 20-Aug-2016 millert

Use connect(2) + a connect_wait() function instead of connect_sync(),
similar to the example in connect(2). OK tedu@


# 1.80 18-Aug-2016 millert

Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@


# 1.79 14-Aug-2016 guenther

Convert remaining calls to strtoq/strtouq in base with strtoll/strtoull.
Fix a type mismatch in ftp's "page" command and could make transfers restart
at the wrong position.

ok and a ull->ll tweak from natano@, ok tedu@


# 1.78 28-Jul-2016 tedu

these programs probably do not need to use TMPDIR. ok florian


Revision tags: OPENBSD_6_0_BASE
# 1.77 16-Mar-2016 krw

More "(<blah> *)0" -> NULL, avoiding any stdarg functions.

Feedback millert@ kettenis@


Revision tags: OPENBSD_5_9_BASE
# 1.76 09-Dec-2015 mmcc

Remove NULL-checks before free(). ok tb@


# 1.75 18-Oct-2015 deraadt

unrelated commit; not ready yet


# 1.74 18-Oct-2015 deraadt

First casualty of making pledge "dns" mandatory for dns users.
"dns" was missing, and this was relying on "inet" support..


# 1.73 18-Oct-2015 mmcc

A whole buncha unsigned char casts for ctype function arguments.

ok guenther@


Revision tags: OPENBSD_5_8_BASE
# 1.72 17-Mar-2015 millert

Eliminate use of TM_YEAR_BASE. OK guenther@ deraadt@ miod@


# 1.71 15-Mar-2015 millert

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time. This makes the
tree safe for /usr/include/tzfile.h removal. The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree. Actual removal of tzfile.h is pending
a ports build. Based on a diff from deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.70 09-Feb-2015 tedu

remove the safeguard against porting to machines without 8 bit bytes.
allows removing sys/param.h include as well.


# 1.69 30-Jan-2015 tedu

remove tenex transfer support. if you still have TOPS20 machines in
service, you'll need to stick with openbsd 5.6.
bonus: remove references to ebcdic.
ok deraadt


# 1.68 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.67 16-Aug-2014 deraadt

I found a number of interactive events which can cause signals, and go
down paths not previously marked as signal handled unsafe. Try to clean
up a few of them especially regarding errno, mark others as unsafe, and
repair a few by avoiding stdio. Glanced at by misc people in Slovenia,
but considered too risky before release..


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.66 29-Jan-2014 dcoppa

Unbreak ftp progress meter after the introduction of the '-D' flag

ok tedu@


# 1.65 23-Jan-2014 deraadt

Add -D shorttitle support, so that the progress meter can show some sort
of reason why it is processing a certain file. This will be used by the
installer for that purpose.
ok krw rpe


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.64 11-Nov-2009 deraadt

do not walk off the prefix array, off by one; found by parfait
ok jsg millert


Revision tags: OPENBSD_4_6_BASE
# 1.63 10-May-2009 deraadt

show which username login failed for; ok martynas


# 1.62 05-May-2009 martynas

make it clean removing the ifdef SMALL maze. separate cmds and
small stuff. make it a fetcher. shrinks quite a bit
agreed by millert@, krw@
ok theo, sthen@


# 1.61 27-Apr-2009 martynas

remove uploading and macros support from install media; to save
some space
discussed with theo, todd@, millert@
tested and looked over by sthen@


# 1.60 27-Apr-2009 deraadt

toast the rcsid strings which just get in the way


# 1.59 26-Apr-2009 martynas

figure out titles automatically by using remote file name. remove
-T and just show titles by default for non-verbose transfers;
discussed with, ok theo, sthen@


# 1.58 26-Apr-2009 sthen

make two similar text strings identical; improves consistency and shrinks
the text segment slightly (though due to padding it does not change the size
of the binary). ok martynas@


# 1.57 13-Apr-2009 deraadt

add a "-T title" option to ftp; this is is used in progress bar mode to
show which filename is being used. ok krw, mdoc repair from jmc


Revision tags: OPENBSD_4_5_BASE
# 1.56 27-Jan-2009 martynas

on some servers LIST defaults to LIST -a. ignore pseudo-directories
so that recursive transfers don't cause a loop. problem reported
and tested by Jesus Sanchez. string compare inlining and looks
good to millert@


# 1.55 22-Aug-2008 sobrado

default file transfer type is binary, not ascii;
commands which toggle settings can take an explicit on or off argument
to force the setting appropiately, show these arguments in usage;
synchronize synopsis and usage of commands; spacing; KNF;
other minor documentation tweaks.

written with help by jmc@

ok jmc@ (documentation), martynas@ (type usage and default file transfer type)


Revision tags: OPENBSD_4_4_BASE
# 1.54 08-Jul-2008 martynas

- add support for recursive transfers (but not for floppies), e.g.
'mget -cr 4.*' would recursively fetch (-r), and resume the previous
transfers (-c) of 4.X release directories
uses local matching (fnmatch), but only for recursive transfers.
current behavior is not changed in any way.
- while here, ifndef SMALL debugging stuff, this saves some space,
for floppies
- some debugging code was enabled for non-debugging mode, checks
assume debug is set to zero, but it's not initially set
- all "Confirm with" prompts are forced, remove redundant argument
- fix usage: -C and -c are not available for SMALL

discussed a year ago w/ pyr@
looks good to millert@
previous version looked good to pyr@
man page tweaks & ok jmc@


# 1.53 26-Jun-2008 ray

First pass at removing clauses 3 and 4 from NetBSD licenses.

Not sure what's more surprising: how long it took for NetBSD to
catch up to the rest of the BSDs (including UCB), or the amount of
code that NetBSD has claimed for itself without attributing to the
actual authors.

OK deraadt@


# 1.52 25-Jun-2008 martynas

in resume mode, pass -c to mget when {dir,file}hasglob, so that i'm
able to continue multiple transfers with -C; ok millert@
while here fix some comments (!SMALL vs. SMALL stuff), and add
missing


# 1.51 16-Jun-2008 martynas

- add 'q', which does the same as eof
- add '?', which will help
- make use of mflag, instead of special-case interactive
- change mflag++ to mflag = 1, because theoretically it can go out
of range
"i like it" millert@. man page help and ok jmc@


# 1.50 16-Jun-2008 martynas

fix transfer interrupting when confirmrest mode is used. change
confirm() to have a 'force' argument, so that ointer/oconf dance
is not needed, and to prevent further bugs like this; ok millert@


# 1.49 15-Jun-2008 martynas

make further prompts work after eof, don't spam with prompts in
m*() cases; ok millert@


# 1.48 13-May-2008 ray

Remove #if 0 code that has been unused for nearly a decade (and
probably doesn't compile, since the types for some variables have
changed from long to char *).

OK millert@


Revision tags: OPENBSD_4_3_BASE
# 1.47 11-Sep-2007 gilles

use strcspn to properly overwrite '\n' in fgets returned buffer

ok pyr@, ray@, millert@, moritz@, chl@


Revision tags: OPENBSD_4_2_BASE
# 1.46 06-Jun-2007 pyr

Remove the .netrc parser when compiling a SMALL binary.
there is no .netrc file on the install media and keeping the parser
shaves a good deal of bytes in the binary.
ok millert@, "go on" deraadt@, "makes sense" steven@


Revision tags: OPENBSD_4_1_BASE
# 1.45 02-Nov-2006 ray

Pass full buffer size to fgets.

OK moritz@ and jaredy@.


# 1.44 02-Nov-2006 ray

Add checks for fgets and properly overwrite newline.

Initial patch from Charles Longeau <chl at tuxfamily dot org>.

OK moritz@ and jaredy@.


Revision tags: OPENBSD_4_0_BASE
# 1.43 16-May-2006 ray

Remove shadowing variables and properly use /* FALLTHROUGH */
comments. No binary change.

Found by lint.

OK beck@, deraadt@


# 1.42 25-Apr-2006 tedu

two strtol calls that were begging to be converted to strtonum


Revision tags: OPENBSD_3_9_BASE
# 1.41 12-Oct-2005 otto

Fix mget directory traversal vulnerability. From NetBSD. CAN-2002-1345.
ok millert@ deraadt@, prodding by david@


Revision tags: OPENBSD_3_8_BASE
# 1.40 11-Apr-2005 deraadt

knf; cloder ok


Revision tags: OPENBSD_3_7_BASE
# 1.39 16-Sep-2004 deraadt

type corrections and other delinting


Revision tags: OPENBSD_3_6_BASE
# 1.38 20-Jul-2004 deraadt

ansi; khalek@linuxgamers.net


Revision tags: OPENBSD_3_5_BASE
# 1.37 16-Dec-2003 deraadt

for -DSMALL, do not include rcsid[]s


# 1.36 31-Oct-2003 otto

New libedit api changes.

Tested by djm@, mouring@, jmc@.

ok deraadt@


Revision tags: OPENBSD_3_4_BASE
# 1.35 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.34 07-Apr-2003 millert

Some NetBSD changes were committed to this file w/o updating the
copyright. I have gone through the cvs logs and added the appropriate
NetBSD Foundation copyright corresponding to those changes.


# 1.33 05-Apr-2003 deraadt

string fixes; ok miod henning


# 1.32 31-Mar-2003 millert

Treat empty environment variables the same as NULL. henning@ OK


Revision tags: OPENBSD_3_3_BASE
# 1.31 08-Nov-2002 fgsch

http redirect support; adapted from NetBSD.


Revision tags: OPENBSD_3_2_BASE
# 1.30 12-Jul-2002 deraadt

malloc/strdup failure not handled; cloder@acm.org


Revision tags: OPENBSD_3_1_BASE
# 1.29 30-Mar-2002 deraadt

stretch banners


# 1.28 19-Feb-2002 mpech

Fix gethostname() usage.

deraadt@ ok


# 1.27 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_3_0_BASE
# 1.26 12-Jul-2001 deraadt

first pass at a -Wall cleanup


# 1.25 18-Jun-2001 millert

Change default transfer type from ascii to binary; closes PR 1626
Similar to patch from mpech@prosoft.org.lv


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.24 15-May-2000 deraadt

0-size files still deserve a progress meter; also, after file is finished
transfer, display a non-ETA line with an elapsed time.


Revision tags: OPENBSD_2_7_BASE
# 1.23 01-Feb-2000 espie

Work-around for lame servers that return `19100' for a date.

Based on NetBSD patch, slightly trimmed since we don't use the fractional
part yet...


# 1.22 08-Dec-1999 itojun

ftp(1) from KAME, should be good for testing.


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.21 22-Sep-1998 deraadt

if winsize.ws_col is 0, assume 80


# 1.20 19-Sep-1998 millert

make the progress meter run correctly in all cases if in -m mode


# 1.19 13-May-1998 deraadt

make signal handlers save/restore errno


# 1.18 26-Apr-1998 deraadt

recommended fix from tri@iki.fi...


Revision tags: OPENBSD_2_3_BASE
# 1.17 30-Mar-1998 deraadt

Y2K fixes from Andreas.Gunnarsson@emw.ericsson.se; culled from various places


# 1.16 25-Nov-1997 deraadt

prompting error; pr#352, blair@nac.net


Revision tags: OPENBSD_2_2_BASE
# 1.15 15-Sep-1997 millert

Don't error out if the remote server doesn't support the "MDTM"
command. Based on a patch from Martin Fredriksson <martin@netman.se>.


# 1.14 11-Sep-1997 millert

- Move `parsed_url' label such that the next statement after the label is
not an "else" (which some strict compilers reject).

- If getlogin() fails fall back on getpwuid(getuid()).


# 1.13 04-Sep-1997 millert

Updtaes from NetBSD (lukem)
bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
the remote name (i.e, in mget, and in get with only one argument).
This is implemented using an extra argument to recvrequest().
Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
* read defaults from $FTPSERVER && $FTPSERVERPORT
* start in gate-ftp mode if invoked as 'gate-ftp'
* toggle or set with 'gate [host [port]]'

Other changes:
* use symbolic flags in access(2)
* Use USHRT_MAX, not 0xffff


# 1.12 25-Aug-1997 jkatz

dumb fix for dumb users-- ftp's mget now idiot-proofs input!


# 1.11 25-Jul-1997 millert

Updates from NetBSD (lukem) include -Wall cleanup.
More -W* cleanup and in_port_t usage by me.


# 1.10 10-Jun-1997 millert

Disable progress meter if started as a bg process. Also don't
print the progress meter if the ftp process is put in the bg
(but do print it when/if the process is foregrounded).
From Enami Tsugutomo <enami@ba2.so-net.or.jp> with tweaks by me.


Revision tags: OPENBSD_2_1_BASE
# 1.9 11-May-1997 millert

Only retry login as "anonymous" if we are doing anonftp.
Found by grr@openbsd.org.


# 1.8 05-May-1997 jkatz

This fixes FTP so that it first tries with the username FTP, and then with
the username ANONYMOUS. It works, too :-)


# 1.7 23-Apr-1997 deraadt

allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work


# 1.6 16-Apr-1997 millert

Sync with NetBSD (lukem):
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers


# 1.5 10-Apr-1997 millert

Sync with NetBSD (lukem)
* support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
only setup setup terminal if going into interactive mode.


# 1.4 14-Mar-1997 millert

Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter
and setting times.


# 1.3 05-Feb-1997 millert

Include signal.h where reasonable and make signal handlers match
what signal(3)'s prototype says (and cast when not).
Also change MAXFOO+1 -> MAXFOO since MAXFOO includes the NULL.
Support $TMPDIR and use utime(3) not utimes(2) for portability's sake.
Don't spew "Passive mode enabled/disabled" unless verbose (this means
togglevar() needs to watch for a NULL 'message').


# 1.2 03-Feb-1997 millert

Add back ``-r'' option and fix strncpy() usage and other nits because
I'm anal. Closer to KNF now.


# 1.1 03-Feb-1997 millert

Sync with NetBSD