#! /bin/sh
#echo "auth using $PAM_SERVICE" >>/tmp/authorizing
if [[ \"$PAM_SERVICE\" == \"login\" || \"$PAM_SERVICE\" == \"sshd\" ]]
then
  ip=$PAM_RHOST
  sorm_started_flag="/tmp/sorm_started"
  date=`date +%dd%Hh%Mm%Ss`
  if [[ \"$PAM_SERVICE\" == \"login\" ]]
  then
    ip="localhost"
  fi

  #is SORM started?
  if test -f $sorm_started_flag
  then
      #echo "Sorm is started. Blocking authorization." >> /tmp/logined
      #echo ":::succ:$PAM_USER@$ip;$date:::" >> /tmp/logined
      echo ":::succ:$PAM_USER@$ip;$date:::" >> /tmp/auth_err
      exit 1
  fi
                  
  /usr/local/bin/sormauth_event &
    


fi
exit 0
