summaryrefslogtreecommitdiffstats
path: root/roles/ands_kitauth/files/scripts/login_script.sh
blob: 9b66968984c7e8527933b26cadc073e7671d15c7 (plain)
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
#!/bin/bash
# Script to authomatecly create user home directories
# Shall we consider creating both NFS and local homes? Or shall we just create it on NFS?

LOG=/var/log/login_script
DATE=`/bin/date +"%b %d %H:%M:%S"`

if [ x${PAM_TYPE} == "xopen_session" ]; then set $(getent passwd $PAM_USER | awk -F ":" '{print $3" "$4" "$5" "$6}')
      USERUID=$1; USERGID=$2; USERHOME=$4

    echo "[$DATE]: login of $PAM_USER: UID=$USERUID: GID=$USERGID: HOME=$USERHOME: from $PAM_RHOST via $PAM_SERVICE" >> $LOG

    if [ ! -z "${USERHOME}" -a ! -d ${USERHOME} ]; then
        #if [ ! -d /home/${USERHOME} ]; then
            echo "  Home for user ${USERNAME} does not exist at ${USERHOME} => creating" >> $LOG

            mkdir -p $USERHOME
            cp -af /etc/skel/.[a-zA-Z]* $USERHOME
            chown -R $USERUID.$USERGID $USERHOME
            chmod 701 $USERHOME
            chmod g+s $USERHOME
    fi
fi
if [ x${PAM_TYPE} == "xclose_session" ]; then
    echo "[$DATE]: logout of $PAM_USER $USERUID" >> $LOG
fi