summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-14 00:21:01 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-14 00:21:01 -0500
commit62bdc4af91c073d2804a9db2acb25be4dcd9068d (patch)
treed0b7a53488b38e4d21e12338639974769c18277e
parent4712c215100e2d3113b78ae6dcdd47a759327227 (diff)
downloadapp-termcast-62bdc4af91c073d2804a9db2acb25be4dcd9068d.tar.gz
app-termcast-62bdc4af91c073d2804a9db2acb25be4dcd9068d.zip
make sure the server accepts our password
-rw-r--r--lib/App/Termcast.pm24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/App/Termcast.pm b/lib/App/Termcast.pm
index cdaddf0..629f78b 100644
--- a/lib/App/Termcast.pm
+++ b/lib/App/Termcast.pm
@@ -151,6 +151,30 @@ sub _build_socket {
}
$socket->syswrite($self->establishment_message);
+
+ # ensure the server accepted our connection info
+ # can't use _build_select_args, since that would cause recursion
+ {
+ my ($rin, $ein, $rout, $eout) = ('') x 4;
+ vec($rin, fileno($socket), 1) = 1;
+ vec($ein, fileno($socket), 1) = 1;
+ my $res = select($rout = $rin, undef, $eout = $ein, undef);
+ redo if ($!{EAGAIN} || $!{EINTR}) && $res == -1;
+ if (vec($eout, fileno($socket), 1)) {
+ Carp::croak("Invalid password");
+ }
+ elsif (vec($rout, fileno($socket), 1)) {
+ my $buf;
+ $socket->recv($buf, 4096);
+ if (!defined $buf || length $buf == 0) {
+ Carp::croak("Invalid password");
+ }
+ elsif ($buf ne ('hello, ' . $self->user . "\n")) {
+ Carp::carp("Unknown login response from server: $buf");
+ }
+ }
+ }
+
ReadMode 5 if $self->_raw_mode;
return $socket;
}