Module Name: src
Committed By: martin
Date: Mon Jun 14 11:57:39 UTC 2021
Modified Files:
src/usr.bin/ftp [netbsd-9]: Makefile ssl.c ssl.h version.h
Log Message:
Pull up following revision(s) (requested by lukem in ticket #1295):
usr.bin/ftp/ssl.c: revision 1.10
usr.bin/ftp/ssl.h: revision 1.5
usr.bin/ftp/version.h: revision 1.93
usr.bin/ftp/Makefile: revision 1.39
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.37 -r1.37.12.1 src/usr.bin/ftp/Makefile
cvs rdiff -u -r1.8.2.1 -r1.8.2.2 src/usr.bin/ftp/ssl.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/usr.bin/ftp/ssl.h
cvs rdiff -u -r1.87.18.2 -r1.87.18.3 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.37 src/usr.bin/ftp/Makefile:1.37.12.1
--- src/usr.bin/ftp/Makefile:1.37 Sun May 21 15:28:43 2017
+++ src/usr.bin/ftp/Makefile Mon Jun 14 11:57:39 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.37 2017/05/21 15:28:43 riastradh Exp $
+# $NetBSD: Makefile,v 1.37.12.1 2021/06/14 11:57:39 martin Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
.include <bsd.own.mk>
@@ -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.8.2.1 src/usr.bin/ftp/ssl.c:1.8.2.2
--- src/usr.bin/ftp/ssl.c:1.8.2.1 Fri Jan 29 20:58:19 2021
+++ src/usr.bin/ftp/ssl.c Mon Jun 14 11:57:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssl.c,v 1.8.2.1 2021/01/29 20:58:19 martin Exp $ */
+/* $NetBSD: ssl.c,v 1.8.2.2 2021/06/14 11:57:39 martin Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -34,13 +34,17 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.8.2.1 2021/01/29 20:58:19 martin Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.8.2.2 2021/06/14 11:57:39 martin 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>
@@ -48,11 +52,14 @@ __RCSID("$NetBSD: ssl.c,v 1.8.2.1 2021/0
#include <netinet/tcp.h>
#include <netinet/in.h>
+
+#ifdef WITH_SSL
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
+#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.4.2.1
--- src/usr.bin/ftp/ssl.h:1.4 Thu Apr 4 00:36:09 2019
+++ src/usr.bin/ftp/ssl.h Mon Jun 14 11:57:39 2021
@@ -1,7 +1,7 @@
-/* $NetBSD: ssl.h,v 1.4 2019/04/04 00:36:09 christos Exp $ */
+/* $NetBSD: ssl.h,v 1.4.2.1 2021/06/14 11:57:39 martin 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
@@ -25,7 +25,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;
@@ -43,21 +42,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: src/usr.bin/ftp/version.h
diff -u src/usr.bin/ftp/version.h:1.87.18.2 src/usr.bin/ftp/version.h:1.87.18.3
--- src/usr.bin/ftp/version.h:1.87.18.2 Mon Jun 14 11:22:16 2021
+++ src/usr.bin/ftp/version.h Mon Jun 14 11:57:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.87.18.2 2021/06/14 11:22:16 martin Exp $ */
+/* $NetBSD: version.h,v 1.87.18.3 2021/06/14 11:57:39 martin Exp $ */
/*-
* Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
#endif
#ifndef FTP_VERSION
-#define FTP_VERSION "20200711"
+#define FTP_VERSION "20210603"
#endif