#! /bin/dash PATH="/usr/bin" export PATH # password file # PASSWD="/vecr/.private/.htpasswd" ### # function to display error and exit # error() { echo "Content-type: text/plain\n" echo "$@" exit 1 } # www.ece # error "set local password not available" exit 1 ### # function to display password requirements # describe_password() { echo "Once you set a local password, it is effective immediately and must be used instead of your Villanova LDAP password to access this system.

Passwords must be 8 characters long, must not contain any blanks, and must contain at least two alphabetic characters (case-sensitive) and at least two non-alphabetic characters (e.g. digits or punctuation)." } ### # function to check password # check_password() { len=$(expr "$password" : ".*") if [ "$len" -ne 8 ]; then error "Password must be 8 characters long." fi x=$(echo "$password" | tr -d '[:space:]') len=$(expr "$x" : ".*") if [ "$len" -ne 8 ]; then error "Password must not contain any blank characters." fi x=$(echo "$password" | tr -d '[:alpha:]') len=$(expr "$x" : ".*") if [ "$len" -lt 2 ]; then error "Password must contain at least 2 non-alphabetic characters." fi x=$(echo "$password" | tr -dc '[:alpha:]') len=$(expr "$x" : ".*") if [ "$len" -lt 2 ]; then error "Password must contain at least 2 alphabetic characters." fi } # echo "Content-type: text/plain\n" # echo "args: $@\n\nstdin:" # cat # exit 0 title="${user} - set/reset local password" ### # handle GET # if [ "$1" = "GET" ]; then echo "Content-type: text/html\n $title

$title

" describe_password echo "

New Password:
" exit ### # handle POST # else case "$user" in root) error "Bad user." ;; esac read password check_password x=$(/usr/bin/htpasswd -d -b "$PASSWD" "$user" "$password" 2>&1) status="$?" if [ "$status" -eq 0 ]; then echo "Content-type: text/html\n\n$title

$title

Local password has been set to:" echo "$password" | sed -e 's/\&/\&/g' -e 's//\>/g' echo "

Please re-login using your new password." else error "Set password failed:\n\n$x" fi exit fi