From c387a49c7cc1cbfa1dac525edf4bc55044bab5fe Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Thu, 17 Aug 2000 23:46:13 +0000 Subject: [PATCH] Fix two bugs: - The ftpPassive() --- lib/libftpio/ftpio.3 | 6 ++++-- lib/libftpio/ftpio.c | 36 ++++++++---------------------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/lib/libftpio/ftpio.3 b/lib/libftpio/ftpio.3 index 510324df724d..8e1b86fca996 100644 --- a/lib/libftpio/ftpio.3 +++ b/lib/libftpio/ftpio.3 @@ -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 diff --git a/lib/libftpio/ftpio.c b/lib/libftpio/ftpio.c index d4e4a9e577a4..fcf242439ca3 100644 --- a/lib/libftpio/ftpio.c +++ b/lib/libftpio/ftpio.c @@ -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