summaryrefslogtreecommitdiffstats
path: root/bin/jlogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/jlogin.in')
-rw-r--r--bin/jlogin.in84
1 files changed, 55 insertions, 29 deletions
diff --git a/bin/jlogin.in b/bin/jlogin.in
index 729afa7..e155d10 100644
--- a/bin/jlogin.in
+++ b/bin/jlogin.in
@@ -1,26 +1,46 @@
#! @EXPECT_PATH@ --
##
-## $Id: jlogin.in,v 1.56 2006/12/05 16:50:52 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.
#
# jlogin - juniper login
#
@@ -29,8 +49,8 @@
#
# Usage line
-set usage "Usage: $argv0 \[-c command\] \[-Evar=x\] \[-f cloginrc-file\] \
-\[-p user-password\] \[-r passphrase\] \[-s script-file\] \
+set usage "Usage: $argv0 \[-dV\] \[-c command\] \[-Evar=x\] \
+\[-f cloginrc-file\] \[-p user-password\] \[-r passphrase\] \[-s script-file\] \
\[-u username\] \[-t timeout\] \[-x command-file\] \[-y ssh_cypher_type\] \
router \[router...\]\n"
@@ -85,6 +105,9 @@ for {set i 0} {$i < $argc} {incr i} {
set command [ lindex $argv $i ]
}
set do_command 1
+ # Expect debug mode
+ } -d* {
+ exp_internal 1
# Environment variable to pass to -s scripts
} -E*
{
@@ -312,7 +335,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
expect_after {
timeout {
send_user "\nError: TIMEOUT reached\n"
- catch {close}; wait
+ catch {close}; catch {wait};
if { $in_proc} {
return 1
} else {
@@ -320,7 +343,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
}
} eof {
send_user "\nError: EOF received\n"
- catch {close}; wait
+ catch {close}; catch {wait};
if { $in_proc} {
return 1
} else {
@@ -337,25 +360,25 @@ proc login { router user passwd cmethod cyphertype identfile} {
# then it will just send the passwd.
expect {
-re "(Connection refused|Secure connection \[^\n\r]+ refused|Connection closed by)" {
- catch {close}; wait
+ catch {close}; catch {wait};
if !$progs {
send_user "\nError: Connection Refused ($prog)\n"; return 1
}
}
eof { send_user "\nError: Couldn't login\n"; wait; return 1
} -nocase "unknown host\r\n" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Unknown host\n"; wait; return 1
} "Host is unreachable" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Host Unreachable!\n"; wait; return 1
} "No address associated with name" {
- catch {close};
+ catch {close}; catch {wait};
send_user "\nError: Unknown host\n"; wait; return 1
}
"Login incorrect" {
send_user "\nError: Check your password for $router\n"
- catch {close}; wait; return 1
+ catch {close}; catch {wait}; return 1
}
-re "Enter passphrase.*: " {
# sleep briefly to allow time for stty -echo
@@ -384,7 +407,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
}
-re "$prompt" { break; }
denied { send_user "\nError: Check your password for $router\n"
- catch {close}; wait; return 1
+ catch {close}; catch {wait}; return 1
}
}
}
@@ -436,7 +459,7 @@ proc run_commands { prompt command } {
send "quit\r"
expect {
"\n" { exp_continue }
- timeout { catch {close}; wait
+ timeout { catch {close}; catch {wait};
return 0
}
eof { return 0 }
@@ -449,6 +472,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]
send_user "$router\n"
@@ -511,11 +535,13 @@ foreach router [lrange $argv $i end] {
# Login to the router
if {[login $router $loginname $passwd $cmethod $cyphertype $identfile]} {
+ incr exitval
continue
}
if { $do_command } {
if {[run_commands $prompt $command]} {
+ incr exitval
continue
}
} elseif { $do_script } {
@@ -524,7 +550,7 @@ foreach router [lrange $argv $i end] {
send "set cli screen-length 0\r"
expect -re $prompt {}
source $sfile
- close
+ catch {close};
} else {
label $router
log_user 1
@@ -532,7 +558,7 @@ foreach router [lrange $argv $i end] {
}
# End of for each router
- wait
+ catch {wait};
sleep 0.3
}
-exit 0
+exit $exitval