From d7d79d848bd5d2c7e2f6c3b7092918a42fda67a6 Mon Sep 17 00:00:00 2001 From: "emre.akkaya" Date: Mon, 27 Jun 2016 12:03:51 +0300 Subject: [PATCH 1/6] bug fix for pam session open --- usr/share/libpam-script/pam_script_ses_open | 31 +++++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/usr/share/libpam-script/pam_script_ses_open b/usr/share/libpam-script/pam_script_ses_open index db3c275..ee9c835 100755 --- a/usr/share/libpam-script/pam_script_ses_open +++ b/usr/share/libpam-script/pam_script_ses_open @@ -1,6 +1,31 @@ #!/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 + From 9c51a4aee42028531695c8a4d163e24fcdaf91d7 Mon Sep 17 00:00:00 2001 From: Emre Akkaya Date: Mon, 27 Jun 2016 12:16:59 +0300 Subject: [PATCH 2/6] Update pam_script_ses_open --- usr/share/libpam-script/pam_script_ses_open | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/usr/share/libpam-script/pam_script_ses_open b/usr/share/libpam-script/pam_script_ses_open index ee9c835..00b5450 100755 --- a/usr/share/libpam-script/pam_script_ses_open +++ b/usr/share/libpam-script/pam_script_ses_open @@ -25,7 +25,6 @@ if [ -n $PAM_USER ] && [ $PAM_USER != "root" ]; 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 + sudo python3 /opt/ahenk/ahenkd.py login $PAM_USER $SERVICE $TTY_DISPLAY fi fi - From ef22848728c56378ee93097c91d83c5a8819e3f4 Mon Sep 17 00:00:00 2001 From: Emre Akkaya Date: Mon, 27 Jun 2016 12:17:28 +0300 Subject: [PATCH 3/6] Update pam_script_ses_open --- usr/share/libpam-script/pam_script_ses_open | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/share/libpam-script/pam_script_ses_open b/usr/share/libpam-script/pam_script_ses_open index 00b5450..817a380 100755 --- a/usr/share/libpam-script/pam_script_ses_open +++ b/usr/share/libpam-script/pam_script_ses_open @@ -18,11 +18,11 @@ 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" + $SERVICE="$PAM_SERVICE" fi TTY_DISPLAY="none" if [ -n $PAM_TTY ]; then - TTY_DISPLAY="$PAM_TTY" + $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 From 4f3168c092043c3ad2b20574e42221b18dba822e Mon Sep 17 00:00:00 2001 From: Emre Akkaya Date: Mon, 27 Jun 2016 12:20:09 +0300 Subject: [PATCH 4/6] Update pam_script_ses_open --- usr/share/libpam-script/pam_script_ses_open | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/share/libpam-script/pam_script_ses_open b/usr/share/libpam-script/pam_script_ses_open index 817a380..00b5450 100755 --- a/usr/share/libpam-script/pam_script_ses_open +++ b/usr/share/libpam-script/pam_script_ses_open @@ -18,11 +18,11 @@ 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" + SERVICE="$PAM_SERVICE" fi TTY_DISPLAY="none" if [ -n $PAM_TTY ]; then - $TTY_DISPLAY="$PAM_TTY" + 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 From f52275cf7886e71053c709cb71bc2a65cb2b5910 Mon Sep 17 00:00:00 2001 From: Emre Akkaya Date: Mon, 27 Jun 2016 12:37:12 +0300 Subject: [PATCH 5/6] Update pam_script_ses_close --- usr/share/libpam-script/pam_script_ses_close | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 From 1653f692eaabe6304a4da6c426de1151c81b32df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Mon, 27 Jun 2016 12:41:16 +0300 Subject: [PATCH 6/6] commamder.py updated for new pam configuration --- opt/ahenk/base/command/commander.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/opt/ahenk/base/command/commander.py b/opt/ahenk/base/command/commander.py index da85512..920e299 100644 --- a/opt/ahenk/base/command/commander.py +++ b/opt/ahenk/base/command/commander.py @@ -29,7 +29,14 @@ class Commander(object): self.clean() return False - elif (params[1] == 'login' or params[1] == 'logout') and len(params) == 3: + elif params[1] == 'login' and len(params) == 7: + print('{1} {0}ing'.format(str(params[1]), str(params[2]))) + data['event'] = params[1] + data['username'] = params[2] + data['service'] = params[4] + data['display'] = str(params[6]).replace(':', '') + + elif params[1] == 'logout' and len(params) == 3: print('{1} {0}ing'.format(str(params[1]), str(params[2]))) data['event'] = params[1] data['username'] = params[2]