summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/eduroam/files/usr/share/libpam-script/pam_script_ses_close
blob: 0568fd64b69d02b6beb420930a9ea51033a8bc02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# pam_script_ses_close
# ran by root after user closes session

echo "[$PAM_TYPE] Closing session for $PAM_USER..."
# minimal uid: users with uid under this wont get deleted.
MIN_UID=234299000

# remove local user & home dir
# only execute for uid > MIN_UID
#if [ $(id -u $PAM_USER) -gt $MIN_UID -a "x$(cat /var/run/eduroam_auth_method.$PAM_USER)" == "xradius" ]
if [ $(id -u $PAM_USER) -gt $MIN_UID ]
then
  #[ -f /var/run/eduroam_auth_method.$PAM_USER ] && rm /var/run/eduroam_auth_method.$PAM_USER
  
  # decrement session
  session_counter=/tmp/$PAM_USER.sessioncount
  session_count=$(cat $session_counter)
  echo "$(($session_count-1))" > $session_counter  
  
  # home dir ugly purge ... (log to debug...)
  log=/var/log/eduroam
  [ -f $log ] && rm $log
  if [ -d /home/$PAM_USER ] 
  then
    umount -fl /home/$PAM_USER/.gvfs &>> $log
    chown -R root:root /home/$PAM_USER &>> $log
    chmod -R a+rwx /home/$PAM_USER &>> $log
    rm -rf /home/$PAM_USER &>> $log
  fi
  find /tmp -user $PAM_USER -delete
  sed -i "/^$PAM_USER/d" /etc/passwd
  sed -i "/^$PAM_USER/d" /etc/shadow
  echo "[$PAM_TYPE] Local user deleted." 
fi

echo "[$PAM_TYPE] Hope you enjoyed your stay $PAM_USER."