SHA256
1
0
forked from pool/pam_mount
pam_mount/pam_mount-0.18-umount-home-dir.dif

39 lines
1.1 KiB
Plaintext

Index: scripts/umount.crypt
===================================================================
--- scripts/umount.crypt.orig
+++ scripts/umount.crypt
@@ -54,9 +54,20 @@ if [ -z "$DMDEVICE" ]; then
exit 1;
fi;
+# kill remaining user processes if we're unmounting a user's home dir
+USER=`stat --format=%U $1 2>/dev/null` && getent passwd "$USER" | grep -e ":$1:" &> /dev/null
+if test $? -eq 0; then
+ lsof -t $1 | xargs kill -TERM &> /dev/null
+ sleep 1
+ lsof -t $1 | xargs kill -9 &> /dev/null
+ sleep 1
+fi
+
+
# ask cryptsetup about the underlying device
#
REALDEVICE=`cryptsetup status "$DMDEVICE" | sed -n '/device/s/[ ]*device:[ ]*//p'`;
+IMGDEVICE=`"$LOSETUP" -a | grep "$REALDEVICE" | awk -F\( '{ print $2 }' | sed 's/)//'`
for ((x = 5; x >= 0; --x)); do
fuser -m "$1" || break;
@@ -90,3 +101,12 @@ if echo "$REALDEVICE" | grep ^/dev/loop
exit 1
fi
fi
+
+if echo "$IMGDEVICE" | grep ^/dev/loop >/dev/null; then
+ "$LOSETUP" -d "$IMGDEVICE";
+ if [ $? -ne 0 ]; then
+ echo "${0##*/}: error removing $IMGDEVICE" >&2
+ exit 1
+ fi
+fi
+