summaryrefslogtreecommitdiffstats
path: root/bin/jlogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/jlogin.in')
-rw-r--r--bin/jlogin.in28
1 files changed, 15 insertions, 13 deletions
diff --git a/bin/jlogin.in b/bin/jlogin.in
index afa860e..e6c4a01 100644
--- a/bin/jlogin.in
+++ b/bin/jlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: jlogin.in,v 1.46 2004/03/11 19:36:25 heas Exp $
+## $Id: jlogin.in,v 1.51 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -48,7 +48,7 @@ set avenable 1
set do_passwd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -252,6 +252,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user passwd cmethod cyphertype identfile} {
global spawn_id in_proc do_command do_script passphrase prompt
global sshcmd
@@ -260,6 +261,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -269,7 +271,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "ssh"] {
# ssh to the router & try to login with or without an identfile.
@@ -278,24 +280,24 @@ proc login { router user passwd cmethod cyphertype identfile} {
if {$identfile != ""} {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user -i $identfile $router} reason ] {
send_user "\nError: failed to $sshcmd: $reason\n"
- exit 1
+ return 1
}
} else {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: failed to $sshcmd: $reason\n"
- exit 1
+ return 1
}
}
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -493,9 +495,9 @@ foreach router [lrange $argv $i end] {
set cmethod [find method $router]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $router]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $router]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the router
if {[login $router $loginname $passwd $cmethod $cyphertype $identfile]} {