001
014
015 package com.liferay.portlet.documentlibrary.antivirus;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018
019 import java.io.File;
020 import java.io.IOException;
021
022
025 public class ClamAntivirusScannerImpl extends BaseFileAntivirusScanner {
026
027 public void scan(File file)
028 throws AntivirusScannerException, SystemException {
029
030 ProcessBuilder processBuilder = new ProcessBuilder(
031 "clamscan", "--stdout", "--no-summary", file.getAbsolutePath());
032
033 processBuilder.redirectErrorStream(true);
034
035 Process process = null;
036
037 try {
038 process = processBuilder.start();
039
040 process.waitFor();
041
042 int exitValue = process.exitValue();
043
044 if (exitValue == 1) {
045 throw new AntivirusScannerException(
046 "Virus detected in " + file.getAbsolutePath());
047 }
048 else if (exitValue >= 2) {
049 throw new AntivirusScannerException(
050 "Unable to scan file due to inability to execute " +
051 "antivirus process");
052 }
053 }
054 catch (IOException ioe) {
055 throw new SystemException("Unable to scan file", ioe);
056 }
057 catch (InterruptedException ie) {
058 throw new SystemException("Unable to scan file", ie);
059 }
060 finally {
061 if (process != null) {
062 process.destroy();
063 }
064 }
065 }
066
067 }