Module Name: othersrc
Committed By: lukem
Date: Fri Aug 27 01:38:49 UTC 2021
Modified Files:
othersrc/usr.bin/tnftp/src: fetch.c ftp.1 ftp.c ssl.c ssl.h util.c
version.h
Log Message:
Merge from NetBSD-2021-01-31 to NetBSD-20210826
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 othersrc/usr.bin/tnftp/src/fetch.c
cvs rdiff -u -r1.17 -r1.18 othersrc/usr.bin/tnftp/src/ftp.1
cvs rdiff -u -r1.23 -r1.24 othersrc/usr.bin/tnftp/src/ftp.c
cvs rdiff -u -r1.5 -r1.6 othersrc/usr.bin/tnftp/src/ssl.c
cvs rdiff -u -r1.4 -r1.5 othersrc/usr.bin/tnftp/src/ssl.h
cvs rdiff -u -r1.24 -r1.25 othersrc/usr.bin/tnftp/src/util.c
cvs rdiff -u -r1.9 -r1.10 othersrc/usr.bin/tnftp/src/version.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/usr.bin/tnftp/src/fetch.c
diff -u othersrc/usr.bin/tnftp/src/fetch.c:1.25 othersrc/usr.bin/tnftp/src/fetch.c:1.26
--- othersrc/usr.bin/tnftp/src/fetch.c:1.25 Sun Apr 25 07:50:37 2021
+++ othersrc/usr.bin/tnftp/src/fetch.c Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-/* $NetBSD: fetch.c,v 1.25 2021/04/25 07:50:37 lukem Exp $ */
-/* from NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp */
+/* $NetBSD: fetch.c,v 1.26 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: fetch.c,v 1.234 2021/08/01 15:29:30 andvar Exp */
/*-
* Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID(" NetBSD: fetch.c,v 1.232 2020/07/11 00:29:38 lukem Exp ");
+__RCSID(" NetBSD: fetch.c,v 1.234 2021/08/01 15:29:30 andvar Exp ");
#endif /* not lint */
/*
@@ -145,6 +145,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
@@ -1657,7 +1694,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;
@@ -2215,7 +2252,7 @@ go_fetch(const char *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().
+ * Otherwise, use fetch_ftp().
*/
proxyenv = getoptionvalue("ftp_proxy");
if (!EMPTYSTRING(proxyenv) && STRNEQUAL(url, FTP_URL))
Index: othersrc/usr.bin/tnftp/src/ftp.1
diff -u othersrc/usr.bin/tnftp/src/ftp.1:1.17 othersrc/usr.bin/tnftp/src/ftp.1:1.18
--- othersrc/usr.bin/tnftp/src/ftp.1:1.17 Sun Apr 25 07:50:37 2021
+++ othersrc/usr.bin/tnftp/src/ftp.1 Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-.\" $NetBSD: ftp.1,v 1.17 2021/04/25 07:50:37 lukem Exp $
-.\" from NetBSD: ftp.1,v 1.144 2021/01/31 08:59:40 lukem Exp
+.\" $NetBSD: ftp.1,v 1.18 2021/08/27 01:38:49 lukem Exp $
+.\" from 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.
@@ -58,7 +58,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd January 31, 2021
+.Dd April 25, 2021
.Dt FTP 1
.Os
.Sh NAME
@@ -185,10 +185,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
@@ -301,7 +304,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.
@@ -543,7 +548,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
@@ -601,7 +608,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:
@@ -1113,7 +1122,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.
@@ -1887,9 +1898,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
Index: othersrc/usr.bin/tnftp/src/ftp.c
diff -u othersrc/usr.bin/tnftp/src/ftp.c:1.23 othersrc/usr.bin/tnftp/src/ftp.c:1.24
--- othersrc/usr.bin/tnftp/src/ftp.c:1.23 Sun Apr 25 07:50:37 2021
+++ othersrc/usr.bin/tnftp/src/ftp.c Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-/* $NetBSD: ftp.c,v 1.23 2021/04/25 07:50:37 lukem Exp $ */
-/* from NetBSD: ftp.c,v 1.171 2021/01/06 04:43:14 lukem Exp */
+/* $NetBSD: ftp.c,v 1.24 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: ftp.c,v 1.174 2021/08/26 06:23:24 lukem Exp */
/*-
* Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -98,7 +98,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.174 2021/08/26 06:23:24 lukem Exp ");
#endif
#endif /* not lint */
@@ -288,6 +288,11 @@ hookup(const char *host, const char *por
goto bad;
}
+ if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
+ (void *)&on, sizeof(on)) == -1) {
+ DWARN("setsockopt %s (ignored)", "SO_KEEPALIVE");
+ }
+
if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
(void *)&on, sizeof(on)) == -1) {
DWARN("setsockopt %s (ignored)", "SO_OOBINLINE");
@@ -1384,13 +1389,11 @@ initconn(void)
if (data_addr.su_family != AF_INET) {
fputs(
"Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
if (code / 10 == 22 && code != 227) {
fputs("wrong server: return code must be 227\n",
ttyout);
- error = 1;
goto bad;
}
error = sscanf(pasv, "%u,%u,%u,%u,%u,%u",
@@ -1399,21 +1402,24 @@ initconn(void)
if (error != 6) {
fputs(
"Passive mode address scan failure. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
- error = 0;
memset(&data_addr, 0, sizeof(data_addr));
data_addr.su_family = AF_INET;
data_addr.su_len = sizeof(struct sockaddr_in);
data_addr.si_su.su_sin.sin_addr.s_addr =
htonl(pack4(addr, 0));
data_addr.su_port = htons(pack2(port, 0));
+ if (data_addr.si_su.su_sin.sin_addr.s_addr !=
+ hisctladdr.si_su.su_sin.sin_addr.s_addr) {
+ fputs("Passive mode address mismatch.\n",
+ ttyout);
+ goto bad;
+ }
} else if (strcmp(pasvcmd, "LPSV") == 0) {
if (code / 10 == 22 && code != 228) {
fputs("wrong server: return code must be 228\n",
ttyout);
- error = 1;
goto bad;
}
switch (data_addr.su_family) {
@@ -1426,23 +1432,26 @@ initconn(void)
if (error != 9) {
fputs(
"Passive mode address scan failure. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
if (af != 4 || hal != 4 || pal != 2) {
fputs(
"Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
- error = 0;
memset(&data_addr, 0, sizeof(data_addr));
data_addr.su_family = AF_INET;
data_addr.su_len = sizeof(struct sockaddr_in);
data_addr.si_su.su_sin.sin_addr.s_addr =
htonl(pack4(addr, 0));
data_addr.su_port = htons(pack2(port, 0));
+ if (data_addr.si_su.su_sin.sin_addr.s_addr !=
+ hisctladdr.si_su.su_sin.sin_addr.s_addr) {
+ fputs("Passive mode address mismatch.\n",
+ ttyout);
+ goto bad;
+ }
break;
#ifdef INET6
case AF_INET6:
@@ -1458,17 +1467,14 @@ initconn(void)
if (error != 21) {
fputs(
"Passive mode address scan failure. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
if (af != 6 || hal != 16 || pal != 2) {
fputs(
"Passive mode AF mismatch. Shouldn't happen!\n", ttyout);
- error = 1;
goto bad;
}
- error = 0;
memset(&data_addr, 0, sizeof(data_addr));
data_addr.su_family = AF_INET6;
data_addr.su_len = sizeof(struct sockaddr_in6);
@@ -1480,10 +1486,19 @@ initconn(void)
}
}
data_addr.su_port = htons(pack2(port, 0));
+ if (memcmp(
+ &data_addr.si_su.su_sin6.sin6_addr,
+ &hisctladdr.si_su.su_sin6.sin6_addr,
+ sizeof(data_addr.si_su.su_sin6.sin6_addr))) {
+ fputs("Passive mode address mismatch.\n",
+ ttyout);
+ goto bad;
+ }
break;
#endif
default:
- error = 1;
+ fputs("Unknown passive mode AF.\n", ttyout);
+ goto bad;
}
} else if (strcmp(pasvcmd, "EPSV") == 0) {
char delim[4];
@@ -1492,20 +1507,17 @@ initconn(void)
if (code / 10 == 22 && code != 229) {
fputs("wrong server: return code must be 229\n",
ttyout);
- error = 1;
goto bad;
}
if (sscanf(pasv, "%c%c%c%d%c", &delim[0],
&delim[1], &delim[2], &port[1],
&delim[3]) != 5) {
fputs("parse error!\n", ttyout);
- error = 1;
goto bad;
}
if (delim[0] != delim[1] || delim[0] != delim[2]
|| delim[0] != delim[3]) {
fputs("parse error!\n", ttyout);
- error = 1;
goto bad;
}
data_addr = hisctladdr;
Index: othersrc/usr.bin/tnftp/src/ssl.c
diff -u othersrc/usr.bin/tnftp/src/ssl.c:1.5 othersrc/usr.bin/tnftp/src/ssl.c:1.6
--- othersrc/usr.bin/tnftp/src/ssl.c:1.5 Sun Apr 25 07:50:37 2021
+++ othersrc/usr.bin/tnftp/src/ssl.c Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-/* $NetBSD: ssl.c,v 1.5 2021/04/25 07:50:37 lukem Exp $ */
-/* from NetBSD: ssl.c,v 1.9 2021/01/06 04:43:14 lukem Exp */
+/* $NetBSD: ssl.c,v 1.6 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: ssl.c,v 1.10 2021/06/03 10:23:33 lukem Exp */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -39,13 +39,17 @@
#include <sys/cdefs.h>
#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 <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
#include <sys/param.h>
#include <sys/select.h>
@@ -53,13 +57,16 @@ __RCSID(" NetBSD: ssl.c,v 1.9 2021/01/06
#include <netinet/tcp.h>
#include <netinet/in.h>
-#endif /* tnftp */
+#ifdef WITH_SSL
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
+#endif
+
+#endif /* tnftp */
#include "ssl.h"
@@ -82,7 +89,9 @@ struct fetch_connect {
int issock;
int iserr;
int iseof;
+#ifdef WITH_SSL
SSL *ssl; /* SSL handle */
+#endif
};
/*
@@ -128,9 +137,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 */
@@ -282,7 +293,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);
@@ -294,6 +307,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)
{
@@ -312,6 +326,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)
@@ -440,9 +455,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:
@@ -571,6 +588,7 @@ fetch_getline(struct fetch_connect *conn
return len;
}
+#ifdef WITH_SSL
void *
fetch_start_ssl(int sock, const char *servername)
{
@@ -631,10 +649,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: othersrc/usr.bin/tnftp/src/ssl.h
diff -u othersrc/usr.bin/tnftp/src/ssl.h:1.4 othersrc/usr.bin/tnftp/src/ssl.h:1.5
--- othersrc/usr.bin/tnftp/src/ssl.h:1.4 Sat Jul 4 09:59:07 2020
+++ othersrc/usr.bin/tnftp/src/ssl.h Fri Aug 27 01:38:49 2021
@@ -1,8 +1,8 @@
-/* $NetBSD: ssl.h,v 1.4 2020/07/04 09:59:07 lukem Exp $ */
-/* from NetBSD: ssl.h,v 1.4 2019/04/04 00:36:09 christos Exp */
+/* $NetBSD: ssl.h,v 1.5 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: ssl.h,v 1.5 2021/06/03 10:23:33 lukem Exp */
/*-
- * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * Copyright (c) 2012-2021 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,7 +26,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifdef WITH_SSL
#define FETCH struct fetch_connect
struct fetch_connect;
@@ -44,21 +43,3 @@ char *fetch_getln(char *, int, struct fe
int fetch_getline(struct fetch_connect *, char *, size_t, const char **);
void fetch_set_ssl(struct fetch_connect *, void *);
void *fetch_start_ssl(int, const char *);
-
-#else /* !WITH_SSL */
-
-#define FETCH FILE
-
-#define fetch_printf fprintf
-#define fetch_fileno fileno
-#define fetch_error ferror
-#define fetch_flush fflush
-#define fetch_open fopen
-#define fetch_fdopen fdopen
-#define fetch_close fclose
-#define fetch_read fread
-#define fetch_getln fgets
-#define fetch_getline get_line
-#define fetch_set_ssl(a, b)
-
-#endif /* !WITH_SSL */
Index: othersrc/usr.bin/tnftp/src/util.c
diff -u othersrc/usr.bin/tnftp/src/util.c:1.24 othersrc/usr.bin/tnftp/src/util.c:1.25
--- othersrc/usr.bin/tnftp/src/util.c:1.24 Sat Jul 4 09:59:07 2020
+++ othersrc/usr.bin/tnftp/src/util.c Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-/* $NetBSD: util.c,v 1.24 2020/07/04 09:59:07 lukem Exp $ */
-/* from NetBSD: util.c,v 1.161 2020/06/08 01:33:27 lukem Exp */
+/* $NetBSD: util.c,v 1.25 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: util.c,v 1.162 2021/04/25 08:26:35 lukem Exp */
/*-
* Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
#include <sys/cdefs.h>
#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 */
/*
@@ -738,7 +738,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,
Index: othersrc/usr.bin/tnftp/src/version.h
diff -u othersrc/usr.bin/tnftp/src/version.h:1.9 othersrc/usr.bin/tnftp/src/version.h:1.10
--- othersrc/usr.bin/tnftp/src/version.h:1.9 Sun Apr 25 07:50:37 2021
+++ othersrc/usr.bin/tnftp/src/version.h Fri Aug 27 01:38:49 2021
@@ -1,5 +1,5 @@
-/* $NetBSD: version.h,v 1.9 2021/04/25 07:50:37 lukem Exp $ */
-/* from NetBSD: version.h,v 1.92 2021/01/06 04:43:14 lukem Exp */
+/* $NetBSD: version.h,v 1.10 2021/08/27 01:38:49 lukem Exp $ */
+/* from NetBSD: version.h,v 1.94 2021/08/26 06:25:59 lukem Exp */
/*-
* Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
@@ -35,5 +35,5 @@
#endif
#ifndef FTP_VERSION
-#define FTP_VERSION "20210106"
+#define FTP_VERSION "20210826"
#endif