From: millert Date: Mon, 3 Feb 1997 01:05:31 +0000 (+0000) Subject: Add back ``-r'' option and fix strncpy() usage and other nits because X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c74a11ce19fd43beac8bc9daae77010624f4b868;p=openbsd Add back ``-r'' option and fix strncpy() usage and other nits because I'm anal. Closer to KNF now. --- diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile index a73908d2179..e4ad344a9bb 100644 --- a/usr.bin/ftp/Makefile +++ b/usr.bin/ftp/Makefile @@ -1,3 +1,4 @@ +# $OpenBSD: Makefile,v 1.6 1997/02/03 01:05:31 millert Exp $ # $NetBSD: Makefile,v 1.8 1997/01/19 14:19:02 lukem Exp $ # from: @(#)Makefile 8.2 (Berkeley) 4/3/94 @@ -5,7 +6,8 @@ #SMALLFTP=yes PROG= ftp -SRCS= cmds.c cmdtab.c domacro.c fetch.c ftp.c main.c ruserpass.c util.c +SRCS= cmds.c cmdtab.c domacro.c fetch.c ftp.c main.c ruserpass.c \ + stringlist.c util.c .if defined(SMALLFTP) CFLAGS+=-DSMALLFTP diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index 76529c943f6..3f10868500c 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,3 +1,4 @@ +/* $OpenBSD: cmds.c,v 1.14 1997/02/03 01:05:33 millert Exp $ */ /* $NetBSD: cmds.c,v 1.18 1997/02/01 10:44:54 lukem Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$NetBSD: cmds.c,v 1.18 1997/02/01 10:44:54 lukem Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.14 1997/02/03 01:05:33 millert Exp $"; #endif #endif /* not lint */ @@ -100,7 +101,7 @@ settype(argc, argv) printf("%s%s", sep, p->t_name); sep = " | "; } - printf(" ]\n"); + puts(" ]"); code = -1; return; } @@ -122,7 +123,7 @@ settype(argc, argv) else comret = command("TYPE %s", p->t_mode); if (comret == COMPLETE) { - (void) strcpy(typename, p->t_name); + (void)strcpy(typename, p->t_name); curtype = type = p->t_type; } } @@ -321,7 +322,7 @@ mput(argc, argv) mname = argv[0]; mflag = 1; oldintr = signal(SIGINT, mabort); - (void) setjmp(jabort); + (void)setjmp(jabort); if (proxy) { char *cp, *tp2, tmpbuf[MAXPATHLEN]; @@ -367,7 +368,7 @@ mput(argc, argv) } } } - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); mflag = 0; return; } @@ -419,7 +420,7 @@ mput(argc, argv) } globfree(&gl); } - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); mflag = 0; } @@ -429,7 +430,7 @@ reget(argc, argv) char *argv[]; { - (void) getit(argc, argv, 1, "r+w"); + (void)getit(argc, argv, 1, "r+w"); } void @@ -438,7 +439,7 @@ get(argc, argv) char *argv[]; { - (void) getit(argc, argv, 0, restart_point ? "r+w" : "w" ); + (void)getit(argc, argv, 0, restart_point ? "r+w" : "w" ); } /* @@ -534,8 +535,8 @@ mabort(signo) int ointer, oconf; alarmtimer(0); - printf("\n"); - (void) fflush(stdout); + putchar('\n'); + (void)fflush(stdout); if (mflag && fromatty) { ointer = interactive; oconf = confirmrest; @@ -573,7 +574,7 @@ mget(argc, argv) mname = argv[0]; mflag = 1; oldintr = signal(SIGINT, mabort); - (void) setjmp(jabort); + (void)setjmp(jabort); while ((cp = remglob(argv, proxy)) != NULL) { if (*cp == '\0') { mflag = 0; @@ -605,7 +606,7 @@ mget(argc, argv) } } } - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); mflag = 0; } @@ -631,7 +632,7 @@ status(argc, argv) if (connected) printf("Connected to %s.\n", hostname); else - printf("Not connected.\n"); + puts("Not connected."); if (!proxy) { pswitch(1); if (connected) { @@ -639,7 +640,7 @@ status(argc, argv) hostname); } else { - printf("No proxy connection.\n"); + puts("No proxy connection."); } pswitch(0); } @@ -657,13 +658,13 @@ status(argc, argv) printf("Ntrans: (in) %s (out) %s\n", ntin, ntout); } else { - printf("Ntrans: off\n"); + puts("Ntrans: off"); } if (mapflag) { printf("Nmap: (in) %s (out) %s\n", mapin, mapout); } else { - printf("Nmap: off\n"); + puts("Nmap: off"); } printf("Hash mark printing: %s; Mark count: %d; Progress bar: %s\n", onoff(hash), mark, onoff(progress)); @@ -672,7 +673,7 @@ status(argc, argv) printf("Command line editing: %s\n", onoff(editing)); #endif /* !SMALLFTP */ if (macnum > 0) { - printf("Macros:\n"); + puts("Macros:"); for (i=0; i 1) { execl(shell, shellnam, "-c", altarg, (char *)0); @@ -1178,8 +1180,8 @@ shell(argc, argv) if (pid > 0) while (wait((int *)&status) != pid) ; - (void) signal(SIGINT, old1); - (void) signal(SIGQUIT, old2); + (void)signal(SIGINT, old1); + (void)signal(SIGQUIT, old2); if (pid == -1) { warn("%s", "Try again later"); code = -1; @@ -1201,7 +1203,7 @@ user(argc, argv) int n, aflag = 0; if (argc < 2) - (void) another(&argc, &argv, "username"); + (void)another(&argc, &argv, "username"); if (argc < 2 || argc > 4) { printf("usage: %s username [password] [account]\n", argv[0]); code = -1; @@ -1215,8 +1217,9 @@ user(argc, argv) } if (n == CONTINUE) { if (argc < 4) { - printf("Account: "); (void) fflush(stdout); - (void) fgets(acct, sizeof(acct) - 1, stdin); + (void)fputs("Account: ", stdout); + (void)fflush(stdout); + (void)fgets(acct, sizeof(acct) - 1, stdin); acct[strlen(acct) - 1] = '\0'; argv[3] = acct; argc++; } @@ -1224,11 +1227,11 @@ user(argc, argv) aflag++; } if (n != COMPLETE) { - fprintf(stdout, "Login failed.\n"); + puts("Login failed."); return; } if (!aflag && argc == 4) { - (void) command("ACCT %s", argv[3]); + (void)command("ACCT %s", argv[3]); } } @@ -1248,8 +1251,8 @@ pwd(argc, argv) */ verbose = 1; if (command("PWD") == ERROR && code == 500) { - printf("PWD command not recognized, trying XPWD\n"); - (void) command("XPWD"); + puts("PWD command not recognized, trying XPWD"); + (void)command("XPWD"); } verbose = oldverbose; } @@ -1288,8 +1291,8 @@ makedir(argc, argv) } if (command("MKD %s", argv[1]) == ERROR && code == 500) { if (verbose) - printf("MKD command not recognized, trying XMKD\n"); - (void) command("XMKD %s", argv[1]); + puts("MKD command not recognized, trying XMKD"); + (void)command("XMKD %s", argv[1]); } } @@ -1310,8 +1313,8 @@ removedir(argc, argv) } if (command("RMD %s", argv[1]) == ERROR && code == 500) { if (verbose) - printf("RMD command not recognized, trying XRMD\n"); - (void) command("XRMD %s", argv[1]); + puts("RMD command not recognized, trying XRMD"); + (void)command("XRMD %s", argv[1]); } } @@ -1364,14 +1367,15 @@ quote1(initial, argc, argv) int i, len; char buf[BUFSIZ]; /* must be >= sizeof(line) */ - (void) strncpy(buf, initial, sizeof(buf)); + (void)strncpy(buf, initial, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (argc > 1) { len = strlen(buf); - len += strlen(strncpy(&buf[len], argv[1], sizeof(buf) - len)); - for (i = 2; i < argc; i++) { + len += strlen(strncpy(&buf[len], argv[1], sizeof(buf) - len - 1)); + for (i = 2; i < argc && len < sizeof(buf); i++) { buf[len++] = ' '; len += strlen(strncpy(&buf[len], argv[i], - sizeof(buf) - len)); + sizeof(buf) - len) - 1); } } if (command(buf) == PRELIM) { @@ -1394,7 +1398,7 @@ usage: code = -1; return; } - (void) command("SITE CHMOD %s %s", argv[1], argv[2]); + (void)command("SITE CHMOD %s %s", argv[1], argv[2]); } void @@ -1405,7 +1409,7 @@ do_umask(argc, argv) int oldverbose = verbose; verbose = 1; - (void) command(argc == 1 ? "SITE UMASK" : "SITE UMASK %s", argv[1]); + (void)command(argc == 1 ? "SITE UMASK" : "SITE UMASK %s", argv[1]); verbose = oldverbose; } @@ -1417,7 +1421,7 @@ idle(argc, argv) int oldverbose = verbose; verbose = 1; - (void) command(argc == 1 ? "SITE IDLE" : "SITE IDLE %s", argv[1]); + (void)command(argc == 1 ? "SITE IDLE" : "SITE IDLE %s", argv[1]); verbose = oldverbose; } @@ -1432,7 +1436,7 @@ rmthelp(argc, argv) int oldverbose = verbose; verbose = 1; - (void) command(argc == 1 ? "HELP" : "HELP %s", argv[1]); + (void)command(argc == 1 ? "HELP" : "HELP %s", argv[1]); verbose = oldverbose; } @@ -1466,9 +1470,9 @@ disconnect(argc, argv) if (!connected) return; - (void) command("QUIT"); + (void)command("QUIT"); if (cout) { - (void) fclose(cout); + (void)fclose(cout); } cout = NULL; connected = 0; @@ -1494,7 +1498,7 @@ account(argc, argv) ap = argv[1]; else ap = getpass("Account:"); - (void) command("ACCT %s", ap); + (void)command("ACCT %s", ap); } jmp_buf abortprox; @@ -1533,20 +1537,20 @@ doproxy(argc, argv) } c = getcmd(argv[1]); if (c == (struct cmd *) -1) { - printf("?Ambiguous command\n"); - (void) fflush(stdout); + puts("?Ambiguous command"); + (void)fflush(stdout); code = -1; return; } if (c == 0) { - printf("?Invalid command\n"); - (void) fflush(stdout); + puts("?Invalid command"); + (void)fflush(stdout); code = -1; return; } if (!c->c_proxy) { - printf("?Invalid proxy command\n"); - (void) fflush(stdout); + puts("?Invalid proxy command"); + (void)fflush(stdout); code = -1; return; } @@ -1557,10 +1561,10 @@ doproxy(argc, argv) oldintr = signal(SIGINT, proxabort); pswitch(1); if (c->c_conn && !connected) { - printf("Not connected\n"); - (void) fflush(stdout); + puts("Not connected"); + (void)fflush(stdout); pswitch(0); - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); code = -1; return; } @@ -1575,7 +1579,7 @@ doproxy(argc, argv) proxflag = 0; } pswitch(0); - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); } void @@ -1603,20 +1607,20 @@ setntrans(argc, argv) { if (argc == 1) { ntflag = 0; - printf("Ntrans off.\n"); + puts("Ntrans off."); code = ntflag; return; } ntflag++; code = ntflag; - (void) strncpy(ntin, argv[1], 16); - ntin[16] = '\0'; + (void)strncpy(ntin, argv[1], sizeof(ntin) - 1); + ntin[sizeof(ntin) - 1] = '\0'; if (argc == 2) { ntout[0] = '\0'; return; } - (void) strncpy(ntout, argv[2], 16); - ntout[16] = '\0'; + (void)strncpy(ntout, argv[2], sizeof(ntout) - 1); + ntout[sizeof(ntout) - 1] = '\0'; } char * @@ -1657,7 +1661,7 @@ setnmap(argc, argv) if (argc == 1) { mapflag = 0; - printf("Nmap off.\n"); + puts("Nmap off."); code = mapflag; return; } @@ -1676,10 +1680,10 @@ setnmap(argc, argv) cp = strchr(altarg, ' '); } *cp = '\0'; - (void) strncpy(mapin, altarg, MAXPATHLEN - 1); + (void)strncpy(mapin, altarg, MAXPATHLEN - 1); while (*++cp == ' ') continue; - (void) strncpy(mapout, cp, MAXPATHLEN - 1); + (void)strncpy(mapout, cp, MAXPATHLEN - 1); } char * @@ -1792,8 +1796,7 @@ LOOP: } } if (!*cp2) { - printf("nmap: unbalanced " - "brackets\n"); + puts("nmap: unbalanced brackets"); return (name); } match = 1; @@ -1806,8 +1809,7 @@ LOOP: } } if (!*cp2) { - printf("nmap: unbalanced " - "brackets\n"); + puts("nmap: unbalanced brackets"); return (name); } break; @@ -1892,7 +1894,7 @@ cdup(argc, argv) r = command("CDUP"); if (r == ERROR && code == 500) { if (verbose) - printf("CDUP command not recognized, trying XCUP\n"); + puts("CDUP command not recognized, trying XCUP"); r = command("XCUP"); } if (r == COMPLETE) @@ -1907,7 +1909,7 @@ restart(argc, argv) { if (argc != 2) - printf("restart: offset not specified\n"); + puts("restart: offset not specified"); else { restart_point = atol(argv[1]); printf("Restarting at %qd. Execute get, put or append to" @@ -1922,7 +1924,7 @@ syst(argc, argv) char *argv[]; { - (void) command("SYST"); + (void)command("SYST"); } void @@ -1934,7 +1936,7 @@ macdef(argc, argv) int c; if (macnum == 16) { - printf("Limit of 16 macros have already been defined\n"); + puts("Limit of 16 macros have already been defined"); code = -1; return; } @@ -1944,20 +1946,19 @@ macdef(argc, argv) return; } if (interactive) { - printf("Enter macro line by line, terminating it with a " - "null line\n"); + puts("Enter macro line by line, terminating it with a null line"); } - (void) strncpy(macros[macnum].mac_name, argv[1], 8); - if (macnum == 0) { + (void)strncpy(macros[macnum].mac_name, argv[1], + sizeof(macros[macnum].mac_name) - 1); + macros[macnum].mac_name[sizeof(macros[macnum].mac_name) - 1] = '\0'; + if (macnum == 0) macros[macnum].mac_start = macbuf; - } - else { + else macros[macnum].mac_start = macros[macnum - 1].mac_end + 1; - } tmp = macros[macnum].mac_start; while (tmp != macbuf+4096) { if ((c = getchar()) == EOF) { - printf("macdef:end of file encountered\n"); + puts("macdef: end of file encountered"); code = -1; return; } @@ -1980,7 +1981,7 @@ macdef(argc, argv) while ((c = getchar()) != '\n' && c != EOF) /* LOOP */; if (c == EOF || getchar() == '\n') { - printf("Macro not defined - 4k buffer exceeded\n"); + puts("Macro not defined - 4k buffer exceeded"); code = -1; return; } @@ -2038,7 +2039,7 @@ rmtstatus(argc, argv) char *argv[]; { - (void) command(argc > 1 ? "STAT %s" : "STAT" , argv[1]); + (void)command(argc > 1 ? "STAT %s" : "STAT" , argv[1]); } /* diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c index db253004310..9624ee83556 100644 --- a/usr.bin/ftp/cmdtab.c +++ b/usr.bin/ftp/cmdtab.c @@ -1,3 +1,4 @@ +/* $OpenBSD: cmdtab.c,v 1.6 1997/02/03 01:05:34 millert Exp $ */ /* $NetBSD: cmdtab.c,v 1.12 1997/01/19 14:19:05 lukem Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$NetBSD: cmdtab.c,v 1.12 1997/01/19 14:19:05 lukem Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.6 1997/02/03 01:05:34 millert Exp $"; #endif #endif /* not lint */ @@ -217,4 +218,4 @@ struct cmd cmdtab[] = { { 0 }, }; -int NCMDS = (sizeof (cmdtab) / sizeof (cmdtab[0])) - 1; +int NCMDS = (sizeof(cmdtab) / sizeof(cmdtab[0])) - 1; diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c index 8faea95a548..4a580e660b4 100644 --- a/usr.bin/ftp/complete.c +++ b/usr.bin/ftp/complete.c @@ -1,3 +1,4 @@ +/* $OpenBSD: complete.c,v 1.2 1997/02/03 01:05:35 millert Exp $ */ /* $NetBSD: complete.c,v 1.2 1997/02/01 10:44:57 lukem Exp $ */ /*- @@ -37,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: complete.c,v 1.2 1997/02/01 10:44:57 lukem Exp $"; +static char rcsid[] = "$OpenBSD: complete.c,v 1.2 1997/02/03 01:05:35 millert Exp $"; #endif /* not lint */ /* @@ -348,7 +349,7 @@ complete(el, ch) case 'r': /* remote complete */ case 'R': if (!connected) { - printf("\nMust be connected to complete\n"); + puts("\nMust be connected to complete"); return CC_REDISPLAY; } return complete_remote(word, dolist); diff --git a/usr.bin/ftp/domacro.c b/usr.bin/ftp/domacro.c index 9e389003594..5dbc939f052 100644 --- a/usr.bin/ftp/domacro.c +++ b/usr.bin/ftp/domacro.c @@ -1,3 +1,4 @@ +/* $OpenBSD: domacro.c,v 1.4 1997/02/03 01:05:36 millert Exp $ */ /* $NetBSD: domacro.c,v 1.8 1997/01/19 14:19:08 lukem Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$NetBSD: domacro.c,v 1.8 1997/01/19 14:19:08 lukem Exp $"; +static char rcsid[] = "$OpenBSD: domacro.c,v 1.4 1997/02/03 01:05:36 millert Exp $"; #endif #endif /* not lint */ @@ -72,7 +73,7 @@ domacro(argc, argv) code = -1; return; } - (void) strcpy(line2, line); + (void)strcpy(line2, line); TOP: cp1 = macros[i].mac_start; while (cp1 != macros[i].mac_end) { @@ -93,7 +94,7 @@ TOP: } cp1--; if (argc - 2 >= j) { - (void) strcpy(cp2, argv[j+1]); + (void)strcpy(cp2, argv[j+1]); cp2 += strlen(argv[j+1]); } break; @@ -102,7 +103,7 @@ TOP: loopflg = 1; cp1++; if (count < argc) { - (void) strcpy(cp2, argv[count]); + (void)strcpy(cp2, argv[count]); cp2 += strlen(argv[count]); } break; @@ -120,26 +121,26 @@ TOP: makeargv(); c = getcmd(margv[0]); if (c == (struct cmd *)-1) { - printf("?Ambiguous command\n"); + puts("?Ambiguous command"); code = -1; } else if (c == 0) { - printf("?Invalid command\n"); + puts("?Invalid command"); code = -1; } else if (c->c_conn && !connected) { - printf("Not connected.\n"); + puts("Not connected."); code = -1; } else { if (verbose) { - printf("%s\n", line); + puts(line); } (*c->c_handler)(margc, margv); if (bell && c->c_bell) { - (void) putchar('\007'); + (void)putchar('\007'); } - (void) strcpy(line, line2); + (void)strcpy(line, line2); makeargv(); argc = margc; argv = margv; diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index abe9d662104..cfa536ce915 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,4 +1,5 @@ /* $NetBSD: extern.h,v 1.11 1997/02/01 10:44:58 lukem Exp $ */ +/* $OpenBSD: extern.h,v 1.7 1997/02/03 01:05:37 millert Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 439f73c9aa7..a6c59628ccd 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fetch.c,v 1.2 1997/02/03 01:05:37 millert Exp $ */ /* $NetBSD: fetch.c,v 1.2 1997/02/01 10:45:00 lukem Exp $ */ /*- @@ -37,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: fetch.c,v 1.2 1997/02/01 10:45:00 lukem Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.2 1997/02/03 01:05:37 millert Exp $"; #endif /* not lint */ /* @@ -260,7 +261,7 @@ http_get(line) oldintr = NULL; if (setjmp(httpabort)) { if (oldintr) - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); goto cleanup_http_get; } oldintr = signal(SIGINT, aborthttp); @@ -283,17 +284,17 @@ http_get(line) } if (hash && !progress) { while (bytes >= hashbytes) { - (void) putchar('#'); + (void)putchar('#'); hashbytes += mark; } - (void) fflush(stdout); + (void)fflush(stdout); } } if (hash && !progress && bytes > 0) { if (bytes < mark) - (void) putchar('#'); - (void) putchar('\n'); - (void) fflush(stdout); + (void)putchar('#'); + (void)putchar('\n'); + (void)fflush(stdout); } if (len != 0) { warn("Reading from socket"); @@ -301,14 +302,14 @@ http_get(line) } progressmeter(1); if (verbose) - printf("Successfully retrieved file.\n"); - (void) signal(SIGINT, oldintr); + puts("Successfully retrieved file."); + (void)signal(SIGINT, oldintr); close(s); close(out); if (proxy) free(proxy); - return(0); + return (0); improper: warnx("improper response from %s", host); @@ -317,7 +318,7 @@ cleanup_http_get: close(s); if (proxy) free(proxy); - return(-1); + return (-1); } /* @@ -328,8 +329,8 @@ aborthttp() { alarmtimer(0); - printf("\nhttp fetch aborted\n"); - (void) fflush(stdout); + puts("\nhttp fetch aborted"); + (void)fflush(stdout); longjmp(httpabort, 1); } @@ -338,7 +339,7 @@ aborthttp() * files of the form "host:path", "ftp://host/path" using the * ftp protocol, and files of the form "http://host/path" using * the http protocol. - * If path has a trailing "/", then return(-1); + * If path has a trailing "/", then return (-1); * the path will be cd-ed into and the connection remains open, * and the function will return -1 (to indicate the connection * is alive). @@ -362,10 +363,10 @@ auto_fetch(argc, argv) if (setjmp(toplevel)) { if (connected) disconnect(0, NULL); - return(argpos + 1); + return (argpos + 1); } - (void) signal(SIGINT, intr); - (void) signal(SIGPIPE, lostpeer); + (void)signal(SIGINT, intr); + (void)signal(SIGPIPE, lostpeer); /* * Loop through as long as there's files to fetch. diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1 index 74c46246c65..bb0c54b05cd 100644 --- a/usr.bin/ftp/ftp.1 +++ b/usr.bin/ftp/ftp.1 @@ -1,3 +1,4 @@ +.\" $OpenBSD: ftp.1,v 1.7 1997/02/03 01:05:38 millert Exp $ .\" $NetBSD: ftp.1,v 1.17 1997/02/01 10:45:01 lukem Exp $ .\" .\" Copyright (c) 1985, 1989, 1990, 1993 @@ -50,6 +51,7 @@ file transfer program .Op Fl n .Op Fl p .Op Fl P Ar port +.Op Fl r Ar seconds .Op Fl t .Op Fl v .Op Fl V @@ -59,15 +61,19 @@ ftp://\fIhost\fR[:\fIport\fR]/\fIfile\fR[/] .Nm ftp http://\fIhost\fR[:\fIport\fR]/\fIfile\fR .Nm ftp -\fIhost\fR:\fIfile\fR[/] +\fIhost\fR:\fI/path/file\fR[/] .Sh DESCRIPTION -.Nm +.Nm Ftp is the user interface to the .Tn ARPANET standard File Transfer Protocol. The program allows a user to transfer files to and from a remote network site. .Pp +The latter three usage formats will fetch a file using either the +HTTP or FTP protocols into the current directory. +This is ideal for scripts. +.Pp Options may be specified at the command line, or to the command interpreter. .Bl -tag -width "port " @@ -104,6 +110,10 @@ Enable passive mode operation for use behind connection filtering firewalls. .It Fl P Ar port Sets the port number to .Ar port . +.It Fl r Ar number +Retry to connect if failed, pausing for +.Ar number +of seconds. .It Fl t Enables packet tracing. .It Fl v @@ -248,8 +258,8 @@ If an optional is specified it is used to set the debugging level. When debugging is on, .Nm -prints each command sent to the remote machine, preceded -by the string +prints each command sent to the remote machine, +preceded by the string .Ql \-\-> .It Ic dir Op Ar remote-directory Op Ar local-file Print a listing of the contents of a @@ -1269,13 +1279,6 @@ The .Nm command appeared in .Bx 4.2 . -.Pp -Various features such as command line editing, context sensitive -command and file completion, dynamic progress bar, automatic -fetching of files, ftp and http URLs, and modification time -preservation were implemented in -.Nx 1.2b -by Luke Mewburn, with assistance from Jason Thorpe. .Sh BUGS Correct execution of many commands depends upon proper behavior by the remote server. diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index 98cc4107c28..835007c8cbf 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,3 +1,4 @@ +/* $OpenBSD: ftp.c,v 1.11 1997/02/03 01:05:40 millert Exp $ */ /* $NetBSD: ftp.c,v 1.22 1997/02/01 10:45:03 lukem Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -static char rcsid[] = "$NetBSD: ftp.c,v 1.22 1997/02/01 10:45:03 lukem Exp $"; +static char rcsid[] = "$OpenBSD: ftp.c,v 1.11 1997/02/03 01:05:40 millert Exp $"; #endif #endif /* not lint */ @@ -87,10 +88,11 @@ hookup(host, port) int s, len, tos; static char hostnamebuf[MAXHOSTNAMELEN]; - memset((char *)&hisctladdr, 0, sizeof (hisctladdr)); + memset((char *)&hisctladdr, 0, sizeof(hisctladdr)); if (inet_aton(host, &hisctladdr.sin_addr) != 0) { hisctladdr.sin_family = AF_INET; - (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf)); + (void)strncpy(hostnamebuf, host, sizeof(hostnamebuf) - 1); + hostnamebuf[sizeof(hostnamebuf) - 1] = '\0'; } else { hp = gethostbyname(host); if (hp == NULL) { @@ -99,10 +101,9 @@ hookup(host, port) return ((char *) 0); } hisctladdr.sin_family = hp->h_addrtype; - memmove((caddr_t)&hisctladdr.sin_addr, - hp->h_addr_list[0], hp->h_length); - memcpy(&hisctladdr.sin_addr, hp->h_addr, hp->h_length); - (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf)); + memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length); + (void)strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf) - 1); + hostnamebuf[sizeof(hostnamebuf) - 1] = '\0'; } hostname = hostnamebuf; s = socket(hisctladdr.sin_family, SOCK_STREAM, 0); @@ -113,7 +114,7 @@ hookup(host, port) } hisctladdr.sin_port = port; while (connect(s, (struct sockaddr *)&hisctladdr, - sizeof (hisctladdr)) < 0) { + sizeof(hisctladdr)) < 0) { if (hp && hp->h_addr_list[1]) { int oerrno = errno; char *ia; @@ -122,11 +123,10 @@ hookup(host, port) errno = oerrno; warn("connect to address %s", ia); hp->h_addr_list++; - memmove((caddr_t)&hisctladdr.sin_addr, - hp->h_addr_list[0], hp->h_length); - fprintf(stdout, "Trying %s...\n", - inet_ntoa(hisctladdr.sin_addr)); - (void) close(s); + memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], + hp->h_length); + printf("Trying %s...\n", inet_ntoa(hisctladdr.sin_addr)); + (void)close(s); s = socket(hisctladdr.sin_family, SOCK_STREAM, 0); if (s < 0) { warn("socket"); @@ -139,7 +139,7 @@ hookup(host, port) code = -1; goto bad; } - len = sizeof (myctladdr); + len = sizeof(myctladdr); if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) { warn("getsockname"); code = -1; @@ -155,9 +155,9 @@ hookup(host, port) if (cin == NULL || cout == NULL) { warnx("fdopen failed."); if (cin) - (void) fclose(cin); + (void)fclose(cin); if (cout) - (void) fclose(cout); + (void)fclose(cout); code = -1; goto bad; } @@ -165,9 +165,9 @@ hookup(host, port) printf("Connected to %s.\n", hostname); if (getreply(0) > 2) { /* read startup message from server */ if (cin) - (void) fclose(cin); + (void)fclose(cin); if (cout) - (void) fclose(cout); + (void)fclose(cout); code = -1; goto bad; } @@ -184,7 +184,7 @@ hookup(host, port) return (hostname); bad: - (void) close(s); + (void)close(s); return ((char *)0); } @@ -247,7 +247,7 @@ login(host) printf("Name (%s:%s): ", host, myname); else printf("Name (%s): ", host); - (void) fgets(tmp, sizeof(tmp) - 1, stdin); + (void)fgets(tmp, sizeof(tmp) - 1, stdin); tmp[strlen(tmp) - 1] = '\0'; if (*tmp == '\0') user = myname; @@ -270,12 +270,12 @@ login(host) return (0); } if (!aflag && acct != NULL) - (void) command("ACCT %s", acct); + (void)command("ACCT %s", acct); if (proxy) return (1); for (n = 0; n < macnum; ++n) { if (!strcmp("init", macros[n].mac_name)) { - (void) strcpy(line, "$init"); + (void)strcpy(line, "$init"); makeargv(); domacro(margc, margv); break; @@ -289,8 +289,8 @@ cmdabort() { alarmtimer(0); - printf("\n"); - (void) fflush(stdout); + putchar('\n'); + (void)fflush(stdout); abrtflag++; if (ptflag) longjmp(ptabort, 1); @@ -308,18 +308,18 @@ va_dcl abrtflag = 0; if (debug) { - printf("---> "); + fputs("---> ", stdout); va_start(ap); fmt = va_arg(ap, char *); if (strncmp("PASS ", fmt, 5) == 0) - printf("PASS XXXX"); + fputs("PASS XXXX", stdout); else if (strncmp("ACCT ", fmt, 5) == 0) - printf("ACCT XXXX"); + fputs("ACCT XXXX", stdout); else - vfprintf(stdout, fmt, ap); + vprintf(fmt, ap); va_end(ap); - printf("\n"); - (void) fflush(stdout); + putchar('\n'); + (void)fflush(stdout); } if (cout == NULL) { warn("No control connection for command"); @@ -331,13 +331,13 @@ va_dcl fmt = va_arg(ap, char *); vfprintf(cout, fmt, ap); va_end(ap); - fprintf(cout, "\r\n"); - (void) fflush(cout); + fputs("\r\n", cout); + (void)fflush(cout); cpend = 1; r = getreply(!strcmp(fmt, "QUIT")); if (abrtflag && oldintr != SIG_IGN) (*oldintr)(SIGINT); - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); return (r); } @@ -366,13 +366,13 @@ getreply(expecteof) case WONT: c = getc(cin); fprintf(cout, "%c%c%c", IAC, DONT, c); - (void) fflush(cout); + (void)fflush(cout); break; case DO: case DONT: c = getc(cin); fprintf(cout, "%c%c%c", IAC, WONT, c); - (void) fflush(cout); + (void)fflush(cout); break; default: break; @@ -382,26 +382,26 @@ getreply(expecteof) dig++; if (c == EOF) { if (expecteof) { - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); code = 221; return (0); } lostpeer(); if (verbose) { - printf("421 Service not available, " - "remote server has closed " - "connection\n"); - (void) fflush(stdout); + puts( +"421 Service not available, remote server has closed connection"); + (void)fflush(stdout); } code = 421; return (4); } if (c != '\r' && (verbose > 0 || - (verbose > -1 && n == '5' && dig > 4))) { + (verbose > -1 && n == '5' && dig > 4)) && + (n < '5' || !retry_connect)) { if (proxflag && (dig == 1 || (dig == 5 && verbose == 0))) printf("%s:", hostname); - (void) putchar(c); + (void)putchar(c); } if (dig < 4 && isdigit(c)) code = code * 10 + (c - '0'); @@ -427,9 +427,10 @@ getreply(expecteof) if (cp < ¤t_line[sizeof(current_line) - 1]) *cp++ = c; } - if (verbose > 0 || (verbose > -1 && n == '5')) { - (void) putchar(c); - (void) fflush (stdout); + if (verbose > 0 || ((verbose > -1 && n == '5') && + (n < '5' || !retry_connect))) { + (void)putchar(c); + (void)fflush (stdout); } if (line == 0) { size_t len = cp - current_line; @@ -437,7 +438,7 @@ getreply(expecteof) if (len > sizeof(reply_string)) len = sizeof(reply_string); - (void) strncpy(reply_string, current_line, len); + (void)strncpy(reply_string, current_line, len); reply_string[len] = '\0'; } if (continuation && code != originalcode) { @@ -448,7 +449,7 @@ getreply(expecteof) *cp = '\0'; if (n != '1') cpend = 0; - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); if (code == 421 || originalcode == 421) lostpeer(); if (abrtflag && oldintr != cmdabort && oldintr != SIG_IGN) @@ -478,8 +479,8 @@ abortsend() alarmtimer(0); mflag = 0; abrtflag = 0; - printf("\nsend aborted\nwaiting for remote to finish abort\n"); - (void) fflush(stdout); + puts("\nsend aborted\nwaiting for remote to finish abort"); + (void)fflush(stdout); longjmp(sendabort, 1); } @@ -519,18 +520,18 @@ sendrequest(cmd, local, remote, printnames) lmode = "w"; if (setjmp(sendabort)) { while (cpend) { - (void) getreply(0); + (void)getreply(0); } if (data >= 0) { - (void) close(data); + (void)close(data); data = -1; } if (oldintr) - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); if (oldinti) - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -543,9 +544,9 @@ sendrequest(cmd, local, remote, printnames) fin = popen(local + 1, "r"); if (fin == NULL) { warn("%s", local + 1); - (void) signal(SIGINT, oldintr); - (void) signal(SIGPIPE, oldintp); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGPIPE, oldintp); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -554,17 +555,17 @@ sendrequest(cmd, local, remote, printnames) fin = fopen(local, "r"); if (fin == NULL) { warn("local: %s", local); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } closefunc = fclose; if (fstat(fileno(fin), &st) < 0 || (st.st_mode&S_IFMT) != S_IFREG) { - fprintf(stdout, "%s: not a plain file.\n", local); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + printf("%s: not a plain file.\n", local); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); fclose(fin); code = -1; return; @@ -572,10 +573,10 @@ sendrequest(cmd, local, remote, printnames) filesize = st.st_size; } if (initconn()) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); code = -1; if (closefunc != NULL) (*closefunc)(fin); @@ -617,20 +618,20 @@ sendrequest(cmd, local, remote, printnames) } if (remote) { if (command("%s %s", cmd, remote) != PRELIM) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) (*closefunc)(fin); return; } } else if (command("%s", cmd) != PRELIM) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) (*closefunc)(fin); return; @@ -645,24 +646,24 @@ sendrequest(cmd, local, remote, printnames) case TYPE_I: case TYPE_L: errno = d = 0; - while ((c = read(fileno(fin), buf, sizeof (buf))) > 0) { + while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) { bytes += c; for (bufp = buf; c > 0; c -= d, bufp += d) if ((d = write(fileno(dout), bufp, c)) <= 0) break; if (hash && (!progress || filesize < 0) ) { while (bytes >= hashbytes) { - (void) putchar('#'); + (void)putchar('#'); hashbytes += mark; } - (void) fflush(stdout); + (void)fflush(stdout); } } if (hash && (!progress || filesize < 0) && bytes > 0) { if (bytes < mark) - (void) putchar('#'); - (void) putchar('\n'); - (void) fflush(stdout); + (void)putchar('#'); + (void)putchar('\n'); + (void)fflush(stdout); } if (c < 0) warn("local: %s", local); @@ -678,16 +679,16 @@ sendrequest(cmd, local, remote, printnames) if (c == '\n') { while (hash && (!progress || filesize < 0) && (bytes >= hashbytes)) { - (void) putchar('#'); - (void) fflush(stdout); + (void)putchar('#'); + (void)fflush(stdout); hashbytes += mark; } if (ferror(dout)) break; - (void) putc('\r', dout); + (void)putc('\r', dout); bytes++; } - (void) putc(c, dout); + (void)putc(c, dout); bytes++; #if 0 /* this violates RFC */ if (c == '\r') { @@ -698,9 +699,9 @@ sendrequest(cmd, local, remote, printnames) } if (hash && (!progress || filesize < 0)) { if (bytes < hashbytes) - (void) putchar('#'); - (void) putchar('\n'); - (void) fflush(stdout); + (void)putchar('#'); + (void)putchar('\n'); + (void)fflush(stdout); } if (ferror(fin)) warn("local: %s", local); @@ -714,31 +715,31 @@ sendrequest(cmd, local, remote, printnames) progressmeter(1); if (closefunc != NULL) (*closefunc)(fin); - (void) fclose(dout); - (void) getreply(0); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)fclose(dout); + (void)getreply(0); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); if (bytes > 0) ptransfer(0); return; abort: - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); + (void)signal(SIGPIPE, oldintp); if (!cpend) { code = -1; return; } if (data >= 0) { - (void) close(data); + (void)close(data); data = -1; } if (dout) - (void) fclose(dout); - (void) getreply(0); + (void)fclose(dout); + (void)getreply(0); code = -1; if (closefunc != NULL && fin != NULL) (*closefunc)(fin); @@ -755,8 +756,8 @@ abortrecv() alarmtimer(0); mflag = 0; abrtflag = 0; - printf("\nreceive aborted\nwaiting for remote to finish abort\n"); - (void) fflush(stdout); + puts("\nreceive aborted\nwaiting for remote to finish abort"); + (void)fflush(stdout); longjmp(recvabort, 1); } @@ -797,16 +798,16 @@ recvrequest(cmd, local, remote, lmode, printnames) tcrflag = !crflag && is_retr; if (setjmp(recvabort)) { while (cpend) { - (void) getreply(0); + (void)getreply(0); } if (data >= 0) { - (void) close(data); + (void)close(data); data = -1; } if (oldintr) - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); if (oldinti) - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -818,8 +819,8 @@ recvrequest(cmd, local, remote, lmode, printnames) if (errno != ENOENT && errno != EACCES) { warn("local: %s", local); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -830,30 +831,30 @@ recvrequest(cmd, local, remote, lmode, printnames) *dir = '/'; if (d < 0) { warn("local: %s", local); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } if (!runique && errno == EACCES && chmod(local, 0600) < 0) { warn("local: %s", local); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } if (runique && errno == EACCES && (local = gunique(local)) == NULL) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } } else if (runique && (local = gunique(local)) == NULL) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -867,8 +868,8 @@ recvrequest(cmd, local, remote, lmode, printnames) filesize = remotesize(remote, 0); } if (initconn()) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); code = -1; return; } @@ -879,14 +880,14 @@ recvrequest(cmd, local, remote, lmode, printnames) return; if (remote) { if (command("%s %s", cmd, remote) != PRELIM) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); return; } } else { if (command("%s", cmd) != PRELIM) { - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); return; } } @@ -915,7 +916,7 @@ recvrequest(cmd, local, remote, lmode, printnames) st.st_blksize = BUFSIZ; if (st.st_blksize > bufsize) { if (buf) - (void) free(buf); + (void)free(buf); buf = malloc((unsigned)st.st_blksize); if (buf == NULL) { warn("malloc"); @@ -943,17 +944,17 @@ recvrequest(cmd, local, remote, lmode, printnames) bytes += c; if (hash && (!progress || filesize < 0)) { while (bytes >= hashbytes) { - (void) putchar('#'); + (void)putchar('#'); hashbytes += mark; } - (void) fflush(stdout); + (void)fflush(stdout); } } if (hash && (!progress || filesize < 0) && bytes > 0) { if (bytes < mark) - (void) putchar('#'); - (void) putchar('\n'); - (void) fflush(stdout); + (void)putchar('#'); + (void)putchar('\n'); + (void)fflush(stdout); } if (c < 0) { if (errno != EPIPE) @@ -995,15 +996,15 @@ done: while (c == '\r') { while (hash && (!progress || filesize < 0) && (bytes >= hashbytes)) { - (void) putchar('#'); - (void) fflush(stdout); + (void)putchar('#'); + (void)fflush(stdout); hashbytes += mark; } bytes++; if ((c = getc(din)) != '\n' || tcrflag) { if (ferror(fout)) goto break2; - (void) putc('\r', fout); + (void)putc('\r', fout); if (c == '\0') { bytes++; goto contin2; @@ -1012,21 +1013,21 @@ done: goto contin2; } } - (void) putc(c, fout); + (void)putc(c, fout); bytes++; contin2: ; } break2: if (bare_lfs) { - printf("WARNING! %d bare linefeeds received in ASCII " - "mode\n", bare_lfs); - printf("File may not have transferred correctly.\n"); + printf("WARNING! %d bare linefeeds received in ASCII mode\n", + bare_lfs); + puts("File may not have transferred correctly."); } if (hash && (!progress || filesize < 0)) { if (bytes < hashbytes) - (void) putchar('#'); - (void) putchar('\n'); - (void) fflush(stdout); + (void)putchar('#'); + (void)putchar('\n'); + (void)fflush(stdout); } if (ferror(din)) { if (errno != EPIPE) @@ -1040,26 +1041,25 @@ break2: progressmeter(1); if (closefunc != NULL) (*closefunc)(fout); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); if (oldintp) - (void) signal(SIGPIPE, oldintp); - (void) fclose(din); - (void) getreply(0); + (void)signal(SIGPIPE, oldintp); + (void)fclose(din); + (void)getreply(0); if (bytes >= 0 && is_retr) { if (bytes > 0) ptransfer(0); if (preserve && (closefunc == fclose)) { mtime = remotemodtime(remote, 0); if (mtime != -1) { - (void) gettimeofday(&tval[0], + (void)gettimeofday(&tval[0], (struct timezone *)0); tval[1].tv_sec = mtime; tval[1].tv_usec = 0; if (utimes(local, tval) == -1) { - printf("Can't change modification time " - "on %s to %s", local, - asctime(localtime(&mtime))); + printf("Can't change modification time on %s to %s", + local, asctime(localtime(&mtime))); } } } @@ -1070,29 +1070,29 @@ abort: /* abort using RFC959 recommended IP,SYNC sequence */ if (oldintp) - (void) signal(SIGPIPE, oldintp); - (void) signal(SIGINT, SIG_IGN); + (void)signal(SIGPIPE, oldintp); + (void)signal(SIGINT, SIG_IGN); if (!cpend) { code = -1; - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); return; } abort_remote(din); code = -1; if (data >= 0) { - (void) close(data); + (void)close(data); data = -1; } if (closefunc != NULL && fout != NULL) (*closefunc)(fout); if (din) - (void) fclose(din); + (void)fclose(din); if (bytes > 0) ptransfer(0); - (void) signal(SIGINT, oldintr); - (void) signal(SIGINFO, oldinti); + (void)signal(SIGINT, oldintr); + (void)signal(SIGINFO, oldinti); } /* @@ -1115,10 +1115,10 @@ initconn() } if ((options & SO_DEBUG) && setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, - sizeof (on)) < 0) + sizeof(on)) < 0) warn("setsockopt (ignored)"); if (command("PASV") != COMPLETE) { - printf("Passive mode refused.\n"); + puts("Passive mode refused."); goto bad; } @@ -1132,8 +1132,7 @@ initconn() if (sscanf(pasv, "%d,%d,%d,%d,%d,%d", &a0, &a1, &a2, &a3, &p0, &p1) != 6) { - printf("Passive mode address scan failure. " - "Shouldn't happen!\n"); + puts("Passive mode address scan failure. Shouldn't happen!"); goto bad; } @@ -1167,7 +1166,7 @@ noport: if (sendport) data_addr.sin_port = 0; /* let system pick one */ if (data != -1) - (void) close(data); + (void)close(data); data = socket(AF_INET, SOCK_STREAM, 0); if (data < 0) { warn("socket"); @@ -1177,19 +1176,19 @@ noport: } if (!sendport) if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, - sizeof (on)) < 0) { + sizeof(on)) < 0) { warn("setsockopt (reuse address)"); goto bad; } - if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) { + if (bind(data, (struct sockaddr *)&data_addr, sizeof(data_addr)) < 0) { warn("bind"); goto bad; } if (options & SO_DEBUG && setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, - sizeof (on)) < 0) + sizeof(on)) < 0) warn("setsockopt (ignored)"); - len = sizeof (data_addr); + len = sizeof(data_addr); if (getsockname(data, (struct sockaddr *)&data_addr, &len) < 0) { warn("getsockname"); goto bad; @@ -1220,7 +1219,7 @@ noport: #endif return (0); bad: - (void) close(data), data = -1; + (void)close(data), data = -1; if (tmpno) sendport = 1; return (1); @@ -1231,7 +1230,7 @@ dataconn(lmode) const char *lmode; { struct sockaddr_in from; - int s, fromlen = sizeof (from), tos; + int s, fromlen = sizeof(from), tos; if (passivemode) return (fdopen(data, lmode)); @@ -1239,10 +1238,10 @@ dataconn(lmode) s = accept(data, (struct sockaddr *) &from, &fromlen); if (s < 0) { warn("accept"); - (void) close(data), data = -1; + (void)close(data), data = -1; return (NULL); } - (void) close(data); + (void)close(data); data = s; #ifdef IP_TOS tos = IPTOS_THROUGHPUT; @@ -1314,10 +1313,10 @@ pswitch(flag) ip->connect = connected; connected = op->connect; if (hostname) { - (void) strncpy(ip->name, hostname, sizeof(ip->name) - 1); - ip->name[strlen(ip->name)] = '\0'; + (void)strncpy(ip->name, hostname, sizeof(ip->name) - 1); + ip->name[sizeof(ip->name) - 1] = '\0'; } else - ip->name[0] = 0; + ip->name[0] = '\0'; hostname = op->name; ip->hctl = hisctladdr; hisctladdr = op->hctl; @@ -1341,21 +1340,21 @@ pswitch(flag) mcase = op->mcse; ip->ntflg = ntflag; ntflag = op->ntflg; - (void) strncpy(ip->nti, ntin, 16); - (ip->nti)[strlen(ip->nti)] = '\0'; - (void) strcpy(ntin, op->nti); - (void) strncpy(ip->nto, ntout, 16); - (ip->nto)[strlen(ip->nto)] = '\0'; - (void) strcpy(ntout, op->nto); + (void)strncpy(ip->nti, ntin, sizeof(ip->nti) - 1); + (ip->nti)[sizeof(ip->nti) - 1] = '\0'; + (void)strcpy(ntin, op->nti); + (void)strncpy(ip->nto, ntout, sizeof(ip->nto) - 1); + (ip->nto)[sizeof(ip->nto) - 1] = '\0'; + (void)strcpy(ntout, op->nto); ip->mapflg = mapflag; mapflag = op->mapflg; - (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1); - (ip->mi)[strlen(ip->mi)] = '\0'; - (void) strcpy(mapin, op->mi); - (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1); - (ip->mo)[strlen(ip->mo)] = '\0'; - (void) strcpy(mapout, op->mo); - (void) signal(SIGINT, oldintr); + (void)strncpy(ip->mi, mapin, sizeof(ip->mi) - 1); + (ip->mi)[sizeof(ip->mi) - 1] = '\0'; + (void)strcpy(mapin, op->mi); + (void)strncpy(ip->mo, mapout, sizeof(ip->mo) - 1); + (ip->mo)[sizeof(ip->mo) - 1] = '\0'; + (void)strcpy(mapout, op->mo); + (void)signal(SIGINT, oldintr); if (abrtflag) { abrtflag = 0; (*oldintr)(SIGINT); @@ -1367,8 +1366,8 @@ abortpt() { alarmtimer(0); - printf("\n"); - (void) fflush(stdout); + putchar('\n'); + (void)fflush(stdout); ptabflg++; mflag = 0; abrtflag = 0; @@ -1397,13 +1396,12 @@ proxtrans(cmd, local, remote) if (curtype != prox_type) changetype(prox_type, 1); if (command("PASV") != COMPLETE) { - printf("proxy server does not support third party " - "transfers.\n"); + puts("proxy server does not support third party transfers."); return; } pswitch(0); if (!connected) { - printf("No primary connection\n"); + puts("No primary connection"); pswitch(1); code = -1; return; @@ -1418,7 +1416,7 @@ proxtrans(cmd, local, remote) goto abort; oldintr = signal(SIGINT, abortpt); if (command("%s %s", cmd, remote) != PRELIM) { - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); pswitch(1); return; } @@ -1428,16 +1426,16 @@ proxtrans(cmd, local, remote) if (command("%s %s", cmd2, local) != PRELIM) goto abort; ptflag++; - (void) getreply(0); + (void)getreply(0); pswitch(0); - (void) getreply(0); - (void) signal(SIGINT, oldintr); + (void)getreply(0); + (void)signal(SIGINT, oldintr); pswitch(1); ptflag = 0; printf("local: %s remote: %s\n", local, remote); return; abort: - (void) signal(SIGINT, SIG_IGN); + (void)signal(SIGINT, SIG_IGN); ptflag = 0; if (strcmp(cmd, "RETR") && !proxy) pswitch(1); @@ -1452,7 +1450,7 @@ abort: pswitch(1); if (ptabflg) code = -1; - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); return; } if (cpend) @@ -1466,7 +1464,7 @@ abort: pswitch(1); if (ptabflg) code = -1; - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); return; } } @@ -1484,15 +1482,15 @@ abort: code = -1; lostpeer(); } - (void) getreply(0); - (void) getreply(0); + (void)getreply(0); + (void)getreply(0); } if (proxy) pswitch(0); pswitch(1); if (ptabflg) code = -1; - (void) signal(SIGINT, oldintr); + (void)signal(SIGINT, oldintr); } void @@ -1512,7 +1510,7 @@ reset(argc, argv) lostpeer(); } else if (nfnd) { - (void) getreply(0); + (void)getreply(0); } } } @@ -1535,12 +1533,12 @@ gunique(local) warn("local: %s", local); return ((char *) 0); } - (void) strcpy(new, local); + (void)strcpy(new, local); cp = new + strlen(new); *cp++ = '.'; while (!d) { if (++count == 100) { - printf("runique: can't find unique file name.\n"); + puts("runique: can't find unique file name."); return ((char *) 0); } *cp++ = ext; @@ -1579,7 +1577,7 @@ abort_remote(din) if (send(fileno(cout), buf, 3, MSG_OOB) != 3) warn("abort"); fprintf(cout, "%cABOR\r\n", DM); - (void) fflush(cout); + (void)fflush(cout); FD_ZERO(&mask); FD_SET(fileno(cin), &mask); if (din) { @@ -1599,7 +1597,7 @@ abort_remote(din) } if (getreply(0) == ERROR && code == 552) { /* 552 needed for nic style abort */ - (void) getreply(0); + (void)getreply(0); } - (void) getreply(0); + (void)getreply(0); } diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h index 3132ccf6e6a..a9921b1f50f 100644 --- a/usr.bin/ftp/ftp_var.h +++ b/usr.bin/ftp/ftp_var.h @@ -1,3 +1,4 @@ +/* $OpenBSD: ftp_var.h,v 1.7 1997/02/03 01:05:41 millert Exp $ */ /* $NetBSD: ftp_var.h,v 1.13 1997/02/01 10:45:05 lukem Exp $ */ /* @@ -41,12 +42,12 @@ #include #include -#include #ifndef SMALLFTP #include #endif /* !SMALLFTP */ +#include "stringlist.h" #include "extern.h" #define HASHBYTES 1024 @@ -104,6 +105,7 @@ char bytename[32]; /* local byte size in ascii */ int bytesize; /* local byte size in binary */ int anonftp; /* automatic anonymous login */ int dirchange; /* remote directory changed by cd command */ +int retry_connect; /* retry connect if failed */ int ttywidth; /* width of tty */ #ifndef SMALLFTP diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index 7896f9f1423..f1c302f05cf 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,3 +1,4 @@ +/* $OpenBSD: main.c,v 1.18 1997/02/03 01:05:42 millert Exp $ */ /* $NetBSD: main.c,v 1.17 1997/02/01 10:45:07 lukem Exp $ */ /* @@ -43,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.17 1997/02/01 10:45:07 lukem Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.18 1997/02/03 01:05:42 millert Exp $"; #endif #endif /* not lint */ @@ -53,10 +54,12 @@ static char rcsid[] = "$NetBSD: main.c,v 1.17 1997/02/01 10:45:07 lukem Exp $"; #include #include +#include #include #include #include #include +#include #include #include @@ -103,7 +106,7 @@ main(argc, argv) if (isatty(fileno(stdout))) progress = 1; /* progress bar on if going to a tty */ - while ((ch = getopt(argc, argv, "adginpP:tvV")) != EOF) { + while ((ch = getopt(argc, argv, "adginpPr:tvV")) != -1) { switch (ch) { case 'a': anonftp = 1; @@ -133,11 +136,18 @@ main(argc, argv) case 'P': port = atoi(optarg); if (port <= 0) - warnx("bad port number: %s", optarg); + warnx("bad port number: %s (ignored)", optarg); else ftpport = htons(port); break; + case 'r': + if (isdigit(*optarg)) + retry_connect = atoi(optarg); + else + errx(1, "-r requires numeric argument"); + break; + case 't': trace = 1; break; @@ -172,7 +182,7 @@ main(argc, argv) pw = getpwuid(getuid()); if (pw != NULL) { home = homedir; - (void) strcpy(home, pw->pw_dir); + (void)strcpy(home, pw->pw_dir); } #ifndef SMALLFTP @@ -199,7 +209,7 @@ main(argc, argv) #endif /* !SMALLFTP */ setttywidth(0); - (void) signal(SIGWINCH, setttywidth); + (void)signal(SIGWINCH, setttywidth); if (argc > 0) { if (strchr(argv[0], ':') != NULL) { @@ -212,20 +222,29 @@ main(argc, argv) if (setjmp(toplevel)) exit(0); - (void) signal(SIGINT, intr); - (void) signal(SIGPIPE, lostpeer); + (void)signal(SIGINT, intr); + (void)signal(SIGPIPE, lostpeer); xargv[0] = __progname; xargv[1] = argv[0]; xargv[2] = argv[1]; xargv[3] = argv[2]; xargv[4] = NULL; - setpeer(argc+1, xargv); + do { + setpeer(argc+1, xargv); + if (!retry_connect) + break; + if (!connected) { + macnum = 0; + puts("Retrying..."); + sleep(retry_connect); + } + } while (!connected); } } top = setjmp(toplevel) == 0; if (top) { - (void) signal(SIGINT, intr); - (void) signal(SIGPIPE, lostpeer); + (void)signal(SIGINT, intr); + (void)signal(SIGPIPE, lostpeer); } for (;;) { cmdscanner(top); @@ -248,13 +267,13 @@ lostpeer() alarmtimer(0); if (connected) { if (cout != NULL) { - (void) shutdown(fileno(cout), 1+1); - (void) fclose(cout); + (void)shutdown(fileno(cout), 1+1); + (void)fclose(cout); cout = NULL; } if (data >= 0) { - (void) shutdown(data, 1+1); - (void) close(data); + (void)shutdown(data, 1+1); + (void)close(data); data = -1; } connected = 0; @@ -262,8 +281,8 @@ lostpeer() pswitch(1); if (connected) { if (cout != NULL) { - (void) shutdown(fileno(cout), 1+1); - (void) fclose(cout); + (void)shutdown(fileno(cout), 1+1); + (void)fclose(cout); cout = NULL; } connected = 0; @@ -296,14 +315,14 @@ cmdscanner(top) && !editing #endif /* !SMALLFTP */ ) - (void) putchar('\n'); + (void)putchar('\n'); for (;;) { #ifndef SMALLFTP if (!editing) { #endif /* !SMALLFTP */ if (fromatty) { - printf("%s", prompt()); - (void) fflush(stdout); + fputs(prompt(), stdout); + (void)fflush(stdout); } if (fgets(line, sizeof(line), stdin) == NULL) quit(0, 0); @@ -315,7 +334,7 @@ cmdscanner(top) break; line[num] = '\0'; } else if (num == sizeof(line) - 2) { - printf("sorry, input line too long\n"); + puts("sorry, input line too long"); while ((num = getchar()) != '\n' && num != EOF) /* void */; break; @@ -331,7 +350,7 @@ cmdscanner(top) if (num == 0) break; } else if (num >= sizeof(line)) { - printf("sorry, input line too long\n"); + puts("sorry, input line too long"); break; } memcpy(line, buf, num); @@ -353,26 +372,26 @@ cmdscanner(top) #endif /* !SMALLFTP */ c = getcmd(margv[0]); if (c == (struct cmd *)-1) { - printf("?Ambiguous command\n"); + puts("?Ambiguous command"); continue; } if (c == 0) { - printf("?Invalid command\n"); + puts("?Invalid command"); continue; } if (c->c_conn && !connected) { - printf("Not connected.\n"); + puts("Not connected."); continue; } confirmrest = 0; (*c->c_handler)(margc, margv); if (bell && c->c_bell) - (void) putchar('\007'); + (void)putchar('\007'); if (c->c_handler != help) break; } - (void) signal(SIGINT, intr); - (void) signal(SIGPIPE, lostpeer); + (void)signal(SIGINT, intr); + (void)signal(SIGPIPE, lostpeer); } struct cmd * @@ -609,7 +628,7 @@ help(argc, argv) return; } -#define HELPINDENT ((int) sizeof ("disconnect")) +#define HELPINDENT ((int) sizeof("disconnect")) while (--argc > 0) { char *arg; @@ -630,7 +649,7 @@ void usage() { (void)fprintf(stderr, - "usage: %s [-adginptvV] [host [port]]\n" + "usage: %s [-adginprtvV] [host [port]]\n" " %s host:path[/]\n" " %s ftp://host[:port]/path[/]\n" " %s http://host[:port]/file\n", diff --git a/usr.bin/ftp/pathnames.h b/usr.bin/ftp/pathnames.h index e028658e736..575b5131450 100644 --- a/usr.bin/ftp/pathnames.h +++ b/usr.bin/ftp/pathnames.h @@ -1,3 +1,4 @@ +/* $OpenBSD: pathnames.h,v 1.5 1997/02/03 01:05:43 millert Exp $ */ /* $NetBSD: pathnames.h,v 1.7 1997/01/09 20:19:40 tls Exp $ */ /* diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c index e8312df2d31..ebec996c0f8 100644 --- a/usr.bin/ftp/ruserpass.c +++ b/usr.bin/ftp/ruserpass.c @@ -1,3 +1,4 @@ +/* $OpenBSD: ruserpass.c,v 1.5 1997/02/03 01:05:44 millert Exp $ */ /* $NetBSD: ruserpass.c,v 1.11 1997/01/19 14:19:16 lukem Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$NetBSD: ruserpass.c,v 1.11 1997/01/19 14:19:16 lukem Exp $"; +static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.5 1997/02/03 01:05:44 millert Exp $"; #endif #endif /* not lint */ @@ -95,7 +96,7 @@ ruserpass(host, aname, apass, aacct) if (hdir == NULL) hdir = "."; if (strlen(hdir) + sizeof(".netrc") < sizeof(buf)) { - (void) sprintf(buf, "%s/.netrc", hdir); + (void)sprintf(buf, "%s/.netrc", hdir); } else { warnx("%s/.netrc: %s", hdir, strerror(ENAMETOOLONG)); return (0); @@ -150,7 +151,7 @@ next: if (*aname == 0) { *aname = malloc((unsigned) strlen(tokval) + 1); - (void) strcpy(*aname, tokval); + (void)strcpy(*aname, tokval); } else { if (strcmp(*aname, tokval)) goto next; @@ -166,7 +167,7 @@ next: } if (token() && *apass == 0) { *apass = malloc((unsigned) strlen(tokval) + 1); - (void) strcpy(*apass, tokval); + (void)strcpy(*apass, tokval); } break; case ACCOUNT: @@ -178,24 +179,24 @@ next: } if (token() && *aacct == 0) { *aacct = malloc((unsigned) strlen(tokval) + 1); - (void) strcpy(*aacct, tokval); + (void)strcpy(*aacct, tokval); } break; case MACDEF: if (proxy) { - (void) fclose(cfile); + (void)fclose(cfile); return (0); } while ((c=getc(cfile)) != EOF) if (c != ' ' && c != '\t') break; if (c == EOF || c == '\n') { - printf("Missing macdef name argument.\n"); + puts("Missing macdef name argument."); goto bad; } if (macnum == 16) { - printf( -"Limit of 16 macros have already been defined\n"); + puts( +"Limit of 16 macros have already been defined"); goto bad; } tmp = macros[macnum].mac_name; @@ -205,8 +206,8 @@ next: *tmp++ = c; } if (c == EOF) { - printf( -"Macro definition missing null line terminator.\n"); + puts( +"Macro definition missing null line terminator."); goto bad; } *tmp = '\0'; @@ -214,8 +215,8 @@ next: while ((c=getc(cfile)) != EOF && c != '\n'); } if (c == EOF) { - printf( -"Macro definition missing null line terminator.\n"); + puts( +"Macro definition missing null line terminator."); goto bad; } if (macnum == 0) { @@ -228,8 +229,8 @@ next: tmp = macros[macnum].mac_start; while (tmp != macbuf + 4096) { if ((c=getc(cfile)) == EOF) { - printf( -"Macro definition missing null line terminator.\n"); + puts( +"Macro definition missing null line terminator."); goto bad; } *tmp = c; @@ -243,7 +244,7 @@ next: tmp++; } if (tmp == macbuf + 4096) { - printf("4K macro buffer exceeded\n"); + puts("4K macro buffer exceeded"); goto bad; } break; @@ -254,10 +255,10 @@ next: goto done; } done: - (void) fclose(cfile); + (void)fclose(cfile); return (0); bad: - (void) fclose(cfile); + (void)fclose(cfile); return (-1); } diff --git a/usr.bin/ftp/stringlist.c b/usr.bin/ftp/stringlist.c new file mode 100644 index 00000000000..a95735dd11f --- /dev/null +++ b/usr.bin/ftp/stringlist.c @@ -0,0 +1,122 @@ +/* $OpenBSD: stringlist.c,v 1.1 1997/02/03 01:05:44 millert Exp $ */ +/* $NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $ */ + +/* + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: stringlist.c,v 1.1 1997/02/03 01:05:44 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#include "stringlist.h" + +#define _SL_CHUNKSIZE 20 + +/* + * sl_init(): Initialize a string list + */ +StringList * +sl_init() +{ + StringList *sl = malloc(sizeof(StringList)); + if (sl == NULL) + _err(1, "stringlist: %m"); + + sl->sl_cur = 0; + sl->sl_max = _SL_CHUNKSIZE; + sl->sl_str = malloc(sl->sl_max * sizeof(char *)); + if (sl->sl_str == NULL) + _err(1, "stringlist: %m"); + return sl; +} + + +/* + * sl_add(): Add an item to the string list + */ +void +sl_add(sl, name) + StringList *sl; + char *name; +{ + if (sl->sl_cur == sl->sl_max - 1) { + sl->sl_max += _SL_CHUNKSIZE; + sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *)); + if (sl->sl_str == NULL) + _err(1, "stringlist: %m"); + } + sl->sl_str[sl->sl_cur++] = name; +} + + +/* + * sl_free(): Free a stringlist + */ +void +sl_free(sl, all) + StringList *sl; + int all; +{ + size_t i; + + if (sl == NULL) + return; + if (sl->sl_str) { + if (all) + for (i = 0; i < sl->sl_cur; i++) + free(sl->sl_str[i]); + free(sl->sl_str); + } + free(sl); +} + + +/* + * sl_find(): Find a name in the string list + */ +char * +sl_find(sl, name) + StringList *sl; + char *name; +{ + size_t i; + + for (i = 0; i < sl->sl_cur; i++) + if (strcmp(sl->sl_str[i], name) == 0) + return sl->sl_str[i]; + + return NULL; +} diff --git a/usr.bin/ftp/stringlist.h b/usr.bin/ftp/stringlist.h new file mode 100644 index 00000000000..8d8f0dd3a81 --- /dev/null +++ b/usr.bin/ftp/stringlist.h @@ -0,0 +1,57 @@ +/* $OpenBSD: stringlist.h,v 1.1 1997/02/03 01:05:45 millert Exp $ */ +/* $NetBSD: stringlist.h,v 1.2 1997/01/17 06:11:36 lukem Exp $ */ + +/* + * Copyright (c) 1994 Christos Zoulas + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _STRINGLIST_H +#define _STRINGLIST_H + +#include +#include + +/* + * Simple string list + */ +typedef struct _stringlist { + char **sl_str; + size_t sl_max; + size_t sl_cur; +} StringList; + +__BEGIN_DECLS +StringList *sl_init __P((void)); +void sl_add __P((StringList *, char *)); +void sl_free __P((StringList *, int)); +char *sl_find __P((StringList *, char *)); +__END_DECLS + +#endif /* _STRINGLIST_H */ diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 5d9c7ecd1fc..f92ad950369 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,3 +1,4 @@ +/* $OpenBSD: util.c,v 1.2 1997/02/03 01:05:46 millert Exp $ */ /* $NetBSD: util.c,v 1.4 1997/02/01 11:26:34 lukem Exp $ */ /* @@ -34,7 +35,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: util.c,v 1.4 1997/02/01 11:26:34 lukem Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.2 1997/02/03 01:05:46 millert Exp $"; #endif /* not lint */ /* @@ -49,6 +50,7 @@ static char rcsid[] = "$NetBSD: util.c,v 1.4 1997/02/01 11:26:34 lukem Exp $"; #include #include #include +#include #include #include #include @@ -70,12 +72,12 @@ setpeer(argc, argv) if (connected) { printf("Already connected to %s, use close first.\n", - hostname); + hostname); code = -1; return; } if (argc < 2) - (void) another(&argc, &argv, "to"); + (void)another(&argc, &argv, "to"); if (argc < 2 || argc > 3) { printf("usage: %s host-name [port]\n", argv[0]); code = -1; @@ -100,15 +102,20 @@ setpeer(argc, argv) /* * Set up defaults for FTP. */ - (void) strcpy(typename, "ascii"), type = TYPE_A; + (void)strcpy(typename, "ascii"), type = TYPE_A; curtype = TYPE_A; - (void) strcpy(formname, "non-print"), form = FORM_N; - (void) strcpy(modename, "stream"), mode = MODE_S; - (void) strcpy(structname, "file"), stru = STRU_F; - (void) strcpy(bytename, "8"), bytesize = 8; + (void)strcpy(formname, "non-print"), form = FORM_N; + (void)strcpy(modename, "stream"), mode = MODE_S; + (void)strcpy(structname, "file"), stru = STRU_F; + (void)strcpy(bytename, "8"), bytesize = 8; if (autologin) - (void) login(argv[1]); + (void)login(argv[1]); +#if (defined(unix) || defined(BSD)) && NBBY == 8 +/* + * this ifdef is to keep someone form "porting" this to an incompatible + * system and not checking this out. This way they have to think about it. + */ overbose = verbose; if (debug == 0) verbose = -1; @@ -125,8 +132,7 @@ setpeer(argc, argv) *cp = '\0'; } - printf("Remote system type is %s.\n", - reply_string+4); + printf("Remote system type is %s.\n", reply_string + 4); if (cp) *cp = c; } @@ -142,7 +148,7 @@ setpeer(argc, argv) * for text files unless changed by the user. */ type = 0; - (void) strcpy(typename, "binary"); + (void)strcpy(typename, "binary"); if (overbose) printf("Using %s mode to transfer files.\n", typename); @@ -153,11 +159,11 @@ setpeer(argc, argv) unix_server = 0; if (overbose && !strncmp(reply_string, "215 TOPS20", 10)) - printf("Remember to set tenex mode when " - "transferring binary files from this " - "machine.\n"); + puts( +"Remember to set tenex mode when transferring binary files from this machine."); } verbose = overbose; +#endif /* unix || BSD */ } } @@ -176,7 +182,7 @@ another(pargc, pargv, prompt) int len = strlen(line), ret; if (len >= sizeof(line) - 3) { - printf("sorry, arguments too long\n"); + puts("sorry, arguments too long"); intr(); } printf("(%s) ", prompt); @@ -211,7 +217,7 @@ remglob(argv, doswitch) } else { if (ftemp) { - (void) fclose(ftemp); + (void)fclose(ftemp); ftemp = NULL; } } @@ -225,7 +231,7 @@ remglob(argv, doswitch) return (cp); } if (ftemp == NULL) { - (void) snprintf(temp, sizeof(temp), "%s%s", _PATH_TMP, TMPFILE) + (void)snprintf(temp, sizeof(temp), "%s%s", _PATH_TMP, TMPFILE) ; fd = mkstemp(temp); if (fd < 0) { @@ -245,14 +251,14 @@ remglob(argv, doswitch) } verbose = oldverbose; hash = oldhash; ftemp = fopen(temp, "r"); - (void) unlink(temp); + (void)unlink(temp); if (ftemp == NULL) { - printf("can't find list of remote files, oops\n"); + puts("can't find list of remote files, oops"); return (NULL); } } - if (fgets(buf, sizeof (buf), ftemp) == NULL) { - (void) fclose(ftemp), ftemp = NULL; + if (fgets(buf, sizeof(buf), ftemp) == NULL) { + (void)fclose(ftemp), ftemp = NULL; return (NULL); } if ((cp = strchr(buf, '\n')) != NULL) @@ -269,7 +275,7 @@ confirm(cmd, file) if (!interactive || confirmrest) return (1); printf("%s %s? ", cmd, file); - (void) fflush(stdout); + (void)fflush(stdout); if (fgets(line, sizeof(line), stdin) == NULL) return (0); switch (tolower(*line)) { @@ -277,7 +283,7 @@ confirm(cmd, file) return (0); case 'p': interactive = 0; - printf("Interactive mode: off\n"); + puts("Interactive mode: off"); break; case 'a': confirmrest = 1; @@ -373,7 +379,7 @@ remotemodtime(file, noisy) else rtime += timebuf.tm_gmtoff; /* conv. local -> GMT */ } else if (noisy && debug == 0) - printf("%s\n", reply_string); + puts(reply_string); verbose = overbose; return (rtime); } @@ -416,11 +422,11 @@ progressmeter(flag) char buf[256]; if (flag == -1) { - (void) gettimeofday(&start, (struct timezone *)0); + (void)gettimeofday(&start, (struct timezone *)0); lastupdate = start; lastsize = restart_point; } - (void) gettimeofday(&now, (struct timezone *)0); + (void)gettimeofday(&now, (struct timezone *)0); if (!progress || filesize <= 0) return; cursize = bytes + restart_point; @@ -487,11 +493,11 @@ progressmeter(flag) (void)write(STDOUT_FILENO, buf, strlen(buf)); if (flag == -1) { - (void) signal(SIGALRM, updateprogressmeter); + (void)signal(SIGALRM, updateprogressmeter); alarmtimer(1); /* set alarm timer for 1 Hz */ } else if (flag == 1) { alarmtimer(0); - (void) putchar('\n'); + (void)putchar('\n'); } fflush(stdout); } @@ -517,7 +523,7 @@ ptransfer(siginfo) if (!verbose && !siginfo) return; - (void) gettimeofday(&now, (struct timezone *)0); + (void)gettimeofday(&now, (struct timezone *)0); timersub(&now, &start, &td); elapsed = td.tv_sec + (td.tv_usec / 1000000.0); bs = bytes / (elapsed == 0.0 ? 1 : elapsed); @@ -568,15 +574,15 @@ list_vertical(sl) for (j = 0; j < columns; j++) { p = sl->sl_str[j * lines + i]; if (p) - printf("%s", p); + fputs(p, stdout); if (j * lines + i + lines >= sl->sl_cur) { - printf("\n"); + putchar('\n'); break; } w = strlen(p); while (w < width) { w = (w + 8) &~ 7; - (void) putchar('\t'); + (void)putchar('\t'); } } }