1. #!/bin/sh
    2. ###########################################################
    3. # checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se>
    4. #
    5. # This script will authenticate OpenVPN users against
    6. # a plain text file. The passfile should simply contain
    7. # one row per user with the username first followed by
    8. # one or more space(s) or tab(s) and then the password.
    9. PASSFILE="/home/openvpn/conf/server/psw-file"
    10. LOG_FILE="/var/log/openvpn-password.log"
    11. TIME_STAMP=`date "+%Y-%m-%d %T"`
    12. ###########################################################
    13. if [ ! -r "${PASSFILE}" ]; then
    14. echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}
    15. exit 1
    16. fi
    17. CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`
    18. if [ "${CORRECT_PASSWORD}" = "" ]; then
    19. echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
    20. exit 1
    21. fi
    22. if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
    23. echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}
    24. exit 0
    25. fi
    26. echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
    27. exit 1