summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ftp/cmds.c205
-rw-r--r--usr.bin/ftp/complete.c10
-rw-r--r--usr.bin/ftp/domacro.c22
-rw-r--r--usr.bin/ftp/extern.h4
-rw-r--r--usr.bin/ftp/fetch.c72
-rw-r--r--usr.bin/ftp/ftp.17
-rw-r--r--usr.bin/ftp/ftp.c115
-rw-r--r--usr.bin/ftp/ftp_var.h4
-rw-r--r--usr.bin/ftp/main.c43
-rw-r--r--usr.bin/ftp/ruserpass.c24
-rw-r--r--usr.bin/ftp/util.c76
11 files changed, 309 insertions, 273 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;
}
diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c
index 84678420633..83996b12473 100644
--- a/usr.bin/ftp/complete.c
+++ b/usr.bin/ftp/complete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: complete.c,v 1.6 1997/04/16 05:02:43 millert Exp $ */
+/* $OpenBSD: complete.c,v 1.7 1997/04/23 20:33:00 deraadt Exp $ */
/* $NetBSD: complete.c,v 1.7 1997/04/14 09:09:16 lukem Exp $ */
/*-
@@ -39,7 +39,7 @@
#ifndef SMALL
#ifndef lint
-static char rcsid[] = "$OpenBSD: complete.c,v 1.6 1997/04/16 05:02:43 millert Exp $";
+static char rcsid[] = "$OpenBSD: complete.c,v 1.7 1997/04/23 20:33:00 deraadt Exp $";
#endif /* not lint */
/*
@@ -118,7 +118,7 @@ complete_ambiguous(word, list, words)
}
}
- putchar('\n');
+ putc('\n', ttyout);
qsort(words->sl_str, words->sl_cur, sizeof(char *), comparstr);
list_vertical(words);
return (CC_REDISPLAY);
@@ -285,7 +285,7 @@ complete_remote(word, list)
sl_add(dirlist, tcp);
}
if (emesg != NULL) {
- printf("\n%s\n", emesg);
+ fprintf(ttyout, "\n%s\n", emesg);
return (CC_REDISPLAY);
}
(void)strcpy(lastdir, dir);
@@ -366,7 +366,7 @@ complete(el, ch)
case 'r': /* remote complete */
case 'R':
if (connected != -1) {
- puts("\nMust be logged in to complete.");
+ fputs("\nMust be logged in to complete.\n", ttyout);
return (CC_REDISPLAY);
}
return (complete_remote(word, dolist));
diff --git a/usr.bin/ftp/domacro.c b/usr.bin/ftp/domacro.c
index dd16c312bc6..b00d82c4489 100644
--- a/usr.bin/ftp/domacro.c
+++ b/usr.bin/ftp/domacro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: domacro.c,v 1.5 1997/03/14 04:32:13 millert Exp $ */
+/* $OpenBSD: domacro.c,v 1.6 1997/04/23 20:33:02 deraadt Exp $ */
/* $NetBSD: domacro.c,v 1.9 1997/03/13 06:23:14 lukem Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: domacro.c,v 1.5 1997/03/14 04:32:13 millert Exp $";
+static char rcsid[] = "$OpenBSD: domacro.c,v 1.6 1997/04/23 20:33:02 deraadt Exp $";
#endif
#endif /* not lint */
@@ -59,7 +59,7 @@ domacro(argc, argv)
struct cmd *c;
if (argc < 2 && !another(&argc, &argv, "macro name")) {
- printf("usage: %s macro_name\n", argv[0]);
+ fprintf(ttyout, "usage: %s macro_name\n", argv[0]);
code = -1;
return;
}
@@ -69,7 +69,7 @@ domacro(argc, argv)
}
}
if (i == macnum) {
- printf("'%s' macro not found.\n", argv[1]);
+ fprintf(ttyout, "'%s' macro not found.\n", argv[1]);
code = -1;
return;
}
@@ -121,23 +121,25 @@ TOP:
makeargv();
c = getcmd(margv[0]);
if (c == (struct cmd *)-1) {
- puts("?Ambiguous command.");
+ fputs("?Ambiguous command.\n", ttyout);
code = -1;
}
else if (c == 0) {
- puts("?Invalid command.");
+ fputs("?Invalid command.\n", ttyout);
code = -1;
}
else if (c->c_conn && !connected) {
- puts("Not connected.");
+ fputs("Not connected.\n", ttyout);
code = -1;
}
else {
- if (verbose)
- puts(line);
+ if (verbose) {
+ fputs(line, ttyout);
+ fputs("\n", ttyout);
+ }
(*c->c_handler)(margc, margv);
if (bell && c->c_bell) {
- (void)putchar('\007');
+ (void)putc('\007', ttyout);
}
(void)strcpy(line, line2);
makeargv();
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 5d9b72fec4e..43861ae48d3 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.12 1997/04/16 05:02:46 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.13 1997/04/23 20:33:04 deraadt Exp $ */
/* $NetBSD: extern.h,v 1.15 1997/04/14 09:09:17 lukem Exp $ */
/*-
@@ -46,7 +46,7 @@ void aborthttp __P((int));
void account __P((int, char **));
void alarmtimer __P((int));
int another __P((int *, char ***, const char *));
-int auto_fetch __P((int, char **));
+int auto_fetch __P((int, char **, int));
void blkfree __P((char **));
void cd __P((int, char **));
void cdup __P((int, char **));
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index b875b4cfc34..e80f2c0e702 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.9 1997/04/18 18:56:49 millert Exp $ */
+/* $OpenBSD: fetch.c,v 1.10 1997/04/23 20:33:06 deraadt Exp $ */
/* $NetBSD: fetch.c,v 1.6 1997/04/14 09:09:19 lukem Exp $ */
/*-
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.9 1997/04/18 18:56:49 millert Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.10 1997/04/23 20:33:06 deraadt Exp $";
#endif /* not lint */
/*
@@ -82,9 +82,10 @@ jmp_buf httpabort;
* Returns -1 on failure, 0 on success
*/
int
-url_get(line, proxyenv)
+url_get(line, proxyenv, fd)
char *line;
char *proxyenv;
+ int fd;
{
struct sockaddr_in sin;
int i, out, port, s;
@@ -145,7 +146,7 @@ url_get(line, proxyenv)
*portnum++ = '\0';
if (debug)
- printf("host %s, port %s, path %s, save as %s.\n",
+ fprintf(ttyout, "host %s, port %s, path %s, save as %s.\n",
host, portnum, path, savefile);
memset(&sin, 0, sizeof(sin));
@@ -198,9 +199,10 @@ url_get(line, proxyenv)
* status of "200". Proxy requests don't want leading /.
*/
if (!proxy)
- printf("Requesting %s:%d/%s\n", line, ntohs(port), path);
+ fprintf(ttyout, "Requesting %s:%d/%s\n", line, ntohs(port),
+ path);
else
- printf("Requesting %s (via %s)\n", line, proxyenv);
+ fprintf(ttyout, "Requesting %s (via %s)\n", line, proxyenv);
snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n",
proxy ? "" : "/", path);
buflen = strlen(buf);
@@ -264,11 +266,14 @@ url_get(line, proxyenv)
goto improper;
/* Open the output file. */
- out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
- if (out < 0) {
- warn("Can't open %s", savefile);
- goto cleanup_url_get;
- }
+ if (fd == -1) {
+ out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
+ if (out < 0) {
+ warn("Can't open %s", savefile);
+ goto cleanup_url_get;
+ }
+ } else
+ out = fd;
/* Trap signals */
oldintr = NULL;
@@ -297,17 +302,17 @@ url_get(line, proxyenv)
}
if (hash && !progress) {
while (bytes >= hashbytes) {
- (void)putchar('#');
+ (void)putc('#', ttyout);
hashbytes += mark;
}
- (void)fflush(stdout);
+ (void)fflush(ttyout);
}
}
if (hash && !progress && bytes > 0) {
if (bytes < mark)
- (void)putchar('#');
- (void)putchar('\n');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (len != 0) {
warn("Reading from socket");
@@ -315,11 +320,12 @@ url_get(line, proxyenv)
}
progressmeter(1);
if (verbose)
- puts("Successfully retrieved file.");
+ fputs("Successfully retrieved file.\n", ttyout);
(void)signal(SIGINT, oldintr);
close(s);
- close(out);
+ if (fd != -1)
+ close(out);
if (proxy)
free(proxy);
return (0);
@@ -343,8 +349,8 @@ aborthttp(notused)
{
alarmtimer(0);
- puts("\nhttp fetch aborted.");
- (void)fflush(stdout);
+ fputs("\nhttp fetch aborted.\n", ttyout);
+ (void)fflush(ttyout);
longjmp(httpabort, 1);
}
@@ -363,9 +369,10 @@ aborthttp(notused)
* Otherwise, 0 is returned if all files retrieved successfully.
*/
int
-auto_fetch(argc, argv)
+auto_fetch(argc, argv, fd)
int argc;
char *argv[];
+ int fd;
{
static char lasthost[MAXHOSTNAMELEN];
char *xargv[5];
@@ -374,7 +381,7 @@ auto_fetch(argc, argv)
char *ftpproxy, *httpproxy;
int rval, xargc, argpos;
int dirhasglob, filehasglob;
- char rempath[MAXPATHLEN];
+ char rempath[MAXPATHLEN], fakedev[MAXPATHLEN];
argpos = 0;
@@ -408,7 +415,7 @@ auto_fetch(argc, argv)
* Try HTTP URL-style arguments first.
*/
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
- if (url_get(line, httpproxy) == -1)
+ if (url_get(line, httpproxy, fd) == -1)
rval = argpos + 1;
continue;
}
@@ -421,7 +428,7 @@ auto_fetch(argc, argv)
host = line;
if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
if (ftpproxy) {
- if (url_get(line, ftpproxy) == -1)
+ if (url_get(line, ftpproxy, fd) == -1)
rval = argpos + 1;
continue;
}
@@ -487,7 +494,7 @@ parsed_url:
}
}
if (debug)
- printf("user %s:%s host %s port %s dir %s file %s\n",
+ fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n",
user, pass, host, portnum, dir, file);
/*
@@ -562,7 +569,7 @@ parsed_url:
}
if (!verbose)
- printf("Retrieving %s/%s\n", dir ? dir : "", file);
+ fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "", file);
if (dirhasglob) {
snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);
@@ -570,6 +577,7 @@ parsed_url:
}
/* Fetch the file(s). */
+ xargc = 2;
xargv[0] = "get";
xargv[1] = file;
xargv[2] = NULL;
@@ -579,10 +587,16 @@ parsed_url:
ointeractive = interactive;
interactive = 0;
xargv[0] = "mget";
- mget(2, xargv);
+ mget(xargc, xargv);
interactive = ointeractive;
- } else
- get(2, xargv);
+ } else {
+ if (fd != -1) {
+ xargv[2] = "-";
+ xargc++;
+ }
+ xargv[3] = NULL;
+ get(xargc, xargv);
+ }
if ((code / 100) != COMPLETE)
rval = argpos + 1;
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index b64dffd452d..0c1cb0d53fb 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ftp.1,v 1.11 1997/04/16 05:02:50 millert Exp $
+.\" $OpenBSD: ftp.1,v 1.12 1997/04/23 20:33:09 deraadt Exp $
.\" $NetBSD: ftp.1,v 1.20 1997/04/14 09:09:20 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
@@ -1059,7 +1059,10 @@ then the equivalent of
.Ic "mget file"
is performed.
.Pp
-If the directory component of
+If standard output is redirected to a non-tty device, ftp will write
+the data file out to standard output. This can be used to pipe data
+directly to another process.
+Otherwise if the directory component of
.Ic file
contains no globbing characters,
it is stored in the current directory as the
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 044b3eab9b5..8a4d968f63d 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp.c,v 1.17 1997/04/16 05:02:54 millert Exp $ */
+/* $OpenBSD: ftp.c,v 1.18 1997/04/23 20:33:13 deraadt Exp $ */
/* $NetBSD: ftp.c,v 1.25 1997/04/14 09:09:22 lukem Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: ftp.c,v 1.17 1997/04/16 05:02:54 millert Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.18 1997/04/23 20:33:13 deraadt Exp $";
#endif
#endif /* not lint */
@@ -129,7 +129,7 @@ hookup(host, port)
hp->h_addr_list++;
memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
hp->h_length);
- printf("Trying %s...\n", inet_ntoa(hisctladdr.sin_addr));
+ fprintf(ttyout, "Trying %s...\n", inet_ntoa(hisctladdr.sin_addr));
(void)close(s);
s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
if (s < 0) {
@@ -166,7 +166,7 @@ hookup(host, port)
goto bad;
}
if (verbose)
- printf("Connected to %s.\n", hostname);
+ fprintf(ttyout, "Connected to %s.\n", hostname);
if (getreply(0) > 2) { /* read startup message from server */
if (cin)
(void)fclose(cin);
@@ -198,8 +198,8 @@ cmdabort(notused)
{
alarmtimer(0);
- putchar('\n');
- (void)fflush(stdout);
+ putc('\n', ttyout);
+ (void)fflush(ttyout);
abrtflag++;
if (ptflag)
longjmp(ptabort, 1);
@@ -223,7 +223,7 @@ command(va_alist)
abrtflag = 0;
if (debug) {
- fputs("---> ", stdout);
+ fputs("---> ", ttyout);
#ifdef __STDC__
va_start(ap, fmt);
#else
@@ -231,14 +231,14 @@ command(va_alist)
fmt = va_arg(ap, const char *);
#endif
if (strncmp("PASS ", fmt, 5) == 0)
- fputs("PASS XXXX", stdout);
+ fputs("PASS XXXX", ttyout);
else if (strncmp("ACCT ", fmt, 5) == 0)
- fputs("ACCT XXXX", stdout);
+ fputs("ACCT XXXX", ttyout);
else
vprintf(fmt, ap);
va_end(ap);
- putchar('\n');
- (void)fflush(stdout);
+ putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (cout == NULL) {
warnx("No control connection for command.");
@@ -311,9 +311,9 @@ getreply(expecteof)
}
lostpeer();
if (verbose) {
- puts(
-"421 Service not available, remote server has closed connection.");
- (void)fflush(stdout);
+ fputs(
+"421 Service not available, remote server has closed connection.\n", ttyout);
+ (void)fflush(ttyout);
}
code = 421;
return (4);
@@ -323,8 +323,8 @@ getreply(expecteof)
(n < '5' || !retry_connect)) {
if (proxflag &&
(dig == 1 || (dig == 5 && verbose == 0)))
- printf("%s:", hostname);
- (void)putchar(c);
+ fprintf(ttyout, "%s:", hostname);
+ (void)putc(c, ttyout);
}
if (dig < 4 && isdigit(c))
code = code * 10 + (c - '0');
@@ -352,8 +352,8 @@ getreply(expecteof)
}
if (verbose > 0 || ((verbose > -1 && n == '5') &&
(n < '5' || !retry_connect))) {
- (void)putchar(c);
- (void)fflush (stdout);
+ (void)putc(c, ttyout);
+ (void)fflush (ttyout);
}
if (line == 0) {
size_t len = cp - current_line;
@@ -403,8 +403,8 @@ abortsend(notused)
alarmtimer(0);
mflag = 0;
abrtflag = 0;
- puts("\nsend aborted\nwaiting for remote to finish abort.");
- (void)fflush(stdout);
+ fputs("\nsend aborted\nwaiting for remote to finish abort.\n", ttyout);
+ (void)fflush(ttyout);
longjmp(sendabort, 1);
}
@@ -429,9 +429,9 @@ sendrequest(cmd, local, remote, printnames)
oprogress = progress;
if (verbose && printnames) {
if (local && *local != '-')
- printf("local: %s ", local);
+ fprintf(ttyout, "local: %s ", local);
if (remote)
- printf("remote: %s\n", remote);
+ fprintf(ttyout, "remote: %s\n", remote);
}
if (proxy) {
proxtrans(cmd, local, remote);
@@ -492,7 +492,7 @@ sendrequest(cmd, local, remote, printnames)
closefunc = fclose;
if (fstat(fileno(fin), &st) < 0 ||
(st.st_mode & S_IFMT) != S_IFREG) {
- printf("%s: not a plain file.\n", local);
+ fprintf(ttyout, "%s: not a plain file.\n", local);
(void)signal(SIGINT, oldintr);
(void)signal(SIGINFO, oldinti);
fclose(fin);
@@ -587,17 +587,17 @@ sendrequest(cmd, local, remote, printnames)
break;
if (hash && (!progress || filesize < 0) ) {
while (bytes >= hashbytes) {
- (void)putchar('#');
+ (void)putc('#', ttyout);
hashbytes += mark;
}
- (void)fflush(stdout);
+ (void)fflush(ttyout);
}
}
if (hash && (!progress || filesize < 0) && bytes > 0) {
if (bytes < mark)
- (void)putchar('#');
- (void)putchar('\n');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (c < 0)
warn("local: %s", local);
@@ -613,8 +613,8 @@ sendrequest(cmd, local, remote, printnames)
if (c == '\n') {
while (hash && (!progress || filesize < 0) &&
(bytes >= hashbytes)) {
- (void)putchar('#');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)fflush(ttyout);
hashbytes += mark;
}
if (ferror(dout))
@@ -633,9 +633,9 @@ sendrequest(cmd, local, remote, printnames)
}
if (hash && (!progress || filesize < 0)) {
if (bytes < hashbytes)
- (void)putchar('#');
- (void)putchar('\n');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (ferror(fin))
warn("local: %s", local);
@@ -693,8 +693,8 @@ abortrecv(notused)
alarmtimer(0);
mflag = 0;
abrtflag = 0;
- puts("\nreceive aborted\nwaiting for remote to finish abort.");
- (void)fflush(stdout);
+ fputs("\nreceive aborted\nwaiting for remote to finish abort.\n", ttyout);
+ (void)fflush(ttyout);
longjmp(recvabort, 1);
}
@@ -724,9 +724,9 @@ recvrequest(cmd, local, remote, lmode, printnames)
is_retr = strcmp(cmd, "RETR") == 0;
if (is_retr && verbose && printnames) {
if (local && *local != '-')
- printf("local: %s ", local);
+ fprintf(ttyout, "local: %s ", local);
if (remote)
- printf("remote: %s\n", remote);
+ fprintf(ttyout, "remote: %s\n", remote);
}
if (proxy && is_retr) {
proxtrans(cmd, local, remote);
@@ -896,17 +896,17 @@ recvrequest(cmd, local, remote, lmode, printnames)
bytes += c;
if (hash && (!progress || filesize < 0)) {
while (bytes >= hashbytes) {
- (void)putchar('#');
+ (void)putc('#', ttyout);
hashbytes += mark;
}
- (void)fflush(stdout);
+ (void)fflush(ttyout);
}
}
if (hash && (!progress || filesize < 0) && bytes > 0) {
if (bytes < mark)
- (void)putchar('#');
- (void)putchar('\n');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (c < 0) {
if (errno != EPIPE)
@@ -950,8 +950,8 @@ done:
while (c == '\r') {
while (hash && (!progress || filesize < 0) &&
(bytes >= hashbytes)) {
- (void)putchar('#');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)fflush(ttyout);
hashbytes += mark;
}
bytes++;
@@ -975,13 +975,13 @@ break2:
if (bare_lfs) {
printf(
"WARNING! %d bare linefeeds received in ASCII mode.\n", bare_lfs);
- puts("File may not have transferred correctly.");
+ fputs("File may not have transferred correctly.\n", ttyout);
}
if (hash && (!progress || filesize < 0)) {
if (bytes < hashbytes)
- (void)putchar('#');
- (void)putchar('\n');
- (void)fflush(stdout);
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
}
if (ferror(din)) {
if (errno != EPIPE)
@@ -1077,7 +1077,7 @@ initconn()
sizeof(on)) < 0)
warn("setsockopt (ignored)");
if (command("PASV") != COMPLETE) {
- puts("Passive mode refused.");
+ fputs("Passive mode refused.\n", ttyout);
goto bad;
}
@@ -1091,8 +1091,8 @@ initconn()
if (sscanf(pasv, "%d,%d,%d,%d,%d,%d",
&a0, &a1, &a2, &a3, &p0, &p1) != 6) {
- puts(
-"Passive mode address scan failure. Shouldn't happen!");
+ fputs(
+"Passive mode address scan failure. Shouldn't happen!\n", ttyout);
goto bad;
}
@@ -1330,8 +1330,8 @@ abortpt(notused)
{
alarmtimer(0);
- putchar('\n');
- (void)fflush(stdout);
+ putc('\n', ttyout);
+ (void)fflush(ttyout);
ptabflg++;
mflag = 0;
abrtflag = 0;
@@ -1360,12 +1360,13 @@ proxtrans(cmd, local, remote)
if (curtype != prox_type)
changetype(prox_type, 1);
if (command("PASV") != COMPLETE) {
- puts("proxy server does not support third party transfers.");
+ fputs("proxy server does not support third party transfers.\n",
+ ttyout);
return;
}
pswitch(0);
if (!connected) {
- puts("No primary connection.");
+ fputs("No primary connection.\n", ttyout);
pswitch(1);
code = -1;
return;
@@ -1396,7 +1397,7 @@ proxtrans(cmd, local, remote)
(void)signal(SIGINT, oldintr);
pswitch(1);
ptflag = 0;
- printf("local: %s remote: %s\n", local, remote);
+ fprintf(ttyout, "local: %s remote: %s\n", local, remote);
return;
abort:
(void)signal(SIGINT, SIG_IGN);
@@ -1502,7 +1503,7 @@ gunique(local)
*cp++ = '.';
while (!d) {
if (++count == 100) {
- puts("runique: can't find unique file name.");
+ fputs("runique: can't find unique file name.\n", ttyout);
return ((char *) 0);
}
*cp++ = ext;
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index 8e875ff1947..747c4d5a8b6 100644
--- a/usr.bin/ftp/ftp_var.h
+++ b/usr.bin/ftp/ftp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp_var.h,v 1.11 1997/04/16 05:02:57 millert Exp $ */
+/* $OpenBSD: ftp_var.h,v 1.12 1997/04/23 20:33:16 deraadt Exp $ */
/* $NetBSD: ftp_var.h,v 1.16 1997/04/14 09:09:23 lukem Exp $ */
/*
@@ -166,3 +166,5 @@ struct macel {
int macnum; /* number of defined macros */
struct macel macros[16];
char macbuf[4096];
+
+FILE *ttyout; /* stdout or stderr, depending on interactive */
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index 7601da8358a..47ca64ad8e8 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.29 1997/04/11 23:14:04 millert Exp $ */
+/* $OpenBSD: main.c,v 1.30 1997/04/23 20:33:19 deraadt Exp $ */
/* $NetBSD: main.c,v 1.21 1997/04/05 03:27:39 lukem Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.29 1997/04/11 23:14:04 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.30 1997/04/23 20:33:19 deraadt Exp $";
#endif
#endif /* not lint */
@@ -75,6 +75,7 @@ main(argc, argv)
struct passwd *pw = NULL;
char *cp, homedir[MAXPATHLEN];
int dumb_terminal = 0;
+ int outfd = -1;
sp = getservbyname("ftp", "tcp");
if (sp == 0)
@@ -116,8 +117,14 @@ main(argc, argv)
editing = 1; /* editing mode on if from a tty */
#endif
}
- if (isatty(fileno(stdout)) && !dumb_terminal)
+
+ ttyout = stdout;
+ if (isatty(fileno(ttyout)) && !dumb_terminal)
progress = 1; /* progress bar on if going to a tty */
+ else {
+ ttyout = stderr;
+ outfd = fileno(stdout);
+ }
while ((ch = getopt(argc, argv, "adeginpPr:tvV")) != -1) {
switch (ch) {
@@ -210,7 +217,7 @@ main(argc, argv)
if (argc > 0) {
if (strchr(argv[0], ':') != NULL) {
anonftp = 1; /* Handle "automatic" transfers. */
- rval = auto_fetch(argc, argv);
+ rval = auto_fetch(argc, argv, outfd);
if (rval >= 0) /* -1 == connected and cd-ed */
exit(rval);
} else {
@@ -231,7 +238,7 @@ main(argc, argv)
break;
if (!connected) {
macnum = 0;
- puts("Retrying...");
+ fputs("Retrying...\n", ttyout);
sleep(retry_connect);
}
} while (!connected);
@@ -314,14 +321,14 @@ cmdscanner(top)
&& !editing
#endif /* !SMALL */
)
- (void)putchar('\n');
+ (void)putc('\n', ttyout);
for (;;) {
#ifndef SMALL
if (!editing) {
#endif /* !SMALL */
if (fromatty) {
- fputs(prompt(), stdout);
- (void)fflush(stdout);
+ fputs(prompt(), ttyout);
+ (void)fflush(ttyout);
}
if (fgets(line, sizeof(line), stdin) == NULL)
quit(0, 0);
@@ -333,7 +340,7 @@ cmdscanner(top)
break;
line[num] = '\0';
} else if (num == sizeof(line) - 2) {
- puts("sorry, input line too long.");
+ fputs("sorry, input line too long.\n", ttyout);
while ((num = getchar()) != '\n' && num != EOF)
/* void */;
break;
@@ -349,7 +356,7 @@ cmdscanner(top)
if (num == 0)
break;
} else if (num >= sizeof(line)) {
- puts("sorry, input line too long.");
+ fputs("sorry, input line too long.\n", ttyout);
break;
}
memcpy(line, buf, num);
@@ -363,7 +370,7 @@ cmdscanner(top)
continue;
c = getcmd(margv[0]);
if (c == (struct cmd *)-1) {
- puts("?Ambiguous command.");
+ fputs("?Ambiguous command.\n", ttyout);
continue;
}
if (c == 0) {
@@ -375,17 +382,17 @@ cmdscanner(top)
*/
if (el_parse(el, margc, margv) != 0)
#endif /* !SMALL */
- puts("?Invalid command.");
+ fputs("?Invalid command.\n", ttyout);
continue;
}
if (c->c_conn && !connected) {
- puts("Not connected.");
+ fputs("Not connected.\n", ttyout);
continue;
}
confirmrest = 0;
(*c->c_handler)(margc, margv);
if (bell && c->c_bell)
- (void)putchar('\007');
+ (void)putc('\007', ttyout);
if (c->c_handler != help)
break;
}
@@ -617,7 +624,7 @@ help(argc, argv)
StringList *buf;
buf = sl_init();
- printf("%sommands may be abbreviated. Commands are:\n\n",
+ fprintf(ttyout, "%sommands may be abbreviated. Commands are:\n\n",
proxy ? "Proxy c" : "C");
for (c = cmdtab; c < &cmdtab[NCMDS]; c++)
if (c->c_name && (!proxy || c->c_proxy))
@@ -635,11 +642,11 @@ help(argc, argv)
arg = *++argv;
c = getcmd(arg);
if (c == (struct cmd *)-1)
- printf("?Ambiguous help command %s\n", arg);
+ fprintf(ttyout, "?Ambiguous help command %s\n", arg);
else if (c == (struct cmd *)0)
- printf("?Invalid help command %s\n", arg);
+ fprintf(ttyout, "?Invalid help command %s\n", arg);
else
- printf("%-*s\t%s\n", HELPINDENT,
+ fprintf(ttyout, "%-*s\t%s\n", HELPINDENT,
c->c_name, c->c_help);
}
}
diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c
index 54784131553..fd9d5789a1d 100644
--- a/usr.bin/ftp/ruserpass.c
+++ b/usr.bin/ftp/ruserpass.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruserpass.c,v 1.7 1997/04/10 00:17:10 millert Exp $ */
+/* $OpenBSD: ruserpass.c,v 1.8 1997/04/23 20:33:21 deraadt Exp $ */
/* $NetBSD: ruserpass.c,v 1.13 1997/04/01 14:20:34 mrg Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.7 1997/04/10 00:17:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.8 1997/04/23 20:33:21 deraadt Exp $";
#endif
#endif /* not lint */
@@ -191,12 +191,12 @@ next:
if (c != ' ' && c != '\t')
break;
if (c == EOF || c == '\n') {
- puts("Missing macdef name argument.");
+ fputs("Missing macdef name argument.\n", ttyout);
goto bad;
}
if (macnum == 16) {
- puts(
-"Limit of 16 macros have already been defined.");
+ fputs(
+"Limit of 16 macros have already been defined.\n", ttyout);
goto bad;
}
tmp = macros[macnum].mac_name;
@@ -206,8 +206,8 @@ next:
*tmp++ = c;
}
if (c == EOF) {
- puts(
-"Macro definition missing null line terminator.");
+ fputs(
+"Macro definition missing null line terminator.\n", ttyout);
goto bad;
}
*tmp = '\0';
@@ -215,8 +215,8 @@ next:
while ((c=getc(cfile)) != EOF && c != '\n');
}
if (c == EOF) {
- puts(
-"Macro definition missing null line terminator.");
+ fputs(
+"Macro definition missing null line terminator.\n", ttyout);
goto bad;
}
if (macnum == 0) {
@@ -229,8 +229,8 @@ next:
tmp = macros[macnum].mac_start;
while (tmp != macbuf + 4096) {
if ((c=getc(cfile)) == EOF) {
- puts(
-"Macro definition missing null line terminator.");
+ fputs(
+"Macro definition missing null line terminator.\n", ttyout);
goto bad;
}
*tmp = c;
@@ -244,7 +244,7 @@ next:
tmp++;
}
if (tmp == macbuf + 4096) {
- puts("4K macro buffer exceeded.");
+ fputs("4K macro buffer exceeded.\n", ttyout);
goto bad;
}
break;
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index a591aefcd82..e379c882d9e 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.6 1997/04/16 05:02:59 millert Exp $ */
+/* $OpenBSD: util.c,v 1.7 1997/04/23 20:33:24 deraadt Exp $ */
/* $NetBSD: util.c,v 1.7 1997/04/14 09:09:24 lukem Exp $ */
/*
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.6 1997/04/16 05:02:59 millert Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.7 1997/04/23 20:33:24 deraadt Exp $";
#endif /* not lint */
/*
@@ -74,7 +74,7 @@ setpeer(argc, argv)
short port;
if (connected) {
- printf("Already connected to %s, use close first.\n",
+ fprintf(ttyout, "Already connected to %s, use close first.\n",
hostname);
code = -1;
return;
@@ -82,7 +82,7 @@ setpeer(argc, argv)
if (argc < 2)
(void)another(&argc, &argv, "to");
if (argc < 2 || argc > 3) {
- printf("usage: %s host-name [port]\n", argv[0]);
+ fprintf(ttyout, "usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
}
@@ -90,8 +90,8 @@ setpeer(argc, argv)
if (argc > 2) {
port = atoi(argv[2]);
if (port <= 0) {
- printf("%s: bad port number '%s'.\n", argv[1], argv[2]);
- printf("usage: %s host-name [port]\n", argv[0]);
+ fprintf(ttyout, "%s: bad port number '%s'.\n", argv[1], argv[2]);
+ fprintf(ttyout, "usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
}
@@ -135,7 +135,7 @@ setpeer(argc, argv)
*cp = '\0';
}
- printf("Remote system type is %s.\n", reply_string + 4);
+ fprintf(ttyout, "Remote system type is %s.\n", reply_string + 4);
if (cp)
*cp = c;
}
@@ -153,8 +153,8 @@ setpeer(argc, argv)
type = 0;
(void)strcpy(typename, "binary");
if (overbose)
- printf("Using %s mode to transfer files.\n",
- typename);
+ fprintf(ttyout, "Using %s mode to transfer files.\n",
+ typename);
} else {
if (proxy)
unix_proxy = 0;
@@ -162,8 +162,9 @@ setpeer(argc, argv)
unix_server = 0;
if (overbose &&
!strncmp(reply_string, "215 TOPS20", 10))
- puts(
-"Remember to set tenex mode when transferring binary files from this machine.");
+ fputs(
+"Remember to set tenex mode when transferring binary files from this machine.\n",
+ ttyout);
}
verbose = overbose;
#endif /* unix || BSD */
@@ -232,9 +233,9 @@ login(host, user, pass)
myname = pp->pw_name;
}
if (myname)
- printf("Name (%s:%s): ", host, myname);
+ fprintf(ttyout, "Name (%s:%s): ", host, myname);
else
- printf("Name (%s): ", host);
+ fprintf(ttyout, "Name (%s): ", host);
(void)fgets(tmp, sizeof(tmp) - 1, stdin);
tmp[strlen(tmp) - 1] = '\0';
if (*tmp == '\0')
@@ -288,10 +289,10 @@ another(pargc, pargv, prompt)
int len = strlen(line), ret;
if (len >= sizeof(line) - 3) {
- puts("sorry, arguments too long.");
+ fputs("sorry, arguments too long.\n", ttyout);
intr();
}
- printf("(%s) ", prompt);
+ fprintf(ttyout, "(%s) ", prompt);
line[len++] = ' ';
if (fgets(&line[len], sizeof(line) - len, stdin) == NULL)
intr();
@@ -382,7 +383,8 @@ remglob(argv, doswitch, errbuf)
(void)unlink(temp);
if (ftemp == NULL) {
if (errbuf == NULL)
- puts("can't find list of remote files, oops.");
+ fputs("can't find list of remote files, oops.\n",
+ ttyout);
else
*errbuf =
"can't find list of remote files, oops.";
@@ -407,8 +409,8 @@ confirm(cmd, file)
if (!interactive || confirmrest)
return (1);
- printf("%s %s? ", cmd, file);
- (void)fflush(stdout);
+ fprintf(ttyout, "%s %s? ", cmd, file);
+ (void)fflush(ttyout);
if (fgets(line, sizeof(line), stdin) == NULL)
return (0);
switch (tolower(*line)) {
@@ -416,11 +418,11 @@ confirm(cmd, file)
return (0);
case 'p':
interactive = 0;
- puts("Interactive mode: off.");
+ fputs("Interactive mode: off.\n", ttyout);
break;
case 'a':
confirmrest = 1;
- printf("Prompting off for duration of %s.\n", cmd);
+ fprintf(ttyout, "Prompting off for duration of %s.\n", cmd);
break;
}
return (1);
@@ -472,8 +474,10 @@ remotesize(file, noisy)
verbose = -1;
if (command("SIZE %s", file) == COMPLETE)
sscanf(reply_string, "%*s %qd", &size);
- else if (noisy && debug == 0)
- puts(reply_string);
+ else if (noisy && debug == 0) {
+ fputs(reply_string, ttyout);
+ fputs("\n", ttyout);
+ }
verbose = overbose;
return (size);
}
@@ -508,11 +512,13 @@ remotemodtime(file, noisy)
timebuf.tm_isdst = -1;
rtime = mktime(&timebuf);
if (rtime == -1 && (noisy || debug != 0))
- printf("Can't convert %s to a time.\n", reply_string);
+ fprintf(ttyout, "Can't convert %s to a time.\n", reply_string);
else
rtime += timebuf.tm_gmtoff; /* conv. local -> GMT */
- } else if (noisy && debug == 0)
- puts(reply_string);
+ } else if (noisy && debug == 0) {
+ fputs(reply_string, ttyout);
+ fputs("\n", ttyout);
+ }
verbose = overbose;
return (rtime);
}
@@ -623,16 +629,16 @@ progressmeter(flag)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
"%02d:%02d ETA", i / 60, i % 60);
}
- (void)write(STDOUT_FILENO, buf, strlen(buf));
+ (void)write(fileno(ttyout), buf, strlen(buf));
if (flag == -1) {
(void)signal(SIGALRM, updateprogressmeter);
alarmtimer(1); /* set alarm timer for 1 Hz */
} else if (flag == 1) {
alarmtimer(0);
- (void)putchar('\n');
+ (void)putc('\n', ttyout);
}
- fflush(stdout);
+ fflush(ttyout);
}
/*
@@ -641,7 +647,7 @@ progressmeter(flag)
* direction to be defined by xfer routines, and filesize and bytes
* to be updated by xfer routines
* If siginfo is nonzero, an ETA is displayed, and the output goes to STDERR
- * instead of STDOUT.
+ * instead of TTYOUT.
*/
void
ptransfer(siginfo)
@@ -676,7 +682,7 @@ ptransfer(siginfo)
" ETA: %02d:%02d:%02d\n", hh, remaining / 60,
remaining % 60);
}
- (void)write(siginfo ? STDERR_FILENO : STDOUT_FILENO, buf, strlen(buf));
+ (void)write(siginfo ? STDERR_FILENO : fileno(ttyout), buf, strlen(buf));
}
/*
@@ -707,15 +713,15 @@ list_vertical(sl)
for (j = 0; j < columns; j++) {
p = sl->sl_str[j * lines + i];
if (p)
- fputs(p, stdout);
+ fputs(p, ttyout);
if (j * lines + i + lines >= sl->sl_cur) {
- putchar('\n');
+ putc('\n', ttyout);
break;
}
w = strlen(p);
while (w < width) {
w = (w + 8) &~ 7;
- (void)putchar('\t');
+ (void)putc('\t', ttyout);
}
}
}
@@ -730,7 +736,7 @@ setttywidth(a)
{
struct winsize winsize;
- if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
+ if (ioctl(fileno(ttyout), TIOCGWINSZ, &winsize) != -1)
ttywidth = winsize.ws_col;
else
ttywidth = 80;
@@ -759,7 +765,7 @@ void
controlediting()
{
if (editing && el == NULL && hist == NULL) {
- el = el_init(__progname, stdin, stdout); /* init editline */
+ el = el_init(__progname, stdin, ttyout); /* init editline */
hist = history_init(); /* init the builtin history */
history(hist, H_EVENT, 100); /* remember 100 events */
el_set(el, EL_HIST, history, hist); /* use history */