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

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

. ./prefs

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

if [ "$2" = "" ]; then
  echo "Usage: $(basename $0) <machine> <admin-passwd>"
  exit 0
fi

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

uid=`$rpcclient -S $1 -U Administrator%$2 -c 'regenum HKU\' | grep $sid | grep -v Classes | awk '{print $1}'`
rid=`echo $uid|awk -F- '{print $8}'`
    $ldapsearch -D $binddn -w $bindpassword rid=$ridhex -LLL |grep uid
user=`$rpcclient -S . -U root%rpcpassword -c "lookupsid $uid" -d0|grep $domain`
    echo $user

exit 0

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