summaryrefslogtreecommitdiff
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-09-04 04:37:18 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-09-04 04:37:18 +0000
commit2554a4cd0c3e889db42e6d3ae0edaf40f59abb49 (patch)
tree37f7c139ba3ff8844b260f7f2a9ccbcf34ed9b36 /usr.bin/ftp
parent6e420cc3b1ae028325992e1092f42f11edf32c91 (diff)
Updtaes from NetBSD (lukem)
bugs fixed: * don't interpret '-' or '|' when a local filename is determined from the remote name (i.e, in mget, and in get with only one argument). This is implemented using an extra argument to recvrequest(). Fixes a major security hole. * clean up memory leak when using globulize() * clean up a couple of comments * fix wording in TNF copyright features added: * support for TIS fwtk gate-ftp servers: * read defaults from $FTPSERVER && $FTPSERVERPORT * start in gate-ftp mode if invoked as 'gate-ftp' * toggle or set with 'gate [host [port]]' Other changes: * use symbolic flags in access(2) * Use USHRT_MAX, not 0xffff
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/Makefile9
-rw-r--r--usr.bin/ftp/cmds.c182
-rw-r--r--usr.bin/ftp/cmdtab.c8
-rw-r--r--usr.bin/ftp/complete.c10
-rw-r--r--usr.bin/ftp/extern.h7
-rw-r--r--usr.bin/ftp/fetch.c12
-rw-r--r--usr.bin/ftp/ftp.135
-rw-r--r--usr.bin/ftp/ftp.c33
-rw-r--r--usr.bin/ftp/ftp_var.h23
-rw-r--r--usr.bin/ftp/main.c43
-rw-r--r--usr.bin/ftp/util.c38
11 files changed, 291 insertions, 109 deletions
diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile
index 735185cc29f..59de87c0715 100644
--- a/usr.bin/ftp/Makefile
+++ b/usr.bin/ftp/Makefile
@@ -1,10 +1,13 @@
-# $OpenBSD: Makefile,v 1.10 1997/07/25 21:56:16 millert Exp $
-# $NetBSD: Makefile,v 1.12 1997/07/20 09:45:35 lukem Exp $
+# $OpenBSD: Makefile,v 1.11 1997/09/04 04:37:12 millert Exp $
+# $NetBSD: Makefile,v 1.13 1997/08/18 10:20:13 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
-# define SMALL to disable command line editing
+# Define SMALL to disable command line editing
#CFLAGS+=-DSMALL
+# Uncomment the following to provide defaults for gate-ftp operation
+#CFLAGS+=-DGATE_SERVER=\"ftp-gw.host\" # -DGATE_PORT=21
+
PROG= ftp
SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c ruserpass.c \
stringlist.c util.c
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index 09b3d2dffc7..3c51f2806de 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: cmds.c,v 1.22 1997/08/30 20:48:41 kstailey Exp $ */
-/* $NetBSD: cmds.c,v 1.26 1997/07/21 14:03:48 lukem Exp $ */
+/* $OpenBSD: cmds.c,v 1.23 1997/09/04 04:37:13 millert Exp $ */
+/* $NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmds.c,v 1.22 1997/08/30 20:48:41 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: cmds.c,v 1.23 1997/09/04 04:37:13 millert Exp $";
#endif
#endif /* not lint */
@@ -299,6 +299,8 @@ usage:
}
sendrequest(cmd, argv[1], argv[2],
argv[1] != oldargv1 || argv[2] != oldargv2);
+ if (oldargv1 != argv[1]) /* free up after globulize() */
+ free(argv[1]);
}
/*
@@ -342,7 +344,8 @@ mput(argc, argv)
tp2 = tmpbuf;
while ((*tp2 = *tp) != '\0') {
if (isupper(*tp2)) {
- *tp2 = 'a' + *tp2 - 'A';
+ *tp2 =
+ tolower(*tp2);
}
tp++;
tp2++;
@@ -453,7 +456,8 @@ getit(argc, argv, restartit, mode)
const char *mode;
{
int loc = 0;
- char *oldargv1, *oldargv2;
+ int rval = 0;
+ char *oldargv1, *oldargv2, *globargv2;
if (argc == 2) {
argc++;
@@ -474,6 +478,7 @@ usage:
code = -1;
return (0);
}
+ globargv2 = argv[2];
if (loc && mcase) {
char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
@@ -485,7 +490,7 @@ usage:
tp2 = tmpbuf;
while ((*tp2 = *tp) != '\0') {
if (isupper(*tp2)) {
- *tp2 = 'a' + *tp2 - 'A';
+ *tp2 = tolower(*tp2);
}
tp++;
tp2++;
@@ -505,7 +510,7 @@ usage:
if (restartit == 1) {
if (ret < 0) {
warn("local: %s", argv[2]);
- return (0);
+ goto freegetit;
}
restart_point = stbuf.st_size;
} else {
@@ -514,17 +519,22 @@ usage:
mtime = remotemodtime(argv[1], 0);
if (mtime == -1)
- return (0);
- if (stbuf.st_mtime >= mtime)
- return (1);
+ goto freegetit;
+ if (stbuf.st_mtime >= mtime) {
+ rval = 1;
+ goto freegetit;
+ }
}
}
}
recvrequest("RETR", argv[2], argv[1], mode,
- argv[1] != oldargv1 || argv[2] != oldargv2);
+ argv[1] != oldargv1 || argv[2] != oldargv2, loc);
restart_point = 0;
- return (0);
+freegetit:
+ if (oldargv2 != globargv2) /* free up after globulize() */
+ free(globargv2);
+ return (rval);
}
/* ARGSUSED */
@@ -593,7 +603,7 @@ mget(argc, argv)
if (mapflag)
tp = domap(tp);
recvrequest("RETR", tp, cp, "w",
- tp != cp || !interactive);
+ tp != cp || !interactive, 1);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
@@ -643,6 +653,8 @@ status(argc, argv)
}
pswitch(0);
}
+ fprintf(ttyout, "Gate ftp: %s, server %s, port %d.\n", onoff(gatemode),
+ *gateserver ? gateserver : "(none)", ntohs(gateport));
fprintf(ttyout, "Passive mode: %s.\n", onoff(passivemode));
fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
modename, typename, formname, structname);
@@ -823,8 +835,7 @@ setprogress(argc, argv)
}
/*
- * Turn on interactive prompting
- * during mget, mput, and mdelete.
+ * Turn on interactive prompting during mget, mput, and mdelete.
*/
/*VARARGS*/
void
@@ -837,8 +848,63 @@ setprompt(argc, argv)
}
/*
- * Toggle metacharacter interpretation
- * on local file names.
+ * Toggle gate-ftp mode, or set gate-ftp server
+ */
+/*VARARGS*/
+void
+setgate(argc, argv)
+ int argc;
+ char *argv[];
+{
+ static char gsbuf[MAXHOSTNAMELEN];
+
+ if (argc > 3) {
+ fprintf(ttyout, "usage: %s [ on | off | gateserver [ port ] ]\n",
+ argv[0]);
+ code = -1;
+ return;
+ } else if (argc < 2) {
+ gatemode = !gatemode;
+ } else {
+ if (argc == 2 && strcasecmp(argv[1], "on") == 0)
+ gatemode = 1;
+ else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
+ gatemode = 0;
+ else {
+ if (argc == 3) {
+ char *ep;
+ long port;
+
+ port = strtol(argv[2], &ep, 10);
+ if (port < 0 || port > USHRT_MAX || *ep != '\0') {
+ fprintf(ttyout,
+ "%s: bad gateport value.\n",
+ argv[2]);
+ code = -1;
+ return;
+ }
+ gateport = htons(port);
+ }
+ strncpy(gsbuf, argv[1], sizeof(gsbuf) - 1);
+ gsbuf[sizeof(gsbuf) - 1] = '\0';
+ gateserver = gsbuf;
+ gatemode = 1;
+ }
+ }
+ if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
+ fprintf(ttyout,
+ "Disabling gate-ftp mode - no gate-ftp server defined.\n");
+ gatemode = 0;
+ } else {
+ fprintf(ttyout, "Gate ftp: %s, server %s, port %d.\n",
+ onoff(gatemode),
+ *gateserver ? gateserver : "(none)", ntohs(gateport));
+ }
+ code = gatemode;
+}
+
+/*
+ * Toggle metacharacter interpretation on local file names.
*/
/*VARARGS*/
void
@@ -864,8 +930,7 @@ setpreserve(argc, argv)
}
/*
- * Set debugging mode on/off and/or
- * set level of debugging.
+ * Set debugging mode on/off and/or set level of debugging.
*/
/*VARARGS*/
void
@@ -906,8 +971,7 @@ setdebug(argc, argv)
}
/*
- * Set current working directory
- * on remote machine.
+ * Set current working directory on remote machine.
*/
void
cd(argc, argv)
@@ -933,8 +997,7 @@ cd(argc, argv)
}
/*
- * Set current working directory
- * on local machine.
+ * Set current working directory on local machine.
*/
void
lcd(argc, argv)
@@ -942,6 +1005,7 @@ lcd(argc, argv)
char *argv[];
{
char buf[MAXPATHLEN];
+ char *oldargv1;
if (argc < 2)
argc++, argv[1] = home;
@@ -950,6 +1014,7 @@ lcd(argc, argv)
code = -1;
return;
}
+ oldargv1 = argv[1];
if (!globulize(&argv[1])) {
code = -1;
return;
@@ -957,13 +1022,15 @@ lcd(argc, argv)
if (chdir(argv[1]) < 0) {
warn("local: %s", argv[1]);
code = -1;
- return;
+ } else {
+ if (getcwd(buf, sizeof(buf)) != NULL)
+ fprintf(ttyout, "Local directory now %s\n", buf);
+ else
+ warn("getcwd: %s", argv[1]);
+ code = 0;
}
- if (getcwd(buf, sizeof(buf)) != NULL)
- fprintf(ttyout, "Local directory now %s\n", buf);
- else
- warn("getcwd: %s", argv[1]);
- code = 0;
+ if (oldargv1 != argv[1]) /* free up after globulize() */
+ free(argv[1]);
}
/*
@@ -1047,8 +1114,7 @@ usage:
}
/*
- * Get a directory listing
- * of remote files.
+ * Get a directory listing of remote files.
*/
void
ls(argc, argv)
@@ -1056,6 +1122,7 @@ ls(argc, argv)
char *argv[];
{
const char *cmd;
+ char *oldargv2, *globargv2;
if (argc < 2)
argc++, argv[1] = NULL;
@@ -1067,25 +1134,30 @@ ls(argc, argv)
return;
}
cmd = strcmp(argv[0], "dir") == 0 ? "LIST" : "NLST";
+ oldargv2 = argv[2];
if (strcmp(argv[2], "-") && !globulize(&argv[2])) {
code = -1;
return;
}
- if (strcmp(argv[2], "-") && *argv[2] != '|')
- if (!globulize(&argv[2]) || !confirm("output to local-file:",
- argv[2])) {
- code = -1;
- return;
+ globargv2 = argv[2];
+ if (strcmp(argv[2], "-") && *argv[2] != '|' && (!globulize(&argv[2]) ||
+ !confirm("output to local-file:", argv[2]))) {
+ code = -1;
+ goto freels;
}
- recvrequest(cmd, argv[2], argv[1], "w", 0);
+ recvrequest(cmd, argv[2], argv[1], "w", 0, 0);
/* flush results in case commands are coming from a pipe */
fflush(ttyout);
+freels:
+ if (argv[2] != globargv2) /* free up after globulize() */
+ free(argv[2]);
+ if (globargv2 != oldargv2)
+ free(globargv2);
}
/*
- * Get a directory listing
- * of multiple remote files.
+ * Get a directory listing of multiple remote files.
*/
void
mls(argc, argv)
@@ -1095,7 +1167,7 @@ mls(argc, argv)
sig_t oldintr;
int ointer, i;
int dolist;
- char mode[1], *dest;
+ char mode[1], *dest, *odest;
if (argc < 2 && !another(&argc, &argv, "remote-files"))
goto usage;
@@ -1105,7 +1177,7 @@ usage:
code = -1;
return;
}
- dest = argv[argc - 1];
+ odest = dest = argv[argc - 1];
argv[argc - 1] = NULL;
if (strcmp(dest, "-") && *dest != '|')
if (!globulize(&dest) ||
@@ -1120,7 +1192,8 @@ usage:
(void)setjmp(jabort);
for (i = 1; mflag && i < argc-1; ++i) {
*mode = (i == 1) ? 'w' : 'a';
- recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, 0);
+ recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
+ 0, 0);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
@@ -1132,6 +1205,8 @@ usage:
}
(void)signal(SIGINT, oldintr);
mflag = 0;
+ if (dest != odest) /* free up after globulize() */
+ free(dest);
}
/*
@@ -1911,7 +1986,9 @@ cdup(argc, argv)
dirchange = 1;
}
-/* restart transfer at specific point */
+/*
+ * Restart transfer at specific point
+ */
void
restart(argc, argv)
int argc;
@@ -1927,7 +2004,9 @@ restart(argc, argv)
}
}
-/* show remote system type */
+/*
+ * Show remote system type
+ */
void
syst(argc, argv)
int argc;
@@ -1999,7 +2078,7 @@ macdef(argc, argv)
}
/*
- * get size of file on remote machine
+ * Get size of file on remote machine
*/
void
sizecmd(argc, argv)
@@ -2020,7 +2099,7 @@ sizecmd(argc, argv)
}
/*
- * get last modification time of file on remote machine
+ * Get last modification time of file on remote machine
*/
void
modtime(argc, argv)
@@ -2041,7 +2120,7 @@ modtime(argc, argv)
}
/*
- * show status on remote machine
+ * Show status on remote machine
*/
void
rmtstatus(argc, argv)
@@ -2053,7 +2132,7 @@ rmtstatus(argc, argv)
}
/*
- * get file if modtime is more recent than current file
+ * Get file if modtime is more recent than current file
*/
void
newer(argc, argv)
@@ -2075,13 +2154,14 @@ page(argc, argv)
char *argv[];
{
int orestart_point, ohash, overbose;
- char *p, *pager;
+ char *p, *pager, *oldargv1;
if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) {
fprintf(ttyout, "usage: %s filename\n", argv[0]);
code = -1;
return;
}
+ oldargv1 = argv[1];
if (!globulize(&argv[1])) {
code = -1;
return;
@@ -2097,9 +2177,11 @@ page(argc, argv)
ohash = hash;
overbose = verbose;
restart_point = hash = verbose = 0;
- recvrequest("RETR", pager, argv[1], "r+w", 1);
+ recvrequest("RETR", pager, argv[1], "r+w", 1, 0);
(void)free(pager);
restart_point = orestart_point;
hash = ohash;
verbose = overbose;
+ if (oldargv1 != argv[1]) /* free up after globulize() */
+ free(argv[1]);
}
diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c
index 35963381815..6d6bb9e4b78 100644
--- a/usr.bin/ftp/cmdtab.c
+++ b/usr.bin/ftp/cmdtab.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: cmdtab.c,v 1.10 1997/07/25 21:56:18 millert Exp $ */
-/* $NetBSD: cmdtab.c,v 1.16 1997/07/20 09:45:41 lukem Exp $ */
+/* $OpenBSD: cmdtab.c,v 1.11 1997/09/04 04:37:13 millert Exp $ */
+/* $NetBSD: cmdtab.c,v 1.17 1997/08/18 10:20:17 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.10 1997/07/25 21:56:18 millert Exp $";
+static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.11 1997/09/04 04:37:13 millert Exp $";
#endif
#endif /* not lint */
@@ -69,6 +69,7 @@ char domachelp[] = "execute macro";
char edithelp[] = "toggle command line editing";
#endif /* !SMALL */
char formhelp[] = "set file transfer format";
+char gatehelp[] = "toggle gate-ftp; specify host[:port] to change proxy";
char globhelp[] = "toggle metacharacter expansion of local file names";
char hashhelp[] = "toggle printing `#' marks; specify number to set size";
char helphelp[] = "print local help information";
@@ -160,6 +161,7 @@ struct cmd cmdtab[] = {
{ "form", formhelp, 0, 1, 1, CMPL0 setform },
{ "ftp", connecthelp, 0, 0, 1, CMPL0 setpeer },
{ "get", receivehelp, 1, 1, 1, CMPL(rl) get },
+ { "gate", gatehelp, 0, 0, 0, CMPL0 setgate },
{ "glob", globhelp, 0, 0, 0, CMPL0 setglob },
{ "hash", hashhelp, 0, 0, 0, CMPL0 sethash },
{ "help", helphelp, 0, 0, 1, CMPL(C) help },
diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c
index efda6057106..3932cb23eba 100644
--- a/usr.bin/ftp/complete.c
+++ b/usr.bin/ftp/complete.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: complete.c,v 1.8 1997/07/25 21:56:18 millert Exp $ */
-/* $NetBSD: complete.c,v 1.9 1997/07/20 09:45:43 lukem Exp $ */
+/* $OpenBSD: complete.c,v 1.9 1997/09/04 04:37:14 millert Exp $ */
+/* $NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -27,8 +27,8 @@
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 REGENTS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * 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
@@ -39,7 +39,7 @@
#ifndef SMALL
#ifndef lint
-static char rcsid[] = "$OpenBSD: complete.c,v 1.8 1997/07/25 21:56:18 millert Exp $";
+static char rcsid[] = "$OpenBSD: complete.c,v 1.9 1997/09/04 04:37:14 millert Exp $";
#endif /* not lint */
/*
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 2abb286eb39..1cfa300cb07 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: extern.h,v 1.15 1997/07/25 21:56:19 millert Exp $ */
-/* $NetBSD: extern.h,v 1.16 1997/07/20 09:45:48 lukem Exp $ */
+/* $OpenBSD: extern.h,v 1.16 1997/09/04 04:37:14 millert Exp $ */
+/* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@@ -112,7 +112,7 @@ void quit __P((int, char **));
void quote __P((int, char **));
void quote1 __P((const char *, int, char **));
void recvrequest __P((const char *, const char *, const char *,
- const char *, int));
+ const char *, int, int));
void reget __P((int, char **));
char *remglob __P((char **, int, char **));
off_t remotesize __P((const char *, int));
@@ -134,6 +134,7 @@ void setdebug __P((int, char **));
void setedit __P((int, char **));
void setform __P((int, char **));
void setftmode __P((int, char **));
+void setgate __P((int, char **));
void setglob __P((int, char **));
void sethash __P((int, char **));
void setnmap __P((int, char **));
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index bc46dbb30f9..c6c431106f1 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: fetch.c,v 1.14 1997/07/25 21:56:20 millert Exp $ */
-/* $NetBSD: fetch.c,v 1.13 1997/07/20 12:49:26 lukem Exp $ */
+/* $OpenBSD: fetch.c,v 1.15 1997/09/04 04:37:15 millert Exp $ */
+/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -27,8 +27,8 @@
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 REGENTS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * 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
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.14 1997/07/25 21:56:20 millert Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.15 1997/09/04 04:37:15 millert Exp $";
#endif /* not lint */
/*
@@ -209,7 +209,7 @@ url_get(origline, proxyenv, fd)
long nport;
nport = strtol(portnum, &ep, 10);
- if (nport < 1 || nport > 0xffff || *ep != '\0') {
+ if (nport < 1 || nport > USHRT_MAX || *ep != '\0') {
warnx("Invalid port: %s", portnum);
goto cleanup_url_get;
}
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index 0f08e9d8b09..15c0e83ee02 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,5 +1,5 @@
-.\" $OpenBSD: ftp.1,v 1.13 1997/07/25 21:56:20 millert Exp $
-.\" $NetBSD: ftp.1,v 1.21 1997/06/10 21:59:58 lukem Exp $
+.\" $OpenBSD: ftp.1,v 1.14 1997/09/04 04:37:15 millert Exp $
+.\" $NetBSD: ftp.1,v 1.22 1997/08/18 10:20:22 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -34,7 +34,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd February 23, 1997
+.Dd August 18, 1997
.Dt FTP 1
.Os BSD 4.2
.Sh NAME
@@ -331,6 +331,21 @@ The current settings for
and
.Ic structure
are used while transferring the file.
+.It Ic gate Op Ar host Op Ar port
+Toggle gate-ftp mode.
+This will not be permitted if the gate-ftp server hasn't been set
+(either explicitly by the user, or from the
+.Ev FTPSERVER
+environment variable).
+If
+.Ar host
+is given,
+then gate-ftp mode will be enabled, and the gate-ftp server will be set to
+.Ar host .
+If
+.Ar port
+is also given, that will be used as the port to connect to on the
+gate-ftp server.
.It Ic glob
Toggle filename expansion for
.Ic mdelete ,
@@ -1322,6 +1337,18 @@ By default, this is bound to the TAB key.
.Nm
utilizes the following environment variables.
.Bl -tag -width "http_proxy"
+.It Ev FTPSERVER
+Host to use as gate-ftp server when
+.Ic gate
+is enabled.
+.It Ev FTPSERVERPORT
+Port to use when connecting to gate-ftp server when
+.Ic gate
+is enabled.
+Default is port returned by a
+.Fn getservbyname
+lookup of
+.Dq ftpgate/tcp .
.It Ev HOME
For default location of a
.Pa .netrc
@@ -1339,7 +1366,9 @@ URL of FTP proxy to use when making FTP URL requests
URL of HTTP proxy to use when making HTTP URL requests.
.El
.Sh SEE ALSO
+.Xr getservbyname 3 ,
.Xr editrc 5 ,
+.Xr services 5 ,
.Xr ftpd 8
.Sh HISTORY
The
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 14e339de700..35e46d98cfa 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ftp.c,v 1.21 1997/08/06 17:35:41 mickey Exp $ */
-/* $NetBSD: ftp.c,v 1.26 1997/07/20 09:45:53 lukem Exp $ */
+/* $OpenBSD: ftp.c,v 1.22 1997/09/04 04:37:16 millert Exp $ */
+/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: ftp.c,v 1.21 1997/08/06 17:35:41 mickey Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.22 1997/09/04 04:37:16 millert Exp $";
#endif
#endif /* not lint */
@@ -713,9 +713,9 @@ abortrecv(notused)
}
void
-recvrequest(cmd, local, remote, lmode, printnames)
+recvrequest(cmd, local, remote, lmode, printnames, ignorespecial)
const char *cmd, *local, *remote, *lmode;
- int printnames;
+ int printnames, ignorespecial;
{
FILE *fout, *din;
int (*closefunc) __P((FILE *));
@@ -752,7 +752,7 @@ recvrequest(cmd, local, remote, lmode, printnames)
opreserve = preserve;
is_retr = strcmp(cmd, "RETR") == 0;
if (is_retr && verbose && printnames) {
- if (local && *local != '-')
+ if (local && (ignorespecial || *local != '-'))
fprintf(ttyout, "local: %s ", local);
if (remote)
fprintf(ttyout, "remote: %s\n", remote);
@@ -784,8 +784,8 @@ recvrequest(cmd, local, remote, lmode, printnames)
}
oldintr = signal(SIGINT, abortrecv);
oldinti = signal(SIGINFO, psummary);
- if (strcmp(local, "-") && *local != '|') {
- if (access(local, 2) < 0) {
+ if (ignorespecial || (strcmp(local, "-") && *local != '|')) {
+ if (access(local, W_OK) < 0) {
char *dir = strrchr(local, '/');
if (errno != ENOENT && errno != EACCES) {
@@ -797,7 +797,7 @@ recvrequest(cmd, local, remote, lmode, printnames)
}
if (dir != NULL)
*dir = 0;
- d = access(dir == local ? "/" : dir ? local : ".", 2);
+ d = access(dir == local ? "/" : dir ? local : ".", W_OK);
if (dir != NULL)
*dir = '/';
if (d < 0) {
@@ -865,11 +865,11 @@ recvrequest(cmd, local, remote, lmode, printnames)
din = dataconn("r");
if (din == NULL)
goto abort;
- if (strcmp(local, "-") == 0) {
+ if (!ignorespecial && strcmp(local, "-") == 0) {
fout = stdout;
progress = 0;
preserve = 0;
- } else if (*local == '|') {
+ } else if (!ignorespecial && *local == '|') {
oldintp = signal(SIGPIPE, SIG_IGN);
fout = popen(local + 1, "w");
if (fout == NULL) {
@@ -1002,9 +1002,10 @@ done:
}
break2:
if (bare_lfs) {
- printf(
+ fprintf(ttyout,
"WARNING! %d bare linefeeds received in ASCII mode.\n", bare_lfs);
- fputs("File may not have transferred correctly.\n", ttyout);
+ fputs("File may not have transferred correctly.\n",
+ ttyout);
}
if (hash && (!progress || filesize < 0)) {
if (bytes < hashbytes)
@@ -1043,7 +1044,7 @@ break2:
ut.actime = time(NULL);
ut.modtime = mtime;
if (utime(local, &ut) == -1)
- printf(
+ fprintf(ttyout,
"Can't change modification time on %s to %s",
local, asctime(localtime(&mtime)));
}
@@ -1528,7 +1529,7 @@ gunique(local)
if (cp)
*cp = '\0';
- d = access(cp == local ? "/" : cp ? local : ".", 2);
+ d = access(cp == local ? "/" : cp ? local : ".", W_OK);
if (cp)
*cp = '/';
if (d < 0) {
@@ -1549,7 +1550,7 @@ gunique(local)
ext = '0';
else
ext++;
- if ((d = access(new, 0)) < 0)
+ if ((d = access(new, F_OK)) < 0)
break;
if (ext != '0')
cp--;
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index 337c18932c1..bffe7894738 100644
--- a/usr.bin/ftp/ftp_var.h
+++ b/usr.bin/ftp/ftp_var.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: ftp_var.h,v 1.13 1997/07/25 21:56:21 millert Exp $ */
-/* $NetBSD: ftp_var.h,v 1.17 1997/07/20 09:45:55 lukem Exp $ */
+/* $OpenBSD: ftp_var.h,v 1.14 1997/09/04 04:37:16 millert Exp $ */
+/* $NetBSD: ftp_var.h,v 1.18 1997/08/18 10:20:25 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -55,8 +55,15 @@
#define STALLTIME 5 /* # of seconds of no xfer before "stalling" */
-#define FTP_PORT 21 /* default if getservbyname("ftp/tcp") fails */
-#define HTTP_PORT 80 /* default if getservbyname("http/tcp") fails */
+#define FTP_PORT 21 /* default if ! getservbyname("ftp/tcp") */
+#define HTTP_PORT 80 /* default if ! getservbyname("http/tcp") */
+#ifndef GATE_PORT
+#define GATE_PORT 21 /* default if ! getservbyname("ftpgate/tcp") */
+#endif
+#ifndef GATE_SERVER
+#define GATE_SERVER "" /* default server */
+#endif
+
#define PAGER "more" /* default pager if $PAGER isn't set */
/*
@@ -77,6 +84,8 @@ int doglob; /* glob local file names */
int autologin; /* establish user account on connection */
int proxy; /* proxy server connection active */
int proxflag; /* proxy connection exists */
+int gatemode; /* use gate-ftp */
+char *gateserver; /* server to use for gate-ftp */
int sunique; /* store files on server with unique name */
int runique; /* store local files with unique name */
int mcase; /* map upper to lower case for mget names */
@@ -88,7 +97,7 @@ int code; /* return/reply code for ftp command */
int crflag; /* if 1, strip car. rets. on ascii gets */
char pasv[64]; /* passive port for proxy data connection */
int passivemode; /* passive mode enabled */
-char *altarg; /* argv[1] with no shell-like preprocessing */
+char *altarg; /* argv[1] with no shell-like preprocessing */
char ntin[17]; /* input translation table */
char ntout[17]; /* output translation table */
char mapin[MAXPATHLEN]; /* input map template */
@@ -122,11 +131,13 @@ off_t bytes; /* current # of bytes read */
off_t filesize; /* size of file being transferred */
char *direction; /* direction transfer is occurring */
-char *hostname; /* name of host connected to */
+char *hostname; /* name of host connected to */
int unix_server; /* server is unix, can use binary for ascii */
int unix_proxy; /* proxy is unix, can use binary for ascii */
+
in_port_t ftpport; /* port number to use for ftp connections */
in_port_t httpport; /* port number to use for http connections */
+in_port_t gateport; /* port number to use for gateftp connections */
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index 626b0b6cee6..f9ae7bbf942 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: main.c,v 1.35 1997/08/06 17:35:42 mickey Exp $ */
-/* $NetBSD: main.c,v 1.23 1997/07/20 09:45:58 lukem Exp $ */
+/* $OpenBSD: main.c,v 1.36 1997/09/04 04:37:16 millert Exp $ */
+/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -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.35 1997/08/06 17:35:42 mickey Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.36 1997/09/04 04:37:16 millert Exp $";
#endif
#endif /* not lint */
@@ -76,7 +76,7 @@ main(argc, argv)
int ch, top, rval;
long port;
struct passwd *pw = NULL;
- char *cp, homedir[MAXPATHLEN];
+ char *cp, *ep, homedir[MAXPATHLEN];
int dumb_terminal = 0;
int outfd = -1;
@@ -90,6 +90,23 @@ main(argc, argv)
httpport = htons(HTTP_PORT); /* good fallback */
else
httpport = sp->s_port;
+ gateport = 0;
+ cp = getenv("FTPSERVERPORT");
+ if (cp != NULL) {
+ port = strtol(cp, &ep, 10);
+ if (port < 1 || port > USHRT_MAX || *ep != '\0')
+ warnx("bad FTPSERVERPORT port number: %s (ignored)",
+ cp);
+ else
+ gateport = htons(port);
+ }
+ if (gateport == 0) {
+ sp = getservbyname("ftpgate", "tcp");
+ if (sp == 0)
+ gateport = htons(GATE_PORT);
+ else
+ gateport = sp->s_port;
+ }
doglob = 1;
interactive = 1;
autologin = 1;
@@ -97,6 +114,7 @@ main(argc, argv)
preserve = 1;
verbose = 0;
progress = 0;
+ gatemode = 0;
#ifndef SMALL
editing = 0;
el = NULL;
@@ -109,6 +127,19 @@ main(argc, argv)
cp = (cp == NULL) ? argv[0] : cp + 1;
if (strcmp(cp, "pftp") == 0)
passivemode = 1;
+ else if (strcmp(cp, "gate-ftp") == 0)
+ gatemode = 1;
+
+ gateserver = getenv("FTPSERVER");
+ if (gateserver == NULL || *gateserver == '\0')
+ gateserver = GATE_SERVER;
+ if (gatemode) {
+ if (*gateserver == '\0') {
+ warnx(
+"Neither $FTPSERVER nor GATE_SERVER is defined; disabling gate-ftp");
+ gatemode = 0;
+ }
+ }
cp = getenv("TERM");
dumb_terminal = (cp == NULL || !strcmp(cp, "dumb") ||
@@ -165,8 +196,8 @@ main(argc, argv)
break;
case 'P':
- port = strtol(optarg, &cp, 10);
- if (port < 1 || port > 0xffff || *cp != '\0')
+ port = strtol(optarg, &ep, 10);
+ if (port < 1 || port > USHRT_MAX || *ep != '\0')
warnx("bad port number: %s (ignored)", optarg);
else
ftpport = htons((in_port_t)port);
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 2166786757e..0fb8c5c6f0e 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: util.c,v 1.12 1997/08/25 21:41:55 jkatz Exp $ */
-/* $NetBSD: util.c,v 1.11 1997/07/21 14:03:49 lukem Exp $ */
+/* $OpenBSD: util.c,v 1.13 1997/09/04 04:37:17 millert Exp $ */
+/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.12 1997/08/25 21:41:55 jkatz Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.13 1997/09/04 04:37:17 millert Exp $";
#endif /* not lint */
/*
@@ -87,13 +87,16 @@ setpeer(argc, argv)
code = -1;
return;
}
- port = ftpport;
+ if (gatemode)
+ port = gateport;
+ else
+ port = ftpport;
if (argc > 2) {
char *ep;
long nport;
nport = strtol(argv[2], &ep, 10);
- if (nport < 1 || nport > 0xffff || *ep != '\0') {
+ if (nport < 1 || nport > USHRT_MAX || *ep != '\0') {
fprintf(ttyout, "%s: bad port number '%s'.\n",
argv[1], argv[2]);
fprintf(ttyout, "usage: %s host-name [port]\n",
@@ -103,10 +106,26 @@ setpeer(argc, argv)
}
port = htons((in_port_t)nport);
}
- host = hookup(argv[1], port);
+
+ if (gatemode) {
+ if (gateserver == NULL || *gateserver == '\0')
+ errx(1, "gateserver not defined (shouldn't happen)");
+ host = hookup(gateserver, port);
+ } else
+ host = hookup(argv[1], port);
+
if (host) {
int overbose;
+ if (gatemode) {
+ if (command("PASSERVE %s", argv[1]) != COMPLETE)
+ return;
+ if (verbose)
+ fprintf(ttyout,
+ "Connected via pass-through server %s\n",
+ gateserver);
+ }
+
connected = 1;
/*
* Set up defaults for FTP.
@@ -384,7 +403,7 @@ remglob(argv, doswitch, errbuf)
if (doswitch)
pswitch(!proxy);
for (mode = "w"; *++argv != NULL; mode = "a")
- recvrequest("NLST", temp, *argv, mode, 0);
+ recvrequest("NLST", temp, *argv, mode, 0, 0);
if ((code / 100) != COMPLETE) {
if (errbuf != NULL)
*errbuf = reply_string;
@@ -475,7 +494,10 @@ globulize(cpp)
globfree(&gl);
return (0);
}
- *cpp = strdup(gl.gl_pathv[0]); /* XXX - wasted memory */
+ /* XXX: caller should check if *cpp changed, and
+ * free(*cpp) if that is the case
+ */
+ *cpp = strdup(gl.gl_pathv[0]);
globfree(&gl);
return (1);
}