#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: check if the default policy is owned by Administrator
## exposure: safe
## tags:
##  - apptest
## packages:
## - univention-samba4

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

administrator=${users_default_administrator:-Administrator}

administrator_uid=$(univention-ldapsearch uid="$administrator" uidNumber | VAL1 uidNumber)

sysvol_domain_dir=$(find /var/lib/samba/sysvol -mindepth 1 -maxdepth 1 -iname "$domainname")

for policy in "$sysvol_domain_dir"/*
do
	ownerid="$(stat -c "%u" "$policy")"
	if [ "$ownerid" != "$administrator_uid" ]; then
		ls -la "$policy"
		fail_test 110 "The owner uid for $policy is not $ownerid"
	fi
done

exit "$RETVAL"
