Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 39 and 401]

ClamAV antivirus integration.

Copyright: 2015 Ruslan Kabalin, Lancaster University.
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 432 lines (18 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: scanner  - X-Ref

Class implementing ClamAV antivirus.

is_configured()   X-Ref
Are the necessary antivirus settings configured?

return: bool True if all necessary config settings been entered

scan_file($file, $filename)   X-Ref
Scan file.

This method is normally called from antivirus manager (\core\antivirus\manager::scan_file).

param: string $file Full path to the file.
param: string $filename Name of the file (could be different from physical file if temp file is used).
return: int Scanning result constant.

scan_data($data)   X-Ref
Scan data.

param: string $data The variable containing the data to scan.
return: int Scanning result constant.

get_unixsocket_destination()   X-Ref
Returns a Unix domain socket destination url

return: string The socket url, fit for stream_socket_client()

get_tcpsocket_destination()   X-Ref
Returns a Internet domain socket destination url

return: string The socket url, fit for stream_socket_client()

get_clam_error_code($returncode)   X-Ref
Returns the string equivalent of a numeric clam error code

param: int $returncode The numeric error code in question.
return: string The definition of the error code

scan_file_execute_commandline($file)   X-Ref
Scan file using command line utility.

param: string $file Full path to the file.
return: int Scanning result constant.

scan_file_execute_socket($file, $type)   X-Ref
Scan file using sockets.

param: string $file Full path to the file.
param: string $type Either 'tcpsocket' or 'unixsocket'
return: int Scanning result constant.

scan_data_execute_socket($data, $type)   X-Ref
Scan data socket.

We are running INSTREAM command and passing data stream in chunks.
The format of the chunk is: <length><data> where <length> is the size of the following
data in bytes expressed as a 4 byte unsigned integer in network byte order and <data>
is the actual chunk. Streaming is terminated by sending a zero-length chunk.
Do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will
reply with INSTREAM size limit exceeded and close the connection.

param: string $data The variable containing the data to scan.
param: string $type Either 'tcpsocket' or 'unixsocket'
return: int Scanning result constant.

parse_socket_response($output)   X-Ref
Parse socket command response.

param: string $output The socket response.
return: int Scanning result constant.

scan_data_execute_unixsocket($data)   X-Ref
Scan data using Unix domain socket.

param: string $data The variable containing the data to scan.
return: int Scanning result constant.

scan_file_execute_unixsocket($file)   X-Ref
Scan file using Unix domain socket.

param: string $file Full path to the file.
return: int Scanning result constant.