Module Name:    othersrc
Committed By:   lukem
Date:           Sun May  5 11:17:31 UTC 2013

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

Log Message:
Merge NetBSD-20130220


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 othersrc/usr.bin/tnftp/src/cmds.c \
    othersrc/usr.bin/tnftp/src/main.c
cvs rdiff -u -r1.11 -r1.12 othersrc/usr.bin/tnftp/src/cmdtab.c
cvs rdiff -u -r1.12 -r1.13 othersrc/usr.bin/tnftp/src/extern.h
cvs rdiff -u -r1.18 -r1.19 othersrc/usr.bin/tnftp/src/fetch.c \
    othersrc/usr.bin/tnftp/src/ftp.c
cvs rdiff -u -r1.13 -r1.14 othersrc/usr.bin/tnftp/src/ftp.1
cvs rdiff -u -r1.10 -r1.11 othersrc/usr.bin/tnftp/src/ftp_var.h
cvs rdiff -u -r1.14 -r1.15 othersrc/usr.bin/tnftp/src/progressbar.c
cvs rdiff -u -r1.21 -r1.22 othersrc/usr.bin/tnftp/src/util.c
cvs rdiff -u -r1.4 -r1.5 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/cmds.c
diff -u othersrc/usr.bin/tnftp/src/cmds.c:1.17 othersrc/usr.bin/tnftp/src/cmds.c:1.18
--- othersrc/usr.bin/tnftp/src/cmds.c:1.17	Tue Jan 12 06:55:47 2010
+++ othersrc/usr.bin/tnftp/src/cmds.c	Sun May  5 11:17:30 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: cmds.c,v 1.17 2010/01/12 06:55:47 lukem Exp $	*/
-/*	from	NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp	*/
+/*	$NetBSD: cmds.c,v 1.18 2013/05/05 11:17:30 lukem Exp $	*/
+/*	from	NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -101,7 +101,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.135 2012/12/22 16:57:09 christos Exp  ");
 #endif
 #endif /* not lint */
 
@@ -116,6 +116,7 @@ __RCSID(" NetBSD: cmds.c,v 1.130 2009/07
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <glob.h>
 #include <limits.h>
 #include <netdb.h>
@@ -149,7 +150,7 @@ static struct types {
 static sigjmp_buf	 jabort;
 
 static int	confirm(const char *, const char *);
-static void	mintr(int);
+__dead static void	mintr(int);
 static void	mabort(const char *);
 static void	set_type(const char *);
 
@@ -563,14 +564,14 @@ void
 reget(int argc, char *argv[])
 {
 
-	(void)getit(argc, argv, 1, "r+");
+	(void)getit(argc, argv, 1, restart_point ? "r+" : "a");
 }
 
 void
 get(int argc, char *argv[])
 {
 
-	(void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
+	(void)getit(argc, argv, 0, restart_point ? "r+" : "w");
 }
 
 /*
@@ -619,10 +620,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;
@@ -2677,7 +2682,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: othersrc/usr.bin/tnftp/src/main.c
diff -u othersrc/usr.bin/tnftp/src/main.c:1.17 othersrc/usr.bin/tnftp/src/main.c:1.18
--- othersrc/usr.bin/tnftp/src/main.c:1.17	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/main.c	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: main.c,v 1.17 2009/11/15 10:12:37 lukem Exp $	*/
-/*	from	NetBSD: main.c,v 1.117 2009/07/13 19:05:41 roy Exp	*/
+/*	$NetBSD: main.c,v 1.18 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: main.c,v 1.122 2012/12/22 16:57:10 christos Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -103,7 +103,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.117 2009/07/13 19:05:41 roy Exp  ");
+__RCSID(" NetBSD: main.c,v 1.122 2012/12/22 16:57:10 christos Exp  ");
 #endif
 #endif /* not lint */
 
@@ -133,11 +133,12 @@ __RCSID(" NetBSD: main.c,v 1.117 2009/07
 
 #define	FTP_PROXY	"ftp_proxy"	/* env var with FTP proxy location */
 #define	HTTP_PROXY	"http_proxy"	/* env var with HTTP proxy location */
+#define	HTTPS_PROXY	"https_proxy"	/* env var with HTTPS proxy location */
 #define	NO_PROXY	"no_proxy"	/* env var with list of non-proxied
 					 * hosts, comma or space separated */
 
+__dead static void	usage(void);
 static void	setupoption(const char *, const char *, const char *);
-int		main(int, char *[]);
 
 int
 main(int volatile argc, char **volatile argv)
@@ -146,9 +147,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();
 #if 0	/* tnftp */	/* XXX */
@@ -160,6 +160,9 @@ main(int volatile argc, char **volatile 
 
 	ftpport = "ftp";
 	httpport = "http";
+#ifdef WITH_SSL
+	httpsport = "https";
+#endif
 	gateport = NULL;
 	cp = getenv("FTPSERVERPORT");
 	if (cp != NULL)
@@ -213,35 +216,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");
-	(void)close(s);
-					/* sanity check returned buffer sizes */
-	if (rcvbuf_size <= 0)
-		rcvbuf_size = 8 * 1024;
-	if (sndbuf_size <= 0)
-		sndbuf_size = 8 * 1024;
-
-	if (sndbuf_size > 8 * 1024 * 1024)
-		sndbuf_size = 8 * 1024 * 1024;
-	if (rcvbuf_size > 8 * 1024 * 1024)
-		rcvbuf_size = 8 * 1024 * 1024;
-
 	marg_sl = ftp_sl_init();
 	if ((tmpdir = getenv("TMPDIR")) == NULL)
 		tmpdir = _PATH_TMP;
@@ -524,6 +498,7 @@ main(int volatile argc, char **volatile 
 	setupoption("anonpass",		getenv("FTPANONPASS"),	anonpass);
 	setupoption("ftp_proxy",	getenv(FTP_PROXY),	"");
 	setupoption("http_proxy",	getenv(HTTP_PROXY),	"");
+	setupoption("https_proxy",	getenv(HTTPS_PROXY),	"");
 	setupoption("no_proxy",		getenv(NO_PROXY),	"");
 	setupoption("pager",		getenv("PAGER"),	DEFAULTPAGER);
 	setupoption("prompt",		getenv("FTPPROMPT"),	DEFAULTPROMPT);
@@ -746,7 +721,7 @@ cmdscanner(void)
 			 */
 			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;
@@ -1083,6 +1058,9 @@ usage(void)
 "           [[user@]host [port]] [host:path[/]] [file:///file]\n"
 "           [ftp://[user[:pass]@]host[:port]/path[/]]\n";
 "           [http://[user[:pass]@]host[:port]/path] [...]\n"
+#ifdef WITH_SSL
+"           [https://[user[:pass]@]host[:port]/path] [...]\n"
+#endif
 "       %s -u URL file [...]\n", progname, progname);
 	exit(1);
 }

Index: othersrc/usr.bin/tnftp/src/cmdtab.c
diff -u othersrc/usr.bin/tnftp/src/cmdtab.c:1.11 othersrc/usr.bin/tnftp/src/cmdtab.c:1.12
--- othersrc/usr.bin/tnftp/src/cmdtab.c:1.11	Wed May 20 12:53:47 2009
+++ othersrc/usr.bin/tnftp/src/cmdtab.c	Sun May  5 11:17:30 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: cmdtab.c,v 1.11 2009/05/20 12:53:47 lukem Exp $	*/
-/*	from	NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp	*/
+/*	$NetBSD: cmdtab.c,v 1.12 2013/05/05 11:17:30 lukem Exp $	*/
+/*	from	NetBSD: cmdtab.c,v 1.52 2012/12/22 16:57:09 christos Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,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 */
 
@@ -306,6 +306,7 @@ struct option optiontab[] = {
 	{ "anonpass",	NULL },
 	{ "ftp_proxy",	NULL },
 	{ "http_proxy",	NULL },
+	{ "https_proxy",NULL },
 	{ "no_proxy",	NULL },
 	{ "pager",	NULL },
 	{ "prompt",	NULL },

Index: othersrc/usr.bin/tnftp/src/extern.h
diff -u othersrc/usr.bin/tnftp/src/extern.h:1.12 othersrc/usr.bin/tnftp/src/extern.h:1.13
--- othersrc/usr.bin/tnftp/src/extern.h:1.12	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/extern.h	Sun May  5 11:17:30 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: extern.h,v 1.12 2009/11/15 10:12:37 lukem Exp $	*/
-/*	from	NetBSD: extern.h,v 1.77 2009/07/13 19:05:41 roy Exp	*/
+/*	$NetBSD: extern.h,v 1.13 2013/05/05 11:17:30 lukem Exp $	*/
+/*	from	NetBSD: extern.h,v 1.80 2012/07/04 06:09:37 is Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -95,9 +95,6 @@ struct tm;
 struct addrinfo;
 
 void	abort_remote(FILE *);
-void	abort_squared(int);
-void	abortpt(int);
-void	abortxfer(int);
 void	account(int, char **);
 void	ai_unmapped(struct addrinfo *);
 int	another(int *, char ***, const char *);
@@ -146,7 +143,7 @@ void	help(int, char **);
 char   *hookup(const char *, const char *);
 void	idlecmd(int, char **);
 int	initconn(void);
-void	intr(int);
+__dead void	intr(int);
 int	isipv6addr(const char *);
 void	list_vertical(StringList *);
 void	lcd(int, char **);
@@ -167,9 +164,10 @@ const char *onoff(int);
 void	opts(int, char **);
 void	newer(int, char **);
 void	page(int, char **);
+const char *parse_rfc2616time(struct tm *, const char *);
 int	parserate(int, char **, int);
 char   *prompt(void);
-void	proxabort(int);
+__dead void	proxabort(int);
 void	proxtrans(const char *, const char *, const char *);
 void	psabort(int);
 void	pswitch(int);
@@ -241,9 +239,8 @@ int	togglevar(int, char **, int *, const
 void	unsetoption(int, char **);
 void	updatelocalcwd(void);
 void	updateremotecwd(void);
-void	usage(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: othersrc/usr.bin/tnftp/src/fetch.c
diff -u othersrc/usr.bin/tnftp/src/fetch.c:1.18 othersrc/usr.bin/tnftp/src/fetch.c:1.19
--- othersrc/usr.bin/tnftp/src/fetch.c:1.18	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/fetch.c	Sun May  5 11:17:30 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: fetch.c,v 1.18 2009/11/15 10:12:37 lukem Exp $	*/
-/*	from	NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp	*/
+/*	$NetBSD: fetch.c,v 1.19 2013/05/05 11:17:30 lukem Exp $	*/
+/*	from	NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID(" NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp  ");
+__RCSID(" NetBSD: fetch.c,v 1.202 2013/02/23 13:47:36 christos Exp  ");
 #endif /* not lint */
 
 /*
@@ -57,6 +57,7 @@ __RCSID(" NetBSD: fetch.c,v 1.191 2009/0
 #include <arpa/ftp.h>
 #include <arpa/inet.h>
 
+#include <assert.h>
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
@@ -70,18 +71,22 @@ __RCSID(" NetBSD: fetch.c,v 1.191 2009/0
 
 #endif	/* tnftp */
 
+#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
 } url_t;
 
-void		aborthttp(int);
+__dead static void	aborthttp(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 *);
@@ -106,7 +111,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).
@@ -288,7 +301,7 @@ url_decode(char *url)
 
 
 /*
- * Parse URL of form (per RFC3986):
+ * Parse URL of form (per RFC 3986):
  *	<type>://[<user>[:<password>]@]<host>[:<port>][/<path>]
  * Returns -1 if a parse error occurred, otherwise 0.
  * It's the caller's responsibility to url_decode() the returned
@@ -298,7 +311,7 @@ url_decode(char *url)
  * malloc(3)ed strings of the relevant section, and port to
  * the number given, or ftpport if ftp://, or httpport if http://.
  *
- * XXX: this is not totally RFC3986 compliant; <path> will have the
+ * XXX: this is not totally RFC 3986 compliant; <path> will have the
  * leading `/' unless it's an ftp:// URL, as this makes things easier
  * for file:// and http:// URLs.  ftp:// URLs have the `/' between the
  * host and the URL-path removed, but any additional leading slashes
@@ -352,6 +365,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:
@@ -401,7 +421,7 @@ parse_url(const char *url, const char *d
 #ifdef INET6
 			/*
 			 * Check if thost is an encoded IPv6 address, as per
-			 * RFC3986:
+			 * RFC 3986:
 			 *	`[' ipv6-address ']'
 			 */
 	if (*thost == '[') {
@@ -469,7 +489,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 /)
@@ -504,17 +524,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;
@@ -537,7 +561,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;
 		}
@@ -577,17 +601,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;
@@ -600,12 +624,19 @@ fetch_url(const char *url, const char *p
 				    (LLT)restart_point);
 			fputs("\n", ttyout);
 		}
+		if (0 == rcvbuf_size) {
+			rcvbuf_size = 8 * 1024; /* XXX */
+		}
 	} else {				/* ftp:// or http:// URLs */
 		const char *leading;
 		int hasleading;
 
 		if (proxyenv == NULL) {
-			if (urltype == HTTP_URL_T)
+#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)
 				proxyenv = getoptionvalue("ftp_proxy");
@@ -666,7 +697,7 @@ fetch_url(const char *url, const char *p
 				    &ppath) == -1)
 					goto cleanup_fetch_url;
 
-				if ((purltype != HTTP_URL_T
+				if ((!IS_HTTP_TYPE(purltype)
 				     && purltype != FTP_URL_T) ||
 				    EMPTYSTRING(phost) ||
 				    (! EMPTYSTRING(ppath)
@@ -696,6 +727,7 @@ fetch_url(const char *url, const char *p
 				FREEPTR(path);
 				path = ftp_strdup(url);
 				FREEPTR(ppath);
+				urltype = purltype;
 			}
 		} /* ! EMPTYSTRING(proxyenv) */
 
@@ -706,7 +738,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;
@@ -715,6 +747,9 @@ fetch_url(const char *url, const char *p
 			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];
 
@@ -740,12 +775,23 @@ 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;
 			}
 
+#ifdef WITH_SSL
+			if (urltype == HTTPS_URL_T) {
+				if ((ssl = fetch_start_ssl(s)) == NULL) {
+					close(s);
+					s = -1;
+					continue;
+				}
+			}
+#endif
+
 			/* success */
 			break;
 		}
@@ -755,7 +801,9 @@ fetch_url(const char *url, const char *p
 			goto cleanup_fetch_url;
 		}
 
-		fin = fdopen(s, "r+");
+		fin = fetch_fdopen(s, "r+");
+		fetch_set_ssl(fin, ssl);
+
 		/*
 		 * Construct and send the request.
 		 */
@@ -770,11 +818,11 @@ fetch_url(const char *url, const char *p
 				leading = ", ";
 				hasleading++;
 			}
-			fprintf(fin, "GET %s HTTP/1.0\r\n", path);
+			fetch_printf(fin, "GET %s HTTP/1.0\r\n", path);
 			if (flushcache)
-				fprintf(fin, "Pragma: no-cache\r\n");
+				fetch_printf(fin, "Pragma: no-cache\r\n");
 		} else {
-			fprintf(fin, "GET %s HTTP/1.1\r\n", path);
+			fetch_printf(fin, "GET %s HTTP/1.1\r\n", path);
 			if (strchr(host, ':')) {
 				char *h, *p;
 
@@ -787,18 +835,23 @@ fetch_url(const char *url, const char *p
 				    (p = strchr(h, '%')) != NULL) {
 					*p = '\0';
 				}
-				fprintf(fin, "Host: [%s]", h);
+				fetch_printf(fin, "Host: [%s]", h);
 				free(h);
 			} else
-				fprintf(fin, "Host: %s", host);
+				fetch_printf(fin, "Host: %s", host);
+#ifdef WITH_SSL
+			if ((urltype == HTTP_URL_T && portnum != HTTP_PORT) ||
+			    (urltype == HTTPS_URL_T && portnum != HTTPS_PORT))
+#else
 			if (portnum != HTTP_PORT)
-				fprintf(fin, ":%u", portnum);
-			fprintf(fin, "\r\n");
-			fprintf(fin, "Accept: */*\r\n");
-			fprintf(fin, "Connection: close\r\n");
+#endif
+				fetch_printf(fin, ":%u", portnum);
+			fetch_printf(fin, "\r\n");
+			fetch_printf(fin, "Accept: */*\r\n");
+			fetch_printf(fin, "Connection: close\r\n");
 			if (restart_point) {
 				fputs(leading, ttyout);
-				fprintf(fin, "Range: bytes=" LLF "-\r\n",
+				fetch_printf(fin, "Range: bytes=" LLF "-\r\n",
 				    (LLT)restart_point);
 				fprintf(ttyout, "restarting at " LLF,
 				    (LLT)restart_point);
@@ -806,12 +859,12 @@ fetch_url(const char *url, const char *p
 				hasleading++;
 			}
 			if (flushcache)
-				fprintf(fin, "Cache-Control: no-cache\r\n");
+				fetch_printf(fin, "Cache-Control: no-cache\r\n");
 		}
 		if ((useragent=getenv("FTPUSERAGENT")) != NULL) {
-			fprintf(fin, "User-Agent: %s\r\n", useragent);
+			fetch_printf(fin, "User-Agent: %s\r\n", useragent);
 		} else {
-			fprintf(fin, "User-Agent: %s/%s\r\n",
+			fetch_printf(fin, "User-Agent: %s/%s\r\n",
 			    FTP_PRODUCT, FTP_VERSION);
 		}
 		if (wwwauth) {
@@ -821,7 +874,7 @@ fetch_url(const char *url, const char *p
 				leading = ", ";
 				hasleading++;
 			}
-			fprintf(fin, "Authorization: %s\r\n", wwwauth);
+			fetch_printf(fin, "Authorization: %s\r\n", wwwauth);
 		}
 		if (proxyauth) {
 			if (verbose) {
@@ -830,18 +883,18 @@ fetch_url(const char *url, const char *p
 				leading = ", ";
 				hasleading++;
 			}
-			fprintf(fin, "Proxy-Authorization: %s\r\n", proxyauth);
+			fetch_printf(fin, "Proxy-Authorization: %s\r\n", proxyauth);
 		}
 		if (verbose && hasleading)
 			fputs(")\n", ttyout);
-		fprintf(fin, "\r\n");
-		if (fflush(fin) == EOF) {
+		fetch_printf(fin, "\r\n");
+		if (fetch_flush(fin) == EOF) {
 			warn("Writing HTTP request");
 			goto cleanup_fetch_url;
 		}
 
 				/* Read the response */
-		len = get_line(fin, buf, sizeof(buf), &errormsg);
+		len = fetch_getline(fin, buf, sizeof(buf), &errormsg);
 		if (len < 0) {
 			if (*errormsg == '\n')
 				errormsg++;
@@ -865,7 +918,7 @@ fetch_url(const char *url, const char *p
 
 				/* Read the rest of the header. */
 		while (1) {
-			len = get_line(fin, buf, sizeof(buf), &errormsg);
+			len = fetch_getline(fin, buf, sizeof(buf), &errormsg);
 			if (len < 0) {
 				if (*errormsg == '\n')
 					errormsg++;
@@ -941,28 +994,18 @@ fetch_url(const char *url, const char *p
 
 			} else if (match_token(&cp, "Last-Modified:")) {
 				struct tm parsed;
-				char *t;
+				const char *t;
 
 				memset(&parsed, 0, sizeof(parsed));
-							/* RFC1123 */
-				if ((t = strptime(cp,
-						"%a, %d %b %Y %H:%M:%S GMT",
-						&parsed))
-							/* RFC0850 */
-				    || (t = strptime(cp,
-						"%a, %d-%b-%y %H:%M:%S GMT",
-						&parsed))
-							/* asctime */
-				    || (t = strptime(cp,
-						"%a, %b %d %H:%M:%S %Y",
-						&parsed))) {
+				t = parse_rfc2616time(&parsed, cp);
+				if (t != NULL) {
 					parsed.tm_isdst = -1;
 					if (*t == '\0')
 						mtime = timegm(&parsed);
 #ifndef NO_DEBUG
 					if (ftp_debug && mtime != -1) {
 						fprintf(ttyout,
-						    "parsed date as: %s",
+						    "parsed time as: %s",
 						rfc2822time(localtime(&mtime)));
 					}
 #endif
@@ -1142,6 +1185,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);
@@ -1162,7 +1206,7 @@ fetch_url(const char *url, const char *p
 		lastchunk = 0;
 					/* read chunk-size */
 		if (ischunked) {
-			if (fgets(xferbuf, bufsize, fin) == NULL) {
+			if (fetch_getln(xferbuf, bufsize, fin) == NULL) {
 				warnx("Unexpected EOF reading chunk-size");
 				goto cleanup_fetch_url;
 			}
@@ -1215,7 +1259,7 @@ fetch_url(const char *url, const char *p
 			if (ischunked)
 				bufrem = MIN(chunksize, bufrem);
 			while (bufrem > 0) {
-				flen = fread(xferbuf, sizeof(char),
+				flen = fetch_read(xferbuf, sizeof(char),
 				    MIN((off_t)bufsize, bufrem), fin);
 				if (flen <= 0)
 					goto chunkdone;
@@ -1254,7 +1298,7 @@ fetch_url(const char *url, const char *p
 					/* read CRLF after chunk*/
  chunkdone:
 		if (ischunked) {
-			if (fgets(xferbuf, bufsize, fin) == NULL) {
+			if (fetch_getln(xferbuf, bufsize, fin) == NULL) {
 				warnx("Unexpected EOF reading chunk CRLF");
 				goto cleanup_fetch_url;
 			}
@@ -1274,7 +1318,7 @@ fetch_url(const char *url, const char *p
 			(void)putc('#', ttyout);
 		(void)putc('\n', ttyout);
 	}
-	if (ferror(fin)) {
+	if (fetch_error(fin)) {
 		warn("Reading file");
 		goto cleanup_fetch_url;
 	}
@@ -1311,7 +1355,7 @@ fetch_url(const char *url, const char *p
 	if (oldintp)
 		(void)xsignal(SIGPIPE, oldintp);
 	if (fin != NULL)
-		fclose(fin);
+		fetch_close(fin);
 	else if (s != -1)
 		close(s);
 	if (closefunc != NULL && fout != NULL)
@@ -1340,7 +1384,7 @@ fetch_url(const char *url, const char *p
 /*
  * Abort a HTTP retrieval
  */
-void
+static void
 aborthttp(int notused)
 {
 	char msgbuf[100];
@@ -1537,12 +1581,12 @@ fetch_ftp(const char *url)
 		 * directories in one step.
 		 *
 		 * If we are dealing with an `ftp://host/path' URL
-		 * (urltype is FTP_URL_T), then RFC3986 says we need to
+		 * (urltype is FTP_URL_T), then RFC 3986 says we need to
 		 * send a separate CWD command for each unescaped "/"
 		 * in the path, and we have to interpret %hex escaping
 		 * *after* we find the slashes.  It's possible to get
 		 * empty components here, (from multiple adjacent
-		 * slashes in the path) and RFC3986 says that we should
+		 * slashes in the path) and RFC 3986 says that we should
 		 * still do `CWD ' (with a null argument) in such cases.
 		 *
 		 * Many ftp servers don't support `CWD ', so if there's an
@@ -1614,8 +1658,8 @@ fetch_ftp(const char *url)
 						fprintf(stderr,
 "\n"
 "ftp: The `CWD ' command (without a directory), which is required by\n"
-"     RFC3986 to support the empty directory in the URL pathname (`//'),\n"
-"     conflicts with the server's conformance to RFC0959.\n"
+"     RFC 3986 to support the empty directory in the URL pathname (`//'),\n"
+"     conflicts with the server's conformance to RFC 959.\n"
 "     Try the same URL without the `//' in the URL pathname.\n"
 "\n");
 					goto cleanup_fetch_ftp;
@@ -1702,6 +1746,7 @@ static int
 go_fetch(const char *url)
 {
 	char *proxyenv;
+	char *p;
 
 #ifndef NO_ABOUT
 	/*
@@ -1742,10 +1787,26 @@ go_fetch(const char *url)
 	/*
 	 * Check for file:// and http:// URLs.
 	 */
-	if (STRNEQUAL(url, HTTP_URL) || STRNEQUAL(url, FILE_URL))
+	if (STRNEQUAL(url, HTTP_URL)
+#ifdef WITH_SSL
+	    || STRNEQUAL(url, HTTPS_URL)
+#endif
+	    || STRNEQUAL(url, FILE_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'", (int)(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().
Index: othersrc/usr.bin/tnftp/src/ftp.c
diff -u othersrc/usr.bin/tnftp/src/ftp.c:1.18 othersrc/usr.bin/tnftp/src/ftp.c:1.19
--- othersrc/usr.bin/tnftp/src/ftp.c:1.18	Wed May 20 12:53:47 2009
+++ othersrc/usr.bin/tnftp/src/ftp.c	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: ftp.c,v 1.18 2009/05/20 12:53:47 lukem Exp $	*/
-/*	from	NetBSD: ftp.c,v 1.159 2009/04/15 03:42:33 jld Exp	*/
+/*	$NetBSD: ftp.c,v 1.19 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 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.159 2009/04/15 03:42:33 jld Exp  ");
+__RCSID(" NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp  ");
 #endif
 #endif /* not lint */
 
@@ -114,6 +114,7 @@ __RCSID(" NetBSD: ftp.c,v 1.159 2009/04/
 #include <arpa/ftp.h>
 #include <arpa/telnet.h>
 
+#include <assert.h>
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
@@ -139,6 +140,7 @@ int	ptflag = 0;
 char	pasv[BUFSIZ];	/* passive port for proxy data connection */
 
 static int empty(FILE *, FILE *, int);
+__dead static void abort_squared(int);
 
 struct sockinet {
 	union sockunion {
@@ -214,7 +216,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;
@@ -545,7 +548,7 @@ empty(FILE *ecin, FILE *din, int sec)
 
 sigjmp_buf	xferabort;
 
-void
+__dead static void
 abortxfer(int notused)
 {
 	char msgbuf[100];
@@ -772,6 +775,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);
@@ -813,7 +817,7 @@ sendrequest(const char *cmd, const char 
 			}
 			(void)putc(c, dout);
 			bytes++;
-#if 0	/* this violates RFC0959 */
+#if 0	/* this violates RFC 959 */
 			if (c == '\r') {
 				(void)putc('\0', dout);
 				bytes++;
@@ -1033,6 +1037,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);
@@ -1160,7 +1165,7 @@ recvrequest(const char *cmd, const char 
 
  abort:
 			/*
-			 * abort using RFC0959 recommended IP,SYNC sequence
+			 * abort using RFC 959 recommended IP,SYNC sequence
 			 */
 	if (! sigsetjmp(xferabort, 1)) {
 			/* this is the first call */
@@ -1472,7 +1477,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;
@@ -1599,18 +1604,25 @@ initconn(void)
 				 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 */
@@ -1820,7 +1832,7 @@ pswitch(int flag)
 	}
 }
 
-void
+__dead static void
 abortpt(int notused)
 {
 
@@ -2032,7 +2044,7 @@ gunique(const char *local)
  *	too impatient to wait or there's another problem then ftp really
  *	needs to get back to a known state.
  */
-void
+static void
 abort_squared(int dummy)
 {
 	char msgbuf[100];

Index: othersrc/usr.bin/tnftp/src/ftp.1
diff -u othersrc/usr.bin/tnftp/src/ftp.1:1.13 othersrc/usr.bin/tnftp/src/ftp.1:1.14
--- othersrc/usr.bin/tnftp/src/ftp.1:1.13	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/ftp.1	Sun May  5 11:17:30 2013
@@ -1,7 +1,7 @@
-.\" 	$NetBSD: ftp.1,v 1.13 2009/11/15 10:12:37 lukem Exp $
-.\" 	from	NetBSD: ftp.1,v 1.130 2009/07/11 18:35:48 joerg Exp
+.\" 	$NetBSD: ftp.1,v 1.14 2013/05/05 11:17:30 lukem Exp $
+.\" 	from	NetBSD: ftp.1,v 1.134 2012/12/22 16:57:10 christos Exp
 .\"
-.\" Copyright (c) 1996-2008 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1996-2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This code is derived from software contributed to The NetBSD Foundation
@@ -58,7 +58,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd May 10, 2008
+.Dd December 22, 2012
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -67,21 +67,11 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 46AadefginpRtVv
-.Bk -words
 .Op Fl N Ar netrc
-.Ek
-.Bk -words
 .Op Fl o Ar output
-.Ek
-.Bk -words
 .Op Fl P Ar port
-.Ek
-.Bk -words
 .Op Fl q Ar quittime
-.Ek
-.Bk -words
 .Op Fl r Ar retry
-.Ek
 .Op Fl s Ar srcaddr
 .Bk -words
 .\" [-T dir,max[,inc]]
@@ -778,7 +768,7 @@ mode is
 .Dq stream .
 .It Ic modtime Ar remote-file
 Show the last modification time of the file on the remote machine, in
-.Li RFC2822
+.Li RFC 2822
 format.
 .It Ic more Ar file
 A synonym for
@@ -999,7 +989,7 @@ traffic.
 servers are required to support the
 .Dv PASV
 command by
-.Li RFC1123 ,
+.Li RFC 1123 ,
 some do not.)
 .It Ic pdir Op Ar remote-path
 Perform
@@ -1336,7 +1326,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
@@ -1346,6 +1336,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 $no_proxy .
@@ -1592,7 +1585,7 @@ ascii or binary (respectively).
 The default transfer type is binary.
 .Pp
 In order to be compliant with
-.Li RFC3986 ,
+.Li RFC 3986 ,
 .Nm
 interprets the
 .Ar path
@@ -1645,7 +1638,7 @@ Any
 .Sq Li \&% Ns Ar XX
 codes
 (per
-.Li RFC3986 )
+.Li RFC 3986 )
 within the path components are decoded, with
 .Ar XX
 representing a character code in hexadecimal.
@@ -1753,6 +1746,29 @@ and
 (and optionally
 .Sq password )
 is in the URL, use them for the first attempt to authenticate.
+.\" https://[user[:password]@]host[:port]/path
+.It Li https:// Ns Oo Ar user Ns Oo Li \&: Ns Ar password Oc Ns Li \&@ Oc \
+Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path
+An
+.Tn HTTPS
+URL, retrieved using the
+.Tn HTTPS
+protocol.
+If
+.Ic "set https_proxy"
+is defined, it is used as a URL to an
+.Tn HTTPS
+proxy server.
+If
+.Tn HTTPS
+authorization is required to retrieve
+.Ar path ,
+and
+.Sq user
+(and optionally
+.Sq password )
+is in the URL, use them for the first attempt to authenticate.
+There is currently no certificate validation and verification.
 .\" file:///path
 .It Li file:/// Ns Ar path
 A local URL, copied from
@@ -1902,7 +1918,7 @@ Failing the above checks, if
 .Dq globbing
 is enabled, local file names are expanded according to the rules
 used in the
-.Xr csh  1  ;
+.Xr csh 1 ;
 see the
 .Ic glob
 command.
@@ -2286,7 +2302,7 @@ URL characters are required in the usern
 or
 .Sq / ) ,
 encode them with
-.Li RFC3986
+.Li RFC 3986
 .Sq Li \&% Ns Ar XX
 encoding.
 .Pp
@@ -2331,23 +2347,23 @@ for an example of how to make this autom
 .Nm
 attempts to be compliant with:
 .Bl -tag -offset indent -width 8n
-.It Li RFC0959
+.It Li RFC 959
 .Em File Transfer Protocol
-.It Li RFC1123
+.It Li RFC 1123
 .Em Requirements for Internet Hosts - Application and Support
-.It Li RFC1635
+.It Li RFC 1635
 .Em How to Use Anonymous FTP
-.It Li RFC2389
+.It Li RFC 2389
 .Em Feature negotiation mechanism for the File Transfer Protocol
-.It Li RFC2428
+.It Li RFC 2428
 .Em FTP Extensions for IPv6 and NATs
-.It Li RFC2616
+.It Li RFC 2616
 .Em Hypertext Transfer Protocol -- HTTP/1.1
-.It Li RFC2822
+.It Li RFC 2822
 .Em Internet Message Format
-.It Li RFC3659
+.It Li RFC 3659
 .Em Extensions to FTP
-.It Li RFC3986
+.It Li RFC 3986
 .Em Uniform Resource Identifier (URI)
 .El
 .Sh HISTORY

Index: othersrc/usr.bin/tnftp/src/ftp_var.h
diff -u othersrc/usr.bin/tnftp/src/ftp_var.h:1.10 othersrc/usr.bin/tnftp/src/ftp_var.h:1.11
--- othersrc/usr.bin/tnftp/src/ftp_var.h:1.10	Wed May 20 12:53:47 2009
+++ othersrc/usr.bin/tnftp/src/ftp_var.h	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: ftp_var.h,v 1.10 2009/05/20 12:53:47 lukem Exp $	*/
-/*	from	NetBSD: ftp_var.h,v 1.81 2009/04/12 10:18:52 lukem Exp	*/
+/*	$NetBSD: ftp_var.h,v 1.11 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: ftp_var.h,v 1.82 2012/12/21 18:07:36 christos Exp	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -182,6 +182,7 @@ enum {
 
 #define	FTP_PORT	21	/* default if ! getservbyname("ftp/tcp") */
 #define	HTTP_PORT	80	/* default if ! getservbyname("http/tcp") */
+#define	HTTPS_PORT	443	/* default if ! getservbyname("https/tcp") */
 #ifndef	GATE_PORT
 #define	GATE_PORT	21	/* default if ! getservbyname("ftpgate/tcp") */
 #endif
@@ -278,6 +279,9 @@ GLOBAL	char   *username;	/* name of user
 GLOBAL	sa_family_t family;	/* address family to use for connections */
 GLOBAL	const char *ftpport;	/* port number to use for FTP connections */
 GLOBAL	const char *httpport;	/* port number to use for HTTP connections */
+#ifdef WITH_SSL
+GLOBAL	const char *httpsport;	/* port number to use for HTTPS connections */
+#endif
 GLOBAL	const char *gateport;	/* port number to use for gateftp connections */
 GLOBAL	struct addrinfo *bindai; /* local address to bind as */
 

Index: othersrc/usr.bin/tnftp/src/progressbar.c
diff -u othersrc/usr.bin/tnftp/src/progressbar.c:1.14 othersrc/usr.bin/tnftp/src/progressbar.c:1.15
--- othersrc/usr.bin/tnftp/src/progressbar.c:1.14	Wed May 20 12:53:47 2009
+++ othersrc/usr.bin/tnftp/src/progressbar.c	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: progressbar.c,v 1.14 2009/05/20 12:53:47 lukem Exp $	*/
-/*	from	NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp	*/
+/*	$NetBSD: progressbar.c,v 1.15 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -36,14 +36,15 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID(" NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp  ");
+__RCSID(" NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp  ");
 #endif /* not lint */
 
 /*
  * FTP User Program -- Misc support routines
  */
-#include <sys/types.h>
 #include <sys/param.h>
+#include <sys/types.h>
+#include <sys/time.h>
 
 #include <err.h>
 #include <errno.h>

Index: othersrc/usr.bin/tnftp/src/util.c
diff -u othersrc/usr.bin/tnftp/src/util.c:1.21 othersrc/usr.bin/tnftp/src/util.c:1.22
--- othersrc/usr.bin/tnftp/src/util.c:1.21	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/util.c	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: util.c,v 1.21 2009/11/15 10:12:37 lukem Exp $	*/
-/*	from	NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp	*/
+/*	$NetBSD: util.c,v 1.22 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp	*/
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID(" NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp  ");
+__RCSID(" NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp  ");
 #endif /* not lint */
 
 /*
@@ -90,6 +90,7 @@ __RCSID(" NetBSD: util.c,v 1.152 2009/07
 #include <signal.h>
 #include <libgen.h>
 #include <limits.h>
+#include <locale.h>
 #include <netdb.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -175,7 +176,7 @@ parse_feat(const char *fline)
 
 			/*
 			 * work-around broken ProFTPd servers that can't
-			 * even obey RFC2389.
+			 * even obey RFC 2389.
 			 */
 	while (*fline && isspace((int)*fline))
 		fline++;
@@ -208,25 +209,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
@@ -399,7 +395,7 @@ ftp_login(const char *host, const char *
 	 */
 	if (anonftp) {
 		FREEPTR(fuser);
-		fuser = ftp_strdup("anonymous");	/* as per RFC1635 */
+		fuser = ftp_strdup("anonymous");	/* as per RFC 1635 */
 		FREEPTR(pass);
 		pass = ftp_strdup(getoptionvalue("anonpass"));
 	}
@@ -763,7 +759,7 @@ remotemodtime(const char *file, int nois
 			else
 				goto cleanup_parse_time;
 		} else {
-			DPRINTF("remotemodtime: parsed date `%s' as " LLF
+			DPRINTF("remotemodtime: parsed time `%s' as " LLF
 			    ", %s",
 			    timestr, (LLT)rtime,
 			    rfc2822time(localtime(&rtime)));
@@ -784,7 +780,7 @@ remotemodtime(const char *file, int nois
 }
 
 /*
- * Format tm in an RFC2822 compatible manner, with a trailing \n.
+ * Format tm in an RFC 2822 compatible manner, with a trailing \n.
  * Returns a pointer to a static string containing the result.
  */
 const char *
@@ -794,11 +790,37 @@ rfc2822time(const struct tm *tm)
 
 	if (strftime(result, sizeof(result),
 	    "%a, %d %b %Y %H:%M:%S %z\n", tm) == 0)
-		errx(1, "Can't convert RFC2822 time: buffer too small");
+		errx(1, "Can't convert RFC 2822 time: buffer too small");
 	return result;
 }
 
 /*
+ * Parse HTTP-date as per RFC 2616.
+ * Return a pointer to the next character of the consumed date string,
+ * or NULL if failed.
+ */
+const char *
+parse_rfc2616time(struct tm *parsed, const char *httpdate)
+{
+	const char *t;
+	const char *curlocale;
+
+	/* The representation of %a depends on the current locale. */
+	curlocale = setlocale(LC_TIME, NULL);
+	(void)setlocale(LC_TIME, "C");
+								/* RFC 1123 */
+	if ((t = strptime(httpdate, "%a, %d %b %Y %H:%M:%S GMT", parsed)) ||
+								/* RFC 850 */
+	    (t = strptime(httpdate, "%a, %d-%b-%y %H:%M:%S GMT", parsed)) ||
+								/* asctime */
+	    (t = strptime(httpdate, "%a, %b %d %H:%M:%S %Y", parsed))) {
+		;			/* do nothing */
+	}
+	(void)setlocale(LC_TIME, curlocale);
+	return t;
+}
+
+/*
  * Update global `localcwd', which contains the state of the local cwd
  */
 void
@@ -1060,6 +1082,32 @@ strsuftoi(const char *arg)
 void
 setupsockbufsize(int sock)
 {
+	socklen_t slen;
+
+	if (0 == rcvbuf_size) {
+		slen = sizeof(rcvbuf_size);
+		if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+		    (void *)&rcvbuf_size, &slen) == -1)
+			err(1, "Unable to determine rcvbuf size");
+		if (rcvbuf_size <= 0)
+			rcvbuf_size = 8 * 1024;
+		if (rcvbuf_size > 8 * 1024 * 1024)
+			rcvbuf_size = 8 * 1024 * 1024;
+		DPRINTF("setupsockbufsize: rcvbuf_size determined as %d\n",
+		    rcvbuf_size);
+	}
+	if (0 == sndbuf_size) {
+		slen = sizeof(sndbuf_size);
+		if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+		    (void *)&sndbuf_size, &slen) == -1)
+			err(1, "Unable to determine sndbuf size");
+		if (sndbuf_size <= 0)
+			sndbuf_size = 8 * 1024;
+		if (sndbuf_size > 8 * 1024 * 1024)
+			sndbuf_size = 8 * 1024 * 1024;
+		DPRINTF("setupsockbufsize: sndbuf_size determined as %d\n",
+		    sndbuf_size);
+	}
 
 	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
 	    (void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)
@@ -1078,9 +1126,8 @@ ftpvis(char *dst, size_t dstlen, const c
 {
 	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 ' ':
@@ -1088,12 +1135,18 @@ ftpvis(char *dst, size_t dstlen, const c
 		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';
@@ -1300,7 +1353,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;
@@ -1366,8 +1419,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;
 		}
 

Index: othersrc/usr.bin/tnftp/src/version.h
diff -u othersrc/usr.bin/tnftp/src/version.h:1.4 othersrc/usr.bin/tnftp/src/version.h:1.5
--- othersrc/usr.bin/tnftp/src/version.h:1.4	Sun Nov 15 10:12:37 2009
+++ othersrc/usr.bin/tnftp/src/version.h	Sun May  5 11:17:31 2013
@@ -1,5 +1,5 @@
-/*	$NetBSD: version.h,v 1.4 2009/11/15 10:12:37 lukem Exp $	*/
-/*	from	NetBSD: version.h,v 1.80 2009/11/15 10:03:16 lukem Exp	*/
+/*	$NetBSD: version.h,v 1.5 2013/05/05 11:17:31 lukem Exp $	*/
+/*	from	NetBSD: version.h,v 1.84 2013/05/05 10:40:19 lukem Exp	*/
 
 /*-
  * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
@@ -35,5 +35,5 @@
 #endif
 
 #ifndef FTP_VERSION
-#define	FTP_VERSION	"20090915"
+#define	FTP_VERSION	"20130220"
 #endif

Reply via email to