| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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 . |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package SMB::Proxy; |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5651
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
19
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use parent 'SMB::Server'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
43
|
use SMB::Client; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
23
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
4
|
use IO::Socket; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new ($%) { |
|
28
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
29
|
0
|
|
|
|
|
|
my %options = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
my $quiet = $options{quiet} ||= 0; |
|
32
|
0
|
|
0
|
|
|
|
my $verbose = $options{verbose} ||= 0; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my %client_options = map { $_ => delete $options{$_} } |
|
|
0
|
|
|
|
|
|
|
|
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
|
|
|
0
|
0
|
|
my $self = shift; |
|
51
|
0
|
|
|
|
|
|
my $connection = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my %options = %{$self->{client_options}}; |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
0
|
0
|
|
my $self = shift; |
|
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
|
|
|
0
|
0
|
|
my $self = shift; |
|
80
|
0
|
|
|
|
|
|
my $connection = shift; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
$connection->recv_nbss or return; |
|
83
|
0
|
|
|
|
|
|
$connection->connection2->send_nbss($connection->parser->data); |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return "dummy"; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub on_command ($$$) { |
|
89
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
90
|
0
|
|
|
|
|
|
my $connection = shift; |
|
91
|
0
|
|
|
|
|
|
my $command = shift; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# ignore a dummy command |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |