diff --git a/opt/ahenk/base/command/commander.py b/opt/ahenk/base/command/commander.py index 5abf8be..9b08ce0 100644 --- a/opt/ahenk/base/command/commander.py +++ b/opt/ahenk/base/command/commander.py @@ -37,6 +37,7 @@ class Commander(object): data['desktop'] = params[4] data['display'] = params[6] + elif params[1] == 'logout' and len(params) == 3: print('{1} {0}ing'.format(str(params[1]), str(params[2]))) data['event'] = params[1] diff --git a/usr/share/libpam-script/pam_script_ses_close b/usr/share/libpam-script/pam_script_ses_close index b2b7ddb..344d77f 100755 --- a/usr/share/libpam-script/pam_script_ses_close +++ b/usr/share/libpam-script/pam_script_ses_close @@ -1,6 +1,30 @@ #!/bin/bash -if [ -n $PAM_USER ]; then - if [ $PAM_USER != "root" ]; then + +function error_exit() { + log "$1:$2 failed, exit status $?" + exit 1 +} + +trap 'error_exit "${BASH_SOURCE}" "${LINENO}"' ERR + +LOG=/var/log/pam_script.log + +function log() { + logger --priority auth.info --tag "$0" "$@" + echo "$(date) $0: $@" >> $LOG +} + +if [ -n $PAM_USER ] && [ $PAM_USER != "root" ]; then + if ([ -n $PAM_SERVICE ] && [[ $PAM_SERVICE == *"dm" ]]) || ([ -n $PAM_TTY ] && [[ $PAM_TTY == ":"* ]]); then + SERVICE="none" + if [ -n $PAM_SERVICE ]; then + SERVICE="$PAM_SERVICE" + fi + TTY_DISPLAY="none" + if [ -n $PAM_TTY ]; then + TTY_DISPLAY="$PAM_TTY" + fi + log "logout: $PAM_USER service: $SERVICE tty: $TTY_DISPLAY" sudo python3 /opt/ahenk/ahenkd.py logout $PAM_USER fi fi diff --git a/usr/share/libpam-script/pam_script_ses_open b/usr/share/libpam-script/pam_script_ses_open index db3c275..00b5450 100755 --- a/usr/share/libpam-script/pam_script_ses_open +++ b/usr/share/libpam-script/pam_script_ses_open @@ -1,6 +1,30 @@ #!/bin/bash -if [ -n $PAM_USER ]; then - if [ $PAM_USER != "root" ]; then - sudo python3 /opt/ahenk/ahenkd.py login $PAM_USER + +function error_exit() { + log "$1:$2 failed, exit status $?" + exit 1 +} + +trap 'error_exit "${BASH_SOURCE}" "${LINENO}"' ERR + +LOG=/var/log/pam_script.log + +function log() { + logger --priority auth.info --tag "$0" "$@" + echo "$(date) $0: $@" >> $LOG +} + +if [ -n $PAM_USER ] && [ $PAM_USER != "root" ]; then + if ([ -n $PAM_SERVICE ] && [[ $PAM_SERVICE == *"dm" ]]) || ([ -n $PAM_TTY ] && [[ $PAM_TTY == ":"* ]]); then + SERVICE="none" + if [ -n $PAM_SERVICE ]; then + SERVICE="$PAM_SERVICE" + fi + TTY_DISPLAY="none" + if [ -n $PAM_TTY ]; then + TTY_DISPLAY="$PAM_TTY" + fi + log "login: $PAM_USER service: $SERVICE tty: $TTY_DISPLAY" + sudo python3 /opt/ahenk/ahenkd.py login $PAM_USER $SERVICE $TTY_DISPLAY fi fi