]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Ramdisk check (closes #13)
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 18:05:17 +0000 (16:05 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 18:05:17 +0000 (16:05 -0200)
lib/keyringer/actions/edit
lib/keyringer/functions

index c539846f10c7fe7f52e6b563d3a9ce6a8ba70761..9a3e4881929c46dc96bfdf4f7815f41af6e3e428 100755 (executable)
@@ -13,9 +13,6 @@ keyringer_get_file "$2"
 # Set recipients file
 keyringer_set_recipients "$FILE"
 
-# Warn user
-echo "Make sure that $BASEDIR is atop of an encrypted volume."
-
 # Get original file EXTENSION
 FILENAME="$(basename "$FILE" .asc)"
 FILENAME="$(basename "$FILENAME")"
index d02b1d846f2fd59d7f3a8f8170b2748fc6a094b4..7570a94238c84c65d9f4f2350b64c5a8e699520c 100755 (executable)
@@ -111,16 +111,64 @@ function keyringer_is_git {
   fi
 }
 
+# Check the security of a temporary folder
+function keyringer_check_tmp {
+  local path="$1"
+  local minor
+  local mode
+
+  if [ -z "$path" ]; then
+    return
+  fi
+
+  # Mode check
+  if [ "`stat -c "%A" $path`" != "drwxrwxrwt" ]; then
+    return 1
+  fi
+
+  # Ramdisk check
+  if [ -x "/sbin/udevadm" ]; then
+    minor="$(/sbin/udevadm info --device-id-of-file "$path" | cut -d : -f 1)"
+  elif which mountpoint &> /dev/null; then
+    minor="$(mountpoint -d $(df "$path" | sed -n '$p' | awk '{print $NF}') | cut -d : -f 1)"
+  fi
+
+  if [ ! -z "$minor" ]; then
+    return $minor
+  else
+    return 1
+  fi
+}
+
 # Setup a temporary file
 function keyringer_set_tmpfile {
+  local tmp
+  local candidate
+  local candidates="/tmp /run/shm $TMP"
+
   if [ -z "$BASEDIR" ]; then
     echo "Please set BASEDIR before creating a tmp file"
     exit 1
   fi
 
+  # Ramdisk check
+  for candidate in $candidates; do
+    if keyringer_check_tmp $candidate; then
+      tmp="$candidate/keyringer.`whoami`"
+      break
+    fi
+  done
+
   # Set base temp folder
-  local tmp="$BASEDIR/tmp"
+  if [ -z "$tmp" ]; then
+    echo "WARNING: neither one of $candidates is mounted in a tmpfs/ramdisk, using $BASEDIR/tmp as fallback."
+    echo "Make sure that $BASEDIR is atop of an encrypted volume."
+    echo "Press any key to continue, Ctrl-C to abort"
+    read key
+    tmp="$BASEDIR/tmp"
+  fi
 
+  # Determine template
   if [ -z "$1" ]; then
     template="$tmp/keyringer.XXXXXXXXXX"
   else