From d5c8176a5d6dae1a6af6450b694aa424cf2e3129 Mon Sep 17 00:00:00 2001 From: Josh Lohrman Date: Wed, 27 Jun 2012 15:00:37 -0300 Subject: [PATCH] Added possibility to handle multiple password fields. EX: Two Factor Authentication. Set the password to "somepassword\nsomeotherpassword" as an example. --- lib/Net/OpenSSH.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Net/OpenSSH.pm b/lib/Net/OpenSSH.pm index 343dc65..7a4f9eb 100644 --- a/lib/Net/OpenSSH.pm +++ b/lib/Net/OpenSSH.pm @@ -855,9 +855,11 @@ sub _wait_for_master { my $fnopty; my $rv = ''; + my @passwdlist; if ($state eq 'waiting_for_password_prompt') { $fnopty = fileno $mpty; - vec($rv, $fnopty, 1) = 1 + vec($rv, $fnopty, 1) = 1; + @passwdlist = split(/\n/, $passwd); } local $self->{_error_prefix} = [@{$self->{_error_prefix}}, @@ -941,8 +943,8 @@ sub _wait_for_master { } if ($$bout =~ s/^(.*:)//s) { $debug and $debug & 4 and _debug "passwd/passphrase requested ($1)"; - print $mpty "$passwd\n"; - $state = 'waiting_for_mux_socket'; + print shift(@passwdlist) . "\n"; + $state = 'waiting_for_mux_socket' if (!@passwdlist); } } else { $$bout = '' }