From 6c08cb89106d0ab22749993ef860f593bb60b344 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 14 Nov 2013 15:01:01 -0200 Subject: Adding keyringer_shred (closes #27) --- lib/keyringer/functions | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/keyringer/functions b/lib/keyringer/functions index 40e13aa..fcec045 100755 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -144,13 +144,42 @@ function keyringer_set_tmpfile { trap "keyringer_unset_tmpfile $TMPWORK; exit" INT TERM EXIT } +# Shred files +function keyringer_shred { + local path="$1" + local tool + + if [ -z "$path" ]; then + return + fi + + # Get shred implementation + if which wipe &> /dev/null; then + tool="wipe" + elif which shred &> /dev/null; then + tool="shred" + else + # Worst implementation + tool="rm" + fi + + echo "Removing $path using $tool..." + + if [ -d "$path" ]; then + find $path -exec $tool -f {} \; + rmdir $path + elif [ -e "$path" ]; then + $tool -f "$path" + fi +} + # Remove a temporary file function keyringer_unset_tmpfile { if [ -z "$1" ]; then echo "No tmp file set" fi - rm -f "$1" + keyringer_shred "$1" if [ "$?" != "0" ]; then echo "Warning: could not delete file $1. Please delete it manually as it might have sensitive information." -- cgit v1.2.3