#!/bin/sh
#writen by Zane C. Bowers <vvelox@vvelox.net>

. `which sh-include`
include random
include lugtools

usage(){
    echo "lurm: search and change the password of a posix user in a LDAP directory"
    echo "version 0.1.2"
    echo ""
    echo "-c <file> the config file to use... the default is ~/.lugtools"
    echo ""
    echo "required:"
    echo "-u <username>  the username of the user"
    echo ""
    echo "-h    display this"
}

#create the tmp file
tmpfile=/tmp/luadd.$$
touch $tmpfile
chmod go-rwx $tmpfile

#default config file
config=~/.lugtools

#get the options
while getopts hu:c: OPTION ; do
    case "$OPTION" in
	u) username="$OPTARG" ;;
	c) config="$OPTARG" ;;
        h) usage=true ;;
       \?) usage=true ;;
    esac
done

#if usage is defined, print the usage info and exit
if  [ ! -z $usage ]; then
    usage;
    exit 1;
fi

#includes the config file
if [ -e $config ]; then
    . $config
else
    echo $config does not exist
    exit 1
fi

#exit if no username is specified
if [ -z $username ]; then
    echo -u not used to specify a user name
    exit 1
fi

#get the user DN
userDN=`LDAPuserDN $username $USERBASE $BIND $PASSWDFILE`

#make sure one was found
if [ -z $userDN ]; then
    echo "$username now found in $USERBASE"
    exit 1
fi

#ask for passwd and change it
ldappasswd -S -y "$PASSWDFILE" -D "$BIND" $userDN


syntax highlighted by Code2HTML, v. 0.9.1