blob: 5d1d905b1005e8694d437b980a45b198bc465cb3 (
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
|
# Kerberos rsh test.
# This is a DejaGnu test script.
# This script tests Kerberos rsh.
# Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
# Find the programs we need. We use the binaries from the build tree
# if they exist. If they do not, then they must be in PATH. We
# expect $objdir to be .../kerberos/src.
if ![info exists RSH] {
set RSH [findfile $objdir/../../appl/bsd/rsh]
}
if ![info exists KRSHD] {
set KRSHD [findfile $objdir/../../appl/bsd/kshd]
}
if ![info exists KLIST] {
set KLIST [findfile $objdir/../../clients/klist/klist]
}
# Make sure .k5login is reasonable.
if ![check_k5login rsh] {
return
}
# Set up the kerberos database.
if {![get_hostname] \
|| ![setup_kerberos_files] \
|| ![setup_kerberos_db 0]} {
return
}
# A procedure to start up the rsh daemon.
proc start_rsh_daemon { option } {
global REALMNAME
global KRSHD
global tmppwd
global krshd_spawn_id
global krshd_pid
# The -D argument tells it to accept a single connection, so we
# don't need to use inetd. The 3544 is the port to listen at.
spawn $KRSHD -k -c -D 3544 -S $tmppwd/srvtab -M $REALMNAME -A $option
set krshd_spawn_id $spawn_id
set krshd_pid [exp_pid]
# Give the rsh daemon a few seconds to get set up.
catch "exec sleep 2"
}
# A procedure to stop the rsh daemon.
proc stop_rsh_daemon { } {
global krshd_spawn_id
global krshd_pid
if [info exists krshd_pid] {
catch "exec kill $krshd_pid"
catch "expect -i $krshd_spawn_id eof"
catch "close -i $krshd_spawn_id"
catch "wait -i $krshd_spawn_id"
unset krshd_pid
}
}
# Wrap the tests in a procedure, so that we can kill the daemons if
# we get some sort of error.
proc rsh_test { } {
global REALMNAME
global KLIST
global RSH
global KEY
global BINSH
global hostname
global env
global spawn_id
global tmppwd
# Start up the kerberos and kadmind daemons and get a srvtab and a
# ticket file.
if {![start_kerberos_daemons 0] \
|| ![add_kerberos_key host/$hostname 0] \
|| ![setup_srvtab 0] \
|| ![add_kerberos_key $env(USER) 0] \
|| ![setup_kerberos_env client] \
|| ![kinit $env(USER) $env(USER)$KEY 0]} {
return
}
# Start up the rsh daemon.
start_rsh_daemon -k
# Run rsh date.
set testname "date"
spawn $RSH $hostname -k $REALMNAME -D 3544 -A date
expect {
-re "\[A-Za-z0-9\]+ \[A-Za-z0-9\]+ +\[0-9\]+ \[0-9\]+:\[0-9\]+:\[0-9\]+ \[A-Za-z0-9\]+ \[0-9\]+\r\n" {
set result $expect_out(0,string)
}
timeout {
fail "$testname (timeout)"
return
}
eof {
fail "$testname (eof)"
return
}
}
expect eof
if ![check_exit_status $testname] {
return
}
if [check_date $result] {
pass $testname
} else {
fail $testname
}
# The rsh daemon should have stopped, but we have no easy way
# of checking whether it actually did. Kill it just in case.
stop_rsh_daemon
# Check encrypted rsh.
set failed no
start_rsh_daemon -ek
set testname "encrypted rsh"
spawn $RSH $hostname -x -k $REALMNAME -D 3544 -A echo hello
expect {
"hello" { expect eof }
timeout {
fail "$testname (timeout)"
set failed yes
}
eof {
fail "$testname (eof)"
set failed yes
}
}
catch "expect eof"
if { $failed == "no" } {
if ![check_exit_status $testname] {
return
}
pass $testname
} else {
catch "wait -i $spawn_id"
catch "close -i $spawn_id"
stop_rsh_daemon
}
# Check ticket forwarding
set failed no
start_rsh_daemon -k
set testname "rsh forwarding tickets"
# We need a wrapper for klist in order to setup for shared library
# runtime environment
setup_wrapper $tmppwd/klist.wrap $KLIST
spawn $RSH $hostname -f -k $REALMNAME -D 3544 -A $BINSH -c $tmppwd/klist.wrap
expect {
"Ticket cache:*\r" {
expect eof
}
"klist: No credentials cache file found" {
fail "$testname (not forwarded)"
return
}
timeout {
fail "$testname (timeout)"
return
}
eof {
fail "$testname (eof)"
return
}
}
if ![check_exit_status $testname] {
return
}
pass $testname
stop_rsh_daemon
# Check encrypted ticket forwarding
set failed no
start_rsh_daemon -e
set testname "encrypted rsh forwarding tickets"
spawn $RSH $hostname -x -f -k $REALMNAME -D 3544 -A $BINSH -c $tmppwd/klist.wrap
expect {
"Ticket cache:*\r" {
expect eof
}
"klist: No credentials cache file found" {
fail "$testname (not forwarded)"
return
}
timeout {
fail "$testname (timeout)"
return
}
eof {
fail "$testname (eof)"
return
}
}
if ![check_exit_status $testname] {
return
}
pass $testname
stop_rsh_daemon
# Check stderr
start_rsh_daemon -k
set testname "rsh to stderr"
spawn $RSH $hostname -k $REALMNAME -D 3544 -A $BINSH -c "'echo hello 1>&2'"
expect {
"hello" { expect eof }
timeout {
fail "$testname (timeout)"
return
}
eof {
fail "$testname (eof)"
return
}
}
if ![check_exit_status $testname] {
return
}
pass $testname
stop_rsh_daemon
start_rsh_daemon -e
set testname "encrypted rsh to stderr"
spawn $RSH $hostname -x -k $REALMNAME -D 3544 -A $BINSH -c "'echo hello 1>&2'"
expect {
"hello" { expect eof }
timeout {
fail "$testname (timeout)"
return
}
eof {
fail "$testname (eof)"
return
}
}
if ![check_exit_status $testname] {
return
}
pass $testname
# The rsh daemon should have stopped, but we have no easy way
# of checking whether it actually did. Kill it just in case.
stop_rsh_daemon
}
# Run the test.
set status [catch rsh_test msg]
# Shut down the kerberos daemons and the rsh daemon.
stop_kerberos_daemons
stop_rsh_daemon
if { $status != 0 } {
send_error "ERROR: error in rsh.exp\n"
send_error "$msg\n"
exit 1
}
|