function clamav_file_validate in ClamAV 7
Same name and namespace in other branches
- 8 clamav.module \clamav_file_validate()
- 2.x clamav.module \clamav_file_validate()
Implements hook_file_validate().
File
- ./
clamav.module, line 84 - Integrate ClamAV to allow uploaded files to be scanned for viruses.
Code
function clamav_file_validate($file) {
$errors = array();
// If ClamAV scanning has been disabled on the config page, abort early.
if (!variable_get('clamav_enabled', TRUE)) {
return $errors;
}
// Check whether files of this scheme should be scanned.
$scheme = clamav_get_file_scheme($file);
if (!empty($scheme) && !clamav_scheme_is_scannable($scheme)) {
return $errors;
}
// If any module that implements hook_clamav_file_is_scannable() returns
// FALSE then we don't scan this file and finish with no errors.
$modules = module_implements('clamav_file_is_scannable');
foreach ($modules as $module) {
if (module_invoke($module, 'clamav_file_is_scannable', $file) === FALSE) {
return $errors;
}
}
// Don't try to scan non-existent files.
if (!file_exists($file->uri)) {
if (variable_get('clamav_verbose', CLAMAV_VERBOSE_DEFAULT)) {
watchdog('clamav', 'Non-existent file sent for scanning: %filename (%fileuri)', array(
'%filename' => $file->filename,
'%fileuri' => $file->uri,
), WATCHDOG_DEBUG);
}
return $errors;
}
require_once dirname(__FILE__) . '/clamav.inc';
$result = clamav_scan_file($file->uri, $file->filename);
if ($result == CLAMAV_SCANRESULT_INFECTED) {
$errors[] = t('A virus has been detected in the file. The file will not be accepted.');
}
elseif ($result == CLAMAV_SCANRESULT_UNCHECKED && variable_get('clamav_unchecked_files', CLAMAV_DEFAULT_UNCHECKED) == CLAMAV_BLOCK_UNCHECKED) {
$errors[] = t('The anti-virus scanner was not able to check the file. The file cannot be uploaded. Please contact the site administrator if this problem persists.');
}
return $errors;
}