| 1 | package Net::SSH::Perl::Auth::Rhosts; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Net::SSH::Perl::Constants qw( | ||
| 7 | SSH_SMSG_FAILURE | ||
| 8 | SSH_SMSG_SUCCESS | ||
| 9 | SSH_CMSG_AUTH_RHOSTS ); | ||
| 10 | |||
| 11 | use Net::SSH::Perl::Packet; | ||
| 12 | use Net::SSH::Perl::Auth; | ||
| 13 | use base qw( Net::SSH::Perl::Auth ); | ||
| 14 | |||
| 15 | use Scalar::Util qw(weaken); | ||
| 16 | |||
| 17 | sub new { | ||
| 18 | my $class = shift; | ||
| 19 | my $ssh = shift; | ||
| 20 | my $auth = bless { ssh => $ssh }, $class; | ||
| 21 | weaken $auth->{ssh}; | ||
| 22 | $auth; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub authenticate { | ||
| 26 | my $auth = shift; | ||
| 27 | my($packet); | ||
| 28 | my $ssh = $auth->{ssh}; | ||
| 29 | |||
| 30 | $ssh->debug("Rhosts authentication is disabled by the client."), return | ||
| 31 | unless $ssh->config->get('auth_rhosts'); | ||
| 32 | |||
| 33 | $ssh->debug("Trying rhosts authentication."); | ||
| 34 | |||
| 35 | $packet = $ssh->packet_start(SSH_CMSG_AUTH_RHOSTS); | ||
| 36 | $packet->put_str($ssh->config->get('user')); | ||
| 37 | $packet->send; | ||
| 38 | |||
| 39 | $packet = Net::SSH::Perl::Packet->read($ssh); | ||
| 40 | my $type = $packet->type; | ||
| 41 | if ($type == SSH_SMSG_SUCCESS) { | ||
| 42 | return 1; | ||
| 43 | } | ||
| 44 | elsif ($type != SSH_SMSG_FAILURE) { | ||
| 45 | $ssh->fatal_disconnect("Protocol error: got $type in response to rhosts auth"); | ||
| 46 | } | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 | __END__ |