diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index 889cf2b30037..89f290c5bfac 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,4 +1,4 @@ -/* $NetBSD: cmds.c,v 1.30 1997/09/26 15:22:46 lukem Exp $ */ +/* $NetBSD: cmds.c,v 1.31 1997/11/01 14:36:49 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -__RCSID("$NetBSD: cmds.c,v 1.30 1997/09/26 15:22:46 lukem Exp $"); +__RCSID("$NetBSD: cmds.c,v 1.31 1997/11/01 14:36:49 lukem Exp $"); #endif #endif /* not lint */ @@ -781,9 +781,12 @@ sethash(argc, argv) else if (strcasecmp(argv[1], "off") == 0) hash = 0; else { - int nmark = atol(argv[1]); - if (nmark < 1) { - printf("%s: bad bytecount value.\n", argv[1]); + int nmark; + char *ep; + + nmark = strtol(argv[1], &ep, 10); + if (nmark < 1 || *ep == '\0') { + printf("mark: bad bytecount value `%s'.\n", argv[1]); code = -1; return; } @@ -1994,13 +1997,26 @@ restart(argc, argv) char *argv[]; { - if (argc != 2) - puts("restart: offset not specified."); - else { - restart_point = atol(argv[1]); - printf("Restarting at %qd. Execute get, put or append to " - "initiate transfer\n", (long long)restart_point); + if (argc > 2) { + printf("usage: %s [restart_point]\n", argv[0]); + code = -1; + return; } + if (argc == 2) { + quad_t rp; + char *ep; + + rp = strtoq(argv[1], &ep, 10); + if (rp < 0 || *ep != '\0') + printf("restart: Invalid offset `%s'\n", argv[1]); + else + restart_point = rp; + } + if (restart_point == 0) + puts("No restart point defined"); + else + printf("Restarting at %qd for next get, put or append\n", + (long long)restart_point); } /* @@ -2152,7 +2168,7 @@ page(argc, argv) int argc; char *argv[]; { - int orestart_point, ohash, overbose; + int ohash, overbose; char *p, *pager, *oldargv1; if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) { @@ -2172,13 +2188,11 @@ page(argc, argv) errx(1, "Can't allocate memory for $PAGER"); (void)sprintf(pager, "|%s", p); - orestart_point = restart_point; ohash = hash; overbose = verbose; - restart_point = hash = verbose = 0; + hash = verbose = 0; recvrequest("RETR", pager, argv[1], "r+w", 1, 0); (void)free(pager); - restart_point = orestart_point; hash = ohash; verbose = overbose; if (oldargv1 != argv[1]) /* free up after globulize() */ diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 10418ba3bc1d..26e14e258f32 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */ +/* $NetBSD: extern.h,v 1.18 1997/11/01 14:36:53 lukem Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. @@ -161,17 +161,12 @@ int togglevar __P((int, char **, int *, const char *)); void usage __P((void)); void user __P((int, char **)); - -extern jmp_buf abortprox; -extern int abrtflag; extern struct cmd cmdtab[]; extern FILE *cout; extern int data; extern char *home; -extern jmp_buf jabort; extern int proxy; extern char reply_string[]; -extern off_t restart_point; extern int NCMDS; extern char *__progname; /* from crt0.o */ diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 00ba5b9944c7..f27897a1eb05 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $NetBSD: fetch.c,v 1.16 1997/09/21 01:06:31 lukem Exp $ */ +/* $NetBSD: fetch.c,v 1.17 1997/11/01 14:36:55 lukem Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fetch.c,v 1.16 1997/09/21 01:06:31 lukem Exp $"); +__RCSID("$NetBSD: fetch.c,v 1.17 1997/11/01 14:36:55 lukem Exp $"); #endif /* not lint */ /* @@ -235,9 +235,8 @@ url_get(origline, proxyenv) printf("Requesting %s\n", origline); else printf("Requesting %s (via %s)\n", origline, proxyenv); - snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", + len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", proxy ? "" : "/", path); - len = strlen(buf); if (write(s, buf, len) < len) { warn("Writing HTTP request"); goto cleanup_url_get; diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index 1c0b275da6e2..08dad9dcc2fd 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftp.c,v 1.29 1997/10/19 19:09:05 mycroft Exp $ */ +/* $NetBSD: ftp.c,v 1.30 1997/11/01 14:36:58 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -__RCSID("$NetBSD: ftp.c,v 1.29 1997/10/19 19:09:05 mycroft Exp $"); +__RCSID("$NetBSD: ftp.c,v 1.30 1997/11/01 14:36:58 lukem Exp $"); #endif #endif /* not lint */ @@ -77,7 +77,6 @@ jmp_buf ptabort; int ptabflg; int ptflag = 0; struct sockaddr_in myctladdr; -off_t restart_point = 0; FILE *cin, *cout; @@ -466,9 +465,8 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGPIPE, oldintp); if (oldinti) (void)signal(SIGINFO, oldinti); - progress = oprogress; code = -1; - return; + goto cleanupsend; } oldintr = signal(SIGINT, abortsend); oldinti = signal(SIGINFO, psummary); @@ -484,7 +482,7 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGPIPE, oldintp); (void)signal(SIGINFO, oldinti); code = -1; - return; + goto cleanupsend; } progress = 0; closefunc = pclose; @@ -495,7 +493,7 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); code = -1; - return; + goto cleanupsend; } closefunc = fclose; if (fstat(fileno(fin), &st) < 0 || !S_ISREG(st.st_mode)) { @@ -504,7 +502,7 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGINFO, oldinti); fclose(fin); code = -1; - return; + goto cleanupsend; } filesize = st.st_size; } @@ -514,10 +512,9 @@ sendrequest(cmd, local, remote, printnames) if (oldintp) (void)signal(SIGPIPE, oldintp); code = -1; - progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); - return; + goto cleanupsend; } if (setjmp(sendabort)) goto abort; @@ -538,44 +535,37 @@ sendrequest(cmd, local, remote, printnames) } if (rc < 0) { warn("local: %s", local); - restart_point = 0; - progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); - return; + goto cleanupsend; } - if (command("REST %ld", (long) restart_point) - != CONTINUE) { - restart_point = 0; - progress = oprogress; + if (command("REST %qd", (long long) restart_point) != + CONTINUE) { if (closefunc != NULL) (*closefunc)(fin); - return; + goto cleanupsend; } - restart_point = 0; lmode = "r+w"; } if (remote) { if (command("%s %s", cmd, remote) != PRELIM) { (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); - progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) (*closefunc)(fin); - return; + goto cleanupsend; } } else if (command("%s", cmd) != PRELIM) { (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); - progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) (*closefunc)(fin); - return; + goto cleanupsend; } dout = dataconn(lmode); if (dout == NULL) @@ -654,7 +644,6 @@ sendrequest(cmd, local, remote, printnames) break; } progressmeter(1); - progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); (void)fclose(dout); @@ -665,11 +654,10 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGPIPE, oldintp); if (bytes > 0) ptransfer(0); - return; + goto cleanupsend; abort: (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); - progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (!cpend) { @@ -688,6 +676,9 @@ abort: (*closefunc)(fin); if (bytes > 0) ptransfer(0); +cleanupsend: + progress = oprogress; + restart_point = 0; } jmp_buf recvabort; @@ -744,7 +735,7 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial) filesize = -1; oprogress = progress; opreserve = preserve; - is_retr = strcmp(cmd, "RETR") == 0; + is_retr = (strcmp(cmd, "RETR") == 0); if (is_retr && verbose && printnames) { if (local && (ignorespecial || *local != '-')) printf("local: %s ", local); @@ -841,7 +832,7 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial) if (setjmp(recvabort)) goto abort; if (is_retr && restart_point && - command("REST %ld", (long) restart_point) != CONTINUE) + command("REST %qd", (long long) restart_point) != CONTINUE) return; if (remote) { if (command("%s %s", cmd, remote) != PRELIM) { @@ -903,7 +894,7 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial) case TYPE_I: case TYPE_L: - if (restart_point && + if (is_retr && restart_point && lseek(fileno(fout), restart_point, SEEK_SET) < 0) { warn("local: %s", local); progress = oprogress; @@ -945,12 +936,13 @@ recvrequest(cmd, local, remote, lmode, printnames, ignorespecial) break; case TYPE_A: - if (restart_point) { - int i, n, ch; + if (is_retr && restart_point) { + int ch; + long i, n; if (fseek(fout, 0L, SEEK_SET) < 0) goto done; - n = restart_point; + n = (long)restart_point; for (i = 0; i++ < n;) { if ((ch = getc(fout)) == EOF) goto done; diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h index 58acbe46cd9b..537d712edb65 100644 --- a/usr.bin/ftp/ftp_var.h +++ b/usr.bin/ftp/ftp_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: ftp_var.h,v 1.20 1997/09/13 09:05:58 lukem Exp $ */ +/* $NetBSD: ftp_var.h,v 1.21 1997/11/01 14:37:00 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -129,6 +129,7 @@ size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */ off_t bytes; /* current # of bytes read */ off_t filesize; /* size of file being transferred */ char *direction; /* direction transfer is occurring */ +off_t restart_point; /* offset to restart transfer */ char *hostname; /* name of host connected to */ int unix_server; /* server is unix, can use binary for ascii */ diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c index d6d5f1889ad8..cb7b7b733d12 100644 --- a/usr.bin/ftp/ruserpass.c +++ b/usr.bin/ftp/ruserpass.c @@ -1,4 +1,4 @@ -/* $NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $ */ +/* $NetBSD: ruserpass.c,v 1.15 1997/11/01 14:37:03 lukem Exp $ */ /* * Copyright (c) 1985, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $"); +__RCSID("$NetBSD: ruserpass.c,v 1.15 1997/11/01 14:37:03 lukem Exp $"); #endif #endif /* not lint */ @@ -148,10 +148,10 @@ next: case LOGIN: if (token()) - if (*aname == 0) { - *aname = malloc((unsigned) - strlen(tokval) + 1); - (void)strcpy(*aname, tokval); + if (*aname == NULL) { + *aname = strdup(tokval); + if (*aname == NULL) + err(1, "can't strdup *aname"); } else { if (strcmp(*aname, tokval)) goto next; @@ -165,9 +165,10 @@ next: warnx("Remove password or make file unreadable by others."); goto bad; } - if (token() && *apass == 0) { - *apass = malloc((unsigned) strlen(tokval) + 1); - (void)strcpy(*apass, tokval); + if (token() && *apass == NULL) { + *apass = strdup(tokval); + if (*apass == NULL) + err(1, "can't strdup *apass"); } break; case ACCOUNT: @@ -177,9 +178,10 @@ next: warnx("Remove account or make file unreadable by others."); goto bad; } - if (token() && *aacct == 0) { - *aacct = malloc((unsigned) strlen(tokval) + 1); - (void)strcpy(*aacct, tokval); + if (token() && *aacct == NULL) { + *aacct = strdup(tokval); + if (*aacct == NULL) + err(1, "can't strdup *aacct"); } break; case MACDEF: diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 0189af9e900c..670cd76772b5 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.16 1997/10/14 16:31:26 christos Exp $ */ +/* $NetBSD: util.c,v 1.17 1997/11/01 14:37:05 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -35,7 +35,7 @@ #include #ifndef lint -__RCSID("$NetBSD: util.c,v 1.16 1997/10/14 16:31:26 christos Exp $"); +__RCSID("$NetBSD: util.c,v 1.17 1997/11/01 14:37:05 lukem Exp $"); #endif /* not lint */ /* @@ -55,6 +55,7 @@ __RCSID("$NetBSD: util.c,v 1.16 1997/10/14 16:31:26 christos Exp $"); #include #include #include +#include #include #include "ftp_var.h" @@ -581,8 +582,8 @@ progressmeter(flag) static off_t lastsize; struct timeval now, td, wait; off_t cursize, abbrevsize; - double elapsed, remaining; - int ratio, barlength, i, len; + double elapsed; + int ratio, barlength, i, len, remaining; char buf[256]; len = 0; @@ -643,20 +644,20 @@ progressmeter(flag) len += snprintf(buf + len, sizeof(buf) - len, " - stalled -"); } else { - remaining = - (filesize - restart_point) / (bytes / elapsed) - elapsed; - if (remaining >= 100 * 3600) + remaining = (int) + ((filesize - restart_point) / (bytes / elapsed) - elapsed); + if (remaining >= 100 * SECSPERHOUR) len += snprintf(buf + len, sizeof(buf) - len, " --:-- ETA"); else { - i = (int)remaining / 3600; + i = remaining / SECSPERHOUR; if (i) len += snprintf(buf + len, sizeof(buf) - len, "%2d:", i); else len += snprintf(buf + len, sizeof(buf) - len, " "); - i = (int)remaining % 3600; + i = remaining % SECSPERHOUR; len += snprintf(buf + len, sizeof(buf) - len, "%02d:%02d ETA", i / 60, i % 60); } @@ -688,7 +689,7 @@ ptransfer(siginfo) struct timeval now, td; double elapsed; off_t bs; - int meg, remaining, hh; + int meg, remaining, hh, len; char buf[100]; if (!verbose && !siginfo) @@ -701,7 +702,8 @@ ptransfer(siginfo) meg = 0; if (bs > (1024 * 1024)) meg = 1; - (void)snprintf(buf, sizeof(buf), + len = 0; + len += snprintf(buf + len, sizeof(buf) - len, "%qd byte%s %s in %.2f seconds (%.2f %sB/s)\n", (long long)bytes, bytes == 1 ? "" : "s", direction, elapsed, bs / (1024.0 * (meg ? 1024.0 : 1.0)), meg ? "M" : "K"); @@ -709,14 +711,14 @@ ptransfer(siginfo) && bytes + restart_point <= filesize) { remaining = (int)((filesize - restart_point) / (bytes / elapsed) - elapsed); - hh = remaining / 3600; - remaining %= 3600; - /* "buf+len(buf) -1" to overwrite \n */ - snprintf(buf + strlen(buf) - 1, sizeof(buf) - strlen(buf), + hh = remaining / SECSPERHOUR; + remaining %= SECSPERHOUR; + len--; /* decrement len to overwrite \n */ + len += snprintf(buf + len, sizeof(buf) - len, " ETA: %02d:%02d:%02d\n", hh, remaining / 60, remaining % 60); } - (void)write(siginfo ? STDERR_FILENO : STDOUT_FILENO, buf, strlen(buf)); + (void)write(siginfo ? STDERR_FILENO : STDOUT_FILENO, buf, len); } /*