#!/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/shares.sh
. "$TESTLIBPATH/shares.sh" || exit 137

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

target_host="$(univention-ldapsearch -LLL "univentionService=S4 Connector" cn | sed -n 's/^cn: //p')"

if [ -z "$target_host" ]; then
    echo "Could not determine the target host for the test."
    exit 137
fi

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
