mirror of
https://github.com/php/php-src.git
synced 2026-04-28 02:33:17 +02:00
enable ftps for shared ext/ftp
This commit is contained in:
@@ -18,5 +18,6 @@ if test "$PHP_FTP" = "yes"; then
|
||||
if test "$PHP_OPENSSL" != "no" || test "$PHP_OPENSSL_DIR" != "no"; then
|
||||
PHP_SETUP_OPENSSL(FTP_SHARED_LIBADD)
|
||||
PHP_SUBST(FTP_SHARED_LIBADD)
|
||||
AC_DEFINE(HAVE_FTP_SSL,1,[Whether FTP over SSL is supported])
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -4,6 +4,16 @@
|
||||
ARG_ENABLE("ftp", "ftp support", "yes");
|
||||
|
||||
if (PHP_FTP == "yes") {
|
||||
|
||||
EXTENSION("ftp", "php_ftp.c ftp.c");
|
||||
|
||||
if (CHECK_HEADER_ADD_INCLUDE("openssl/ssl.h", "CFLAGS_FTP") &&
|
||||
CHECK_LIB("ssleay32.lib", "ftp", PHP_FTP) &&
|
||||
CHECK_LIB("libeay32.lib", "ftp", PHP_FTP) &&
|
||||
ADD_EXTENSION_DEP("ftp", "openssl", true)) {
|
||||
MESSAGE("Enabling SSL support for ext\\ftp");
|
||||
AC_DEFINE('HAVE_FTP_SSL', 1, 'Have FTP over SSL support');
|
||||
}
|
||||
|
||||
AC_DEFINE('HAVE_FTP', 1, 'Have FTP support');
|
||||
}
|
||||
|
||||
+14
-14
@@ -65,7 +65,7 @@
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
#include <openssl/ssl.h>
|
||||
#endif
|
||||
|
||||
@@ -182,7 +182,7 @@ ftp_close(ftpbuf_t *ftp)
|
||||
php_stream_close(ftp->stream);
|
||||
}
|
||||
if (ftp->fd != -1) {
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (ftp->ssl_active) {
|
||||
SSL_shutdown(ftp->ssl_handle);
|
||||
SSL_free(ftp->ssl_handle);
|
||||
@@ -245,15 +245,15 @@ ftp_quit(ftpbuf_t *ftp)
|
||||
int
|
||||
ftp_login(ftpbuf_t *ftp, const char *user, const char *pass)
|
||||
{
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
SSL_CTX *ctx = NULL;
|
||||
zend_long ssl_ctx_options = SSL_OP_ALL;
|
||||
long ssl_ctx_options = SSL_OP_ALL;
|
||||
#endif
|
||||
if (ftp == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (ftp->use_ssl && !ftp->ssl_active) {
|
||||
if (!ftp_putcmd(ftp, "AUTH", "TLS")) {
|
||||
return 0;
|
||||
@@ -1243,7 +1243,7 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
|
||||
sent = SSL_write(ftp->ssl_handle, buf, size);
|
||||
} else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
|
||||
@@ -1251,7 +1251,7 @@ my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
|
||||
} else {
|
||||
#endif
|
||||
sent = send(s, buf, size, 0);
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
}
|
||||
#endif
|
||||
if (sent == -1) {
|
||||
@@ -1283,7 +1283,7 @@ my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
|
||||
nr_bytes = SSL_read(ftp->ssl_handle, buf, len);
|
||||
} else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
|
||||
@@ -1291,7 +1291,7 @@ my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
|
||||
} else {
|
||||
#endif
|
||||
nr_bytes = recv(s, buf, len, 0);
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
}
|
||||
#endif
|
||||
return (nr_bytes);
|
||||
@@ -1490,7 +1490,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp)
|
||||
php_sockaddr_storage addr;
|
||||
socklen_t size;
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
SSL_CTX *ctx;
|
||||
zend_long ssl_ctx_options = SSL_OP_ALL;
|
||||
#endif
|
||||
@@ -1509,7 +1509,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp)
|
||||
}
|
||||
|
||||
data_accepted:
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
|
||||
/* now enable ssl if we need to */
|
||||
if (ftp->use_ssl && ftp->use_ssl_for_data) {
|
||||
@@ -1559,14 +1559,14 @@ data_accepted:
|
||||
databuf_t*
|
||||
data_close(ftpbuf_t *ftp, databuf_t *data)
|
||||
{
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
SSL_CTX *ctx;
|
||||
#endif
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (data->listener != -1) {
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (data->ssl_active) {
|
||||
|
||||
ctx = SSL_get_SSL_CTX(data->ssl_handle);
|
||||
@@ -1580,7 +1580,7 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
|
||||
closesocket(data->listener);
|
||||
}
|
||||
if (data->fd != -1) {
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
if (data->ssl_active) {
|
||||
ctx = SSL_get_SSL_CTX(data->ssl_handle);
|
||||
SSL_CTX_free(ctx);
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ typedef struct databuf
|
||||
php_socket_t fd; /* data connection */
|
||||
ftptype_t type; /* transfer type */
|
||||
char buf[FTP_BUFSIZE]; /* data buffer */
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
SSL *ssl_handle; /* ssl handle */
|
||||
int ssl_active; /* flag if ssl is active or not */
|
||||
#endif
|
||||
@@ -78,7 +78,7 @@ typedef struct ftpbuf
|
||||
int lastch; /* last char of previous call */
|
||||
int direction; /* recv = 0 / send = 1 */
|
||||
int closestream;/* close or not close stream */
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
int use_ssl; /* enable(1) or disable(0) ssl */
|
||||
int use_ssl_for_data; /* en/disable ssl for the dataconnection */
|
||||
int old_ssl; /* old mode = forced data encryption */
|
||||
|
||||
+26
-7
@@ -29,7 +29,7 @@
|
||||
#include <novsock2.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
# include <openssl/ssl.h>
|
||||
#endif
|
||||
|
||||
@@ -51,7 +51,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, timeout)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_ssl_connect, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, host)
|
||||
ZEND_ARG_INFO(0, port)
|
||||
@@ -243,7 +243,7 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
const zend_function_entry php_ftp_functions[] = {
|
||||
PHP_FE(ftp_connect, arginfo_ftp_connect)
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
PHP_FE(ftp_ssl_connect, arginfo_ftp_ssl_connect)
|
||||
#endif
|
||||
PHP_FE(ftp_login, arginfo_ftp_login)
|
||||
@@ -281,8 +281,22 @@ const zend_function_entry php_ftp_functions[] = {
|
||||
PHP_FE_END
|
||||
};
|
||||
|
||||
#ifdef HAVE_FTP_SSL
|
||||
/* {{{ ftp_deps */
|
||||
static const zend_module_dep ftp_deps[] = {
|
||||
ZEND_MOD_REQUIRED("openssl")
|
||||
{NULL, NULL, NULL}
|
||||
};/*}}}*/
|
||||
#endif
|
||||
|
||||
zend_module_entry php_ftp_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
STANDARD_MODULE_HEADER_EX,
|
||||
NULL,
|
||||
#ifdef HAVE_FTP_SSL
|
||||
ftp_deps,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
"ftp",
|
||||
php_ftp_functions,
|
||||
PHP_MINIT(ftp),
|
||||
@@ -290,7 +304,7 @@ zend_module_entry php_ftp_module_entry = {
|
||||
NULL,
|
||||
NULL,
|
||||
PHP_MINFO(ftp),
|
||||
NO_VERSION_YET,
|
||||
NO_VERSION_YET,
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
|
||||
@@ -325,6 +339,11 @@ PHP_MINFO_FUNCTION(ftp)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_row(2, "FTP support", "enabled");
|
||||
#ifdef HAVE_FTP_SSL
|
||||
php_info_print_table_row(2, "FTPS support", "enabled");
|
||||
#else
|
||||
php_info_print_table_row(2, "FTPS support", "disabled");
|
||||
#endif
|
||||
php_info_print_table_end();
|
||||
}
|
||||
|
||||
@@ -363,7 +382,7 @@ PHP_FUNCTION(ftp_connect)
|
||||
|
||||
/* autoseek for resuming */
|
||||
ftp->autoseek = FTP_DEFAULT_AUTOSEEK;
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
/* disable ssl */
|
||||
ftp->use_ssl = 0;
|
||||
#endif
|
||||
@@ -372,7 +391,7 @@ PHP_FUNCTION(ftp_connect)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#if HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
/* {{{ proto resource ftp_ssl_connect(string host [, int port [, int timeout]])
|
||||
Opens a FTP-SSL stream */
|
||||
PHP_FUNCTION(ftp_ssl_connect)
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ PHP_MINIT_FUNCTION(ftp);
|
||||
PHP_MINFO_FUNCTION(ftp);
|
||||
|
||||
PHP_FUNCTION(ftp_connect);
|
||||
#ifdef HAVE_OPENSSL_EXT
|
||||
#ifdef HAVE_FTP_SSL
|
||||
PHP_FUNCTION(ftp_ssl_connect);
|
||||
#endif
|
||||
PHP_FUNCTION(ftp_login);
|
||||
|
||||
Reference in New Issue
Block a user