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 @Override
028 public void scan(File file)
029 throws AntivirusScannerException, SystemException {
030
031 ProcessBuilder processBuilder = new ProcessBuilder(
032 "clamscan", "--stdout", "--no-summary", file.getAbsolutePath());
033
034 processBuilder.redirectErrorStream(true);
035
036 Process process = null;
037
038 try {
039 process = processBuilder.start();
040
041 process.waitFor();
042
043 int exitValue = process.exitValue();
044
045 if (exitValue == 1) {
046 throw new AntivirusScannerException(
047 "Virus detected in " + file.getAbsolutePath());
048 }
049 else if (exitValue >= 2) {
050 throw new AntivirusScannerException(
051 "Unable to scan file due to inability to execute " +
052 "antivirus process");
053 }
054 }
055 catch (IOException ioe) {
056 throw new SystemException("Unable to scan file", ioe);
057 }
058 catch (InterruptedException ie) {
059 throw new SystemException("Unable to scan file", ie);
060 }
061 finally {
062 if (process != null) {
063 process.destroy();
064 }
065 }
066 }
067
068 }