pam_mount/pam_mount-0.18-umount-home-dir.dif

45 lines
1.2 KiB
Plaintext
Raw Normal View History

--- scripts/umount.crypt
+++ scripts/umount.crypt 2007/09/21 09:14:07
@@ -57,9 +57,19 @@
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/)//'`
"$UMOUNT" "$1";
if [ $? -ne 0 ]; then
@@ -69,7 +79,7 @@
# Check for LUKS
#
-if "$CRYPTSETUP" isLuks "$DEVICE" 2>/dev/null; then
+if "$CRYPTSETUP" isLuks "$REALDEVICE" 2>/dev/null; then
"$CRYPTSETUP" luksClose "$DMDEVICE";
else
"$CRYPTSETUP" remove "$DMDEVICE";
@@ -87,3 +97,12 @@
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
+