HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: //opt/BCLinux/bse/secure_set/s02_passRemember
#!/bin/sh

#=======================================================
InsertSection "Set password remember times"

if [ $SET_PASSWORD_REM -eq 1 ];then

    cp -np /etc/pam.d/system-auth /etc/pam.d/system-auth_bak

    #echo -e "make sure this file has (password restrictions, and has remember >=5)"
    if [ ! -w /etc/security/opasswd ] ; then
        #echo "no opasswd file, creating..."
        touch /etc/security/opasswd
        chown root:root /etc/security/opasswd
        chmod 600 /etc/security/opasswd
    fi

    if [ -w /etc/security/opasswd ]; then
        Display --indent 2 --text "- create the  opasswd file finished... " --result FINISHED --color GREEN
    else
        Display --indent 2 --text "- create the  opasswd file failed... " --result FAILED --color RED
    fi

    IS_EXIST=`grep password /etc/pam.d/system-auth |grep pam_unix.so | grep -v "^#" |wc -l`
    if [ "${IS_EXIST}" != "0" ] ; then
        IS_EXIST=`grep password /etc/pam.d/system-auth |grep pam_unix.so | grep  remember= | grep -v "^#" |wc -l`
        if [ "${IS_EXIST}" = "0" ] ; then
            #echo -e "has pam_unix.so module, but does not contain remember config, adding...."
            sed -i 's/^password    sufficient.*pam_unix.so.*/& remember='$PASSWORD_REM'/' /etc/pam.d/system-auth
        else
            sed -i "s/\(.*password.*pam_unix.so.*\) remember=.*/\1 remember=$PASSWORD_REM/" /etc/pam.d/system-auth
        fi
    else
        sed -i "/password.*pam_pwquality.so/a\password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=$PASSWORD_REM" /etc/pam.d/system-auth
    fi


    IS_EXIST=`grep password /etc/pam.d/system-auth |grep pam_unix.so |wc -l`
    if [ "${IS_EXIST}" != "0" ] ; then
        IS_EXIST=`grep password /etc/pam.d/system-auth |grep pam_unix.so | grep remember |wc -l`
        if [ ${IS_EXIST} -gt 0 ] ; then
            Display --indent 2 --text "- Set password remember times... " --result FINISHED --color GREEN
        else
            Display --indent 2 --text "- Set password remember times... " --result FAILED --color RED
        fi
    else
        Display --indent 2 --text "- No pam_unix.so set, Please check... " --result FAILED --color RED
    fi

else

    Display --indent 2 --text "- Skip set opasswd rem times due to config file... " --result SKIPPING --color YELLOW

fi