mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 20:41:53 -07:00
safe way to check permissions
This commit is contained in:
parent
a0ee9bbc98
commit
c06ba9fc9c
1 changed files with 9 additions and 17 deletions
|
@ -5,10 +5,10 @@
|
|||
# The function opens/reads files on the file system
|
||||
|
||||
user=$1
|
||||
src_file=$2
|
||||
src=$2
|
||||
|
||||
# Checking arguments
|
||||
if [ -z "$src_file" ]; then
|
||||
if [ -z "$src" ]; then
|
||||
echo "Usage: USER FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -27,27 +27,19 @@ if [ -z $homedir ]; then
|
|||
fi
|
||||
|
||||
# Checking path
|
||||
if [ ! -z "$src_file" ]; then
|
||||
rpath=$(readlink -f "$src_file")
|
||||
if [ ! -z "$src" ]; then
|
||||
rpath=$(readlink -f "$src")
|
||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||
echo "Error: invalid source path $src_file"
|
||||
echo "Error: invalid source path $user $src"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# Reading file
|
||||
#sudo -u $user cat "$src_file" 2>/dev/null
|
||||
#if [ $? -ne 0 ]; then
|
||||
# echo "Error: file $src_file was not opened"
|
||||
# exit 3
|
||||
#fi
|
||||
|
||||
# Checking if file has readable permission
|
||||
if [[ ! -r $src_file ]]
|
||||
then
|
||||
# echo "File is readable"
|
||||
#else
|
||||
echo "Cannot read file"
|
||||
sudo -u $user ls "$src" > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: can't read $src"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Exiting
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue