| 1 | # SMB Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org | ||||||||||||
| 2 | # | ||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||
| 12 | # | ||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||
| 15 | |||||||||||||
| 16 | package SMB::Proxy; | ||||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | use parent 'SMB::Server'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 1 | ▶ | use SMB::Client; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 1 | ▶ | use IO::Socket; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | |||||||||||||
| 27 | sub new ($%) { | ||||||||||||
| 28 | 0 | ▶ | my $class = shift; | ||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 29 | 0 | my %options = @_; | |||||||||||
| 30 | |||||||||||||
| 31 | 0 | ▶ | my $quiet = $options{quiet} ||= 0; | ||||||||||
|
Condition0%0/2
$options{"quiet"} ||= 0
MC/DC0%0/1
$options{"quiet"} ||= 0
$options{"quiet"}
Truth table0%0/2
A
A= $options{"quiet"}
| |||||||||||||
| 32 | 0 | ▶ | my $verbose = $options{verbose} ||= 0; | ||||||||||
|
Condition0%0/2
$options{"verbose"} ||= 0
MC/DC0%0/1
$options{"verbose"} ||= 0
$options{"verbose"}
Truth table0%0/2
A
A= $options{"verbose"}
| |||||||||||||
| 33 | |||||||||||||
| 34 | 0 | my %client_options = map { $_ => delete $options{$_} } | |||||||||||
| 35 | qw(server_addr server_username server_password quiet verbose); | ||||||||||||
| 36 | |||||||||||||
| 37 | 0 | my $self = $class->SUPER::new( | |||||||||||
| 38 | %options, | ||||||||||||
| 39 | quiet => $quiet, | ||||||||||||
| 40 | verbose => $verbose, | ||||||||||||
| 41 | share_roots => '-', | ||||||||||||
| 42 | client_options => \%client_options, | ||||||||||||
| 43 | ); | ||||||||||||
| 44 | |||||||||||||
| 45 | 0 | return $self; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | # on connection from client, create connection to server | ||||||||||||
| 49 | sub on_connect ($$) { | ||||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
on_connect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 51 | 0 | my $connection = shift; | |||||||||||
| 52 | |||||||||||||
| 53 | 0 | my %options = %{$self->{client_options}}; | |||||||||||
| 54 | my $client = SMB::Client->new( | ||||||||||||
| 55 | $options{server_addr}, | ||||||||||||
| 56 | quiet => $options{quiet}, | ||||||||||||
| 57 | verbose => $options{verbose}, | ||||||||||||
| 58 | username => $options{server_username}, | ||||||||||||
| 59 | password => $options{server_password}, | ||||||||||||
| 60 | 0 | just_socket => 1, | |||||||||||
| 61 | ); | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | my $connection2 = $self->add_connection($client->socket, -$self->client_id); | |||||||||||
| 64 | |||||||||||||
| 65 | 0 | $connection->{connection2} = $connection2; | |||||||||||
| 66 | 0 | $connection2->{connection2} = $connection; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | # on disconnection from client or server, disconnect the other end | ||||||||||||
| 70 | sub on_disconnect ($$) { | ||||||||||||
| 71 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
on_disconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 72 | 0 | my $connection = shift; | |||||||||||
| 73 | |||||||||||||
| 74 | 0 | $self->delete_connection($connection->connection2); | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | # just forward packet to the other end, ignore the actual command semantics | ||||||||||||
| 78 | sub recv_command ($$) { | ||||||||||||
| 79 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
recv_command: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 80 | 0 | my $connection = shift; | |||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | $connection->recv_nbss or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | $connection->connection2->send_nbss($connection->parser->data); | |||||||||||
| 84 | |||||||||||||
| 85 | 0 | return "dummy"; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | sub on_command ($$$) { | ||||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
on_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 90 | 0 | my $connection = shift; | |||||||||||
| 91 | 0 | my $command = shift; | |||||||||||
| 92 | |||||||||||||
| 93 | # ignore a dummy command | ||||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 1 | 1; | |||||||||||