Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp use fetch_*() for I/O with SMALLPROG / !WITH_SSL...



details:   https://anonhg.NetBSD.org/src/rev/bb5b27247d37
branches:  trunk
changeset: 379502:bb5b27247d37
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Jun 03 10:23:33 2021 +0000

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

diffstat:

 usr.bin/ftp/Makefile  |   4 ++--
 usr.bin/ftp/ssl.c     |  29 +++++++++++++++++++++++++----
 usr.bin/ftp/ssl.h     |  23 ++---------------------
 usr.bin/ftp/version.h |   4 ++--
 4 files changed, 31 insertions(+), 29 deletions(-)

diffs (211 lines):

diff -r 1610f887417c -r bb5b27247d37 usr.bin/ftp/Makefile
--- a/usr.bin/ftp/Makefile      Thu Jun 03 10:11:00 2021 +0000
+++ b/usr.bin/ftp/Makefile      Thu Jun 03 10:23:33 2021 +0000
@@ -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 <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
diff -r 1610f887417c -r bb5b27247d37 usr.bin/ftp/ssl.c
--- a/usr.bin/ftp/ssl.c Thu Jun 03 10:11:00 2021 +0000
+++ b/usr.bin/ftp/ssl.c Thu Jun 03 10:23:33 2021 +0000
@@ -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 <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>
@@ -48,11 +52,14 @@
 
 #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
 }
diff -r 1610f887417c -r bb5b27247d37 usr.bin/ftp/ssl.h
--- a/usr.bin/ftp/ssl.h Thu Jun 03 10:11:00 2021 +0000
+++ b/usr.bin/ftp/ssl.h Thu Jun 03 10:23:33 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: ssl.h,v 1.4 2019/04/04 00:36:09 christos Exp $ */
+/*     $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
@@ -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 */
diff -r 1610f887417c -r bb5b27247d37 usr.bin/ftp/version.h
--- a/usr.bin/ftp/version.h     Thu Jun 03 10:11:00 2021 +0000
+++ b/usr.bin/ftp/version.h     Thu Jun 03 10:23:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.92 2021/01/06 04:43:14 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.93 2021/06/03 10:23:33 lukem Exp $       */
 
 /*-
  * Copyright (c) 1999-2021 The NetBSD Foundation, Inc.
@@ -34,5 +34,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define        FTP_VERSION     "20210106"
+#define        FTP_VERSION     "20210603"
 #endif



Home | Main Index | Thread Index | Old Index