ddr-antivirus 2.2.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5004e827b8e72a4bad210f59e100daa8bc8ee87c7f02778c1507eac15ea97b8f
4
- data.tar.gz: 302cc664882883e7830664df63f0c21caec065dcf98d116ad8f42c102f659525
3
+ metadata.gz: f9033df3eb197f13dc5cc039718792b0232a7a6c110ee287d5e79e869d20702e
4
+ data.tar.gz: 55364e7e8fe95e952ed40c10e3a2c92d3c105ab01a0d5919856fc6102dbba3d4
5
5
  SHA512:
6
- metadata.gz: 341b67b0bbe4678f02beb2cf5d10bfe7186c3a46aeaa1fa2b1beac6fa8bdcf33a3c0a5010bd9c90121f0b58ac09040c49191e12b88ed709a9042b3b59866b563
7
- data.tar.gz: ce3fc8405d17441a81856fcb80f946e76dffcaae7570edb59c55873f8639da924b8a9d350a53f08cf6c9c72d06049dc458ff2801d2aaf0a99df36efc2f03b40b
6
+ metadata.gz: 4ce9a5e1f5b922ee8306093a028477d12429903340bd4ff21a18dbd2f9d7a54b261e304a9cfa5dab0de4cd5889914ea79237ec82be87f7f897e5b691a647baf3
7
+ data.tar.gz: e9c7ca3a9a483645e4ecc1505bf89a9010642748de8013929c8a355c2ff72c6078f1f82571b05573c088682a1b7b9b8e5543b016613d4dc59ec7c3cd9ea63a42
@@ -2,7 +2,9 @@ ARG RUBY_VERSION
2
2
  FROM ruby:${RUBY_VERSION}
3
3
 
4
4
  ARG APPUSER=appuser
5
- ARG APPGROUP=root
5
+ ARG APPUID=1001
6
+ ARG APPGROUP=$APPUSER
7
+ ARG APPGID=1001
6
8
  ARG APPROOT=/usr/src/app
7
9
 
8
10
  RUN apt-get -y update \
@@ -12,18 +14,18 @@ RUN apt-get -y update \
12
14
  vim \
13
15
  wait-for-it
14
16
 
15
- WORKDIR /usr/src/app
17
+ RUN groupadd -g $APPGID $APPGROUP \
18
+ && useradd -u $APPUID -m -g $APPGID $APPUSER
19
+
20
+ WORKDIR $APPROOT
16
21
  COPY . .
17
- RUN gem install bundler -N \
22
+ RUN gem install bundler \
18
23
  && bundle install
19
24
 
20
25
  COPY .docker/clamd.conf /etc/clamav/
21
26
  COPY .docker/docker-entrypoint.sh /usr/bin/
22
27
  RUN chmod +x /usr/bin/docker-entrypoint.sh
23
28
 
24
- RUN groupadd -r -f $APPGROUP \
25
- && useradd -m -r -g $APPGROUP $APPUSER
26
-
27
- USER $APPUSER
29
+ USER $APPUID
28
30
  ENTRYPOINT ["docker-entrypoint.sh"]
29
31
  CMD ["bundle", "exec", "rake"]
@@ -12,4 +12,4 @@ services:
12
12
  - clamav
13
13
 
14
14
  clamav:
15
- image: gitlab-registry.oit.duke.edu/dul-its/clamav-docker:latest
15
+ image: gitlab-registry.oit.duke.edu/devops/containers/clamav:latest
data/README.md CHANGED
@@ -86,11 +86,3 @@ To easily configure `Ddr::Antivirus` to use the `NullScannerAdapter` and log to
86
86
  ```ruby
87
87
  Ddr::Antivirus.test_mode!
88
88
  ```
89
-
90
- ## Contributing
91
-
92
- 1. Fork it ( https://github.com/[my-github-username]/ddr-antivirus/fork )
93
- 2. Create your feature branch (`git checkout -b my-new-feature`)
94
- 3. Commit your changes (`git commit -am 'Add some feature'`)
95
- 4. Push to the branch (`git push origin my-new-feature`)
96
- 5. Create a new Pull Request
@@ -1,5 +1,4 @@
1
1
  require "fileutils"
2
- require "shellwords"
3
2
 
4
3
  module Ddr::Antivirus
5
4
  #
@@ -7,13 +6,19 @@ module Ddr::Antivirus
7
6
  #
8
7
  class ClamdScannerAdapter < ScannerAdapter
9
8
 
10
- SCANNER = "clamdscan".freeze
11
- CONFIG = "clamconf".freeze
12
-
13
9
  MAX_FILE_SIZE_RE = Regexp.new('^MaxFileSize = "(\d+)"')
10
+ DEFAULT_MAX_FILE_SIZE = 26214400 # 25Mb
11
+
12
+ attr_reader :config
13
+
14
+ def initialize
15
+ @config = `clamconf` rescue nil
16
+ end
14
17
 
15
18
  def scan(path)
19
+ check_file_size(path) # raises Ddr::Antivirus::MaxFileSizeExceeded
16
20
  output, exitcode = clamdscan(path)
21
+ # FIXME I don't like where the scanned_at time is set, but I'm nit-picking --DCS
17
22
  result = ScanResult.new(path, output, version: version, scanned_at: Time.now.utc)
18
23
  case exitcode
19
24
  when 0
@@ -26,61 +31,33 @@ module Ddr::Antivirus
26
31
  end
27
32
 
28
33
  def clamdscan(path)
29
- check_file_size(path) if max_file_size
30
- output = make_readable(path) do
31
- command "--fdpass", safe_path(path)
34
+ output = IO.popen(["clamdscan", "--fdpass", path, err: [:child, :out]]) do |io|
35
+ io.read
32
36
  end
33
37
  [ output, $?.exitstatus ]
34
38
  end
35
39
 
36
40
  def version
37
- @version ||= command("-V").strip
38
- end
39
-
40
- def config
41
- # If client and server are on separate hosts
42
- # attempt to read config may raise an exception.
43
- @config ||= `#{CONFIG}` rescue nil
41
+ @version ||= `clamdscan -V`.strip
44
42
  end
45
43
 
46
44
  def max_file_size
47
- if m = MAX_FILE_SIZE_RE.match(config)
48
- m[1].to_i
49
- end
45
+ @max_file_size ||= if config && (m = MAX_FILE_SIZE_RE.match(config))
46
+ m[1].to_i
47
+ else
48
+ DEFAULT_MAX_FILE_SIZE
49
+ end
50
50
  end
51
51
 
52
52
  private
53
53
 
54
54
  def check_file_size(path)
55
55
  if (file_size = File.size(path)) > max_file_size
56
- raise MaxFileSizeExceeded, "Unable to scan file \"#{path}\" because size (#{file_size})" \
57
- " exceeds clamconf MaxFileSize (#{max_file_size})."
56
+ raise MaxFileSizeExceeded,
57
+ "Unable to scan file at \"#{path}\" -- size (#{file_size}) " \
58
+ "exceeds clamd MaxFileSize setting (#{max_file_size})."
58
59
  end
59
60
  end
60
61
 
61
- def command(*args)
62
- cmd = args.dup.unshift(SCANNER).join(" ")
63
- `#{cmd}`
64
- end
65
-
66
- def make_readable(path)
67
- changed = false
68
- original = File.stat(path).mode # raises Errno::ENOENT
69
- if !File.world_readable?(path)
70
- changed = FileUtils.chmod("a+r", path)
71
- logger.debug "#{self.class} - File \"#{path}\" made world-readable."
72
- end
73
- result = yield
74
- if changed
75
- FileUtils.chmod(original, path)
76
- logger.debug "#{self.class} - Mode on file \"#{path}\" reset to original: #{original}."
77
- end
78
- result
79
- end
80
-
81
- def safe_path(path)
82
- Shellwords.shellescape(path)
83
- end
84
-
85
62
  end
86
63
  end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Antivirus
3
- VERSION = "2.2.0"
3
+ VERSION = "3.0.0.rc1"
4
4
  end
5
5
  end
@@ -22,14 +22,6 @@ EOS
22
22
  describe "#scan" do
23
23
  describe "file size" do
24
24
  let(:path) { File.expand_path(File.join("..", "..", "fixtures", "blue-devil.png"), __FILE__) }
25
- describe "when max file size is not set or unknown" do
26
- before do
27
- allow(subject).to receive(:max_file_size) { nil }
28
- end
29
- it "scans the file" do
30
- expect { subject.scan(path) }.not_to raise_error
31
- end
32
- end
33
25
  describe "when max file size is greater than the size of the file to be scanned" do
34
26
  before do
35
27
  allow(subject).to receive(:max_file_size) { File.size(path) + 1 }
@@ -56,24 +48,6 @@ EOS
56
48
  end
57
49
  end
58
50
 
59
- describe "permissions" do
60
- before do
61
- @file = Tempfile.new("test")
62
- @file.write("Scan me!")
63
- @file.close
64
- FileUtils.chmod(0000, @file.path)
65
- end
66
- after { @file.unlink }
67
- describe "when the file is not readable" do
68
- it "scans the file" do
69
- expect { subject.scan(@file.path) }.not_to raise_error
70
- end
71
- it "resets the original permissions" do
72
- expect { subject.scan(@file.path) }.not_to change { File.stat(@file.path).mode }
73
- end
74
- end
75
- end
76
-
77
51
  describe "result" do
78
52
  let(:path) { File.expand_path(File.join("..", "..", "fixtures", "blue-devil.png"), __FILE__) }
79
53
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-antivirus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,9 +115,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ">="
118
+ - - ">"
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: 1.3.1
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 2.7.9