-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns lrsql.init.clamav | ||
"ClamAV virus scanning" | ||
(:require [clojure.string :as cs] | ||
[clojure.java.io :as io]) | ||
(:import [xyz.capybara.clamav ClamavClient] | ||
[xyz.capybara.clamav.commands.scan.result ScanResult ScanResult$OK])) | ||
|
||
;; questions | ||
;; | ||
;; * What do we want to know about found viruses? Anything? | ||
;; * | ||
|
||
(defn init-file-scanner | ||
"Given ClamAV config, creates a client and returns a function that reads in | ||
the input and scans it with ClamAV. | ||
Compatible with build-routes' :file-scanner argument" | ||
[{:keys [clamav-host | ||
clamav-port] | ||
:or {clamav-host "localhost" | ||
clamav-port 3310}}] | ||
(let [client (new ClamavClient clamav-host clamav-port)] | ||
(fn [input] | ||
(with-open [in (io/input-stream input)] | ||
(let [^ScanResult scan-result (.scan client in)] | ||
(when-not (instance? ScanResult$OK scan-result) | ||
(let [virus-list (-> scan-result | ||
bean ;; FIXME: Normal property access? | ||
:foundViruses | ||
(get "stream") | ||
(->> (into [])))] | ||
{:message (format "Submitted file failed scan. Found: %s" | ||
(cs/join ", " virus-list))}))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters