blob: 887f738cfc2363f074d0d6bd1846b6dfd2d210f7 (
plain)
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#!/bin/bash
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
#testing "name" "command" "result" "infile" "stdin"
umask 022
PERM="---""--x""-w-""-wx""r--""r-x""rw-""rwx"
num2perm()
{
for i in 0 1 2
do
num=${1:$i:1}
printf "%s" ${PERM:$(($num*3)):3}
done
echo
}
# Creating test files to test chmod command
mkdir dir
touch file
# We don't need to test all 512 permissions
for u in 0 1 2 3 4 5 6 7
do
for g in 0 3 6
do
for o in 0 7
do
if [ "$type" == file ]
then
type=dir
rm -rf "./$type" && mkdir $type
DASH=d
else
type=file
rm -f "./$type" && touch $type
DASH=-
fi
DASHES=$(num2perm $u$g$o)
testing "chmod $u$g$o $type" "chmod $u$g$o $type &&
ls -ld $type | cut -d' ' -f 1 | cut -d. -f 1" "$DASH$DASHES\n" "" ""
done
done
done
rm -rf dir file && mkdir dir && touch file
testing "chmod 750 dir 640 file" \
"chmod 750 dir 640 file 2>/dev/null ||
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x---\n-rwxr-x---\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod 666 dir file" \
"chmod 666 dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod 765 *" "chmod 765 * &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" ""
##### u,g,o,a=r,w,x
rm -rf dir file && mkdir dir && touch file
testing "chmod u=r dir file" "chmod u=r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u=w dir file" "chmod u=w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u=x dir file" "chmod u=x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--xr-xr-x\n---xr--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+r dir file" "chmod u+r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+w dir file" "chmod u+w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+x dir file" "chmod u+x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-r dir file" "chmod u-r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-w dir file" "chmod u-w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-x dir file" "chmod u-x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=r dir file" "chmod g=r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=w dir file" "chmod g=w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=x dir file" "chmod g=x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw---xr--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+r dir file" "chmod g+r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+w dir file" "chmod g+w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+x dir file" "chmod g+x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-r dir file" "chmod g-r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwx--xr-x\n-rw----r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-w dir file" "chmod g-w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-x dir file" "chmod g-x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=r dir file" "chmod o=r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=w dir file" "chmod o=w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=x dir file" "chmod o=x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r----x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+r dir file" "chmod o+r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+w dir file" "chmod o+w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+x dir file" "chmod o+x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-r dir file" "chmod o-r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-x--x\n-rw-r-----\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-w dir file" "chmod o-w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-x dir file" "chmod o-x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=r dir file" "chmod a=r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=w dir file" "chmod a=w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w--w--w-\n--w--w--w-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=x dir file" "chmod a=x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+r dir file" "chmod a+r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+w dir file" "chmod a+w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+x dir file" "chmod a+x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-r dir file" "chmod a-r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-w dir file" "chmod a-w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-x dir file" "chmod a-x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =r dir file" "chmod =r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =w dir file" "chmod =w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-w-------\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =x dir file" "chmod =x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d--x--x--x\n---x--x--x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +r dir file" "chmod +r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +w dir file" "chmod +w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +x dir file" "chmod +x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -r dir file" "chmod -r dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "d-wx--x--x\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -w dir file" "chmod -w dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -x dir file" "chmod -x dir file &&
ls -ld dir file | cut -d' ' -f 1 | cut -d. -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
# Removing test files for cleanup purpose
rm -rf dir file
|