mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-17 08:00:48 +01:00
Add support for passive mode FTP (default off) to base FTP client to support
users behind packet filtering firewalls. Obtained from: David Carrel <carrel@cisco.com>
This commit is contained in:
parent
e69c40d865
commit
9095be3705
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2805
@ -2132,9 +2132,20 @@ macdef(argc, argv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Start up passive mode interaction
|
||||
*/
|
||||
setpassive()
|
||||
{
|
||||
passivemode = !passivemode;
|
||||
printf("Passive mode %s.\n", onoff(passivemode));
|
||||
code = passivemode;
|
||||
}
|
||||
|
||||
/*
|
||||
* get size of file on remote machine
|
||||
*/
|
||||
/*VARARGS*/
|
||||
void
|
||||
sizecmd(argc, argv)
|
||||
int argc;
|
||||
|
@ -78,6 +78,7 @@ char newerhelp[] = "get file if remote file is newer than local file ";
|
||||
char nlisthelp[] = "nlist contents of remote directory";
|
||||
char nmaphelp[] = "set templates for default file name mapping";
|
||||
char ntranshelp[] = "set translation table for default file name mapping";
|
||||
char passivehelp[] = "enter passive transfer mode";
|
||||
char porthelp[] = "toggle use of PORT cmd for each data connection";
|
||||
char prompthelp[] = "force interactive prompting on multiple commands";
|
||||
char proxyhelp[] = "issue command on alternate connection";
|
||||
@ -151,6 +152,7 @@ struct cmd cmdtab[] = {
|
||||
{ "ntrans", ntranshelp, 0, 0, 1, setntrans },
|
||||
{ "open", connecthelp, 0, 0, 1, setpeer },
|
||||
{ "prompt", prompthelp, 0, 0, 0, setprompt },
|
||||
{ "passive", passivehelp, 0, 0, 0, setpassive },
|
||||
{ "proxy", proxyhelp, 0, 0, 1, doproxy },
|
||||
{ "sendport", porthelp, 0, 0, 0, setport },
|
||||
{ "put", sendhelp, 1, 1, 1, put },
|
||||
|
@ -120,6 +120,7 @@ void setglob __P((int, char **));
|
||||
void sethash __P((int, char **));
|
||||
void setnmap __P((int, char **));
|
||||
void setntrans __P((int, char **));
|
||||
void setpassive __P((int, char **));
|
||||
void setpeer __P((int, char **));
|
||||
void setport __P((int, char **));
|
||||
void setprompt __P((int, char **));
|
||||
|
@ -1000,6 +1000,55 @@ initconn()
|
||||
char *p, *a;
|
||||
int result, len, tmpno = 0;
|
||||
int on = 1;
|
||||
u_long a1,a2,a3,a4,p1,p2;
|
||||
|
||||
if (passivemode) {
|
||||
data = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (data < 0) {
|
||||
perror("ftp: socket");
|
||||
return(1);
|
||||
}
|
||||
if (options & SO_DEBUG &&
|
||||
setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
|
||||
sizeof (on)) < 0)
|
||||
perror("ftp: setsockopt (ignored)");
|
||||
if (command("PASV") != COMPLETE) {
|
||||
printf("Passive mode refused.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* What we've got at this point is a string of comma separated
|
||||
* one-byte unsigned integer values, separated by commas.
|
||||
* The first four are the an IP address. The fifth is the MSB
|
||||
* of the port number, the sixth is the LSB. From that we'll
|
||||
* prepare a sockaddr_in.
|
||||
*/
|
||||
|
||||
if (sscanf(pasv,"%d,%d,%d,%d,%d,%d",&a1,&a2,&a3,&a4,&p1,&p2)
|
||||
!= 6) {
|
||||
printf("Passive mode address scan failure. Shouldn't happen!\n");
|
||||
return(1);
|
||||
};
|
||||
|
||||
data_addr.sin_family = AF_INET;
|
||||
data_addr.sin_addr.s_addr = htonl((a1 << 24) | (a2 << 16) |
|
||||
(a3 << 8) | a4);
|
||||
data_addr.sin_port = htons((p1 << 8) | p2);
|
||||
|
||||
if (connect(data, (struct sockaddr *) &data_addr,
|
||||
sizeof(data_addr))<0) {
|
||||
perror("ftp: connect");
|
||||
return(1);
|
||||
}
|
||||
#ifdef IP_TOS
|
||||
on = IPTOS_THROUGHPUT;
|
||||
if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on,
|
||||
sizeof(int)) < 0)
|
||||
perror("ftp: setsockopt TOS (ignored)");
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
noport:
|
||||
data_addr = myctladdr;
|
||||
@ -1070,6 +1119,9 @@ dataconn(lmode)
|
||||
struct sockaddr_in from;
|
||||
int s, fromlen = sizeof (from), tos;
|
||||
|
||||
if (passivemode)
|
||||
return (fdopen(data, lmode));
|
||||
|
||||
s = accept(data, (struct sockaddr *) &from, &fromlen);
|
||||
if (s < 0) {
|
||||
warn("accept");
|
||||
|
@ -66,6 +66,7 @@ int mapflag; /* use mapin mapout templates on file names */
|
||||
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 ntin[17]; /* input translation table */
|
||||
char ntout[17]; /* output translation table */
|
||||
|
@ -118,6 +118,7 @@ main(argc, argv)
|
||||
verbose++;
|
||||
cpend = 0; /* no pending replies */
|
||||
proxy = 0; /* proxy not active */
|
||||
passivemode = 0;/* passive mode not active */
|
||||
crflag = 1; /* strip c.r. on ascii gets */
|
||||
sendport = -1; /* not using ports */
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user