|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2014 Victor Dubiniuk <[email protected]> |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. |
|
6
|
|
|
* See the COPYING-README file. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace OCA\Files_Antivirus\Scanner; |
|
11
|
|
|
|
|
12
|
|
|
class External extends \OCA\Files_Antivirus\Scanner { |
|
13
|
|
|
|
|
14
|
|
|
// Daemon/socket mode |
|
15
|
|
|
private $useSocket; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($config){ |
|
18
|
|
|
$this->appConfig = $config; |
|
19
|
|
|
$this->useSocket = $this->appConfig->getAvMode() === 'socket'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
protected function initScanner(){ |
|
23
|
|
|
parent::initScanner(); |
|
24
|
|
|
|
|
25
|
|
|
if ($this->useSocket){ |
|
26
|
|
|
$avSocket = $this->appConfig->getAvSocket(); |
|
27
|
|
|
$this->writeHandle = stream_socket_client('unix://' . $avSocket, $errno, $errstr, 5); |
|
28
|
|
|
if (!$this->getWriteHandle()) { |
|
29
|
|
|
throw new \RuntimeException('Cannot connect to "' . $avSocket . '": ' . $errstr . ' (code ' . $errno . ')'); |
|
30
|
|
|
} |
|
31
|
|
|
} else { |
|
32
|
|
|
$avHost = $this->appConfig->getAvHost(); |
|
33
|
|
|
$avPort = $this->appConfig->getAvPort(); |
|
34
|
|
|
$this->writeHandle = ($avHost && $avPort) ? @fsockopen($avHost, $avPort) : false; |
|
35
|
|
|
if (!$this->getWriteHandle()) { |
|
36
|
|
|
throw new \RuntimeException('The clamav module is not configured for daemon mode.'); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// request scan from the daemon |
|
41
|
|
|
$this->fwrite("nINSTREAM\n"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function shutdownScanner(){ |
|
45
|
|
|
$this->fwrite($this->getWriteHandle(), pack('N', 0)); |
|
|
|
|
|
|
46
|
|
|
$response = fgets($this->getWriteHandle()); |
|
47
|
|
|
\OCP\Util::writeLog('files_antivirus', 'Response :: '.$response, \OCP\Util::DEBUG); |
|
48
|
|
|
@fclose($this->getWriteHandle()); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$this->status->parseResponse($response); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function prepareChunk($data){ |
|
54
|
|
|
$chunk_len = pack('N', strlen($data)); |
|
55
|
|
|
return $chunk_len.$data; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.