diff options
author | Tar Committer <tar@ocjtech.us> | 2005-07-07 01:14:43 +0000 |
---|---|---|
committer | Tar Committer <tar@ocjtech.us> | 2005-07-07 01:14:43 +0000 |
commit | 96dc4026054df77affedfe50380a661dcdba732a (patch) | |
tree | 0c8de7e68e7f316bf312cecce0b76e1f76b63020 /bin/tntlogin.in | |
parent | 4d684aecaacc9a59e7e9c0661934aeba0b16efec (diff) | |
download | rancid-96dc4026054df77affedfe50380a661dcdba732a.tar.gz rancid-96dc4026054df77affedfe50380a661dcdba732a.tar.xz rancid-96dc4026054df77affedfe50380a661dcdba732a.zip |
Imported from rancid-2.3.2a2.tar.gz.rancid-2.3.2a2
Diffstat (limited to 'bin/tntlogin.in')
-rw-r--r-- | bin/tntlogin.in | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/bin/tntlogin.in b/bin/tntlogin.in index 2eae6e3..027be07 100644 --- a/bin/tntlogin.in +++ b/bin/tntlogin.in @@ -1,6 +1,6 @@ #! @EXPECT_PATH@ -- ## -## $Id: tntlogin.in,v 1.12 2004/02/02 17:38:36 heas Exp $ +## $Id: tntlogin.in,v 1.17 2005/06/14 20:20:44 heas Exp $ ## ## Copyright (C) 1997-2004 by Terrapin Communications, Inc. ## All rights reserved. @@ -39,16 +39,16 @@ set password_file $env(HOME)/.cloginrc set do_command 0 set do_script 0 # The default is to automatically enable -set avenable 0 +set avenable 0 # The default is that you login non-enabled (tacacs can have you login already # enabled) -set avautoenable 1 +set avautoenable 1 # The default is to look in the password file to find the passwords. This # tracks if we receive them on the command line. 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) @@ -61,9 +61,9 @@ if {[ info exists env(CISCO_USER) ] } { if [ catch {exec id} reason ] { send_error "\nError: could not exec id: $reason\n" exit 1 - } + } regexp {\(([^)]*)} "$reason" junk default_user -} +} # Sometimes routers take awhile to answer (the default is 10 sec) set timeout 45 @@ -260,6 +260,7 @@ proc source_password_file { password_file } { } # Log into the router. +# returns: 0 on success, 1 on failure proc login { router user userpswd passwd prompt cmethod cyphertype } { global spawn_id in_proc do_command do_script global u_prompt p_prompt sshcmd @@ -269,6 +270,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { # 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" == ""} { @@ -278,24 +280,24 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } { } if { $retval } { send_user "\nError: telnet failed: $reason\n" - exit 1 + return 1 } - } elseif ![string compare $prog "ssh"] { + } elseif ![string compare $prog "ssh"] { if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] { send_user "\nError: $sshcmd failed: $reason\n" - exit 1 - } - } elseif ![string compare $prog "rsh"] { - if [ catch {spawn rsh -l $user $router} reason ] { - send_user "\nError: rsh failed: $reason\n" - exit 1 + return 1 } - } else { - puts "\nError: unknown connection method: $prog" + } elseif ![string compare $prog "rsh"] { + send_error "\nError: unsupported method: rsh\n" + if { $progs == 0 } { + return 1 + } + continue; + } else { + send_user "\nError: unknown connection method: $prog\n" return 1 - } - incr progs -1 - sleep 0.3 + } + sleep 0.3 # This helps cleanup each expect clause. expect_after { @@ -387,7 +389,7 @@ proc run_commands { prompt command } { send "lines 0\r" expect -re $prompt {} regsub -all "\[)(]" $prompt {\\&} reprompt - + # Is this a multi-command? if [ string match "*\;*" "$command" ] { set commands [split $command \;] @@ -409,7 +411,7 @@ proc run_commands { prompt command } { -re "\[\n\r]+" { exp_continue } } } - + send "quit\r" # expect { # -re "^WARNING: the current user has insufficient rights to view password fields. A configuration saved under this circumstance should not be used to restore profiles containing passwords. Save anyway? [y/n]" @@ -496,9 +498,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 $ruser $userpswd $passwd $prompt $cmethod $cyphertype]} { |