summaryrefslogtreecommitdiffstats
path: root/bin/tntlogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/tntlogin.in')
-rw-r--r--bin/tntlogin.in113
1 files changed, 55 insertions, 58 deletions
diff --git a/bin/tntlogin.in b/bin/tntlogin.in
index 8a265b3..02c20a0 100644
--- a/bin/tntlogin.in
+++ b/bin/tntlogin.in
@@ -3,7 +3,7 @@
## $Id$
##
## @PACKAGE@ @VERSION@
-## Copyright (c) 1997-2008 by Terrapin Communications, Inc.
+## Copyright (c) 1997-2009 by Terrapin Communications, Inc.
## All rights reserved.
##
## This code is derived from software contributed to and maintained by
@@ -45,11 +45,10 @@
# Modified by P B Matthews.
# Usage line
-set usage "Usage: $argv0 \[-dV\] \[-c command\] \
-\[-Evar=x\] \[-f cloginrc-file\] \
-\[-s script-file\] \[-t timeout\] \[-u username\] \
-\[-v vty-password\] \[-x command-file\] \
-\[-y ssh_cypher_type\] router \[router...\]\n"
+set usage "Usage: $argv0 \[-dSV\] \[-c command\] \[-Evar=x\] \
+\[-f cloginrc-file\] \[-s script-file\] \[-t timeout\] \[-u username\] \
+\[-v vty-password\] \[-x command-file\] \[-y ssh_cypher_type\] router \
+\[router...\]\n"
# env(CLOGIN) may contain:
# x == do not set xterm banner or name
@@ -67,6 +66,8 @@ 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
+# Save config, if prompted
+set do_saveconfig 0
# Find the user in the ENV, or use the unix userid.
if {[ info exists env(CISCO_USER) ]} {
@@ -101,8 +102,7 @@ for {set i 0} {$i < $argc} {incr i} {
-d* {
exp_internal 1
# Username
- } -u* -
- -U* {
+ } -u* {
if {! [ regexp .\[uU\](.+) $arg ignore user]} {
incr i
set username [ lindex $argv $i ]
@@ -119,12 +119,10 @@ for {set i 0} {$i < $argc} {incr i} {
send_user "@PACKAGE@ @VERSION@\n"
exit 0
# Enable Username
- } -w* -
- -W* {
+ } -w* {
# ignore -w
# Environment variable to pass to -s scripts
- } -E*
- {
+ } -E* {
if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} {
incr i
set E$varname $varvalue
@@ -133,20 +131,17 @@ for {set i 0} {$i < $argc} {incr i} {
exit 1
}
# Enable Password
- } -e*
- {
+ } -e* {
# ignore -e
# Command to run.
- } -c* -
- -C* {
+ } -c* {
if {! [ regexp .\[cC\](.+) $arg ignore command]} {
incr i
set command [ lindex $argv $i ]
}
set do_command 1
# Expect script to run.
- } -s* -
- -S* {
+ } -s* {
if {! [ regexp .\[sS\](.+) $arg ignore sfile]} {
incr i
set sfile [ lindex $argv $i ]
@@ -156,30 +151,29 @@ for {set i 0} {$i < $argc} {incr i} {
exit 1
}
set do_script 1
+ # save config on exit
+ } -S* {
+ set do_saveconfig 1
# 'ssh -c' cypher type
- } -y* -
- -Y* {
+ } -y* {
if {! [ regexp .\[eE\](.+) $arg ignore cypher]} {
incr i
set cypher [ lindex $argv $i ]
}
# alternate cloginrc file
- } -f* -
- -F* {
+ } -f* {
if {! [ regexp .\[fF\](.+) $arg ignore password_file]} {
incr i
set password_file [ lindex $argv $i ]
}
# Timeout
- } -t* -
- -T* {
+ } -t* {
if {! [ regexp .\[tT\](.+) $arg ignore timeout]} {
incr i
- set timeout [ lindex $argv $i ]
+ set timeout [ lindex $argv $i ]
}
# Command file
- } -x* -
- -X {
+ } -x* {
if {! [ regexp .\[xX\](.+) $arg ignore cmd_file]} {
incr i
set cmd_file [ lindex $argv $i ]
@@ -313,10 +307,10 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
return 1
}
} elseif ![string compare $prog "ssh"] {
- if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
- send_user "\nError: $sshcmd failed: $reason\n"
- return 1
- }
+ if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
+ send_user "\nError: $sshcmd failed: $reason\n"
+ return 1
+ }
} elseif ![string compare $prog "rsh"] {
send_error "\nError: unsupported method: rsh\n"
if { $progs == 0 } {
@@ -324,8 +318,8 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
}
continue;
} else {
- send_user "\nError: unknown connection method: $prog\n"
- return 1
+ send_user "\nError: unknown connection method: $prog\n"
+ return 1
}
sleep 0.3
@@ -356,7 +350,8 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
sleep 0.3
expect eof
send_user "\nError: Connection Refused\n"; wait; return 1
- } eof { send_user "\nError: Couldn't login\n"; wait; return 1
+ }
+ eof { send_user "\nError: Couldn't login\n"; wait; return 1
} "Unknown host\r\n" {
expect eof
send_user "\nError: Unknown host\n"; wait; return 1
@@ -370,16 +365,18 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
-re "(Host key not found |The authenticity of host .* be established).*\(yes\/no\)\?" {
send "yes\r"
send_user "\nHost $router added to the list of known hosts.\n"
- exp_continue }
- -re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" {
+ exp_continue
+ }
+ -re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" {
send "no\r"
send_user "\nError: The host key for $router has changed. Update the SSH known_hosts file accordingly.\n"
- return 1 }
- -re "Offending key for .* \(yes\/no\)\?" {
+ return 1
+ }
+ -re "Offending key for .* \(yes\/no\)\?" {
send "no\r"
send_user "\nError: host key mismatch for $router. Update the SSH known_hosts file accordingly.\n"
- return 1 }
-
+ return 1
+ }
-re "$u_prompt" {
send -- "$user\r"
set uprompt_seen 1
@@ -466,30 +463,30 @@ foreach router [lrange $argv $i end] {
# Figure out passwords
if { $do_passwd } {
- set pswd [find password $router]
- if { [llength $pswd] == 0 } {
- send_user "\nError - no password for $router in $password_file.\n"
- continue
- }
- set passwd [join [lindex $pswd 0] ""]
+ set pswd [find password $router]
+ if { [llength $pswd] == 0 } {
+ send_user "\nError - no password for $router in $password_file.\n"
+ continue
+ }
+ set passwd [join [lindex $pswd 0] ""]
}
# Figure out username
if {[info exists username]} {
- # command line username
- set ruser $username
+ # command line username
+ set ruser $username
} else {
- set ruser [join [find user $router] ""]
- if { "$ruser" == "" } { set ruser $default_user }
+ set ruser [join [find user $router] ""]
+ if { "$ruser" == "" } { set ruser $default_user }
}
# Figure out username's password (if different from the vty password)
if {[info exists userpasswd]} {
- # command line username
- set userpswd $userpasswd
+ # command line username
+ set userpswd $userpasswd
} else {
- set userpswd [join [find userpassword $router] ""]
- if { "$userpswd" == "" } { set userpswd $passwd }
+ set userpswd [join [find userpassword $router] ""]
+ if { "$userpswd" == "" } { set userpswd $passwd }
}
# Figure out prompts
@@ -509,11 +506,11 @@ foreach router [lrange $argv $i end] {
# Figure out cypher type
if {[info exists cypher]} {
- # command line cypher type
- set cyphertype $cypher
+ # command line cypher type
+ set cyphertype $cypher
} else {
- set cyphertype [find cyphertype $router]
- if { "$cyphertype" == "" } { set cyphertype "3des" }
+ set cyphertype [find cyphertype $router]
+ if { "$cyphertype" == "" } { set cyphertype "3des" }
}
# Figure out connection method