summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2009-07-27 23:11:27 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2009-07-27 23:11:27 +0000
commita9eb95f32f6bf514b694cbd6b0d93f3dbf140536 (patch)
treedcab23dd81ddf025bbb740b16bac1997d5d4f568 /usr.bin
parent4955b06c86fcc9367821b5a88394eb4694a03727 (diff)
- make urls such as http://foo, http://foo/, or http://foo/bar/
fetchable, if -o outfile is passed. outfile will be used as a local filename - fix a bug where 'no file after host' code path never got entered; consider no file after dir invalid; as code intended proxy help&ok halex@; testing(including proxies,pkg_add)&ok sthen@; looks good to millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ftp/fetch.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index d43a8f00b50..3370a81c897 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.92 2009/07/18 12:43:30 jsg Exp $ */
+/* $OpenBSD: fetch.c,v 1.93 2009/07/27 23:11:26 martynas Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -153,15 +153,19 @@ url_get(const char *origline, const char *proxyenv, const char *outfile)
if (isfileurl) {
path = host;
} else {
- path = strchr(host, '/'); /* find path */
+ path = strchr(host, '/'); /* Find path */
if (EMPTYSTRING(path)) {
+ if (outfile) { /* No slash, but */
+ path=strchr(host,'\0'); /* we have outfile. */
+ goto noslash;
+ }
if (isftpurl)
goto noftpautologin;
warnx("Invalid URL (no `/' after host): %s", origline);
goto cleanup_url_get;
}
*path++ = '\0';
- if (EMPTYSTRING(path)) {
+ if (EMPTYSTRING(path) && !outfile) {
if (isftpurl)
goto noftpautologin;
warnx("Invalid URL (no file after host): %s", origline);
@@ -169,17 +173,15 @@ url_get(const char *origline, const char *proxyenv, const char *outfile)
}
}
+noslash:
if (outfile)
savefile = outfile;
- else
- savefile = basename(path);
-
-#ifndef SMALL
- if (resume && (strcmp(savefile, "-") == 0)) {
- warnx("can't append to stdout");
- goto cleanup_url_get;
+ else {
+ if (path[strlen(path) - 1] == '/') /* Consider no file */
+ savefile = NULL; /* after dir invalid. */
+ else
+ savefile = basename(path);
}
-#endif /* !SMALL */
if (EMPTYSTRING(savefile)) {
if (isftpurl)
@@ -188,6 +190,13 @@ url_get(const char *origline, const char *proxyenv, const char *outfile)
goto cleanup_url_get;
}
+#ifndef SMALL
+ if (resume && (strcmp(savefile, "-") == 0)) {
+ warnx("can't append to stdout");
+ goto cleanup_url_get;
+ }
+#endif /* !SMALL */
+
if (!isfileurl && proxyenv != NULL) { /* use proxy */
#ifndef SMALL
if (ishttpsurl) {
@@ -212,7 +221,8 @@ url_get(const char *origline, const char *proxyenv, const char *outfile)
warnx("Malformed proxy URL: %s", proxyenv);
goto cleanup_url_get;
}
- *--path = '/'; /* add / back to real path */
+ if (*--path == '\0')
+ *path = '/'; /* add / back to real path */
path = strchr(host, '/'); /* remove trailing / on host */
if (!EMPTYSTRING(path))
*path++ = '\0'; /* i guess this ++ is useless */