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
|
--TEST--
Test fileperms() & chmod() functions: usage variation - misc. perms
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Not on Windows');
}
// Skip if being run by root
$filename = dirname(__FILE__)."/006_root_check.tmp";
$fp = fopen($filename, 'w');
fclose($fp);
if(fileowner($filename) == 0) {
unlink ($filename);
die('skip cannot be run as root');
}
unlink($filename);
?>
--FILE--
<?php
/*
Prototype: int fileperms ( string $filename );
Description: Returns the permissions on the file, or FALSE in case of an error
Prototype: bool chmod ( string $filename, int $mode );
Description: Attempts to change the mode of the file specified by
filename to that given in mode
*/
/* Testing with miscellaneous Permission */
echo "*** Testing fileperms() & chmod() : usage variations ***\n";
$file_name = dirname(__FILE__)."/006_variation2.tmp";
$file_handle = fopen($file_name, "w");
fclose($file_handle);
$dir_name = dirname(__FILE__)."/006_variation2";
mkdir($dir_name);
echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
$perms_array = array(
/* testing sticky bit */
07777,
00000,
01000,
011111,
/* negative values as permission */
-0777, // permissions will be given as 2's complement form of -0777
-07777, // permissions will be given as 2's complement form of -07777
/* decimal values as permission */
777, // permissions will be given as octal equivalent value of 777
7777, // permissions will be given as octal equivalent value of 7777
-7777, // permissions are given as 2's complement of octal equivalent of 7777
/* hex value as permission */
0x777, // permissions will be given as ocatal equivalent value of 0x777
0x7777,
/* strings notation of permission, wont work properly */
"r+w",
"r+w+x",
"u+rwx",
"u+rwx, g+rw, o+wx"
);
$count = 1;
foreach($perms_array as $permission) {
echo "-- Iteration $count --\n";
try {
var_dump( chmod($file_name, $permission) );
printf("%o", fileperms($file_name) );
echo "\n";
clearstatcache();
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump( chmod($dir_name, $permission) );
printf("%o", fileperms($dir_name) );
echo "\n";
clearstatcache();
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
$count++;
}
echo "*** Done ***\n";
?>
--CLEAN--
<?php
chmod(dirname(__FILE__)."/006_variation2.tmp", 0777);
chmod(dirname(__FILE__)."/006_variation2", 0777);
unlink(dirname(__FILE__)."/006_variation2.tmp");
rmdir(dirname(__FILE__)."/006_variation2");
?>
--EXPECTF--
*** Testing fileperms() & chmod() : usage variations ***
*** Testing fileperms(), chmod() with miscellaneous permissions ***
-- Iteration 1 --
bool(true)
107777
bool(true)
47777
-- Iteration 2 --
bool(true)
100000
bool(true)
40000
-- Iteration 3 --
bool(true)
101000
bool(true)
41000
-- Iteration 4 --
bool(true)
101111
bool(true)
41111
-- Iteration 5 --
bool(true)
107001
bool(true)
47001
-- Iteration 6 --
bool(true)
100001
bool(true)
40001
-- Iteration 7 --
bool(true)
101411
bool(true)
41411
-- Iteration 8 --
bool(true)
107141
bool(true)
47141
-- Iteration 9 --
bool(true)
100637
bool(true)
40637
-- Iteration 10 --
bool(true)
103567
bool(true)
43567
-- Iteration 11 --
bool(true)
103567
bool(true)
43567
-- Iteration 12 --
chmod() expects parameter 2 to be int, string given
chmod() expects parameter 2 to be int, string given
-- Iteration 13 --
chmod() expects parameter 2 to be int, string given
chmod() expects parameter 2 to be int, string given
-- Iteration 14 --
chmod() expects parameter 2 to be int, string given
chmod() expects parameter 2 to be int, string given
-- Iteration 15 --
chmod() expects parameter 2 to be int, string given
chmod() expects parameter 2 to be int, string given
*** Done ***
|