Blame 0013-90crypt-enhance-crypt-lib-keydev-mounting.patch

Harald Hoyer 12f6cc
From c5758f20902b37e3232cd6a1b79f914155457ffd Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: Leho Kraav <leho@kraav.com>
Harald Hoyer 12f6cc
Date: Tue, 24 Jul 2012 15:08:52 +0300
Harald Hoyer 12f6cc
Subject: [PATCH] 90crypt: enhance crypt-lib keydev mounting
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
Combining $keydev and $keypath should result in a unique, re-usable keydev
Harald Hoyer 12f6cc
mountpoint. mkuniqdir doesn't seem to have any an advantage here and lacks
Harald Hoyer 12f6cc
reusability. Is there ever a use case where these are true:
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
 * there are more than one rd.luks.key=$keypath:$keydev
Harald Hoyer 12f6cc
 * one is actually different from the other
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 modules.d/90crypt/crypt-lib.sh | 13 +++++++++++--
Harald Hoyer 12f6cc
 1 file changed, 11 insertions(+), 2 deletions(-)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/modules.d/90crypt/crypt-lib.sh b/modules.d/90crypt/crypt-lib.sh
Harald Hoyer 12f6cc
index 3aed84d..5f7567e 100755
Harald Hoyer 12f6cc
--- a/modules.d/90crypt/crypt-lib.sh
Harald Hoyer 12f6cc
+++ b/modules.d/90crypt/crypt-lib.sh
Harald Hoyer 12f6cc
@@ -165,8 +165,15 @@ readkey() {
Harald Hoyer 12f6cc
     local keydev="$2"
Harald Hoyer 12f6cc
     local device="$3"
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
-    local mntp=$(mkuniqdir /mnt keydev)
Harald Hoyer 12f6cc
-    mount -r "$keydev" "$mntp" || die 'Mounting rem. dev. failed!'
Harald Hoyer 12f6cc
+    # This creates a unique single mountpoint for *, or several for explicitly
Harald Hoyer 12f6cc
+    # given LUKS devices. It accomplishes unlocking multiple LUKS devices with
Harald Hoyer 12f6cc
+    # a single password entry.
Harald Hoyer 12f6cc
+    local mntp="/mnt/$(str_replace "keydev-$keydev-$keypath" '/' '-')"
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    if [ ! -d "$mntp" ]; then
Harald Hoyer 12f6cc
+        mkdir "$mntp"
Harald Hoyer 12f6cc
+        mount -r "$keydev" "$mntp" || die 'Mounting rem. dev. failed!'
Harald Hoyer 12f6cc
+    fi
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
     case "${keypath##*.}" in
Harald Hoyer 12f6cc
         gpg)
Harald Hoyer 12f6cc
@@ -188,6 +195,8 @@ readkey() {
Harald Hoyer 12f6cc
         *) cat "$mntp/$keypath" ;;
Harald Hoyer 12f6cc
     esac
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
+    # General unmounting mechanism, modules doing custom cleanup should return earlier
Harald Hoyer 12f6cc
+    # and install a pre-pivot cleanup hook
Harald Hoyer 12f6cc
     umount "$mntp"
Harald Hoyer 12f6cc
     rmdir "$mntp"
Harald Hoyer 12f6cc
 }