SUPPORT-9156: remove throw exception
This commit is contained in:
parent
bad10b0324
commit
862cf49511
1 changed files with 20 additions and 10 deletions
|
|
@ -24,6 +24,8 @@ import ru.micord.av.service.exception.AvException;
|
|||
public class FileScanService {
|
||||
private static final String KESL_CONTROL = "kesl-control";
|
||||
private static final String KESL_SCAN = "--scan-file";
|
||||
private static final int CLEAN_CODE = 0;
|
||||
private static final int INFECTED_CODE = 72;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FileScanService.class);
|
||||
@Value("${file.upload.directory:/tmp/uploaded_files}")
|
||||
private String uploadDirectory;
|
||||
|
|
@ -70,32 +72,40 @@ public class FileScanService {
|
|||
String processOutput = processResult.outputUTF8();
|
||||
int exitCode = processResult.getExitValue();
|
||||
|
||||
if (exitCode != 0 && exitCode != 72) {
|
||||
if (exitCode != CLEAN_CODE && exitCode != INFECTED_CODE) {
|
||||
throw new AvException(
|
||||
"KESL error scanning file: " + originalFileName + ", exit code: " + exitCode);
|
||||
}
|
||||
checkScanResult(processOutput, originalFileName);
|
||||
|
||||
if (isPasswordProtectedFile(processOutput)) {
|
||||
LOGGER.warn("File '{}' is identified as password protected. Please review the file.",
|
||||
originalFileName
|
||||
);
|
||||
exitCode = INFECTED_CODE;
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private void checkScanResult(String result, String originalFileName) {
|
||||
private boolean isPasswordProtectedFile(String result) {
|
||||
if (!result.contains(passwordProtectedResultName)) {
|
||||
throw new AvException(String.format(
|
||||
"File scan result doesn't contains \"%s\", "
|
||||
+ "please check property \"password.protected.result.name\" is correct",
|
||||
LOGGER.warn(
|
||||
"File scan result doesn't contains \"{}\"."
|
||||
+ "Please check property \"password.protected.result.name\" is correct",
|
||||
passwordProtectedResultName
|
||||
));
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String line : result.split("\n")) {
|
||||
String[] lineParts = line.split(":");
|
||||
if (lineParts.length > 1) {
|
||||
if (lineParts[0].startsWith(passwordProtectedResultName)
|
||||
&& Integer.parseInt(lineParts[1].trim()) > 0) {
|
||||
throw new AvException("Detected password-protected file: " + originalFileName);
|
||||
if (lineParts[0].startsWith(passwordProtectedResultName)) {
|
||||
int count = Integer.parseInt(lineParts[1].trim());
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue