line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::VirusScan::Engine::Daemon::Sophos::Sophie; |
2
|
1
|
|
|
1
|
|
110152
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
326
|
use File::VirusScan::Engine::Daemon; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
42
|
use vars qw( @ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
8
|
|
|
|
|
|
|
@ISA = qw( File::VirusScan::Engine::Daemon ); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
338
|
use IO::Socket::UNIX; |
|
1
|
|
|
|
|
10243
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
427
|
use Cwd 'abs_path'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
339
|
use File::VirusScan::Result; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
447
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
8
|
|
|
8
|
1
|
17088
|
my ($class, $conf) = @_; |
18
|
|
|
|
|
|
|
|
19
|
8
|
100
|
|
|
|
22
|
if(!$conf->{socket_name}) { |
20
|
1
|
|
|
|
|
11
|
croak "Must supply a 'socket_name' config value for $class"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
14
|
my $self = { socket_name => $conf->{socket_name}, }; |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
29
|
return bless $self, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _get_socket |
29
|
|
|
|
|
|
|
{ |
30
|
1
|
|
|
1
|
|
1315
|
my ($self) = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
8
|
my $sock = IO::Socket::UNIX->new(Peer => $self->{socket_name}); |
33
|
1
|
50
|
|
|
|
330
|
if(!defined $sock) { |
34
|
1
|
|
|
|
|
17
|
croak "Error: Could not connect to sophie daemon at $self->{socket_name}"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $sock; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub scan |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $abs = abs_path($path); |
45
|
0
|
0
|
0
|
|
|
|
if ($abs && $abs ne $path) { |
46
|
0
|
|
|
|
|
|
$path = $abs; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $sock = eval { $self->_get_socket }; |
|
0
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if($@) { |
51
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error($@); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if(!$sock->print("$path\n")) { |
55
|
0
|
|
|
|
|
|
$sock->close; |
56
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error("Could not get sophie to scan $path"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(!$sock->flush) { |
60
|
0
|
|
|
|
|
|
$sock->close; |
61
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error("Could not get sophie to scan $path"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $scan_response; |
65
|
0
|
|
|
|
|
|
my $rc = $sock->sysread($scan_response, 256); |
66
|
0
|
|
|
|
|
|
$sock->close(); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if(!$rc) { |
69
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error("Did not get response from sophie while scanning $path"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if($scan_response =~ m/^0/) { |
73
|
0
|
|
|
|
|
|
return File::VirusScan::Result->clean(); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if($scan_response =~ m/^1/) { |
77
|
0
|
|
|
|
|
|
my ($virus_name) = $scan_response =~ /^1:(.*)$/; |
78
|
0
|
|
0
|
|
|
|
$virus_name ||= 'Unknown-sophie-virus'; |
79
|
0
|
|
|
|
|
|
return File::VirusScan::Result->virus($virus_name); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if($scan_response =~ m/^-1:(.*)$/) { |
83
|
0
|
|
|
|
|
|
my $error_message = $1; |
84
|
0
|
|
0
|
|
|
|
$error_message ||= 'unknown error'; |
85
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error($error_message); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return File::VirusScan::Result->error('Unknown response from sophie'); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |