#!/bin/bash 
# Required smbclient
function Test_Admin_Share {
	user=$1
	pass_file=$2
	host=$3

	user_name=$user
	if [[ ! -z $(echo "$user" | grep '\\') ]]
	then
		domain=$(echo $user | sed -En 's/(.*)\\(.*)/\1/p')
		user_name=$(echo $user | sed -En 's/(.*)\\(.*)/\2/p')
	fi
	rnd=$(echo $RANDOM | md5sum | head -c 6)
	random_name="colibri-$rnd"
	tmp_store="/tmp/$random_name"
	printf 'username=%s\npassword=%s\ndomain=%s' "$user_name" "$(cat $pass_file)" "$domain" > $tmp_store
	output=$(smbclient -L "$host" -A "$tmp_store" | grep -w "C\\$")
	rm $tmp_store

	if [ -z "$output" ]
	then
		return 1
	else
		return 0
	fi
}
