]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Adding keyringer_shred (closes #27)
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 17:01:01 +0000 (15:01 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 17:01:01 +0000 (15:01 -0200)
lib/keyringer/functions

index 40e13aa5c502c70f1e1b409c6854ef5c010499bb..fcec045e290e80e61fd4335b58f901a24a0422e9 100755 (executable)
@@ -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."