From 9f2402b0d86333f5f7e9d50437036cd3124bde47 Mon Sep 17 00:00:00 2001 From: Tar Committer Date: Fri, 4 Jan 2002 21:31:49 +0000 Subject: Imported from rancid-2.2.tar.gz. --- bin/alogin.in | 61 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) mode change 100755 => 100644 bin/alogin.in (limited to 'bin/alogin.in') diff --git a/bin/alogin.in b/bin/alogin.in old mode 100755 new mode 100644 index 8ccf37b..9ffb9e8 --- 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" -- cgit