summaryrefslogtreecommitdiff
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-12-17 16:03:06 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-12-17 16:03:06 +0000
commitc8f9924fcf1891ef48d930a33d2431230b65d1d4 (patch)
tree808da54b7316669f53251a4aed099cdaf7fab195 /usr.bin/ftp
parent8cea511de8022ef4c932d0936bb1b9e3fad5a4d4 (diff)
By default, use passive mode and fall back to active as needed.
The user can specify active only with the -A flag, or use the new FTPMODE envariable.
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/ftp.127
-rw-r--r--usr.bin/ftp/ftp.c12
-rw-r--r--usr.bin/ftp/ftp_var.h3
-rw-r--r--usr.bin/ftp/main.c41
4 files changed, 68 insertions, 15 deletions
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index 6f2d635e60a..dd9f5258818 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ftp.1,v 1.15 1997/09/04 04:42:34 millert Exp $
+.\" $OpenBSD: ftp.1,v 1.16 1997/12/17 16:03:01 millert Exp $
.\" $NetBSD: ftp.1,v 1.22 1997/08/18 10:20:22 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
@@ -44,6 +44,7 @@
file transfer program
.Sh SYNOPSIS
.Nm
+.Op Fl A
.Op Fl a
.Op Fl d
.Op Fl e
@@ -80,6 +81,14 @@ below for more information.
Options may be specified at the command line, or to the
command interpreter.
.Bl -tag -width "port "
+.It Fl A
+Force active mode ftp. By default,
+.Nm
+will try to use passive mode ftp and fall back to active mode
+if passive is not supported by the server. This option causes
+.Nm
+to always use an active connection. It is only useful for connecting
+to very old servers that do not implement passive mode properly.
.It Fl a
Causes
.Nm
@@ -112,6 +121,10 @@ identity on the local machine), and, if necessary, prompt for a password
and an account with which to login.
.It Fl p
Enable passive mode operation for use behind connection filtering firewalls.
+This option has been deprecated as
+.Nm
+now tries to use passive mode by default, falling back to active mode
+if the server does not support passive connections.
.It Fl P Ar port
Sets the port number to
.Ar port .
@@ -1337,6 +1350,18 @@ By default, this is bound to the TAB key.
.Nm
utilizes the following environment variables.
.Bl -tag -width "FTPSERVERPORT"
+.It Ev FTPMODE
+Overrides the default operation mode. Recognized values are:
+.Bl -tag -width "passive "
+.It passive
+passive mode ftp only
+.It active
+active mode ftp only
+.It auto
+automatic determination of passive or active (this is the default)
+.It gate
+gate-ftp mode
+.El
.It Ev FTPSERVER
Host to use as gate-ftp server when
.Ic gate
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 5f50e776f25..29be2baeecf 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp.c,v 1.23 1997/09/05 00:02:29 millert Exp $ */
+/* $OpenBSD: ftp.c,v 1.24 1997/12/17 16:03:03 millert Exp $ */
/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 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.23 1997/09/05 00:02:29 millert Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.24 1997/12/17 16:03:03 millert Exp $";
#endif
#endif /* not lint */
@@ -1096,6 +1096,7 @@ initconn()
int on = 1;
int a0, a1, a2, a3, p0, p1;
+reinit:
if (passivemode) {
data = socket(AF_INET, SOCK_STREAM, 0);
if (data < 0) {
@@ -1107,6 +1108,13 @@ initconn()
sizeof(on)) < 0)
warn("setsockopt (ignored)");
if (command("PASV") != COMPLETE) {
+ if (activefallback) {
+ (void)close(data);
+ data = -1;
+ passivemode = 0;
+ activefallback = 0;
+ goto reinit;
+ }
fputs("Passive mode refused.\n", ttyout);
goto bad;
}
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index 5b4b90ce6ca..04a30d0b020 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.16 1997/10/02 04:22:01 imp Exp $ */
+/* $OpenBSD: ftp_var.h,v 1.17 1997/12/17 16:03:04 millert Exp $ */
/* $NetBSD: ftp_var.h,v 1.18 1997/08/18 10:20:25 lukem Exp $ */
/*
@@ -102,6 +102,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 */
+int activefallback; /* fall back to active mode if passive fails */
char *altarg; /* argv[1] with no shell-like preprocessing */
char ntin[17]; /* input translation table */
char ntout[17]; /* output translation table */
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index f9ae7bbf942..b09fc7aaba0 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.36 1997/09/04 04:37:16 millert Exp $ */
+/* $OpenBSD: main.c,v 1.37 1997/12/17 16:03:05 millert Exp $ */
/* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 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.36 1997/09/04 04:37:16 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.37 1997/12/17 16:03:05 millert Exp $";
#endif
#endif /* not lint */
@@ -110,7 +110,8 @@ main(argc, argv)
doglob = 1;
interactive = 1;
autologin = 1;
- passivemode = 0;
+ passivemode = 1;
+ activefallback = 1;
preserve = 1;
verbose = 0;
progress = 0;
@@ -123,20 +124,32 @@ main(argc, argv)
mark = HASHBYTES;
marg_sl = sl_init();
- cp = strrchr(argv[0], '/');
- cp = (cp == NULL) ? argv[0] : cp + 1;
- if (strcmp(cp, "pftp") == 0)
- passivemode = 1;
- else if (strcmp(cp, "gate-ftp") == 0)
- gatemode = 1;
+ /* Set default operation mode based on FTPMODE environment variable */
+ if ((cp = getenv("FTPMODE")) != NULL) {
+ if (strcmp(cp, "passive") == 0) {
+ passivemode = 1;
+ activefallback = 0;
+ } else if (strcmp(cp, "active") == 0) {
+ passivemode = 0;
+ activefallback = 0;
+ } else if (strcmp(cp, "gate") == 0) {
+ gatemode = 1;
+ } else if (strcmp(cp, "auto") == 0) {
+ passivemode = 1;
+ activefallback = 1;
+ } else
+ warnx("unknown FTPMODE: %s. Using defaults", cp);
+ }
+ if (strcmp(__progname, "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");
+"Neither $FTPSERVER nor $GATE_SERVER is defined; disabling gate-ftp");
gatemode = 0;
}
}
@@ -162,8 +175,13 @@ main(argc, argv)
ttyout = stderr;
}
- while ((ch = getopt(argc, argv, "adeginpPr:tvV")) != -1) {
+ while ((ch = getopt(argc, argv, "AadeginpPr:tvV")) != -1) {
switch (ch) {
+ case 'A':
+ activefallback = 0;
+ passivemode = 0;
+ break;
+
case 'a':
anonftp = 1;
break;
@@ -193,6 +211,7 @@ main(argc, argv)
case 'p':
passivemode = 1;
+ activefallback = 0;
break;
case 'P':