1--TEST--
2Test dir() 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/*
13 * remove the execute permission from the parent dir and test dir() on child dir
14 *   1) remove write & execute permission from the 1st parent and test dir()
15 *   2) remove execute permission from 2nd parent and test dir()
16 */
17
18echo "*** Testing dir() : remove execute permission from the parent dir ***\n";
19
20/* create the temporary directory :
21  dir_variation7  ( parent )
22    |-> sub_dir    ( sub parent )
23         |-> child_dir  ( child dir)
24*/
25$file_path = __DIR__;
26$parent_dir_path = $file_path."/dir_variation7";
27@mkdir($parent_dir_path);
28chmod($parent_dir_path, 0777);
29
30// create sub_dir
31$sub_dir_path = $parent_dir_path."/sub_dir";
32@mkdir($sub_dir_path);
33chmod($sub_dir_path, 0777);
34
35//create sub_sub_dir
36$child_dir_path = $sub_dir_path."/child_dir";
37@mkdir($child_dir_path);
38
39// remove the write and execute permission from sub parent
40chmod($sub_dir_path, 0444);
41echo "-- After restricting 1st level parent directory --\n";
42$d = dir($child_dir_path); // try to open, expected failure
43var_dump( $d ); // dump it
44
45// remove the execute permission from parent dir, allowing all permission for sub dir
46chmod($sub_dir_path, 0777); // all permission to sub dir
47chmod($parent_dir_path, 0666); // restricting parent directory
48echo "-- After restricting parent directory --\n";
49$d = dir($child_dir_path); // try to open, expected failure
50var_dump( $d ); // dump it
51
52echo "Done";
53?>
54--CLEAN--
55<?php
56$file_path = __DIR__;
57$parent_dir_path = $file_path."/dir_variation7";
58$sub_dir_path = $parent_dir_path."/sub_dir";
59$child_dir_path = $sub_dir_path."/child_dir";
60
61// changing permissions for each temporary directory to delete them
62chmod($parent_dir_path, 0777);
63chmod($sub_dir_path, 0777);
64chmod($child_dir_path, 0777);
65
66rmdir($child_dir_path);
67rmdir($sub_dir_path);
68rmdir($parent_dir_path);
69?>
70--EXPECTF--
71*** Testing dir() : remove execute permission from the parent dir ***
72-- After restricting 1st level parent directory --
73
74Warning: dir(%s/dir_variation7/sub_dir/child_dir): Failed to open directory: %s in %s on line %d
75bool(false)
76-- After restricting parent directory --
77
78Warning: dir(%s/dir_variation7/sub_dir/child_dir): Failed to open directory: %s in %s on line %d
79bool(false)
80Done
81