sesser Sun Sep 8 18:26:11 2002 EDT Modified files: /php4/ext/standard ftp_fopen_wrapper.c /php4/main network.c php_network.h Log: Added possibility to reuse an old SSL session id. Ugly but needed for f.e.: debians ftpd-ssl Index: php4/ext/standard/ftp_fopen_wrapper.c diff -u php4/ext/standard/ftp_fopen_wrapper.c:1.31 php4/ext/standard/ftp_fopen_wrapper.c:1.32 --- php4/ext/standard/ftp_fopen_wrapper.c:1.31 Sun Sep 8 16:52:03 2002 +++ php4/ext/standard/ftp_fopen_wrapper.c Sun Sep 8 18:26:11 2002 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: ftp_fopen_wrapper.c,v 1.31 2002/09/08 20:52:03 shane Exp $ */ +/* $Id: ftp_fopen_wrapper.c,v 1.32 2002/09/08 22:26:11 sesser Exp $ */ #include "php.h" #include "php_globals.h" @@ -134,7 +134,7 @@ */ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { - php_stream *stream=NULL, *datastream=NULL; + php_stream *stream=NULL, *datastream=NULL, *reuseid=NULL; php_url *resource=NULL; char tmp_line[512]; char ip[sizeof("123.123.123.123")]; @@ -190,6 +190,10 @@ result = GET_FTP_RESULT(stream); if (result != 334) { use_ssl = 0; + } else { + /* we must reuse the old SSL session id */ + /* if we talk to an old ftpd-ssl */ + reuseid = stream; } } else { /* encrypt data etc */ @@ -219,7 +223,7 @@ /* get the response */ result = GET_FTP_RESULT(stream); - use_ssl_on_data = result >= 200 && result<=299; + use_ssl_on_data = (result >= 200 && result<=299) || reuseid; #else php_stream_write_string(stream, "PROT C\r\n"); @@ -407,20 +411,20 @@ if (datastream == NULL) goto errexit; - /* remember control stream */ - datastream->wrapperdata = (zval *)stream; - php_stream_context_set(datastream, context); php_stream_notify_progress_init(context, 0, file_size); #if HAVE_OPENSSL_EXT - if (use_ssl_on_data && php_stream_sock_ssl_activate_with_method(datastream, 1, SSLv23_method()) == FAILURE) { + if (use_ssl_on_data && php_stream_sock_ssl_activate_with_method_ex(datastream, +1, SSLv23_method(), reuseid) == FAILURE) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); php_stream_close(datastream); datastream = NULL; goto errexit; } #endif + + /* remember control stream */ + datastream->wrapperdata = (zval *)stream; php_url_free(resource); return datastream; Index: php4/main/network.c diff -u php4/main/network.c:1.63 php4/main/network.c:1.64 --- php4/main/network.c:1.63 Sun Aug 25 18:17:56 2002 +++ php4/main/network.c Sun Sep 8 18:26:11 2002 @@ -16,7 +16,7 @@ | Streams work by Wez Furlong <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: network.c,v 1.63 2002/08/25 22:17:56 sebastian Exp $ */ +/* $Id: network.c,v 1.64 2002/09/08 22:26:11 sesser Exp $ */ /*#define DEBUG_MAIN_NETWORK 1*/ #define MAX_CHUNKS_PER_READ 10 @@ -582,11 +582,16 @@ } #if HAVE_OPENSSL_EXT -PHPAPI int php_stream_sock_ssl_activate_with_method(php_stream *stream, int activate, SSL_METHOD *method TSRMLS_DC) +PHPAPI int php_stream_sock_ssl_activate_with_method_ex(php_stream *stream, int +activate, SSL_METHOD *method, php_stream *control TSRMLS_DC) { php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; + php_netstream_data_t *psock = NULL; SSL_CTX *ctx = NULL; + if (control) { + psock = (php_netstream_data_t*)control->abstract; + } + if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "php_stream_sock_ssl_activate_with_method: stream is not a network stream"); return FAILURE; @@ -610,6 +615,10 @@ } SSL_set_fd(sock->ssl_handle, sock->socket); + + if (psock) { + SSL_copy_session_id(sock->ssl_handle, psock->ssl_handle); + } } if (activate) { @@ -626,6 +635,7 @@ } return SUCCESS; } + #endif PHPAPI void php_stream_sock_set_timeout(php_stream *stream, struct timeval *timeout TSRMLS_DC) Index: php4/main/php_network.h diff -u php4/main/php_network.h:1.25 php4/main/php_network.h:1.26 --- php4/main/php_network.h:1.25 Sun Aug 25 18:17:56 2002 +++ php4/main/php_network.h Sun Sep 8 18:26:11 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: php_network.h,v 1.25 2002/08/25 22:17:56 sebastian Exp $ */ +/* $Id: php_network.h,v 1.26 2002/09/08 22:26:11 sesser Exp $ */ #ifndef _PHP_NETWORK_H #define _PHP_NETWORK_H @@ -148,7 +148,8 @@ PHPAPI size_t php_stream_sock_set_chunk_size(php_stream *stream, size_t size TSRMLS_DC); #if HAVE_OPENSSL_EXT -PHPAPI int php_stream_sock_ssl_activate_with_method(php_stream *stream, int activate, SSL_METHOD *method TSRMLS_DC); +PHPAPI int php_stream_sock_ssl_activate_with_method_ex(php_stream *stream, int +activate, SSL_METHOD *method, php_stream *control TSRMLS_DC); +#define php_stream_sock_ssl_activate_with_method(stream, activate, method) +php_stream_sock_ssl_activate_with_method_ex((stream), (activate), +SSLv23_client_method(), NULL TSRMLS_CC) #define php_stream_sock_ssl_activate(stream, activate) php_stream_sock_ssl_activate_with_method((stream), (activate), SSLv23_client_method() TSRMLS_CC) #endif
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php