=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/cmds.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- src/usr.bin/ftp/cmds.c 1997/04/16 05:02:39 1.19 +++ src/usr.bin/ftp/cmds.c 1997/04/23 20:32:57 1.20 @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ aflag++; } if (n != COMPLETE) { - puts("Login failed."); + fputs("Login failed.\n", ttyout); return; } if (!aflag && argc == 4) { @@ -1255,7 +1256,7 @@ */ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { if (argc == 1) { ntflag = 0; - puts("Ntrans off."); + fputs("Ntrans off.\n", ttyout); code = ntflag; return; } @@ -1667,12 +1668,12 @@ 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 @@ } } if (!*cp2) { - puts( -"nmap: unbalanced brackets."); + fputs( +"nmap: unbalanced brackets.\n", ttyout); return (name); } match = 1; @@ -1816,8 +1817,8 @@ } } if (!*cp2) { - puts( -"nmap: unbalanced brackets."); + fputs( +"nmap: unbalanced brackets.\n", ttyout); return (name); } break; @@ -1903,7 +1904,7 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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; }