summaryrefslogtreecommitdiffstats
path: root/bin/clogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/clogin.in')
-rw-r--r--bin/clogin.in115
1 files changed, 70 insertions, 45 deletions
diff --git a/bin/clogin.in b/bin/clogin.in
index 99a0874..4431f63 100644
--- a/bin/clogin.in
+++ b/bin/clogin.in
@@ -1,27 +1,47 @@
#! @EXPECT_PATH@ --
##
-## $Id: clogin.in,v 1.107 2006/12/08 21:28:25 heas Exp $
+## $Id$
##
## @PACKAGE@ @VERSION@
-## Copyright (C) 1997-2006 by Terrapin Communications, Inc.
+## Copyright (c) 1997-2007 by Terrapin Communications, Inc.
## All rights reserved.
##
-## This software may be freely copied, modified and redistributed
-## without fee for non-commerical purposes provided that this license
-## remains intact and unmodified with any RANCID distribution.
+## This code is derived from software contributed to and maintained by
+## Terrapin Communications, Inc. by Henry Kilmer, John Heasley, Andrew Partan,
+## Pete Whiting, Austin Schutz, and Andrew Fort.
##
-## There is no warranty or other guarantee of fitness of this software.
-## It is provided solely "as is". The author(s) disclaim(s) all
-## responsibility and liability with respect to this software's usage
-## or its effect upon hardware, computer systems, other software, or
-## anything else.
+## Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions
+## are met:
+## 1. Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## 2. Redistributions in binary form must reproduce the above copyright
+## notice, this list of conditions and the following disclaimer in the
+## documentation and/or other materials provided with the distribution.
+## 3. All advertising materials mentioning features or use of this software
+## must display the following acknowledgement:
+## This product includes software developed by Terrapin Communications,
+## Inc. and its contributors for RANCID.
+## 4. Neither the name of Terrapin Communications, Inc. nor the names of its
+## contributors may be used to endorse or promote products derived from
+## this software without specific prior written permission.
+## 5. It is requested that non-binding fixes and modifications be contributed
+## back to Terrapin Communications, Inc.
##
-## Except where noted otherwise, rancid was written by and is maintained by
-## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin Schutz.
-##
-#
-# The login expect scripts were based on Erik Sherk's gwtn, by permission.
-#
+## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC. AND CONTRIBUTORS
+## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS
+## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+## POSSIBILITY OF SUCH DAMAGE.
+#
+# The expect login scripts were based on Erik Sherk's gwtn, by permission.
+#
# clogin - Cisco login
#
# Most options are intuitive for logging into a Cisco router.
@@ -33,7 +53,7 @@
#
# Usage line
-set usage "Usage: $argv0 \[-autoenable\] \[-noenable\] \[-c command\] \
+set usage "Usage: $argv0 \[-dV\] \[-autoenable\] \[-noenable\] \[-c command\] \
\[-Evar=x\] \[-e enable-password\] \[-f cloginrc-file\] \[-p user-password\] \
\[-s script-file\] \[-t timeout\] \[-u username\] \
\[-v vty-password\] \[-w enable-username\] \[-x command-file\] \
@@ -88,8 +108,11 @@ for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
switch -glob -- $arg {
+ # Expect debug mode
+ -d* {
+ exp_internal 1
# Username
- -u* -
+ } -u* -
-U* {
if {! [ regexp .\[uU\](.+) $arg ignore user]} {
incr i
@@ -295,7 +318,7 @@ proc source_password_file { password_file } {
# Log into the router.
# returns: 0 on success, 1 on failure, -1 if rsh was used successfully
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
- global spawn_id in_proc do_command do_script platform
+ global command spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
set in_proc 1
set uprompt_seen 0
@@ -305,7 +328,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
foreach prog [lrange $cmethod 0 end] {
incr progs -1
if [string match "telnet*" $prog] {
- regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
+ regexp {telnet(:([^[:space:]]+))*} $prog methcmd suffix port
if {"$port" == ""} {
set retval [ catch {spawn telnet $router} reason ]
} else {
@@ -316,7 +339,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
return 1
}
} elseif [string match "ssh*" $prog] {
- regexp {ssh(:([^[:space:]]+))*} $prog command suffix port
+ regexp {ssh(:([^[:space:]]+))*} $prog methcmd suffix port
if {"$port" == ""} {
set retval [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ]
@@ -328,8 +351,6 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
return 1
}
} elseif ![string compare $prog "rsh"] {
- global command
-
if { ! $do_command } {
if { [llength $cmethod] == 1 } {
send_user "\nError: rsh is an invalid method for -x and "
@@ -356,24 +377,24 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# rcmd does not get a pager and no prompts, so we just have to
# look for failures & lines.
expect {
- "Connection refused" { catch {close}; wait;
+ "Connection refused" { catch {close}; catch {wait};
send_user "\nError: Connection\
Refused ($prog): $router\n"
set rshfail 1
}
-re "(Connection closed by|Connection to \[^\n\r]+ closed)" {
- catch {close}; wait;
+ catch {close}; catch {wait};
send_user "\nError: Connection\
closed ($prog): $router\n"
set rshfail 1
}
- "Host is unreachable" { catch {close}; wait;
+ "Host is unreachable" { catch {close}; catch {wait};
send_user "\nError: Host Unreachable:\
$router\n"
set rshfail 1
}
"No address associated with" {
- catch {close}; wait;
+ catch {close}; catch {wait};
send_user "\nError: Unknown host\
$router\n"
set rshfail 1
@@ -382,11 +403,11 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
-re "\[\n\r]+" { send_user -- "$expect_out(buffer)"
exp_continue
}
- timeout { catch {close}; wait
+ timeout { catch {close}; catch {wait};
send_user "\nError: TIMEOUT reached\n"
set rshfail 1
}
- eof { catch {close}; wait }
+ eof { catch {close}; catch {wait}; }
}
log_user 1
}
@@ -411,7 +432,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
expect_after {
timeout {
send_user "\nError: TIMEOUT reached\n"
- catch {close}; wait
+ catch {close}; catch {wait};
if { $in_proc} {
return 1
} else {
@@ -419,7 +440,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
} eof {
send_user "\nError: EOF received\n"
- catch {close}; wait
+ catch {close}; catch {wait};
if { $in_proc} {
return 1
} else {
@@ -437,14 +458,14 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# if telnet fails with connection refused, try ssh
expect {
-re "(Connection refused|Secure connection \[^\n\r]+ refused)" {
- catch {close}; wait
+ catch {close}; catch {wait};
if !$progs {
send_user "\nError: Connection Refused ($prog): $router\n"
return 1
}
}
-re "(Connection closed by|Connection to \[^\n\r]+ closed)" {
- catch {close}; wait
+ catch {close}; catch {wait};
if !$progs {
send_user "\nError: Connection closed ($prog): $router\n"
return 1
@@ -452,15 +473,15 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
eof { send_user "\nError: Couldn't login: $router\n"; wait; return 1 }
-nocase "unknown host\r" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Unknown host $router\n"; wait; return 1
}
"Host is unreachable" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Host Unreachable: $router\n"; wait; return 1
}
"No address associated with name" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Unknown host $router\n"; wait; return 1
}
-re "(Host key not found |The authenticity of host .* be established).*\(yes\/no\)\?" {
@@ -477,7 +498,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
return 1 }
-re "(denied|Sorry)" {
send_user "\nError: Check your passwd for $router\n"
- catch {close}; wait; return 1
+ catch {close}; catch {wait}; return 1
}
"Login failed" {
send_user "\nError: Check your passwd for $router\n"
@@ -487,7 +508,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
send_user "\nError: Check your passwd for $router\n"
return 1
}
- "Press any key to continue." {
+ "Press any key to continue" {
# send_user "Pressing the ANY key\n"
send "\r"
exp_continue
@@ -524,7 +545,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
-re "$prompt" { break; }
"Login invalid" {
send_user "\nError: Invalid login: $router\n";
- catch {close}; wait; return 1
+ catch {close}; catch {wait}; return 1
}
}
}
@@ -613,7 +634,7 @@ proc run_commands { prompt command } {
}
-re "^\[^\n\r]*$reprompt." { send_user -- "$expect_out(buffer)"
exp_continue }
- -re "^--More--\r\n" { # specific match c1900 pager
+ -re "^--More--\[\r\n]+" { # specific match c1900 pager
send " "
exp_continue }
-re "\[\n\r]+" { send_user -- "$expect_out(buffer)"
@@ -696,7 +717,7 @@ proc run_commands { prompt command } {
exp_continue
}
-re "\[\n\r]+" { exp_continue }
- timeout { catch {close}; wait
+ timeout { catch {close}; catch {wait};
return 0
}
eof { return 0 }
@@ -709,6 +730,7 @@ proc run_commands { prompt command } {
#
source_password_file $password_file
set in_proc 0
+set exitval 0
foreach router [lrange $argv $i end] {
set router [string tolower $router]
# attempt at platform switching.
@@ -825,13 +847,15 @@ foreach router [lrange $argv $i end] {
# Login to the router
if {[login $router $ruser $userpswd $passwd $enapasswd $cmethod $cyphertype]} {
+ incr exitval
# if login failed or rsh was unsuccessful, move on to the next device
continue
}
if { $enable } {
if {[do_enable $enauser $enapasswd]} {
if { $do_command || $do_script } {
- catch {close}; catch {wait}
+ incr exitval
+ catch {close}; catch {wait};
continue
}
}
@@ -859,6 +883,7 @@ foreach router [lrange $argv $i end] {
if { $do_command } {
if {[run_commands $prompt $command]} {
+ incr exitval
continue
}
} elseif { $do_script } {
@@ -872,7 +897,7 @@ foreach router [lrange $argv $i end] {
}
expect -re $prompt {}
source $sfile
- close
+ catch {close};
} else {
label $router
log_user 1
@@ -880,7 +905,7 @@ foreach router [lrange $argv $i end] {
}
# End of for each router
- wait
+ catch {wait};
sleep 0.3
}
-exit 0
+exit $exitval