Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions ext/ftp/tests/cert.pem

This file was deleted.

34 changes: 25 additions & 9 deletions ext/ftp/tests/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$socket = null;
$errno = 0;
$context = stream_context_create(array('ssl' => array('local_cert' => dirname(__FILE__).'/cert.pem', 'passphrase' => 'pass')));
$context = stream_context_create(array('ssl' => array('local_cert' => dirname(__FILE__).'/test.pem')));

for ($i=0; $i<10 && !$socket; ++$i) {
$port = rand(50000, 65535);
Expand Down Expand Up @@ -265,7 +265,7 @@ if ($pid) {

} elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) {

if (isset($m[1]) && $m[1] === 'bogusdir') {
if (isset($m[1]) && (($m[1] === 'bogusdir') || ($m[1] === '/bogusdir'))) {
fputs($s, "250 $m[1]: No such file or directory\r\n");
continue;
}
Expand All @@ -276,13 +276,28 @@ if ($pid) {
continue;
}

fputs($s, "150 File status okay; about to open data connection\r\n");
if (empty($pasv)) {
if (!$fs = stream_socket_client("tcp://$host:$port")) {
fputs($s, "425 Can't open data connection\r\n");
continue;
}
} else {
if (!empty($ssl)) {
$soc = stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
} else {
$soc = stream_socket_server("tcp://127.0.0.1:$pasv_port");
}
}

if (!$fs = stream_socket_client("tcp://$host:$port")) {
fputs($s, "425 Can't open data connection\r\n");
continue;
fputs($s, "150 File status okay; about to open data connection\r\n");
if (!empty($pasv)) {
$fs = stream_socket_accept($soc, 5);
}

if ((!empty($ssl)) && (!stream_socket_enable_crypto($fs, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER))) {
die("SSLv23 handshake failed.\n");
}

if (empty($m[1]) || $m[1] !== 'emptydir') {
fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n");
}
Expand Down Expand Up @@ -368,7 +383,7 @@ if ($pid) {
}
fputs($s, "226 Closing data Connection.\r\n");
break;
case "mediumfile":
case "mediumfile":
fputs($s, "150 File status okay; about to open data connection.\r\n");
for($i = 0; $i < 150; $i++){
fputs($fs, "This is line $i of the test data.\n");
Expand All @@ -384,13 +399,14 @@ if ($pid) {


}elseif (preg_match('/^PASV/', $buf, $matches)) {
$pasv=true;
$port = $pasv_port;
$p2 = $port % ((int) 1 << 8);
$p1 = ($port-$p2)/((int) 1 << 8);
$host = "127.0.0.1";
fputs($s, "227 Entering Passive Mode. (127,0,0,1,{$p1},{$p2})\r\n");


}elseif (preg_match('/^EPSV/', $buf, $matches)) {
fputs($s, "550 Extended passsive mode not supported.\r\n");
} elseif (preg_match('/^SITE EXEC/', $buf, $matches)) {
fputs($s, "200 OK\r\n");

Expand Down
49 changes: 49 additions & 0 deletions ext/ftp/tests/test.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-----BEGIN CERTIFICATE-----
MIIDhTCCAm2gAwIBAgIJAN75FFz+owOAMA0GCSqGSIb3DQEBCwUAMFkxCzAJBgNV
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCTEyNy4wLjAuMTAeFw0xNjA3MjUxMjM3
MTJaFw0yNjA3MjMxMjM3MTJaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21l
LVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV
BAMMCTEyNy4wLjAuMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALtG
AIrNUDItISfpAqztL2TFEWEHLGTzCEh5Ag2sdMD7UYbqIPHLOE4EINv+dqEMM0Nz
LYnw7ChtVeg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JjUAAtpgAptFLkNYTk
kR9sA5DZ7BMDPXaIVg9Nv5peP3SWHNc5IPtI7kIdUu9R0cW7J+e2V3vJphlC/ITA
wRuAoZ0BXmEKTHhae3aMEdXwrcZE8kpNsrO/4hcBAoGBAMISiPJPuxAX1UtqcxTa
mDJfnQ2gxRu6AK9VmXqo0X4IBxDSnTjcL0huUlS849wgsE5oTXgdYb2hn+TXM5JJ
NsEXLhV09X1mrk4M4LV1npd0mYxvFsO4+p+IX5YLiahInmQtq0gx3DWE8wouVFER
4yzfp27z8MZT8Qvr/ZI9lzWd
-----END PRIVATE KEY-----
11 changes: 5 additions & 6 deletions ext/standard/ftp_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,18 +720,17 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat
if (hoststart == NULL) {
hoststart = resource->host;
}
datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0);
if (datastream == NULL) {
goto opendir_errexit;
}

result = GET_FTP_RESULT(stream);
if (result != 150 && result != 125) {
/* Could not retrieve or send the file
* this data will only be sent to us after connection on the data port was initiated.
*/
php_stream_close(datastream);
datastream = NULL;
goto opendir_errexit;
}

datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0);
if (datastream == NULL) {
goto opendir_errexit;
}

Expand Down
19 changes: 19 additions & 0 deletions ext/standard/tests/streams/opendir-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
opendir() with 'ftp://' stream.
--SKIPIF--
<?php if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available."); ?>
--FILE--
<?php

require __DIR__ . "/../../../ftp/tests/server.inc";

$path="ftp://localhost:" . $port."/bogusdir";

var_dump(opendir($path));
?>
==DONE==
--EXPECTF--
Warning: opendir(ftp://localhost:%d/bogusdir): failed to open dir: FTP server reports 250 /bogusdir: No such file or directory
in %s on line %d
bool(false)
==DONE==
28 changes: 28 additions & 0 deletions ext/standard/tests/streams/opendir-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
opendir() with 'ftp://' stream.
--SKIPIF--
<?php if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available."); ?>
--FILE--
<?php

require __DIR__ . "/../../../ftp/tests/server.inc";

$path="ftp://localhost:" . $port."/";

$ds=opendir($path);
var_dump($ds);

while ($fn=readdir($ds)) {
var_dump($fn);
}

closedir($ds);
?>
==DONE==
--EXPECTF--
resource(%d) of type (stream)
string(5) "file1"
string(5) "file1"
string(3) "fil"
string(4) "b0rk"
==DONE==
22 changes: 22 additions & 0 deletions ext/standard/tests/streams/opendir-003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
opendir() with 'ftps://' stream.
--SKIPIF--
<?php if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available."); ?>
--FILE--
<?php

$ssl=true;
require __DIR__ . "/../../../ftp/tests/server.inc";

$path="ftps://127.0.0.1:" . $port."/bogusdir";

$context = stream_context_create(array('ssl' => array('cafile' => __DIR__ . '/../../../ftp/tests/test.pem')));

var_dump(opendir($path, $context));
?>
==DONE==
--EXPECTF--
Warning: opendir(ftps://127.0.0.1:%d/bogusdir): failed to open dir: FTP server reports 250 /bogusdir: No such file or directory
in %s on line %d
bool(false)
==DONE==
28 changes: 28 additions & 0 deletions ext/standard/tests/streams/opendir-004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
opendir() with 'ftps://' stream.
--SKIPIF--
<?php if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available."); ?>
--FILE--
<?php

$ssl=true;
require __DIR__ . "/../../../ftp/tests/server.inc";

$path="ftps://127.0.0.1:" . $port."/";

$context = stream_context_create(array('ssl' => array('cafile' => __DIR__ . '/../../../ftp/tests/test.pem')));

$ds=opendir($path, $context);
var_dump($ds);
while ($fn=readdir($ds)) {
var_dump($fn);
}
?>
==DONE==
--EXPECTF--
resource(%d) of type (stream)
string(5) "file1"
string(5) "file1"
string(3) "fil"
string(4) "b0rk"
==DONE==