1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

testprogs: Add net offlinejoin composeodj tests

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13577

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Sep  5 22:11:46 UTC 2023 on atb-devel-224
This commit is contained in:
Samuel Cabrero 2023-09-04 16:49:52 +02:00 committed by Andrew Bartlett
parent e92e4b9544
commit f3c632e74b

View File

@ -27,6 +27,7 @@ cd $RUNDIR
failed=0
net_tool="$BINDIR/net --configfile=$BASEDIR/$WORKDIR/client.conf --option=security=ads"
samba_texpect="$BINDIR/texpect"
# Load test functions
. $(dirname $0)/subunit.sh
@ -69,6 +70,93 @@ rm -f $ODJFILE
testit "leave" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(expr $failed + 1)
test_compose_odj() {
local mode=$1
local composeargv=()
# Retrieve the necessary information to compose the ODJ blob
# The machine needs to be correctly joined at this point
local netbios_domain_name=$($net_tool ads lookup | awk -F': ' '/^Pre-Win2k Domain/ {print $2}')
local domain_sid=$($net_tool getdomainsid | awk -F': ' "/^SID for domain $netbios_domain_name/ {print \$2}")
local domain_guid=$($net_tool ads lookup | awk -F': ' '/^GUID/ {print $2}')
local forest_name=$($net_tool ads lookup | awk -F': ' '/^Forest/ {print $2}')
local dc_name=$($net_tool ads info | awk -F': ' '/^LDAP server name/ {print $2}')
local dc_address=$($net_tool ads info | awk -F': ' '/^LDAP server:/ {print $2}')
local ret=1
local out=""
composeargv=( \
"domain_sid=${domain_sid}" \
"domain_guid=${domain_guid}" \
"forest_name=${forest_name}" \
"-S ${dc_name}" \
"-I ${dc_address}" \
"savefile=${ODJFILE}"
)
case $mode in
machacct)
cmd='$net_tool offlinejoin composeodj ${composeargv[@]} -P 2>&1'
out=$(eval $cmd)
ret=$?
;;
stdinfd)
cmd='echo ${netbios} | $net_tool offlinejoin composeodj ${composeargv[@]} -U${netbios^^}\$ 2>&1'
out=$(PASSWD_FD=0 eval $cmd)
ret=$?
;;
callback)
tmpfile=$BASEDIR/$WORKDIR/composeodj_password_script
cat >$tmpfile <<EOF
expect Password for [${netbios_domain_name^^}\\${netbios^^}\$]:
send $netbios\n
EOF
cmd='$samba_texpect -v $tmpfile $net_tool offlinejoin composeodj ${composeargv[@]} 2>&1'
out=$(eval $cmd)
ret=$?
rm -f $tmpfile
;;
*)
out="Unknown mode '$mode'"
;;
esac
if [ $ret -ne 0 ]; then
echo "Failed to compose ODJ blob: $out"
return 1
fi
}
# 4. Test composeodj
modes=("machacct" "stdinfd" "callback")
for mode in "${modes[@]}"; do
defpwd="defpwd"
if [ "$mode" == "machacct" ]; then
defpwd=""
fi
testit "provision[$mode]" $VALGRIND $net_tool offlinejoin provision domain=$REALM machine_name=$netbios savefile=$ODJFILE $defpwd -U$DC_USERNAME%$DC_PASSWORD || failed=$(expr $failed + 1)
testit "requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(expr $failed + 1)
testit "testjoin [$mode]" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(expr $failed + 1)
testit "removeodjblob [$mode]" rm $ODJFILE || failed=$(expr $failed + 1)
testit "composeodj [$mode]" test_compose_odj $mode || failed=$(expr $failed + 1)
testit "removesecretsdb [$mode]" rm $BASEDIR/$WORKDIR/private/secrets.tdb || failed=$(expr $failed + 1)
testit "requestodj [$mode]" $VALGRIND $net_tool offlinejoin requestodj loadfile=$ODJFILE || failed=$(expr $failed + 1)
testit "removeodjblob [$mode]" rm $ODJFILE || failed=$(expr $failed + 1)
testit "testjoin [$mode]" $VALGRIND $net_tool ads testjoin -P --use-kerberos=required || failed=$(expr $failed + 1)
testit "leave [$mode]" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=$(expr $failed + 1)
done
rm -rf $BASEDIR/$WORKDIR
exit $failed