summaryrefslogtreecommitdiffstats
path: root/bin/elogin.in
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2002-01-04 21:31:49 +0000
committerTar Committer <tar@ocjtech.us>2002-01-04 21:31:49 +0000
commit9f2402b0d86333f5f7e9d50437036cd3124bde47 (patch)
tree163861dc0a0052447f838d3674a35870a80026f5 /bin/elogin.in
parentb0d71377c1854271b4511488422427f73d9473d1 (diff)
downloadrancid-9f2402b0d86333f5f7e9d50437036cd3124bde47.tar.gz
rancid-9f2402b0d86333f5f7e9d50437036cd3124bde47.tar.xz
rancid-9f2402b0d86333f5f7e9d50437036cd3124bde47.zip
Imported from rancid-2.2.tar.gz.rancid-2.2
Diffstat (limited to 'bin/elogin.in')
-rwxr-xr-xbin/elogin.in79
1 files changed, 46 insertions, 33 deletions
diff --git a/bin/elogin.in b/bin/elogin.in
index 1affce7..56eab56 100755
--- a/bin/elogin.in
+++ b/bin/elogin.in
@@ -239,7 +239,6 @@ proc find {var router} {
return {}
}
-
# Loads the password file. Note that as this file is tcl, and that
# it is sourced, the user better know what to put in there, as it
# could install more than just password info... I will assume however,
@@ -262,20 +261,33 @@ proc source_password_file { password_file } {
}
}
-
# Log into the router.
-proc login { router user userpswd passwd prompt cyphertype } {
+proc login { router user userpswd passwd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt
set in_proc 1
- set tryssh 1
-
- # Telnet to the router & try to login.
- if [ catch {spawn telnet $router} reason ] {
- send_user "\nError: failed to telnet: $reason\n"
- exit 1
- }
- sleep 0.3
+ set uprompt_seen 0
+
+ # try each of the connection methods in $cmethod until one is successful
+ set progs [llength $cmethod]
+ foreach prog [lrange $cmethod 0 end] {
+ if [string match "telnet*" $prog] {
+ regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
+ if {"$port" == ""} {
+ set retval [ catch {spawn telnet $router} reason ]
+ } else {
+ set retval [ catch {spawn telnet $router $port} reason ]
+ }
+ if { $retval } {
+ send_user "\nError: telnet failed: $reason\n"
+ exit 1
+ }
+ } else {
+ puts "\nError: unknown connection method: $prog"
+ return 1
+ }
+ incr progs -1
+ sleep 0.3
# This helps cleanup each expect clause.
expect_after {
@@ -315,28 +327,24 @@ proc login { router user userpswd passwd prompt cyphertype } {
expect eof
send_user "\nError: Unknown host\n"; wait; return 1
}
- -re "$u_prompt" { send "$user\r"
- expect {
- "Login incorrect" { send_user "\nError: Couldn't login\n";
- catch {close}; wait; return 1 }
- eof { send_user "\nError: Couldn't login\n"; wait; return 1 }
- -re "$p_prompt" { send "$userpswd\r" }
- "$prompt" { set in_proc 0; return 0 }
- }
- exp_continue
- }
- -re "$p_prompt" { send "$passwd\r"
- expect {
- "Password incorrect" { send_user "\nError: Couldn't login\n";
- catch {close}; wait; return 1 }
- eof { send_user "\nError: Couldn't login\n"; wait; return 1 }
- "$prompt" { set in_proc 0; return 0 }
- }
- exp_continue
- }
+ -re "$u_prompt" {
+ send "$user\r"
+ set uprompt_seen 1
+ exp_continue
+ }
+ -re "$p_prompt" {
+ sleep 1
+ if {$uprompt_seen == 1} {
+ send "$userpswd\r"
+ } else {
+ send "$passwd\r"
+ }
+ exp_continue
+ }
"Password incorrect" { send_user "\nError: Check your password for $router\n";
- catch {close}; wait; return 1 }
- "$prompt" { }
+ catch {close}; wait; return 1
+ }
+ "$prompt" { break; }
denied { send_user "\nError: Check your passwd for $router\n"
if { $do_command || $do_script } {
send "exit\r"
@@ -347,6 +355,7 @@ proc login { router user userpswd passwd prompt cyphertype } {
}
}
"\r\n" { exp_continue; }
+ }
}
set in_proc 0
return 0
@@ -449,8 +458,12 @@ foreach router [lrange $argv $i end] {
if { "$cyphertype" == "" } { set cyphertype "3des" }
}
+ # Figure out connection method
+ set cmethod [find method $router]
+ if { "$cmethod" == "" } { set cmethod {{telnet}} }
+
# Login to the router
- if {[login $router $ruser $userpswd $passwd $prompt $cyphertype]} {
+ if {[login $router $ruser $userpswd $passwd $prompt $cmethod $cyphertype]} {
continue
}