diff options
author | Kevin Krammer <kevin.krammer@gmx.at> | 2006-07-29 09:50:10 +0000 |
---|---|---|
committer | Kevin Krammer <kevin.krammer@gmx.at> | 2006-07-29 09:50:10 +0000 |
commit | 019013c4559c2f278cd7eb29a090759ea4bb4739 (patch) | |
tree | 7e9739a5bb537b5df85c1c7c1ab8316cbc8242c3 /portland | |
parent | 93b6c6aaa5ce9c745d7c8ea69e51a8201e5e4503 (diff) |
Explicitly check for file existance and read permission of --info input file
before handing it over to the desktop tools
Diffstat (limited to 'portland')
-rwxr-xr-x | portland/xdg-utils/scripts/xdg-mime.in | 2 | ||||
-rw-r--r-- | portland/xdg-utils/scripts/xdg-utils-common.in | 55 |
2 files changed, 54 insertions, 3 deletions
diff --git a/portland/xdg-utils/scripts/xdg-mime.in b/portland/xdg-utils/scripts/xdg-mime.in index 73298fe..5c9063a 100755 --- a/portland/xdg-utils/scripts/xdg-mime.in +++ b/portland/xdg-utils/scripts/xdg-mime.in @@ -350,6 +350,8 @@ if [ "$action" = "makedefault" ]; then fi if [ "$action" = "info" ]; then + check_input_file "$filename" + detectDE if [ x"$DE" = x"" ]; then diff --git a/portland/xdg-utils/scripts/xdg-utils-common.in b/portland/xdg-utils/scripts/xdg-utils-common.in index 4204998..a8ab2dc 100644 --- a/portland/xdg-utils/scripts/xdg-utils-common.in +++ b/portland/xdg-utils/scripts/xdg-utils-common.in @@ -36,7 +36,7 @@ exit_failure_syntax() echo "Try '@NAME@ --help' for more information." >&2 else usage - echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." + echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." fi exit 1 @@ -78,6 +78,55 @@ exit_failure_operation_failed() exit 4 } +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_read() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + fi + + exit 5 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_write() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + fi + + exit 6 +} + +check_input_file() +{ + if [ ! -e "$1" ]; then + exit_failure_file_missing "file '$1' does not exist" + fi + if [ ! -r "$1" ]; then + exit_failure_file_permission_read "no permission to read file '$1'" + fi +} + +check_output_file() +{ + # if the file exists, check if it is writeable + # if it does not exists, check if we are allowed to write on the directory + if [ -e "$1" ]; then + if [ ! -w "$1" ]; then + exit_failure_file_permission_write "no permission to write to file '$1'" + fi + else + DIR=`dirname "$1"` + if [ ! -w "$DIR" -o ! -x "$DIR" ]; then + exit_failure_file_permission_write "no permission to create file '$1'" + fi + fi +} #---------------------------------------- # Checks for shared commands, e.g. --help @@ -91,7 +140,7 @@ check_common_commands() case "$parm" in --help) usage - echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." + echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." exit_success ;; @@ -111,7 +160,7 @@ check_common_commands() check_common_commands "$@" if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then # Be silent - xdg_redirect_output=" > /dev/null 2> /dev/null" + xdg_redirect_output=" > /dev/null 2> /dev/null" else # All output to stderr xdg_redirect_output=" >&2" |