blob: b4046a31051dcdd51f66207f45fd20bff9739658 (
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
# Test for the GSS-API.
# This is a DejaGnu test script.
# This script tests that the GSS-API tester functions correctly.
# This mostly just calls procedures in test/dejagnu/config/default.exp.
if ![info exists KDESTROY] {
set KDESTROY [findfile $objdir/../../clients/kdestroy/kdestroy]
}
if ![info exists GSSCLIENT] {
set GSSCLIENT [findfile $objdir/../../appl/gss-sample/gss-client]
}
if ![info exists GSSSERVER] {
set GSSSERVER [findfile $objdir/../../appl/gss-sample/gss-server]
}
# 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
}
#
# Like kinit in default.exp, but allows us to specify a different ccache.
#
proc our_kinit { name pass ccache } {
global REALMNAME
global KINIT
global spawn_id
# Use kinit to get a ticket.
spawn $KINIT -5 -c $ccache $name@$REALMNAME
expect {
"Password for $name@$REALMNAME:" {
verbose "kinit started"
}
timeout {
fail "kinit"
return 0
}
eof {
fail "kinit"
return 0
}
}
send "$pass\r"
# This last expect seems useless, but without it the test hangs on
# AIX.
expect {
"\r" { }
}
expect eof
if ![check_exit_status kinit] {
return 0
}
return 1
}
#
# Destroys a particular ccache.
#
proc our_kdestroy { ccache } {
global KDESTROY
global spawn_id
spawn $KDESTROY -c $ccache
if ![check_exit_status "kdestroy"] {
return 0
}
return 1
}
#
# Stops the gss-server.
#
proc stop_gss_server { } {
global gss_server_pid
global gss_server_spawn_id
if [info exists gss_server_pid] {
catch "close -i $gss_server_spawn_id"
catch "exec kill $gss_server_pid"
wait -i $gss_server_spawn_id
unset gss_server_pid
}
}
#
# Restore environment variables possibly set.
#
proc gss_restore_env { } {
global env
global gss_save_ccname
global gss_save_ktname
catch "unset env(KRB5CCNAME)"
if [info exists gss_save_ccname] {
set env(KRB5CCNAME) $gss_save_ccname
unset gss_save_ccname
}
catch "unset env(KRB5_KTNAME)"
if [info exists gss_save_ktname] {
set env(KRB5_KTNAME) $gss_save_ktname
unset gss_save_ktname
}
}
proc run_client {test tkfile client} {
global env
global hostname
global GSSCLIENT
global spawn_id
global gss_server_spawn_id
global REALMNAME
set env(KRB5CCNAME) $tkfile
verbose "KRB5CCNAME=$env(KRB5CCNAME)"
verbose "spawning gssclient, identity=$client"
spawn $GSSCLIENT -port 5556 $hostname gssservice@$hostname "message from $client"
set got_client 0
set got_server 0
expect_after {
-i $spawn_id
timeout {
if {!$got_client} {
verbose -log "client timeout"
fail $test
catch "expect_after"
return
}
}
eof {
if {!$got_client} {
verbose -log "client eof"
fail $test
catch "expect_after"
return
}
}
-i $gss_server_spawn_id
timeout {
if {!$got_server} {
verbose -log "server timeout"
fail $test
catch "expect_after"
return
}
}
eof {
if {!$got_server} {
verbose -log "server eof"
fail $test
catch "expect_after"
return
}
}
}
expect {
-i $gss_server_spawn_id
"Accepted connection: \"$client@$REALMNAME\"" exp_continue
"Received message: \"message from $client\"" {
set got_server 1
if {!$got_client} {
exp_continue
}
}
-i $spawn_id
"Signature verified" {
set got_client 1
if {!$got_server} {
exp_continue
}
}
}
catch "expect_after"
if ![check_exit_status $test] {
# check_exit_staus already calls fail for us
return
}
pass $test
}
proc doit { } {
global REALMNAME
global env
global KLIST
global KDESTROY
global KEY
global GSSTEST
global GSSSERVER
global GSSCLIENT
global hostname
global tmppwd
global spawn_id
global timeout
global gss_server_pid
global gss_server_spawn_id
global gss_save_ccname
global gss_save_ktname
# Start up the kerberos and kadmind daemons.
if ![start_kerberos_daemons 0] {
perror "failed to start kerberos daemons"
}
# Use kadmin to add a key for us.
if ![add_kerberos_key gsstest0 0] {
perror "failed to set up gsstest0 key"
}
# Use kadmin to add a key for us.
if ![add_kerberos_key gsstest1 0] {
perror "failed to set up gsstest1 key"
}
# Use kadmin to add a key for us.
if ![add_kerberos_key gsstest2 0] {
perror "failed to set up gsstest2 key"
}
# Use kadmin to add a key for us.
if ![add_kerberos_key gsstest3 0] {
perror "faild to set up gsstest3 key"
}
# Use kadmin to add a service key for us.
if ![add_random_key gssservice/$hostname 0] {
perror "failed to set up gssservice/$hostname key"
}
# Use kdb5_edit to create a srvtab entry for gssservice
if ![setup_srvtab 0 gssservice] {
perror "failed to set up gssservice srvtab"
}
catch "exec rm -f $tmppwd/gss_tk_0 $tmppwd/gss_tk_1 $tmppwd/gss_tk_2 $tmppwd/gss_tk_3"
# Use kinit to get a ticket.
if ![our_kinit gsstest0 gsstest0$KEY $tmppwd/gss_tk_0] {
perror "failed to kinit gsstest0"
}
# Use kinit to get a ticket.
if ![our_kinit gsstest1 gsstest1$KEY $tmppwd/gss_tk_1] {
perror "failed to kinit gsstest1"
}
# Use kinit to get a ticket.
if ![our_kinit gsstest2 gsstest2$KEY $tmppwd/gss_tk_2] {
perror "failed to kinit gsstest2"
}
# Use kinit to get a ticket.
if ![our_kinit gsstest3 gsstest3$KEY $tmppwd/gss_tk_3] {
perror "failed to kinit gsstest3"
}
#
# Save settings of KRB5CCNAME and KRB5_KTNAME
#
if [info exists env(KRB5CCNAME)] {
set gss_save_ccname $env(KRB5CCNAME)
}
if [info exists env(KRB5_KTNAME)] {
set gss_save_ktname $env(KRB5_KTNAME)
}
#
# set KRB5CCNAME and KRB5_KTNAME
#
set env(KRB5_KTNAME) FILE:$tmppwd/srvtab
verbose "KRB5_KTNAME=$env(KRB5_KTNAME)"
# Now start the gss-server.
spawn $GSSSERVER -export -logfile $tmppwd/gss-server.log -verbose -port 5556 gssservice@$hostname
set gss_server_pid [exp_pid]
set gss_server_spawn_id $spawn_id
sleep 2
run_client gssclient0 $tmppwd/gss_tk_0 gssclient0
run_client gssclient1 $tmppwd/gss_tk_1 gssclient1
run_client gssclient2 $tmppwd/gss_tk_2 gssclient2
run_client gssclient3 $tmppwd/gss_tk_3 gssclient3
stop_gss_server
gss_restore_env
if ![our_kdestroy $tmppwd/gss_tk_0] {
perror "failed kdestroy gss_tk_0" 0
}
if ![our_kdestroy $tmppwd/gss_tk_1] {
perror "failed kdestroy gss_tk_1" 0
}
if ![our_kdestroy $tmppwd/gss_tk_2] {
perror "failed kdestroy gss_tk_2" 0
}
if ![our_kdestroy $tmppwd/gss_tk_3] {
perror "failed kdestroy gss_tk_3" 0
}
catch "exec rm -f $tmppwd/gss_tk_0 $tmppwd/gss_tk_1 $tmppwd/gss_tk_2 $tmppwd/gss_tk_3"
return
}
set status [catch doit msg]
stop_gss_server
gss_restore_env
stop_kerberos_daemons
if { $status != 0 } {
perror "error in gssapi.exp" 0
perror $msg 0
}
|