aboutsummaryrefslogtreecommitdiff
path: root/src/tests/dejagnu/krb-standalone/standalone.exp
blob: ca601ef48ec3500ee0d01bd177eea9250be96edf (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# 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.

# 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 dump_and_reload {} {
    global KDB5_UTIL
    global tmppwd

    set dumpfile $tmppwd/dump-file
    set dumpokfile $dumpfile.dump_ok

    set test1name "kdb5_util dump"
    set test2name "kdb5_util load"

    if [file exists $dumpfile] { file delete $dumpfile }
    if [file exists $dumpokfile] { file delete $dumpokfile }

    spawn $KDB5_UTIL dump $dumpfile
    expect {
	-re "..*" {
	    fail $test1name
	    untested $test2name
	    return
	}
	timeout {
	    fail $test1name
	    untested $test2name
	    return
	}
	eof { }
    }
    if ![check_exit_status $test1name] {
	untested $test2name
	return
    }
    if ![file exists $dumpfile]||![file exists $dumpokfile] {
	fail $test1name
	untested $test2name
	return
    }
    pass $test1name

    spawn $KDB5_UTIL load $dumpfile
    expect {
	-re "..*" {
	    fail $test2name
	    return
	}
	timeout {
	    fail $test2name
	    return
	}
	eof { }
    }
    if [check_exit_status $test2name] {
	pass $test2name
    }
}

proc doit { } {
    global REALMNAME
    global KLIST
    global KDESTROY
    global KEY
    global KADMIN_LOCAL
    global KTUTIL
    global hostname
    global tmppwd
    global spawn_id
    global supported_enctypes
    global KRBIV
    global portbase
    global mode

    setup_kerberos_env kdc

    # 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
    }

    spawn $KADMIN_LOCAL -q "addpol fred"
    catch expect_after
    expect {
	timeout {
	    fail "kadmin.local addpol fred"
	}
	eof {
	    pass "kadmin.local addpol fred"
	}
    }
    set k_stat [wait -i $spawn_id]
    verbose "wait -i $spawn_id returned $k_stat (kadmin addpol)"
    catch "close -i $spawn_id"

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

    # Test dump and load.  Continue on, whatever the result.
    dump_and_reload

    spawn $KADMIN_LOCAL -q "getpols"
    expect {
	fred {
	    pass "kadmin.local getpols"
	    expect eof
	}
	timeout {
	    fail "kadmin.local getpols"
	}
	eof {
	    fail "kadmin.local getpols"
	}
    }
    set k_stat [wait -i $spawn_id]
    verbose "wait -i $spawn_id returned $k_stat (kadmin addpol)"
    catch "close -i $spawn_id"

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

    # Make sure that klist can see the ticket.
    if ![do_klist "krbtest/admin@$REALMNAME" "krbtgt/$REALMNAME@$REALMNAME" "klist"] {
	return
    }

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

    # Double check that the ticket was destroyed.
    if ![do_klist_err "klist after destroy"] { return }

    if ![add_random_key foo/bar 1] {
	return
    }

    set keytab $tmppwd/fookeytab
    catch "exec rm -f $keytab"

    modify_principal foo/bar -kvno 252
    foreach vno {253 254 255 256 257 258} {
	xst $tmppwd/fookeytab foo/bar
	do_klist_kt $tmppwd/fookeytab "klist keytab foo/bar vno $vno"
	kinit_kt "foo/bar" $tmppwd/fookeytab 1 "kt kvno $vno"
	do_klist "foo/bar" "krbtgt/$REALMNAME@$REALMNAME" "klist kt foo/bar vno $vno"
	do_kdestroy "kdestroy foo/bar vno $vno"
	
	if {[info exists KRBIV] && $KRBIV &&
	    [regexp {des-cbc-[a-z0-9-]*:v4} [lindex $supported_enctypes 0]]} {
	    catch "exec rm -f $tmppwd/foosrvtab"
	    spawn $KTUTIL
	    expect_after {
		timeout	{ fail "ktutil converting keytab to srvtab" ; set ok 0 }
		eof	{ fail "ktutil converting keytab to srvtab" ; set ok 0 }
	    }
	    expect "ktutil: "
	    send "rkt $tmppwd/fookeytab\r"
	    expect -ex "rkt $tmppwd/fookeytab\r"
	    expect "ktutil: "
# for debugging, just log this
#	    send "list\r"
#	    expect "ktutil: "
	    #
	    send "wst $tmppwd/foosrvtab\r"
	    expect -ex "wst $tmppwd/foosrvtab\r"
	    expect "ktutil: "
# for debugging, just log this
#	    send "clear\r"
#	    expect "ktutil: "
#	    send "rst $tmppwd/foosrvtab\r"
#	    expect "ktutil: "
#	    send "list\r"
#	    expect "ktutil: "
	    # okay, now quit and finish testing
	    send "quit\r"
	    expect eof
	    catch expect_after
	    if [check_exit_status "ktutil converting keytab to srvtab (vno $vno)"] {
		pass "ktutil converting keytab to srvtab (vno $vno)"
		do_klist_kt $tmppwd/fookeytab "klist srvtab foo/bar vno $vno"
		kinit_kt "foo/bar" "SRVTAB:$tmppwd/foosrvtab" 1 "st kvno $vno"
		do_klist "foo/bar" "krbtgt/$REALMNAME@$REALMNAME" "klist st foo/bar vno $vno"
		do_kdestroy "kdestroy st foo/bar vno $vno"
	    }
	} else {
	    verbose "skipping v5kinit/srvtab tests because of non-v4 enctype"
	}
    }
    catch "exec rm -f $keytab"
    # Check that kadmin.local can actually read the correct kvno, even
    # if we don't expect kadmin to be able to.
    setup_kerberos_env kdc
    spawn $KADMIN_LOCAL -r $REALMNAME
    set ok 1
    expect_after {
	timeout		{ fail "kadmin.local correct high kvno" ; set ok 0 }
	eof		{ fail "kadmin.local correct high kvno" ; set ok 0 }
    }
    expect "kadmin.local: "
    send "getprinc foo/bar\r"
#    exec sleep 10
    expect "Key: vno $vno,"
    send "quit\r"
    expect eof
    if [check_exit_status "kadmin.local examine foo/bar for high kvno"] {
	if $ok {
	    pass "kadmin.local correct high kvno"
	}
    }
}

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
}