Annotation of embedaddon/php/ext/standard/tests/dir/opendir_variation5.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test opendir() function : usage variations - directories with restricted permissions
        !             3: --SKIPIF--
        !             4: <?php
        !             5: if( substr(PHP_OS, 0, 3) == 'WIN') {
        !             6:        die('skip Not for Windows');
        !             7: }
        !             8: // Skip if being run by root (files are always readable, writeable and executable)
        !             9: $filename = dirname(__FILE__)."/dir_root_check.tmp";
        !            10: $fp = fopen($filename, 'w');
        !            11: fclose($fp);
        !            12: if(fileowner($filename) == 0) {
        !            13:        unlink ($filename);
        !            14:        die('skip...cannot be run as root\n');
        !            15: }
        !            16: unlink($filename);
        !            17: ?>
        !            18: --FILE--
        !            19: <?php
        !            20: /* Prototype  : mixed opendir(string $path[, resource $context])
        !            21:  * Description: Open a directory and return a dir_handle 
        !            22:  * Source code: ext/standard/dir.c
        !            23:  */
        !            24: 
        !            25: /*
        !            26:  * remove the execute permission from the parent dir and test opendir() on child dir
        !            27:  *   1) remove write & execute permission from the 1st parent and test opendir()
        !            28:  *   2) remove execute permission from 2nd parent and test opendir()
        !            29:  */
        !            30: 
        !            31: echo "*** Testing opendir() : usage variations ***\n";
        !            32: 
        !            33: /* create the temporary directory :
        !            34:  * opendir_variation5  ( parent )
        !            35:  *  |-> sub_dir    ( sub parent )
        !            36:  *      |-> child_dir  ( child dir)
        !            37:  */
        !            38: 
        !            39: $parent_dir_path = dirname(__FILE__) . "/opendir_variation5";
        !            40: mkdir($parent_dir_path);
        !            41: chmod($parent_dir_path, 0777);
        !            42: 
        !            43: // create sub_dir
        !            44: $sub_dir_path = $parent_dir_path . "/sub_dir";
        !            45: mkdir($sub_dir_path);
        !            46: chmod($sub_dir_path, 0777);
        !            47: 
        !            48: //create sub_sub_dir
        !            49: $child_dir_path = $sub_dir_path."/child_dir";
        !            50: mkdir($child_dir_path);
        !            51: 
        !            52: // remove the write and execute permisson from sub parent
        !            53: chmod($sub_dir_path, 0444);
        !            54: 
        !            55: echo "\n-- After restricting 1st level parent directory --\n";
        !            56: $dir_handle1 = opendir($child_dir_path);
        !            57: var_dump( $dir_handle1 );
        !            58: 
        !            59: // remove the execute permisson from parent dir, allowing all permission for sub dir
        !            60: chmod($sub_dir_path, 0777); // all permisson to sub dir
        !            61: chmod($parent_dir_path, 0666); // restricting parent directory
        !            62: 
        !            63: echo "\n-- After restricting parent directory --\n";
        !            64: $dir_handle2 = opendir($child_dir_path); // try to open, expected failure
        !            65: var_dump( $dir_handle2 ); // dump it
        !            66: 
        !            67: if (is_resource($dir_handle1)) {
        !            68:        closedir($dir_handle1);
        !            69: }
        !            70: if (is_resource($dir_handle2)) {
        !            71:        closedir($dir_handle2);
        !            72: }
        !            73: ?>
        !            74: ===DONE===
        !            75: --CLEAN--
        !            76: <?php
        !            77: $parent_dir_path = dirname(__FILE__) . "/opendir_variation5";
        !            78: $sub_dir_path = $parent_dir_path."/sub_dir";
        !            79: $child_dir_path = $sub_dir_path."/child_dir";
        !            80: 
        !            81: // changing permissions for each temporary directory to delete them
        !            82: chmod($parent_dir_path, 0777);
        !            83: chmod($sub_dir_path, 0777);
        !            84: chmod($child_dir_path, 0777);
        !            85: 
        !            86: rmdir($child_dir_path);
        !            87: rmdir($sub_dir_path);
        !            88: rmdir($parent_dir_path);
        !            89: ?>
        !            90: 
        !            91: --EXPECTF--
        !            92: *** Testing opendir() : usage variations ***
        !            93: 
        !            94: -- After restricting 1st level parent directory --
        !            95: 
        !            96: Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
        !            97: bool(false)
        !            98: 
        !            99: -- After restricting parent directory --
        !           100: 
        !           101: Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
        !           102: bool(false)
        !           103: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>