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
|
# The function opens/reads files on the file system
|
||||||
|
|
||||||
user=$1
|
user=$1
|
||||||
src_file=$2
|
src=$2
|
||||||
|
|
||||||
# Checking arguments
|
# Checking arguments
|
||||||
if [ -z "$src_file" ]; then
|
if [ -z "$src" ]; then
|
||||||
echo "Usage: USER FILE"
|
echo "Usage: USER FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -27,27 +27,19 @@ if [ -z $homedir ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Checking path
|
# Checking path
|
||||||
if [ ! -z "$src_file" ]; then
|
if [ ! -z "$src" ]; then
|
||||||
rpath=$(readlink -f "$src_file")
|
rpath=$(readlink -f "$src")
|
||||||
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
|
||||||
echo "Error: invalid source path $src_file"
|
echo "Error: invalid source path $user $src"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
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
|
# Checking if file has readable permission
|
||||||
if [[ ! -r $src_file ]]
|
sudo -u $user ls "$src" > /dev/null 2>&1
|
||||||
then
|
if [ $? -ne 0 ]; then
|
||||||
# echo "File is readable"
|
echo "Error: can't read $src"
|
||||||
#else
|
exit 1
|
||||||
echo "Cannot read file"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Exiting
|
# Exiting
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue