CVS commit: src/usr.bin/ftp

2024-04-16 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Wed Apr 17 02:46:03 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp.1: drop a sentence that's no longer accurate


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2024-04-16 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Wed Apr 17 02:46:03 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp.1: drop a sentence that's no longer accurate


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.153 src/usr.bin/ftp/ftp.1:1.154
--- src/usr.bin/ftp/ftp.1:1.153	Mon Feb 19 00:15:20 2024
+++ src/usr.bin/ftp/ftp.1	Wed Apr 17 02:46:03 2024
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.153 2024/02/19 00:15:20 christos Exp $
+.\" 	$NetBSD: ftp.1,v 1.154 2024/04/17 02:46:03 gutteridge Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd February 18, 2024
+.Dd April 17, 2024
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -1905,7 +1905,6 @@ and
 (and optionally
 .Ar password\^ )
 is in the URL, use them for the first attempt to authenticate.
-There is currently no certificate validation and verification.
 .\" file:///path
 .It Li file:/// Ns Ar path
 A local URL, copied from



CVS commit: src/usr.bin/ftp

2024-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 19 00:15:21 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp.1 ssl.c

Log Message:
default is now 16K


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.152 src/usr.bin/ftp/ftp.1:1.153
--- src/usr.bin/ftp/ftp.1:1.152	Sun Feb 18 17:29:56 2024
+++ src/usr.bin/ftp/ftp.1	Sun Feb 18 19:15:20 2024
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.152 2024/02/18 22:29:56 christos Exp $
+.\" 	$NetBSD: ftp.1,v 1.153 2024/02/19 00:15:20 christos Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -205,6 +205,8 @@ to bypass normal login procedure, and us
 .It Fl b Ar bufsize
 Change the input buffer size to
 .Ar bufsize .
+The default is 
+.Dv 16K .
 .It Fl d
 Enables debugging.
 .It Fl e

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.17 src/usr.bin/ftp/ssl.c:1.18
--- src/usr.bin/ftp/ssl.c:1.17	Sun Feb 18 17:29:56 2024
+++ src/usr.bin/ftp/ssl.c	Sun Feb 18 19:15:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.17 2024/02/18 22:29:56 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.18 2024/02/19 00:15:20 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -35,7 +35,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.17 2024/02/18 22:29:56 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.18 2024/02/19 00:15:20 christos Exp $");
 #endif
 
 #include 
@@ -579,7 +579,7 @@ fetch_getline(struct fetch_connect *conn
 break;
 		}
 		if (errormsg)
-			*errormsg = "Input line is too long (specify -b > 4K)";
+			*errormsg = "Input line is too long (specify -b > 16K)";
 		fetch_clearerr(conn);
 		return -3;
 	}



CVS commit: src/usr.bin/ftp

2024-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 19 00:15:21 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp.1 ssl.c

Log Message:
default is now 16K


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/usr.bin/ftp

2024-02-18 Thread Christos Zoulas
In article <20240218223315.800aff...@cvs.netbsd.org>,
Thomas Klausner  wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  wiz
>Date:  Sun Feb 18 22:33:15 UTC 2024
>
>Modified Files:
>   src/usr.bin/ftp: ftp_var.h
>
>Log Message:
>ftp: bump FTPBUFLEN from 4kB to 16kB
>
>sourceforge.net returns a 5kB content-security-policy.
>Analyzed by mlelstv@ who reports usual limits are between 4kB and 48kB.

This is used in two other places unrelated to fetch
(one in getline on the stack and one static for completions).
While it is ok to increase the default now because I've made it
dynamically allocated in the fetch cases, we should probably
use a different buffer constant for the other two...

christos



CVS commit: src/usr.bin/ftp

2024-02-18 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Feb 18 22:33:15 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp_var.h

Log Message:
ftp: bump FTPBUFLEN from 4kB to 16kB

sourceforge.net returns a 5kB content-security-policy.
Analyzed by mlelstv@ who reports usual limits are between 4kB and 48kB.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/ftp/ftp_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp_var.h
diff -u src/usr.bin/ftp/ftp_var.h:1.87 src/usr.bin/ftp/ftp_var.h:1.88
--- src/usr.bin/ftp/ftp_var.h:1.87	Sun Feb 18 22:29:56 2024
+++ src/usr.bin/ftp/ftp_var.h	Sun Feb 18 22:33:15 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.87 2024/02/18 22:29:56 christos Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.88 2024/02/18 22:33:15 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -169,7 +169,7 @@ enum {
 /*
  * Global defines
  */
-#define	FTPBUFLEN	(4 * MAXPATHLEN)
+#define	FTPBUFLEN	(16 * 1024)
 #define	MAX_IN_PORT_T	0xU
 
 #define	HASHBYTES	1024	/* default mark for `hash' command */



CVS commit: src/usr.bin/ftp

2024-02-18 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Feb 18 22:33:15 UTC 2024

Modified Files:
src/usr.bin/ftp: ftp_var.h

Log Message:
ftp: bump FTPBUFLEN from 4kB to 16kB

sourceforge.net returns a 5kB content-security-policy.
Analyzed by mlelstv@ who reports usual limits are between 4kB and 48kB.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/ftp/ftp_var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2024-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb 18 22:29:56 UTC 2024

Modified Files:
src/usr.bin/ftp: fetch.c ftp.1 ftp.c ftp_var.h main.c ssl.c

Log Message:
Add -b  to specify the buffer size.


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.238 src/usr.bin/ftp/fetch.c:1.239
--- src/usr.bin/ftp/fetch.c:1.238	Sat Aug 12 03:40:13 2023
+++ src/usr.bin/ftp/fetch.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $	*/
+/*	$NetBSD: fetch.c,v 1.239 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.239 2024/02/18 22:29:56 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1116,15 +1116,17 @@ negotiate_connection(FETCH *fin, const c
 char **auth, struct urlinfo *ui)
 {
 	int			len, hcode, rv;
-	char			buf[FTPBUFLEN], *ep;
+	char			*buf = NULL, *ep;
 	const char		*cp, *token;
 	char			*location, *message;
 
 	*auth = message = location = NULL;
 
+	buf = ftp_malloc(ftp_buflen);
+
 	/* Read the response */
 	ep = buf;
-	switch (getresponse(fin, , sizeof(buf), )) {
+	switch (getresponse(fin, , ftp_buflen, )) {
 	case C_CLEANUP:
 		goto cleanup_fetch_url;
 	case C_IMPROPER:
@@ -1137,7 +1139,7 @@ negotiate_connection(FETCH *fin, const c
 	/* Read the rest of the header. */
 
 	for (;;) {
-		if ((rv = getresponseline(fin, buf, sizeof(buf), )) != C_OK)
+		if ((rv = getresponseline(fin, buf, ftp_buflen, )) != C_OK)
 			goto cleanup_fetch_url;
 		if (len == 0)
 			break;
@@ -1265,6 +1267,7 @@ improper:
 	rv = C_IMPROPER;
 	goto out;
 out:
+	FREEPTR(buf);
 	FREEPTR(message);
 	FREEPTR(location);
 	return rv;
@@ -1279,7 +1282,7 @@ connectmethod(FETCH *fin, const char *ur
 	void *ssl;
 	int hcode, rv;
 	const char *cp;
-	char buf[FTPBUFLEN], *ep;
+	char *buf = NULL, *ep;
 	char *message = NULL;
 
 	print_connect(fin, oui);
@@ -1299,9 +1302,11 @@ connectmethod(FETCH *fin, const char *ur
 	}
 	alarmtimer(0);
 
+	buf = ftp_malloc(ftp_buflen);
+
 	/* Read the response */
 	ep = buf;
-	switch (getresponse(fin, , sizeof(buf), )) {
+	switch (getresponse(fin, , ftp_buflen, )) {
 	case C_CLEANUP:
 		goto cleanup_fetch_url;
 	case C_IMPROPER:
@@ -1313,7 +1318,7 @@ connectmethod(FETCH *fin, const char *ur
 
 	for (;;) {
 		int len;
-		if (getresponseline(fin, buf, sizeof(buf), ) != C_OK)
+		if (getresponseline(fin, buf, ftp_buflen, ) != C_OK)
 			goto cleanup_fetch_url;
 		if (len == 0)
 			break;
@@ -1364,6 +1369,7 @@ cleanup_fetch_url:
 	rv = C_CLEANUP;
 	goto out;
 out:
+	FREEPTR(buf);
 	FREEPTR(message);
 	return rv;
 }

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.151 src/usr.bin/ftp/ftp.1:1.152
--- src/usr.bin/ftp/ftp.1:1.151	Fri Dec  8 21:15:11 2023
+++ src/usr.bin/ftp/ftp.1	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.151 2023/12/09 02:15:11 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.152 2024/02/18 22:29:56 christos Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd December 9, 2023
+.Dd February 18, 2024
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -69,6 +69,7 @@
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
+.Op Fl b Ar bufsize
 .Op Fl q Ar quittime
 .Op Fl r Ar retry
 .Op Fl s Ar srcaddr
@@ -201,6 +202,9 @@ implement passive mode properly.
 Causes
 .Nm
 to bypass normal login procedure, and use an anonymous login instead.
+.It Fl b Ar bufsize
+Change the input buffer size to
+.Ar bufsize .
 .It Fl d
 Enables debugging.
 .It Fl e

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.175 src/usr.bin/ftp/ftp.c:1.176
--- src/usr.bin/ftp/ftp.c:1.175	Fri May  5 11:46:06 2023
+++ src/usr.bin/ftp/ftp.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.176 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.176 2024/02/18 22:29:56 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,6 +130,7 @@ sigjmp_buf	ptabort;
 int	ptabflg;
 int	ptflag = 0;
 char	pasv[BUFSIZ];	/* passive port for proxy data connection */

CVS commit: src/usr.bin/ftp

2024-02-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb 18 22:29:56 UTC 2024

Modified Files:
src/usr.bin/ftp: fetch.c ftp.1 ftp.c ftp_var.h main.c ssl.c

Log Message:
Add -b  to specify the buffer size.


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-12-08 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Dec  9 02:15:11 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): wording and formatting improvements

Fix grammar issue with "Support values" reported in private mail.
Document all file transfer types in "type" and cross-reference that.
Consistency fixes in describing file transfer parameters and types.
Fix some mandoc -Tlint issues (except "useless macro: Tn").


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-12-08 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Dec  9 02:15:11 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): wording and formatting improvements

Fix grammar issue with "Support values" reported in private mail.
Document all file transfer types in "type" and cross-reference that.
Consistency fixes in describing file transfer parameters and types.
Fix some mandoc -Tlint issues (except "useless macro: Tn").


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.150 src/usr.bin/ftp/ftp.1:1.151
--- src/usr.bin/ftp/ftp.1:1.150	Sat Feb 25 17:37:09 2023
+++ src/usr.bin/ftp/ftp.1	Sat Dec  9 02:15:11 2023
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.150 2023/02/25 17:37:09 uwe Exp $
+.\" 	$NetBSD: ftp.1,v 1.151 2023/12/09 02:15:11 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd February 25, 2023
+.Dd December 9, 2023
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -65,7 +65,7 @@
 .Nd Internet file transfer program
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46AadefginpRtVv?
+.Op Fl 46AadefginpRtVv\&?
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
@@ -289,7 +289,7 @@ Uses
 as the local IP address for all connections.
 .It Fl t
 Enables packet tracing.
-.It Fl T Ar direction Ns Cm \&, Ns Ar maximum\| Ns Oo Cm \&, Ns Ar increment Oc
+.It Fl T Ar direction Ns Cm \&, Ns Ar maximum Ns Oo Cm \&, Ns Ar increment Oc
 Set the maximum transfer rate for
 .Ar direction
 to
@@ -392,24 +392,20 @@ or
 .Ic nmap
 setting.
 File transfer uses the current settings for
-.Ic type  ,
-.Ic format ,
-.Ic mode  ,
+.Ic type ,
+.Ic form ,
+.Ic mode ,
 and
-.Ic structure .
+.Ic struct .
 .It Ic ascii
-Set the file transfer
-.Ic type
-to network
-.Tn ASCII .
-This is the default type.
+A synonym for
+.Ic type Cm ascii .
 .It Ic bell
 Arrange that a bell be sounded after each file transfer
 command is completed.
 .It Ic binary
-Set the file transfer
-.Ic type
-to support binary image transfer.
+A synonym for
+.Ic type Cm binary .
 .It Ic bye
 Terminate the
 .Tn FTP
@@ -450,9 +446,12 @@ return to the command interpreter.
 Any defined macros are erased.
 .It Ic \
 Toggle carriage return stripping during
-ascii type file retrieval.
+.Ic type Cm ascii
+file retrieval.
 Records are denoted by a carriage return/linefeed sequence
-during ascii type file transfer.
+during
+.Ic type Cm ascii
+file transfer.
 When
 .Ic \
 is on (the default), carriage returns are stripped from this
@@ -463,7 +462,9 @@ delimiter.
 Records on
 .Pf non\- Ux
 remote systems may contain single linefeeds;
-when an ascii type transfer is made, these linefeeds may be
+when a
+.Ic type Cm ascii
+transfer is made, these linefeeds may be
 distinguished from a record delimiter only when
 .Ic \
 is off.
@@ -541,12 +542,11 @@ Retrieve the files listed in
 .Ar localfile ,
 which has one line per filename.
 .It Ic form Ar format
-Set the file transfer
-.Ic form
-to
+Set the file transfer format control to
 .Ar format .
 The default (and only supported)
-format is
+.Ar format
+is
 .Ql non-print .
 .It Ic ftp Ar host Op Ar port
 A synonym for
@@ -579,27 +579,27 @@ If the local
 file name is not specified, it is given the same
 name it has on the remote machine, subject to
 alteration by the current
-.Ic case  ,
+.Ic case ,
 .Ic ntrans ,
 and
 .Ic nmap
 settings.
 The current settings for
-.Ic type  ,
+.Ic type ,
 .Ic form ,
-.Ic mode  ,
+.Ic mode ,
 and
-.Ic structure
+.Ic struct
 are used while transferring the file.
 .It Ic glob
 Toggle filename expansion for
-.Ic mdelete  ,
+.Ic mdelete ,
 .Ic mget ,
 .Ic mput ,
 and
 .Ic mreget .
 If globbing is turned off with
-.Ic glob  ,
+.Ic glob ,
 the file name arguments
 are taken literally and not expanded.
 Globbing for
@@ -630,7 +630,9 @@ entire directory subtrees of files.
 That can be done by
 transferring a
 .Xr tar 1
-archive of the subtree (in binary mode).
+archive of the subtree (in
+.Ic type Cm binary
+mode).
 .It Ic hash Op Ar size
 Toggle hash-sign
 .Pq Ql #
@@ -658,7 +660,7 @@ If
 is omitted, the current inactivity timer is printed.
 .It Ic image
 A synonym for
-.Ic binary .
+.Ic type Cm binary .
 .It Ic lcd Op Ar directory
 Change the working directory on the local machine.
 If
@@ -682,7 +684,7 @@ A synonym for
 .It Ic macdef Ar macro-name
 Define a macro.
 Subsequent lines are stored as the macro
-.Ar macro-name  ;
+.Ar macro-name ;
 a null line
 .Po
 consecutive newline characters in a file or carriage
@@ -740,7 +742,7 @@ Delete the
 on the remote machine.
 .It Ic mdir Ar remote-files local-file
 Like
-.Ic dir  ,
+.Ic dir ,
 except multiple remote files may be specified.
 If interactive prompting is on,
 .Nm
@@ -759,7 +761,7 @@ See
 .Ic glob
 for details on the filename 

CVS commit: src/usr.bin/ftp

2023-08-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Aug 12 07:40:13 UTC 2023

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Don't finish downloading an empty file with 'already done' before it is
created locally.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.237 src/usr.bin/ftp/fetch.c:1.238
--- src/usr.bin/ftp/fetch.c:1.237	Sun Jul  2 10:02:09 2023
+++ src/usr.bin/ftp/fetch.c	Sat Aug 12 07:40:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.237 2023/07/02 10:02:09 mlelstv Exp $	*/
+/*	$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.237 2023/07/02 10:02:09 mlelstv Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $");
 #endif /* not lint */
 
 /*
@@ -1652,9 +1652,10 @@ fetch_url(const char *url, const char *p
 		}
 	}
 	if (fout == NULL) {
-		if ((pi.rangeend != -1 && pi.rangeend <= restart_point) ||
+		if (restart_point && (
+		(pi.rangeend != -1 && pi.rangeend <= restart_point) ||
 		(pi.rangestart == -1 &&
-		filesize != -1 && filesize <= restart_point)) {
+		filesize != -1 && filesize <= restart_point))) {
 			/* already done */
 			if (verbose)
 fprintf(ttyout, "already done\n");



CVS commit: src/usr.bin/ftp

2023-08-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Aug 12 07:40:13 UTC 2023

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Don't finish downloading an empty file with 'already done' before it is
created locally.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-07-02 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jul  2 10:02:09 UTC 2023

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Fix HTTPS through Proxy.

While a regular HTTP Proxy, requires the absolute URL with protocol
and host part, yyou must only send the relative URL through a
CONNECT tunnel (you are talking to the target server).


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.236 src/usr.bin/ftp/fetch.c:1.237
--- src/usr.bin/ftp/fetch.c:1.236	Sat Feb 25 12:07:25 2023
+++ src/usr.bin/ftp/fetch.c	Sun Jul  2 10:02:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.236 2023/02/25 12:07:25 mlelstv Exp $	*/
+/*	$NetBSD: fetch.c,v 1.237 2023/07/02 10:02:09 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.236 2023/02/25 12:07:25 mlelstv Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.237 2023/07/02 10:02:09 mlelstv Exp $");
 #endif /* not lint */
 
 /*
@@ -801,7 +801,12 @@ handle_proxy(const char *url, const char
 	}
 
 	FREEPTR(pui.path);
-	pui.path = ftp_strdup(url);
+#ifdef WITH_SSL
+	if (ui->utype == HTTPS_URL_T)
+		pui.path = ftp_strdup(ui->path);
+	else
+#endif
+		pui.path = ftp_strdup(url);
 
 	freeurlinfo(ui);
 	*ui = pui;



CVS commit: src/usr.bin/ftp

2023-07-02 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jul  2 10:02:09 UTC 2023

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Fix HTTPS through Proxy.

While a regular HTTP Proxy, requires the absolute URL with protocol
and host part, yyou must only send the relative URL through a
CONNECT tunnel (you are talking to the target server).


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-05-16 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue May 16 22:00:23 UTC 2023

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
ftp 20230516 for openssl 3.0 compat SSL_OP_IGNORE_UNEXPECTED_EOF


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.97 src/usr.bin/ftp/version.h:1.98
--- src/usr.bin/ftp/version.h:1.97	Fri May  5 15:46:06 2023
+++ src/usr.bin/ftp/version.h	Tue May 16 22:00:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.97 2023/05/05 15:46:06 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.98 2023/05/16 22:00:23 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2023 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20230505"
+#define	FTP_VERSION	"20230516"
 #endif



CVS commit: src/usr.bin/ftp

2023-05-16 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue May 16 22:00:23 UTC 2023

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
ftp 20230516 for openssl 3.0 compat SSL_OP_IGNORE_UNEXPECTED_EOF


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-05-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 16 18:52:09 UTC 2023

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Ignore EOF from remote.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.15 src/usr.bin/ftp/ssl.c:1.16
--- src/usr.bin/ftp/ssl.c:1.15	Fri May  5 11:46:06 2023
+++ src/usr.bin/ftp/ssl.c	Tue May 16 14:52:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.15 2023/05/05 15:46:06 lukem Exp $	*/
+/*	$NetBSD: ssl.c,v 1.16 2023/05/16 18:52:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -35,7 +35,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.15 2023/05/05 15:46:06 lukem Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.16 2023/05/16 18:52:09 christos Exp $");
 #endif
 
 #include 
@@ -639,6 +639,9 @@ fetch_start_ssl(int sock, const char *se
 		/* Enable peer verification, (using the default callback) */
 		SSL_set_verify(ssl, SSL_VERIFY_PEER, NULL);
 	}
+#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
+	SSL_set_options(ssl, SSL_OP_IGNORE_UNEXPECTED_EOF);
+#endif
 
 		/* save current socket flags */
 	if ((flags = fcntl(sock, F_GETFL, 0)) == -1) {



CVS commit: src/usr.bin/ftp

2023-05-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 16 18:52:09 UTC 2023

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Ignore EOF from remote.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-05-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Fri May  5 15:46:06 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.c ssl.c util.c version.h

Log Message:
add timeout for ssl connect

Implement a timeout for SSL connection setup, using -q QUITTIME,
defaulting to 60 seconds.
SSL_connect(3) (unlike connect(2)) doesn't timeout by default.

Adapt ssl error messages destination: if unexpected error
from local API, use warn()/warnx() to stderr;
if expected error from a network operation (e.g., timeouts),
use fprintf to ttyout (which might be stdout).

Consistently use ftp_poll() instead of select();
ssl.c (using select()) was added 7 years after the
previous uses of select() were converted to poll().

Check EAGAIN as well as existing EINTR error from ftp_poll(),
for portability.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.166 -r1.167 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.174 src/usr.bin/ftp/ftp.c:1.175
--- src/usr.bin/ftp/ftp.c:1.174	Thu Aug 26 06:23:24 2021
+++ src/usr.bin/ftp/ftp.c	Fri May  5 15:46:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.174 2021/08/26 06:23:24 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.174 2021/08/26 06:23:24 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1733,7 +1733,8 @@ dataconn(const char *lmode)
 		if (timeout < 0)
 			timeout = 0;
 		rv = ftp_poll(pfd, 1, timeout);
-	} while (rv == -1 && errno == EINTR);	/* loop until poll ! EINTR */
+			/* loop until poll !EINTR && !EAGAIN */
+	} while (rv == -1 && (errno == EINTR || errno == EAGAIN));
 	if (rv == -1) {
 		warn("Can't poll waiting before accept");
 		goto dataconn_failed;
@@ -1747,7 +1748,8 @@ dataconn(const char *lmode)
 	fromlen = myctladdr.su_len;
 	do {
 		s = accept(data, (struct sockaddr *) _su, );
-	} while (s == -1 && errno == EINTR);	/* loop until accept ! EINTR */
+			/* loop until accept !EINTR && !EAGAIN */
+	} while (s == -1 && (errno == EINTR || errno == EAGAIN));
 	if (s == -1) {
 		warn("Can't accept data connection");
 		goto dataconn_failed;

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.14 src/usr.bin/ftp/ssl.c:1.15
--- src/usr.bin/ftp/ssl.c:1.14	Sun Apr  9 06:10:03 2023
+++ src/usr.bin/ftp/ssl.c	Fri May  5 15:46:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.14 2023/04/09 06:10:03 lukem Exp $	*/
+/*	$NetBSD: ssl.c,v 1.15 2023/05/05 15:46:06 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -35,9 +35,10 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.14 2023/04/09 06:10:03 lukem Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.15 2023/05/05 15:46:06 lukem Exp $");
 #endif
 
+#include 
 #include 
 #include 
 #include 
@@ -48,7 +49,6 @@ __RCSID("$NetBSD: ssl.c,v 1.14 2023/04/0
 #include 
 
 #include 
-#include 
 #include 
 
 #include 
@@ -96,38 +96,33 @@ struct fetch_connect {
 static ssize_t
 fetch_writev(struct fetch_connect *conn, struct iovec *iov, int iovcnt)
 {
-	struct timeval now, timeout, delta;
-	fd_set writefds;
+	struct timeval timeout, now, delta;
 	ssize_t len, total;
 	int fd = conn->sd;
-	int r;
+	int rv, timeout_secs;
+	struct pollfd pfd[1];
 
-	if (quit_time > 0) {
-		FD_ZERO();
-		gettimeofday(, NULL);
-		timeout.tv_sec += quit_time;
-	}
+	pfd[0].fd = fd;
+	pfd[0].events = POLLOUT;
+	gettimeofday(, NULL);
+	timeout.tv_sec += quit_time;
 
 	total = 0;
 	while (iovcnt > 0) {
-		while (quit_time > 0 && !FD_ISSET(fd, )) {
-			FD_SET(fd, );
-			gettimeofday(, NULL);
-			delta.tv_sec = timeout.tv_sec - now.tv_sec;
-			delta.tv_usec = timeout.tv_usec - now.tv_usec;
-			if (delta.tv_usec < 0) {
-delta.tv_usec += 100;
-delta.tv_sec--;
-			}
-			if (delta.tv_sec < 0) {
-errno = ETIMEDOUT;
+		if (quit_time > 0) {	/* enforce timeout */
+			do {
+(void)gettimeofday(, NULL);
+timersub(, , );
+timeout_secs = delta.tv_sec * 1000 + delta.tv_usec/1000;
+if (timeout_secs < 0)
+	timeout_secs = 0;
+rv = ftp_poll(pfd, 1, timeout_secs);
+	/* loop until poll !EINTR && !EAGAIN */
+			} while (rv == -1 && (errno == EINTR || errno == EAGAIN));
+			if (rv == -1)
 return -1;
-			}
-			errno = 0;
-			r = select(fd + 1, NULL, , NULL, );
-			if (r == -1) {
-if (errno == EINTR)
-	continue;
+			if (rv == 0) {
+errno = ETIMEDOUT;
 return -1;
 			}
 		}
@@ -330,7 +325,7 @@ fetch_nonssl_read(int sd, void *buf, siz
 
 	rlen = read(sd, buf, len);
 	if (rlen == -1) {
-		if (errno == EAGAIN 

CVS commit: src/usr.bin/ftp

2023-05-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Fri May  5 15:46:06 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.c ssl.c util.c version.h

Log Message:
add timeout for ssl connect

Implement a timeout for SSL connection setup, using -q QUITTIME,
defaulting to 60 seconds.
SSL_connect(3) (unlike connect(2)) doesn't timeout by default.

Adapt ssl error messages destination: if unexpected error
from local API, use warn()/warnx() to stderr;
if expected error from a network operation (e.g., timeouts),
use fprintf to ttyout (which might be stdout).

Consistently use ftp_poll() instead of select();
ssl.c (using select()) was added 7 years after the
previous uses of select() were converted to poll().

Check EAGAIN as well as existing EINTR error from ftp_poll(),
for portability.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.166 -r1.167 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-04-09 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr  9 06:10:03 UTC 2023

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Simplify includes

Include "ftp_var.h" instead of various system headers and "extern.h".


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.13 src/usr.bin/ftp/ssl.c:1.14
--- src/usr.bin/ftp/ssl.c:1.13	Sat Feb 25 12:07:25 2023
+++ src/usr.bin/ftp/ssl.c	Sun Apr  9 06:10:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.13 2023/02/25 12:07:25 mlelstv Exp $	*/
+/*	$NetBSD: ssl.c,v 1.14 2023/04/09 06:10:03 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -35,7 +35,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.13 2023/02/25 12:07:25 mlelstv Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.14 2023/04/09 06:10:03 lukem Exp $");
 #endif
 
 #include 
@@ -63,11 +63,7 @@ __RCSID("$NetBSD: ssl.c,v 1.13 2023/02/2
 #endif
 
 #include "ssl.h"
-
-#include 
-#include 
-#include 
-#include "extern.h"
+#include "ftp_var.h"
 
 extern int quit_time, verbose, ftp_debug;
 extern FILE *ttyout;



CVS commit: src/usr.bin/ftp

2023-04-09 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr  9 06:10:03 UTC 2023

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Simplify includes

Include "ftp_var.h" instead of various system headers and "extern.h".


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-02-25 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sat Feb 25 17:37:09 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): better mark up for url vs cd example


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-02-25 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sat Feb 25 17:37:09 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): better mark up for url vs cd example


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.149 src/usr.bin/ftp/ftp.1:1.150
--- src/usr.bin/ftp/ftp.1:1.149	Sat Feb 25 13:51:48 2023
+++ src/usr.bin/ftp/ftp.1	Sat Feb 25 17:37:09 2023
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.149 2023/02/25 13:51:48 uwe Exp $
+.\" 	$NetBSD: ftp.1,v 1.150 2023/02/25 17:37:09 uwe Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -1792,24 +1792,38 @@ and where to use
 For example, the following URLs correspond to the
 equivalents of the indicated commands:
 .Bl -tag -width "ftp://host/%2Fdir1%2Fdir2%2Ffile;
-.It ftp://host/dir1/dir2/file
-.Dq "cd dir1" ,
-.Dq "cd dir2" ,
-.Dq "get file" .
-.It ftp://host/%2Fdir1/dir2/file
-.Dq "cd /dir1" ,
-.Dq "cd dir2" ,
-.Dq "get file" .
-.It ftp://host/dir1%2Fdir2/file
-.Dq "cd dir1/dir2" ,
-.Dq "get file" .
-.It ftp://host/%2Fdir1%2Fdir2/file
-.Dq "cd /dir1/dir2" ,
-.Dq "get file" .
-.It ftp://host/dir1%2Fdir2%2Ffile
-.Dq "get dir1/dir2/file" .
-.It ftp://host/%2Fdir1%2Fdir2%2Ffile
-.Dq "get /dir1/dir2/file" .
+.It Xo \" ftp://host/dir1/dir2/file
+.Sm off
+.Ic ftp:// Ar host
+.Ic / Ar dir1
+.Ic / Ar dir2
+.Ic / Ar file
+.Sm on
+.Xc
+.Ic cd Ar dir1 ,
+.Ic cd Ar dir2 ,
+.Ic get Ar file .
+.It Xo \" ftp://host/%2Fdir1/dir2/file
+.Sm off
+.Ic ftp:// Ar host
+.Ic /%2F Ar dir1
+.Ic / Ar dir2
+.Ic / Ar file
+.Sm on
+.Xc
+.Ic cd / Ns Ar dir1 ,
+.Ic cd Ar dir2 ,
+.Ic get Ar file .
+.It Xo \" ftp://host/dir1%2Fdir2/file
+.Sm off
+.Ic ftp:// Ar host
+.Ic / Ar dir1
+.Ic %2F Ar dir2
+.Ic / Ar file
+.Sm on
+.Xc
+.Ic cd Ar dir1 Ns Ic / Ns Ar dir2 ,
+.Ic get Ar file .
 .El
 .It
 You must have appropriate access permission for each of the



CVS commit: src/usr.bin/ftp

2023-02-25 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sat Feb 25 13:51:48 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): minor markup tweaks

Use .Ql instead of .Sq Li, add some missing ones.  Use .Pq instead of
explicit () for longer phrases - these are easier to read in the
postscript output b/c of extra spacing.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.148 src/usr.bin/ftp/ftp.1:1.149
--- src/usr.bin/ftp/ftp.1:1.148	Sat Feb 25 12:07:25 2023
+++ src/usr.bin/ftp/ftp.1	Sat Feb 25 13:51:48 2023
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.148 2023/02/25 12:07:25 mlelstv Exp $
+.\" 	$NetBSD: ftp.1,v 1.149 2023/02/25 13:51:48 uwe Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -77,9 +77,9 @@
 .Oo
 .Fl T Xo
 .Sm off
-.Ar dir ,
+.Ar dir Cm \&,
 .Ar max
-.Op , Ar inc
+.Op Cm \&, Ar inc
 .Sm on
 .Xc
 .Oc
@@ -239,11 +239,14 @@ will check the
 an account on the remote machine.
 If no entry exists,
 .Nm
-will prompt for the remote machine login name (default is the user
-identity on the local machine), and, if necessary, prompt for a password
+will prompt for the remote machine login name
+.Pq default is the user identity on the local machine ,
+and, if necessary, prompt for a password
 and an account with which to login.
 To override the auto-login for auto-fetch transfers, specify the
-username (and optionally, password) as appropriate.
+username
+.Pq and optionally, password
+as appropriate.
 .It Fl o Ar output
 When auto-fetching files, save the contents in
 .Ar output .
@@ -254,9 +257,9 @@ below.
 If
 .Ar output
 is not
-.Sq -
+.Sq Fl
 or doesn't start with
-.Sq \&| ,
+.Sq Cm \&| ,
 then only the first file specified will be retrieved into
 .Ar output ;
 all other files will be retrieved into the basename of their
@@ -286,7 +289,7 @@ Uses
 as the local IP address for all connections.
 .It Fl t
 Enables packet tracing.
-.It Fl T Ar direction Ns , Ns Ar maximum Ns Oo , Ns Ar increment Oc
+.It Fl T Ar direction Ns Cm \&, Ns Ar maximum\| Ns Oo Cm \&, Ns Ar increment Oc
 Set the maximum transfer rate for
 .Ar direction
 to
@@ -304,9 +307,10 @@ Upload files on the command line to
 where
 .Ar url
 is one of the
-.Sq Li ftp://
+.Ql ftp://
 URL types as supported by auto-fetch
-(with an optional target filename for single file uploads), and
+.Pq with an optional target filename for single file uploads ,
+and
 .Ar file
 is one or more local files to be uploaded.
 .It Fl V
@@ -320,10 +324,13 @@ Enable
 .Ic verbose
 and
 .Ic progress .
-This is the default if output is to a terminal (and in the case of
+This is the default if output is to a terminal
+.Po
+and in the case of
 .Ic progress ,
 .Nm
-is the foreground process).
+is the foreground process
+.Pc .
 Forces
 .Nm
 to show all responses from the remote server, as well
@@ -334,7 +341,7 @@ Set the size of the socket send and rece
 Refer to
 .Ic xferbuf
 for more information.
-.It Fl ?
+.It Fl \&?
 Display help to stdout, and exit.
 .El
 .Pp
@@ -356,7 +363,7 @@ is awaiting commands from the user the p
 is provided to the user.
 The following commands are recognized
 by
-.Nm ftp :
+.Nm :
 .Bl -tag -width Ic
 .It Ic \&! Op Ar command Op Ar args
 Invoke an interactive shell on the local machine.
@@ -454,7 +461,7 @@ sequence to conform with the
 single linefeed record
 delimiter.
 Records on
-.Pf non\- Ns Ux
+.Pf non\- Ux
 remote systems may contain single linefeeds;
 when an ascii type transfer is made, these linefeeds may be
 distinguished from a record delimiter only when
@@ -527,9 +534,8 @@ is executed again.
 A synonym for
 .Ic bye .
 .It Ic features
-Display what features the remote server supports (using the
-.Dv FEAT
-command).
+Display what features the remote server supports
+.Pq using the Dv FEAT No command .
 .It Ic fget Ar localfile
 Retrieve the files listed in
 .Ar localfile ,
@@ -541,7 +547,7 @@ to
 .Ar format .
 The default (and only supported)
 format is
-.Dq non-print .
+.Ql non-print .
 .It Ic ftp Ar host Op Ar port
 A synonym for
 .Ic open .
@@ -551,9 +557,11 @@ TIS FWTK and Gauntlet
 .Tn FTP
 proxies.
 This will not be permitted if the gate-ftp server hasn't been set
-(either explicitly by the user, or from the
+.Po
+either explicitly by the user, or from the
 .Ev FTPSERVER
-environment variable).
+environment variable
+.Pc .
 If
 .Ar host
 is given,
@@ -625,7 +633,7 @@ transferring a
 archive of the subtree (in binary mode).
 .It Ic hash Op Ar size
 Toggle hash-sign
-.Pq Sq #
+.Pq Ql #
 printing for each data block transferred.
 The size of a data block defaults to 1024 bytes.
 This can be changed by specifying
@@ -675,16 +683,24 @@ A synonym for
 Define a macro.
 Subsequent lines are stored as the macro
 .Ar macro-name  ;
-a null line 

CVS commit: src/usr.bin/ftp

2023-02-25 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sat Feb 25 13:51:48 UTC 2023

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): minor markup tweaks

Use .Ql instead of .Sq Li, add some missing ones.  Use .Pq instead of
explicit () for longer phrases - these are easier to read in the
postscript output b/c of extra spacing.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-02-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 25 12:07:25 UTC 2023

Modified Files:
src/usr.bin/ftp: cmdtab.c extern.h fetch.c ftp.1 main.c ssl.c util.c
version.h

Log Message:
Add option sslnoverify to control validation of SSL certificates.
Add netrc processing to fetch-mode (URL on command line) to enable options and 
autologin
via netrc.
Fix SSL cleanup in some error paths.

Certificate validation is now enabled by default. Set FTPSSLNOVERIFY=1 in 
environment
or configure a corresponding init macro via netrc to not validate certs 
(required if
you haven't installed a required CA certificate for OpenSSL).

Discussed with lukem@ on icb.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/ftp/cmdtab.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.235 -r1.236 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.147 -r1.148 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.165 -r1.166 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-02-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 25 12:07:25 UTC 2023

Modified Files:
src/usr.bin/ftp: cmdtab.c extern.h fetch.c ftp.1 main.c ssl.c util.c
version.h

Log Message:
Add option sslnoverify to control validation of SSL certificates.
Add netrc processing to fetch-mode (URL on command line) to enable options and 
autologin
via netrc.
Fix SSL cleanup in some error paths.

Certificate validation is now enabled by default. Set FTPSSLNOVERIFY=1 in 
environment
or configure a corresponding init macro via netrc to not validate certs 
(required if
you haven't installed a required CA certificate for OpenSSL).

Discussed with lukem@ on icb.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/ftp/cmdtab.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.235 -r1.236 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.147 -r1.148 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.165 -r1.166 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/cmdtab.c
diff -u src/usr.bin/ftp/cmdtab.c:1.52 src/usr.bin/ftp/cmdtab.c:1.53
--- src/usr.bin/ftp/cmdtab.c:1.52	Sat Dec 22 16:57:09 2012
+++ src/usr.bin/ftp/cmdtab.c	Sat Feb 25 12:07:25 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $	*/
+/*	$NetBSD: cmdtab.c,v 1.53 2023/02/25 12:07:25 mlelstv Exp $	*/
 
 /*-
- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)cmdtab.c	8.4 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.53 2023/02/25 12:07:25 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -295,13 +295,14 @@ struct cmd cmdtab[] = {
 };
 
 struct option optiontab[] = {
-	{ "anonpass",	NULL },
-	{ "ftp_proxy",	NULL },
-	{ "http_proxy",	NULL },
-	{ "https_proxy",NULL },
-	{ "no_proxy",	NULL },
-	{ "pager",	NULL },
-	{ "prompt",	NULL },
-	{ "rprompt",	NULL },
-	{ NULL,		NULL },
+	{ "anonpass",	   NULL },
+	{ "ftp_proxy",	   NULL },
+	{ "http_proxy",	   NULL },
+	{ "https_proxy",   NULL },
+	{ "no_proxy",	   NULL },
+	{ "pager",	   NULL },
+	{ "prompt",	   NULL },
+	{ "rprompt",	   NULL },
+	{ "sslnoverify"   ,NULL },
+	{ NULL,		   NULL },
 };

Index: src/usr.bin/ftp/extern.h
diff -u src/usr.bin/ftp/extern.h:1.82 src/usr.bin/ftp/extern.h:1.83
--- src/usr.bin/ftp/extern.h:1.82	Sat Jun 22 23:40:53 2019
+++ src/usr.bin/ftp/extern.h	Sat Feb 25 12:07:25 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: extern.h,v 1.82 2019/06/22 23:40:53 christos Exp $	*/
+/*	$NetBSD: extern.h,v 1.83 2023/02/25 12:07:25 mlelstv Exp $	*/
 
 /*-
- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -243,6 +243,7 @@ void	user(int, char **);
 int	ftp_connect(int, const struct sockaddr *, socklen_t, int);
 int	ftp_listen(int, int);
 int	ftp_poll(struct pollfd *, int, int);
+int	ftp_truthy(const char *, const char *, int);
 #ifndef SMALL
 void   *ftp_malloc(size_t);
 StringList *ftp_sl_init(void);

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.235 src/usr.bin/ftp/fetch.c:1.236
--- src/usr.bin/ftp/fetch.c:1.235	Sun Sep 11 20:49:27 2022
+++ src/usr.bin/ftp/fetch.c	Sat Feb 25 12:07:25 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.235 2022/09/11 20:49:27 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.236 2023/02/25 12:07:25 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.235 2022/09/11 20:49:27 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.236 2023/02/25 12:07:25 mlelstv Exp $");
 #endif /* not lint */
 
 /*
@@ -617,13 +617,15 @@ parse_url(const char *url, const char *d
 sigjmp_buf	httpabort;
 
 static int
-ftp_socket(const struct urlinfo *ui, void **ssl)
+ftp_socket(const struct urlinfo *ui, void **ssl, struct authinfo *auth)
 {
 	struct addrinfo hints, *res, *res0 = NULL;
 	int error;
 	int s;
 	const char *host = ui->host;
 	const char *port = ui->port;
+	char *fuser = NULL, *pass = NULL, *facct = NULL;
+	int n;
 
 	if (ui->utype != HTTPS_URL_T)
 		ssl = NULL;
@@ -688,6 +690,28 @@ ftp_socket(const struct urlinfo *ui, voi
 			continue;
 		}
 
+		if (ruserpass("", , , ) < 0) {
+			close(s);
+			s = -1;
+			continue;
+		}
+
+		if (autologin) {
+			if (fuser != NULL && auth->user == NULL)
+auth->user = ftp_strdup(fuser);
+			if (pass != NULL && auth->pass == 

CVS commit: src/usr.bin/ftp

2023-01-20 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Jan 20 22:08:49 UTC 2023

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
s/bninary/binary/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2023-01-20 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Jan 20 22:08:49 UTC 2023

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
s/bninary/binary/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.164 src/usr.bin/ftp/util.c:1.165
--- src/usr.bin/ftp/util.c:1.164	Sat Aug  6 18:26:43 2022
+++ src/usr.bin/ftp/util.c	Fri Jan 20 22:08:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.164 2022/08/06 18:26:43 andvar Exp $	*/
+/*	$NetBSD: util.c,v 1.165 2023/01/20 22:08:48 andvar Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.164 2022/08/06 18:26:43 andvar Exp $");
+__RCSID("$NetBSD: util.c,v 1.165 2023/01/20 22:08:48 andvar Exp $");
 #endif /* not lint */
 
 /*
@@ -209,7 +209,7 @@ getremoteinfo(void)
 			os_len, reply_string + 4);
 		}
 		/*
-		 * Decide whether we should default to bninary.
+		 * Decide whether we should default to binary.
 		 * Traditionally checked for "215 UNIX Type: L8", but
 		 * some printers report "Linux" ! so be more forgiving.
 		 * In reality we probably almost never want text any more.



CVS commit: src/usr.bin/ftp

2022-09-21 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Sep 22 03:31:04 UTC 2022

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20220911

PR/57003: Handle relative URLs (patch by kim@)


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.94 src/usr.bin/ftp/version.h:1.95
--- src/usr.bin/ftp/version.h:1.94	Thu Aug 26 06:25:59 2021
+++ src/usr.bin/ftp/version.h	Thu Sep 22 03:31:04 2022
@@ -1,7 +1,7 @@
-/*	$NetBSD: version.h,v 1.94 2021/08/26 06:25:59 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.95 2022/09/22 03:31:04 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999-2022 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20210826"
+#define	FTP_VERSION	"20220911"
 #endif



CVS commit: src/usr.bin/ftp

2022-09-21 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Sep 22 03:31:04 UTC 2022

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20220911

PR/57003: Handle relative URLs (patch by kim@)


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2022-09-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 12 15:10:31 UTC 2022

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Disable verification for now until we implement installation of trust anchors.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.11 src/usr.bin/ftp/ssl.c:1.12
--- src/usr.bin/ftp/ssl.c:1.11	Tue Aug 30 04:51:28 2022
+++ src/usr.bin/ftp/ssl.c	Mon Sep 12 11:10:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.11 2022/08/30 08:51:28 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.12 2022/09/12 15:10:31 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.11 2022/08/30 08:51:28 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.12 2022/09/12 15:10:31 christos Exp $");
 #endif
 
 #include 
@@ -589,7 +589,7 @@ fetch_start_ssl(int sock, const char *se
 	SSL_CTX *ctx;
 	X509_VERIFY_PARAM *param;
 	int ret, ssl_err;
-	int verify = getenv("NO_CERT_VERIFY") == NULL;
+	int verify = 0;	// getenv("NO_CERT_VERIFY") == NULL;
 
 	/* Init the SSL library and context */
 	if (!SSL_library_init()){



CVS commit: src/usr.bin/ftp

2022-09-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Sep 12 15:10:31 UTC 2022

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
Disable verification for now until we implement installation of trust anchors.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2022-09-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 11 20:49:27 UTC 2022

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
PR/57003: Handle relative URLs (patch by kim@)


To generate a diff of this commit:
cvs rdiff -u -r1.234 -r1.235 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.234 src/usr.bin/ftp/fetch.c:1.235
--- src/usr.bin/ftp/fetch.c:1.234	Sun Aug  1 11:29:30 2021
+++ src/usr.bin/ftp/fetch.c	Sun Sep 11 16:49:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.234 2021/08/01 15:29:30 andvar Exp $	*/
+/*	$NetBSD: fetch.c,v 1.235 2022/09/11 20:49:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.234 2021/08/01 15:29:30 andvar Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.235 2022/09/11 20:49:27 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -106,12 +106,13 @@ __dead static void	timeouthttp(int);
 static int	auth_url(const char *, char **, const struct authinfo *);
 static void	base64_encode(const unsigned char *, size_t, unsigned char *);
 #endif
-static int	go_fetch(const char *);
+static int	go_fetch(const char *, struct urlinfo *);
 static int	fetch_ftp(const char *);
-static int	fetch_url(const char *, const char *, char *, char *);
+static int	fetch_url(const char *, const char *, char *, char *,
+struct urlinfo *);
 static const char *match_token(const char **, const char *);
 static int	parse_url(const char *, const char *, struct urlinfo *,
-struct authinfo *);
+struct authinfo *, struct urlinfo *);
 static void	url_decode(char *);
 static void	freeauthinfo(struct authinfo *);
 static void	freeurlinfo(struct urlinfo *);
@@ -274,7 +275,7 @@ auth_url(const char *challenge, char **r
 	scheme = "Basic";	/* only support Basic authentication */
 	gotpass = NULL;
 
-	DPRINTF("auth_url: challenge `%s'\n", challenge);
+	DPRINTF("%s: challenge `%s'\n", __func__, challenge);
 
 	if (! match_token(, scheme)) {
 		warnx("Unsupported authentication challenge `%s'",
@@ -336,7 +337,7 @@ auth_url(const char *challenge, char **r
 	*response = ftp_malloc(rlen);
 	(void)strlcpy(*response, scheme, rlen);
 	len = strlcat(*response, " ", rlen);
-			/* use  `clen - 1'  to not encode the trailing NUL */
+			/* use	`clen - 1'  to not encode the trailing NUL */
 	base64_encode((unsigned char *)clear, clen - 1,
 	(unsigned char *)*response + len);
 	memset(clear, 0, clen);
@@ -367,7 +368,7 @@ base64_encode(const unsigned char *clear
 			| ((clear[i + 1] >> 4) & 0x0f)];
 		*(cp++) = enc[((clear[i + 1] << 2) & 0x3c)
 			| ((clear[i + 2] >> 6) & 0x03)];
-		*(cp++) = enc[((clear[i + 2] ) & 0x3f)];
+		*(cp++) = enc[((clear[i + 2]	 ) & 0x3f)];
 	}
 	*cp = '\0';
 	while (i-- > len)
@@ -400,6 +401,42 @@ url_decode(char *url)
 	*q = '\0';
 }
 
+static const char *
+get_port(const struct urlinfo *ui)
+{
+
+	switch(ui->utype) {
+	case HTTP_URL_T:
+		return httpport;
+	case FTP_URL_T:
+		return ftpport;
+	case FILE_URL_T:
+		return "";
+#ifdef WITH_SSL
+	case HTTPS_URL_T:
+		return httpsport;
+#endif
+	default:
+		return NULL;
+	}
+}
+
+static int
+use_relative(const struct urlinfo *ui)
+{
+	if (ui == NULL)
+		return 0;
+	switch (ui->utype) {
+	case HTTP_URL_T:
+	case FILE_URL_T:
+#ifdef WITH_SSL
+	case HTTPS_URL_T:
+#endif
+		return 1;
+	default:
+		return 0;
+	}
+}
 
 /*
  * Parse URL of form (per RFC 3986):
@@ -435,7 +472,7 @@ url_decode(char *url)
 
 static int
 parse_url(const char *url, const char *desc, struct urlinfo *ui,
-struct authinfo *auth) 
+struct authinfo *auth, struct urlinfo *rui)
 {
 	const char	*origurl, *tport;
 	char		*cp, *ep, *thost;
@@ -446,29 +483,26 @@ parse_url(const char *url, const char *d
 	DPRINTF("parse_url: %s `%s'\n", desc, url);
 
 	origurl = url;
-	tport = NULL;
 
 	if (STRNEQUAL(url, HTTP_URL)) {
 		url += sizeof(HTTP_URL) - 1;
 		ui->utype = HTTP_URL_T;
 		ui->portnum = HTTP_PORT;
-		tport = httpport;
 	} else if (STRNEQUAL(url, FTP_URL)) {
 		url += sizeof(FTP_URL) - 1;
 		ui->utype = FTP_URL_T;
 		ui->portnum = FTP_PORT;
-		tport = ftpport;
 	} else if (STRNEQUAL(url, FILE_URL)) {
 		url += sizeof(FILE_URL) - 1;
 		ui->utype = FILE_URL_T;
-		tport = "";
 #ifdef WITH_SSL
 	} else if (STRNEQUAL(url, HTTPS_URL)) {
 		url += sizeof(HTTPS_URL) - 1;
 		ui->utype = HTTPS_URL_T;
 		ui->portnum = HTTPS_PORT;
-		tport = httpsport;
 #endif
+	} else if (rui != NULL) {
+		copyurlinfo(ui, rui);
 	} else {
 		warnx("Invalid %s `%s'", desc, url);
  cleanup_parse_url:
@@ -477,6 +511,7 @@ parse_url(const char *url, const char *d
 		return (-1);
 	}
 
+
 	if (*url == '\0')
 		return (0);
 
@@ -541,7 +576,8 @@ parse_url(const char *url, const char *d
 #endif /* INET6 */
 		if ((cp = strchr(thost, ':')) != NULL)
 			*cp++ = '\0';
-	ui->host = thost;
+	if (*thost != '\0')
+		

CVS commit: src/usr.bin/ftp

2022-09-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 11 20:49:27 UTC 2022

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
PR/57003: Handle relative URLs (patch by kim@)


To generate a diff of this commit:
cvs rdiff -u -r1.234 -r1.235 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2022-08-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 30 08:51:28 UTC 2022

Modified Files:
src/usr.bin/ftp: ftp.1 ssl.c

Log Message:
Add cert verification, together with an environment variable "NO_CERT_VERIFY",
to turn it off.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.146 src/usr.bin/ftp/ftp.1:1.147
--- src/usr.bin/ftp/ftp.1:1.146	Sun Apr 25 05:09:55 2021
+++ src/usr.bin/ftp/ftp.1	Tue Aug 30 04:51:28 2022
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.146 2021/04/25 09:09:55 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.147 2022/08/30 08:51:28 christos Exp $
 .\"
 .\" Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd April 25, 2021
+.Dd August 29, 2022
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -2320,6 +2320,8 @@ file, if one exists.
 An alternate location of the
 .Pa .netrc
 file.
+.It Ev NO_CERT_VERIFY
+Don't verify SSL certificates.
 .It Ev PAGER
 Used by various commands to display files.
 Defaults to

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.10 src/usr.bin/ftp/ssl.c:1.11
--- src/usr.bin/ftp/ssl.c:1.10	Thu Jun  3 06:23:33 2021
+++ src/usr.bin/ftp/ssl.c	Tue Aug 30 04:51:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.10 2021/06/03 10:23:33 lukem Exp $	*/
+/*	$NetBSD: ssl.c,v 1.11 2022/08/30 08:51:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.10 2021/06/03 10:23:33 lukem Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.11 2022/08/30 08:51:28 christos Exp $");
 #endif
 
 #include 
@@ -587,7 +587,9 @@ fetch_start_ssl(int sock, const char *se
 {
 	SSL *ssl;
 	SSL_CTX *ctx;
+	X509_VERIFY_PARAM *param;
 	int ret, ssl_err;
+	int verify = getenv("NO_CERT_VERIFY") == NULL;
 
 	/* Init the SSL library and context */
 	if (!SSL_library_init()){
@@ -599,6 +601,10 @@ fetch_start_ssl(int sock, const char *se
 
 	ctx = SSL_CTX_new(SSLv23_client_method());
 	SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);
+	if (verify) {
+		SSL_CTX_set_default_verify_paths(ctx);
+		SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
+	}
 
 	ssl = SSL_new(ctx);
 	if (ssl == NULL){
@@ -606,6 +612,19 @@ fetch_start_ssl(int sock, const char *se
 		SSL_CTX_free(ctx);
 		return NULL;
 	}
+
+	if (verify) {
+		param = SSL_get0_param(ssl);
+		if (!X509_VERIFY_PARAM_set1_host(param, servername,
+		strlen(servername))) {
+			fprintf(ttyout, "SSL verification setup failed\n");
+			return NULL;
+		}
+
+		/* Enable peer verification, (using the default callback) */
+		SSL_set_verify(ssl, SSL_VERIFY_PEER, NULL);
+	}
+
 	SSL_set_fd(ssl, sock);
 	if (!SSL_set_tlsext_host_name(ssl, __UNCONST(servername))) {
 		fprintf(ttyout, "SSL hostname setting failed\n");



CVS commit: src/usr.bin/ftp

2022-08-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 30 08:51:28 UTC 2022

Modified Files:
src/usr.bin/ftp: ftp.1 ssl.c

Log Message:
Add cert verification, together with an environment variable "NO_CERT_VERIFY",
to turn it off.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-10-09 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Oct  9 09:07:21 UTC 2021

Modified Files:
src/usr.bin/ftp: main.c

Log Message:
ftp: fix -? more portably

Start the optstring with ":" (which implicitly disables opterr),
and handle '?' with optopt=='?' separately to ':'.
Fixes -? display of full usage on other platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/ftp/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.127 src/usr.bin/ftp/main.c:1.128
--- src/usr.bin/ftp/main.c:1.127	Sat Jul 18 03:00:37 2020
+++ src/usr.bin/ftp/main.c	Sat Oct  9 09:07:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $	*/
+/*	$NetBSD: main.c,v 1.128 2021/10/09 09:07:20 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.128 2021/10/09 09:07:20 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -267,7 +267,7 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, "?46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+	while ((ch = getopt(argc, argv, ":46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -420,6 +420,11 @@ main(int volatile argc, char **volatile 
 			if (optopt == '?') {
 return usage_help();
 			}
+			warnx("-%c: unknown option", optopt);
+			return usage();
+
+		case ':':
+			warnx("-%c: missing argument", optopt);
 			return usage();
 
 		default:



CVS commit: src/usr.bin/ftp

2021-10-09 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Oct  9 09:07:21 UTC 2021

Modified Files:
src/usr.bin/ftp: main.c

Log Message:
ftp: fix -? more portably

Start the optstring with ":" (which implicitly disables opterr),
and handle '?' with optopt=='?' separately to ':'.
Fixes -? display of full usage on other platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/ftp/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-08-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 27 17:35:03 UTC 2021

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
ftp: fix undefined behavior when parsing FEAT

lint says: warning: argument to 'function from ' must be cast
to 'unsigned char', not to 'int' [342]


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-08-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 27 17:35:03 UTC 2021

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
ftp: fix undefined behavior when parsing FEAT

lint says: warning: argument to 'function from ' must be cast
to 'unsigned char', not to 'int' [342]


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.162 src/usr.bin/ftp/util.c:1.163
--- src/usr.bin/ftp/util.c:1.162	Sun Apr 25 08:26:35 2021
+++ src/usr.bin/ftp/util.c	Fri Aug 27 17:35:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.162 2021/04/25 08:26:35 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.163 2021/08/27 17:35:03 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.162 2021/04/25 08:26:35 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.163 2021/08/27 17:35:03 rillig Exp $");
 #endif /* not lint */
 
 /*
@@ -171,7 +171,7 @@ parse_feat(const char *fline)
 			 * work-around broken ProFTPd servers that can't
 			 * even obey RFC 2389.
 			 */
-	while (*fline && isspace((int)*fline))
+	while (*fline && isspace((unsigned char)*fline))
 		fline++;
 
 	if (strcasecmp(fline, "MDTM") == 0)



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:25:59 UTC 2021

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20210826

Version bump for PASV/LPSV address validation


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.93 src/usr.bin/ftp/version.h:1.94
--- src/usr.bin/ftp/version.h:1.93	Thu Jun  3 10:23:33 2021
+++ src/usr.bin/ftp/version.h	Thu Aug 26 06:25:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.93 2021/06/03 10:23:33 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.94 2021/08/26 06:25:59 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20210603"
+#define	FTP_VERSION	"20210826"
 #endif



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:25:59 UTC 2021

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20210826

Version bump for PASV/LPSV address validation


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:23:24 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
ftp: remove unnecessary variable assignments

Remove assignment to error in initconn(); it's not tested anywhere after the
initial use, so no need to set it before goto bad.

(Looks like copypasta from the initial addition of the code in rev 1.48.)


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.173 src/usr.bin/ftp/ftp.c:1.174
--- src/usr.bin/ftp/ftp.c:1.173	Thu Aug 26 06:16:29 2021
+++ src/usr.bin/ftp/ftp.c	Thu Aug 26 06:23:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.173 2021/08/26 06:16:29 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.174 2021/08/26 06:23:24 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.173 2021/08/26 06:16:29 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.174 2021/08/26 06:23:24 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1381,13 +1381,11 @@ initconn(void)
 			if (data_addr.su_family != AF_INET) {
 fputs(
 "Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
-error = 1;
 goto bad;
 			}
 			if (code / 10 == 22 && code != 227) {
 fputs("wrong server: return code must be 227\n",
 	ttyout);
-error = 1;
 goto bad;
 			}
 			error = sscanf(pasv, "%u,%u,%u,%u,%u,%u",
@@ -1396,10 +1394,8 @@ initconn(void)
 			if (error != 6) {
 fputs(
 "Passive mode address scan failure. Shouldn't happen!\n", ttyout);
-error = 1;
 goto bad;
 			}
-			error = 0;
 			memset(_addr, 0, sizeof(data_addr));
 			data_addr.su_family = AF_INET;
 			data_addr.su_len = sizeof(struct sockaddr_in);
@@ -1416,7 +1412,6 @@ initconn(void)
 			if (code / 10 == 22 && code != 228) {
 fputs("wrong server: return code must be 228\n",
 	ttyout);
-error = 1;
 goto bad;
 			}
 			switch (data_addr.su_family) {
@@ -1429,17 +1424,14 @@ initconn(void)
 if (error != 9) {
 	fputs(
 "Passive mode address scan failure. Shouldn't happen!\n", ttyout);
-	error = 1;
 	goto bad;
 }
 if (af != 4 || hal != 4 || pal != 2) {
 	fputs(
 "Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
-	error = 1;
 	goto bad;
 }
 
-error = 0;
 memset(_addr, 0, sizeof(data_addr));
 data_addr.su_family = AF_INET;
 data_addr.su_len = sizeof(struct sockaddr_in);
@@ -1467,17 +1459,14 @@ initconn(void)
 if (error != 21) {
 	fputs(
 "Passive mode address scan failure. Shouldn't happen!\n", ttyout);
-	error = 1;
 	goto bad;
 }
 if (af != 6 || hal != 16 || pal != 2) {
 	fputs(
 "Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
-	error = 1;
 	goto bad;
 }
 
-error = 0;
 memset(_addr, 0, sizeof(data_addr));
 data_addr.su_family = AF_INET6;
 data_addr.su_len = sizeof(struct sockaddr_in6);
@@ -1500,7 +1489,8 @@ initconn(void)
 break;
 #endif
 			default:
-error = 1;
+fputs("Unknown passive mode AF.\n", ttyout);
+goto bad;
 			}
 		} else if (strcmp(pasvcmd, "EPSV") == 0) {
 			char delim[4];
@@ -1509,20 +1499,17 @@ initconn(void)
 			if (code / 10 == 22 && code != 229) {
 fputs("wrong server: return code must be 229\n",
 	ttyout);
-error = 1;
 goto bad;
 			}
 			if (sscanf(pasv, "%c%c%c%d%c", [0],
 	[1], [2], [1],
 	[3]) != 5) {
 fputs("parse error!\n", ttyout);
-error = 1;
 goto bad;
 			}
 			if (delim[0] != delim[1] || delim[0] != delim[2]
 			 || delim[0] != delim[3]) {
 fputs("parse error!\n", ttyout);
-error = 1;
 goto bad;
 			}
 			data_addr = hisctladdr;



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:23:24 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
ftp: remove unnecessary variable assignments

Remove assignment to error in initconn(); it's not tested anywhere after the
initial use, so no need to set it before goto bad.

(Looks like copypasta from the initial addition of the code in rev 1.48.)


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:16:29 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
ftp: validate address from PASV and LPSV response

Fail if the server's response to PASV or LPSV contains an IP address
that doesn't match that of the control connection.
(EPSV already only uses the port portion of the server's response,
per RFC 2428).

Previously a hostile server could cause ftp to open a data connection elsewhere.

Many other ftp implementations have had a similar change for many years,
including those in popular browsers (before they deprecated FTP ...)

Thanks to Simon Josefsson notifying me about
  https://lists.gnu.org/archive/html/bug-inetutils/2021-06/msg2.html


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-08-26 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Aug 26 06:16:29 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
ftp: validate address from PASV and LPSV response

Fail if the server's response to PASV or LPSV contains an IP address
that doesn't match that of the control connection.
(EPSV already only uses the port portion of the server's response,
per RFC 2428).

Previously a hostile server could cause ftp to open a data connection elsewhere.

Many other ftp implementations have had a similar change for many years,
including those in popular browsers (before they deprecated FTP ...)

Thanks to Simon Josefsson notifying me about
  https://lists.gnu.org/archive/html/bug-inetutils/2021-06/msg2.html


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.172 src/usr.bin/ftp/ftp.c:1.173
--- src/usr.bin/ftp/ftp.c:1.172	Thu Jun  3 10:11:00 2021
+++ src/usr.bin/ftp/ftp.c	Thu Aug 26 06:16:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.172 2021/06/03 10:11:00 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.173 2021/08/26 06:16:29 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.172 2021/06/03 10:11:00 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.173 2021/08/26 06:16:29 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1406,6 +1406,12 @@ initconn(void)
 			data_addr.si_su.su_sin.sin_addr.s_addr =
 			htonl(pack4(addr, 0));
 			data_addr.su_port = htons(pack2(port, 0));
+			if (data_addr.si_su.su_sin.sin_addr.s_addr !=
+			hisctladdr.si_su.su_sin.sin_addr.s_addr) {
+fputs("Passive mode address mismatch.\n",
+ttyout);
+goto bad;
+			}
 		} else if (strcmp(pasvcmd, "LPSV") == 0) {
 			if (code / 10 == 22 && code != 228) {
 fputs("wrong server: return code must be 228\n",
@@ -1440,6 +1446,12 @@ initconn(void)
 data_addr.si_su.su_sin.sin_addr.s_addr =
 htonl(pack4(addr, 0));
 data_addr.su_port = htons(pack2(port, 0));
+if (data_addr.si_su.su_sin.sin_addr.s_addr !=
+hisctladdr.si_su.su_sin.sin_addr.s_addr) {
+	fputs("Passive mode address mismatch.\n",
+	ttyout);
+	goto bad;
+}
 break;
 #ifdef INET6
 			case AF_INET6:
@@ -1477,6 +1489,14 @@ initconn(void)
 }
 			}
 data_addr.su_port = htons(pack2(port, 0));
+if (memcmp(
+_addr.si_su.su_sin6.sin6_addr,
+_su.su_sin6.sin6_addr,
+sizeof(data_addr.si_su.su_sin6.sin6_addr))) {
+	fputs("Passive mode address mismatch.\n",
+	ttyout);
+	goto bad;
+}
 break;
 #endif
 			default:



CVS commit: src/usr.bin/ftp

2021-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jul  6 09:26:47 UTC 2021

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Use raw write(2) instead of fwrite(3) to avoid stream corruption because
of the progress bar interrupts. From RVP.


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.232 src/usr.bin/ftp/fetch.c:1.233
--- src/usr.bin/ftp/fetch.c:1.232	Fri Jul 10 20:29:38 2020
+++ src/usr.bin/ftp/fetch.c	Tue Jul  6 05:26:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp $	*/
+/*	$NetBSD: fetch.c,v 1.233 2021/07/06 09:26:47 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.233 2021/07/06 09:26:47 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -138,6 +138,43 @@ static int	redirect_loop;
 	((urltype) == HTTP_URL_T)
 #endif
 
+/**
+ * fwrite(3) replacement that just uses write(2). Many stdio implementations
+ * don't handle interrupts properly and corrupt the output. We are taking
+ * alarm interrupts because of the progress bar.
+ *
+ * Assumes `fp' is pristine with no prior I/O calls on it.
+ */
+static size_t
+maxwrite(const void *buf, size_t size, size_t nmemb, FILE *fp)
+{
+	const char *p = buf;
+	ssize_t nwr = 0;
+	ssize_t n;
+	int fd = fileno(fp);
+
+	size *= nmemb;	/* assume no overflow */
+
+	while (size > 0) {
+		if ((n = write(fd, p, size)) == -1) {
+			switch (errno) {
+			case EINTR:
+			case EAGAIN:
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
+			case EWOULDBLOCK:
+#endif
+continue;
+			default:
+return nwr;
+			}
+		}
+		p += n;
+		nwr += n;
+		size -= n;
+	}
+	return nwr;
+}
+
 /*
  * Determine if token is the next word in buf (case insensitive).
  * If so, advance buf past the token and any trailing LWS, and
@@ -1650,7 +1687,7 @@ fetch_url(const char *url, const char *p
 }
 bytes += flen;
 bufrem -= flen;
-if (fwrite(xferbuf, sizeof(char), flen, fout)
+if (maxwrite(xferbuf, sizeof(char), flen, fout)
 != flen) {
 	warn("Writing `%s'", savefile);
 	goto cleanup_fetch_url;



CVS commit: src/usr.bin/ftp

2021-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jul  6 09:26:47 UTC 2021

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
Use raw write(2) instead of fwrite(3) to avoid stream corruption because
of the progress bar interrupts. From RVP.


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-06-03 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Jun  3 10:23:33 UTC 2021

Modified Files:
src/usr.bin/ftp: Makefile ssl.c ssl.h version.h

Log Message:
use fetch_*() for I/O with SMALLPROG / !WITH_SSL builds

Adapt the SMALLPROG / -UWITH_SSL build to also use the fetch_*()
methods from ssl.c, instead of using stdio, as stdio isn't robust
when using interruptable signals.

Disable ssl-specific support in the fetch_*() methods if WITH_SSL
isn't defined, so SMALLPROG still doesn't have ssl support (as expected).

The resulting SMALLPROG binary is slightly larger than before
(e.g., 157KiB vs 153KiB on amd64).

Set version to 20210603 for this fix and the SO_KEEPALIVE fix for PR 56129.

PR install/56219


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/ftp/Makefile
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/ftp/ssl.h
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/Makefile
diff -u src/usr.bin/ftp/Makefile:1.38 src/usr.bin/ftp/Makefile:1.39
--- src/usr.bin/ftp/Makefile:1.38	Sun Sep  6 07:20:31 2020
+++ src/usr.bin/ftp/Makefile	Thu Jun  3 10:23:33 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.38 2020/09/06 07:20:31 mrg Exp $
+#	$NetBSD: Makefile,v 1.39 2021/06/03 10:23:33 lukem Exp $
 #	from: @(#)Makefile	8.2 (Berkeley) 4/3/94
 
 .include 
@@ -8,6 +8,7 @@ USE_FORT?= yes	# network client
 PROG=	ftp
 SRCS=	cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c \
 	progressbar.c ruserpass.c util.c
+SRCS+=	ssl.c
 
 # Uncomment the following to provide defaults for gate-ftp operation
 #
@@ -19,7 +20,6 @@ CPPFLAGS+=-DNO_EDITCOMPLETE -DNO_ABOUT -
 LDADD+=	-ledit -lterminfo
 DPADD+=	${LIBEDIT} ${LIBTERMINFO}
 CPPFLAGS+= -DWITH_SSL
-SRCS+=ssl.c
 LDADD+= -lssl -lcrypto
 DPADD+= ${LIBSSL} ${LIBCRYPTO}
 .endif

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.9 src/usr.bin/ftp/ssl.c:1.10
--- src/usr.bin/ftp/ssl.c:1.9	Wed Jan  6 04:43:14 2021
+++ src/usr.bin/ftp/ssl.c	Thu Jun  3 10:23:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.9 2021/01/06 04:43:14 lukem Exp $	*/
+/*	$NetBSD: ssl.c,v 1.10 2021/06/03 10:23:33 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,13 +34,17 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.9 2021/01/06 04:43:14 lukem Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.10 2021/06/03 10:23:33 lukem Exp $");
 #endif
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
-#include 
 
 #include 
 #include 
@@ -48,11 +52,14 @@ __RCSID("$NetBSD: ssl.c,v 1.9 2021/01/06
 
 #include 
 #include 
+
+#ifdef WITH_SSL
 #include 
 #include 
 #include 
 #include 
 #include 
+#endif
 
 #include "ssl.h"
 
@@ -75,7 +82,9 @@ struct fetch_connect {
 	int 			 issock;
 	int			 iserr;
 	int			 iseof;
+#ifdef WITH_SSL
 	SSL			*ssl;		/* SSL handle */
+#endif
 };
 
 /*
@@ -121,9 +130,11 @@ fetch_writev(struct fetch_connect *conn,
 			}
 		}
 		errno = 0;
+#ifdef WITH_SSL
 		if (conn->ssl != NULL)
 			len = SSL_write(conn->ssl, iov->iov_base, iov->iov_len);
 		else
+#endif
 			len = writev(fd, iov, iovcnt);
 		if (len == 0) {
 			/* we consider a short write a failure */
@@ -275,7 +286,9 @@ fetch_close(struct fetch_connect *conn)
 		return 0;
 
 	fetch_flush(conn);
+#ifdef WITH_SSL
 	SSL_free(conn->ssl);
+#endif
 	close(conn->sd);
 	free(conn->cache.buf);
 	free(conn->buf);
@@ -287,6 +300,7 @@ fetch_close(struct fetch_connect *conn)
 #define FETCH_READ_WAIT		-2
 #define FETCH_READ_ERROR	-1
 
+#ifdef WITH_SSL
 static ssize_t
 fetch_ssl_read(SSL *ssl, void *buf, size_t len)
 {
@@ -305,6 +319,7 @@ fetch_ssl_read(SSL *ssl, void *buf, size
 		return FETCH_READ_ERROR;
 	}
 }
+#endif /* WITH_SSL */
 
 static ssize_t
 fetch_nonssl_read(int sd, void *buf, size_t len)
@@ -433,9 +448,11 @@ fetch_read(void *ptr, size_t size, size_
 		 * In the non-SSL case, it may improve performance (very
 		 * slightly) when reading small amounts of data.
 		 */
+#ifdef WITH_SSL
 		if (conn->ssl != NULL)
 			rlen = fetch_ssl_read(conn->ssl, buf, len);
 		else
+#endif
 			rlen = fetch_nonssl_read(conn->sd, buf, len);
 		switch (rlen) {
 		case 0:
@@ -564,6 +581,7 @@ fetch_getline(struct fetch_connect *conn
 	return len;
 }
 
+#ifdef WITH_SSL
 void *
 fetch_start_ssl(int sock, const char *servername)
 {
@@ -624,10 +642,13 @@ fetch_start_ssl(int sock, const char *se
 
 	return ssl;
 }
+#endif /* WITH_SSL */
 
 
 void
 fetch_set_ssl(struct fetch_connect *conn, void *ssl)
 {
+#ifdef WITH_SSL
 	conn->ssl = ssl;
+#endif
 }

Index: src/usr.bin/ftp/ssl.h
diff -u src/usr.bin/ftp/ssl.h:1.4 src/usr.bin/ftp/ssl.h:1.5
--- src/usr.bin/ftp/ssl.h:1.4	Thu Apr  4 00:36:09 2019
+++ src/usr.bin/ftp/ssl.h	Thu Jun  3 10:23:33 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: ssl.h,v 1.4 2019/04/04 00:36:09 christos Exp $	*/
+/*	$NetBSD: ssl.h,v 1.5 

CVS commit: src/usr.bin/ftp

2021-06-03 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Jun  3 10:23:33 UTC 2021

Modified Files:
src/usr.bin/ftp: Makefile ssl.c ssl.h version.h

Log Message:
use fetch_*() for I/O with SMALLPROG / !WITH_SSL builds

Adapt the SMALLPROG / -UWITH_SSL build to also use the fetch_*()
methods from ssl.c, instead of using stdio, as stdio isn't robust
when using interruptable signals.

Disable ssl-specific support in the fetch_*() methods if WITH_SSL
isn't defined, so SMALLPROG still doesn't have ssl support (as expected).

The resulting SMALLPROG binary is slightly larger than before
(e.g., 157KiB vs 153KiB on amd64).

Set version to 20210603 for this fix and the SO_KEEPALIVE fix for PR 56129.

PR install/56219


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/ftp/Makefile
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/ftp/ssl.h
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-06-03 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Jun  3 10:11:00 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
set SO_KEEPALIVE on control connection

Attempt to prevent timeouts of the control connection by setting SO_KEEPALIVE.
This matches the equivalent behaviour in ftpd.

Note: This is a much simpler change than adding a background polling event
to invoke "STAT" (or "NOOP") on the control connection during a transfer.
(It's unclear from RFC 959 whether "NOOP" is even permitted during a transfer).

PR bin/56129


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-06-03 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Jun  3 10:11:00 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c

Log Message:
set SO_KEEPALIVE on control connection

Attempt to prevent timeouts of the control connection by setting SO_KEEPALIVE.
This matches the equivalent behaviour in ftpd.

Note: This is a much simpler change than adding a background polling event
to invoke "STAT" (or "NOOP") on the control connection during a transfer.
(It's unclear from RFC 959 whether "NOOP" is even permitted during a transfer).

PR bin/56129


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/usr.bin/ftp/ftp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.171 src/usr.bin/ftp/ftp.c:1.172
--- src/usr.bin/ftp/ftp.c:1.171	Wed Jan  6 04:43:14 2021
+++ src/usr.bin/ftp/ftp.c	Thu Jun  3 10:11:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.171 2021/01/06 04:43:14 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.172 2021/06/03 10:11:00 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.171 2021/01/06 04:43:14 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.172 2021/06/03 10:11:00 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -280,6 +280,11 @@ hookup(const char *host, const char *por
 		goto bad;
 	}
 
+	if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
+			(void *), sizeof(on)) == -1) {
+		DWARN("setsockopt %s (ignored)", "SO_KEEPALIVE");
+	}
+
 	if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
 			(void *), sizeof(on)) == -1) {
 		DWARN("setsockopt %s (ignored)", "SO_OOBINLINE");



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 09:09:55 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistently use FTP for protocol use.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 09:09:55 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistently use FTP for protocol use.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.145 src/usr.bin/ftp/ftp.1:1.146
--- src/usr.bin/ftp/ftp.1:1.145	Sun Apr 25 08:46:19 2021
+++ src/usr.bin/ftp/ftp.1	Sun Apr 25 09:09:55 2021
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.145 2021/04/25 08:46:19 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.146 2021/04/25 09:09:55 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -184,10 +184,13 @@ Forces
 .Nm
 to only use IPv6 addresses.
 .It Fl A
-Force active mode ftp.
+Force active mode
+.Tn FTP .
 By default,
 .Nm
-will try to use passive mode ftp and fall back to active mode
+will try to use passive mode
+.Tn FTP
+and fall back to active mode
 if passive is not supported by the server.
 This option causes
 .Nm
@@ -300,7 +303,9 @@ Upload files on the command line to
 .Ar url
 where
 .Ar url
-is one of the ftp URL types as supported by auto-fetch
+is one of the
+.Sq Li ftp://
+URL types as supported by auto-fetch
 (with an optional target filename for single file uploads), and
 .Ar file
 is one or more local files to be uploaded.
@@ -542,7 +547,9 @@ A synonym for
 .Ic open .
 .It Ic gate Op Ar host Op Ar port
 Toggle gate-ftp mode, which used to connect through the
-TIS FWTK and Gauntlet ftp proxies.
+TIS FWTK and Gauntlet
+.Tn FTP
+proxies.
 This will not be permitted if the gate-ftp server hasn't been set
 (either explicitly by the user, or from the
 .Ev FTPSERVER
@@ -600,7 +607,9 @@ each remote file name is expanded
 separately on the remote machine and the lists are not merged.
 Expansion of a directory name is likely to be
 different from expansion of the name of an ordinary file:
-the exact result depends on the foreign operating system and ftp server,
+the exact result depends on the foreign operating system and
+.Tn FTP
+server,
 and can be previewed by doing
 .Sq Li mls remote-files \- .
 Note:
@@ -1112,7 +1121,9 @@ Any other response will answer
 .Sq yes
 to the current file.
 .It Ic proxy Ar ftp-command
-Execute an ftp command on a secondary control connection.
+Execute an
+.Tn FTP
+command on a secondary control connection.
 This command allows simultaneous connection to two remote
 .Tn FTP
 servers for transferring files between the two servers.



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 08:46:19 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistent Ic (not Nm) for commands


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.144 src/usr.bin/ftp/ftp.1:1.145
--- src/usr.bin/ftp/ftp.1:1.144	Sun Jan 31 08:59:40 2021
+++ src/usr.bin/ftp/ftp.1	Sun Apr 25 08:46:19 2021
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.144 2021/01/31 08:59:40 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.145 2021/04/25 08:46:19 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd January 31, 2021
+.Dd April 25, 2021
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -1886,9 +1886,9 @@ proxies will be restarted.
 For
 .Tn FTP ,
 this is implemented by using
-.Nm reget
+.Ic reget
 instead of
-.Nm get .
+.Ic get .
 For
 .Tn HTTP ,
 this is implemented by using the



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 08:46:19 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistent Ic (not Nm) for commands


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 08:26:35 UTC 2021

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
better XXX comment for buggy ftp server


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.161 src/usr.bin/ftp/util.c:1.162
--- src/usr.bin/ftp/util.c:1.161	Mon Jun  8 01:33:27 2020
+++ src/usr.bin/ftp/util.c	Sun Apr 25 08:26:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.161 2020/06/08 01:33:27 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.162 2021/04/25 08:26:35 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.161 2020/06/08 01:33:27 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.162 2021/04/25 08:26:35 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -731,7 +731,7 @@ remotemodtime(const char *file, int nois
 			*frac++ = '\0';
 		if (strlen(timestr) == 15 && strncmp(timestr, "191", 3) == 0) {
 			/*
-			 * XXX:	Workaround for lame ftpd's that return
+			 * XXX:	Workaround for buggy ftp servers that return
 			 *	`19100' instead of `2000'
 			 */
 			fprintf(ttyout,



CVS commit: src/usr.bin/ftp

2021-04-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 25 08:26:35 UTC 2021

Modified Files:
src/usr.bin/ftp: util.c

Log Message:
better XXX comment for buggy ftp server


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-01-31 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Jan 31 08:59:40 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): more $https_proxy documentation

Document $https_proxy in ENVIRONMENT.
(It was already documented elsewhere).

Fixes PR bin/51883


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.143 src/usr.bin/ftp/ftp.1:1.144
--- src/usr.bin/ftp/ftp.1:1.143	Wed Jan  6 09:15:59 2021
+++ src/usr.bin/ftp/ftp.1	Sun Jan 31 08:59:40 2021
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.143 2021/01/06 09:15:59 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.144 2021/01/31 08:59:40 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd January 6, 2021
+.Dd January 31, 2021
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -2362,6 +2362,16 @@ may be incompatible with other programs 
 .Em NOTE :
 this is not used for interactive sessions, only for command-line
 fetches.
+.It Ev https_proxy
+URL of
+.Tn HTTPS
+proxy to use when making
+.Tn HTTPS
+URL requests.
+.Pp
+See
+.Ev http_proxy
+for further notes about proxy use.
 .It Ev no_proxy
 A space or comma separated list of hosts (or domains) for which
 proxying is not to be used.



CVS commit: src/usr.bin/ftp

2021-01-31 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Jan 31 08:59:40 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): more $https_proxy documentation

Document $https_proxy in ENVIRONMENT.
(It was already documented elsewhere).

Fixes PR bin/51883


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-01-06 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jan  6 09:15:59 UTC 2021

Modified Files:
src/usr.bin/ftp: cmds.c ftp.1

Log Message:
ftp(1): fix description of "debug"

"debug" command and documentation got accidentally renamed
to "ftp_debug" 13 years ago, and was only partially fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.142 -r1.143 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/cmds.c
diff -u src/usr.bin/ftp/cmds.c:1.140 src/usr.bin/ftp/cmds.c:1.141
--- src/usr.bin/ftp/cmds.c:1.140	Wed Feb  6 07:56:42 2019
+++ src/usr.bin/ftp/cmds.c	Wed Jan  6 09:15:59 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: cmds.c,v 1.140 2019/02/06 07:56:42 martin Exp $	*/
+/*	$NetBSD: cmds.c,v 1.141 2021/01/06 09:15:59 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.140 2019/02/06 07:56:42 martin Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.141 2021/01/06 09:15:59 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1131,7 +1131,7 @@ setdebug(int argc, char *argv[])
 		options |= SO_DEBUG;
 	else
 		options &= ~SO_DEBUG;
-	fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
+	fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(ftp_debug), ftp_debug);
 	code = ftp_debug > 0;
 }
 

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.142 src/usr.bin/ftp/ftp.1:1.143
--- src/usr.bin/ftp/ftp.1:1.142	Sat Jul 18 03:00:37 2020
+++ src/usr.bin/ftp/ftp.1	Wed Jan  6 09:15:59 2021
@@ -1,6 +1,6 @@
-.\" 	$NetBSD: ftp.1,v 1.142 2020/07/18 03:00:37 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.143 2021/01/06 09:15:59 lukem Exp $
 .\"
-.\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 18, 2020
+.Dd January 6, 2021
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -455,6 +455,16 @@ when an ascii type transfer is made, the
 distinguished from a record delimiter only when
 .Ic \
 is off.
+.It Ic debug Op Ar debug-value
+Toggle debugging mode.
+If an optional
+.Ar debug-value
+is specified it is used to set the debugging level.
+When debugging is on,
+.Nm
+prints each command sent to the remote machine, preceded
+by the string
+.Ql \-\-> .
 .It Ic delete Ar remote-file
 Delete the file
 .Ar remote-file
@@ -530,16 +540,6 @@ format is
 .It Ic ftp Ar host Op Ar port
 A synonym for
 .Ic open .
-.It Ic ftp_debug Op Ar ftp_debug-value
-Toggle debugging mode.
-If an optional
-.Ar ftp_debug-value
-is specified it is used to set the debugging level.
-When debugging is on,
-.Nm
-prints each command sent to the remote machine, preceded
-by the string
-.Ql \-\-> .
 .It Ic gate Op Ar host Op Ar port
 Toggle gate-ftp mode, which used to connect through the
 TIS FWTK and Gauntlet ftp proxies.



CVS commit: src/usr.bin/ftp

2021-01-06 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jan  6 09:15:59 UTC 2021

Modified Files:
src/usr.bin/ftp: cmds.c ftp.1

Log Message:
ftp(1): fix description of "debug"

"debug" command and documentation got accidentally renamed
to "ftp_debug" 13 years ago, and was only partially fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.142 -r1.143 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2021-01-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jan  6 04:43:14 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c progressbar.c progressbar.h ssl.c version.h

Log Message:
ftp: don't use restartable signals

Refactor to not rely upon restartable signals (SA_RESTART),
possibly fixing intermittent failures with -q QUITTIME.

ftp transfers: handle EINTR/EAGAIN in copy_bytes(),
instead of relying upon restartable signals.

http/https transfers: Explicitly print an error similar to
progressmeter() when timing-out for -Q QUITTIME in fetch_wait(),
and set errno to ETIMEDOUT so that the warn() in fetch_url()
prints a more accurate error message.

PR/55857


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/ftp/progressbar.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/ftp/progressbar.h src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.170 src/usr.bin/ftp/ftp.c:1.171
--- src/usr.bin/ftp/ftp.c:1.170	Sat Jul 11 02:19:31 2020
+++ src/usr.bin/ftp/ftp.c	Wed Jan  6 04:43:14 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: ftp.c,v 1.170 2020/07/11 02:19:31 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.171 2021/01/06 04:43:14 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.170 2020/07/11 02:19:31 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.171 2021/01/06 04:43:14 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -593,7 +593,7 @@ abortxfer(int notused)
 
 /*
  * Read data from infd & write to outfd, using buf/bufsize as the temporary
- * buffer, dealing with short writes.
+ * buffer, dealing with short reads or writes.
  * If rate_limit != 0, rate-limit the transfer.
  * If hash_interval != 0, fputc('c', ttyout) every hash_interval bytes.
  * Updates global variables: bytes.
@@ -627,15 +627,25 @@ copy_bytes(int infd, int outfd, char *bu
 		bufrem = bufchunk;
 		while (bufrem > 0) {
 			inc = read(infd, buf, MIN((off_t)bufsize, bufrem));
-			if (inc <= 0)
+			if (inc < 0) {
+if (errno == EINTR || errno == EAGAIN) {
+	continue;
+}
+goto copy_done;
+			} else if (inc == 0) {
 goto copy_done;
+			}
 			bytes += inc;
 			bufrem -= inc;
 			bufp = buf;
 			while (inc > 0) {
 outc = write(outfd, bufp, inc);
-if (outc < 0)
+if (outc < 0) {
+	if (errno == EINTR || errno == EAGAIN) {
+		continue;
+	}
 	goto copy_done;
+}
 inc -= outc;
 bufp += outc;
 			}

Index: src/usr.bin/ftp/progressbar.c
diff -u src/usr.bin/ftp/progressbar.c:1.23 src/usr.bin/ftp/progressbar.c:1.24
--- src/usr.bin/ftp/progressbar.c:1.23	Sat Jun 22 23:40:33 2019
+++ src/usr.bin/ftp/progressbar.c	Wed Jan  6 04:43:14 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $	*/
+/*	$NetBSD: progressbar.c,v 1.24 2021/01/06 04:43:14 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $");
+__RCSID("$NetBSD: progressbar.c,v 1.24 2021/01/06 04:43:14 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -193,7 +193,7 @@ progressmeter(int flag)
 	if (quit_time > 0 || progress) {
 #endif /* !STANDALONE_PROGRESS */
 		if (flag == -1) {
-			(void)xsignal_restart(SIGALRM, updateprogressmeter, 1);
+			(void)xsignal(SIGALRM, updateprogressmeter);
 			alarmtimer(1);		/* set alarm timer for 1 Hz */
 		} else if (flag == 1) {
 			alarmtimer(0);
@@ -404,73 +404,21 @@ alarmtimer(int wait)
 	setitimer(ITIMER_REAL, , NULL);
 }
 
-
 /*
- * Install a POSIX signal handler, allowing the invoker to set whether
- * the signal should be restartable or not
+ * Install a non-restartable POSIX signal handler.
  */
 sigfunc
-xsignal_restart(int sig, sigfunc func, int restartable)
+xsignal(int sig, sigfunc func)
 {
 	struct sigaction act, oact;
 	act.sa_handler = func;
 
 	sigemptyset(_mask);
-#if defined(SA_RESTART)			/* 4.4BSD, Posix(?), SVR4 */
-	act.sa_flags = restartable ? SA_RESTART : 0;
-#elif defined(SA_INTERRUPT)		/* SunOS 4.x */
-	act.sa_flags = restartable ? 0 : SA_INTERRUPT;
-#else
-#error "system must have SA_RESTART or SA_INTERRUPT"
+	act.sa_flags = 0;
+#if defined(SA_INTERRUPT)		/* SunOS 4.x */
+	act.sa_flags = SA_INTERRUPT;
 #endif
 	if (sigaction(sig, , ) < 0)
 		return (SIG_ERR);
 	return (oact.sa_handler);
 }
-

CVS commit: src/usr.bin/ftp

2021-01-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jan  6 04:43:14 UTC 2021

Modified Files:
src/usr.bin/ftp: ftp.c progressbar.c progressbar.h ssl.c version.h

Log Message:
ftp: don't use restartable signals

Refactor to not rely upon restartable signals (SA_RESTART),
possibly fixing intermittent failures with -q QUITTIME.

ftp transfers: handle EINTR/EAGAIN in copy_bytes(),
instead of relying upon restartable signals.

http/https transfers: Explicitly print an error similar to
progressmeter() when timing-out for -Q QUITTIME in fetch_wait(),
and set errno to ETIMEDOUT so that the warn() in fetch_url()
prints a more accurate error message.

PR/55857


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/ftp/progressbar.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/ftp/progressbar.h src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-17 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 18 03:00:38 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1 main.c version.h

Log Message:
ftp: add -? for help. improve synopsis

Add -? to display usage synopsis and help to stdout.
This allows for "ftp -? | less", which is more user friendly.
Errors still show usage to stderr.
Consistency improvements in some usage text.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.141 src/usr.bin/ftp/ftp.1:1.142
--- src/usr.bin/ftp/ftp.1:1.141	Wed Jul 15 19:23:44 2020
+++ src/usr.bin/ftp/ftp.1	Sat Jul 18 03:00:37 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.141 2020/07/15 19:23:44 uwe Exp $
+.\" 	$NetBSD: ftp.1,v 1.142 2020/07/18 03:00:37 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 15, 2020
+.Dd July 18, 2020
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -65,7 +65,7 @@
 .Nd Internet file transfer program
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46AadefginpRtVv
+.Op Fl 46AadefginpRtVv?
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
@@ -121,7 +121,7 @@
 .Ar host Oo Li \&: Ar port Oc
 .Li / Ar path
 .Op Li /
-.Op Li ;type= Ar X
+.Op Li ;type= Ar type
 .Oc
 .Sm on
 .Ek
@@ -138,6 +138,19 @@
 .Oc
 .Sm on
 .Ek
+.Bk -words
+.\" [https://[user[:password]@]host[:port]/path]
+.Sm off
+.Oo
+.Li https://
+.Oo Ar user
+.Op Li \&: Ar password
+.Li \&@ Oc
+.Ar host Oo Li \&: Ar port Oc
+.Li / Ar path
+.Oc
+.Sm on
+.Ek
 .Ar \&...
 .Nm
 .Bk -words
@@ -316,6 +329,8 @@ Set the size of the socket send and rece
 Refer to
 .Ic xferbuf
 for more information.
+.It Fl ?
+Display help to stdout, and exit.
 .El
 .Pp
 The client host with which
@@ -1581,10 +1596,10 @@ of
 in the current directory.
 Otherwise, the full remote name is used as the local name,
 relative to the local root directory.
-.\" ftp://[user[:password]@]host[:port]/path[/][;type=X]
+.\" ftp://[user[:password]@]host[:port]/path[/][;type=type]
 .It Li ftp:// Ns Oo Ar user Ns Oo Ns Li \&: Ns Ar password Oc Ns Li \&@ Oc \
 Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path Ns Oo Li / Oc \
-Ns Oo Li ;type= Ns Ar X Oc
+Ns Oo Li ;type= Ns Ar type Oc
 An
 .Tn FTP
 URL, retrieved using the

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.126 src/usr.bin/ftp/main.c:1.127
--- src/usr.bin/ftp/main.c:1.126	Mon Feb  4 04:09:13 2019
+++ src/usr.bin/ftp/main.c	Sat Jul 18 03:00:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $	*/
+/*	$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $");
+__RCSID("$NetBSD: main.c,v 1.127 2020/07/18 03:00:37 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,7 +130,8 @@ __RCSID("$NetBSD: main.c,v 1.126 2019/02
 #define	NO_PROXY	"no_proxy"	/* env var with list of non-proxied
 	 * hosts, comma or space separated */
 
-__dead static void	usage(void);
+static int	usage(void);
+static int	usage_help(void);
 static void	setupoption(const char *, const char *, const char *);
 
 int
@@ -266,7 +267,7 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+	while ((ch = getopt(argc, argv, "?46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -378,15 +379,15 @@ main(int volatile argc, char **volatile 
 if (*cp == '\0') {
 	warnx("Bad throttle value `%s'",
 	optarg);
-	usage();
-	/* NOTREACHED */
+	return usage();
 }
 targv[targc++] = cp;
 if (targc >= 5)
 	break;
 			}
-			if (parserate(targc, targv, 1) == -1)
-usage();
+			if (parserate(targc, targv, 1) == -1) {
+return usage();
+			}
 			free(oac);
 			break;
 		}
@@ -415,8 +416,14 @@ main(int volatile argc, char **volatile 
 			rcvbuf_size = sndbuf_size;
 			break;
 
+		case '?':
+			if (optopt == '?') {
+return usage_help();
+			}
+			return usage();
+
 		default:
-			usage();
+			errx(1, "unimplemented option -%c", ch);
 		}
 	}
 			/* set line buffering on ttyout */
@@ -572,8 +579,9 @@ main(int volatile argc, char **volatile 
 			retry_connect = 0; /* connected, stop hiding msgs */
 		}
 	}
-	if (isupload)
-		usage();
+	if (isupload) {
+		return usage();
+	}
 
 #ifndef NO_EDITCOMPLETE
 	controlediting();
@@ -836,7 +844,6 @@ slurpstring(void)
 slrflag++;
 INC_CHKCURSOR(stringbase);
 

CVS commit: src/usr.bin/ftp

2020-07-17 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 18 03:00:38 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1 main.c version.h

Log Message:
ftp: add -? for help. improve synopsis

Add -? to display usage synopsis and help to stdout.
This allows for "ftp -? | less", which is more user friendly.
Errors still show usage to stderr.
Consistency improvements in some usage text.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 15 19:23:44 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Try to improve markup for better PostScript output.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 15 19:23:44 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Try to improve markup for better PostScript output.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.140 src/usr.bin/ftp/ftp.1:1.141
--- src/usr.bin/ftp/ftp.1:1.140	Wed Jul 15 17:36:38 2020
+++ src/usr.bin/ftp/ftp.1	Wed Jul 15 19:23:44 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.140 2020/07/15 17:36:38 uwe Exp $
+.\" 	$NetBSD: ftp.1,v 1.141 2020/07/15 19:23:44 uwe Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -475,18 +475,16 @@ Toggle command line editing, and context
 completion.
 This is automatically enabled if input is from a terminal, and
 disabled otherwise.
-.It Ic epsv epsv4 epsv6
+.It Ic epsv , epsv4 , epsv6
 Toggle the use of the extended
 .Dv EPSV
 and
 .Dv EPRT
 commands on all IP, IPv4, and IPv6 connections respectively.
 First try
-.Dv EPSV /
-.Dv EPRT ,
+.Dv EPSV Ns \^/\^ Ns Dv EPRT ,
 and then
-.Dv PASV /
-.Dv PORT .
+.Dv PASV Ns \^/\^ Ns Dv PORT .
 This is enabled by default.
 If an extended command fails then this option will be temporarily
 disabled for the duration of the current connection, or until
@@ -589,7 +587,7 @@ Expansion of a directory name is likely 
 different from expansion of the name of an ordinary file:
 the exact result depends on the foreign operating system and ftp server,
 and can be previewed by doing
-.Ql mls remote-files \-
+.Sq Li mls remote-files \- .
 Note:
 .Ic mget ,
 .Ic mput
@@ -670,32 +668,32 @@ To invoke a macro, use the
 command (see above).
 .Pp
 The macro processor interprets
-.Sq $
+.Ql $
 and
-.Sq \e
+.Ql \e
 as special characters.
 A
-.Sq $
+.Ql $
 followed by a number (or numbers) is replaced by the
 corresponding argument on the macro invocation command line.
 A
-.Sq $
+.Ql $
 followed by an
-.Sq i
+.Ql i
 signals the macro processor that the executing macro is to be
 looped.
 On the first pass
-.Dq $i
+.Ql $i
 is replaced by the first argument on the macro invocation command
 line, on the second pass it is replaced by the second argument,
 and so on.
 A
-.Sq \e
+.Ql \e
 followed by any character is replaced by that character.
 Use the
-.Sq \e
+.Ql \e
 to prevent special treatment of the
-.Sq $ .
+.Ql $ .
 .It Ic mdelete Op Ar remote-files
 Delete the
 .Ar remote-files
@@ -730,7 +728,7 @@ Files are transferred into the local wor
 which can be changed with
 .Ql lcd directory ;
 new local directories can be created with
-.Ql "\&! mkdir directory" .
+.Sq Li "\&! mkdir directory" .
 .It Ic mkdir Ar directory-name
 Make a directory on the remote machine.
 .It Ic mls Ar remote-files local-file
@@ -753,7 +751,7 @@ Display the contents of
 in a machine-parsable form, using
 .Dv MLSD .
 The format of display can be changed with
-.Sq "remopts mlst ..." .
+.Sq Li "remopts mlst ..." .
 .It Ic mlst Op Ar remote-path
 Display the details about
 .Ar remote-path
@@ -761,7 +759,7 @@ Display the details about
 in a machine-parsable form, using
 .Dv MLST .
 The format of display can be changed with
-.Sq "remopts mlst ..." .
+.Sq Li "remopts mlst ..." .
 .It Ic mode Ar mode-name
 Set the file transfer
 .Ic mode
@@ -807,7 +805,7 @@ If the file does not
 exist on the current system, the remote file is considered
 .Ic newer .
 Otherwise, this command is identical to
-.Ar get .
+.Ic get .
 .It Ic nlist Op Ar remote-path Op Ar local-file
 A synonym for
 .Ic ls .
@@ -832,7 +830,8 @@ The mapping follows the pattern set by
 .Ar inpattern
 and
 .Ar outpattern .
-.Op Ar Inpattern
+.Pp
+.Ar inpattern
 is a template for incoming filenames (which may have already been
 processed according to the
 .Ic ntrans
@@ -841,16 +840,16 @@ and
 settings).
 Variable templating is accomplished by including the
 sequences
-.Dq $1 ,
-.Dq $2 ,
-\&...
-.Dq $9
+.Ql $1 ,
+.Ql $2 ,
+\&...\|,
+.Ql $9
 in
 .Ar inpattern .
 Use
-.Sq \e
+.Ql \e
 to prevent this special treatment of the
-.Sq $
+.Ql $
 character.
 All other characters are treated literally, and are used to determine the
 .Ic nmap
@@ -858,53 +857,72 @@ All other characters are treated literal
 variable values.
 For example, given
 .Ar inpattern
-$1.$2 and the remote file name "mydata.data", $1 would have the value
-"mydata", and $2 would have the value "data".
+.Sq Li $1.$2
+and the remote file name
+.Sq Li mydata.data ,
+.Ql $1
+would have the value
+.Sq Li mydata ,
+and
+.Ql $2
+would have the value
+.Sq Li data .
+.Pp
 The
 .Ar outpattern
 determines the resulting mapped filename.
 The sequences
-.Dq $1 ,
-.Dq $2 ,
-\&...
-.Dq $9
+.Ql $1 ,
+.Ql $2 ,
+\&...\|,
+.Ql $9
 are replaced by any value resulting from the
 .Ar inpattern
 template.
 The sequence
-.Dq $0
+.Ql $0
 is replaced by the original filename.
 

CVS commit: src/usr.bin/ftp

2020-07-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 15 17:36:38 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Do not use "[...]", just "..." is enough.

Conventionally the ellipsis already expresses optional repetition,
e.g. .Ar without arguments produces "file ...".


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.139 src/usr.bin/ftp/ftp.1:1.140
--- src/usr.bin/ftp/ftp.1:1.139	Wed Jul 15 16:41:16 2020
+++ src/usr.bin/ftp/ftp.1	Wed Jul 15 17:36:38 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.139 2020/07/15 16:41:16 pgoyette Exp $
+.\" 	$NetBSD: ftp.1,v 1.140 2020/07/15 17:36:38 uwe Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -138,12 +138,11 @@
 .Oc
 .Sm on
 .Ek
-.Op Ar \&.\&.\&.
+.Ar \&...
 .Nm
 .Bk -words
-.Fl u Ar url Ar file
+.Fl u Ar url Ar
 .Ek
-.Op Ar \&.\&.\&.
 .Sh DESCRIPTION
 .Nm
 is the user interface to the Internet standard File Transfer Protocol.
@@ -283,7 +282,7 @@ bytes/second.
 Refer to
 .Ic rate
 for more information.
-.It Fl u Ar url file Op \&.\&.\&.
+.It Fl u Ar url Ar
 Upload files on the command line to
 .Ar url
 where



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jul 15 17:36:38 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Do not use "[...]", just "..." is enough.

Conventionally the ellipsis already expresses optional repetition,
e.g. .Ar without arguments produces "file ...".


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul 15 16:41:16 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Remove now-extraneous Op since we already have Oo and Oc to enclose
the Ar port.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jul 15 16:41:16 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
Remove now-extraneous Op since we already have Oo and Oc to enclose
the Ar port.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.138 src/usr.bin/ftp/ftp.1:1.139
--- src/usr.bin/ftp/ftp.1:1.138	Wed Jul 15 08:56:05 2020
+++ src/usr.bin/ftp/ftp.1	Wed Jul 15 16:41:16 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.138 2020/07/15 08:56:05 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.139 2020/07/15 16:41:16 pgoyette Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -88,7 +88,7 @@
 .Bk -words
 .\" [[user@]host [port]]
 .Oo
-.Oo Ar user Ns Li \&@ Oc Ns Ar host Oo Op Ar port Oc
+.Oo Ar user Ns Li \&@ Oc Ns Ar host Oo Ar port Oc
 .Oc
 .Ek
 .Bk -words



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jul 15 08:56:06 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp.1: don't wrap "[[user@]host [port]]"


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.137 src/usr.bin/ftp/ftp.1:1.138
--- src/usr.bin/ftp/ftp.1:1.137	Mon Jul 13 11:17:14 2020
+++ src/usr.bin/ftp/ftp.1	Wed Jul 15 08:56:05 2020
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.137 2020/07/13 11:17:14 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.138 2020/07/15 08:56:05 lukem Exp $
 .\"
 .\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd July 13, 2020
+.Dd July 15, 2020
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -88,8 +88,7 @@
 .Bk -words
 .\" [[user@]host [port]]
 .Oo
-.Oo Ar user Ns Li \&@ Oc Ns Ar host
-.Op Ar port
+.Oo Ar user Ns Li \&@ Oc Ns Ar host Oo Op Ar port Oc
 .Oc
 .Ek
 .Bk -words



CVS commit: src/usr.bin/ftp

2020-07-15 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Jul 15 08:56:06 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp.1: don't wrap "[[user@]host [port]]"


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-13 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jul 13 11:17:14 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistency tweaks


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.136 src/usr.bin/ftp/ftp.1:1.137
--- src/usr.bin/ftp/ftp.1:1.136	Mon Jul  3 21:34:57 2017
+++ src/usr.bin/ftp/ftp.1	Mon Jul 13 11:17:14 2020
@@ -1,6 +1,6 @@
-.\" 	$NetBSD: ftp.1,v 1.136 2017/07/03 21:34:57 wiz Exp $
+.\" 	$NetBSD: ftp.1,v 1.137 2020/07/13 11:17:14 lukem Exp $
 .\"
-.\" Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd April 24, 2015
+.Dd July 13, 2020
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -84,7 +84,7 @@
 .Xc
 .Oc
 .Ek
-.Op Fl x Ar xferbufsize
+.Op Fl x Ar xfersize
 .Bk -words
 .\" [[user@]host [port]]
 .Oo
@@ -142,7 +142,7 @@
 .Op Ar \&.\&.\&.
 .Nm
 .Bk -words
-.Fl u Ar URL Ar file
+.Fl u Ar url Ar file
 .Ek
 .Op Ar \&.\&.\&.
 .Sh DESCRIPTION
@@ -284,11 +284,11 @@ bytes/second.
 Refer to
 .Ic rate
 for more information.
-.It Fl u Ar URL file Op \&.\&.\&.
+.It Fl u Ar url file Op \&.\&.\&.
 Upload files on the command line to
-.Ar URL
+.Ar url
 where
-.Ar URL
+.Ar url
 is one of the ftp URL types as supported by auto-fetch
 (with an optional target filename for single file uploads), and
 .Ar file
@@ -312,9 +312,9 @@ Forces
 .Nm
 to show all responses from the remote server, as well
 as report on data transfer statistics.
-.It Fl x Ar xferbufsize
+.It Fl x Ar xfersize
 Set the size of the socket send and receive buffers to
-.Ar xferbufsize .
+.Ar xfersize .
 Refer to
 .Ic xferbuf
 for more information.



CVS commit: src/usr.bin/ftp

2020-07-13 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jul 13 11:17:14 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.1

Log Message:
ftp(1): consistency tweaks


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/usr.bin/ftp/ftp.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-10 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 11 02:19:32 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.c version.h

Log Message:
ftp.c: improve signal handler restoration

Only invoke the old signal handler if it's a real signal handler
and not SIG_IGN, SIG_DFL, SIG_HOLD, or SIG_ERR, using new static
function issighandler().
Avoids an intermittent race condition with a null pointer
dereference via (*SIG_DFL)().
Bug class reported by Joyu Liao from Juniper Networks.

Use SIG_ERR instead of NULL as the indicator that a signal handler
hasn't been changed, so that SIG_DFL (equivalent to NULL)
will be restored.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.169 src/usr.bin/ftp/ftp.c:1.170
--- src/usr.bin/ftp/ftp.c:1.169	Mon Jun  8 01:33:27 2020
+++ src/usr.bin/ftp/ftp.c	Sat Jul 11 02:19:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.169 2020/06/08 01:33:27 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.170 2020/07/11 02:19:31 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.169 2020/06/08 01:33:27 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.170 2020/07/11 02:19:31 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -320,6 +320,17 @@ cmdtimeout(int notused)
 	errno = oerrno;
 }
 
+static int
+issighandler(sigfunc func)
+{
+	return (func != SIG_IGN &&
+		func != SIG_DFL &&
+#ifdef SIG_HOLD
+		func != SIG_HOLD &&
+#endif
+		func != SIG_ERR);
+}
+
 /*VARARGS*/
 int
 command(const char *fmt, ...)
@@ -359,8 +370,9 @@ command(const char *fmt, ...)
 	(void)fflush(cout);
 	cpend = 1;
 	r = getreply(!strcmp(fmt, "QUIT"));
-	if (abrtflag && oldsigint != SIG_IGN)
+	if (abrtflag && issighandler(oldsigint)) {
 		(*oldsigint)(SIGINT);
+	}
 	(void)xsignal(SIGINT, oldsigint);
 	return (r);
 }
@@ -510,11 +522,14 @@ getreply(int expecteof)
 		(void)xsignal(SIGALRM, oldsigalrm);
 		if (code == 421 || originalcode == 421)
 			lostpeer(0);
-		if (abrtflag && oldsigint != cmdabort && oldsigint != SIG_IGN)
+		if (abrtflag && oldsigint != cmdabort &&
+		issighandler(oldsigint)) {
 			(*oldsigint)(SIGINT);
+		}
 		if (timeoutflag && oldsigalrm != cmdtimeout &&
-		oldsigalrm != SIG_IGN)
+		issighandler(oldsigalrm)) {
 			(*oldsigalrm)(SIGINT);
+		}
 		return (n - '0');
 	}
 }
@@ -670,7 +685,7 @@ sendrequest(const char *cmd, const char 
 	FILE *volatile dout;
 	int (*volatile closefunc)(FILE *);
 	sigfunc volatile oldintr;
-	sigfunc volatile oldintp;
+	sigfunc volatile oldpipe;
 	off_t volatile hashbytes;
 	int hash_interval;
 	const char *lmode;
@@ -697,8 +712,8 @@ sendrequest(const char *cmd, const char 
 	if (curtype != type)
 		changetype(type, 0);
 	closefunc = NULL;
-	oldintr = NULL;
-	oldintp = NULL;
+	oldintr = SIG_ERR;
+	oldpipe = SIG_ERR;
 	lmode = "w";
 	if (sigsetjmp(xferabort, 1)) {
 		while (cpend)
@@ -712,7 +727,7 @@ sendrequest(const char *cmd, const char 
 		fin = stdin;
 		progress = 0;
 	} else if (*local == '|') {
-		oldintp = xsignal(SIGPIPE, SIG_IGN);
+		oldpipe = xsignal(SIGPIPE, SIG_IGN);
 		fin = popen(local + 1, "r");
 		if (fin == NULL) {
 			warn("Can't execute `%s'", local + 1);
@@ -786,7 +801,9 @@ sendrequest(const char *cmd, const char 
 	}
 
 	progressmeter(-1);
-	oldintp = xsignal(SIGPIPE, SIG_IGN);
+	if (oldpipe == SIG_ERR) {
+		oldpipe = xsignal(SIGPIPE, SIG_IGN);
+	}
 	hash_interval = (hash && (!progress || filesize < 0)) ? mark : 0;
 
 	switch (curtype) {
@@ -855,7 +872,7 @@ sendrequest(const char *cmd, const char 
 
  abort:
 	(void)xsignal(SIGINT, oldintr);
-	oldintr = NULL;
+	oldintr = SIG_ERR;
 	if (!cpend) {
 		code = -1;
 		goto cleanupsend;
@@ -874,10 +891,10 @@ sendrequest(const char *cmd, const char 
 		ptransfer(0);
 
  cleanupsend:
-	if (oldintr)
+	if (oldintr != SIG_ERR)
 		(void)xsignal(SIGINT, oldintr);
-	if (oldintp)
-		(void)xsignal(SIGPIPE, oldintp);
+	if (oldpipe != SIG_ERR)
+		(void)xsignal(SIGPIPE, oldpipe);
 	if (data >= 0) {
 		(void)close(data);
 		data = -1;
@@ -899,7 +916,7 @@ recvrequest(const char *cmd, const char 
 	FILE *volatile din;
 	int (*volatile closefunc)(FILE *);
 	sigfunc volatile oldintr;
-	sigfunc volatile oldintp;
+	sigfunc volatile oldpipe;
 	int c, d;
 	int volatile is_retr;
 	int volatile tcrflag;
@@ -935,8 +952,8 @@ recvrequest(const char *cmd, const char 
 		return;
 	}
 	closefunc = NULL;
-	oldintr = NULL;
-	oldintp = NULL;
+	oldintr = SIG_ERR;
+	oldpipe = SIG_ERR;
 	tcrflag = !crflag && is_retr;
 	if (sigsetjmp(xferabort, 1)) {
 		while (cpend)
@@ -1017,7 +1034,7 @@ recvrequest(const char *cmd, const char 
 		progress = 0;
 		preserve = 0;
 	} else if (!ignorespecial && *local == '|') {
-		

CVS commit: src/usr.bin/ftp

2020-07-10 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 11 02:19:32 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.c version.h

Log Message:
ftp.c: improve signal handler restoration

Only invoke the old signal handler if it's a real signal handler
and not SIG_IGN, SIG_DFL, SIG_HOLD, or SIG_ERR, using new static
function issighandler().
Avoids an intermittent race condition with a null pointer
dereference via (*SIG_DFL)().
Bug class reported by Joyu Liao from Juniper Networks.

Use SIG_ERR instead of NULL as the indicator that a signal handler
hasn't been changed, so that SIG_DFL (equivalent to NULL)
will be restored.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-07-10 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 11 00:29:38 UTC 2020

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
fetch_url: improve signal handler restoration

Use SIG_ERR not NULL as the indicator that a signal handler
hasn't been changed, so that SIG_DFL (equivalent to NULL)
will be restored.

Fix restoration of SIGQUIT; use the old handler not SIGPIPE's.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.231 src/usr.bin/ftp/fetch.c:1.232
--- src/usr.bin/ftp/fetch.c:1.231	Thu Apr  4 00:36:09 2019
+++ src/usr.bin/ftp/fetch.c	Sat Jul 11 00:29:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.231 2019/04/04 00:36:09 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.231 2019/04/04 00:36:09 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -1295,7 +1295,7 @@ fetch_url(const char *url, const char *p
 
 	DPRINTF("%s: `%s' proxyenv `%s'\n", __func__, url, STRorNULL(penv));
 
-	oldquit = oldalrm = oldint = oldpipe = NULL;
+	oldquit = oldalrm = oldint = oldpipe = SIG_ERR;
 	closefunc = NULL;
 	fin = NULL;
 	fout = NULL;
@@ -1572,9 +1572,9 @@ fetch_url(const char *url, const char *p
 
 	bytes = 0;
 	hashbytes = mark;
-	if (oldalrm) {
+	if (oldalrm != SIG_ERR) {
 		(void)xsignal(SIGALRM, oldalrm);
-		oldalrm = NULL;
+		oldalrm = SIG_ERR;
 	}
 	progressmeter(-1);
 
@@ -1736,14 +1736,14 @@ chunkerror:
 	warnx("Improper response from `%s:%s'", ui.host, ui.port);
 
  cleanup_fetch_url:
-	if (oldint)
+	if (oldint != SIG_ERR)
 		(void)xsignal(SIGINT, oldint);
-	if (oldpipe)
+	if (oldpipe != SIG_ERR)
 		(void)xsignal(SIGPIPE, oldpipe);
-	if (oldalrm)
+	if (oldalrm != SIG_ERR)
 		(void)xsignal(SIGALRM, oldalrm);
-	if (oldquit)
-		(void)xsignal(SIGQUIT, oldpipe);
+	if (oldquit != SIG_ERR)
+		(void)xsignal(SIGQUIT, oldquit);
 	if (fin != NULL)
 		fetch_close(fin);
 	else if (s != -1)



CVS commit: src/usr.bin/ftp

2020-07-10 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jul 11 00:29:38 UTC 2020

Modified Files:
src/usr.bin/ftp: fetch.c

Log Message:
fetch_url: improve signal handler restoration

Use SIG_ERR not NULL as the indicator that a signal handler
hasn't been changed, so that SIG_DFL (equivalent to NULL)
will be restored.

Fix restoration of SIGQUIT; use the old handler not SIGPIPE's.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 src/usr.bin/ftp/fetch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-06-07 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jun  8 01:33:27 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.c util.c version.h

Log Message:
ftp: exit if lostpeer invoked by a signal

lostpeer() calls too many async-unsafe functions (both directly
and indirectly) to close and cleanup the remote connections,
so just exit after the cleanup if invoked by a signal.

Reported in private mail by Qi Hou.
May also resolve a crash reported by Thomas Klausner.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.168 src/usr.bin/ftp/ftp.c:1.169
--- src/usr.bin/ftp/ftp.c:1.168	Mon Feb  4 04:09:13 2019
+++ src/usr.bin/ftp/ftp.c	Mon Jun  8 01:33:27 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: ftp.c,v 1.168 2019/02/04 04:09:13 mrg Exp $	*/
+/*	$NetBSD: ftp.c,v 1.169 2020/06/08 01:33:27 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.168 2019/02/04 04:09:13 mrg Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.169 2020/06/08 01:33:27 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -2047,7 +2047,7 @@ gunique(const char *local)
  *	needs to get back to a known state.
  */
 static void
-abort_squared(int dummy)
+abort_squared(int signo)
 {
 	char msgbuf[100];
 	size_t len;
@@ -2057,7 +2057,7 @@ abort_squared(int dummy)
 	len = strlcpy(msgbuf, "\nremote abort aborted; closing connection.\n",
 	sizeof(msgbuf));
 	write(fileno(ttyout), msgbuf, len);
-	lostpeer(0);
+	lostpeer(signo);
 	siglongjmp(xferabort, 1);
 }
 

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.160 src/usr.bin/ftp/util.c:1.161
--- src/usr.bin/ftp/util.c:1.160	Sat Jun 22 23:40:53 2019
+++ src/usr.bin/ftp/util.c	Mon Jun  8 01:33:27 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $	*/
+/*	$NetBSD: util.c,v 1.161 2020/06/08 01:33:27 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $");
+__RCSID("$NetBSD: util.c,v 1.161 2020/06/08 01:33:27 lukem Exp $");
 #endif /* not lint */
 
 /*
@@ -324,9 +324,10 @@ intr(int signo)
 /*
  * Signal handler for lost connections; cleanup various elements of
  * the connection state, and call cleanuppeer() to finish it off.
+ * This function is not signal safe, so exit if called by a signal.
  */
 void
-lostpeer(int dummy)
+lostpeer(int signo)
 {
 	int oerrno = errno;
 
@@ -356,6 +357,9 @@ lostpeer(int dummy)
 	proxflag = 0;
 	pswitch(0);
 	cleanuppeer();
+	if (signo) {
+		errx(1, "lostpeer due to signal %d", signo);
+	}
 	errno = oerrno;
 }
 

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.88 src/usr.bin/ftp/version.h:1.89
--- src/usr.bin/ftp/version.h:1.88	Wed Feb 26 05:55:27 2020
+++ src/usr.bin/ftp/version.h	Mon Jun  8 01:33:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.88 2020/02/26 05:55:27 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.89 2020/06/08 01:33:27 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2020 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20190622"
+#define	FTP_VERSION	"20200608"
 #endif



CVS commit: src/usr.bin/ftp

2020-06-07 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon Jun  8 01:33:27 UTC 2020

Modified Files:
src/usr.bin/ftp: ftp.c util.c version.h

Log Message:
ftp: exit if lostpeer invoked by a signal

lostpeer() calls too many async-unsafe functions (both directly
and indirectly) to close and cleanup the remote connections,
so just exit after the cleanup if invoked by a signal.

Reported in private mail by Qi Hou.
May also resolve a crash reported by Thomas Klausner.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2020-02-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Feb 26 05:55:27 UTC 2020

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20190622


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.87 src/usr.bin/ftp/version.h:1.88
--- src/usr.bin/ftp/version.h:1.87	Sat Sep 12 20:18:52 2015
+++ src/usr.bin/ftp/version.h	Wed Feb 26 05:55:27 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: version.h,v 1.87 2015/09/12 20:18:52 wiz Exp $	*/
+/*	$NetBSD: version.h,v 1.88 2020/02/26 05:55:27 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1999-2015 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999-2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20150912"
+#define	FTP_VERSION	"20190622"
 #endif



CVS commit: src/usr.bin/ftp

2020-02-25 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Wed Feb 26 05:55:27 UTC 2020

Modified Files:
src/usr.bin/ftp: version.h

Log Message:
update ftp version to 20190622


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/ftp/version.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-06-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun 22 23:40:53 UTC 2019

Modified Files:
src/usr.bin/ftp: extern.h util.c

Log Message:
trim down error checking if we are small.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-06-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun 22 23:40:33 UTC 2019

Modified Files:
src/usr.bin/ftp: progressbar.c

Log Message:
make this compile again with -DNO_PROGRESS


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/ftp/progressbar.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-06-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun 22 23:40:33 UTC 2019

Modified Files:
src/usr.bin/ftp: progressbar.c

Log Message:
make this compile again with -DNO_PROGRESS


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/ftp/progressbar.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/progressbar.c
diff -u src/usr.bin/ftp/progressbar.c:1.22 src/usr.bin/ftp/progressbar.c:1.23
--- src/usr.bin/ftp/progressbar.c:1.22	Wed Jun 27 18:07:36 2012
+++ src/usr.bin/ftp/progressbar.c	Sat Jun 22 19:40:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp $	*/
+/*	$NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp $");
+__RCSID("$NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -87,6 +87,7 @@ updateprogressmeter(int dummy)
 /*
  * List of order of magnitude suffixes, per IEC 60027-2.
  */
+#if !defined(NO_PROGRESS) || !defined(STANDALONE_PROGRESS)
 static const char * const suffixes[] = {
 	"",	/* 2^0  (byte) */
 	"KiB",	/* 2^10 Kibibyte */
@@ -102,6 +103,7 @@ static const char * const suffixes[] = {
 #endif
 };
 #define NSUFFIXES	(int)(sizeof(suffixes) / sizeof(suffixes[0]))
+#endif
 
 /*
  * Display a transfer progress bar if progress is non-zero.
@@ -139,8 +141,10 @@ progressmeter(int flag)
 			 *	these appropriately.
 			 */
 #endif
+#if !defined(NO_PROGRESS) || !defined(STANDALONE_PROGRESS)
 	size_t		len;
 	char		buf[256];	/* workspace for progress bar */
+#endif
 #ifndef NO_PROGRESS
 #define	BAROVERHEAD	45		/* non `*' portion of progress bar */
 	/*



CVS commit: src/usr.bin/ftp

2019-06-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun 22 23:40:53 UTC 2019

Modified Files:
src/usr.bin/ftp: extern.h util.c

Log Message:
trim down error checking if we are small.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/ftp/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/extern.h
diff -u src/usr.bin/ftp/extern.h:1.81 src/usr.bin/ftp/extern.h:1.82
--- src/usr.bin/ftp/extern.h:1.81	Sun Feb  3 23:09:13 2019
+++ src/usr.bin/ftp/extern.h	Sat Jun 22 19:40:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.81 2019/02/04 04:09:13 mrg Exp $	*/
+/*	$NetBSD: extern.h,v 1.82 2019/06/22 23:40:53 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -243,7 +243,14 @@ void	user(int, char **);
 int	ftp_connect(int, const struct sockaddr *, socklen_t, int);
 int	ftp_listen(int, int);
 int	ftp_poll(struct pollfd *, int, int);
+#ifndef SMALL
 void   *ftp_malloc(size_t);
 StringList *ftp_sl_init(void);
 void	ftp_sl_add(StringList *, char *);
 char   *ftp_strdup(const char *);
+#else
+#define	ftp_malloc(a)	malloc(a);
+#define ftp_sl_init()	sl_init()
+#define ftp_sl_add(a, b)	sl_add((a), (b))
+#define ftp_strdup(a)	strdup(a)
+#endif

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.159 src/usr.bin/ftp/util.c:1.160
--- src/usr.bin/ftp/util.c:1.159	Mon Nov 20 16:11:36 2017
+++ src/usr.bin/ftp/util.c	Sat Jun 22 19:40:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $	*/
+/*	$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $");
+__RCSID("$NetBSD: util.c,v 1.160 2019/06/22 23:40:53 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1491,6 +1491,7 @@ ftp_poll(struct pollfd *fds, int nfds, i
 	return poll(fds, nfds, timeout);
 }
 
+#ifndef SMALL
 /*
  * malloc() with inbuilt error checking
  */
@@ -1545,3 +1546,4 @@ ftp_strdup(const char *str)
 		err(1, "Unable to allocate memory for string copy");
 	return (s);
 }
+#endif



CVS commit: src/usr.bin/ftp

2019-04-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr  7 00:44:54 UTC 2019

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
redo the connection waiting handling to make it more clear.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.7 src/usr.bin/ftp/ssl.c:1.8
--- src/usr.bin/ftp/ssl.c:1.7	Wed Apr  3 20:36:09 2019
+++ src/usr.bin/ftp/ssl.c	Sat Apr  6 20:44:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.7 2019/04/04 00:36:09 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.8 2019/04/07 00:44:54 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.7 2019/04/04 00:36:09 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.8 2019/04/07 00:44:54 christos Exp $");
 #endif
 
 #include 
@@ -88,6 +88,7 @@ fetch_writev(struct fetch_connect *conn,
 	struct timeval now, timeout, delta;
 	fd_set writefds;
 	ssize_t len, total;
+	int fd = conn->sd;
 	int r;
 
 	if (quit_time > 0) {
@@ -98,8 +99,8 @@ fetch_writev(struct fetch_connect *conn,
 
 	total = 0;
 	while (iovcnt > 0) {
-		while (quit_time > 0 && !FD_ISSET(conn->sd, )) {
-			FD_SET(conn->sd, );
+		while (quit_time > 0 && !FD_ISSET(fd, )) {
+			FD_SET(fd, );
 			gettimeofday(, NULL);
 			delta.tv_sec = timeout.tv_sec - now.tv_sec;
 			delta.tv_usec = timeout.tv_usec - now.tv_usec;
@@ -112,7 +113,7 @@ fetch_writev(struct fetch_connect *conn,
 return -1;
 			}
 			errno = 0;
-			r = select(conn->sd + 1, NULL, , NULL, );
+			r = select(fd + 1, NULL, , NULL, );
 			if (r == -1) {
 if (errno == EINTR)
 	continue;
@@ -123,7 +124,7 @@ fetch_writev(struct fetch_connect *conn,
 		if (conn->ssl != NULL)
 			len = SSL_write(conn->ssl, iov->iov_base, iov->iov_len);
 		else
-			len = writev(conn->sd, iov, iovcnt);
+			len = writev(fd, iov, iovcnt);
 		if (len == 0) {
 			/* we consider a short write a failure */
 			/* XXX perhaps we shouldn't in the SSL case */
@@ -131,7 +132,7 @@ fetch_writev(struct fetch_connect *conn,
 			return -1;
 		}
 		if (len < 0) {
-			if (errno == EINTR)
+			if (errno == EINTR || errno == EAGAIN)
 continue;
 			return -1;
 		}
@@ -149,11 +150,8 @@ fetch_writev(struct fetch_connect *conn,
 	return total;
 }
 
-/*
- * Write to a connection w/ timeout
- */
-static int
-fetch_write(struct fetch_connect *conn, const char *str, size_t len)
+static ssize_t
+fetch_write(const void *str, size_t len, struct fetch_connect *conn)
 {
 	struct iovec iov[1];
 
@@ -182,7 +180,7 @@ fetch_printf(struct fetch_connect *conn,
 		return -1;
 	}
 
-	r = fetch_write(conn, msg, len);
+	r = fetch_write(msg, len, conn);
 	free(msg);
 	return r;
 }
@@ -211,15 +209,16 @@ fetch_clearerr(struct fetch_connect *con
 int
 fetch_flush(struct fetch_connect *conn)
 {
-	int v;
 
 	if (conn->issock) {
+		int fd = conn->sd;
+		int v;
 #ifdef TCP_NOPUSH
 		v = 0;
-		setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, , sizeof(v));
+		setsockopt(fd, IPPROTO_TCP, TCP_NOPUSH, , sizeof(v));
 #endif
 		v = 1;
-		setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, , sizeof(v));
+		setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, , sizeof(v));
 	}
 	return 0;
 }
@@ -272,23 +271,19 @@ fetch_fdopen(int sd, const char *fmode)
 int
 fetch_close(struct fetch_connect *conn)
 {
-	int rv = 0;
+	if (conn == NULL)
+		return 0;
 
-	if (conn != NULL) {
-		fetch_flush(conn);
-		SSL_free(conn->ssl);
-		rv = close(conn->sd);
-		if (rv < 0) {
-			errno = rv;
-			rv = EOF;
-		}
-		free(conn->cache.buf);
-		free(conn->buf);
-		free(conn);
-	}
-	return rv;
+	fetch_flush(conn);
+	SSL_free(conn->ssl);
+	close(conn->sd);
+	free(conn->cache.buf);
+	free(conn->buf);
+	free(conn);
+	return 0;
 }
 
+#define FETCH_WRITE_WAIT	-3
 #define FETCH_READ_WAIT		-2
 #define FETCH_READ_ERROR	-1
 
@@ -296,19 +291,19 @@ static ssize_t
 fetch_ssl_read(SSL *ssl, void *buf, size_t len)
 {
 	ssize_t rlen;
-	int ssl_err;
-
 	rlen = SSL_read(ssl, buf, len);
-	if (rlen < 0) {
-		ssl_err = SSL_get_error(ssl, rlen);
-		if (ssl_err == SSL_ERROR_WANT_READ ||
-		ssl_err == SSL_ERROR_WANT_WRITE) {
-			return FETCH_READ_WAIT;
-		}
+	if (rlen >= 0)
+		return rlen;
+
+	switch (SSL_get_error(ssl, rlen)) {
+	case SSL_ERROR_WANT_READ:
+		return FETCH_READ_WAIT;
+	case SSL_ERROR_WANT_WRITE:
+		return FETCH_WRITE_WAIT;
+	default:
 		ERR_print_errors_fp(ttyout);
 		return FETCH_READ_ERROR;
 	}
-	return rlen;
 }
 
 static ssize_t
@@ -317,7 +312,7 @@ fetch_nonssl_read(int sd, void *buf, siz
 	ssize_t rlen;
 
 	rlen = read(sd, buf, len);
-	if (rlen < 0) {
+	if (rlen == -1) {
 		if (errno == EAGAIN || errno == EINTR)
 			return FETCH_READ_WAIT;
 		return FETCH_READ_ERROR;
@@ -348,14 +343,45 @@ fetch_cache_data(struct fetch_connect *c
 	return 0;
 }
 
+static int
+fetch_wait(struct fetch_connect *conn, ssize_t rlen, struct 

CVS commit: src/usr.bin/ftp

2019-04-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr  7 00:44:54 UTC 2019

Modified Files:
src/usr.bin/ftp: ssl.c

Log Message:
redo the connection waiting handling to make it more clear.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr  4 00:36:09 UTC 2019

Modified Files:
src/usr.bin/ftp: fetch.c ssl.c ssl.h

Log Message:
Make fetch_read() return size_t like fread() does. It is bogus to
have one backing implementation that returns different values and
types than the other.  Handle error setting properly; i.e. bail
out if the internal read returned an error. Now we get a proper
error message when the the server resets our connection instead of
a warning that the right failed with an invalid argument.

The server used for testing was:
http://capeweather.dyndns.org:8080/graphs/3474.png
Which seems to be unreliable :-)


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/ftp/ssl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.230 src/usr.bin/ftp/fetch.c:1.231
--- src/usr.bin/ftp/fetch.c:1.230	Sat Feb 10 21:51:58 2018
+++ src/usr.bin/ftp/fetch.c	Wed Apr  3 20:36:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.230 2018/02/11 02:51:58 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.231 2019/04/04 00:36:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.230 2018/02/11 02:51:58 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.231 2019/04/04 00:36:09 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1640,10 +1640,14 @@ fetch_url(const char *url, const char *p
 			if (ischunked)
 bufrem = MIN(chunksize, bufrem);
 			while (bufrem > 0) {
+size_t nr = MIN((off_t)bufsize, bufrem);
 flen = fetch_read(xferbuf, sizeof(char),
-MIN((off_t)bufsize, bufrem), fin);
-if (flen <= 0)
+nr, fin);
+if (flen == 0) {
+	if (fetch_error(fin))
+		goto chunkerror;
 	goto chunkdone;
+}
 bytes += flen;
 bufrem -= flen;
 if (fwrite(xferbuf, sizeof(char), flen, fout)
@@ -1694,7 +1698,7 @@ fetch_url(const char *url, const char *p
 	} while (ischunked);
 
 /* XXX: deal with optional trailer & CRLF here? */
-
+chunkerror:
 	if (hash && !progress && bytes > 0) {
 		if (bytes < mark)
 			(void)putc('#', ttyout);

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.6 src/usr.bin/ftp/ssl.c:1.7
--- src/usr.bin/ftp/ssl.c:1.6	Tue Feb  6 14:26:02 2018
+++ src/usr.bin/ftp/ssl.c	Wed Apr  3 20:36:09 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.6 2018/02/06 19:26:02 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.7 2019/04/04 00:36:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.6 2018/02/06 19:26:02 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.7 2019/04/04 00:36:09 christos Exp $");
 #endif
 
 #include 
@@ -348,7 +348,7 @@ fetch_cache_data(struct fetch_connect *c
 	return 0;
 }
 
-ssize_t
+size_t
 fetch_read(void *ptr, size_t size, size_t nmemb, struct fetch_connect *conn)
 {
 	struct timeval now, timeout, delta;
@@ -408,6 +408,7 @@ fetch_read(void *ptr, size_t size, size_
 		else
 			rlen = fetch_nonssl_read(conn->sd, buf, len);
 		if (rlen == 0) {
+			conn->iseof = 1;
 			break;
 		} else if (rlen > 0) {
 			len -= rlen;
@@ -415,9 +416,10 @@ fetch_read(void *ptr, size_t size, size_
 			total += rlen;
 			continue;
 		} else if (rlen == FETCH_READ_ERROR) {
+			conn->iserr = errno;
 			if (errno == EINTR)
 fetch_cache_data(conn, start, total);
-			return -1;
+			return 0;
 		}
 		FD_ZERO();
 		while (!FD_ISSET(conn->sd, )) {
@@ -425,8 +427,8 @@ fetch_read(void *ptr, size_t size, size_
 			if (quit_time > 0) {
 gettimeofday(, NULL);
 if (!timercmp(, , >)) {
-	errno = ETIMEDOUT;
-	return -1;
+	conn->iserr = ETIMEDOUT;
+	return 0;
 }
 timersub(, , );
 			}
@@ -435,7 +437,8 @@ fetch_read(void *ptr, size_t size, size_
 quit_time > 0 ?  : NULL) < 0) {
 if (errno == EINTR)
 	continue;
-return -1;
+conn->iserr = errno;
+return 0;
 			}
 		}
 	}
@@ -451,7 +454,7 @@ char *
 fetch_getln(char *str, int size, struct fetch_connect *conn)
 {
 	size_t tmpsize;
-	ssize_t len;
+	size_t len;
 	char c;
 
 	if (conn->buf == NULL) {
@@ -474,13 +477,12 @@ fetch_getln(char *str, int size, struct 
 	conn->buflen = 0;
 	do {
 		len = fetch_read(, sizeof(c), 1, conn);
-		if (len == -1) {
-			conn->iserr = 1;
-			return NULL;
-		}
 		if (len == 0) {
-			conn->iseof = 1;
-			break;
+			if (conn->iserr)
+return NULL;
+			if (conn->iseof)
+break;
+			abort();
 		}
 		conn->buf[conn->buflen++] = c;
 		if (conn->buflen == conn->bufsize) {
@@ -532,8 +534,8 @@ fetch_getline(struct fetch_connect *conn
 	} else if (len == buflen - 1) {	/* line too long */
 		while (1) {
 			char c;
-			ssize_t rlen = fetch_read(, sizeof(c), 1, 

CVS commit: src/usr.bin/ftp

2019-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr  4 00:36:09 UTC 2019

Modified Files:
src/usr.bin/ftp: fetch.c ssl.c ssl.h

Log Message:
Make fetch_read() return size_t like fread() does. It is bogus to
have one backing implementation that returns different values and
types than the other.  Handle error setting properly; i.e. bail
out if the internal read returned an error. Now we get a proper
error message when the the server resets our connection instead of
a warning that the right failed with an invalid argument.

The server used for testing was:
http://capeweather.dyndns.org:8080/graphs/3474.png
Which seems to be unreliable :-)


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/ftp/ssl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-02-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb  6 07:56:42 UTC 2019

Modified Files:
src/usr.bin/ftp: cmds.c

Log Message:
Try to avoid a (bogus) fatal warning from clang.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/ftp/cmds.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/cmds.c
diff -u src/usr.bin/ftp/cmds.c:1.139 src/usr.bin/ftp/cmds.c:1.140
--- src/usr.bin/ftp/cmds.c:1.139	Mon Feb  4 04:09:13 2019
+++ src/usr.bin/ftp/cmds.c	Wed Feb  6 07:56:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.139 2019/02/04 04:09:13 mrg Exp $	*/
+/*	$NetBSD: cmds.c,v 1.140 2019/02/06 07:56:42 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.139 2019/02/04 04:09:13 mrg Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.140 2019/02/06 07:56:42 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -1781,6 +1781,11 @@ justquit(void)
 {
 
 	quit(0, NULL);
+	/*
+	 * quit is not __dead, but for our invocation it never will return,
+	 * but some compilers are not smart enough to find this out.
+	 */
+	exit(0);
 }
 
 /*



CVS commit: src/usr.bin/ftp

2019-02-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Feb  6 07:56:42 UTC 2019

Modified Files:
src/usr.bin/ftp: cmds.c

Log Message:
Try to avoid a (bogus) fatal warning from clang.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/ftp/cmds.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-02-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 04:09:13 UTC 2019

Modified Files:
src/usr.bin/ftp: cmds.c extern.h ftp.c main.c

Log Message:
- add justquit() that always exits.  use it to avoid unreachable code.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.125 -r1.126 src/usr.bin/ftp/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/cmds.c
diff -u src/usr.bin/ftp/cmds.c:1.138 src/usr.bin/ftp/cmds.c:1.139
--- src/usr.bin/ftp/cmds.c:1.138	Mon Nov 20 21:11:36 2017
+++ src/usr.bin/ftp/cmds.c	Mon Feb  4 04:09:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre Exp $	*/
+/*	$NetBSD: cmds.c,v 1.139 2019/02/04 04:09:13 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.139 2019/02/04 04:09:13 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -1776,6 +1776,13 @@ quit(int argc, char *argv[])
 	exit(0);
 }
 
+void __dead
+justquit(void)
+{
+
+	quit(0, NULL);
+}
+
 /*
  * Terminate session, but don't exit.
  * May be called with 0, NULL.
@@ -2185,7 +2192,7 @@ LOOP:
 	}
 	break;
 }
-/* intentional drop through */
+/* FALLTHROUGH */
 			default:
 *cp2++ = *cp1;
 break;

Index: src/usr.bin/ftp/extern.h
diff -u src/usr.bin/ftp/extern.h:1.80 src/usr.bin/ftp/extern.h:1.81
--- src/usr.bin/ftp/extern.h:1.80	Wed Jul  4 06:09:37 2012
+++ src/usr.bin/ftp/extern.h	Mon Feb  4 04:09:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.80 2012/07/04 06:09:37 is Exp $	*/
+/*	$NetBSD: extern.h,v 1.81 2019/02/04 04:09:13 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -173,6 +173,7 @@ void	pswitch(int);
 void	put(int, char **);
 void	pwd(int, char **);
 void	quit(int, char **);
+void	justquit(void) __dead;
 void	quote(int, char **);
 void	quote1(const char *, int, char **);
 void	recvrequest(const char *, const char *, const char *,

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.167 src/usr.bin/ftp/ftp.c:1.168
--- src/usr.bin/ftp/ftp.c:1.167	Tue Oct  4 15:06:31 2016
+++ src/usr.bin/ftp/ftp.c	Mon Feb  4 04:09:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.167 2016/10/04 15:06:31 joerg Exp $	*/
+/*	$NetBSD: ftp.c,v 1.168 2019/02/04 04:09:13 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.167 2016/10/04 15:06:31 joerg Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.168 2019/02/04 04:09:13 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -1553,8 +1553,8 @@ initconn(void)
 result = COMPLETE + 1;
 break;
 			}
-			/* FALLTHROUGH */
 #ifdef INET6
+			/* FALLTHROUGH */
 		case AF_INET6:
 			if (!epsv6 || epsv6bad) {
 result = COMPLETE + 1;

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.125 src/usr.bin/ftp/main.c:1.126
--- src/usr.bin/ftp/main.c:1.125	Sun Mar  4 19:57:41 2018
+++ src/usr.bin/ftp/main.c	Mon Feb  4 04:09:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.125 2018/03/04 19:57:41 dholland Exp $	*/
+/*	$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.125 2018/03/04 19:57:41 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.126 2019/02/04 04:09:13 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -660,7 +660,7 @@ cmdscanner(void)
 			case -2:	/* error */
 if (fromatty)
 	putc('\n', ttyout);
-quit(0, NULL);
+justquit();
 /* NOTREACHED */
 			case -3:	/* too long; try again */
 fputs("Sorry, input line is too long.\n",
@@ -682,7 +682,7 @@ cmdscanner(void)
 			if (buf == NULL || num == 0) {
 if (fromatty)
 	putc('\n', ttyout);
-quit(0, NULL);
+justquit();
 			}
 			if (num >= sizeof(line)) {
 fputs("Sorry, input line is too long.\n",



CVS commit: src/usr.bin/ftp

2019-02-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Feb  4 04:09:13 UTC 2019

Modified Files:
src/usr.bin/ftp: cmds.c extern.h ftp.c main.c

Log Message:
- add justquit() that always exits.  use it to avoid unreachable code.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.125 -r1.126 src/usr.bin/ftp/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/ftp

2019-01-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 28 12:04:16 UTC 2019

Modified Files:
src/usr.bin/ftp: complete.c

Log Message:
PR/53916: Rob Gill: remove redundant assignment to matchlen.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/ftp/complete.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/complete.c
diff -u src/usr.bin/ftp/complete.c:1.46 src/usr.bin/ftp/complete.c:1.47
--- src/usr.bin/ftp/complete.c:1.46	Sun Apr 12 06:18:52 2009
+++ src/usr.bin/ftp/complete.c	Mon Jan 28 07:04:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: complete.c,v 1.47 2019/01/28 12:04:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp $");
+__RCSID("$NetBSD: complete.c,v 1.47 2019/01/28 12:04:16 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -99,11 +99,10 @@ complete_ambiguous(char *word, int list,
 	}
 
 	if (!list) {
-		matchlen = 0;
 		lastmatch = words->sl_str[0];
 		matchlen = strlen(lastmatch);
 		for (i = 1 ; i < words->sl_cur ; i++) {
-			for (j = wordlen ; j < strlen(words->sl_str[i]); j++)
+			for (j = wordlen; j < strlen(words->sl_str[i]); j++)
 if (lastmatch[j] != words->sl_str[i][j])
 	break;
 			if (j < matchlen)



  1   2   3   >