Class: Ddr::Antivirus::ClamdScannerAdapter
- Inherits:
-
ScannerAdapter
- Object
- ScannerAdapter
- Ddr::Antivirus::ClamdScannerAdapter
- Defined in:
- lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb
Overview
Adapter for clamd client (clamdscan)
Constant Summary collapse
- SCANNER =
"clamdscan".freeze
- CONFIG =
"clamconf".freeze
- MAX_FILE_SIZE_RE =
Regexp.new('^MaxFileSize = "(\d+)"')
Instance Method Summary collapse
- #clamdscan(path) ⇒ Object
- #config ⇒ Object
- #max_file_size ⇒ Object
- #scan(path) ⇒ Object
- #version ⇒ Object
Instance Method Details
#clamdscan(path) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb', line 28 def clamdscan(path) check_file_size(path) if max_file_size output = make_readable(path) do command "--fdpass", safe_path(path) end [ output, $?.exitstatus ] end |
#config ⇒ Object
40 41 42 43 44 |
# File 'lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb', line 40 def config # If client and server are on separate hosts # attempt to read config may raise an exception. @config ||= `#{CONFIG}` rescue nil end |
#max_file_size ⇒ Object
46 47 48 49 50 |
# File 'lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb', line 46 def max_file_size if m = MAX_FILE_SIZE_RE.match(config) m[1].to_i end end |
#scan(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb', line 15 def scan(path) output, exitcode = clamdscan(path) result = ScanResult.new(path, output, version: version, scanned_at: Time.now.utc) case exitcode when 0 result when 1 raise VirusFoundError.new(result) when 2 raise ScannerError.new(result) end end |
#version ⇒ Object
36 37 38 |
# File 'lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb', line 36 def version @version ||= command("-V").strip end |