nlopess         Tue Feb 13 18:30:19 2007 UTC

  Modified files:              
    /php-src/ext/ftp    ftp.c 
    /php-src/ext/ftp/tests      bug37799.phpt server.inc 
  Log:
  MFB
  
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/ftp.c?r1=1.120&r2=1.121&diff_format=u
Index: php-src/ext/ftp/ftp.c
diff -u php-src/ext/ftp/ftp.c:1.120 php-src/ext/ftp/ftp.c:1.121
--- php-src/ext/ftp/ftp.c:1.120 Mon Jan  1 09:29:23 2007
+++ php-src/ext/ftp/ftp.c       Tue Feb 13 18:30:19 2007
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ftp.c,v 1.120 2007/01/01 09:29:23 sebastian Exp $ */
+/* $Id: ftp.c,v 1.121 2007/02/13 18:30:19 nlopess Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -266,60 +266,57 @@
                        }
                                
                        if (ftp->resp != 334) {
-                               ftp->use_ssl = 0;
+                               return 0;
                        } else {
                                ftp->old_ssl = 1;
                                ftp->use_ssl_for_data = 1;
                        }
                }
                
-               /* now enable ssl if we still need to */
-               if (ftp->use_ssl) {
-                       ctx = SSL_CTX_new(SSLv23_client_method());
-                       if (ctx == NULL) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"failed to create the SSL context");
+               ctx = SSL_CTX_new(SSLv23_client_method());
+               if (ctx == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to 
create the SSL context");
+                       return 0;
+               }
+
+               SSL_CTX_set_options(ctx, SSL_OP_ALL);
+
+               ftp->ssl_handle = SSL_new(ctx);
+               if (ftp->ssl_handle == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to 
create the SSL handle");
+                       SSL_CTX_free(ctx);
+                       return 0;
+               }
+
+               SSL_set_fd(ftp->ssl_handle, ftp->fd);
+
+               if (SSL_connect(ftp->ssl_handle) <= 0) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS 
handshake failed");
+                       SSL_shutdown(ftp->ssl_handle);
+                       return 0;
+               }
+
+               ftp->ssl_active = 1;
+
+               if (!ftp->old_ssl) {
+
+                       /* set protection buffersize to zero */
+                       if (!ftp_putcmd(ftp, "PBSZ", "0")) {
+                               return 0;
+                       }
+                       if (!ftp_getresp(ftp)) {
                                return 0;
                        }
 
-                       SSL_CTX_set_options(ctx, SSL_OP_ALL);
-
-                       ftp->ssl_handle = SSL_new(ctx);
-                       if (ftp->ssl_handle == NULL) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"failed to create the SSL handle");
-                               SSL_CTX_free(ctx);
+                       /* enable data conn encryption */
+                       if (!ftp_putcmd(ftp, "PROT", "P")) {
                                return 0;
                        }
-                       
-                       SSL_set_fd(ftp->ssl_handle, ftp->fd);
-                       
-                       if (SSL_connect(ftp->ssl_handle) <= 0) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"SSL/TLS handshake failed");
-                               SSL_shutdown(ftp->ssl_handle);
+                       if (!ftp_getresp(ftp)) {
                                return 0;
                        }
                        
-                       ftp->ssl_active = 1;
-                       
-                       if (!ftp->old_ssl) {
-                               
-                               /* set protection buffersize to zero */
-                               if (!ftp_putcmd(ftp, "PBSZ", "0")) {
-                                       return 0;
-                               }
-                               if (!ftp_getresp(ftp)) {
-                                       return 0;
-                               }
-                                       
-                               /* enable data conn encryption */
-                               if (!ftp_putcmd(ftp, "PROT", "P")) {
-                                       return 0;
-                               }
-                               if (!ftp_getresp(ftp)) {
-                                       return 0;
-                               }
-                               
-                               ftp->use_ssl_for_data = (ftp->resp >= 200 && 
ftp->resp <=299);          
-                       }
+                       ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp 
<=299);          
                }
        }
 #endif
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/bug37799.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/ftp/tests/bug37799.phpt
diff -u /dev/null php-src/ext/ftp/tests/bug37799.phpt:1.2
--- /dev/null   Tue Feb 13 18:30:19 2007
+++ php-src/ext/ftp/tests/bug37799.phpt Tue Feb 13 18:30:19 2007
@@ -0,0 +1,21 @@
+--TEST--
+Bug #37799: ftp_ssl_connect() falls back to non-ssl connection
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug37799=$ssl=1;
+require 'server.inc';
+
+$ftp = ftp_ssl_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+ftp_close($ftp);
+?>
+--EXPECTF--
+Warning: ftp_login(): bogus msg in %sbug37799.php on line 8
+bool(false)
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/server.inc?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/ftp/tests/server.inc
diff -u php-src/ext/ftp/tests/server.inc:1.7 
php-src/ext/ftp/tests/server.inc:1.8
--- php-src/ext/ftp/tests/server.inc:1.7        Fri Dec  1 16:42:48 2006
+++ php-src/ext/ftp/tests/server.inc    Tue Feb 13 18:30:19 2007
@@ -59,7 +59,7 @@
 
 
 function user_auth($buf) {
-       global $user, $s, $ssl;
+       global $user, $s, $ssl, $bug37799;
 
 if (!empty($ssl)) {
        if ($buf !== "AUTH TLS\r\n") {
@@ -67,7 +67,13 @@
                dump_and_exit($buf);
        }
 
-       fputs($s, "234 auth type accepted\r\n");
+       if (empty($bug37799)) {
+               fputs($s, "234 auth type accepted\r\n");
+       } else {
+               fputs($s, "666 dummy\r\n");
+               fputs($s, "666 bogus msg\r\n");
+               exit;
+       }
 
        if (!stream_socket_enable_crypto($s, true, 
STREAM_CRYPTO_METHOD_SSLv23_SERVER)) {
                die("SSLv23 handshake failed.\n");



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to