Module Name: src
Committed By: apb
Date: Fri Feb 24 19:40:49 UTC 2012
Modified Files:
src/usr.bin/ftp: fetch.c
Log Message:
When given an URL that contains "://" but is not recognised,
print an error message. Now "ftp https://foo/bar" prints
ftp: Unsupported URL scheme `https'
instead of
ftp: Can't lookup `https:ftp': No address associated with hostname
ftp: Can't connect or login to host `https:?'
To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 src/usr.bin/ftp/fetch.c
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/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.195 src/usr.bin/ftp/fetch.c:1.196
--- src/usr.bin/ftp/fetch.c:1.195 Sat Dec 10 05:53:58 2011
+++ src/usr.bin/ftp/fetch.c Fri Feb 24 19:40:49 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $ */
+/* $NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $ */
/*-
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.196 2012/02/24 19:40:49 apb Exp $");
#endif /* not lint */
/*
@@ -700,7 +700,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;
@@ -1687,6 +1687,7 @@ static int
go_fetch(const char *url)
{
char *proxyenv;
+ char *p;
#ifndef NO_ABOUT
/*
@@ -1731,6 +1732,18 @@ go_fetch(const char *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'", (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().