summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>1999-06-25 14:11:16 +0000
committerru <ru@FreeBSD.org>1999-06-25 14:11:16 +0000
commitd321f9c4e499838b14e5ff3e1057ab29cabc608f (patch)
tree7be728efd338a63d9edbeaad8559863cdc69d705 /usr.bin/ftp
parent5ed26c8f51820fc71578a9f1abc4fa06760f89d3 (diff)
downloadFreeBSD-src-d321f9c4e499838b14e5ff3e1057ab29cabc608f.zip
FreeBSD-src-d321f9c4e499838b14e5ff3e1057ab29cabc608f.tar.gz
- add "-s src_addr" option to allow setting of the source IP address;
- fix two minor bugs; - slightly cleanup manpage.
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/Makefile3
-rw-r--r--usr.bin/ftp/fetch.c8
-rw-r--r--usr.bin/ftp/ftp.155
-rw-r--r--usr.bin/ftp/ftp.c49
-rw-r--r--usr.bin/ftp/ftp_var.h6
-rw-r--r--usr.bin/ftp/main.c56
-rw-r--r--usr.bin/ftp/util.c6
7 files changed, 108 insertions, 75 deletions
diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile
index 225d10e..c74e3ad 100644
--- a/usr.bin/ftp/Makefile
+++ b/usr.bin/ftp/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.7 1997/10/05 09:39:55 jkh Exp $
+# $Id: Makefile,v 1.8 1997/12/13 20:38:12 pst Exp $
# $NetBSD: Makefile,v 1.15 1997/10/18 15:31:20 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
@@ -9,7 +9,6 @@
PROG= ftp
SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c ruserpass.c \
util.c
-CFLAGS+=-I${.CURDIR}/../../contrib-crypto/telnet
LDADD+= -ledit -ltermcap
DPADD+= ${LIBEDIT} ${LIBTERMCAP}
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 2f2450e..a675886 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$Id: fetch.c,v 1.4 1997/12/16 08:22:35 ache Exp $");
+__RCSID("$Id: fetch.c,v 1.5 1997/12/16 08:58:15 ache Exp $");
__RCSID_SOURCE("$NetBSD: fetch.c,v 1.16.2.1 1997/11/18 01:00:22 mellon Exp $");
#endif /* not lint */
@@ -223,6 +223,12 @@ url_get(origline, proxyenv)
goto cleanup_url_get;
}
+ if (dobind && bind(s, (struct sockaddr *)&bindto,
+ sizeof(bindto)) == -1) {
+ warn("Can't bind to %s", inet_ntoa(bindto.sin_addr));
+ goto cleanup_url_get;
+ }
+
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
warn("Can't connect to %s", host);
goto cleanup_url_get;
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index aa1f794..738000f 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,4 +1,4 @@
-.\" $Id: ftp.1,v 1.7 1997/12/13 20:38:17 pst Exp $
+.\" $Id: ftp.1,v 1.8 1998/03/01 18:58:03 steve Exp $
.\" $NetBSD: ftp.1,v 1.21 1997/06/10 21:59:58 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
@@ -44,18 +44,9 @@
file transfer program
.Sh SYNOPSIS
.Nm
-.Op Fl a
-.Op Fl d
-.Op Fl e
-.Op Fl g
-.Op Fl i
-.Op Fl n
-.Op Fl U
-.Op Fl p
+.Op Fl adeginptUvV
.Op Fl P Ar port
-.Op Fl t
-.Op Fl v
-.Op Fl V
+.Op Fl s Ar src_addr
.Op Ar host Op Ar port
.Nm ftp
ftp://[\fIuser\fR:\fIpassword\fR@]\fIhost\fR[:\fIport\fR]/\fIfile\fR[/]
@@ -80,7 +71,7 @@ below for more information.
.Pp
Options may be specified at the command line, or to the
command interpreter.
-.Bl -tag -width "port "
+.Bl -tag -width Fl
.It Fl a
Causes
.Nm
@@ -91,8 +82,6 @@ Enables debugging.
Disables command line editing.
.It Fl g
Disables file name globbing.
-.It Fl U
-Disable data port range restrictions.
.It Fl i
Turns off interactive prompting during
multiple file transfers.
@@ -114,15 +103,21 @@ will prompt for the remote machine login name (default is the user
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.
+Enables passive mode operation for use behind connection filtering firewalls.
Using the
.Nm pftp
command has the same effect.
.It Fl P Ar port
Sets the port number to
.Ar port .
+.It Fl s Ar src_addr
+Sets the local IP address for all connections to
+.Ar src_addr ,
+which can be an IP address or a host name.
.It Fl t
Enables packet tracing.
+.It Fl U
+Disable data port range restrictions.
.It Fl v
Enable verbose mode.
This is the default if input is from a terminal.
@@ -184,7 +179,7 @@ setting.
File transfer uses the current settings for
.Ic type ,
.Ic format ,
-.Ic mode ,
+.Ic mode
and
.Ic structure .
.It Ic ascii
@@ -262,7 +257,7 @@ on the remote machine.
Toggle debugging mode.
If an optional
.Ar debug-value
-is specified it is used to set the debugging level.
+is specified, it is used to set the debugging level.
When debugging is on,
.Nm
prints each command sent to the remote machine, preceded
@@ -322,14 +317,14 @@ file name is not specified, it is given the same
name it has on the remote machine, subject to
alteration by the current
.Ic case ,
-.Ic ntrans ,
+.Ic ntrans
and
.Ic nmap
settings.
The current settings for
.Ic type ,
.Ic form ,
-.Ic mode ,
+.Ic mode
and
.Ic structure
are used while transferring the file.
@@ -479,7 +474,7 @@ See
for details on the filename expansion.
Resulting file names will then be processed according to
.Ic case ,
-.Ic ntrans ,
+.Ic ntrans
and
.Ic nmap
settings.
@@ -611,7 +606,7 @@ Spaces may be included in
.Ar outpattern ,
as in the example: `nmap $1 sed "s/ *$//" > $1' .
Use the `\e' character to prevent special treatment
-of the `$','[',']', and `,' characters.
+of the `$','[',']' and `,' characters.
.It Ic ntrans Op Ar inchars Op Ar outchars
Set or unset the filename character translation mechanism.
If no arguments are specified, the filename character
@@ -759,7 +754,7 @@ and
transfer files from the host on the primary control connection
to the host on the secondary control connection, and
.Ic put ,
-.Ic mput ,
+.Ic mput
and
.Ic append
transfer files from the host on the secondary control connection
@@ -782,7 +777,7 @@ File transfer uses the
current settings for
.Ic type ,
.Ic format ,
-.Ic mode ,
+.Ic mode
and
.Ic structure .
.It Ic pwd
@@ -859,7 +854,7 @@ to the client host on a separate data port. In previous versions, that
remote port fell in the range 1024..4999. However, most firewall setups
filter that range of TCP ports because other services reside there.
The default behavior now is for the client to request that the server
-connect back to the client using the port range 40000..44999. Firewall
+connect back to the client using the port range 49152..65535. Firewall
administrators can chose to allow TCP connections in that range, if they
deem it to not be a security risk.
.It Ic rmdir Ar directory-name
@@ -1153,7 +1148,9 @@ must be quoted; e.g.
A particularly
useful example of this mechanism is: \*(Lqdir \&|more\*(Rq.
.It
-Failing the above checks, if ``globbing'' is enabled,
+Failing the above checks, if
+.Dq globbing
+is enabled,
local file names are expanded
according to the rules used in the
.Xr csh 1 ;
@@ -1162,7 +1159,7 @@ c.f. the
command.
If the
.Nm
-command expects a single local file (.e.g.
+command expects a single local file (e.g.
.Ic put ) ,
only the first filename generated by the "globbing" operation is used.
.It
@@ -1201,7 +1198,7 @@ affect a file transfer.
The
.Ic type
may be one of \*(Lqascii\*(Rq, \*(Lqimage\*(Rq (binary),
-\*(Lqebcdic\*(Rq, and \*(Lqlocal byte size\*(Rq (for
+\*(Lqebcdic\*(Rq and \*(Lqlocal byte size\*(Rq (for
.Tn PDP Ns -10's
and
.Tn PDP Ns -20's
@@ -1216,7 +1213,7 @@ mode transfers.
supports only the default values for the remaining
file transfer parameters:
.Ic mode ,
-.Ic form ,
+.Ic form
and
.Ic struct .
.Sh THE .netrc FILE
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index a1e49a3..154f694 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $Id: ftp.c,v 1.14 1998/07/26 18:49:36 imp Exp $ */
+/* $Id: ftp.c,v 1.15 1998/12/09 20:49:20 eivind Exp $ */
/* $NetBSD: ftp.c,v 1.29.2.1 1997/11/18 01:01:04 mellon Exp $ */
/*
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$Id: ftp.c,v 1.14 1998/07/26 18:49:36 imp Exp $");
+__RCSID("$Id: ftp.c,v 1.15 1998/12/09 20:49:20 eivind Exp $");
__RCSID_SOURCE("$NetBSD: ftp.c,v 1.29.2.1 1997/11/18 01:01:04 mellon Exp $");
#endif
#endif /* not lint */
@@ -110,34 +110,30 @@ hookup(host, port)
}
hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
hostname = hostnamebuf;
- s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
- if (s < 0) {
- warn("socket");
- code = -1;
- return (0);
- }
hisctladdr.sin_port = port;
- while (connect(s, (struct sockaddr *)&hisctladdr,
- sizeof(hisctladdr)) < 0) {
- if (hp && hp->h_addr_list[1]) {
- int oerrno = errno;
- char *ia;
-
- ia = inet_ntoa(hisctladdr.sin_addr);
- errno = oerrno;
- warn("connect to address %s", ia);
- hp->h_addr_list++;
+ while (1) {
+ if ((s = socket(hisctladdr.sin_family, SOCK_STREAM, 0)) == -1) {
+ warn("socket");
+ code = -1;
+ return (0);
+ }
+ if (dobind && bind(s, (struct sockaddr *)&bindto,
+ sizeof(bindto)) == -1) {
+ warn("bind");
+ code = -1;
+ goto bad;
+ }
+ if (connect(s, (struct sockaddr *)&hisctladdr,
+ sizeof(hisctladdr)) == 0)
+ break;
+ if (hp && *++hp->h_addr_list) {
+ warnc(errno, "connect to address %s",
+ inet_ntoa(hisctladdr.sin_addr));
memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
MIN(hp->h_length,sizeof(hisctladdr.sin_addr)));
printf("Trying %s...\n",
inet_ntoa(hisctladdr.sin_addr));
(void)close(s);
- s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
- if (s < 0) {
- warn("socket");
- code = -1;
- return (0);
- }
continue;
}
warn("connect");
@@ -1093,6 +1089,11 @@ initconn()
warn("socket");
return (1);
}
+ if (dobind && bind(data, (struct sockaddr *)&bindto,
+ sizeof(bindto)) == -1) {
+ warn("bind");
+ goto bad;
+ }
if ((options & SO_DEBUG) &&
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
sizeof(on)) < 0)
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index 0dd0716..2a4f2c8 100644
--- a/usr.bin/ftp/ftp_var.h
+++ b/usr.bin/ftp/ftp_var.h
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id: ftp_var.h,v 1.6 1997/12/13 20:38:18 pst Exp $ */
/* $NetBSD: ftp_var.h,v 1.20.2.1 1997/11/18 01:01:37 mellon Exp $ */
/*
@@ -43,6 +43,7 @@
#include <sys/param.h>
#include <setjmp.h>
#include <stringlist.h>
+#include <netinet/in.h>
#ifndef SMALL
#include <histedit.h>
@@ -141,6 +142,9 @@ 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 */
+int dobind; /* bind to specific address */
+struct sockaddr_in bindto; /* address to bind to */
+
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
char line[FTPBUFLEN]; /* input line buffer */
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index d8e339d..0348462 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.16 1997/12/13 20:38:19 pst Exp $ */
+/* $Id: main.c,v 1.17 1999/06/07 16:35:15 des Exp $ */
/* $NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $ */
/*
@@ -44,7 +44,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$Id: main.c,v 1.16 1997/12/13 20:38:19 pst Exp $");
+__RCSID("$Id: main.c,v 1.17 1999/06/07 16:35:15 des Exp $");
__RCSID_SOURCE("$NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $");
#endif
#endif /* not lint */
@@ -54,6 +54,8 @@ __RCSID_SOURCE("$NetBSD: main.c,v 1.26 1997/10/14 16:31:22 christos Exp $");
*/
#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <err.h>
#include <locale.h>
@@ -80,6 +82,7 @@ main(argc, argv)
struct passwd *pw = NULL;
char *cp, *ep, homedir[MAXPATHLEN], *s;
int dumbterm;
+ char *src_addr = NULL;
(void) setlocale(LC_ALL, "");
@@ -166,7 +169,7 @@ main(argc, argv)
if (isatty(fileno(stdout)) && !dumbterm)
progress = 1; /* progress bar on if tty is usable */
- while ((ch = getopt(argc, argv, "adeginpP:tvVU")) != -1) {
+ while ((ch = getopt(argc, argv, "adeginpP:s:tUvV")) != -1) {
switch (ch) {
case 'a':
anonftp = 1;
@@ -207,10 +210,19 @@ main(argc, argv)
ftpport = htons(port);
break;
+ case 's':
+ dobind = 1;
+ src_addr = optarg;
+ break;
+
case 't':
trace = 1;
break;
+ case 'U':
+ restricted_data_ports = 0;
+ break;
+
case 'v':
verbose = 1;
break;
@@ -219,10 +231,6 @@ main(argc, argv)
verbose = 0;
break;
- case 'U':
- restricted_data_ports = 0;
- break;
-
default:
usage();
}
@@ -234,6 +242,21 @@ main(argc, argv)
proxy = 0; /* proxy not active */
crflag = 1; /* strip c.r. on ascii gets */
sendport = -1; /* not using ports */
+
+ if (dobind) {
+ memset((void *)&bindto, 0, sizeof(bindto));
+ if (inet_aton(src_addr, &bindto.sin_addr) == 1)
+ bindto.sin_family = AF_INET;
+ else {
+ struct hostent *hp = gethostbyname(src_addr);
+ if (hp == NULL)
+ errx(1, "%s: %s", src_addr, hstrerror(h_errno));
+ bindto.sin_family = hp->h_addrtype;
+ memcpy(&bindto.sin_addr, hp->h_addr_list[0],
+ MIN(hp->h_length,sizeof(bindto.sin_addr)));
+ }
+ }
+
/*
* Set up the home directory in case we're globbing.
*/
@@ -263,18 +286,21 @@ main(argc, argv)
if (rval >= 0) /* -1 == connected and cd-ed */
exit(rval);
} else {
- char *xargv[5];
+ char *xargv[4], **xargp = xargv;
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&xargp;
+#endif
if (setjmp(toplevel))
exit(0);
(void)signal(SIGINT, (sig_t)intr);
(void)signal(SIGPIPE, (sig_t)lostpeer);
- xargv[0] = __progname;
- xargv[1] = argv[0];
- xargv[2] = argv[1];
- xargv[3] = argv[2];
- xargv[4] = NULL;
- setpeer(argc+1, xargv);
+ *xargp++ = __progname;
+ *xargp++ = argv[0]; /* host */
+ if (argc > 1)
+ *xargp++ = argv[1]; /* port */
+ *xargp = NULL;
+ setpeer(xargp-xargv, xargv);
}
}
#ifndef SMALL
@@ -688,7 +714,7 @@ void
usage()
{
(void)fprintf(stderr,
- "usage: %s [-adeginptvV] [host [port]]\n"
+ "usage: %s [-adeginptUvV] [-P port] [-s src_addr] [host [port]]\n"
" %s host:path[/]\n"
" %s ftp://host[:port]/path[/]\n"
" %s http://host[:port]/file\n",
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index a97af4d..45baf32 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $Id: util.c,v 1.5 1998/02/03 20:53:25 pst Exp $ */
+/* $Id: util.c,v 1.6 1998/07/19 00:01:24 jmz Exp $ */
/* $NetBSD: util.c,v 1.16.2.1 1997/11/18 01:02:33 mellon Exp $ */
/*
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$Id: util.c,v 1.5 1998/02/03 20:53:25 pst Exp $");
+__RCSID("$Id: util.c,v 1.6 1998/07/19 00:01:24 jmz Exp $");
__RCSID_SOURCE("$NetBSD: util.c,v 1.16.2.1 1997/11/18 01:02:33 mellon Exp $");
#endif /* not lint */
@@ -101,7 +101,7 @@ setpeer(argc, argv)
nport = strtol(argv[2], &ep, 10);
if (nport < 1 || nport > 0xffff || *ep != '\0') {
- printf("%s: bad port number '%s'.\n", argv[1], argv[2]);
+ printf("%s: bad port number '%s'.\n", argv[0], argv[2]);
printf("usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
OpenPOWER on IntegriCloud