#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Test accessing sysvol with smbclient using machine.secret
## exposure: safe
## packages:
##  - smbclient
## bugs: [30818]
## roles-not: [basesystem]

# shellcheck source=../../lib/base.sh
. "$TESTLIBPATH/base.sh" || exit 137
# shellcheck source=../../lib/shares.sh
. "$TESTLIBPATH/shares.sh" || exit 137

password="$(cat /etc/machine.secret)"

target_host="$(univention-ldapsearch -LLL "univentionService=S4 Connector" cn | VAL cn)"
[ -n "$target_host" ] ||
	fail_fast 137 "Could not determine the target host for the test."

info "----Accessing sysvol on $target_host.$domainname using smbclient and hostname/machine.secret credentials"

output="$(smbclient -U "$hostname\$%$password" "//$target_host.$domainname/sysvol" -c "ls $domainname/Policies" 2>&1)" &&
	exit "$RETVAL"

error "$output"
fail_test 1 "Could not access Policies on sysvol with machine.secret credentials"

exit "$RETVAL"
