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::Agent; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
1113
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
19
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
540
|
use parent 'SMB'; |
|
1
|
|
|
|
|
366
|
|
|
1
|
|
|
|
|
7
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
545
|
use SMB::Connection; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
24
|
1
|
|
|
1
|
|
564
|
use SMB::Auth; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
25
|
1
|
|
|
1
|
|
410
|
use IO::Socket; |
|
1
|
|
|
|
|
16590
|
|
|
1
|
|
|
|
|
4
|
|
26
|
1
|
|
|
1
|
|
701
|
use IO::Select; |
|
1
|
|
|
|
|
1454
|
|
|
1
|
|
|
|
|
415
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new ($%) { |
29
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
30
|
0
|
|
|
|
|
|
my %options = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
0
|
|
|
|
$options{quiet} ||= 0; |
33
|
0
|
|
0
|
|
|
|
$options{verbose} ||= 0; |
34
|
0
|
|
0
|
|
|
|
($options{log_level} ||= SMB::LOG_LEVEL_DEBUG) += $options{verbose} - $options{quiet}; |
35
|
0
|
|
0
|
|
|
|
$options{unique_conn_addr} ||= 0; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( |
38
|
|
|
|
|
|
|
%options, |
39
|
|
|
|
|
|
|
socket_pool => IO::Select->new, |
40
|
|
|
|
|
|
|
connections => {}, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_connection_key ($$) { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $socket = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
return $self->unique_conn_addr |
51
|
|
|
|
|
|
|
? SMB::Connection->get_socket_addr($socket) |
52
|
|
|
|
|
|
|
: $socket->fileno; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_connection ($$) { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my $socket = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
my $key = $self->get_connection_key($socket) |
60
|
|
|
|
|
|
|
or return; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->connections->{$key}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub add_connection ($$$%) { |
66
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my $socket = shift; |
68
|
0
|
|
|
|
|
|
my $id = shift; |
69
|
0
|
|
|
|
|
|
my %options = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $key = $self->get_connection_key($socket); |
72
|
0
|
0
|
|
|
|
|
return $self->connections->{$key} if $self->connections->{$key}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
0
|
|
|
|
$options{auth} //= SMB::Auth->new; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
my $connection = SMB::Connection->new( |
77
|
|
|
|
|
|
|
$socket, $id, |
78
|
|
|
|
|
|
|
log_level => $self->log_level, |
79
|
|
|
|
|
|
|
%options, |
80
|
|
|
|
|
|
|
) or return; |
81
|
0
|
|
|
|
|
|
$self->socket_pool->add($socket); |
82
|
0
|
|
|
|
|
|
$self->connections->{$key} = $connection; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
return wantarray ? ($key, $connection) : $connection; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub delete_connection ($$) { |
88
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
89
|
0
|
|
0
|
|
|
|
my $connection = shift || return; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $socket = $connection->socket; |
92
|
0
|
|
|
|
|
|
$self->socket_pool->remove($socket); |
93
|
0
|
|
|
|
|
|
delete $self->connections->{$self->get_connection_key($socket)}; |
94
|
0
|
|
|
|
|
|
$connection->close; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub delete_all_connections ($$) { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
for (values %{$self->connections}) { |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->delete_connection($_); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub DESTROY ($) { |
106
|
0
|
|
|
0
|
|
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->delete_all_connections; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |