ant Thu May 1 11:46:18 2008 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/dir open_basedir_opendir.phpt
open_basedir.inc
open_basedir_dir.phpt
open_basedir_scandir.phpt
Log:
open_basedir tests for directory functions
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/dir/open_basedir_opendir.phpt?view=markuprev=1.1
Index: php-src/ext/standard/tests/dir/open_basedir_opendir.phpt
+++ php-src/ext/standard/tests/dir/open_basedir_opendir.phpt
--TEST--
Test open_basedir configuration
--INI--
open_basedir=.
--FILE--
?php
require_once open_basedir.inc;
test_open_basedir_before(opendir);
test_open_basedir_error(opendir);
$directory = dirname(__FILE__);
var_dump(opendir($directory./test/ok/));
var_dump(opendir($directory./test/ok));
var_dump(opendir($directory./test/ok/../ok));
test_open_basedir_after(opendir);?
--CLEAN--
?php
require_once open_basedir.inc;
delete_directories();
?
--EXPECTF--
*** Testing open_basedir configuration [opendir] ***
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Warning: opendir(): open_basedir restriction in effect. File(../bad) is not
within the allowed path(s): (.) in %s on line %d
Warning: opendir(../bad): failed to open dir: Operation not permitted in %s on
line %d
bool(false)
Warning: opendir(): open_basedir restriction in effect. File(../bad/bad.txt) is
not within the allowed path(s): (.) in %s on line %d
Warning: opendir(../bad/bad.txt): failed to open dir: Operation not permitted
in %s on line %d
bool(false)
Warning: opendir(): open_basedir restriction in effect. File(..) is not within
the allowed path(s): (.) in %s on line %d
Warning: opendir(..): failed to open dir: Operation not permitted in %s on line
%d
bool(false)
Warning: opendir(): open_basedir restriction in effect. File(../) is not within
the allowed path(s): (.) in %s on line %d
Warning: opendir(../): failed to open dir: Operation not permitted in %s on
line %d
bool(false)
Warning: opendir(): open_basedir restriction in effect. File(/) is not within
the allowed path(s): (.) in %s on line %d
Warning: opendir(/): failed to open dir: Operation not permitted in %s on line
%d
bool(false)
Warning: opendir(): open_basedir restriction in effect. File(../bad/.) is not
within the allowed path(s): (.) in %s on line %d
Warning: opendir(../bad/.): failed to open dir: Operation not permitted in %s
on line %d
bool(false)
Warning: opendir(): open_basedir restriction in effect.
File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line
%d
Warning: opendir(%s/test/bad/bad.txt): failed to open dir: Operation not
permitted in %s on line %d
bool(false)
Warning: opendir(): open_basedir restriction in effect.
File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s
on line %d
Warning: opendir(%s/test/bad/../bad/bad.txt): failed to open dir: Operation not
permitted in %s on line %d
bool(false)
resource(8) of type (stream)
resource(9) of type (stream)
resource(10) of type (stream)
*** Finished testing open_basedir configuration [opendir] ***
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/dir/open_basedir.inc?view=markuprev=1.1
Index: php-src/ext/standard/tests/dir/open_basedir.inc
+++ php-src/ext/standard/tests/dir/open_basedir.inc
?php
// This file contains helper functions for testing open_basedir configuration
// Care must be taken with where the directories are created because different
// SAPIs set the working directory differently. So simply creating a directory
// relative to the current working directory like this: mkdir(blah) might
// actually create it in several different places depending on the SAPI..!
//
// Note also depending on the version of php being tested, so the open_basedir
// configuration may or may not be changeable from a script (PHP_INI_SYSTEM).
//
// For this reason we set the open_basedir to . (current directory) and then
// move around to various directories for testing using chdir(). This is NOT
// recommended for production use as . bypasses all semblence of security..!
//
// Although safe mode has been removed in php 6.0, open_basedir is still valid.
// See http://www.php.net/features.safe-mode for more information
function recursive_delete_directory($directory) {
// Remove any trailing slash first
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
// Make sure the directory is valid
if (is_dir($directory) == FALSE) {
return FALSE;
}
// Check we can access the directory
if (is_readable($directory) == FALSE) {
return FALSE;
}
$handle = opendir($directory);
// Scan through the directory contents
while (FALSE !== ($item = readdir($handle))) {
if ($item != '.') {
if ($item != '..') {