]> granicus.if.org Git - php/commitdiff
enable ftps for shared ext/ftp
authorAnatol Belski <ab@php.net>
Wed, 11 Mar 2015 12:30:26 +0000 (13:30 +0100)
committerAnatol Belski <ab@php.net>
Wed, 11 Mar 2015 20:46:38 +0000 (21:46 +0100)
ext/ftp/config.m4
ext/ftp/config.w32
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c
ext/ftp/php_ftp.h

index 2df7f7b449bd903af93ac334524733ebe3c204bf..fbc7d51ede7c14505b7819285f2ed00e631980b9 100644 (file)
@@ -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
index c91e350a86a4970bd1e6bf6b8b46c56597ad86de..b181a0b95a9ca34b35fe4f9343410b6afc420a8f 100644 (file)
@@ -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');
 }
index 322c0b43578e2887c7ee6db837bb0aabf57afa8d..abe8e89ca7f5109a528d03207b6f531f043e97ee 100644 (file)
@@ -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);
index d2dd18df56b040c73f3e48fdbe221c33a7205398..546c69ccb7a77eb513686d3b48b20a9a264e4751 100644 (file)
@@ -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 */
index 746cb30441a7f2127db1ead77f3ad9c0c3ae8010..1a6304672d38ef00fda0241416bf6c79ac9dfe35 100644 (file)
@@ -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)
index 154397360b2a82d89ee97b2cb1cf9188ff6eef1e..054ec508ed6e8f479eece5eada540289acdeac24 100644 (file)
@@ -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);