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

42 lines
1.2 KiB
Plaintext

Index: scripts/umount.crypt
===================================================================
--- scripts/umount.crypt.orig
+++ scripts/umount.crypt
@@ -46,6 +46,7 @@ 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;
@@ -53,6 +54,15 @@ for ((x = 5; x >= 0; --x)); do
sleep 1;
done;
+# 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
+
umount "$1";
if [ $? -ne 0 ]; then
echo "${0##*/}: error unmounting $1" >&2
@@ -73,3 +83,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
+