From: Peter Avalos Date: Wed, 11 Jul 2012 06:45:26 +0000 (-0700) Subject: ftp: Sync with NetBSD: X-Git-Tag: v3.2.0~617^2 X-Git-Url: https://gitweb.dragonflybsd.org/~nant/dragonfly.git/commitdiff_plain/d2b51479fe143801afdecbb950c85847806cba27 ftp: Sync with NetBSD: make -R work the same in ftp:// like it does for http:// (i.e. work if there is no local file). Don't display expected EHOSTUNREACH for all but the last connect attempts in terse mode. When given an URL that contains "://" but is not recognised, print an error message. Remove unnecessary Bk/Ek pairs from SYNOPSIS. --- diff --git a/contrib/tnftp/cmds.c b/contrib/tnftp/cmds.c index 467d7e6a19..633ab0060f 100644 --- a/contrib/tnftp/cmds.c +++ b/contrib/tnftp/cmds.c @@ -1,4 +1,4 @@ -/* $NetBSD: cmds.c,v 1.132 2011/09/16 15:39:26 joerg Exp $ */ +/* $NetBSD: cmds.c,v 1.134 2012/01/15 20:43:24 christos Exp $ */ /*- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -__RCSID("$NetBSD: cmds.c,v 1.132 2011/09/16 15:39:26 joerg Exp $"); +__RCSID("$NetBSD: cmds.c,v 1.134 2012/01/15 20:43:24 christos Exp $"); #endif #endif /* not lint */ @@ -111,6 +111,7 @@ __RCSID("$NetBSD: cmds.c,v 1.132 2011/09/16 15:39:26 joerg Exp $"); #include #include +#include #include #include #include @@ -556,14 +557,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"); } /* @@ -612,10 +613,14 @@ getit(int argc, char *argv[], int restartit, const char *gmode) 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; diff --git a/contrib/tnftp/extern.h b/contrib/tnftp/extern.h index bb71466133..e856ef4538 100644 --- a/contrib/tnftp/extern.h +++ b/contrib/tnftp/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.79 2011/09/16 15:39:26 joerg Exp $ */ +/* $NetBSD: extern.h,v 1.80 2012/07/04 06:09:37 is Exp $ */ /*- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc. @@ -239,7 +239,7 @@ void unsetoption(int, char **); void updatelocalcwd(void); void updateremotecwd(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); diff --git a/contrib/tnftp/fetch.c b/contrib/tnftp/fetch.c index 9fead8c6bc..30087f894d 100644 --- a/contrib/tnftp/fetch.c +++ b/contrib/tnftp/fetch.c @@ -1,4 +1,4 @@ -/* $NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $ */ +/* $NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $ */ /*- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $"); +__RCSID("$NetBSD: fetch.c,v 1.198 2012/07/04 06:09:37 is Exp $"); #endif /* not lint */ /* @@ -700,7 +700,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth) 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; @@ -734,7 +734,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth) 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; @@ -1687,6 +1688,7 @@ static int go_fetch(const char *url) { char *proxyenv; + char *p; #ifndef NO_ABOUT /* @@ -1730,6 +1732,18 @@ go_fetch(const char *url) if (STRNEQUAL(url, HTTP_URL) || 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() diff --git a/contrib/tnftp/ftp.1 b/contrib/tnftp/ftp.1 index 8c8290365a..ac6babe7d2 100644 --- a/contrib/tnftp/ftp.1 +++ b/contrib/tnftp/ftp.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: ftp.1,v 1.131 2010/03/05 07:41:10 lukem Exp $ +.\" $NetBSD: ftp.1,v 1.133 2012/04/08 22:00:38 wiz Exp $ .\" .\" Copyright (c) 1996-2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -66,21 +66,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]] @@ -1901,7 +1891,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. diff --git a/contrib/tnftp/ftp.c b/contrib/tnftp/ftp.c index f9f5769a00..d1a87859b5 100644 --- a/contrib/tnftp/ftp.c +++ b/contrib/tnftp/ftp.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $ */ +/* $NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp $ */ /*- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc. @@ -92,7 +92,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -__RCSID("$NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $"); +__RCSID("$NetBSD: ftp.c,v 1.164 2012/07/04 06:09:37 is Exp $"); #endif #endif /* not lint */ @@ -208,7 +208,8 @@ hookup(const char *host, const char *port) 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; @@ -1468,7 +1469,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; diff --git a/contrib/tnftp/progressbar.c b/contrib/tnftp/progressbar.c index d7edd2715d..2350776d6b 100644 --- a/contrib/tnftp/progressbar.c +++ b/contrib/tnftp/progressbar.c @@ -1,4 +1,4 @@ -/* $NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp $ */ +/* $NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp $ */ /*- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. @@ -31,14 +31,15 @@ #include #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 #include +#include +#include #include #include diff --git a/contrib/tnftp/util.c b/contrib/tnftp/util.c index 3a59d790de..b0e990dcff 100644 --- a/contrib/tnftp/util.c +++ b/contrib/tnftp/util.c @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $ */ +/* $NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $ */ /*- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include #ifndef lint -__RCSID("$NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $"); +__RCSID("$NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $"); #endif /* not lint */ /* @@ -1351,7 +1351,7 @@ get_line(FILE *stream, char *buf, size_t buflen, const char **errormsg) * 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; @@ -1417,8 +1417,9 @@ ftp_connect(int sock, const struct sockaddr *name, socklen_t namelen) 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; }