--- /dev/null
+# Test for the sample clients
+# This is a DejaGnu test script.
+# This script tests that sample user-user communication works.
+
+# This mostly just calls procedures in test/dejagnu/config/default.exp.
+
+if ![info exists KLIST] {
+ set KLIST [findfile $objdir/../../clients/klist/klist]
+}
+
+if ![info exists KDESTROY] {
+ set KDESTROY [findfile $objdir/../../clients/kdestroy/kdestroy]
+}
+
+if ![info exists SSERVER] {
+ set SSERVER [findfile $objdir/../../appl/sample/sserver/sserver]
+}
+if ![info exists SCLIENT] {
+ set SCLIENT [findfile $objdir/../../appl/sample/sclient/sclient]
+}
+
+# Set up the Kerberos files and environment.
+if {![get_hostname] || ![setup_kerberos_files] || ![setup_kerberos_env]} {
+ return
+}
+
+# Initialize the Kerberos database. The argument tells
+# setup_kerberos_db that it is being called from here.
+if ![setup_kerberos_db 0] {
+ return
+}
+
+proc stop_sserver_daemon { } {
+ global sserver_pid
+ global sserver_spawn_id
+
+ if [info exists sserver_pid] {
+ catch "close -i $sserver_spawn_id"
+ catch "exec kill $sserver_pid"
+ wait -i $sserver_spawn_id
+ unset sserver_pid
+ }
+
+ return 1
+}
+
+# We are about to start up a couple of daemon processes. We do all
+# the rest of the tests inside a proc, so that we can easily kill the
+# processes when the procedure ends.
+
+proc doit { } {
+ global KLIST
+ global KDESTROY
+ global KEY
+ global SSERVER
+ global SCLIENT
+ global hostname
+ global tmppwd
+ global spawn_id
+ global sserver_pid
+ global sserver_spawn_id
+
+ # Start up the kerberos and kadmind daemons.
+ if ![start_kerberos_daemons 0] {
+ return
+ }
+
+ # Use kadmin to add an host key.
+ if ![add_random_key sample/$hostname 1] {
+ return
+ }
+
+ # Use ksrvutil to create a srvtab entry for sample
+ if ![setup_srvtab 1 sample] {
+ return
+ }
+
+ # Use kinit to get a ticket.
+ if ![kinit krbtest/admin adminpass$KEY 1] {
+ return
+ }
+
+ # Start the sserver
+ spawn $SSERVER -p 3964 -S $tmppwd/srvtab
+ set sserver_pid [exp_pid]
+ set sserver_spawn_id $spawn_id
+
+ verbose "sserver_spawn is" $sserver_spawn_id
+
+ # Give sserver some time to start
+ catch "exec sleep 2"
+
+ # Test the client
+ spawn $SCLIENT $hostname 3964
+ expect {
+ "sendauth succeeded, reply is:" {
+ verbose "Start proper message"
+ }
+ timeout {
+ fail "sclient"
+ return
+ }
+ eof {
+ fail "sclient"
+ return
+ }
+ }
+
+ expect {
+ "You are krbtest/admin@KRBTEST.COM" {
+ verbose "received valid sample message"}
+ eof {
+ fail "sclient"
+ return
+ }
+ }
+
+ if ![check_exit_status "ssample"] {
+ return
+ }
+ pass "ssample"
+
+ # Check the exit status of sserver - should exit here
+ set status_list [wait -i $sserver_spawn_id]
+ verbose "wait -i $sserver_spawn_id returned $status_list (sserver)"
+ catch "close -i $sserver_spawn_id"
+ if { [lindex $status_list 2] != 0 || [lindex $status_list 3] != 0 } {
+ send_log "exit status: $status_list\n"
+ verbose "exit status: $status_list"
+ fail "sserver"
+ } else {
+ pass "sserver"
+ }
+ # In either case the server shutdown
+ unset sserver_pid
+
+ return
+}
+
+set status [catch doit msg]
+
+stop_sserver_daemon
+
+stop_kerberos_daemons
+
+if { $status != 0 } {
+ send_error "ERROR: error in sample.exp\n"
+ send_error "$msg\n"
+ exit 1
+}