Enable ftps for shared ext/ftp https://github.com/php/php-src/commit/167979fe76215978efc64fccad454abb22de862a --- ext/ftp/config.m4.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/config.m4 2020-01-19 00:19:04.000000000 -0600 @@ -18,5 +18,6 @@ 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 --- ext/ftp/config.w32.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/config.w32 2020-01-19 00:19:04.000000000 -0600 @@ -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'); } --- ext/ftp/ftp.c.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/ftp.c 2020-01-19 00:19:04.000000000 -0600 @@ -65,7 +65,7 @@ #include #endif -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL #include #endif @@ -183,7 +183,7 @@ 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); @@ -246,7 +246,7 @@ int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC) { -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL SSL_CTX *ctx = NULL; long ssl_ctx_options = SSL_OP_ALL; #endif @@ -254,7 +254,7 @@ 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; @@ -1244,7 +1244,7 @@ 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) { @@ -1252,7 +1252,7 @@ } else { #endif sent = send(s, buf, size, 0); -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL } #endif if (sent == -1) { @@ -1284,7 +1284,7 @@ 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) { @@ -1292,7 +1292,7 @@ } else { #endif nr_bytes = recv(s, buf, len, 0); -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL } #endif return (nr_bytes); @@ -1491,7 +1491,7 @@ php_sockaddr_storage addr; socklen_t size; -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL SSL_CTX *ctx; long ssl_ctx_options = SSL_OP_ALL; #endif @@ -1510,7 +1510,7 @@ } 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) { @@ -1560,14 +1560,14 @@ 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); @@ -1581,7 +1581,7 @@ 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); --- ext/ftp/ftp.h.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/ftp.h 2020-01-19 00:19:04.000000000 -0600 @@ -49,7 +49,7 @@ 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 @@ 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 */ --- ext/ftp/php_ftp.c.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/php_ftp.c 2020-01-19 00:19:47.000000000 -0600 @@ -29,7 +29,7 @@ #include #endif -#if HAVE_OPENSSL_EXT +#ifdef HAVE_FTP_SSL # include #endif @@ -51,7 +51,7 @@ 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 @@ 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 @@ 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 @@ NULL, NULL, PHP_MINFO(ftp), - NO_VERSION_YET, + NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; @@ -325,6 +339,11 @@ { 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 @@ /* 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 @@ } /* }}} */ -#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) --- ext/ftp/php_ftp.h.orig 2016-07-20 03:41:48.000000000 -0500 +++ ext/ftp/php_ftp.h 2020-01-19 00:19:04.000000000 -0600 @@ -35,7 +35,7 @@ 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);