summaryrefslogtreecommitdiffstats
path: root/bin/alogin.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/alogin.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/alogin.in')
-rw-r--r--[-rwxr-xr-x]bin/alogin.in61
1 files changed, 31 insertions, 30 deletions
diff --git a/bin/alogin.in b/bin/alogin.in
index 8ccf37b..9ffb9e8 100755..100644
--- a/bin/alogin.in
+++ b/bin/alogin.in
@@ -233,7 +233,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,
@@ -256,22 +255,27 @@ proc source_password_file { password_file } {
}
}
-
# Log into the router.
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
+ 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 compare $prog "telnet"] {
- if [ catch {spawn telnet $router} reason ] {
- send_user "Error: telnet failed: $reason\n"
- exit 1
- }
+ 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
+ }
} elseif ![string compare $prog "ssh"] {
if [ catch {spawn ssh -c $cyphertype -x -l $user $router} reason ] {
send_user "Error: ssh failed: $reason\n"
@@ -327,30 +331,27 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
expect eof
send_user "Error: Unknown host\n"; wait; return 1
}
- -re "$u_prompt" { send "$user\r"
- expect {
- "Login incorrect" { send_user "Error: Couldn't login\n";
- catch {close}; wait; return 1 }
- eof { send_user "Error: Couldn't login\n"; wait; return 1 }
- -re "$p_prompt" { send "$userpswd\r" }
- -re "$prompt" { set in_proc 0; return 0 }
- }
- exp_continue
- }
- -re "$p_prompt" { send "$passwd\r"
- expect {
- "Password incorrect" { send_user "Error: Couldn't login\n";
- catch {close}; wait; return 1 }
- eof { send_user "Error: Couldn't login\n"; wait; return 1 }
- -re "$prompt" { set in_proc 0; return 0 }
- "Confirm seeing above note" { send "y\r" }
- }
- exp_continue
- }
- -re "^Confirm seeing above note" { send "y\r" }
+ -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
+ }
+ -re "^Confirm seeing above note" {
+ send "y\r"
+ exp_continue
+ }
"Password incorrect" { send_user "Error: Check your password for $router\n";
catch {close}; wait; return 1 }
- -re "$prompt" { }
+ -re "$prompt" { break; }
denied { send_user "Error: Check your passwd for $router\n"
if { $do_command || $do_script } {
send "exit\r"