#!/bin/bash
# Samba-TNG                                         delete_domain_user
# --------------------------------------------------------------------

# --------------------------------------------------------------------
# config here

. ./prefs

# --------------------------------------------------------------------
# print usage

if [ "$1" = "" ]; then
	echo "Usage: $(basename $0) <username>"
	exit 0
fi

# --------------------------------------------------------------------
# begin

userexist=`$ldapsearch -D $binddn -w $bindpassword -b $smbsuffix uid="$1" -LLL |grep sambaAccount`

if [ "$userexist" = "" ]; then
	echo "Domain User does not exist!"
	exit 1
else

# This function is not yet implemented with LDAP
#       $rpcclient -S . -U $user%$password -c "deluser \"$1\" " -d0

udn="uid=$1,$suffix"
echo "Deleting $udn"
ldapdelete $udn -D $binddn -w $bindpassword

	exit 0
fi

exit 0

# --------------------------------------------------------------------
