blob: de66776f108be359ccf5f6b40e8275a258f746a4 (
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
|
#!/bin/sh -x
set -e
check_perms() {
file=$1
r=$(ls -la ${file})
if test $? != 0; then
echo "ERROR: File listing/stat failed"
exit 1
fi
perms=$2
if test "${perms}" != $(echo ${r} | awk '{print $1}') && \
test "${perms}." != $(echo ${r} | awk '{print $1}') && \
test "${perms}+" != $(echo ${r} | awk '{print $1}'); then
echo "ERROR: Permissions should be ${perms}"
exit 1
fi
}
file=test_chmod.$$
echo "foo" > ${file}
if test $? != 0; then
echo "ERROR: Failed to create file ${file}"
exit 1
fi
chmod 400 ${file}
if test $? != 0; then
echo "ERROR: Failed to change mode of ${file}"
exit 1
fi
check_perms ${file} "-r--------"
set +e
echo "bar" >> ${file}
if test $? = 0; then
echo "ERROR: Write to read-only file should Fail"
exit 1
fi
set -e
chmod 600 ${file}
echo "bar" >> ${file}
if test $? != 0; then
echo "ERROR: Write to writeable file failed"
exit 1
fi
check_perms ${file} "-rw-------"
echo "foo" >> ${file}
if test $? != 0; then
echo "ERROR: Failed to write to file"
exit 1
fi
|