2012-10-14 19:24:58 +00:00
|
|
|
#!/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
|
2015-05-04 16:33:16 +00:00
|
|
|
if test "${perms}" != $(echo ${r} | awk '{print $1}') && \
|
|
|
|
test "${perms}." != $(echo ${r} | awk '{print $1}') && \
|
|
|
|
test "${perms}+" != $(echo ${r} | awk '{print $1}'); then
|
2012-10-14 19:24:58 +00:00
|
|
|
echo "ERROR: Permissions should be ${perms}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-10-18 15:13:12 +00:00
|
|
|
file=test_chmod.$$
|
|
|
|
|
|
|
|
echo "foo" > ${file}
|
2012-10-14 19:24:58 +00:00
|
|
|
if test $? != 0; then
|
2012-10-18 15:13:12 +00:00
|
|
|
echo "ERROR: Failed to create file ${file}"
|
2012-10-14 19:24:58 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-18 15:13:12 +00:00
|
|
|
chmod 400 ${file}
|
2012-10-14 19:24:58 +00:00
|
|
|
if test $? != 0; then
|
2012-10-18 15:13:12 +00:00
|
|
|
echo "ERROR: Failed to change mode of ${file}"
|
2012-10-14 19:24:58 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-18 15:13:12 +00:00
|
|
|
check_perms ${file} "-r--------"
|
2012-10-14 19:24:58 +00:00
|
|
|
|
|
|
|
set +e
|
2012-10-18 15:13:12 +00:00
|
|
|
echo "bar" >> ${file}
|
2012-10-14 19:24:58 +00:00
|
|
|
if test $? = 0; then
|
|
|
|
echo "ERROR: Write to read-only file should Fail"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
2012-10-18 15:13:12 +00:00
|
|
|
chmod 600 ${file}
|
|
|
|
echo "bar" >> ${file}
|
2012-10-14 19:24:58 +00:00
|
|
|
if test $? != 0; then
|
|
|
|
echo "ERROR: Write to writeable file failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-18 15:13:12 +00:00
|
|
|
check_perms ${file} "-rw-------"
|
2012-10-14 19:24:58 +00:00
|
|
|
|
2012-10-18 15:13:12 +00:00
|
|
|
echo "foo" >> ${file}
|
2012-10-14 19:24:58 +00:00
|
|
|
if test $? != 0; then
|
|
|
|
echo "ERROR: Failed to write to file"
|
|
|
|
exit 1
|
|
|
|
fi
|