summaryrefslogblamecommitdiffstats
path: root/remote/modules/pam/data/opt/openslx/scripts/pam_script_ses_close
blob: fda9633ee08d3db931a582a2932dd1bb0694f16f (plain) (tree)
1
2
3
4
5
6
7
8



                                                    



                                                         













                                                               
                                                                        

                                       
                                                             


      
 
#!/bin/bash

echo "[${PAM_TYPE}] Closing session for ${PAM_USER}"

# NSA needs to know
slxlog "session-close" "$PAM_USER logged out on $PAM_TTY"

OPENSESSIONS=$(loginctl | grep "${PAM_USER}" | wc -l)

if [ "x${OPENSESSIONS}" == "x1" ]; then
	# last sessions, close all ghost user processes
	pkill -u "${PAM_USER}"

	# check if it worker
	while ps aux | grep -v grep | grep -q "${PAM_USER}"; do
		sleep 1
	done
	# all done, kill it again to be sure
	pkill -9 -u "${PAM_USER}" 

	# unmount the home directory structure
	umount "/home/${PAM_USER}/PERSISTENT" || \
		echo "Could not unmount '/home/${PAM_USER}/PERSISTENT'."
        
	umount "/home/${PAM_USER}" || \
		echo "Could not unmount '/home/${PAM_USER}'."
fi

exit 0