#!/bin/sh
env_setup="@env_setup@"
objdir="@objdir@"
srcdir="@srcdir@"
testfailed="echo test failed; cat messages.log; exit 1"
. ${env_setup}
${have_db} || exit 77
R=TEST.H5L.SE
uuspid=
port=@port@
kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port"
cache1="FILE:${objdir}/cache1.krb5"
cache2="FILE:${objdir}/cache2.krb5"
kinit1="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache1 ${afs_no_afslog}"
kinit2="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache2 ${afs_no_afslog}"
kdestroy1="${TESTS_ENVIRONMENT} ../../kuser/kdestroy -c $cache1 ${afs_no_unlog}"
kdestroy2="${TESTS_ENVIRONMENT} ../../kuser/kdestroy -c $cache2 ${afs_no_unlog}"
uu_server="${TESTS_ENVIRONMENT} ../../appl/test/uu_server"
uu_client="${TESTS_ENVIRONMENT} ../../appl/test/uu_client"
KRB5_CONFIG="${objdir}/krb5.conf"
export KRB5_CONFIG
rm -f current-db*
rm -f out-*
rm -f mkey.file*
> messages.log
echo Creating database
${kadmin} \
init \
--realm-max-ticket-life=1day \
--realm-max-renewable-life=1month \
${R} || exit 1
${kadmin} add -p foo --use-defaults user1@${R} || exit 1
${kadmin} add -p foo --use-defaults user2@${R} || exit 1
echo "Doing database check"
${kadmin} check ${R} || exit 1
echo foo > ${objdir}/foopassword
echo Starting kdc
${kdc} &
kdcpid=$!
sh ${wait_kdc}
if [ "$?" != 0 ] ; then
kill -9 ${kdcpid}
exit 1
fi
trap "kill -9 ${kdcpid} ${uuspid}; echo signal killing kdc; exit 1;" EXIT
ec=0
echo "Getting client initial tickets user1"; > messages.log
${kinit1} --password-file=${objdir}/foopassword user1@$R || \
{ ec=1 ; eval "${testfailed}"; }
echo "Getting client initial tickets user2"; > messages.log
${kinit2} --password-file=${objdir}/foopassword user2@$R || \
{ ec=1 ; eval "${testfailed}"; }
echo "starting uu server (using user1)"
KRB5CCNAME=$cache1 ${uu_server} > uuserver.log &
uuspid=$!
sleep 5
echo "trying to contact server with client (using user2)"
KRB5CCNAME=$cache2 ${uu_client} localhost > messages.log 2>&1 || \
{ ec=1; eval "${testfailed}"; }
sleep 5
echo "checking if server got the right message"
cmp uuserver.log ${srcdir}/uuserver.txt || \
{ ec=1; eval "${testfailed}"; }
uuspid=""
${kdestroy1}
${kdestroy2}
echo "killing kdc uu_server (${kdcpid} ${uuspid})"
sh ${leaks_kill} kdc $kdcpid || exit 1
trap "" EXIT
exit $ec