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