1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
--TEST--
Test dir() function : usage variations - different directory permissions
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Not for Windows');
}
require __DIR__ . '/../skipif_root.inc';
?>
--FILE--
<?php
/*
* Prototype : object dir(string $directory[, resource $context])
* Description: Directory class with properties, handle and class and methods read, rewind and close
* Source code: ext/standard/dir.c
*/
/*
* Providing various permissions to the directory to be opened and checking
* to see if dir() function opens the directory successfully.
*/
echo "*** Testing dir() : different directory permissions ***";
// create the temporary directory
$file_path = __DIR__;
$dir_path = $file_path."/dir_variation3";
@mkdir($dir_path);
/* different values for directory permissions */
$permission_values = array(
/*1*/ 0477, // owner has read only, other and group has rwx
0677, // owner has rw only, other and group has rwx
/*3*/ 0444, // all have read only
0666, // all have rw only
/*5*/ 0400, // owner has read only, group and others have no permission
0600, // owner has rw only, group and others have no permission
/*7*/ 0470, // owner has read only, group has rwx & others have no permission
0407, // owner has read only, other has rwx & group has no permission
/*9*/ 0670, // owner has rw only, group has rwx & others have no permission
/*10*/ 0607 // owner has rw only, group has no permission and others have rwx
);
// Open directory with different permission values, read and close, expected: none of them to succeed.
for($count = 0; $count < count($permission_values); $count++) {
echo "\n-- Iteration ".($count + 1)." --\n";
// try to remove the dir if exists & create
$file_path = __DIR__;
$dir_path = $file_path."/dir_variation3";
@chmod ($dir_path, 0777); // change dir permission to allow all operation
@rmdir ($dir_path); // try n delete the dir
// create the dir now
@mkdir($dir_path);
// change the dir permission to test dir on it
var_dump( chmod($dir_path, $permission_values[$count]) );
// try to get dir handle
$d = dir($dir_path);
var_dump($d); // dump the handle
// try read directory, expected : false
echo "-- reading contents --\n";
var_dump($d->read());
// close directory
$d->close();
}
echo "Done";
?>
--CLEAN--
<?php
// deleting temporary directory
$file_path = __DIR__;
$dir_path = $file_path."/dir_variation3";
rmdir($dir_path);
?>
--EXPECTF--
*** Testing dir() : different directory permissions ***
-- Iteration 1 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 2 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 3 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 4 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 5 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 6 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 7 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 8 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 9 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
-- Iteration 10 --
bool(true)
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation3"
["handle"]=>
resource(%d) of type (stream)
}
-- reading contents --
string(%d) "%s"
Done
|