summaryrefslogtreecommitdiffstats
path: root/usr.bin/fetch
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1998-09-20 00:01:26 +0000
committerjkh <jkh@FreeBSD.org>1998-09-20 00:01:26 +0000
commit79ff6f224d335b39f52730937b59b8cbc8bf329b (patch)
tree07cad22cff9f186bfe8402dba70389115f72271f /usr.bin/fetch
parent0337d32241d1e13ea8c89f393dcbebbee887d4a6 (diff)
downloadFreeBSD-src-79ff6f224d335b39f52730937b59b8cbc8bf329b.zip
FreeBSD-src-79ff6f224d335b39f52730937b59b8cbc8bf329b.tar.gz
Add -S flag; this is benign since fetch's behavior is unchanged if you
don't use it. That's why I'm bringing it in during our "code slush" Submitted by: Stefan Esser <se@mi.uni-koeln.de>
Diffstat (limited to 'usr.bin/fetch')
-rw-r--r--usr.bin/fetch/fetch.117
-rw-r--r--usr.bin/fetch/fetch.h3
-rw-r--r--usr.bin/fetch/ftp.c9
-rw-r--r--usr.bin/fetch/http.c17
-rw-r--r--usr.bin/fetch/main.c17
5 files changed, 55 insertions, 8 deletions
diff --git a/usr.bin/fetch/fetch.1 b/usr.bin/fetch/fetch.1
index 83de879..20be53d 100644
--- a/usr.bin/fetch/fetch.1
+++ b/usr.bin/fetch/fetch.1
@@ -1,4 +1,4 @@
-.\" $Id: fetch.1,v 1.22 1998/05/09 20:50:35 wollman Exp $
+.\" $Id: fetch.1,v 1.23 1998/05/09 21:39:49 wollman Exp $
.Dd July 2, 1996
.Dt FETCH 1
.Os FreeBSD 2.2
@@ -8,11 +8,13 @@
.Sh SYNOPSIS
.Nm fetch
.Op Fl MPabmnpqr
+.Op Fl S Ar size
.Op Fl o Ar file
.Ar URL
.Op Ar ...
.Nm fetch
.Op Fl MPRmnpqr
+.Op Fl S Ar size
.Op Fl o Ar file
.Op Fl c Ar dir
.Fl f Ar file
@@ -99,6 +101,19 @@ The filenames specified are ``precious'', and should not be deleted
under any circumstances, even if the transfer failed or was incomplete.
.It Fl r
Restart a previously interrupted transfer.
+.It Fl S Ar bytes
+Require file size reported by
+.Tn FTP
+or
+.Tn HTTP
+server to match the value specified with this option.
+On mismatch, a message is printed and the file will not be fetched.
+If the server does not support reporting of file sizes, the option
+will be ignored and the file will be retrieved anyway.
+This option is useful to prevent
+.Nm fetch
+from downloading a file that is either incomplete or the wrong version,
+given the correct size of the file in advance.
.It Fl t
Work around a different set of buggy
.Tn TCP
diff --git a/usr.bin/fetch/fetch.h b/usr.bin/fetch/fetch.h
index dc265be..aac3fbc 100644
--- a/usr.bin/fetch/fetch.h
+++ b/usr.bin/fetch/fetch.h
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fetch.h,v 1.4 1997/07/25 19:35:42 wollman Exp $
+ * $Id: fetch.h,v 1.5 1997/08/05 20:18:38 ache Exp $
*/
#ifndef fetch_h
@@ -51,6 +51,7 @@ struct fetch_state {
int fs_auto_retry; /* -a option */
int fs_linux_bug; /* -b option */
int fs_use_connect; /* -t option */
+ off_t fs_expectedsize; /* -S option */
time_t fs_modtime;
void *fs_proto;
int (*fs_retrieve)(struct fetch_state *);
diff --git a/usr.bin/fetch/ftp.c b/usr.bin/fetch/ftp.c
index 362d1c9..6c6c71c 100644
--- a/usr.bin/fetch/ftp.c
+++ b/usr.bin/fetch/ftp.c
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ftp.c,v 1.8 1997/10/06 01:09:56 fenner Exp $
+ * $Id: ftp.c,v 1.9 1997/10/08 18:43:53 fenner Exp $
*/
#include <sys/types.h>
@@ -375,6 +375,13 @@ ftp_retrieve(struct fetch_state *fs)
}
}
size = ftpGetSize(ftp, ftps->ftp_remote_file);
+ if (size > 0 && fs->fs_expectedsize != -1 && size != fs->fs_expectedsize) {
+ warnx("%s: size mismatch, expected=%lu / actual=%lu",
+ ftps->ftp_remote_path,
+ (unsigned long)fs->fs_expectedsize,
+ (unsigned long)size);
+ return EX_DATAERR;
+ }
modtime = ftpGetModtime(ftp, ftps->ftp_remote_file);
if (modtime <= 0) { /* xxx */
warnx("%s: cannot get remote modification time",
diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c
index e29bd0f..ecade4e 100644
--- a/usr.bin/fetch/http.c
+++ b/usr.bin/fetch/http.c
@@ -26,7 +26,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: http.c,v 1.18 1998/05/09 20:50:37 wollman Exp $
+ * $Id: http.c,v 1.19 1998/07/12 09:07:36 se Exp $
*/
#include <sys/types.h>
@@ -929,7 +929,20 @@ spewerror:
free(base64ofmd5);
return EX_PROTOCOL;
}
-
+
+ if (total_length > 0 && fs->fs_expectedsize != -1
+ && total_length != fs->fs_expectedsize) {
+ warnx("%s: size mismatch, expected=%lu / actual=%lu",
+ fs->fs_outputfile,
+ (unsigned long)fs->fs_expectedsize,
+ (unsigned long)total_length);
+ fclose(remote);
+ if (base64ofmd5)
+ free(base64ofmd5);
+ unsetup_sigalrm();
+ return EX_DATAERR;
+ }
+
fs->fs_status = "retrieving file from HTTP/1.x server";
/*
diff --git a/usr.bin/fetch/main.c b/usr.bin/fetch/main.c
index 2fe30ae..6669ad0 100644
--- a/usr.bin/fetch/main.c
+++ b/usr.bin/fetch/main.c
@@ -24,7 +24,7 @@
* SUCH DAMAGE.
*/
-/* $Id: main.c,v 1.45 1998/05/09 08:41:23 des Exp $ */
+/* $Id: main.c,v 1.46 1998/05/09 08:56:07 des Exp $ */
#include <sys/types.h>
@@ -52,7 +52,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n",
- "usage: fetch [-DHILMNPRTValmnpqrv] [-o outputfile]",
+ "usage: fetch [-DHILMNPRTValmnpqrv] [-o outputfile] [-S bytes]",
" [-f file -h host [-c dir] | URL]");
exit(EX_USAGE);
}
@@ -71,9 +71,10 @@ main(int argc, char *const *argv)
init_schemes();
fs = clean_fetch_state;
fs.fs_verbose = 1;
+ fs.fs_expectedsize = -1;
change_to_dir = file_to_get = hostname = 0;
- while ((c = getopt(argc, argv, "abc:D:f:h:HilLmMnNo:pPqRrtT:vV:")) != -1) {
+ while ((c = getopt(argc, argv, "abc:D:f:h:HilLmMnNo:pPqRrS:tT:vV:")) != -1) {
switch (c) {
case 'D': case 'H': case 'I': case 'N': case 'L': case 'V':
break; /* ncftp compatibility */
@@ -134,6 +135,16 @@ main(int argc, char *const *argv)
fs.fs_use_connect = 1;
break;
+ case 'S':
+ /* strtol sets errno to ERANGE in the case of overflow */
+ errno = 0;
+ l = strtoul(optarg, &ep, 0);
+ if (!optarg[0] || *ep || errno != 0 || l > INT_MAX)
+ errx(EX_USAGE, "invalid size value: `%s'",
+ optarg);
+ fs.fs_expectedsize = l;
+ break;
+
case 'T':
/* strtol sets errno to ERANGE in the case of overflow */
errno = 0;
OpenPOWER on IntegriCloud