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 * Prototype  : object dir(string $directory[, resource $context])
14 * Description: Directory class with properties, handle and class and methods read, rewind and close
15 * Source code: ext/standard/dir.c
16 */
17
18/*
19 * remove the execute permission from the parent dir and test dir() on child dir
20 *   1) remove write & execute permission from the 1st parent and test dir()
21 *   2) remove execute permission from 2nd parent and test dir()
22 */
23
24echo "*** Testing dir() : remove execute permission from the parent dir ***\n";
25
26/* create the temporary directory :
27  dir_variation7  ( parent )
28    |-> sub_dir    ( sub parent )
29         |-> child_dir  ( child dir)
30*/
31$file_path = __DIR__;
32$parent_dir_path = $file_path."/dir_variation7";
33@mkdir($parent_dir_path);
34chmod($parent_dir_path, 0777);
35
36// create sub_dir
37$sub_dir_path = $parent_dir_path."/sub_dir";
38@mkdir($sub_dir_path);
39chmod($sub_dir_path, 0777);
40
41//create sub_sub_dir
42$child_dir_path = $sub_dir_path."/child_dir";
43@mkdir($child_dir_path);
44
45// remove the write and execute permisson from sub parent
46chmod($sub_dir_path, 0444);
47echo "-- After restricting 1st level parent directory --\n";
48$d = dir($child_dir_path); // try to open, expected failure
49var_dump( $d ); // dump it
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
54echo "-- After restricting parent directory --\n";
55$d = dir($child_dir_path); // try to open, expected failure
56var_dump( $d ); // dump it
57
58echo "Done";
59?>
60--CLEAN--
61<?php
62$file_path = __DIR__;
63$parent_dir_path = $file_path."/dir_variation7";
64$sub_dir_path = $parent_dir_path."/sub_dir";
65$child_dir_path = $sub_dir_path."/child_dir";
66
67// changing permissions for each temporary directory to delete them
68chmod($parent_dir_path, 0777);
69chmod($sub_dir_path, 0777);
70chmod($child_dir_path, 0777);
71
72rmdir($child_dir_path);
73rmdir($sub_dir_path);
74rmdir($parent_dir_path);
75?>
76--EXPECTF--
77*** Testing dir() : remove execute permission from the parent dir ***
78-- After restricting 1st level parent directory --
79
80Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d
81bool(false)
82-- After restricting parent directory --
83
84Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d
85bool(false)
86Done
87