summaryrefslogtreecommitdiffstats
path: root/src/tests/dejagnu/krb-standalone/standalone.exp
blob: 0b3a4b0bf723792756fa6d159a1f8312aa4a62e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
 # Standalone Kerberos test.
# This is a DejaGnu test script.
# This script tests that the Kerberos tools can talk to each other.

# This mostly just calls procedures in testsuite/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]
}

# 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 1] {
    return
}

# 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 REALMNAME
    global KLIST
    global KDESTROY
    global KEY
    global hostname
    global tmppwd
    global spawn_id

    # Start up the kerberos and kadmind daemons.
    if ![start_kerberos_daemons 1] {
	return
    }

    # Use kadmin to add an host key.
    if ![add_random_key host/$hostname 1] {
	return
    }

    # Use ksrvutil to create a srvtab entry.
    if ![setup_srvtab 1] {
	return
    }

    # Use kinit to get a ticket.
    if ![kinit krbtest/admin adminpass$KEY 1] {
	return
    }

    # Make sure that klist can see the ticket.
    spawn $KLIST
    expect {
	-re "Ticket cache:\[ 	\]*$tmppwd/tkt.*Default principal:\[ 	\]*krbtest/admin@$REALMNAME.*krbtgt/$REALMNAME@$REALMNAME\r\n" {
	    verbose "klist started"
	}
	timeout {
	    fail "klist"
	    return
	}
	eof {
	    fail "klist"
	    return
	}
    }

   expect {
        "\r" { }
    }

    if ![check_exit_status "klist"] {
	return
    }
    pass "klist"

    # Destroy the ticket.
    spawn $KDESTROY
    if ![check_exit_status "kdestroy"] {
	return
    }
    pass "kdestroy"

    # Double check that the ticket was destroyed.
    spawn $KLIST
    expect {
	-re "klist: No credentials cache file found.*\r\n" {
	    verbose "klist started"
	}
	timeout {
	    fail "klist after kdestroy"
	    return
	}
	eof {
	    fail "klist after kdestroy"
	    return
	}
    }
    # We can't use check_exit_status, because we expect an exit status
    # of 1.
    set status_list [wait -i $spawn_id]
    verbose "wait -i $spawn_id returned $status_list (klist)"
    if { [lindex $status_list 2] != 0 } {
	fail "klist (bad exit status) $status_list"
	return
    } else { if { [lindex $status_list 3] != 1 } {
	fail "klist (bad exit status) $status_list"
	return
    } else {
	pass klist
    } }
}

set status [catch doit msg]

stop_kerberos_daemons

if { $status != 0 } {
    send_error "ERROR: error in standalone.exp\n"
    send_error "$msg\n"
    exit 1
}