aboutsummaryrefslogtreecommitdiff
path: root/src/tests/dejagnu/krb-root/rlogin.exp
blob: ac3952005cdcf553109193d2de7aa8b87152c9e3 (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
# Kerberos rlogin test.
# This is a DejaGnu test script.
# This script tests Kerberos rlogin.
# 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 KRLOGIN] {
    set KRLOGIN [findfile $objdir/../../appl/bsd/rlogin]
}

if ![info exists KRLOGIND] {
    set KRLOGIND [findfile $objdir/../../appl/bsd/klogind]
}

if ![info exists LOGINKRB5] {
    set LOGINKRB5 [findfile $objdir/../../appl/bsd/login.krb5]
}

# Start up a root shell.
if ![setup_root_shell rlogin] {
    return
}

# Make sure .k5login is reasonable.
if ![check_k5login rlogin] {
    stop_root_shell
    return
}

# Set up the kerberos database.
if {![get_hostname] \
    || ![setup_kerberos_files] \
    || ![setup_kerberos_env] \
    || ![setup_kerberos_db 0]} {
    stop_root_shell
    return
}

# A procedure to start up the rlogin daemon.

proc start_rlogin_daemon { option } {
    global REALMNAME
    global KRLOGIND
    global LOGINKRB5
    global ROOT_PROMPT
    global tmppwd
    global hostname
    global rlogin_spawn_id
    global krlogind_pid

    # The -p argument tells it to accept a single connection, so we
    # don't need to use inetd.  The 3543 is the port to listen at.
    # Note that tmppwd here is a shell variable, which is set in
    # setup_root_shell, not a TCL variable.  The sh -c is to workaround
    # the broken controlling tty handling in hpux, and shouldn't hurt
    # anything else.
    send -i $rlogin_spawn_id "sh -c \"$KRLOGIND -k -c -D 3543 -S \$tmppwd/srvtab -M $REALMNAME -L $LOGINKRB5 $option\" &\r"
    expect {
	-i $rlogin_spawn_id 
	-re "$ROOT_PROMPT" { }
	timeout {
	    send_error "ERROR: timeout from rlogin $hostname -l root\n"
	    return
	}
	eof {
	    send_error "ERROR: eof from rlogin $hostname -l root\n"
	    return
	}
    }
    send -i $rlogin_spawn_id "echo \$!\r"
    expect {
	-i $rlogin_spawn_id
	-re "\[0-9\]+" {
	    set krlogind_pid $expect_out(0,string)
	    verbose "krlogind process ID is $krlogind_pid"
	}
	timeout {
	    send_error "ERROR: timeout from rlogin $hostname -l root\n"
	    return
	}
	eof {
	    send_error "ERROR: eof from rlogin $hostname -l root\n"
	    return
	}
    }
    expect {
	-i $rlogin_spawn_id
	-re "$ROOT_PROMPT" { }
	timeout {
	    send_error "ERROR: timeout from rlogin $hostname -l root\n"
	    return
	}
	eof {
	    send_error "ERROR: eof from rlogin $hostname -l root\n"
	    return
	}
    }

    # Give the rlogin daemon a few seconds to get set up.
    catch "exec sleep 2"
}

# A procedure to stop the rlogin daemon.

proc stop_rlogin_daemon { } {
    global krlogind_pid

    if [info exists krlogind_pid] {
	catch "exec kill $krlogind_pid"
	unset krlogind_pid
    }
}

# Wrap the tests in a procedure, so that we can kill the daemons if
# we get some sort of error.

proc rlogin_test { } {
    global REALMNAME
    global KRLOGIN
    global BINSH
    global SHELL_PROMPT
    global KEY
    global hostname
    global hostname
    global env

    # 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] \
	|| ![kinit $env(USER) $env(USER)$KEY 0]} {
	return
    }

    # Start up the rlogin daemon.
    start_rlogin_daemon -k

    # Make an rlogin connection.
    spawn $KRLOGIN $hostname -k $REALMNAME -D 3543

    expect_after {
	timeout {
	    fail "$testname (timeout)"
	    catch "expect_after"
	    return
	}
	"onnection closed." {
	    fail "$testname (connection closed)"
	    catch "expect_after"
	    return
	}
	eof {
	    fail "$testname (eof)"
	    catch "expect_after"
	    return
	}
    }

    set testname "rlogin"
    expect {
	-re "$SHELL_PROMPT" {
	    pass $testname
	}
    }

    # Switch to /bin/sh to try to avoid confusion from the shell
    # prompt.
    set testname "shell"
    send "$BINSH\r"
    expect -re "$SHELL_PROMPT"

    set testname "date"
    send "date\r"
    expect "date"
    expect {
	-re "\[A-Za-z0-9 :\]+\[\r\n\]+" {
	    if [check_date $expect_out(0,string)] {
		pass "date"
	    } else {
		fail "date"
	    }
	}
    }
    expect -re "$SHELL_PROMPT"

    set testname "exit"
    send "exit\r"
    expect -re "$SHELL_PROMPT"
    send "exit\r"
    expect {
	"onnection closed." {
	    pass $testname
	}
    }
    # This last expect seems useless, but without it the rlogin process
    # sometimes hangs on HP-UX, in a tcsetattr call with TCSADRAIN.
    expect {
        "\r" { }
    }

    expect_after

    if [check_exit_status "exit status"] {
	pass "exit status"
    }

    # The rlogin daemon should have stopped, but we have no easy way
    # of checking whether it actually did.  Kill it just in case.
    stop_rlogin_daemon

    # Try an encrypted connection.
    start_rlogin_daemon -e
    spawn $KRLOGIN $hostname -x -k $REALMNAME -D 3543

    expect_after {
	timeout {
	    fail "$testname (timeout)"
	    catch "expect_after"
	    return
	}
	"onnection closed" {
	    fail "$testname (connection closed)"
	    catch "expect_after"
	    return
	}
	eof {
	    fail "$testname (eof)"
	    catch "expect_after"
	    return
	}
    }

    set testname "encrypted rlogin"
    expect "using DES encryption for all data transmissions"
    expect {
	-re "$SHELL_PROMPT" {
	    pass $testname
	}
    }

    # Switch to /bin/sh to try to avoid confusion from the shell
    # prompt.
    set testname "shell"
    send "$BINSH\r"
    expect -re "$SHELL_PROMPT"

    # Make sure the encryption is not destroying the text.
    set testname "echo"
    send "echo hello\r"
    expect "echo hello"
    expect "hello"
    expect {
	-re "$SHELL_PROMPT" {
	    pass $testname
	}
    }

    # Send some characters which might cause an interrupt, and then
    # make sure we can still talk to the shell.
    set testname "interrupt characters"
    send "\003\177\034\r"
    expect -re "$SHELL_PROMPT"
    send "echo hello\r"
    expect "echo hello"
    expect "hello"
    expect {
	-re "$SHELL_PROMPT" {
	    pass $testname
	}
    }

    set testname "~."
    send "~."
    expect {
	"Closed connection.\r" {
	    pass $testname
	}
	"onnection closed" {
	    pass $testname
	}
    }

    expect_after

    if [check_exit_status "exit status"] {
	pass "exit status"
    }

    # The rlogin daemon should have stopped, but we have no easy way
    # of checking whether it actually did.  Kill it just in case.
    stop_rlogin_daemon
}

# Run the test.  Logging in sometimes takes a while, so increase the
# timeout.
set oldtimeout $timeout
set timeout 60
set status [catch rlogin_test msg]
set timeout $oldtimeout

# Shut down the kerberos daemons, the rlogin daemon, and the root
# process.
stop_kerberos_daemons

stop_rlogin_daemon

stop_root_shell

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