1 # Copyright
(C
) 1992-2019, 2020 Free Software Foundation
, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software
; you can redistribute it and
/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # DejaGnu is distributed in the hope that it will be useful
, but
11 # WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu
; if not
, write to the Free Software Foundation
,
17 # Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
, MA
02110-1301, USA.
20 #
Connect to HOSTNAME using Telnet.
ARGS is a list of options.
21 # Currently the only supported option is
"raw". Sets the fileid field
22 # in the config array and returns
-1 for error or the spawn id.
24 proc telnet_open
{ hostname
args } {
38 if {[board_info $hostname
exists name]} {
39 set connhost
[board_info $hostname
name]
41 set connhost $hostname
44 if {[board_info $connhost
exists hostname
]} {
45 set hostname
[board_info $connhost hostname
]
48 if {[file
exists /usr
/kerberos
/bin
/telnet
]} {
49 set telnet
/usr
/kerberos
/bin
/telnet
54 # Instead of unsetting it
, let
's return it. One connection at a
56 if {[board_info $connhost exists fileid]} {
57 return [board_info $connhost fileid]
60 # Get the hostname and port number from the config array.
61 if {[board_info $connhost exists netport]} {
63 set hosttmp [split [board_info $connhost netport] ":"]
64 set hostname [lindex $hosttmp 0]
65 if { [llength $hosttmp] > 1 } {
66 set port [lindex $hosttmp 1]
73 if {[board_info $connhost exists shell_prompt]} {
74 set shell_prompt [board_info $connhost shell_prompt]
76 if {![info exists shell_prompt]} {
77 # If no prompt, then set it to something generic.
78 set shell_prompt ".*> "
84 verbose "Starting a telnet connection to $hostname:$port $shell_prompt" 2
85 while { $result < 0 && $tries <= 3 } {
86 if { $need_respawn } {
88 spawn $telnet $hostname $port
94 -re "$shell_prompt.*$" {
95 verbose "Got prompt\n"
98 -re "nt Name:|ogin:" {
99 if {[board_info $connhost exists telnet_username]} {
100 exp_send "[board_info $connhost telnet_username]\n"
103 if {[board_info $connhost exists username]} {
104 exp_send "[board_info $connhost username]\n"
107 perror "telnet: need to login"
111 if {[board_info $connhost exists telnet_password]} {
112 exp_send "[board_info $connhost telnet_password]\n"
115 if {[board_info $connhost exists password]} {
116 exp_send "[board_info $connhost password]\n"
119 perror "telnet: need a password"
122 -re {advance.*y/n.*\?} {
126 -re {([Aa]dvanced|[Ss]imple) or ([Ss]imple|[Aa]dvanced)} {
135 perror "telnet: unknown host"
143 -re {Escape character is.*\.[\r\n]} {
144 if { $raw || [board_info $connhost exists dont_wait_for_prompt] } {
147 if {[board_info $connhost exists send_initial_cr]} {
153 "has logged on from" {
156 "You have no Kerberos tickets" {
157 warning "telnet: no kerberos Tickets, please kinit"
160 -re "Connection refused.*$" {
161 catch "exp_send \"\003\"" foo
163 warning "telnet: connection refused."
165 -re "Sorry, this system is engaged.*" {
167 warning "telnet: already connected."
169 "Connection closed by foreign host.*$" {
170 warning "telnet: connection closed by foreign host."
180 warning "telnet: got unexpected EOF from telnet."
190 # We look for this here again cause it means something went wrong,
191 # and it doesn't always
show up in the expect in buffer till the
193 if {[info exists expect_out
(buffer
)]} {
194 if {[regexp
"assword:|ogin:" $expect_out(buffer)]} {
195 perror
"telnet: need to supply a login and password."
203 if { $spawn_id
>= 0 } {
204 verbose
"setting board_info($connhost,fileid) to $spawn_id" 3
205 set board_info
($connhost
,fileid
) $spawn_id
211 # Put the Telnet connection to HOSTNAME into binary
mode.
213 proc telnet_binary
{ hostname
} {
214 if {[board_info $hostname
exists fileid
]} {
215 remote_send $hostname
"\x1d"
216 remote_expect $hostname
5 {
220 remote_send $hostname
"set binary\n"
221 remote_expect $hostname
5 {
222 -re
"Format is .*telnet> *$" {
223 remote_send $hostname
"toggle binary\n"
226 -re
"Negotiating network ascii.*telnet> *$" {
227 remote_send $hostname
"toggle binary\n"
230 -re
{Negotiating binary.
*[\r\n].
*$
} { }
231 -re
"binary.*unknown argument.*telnet> *$" {
232 remote_send $hostname
"mode character\n"
234 -re
{Already operating in binary.
*[\r\n].
*$
} { }
236 warning
"Never got binary response from telnet."