diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-04-23 20:33:25 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-04-23 20:33:25 +0000 |
commit | 616dc84ff029620576cad6e2345c4de438fb3ea2 (patch) | |
tree | 3b3f7fa0e86c10bdb1340cb42513b33defde04b7 /usr.bin/ftp/cmds.c | |
parent | 7d750354839939345823f4fd6e1d98eb5b3f2fc5 (diff) |
allow "ftp -aV ftp://host/foo.tar.gz | tar xvfpz -" to work
Diffstat (limited to 'usr.bin/ftp/cmds.c')
-rw-r--r-- | usr.bin/ftp/cmds.c | 205 |
1 files changed, 103 insertions, 102 deletions
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index 23dfa9423eb..cadf58742f6 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmds.c,v 1.19 1997/04/16 05:02:39 millert Exp $ */ +/* $OpenBSD: cmds.c,v 1.20 1997/04/23 20:32:57 deraadt Exp $ */ /* $NetBSD: cmds.c,v 1.23 1997/04/14 09:09:15 lukem Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmds.c,v 1.19 1997/04/16 05:02:39 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.20 1997/04/23 20:32:57 deraadt Exp $"; #endif #endif /* not lint */ @@ -95,18 +95,18 @@ settype(argc, argv) if (argc > 2) { char *sep; - printf("usage: %s [", argv[0]); + fprintf(ttyout, "usage: %s [", argv[0]); sep = " "; for (p = types; p->t_name; p++) { - printf("%s%s", sep, p->t_name); + fprintf(ttyout, "%s%s", sep, p->t_name); sep = " | "; } - puts(" ]"); + fputs(" ]\n", ttyout); code = -1; return; } if (argc < 2) { - printf("Using %s mode to transfer files.\n", typename); + fprintf(ttyout, "Using %s mode to transfer files.\n", typename); code = 0; return; } @@ -114,7 +114,7 @@ settype(argc, argv) if (strcmp(argv[1], p->t_name) == 0) break; if (p->t_name == 0) { - printf("%s: unknown mode.\n", argv[1]); + fprintf(ttyout, "%s: unknown mode.\n", argv[1]); code = -1; return; } @@ -220,7 +220,7 @@ setftmode(argc, argv) char *argv[]; { - printf("We only support %s mode, sorry.\n", modename); + fprintf(ttyout, "We only support %s mode, sorry.\n", modename); code = -1; } @@ -234,7 +234,7 @@ setform(argc, argv) char *argv[]; { - printf("We only support %s format, sorry.\n", formname); + fprintf(ttyout, "We only support %s format, sorry.\n", formname); code = -1; } @@ -248,7 +248,7 @@ setstruct(argc, argv) char *argv[]; { - printf("We only support %s structure, sorry.\n", structname); + fprintf(ttyout, "We only support %s structure, sorry.\n", structname); code = -1; } @@ -273,7 +273,7 @@ put(argc, argv) goto usage; if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) { usage: - printf("usage: %s local-file [ remote-file ]\n", argv[0]); + fprintf(ttyout, "usage: %s local-file [ remote-file ]\n", argv[0]); code = -1; return; } @@ -315,7 +315,7 @@ mput(argc, argv) char *tp; if (argc < 2 && !another(&argc, &argv, "local-files")) { - printf("usage: %s local-files\n", argv[0]); + fprintf(ttyout, "usage: %s local-files\n", argv[0]); code = -1; return; } @@ -464,7 +464,7 @@ getit(argc, argv, restartit, mode) goto usage; if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) { usage: - printf("usage: %s remote-file [ local-file ]\n", argv[0]); + fprintf(ttyout, "usage: %s remote-file [ local-file ]\n", argv[0]); code = -1; return (0); } @@ -535,8 +535,8 @@ mabort(signo) int ointer, oconf; alarmtimer(0); - putchar('\n'); - (void)fflush(stdout); + putc('\n', ttyout); + (void)fflush(ttyout); if (mflag && fromatty) { ointer = interactive; oconf = confirmrest; @@ -567,7 +567,7 @@ mget(argc, argv) char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN]; if (argc < 2 && !another(&argc, &argv, "remote-files")) { - printf("usage: %s remote-files\n", argv[0]); + fprintf(ttyout, "usage: %s remote-files\n", argv[0]); code = -1; return; } @@ -630,53 +630,53 @@ status(argc, argv) int i; if (connected) - printf("Connected %sto %s.\n", + fprintf(ttyout, "Connected %sto %s.\n", connected == -1 ? "and logged in" : "", hostname); else - puts("Not connected."); + fputs("Not connected.\n", ttyout); if (!proxy) { pswitch(1); if (connected) { - printf("Connected for proxy commands to %s.\n", + fprintf(ttyout, "Connected for proxy commands to %s.\n", hostname); } else { - puts("No proxy connection."); + fputs("No proxy connection.\n", ttyout); } pswitch(0); } - printf("Passive mode: %s.\n", onoff(passivemode)); - printf("Mode: %s; Type: %s; Form: %s; Structure: %s.\n", + fprintf(ttyout, "Passive mode: %s.\n", onoff(passivemode)); + fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n", modename, typename, formname, structname); - printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n", + fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n", onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob)); - printf("Store unique: %s; Receive unique: %s.\n", onoff(sunique), + fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n", onoff(sunique), onoff(runique)); - printf("Preserve modification times: %s.\n", onoff(preserve)); - printf("Case: %s; CR stripping: %s.\n", onoff(mcase), onoff(crflag)); + fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve)); + fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase), onoff(crflag)); if (ntflag) { - printf("Ntrans: (in) %s (out) %s\n", ntin, ntout); + fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout); } else { - puts("Ntrans: off."); + fputs("Ntrans: off.\n", ttyout); } if (mapflag) { - printf("Nmap: (in) %s (out) %s\n", mapin, mapout); + fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout); } else { - puts("Nmap: off."); + fputs("Nmap: off.\n", ttyout); } - printf("Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n", + fprintf(ttyout, "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n", onoff(hash), mark, onoff(progress)); - printf("Use of PORT cmds: %s.\n", onoff(sendport)); + fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport)); #ifndef SMALL - printf("Command line editing: %s.\n", onoff(editing)); + fprintf(ttyout, "Command line editing: %s.\n", onoff(editing)); #endif /* !SMALL */ if (macnum > 0) { - puts("Macros:"); + fputs("Macros:", ttyout); for (i=0; i<macnum; i++) { - printf("\t%s\n", macros[i].mac_name); + fprintf(ttyout, "\t%s\n", macros[i].mac_name); } } code = 0; @@ -699,11 +699,11 @@ togglevar(argc, argv, var, mesg) } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) { *var = 0; } else { - printf("usage: %s [ on | off ]\n", argv[0]); + fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]); return (-1); } if (mesg) - printf("%s %s.\n", mesg, onoff(*var)); + fprintf(ttyout, "%s %s.\n", mesg, onoff(*var)); return (*var); } @@ -761,7 +761,7 @@ sethash(argc, argv) if (argc == 1) hash = !hash; else if (argc != 2) { - printf("usage: %s [ on | off | bytecount ]\n", argv[0]); + fprintf(ttyout, "usage: %s [ on | off | bytecount ]\n", argv[0]); code = -1; return; } else if (strcasecmp(argv[1], "on") == 0) @@ -771,17 +771,17 @@ sethash(argc, argv) else { int nmark = atol(argv[1]); if (nmark < 1) { - printf("%s: bad bytecount value.\n", argv[1]); + fprintf(ttyout, "%s: bad bytecount value.\n", argv[1]); code = -1; return; } mark = nmark; hash = 1; } - printf("Hash mark printing %s", onoff(hash)); + fprintf(ttyout, "Hash mark printing %s", onoff(hash)); if (hash) - printf(" (%d bytes/hash mark)", mark); - puts("."); + fprintf(ttyout, " (%d bytes/hash mark)", mark); + fputs(".\n", ttyout); code = hash; } @@ -878,7 +878,7 @@ setdebug(argc, argv) int val; if (argc > 2) { - printf("usage: %s [ on | off | debuglevel ]\n", argv[0]); + fprintf(ttyout, "usage: %s [ on | off | debuglevel ]\n", argv[0]); code = -1; return; } else if (argc == 2) { @@ -889,7 +889,7 @@ setdebug(argc, argv) else { val = atoi(argv[1]); if (val < 0) { - printf("%s: bad debugging value.\n", argv[1]); + fprintf(ttyout, "%s: bad debugging value.\n", argv[1]); code = -1; return; } @@ -901,7 +901,7 @@ setdebug(argc, argv) options |= SO_DEBUG; else options &= ~SO_DEBUG; - printf("Debugging %s (debug=%d).\n", onoff(debug), debug); + fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(debug), debug); code = debug > 0; } @@ -918,14 +918,14 @@ cd(argc, argv) if ((argc < 2 && !another(&argc, &argv, "remote-directory")) || argc > 2) { - printf("usage: %s remote-directory\n", argv[0]); + fprintf(ttyout, "usage: %s remote-directory\n", argv[0]); code = -1; return; } r = command("CWD %s", argv[1]); if (r == ERROR && code == 500) { if (verbose) - puts("CWD command not recognized, trying XCWD."); + fputs("CWD command not recognized, trying XCWD.\n", ttyout); r = command("XCWD %s", argv[1]); } if (r == COMPLETE) @@ -946,7 +946,7 @@ lcd(argc, argv) if (argc < 2) argc++, argv[1] = home; if (argc != 2) { - printf("usage: %s local-directory\n", argv[0]); + fprintf(ttyout, "usage: %s local-directory\n", argv[0]); code = -1; return; } @@ -960,7 +960,7 @@ lcd(argc, argv) return; } if (getcwd(buf, sizeof(buf)) != NULL) - printf("Local directory now %s\n", buf); + fprintf(ttyout, "Local directory now %s\n", buf); else warn("getcwd: %s", argv[1]); code = 0; @@ -976,7 +976,7 @@ delete(argc, argv) { if ((argc < 2 && !another(&argc, &argv, "remote-file")) || argc > 2) { - printf("usage: %s remote-file\n", argv[0]); + fprintf(ttyout, "usage: %s remote-file\n", argv[0]); code = -1; return; } @@ -996,7 +996,7 @@ mdelete(argc, argv) char *cp; if (argc < 2 && !another(&argc, &argv, "remote-files")) { - printf("usage: %s remote-files\n", argv[0]); + fprintf(ttyout, "usage: %s remote-files\n", argv[0]); code = -1; return; } @@ -1038,7 +1038,7 @@ renamefile(argc, argv) goto usage; if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) { usage: - printf("usage: %s from-name to-name\n", argv[0]); + fprintf(ttyout, "usage: %s from-name to-name\n", argv[0]); code = -1; return; } @@ -1062,7 +1062,7 @@ ls(argc, argv) if (argc < 3) argc++, argv[2] = "-"; if (argc > 3) { - printf("usage: %s remote-directory local-file\n", argv[0]); + fprintf(ttyout, "usage: %s remote-directory local-file\n", argv[0]); code = -1; return; } @@ -1080,7 +1080,7 @@ ls(argc, argv) recvrequest(cmd, argv[2], argv[1], "w", 0); /* flush results in case commands are coming from a pipe */ - fflush(stdout); + fflush(ttyout); } /* @@ -1101,7 +1101,7 @@ mls(argc, argv) goto usage; if (argc < 3 && !another(&argc, &argv, "local-file")) { usage: - printf("usage: %s remote-files local-file\n", argv[0]); + fprintf(ttyout, "usage: %s remote-files local-file\n", argv[0]); code = -1; return; } @@ -1167,8 +1167,9 @@ shell(argc, argv) if (strcmp(namep, "sh") != 0) shellnam[0] = '+'; if (debug) { - puts(shell); - (void)fflush(stdout); + fputs(shell, ttyout); + fputs("\n", ttyout); + (void)fflush(ttyout); } if (argc > 1) { execl(shell, shellnam, "-c", altarg, (char *)0); @@ -1208,7 +1209,7 @@ user(argc, argv) if (argc < 2) (void)another(&argc, &argv, "username"); if (argc < 2 || argc > 4) { - printf("usage: %s username [password] [account]\n", argv[0]); + fprintf(ttyout, "usage: %s username [password] [account]\n", argv[0]); code = -1; return; } @@ -1220,8 +1221,8 @@ user(argc, argv) } if (n == CONTINUE) { if (argc < 4) { - (void)fputs("Account: ", stdout); - (void)fflush(stdout); + (void)fputs("Account: ", ttyout); + (void)fflush(ttyout); (void)fgets(acct, sizeof(acct) - 1, stdin); acct[strlen(acct) - 1] = '\0'; argv[3] = acct; argc++; @@ -1230,7 +1231,7 @@ user(argc, argv) aflag++; } if (n != COMPLETE) { - puts("Login failed."); + fputs("Login failed.\n", ttyout); return; } if (!aflag && argc == 4) { @@ -1255,7 +1256,7 @@ pwd(argc, argv) */ verbose = 1; if (command("PWD") == ERROR && code == 500) { - puts("PWD command not recognized, trying XPWD."); + fputs("PWD command not recognized, trying XPWD.\n", ttyout); (void)command("XPWD"); } verbose = oldverbose; @@ -1272,7 +1273,7 @@ lpwd(argc, argv) char buf[MAXPATHLEN]; if (getcwd(buf, sizeof(buf)) != NULL) - printf("Local directory %s\n", buf); + fprintf(ttyout, "Local directory %s\n", buf); else warn("getcwd"); code = 0; @@ -1289,13 +1290,13 @@ makedir(argc, argv) if ((argc < 2 && !another(&argc, &argv, "directory-name")) || argc > 2) { - printf("usage: %s directory-name\n", argv[0]); + fprintf(ttyout, "usage: %s directory-name\n", argv[0]); code = -1; return; } if (command("MKD %s", argv[1]) == ERROR && code == 500) { if (verbose) - puts("MKD command not recognized, trying XMKD."); + fputs("MKD command not recognized, trying XMKD.\n", ttyout); (void)command("XMKD %s", argv[1]); } } @@ -1311,13 +1312,13 @@ removedir(argc, argv) if ((argc < 2 && !another(&argc, &argv, "directory-name")) || argc > 2) { - printf("usage: %s directory-name\n", argv[0]); + fprintf(ttyout, "usage: %s directory-name\n", argv[0]); code = -1; return; } if (command("RMD %s", argv[1]) == ERROR && code == 500) { if (verbose) - puts("RMD command not recognized, trying XRMD."); + fputs("RMD command not recognized, trying XRMD.\n", ttyout); (void)command("XRMD %s", argv[1]); } } @@ -1332,7 +1333,7 @@ quote(argc, argv) { if (argc < 2 && !another(&argc, &argv, "command line to send")) { - printf("usage: %s line-to-send\n", argv[0]); + fprintf(ttyout, "usage: %s line-to-send\n", argv[0]); code = -1; return; } @@ -1351,7 +1352,7 @@ site(argc, argv) { if (argc < 2 && !another(&argc, &argv, "arguments to SITE command")) { - printf("usage: %s line-to-send\n", argv[0]); + fprintf(ttyout, "usage: %s line-to-send\n", argv[0]); code = -1; return; } @@ -1399,7 +1400,7 @@ do_chmod(argc, argv) goto usage; if ((argc < 3 && !another(&argc, &argv, "file-name")) || argc > 3) { usage: - printf("usage: %s mode file-name\n", argv[0]); + fprintf(ttyout, "usage: %s mode file-name\n", argv[0]); code = -1; return; } @@ -1495,7 +1496,7 @@ account(argc, argv) char *ap; if (argc > 2) { - printf("usage: %s [password]\n", argv[0]); + fprintf(ttyout, "usage: %s [password]\n", argv[0]); code = -1; return; } @@ -1537,26 +1538,26 @@ doproxy(argc, argv) sig_t oldintr; if (argc < 2 && !another(&argc, &argv, "command")) { - printf("usage: %s command\n", argv[0]); + fprintf(ttyout, "usage: %s command\n", argv[0]); code = -1; return; } c = getcmd(argv[1]); if (c == (struct cmd *) -1) { - puts("?Ambiguous command."); - (void)fflush(stdout); + fputs("?Ambiguous command.\n", ttyout); + (void)fflush(ttyout); code = -1; return; } if (c == 0) { - puts("?Invalid command."); - (void)fflush(stdout); + fputs("?Invalid command.\n", ttyout); + (void)fflush(ttyout); code = -1; return; } if (!c->c_proxy) { - puts("?Invalid proxy command."); - (void)fflush(stdout); + fputs("?Invalid proxy command.\n", ttyout); + (void)fflush(ttyout); code = -1; return; } @@ -1567,8 +1568,8 @@ doproxy(argc, argv) oldintr = signal(SIGINT, proxabort); pswitch(1); if (c->c_conn && !connected) { - puts("Not connected."); - (void)fflush(stdout); + fputs("Not connected.\n", ttyout); + (void)fflush(ttyout); pswitch(0); (void)signal(SIGINT, oldintr); code = -1; @@ -1613,7 +1614,7 @@ setntrans(argc, argv) { if (argc == 1) { ntflag = 0; - puts("Ntrans off."); + fputs("Ntrans off.\n", ttyout); code = ntflag; return; } @@ -1667,12 +1668,12 @@ setnmap(argc, argv) if (argc == 1) { mapflag = 0; - puts("Nmap off."); + fputs("Nmap off.\n", ttyout); code = mapflag; return; } if ((argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) { - printf("usage: %s [mapin mapout]\n", argv[0]); + fprintf(ttyout, "usage: %s [mapin mapout]\n", argv[0]); code = -1; return; } @@ -1802,8 +1803,8 @@ LOOP: } } if (!*cp2) { - puts( -"nmap: unbalanced brackets."); + fputs( +"nmap: unbalanced brackets.\n", ttyout); return (name); } match = 1; @@ -1816,8 +1817,8 @@ LOOP: } } if (!*cp2) { - puts( -"nmap: unbalanced brackets."); + fputs( +"nmap: unbalanced brackets.\n", ttyout); return (name); } break; @@ -1903,7 +1904,7 @@ cdup(argc, argv) r = command("CDUP"); if (r == ERROR && code == 500) { if (verbose) - puts("CDUP command not recognized, trying XCUP."); + fputs("CDUP command not recognized, trying XCUP.\n", ttyout); r = command("XCUP"); } if (r == COMPLETE) @@ -1918,10 +1919,10 @@ restart(argc, argv) { if (argc != 2) - puts("restart: offset not specified."); + fputs("restart: offset not specified.\n", ttyout); else { restart_point = atol(argv[1]); - printf("Restarting at %qd. Execute get, put or append to" + fprintf(ttyout, "Restarting at %qd. Execute get, put or append to" "initiate transfer\n", restart_point); } } @@ -1945,18 +1946,18 @@ macdef(argc, argv) int c; if (macnum == 16) { - puts("Limit of 16 macros have already been defined."); + fputs("Limit of 16 macros have already been defined.\n", ttyout); code = -1; return; } if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) { - printf("usage: %s macro_name\n", argv[0]); + fprintf(ttyout, "usage: %s macro_name\n", argv[0]); code = -1; return; } if (interactive) - puts( -"Enter macro line by line, terminating it with a null line."); + fputs( +"Enter macro line by line, terminating it with a null line.\n", ttyout); (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'; @@ -1967,7 +1968,7 @@ macdef(argc, argv) tmp = macros[macnum].mac_start; while (tmp != macbuf+4096) { if ((c = getchar()) == EOF) { - puts("macdef: end of file encountered."); + fputs("macdef: end of file encountered.\n", ttyout); code = -1; return; } @@ -1990,7 +1991,7 @@ macdef(argc, argv) while ((c = getchar()) != '\n' && c != EOF) /* LOOP */; if (c == EOF || getchar() == '\n') { - puts("Macro not defined - 4K buffer exceeded."); + fputs("Macro not defined - 4K buffer exceeded.\n", ttyout); code = -1; return; } @@ -2008,13 +2009,13 @@ sizecmd(argc, argv) off_t size; if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) { - printf("usage: %s filename\n", argv[0]); + fprintf(ttyout, "usage: %s filename\n", argv[0]); code = -1; return; } size = remotesize(argv[1], 1); if (size != -1) - printf("%s\t%qd\n", argv[1], size); + fprintf(ttyout, "%s\t%qd\n", argv[1], size); code = size; } @@ -2029,13 +2030,13 @@ modtime(argc, argv) time_t mtime; if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) { - printf("usage: %s filename\n", argv[0]); + fprintf(ttyout, "usage: %s filename\n", argv[0]); code = -1; return; } mtime = remotemodtime(argv[1], 1); if (mtime != -1) - printf("%s\t%s", argv[1], asctime(localtime(&mtime))); + fprintf(ttyout, "%s\t%s", argv[1], asctime(localtime(&mtime))); code = mtime; } @@ -2061,7 +2062,7 @@ newer(argc, argv) { if (getit(argc, argv, -1, "w")) - printf("Local file \"%s\" is newer than remote file \"%s\".\n", + fprintf(ttyout, "Local file \"%s\" is newer than remote file \"%s\".\n", argv[2], argv[1]); } @@ -2077,7 +2078,7 @@ page(argc, argv) char *p, *pager; if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) { - printf("usage: %s filename\n", argv[0]); + fprintf(ttyout, "usage: %s filename\n", argv[0]); code = -1; return; } |