File Coverage

lib/SMB/Proxy.pm
Criterion Covered Total %
statement 15 40 37.5
branch 0 2 0.0
condition n/a
subroutine 5 10 50.0
pod 1 5 20.0
total 21 57 36.8


line stmt bran cond sub pod time code
1             # SMB Perl library, Copyright (C) 2014-2018 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 .
15              
16             package SMB::Proxy;
17              
18 1     1   4098 use strict;
  1         3  
  1         37  
19 1     1   9 use warnings;
  1         2  
  1         41  
20              
21 1     1   7 use parent 'SMB::Server';
  1         3  
  1         7  
22              
23 1     1   63 use SMB::Client;
  1         3  
  1         30  
24              
25 1     1   7 use IO::Socket;
  1         3  
  1         8  
26              
27             sub new ($%) {
28 0     0 1   my $class = shift;
29 0           my %options = @_;
30              
31 0           my %client_options = map { $_ => delete $options{$_} }
  0            
32             qw(server_addr server_username server_password);
33              
34 0           my $self = $class->SUPER::new(
35             %options,
36             share_roots => '-',
37             client_options => \%client_options,
38             );
39              
40 0           return $self;
41             }
42              
43             # on connection from client, create connection to server
44             sub on_connect ($$) {
45 0     0 0   my $self = shift;
46 0           my $connection = shift;
47              
48 0           my %options = %{$self->{client_options}};
  0            
49             my $client = SMB::Client->new(
50             $options{server_addr},
51             quiet => $self->quiet,
52             verbose => $self->verbose,
53             username => $options{server_username},
54             password => $options{server_password},
55 0           just_socket => 1,
56             );
57              
58 0           my $connection2 = $self->add_connection($client->socket, -$self->client_id);
59              
60 0           $connection->{connection2} = $connection2;
61 0           $connection2->{connection2} = $connection;
62             }
63              
64             # on disconnection from client or server, disconnect the other end
65             sub on_disconnect ($$) {
66 0     0 0   my $self = shift;
67 0           my $connection = shift;
68              
69 0           $self->delete_connection($connection->connection2);
70             }
71              
72             # just forward packet to the other end, ignore the actual command semantics
73             sub recv_command ($$) {
74 0     0 0   my $self = shift;
75 0           my $connection = shift;
76              
77 0 0         $connection->recv_nbss or return;
78 0           $connection->connection2->send_nbss($connection->parser->data);
79              
80 0           return "dummy";
81             }
82              
83             sub on_command ($$$) {
84 0     0 0   my $self = shift;
85 0           my $connection = shift;
86 0           my $command = shift;
87              
88             # ignore a dummy command
89             }
90              
91             1;