Fix two bugs:

- The ftpPassive()
This commit is contained in:
archie 2000-08-17 23:46:13 +00:00
parent d2bdccc3f8
commit 0df88a05d9
2 changed files with 12 additions and 30 deletions

View File

@ -213,8 +213,10 @@ from the peer before aborting an
.Tn FTP
connection.
.It Ev FTP_PASSIVE_MODE
Force the use of passive mode
.Tn FTP .
If defined, forces the use of passive mode, unless equal
to ``NO'' or ``no'' in which case active mode is forced.
If defined, the setting of this variable always overrides any calls to
.Fn ftpPassive .
.El
.Sh BUGS
I'm sure you can get this thing's internal state machine confused if

View File

@ -327,37 +327,12 @@ ftpPut(FILE *fp, char *file)
return NULL;
}
/* Unlike binary mode, passive mode is a toggle! :-( */
int
ftpPassive(FILE *fp, int st)
{
FTP_t ftp = fcookie(fp);
int i;
if (ftp->is_passive == st)
return SUCCESS;
switch (ftp->addrtype) {
case AF_INET:
i = cmd(ftp, "PASV");
if (i < 0)
return i;
if (i != FTP_PASSIVE_HAPPY)
return FAILURE;
break;
case AF_INET6:
i = cmd(ftp, "EPSV");
if (i < 0)
return i;
if (i != FTP_EPASSIVE_HAPPY) {
i = cmd(ftp, "LPSV");
if (i < 0)
return i;
if (i != FTP_LPASSIVE_HAPPY)
return FAILURE;
}
break;
}
ftp->is_passive = !ftp->is_passive;
ftp->is_passive = !!st; /* normalize "st" to zero or one */
return SUCCESS;
}
@ -545,12 +520,17 @@ ftp_close_method(void *n)
return i;
}
/*
* This function checks whether the FTP_PASSIVE_MODE environment
* variable is set, and, if so, enforces the desired mode.
*/
static void
check_passive(FILE *fp)
{
char *cp = getenv("FTP_PASSIVE_MODE");
const char *cp = getenv("FTP_PASSIVE_MODE");
ftpPassive(fp, (cp && strncasecmp(cp, "no", 2)));
if (cp != NULL)
ftpPassive(fp, strncasecmp(cp, "no", 2));
}
static void