#!/bin/bash
# change password  (wijzig paswoord)
# paul@vandervlis.nl

# get variables
. /usr/local/sbin/variables

# ask user when not on commandline:
if test "$1" = ""; then
  read -p "Username: " user
else
  user=$1
fi
if test "$user" = ""; then
  echo no user.
  exit
fi

# ask for password password:
passwordc=`pwgen -A 8 1`
read -p "Password for $user, specify a password (return=$passwordc) : " password
if test "$password" = ""; then
  password="$passwordc"
fi

# change password
kadmin.local -q "change_password -pw $password $user"

# nscd restart   
service nscd restart > /dev/null

# samba
if test "$samba" = "1"; then
  echo "Samba:"
  echo -ne "$password\n$password\n" | smbpasswd -s $user
fi

# log
echo "`date` change password $user with new password $password" >> /var/log/au.log

