Joseph Reynolds | fa32483 | 2021-03-16 21:30:40 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Convert OpenBMC linux-PAM config files |
| 3 | |
| 4 | # Location of config files this script modifies: |
| 5 | # PAM_CONF_DIR - path to the PAM config files |
| 6 | # SECURITY_CONF_DIR - path to the security config files |
| 7 | PAM_CONF_DIR=/etc/pam.d |
| 8 | SECURITY_CONF_DIR=/etc/security |
| 9 | |
| 10 | # Handle common-password: |
| 11 | # Change cracklib to pwquality and handle the minlen parameter |
| 12 | pam_cracklib=$(grep "^password.*pam_cracklib.so" ${PAM_CONF_DIR}/common-password) |
| 13 | if [ -n "${pam_cracklib}" ] |
| 14 | then |
| 15 | echo "Changing ${PAM_CONF_DIR}/common-password to use pam_pwquality.so (was pam_cracklib.so)" >&2 |
| 16 | minlen=$(echo "${pam_cracklib}" | sed -e "s/.*minlen=\([[:alnum:]]*\).*/\1/") |
| 17 | echo " Converting parameter minlen=${minlen} to ${SECURITY_CONF_DIR}/pwquality.conf minlen" >&2 |
| 18 | sed -i.bak -e "s/^minlen=.*/minlen=$minlen/" ${SECURITY_CONF_DIR}/pwquality.conf |
| 19 | pwquality='password [success=ok default=die] pam_pwquality.so debug' |
| 20 | sed -i.bak -e "s/^password.*pam_cracklib.so.*/$pwquality/" ${PAM_CONF_DIR}/common-password |
| 21 | echo "# This file was converted by $0" >>${PAM_CONF_DIR}/common-password |
| 22 | fi |
| 23 | |
| 24 | # Handle common-auth: |
| 25 | # Change tally2 to faillock and handle the deny & unlock_time parameters |
| 26 | pam_tally2=$(grep "^auth.*pam_tally2.so" ${PAM_CONF_DIR}/common-auth) |
| 27 | if [ -n "${pam_tally2}" ] |
| 28 | then |
| 29 | echo "Changing ${PAM_CONF_DIR}/common-auth to use pam_faillock.so (was pam_tally2.so)" >&2 |
| 30 | deny=$(echo "${pam_tally2}" | sed -e "s/.*deny=\([[:alnum:]]*\).*/\1/") |
| 31 | unlock_time=$(echo "${pam_tally2}" | sed -e "s/.*unlock_time=\([[:alnum:]]*\).*/\1/") |
| 32 | # Change faillock.conf parameters |
| 33 | echo " Converting parameter deny=${deny} to ${SECURITY_CONF_DIR}/faillock.conf deny" >&2 |
| 34 | echo " Converting parameter unlock_time=${unlock_time} to ${SECURITY_CONF_DIR}/faillock.conf unlock_time" >&2 |
| 35 | sed -i.bak \ |
| 36 | -e "s/^deny=.*/deny=$deny/" \ |
| 37 | -e "s/^unlock_time=.*/unlock_time=$unlock_time/" \ |
| 38 | ${SECURITY_CONF_DIR}/faillock.conf |
| 39 | # Change pam_tally2 to pam_faillock (changes the overall auth stack) |
| 40 | authfail='auth [default=die] pam_faillock.so authfail' |
| 41 | authsucc='auth sufficient pam_faillock.so authsucc' |
| 42 | sed -i.bak \ |
| 43 | -e "/^auth.*pam_tally2.so.*$/d" \ |
| 44 | -e "/^auth.*pam_deny.so/i $authfail\n$authsucc" \ |
| 45 | ${PAM_CONF_DIR}/common-auth |
| 46 | echo "# This file was converted by $0" >>${PAM_CONF_DIR}/common-auth |
| 47 | fi |
| 48 | |