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]]'
This commit is contained in:
lukem 1997-08-18 10:20:13 +00:00
parent 5170e3eccc
commit 2fec2a28f5
11 changed files with 264 additions and 86 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.12 1997/07/20 09:45:35 lukem Exp $
# $NetBSD: Makefile,v 1.13 1997/08/18 10:20:13 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
PROG= ftp
@ -6,6 +6,10 @@ SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c ruserpass.c \
util.c
WARNS= 1
# Uncomment the following to provide defaults for gate-ftp operation
#
#CFLAGS+=-DGATE_SERVER=\"ftp-gw.host\" # -DGATE_PORT=21
LDADD+= -ledit -ltermcap
DPADD+= ${LIBEDIT} ${LIBTERMCAP}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.26 1997/07/21 14:03:48 lukem 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
__RCSID("$NetBSD: cmds.c,v 1.26 1997/07/21 14:03:48 lukem Exp $");
__RCSID("$NetBSD: cmds.c,v 1.27 1997/08/18 10:20:15 lukem 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 */
@ -595,7 +605,7 @@ mget(argc, argv)
tp = domap(tp);
}
recvrequest("RETR", tp, cp, "w",
tp != cp || !interactive);
tp != cp || !interactive, 1);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
@ -645,6 +655,8 @@ status(argc, argv)
}
pswitch(0);
}
printf("Gate ftp: %s, server %s, port %d.\n", onoff(gatemode),
*gateserver ? gateserver : "(none)", ntohs(gateport));
printf("Passive mode: %s.\n", onoff(passivemode));
printf("Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
modename, typename, formname, structname);
@ -825,8 +837,7 @@ setprogress(argc, argv)
}
/*
* Turn on interactive prompting
* during mget, mput, and mdelete.
* Turn on interactive prompting during mget, mput, and mdelete.
*/
/*VARARGS*/
void
@ -839,8 +850,60 @@ 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) {
printf("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 > 0xffff || *ep != '\0') {
printf("%s: bad gateport value.\n",
argv[2]);
code = -1;
return;
}
gateport = htons(port);
}
strncpy(gsbuf, argv[1], sizeof(gsbuf) - 1);
gateserver = gsbuf;
gatemode = 1;
}
}
if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
printf(
"Disabling gate-ftp mode - no gate-ftp server defined.\n");
gatemode = 0;
} else {
printf("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
@ -866,8 +929,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
@ -907,8 +969,7 @@ setdebug(argc, argv)
}
/*
* Set current working directory
* on remote machine.
* Set current working directory on remote machine.
*/
void
cd(argc, argv)
@ -934,8 +995,7 @@ cd(argc, argv)
}
/*
* Set current working directory
* on local machine.
* Set current working directory on local machine.
*/
void
lcd(argc, argv)
@ -943,6 +1003,7 @@ lcd(argc, argv)
char *argv[];
{
char buf[MAXPATHLEN];
char *oldargv1;
if (argc < 2)
argc++, argv[1] = home;
@ -951,6 +1012,7 @@ lcd(argc, argv)
code = -1;
return;
}
oldargv1 = argv[1];
if (!globulize(&argv[1])) {
code = -1;
return;
@ -958,13 +1020,15 @@ lcd(argc, argv)
if (chdir(argv[1]) < 0) {
warn("local: %s", argv[1]);
code = -1;
return;
}
} else {
if (getcwd(buf, sizeof(buf)) != NULL)
printf("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]);
}
/*
@ -1048,8 +1112,7 @@ usage:
}
/*
* Get a directory listing
* of remote files.
* Get a directory listing of remote files.
*/
void
ls(argc, argv)
@ -1057,6 +1120,7 @@ ls(argc, argv)
char *argv[];
{
const char *cmd;
char *oldargv2, *globargv2;
if (argc < 2)
argc++, argv[1] = NULL;
@ -1068,25 +1132,31 @@ 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;
}
globargv2 = argv[2];
if (strcmp(argv[2], "-") && *argv[2] != '|')
if (!globulize(&argv[2]) || !confirm("output to local-file:",
argv[2])) {
code = -1;
return;
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(stdout);
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)
@ -1096,7 +1166,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;
@ -1106,7 +1176,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) ||
@ -1121,7 +1191,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;
@ -1133,6 +1204,8 @@ usage:
}
(void)signal(SIGINT, oldintr);
mflag = 0;
if (dest != odest) /* free up after globulize() */
free(dest);
}
/*
@ -1911,7 +1984,9 @@ cdup(argc, argv)
dirchange = 1;
}
/* restart transfer at specific point */
/*
* Restart transfer at specific point
*/
void
restart(argc, argv)
int argc;
@ -1927,7 +2002,9 @@ restart(argc, argv)
}
}
/* show remote system type */
/*
* Show remote system type
*/
void
syst(argc, argv)
int argc;
@ -1999,7 +2076,7 @@ macdef(argc, argv)
}
/*
* get size of file on remote machine
* Get size of file on remote machine
*/
void
sizecmd(argc, argv)
@ -2020,7 +2097,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 +2118,7 @@ modtime(argc, argv)
}
/*
* show status on remote machine
* Show status on remote machine
*/
void
rmtstatus(argc, argv)
@ -2053,7 +2130,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 +2152,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) {
printf("usage: %s filename\n", argv[0]);
code = -1;
return;
}
oldargv1 = argv[1];
if (!globulize(&argv[1])) {
code = -1;
return;
@ -2097,9 +2175,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]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmdtab.c,v 1.16 1997/07/20 09:45:41 lukem 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
__RCSID("$NetBSD: cmdtab.c,v 1.16 1997/07/20 09:45:41 lukem Exp $");
__RCSID("$NetBSD: cmdtab.c,v 1.17 1997/08/18 10:20:17 lukem 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 },

View File

@ -1,4 +1,4 @@
/* $NetBSD: complete.c,v 1.9 1997/07/20 09:45:43 lukem Exp $ */
/* $NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -26,8 +26,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
@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: complete.c,v 1.9 1997/07/20 09:45:43 lukem Exp $");
__RCSID("$NetBSD: complete.c,v 1.10 1997/08/18 10:20:18 lukem Exp $");
#endif /* not lint */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.16 1997/07/20 09:45:48 lukem 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.
@ -110,7 +110,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));
@ -132,6 +132,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 **));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.13 1997/07/20 12:49:26 lukem Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -26,8 +26,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 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: fetch.c,v 1.13 1997/07/20 12:49:26 lukem Exp $");
__RCSID("$NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $");
#endif /* not lint */
/*

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.21 1997/06/10 21:59:58 lukem 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.
@ -33,7 +33,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
@ -326,6 +326,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 ,
@ -1314,6 +1329,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
@ -1331,7 +1358,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

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp.c,v 1.26 1997/07/20 09:45:53 lukem 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
__RCSID("$NetBSD: ftp.c,v 1.26 1997/07/20 09:45:53 lukem Exp $");
__RCSID("$NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $");
#endif
#endif /* not lint */
@ -707,9 +707,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 *));
@ -747,7 +747,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 != '-'))
printf("local: %s ", local);
if (remote)
printf("remote: %s\n", remote);
@ -779,7 +779,7 @@ recvrequest(cmd, local, remote, lmode, printnames)
}
oldintr = signal(SIGINT, abortrecv);
oldinti = signal(SIGINFO, psummary);
if (strcmp(local, "-") && *local != '|') {
if (ignorespecial || (strcmp(local, "-") && *local != '|')) {
if (access(local, 2) < 0) {
char *dir = strrchr(local, '/');
@ -860,11 +860,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) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.17 1997/07/20 09:45:55 lukem Exp $ */
/* $NetBSD: ftp_var.h,v 1.18 1997/08/18 10:20:25 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -54,8 +54,14 @@
#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 "less" /* default pager if $PAGER isn't set */
@ -77,6 +83,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 */
@ -124,8 +132,10 @@ char *direction; /* direction transfer is occurring */
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 */
u_int16_t ftpport; /* port number to use for ftp connections */
u_int16_t httpport; /* port number to use for http connections */
u_int16_t gateport; /* port number to use for gateftp connections */
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.23 1997/07/20 09:45:58 lukem Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: main.c,v 1.23 1997/07/20 09:45:58 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $");
#endif
#endif /* not lint */
@ -74,7 +74,7 @@ main(argc, argv)
int ch, top, rval;
long port;
struct passwd *pw = NULL;
char *cp, homedir[MAXPATHLEN];
char *cp, *ep, homedir[MAXPATHLEN];
int dumbterm;
sp = getservbyname("ftp", "tcp");
@ -87,6 +87,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 > 0xffff || *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;
@ -94,6 +111,7 @@ main(argc, argv)
preserve = 1;
verbose = 0;
progress = 0;
gatemode = 0;
#ifndef SMALL
editing = 0;
el = NULL;
@ -106,6 +124,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");
if (cp == NULL || strcmp(cp, "dumb") == 0)
@ -157,8 +188,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 > 0xffff || *ep != '\0')
warnx("bad port number: %s (ignored)", optarg);
else
ftpport = htons(port);

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.11 1997/07/21 14:03:49 lukem 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 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.11 1997/07/21 14:03:49 lukem Exp $");
__RCSID("$NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $");
#endif /* not lint */
/*
@ -85,6 +85,9 @@ setpeer(argc, argv)
code = -1;
return;
}
if (gatemode)
port = gateport;
else
port = ftpport;
if (argc > 2) {
char *ep;
@ -99,10 +102,25 @@ setpeer(argc, argv)
}
port = htons(nport);
}
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)
printf("Connected via pass-through server %s\n",
gateserver);
}
connected = 1;
/*
* Set up defaults for FTP.
@ -352,7 +370,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;
@ -433,7 +451,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);
}