summaryrefslogtreecommitdiffstats
path: root/bin/tntlogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/tntlogin.in')
-rw-r--r--bin/tntlogin.in73
1 files changed, 42 insertions, 31 deletions
diff --git a/bin/tntlogin.in b/bin/tntlogin.in
index 021f0d2..57fbfc0 100644
--- a/bin/tntlogin.in
+++ b/bin/tntlogin.in
@@ -1,8 +1,9 @@
#! @EXPECT_PATH@ --
##
-## $Id: tntlogin.in,v 1.11 2004/01/11 05:39:15 heas Exp $
+## $Id: tntlogin.in,v 1.22 2006/12/05 16:50:53 heas Exp $
##
-## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
+## @PACKAGE@ @VERSION@
+## Copyright (C) 1997-2006 by Terrapin Communications, Inc.
## All rights reserved.
##
## This software may be freely copied, modified and redistributed
@@ -39,16 +40,16 @@ set password_file $env(HOME)/.cloginrc
set do_command 0
set do_script 0
# The default is to automatically enable
-set enable 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 +62,12 @@ 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
-}
+}
+if {[ info exists env(CLOGINRC) ]} {
+ set password_file $env(CLOGINRC)
+}
# Sometimes routers take awhile to answer (the default is 10 sec)
set timeout 45
@@ -81,13 +85,16 @@ for {set i 0} {$i < $argc} {incr i} {
set username [ lindex $argv $i ]
}
# VTY Password
- } -v* -
- -v* {
+ } -v* {
if {! [ regexp .\[vV\](.+) $arg ignore passwd]} {
incr i
set passwd [ lindex $argv $i ]
}
set do_passwd 0
+ # Version string
+ } -V* {
+ send_user "@PACKAGE@ @VERSION@\n"
+ exit 0
# Enable Username
} -w* -
-W* {
@@ -260,6 +267,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 +277,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 +287,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 +396,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 +418,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]"
@@ -417,10 +426,12 @@ proc run_commands { prompt command } {
# send "y\r"
exp_continue
}
- "\n" { exp_continue }
- "\[^\n\r *]*Session terminated" { return 0 }
- timeout { return 0 }
- eof { return 0 }
+ "\n" { exp_continue }
+ "\[^\n\r *]*Session terminated" { return 0 }
+ timeout { catch {close}; wait
+ return 0
+ }
+ eof { return 0 }
}
set in_proc 0
}
@@ -496,9 +507,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]} {