#!/bin/sh
############################################################ checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se>## This script will authenticate OpenVPN users against# a plain text file. The passfile should simply contain# one row per user with the username first followed by# one or more space(s) or tab(s) and then the password.PASSFILE="/etc/openvpn/psw-file"LOG_FILE="/etc/openvpn/openvpn-password.log"TIME_STAMP=`date "+%Y-%m-%d %T"`###########################################################if[ ! -r "${PASSFILE}"];thenecho"${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE}exit1fiCORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}'${PASSFILE}`if["${CORRECT_PASSWORD}"=""];thenecho"${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}exit1fiif["${password}"="${CORRECT_PASSWORD}"];thenecho"${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}exit0fiecho"${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}exit1