| 1 | package File::VirusScan::Engine::Daemon::Symantec::CSS; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::VirusScan::Engine::Daemon; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | @ISA = qw( File::VirusScan::Engine::Daemon ); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Cwd 'abs_path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::VirusScan::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||
| 16 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 8 | my ($class, $conf) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | if(!$conf->{host}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | croak "Must supply a 'host' config value for $class"; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | my $self = { | ||||||||||||||||||||||||||||
| 24 | host => $conf->{host}, | ||||||||||||||||||||||||||||
| 25 | port => $conf->{port} || 7777, | ||||||||||||||||||||||||||||
| 26 | 7 | ▶ | is_local => $conf->{is_local} || 1, | ||||||||||||||||||||||||||
|
Condition50%2/4
$conf->{'port'} || 7777
$conf->{'is_local'} || 1
MC/DC0%0/1
$conf->{'port'} || 7777
$conf->{'port'}
MC/DC0%0/1
$conf->{'is_local'} || 1
$conf->{'is_local'}
Truth table50%1/2
A
A= $conf->{'port'}
Truth table50%1/2
A
A= $conf->{'is_local'}
| |||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 7 | return bless $self, $class; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub _get_socket | ||||||||||||||||||||||||||||
| 33 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_get_socket: called CC=4 SCAR=22.6
| |||||||||||||||||||||||||||||
| 34 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | my $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||
| 37 | PeerAddr => $self->{host}, | ||||||||||||||||||||||||||||
| 38 | PeerPort => $self->{port}, | ||||||||||||||||||||||||||||
| 39 | 5 | ); | |||||||||||||||||||||||||||
| 40 | 5 | ▶ | if(!defined $sock) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 5 | croak "Error: Could not connect to CarrierScan Server on $self->{host}, port $self->{port}: $!"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # First reply line should be 220 code | ||||||||||||||||||||||||||||
| 45 | 0 | my $line = _read_line($sock); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless ($line =~ /^220/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | croak "Error: Unexpected reply $line from CarrierScan Server"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Next line must be version | ||||||||||||||||||||||||||||
| 51 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless ($line eq '2') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | croak "Error: Unexpected version $line from CarrierScan Server"; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # OK, probably fine to use this sock | ||||||||||||||||||||||||||||
| 57 | 0 | return $sock; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub scan | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
scan: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my $abs = abs_path($path); | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($abs && $abs ne $path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$abs and $abs ne $path
MC/DC0%0/2
$abs and $abs ne $path
$abs
$abs ne $path
Truth table0%0/3
A and B
A= $absB= $abs ne $path
| |||||||||||||||||||||||||||||
| 66 | 0 | $path = $abs; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my @files = eval { $self->list_files($path) }; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | return File::VirusScan::Result->error($@); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | foreach my $file_path (@files) { | |||||||||||||||||||||||||||
| 75 | my $result | ||||||||||||||||||||||||||||
| 76 | = $self->{is_local} | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | ? $self->_scan_local($file_path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | : $self->_scan_remote($file_path); | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if(!$result->is_clean()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | return $result; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub _scan_local | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_scan_local: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my $sock = eval { $self->_get_socket }; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | return File::VirusScan::Result->error($@); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if(!$sock->print("Version2\nAVSCANLOCAL\n$path\n")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 96 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 97 | 0 | return File::VirusScan::Result->error("Could not write to socket: $err"); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if(!$sock->flush) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 102 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 103 | 0 | return File::VirusScan::Result->error("Error flushing socket: $err"); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $result = $self->_parse_server_response($sock); | |||||||||||||||||||||||||||
| 107 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 108 | 0 | return $result; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub _scan_remote | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_scan_remote: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $size = (stat($path))[7]; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless (defined($size)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | return File::VirusScan::Result->error("Cannot stat $path: $!"); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my $sock = eval { $self->_get_socket }; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | if($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | return File::VirusScan::Result->error($@); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if(!$sock->print("Version2\nAVSCAN\n$path\n$size\n")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 127 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 128 | 0 | return File::VirusScan::Result->error("Could not write to socket: $err"); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $fh = IO::File->new("<$path"); | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | if(!$fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | return File::VirusScan::Result->error("Cannot open $path: $!"); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # Write file to socket | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | while ($size > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $chunksize | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | = ($size < 8192) | ||||||||||||||||||||||||||||
| 140 | ? $size | ||||||||||||||||||||||||||||
| 141 | : 8192; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | my $chunk; | |||||||||||||||||||||||||||
| 144 | 0 | my $nread = $fh->read($chunk, $chunksize); | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | unless (defined $nread) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 147 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 148 | 0 | return File::VirusScan::Result->error("Error reading $path: $err"); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | last if($nread == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if(!$sock->print($chunk)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 155 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 156 | 0 | return File::VirusScan::Result->error("Error writing to socket: $err"); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $size -= $nread; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if($size > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 164 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 165 | 0 | return File::VirusScan::Result->error("Error reading $path: $err"); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if(!$sock->flush) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | my $err = $!; | |||||||||||||||||||||||||||
| 170 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 171 | 0 | return File::VirusScan::Result->error("Error flushing socket: $err"); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my $result = $self->_parse_server_response($sock); | |||||||||||||||||||||||||||
| 175 | 0 | $sock->close; | |||||||||||||||||||||||||||
| 176 | 0 | return $result; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub _parse_server_response | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_parse_server_response: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 181 | 0 | my ($self, $sock) = @_; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # Get reply from server | ||||||||||||||||||||||||||||
| 184 | 0 | my $line = _read_line($sock); | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | unless ($line =~ /^230/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | return File::VirusScan::Result->error("Unexpected response to AVSCAN or AVSCANLOCAL command: $line"); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # Read infection status | ||||||||||||||||||||||||||||
| 191 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 192 | 0 | ▶ | if($line eq '0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | return File::VirusScan::Result->clean(); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # Skip next four lines: | ||||||||||||||||||||||||||||
| 197 | # - definition date | ||||||||||||||||||||||||||||
| 198 | # - definition version | ||||||||||||||||||||||||||||
| 199 | # - infection count | ||||||||||||||||||||||||||||
| 200 | # - filename | ||||||||||||||||||||||||||||
| 201 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 202 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 203 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 204 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # Get virus name | ||||||||||||||||||||||||||||
| 207 | 0 | $line = _read_line($sock); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | return File::VirusScan::Result->virus($line); | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub _read_line | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_read_line: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 214 | 0 | my ($sock) = @_; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | chomp(my $line = $sock->getline); | |||||||||||||||||||||||||||
| 217 | 0 | $line =~ s/\r//g; | |||||||||||||||||||||||||||
| 218 | 0 | return $line; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 1 | 1; | |||||||||||||||||||||||||||
| 222 | __END__ | ||||||||||||||||||||||||||||