mirror of
https://github.com/ceph/ceph
synced 2024-12-16 08:26:25 +00:00
ac07afa205
We can't check the initial permissions of the file because the umask may be set to something other than 0022. The check isn't needed to check for chmod correctness anyway. Signed-off-by: Sam Lang <sam.lang@inktank.com>
59 lines
903 B
Bash
Executable File
59 lines
903 B
Bash
Executable File
#!/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}'); 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
|