summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAvi Brender <abrender@elitehosts.com>2015-12-15 11:51:32 +0200
committerLior Kaplan <kaplanlior@gmail.com>2015-12-15 11:51:32 +0200
commit71e468e14149169b28439a552f5924330580acab (patch)
tree22a014cb49e0a72e1bfc83f1ac9ac16bbea39b70 /ext
parente048b3fc6b482d19c3f21e6691b2e0188fc83a77 (diff)
parent838e4039d7fc8f79fe71091725ab0a13a5f4ad2a (diff)
downloadphp-git-71e468e14149169b28439a552f5924330580acab.tar.gz
Implement FR #55651 (Option to ignore the returned FTP PASV address)
Diffstat (limited to 'ext')
-rw-r--r--ext/ftp/ftp.c8
-rw-r--r--ext/ftp/ftp.h2
-rw-r--r--ext/ftp/php_ftp.c15
-rw-r--r--ext/ftp/php_ftp.h1
4 files changed, 23 insertions, 3 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index bb41b1a621..41aa378511 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -754,10 +754,11 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
memset(&ftp->pasvaddr, 0, n);
sa = (struct sockaddr *) &ftp->pasvaddr;
-#if HAVE_IPV6
if (getpeername(ftp->fd, sa, &n) < 0) {
return 0;
}
+
+#if HAVE_IPV6
if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
char *endptr, delimiter;
@@ -810,8 +811,9 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
ipbox.c[n] = (unsigned char) b[n];
}
sin = (struct sockaddr_in *) sa;
- sin->sin_family = AF_INET;
- sin->sin_addr = ipbox.ia[0];
+ if (ftp->usepasvaddress) {
+ sin->sin_addr = ipbox.ia[0];
+ }
sin->sin_port = ipbox.s[2];
ftp->pasv = 2;
diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h
index 546c69ccb7..aed416588f 100644
--- a/ext/ftp/ftp.h
+++ b/ext/ftp/ftp.h
@@ -31,6 +31,7 @@
#define FTP_DEFAULT_TIMEOUT 90
#define FTP_DEFAULT_AUTOSEEK 1
+#define FTP_DEFAULT_USEPASVADDRESS 1
#define PHP_FTP_FAILED 0
#define PHP_FTP_FINISHED 1
#define PHP_FTP_MOREDATA 2
@@ -71,6 +72,7 @@ typedef struct ftpbuf
php_sockaddr_storage pasvaddr; /* passive mode address */
zend_long timeout_sec; /* User configurable timeout (seconds) */
int autoseek; /* User configurable autoseek flag */
+ int usepasvaddress; /* Use the address returned by the pasv command */
int nb; /* "nonblocking" transfer in progress */
databuf_t *data; /* Data connection for "nonblocking" transfers */
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index eaed5c6847..ca62720790 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -326,6 +326,7 @@ PHP_MINIT_FUNCTION(ftp)
REGISTER_LONG_CONSTANT("FTP_AUTORESUME", PHP_FTP_AUTORESUME, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_TIMEOUT_SEC", PHP_FTP_OPT_TIMEOUT_SEC, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_AUTOSEEK", PHP_FTP_OPT_AUTOSEEK, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("FTP_USEPASVADDRESS", PHP_FTP_OPT_USEPASVADDRESS, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_FAILED", PHP_FTP_FAILED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_FINISHED", PHP_FTP_FINISHED, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("FTP_MOREDATA", PHP_FTP_MOREDATA, CONST_PERSISTENT | CONST_CS);
@@ -379,6 +380,7 @@ PHP_FUNCTION(ftp_connect)
/* autoseek for resuming */
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
+ ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS;
#ifdef HAVE_FTP_SSL
/* disable ssl */
ftp->use_ssl = 0;
@@ -415,6 +417,7 @@ PHP_FUNCTION(ftp_ssl_connect)
/* autoseek for resuming */
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
+ ftp->usepasvaddress = FTP_DEFAULT_USEPASVADDRESS;
/* enable ssl */
ftp->use_ssl = 1;
@@ -1478,6 +1481,15 @@ PHP_FUNCTION(ftp_set_option)
ftp->autoseek = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0;
RETURN_TRUE;
break;
+ case PHP_FTP_OPT_USEPASVADDRESS:
+ if (Z_TYPE_P(z_value) != IS_TRUE && Z_TYPE_P(z_value) != IS_FALSE) {
+ php_error_docref(NULL, E_WARNING, "Option USEPASVADDRESS expects value of type boolean, %s given",
+ zend_zval_type_name(z_value));
+ RETURN_FALSE;
+ }
+ ftp->usepasvaddress = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0;
+ RETURN_TRUE;
+ break;
default:
php_error_docref(NULL, E_WARNING, "Unknown option '%pd'", option);
RETURN_FALSE;
@@ -1509,6 +1521,9 @@ PHP_FUNCTION(ftp_get_option)
case PHP_FTP_OPT_AUTOSEEK:
RETURN_BOOL(ftp->autoseek);
break;
+ case PHP_FTP_OPT_USEPASVADDRESS:
+ RETURN_BOOL(ftp->usepasvaddress);
+ break;
default:
php_error_docref(NULL, E_WARNING, "Unknown option '%pd'", option);
RETURN_FALSE;
diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h
index 3ddc76f074..8000a3e3c9 100644
--- a/ext/ftp/php_ftp.h
+++ b/ext/ftp/php_ftp.h
@@ -32,6 +32,7 @@ extern zend_module_entry php_ftp_module_entry;
#define PHP_FTP_OPT_TIMEOUT_SEC 0
#define PHP_FTP_OPT_AUTOSEEK 1
+#define PHP_FTP_OPT_USEPASVADDRESS 2
#define PHP_FTP_AUTORESUME -1
PHP_MINIT_FUNCTION(ftp);