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-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: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.

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: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-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-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-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

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-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 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-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-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 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-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-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

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-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-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-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-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)



CVS commit: src/usr.bin/ftp

2018-03-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Mar  4 19:57:41 UTC 2018

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

Log Message:
Don't use the local username as the default anonftp password.

once upon a time doing this was part of the social glue that held the
community together, but that was a long time ago, and now it's just an
information leak.

proposed on tech-userlevel in 2008, then apparently forgotten :-|


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 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.124 src/usr.bin/ftp/main.c:1.125
--- src/usr.bin/ftp/main.c:1.124	Sat Nov 25 15:39:17 2017
+++ src/usr.bin/ftp/main.c	Sun Mar  4 19:57:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.124 2017/11/25 15:39:17 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.125 2018/03/04 19:57:41 dholland 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.124 2017/11/25 15:39:17 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.125 2018/03/04 19:57:41 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -464,7 +464,6 @@ main(int volatile argc, char **volatile 
 		if (localhome == NULL && !EMPTYSTRING(pw->pw_dir))
 			localhome = ftp_strdup(pw->pw_dir);
 		localname = ftp_strdup(pw->pw_name);
-		anonuser = localname;
 	}
 	if (netrc[0] == '\0' && localhome != NULL) {
 		if (strlcpy(netrc, localhome, sizeof(netrc)) >= sizeof(netrc) ||



CVS commit: src/usr.bin/ftp

2018-02-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Feb 11 02:51:58 UTC 2018

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

Log Message:
more volatile to appease gcc.


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 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.229 src/usr.bin/ftp/fetch.c:1.230
--- src/usr.bin/ftp/fetch.c:1.229	Sat Nov 25 10:39:17 2017
+++ src/usr.bin/ftp/fetch.c	Sat Feb 10 21:51:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.230 2018/02/11 02:51:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.230 2018/02/11 02:51:58 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1277,7 +1277,7 @@ fetch_url(const char *url, const char *p
 	static char		*xferbuf;
 	const char		*cp;
 	char			*ep;
-	char			*auth;
+	char			*volatile auth;
 	char			*volatile savefile;
 	char			*volatile location;
 	char			*volatile message;
@@ -1460,7 +1460,8 @@ fetch_url(const char *url, const char *p
 #ifdef WITH_SSL
 		if (isproxy && oui.utype == HTTPS_URL_T) {
 			switch (connectmethod(fin, url, penv, , ,
-			, , , , )) {
+			, , __UNVOLATILE(), ,
+			)) {
 			case C_CLEANUP:
 goto cleanup_fetch_url;
 			case C_IMPROPER:
@@ -1496,7 +1497,8 @@ fetch_url(const char *url, const char *p
 		alarmtimer(0);
 
 		switch (negotiate_connection(fin, url, penv, ,
-		, , , , , )) {
+		, , , , ,
+		__UNVOLATILE())) {
 		case C_OK:
 			break;
 		case C_CLEANUP:



CVS commit: src/usr.bin/ftp

2018-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb  6 19:26:02 UTC 2018

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

Log Message:
explicitly include  since OpenSSL-1.1 does not do it for us.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/usr.bin/ftp/ssl.c:1.6
--- src/usr.bin/ftp/ssl.c:1.5	Wed Sep 16 11:32:53 2015
+++ src/usr.bin/ftp/ssl.c	Tue Feb  6 14:26:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.5 2015/09/16 15:32:53 joerg Exp $	*/
+/*	$NetBSD: ssl.c,v 1.6 2018/02/06 19:26:02 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,11 +34,12 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.5 2015/09/16 15:32:53 joerg Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.6 2018/02/06 19:26:02 christos Exp $");
 #endif
 
 #include 
 #include 
+#include 
 #include 
 
 #include 



CVS commit: src/usr.bin/ftp

2017-11-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov 25 15:39:18 UTC 2017

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

Log Message:
Make outfile always allocated, free it to set it to NULL, and don't move it
around.


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.123 -r1.124 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/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.228 src/usr.bin/ftp/fetch.c:1.229
--- src/usr.bin/ftp/fetch.c:1.228	Wed Feb 15 06:52:11 2017
+++ src/usr.bin/ftp/fetch.c	Sat Nov 25 10:39:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $	*/
+/*	$NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -2097,14 +2097,15 @@ fetch_ftp(const char *url)
 		mget(xargc, xargv);
 		interactive = ointeractive;
 	} else {
-		if (outfile == NULL) {
+		char *destfile = outfile;
+		if (destfile == NULL) {
 			cp = strrchr(file, '/');	/* find savefile */
 			if (cp != NULL)
-outfile = cp + 1;
+destfile = cp + 1;
 			else
-outfile = file;
+destfile = file;
 		}
-		xargv[2] = (char *)outfile;
+		xargv[2] = (char *)destfile;
 		xargv[3] = NULL;
 		xargc++;
 		if (restartautofetch)
@@ -2250,8 +2251,9 @@ auto_fetch(int argc, char *argv[])
 			anonftp = 2;	/* Handle "automatic" transfers. */
 		rval = go_fetch(argv[argpos]);
 		if (outfile != NULL && strcmp(outfile, "-") != 0
-		&& outfile[0] != '|')
-			outfile = NULL;
+		&& outfile[0] != '|') {
+			FREEPTR(outfile);
+		}
 		if (rval > 0)
 			rval = argpos + 1;
 	}

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.123 src/usr.bin/ftp/main.c:1.124
--- src/usr.bin/ftp/main.c:1.123	Thu Apr 23 19:31:23 2015
+++ src/usr.bin/ftp/main.c	Sat Nov 25 10:39:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.123 2015/04/23 23:31:23 lukem Exp $	*/
+/*	$NetBSD: main.c,v 1.124 2017/11/25 15:39:17 christos 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.123 2015/04/23 23:31:23 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.124 2017/11/25 15:39:17 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -324,7 +324,7 @@ main(int volatile argc, char **volatile 
 			break;
 
 		case 'o':
-			outfile = optarg;
+			outfile = ftp_strdup(optarg);
 			if (strcmp(outfile, "-") == 0)
 ttyout = stderr;
 			break;



CVS commit: src/usr.bin/ftp

2017-11-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Nov 20 21:11:37 UTC 2017

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

Log Message:
Issue PWD commands to the server only when we actually
need the results, not speculatively, just in case we might.

Allows operation with some broken servers that get confused
by PWD commands in some situations, and saves server round
trips in the (modern) common case of
ftp ftp://path/name
where we never need to know the results from PWD.


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.158 -r1.159 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/cmds.c
diff -u src/usr.bin/ftp/cmds.c:1.137 src/usr.bin/ftp/cmds.c:1.138
--- src/usr.bin/ftp/cmds.c:1.137	Sat Feb 27 16:31:31 2016
+++ src/usr.bin/ftp/cmds.c	Mon Nov 20 21:11:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos Exp $	*/
+/*	$NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre 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.137 2016/02/27 16:31:31 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.138 2017/11/20 21:11:36 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1158,7 +1158,8 @@ cd(int argc, char *argv[])
 	}
 	if (r == COMPLETE) {
 		dirchange = 1;
-		updateremotecwd();
+		remotecwd[0] = '\0';
+		remcwdvalid = 0;
 	}
 }
 
@@ -1544,9 +1545,9 @@ pwd(int argc, char *argv[])
 		UPRINTF("usage: %s\n", argv[0]);
 		return;
 	}
-	if (! remotecwd[0])
+	if (!remcwdvalid || remotecwd[0] == '\0')
 		updateremotecwd();
-	if (! remotecwd[0])
+	if (remotecwd[0] == '\0')
 		fprintf(ttyout, "Unable to determine remote directory\n");
 	else {
 		fprintf(ttyout, "Remote directory: %s\n", remotecwd);
@@ -2359,7 +2360,8 @@ cdup(int argc, char *argv[])
 	}
 	if (r == COMPLETE) {
 		dirchange = 1;
-		updateremotecwd();
+		remotecwd[0] = '\0';
+		remcwdvalid = 0;
 	}
 }
 

Index: src/usr.bin/ftp/ftp_var.h
diff -u src/usr.bin/ftp/ftp_var.h:1.84 src/usr.bin/ftp/ftp_var.h:1.85
--- src/usr.bin/ftp/ftp_var.h:1.84	Wed Dec 16 23:00:39 2015
+++ src/usr.bin/ftp/ftp_var.h	Mon Nov 20 21:11:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.84 2015/12/16 23:00:39 christos Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.85 2017/11/20 21:11:36 kre Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -269,6 +269,7 @@ GLOBAL	int	unix_server;	/* server is uni
 GLOBAL	int	unix_proxy;	/* proxy is unix, can use binary for ascii */
 GLOBAL	char	localcwd[MAXPATHLEN];	/* local dir */
 GLOBAL	char	remotecwd[MAXPATHLEN];	/* remote dir */
+GLOBAL	int	remcwdvalid;		/* remotecwd has been updated */
 GLOBAL	char   *username;	/* name of user logged in as. (dynamic) */
 
 GLOBAL	sa_family_t family;	/* address family to use for connections */

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.158 src/usr.bin/ftp/util.c:1.159
--- src/usr.bin/ftp/util.c:1.158	Tue Feb 19 23:29:15 2013
+++ src/usr.bin/ftp/util.c	Mon Nov 20 21:11:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $	*/
+/*	$NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $");
+__RCSID("$NetBSD: util.c,v 1.159 2017/11/20 21:11:36 kre Exp $");
 #endif /* not lint */
 
 /*
@@ -478,7 +478,8 @@ ftp_login(const char *host, const char *
 		}
 	}
 	updatelocalcwd();
-	updateremotecwd();
+	remotecwd[0] = '\0';
+	remcwdvalid = 0;
 
  cleanup_ftp_login:
 	FREEPTR(fuser);
@@ -835,6 +836,7 @@ updateremotecwd(void)
 	size_t	 i;
 	char	*cp;
 
+	remcwdvalid = 1;	/* whether it works or not, we are done */
 	overbose = verbose;
 	ocode = code;
 	if (ftp_debug == 0)
@@ -1174,6 +1176,8 @@ formatbuf(char *buf, size_t len, const c
 		case '/':
 		case '.':
 		case 'c':
+			if (connected && !remcwdvalid)
+updateremotecwd();
 			p2 = connected ? remotecwd : "";
 			updirs = pdirs = 0;
 



CVS commit: src/usr.bin/ftp

2017-02-15 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Wed Feb 15 11:52:11 UTC 2017

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

Log Message:
ftp(1): split the auth processing function.


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 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.227 src/usr.bin/ftp/fetch.c:1.228
--- src/usr.bin/ftp/fetch.c:1.227	Tue Jan 31 21:05:35 2017
+++ src/usr.bin/ftp/fetch.c	Wed Feb 15 11:52:11 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.227 2017/01/31 21:05:35 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.227 2017/01/31 21:05:35 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -855,7 +855,6 @@ print_connect(FETCH *fin, const struct u
 #define C_OK 0
 #define C_CLEANUP 1
 #define C_IMPROPER 2
-#define C_RESTART 3
 
 static int
 getresponseline(FETCH *fin, char *buf, size_t buflen, int *len)
@@ -950,6 +949,52 @@ parse_posinfo(const char **cp, struct po
 	return 0;
 }
 
+#ifndef NO_AUTH
+static void
+do_auth(int hcode, const char *url, const char *penv, struct authinfo *wauth,
+struct authinfo *pauth, char **auth, const char *message,
+volatile int *rval)
+{
+	struct authinfo aauth;
+	char *response;
+
+	if (hcode == 401)
+		aauth = *wauth;
+	else
+		aauth = *pauth;
+
+	if (verbose || aauth.auth == NULL ||
+	aauth.user == NULL || aauth.pass == NULL)
+		fprintf(ttyout, "%s\n", message);
+	if (EMPTYSTRING(*auth)) {
+		warnx("No authentication challenge provided by server");
+		return;
+	}
+
+	if (aauth.auth != NULL) {
+		char reply[10];
+
+		fprintf(ttyout, "Authorization failed. Retry (y/n)? ");
+		if (get_line(stdin, reply, sizeof(reply), NULL) < 0) {
+			return;
+		}
+		if (tolower((unsigned char)reply[0]) != 'y')
+			return;
+
+		aauth.user = NULL;
+		aauth.pass = NULL;
+	}
+
+	if (auth_url(*auth, , ) == 0) {
+		*rval = fetch_url(url, penv,
+		hcode == 401 ? pauth->auth : response,
+		hcode == 401 ? response: wauth->auth);
+		memset(response, 0, strlen(response));
+		FREEPTR(response);
+	}
+}
+#endif
+
 static int
 negotiate_connection(FETCH *fin, const char *url, const char *penv,
 struct posinfo *pi, time_t *mtime, struct authinfo *wauth,
@@ -1085,49 +1130,8 @@ negotiate_connection(FETCH *fin, const c
 #ifndef NO_AUTH
 	case 401:
 	case 407:
-	{
-		struct authinfo aauth;
-		char **authp;
-
-		if (hcode == 401)
-			aauth = *wauth;
-		else
-			aauth = *pauth;
-		
-		if (verbose || aauth.auth == NULL ||
-		aauth.user == NULL || aauth.pass == NULL)
-			fprintf(ttyout, "%s\n", message);
-		if (EMPTYSTRING(*auth)) {
-			warnx(
-		"No authentication challenge provided by server");
-			goto cleanup_fetch_url;
-		}
-
-		if (aauth.auth != NULL) {
-			char reply[10];
-
-			fprintf(ttyout,
-			"Authorization failed. Retry (y/n)? ");
-			if (get_line(stdin, reply, sizeof(reply), NULL)
-			< 0) {
-goto cleanup_fetch_url;
-			}
-			if (tolower((unsigned char)reply[0]) != 'y')
-goto cleanup_fetch_url;
-			aauth.user = NULL;
-			aauth.pass = NULL;
-		}
-
-		authp = 
-		if (auth_url(*auth, authp, ) == 0) {
-			*rval = fetch_url(url, penv,
-			hcode == 401 ? pauth->auth : aauth.auth,
-			hcode == 401 ? aauth.auth : wauth->auth);
-			memset(*authp, 0, strlen(*authp));
-			FREEPTR(*authp);
-		}
+		do_auth(hcode, url, penv, wauth, pauth, auth, message, rval);
 		goto cleanup_fetch_url;
-	}
 #endif
 	default:
 		if (message)
@@ -1153,8 +1157,9 @@ out:
 
 #ifdef WITH_SSL
 static int
-connectmethod(int s, FETCH *fin, struct urlinfo *oui, struct urlinfo *ui,
-struct authinfo *pauth, char **auth, int *hasleading)
+connectmethod(FETCH *fin, const char *url, const char *penv,
+struct urlinfo *oui, struct urlinfo *ui, struct authinfo *wauth,
+struct authinfo *pauth, char **auth, int *hasleading, volatile int *rval)
 {
 	void *ssl;
 	int hcode, rv;
@@ -1219,30 +1224,7 @@ connectmethod(int s, FETCH *fin, struct 
 		break;
 #ifndef NO_AUTH
 	case 407:
-		if (verbose || pauth->auth == NULL ||
-		pauth->user == NULL || pauth->pass == NULL)
-			fprintf(ttyout, "%s\n", message);
-		if (EMPTYSTRING(*auth)) {
-			warnx("No authentication challenge provided by server");
-			goto cleanup_fetch_url;
-		}
-
-		if (pauth->auth != NULL) {
-			char reply[10];
-
-			fprintf(ttyout, "Authorization failed. Retry (y/n)? ");
-			if (get_line(stdin, reply, sizeof(reply), NULL)
-			< 0) {
-goto cleanup_fetch_url;
-			}
-			if (tolower((unsigned char)reply[0]) != 'y')
-goto cleanup_fetch_url;
-			pauth->user = NULL;
-			pauth->pass = NULL;
-		}
-
-		if (auth_url(*auth, >auth, pauth) == 0)
-			goto 

CVS commit: src/usr.bin/ftp

2017-01-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 31 21:05:35 UTC 2017

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

Log Message:
Use the first name we requested the http/https URL for, not any name we ended
up with after random redirects.


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 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.226 src/usr.bin/ftp/fetch.c:1.227
--- src/usr.bin/ftp/fetch.c:1.226	Wed Dec 14 23:49:15 2016
+++ src/usr.bin/ftp/fetch.c	Tue Jan 31 16:05:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $	*/
+/*	$NetBSD: fetch.c,v 1.227 2017/01/31 21:05:35 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.227 2017/01/31 21:05:35 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1369,6 +1369,12 @@ fetch_url(const char *url, const char *p
 			savefile = ftp_strdup(cp + 1);
 		else
 			savefile = ftp_strdup(decodedpath);
+		/*
+		 * Use the first URL we requested not the name after a
+		 * possible redirect, but careful to save it because our
+		 * "safety" check is the match to outfile.
+		 */
+		outfile = ftp_strdup(savefile);
 	}
 	DPRINTF("%s: savefile `%s'\n", __func__, savefile);
 	if (EMPTYSTRING(savefile)) {



CVS commit: src/usr.bin/ftp

2016-12-14 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu Dec 15 04:49:15 UTC 2016

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

Log Message:
handle proxy authentication correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 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.225 src/usr.bin/ftp/fetch.c:1.226
--- src/usr.bin/ftp/fetch.c:1.225	Mon Oct 17 00:52:53 2016
+++ src/usr.bin/ftp/fetch.c	Thu Dec 15 04:49:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.226 2016/12/15 04:49:15 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -855,8 +855,7 @@ print_connect(FETCH *fin, const struct u
 #define C_OK 0
 #define C_CLEANUP 1
 #define C_IMPROPER 2
-#define C_PROXY 3
-#define C_NOPROXY 4
+#define C_RESTART 3
 
 static int
 getresponseline(FETCH *fin, char *buf, size_t buflen, int *len)
@@ -1087,7 +1086,7 @@ negotiate_connection(FETCH *fin, const c
 	case 401:
 	case 407:
 	{
-		struct  authinfo aauth;
+		struct authinfo aauth;
 		char **authp;
 
 		if (hcode == 401)
@@ -1122,7 +1121,8 @@ negotiate_connection(FETCH *fin, const c
 		authp = 
 		if (auth_url(*auth, authp, ) == 0) {
 			*rval = fetch_url(url, penv,
-			pauth->auth, wauth->auth);
+			hcode == 401 ? pauth->auth : aauth.auth,
+			hcode == 401 ? aauth.auth : wauth->auth);
 			memset(*authp, 0, strlen(*authp));
 			FREEPTR(*authp);
 		}
@@ -1217,6 +1217,34 @@ connectmethod(int s, FETCH *fin, struct 
 	switch (hcode) {
 	case 200:
 		break;
+#ifndef NO_AUTH
+	case 407:
+		if (verbose || pauth->auth == NULL ||
+		pauth->user == NULL || pauth->pass == NULL)
+			fprintf(ttyout, "%s\n", message);
+		if (EMPTYSTRING(*auth)) {
+			warnx("No authentication challenge provided by server");
+			goto cleanup_fetch_url;
+		}
+
+		if (pauth->auth != NULL) {
+			char reply[10];
+
+			fprintf(ttyout, "Authorization failed. Retry (y/n)? ");
+			if (get_line(stdin, reply, sizeof(reply), NULL)
+			< 0) {
+goto cleanup_fetch_url;
+			}
+			if (tolower((unsigned char)reply[0]) != 'y')
+goto cleanup_fetch_url;
+			pauth->user = NULL;
+			pauth->pass = NULL;
+		}
+
+		if (auth_url(*auth, >auth, pauth) == 0)
+			goto restart_fetch_url;
+		goto cleanup_fetch_url;
+#endif
 	default:
 		if (message)
 			warnx("Error proxy connect " "`%s'", message);
@@ -1237,6 +1265,9 @@ improper:
 cleanup_fetch_url:
 	rv = C_CLEANUP;
 	goto out;
+restart_fetch_url:
+	rv = C_RESTART;
+	goto out;
 out:
 	FREEPTR(message);
 	return rv;
@@ -1445,6 +1476,10 @@ fetch_url(const char *url, const char *p
 		if (isproxy && oui.utype == HTTPS_URL_T) {
 			switch (connectmethod(s, fin, , , , ,
 			)) {
+			case C_RESTART:
+rval = fetch_url(url, penv, pauth.auth,
+wauth.auth);
+/*FALLTHROUGH*/
 			case C_CLEANUP:
 goto cleanup_fetch_url;
 			case C_IMPROPER:



CVS commit: src/usr.bin/ftp

2016-10-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 17 00:52:53 UTC 2016

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

Log Message:
PR/51558: ast@: ftp dumps core after usage message when IPv6 URL lacks a slash.
Initialize variable so that we don't get random behavior on cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 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.224 src/usr.bin/ftp/fetch.c:1.225
--- src/usr.bin/ftp/fetch.c:1.224	Wed Aug  3 08:33:56 2016
+++ src/usr.bin/ftp/fetch.c	Sun Oct 16 20:52:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.224 2016/08/03 12:33:56 maya Exp $	*/
+/*	$NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.224 2016/08/03 12:33:56 maya Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.225 2016/10/17 00:52:53 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1296,6 +1296,7 @@ fetch_url(const char *url, const char *p
 	rval = 1;
 
 	initurlinfo();
+	initurlinfo();
 	initauthinfo(, wwwauth);
 	initauthinfo(, proxyauth);
 



CVS commit: src/usr.bin/ftp

2016-10-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Oct  4 15:06:31 UTC 2016

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

Log Message:
When using data outside the signed char range, it is better to
consistently use an unsigned char buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 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.166 src/usr.bin/ftp/ftp.c:1.167
--- src/usr.bin/ftp/ftp.c:1.166	Sun Dec 13 14:06:13 2015
+++ src/usr.bin/ftp/ftp.c	Tue Oct  4 15:06:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.166 2015/12/13 14:06:13 tron Exp $	*/
+/*	$NetBSD: ftp.c,v 1.167 2016/10/04 15:06:31 joerg 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.166 2015/12/13 14:06:13 tron Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.167 2016/10/04 15:06:31 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -2064,7 +2064,7 @@ abort_squared(int dummy)
 void
 abort_remote(FILE *din)
 {
-	char buf[BUFSIZ];
+	unsigned char buf[BUFSIZ];
 	int nfnd;
 
 	if (cout == NULL) {



CVS commit: src/usr.bin/ftp

2016-08-03 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Wed Aug  3 12:33:56 UTC 2016

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

Log Message:
Do globbing for FTP URLs of the form ftp://... too

ok christos


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 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.223 src/usr.bin/ftp/fetch.c:1.224
--- src/usr.bin/ftp/fetch.c:1.223	Mon Apr  4 23:59:41 2016
+++ src/usr.bin/ftp/fetch.c	Wed Aug  3 12:33:56 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.223 2016/04/04 23:59:41 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.224 2016/08/03 12:33:56 maya Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.223 2016/04/04 23:59:41 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.224 2016/08/03 12:33:56 maya Exp $");
 #endif /* not lint */
 
 /*
@@ -1899,7 +1899,8 @@ fetch_ftp(const char *url)
 	STRorNULL(ui.path), STRorNULL(dir), STRorNULL(file));
 
 	dirhasglob = filehasglob = 0;
-	if (doglob && ui.utype == CLASSIC_URL_T) {
+	if (doglob &&
+	(ui.utype == CLASSIC_URL_T || ui.utype == FTP_URL_T)) {
 		if (! EMPTYSTRING(dir) && strpbrk(dir, "*?[]{}") != NULL)
 			dirhasglob = 1;
 		if (! EMPTYSTRING(file) && strpbrk(file, "*?[]{}") != NULL)



CVS commit: src/usr.bin/ftp

2016-04-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Apr  4 23:59:41 UTC 2016

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

Log Message:
PR/51043: Yorick Hardy: ftp(1) should use the port number for CONNECT


To generate a diff of this commit:
cvs rdiff -u -r1.222 -r1.223 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.222 src/usr.bin/ftp/fetch.c:1.223
--- src/usr.bin/ftp/fetch.c:1.222	Fri Mar 18 14:42:25 2016
+++ src/usr.bin/ftp/fetch.c	Mon Apr  4 19:59:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.222 2016/03/18 18:42:25 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.223 2016/04/04 23:59:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.222 2016/03/18 18:42:25 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.223 2016/04/04 23:59:41 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -847,8 +847,8 @@ print_connect(FETCH *fin, const struct u
 	} else
 		h = ui->host;
 
-	fetch_printf(fin, "CONNECT %s:%s HTTP/1.1\r\n", h, ui->port);
-	fetch_printf(fin, "Host: %s:%s\r\n", h, ui->port);
+	fetch_printf(fin, "CONNECT %s:%d HTTP/1.1\r\n", h, ui->portnum);
+	fetch_printf(fin, "Host: %s:%d\r\n", h, ui->portnum);
 }
 #endif
 



CVS commit: src/usr.bin/ftp

2016-03-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Mar 18 18:42:25 UTC 2016

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

Log Message:
sprinkle more volatile (distribution build with gcc-5.3)


To generate a diff of this commit:
cvs rdiff -u -r1.221 -r1.222 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.221 src/usr.bin/ftp/fetch.c:1.222
--- src/usr.bin/ftp/fetch.c:1.221	Thu Feb  4 22:41:05 2016
+++ src/usr.bin/ftp/fetch.c	Fri Mar 18 14:42:25 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.221 2016/02/05 03:41:05 nonaka Exp $	*/
+/*	$NetBSD: fetch.c,v 1.222 2016/03/18 18:42:25 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.221 2016/02/05 03:41:05 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.222 2016/03/18 18:42:25 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -954,7 +954,8 @@ parse_posinfo(const char **cp, struct po
 static int
 negotiate_connection(FETCH *fin, const char *url, const char *penv,
 struct posinfo *pi, time_t *mtime, struct authinfo *wauth,
-struct authinfo *pauth, int *rval, int *ischunked, char **auth)
+struct authinfo *pauth, volatile int *rval, volatile int *ischunked,
+char **auth)
 {
 	int			len, hcode, rv;
 	char			buf[FTPBUFLEN], *ep;
@@ -1260,7 +1261,7 @@ fetch_url(const char *url, const char *p
 	int volatile		s;
 	struct stat		sb;
 	int volatile		isproxy;
-	int 			rval, ischunked;
+	int volatile 		rval, ischunked;
 	size_t			flen;
 	static size_t		bufsize;
 	static char		*xferbuf;



CVS commit: src/usr.bin/ftp

2016-02-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 27 16:31:31 UTC 2016

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

Log Message:
CID 1354295: Array overrun.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 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.136 src/usr.bin/ftp/cmds.c:1.137
--- src/usr.bin/ftp/cmds.c:1.136	Sat Feb  6 16:23:09 2016
+++ src/usr.bin/ftp/cmds.c	Sat Feb 27 11:31:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.136 2016/02/06 21:23:09 christos Exp $	*/
+/*	$NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos 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.136 2016/02/06 21:23:09 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1971,7 +1971,7 @@ dotrans(char *dst, size_t dlen, const ch
 		continue;
 	for (cp1 = src; *cp1; cp1++) {
 		int found = 0;
-		for (i = 0; ntin[i] && i < sizeof(ntin); i++) {
+		for (i = 0; i < sizeof(ntin) && ntin[i]; i++) {
 			if (*cp1 == ntin[i]) {
 found++;
 if (i < ostop) {



CVS commit: src/usr.bin/ftp

2016-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb  6 21:23:09 UTC 2016

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

Log Message:
use sizeof() and array notation.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 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.135 src/usr.bin/ftp/cmds.c:1.136
--- src/usr.bin/ftp/cmds.c:1.135	Sat Dec 22 11:57:09 2012
+++ src/usr.bin/ftp/cmds.c	Sat Feb  6 16:23:09 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos Exp $	*/
+/*	$NetBSD: cmds.c,v 1.136 2016/02/06 21:23:09 christos 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.135 2012/12/22 16:57:09 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.136 2016/02/06 21:23:09 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1967,15 +1967,15 @@ dotrans(char *dst, size_t dlen, const ch
 	char *cp2 = dst;
 	size_t i, ostop;
 
-	for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
+	for (ostop = 0; ntout[ostop] && ostop < sizeof(ntout); ostop++)
 		continue;
 	for (cp1 = src; *cp1; cp1++) {
 		int found = 0;
-		for (i = 0; *(ntin + i) && i < 16; i++) {
-			if (*cp1 == *(ntin + i)) {
+		for (i = 0; ntin[i] && i < sizeof(ntin); i++) {
+			if (*cp1 == ntin[i]) {
 found++;
 if (i < ostop) {
-	*cp2++ = *(ntout + i);
+	*cp2++ = ntout[i];
 	if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
 		goto out;
 }



CVS commit: src/usr.bin/ftp

2016-02-04 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri Feb  5 03:41:05 UTC 2016

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

Log Message:
Initialize the token match pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 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.220 src/usr.bin/ftp/fetch.c:1.221
--- src/usr.bin/ftp/fetch.c:1.220	Tue Jan  5 11:41:00 2016
+++ src/usr.bin/ftp/fetch.c	Fri Feb  5 03:41:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.220 2016/01/05 11:41:00 wiz Exp $	*/
+/*	$NetBSD: fetch.c,v 1.221 2016/02/05 03:41:05 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.220 2016/01/05 11:41:00 wiz Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.221 2016/02/05 03:41:05 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -1196,6 +1196,8 @@ connectmethod(int s, FETCH *fin, struct 
 			goto cleanup_fetch_url;
 		if (len == 0)
 			break;
+
+		cp = buf;
 		if (match_token(, "Proxy-Authenticate:")) {
 			const char *token;
 			if (!(token = match_token(, "Basic"))) {



CVS commit: src/usr.bin/ftp

2016-01-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jan  5 11:41:00 UTC 2016

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

Log Message:
Fix downloads of local files using file:// URLs

Previously it would error out in copyurlinfo() when copying a NULL port.


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 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.219 src/usr.bin/ftp/fetch.c:1.220
--- src/usr.bin/ftp/fetch.c:1.219	Thu Dec 17 20:36:36 2015
+++ src/usr.bin/ftp/fetch.c	Tue Jan  5 11:41:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.219 2015/12/17 20:36:36 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.220 2016/01/05 11:41:00 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.219 2015/12/17 20:36:36 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.220 2016/01/05 11:41:00 wiz Exp $");
 #endif /* not lint */
 
 /*
@@ -424,6 +424,7 @@ parse_url(const char *url, const char *d
 	} 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;



CVS commit: src/usr.bin/ftp

2015-12-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 17 17:08:45 UTC 2015

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

Log Message:
Simplify and factor out connect message


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 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.216 src/usr.bin/ftp/fetch.c:1.217
--- src/usr.bin/ftp/fetch.c:1.216	Wed Dec 16 23:36:56 2015
+++ src/usr.bin/ftp/fetch.c	Thu Dec 17 12:08:45 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.216 2015/12/17 04:36:56 nonaka Exp $	*/
+/*	$NetBSD: fetch.c,v 1.217 2015/12/17 17:08:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.216 2015/12/17 04:36:56 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.217 2015/12/17 17:08:45 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -813,6 +813,30 @@ print_proxy(FETCH *fin, int hasleading, 
 	return hasleading;
 }
 
+static void
+print_connect(FETCH *fin, const struct urlinfo *ui)
+{
+	char hname[NI_MAXHOST], *p;
+	const char *h;
+
+	if (isipv6addr(ui->host)) {
+		/*
+		 * strip off IPv6 scope identifier,
+		 * since it is local to the node
+		 */
+		if ((p = strchr(ui->host, '%')) == NULL)
+			snprintf(hname, sizeof(hname), "[%s]", ui->host);
+		else
+			snprintf(hname, sizeof(hname), "[%.*s]",
+			(int)(p - ui->host), ui->host);
+		h = hname;
+	} else
+		h = ui->host;
+
+	fetch_printf(fin, "CONNECT %s:%s HTTP/1.1\r\n", h, ui->port);
+	fetch_printf(fin, "Host: %s:%s\r\n", h, ui->port);
+}
+
 #define C_OK 0
 #define C_CLEANUP 1
 #define C_IMPROPER 2
@@ -1115,27 +1139,7 @@ connectmethod(int s, FETCH *fin, struct 
 	char buf[FTPBUFLEN], *ep;
 	char *message = NULL;
 
-	if (strchr(oui->host, ':')) {
-		char *h, *p;
-
-		/*
-		 * strip off IPv6 scope identifier,
-		 * since it is local to the node
-		 */
-		h = ftp_strdup(oui->host);
-		if (isipv6addr(h) && (p = strchr(h, '%')) != NULL) {
-			*p = '\0';
-		}
-		fetch_printf(fin, "CONNECT [%s]:%s HTTP/1.1\r\n",
-		h, oui->port);
-		fetch_printf(fin, "Host: [%s]:%s\r\n", h, oui->port);
-		free(h);
-	} else {
-		fetch_printf(fin, "CONNECT %s:%s HTTP/1.1\r\n",
-		oui->host, oui->port);
-		fetch_printf(fin, "Host: %s:%s\r\n",
-		oui->host, oui->port);
-	}
+	print_connect(fin, oui);
 
 	print_agent(fin);
 	*hasleading = print_proxy(fin, *hasleading, NULL, pauth->auth);



CVS commit: src/usr.bin/ftp

2015-12-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 17 17:26:46 UTC 2015

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

Log Message:
Split the position/size parsing into a separate function.


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 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.217 src/usr.bin/ftp/fetch.c:1.218
--- src/usr.bin/ftp/fetch.c:1.217	Thu Dec 17 12:08:45 2015
+++ src/usr.bin/ftp/fetch.c	Thu Dec 17 12:26:45 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.217 2015/12/17 17:08:45 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.218 2015/12/17 17:26:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.217 2015/12/17 17:08:45 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.218 2015/12/17 17:26:45 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -94,6 +94,12 @@ struct urlinfo {
 	in_port_t portnum;
 };
 
+struct posinfo {
+	off_t rangestart;
+	off_t rangeend;
+	off_t entitylen;
+};
+
 __dead static void	aborthttp(int);
 __dead static void	timeouthttp(int);
 #ifndef NO_AUTH
@@ -161,6 +167,12 @@ match_token(const char **buf, const char
 }
 
 static void
+initposinfo(struct posinfo *pi)
+{
+	pi->rangestart = pi->rangeend = pi->entitylen = -1;
+}
+
+static void
 initauthinfo(struct authinfo *ai, char *auth)
 {
 	ai->auth = auth;
@@ -890,10 +902,56 @@ getresponse(FETCH *fin, char **cp, size_
 }
 
 static int
+parse_posinfo(const char **cp, struct posinfo *pi)
+{
+	char *ep;
+	if (!match_token(cp, "bytes"))
+		return -1;
+
+	if (**cp == '*')
+		(*cp)++;
+	else {
+		pi->rangestart = STRTOLL(*cp, , 10);
+		if (pi->rangestart < 0 || *ep != '-')
+			return -1;
+		*cp = ep + 1;
+		pi->rangeend = STRTOLL(*cp, , 10);
+		if (pi->rangeend < 0 || pi->rangeend < pi->rangestart)
+			return -1;
+		*cp = ep;
+	}
+	if (**cp != '/')
+		return -1;
+	(*cp)++;
+	if (**cp == '*')
+		(*cp)++;
+	else {
+		pi->entitylen = STRTOLL(*cp, , 10);
+		if (pi->entitylen < 0)
+			return -1;
+		*cp = ep;
+	}
+	if (**cp != '\0')
+		return -1;
+
+#ifndef NO_DEBUG
+	if (ftp_debug) {
+		fprintf(ttyout, "parsed range as: ");
+		if (pi->rangestart == -1)
+			fprintf(ttyout, "*");
+		else
+			fprintf(ttyout, LLF "-" LLF, (LLT)pi->rangestart,
+			(LLT)pi->rangeend);
+		fprintf(ttyout, "/" LLF "\n", (LLT)pi->entitylen);
+	}
+#endif
+	return 0;
+}
+
+static int
 negotiate_connection(FETCH *fin, const char *url, const char *penv,
-off_t *rangestart, off_t *rangeend, off_t *entitylen,
-time_t *mtime, struct authinfo *wauth, struct authinfo *pauth,
-int *rval, int *ischunked, char **auth)
+struct posinfo *pi, time_t *mtime, struct authinfo *wauth,
+struct authinfo *pauth, int *rval, int *ischunked, char **auth)
 {
 	int			len, hcode, rv;
 	char			buf[FTPBUFLEN], *ep;
@@ -936,47 +994,8 @@ negotiate_connection(FETCH *fin, const c
 			__func__, (LLT)filesize);
 
 		} else if (match_token(, "Content-Range:")) {
-			if (! match_token(, "bytes"))
+			if (parse_posinfo(, pi) == -1)
 goto improper;
-
-			if (*cp == '*')
-cp++;
-			else {
-*rangestart = STRTOLL(cp, , 10);
-if (*rangestart < 0 || *ep != '-')
-	goto improper;
-cp = ep + 1;
-*rangeend = STRTOLL(cp, , 10);
-if (*rangeend < 0 || *rangeend < *rangestart)
-	goto improper;
-cp = ep;
-			}
-			if (*cp != '/')
-goto improper;
-			cp++;
-			if (*cp == '*')
-cp++;
-			else {
-*entitylen = STRTOLL(cp, , 10);
-if (*entitylen < 0)
-	goto improper;
-cp = ep;
-			}
-			if (*cp != '\0')
-goto improper;
-
-#ifndef NO_DEBUG
-			if (ftp_debug) {
-fprintf(ttyout, "parsed range as: ");
-if (*rangestart == -1)
-	fprintf(ttyout, "*");
-else
-	fprintf(ttyout, LLF "-" LLF,
-	(LLT)*rangestart,
-	(LLT)*rangeend);
-fprintf(ttyout, "/" LLF "\n", (LLT)*entitylen);
-			}
-#endif
 			if (! restart_point) {
 warnx(
 			"Received unexpected Content-Range header");
@@ -1248,7 +1267,8 @@ fetch_url(const char *url, const char *p
 	char			*volatile message;
 	char			*volatile decodedpath;
 	struct authinfo 	wauth, pauth;
-	off_t			hashbytes, rangestart, rangeend, entitylen;
+	struct posinfo		pi;
+	off_t			hashbytes;
 	int			(*volatile closefunc)(FILE *);
 	FETCH			*volatile fin;
 	FILE			*volatile fout;
@@ -1325,7 +1345,7 @@ fetch_url(const char *url, const char *p
 
 	restart_point = 0;
 	filesize = -1;
-	rangestart = rangeend = entitylen = -1;
+	initposinfo();
 	mtime = -1;
 	if (restartautofetch) {
 		if (stat(savefile, ) == 0)
@@ -1452,8 +1472,7 @@ fetch_url(const char *url, const char *p
 		}
 		alarmtimer(0);
 
-		switch (negotiate_connection(fin, url, penv,
-		, , ,
+		switch (negotiate_connection(fin, url, penv, ,
 		, , , , , )) {
 		case C_OK:
 			break;
@@ 

CVS commit: src/usr.bin/ftp

2015-12-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec 17 20:36:36 UTC 2015

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

Log Message:
mark function as only needed with ssl.


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 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.218 src/usr.bin/ftp/fetch.c:1.219
--- src/usr.bin/ftp/fetch.c:1.218	Thu Dec 17 12:26:45 2015
+++ src/usr.bin/ftp/fetch.c	Thu Dec 17 15:36:36 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.218 2015/12/17 17:26:45 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.219 2015/12/17 20:36:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.218 2015/12/17 17:26:45 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.219 2015/12/17 20:36:36 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -825,6 +825,7 @@ print_proxy(FETCH *fin, int hasleading, 
 	return hasleading;
 }
 
+#ifdef WITH_SSL
 static void
 print_connect(FETCH *fin, const struct urlinfo *ui)
 {
@@ -848,6 +849,7 @@ print_connect(FETCH *fin, const struct u
 	fetch_printf(fin, "CONNECT %s:%s HTTP/1.1\r\n", h, ui->port);
 	fetch_printf(fin, "Host: %s:%s\r\n", h, ui->port);
 }
+#endif
 
 #define C_OK 0
 #define C_CLEANUP 1



CVS commit: src/usr.bin/ftp

2015-12-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec 16 21:11:47 UTC 2015

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

Log Message:
PR/50438: NONAKA Kimihiro: ftp(1): CONNECT method support
Please test!


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 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.214 src/usr.bin/ftp/fetch.c:1.215
--- src/usr.bin/ftp/fetch.c:1.214	Wed Dec 16 14:17:16 2015
+++ src/usr.bin/ftp/fetch.c	Wed Dec 16 16:11:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.214 2015/12/16 19:17:16 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.215 2015/12/16 21:11:47 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.214 2015/12/16 19:17:16 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.215 2015/12/16 21:11:47 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -184,6 +184,18 @@ initurlinfo(struct urlinfo *ui)
 	ui->portnum = 0;
 }
 
+#ifdef WITH_SSL
+static void
+copyurlinfo(struct urlinfo *dui, struct urlinfo *sui)
+{
+	dui->host = ftp_strdup(sui->host);
+	dui->port = ftp_strdup(sui->port);
+	dui->path = ftp_strdup(sui->path);
+	dui->utype = sui->utype;
+	dui->portnum = sui->portnum;
+}
+#endif
+
 static void
 freeurlinfo(struct urlinfo *ui)
 {
@@ -721,10 +733,9 @@ print_cache(FETCH *fin, int isproxy)
 }
 
 static int
-print_get(FETCH *fin, int isproxy, const struct urlinfo *ui)
+print_get(FETCH *fin, int hasleading, int isproxy, const struct urlinfo *ui)
 {
-	int hasleading = 0;
-	const char *leading = "  (";
+	const char *leading = hasleading ? ", " : "  (";
 
 	if (isproxy) {
 		if (verbose) {
@@ -807,66 +818,87 @@ print_proxy(FETCH *fin, const char *lead
 #define C_OK 0
 #define C_CLEANUP 1
 #define C_IMPROPER 2
-
+#define C_PROXY 3
+#define C_NOPROXY 4
 
 static int
-negotiate_connection(FETCH *fin, const char *url, const char *penv,
-off_t *rangestart, off_t *rangeend, off_t *entitylen,
-time_t *mtime, struct authinfo *wauth, struct authinfo *pauth,
-int *rval, int *ischunked)
+getresponseline(FETCH *fin, char *buf, size_t buflen, int *len)
 {
-	int			len, hcode, rv;
-	char			buf[FTPBUFLEN], *ep;
-	const char		*errormsg, *cp, *token;
-	char 			*location, *message, *auth;
-
-	auth = message = location = NULL;
+	const char *errormsg;
 
-	/* Read the response */
 	alarmtimer(quit_time ? quit_time : 60);
-	len = fetch_getline(fin, buf, sizeof(buf), );
+	*len = fetch_getline(fin, buf, buflen, );
 	alarmtimer(0);
-	if (len < 0) {
+	if (*len < 0) {
 		if (*errormsg == '\n')
 			errormsg++;
 		warnx("Receiving HTTP reply: %s", errormsg);
-		goto cleanup_fetch_url;
+		return C_CLEANUP;
 	}
-	while (len > 0 && (ISLWS(buf[len-1])))
-		buf[--len] = '\0';
+	while (*len > 0 && (ISLWS(buf[*len-1])))
+		buf[--*len] = '\0';
 
-	DPRINTF("%s: received `%s'\n", __func__, buf);
+	if (*len)
+		DPRINTF("%s: received `%s'\n", __func__, buf);
+	return C_OK;
+}
+
+static int
+getresponse(FETCH *fin, char **cp, size_t buflen, int *hcode)
+{
+	int len, rv;
+	char *ep, *buf = *cp;
+
+	*hcode = 0;
+	if ((rv = getresponseline(fin, buf, buflen, )) != C_OK)
+		return rv;
 
 	/* Determine HTTP response code */
-	cp = strchr(buf, ' ');
-	if (cp == NULL)
-		goto improper;
-	else
-		cp++;
+	*cp = strchr(buf, ' ');
+	if (*cp == NULL)
+		return C_IMPROPER;
 
-	hcode = strtol(cp, , 10);
+	(*cp)++;
+
+	*hcode = strtol(*cp, , 10);
 	if (*ep != '\0' && !isspace((unsigned char)*ep))
-		goto improper;
+		return C_IMPROPER;
+
+	return C_OK;
+}
+
+static int
+negotiate_connection(FETCH *fin, const char *url, const char *penv,
+off_t *rangestart, off_t *rangeend, off_t *entitylen,
+time_t *mtime, struct authinfo *wauth, struct authinfo *pauth,
+int *rval, int *ischunked, char **auth)
+{
+	int			len, hcode, rv;
+	char			buf[FTPBUFLEN], *ep;
+	const char		*cp, *token;
+	char 			*location, *message;
 
-	message = ftp_strdup(cp);
+	*auth = message = location = NULL;
+
+	/* Read the response */
+	ep = buf;
+	switch (getresponse(fin, , sizeof(buf), )) {
+	case C_CLEANUP:
+		goto cleanup_fetch_url;
+	case C_IMPROPER:
+		goto improper;
+	case C_OK:
+		message = ftp_strdup(ep);
+		break;
+	}
 
 	/* Read the rest of the header. */
 
 	for (;;) {
-		alarmtimer(quit_time ? quit_time : 60);
-		len = fetch_getline(fin, buf, sizeof(buf), );
-		alarmtimer(0);
-		if (len < 0) {
-			if (*errormsg == '\n')
-errormsg++;
-			warnx("Receiving HTTP reply: %s", errormsg);
+		if ((rv = getresponseline(fin, buf, sizeof(buf), )) != C_OK)
 			goto cleanup_fetch_url;
-		}
-		while (len > 0 && (ISLWS(buf[len-1])))
-			buf[--len] = '\0';
 		if (len == 0)
 			break;
-		DPRINTF("%s: received `%s'\n", __func__, buf);
 
 	/*
 	 * Look for some headers
@@ -960,8 +992,8 @@ negotiate_connection(FETCH *fin, const c
 "scheme `%s'\n", 

CVS commit: src/usr.bin/ftp

2015-12-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec 16 19:17:16 UTC 2015

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

Log Message:
more refactoring:
- introduce authinfo and urlinfo structures
- split negotiation code out.


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 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.213 src/usr.bin/ftp/fetch.c:1.214
--- src/usr.bin/ftp/fetch.c:1.213	Tue Dec 15 20:20:05 2015
+++ src/usr.bin/ftp/fetch.c	Wed Dec 16 14:17:16 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.213 2015/12/16 01:20:05 nonaka Exp $	*/
+/*	$NetBSD: fetch.c,v 1.214 2015/12/16 19:17:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.213 2015/12/16 01:20:05 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.214 2015/12/16 19:17:16 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -80,19 +80,35 @@ typedef enum {
 	CLASSIC_URL_T
 } url_t;
 
+struct authinfo {
+	char *auth;
+	char *user;
+	char *pass;
+};
+
+struct urlinfo {
+	char *host;
+	char *port;
+	char *path;
+	url_t utype;
+	in_port_t portnum;
+};
+
 __dead static void	aborthttp(int);
 __dead static void	timeouthttp(int);
 #ifndef NO_AUTH
-static int	auth_url(const char *, char **, const char *, const char *);
+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	fetch_ftp(const char *);
 static int	fetch_url(const char *, const char *, char *, char *);
 static const char *match_token(const char **, const char *);
-static int	parse_url(const char *, const char *, url_t *, char **,
-			char **, char **, char **, in_port_t *, char **);
+static int	parse_url(const char *, const char *, struct urlinfo *,
+struct authinfo *);
 static void	url_decode(char *);
+static void	freeauthinfo(struct authinfo *);
+static void	freeurlinfo(struct urlinfo *);
 
 static int	redirect_loop;
 
@@ -144,6 +160,38 @@ match_token(const char **buf, const char
 	return orig;
 }
 
+static void
+initauthinfo(struct authinfo *ai, char *auth)
+{
+	ai->auth = auth;
+	ai->user = ai->pass = 0;
+}
+
+static void
+freeauthinfo(struct authinfo *a)
+{
+	FREEPTR(a->user);
+	if (a->pass != NULL)
+		memset(a->pass, 0, strlen(a->pass));
+	FREEPTR(a->pass);
+}
+
+static void
+initurlinfo(struct urlinfo *ui)
+{
+	ui->host = ui->port = ui->path = 0;
+	ui->utype = UNKNOWN_URL_T;
+	ui->portnum = 0;
+}
+
+static void
+freeurlinfo(struct urlinfo *ui)
+{
+	FREEPTR(ui->host);
+	FREEPTR(ui->port);
+	FREEPTR(ui->path);
+}
+
 #ifndef NO_AUTH
 /*
  * Generate authorization response based on given authentication challenge.
@@ -151,8 +199,7 @@ match_token(const char **buf, const char
  * Sets response to a malloc(3)ed string; caller should free.
  */
 static int
-auth_url(const char *challenge, char **response, const char *guser,
-	const char *gpass)
+auth_url(const char *challenge, char **response, const struct authinfo *auth)
 {
 	const char	*cp, *scheme, *errormsg;
 	char		*ep, *clear, *realm;
@@ -196,8 +243,8 @@ auth_url(const char *challenge, char **r
 	}
 
 	fprintf(ttyout, "Username for `%s': ", realm);
-	if (guser != NULL) {
-		(void)strlcpy(uuser, guser, sizeof(uuser));
+	if (auth->user != NULL) {
+		(void)strlcpy(uuser, auth->user, sizeof(uuser));
 		fprintf(ttyout, "%s\n", uuser);
 	} else {
 		(void)fflush(ttyout);
@@ -206,8 +253,8 @@ auth_url(const char *challenge, char **r
 			goto cleanup_auth_url;
 		}
 	}
-	if (gpass != NULL)
-		upass = gpass;
+	if (auth->pass != NULL)
+		upass = auth->pass;
 	else {
 		gotpass = getpass("Password: ");
 		if (gotpass == NULL) {
@@ -227,7 +274,7 @@ auth_url(const char *challenge, char **r
 
 		/* scheme + " " + enc + "\0" */
 	rlen = strlen(scheme) + 1 + (clen + 2) * 4 / 3 + 1;
-	*response = (char *)ftp_malloc(rlen);
+	*response = ftp_malloc(rlen);
 	(void)strlcpy(*response, scheme, rlen);
 	len = strlcat(*response, " ", rlen);
 			/* use  `clen - 1'  to not encode the trailing NUL */
@@ -326,57 +373,47 @@ url_decode(char *url)
  *	"ftp://host/dir/file;		"dir/file"
  *	"ftp://host//dir/file;		"/dir/file"
  */
+
 static int
-parse_url(const char *url, const char *desc, url_t *utype,
-		char **uuser, char **pass, char **host, char **port,
-		in_port_t *portnum, char **path)
+parse_url(const char *url, const char *desc, struct urlinfo *ui,
+struct authinfo *auth) 
 {
 	const char	*origurl, *tport;
 	char		*cp, *ep, *thost;
 	size_t		 len;
 
-	if (url == NULL || desc == NULL || utype == NULL || uuser == NULL
-	|| pass == NULL || host == NULL || port == NULL || portnum == NULL
-	|| path == NULL)
+	if (url == NULL || desc == NULL || ui == NULL || auth == NULL)
 		

CVS commit: src/usr.bin/ftp

2015-12-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec 16 23:00:39 UTC 2015

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

Log Message:
make DPRINTF/DWARN always statements.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/usr.bin/ftp/ftp_var.h:1.84
--- src/usr.bin/ftp/ftp_var.h:1.83	Mon Jan 12 09:17:08 2015
+++ src/usr.bin/ftp/ftp_var.h	Wed Dec 16 18:00:39 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.83 2015/01/12 14:17:08 christos Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.84 2015/12/16 23:00:39 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -337,11 +337,12 @@ extern	struct option	optiontab[];
 #endif
 
 #ifdef NO_DEBUG
-#define DPRINTF(...)
-#define DWARN(...)
+#define DPRINTF(...)	(void)0
+#define DWARN(...)	(void)0
 #else
-#define DPRINTF(...)	if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
-#define DWARN(...)	if (ftp_debug) warn(__VA_ARGS__)
+#define DWFTP(a)	do a; while (/*CONSTCOND*/0)
+#define DPRINTF(...)	DWFTP(if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__))
+#define DWARN(...)	DWFTP(if (ftp_debug) warn(__VA_ARGS__))
 #endif
 
 #define STRorNULL(s)	((s) ? (s) : "")



CVS commit: src/usr.bin/ftp

2015-12-16 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu Dec 17 04:36:56 UTC 2015

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

Log Message:
- Fix to connect https via proxy.
- Fix ttyout message.


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 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.215 src/usr.bin/ftp/fetch.c:1.216
--- src/usr.bin/ftp/fetch.c:1.215	Wed Dec 16 21:11:47 2015
+++ src/usr.bin/ftp/fetch.c	Thu Dec 17 04:36:56 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.215 2015/12/16 21:11:47 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.216 2015/12/17 04:36:56 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.215 2015/12/16 21:11:47 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.216 2015/12/17 04:36:56 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -184,7 +184,6 @@ initurlinfo(struct urlinfo *ui)
 	ui->portnum = 0;
 }
 
-#ifdef WITH_SSL
 static void
 copyurlinfo(struct urlinfo *dui, struct urlinfo *sui)
 {
@@ -194,7 +193,6 @@ copyurlinfo(struct urlinfo *dui, struct 
 	dui->utype = sui->utype;
 	dui->portnum = sui->portnum;
 }
-#endif
 
 static void
 freeurlinfo(struct urlinfo *ui)
@@ -691,25 +689,29 @@ handle_proxy(const char *url, const char
 }
 
 static void
-print_host(FETCH *fin, const char *host)
+print_host(FETCH *fin, const struct urlinfo *ui)
 {
 	char *h, *p;
 
-	if (strchr(host, ':') == NULL) {
-		fetch_printf(fin, "Host: %s", host);
-		return;
-	}
+	if (strchr(ui->host, ':') == NULL) {
+		fetch_printf(fin, "Host: %s", ui->host);
+	} else {
+		/*
+		 * strip off IPv6 scope identifier, since it is
+		 * local to the node
+		 */
+		h = ftp_strdup(ui->host);
+		if (isipv6addr(h) && (p = strchr(h, '%')) != NULL)
+			*p = '\0';
 
-	/*
-	 * strip off IPv6 scope identifier, since it is
-	 * local to the node
-	 */
-	h = ftp_strdup(host);
-	if (isipv6addr(h) && (p = strchr(h, '%')) != NULL)
-		*p = '\0';
+		fetch_printf(fin, "Host: [%s]", h);
+		free(h);
+	}
 
-	fetch_printf(fin, "Host: [%s]", h);
-	free(h);
+	if ((ui->utype == HTTP_URL_T && ui->portnum != HTTP_PORT) ||
+	(ui->utype == HTTPS_URL_T && ui->portnum != HTTPS_PORT))
+		fetch_printf(fin, ":%u", ui->portnum);
+	fetch_printf(fin, "\r\n");
 }
 
 static void
@@ -733,7 +735,8 @@ print_cache(FETCH *fin, int isproxy)
 }
 
 static int
-print_get(FETCH *fin, int hasleading, int isproxy, const struct urlinfo *ui)
+print_get(FETCH *fin, int hasleading, int isproxy, const struct urlinfo *oui,
+const struct urlinfo *ui)
 {
 	const char *leading = hasleading ? ", " : "  (";
 
@@ -745,17 +748,12 @@ print_get(FETCH *fin, int hasleading, in
 			hasleading++;
 		}
 		fetch_printf(fin, "GET %s HTTP/1.0\r\n", ui->path);
+		print_host(fin, oui);
 		return hasleading;
 	}
 
 	fetch_printf(fin, "GET %s HTTP/1.1\r\n", ui->path);
-	print_host(fin, ui->host);
-
-	if ((ui->utype == HTTP_URL_T && ui->portnum != HTTP_PORT) ||
-	(ui->utype == HTTPS_URL_T && ui->portnum != HTTPS_PORT))
-		fetch_printf(fin, ":%u", ui->portnum);
-
-	fetch_printf(fin, "\r\n");
+	print_host(fin, ui);
 	fetch_printf(fin, "Accept: */*\r\n");
 	fetch_printf(fin, "Connection: close\r\n");
 	if (restart_point) {
@@ -793,10 +791,10 @@ getmtime(const char *cp, time_t *mtime)
 }
 
 static int
-print_proxy(FETCH *fin, const char *leading,
-const char *wwwauth, const char *proxyauth)
+print_proxy(FETCH *fin, int hasleading, const char *wwwauth,
+const char *proxyauth)
 {
-	int hasleading = 0;
+	const char *leading = hasleading ? ", " : "  (";
 
 	if (wwwauth) {
 		if (verbose) {
@@ -1109,12 +1107,10 @@ out:
 #ifdef WITH_SSL
 static int
 connectmethod(int s, FETCH *fin, struct urlinfo *oui, struct urlinfo *ui,
-struct authinfo *wauth, struct authinfo *pauth,
-char **auth, int *hasleading)
+struct authinfo *pauth, char **auth, int *hasleading)
 {
 	void *ssl;
 	int hcode, rv;
-	const char *leading = *hasleading ? ", " : "  (";
 	const char *cp;
 	char buf[FTPBUFLEN], *ep;
 	char *message = NULL;
@@ -1142,27 +1138,10 @@ connectmethod(int s, FETCH *fin, struct 
 	}
 
 	print_agent(fin);
-	*hasleading = print_proxy(fin, leading, wauth->auth, pauth->auth);
-
-	if (verbose) {
-		leading = ", ";
-		(*hasleading)++;
-	} else {
-		leading = "  (";
-		*hasleading = 0;
-	}
-	if (pauth->auth) {
-		if (verbose) {
-			fprintf(ttyout, "%swith proxy authorization" , leading);
-			leading = ", ";
-			(*hasleading)++;
-		}
-		fetch_printf(fin, "Proxy-Authorization: %s\r\n", pauth->auth);
-	}
+	*hasleading = print_proxy(fin, *hasleading, NULL, pauth->auth);
 
 	if (verbose && *hasleading)
 		fputs(")\n", ttyout);
-	leading = "  (";
 	*hasleading = 0;
 
 	fetch_printf(fin, "\r\n");
@@ -1217,14 +1196,10 @@ connectmethod(int s, FETCH *fin, struct 
 		goto cleanup_fetch_url;
 	}
 
-	if 

CVS commit: src/usr.bin/ftp

2015-12-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 15 21:45:21 UTC 2015

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

Log Message:
Factor the proxy handling code out.


To generate a diff of this commit:
cvs rdiff -u -r1.211 -r1.212 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.211 src/usr.bin/ftp/fetch.c:1.212
--- src/usr.bin/ftp/fetch.c:1.211	Tue Dec 15 16:01:27 2015
+++ src/usr.bin/ftp/fetch.c	Tue Dec 15 16:45:21 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.212 2015/12/15 21:45:21 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.212 2015/12/15 21:45:21 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -605,6 +605,46 @@ handle_noproxy(const char *host, in_port
 	return isproxy;
 }
 
+static int
+handle_proxy(const char *penv, char **host, char **port, char **puser,
+char **ppass, url_t *urltype)
+{
+	url_t purltype;
+	char *phost, *ppath;
+	char *pport;
+	in_port_t pportnum;
+
+	if (isipv6addr(*host) && strchr(*host, '%') != NULL) {
+		warnx("Scoped address notation `%s' disallowed via web proxy",
+		*host);
+		return -1;
+	}
+
+	if (parse_url(penv, "proxy URL", , puser, ppass, ,
+	, , ) == -1)
+		return -1;
+
+	if ((!IS_HTTP_TYPE(purltype) && purltype != FTP_URL_T) ||
+	EMPTYSTRING(phost) ||
+	(! EMPTYSTRING(ppath) && strcmp(ppath, "/") != 0)) {
+		warnx("Malformed proxy URL `%s'", penv);
+		FREEPTR(phost);
+		FREEPTR(pport);
+		FREEPTR(ppath);
+		return -1;
+	}
+	FREEPTR(ppath);
+
+	FREEPTR(*host);
+	*host = phost;
+	FREEPTR(*port);
+	*port = pport;
+
+	*urltype = purltype;
+
+	return 0;
+}
+
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
@@ -763,10 +803,6 @@ fetch_url(const char *url, const char *p
 		}
 		direction = "retrieved";
 		if (! EMPTYSTRING(penv)) {			/* use proxy */
-			url_t purltype;
-			char *phost, *ppath;
-			char *pport;
-			in_port_t pportnum;
 
 			isproxy = handle_noproxy(host, portnum);
 
@@ -777,45 +813,18 @@ fetch_url(const char *url, const char *p
 
 			if (isproxy) {
 if (restart_point) {
-	warnx("Can't restart via proxy URL `%s'",
+	warnx(
+	"Can't restart via proxy URL `%s'",
 	penv);
 	goto cleanup_fetch_url;
 }
-if (parse_url(penv, "proxy URL", ,
-, , , , ,
-) == -1)
-	goto cleanup_fetch_url;
-
-if ((!IS_HTTP_TYPE(purltype)
- && purltype != FTP_URL_T) ||
-EMPTYSTRING(phost) ||
-(! EMPTYSTRING(ppath)
- && strcmp(ppath, "/") != 0)) {
-	warnx("Malformed proxy URL `%s'", penv);
-	FREEPTR(phost);
-	FREEPTR(pport);
-	FREEPTR(ppath);
-	goto cleanup_fetch_url;
-}
-if (isipv6addr(host) &&
-strchr(host, '%') != NULL) {
-	warnx(
-"Scoped address notation `%s' disallowed via web proxy",
-	host);
-	FREEPTR(phost);
-	FREEPTR(pport);
-	FREEPTR(ppath);
+if (handle_proxy(penv, , ,
+, , ) < 0) {
 	goto cleanup_fetch_url;
+} else {
+FREEPTR(path);
+path = ftp_strdup(url);
 }
-
-FREEPTR(host);
-host = phost;
-FREEPTR(port);
-port = pport;
-FREEPTR(path);
-path = ftp_strdup(url);
-FREEPTR(ppath);
-urltype = purltype;
 			}
 		} /* ! EMPTYSTRING(penv) */
 



CVS commit: src/usr.bin/ftp

2015-12-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 15 20:49:50 UTC 2015

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

Log Message:
Try to factor out some code, this is completely out of control.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 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.209 src/usr.bin/ftp/fetch.c:1.210
--- src/usr.bin/ftp/fetch.c:1.209	Sun Dec 13 09:06:13 2015
+++ src/usr.bin/ftp/fetch.c	Tue Dec 15 15:49:49 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.209 2015/12/13 14:06:13 tron Exp $	*/
+/*	$NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.209 2015/12/13 14:06:13 tron Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -483,6 +483,89 @@ parse_url(const char *url, const char *d
 
 sigjmp_buf	httpabort;
 
+static int
+ftp_socket(const char *host, const char *port, void **ssl)
+{
+	struct addrinfo	hints, *res, *res0 = NULL;
+	int error;
+	int s;
+
+	memset(, 0, sizeof(hints));
+	hints.ai_flags = 0;
+	hints.ai_family = family;
+	hints.ai_socktype = SOCK_STREAM;
+	hints.ai_protocol = 0;
+
+	error = getaddrinfo(host, port, , );
+	if (error) {
+		warnx("Can't LOOKUP `%s:%s': %s", host, port,
+		(error == EAI_SYSTEM) ? strerror(errno)
+	  : gai_strerror(error));
+		return -1;
+	}
+
+	if (res0->ai_canonname)
+		host = res0->ai_canonname;
+
+	s = -1;
+	if (ssl)
+		*ssl = NULL;
+	for (res = res0; res; res = res->ai_next) {
+		char	hname[NI_MAXHOST], sname[NI_MAXSERV];
+
+		ai_unmapped(res);
+		if (getnameinfo(res->ai_addr, res->ai_addrlen,
+		hname, sizeof(hname), sname, sizeof(sname),
+		NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+			strlcpy(hname, "?", sizeof(hname));
+			strlcpy(sname, "?", sizeof(sname));
+		}
+
+		if (verbose && res0->ai_next) {
+#ifdef INET6
+			if(res->ai_family == AF_INET6) {
+fprintf(ttyout, "Trying [%s]:%s ...\n",
+hname, sname);
+			} else {
+#endif
+fprintf(ttyout, "Trying %s:%s ...\n",
+hname, sname);
+#ifdef INET6
+			}
+#endif
+		}
+
+		s = socket(res->ai_family, SOCK_STREAM, res->ai_protocol);
+		if (s < 0) {
+			warn(
+			"Can't create socket for connection to "
+			"`%s:%s'", hname, sname);
+			continue;
+		}
+
+		if (ftp_connect(s, res->ai_addr, res->ai_addrlen,
+		verbose || !res->ai_next) < 0) {
+			close(s);
+			s = -1;
+			continue;
+		}
+
+#ifdef WITH_SSL
+		if (ssl) {
+			if ((*ssl = fetch_start_ssl(s, host)) == NULL) {
+close(s);
+s = -1;
+continue;
+			}
+		}
+#endif
+		break;
+	}
+	if (res0)
+		freeaddrinfo(res0);
+	return s;
+}
+
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
@@ -494,8 +577,6 @@ sigjmp_buf	httpabort;
 static int
 fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
 {
-	struct addrinfo		hints, *res, *res0 = NULL;
-	int			error;
 	sigfunc volatile	oldint;
 	sigfunc volatile	oldpipe;
 	sigfunc volatile	oldalrm;
@@ -529,9 +610,7 @@ fetch_url(const char *url, const char *p
 	time_t			mtime;
 	url_t			urltype;
 	in_port_t		portnum;
-#ifdef WITH_SSL
-	void			*ssl;
-#endif
+	void			*ssl = NULL;
 
 	DPRINTF("%s: `%s' proxyenv `%s'\n", __func__, url, STRorNULL(penv));
 
@@ -732,80 +811,8 @@ fetch_url(const char *url, const char *p
 			}
 		} /* ! EMPTYSTRING(penv) */
 
-		memset(, 0, sizeof(hints));
-		hints.ai_flags = 0;
-		hints.ai_family = family;
-		hints.ai_socktype = SOCK_STREAM;
-		hints.ai_protocol = 0;
-		error = getaddrinfo(host, port, , );
-		if (error) {
-			warnx("Can't LOOKUP `%s:%s': %s", host, port,
-			(error == EAI_SYSTEM) ? strerror(errno)
-		  : gai_strerror(error));
-			goto cleanup_fetch_url;
-		}
-		if (res0->ai_canonname)
-			host = res0->ai_canonname;
-
-		s = -1;
-#ifdef WITH_SSL
-		ssl = NULL;
-#endif
-		for (res = res0; res; res = res->ai_next) {
-			char	hname[NI_MAXHOST], sname[NI_MAXSERV];
-
-			ai_unmapped(res);
-			if (getnameinfo(res->ai_addr, res->ai_addrlen,
-			hname, sizeof(hname), sname, sizeof(sname),
-			NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
-strlcpy(hname, "?", sizeof(hname));
-strlcpy(sname, "?", sizeof(sname));
-			}
-
-			if (verbose && res0->ai_next) {
-#ifdef INET6
-if(res->ai_family == AF_INET6) {
-	fprintf(ttyout, "Trying [%s]:%s ...\n",
-	hname, sname);
-} else {
-#endif
-	fprintf(ttyout, "Trying %s:%s ...\n",
-	hname, sname);
-#ifdef INET6
-}
-#endif
-			}
-
-			s = socket(res->ai_family, SOCK_STREAM,
-			res->ai_protocol);
-			if (s < 0) {
-warn(
-"Can't create socket for connection to "
-"`%s:%s'", hname, 

CVS commit: src/usr.bin/ftp

2015-12-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 15 21:01:27 UTC 2015

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

Log Message:
Separate no_proxy handling.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 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.210 src/usr.bin/ftp/fetch.c:1.211
--- src/usr.bin/ftp/fetch.c:1.210	Tue Dec 15 15:49:49 2015
+++ src/usr.bin/ftp/fetch.c	Tue Dec 15 16:01:27 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -566,6 +566,45 @@ ftp_socket(const char *host, const char 
 	return s;
 }
 
+static int
+handle_noproxy(const char *host, in_port_t portnum)
+{
+
+	char *cp, *ep, *np, *np_copy, *np_iter, *no_proxy;
+	unsigned long np_port;
+	size_t hlen, plen;
+	int isproxy = 1;
+
+	/* check URL against list of no_proxied sites */
+	no_proxy = getoptionvalue("no_proxy");
+	if (EMPTYSTRING(no_proxy))
+		return isproxy;
+
+	np_iter = np_copy = ftp_strdup(no_proxy);
+	hlen = strlen(host);
+	while ((cp = strsep(_iter, " ,")) != NULL) {
+		if (*cp == '\0')
+			continue;
+		if ((np = strrchr(cp, ':')) != NULL) {
+			*np++ =  '\0';
+			np_port = strtoul(np, , 10);
+			if (*np == '\0' || *ep != '\0')
+continue;
+			if (np_port != portnum)
+continue;
+		}
+		plen = strlen(cp);
+		if (hlen < plen)
+			continue;
+		if (strncasecmp(host + hlen - plen, cp, plen) == 0) {
+			isproxy = 0;
+			break;
+		}
+	}
+	FREEPTR(np_copy);
+	return isproxy;
+}
+
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
@@ -726,45 +765,14 @@ fetch_url(const char *url, const char *p
 		if (! EMPTYSTRING(penv)) {			/* use proxy */
 			url_t purltype;
 			char *phost, *ppath;
-			char *pport, *no_proxy;
+			char *pport;
 			in_port_t pportnum;
 
-			isproxy = 1;
+			isproxy = handle_noproxy(host, portnum);
 
-/* check URL against list of no_proxied sites */
-			no_proxy = getoptionvalue("no_proxy");
-			if (! EMPTYSTRING(no_proxy)) {
-char *np, *np_copy, *np_iter;
-unsigned long np_port;
-size_t hlen, plen;
-
-np_iter = np_copy = ftp_strdup(no_proxy);
-hlen = strlen(host);
-while ((cp = strsep(_iter, " ,")) != NULL) {
-	if (*cp == '\0')
-		continue;
-	if ((np = strrchr(cp, ':')) != NULL) {
-		*np++ =  '\0';
-		np_port = strtoul(np, , 10);
-		if (*np == '\0' || *ep != '\0')
-			continue;
-		if (np_port != portnum)
-			continue;
-	}
-	plen = strlen(cp);
-	if (hlen < plen)
-		continue;
-	if (strncasecmp(host + hlen - plen,
-	cp, plen) == 0) {
-		isproxy = 0;
-		break;
-	}
-}
-FREEPTR(np_copy);
-if (isproxy == 0 && urltype == FTP_URL_T) {
-	rval = fetch_ftp(url);
-	goto cleanup_fetch_url;
-}
+			if (isproxy == 0 && urltype == FTP_URL_T) {
+rval = fetch_ftp(url);
+goto cleanup_fetch_url;
 			}
 
 			if (isproxy) {



CVS commit: src/usr.bin/ftp

2015-12-15 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Wed Dec 16 01:20:06 UTC 2015

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

Log Message:
Fix compile failure without WITH_SSL.

>/tmp/bracket/build/2015.12.15.21.01.27-i386/src/usr.bin/ftp/fetch.c: In 
> function 'fetch_url':
>
> /tmp/bracket/build/2015.12.15.21.01.27-i386/src/usr.bin/ftp/fetch.c:823:18: 
> error: 'HTTPS_URL_T' undeclared (first use in this function)
>   urltype == HTTPS_URL_T ?  : NULL);


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 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.212 src/usr.bin/ftp/fetch.c:1.213
--- src/usr.bin/ftp/fetch.c:1.212	Tue Dec 15 21:45:21 2015
+++ src/usr.bin/ftp/fetch.c	Wed Dec 16 01:20:05 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.212 2015/12/15 21:45:21 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.213 2015/12/16 01:20:05 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.212 2015/12/15 21:45:21 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.213 2015/12/16 01:20:05 nonaka Exp $");
 #endif /* not lint */
 
 /*
@@ -74,9 +74,7 @@ __RCSID("$NetBSD: fetch.c,v 1.212 2015/1
 typedef enum {
 	UNKNOWN_URL_T=-1,
 	HTTP_URL_T,
-#ifdef WITH_SSL
 	HTTPS_URL_T,
-#endif
 	FTP_URL_T,
 	FILE_URL_T,
 	CLASSIC_URL_T



CVS commit: src/usr.bin/ftp

2015-12-13 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Sun Dec 13 14:06:13 UTC 2015

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

Log Message:
(Hopefully) fix build without IPv6 support


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.165 -r1.166 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/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.208 src/usr.bin/ftp/fetch.c:1.209
--- src/usr.bin/ftp/fetch.c:1.208	Fri Dec 11 08:37:31 2015
+++ src/usr.bin/ftp/fetch.c	Sun Dec 13 14:06:13 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.208 2015/12/11 08:37:31 tron Exp $	*/
+/*	$NetBSD: fetch.c,v 1.209 2015/12/13 14:06:13 tron Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.208 2015/12/11 08:37:31 tron Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.209 2015/12/13 14:06:13 tron Exp $");
 #endif /* not lint */
 
 /*
@@ -763,13 +763,17 @@ fetch_url(const char *url, const char *p
 			}
 
 			if (verbose && res0->ai_next) {
+#ifdef INET6
 if(res->ai_family == AF_INET6) {
 	fprintf(ttyout, "Trying [%s]:%s ...\n",
 	hname, sname);
 } else {
+#endif
 	fprintf(ttyout, "Trying %s:%s ...\n",
 	hname, sname);
+#ifdef INET6
 }
+#endif
 			}
 
 			s = socket(res->ai_family, SOCK_STREAM,

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.165 src/usr.bin/ftp/ftp.c:1.166
--- src/usr.bin/ftp/ftp.c:1.165	Fri Dec 11 08:37:31 2015
+++ src/usr.bin/ftp/ftp.c	Sun Dec 13 14:06:13 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.165 2015/12/11 08:37:31 tron Exp $	*/
+/*	$NetBSD: ftp.c,v 1.166 2015/12/13 14:06:13 tron 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.165 2015/12/11 08:37:31 tron Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.166 2015/12/13 14:06:13 tron Exp $");
 #endif
 #endif /* not lint */
 
@@ -200,13 +200,17 @@ hookup(const char *host, const char *por
 		}
 		if (verbose && res0->ai_next) {
 /* if we have multiple possibilities */
+#ifdef INET6
 			if(res->ai_family == AF_INET6) {
 fprintf(ttyout, "Trying [%s]:%s ...\n", hname,
 sname);
 			} else {
+#endif
 fprintf(ttyout, "Trying %s:%s ...\n", hname,
 sname);
+#ifdef INET6
 			}
+#endif
 		}
 		s = socket(res->ai_family, SOCK_STREAM, res->ai_protocol);
 		if (s < 0) {



CVS commit: src/usr.bin/ftp

2015-12-11 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Fri Dec 11 08:37:32 UTC 2015

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

Log Message:
Use the proper format "[IPv6 address]:port" when reporting connection
attempts to IPv6 endpoints.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.164 -r1.165 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/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.207 src/usr.bin/ftp/fetch.c:1.208
--- src/usr.bin/ftp/fetch.c:1.207	Sat Sep 12 19:38:42 2015
+++ src/usr.bin/ftp/fetch.c	Fri Dec 11 08:37:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.207 2015/09/12 19:38:42 wiz Exp $	*/
+/*	$NetBSD: fetch.c,v 1.208 2015/12/11 08:37:31 tron Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.207 2015/09/12 19:38:42 wiz Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.208 2015/12/11 08:37:31 tron Exp $");
 #endif /* not lint */
 
 /*
@@ -763,8 +763,13 @@ fetch_url(const char *url, const char *p
 			}
 
 			if (verbose && res0->ai_next) {
-fprintf(ttyout, "Trying %s:%s ...\n",
-hname, sname);
+if(res->ai_family == AF_INET6) {
+	fprintf(ttyout, "Trying [%s]:%s ...\n",
+	hname, sname);
+} else {
+	fprintf(ttyout, "Trying %s:%s ...\n",
+	hname, sname);
+}
 			}
 
 			s = socket(res->ai_family, SOCK_STREAM,

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.164 src/usr.bin/ftp/ftp.c:1.165
--- src/usr.bin/ftp/ftp.c:1.164	Wed Jul  4 06:09:37 2012
+++ src/usr.bin/ftp/ftp.c	Fri Dec 11 08:37:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp $	*/
+/*	$NetBSD: ftp.c,v 1.165 2015/12/11 08:37:31 tron 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.164 2012/07/04 06:09:37 is Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.165 2015/12/11 08:37:31 tron Exp $");
 #endif
 #endif /* not lint */
 
@@ -200,7 +200,13 @@ hookup(const char *host, const char *por
 		}
 		if (verbose && res0->ai_next) {
 /* if we have multiple possibilities */
-			fprintf(ttyout, "Trying %s:%s ...\n", hname, sname);
+			if(res->ai_family == AF_INET6) {
+fprintf(ttyout, "Trying [%s]:%s ...\n", hname,
+sname);
+			} else {
+fprintf(ttyout, "Trying %s:%s ...\n", hname,
+sname);
+			}
 		}
 		s = socket(res->ai_family, SOCK_STREAM, res->ai_protocol);
 		if (s < 0) {



CVS commit: src/usr.bin/ftp

2015-09-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Sep 16 15:32:53 UTC 2015

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

Log Message:
Workaround const issues of SSL_set_tlsext_host_name.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/usr.bin/ftp/ssl.c:1.5
--- src/usr.bin/ftp/ssl.c:1.4	Sat Sep 12 20:23:27 2015
+++ src/usr.bin/ftp/ssl.c	Wed Sep 16 15:32:53 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.4 2015/09/12 20:23:27 wiz Exp $	*/
+/*	$NetBSD: ssl.c,v 1.5 2015/09/16 15:32:53 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.4 2015/09/12 20:23:27 wiz Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.5 2015/09/16 15:32:53 joerg Exp $");
 #endif
 
 #include 
@@ -570,7 +570,7 @@ fetch_start_ssl(int sock, const char *se
 		return NULL;
 	}
 	SSL_set_fd(ssl, sock);
-	if (!SSL_set_tlsext_host_name(ssl, servername)) {
+	if (!SSL_set_tlsext_host_name(ssl, __UNCONST(servername))) {
 		fprintf(ttyout, "SSL hostname setting failed\n");
 		SSL_CTX_free(ctx);
 		return NULL;



CVS commit: src/usr.bin/ftp

2015-09-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Sep 12 20:18:52 UTC 2015

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

Log Message:
Bump version for SNI support.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 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.86 src/usr.bin/ftp/version.h:1.87
--- src/usr.bin/ftp/version.h:1.86	Thu Apr 23 23:31:23 2015
+++ src/usr.bin/ftp/version.h	Sat Sep 12 20:18:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.86 2015/04/23 23:31:23 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.87 2015/09/12 20:18:52 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1999-2015 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20150424"
+#define	FTP_VERSION	"20150912"
 #endif



CVS commit: src/usr.bin/ftp

2015-09-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Sep 12 20:23:27 UTC 2015

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

Log Message:
servername cannot be NULL here.

Noted by joerg@.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 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.3 src/usr.bin/ftp/ssl.c:1.4
--- src/usr.bin/ftp/ssl.c:1.3	Sat Sep 12 19:38:42 2015
+++ src/usr.bin/ftp/ssl.c	Sat Sep 12 20:23:27 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.3 2015/09/12 19:38:42 wiz Exp $	*/
+/*	$NetBSD: ssl.c,v 1.4 2015/09/12 20:23:27 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.3 2015/09/12 19:38:42 wiz Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.4 2015/09/12 20:23:27 wiz Exp $");
 #endif
 
 #include 
@@ -570,12 +570,10 @@ fetch_start_ssl(int sock, const char *se
 		return NULL;
 	}
 	SSL_set_fd(ssl, sock);
-	if (servername != NULL) {
-		if (!SSL_set_tlsext_host_name(ssl, servername)) {
-			fprintf(ttyout, "SSL hostname setting failed\n");
-			SSL_CTX_free(ctx);
-			return NULL;
-		}
+	if (!SSL_set_tlsext_host_name(ssl, servername)) {
+		fprintf(ttyout, "SSL hostname setting failed\n");
+		SSL_CTX_free(ctx);
+		return NULL;
 	}
 	while ((ret = SSL_connect(ssl)) == -1) {
 		ssl_err = SSL_get_error(ssl, ret);



CVS commit: src/usr.bin/ftp

2015-09-12 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Sep 12 19:38:42 UTC 2015

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

Log Message:
Add Server Name Indication (SNI) support for https.

Needed for e.g. some github URLs.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/ftp/ssl.c 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.206 src/usr.bin/ftp/fetch.c:1.207
--- src/usr.bin/ftp/fetch.c:1.206	Sun Oct 26 16:21:59 2014
+++ src/usr.bin/ftp/fetch.c	Sat Sep 12 19:38:42 2015
@@ -1,7 +1,7 @@
-/*	$NetBSD: fetch.c,v 1.206 2014/10/26 16:21:59 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.207 2015/09/12 19:38:42 wiz Exp $	*/
 
 /*-
- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -10,6 +10,9 @@
  * This code is derived from software contributed to The NetBSD Foundation
  * by Scott Aaron Bamford.
  *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Thomas Klausner.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -34,7 +37,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.206 2014/10/26 16:21:59 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.207 2015/09/12 19:38:42 wiz Exp $");
 #endif /* not lint */
 
 /*
@@ -782,7 +785,7 @@ fetch_url(const char *url, const char *p
 
 #ifdef WITH_SSL
 			if (urltype == HTTPS_URL_T) {
-if ((ssl = fetch_start_ssl(s)) == NULL) {
+if ((ssl = fetch_start_ssl(s, host)) == NULL) {
 	close(s);
 	s = -1;
 	continue;

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.2 src/usr.bin/ftp/ssl.c:1.3
--- src/usr.bin/ftp/ssl.c:1.2	Mon Dec 24 22:12:28 2012
+++ src/usr.bin/ftp/ssl.c	Sat Sep 12 19:38:42 2015
@@ -1,8 +1,9 @@
-/*	$NetBSD: ssl.c,v 1.2 2012/12/24 22:12:28 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.3 2015/09/12 19:38:42 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2010 Joerg Sonnenberger 
+ * Copyright (c) 2015 Thomas Klausner 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.2 2012/12/24 22:12:28 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.3 2015/09/12 19:38:42 wiz Exp $");
 #endif
 
 #include 
@@ -545,7 +546,7 @@ fetch_getline(struct fetch_connect *conn
 }
 
 void *
-fetch_start_ssl(int sock)
+fetch_start_ssl(int sock, const char *servername)
 {
 	SSL *ssl;
 	SSL_CTX *ctx;
@@ -569,6 +570,13 @@ fetch_start_ssl(int sock)
 		return NULL;
 	}
 	SSL_set_fd(ssl, sock);
+	if (servername != NULL) {
+		if (!SSL_set_tlsext_host_name(ssl, servername)) {
+			fprintf(ttyout, "SSL hostname setting failed\n");
+			SSL_CTX_free(ctx);
+			return NULL;
+		}
+	}
 	while ((ret = SSL_connect(ssl)) == -1) {
 		ssl_err = SSL_get_error(ssl, ret);
 		if (ssl_err != SSL_ERROR_WANT_READ &&
Index: src/usr.bin/ftp/ssl.h
diff -u src/usr.bin/ftp/ssl.h:1.2 src/usr.bin/ftp/ssl.h:1.3
--- src/usr.bin/ftp/ssl.h:1.2	Tue Jan  7 02:07:08 2014
+++ src/usr.bin/ftp/ssl.h	Sat Sep 12 19:38:42 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.h,v 1.2 2014/01/07 02:07:08 joerg Exp $	*/
+/*	$NetBSD: ssl.h,v 1.3 2015/09/12 19:38:42 wiz Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@ ssize_t fetch_read(void *, size_t, size_
 char *fetch_getln(char *, int, struct fetch_connect *);
 int fetch_getline(struct fetch_connect *, char *, size_t, const char **);
 void fetch_set_ssl(struct fetch_connect *, void *);
-void *fetch_start_ssl(int);
+void *fetch_start_ssl(int, const char *);
 
 #else	/* !WITH_SSL */
 



CVS commit: src/usr.bin/ftp

2015-04-23 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Thu Apr 23 23:31:23 UTC 2015

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

Log Message:
Add  -x xferbufsize  to set xferbuf size.

Implement  -x xferbufsize  set the socket send and receive buffer size,
as per 'xferbuf' in interactive mode.

Patch from Nicholas Mills (via private mail), with minor adjustment by me.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.85 -r1.86 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.134 src/usr.bin/ftp/ftp.1:1.135
--- src/usr.bin/ftp/ftp.1:1.134	Sat Dec 22 16:57:10 2012
+++ src/usr.bin/ftp/ftp.1	Thu Apr 23 23:31:23 2015
@@ -1,6 +1,6 @@
-.\ 	$NetBSD: ftp.1,v 1.134 2012/12/22 16:57:10 christos Exp $
+.\ 	$NetBSD: ftp.1,v 1.135 2015/04/23 23:31:23 lukem Exp $
 .\
-.\ Copyright (c) 1996-2010 The NetBSD Foundation, Inc.
+.\ Copyright (c) 1996-2015 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 December 22, 2012
+.Dd April 24, 2015
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -84,6 +84,7 @@
 .Xc
 .Oc
 .Ek
+.Op Fl x Ar xferbufsize
 .Bk -words
 .\ [[user@]host [port]]
 .Oo
@@ -311,6 +312,12 @@ Forces
 .Nm
 to show all responses from the remote server, as well
 as report on data transfer statistics.
+.It Fl x Ar xferbufsize
+Set the size of the socket send and receive buffers to
+.Ar xferbufsize .
+Refer to
+.Ic xferbuf
+for more information.
 .El
 .Pp
 The client host with which

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.122 src/usr.bin/ftp/main.c:1.123
--- src/usr.bin/ftp/main.c:1.122	Sat Dec 22 16:57:10 2012
+++ src/usr.bin/ftp/main.c	Thu Apr 23 23:31:23 2015
@@ -1,7 +1,7 @@
-/*	$NetBSD: main.c,v 1.122 2012/12/22 16:57:10 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.123 2015/04/23 23:31:23 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -91,14 +91,14 @@
 #ifndef lint
 __COPYRIGHT(@(#) Copyright (c) 1985, 1989, 1993, 1994\
  The Regents of the University of California.  All rights reserved.\
-  Copyright 1996-2008 The NetBSD Foundation, Inc.  All rights reserved);
+  Copyright 1996-2015 The NetBSD Foundation, Inc.  All rights reserved);
 #endif /* not lint */
 
 #ifndef lint
 #if 0
 static char sccsid[] = @(#)main.c	8.6 (Berkeley) 10/9/94;
 #else
-__RCSID($NetBSD: main.c,v 1.122 2012/12/22 16:57:10 christos Exp $);
+__RCSID($NetBSD: main.c,v 1.123 2015/04/23 23:31:23 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -266,7 +266,7 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, 46AadefginN:o:pP:q:r:Rs:tT:u:vV)) != -1) {
+	while ((ch = getopt(argc, argv, 46AadefginN:o:pP:q:r:Rs:tT:u:vVx:)) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -408,6 +408,13 @@ main(int volatile argc, char **volatile 
 			progress = verbose = 0;
 			break;
 
+		case 'x':
+			sndbuf_size = strsuftoi(optarg);
+			if (sndbuf_size  1)
+errx(1, Bad xferbuf value: %s, optarg);
+			rcvbuf_size = sndbuf_size;
+			break;
+
 		default:
 			usage();
 		}
@@ -1045,7 +1052,7 @@ usage(void)
 
 	(void)fprintf(stderr,
 usage: %s [-46AadefginpRtVv] [-N netrc] [-o outfile] [-P port] [-q quittime]\n
-   [-r retry] [-s srcaddr] [-T dir,max[,inc]]\n
+   [-r retry] [-s srcaddr] [-T dir,max[,inc]] [-x xferbufsize]\n
[[user@]host [port]] [host:path[/]] [file:///file]\n
[ftp://[user[:pass]@]host[:port]/path[/]]\n;
[http://[user[:pass]@]host[:port]/path] [...]\n

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.85 src/usr.bin/ftp/version.h:1.86
--- src/usr.bin/ftp/version.h:1.85	Fri Oct 31 03:27:18 2014
+++ src/usr.bin/ftp/version.h	Thu Apr 23 23:31:23 2015
@@ -1,7 +1,7 @@
-/*	$NetBSD: version.h,v 1.85 2014/10/31 03:27:18 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.86 2015/04/23 23:31:23 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999-2015 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	20141026
+#define	FTP_VERSION	20150424
 #endif



CVS commit: src/usr.bin/ftp

2015-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 12 14:17:08 UTC 2015

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

Log Message:
Increase the buffer limit; otherwise files in:

http://www.taxdetective.ca/Samples/sampledatafiles.html

fail.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/usr.bin/ftp/ftp_var.h:1.83
--- src/usr.bin/ftp/ftp_var.h:1.82	Fri Dec 21 13:07:36 2012
+++ src/usr.bin/ftp/ftp_var.h	Mon Jan 12 09:17:08 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.82 2012/12/21 18:07:36 christos Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.83 2015/01/12 14:17:08 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -169,7 +169,7 @@ enum {
 /*
  * Global defines
  */
-#define	FTPBUFLEN	MAXPATHLEN + 200
+#define	FTPBUFLEN	(4 * MAXPATHLEN)
 #define	MAX_IN_PORT_T	0xU
 
 #define	HASHBYTES	1024	/* default mark for `hash' command */



CVS commit: src/usr.bin/ftp

2014-10-30 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Fri Oct 31 03:27:18 UTC 2014

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

Log Message:
Version 20141026

Ignore special characters unless they're from the command line.
Fixes CVE-2014-8517


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 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.84 src/usr.bin/ftp/version.h:1.85
--- src/usr.bin/ftp/version.h:1.84	Sun May  5 10:40:19 2013
+++ src/usr.bin/ftp/version.h	Fri Oct 31 03:27:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.84 2013/05/05 10:40:19 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.85 2014/10/31 03:27:18 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20130220
+#define	FTP_VERSION	20141026
 #endif



CVS commit: src/usr.bin/ftp

2014-10-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 26 16:21:59 UTC 2014

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

Log Message:
don't pay attention to special characters if they don't come from the command
line (from jmcneill)


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 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.205 src/usr.bin/ftp/fetch.c:1.206
--- src/usr.bin/ftp/fetch.c:1.205	Wed Nov  6 21:06:51 2013
+++ src/usr.bin/ftp/fetch.c	Sun Oct 26 12:21:59 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.205 2013/11/07 02:06:51 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.206 2014/10/26 16:21:59 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.205 2013/11/07 02:06:51 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.206 2014/10/26 16:21:59 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -571,7 +571,7 @@ fetch_url(const char *url, const char *p
 	url_decode(decodedpath);
 
 	if (outfile)
-		savefile = ftp_strdup(outfile);
+		savefile = outfile;
 	else {
 		cp = strrchr(decodedpath, '/');		/* find savefile */
 		if (cp != NULL)
@@ -595,8 +595,7 @@ fetch_url(const char *url, const char *p
 	rangestart = rangeend = entitylen = -1;
 	mtime = -1;
 	if (restartautofetch) {
-		if (strcmp(savefile, -) != 0  *savefile != '|' 
-		stat(savefile, sb) == 0)
+		if (stat(savefile, sb) == 0)
 			restart_point = sb.st_size;
 	}
 	if (urltype == FILE_URL_T) {		/* file:// URLs */
@@ -1150,18 +1149,26 @@ fetch_url(const char *url, const char *p
 		}
 	}		/* end of ftp:// or http:// specific setup */
 
-			/* Open the output file. */
-	if (strcmp(savefile, -) == 0) {
-		fout = stdout;
-	} else if (*savefile == '|') {
-		oldpipe = xsignal(SIGPIPE, SIG_IGN);
-		fout = popen(savefile + 1, w);
-		if (fout == NULL) {
-			warn(Can't execute `%s', savefile + 1);
-			goto cleanup_fetch_url;
+	/* Open the output file. */
+
+	/*
+	 * Only trust filenames with special meaning if they came from
+	 * the command line
+	 */
+	if (outfile == savefile) {
+		if (strcmp(savefile, -) == 0) {
+			fout = stdout;
+		} else if (*savefile == '|') {
+			oldpipe = xsignal(SIGPIPE, SIG_IGN);
+			fout = popen(savefile + 1, w);
+			if (fout == NULL) {
+warn(Can't execute `%s', savefile + 1);
+goto cleanup_fetch_url;
+			}
+			closefunc = pclose;
 		}
-		closefunc = pclose;
-	} else {
+	}
+	if (fout == NULL) {
 		if ((rangeend != -1  rangeend = restart_point) ||
 		(rangestart == -1  filesize != -1  filesize = restart_point)) {
 			/* already done */
@@ -1379,7 +1386,8 @@ fetch_url(const char *url, const char *p
 		(*closefunc)(fout);
 	if (res0)
 		freeaddrinfo(res0);
-	FREEPTR(savefile);
+	if (savefile != outfile)
+		FREEPTR(savefile);
 	FREEPTR(uuser);
 	if (pass != NULL)
 		memset(pass, 0, strlen(pass));



CVS commit: src/usr.bin/ftp

2013-11-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov  7 02:06:52 UTC 2013

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

Log Message:
more volatile for m68k


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 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.204 src/usr.bin/ftp/fetch.c:1.205
--- src/usr.bin/ftp/fetch.c:1.204	Sun Nov  3 09:45:50 2013
+++ src/usr.bin/ftp/fetch.c	Wed Nov  6 21:06:51 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.204 2013/11/03 14:45:50 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.205 2013/11/07 02:06:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.204 2013/11/03 14:45:50 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.205 2013/11/07 02:06:51 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -1263,7 +1263,7 @@ fetch_url(const char *url, const char *p
 	/* transfer file or chunk */
 		while (1) {
 			struct timeval then, now, td;
-			off_t bufrem;
+			volatile off_t bufrem;
 
 			if (rate_get)
 (void)gettimeofday(then, NULL);



CVS commit: src/usr.bin/ftp

2013-11-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Nov  3 14:45:50 UTC 2013

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

Log Message:
let progressmeter deal with the timeout once we've started transferring.


To generate a diff of this commit:
cvs rdiff -u -r1.203 -r1.204 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.203 src/usr.bin/ftp/fetch.c:1.204
--- src/usr.bin/ftp/fetch.c:1.203	Sat Nov  2 15:55:47 2013
+++ src/usr.bin/ftp/fetch.c	Sun Nov  3 09:45:50 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.203 2013/11/02 19:55:47 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.204 2013/11/03 14:45:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.203 2013/11/02 19:55:47 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.204 2013/11/03 14:45:50 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -1203,6 +1203,10 @@ fetch_url(const char *url, const char *p
 
 	bytes = 0;
 	hashbytes = mark;
+	if (oldalrm) {
+		(void)xsignal(SIGALRM, oldalrm);
+		oldalrm = NULL;
+	}
 	progressmeter(-1);
 
 			/* Finally, suck down the file. */
@@ -1214,12 +1218,10 @@ fetch_url(const char *url, const char *p
 		lastchunk = 0;
 	/* read chunk-size */
 		if (ischunked) {
-			alarmtimer(quit_time ? quit_time : 60);
 			if (fetch_getln(xferbuf, bufsize, fin) == NULL) {
 warnx(Unexpected EOF reading chunk-size);
 goto cleanup_fetch_url;
 			}
-			alarmtimer(0);
 			errno = 0;
 			chunksize = strtol(xferbuf, ep, 16);
 			if (ep == xferbuf) {
@@ -1269,10 +1271,8 @@ fetch_url(const char *url, const char *p
 			if (ischunked)
 bufrem = MIN(chunksize, bufrem);
 			while (bufrem  0) {
-alarmtimer(quit_time ? quit_time : 60);
 flen = fetch_read(xferbuf, sizeof(char),
 MIN((off_t)bufsize, bufrem), fin);
-alarmtimer(0);
 if (flen = 0)
 	goto chunkdone;
 bytes += flen;
@@ -1310,13 +1310,11 @@ fetch_url(const char *url, const char *p
 	/* read CRLF after chunk*/
  chunkdone:
 		if (ischunked) {
-			alarmtimer(quit_time ? quit_time : 60);
 			if (fetch_getln(xferbuf, bufsize, fin) == NULL) {
 alarmtimer(0);
 warnx(Unexpected EOF reading chunk CRLF);
 goto cleanup_fetch_url;
 			}
-			alarmtimer(0);
 			if (strcmp(xferbuf, \r\n) != 0) {
 warnx(Unexpected data following chunk);
 goto cleanup_fetch_url;



CVS commit: src/usr.bin/ftp

2013-11-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  2 19:55:47 UTC 2013

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

Log Message:
PR/34796: Hauke Fath: ftp does not timeout on http fetches.


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 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.202 src/usr.bin/ftp/fetch.c:1.203
--- src/usr.bin/ftp/fetch.c:1.202	Sat Feb 23 08:47:36 2013
+++ src/usr.bin/ftp/fetch.c	Sat Nov  2 15:55:47 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.203 2013/11/02 19:55:47 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.203 2013/11/02 19:55:47 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -80,6 +80,7 @@ typedef enum {
 } url_t;
 
 __dead static void	aborthttp(int);
+__dead static void	timeouthttp(int);
 #ifndef NO_AUTH
 static int	auth_url(const char *, char **, const char *, const char *);
 static void	base64_encode(const unsigned char *, size_t, unsigned char *);
@@ -492,8 +493,10 @@ fetch_url(const char *url, const char *p
 {
 	struct addrinfo		hints, *res, *res0 = NULL;
 	int			error;
-	sigfunc volatile	oldintr;
-	sigfunc volatile	oldintp;
+	sigfunc volatile	oldint;
+	sigfunc volatile	oldpipe;
+	sigfunc volatile	oldalrm;
+	sigfunc volatile	oldquit;
 	int volatile		s;
 	struct stat		sb;
 	int volatile		ischunked;
@@ -519,6 +522,7 @@ fetch_url(const char *url, const char *p
 	int			(*volatile closefunc)(FILE *);
 	FETCH			*volatile fin;
 	FILE			*volatile fout;
+	const char		*volatile penv = proxyenv;
 	time_t			mtime;
 	url_t			urltype;
 	in_port_t		portnum;
@@ -526,9 +530,9 @@ fetch_url(const char *url, const char *p
 	void			*ssl;
 #endif
 
-	DPRINTF(fetch_url: `%s' proxyenv `%s'\n, url, STRorNULL(proxyenv));
+	DPRINTF(%s: `%s' proxyenv `%s'\n, __func__, url, STRorNULL(penv));
 
-	oldintr = oldintp = NULL;
+	oldquit = oldalrm = oldint = oldpipe = NULL;
 	closefunc = NULL;
 	fin = NULL;
 	fout = NULL;
@@ -539,6 +543,9 @@ fetch_url(const char *url, const char *p
 	rval = 1;
 	uuser = pass = host = path = decodedpath = puser = ppass = NULL;
 
+	if (sigsetjmp(httpabort, 1))
+		goto cleanup_fetch_url;
+
 	if (parse_url(url, URL, urltype, uuser, pass, host, port,
 	portnum, path) == -1)
 		goto cleanup_fetch_url;
@@ -572,7 +579,7 @@ fetch_url(const char *url, const char *p
 		else
 			savefile = ftp_strdup(decodedpath);
 	}
-	DPRINTF(fetch_url: savefile `%s'\n, savefile);
+	DPRINTF(%s: savefile `%s'\n, __func__, savefile);
 	if (EMPTYSTRING(savefile)) {
 		if (urltype == FTP_URL_T) {
 			rval = fetch_ftp(url);
@@ -624,18 +631,18 @@ fetch_url(const char *url, const char *p
 		const char *leading;
 		int hasleading;
 
-		if (proxyenv == NULL) {
+		if (penv == NULL) {
 #ifdef WITH_SSL
 			if (urltype == HTTPS_URL_T)
-proxyenv = getoptionvalue(https_proxy);
+penv = getoptionvalue(https_proxy);
 #endif
-			if (proxyenv == NULL  IS_HTTP_TYPE(urltype))
-proxyenv = getoptionvalue(http_proxy);
+			if (penv == NULL  IS_HTTP_TYPE(urltype))
+penv = getoptionvalue(http_proxy);
 			else if (urltype == FTP_URL_T)
-proxyenv = getoptionvalue(ftp_proxy);
+penv = getoptionvalue(ftp_proxy);
 		}
 		direction = retrieved;
-		if (! EMPTYSTRING(proxyenv)) {			/* use proxy */
+		if (! EMPTYSTRING(penv)) {			/* use proxy */
 			url_t purltype;
 			char *phost, *ppath;
 			char *pport, *no_proxy;
@@ -682,10 +689,10 @@ fetch_url(const char *url, const char *p
 			if (isproxy) {
 if (restart_point) {
 	warnx(Can't restart via proxy URL `%s',
-	proxyenv);
+	penv);
 	goto cleanup_fetch_url;
 }
-if (parse_url(proxyenv, proxy URL, purltype,
+if (parse_url(penv, proxy URL, purltype,
 puser, ppass, phost, pport, pportnum,
 ppath) == -1)
 	goto cleanup_fetch_url;
@@ -695,8 +702,7 @@ fetch_url(const char *url, const char *p
 EMPTYSTRING(phost) ||
 (! EMPTYSTRING(ppath)
   strcmp(ppath, /) != 0)) {
-	warnx(Malformed proxy URL `%s',
-	proxyenv);
+	warnx(Malformed proxy URL `%s', penv);
 	FREEPTR(phost);
 	FREEPTR(pport);
 	FREEPTR(ppath);
@@ -722,7 +728,7 @@ fetch_url(const char *url, const char *p
 FREEPTR(ppath);
 urltype = purltype;
 			}
-		} /* ! EMPTYSTRING(proxyenv) */
+		} /* ! EMPTYSTRING(penv) */
 
 		memset(hints, 0, sizeof(hints));
 		hints.ai_flags = 0;
@@ -794,9 +800,13 @@ fetch_url(const char *url, const char *p
 			goto cleanup_fetch_url;
 		}
 
+		oldalrm = xsignal(SIGALRM, timeouthttp);
+		alarmtimer(quit_time ? quit_time : 60);
 		fin = fetch_fdopen(s, r+);
 		fetch_set_ssl(fin, ssl);
+		

CVS commit: src/usr.bin/ftp

2013-05-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun May  5 10:40:19 UTC 2013

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

Log Message:
Version 20130220: restart fix, SYST response parsing improvement


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/usr.bin/ftp/version.h:1.84
--- src/usr.bin/ftp/version.h:1.83	Wed Feb  6 16:37:20 2013
+++ src/usr.bin/ftp/version.h	Sun May  5 10:40:19 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.83 2013/02/06 16:37:20 christos Exp $	*/
+/*	$NetBSD: version.h,v 1.84 2013/05/05 10:40:19 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20121224
+#define	FTP_VERSION	20130220
 #endif



CVS commit: src/usr.bin/ftp

2013-02-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 23 13:47:36 UTC 2013

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

Log Message:
fix restart from anon ymous


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 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.201 src/usr.bin/ftp/fetch.c:1.202
--- src/usr.bin/ftp/fetch.c:1.201	Sat Dec 22 11:58:51 2012
+++ src/usr.bin/ftp/fetch.c	Sat Feb 23 08:47:36 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.201 2012/12/22 16:58:51 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.201 2012/12/22 16:58:51 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -844,7 +844,7 @@ fetch_url(const char *url, const char *p
 			fetch_printf(fin, Connection: close\r\n);
 			if (restart_point) {
 fputs(leading, ttyout);
-fprintf(ttyout, Range: bytes= LLF -\r\n,
+fetch_printf(fin, Range: bytes= LLF -\r\n,
 (LLT)restart_point);
 fprintf(ttyout, restarting at  LLF,
 (LLT)restart_point);



CVS commit: src/usr.bin/ftp

2013-02-19 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue Feb 19 23:29:16 UTC 2013

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

Log Message:
When using the response to SYST to decide whether to default to 'binary'
  be a lot less specific.
Kyocera printers report 230 Linux but really don't want text transfers
of pdf files!


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 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.157 src/usr.bin/ftp/util.c:1.158
--- src/usr.bin/ftp/util.c:1.157	Wed Jul  4 06:09:37 2012
+++ src/usr.bin/ftp/util.c	Tue Feb 19 23:29:15 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $	*/
+/*	$NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $);
+__RCSID($NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $);
 #endif /* not lint */
 
 /*
@@ -202,25 +202,20 @@ getremoteinfo(void)
 			/* determine remote system type */
 	if (command(SYST) == COMPLETE) {
 		if (overbose) {
-			char *cp, c;
-
-			c = 0;
-			cp = strchr(reply_string + 4, ' ');
-			if (cp == NULL)
-cp = strchr(reply_string + 4, '\r');
-			if (cp) {
-if (cp[-1] == '.')
-	cp--;
-c = *cp;
-*cp = '\0';
-			}
-
-			fprintf(ttyout, Remote system type is %s.\n,
-			reply_string + 4);
-			if (cp)
-*cp = c;
+			int os_len = strcspn(reply_string + 4,  \r\n\t);
+			if (os_len  1  reply_string[4 + os_len - 1] == '.')
+os_len--;
+			fprintf(ttyout, Remote system type is %.*s.\n,
+			os_len, reply_string + 4);
 		}
-		if (!strncmp(reply_string, 215 UNIX Type: L8, 17)) {
+		/*
+		 * Decide whether we should default to bninary.
+		 * 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.
+		 */
+		if (!strncasecmp(reply_string + 4, unix, 4) ||
+		!strncasecmp(reply_string + 4, linux, 5)) {
 			if (proxy)
 unix_proxy = 1;
 			else



CVS commit: src/usr.bin/ftp

2013-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb  6 16:37:20 UTC 2013

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

Log Message:
merry belated x-mas.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/usr.bin/ftp/version.h:1.83
--- src/usr.bin/ftp/version.h:1.82	Sat Jun  5 09:59:39 2010
+++ src/usr.bin/ftp/version.h	Wed Feb  6 11:37:20 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.82 2010/06/05 13:59:39 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.83 2013/02/06 16:37:20 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20100605
+#define	FTP_VERSION	20121224
 #endif



CVS commit: src/usr.bin/ftp

2012-12-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 24 22:12:29 UTC 2012

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

Log Message:
backwards compatible with netbsd-6.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 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.1 src/usr.bin/ftp/ssl.c:1.2
--- src/usr.bin/ftp/ssl.c:1.1	Fri Dec 21 13:07:36 2012
+++ src/usr.bin/ftp/ssl.c	Mon Dec 24 17:12:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.1 2012/12/21 18:07:36 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.2 2012/12/24 22:12:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -33,7 +33,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: ssl.c,v 1.1 2012/12/21 18:07:36 christos Exp $);
+__RCSID($NetBSD: ssl.c,v 1.2 2012/12/24 22:12:28 christos Exp $);
 #endif
 
 #include time.h
@@ -248,7 +248,9 @@ struct fetch_connect *
 fetch_fdopen(int sd, const char *fmode)
 {
 	struct fetch_connect *conn;
+#if defined(SO_NOSIGPIPE) || defined(TCP_NOPUSH)
 	int opt = 1;
+#endif
 
 	if ((conn = calloc(1, sizeof(*conn))) == NULL)
 		return NULL;
@@ -256,7 +258,9 @@ fetch_fdopen(int sd, const char *fmode)
 	conn-sd = sd;
 	conn-issock = 1;
 	fcntl(sd, F_SETFD, FD_CLOEXEC);
+#ifdef SO_NOSIGPIPE
 	setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, opt, sizeof(opt));
+#endif
 #ifdef TCP_NOPUSH
 	setsockopt(sd, IPPROTO_TCP, TCP_NOPUSH, opt, sizeof(opt));
 #endif



CVS commit: src/usr.bin/ftp

2012-12-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Dec 22 16:57:10 UTC 2012

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

Log Message:
document https support, mentioning certificates are not validated, and obey
https_proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/ftp/cmdtab.c
cvs rdiff -u -r1.199 -r1.200 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.121 -r1.122 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.134 src/usr.bin/ftp/cmds.c:1.135
--- src/usr.bin/ftp/cmds.c:1.134	Sun Jan 15 15:43:24 2012
+++ src/usr.bin/ftp/cmds.c	Sat Dec 22 11:57:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.134 2012/01/15 20:43:24 christos Exp $	*/
+/*	$NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos 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.134 2012/01/15 20:43:24 christos Exp $);
+__RCSID($NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -2675,7 +2675,7 @@ setoption(int argc, char *argv[])
 		return;
 	}
 
-#define	OPTIONINDENT ((int) sizeof(http_proxy))
+#define	OPTIONINDENT ((int) sizeof(https_proxy))
 	if (argc == 1) {
 		for (o = optiontab; o-name != NULL; o++) {
 			fprintf(ttyout, %-*s\t%s\n, OPTIONINDENT,

Index: src/usr.bin/ftp/cmdtab.c
diff -u src/usr.bin/ftp/cmdtab.c:1.51 src/usr.bin/ftp/cmdtab.c:1.52
--- src/usr.bin/ftp/cmdtab.c:1.51	Sun Apr 12 06:18:52 2009
+++ src/usr.bin/ftp/cmdtab.c	Sat Dec 22 11:57:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = @(#)cmdtab.c	8.4 (Berkeley) 10/9/94;
 #else
-__RCSID($NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp $);
+__RCSID($NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -298,6 +298,7 @@ struct option optiontab[] = {
 	{ anonpass,	NULL },
 	{ ftp_proxy,	NULL },
 	{ http_proxy,	NULL },
+	{ https_proxy,NULL },
 	{ no_proxy,	NULL },
 	{ pager,	NULL },
 	{ prompt,	NULL },

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.199 src/usr.bin/ftp/fetch.c:1.200
--- src/usr.bin/ftp/fetch.c:1.199	Fri Dec 21 13:07:36 2012
+++ src/usr.bin/ftp/fetch.c	Sat Dec 22 11:57:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.199 2012/12/21 18:07:36 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.200 2012/12/22 16:57:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.199 2012/12/21 18:07:36 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.200 2012/12/22 16:57:09 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -482,7 +482,7 @@ sigjmp_buf	httpabort;
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
- * http_proxy as appropriate.
+ * http_proxy/https_proxy as appropriate.
  * Supports HTTP redirects.
  * Returns 1 on failure, 0 on completed xfer, -1 if ftp connection
  * is still open (e.g, ftp xfer with trailing /)
@@ -625,7 +625,9 @@ fetch_url(const char *url, const char *p
 		int hasleading;
 
 		if (proxyenv == NULL) {
-			if (IS_HTTP_TYPE(urltype))
+			if (urltype == HTTPS_URL_T)
+proxyenv = getoptionvalue(https_proxy);
+			if (proxyenv == NULL  IS_HTTP_TYPE(urltype))
 proxyenv = getoptionvalue(http_proxy);
 			else if (urltype == FTP_URL_T)
 proxyenv = getoptionvalue(ftp_proxy);

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.133 src/usr.bin/ftp/ftp.1:1.134
--- src/usr.bin/ftp/ftp.1:1.133	Sun Apr  8 18:00:38 2012
+++ src/usr.bin/ftp/ftp.1	Sat Dec 22 11:57:10 2012
@@ -1,4 +1,4 @@
-.\ 	$NetBSD: ftp.1,v 1.133 2012/04/08 22:00:38 wiz Exp $
+.\ 	$NetBSD: ftp.1,v 1.134 2012/12/22 16:57:10 christos Exp $
 .\
 .\ Copyright (c) 1996-2010 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -57,7 +57,7 @@
 .\
 .\	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\
-.Dd March 5, 2010
+.Dd December 22, 2012
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -1325,7 +1325,7 @@ and
 .Ar value
 are not given, display all of the options and their values.
 The currently supported options are:
-.Bl -tag -width http_proxy -offset indent
+.Bl -tag -width https_proxy -offset indent
 .It Cm anonpass
 Defaults to
 .Ev $FTPANONPASS
@@ -1335,6 +1335,9 @@ Defaults to
 .It Cm http_proxy
 Defaults to
 .Ev $http_proxy .
+.It Cm https_proxy
+Defaults to
+.Ev $https_proxy .
 .It Cm no_proxy
 Defaults to
 .Ev 

CVS commit: src/usr.bin/ftp

2012-12-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Dec 22 16:58:51 UTC 2012

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

Log Message:
compile without SSL


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 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.200 src/usr.bin/ftp/fetch.c:1.201
--- src/usr.bin/ftp/fetch.c:1.200	Sat Dec 22 11:57:09 2012
+++ src/usr.bin/ftp/fetch.c	Sat Dec 22 11:58:51 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.200 2012/12/22 16:57:09 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.201 2012/12/22 16:58:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.200 2012/12/22 16:57:09 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.201 2012/12/22 16:58:51 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -625,8 +625,10 @@ fetch_url(const char *url, const char *p
 		int hasleading;
 
 		if (proxyenv == NULL) {
+#ifdef WITH_SSL
 			if (urltype == HTTPS_URL_T)
 proxyenv = getoptionvalue(https_proxy);
+#endif
 			if (proxyenv == NULL  IS_HTTP_TYPE(urltype))
 proxyenv = getoptionvalue(http_proxy);
 			else if (urltype == FTP_URL_T)



CVS commit: src/usr.bin/ftp

2012-12-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 21 18:07:37 UTC 2012

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

Log Message:
PR/47276: Add https support


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/ftp/Makefile
cvs rdiff -u -r1.198 -r1.199 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/ftp/main.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/ftp/ssl.c 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/Makefile
diff -u src/usr.bin/ftp/Makefile:1.35 src/usr.bin/ftp/Makefile:1.36
--- src/usr.bin/ftp/Makefile:1.35	Sun Aug 14 08:58:15 2011
+++ src/usr.bin/ftp/Makefile	Fri Dec 21 13:07:36 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.35 2011/08/14 12:58:15 christos Exp $
+#	$NetBSD: Makefile,v 1.36 2012/12/21 18:07:36 christos Exp $
 #	from: @(#)Makefile	8.2 (Berkeley) 4/3/94
 
 .include bsd.own.mk
@@ -18,6 +18,12 @@ CPPFLAGS+=-DNO_EDITCOMPLETE -DNO_ABOUT -
 .else
 LDADD+=	-ledit -lterminfo
 DPADD+=	${LIBEDIT} ${LIBTERMINFO}
+.if (${MKCRYPTO} != no)
+CPPFLAGS+= -DWITH_SSL
+SRCS+=ssl.c
+LDADD+= -lssl -lcrypto
+DPADD+= ${LIBSSL} ${LIBCRYPTO}
+.endif
 .endif
 
 .if (!defined(SMALLPROG) || defined(SMALLPROG_INET6))  (${USE_INET6} != no)

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.198 src/usr.bin/ftp/fetch.c:1.199
--- src/usr.bin/ftp/fetch.c:1.198	Wed Jul  4 02:09:37 2012
+++ src/usr.bin/ftp/fetch.c	Fri Dec 21 13:07:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $	*/
+/*	$NetBSD: fetch.c,v 1.199 2012/12/21 18:07:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $);
+__RCSID($NetBSD: fetch.c,v 1.199 2012/12/21 18:07:36 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -64,12 +64,16 @@ __RCSID($NetBSD: fetch.c,v 1.198 2012/0
 #include unistd.h
 #include time.h
 
+#include ssl.h
 #include ftp_var.h
 #include version.h
 
 typedef enum {
 	UNKNOWN_URL_T=-1,
 	HTTP_URL_T,
+#ifdef WITH_SSL
+	HTTPS_URL_T,
+#endif
 	FTP_URL_T,
 	FILE_URL_T,
 	CLASSIC_URL_T
@@ -100,7 +104,15 @@ static int	redirect_loop;
 #define	FILE_URL	file://	/* file URL prefix */
 #define	FTP_URL		ftp://;	/* ftp URL prefix */
 #define	HTTP_URL	http://;	/* http URL prefix */
+#ifdef WITH_SSL
+#define	HTTPS_URL	https://;	/* https URL prefix */
 
+#define	IS_HTTP_TYPE(urltype) \
+	(((urltype) == HTTP_URL_T) || ((urltype) == HTTPS_URL_T))
+#else
+#define	IS_HTTP_TYPE(urltype) \
+	((urltype) == HTTP_URL_T)
+#endif
 
 /*
  * Determine if token is the next word in buf (case insensitive).
@@ -346,6 +358,13 @@ parse_url(const char *url, const char *d
 	} else if (STRNEQUAL(url, FILE_URL)) {
 		url += sizeof(FILE_URL) - 1;
 		*utype = FILE_URL_T;
+#ifdef WITH_SSL
+	} else if (STRNEQUAL(url, HTTPS_URL)) {
+		url += sizeof(HTTPS_URL) - 1;
+		*utype = HTTPS_URL_T;
+		*portnum = HTTPS_PORT;
+		tport = httpsport;
+#endif
 	} else {
 		warnx(Invalid %s `%s', desc, url);
  cleanup_parse_url:
@@ -498,17 +517,21 @@ fetch_url(const char *url, const char *p
 	char			*puser, *ppass, *useragent;
 	off_t			hashbytes, rangestart, rangeend, entitylen;
 	int			(*volatile closefunc)(FILE *);
-	FILE			*volatile fin;
+	FETCH			*volatile fin;
 	FILE			*volatile fout;
 	time_t			mtime;
 	url_t			urltype;
 	in_port_t		portnum;
+#ifdef WITH_SSL
+	void			*ssl;
+#endif
 
 	DPRINTF(fetch_url: `%s' proxyenv `%s'\n, url, STRorNULL(proxyenv));
 
 	oldintr = oldintp = NULL;
 	closefunc = NULL;
-	fin = fout = NULL;
+	fin = NULL;
+	fout = NULL;
 	s = -1;
 	savefile = NULL;
 	auth = location = message = NULL;
@@ -531,7 +554,7 @@ fetch_url(const char *url, const char *p
 			rval = fetch_ftp(url);
 			goto cleanup_fetch_url;
 		}
-		if (urltype != HTTP_URL_T || outfile == NULL)  {
+		if (!IS_HTTP_TYPE(urltype) || outfile == NULL)  {
 			warnx(Invalid URL (no file after host) `%s', url);
 			goto cleanup_fetch_url;
 		}
@@ -571,17 +594,17 @@ fetch_url(const char *url, const char *p
 	}
 	if (urltype == FILE_URL_T) {		/* file:// URLs */
 		direction = copied;
-		fin = fopen(decodedpath, r);
+		fin = fetch_open(decodedpath, r);
 		if (fin == NULL) {
 			warn(Can't open `%s', decodedpath);
 			goto cleanup_fetch_url;
 		}
-		if (fstat(fileno(fin), sb) == 0) {
+		if (fstat(fetch_fileno(fin), sb) == 0) {
 			mtime = sb.st_mtime;
 			filesize = sb.st_size;
 		}
 		if (restart_point) {
-			if (lseek(fileno(fin), restart_point, SEEK_SET)  0) {
+			if (lseek(fetch_fileno(fin), restart_point, SEEK_SET)  0) {
 warn(Can't seek to restart `%s',
 decodedpath);
 goto cleanup_fetch_url;
@@ -594,12 +617,15 @@ fetch_url(const char *url, const char *p
 (LLT)restart_point);
 			

CVS commit: src/usr.bin/ftp

2012-07-04 Thread Ignatios Souvatzis
Module Name:src
Committed By:   is
Date:   Wed Jul  4 06:09:38 UTC 2012

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

Log Message:
As discussed on tech-net@: Don't display expected EHOSTUNREACH for all but
the last connect attempts in terse mode.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.197 -r1.198 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.163 -r1.164 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.156 -r1.157 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.79 src/usr.bin/ftp/extern.h:1.80
--- src/usr.bin/ftp/extern.h:1.79	Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/extern.h	Wed Jul  4 06:09:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.79 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: extern.h,v 1.80 2012/07/04 06:09:37 is Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -239,7 +239,7 @@ void	unsetoption(int, char **);
 void	updatelocalcwd(void);
 void	updateremotecwd(void);
 void	user(int, char **);
-int	ftp_connect(int, const struct sockaddr *, socklen_t);
+int	ftp_connect(int, const struct sockaddr *, socklen_t, int);
 int	ftp_listen(int, int);
 int	ftp_poll(struct pollfd *, int, int);
 void   *ftp_malloc(size_t);

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.197 src/usr.bin/ftp/fetch.c:1.198
--- src/usr.bin/ftp/fetch.c:1.197	Fri Feb 24 19:53:31 2012
+++ src/usr.bin/ftp/fetch.c	Wed Jul  4 06:09:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.197 2012/02/24 19:53:31 apb Exp $	*/
+/*	$NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.197 2012/02/24 19:53:31 apb Exp $);
+__RCSID($NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $);
 #endif /* not lint */
 
 /*
@@ -734,7 +734,8 @@ fetch_url(const char *url, const char *p
 continue;
 			}
 
-			if (ftp_connect(s, res-ai_addr, res-ai_addrlen)  0) {
+			if (ftp_connect(s, res-ai_addr, res-ai_addrlen,
+			verbose || !res-ai_next)  0) {
 close(s);
 s = -1;
 continue;

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.163 src/usr.bin/ftp/ftp.c:1.164
--- src/usr.bin/ftp/ftp.c:1.163	Sat Dec 10 05:53:58 2011
+++ src/usr.bin/ftp/ftp.c	Wed Jul  4 06:09:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is 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.163 2011/12/10 05:53:58 lukem Exp $);
+__RCSID($NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp $);
 #endif
 #endif /* not lint */
 
@@ -208,7 +208,8 @@ hookup(const char *host, const char *por
 			hname, sname);
 			continue;
 		}
-		if (ftp_connect(s, res-ai_addr, res-ai_addrlen)  0) {
+		if (ftp_connect(s, res-ai_addr, res-ai_addrlen,
+		verbose || !res-ai_next)  0) {
 			close(s);
 			s = -1;
 			continue;
@@ -1468,7 +1469,7 @@ initconn(void)
 			goto bad;
 
 		if (ftp_connect(data, (struct sockaddr *)data_addr.si_su,
-		data_addr.su_len)  0) {
+		data_addr.su_len, 1)  0) {
 			if (activefallback) {
 (void)close(data);
 data = -1;

Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.156 src/usr.bin/ftp/util.c:1.157
--- src/usr.bin/ftp/util.c:1.156	Sat Dec 10 05:53:58 2011
+++ src/usr.bin/ftp/util.c	Wed Jul  4 06:09:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $);
+__RCSID($NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $);
 #endif /* not lint */
 
 /*
@@ -1351,7 +1351,7 @@ get_line(FILE *stream, char *buf, size_t
  * error message displayed.)
  */
 int
-ftp_connect(int sock, const struct sockaddr *name, socklen_t namelen)
+ftp_connect(int sock, const struct sockaddr *name, socklen_t namelen, int pe)
 {
 	int		flags, rv, timeout, error;
 	socklen_t	slen;
@@ -1417,8 +1417,9 @@ ftp_connect(int sock, const struct socka
 	rv = connect(sock, name, namelen);	/* inititate the connection */
 	if (rv == -1) {/* connection error */
 		if (errno != EINPROGRESS) {	/* error isn't please wait */
+			if (pe || (errno != EHOSTUNREACH))
  connecterror:
-			warn(Can't connect to `%s:%s', hname, sname);
+warn(Can't connect to `%s:%s', hname, sname);
 			return -1;
 		}
 



CVS commit: src/usr.bin/ftp

2012-02-24 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Feb 24 19:40:49 UTC 2012

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

Log Message:
When given an URL that contains :// but is not recognised,
print an error message.  Now ftp https://foo/bar; prints

ftp: Unsupported URL scheme `https'

instead of

ftp: Can't lookup `https:ftp': No address associated with hostname
ftp: Can't connect or login to host `https:?'


To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 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.195 src/usr.bin/ftp/fetch.c:1.196
--- src/usr.bin/ftp/fetch.c:1.195	Sat Dec 10 05:53:58 2011
+++ src/usr.bin/ftp/fetch.c	Fri Feb 24 19:40:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $	*/
+/*	$NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $);
+__RCSID($NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $);
 #endif /* not lint */
 
 /*
@@ -700,7 +700,7 @@ fetch_url(const char *url, const char *p
 		hints.ai_protocol = 0;
 		error = getaddrinfo(host, port, hints, res0);
 		if (error) {
-			warnx(Can't lookup `%s:%s': %s, host, port,
+			warnx(Can't LOOKUP `%s:%s': %s, host, port,
 			(error == EAI_SYSTEM) ? strerror(errno)
 		  : gai_strerror(error));
 			goto cleanup_fetch_url;
@@ -1687,6 +1687,7 @@ static int
 go_fetch(const char *url)
 {
 	char *proxyenv;
+	char *p;
 
 #ifndef NO_ABOUT
 	/*
@@ -1731,6 +1732,18 @@ go_fetch(const char *url)
 		return (fetch_url(url, NULL, NULL, NULL));
 
 	/*
+	 * If it contains :// but does not begin with ftp://
+	 * or something that was already handled, then it's
+	 * unsupported.
+	 *
+	 * If it contains : but not :// then we assume the
+	 * part before the colon is a host name, not an URL scheme,
+	 * so we don't try to match that here.
+	 */
+	if ((p = strstr(url, ://)) != NULL  ! STRNEQUAL(url, FTP_URL))
+		errx(1, Unsupported URL scheme `%.*s', (p - url), url);
+
+	/*
 	 * Try FTP URL-style and host:file arguments next.
 	 * If ftpproxy is set with an FTP URL, use fetch_url()
 	 * Othewise, use fetch_ftp().



CVS commit: src/usr.bin/ftp

2012-02-24 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Feb 24 19:53:31 UTC 2012

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

Log Message:
subtracting two pointers yields ptrdiff_t, so cast it to int.


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 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.196 src/usr.bin/ftp/fetch.c:1.197
--- src/usr.bin/ftp/fetch.c:1.196	Fri Feb 24 19:40:49 2012
+++ src/usr.bin/ftp/fetch.c	Fri Feb 24 19:53:31 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $	*/
+/*	$NetBSD: fetch.c,v 1.197 2012/02/24 19:53:31 apb Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $);
+__RCSID($NetBSD: fetch.c,v 1.197 2012/02/24 19:53:31 apb Exp $);
 #endif /* not lint */
 
 /*
@@ -1741,7 +1741,7 @@ go_fetch(const char *url)
 	 * so we don't try to match that here.
 	 */
 	if ((p = strstr(url, ://)) != NULL  ! STRNEQUAL(url, FTP_URL))
-		errx(1, Unsupported URL scheme `%.*s', (p - url), url);
+		errx(1, Unsupported URL scheme `%.*s', (int)(p - url), url);
 
 	/*
 	 * Try FTP URL-style and host:file arguments next.



CVS commit: src/usr.bin/ftp

2012-01-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 15 03:58:28 UTC 2012

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

Log Message:
make -R work the same in ftp:// like it does for http:// (i.e. work if
there is no local file).


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 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.132 src/usr.bin/ftp/cmds.c:1.133
--- src/usr.bin/ftp/cmds.c:1.132	Fri Sep 16 11:39:26 2011
+++ src/usr.bin/ftp/cmds.c	Sat Jan 14 22:58:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.132 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: cmds.c,v 1.133 2012/01/15 03:58:28 christos 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.132 2011/09/16 15:39:26 joerg Exp $);
+__RCSID($NetBSD: cmds.c,v 1.133 2012/01/15 03:58:28 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -111,6 +111,7 @@ __RCSID($NetBSD: cmds.c,v 1.132 2011/09
 
 #include ctype.h
 #include err.h
+#include errno.h
 #include glob.h
 #include limits.h
 #include netdb.h
@@ -556,7 +557,7 @@ void
 reget(int argc, char *argv[])
 {
 
-	(void)getit(argc, argv, 1, r+);
+	(void)getit(argc, argv, 1, restart_point ? r+ : w );
 }
 
 void
@@ -612,10 +613,14 @@ getit(int argc, char *argv[], int restar
 		ret = stat(locfile, stbuf);
 		if (restartit == 1) {
 			if (ret  0) {
-warn(Can't stat `%s', locfile);
-goto freegetit;
+if (errno != ENOENT) {
+	warn(Can't stat `%s', locfile);
+	goto freegetit;
+}
+restart_point = 0;
 			}
-			restart_point = stbuf.st_size;
+			else
+restart_point = stbuf.st_size;
 		} else {
 			if (ret == 0) {
 time_t mtime;



CVS commit: src/usr.bin/ftp

2011-12-09 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Dec 10 05:53:59 UTC 2011

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

Log Message:
Move determination of socket buffer sizes from startup to the first
time a socket is used, as the previous logic assumed AF_INET sockets
were available (which they may not be in an IPv6-only system).
Per discussion with Maxim Konovalov and the FreeBSD problem 162661.


To generate a diff of this commit:
cvs rdiff -u -r1.194 -r1.195 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.155 -r1.156 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/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.194 src/usr.bin/ftp/fetch.c:1.195
--- src/usr.bin/ftp/fetch.c:1.194	Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/fetch.c	Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.194 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.194 2011/09/16 15:39:26 joerg Exp $);
+__RCSID($NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $);
 #endif /* not lint */
 
 /*
@@ -52,6 +52,7 @@ __RCSID($NetBSD: fetch.c,v 1.194 2011/0
 #include arpa/ftp.h
 #include arpa/inet.h
 
+#include assert.h
 #include ctype.h
 #include err.h
 #include errno.h
@@ -1125,6 +1126,7 @@ fetch_url(const char *url, const char *p
 	(void)xsignal(SIGQUIT, psummary);
 	oldintr = xsignal(SIGINT, aborthttp);
 
+	assert(rcvbuf_size  0);
 	if ((size_t)rcvbuf_size  bufsize) {
 		if (xferbuf)
 			(void)free(xferbuf);

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.162 src/usr.bin/ftp/ftp.c:1.163
--- src/usr.bin/ftp/ftp.c:1.162	Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/ftp.c	Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.162 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem 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.162 2011/09/16 15:39:26 joerg Exp $);
+__RCSID($NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -108,6 +108,7 @@ __RCSID($NetBSD: ftp.c,v 1.162 2011/09/
 #include arpa/ftp.h
 #include arpa/telnet.h
 
+#include assert.h
 #include ctype.h
 #include err.h
 #include errno.h
@@ -765,6 +766,7 @@ sendrequest(const char *cmd, const char 
 	if (dout == NULL)
 		goto abort;
 
+	assert(sndbuf_size  0);
 	if ((size_t)sndbuf_size  bufsize) {
 		if (buf)
 			(void)free(buf);
@@ -1026,6 +1028,7 @@ recvrequest(const char *cmd, const char 
 		progress = 0;
 		preserve = 0;
 	}
+	assert(rcvbuf_size  0);
 	if ((size_t)rcvbuf_size  bufsize) {
 		if (buf)
 			(void)free(buf);

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.119 src/usr.bin/ftp/main.c:1.120
--- src/usr.bin/ftp/main.c:1.119	Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/main.c	Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.119 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: main.c,v 1.120 2011/12/10 05:53:58 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 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.119 2011/09/16 15:39:26 joerg Exp $);
+__RCSID($NetBSD: main.c,v 1.120 2011/12/10 05:53:58 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -139,9 +139,8 @@ main(int volatile argc, char **volatile 
 	struct passwd *pw;
 	char *cp, *ep, *anonpass, *upload_path, *src_addr;
 	const char *anonuser;
-	int dumbterm, s, isupload;
+	int dumbterm, isupload;
 	size_t len;
-	socklen_t slen;
 
 	tzset();
 	setlocale(LC_ALL, );
@@ -204,35 +203,6 @@ main(int volatile argc, char **volatile 
 	if (cp != NULL  strlcpy(netrc, cp, sizeof(netrc)) = sizeof(netrc))
 		errx(1, $NETRC `%s': %s, cp, strerror(ENAMETOOLONG));
 
-	/*
-	 * Get the default socket buffer sizes if we don't already have them.
-	 * It doesn't matter which socket we do this to, because on the first
-	 * call no socket buffer sizes will have been modified, so we are
-	 * guaranteed to get the system defaults.
-	 */
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s == -1)
-		err(1, Can't create socket to determine default socket sizes);
-	slen = sizeof(rcvbuf_size);
-	if (getsockopt(s, SOL_SOCKET, SO_RCVBUF,
-	(void *)rcvbuf_size, slen) == -1)
-		err(1, Unable to get default rcvbuf size);
-	slen = sizeof(sndbuf_size);
-	if (getsockopt(s, SOL_SOCKET, SO_SNDBUF,
-	(void *)sndbuf_size, slen) == -1)
-		err(1, Unable to get default sndbuf size);
-	

CVS commit: src/usr.bin/ftp

2011-08-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 14 12:58:16 UTC 2011

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

Log Message:
fix gcc-4.5 warnings


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/ftp/Makefile
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.117 -r1.118 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/Makefile
diff -u src/usr.bin/ftp/Makefile:1.34 src/usr.bin/ftp/Makefile:1.35
--- src/usr.bin/ftp/Makefile:1.34	Tue Jun 21 22:49:44 2011
+++ src/usr.bin/ftp/Makefile	Sun Aug 14 08:58:15 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.34 2011/06/22 02:49:44 mrg Exp $
+#	$NetBSD: Makefile,v 1.35 2011/08/14 12:58:15 christos Exp $
 #	from: @(#)Makefile	8.2 (Berkeley) 4/3/94
 
 .include bsd.own.mk
@@ -28,9 +28,3 @@
 main.o:	ftp_var.h
 
 .include bsd.prog.mk
-
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS.main.c+=	-Wno-error
-COPTS.ftp.c+=	-Wno-error
-.endif

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.160 src/usr.bin/ftp/ftp.c:1.161
--- src/usr.bin/ftp/ftp.c:1.160	Fri Mar  5 02:41:10 2010
+++ src/usr.bin/ftp/ftp.c	Sun Aug 14 08:58:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.160 2010/03/05 07:41:10 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.161 2011/08/14 12:58:15 christos 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.160 2010/03/05 07:41:10 lukem Exp $);
+__RCSID($NetBSD: ftp.c,v 1.161 2011/08/14 12:58:15 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -1591,18 +1591,25 @@
  UC(p[0]), UC(p[1]));
 			break;
 #ifdef INET6
-		case AF_INET6:
-			a = (char *)data_addr.si_su.su_sin6.sin6_addr;
-			p = (char *)data_addr.su_port;
+		case AF_INET6: {
+			uint8_t ua[sizeof(data_addr.si_su.su_sin6.sin6_addr)];
+			uint8_t up[sizeof(data_addr.su_port)];
+
+			memcpy(ua, data_addr.si_su.su_sin6.sin6_addr,
+			sizeof(ua));
+			memcpy(up, data_addr.su_port, sizeof(up));
+			
 			result = command(
 	LPRT %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,
  6, 16,
- UC(a[0]),UC(a[1]),UC(a[2]),UC(a[3]),
- UC(a[4]),UC(a[5]),UC(a[6]),UC(a[7]),
- UC(a[8]),UC(a[9]),UC(a[10]),UC(a[11]),
- UC(a[12]),UC(a[13]),UC(a[14]),UC(a[15]),
- 2, UC(p[0]), UC(p[1]));
+  ua[0],  ua[1],  ua[2],  ua[3],
+  ua[4],  ua[5],  ua[6],  ua[7],
+  ua[8],  ua[9], ua[10], ua[11],
+ ua[12], ua[13], ua[14], ua[15],
+ 2,
+ up[0], up[1]);
 			break;
+		}
 #endif
 		default:
 			result = COMPLETE + 1; /* xxx */

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.117 src/usr.bin/ftp/main.c:1.118
--- src/usr.bin/ftp/main.c:1.117	Mon Jul 13 15:05:41 2009
+++ src/usr.bin/ftp/main.c	Sun Aug 14 08:58:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.117 2009/07/13 19:05:41 roy Exp $	*/
+/*	$NetBSD: main.c,v 1.118 2011/08/14 12:58:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@
 #if 0
 static char sccsid[] = @(#)main.c	8.6 (Berkeley) 10/9/94;
 #else
-__RCSID($NetBSD: main.c,v 1.117 2009/07/13 19:05:41 roy Exp $);
+__RCSID($NetBSD: main.c,v 1.118 2011/08/14 12:58:15 christos Exp $);
 #endif
 #endif /* not lint */
 
@@ -737,7 +737,7 @@
 			 */
 			if (strchr(margv[0], ':') != NULL ||
 			!editing ||
-			el_parse(el, margc, (const char **)margv) != 0)
+			el_parse(el, margc, (void *)margv) != 0)
 #endif /* !NO_EDITCOMPLETE */
 fputs(?Invalid command.\n, ttyout);
 			continue;



CVS commit: src/usr.bin/ftp

2010-06-05 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sat Jun  5 13:59:39 UTC 2010

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

Log Message:
In ftpvis(), prevent incomplete escape sequences at end of dst,
and ensure NUL-termination of dst.  Also tweak for readibility.
Fix from Uwe Stuehler and Stefan Sperling, via Marc Balmer.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.81 -r1.82 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/util.c
diff -u src/usr.bin/ftp/util.c:1.154 src/usr.bin/ftp/util.c:1.155
--- src/usr.bin/ftp/util.c:1.154	Fri Mar  5 07:41:10 2010
+++ src/usr.bin/ftp/util.c	Sat Jun  5 13:59:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.154 2010/03/05 07:41:10 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: util.c,v 1.154 2010/03/05 07:41:10 lukem Exp $);
+__RCSID($NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $);
 #endif /* not lint */
 
 /*
@@ -1098,9 +1098,8 @@
 {
 	size_t	di, si;
 
-	for (di = si = 0;
-	src[si] != '\0'  di  dstlen  si  srclen;
-	di++, si++) {
+	di = si = 0;
+	while (src[si] != '\0'  di  dstlen  si  srclen) {
 		switch (src[si]) {
 		case '\\':
 		case ' ':
@@ -1108,12 +1107,18 @@
 		case '\r':
 		case '\n':
 		case '':
-			dst[di++] = '\\';
-			if (di = dstlen)
+			/*
+			 * Need room for two characters and NUL, avoiding
+			 * incomplete escape sequences at end of dst.
+			 */
+			if (di = dstlen - 3)
 break;
+			dst[di++] = '\\';
 			/* FALLTHROUGH */
 		default:
-			dst[di] = src[si];
+			dst[di] = src[si++];
+			if (di  dstlen)
+di++;
 		}
 	}
 	dst[di] = '\0';

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.81 src/usr.bin/ftp/version.h:1.82
--- src/usr.bin/ftp/version.h:1.81	Fri Mar  5 07:45:40 2010
+++ src/usr.bin/ftp/version.h	Sat Jun  5 13:59:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.81 2010/03/05 07:45:40 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.82 2010/06/05 13:59:39 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20100305
+#define	FTP_VERSION	20100605
 #endif



CVS commit: src/usr.bin/ftp

2010-01-11 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue Jan 12 06:50:05 UTC 2010

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

Log Message:
rename argument from bool to val


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 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.130 src/usr.bin/ftp/cmds.c:1.131
--- src/usr.bin/ftp/cmds.c:1.130	Mon Jul 13 19:05:41 2009
+++ src/usr.bin/ftp/cmds.c	Tue Jan 12 06:50:04 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp $	*/
+/*	$NetBSD: cmds.c,v 1.131 2010/01/12 06:50:04 lukem 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.130 2009/07/13 19:05:41 roy Exp $);
+__RCSID($NetBSD: cmds.c,v 1.131 2010/01/12 06:50:04 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -779,10 +779,10 @@
 }
 
 const char *
-onoff(int bool)
+onoff(int val)
 {
 
-	return (bool ? on : off);
+	return (val ? on : off);
 }
 
 /*



CVS commit: src/usr.bin/ftp

2009-11-15 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Nov 15 10:03:16 UTC 2009

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

Log Message:
Crank version to 20090915:
* rename internal getline() to get_line() to avoid conflict with libc
* avoid NULL deref in verbose output in an error path
* improve man page markup


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/usr.bin/ftp/version.h:1.80
--- src/usr.bin/ftp/version.h:1.79	Fri Apr 24 08:57:26 2009
+++ src/usr.bin/ftp/version.h	Sun Nov 15 10:03:16 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.79 2009/04/24 08:57:26 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.80 2009/11/15 10:03:16 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20090424
+#define	FTP_VERSION	20090915
 #endif



CVS commit: src/usr.bin/ftp

2009-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 17 09:08:17 UTC 2009

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

Log Message:
back out previous; luke says:
'@' is a reserved URI char per RFC 3986, use %40


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 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.190 src/usr.bin/ftp/fetch.c:1.191
--- src/usr.bin/ftp/fetch.c:1.190	Sat Aug 15 22:49:23 2009
+++ src/usr.bin/ftp/fetch.c	Mon Aug 17 05:08:16 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.190 2009/08/16 02:49:23 christos Exp $	*/
+/*	$NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.190 2009/08/16 02:49:23 christos Exp $);
+__RCSID($NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $);
 #endif /* not lint */
 
 /*
@@ -374,7 +374,7 @@
 		*path = ftp_strdup(ep);
 	}
 
-	cp = strrchr(thost, '@');	/* look for user[:pass]@ in URLs */
+	cp = strchr(thost, '@');	/* look for user[:pass]@ in URLs */
 	if (cp != NULL) {
 		if (*utype == FTP_URL_T)
 			anonftp = 0;	/* disable anonftp */



CVS commit: src/usr.bin/ftp

2009-08-13 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Thu Aug 13 17:55:18 UTC 2009

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

Log Message:
avoid NULL dereference in log output if the command line parser
failed to extract a port number from the URL


To generate a diff of this commit:
cvs rdiff -u -r1.188 -r1.189 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.188 src/usr.bin/ftp/fetch.c:1.189
--- src/usr.bin/ftp/fetch.c:1.188	Mon Jul 13 19:05:41 2009
+++ src/usr.bin/ftp/fetch.c	Thu Aug 13 17:55:18 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.188 2009/07/13 19:05:41 roy Exp $	*/
+/*	$NetBSD: fetch.c,v 1.189 2009/08/13 17:55:18 drochner Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: fetch.c,v 1.188 2009/07/13 19:05:41 roy Exp $);
+__RCSID($NetBSD: fetch.c,v 1.189 2009/08/13 17:55:18 drochner Exp $);
 #endif /* not lint */
 
 /*
@@ -1498,7 +1498,8 @@
 	autologin = oautologin;
 	if ((connected == 0) ||
 	(connected == 1  !ftp_login(host, uuser, pass))) {
-		warnx(Can't connect or login to host `%s:%s', host, port);
+		warnx(Can't connect or login to host `%s:%s',
+			host, port ? port : ?);
 		goto cleanup_fetch_ftp;
 	}
 



CVS commit: src/usr.bin/ftp

2009-07-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Jul 11 18:35:49 UTC 2009

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

Log Message:
Fix markup.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 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.129 src/usr.bin/ftp/ftp.1:1.130
--- src/usr.bin/ftp/ftp.1:1.129	Mon May  4 19:47:09 2009
+++ src/usr.bin/ftp/ftp.1	Sat Jul 11 18:35:48 2009
@@ -1,4 +1,4 @@
-.\ 	$NetBSD: ftp.1,v 1.129 2009/05/04 19:47:09 wiz Exp $
+.\ 	$NetBSD: ftp.1,v 1.130 2009/07/11 18:35:48 joerg Exp $
 .\
 .\ Copyright (c) 1996-2008 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -62,8 +62,7 @@
 .Os
 .Sh NAME
 .Nm ftp
-.Nd
-Internet file transfer program
+.Nd Internet file transfer program
 .Sh SYNOPSIS
 .Nm
 .Op Fl 46AadefginpRtVv



CVS commit: src/usr.bin/ftp

2009-04-24 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Fri Apr 24 08:57:26 UTC 2009

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

Log Message:
Revert incorrect change made as part of the WARNS=4.
Fixes ftp host [port] on the CLI.
Noted by Geoff Wing.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.78 -r1.79 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/main.c
diff -u src/usr.bin/ftp/main.c:1.115 src/usr.bin/ftp/main.c:1.116
--- src/usr.bin/ftp/main.c:1.115	Sun Apr 12 10:18:52 2009
+++ src/usr.bin/ftp/main.c	Fri Apr 24 08:57:26 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.115 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: main.c,v 1.116 2009/04/24 08:57:26 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@
 #if 0
 static char sccsid[] = @(#)main.c	8.6 (Berkeley) 10/9/94;
 #else
-__RCSID($NetBSD: main.c,v 1.115 2009/04/12 10:18:52 lukem Exp $);
+__RCSID($NetBSD: main.c,v 1.116 2009/04/24 08:57:26 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -574,7 +574,7 @@
 	anonftp = 0;
 	autologin = 0;
 }
-setpeer(3, xargv);
+setpeer(argc+1, xargv);
 autologin = oautologin;
 if (connected == 1  uuser != NULL)
 	(void)ftp_login(host, uuser, NULL);

Index: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.78 src/usr.bin/ftp/version.h:1.79
--- src/usr.bin/ftp/version.h:1.78	Sun Apr 12 10:18:52 2009
+++ src/usr.bin/ftp/version.h	Fri Apr 24 08:57:26 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: version.h,v 1.78 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: version.h,v 1.79 2009/04/24 08:57:26 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	20090412
+#define	FTP_VERSION	20090424
 #endif



CVS commit: src/usr.bin/ftp

2009-04-14 Thread Jed Davis
Module Name:src
Committed By:   jld
Date:   Wed Apr 15 03:42:33 UTC 2009

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

Log Message:
Unbreak the build by adding curly braces to placate the empty-body warning.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 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.158 src/usr.bin/ftp/ftp.c:1.159
--- src/usr.bin/ftp/ftp.c:1.158	Sun Apr 12 10:18:52 2009
+++ src/usr.bin/ftp/ftp.c	Wed Apr 15 03:42:33 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.158 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.159 2009/04/15 03:42:33 jld 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.158 2009/04/12 10:18:52 lukem Exp $);
+__RCSID($NetBSD: ftp.c,v 1.159 2009/04/15 03:42:33 jld Exp $);
 #endif
 #endif /* not lint */
 
@@ -1624,8 +1624,9 @@
 	if (data_addr.su_family == AF_INET) {
 		on = IPTOS_THROUGHPUT;
 		if (setsockopt(data, IPPROTO_IP, IP_TOS,
-(void *)on, sizeof(on)) == -1)
+(void *)on, sizeof(on)) == -1) {
 			DWARN(setsockopt %s (ignored), IPTOS_THROUGHPUT);
+		}
 	}
 #endif
 	return (0);



CVS commit: src/usr.bin/ftp

2009-04-14 Thread Jed Davis
Module Name:src
Committed By:   jld
Date:   Wed Apr 15 04:19:39 UTC 2009

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

Log Message:
Another empty-body warning/error, another set of curly braces.  This, and
the last one, appear to affect only the NO_DEBUG (e.g., SMALLPROG) build.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 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.150 src/usr.bin/ftp/util.c:1.151
--- src/usr.bin/ftp/util.c:1.150	Sun Apr 12 10:18:52 2009
+++ src/usr.bin/ftp/util.c	Wed Apr 15 04:19:39 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.150 2009/04/12 10:18:52 lukem Exp $	*/
+/*	$NetBSD: util.c,v 1.151 2009/04/15 04:19:39 jld Exp $	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: util.c,v 1.150 2009/04/12 10:18:52 lukem Exp $);
+__RCSID($NetBSD: util.c,v 1.151 2009/04/15 04:19:39 jld Exp $);
 #endif /* not lint */
 
 /*
@@ -755,11 +755,12 @@
 goto bad_parse_time;
 			else
 goto cleanup_parse_time;
-		} else
+		} else {
 			DPRINTF(remotemodtime: parsed date `%s' as  LLF
 			, %s,
 			timestr, (LLT)rtime,
 			rfc2822time(localtime(rtime)));
+		}
 	} else {
 		if (r == ERROR  code == 500  features[FEAT_MDTM] == -1)
 			features[FEAT_MDTM] = 0;



CVS commit: src/usr.bin/ftp

2009-04-12 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 12 10:18:52 UTC 2009

Modified Files:
src/usr.bin/ftp: cmds.c cmdtab.c complete.c domacro.c extern.h fetch.c
ftp.c ftp_var.h main.c progressbar.c progressbar.h util.c version.h

Log Message:
Fix numerous WARNS=4 issues (-Wcast-qual -Wsign-compare).


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/ftp/cmds.c
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/ftp/cmdtab.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/ftp/complete.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/ftp/domacro.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/ftp/extern.h
cvs rdiff -u -r1.186 -r1.187 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.157 -r1.158 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/ftp/progressbar.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/ftp/progressbar.h
cvs rdiff -u -r1.149 -r1.150 src/usr.bin/ftp/util.c
cvs rdiff -u -r1.77 -r1.78 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/cmds.c
diff -u src/usr.bin/ftp/cmds.c:1.128 src/usr.bin/ftp/cmds.c:1.129
--- src/usr.bin/ftp/cmds.c:1.128	Sun Apr 12 07:07:41 2009
+++ src/usr.bin/ftp/cmds.c	Sun Apr 12 10:18:52 2009
@@ -1,7 +1,7 @@
-/*	$NetBSD: cmds.c,v 1.128 2009/04/12 07:07:41 lukem Exp $	*/
+/*	$NetBSD: cmds.c,v 1.129 2009/04/12 10:18:52 lukem Exp $	*/
 
 /*-
- * Copyright (c) 1996-2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 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.128 2009/04/12 07:07:41 lukem Exp $);
+__RCSID($NetBSD: cmds.c,v 1.129 2009/04/12 10:18:52 lukem Exp $);
 #endif
 #endif /* not lint */
 
@@ -115,6 +115,7 @@
 #include limits.h
 #include netdb.h
 #include paths.h
+#include stddef.h
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -125,17 +126,17 @@
 #include version.h
 
 static struct types {
-	char	*t_name;
-	char	*t_mode;
-	int	t_type;
-	char	*t_arg;
+	const char	*t_name;
+	const char	*t_mode;
+	int		t_type;
+	const char	*t_arg;
 } types[] = {
 	{ ascii,	A,	TYPE_A,	0 },
 	{ binary,	I,	TYPE_I,	0 },
 	{ image,	I,	TYPE_I,	0 },
 	{ ebcdic,	E,	TYPE_E,	0 },
 	{ tenex,	L,	TYPE_L,	bytename },
-	{ NULL }
+	{ NULL,		NULL,	0, NULL }
 };
 
 static sigjmp_buf	 jabort;
@@ -143,6 +144,7 @@
 static int	confirm(const char *, const char *);
 static void	mintr(int);
 static void	mabort(const char *);
+static void	set_type(const char *);
 
 static const char *doprocess(char *, size_t, const char *, int, int, int);
 static const char *domap(char *, size_t, const char *);
@@ -217,10 +219,9 @@
 settype(int argc, char *argv[])
 {
 	struct types *p;
-	int comret;
 
 	if (argc == 0 || argc  2) {
-		char *sep;
+		const char *sep;
 
 		UPRINTF(usage: %s [, argv[0]);
 		sep =  ;
@@ -237,11 +238,20 @@
 		code = 0;
 		return;
 	}
+	set_type(argv[1]);
+}
+
+void
+set_type(const char *ttype)
+{
+	struct types *p;
+	int comret;
+
 	for (p = types; p-t_name; p++)
-		if (strcmp(argv[1], p-t_name) == 0)
+		if (strcmp(ttype, p-t_name) == 0)
 			break;
 	if (p-t_name == 0) {
-		fprintf(ttyout, %s: unknown mode.\n, argv[1]);
+		fprintf(ttyout, %s: unknown mode.\n, ttype);
 		code = -1;
 		return;
 	}
@@ -287,12 +297,6 @@
 	verbose = oldverbose;
 }
 
-char *stype[] = {
-	type,
-	,
-	0
-};
-
 /*
  * Set binary transfer type.
  */
@@ -306,8 +310,7 @@
 		code = -1;
 		return;
 	}
-	stype[1] = binary;
-	settype(2, stype);
+	set_type(binary);
 }
 
 /*
@@ -323,8 +326,7 @@
 		code = -1;
 		return;
 	}
-	stype[1] = ascii;
-	settype(2, stype);
+	set_type(ascii);
 }
 
 /*
@@ -340,8 +342,7 @@
 		code = -1;
 		return;
 	}
-	stype[1] = tenex;
-	settype(2, stype);
+	set_type(tenex);
 }
 
 /*
@@ -402,7 +403,7 @@
 put(int argc, char *argv[])
 {
 	char buf[MAXPATHLEN];
-	char *cmd;
+	const char *cmd;
 	int loc = 0;
 	char *locfile;
 	const char *remfile;
@@ -680,7 +681,7 @@
 	int ointer;
 	char *cp;
 	const char *tp;
-	int restartit;
+	int volatile restartit;
 
 	if (argc == 0 ||
 	(argc == 1  !another(argc, argv, remote-files))) {
@@ -747,9 +748,9 @@
 void
 fget(int argc, char *argv[])
 {
-	char	*gmode;
+	const char *gmode;
 	FILE	*fp;
-	char	buf[MAXPATHLEN];
+	char	buf[MAXPATHLEN], cmdbuf[MAX_C_NAME];
 
 	if (argc != 2) {
 		UPRINTF(usage: %s localfile\n, argv[0]);
@@ -764,7 +765,8 @@
 		return;
 	}
 
-	argv[0] = get;
+	(void)strlcpy(cmdbuf, get, sizeof(cmdbuf));
+	argv[0] = cmdbuf;
 	gmode = restart_point ? r+ : w;
 
 	while (getline(fp, buf, sizeof(buf), NULL) = 0) {
@@ -1282,12 +1284,14 @@
 ls(int argc, char *argv[])
 {
 	const char *cmd;
-	char *remdir, *locfile;
-	int freelocfile, pagecmd, mlsdcmd;
+	char *remdir, *locbuf;
+	const char