You are here

function _clamav_scan_via_unix_socket in ClamAV 7

Scan a single file by connecting to ClamAV over a unix socket.

Parameters

String $filepath: Full filepath to the file which is to be scanned. This must be a file which is readable by the web server.

String $filename: Filename of the uploaded file (used for logging).

Return value

int one of:

1 call to _clamav_scan_via_unix_socket()
clamav_scan_file in ./clamav.inc
Scan a single file

File

./clamav.inc, line 115
clamav.inc API and helper functions for the ClamAV module.

Code

function _clamav_scan_via_unix_socket($filepath, $filename) {
  $socket_path = variable_get('clamav_daemon_unix_socket', CLAMAV_DEFAULT_UNIX_SOCKET);
  $socket = "unix://{$socket_path}";

  // try to open a socket to clamav
  $handler = $socket_path ? @fsockopen($socket) : FALSE;
  if (!$handler) {
    watchdog('clamav', 'The clamav module can not connect to the clamav daemon over unix socket.  The uploaded file %filename could not be scanned.', array(
      '%filename' => $filename,
    ), WATCHDOG_WARNING);
    return CLAMAV_SCANRESULT_UNCHECKED;
  }
  return _clamav_scan_via_daemon_handler($handler, $filepath, $filename);
}