Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/usr.bin/ftp Catch up to current, requested by christos in...
details: https://anonhg.NetBSD.org/src/rev/c870249d953c
branches: netbsd-8
changeset: 370021:c870249d953c
user: martin <martin%NetBSD.org@localhost>
date: Mon Sep 12 14:46:51 2022 +0000
description:
Catch up to current, requested by christos in ticket #1763:
usr.bin/ftp/Makefile up to 1.39
usr.bin/ftp/cmds.c up to 1.141
usr.bin/ftp/complete.c up to 1.47
usr.bin/ftp/domacro.c up to 1.23
usr.bin/ftp/extern.h up to 1.82
usr.bin/ftp/fetch.c up to 1.235
usr.bin/ftp/ftp.1 up to 1.147
usr.bin/ftp/ftp.c up to 1.174
usr.bin/ftp/ftp_var.h up to 1.86
usr.bin/ftp/main.c up to 1.128
usr.bin/ftp/progressbar.c up to 1.24
usr.bin/ftp/progressbar.h up to 1.9
usr.bin/ftp/ssl.c up to 1.11
usr.bin/ftp/ssl.h up to 1.5
usr.bin/ftp/util.c up to 1.164
usr.bin/ftp/version.h up to 1.94
ftp(1): validate address from PASV and LPSV response.
ftp(1): use raw write(2) instead of fwrite(3) to avoid stream
corruption because of the progress bar interrupts.
Fixes for PR 56219 and PR 55857.
PR 57003: Support relative redirects.
diffstat:
usr.bin/ftp/Makefile | 6 +-
usr.bin/ftp/cmds.c | 32 ++-
usr.bin/ftp/complete.c | 7 +-
usr.bin/ftp/domacro.c | 6 +-
usr.bin/ftp/extern.h | 10 +-
usr.bin/ftp/fetch.c | 258 ++++++++++++++++++++++----------
usr.bin/ftp/ftp.1 | 362 +++++++++++++++++++++++++++------------------
usr.bin/ftp/ftp.c | 127 ++++++++++-----
usr.bin/ftp/ftp_var.h | 5 +-
usr.bin/ftp/main.c | 122 +++++++++++---
usr.bin/ftp/progressbar.c | 74 +-------
usr.bin/ftp/progressbar.h | 5 +-
usr.bin/ftp/ssl.c | 217 +++++++++++++++++----------
usr.bin/ftp/ssl.h | 25 +--
usr.bin/ftp/util.c | 26 ++-
usr.bin/ftp/version.h | 6 +-
16 files changed, 786 insertions(+), 502 deletions(-)
diffs (truncated from 3227 to 300 lines):
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/Makefile
--- a/usr.bin/ftp/Makefile Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/Makefile Mon Sep 12 14:46:51 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.37 2017/05/21 15:28:43 riastradh Exp $
+# $NetBSD: Makefile,v 1.37.2.1 2022/09/12 14:46:51 martin Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
.include <bsd.own.mk>
@@ -8,6 +8,7 @@
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 @@
LDADD+= -ledit -lterminfo
DPADD+= ${LIBEDIT} ${LIBTERMINFO}
CPPFLAGS+= -DWITH_SSL
-SRCS+=ssl.c
LDADD+= -lssl -lcrypto
DPADD+= ${LIBSSL} ${LIBCRYPTO}
.endif
@@ -31,4 +31,6 @@
cmds.o fetch.o: version.h
main.o: ftp_var.h
+CWARNFLAGS.gcc+= ${GCC_NO_FORMAT_OVERFLOW}
+
.include <bsd.prog.mk>
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/cmds.c Mon Sep 12 14:46:51 2022 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: cmds.c,v 1.137 2016/02/27 16:31:31 christos Exp $ */
+/* $NetBSD: cmds.c,v 1.137.8.1 2022/09/12 14:46:51 martin 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.137 2016/02/27 16:31:31 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.137.8.1 2022/09/12 14:46:51 martin Exp $");
#endif
#endif /* not lint */
@@ -1131,7 +1131,7 @@
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;
}
@@ -1158,7 +1158,8 @@
}
if (r == COMPLETE) {
dirchange = 1;
- updateremotecwd();
+ remotecwd[0] = '\0';
+ remcwdvalid = 0;
}
}
@@ -1544,9 +1545,9 @@
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);
@@ -1775,6 +1776,18 @@
exit(0);
}
+void __dead
+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);
+}
+
/*
* Terminate session, but don't exit.
* May be called with 0, NULL.
@@ -2184,7 +2197,7 @@
}
break;
}
- /* intentional drop through */
+ /* FALLTHROUGH */
default:
*cp2++ = *cp1;
break;
@@ -2359,7 +2372,8 @@
}
if (r == COMPLETE) {
dirchange = 1;
- updateremotecwd();
+ remotecwd[0] = '\0';
+ remcwdvalid = 0;
}
}
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/complete.c
--- a/usr.bin/ftp/complete.c Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/complete.c Mon Sep 12 14:46:51 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp $ */
+/* $NetBSD: complete.c,v 1.46.38.1 2022/09/12 14:46:51 martin Exp $ */
/*-
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp $");
+__RCSID("$NetBSD: complete.c,v 1.46.38.1 2022/09/12 14:46:51 martin Exp $");
#endif /* not lint */
/*
@@ -99,11 +99,10 @@
}
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)
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/domacro.c
--- a/usr.bin/ftp/domacro.c Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/domacro.c Mon Sep 12 14:46:51 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: domacro.c,v 1.22 2009/04/12 10:18:52 lukem Exp $ */
+/* $NetBSD: domacro.c,v 1.22.38.1 2022/09/12 14:46:51 martin Exp $ */
/*
* Copyright (c) 1985, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: domacro.c,v 1.22 2009/04/12 10:18:52 lukem Exp $");
+__RCSID("$NetBSD: domacro.c,v 1.22.38.1 2022/09/12 14:46:51 martin Exp $");
#endif
#endif /* not lint */
@@ -102,7 +102,7 @@
}
break;
}
- /* intentional drop through */
+ /* FALLTHROUGH */
default:
*cp2++ = *cp1;
break;
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/extern.h
--- a/usr.bin/ftp/extern.h Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/extern.h Mon Sep 12 14:46:51 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.80 2012/07/04 06:09:37 is Exp $ */
+/* $NetBSD: extern.h,v 1.80.24.1 2022/09/12 14:46:51 martin Exp $ */
/*-
* Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -173,6 +173,7 @@
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 *,
@@ -242,7 +243,14 @@
int ftp_connect(int, const struct sockaddr *, socklen_t, int);
int ftp_listen(int, int);
int ftp_poll(struct pollfd *, int, int);
+#ifndef SMALL
void *ftp_malloc(size_t);
StringList *ftp_sl_init(void);
void ftp_sl_add(StringList *, char *);
char *ftp_strdup(const char *);
+#else
+#define ftp_malloc(a) malloc(a);
+#define ftp_sl_init() sl_init()
+#define ftp_sl_add(a, b) sl_add((a), (b))
+#define ftp_strdup(a) strdup(a)
+#endif
diff -r 44d293296e87 -r c870249d953c usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c Mon Sep 12 14:29:19 2022 +0000
+++ b/usr.bin/ftp/fetch.c Mon Sep 12 14:46:51 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $ */
+/* $NetBSD: fetch.c,v 1.228.4.1 2022/09/12 14:46:51 martin Exp $ */
/*-
* Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.228.4.1 2022/09/12 14:46:51 martin Exp $");
#endif /* not lint */
/*
@@ -106,12 +106,13 @@
static int auth_url(const char *, char **, const struct authinfo *);
static void base64_encode(const unsigned char *, size_t, unsigned char *);
#endif
-static int go_fetch(const char *);
+static int go_fetch(const char *, struct urlinfo *);
static int fetch_ftp(const char *);
-static int fetch_url(const char *, const char *, char *, char *);
+static int fetch_url(const char *, const char *, char *, char *,
+ struct urlinfo *);
static const char *match_token(const char **, const char *);
static int parse_url(const char *, const char *, struct urlinfo *,
- struct authinfo *);
+ struct authinfo *, struct urlinfo *);
static void url_decode(char *);
static void freeauthinfo(struct authinfo *);
static void freeurlinfo(struct urlinfo *);
@@ -138,6 +139,43 @@
((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
@@ -237,7 +275,7 @@
scheme = "Basic"; /* only support Basic authentication */
gotpass = NULL;
- DPRINTF("auth_url: challenge `%s'\n", challenge);
+ DPRINTF("%s: challenge `%s'\n", __func__, challenge);
if (! match_token(&cp, scheme)) {
Home |
Main Index |
Thread Index |
Old Index