clamrb 0.0.2 → 0.0.3

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: ee48d033a2f6004ad93b96da388662eb239d01728751b39fe04350d2a1e564ac
4
- data.tar.gz: cb0bb2b613050912a5742dcf20c3029a181844e69bbb1303828de32865365984
3
+ metadata.gz: 2571458cad6146ed01c79bd0f97752529fbd8f33831248f23f4a98a60f4059ec
4
+ data.tar.gz: c4e2c4d64025d751a79173785647bbf5ecabdb65a31f0896f53f0d6bd5cac4ac
5
5
  SHA512:
6
- metadata.gz: 0bd8f61cd8cca53b0c2fd696db4fb6976d620d8a4a38d72b0d66c282b7d9a2a1ae384313b580da93ac8f54256c6ea7495ddbb7ae329a43458aad8e329ce9f422
7
- data.tar.gz: f65c82ba6877d67747c90dcf0fa903fcd3f5fdb39405f25e8d06d64de17ffeab5f8ae37a10c351e44c16276c6940998228035084c6c870d31e37e635a44e6c05
6
+ metadata.gz: 554560cc7c1dda6a7b68d8639cb89d6dd68ff4b72c050d4bcbd63425b54ed0500ca9f55f414f7b318782d700ef87aed325c7c48ad35ede6f6ae5809a2b10fcff
7
+ data.tar.gz: 181929942e2f0494cb6fcb525e47e1ba234f3012aeb0504cd832330d2df8bc6586a7b12dd0b24db45c3b1d0f5332a0ad3654f62a00c16ef009f5111cea12ed8b
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ before_install:
10
+ - sudo apt-get install gcc make pkg-config clamav libclamav-dev clamav-freshclam
11
+ - sudo freshclam
12
+
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
2
  gemspec
6
3
 
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ clamrb (0.0.3)
5
+ rake-compiler (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ power_assert (1.1.3)
11
+ rake (10.5.0)
12
+ rake-compiler (1.0.5)
13
+ rake
14
+ test-unit (3.2.8)
15
+ power_assert
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.16)
22
+ clamrb!
23
+ rake (~> 10.0)
24
+ test-unit (~> 3.2)
25
+
26
+ BUNDLED WITH
27
+ 1.16.6
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright Aaron Bedra
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # clamrb
1
+ # clamrb [![Build Status](https://secure.travis-ci.org/abedra/clamrb.png)](http://travis-ci.org/abedra/clamrb?branch=master) ![](https://ruby-gem-downloads-badge.herokuapp.com/clamrb) [![Gem Version](https://badge.fury.io/rb/clamrb.svg)](https://badge.fury.io/rb/clamrb)
2
2
 
3
3
  This project is a Ruby gem that interfaces with the Clam AV engine using libclamav.
4
4
 
data/Rakefile CHANGED
@@ -1,28 +1,20 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/extensiontask'
2
3
  require 'rake/testtask'
3
4
  require 'rake/clean'
4
5
  require 'rbconfig'
5
6
  require 'fileutils'
6
7
 
7
- EXT = RbConfig::CONFIG['DLEXT']
8
-
9
- file "lib/clamrb/clamrb.#{EXT}" => Dir.glob('ext/clamrb/*.c') do
10
- Dir.chdir('ext/clamrb') do
11
- ruby "extconf.rb"
12
- sh "make"
13
- end
14
- FileUtils.mkdir_p('lib/clamrb')
15
- cp "ext/clamrb/clamrb.#{EXT}", "lib/clamrb/clamrb.#{EXT}"
8
+ Rake::ExtensionTask.new("clamrb") do |extension|
9
+ extension.lib_dir = 'lib/clamrb'
16
10
  end
17
11
 
18
- task :test => "lib/clamrb/clamrb.#{EXT}"
12
+ task :build => [:clean, :compile]
19
13
 
20
- CLEAN.include("ext/**/*{.o,.log,.#{EXT}")
21
- CLEAN.include('ext/**/Makefile')
22
- CLEAN.include("lib/**/*.#{EXT}")
23
-
24
- Rake::TestTask.new do |t|
25
- t.libs << 'test'
14
+ Rake::TestTask.new(:test => :build) do |t|
15
+ t.test_files = Dir['**/*_test.rb'].reject do |path|
16
+ path.include?('vendor')
17
+ end
26
18
  end
27
19
 
28
20
  task :default => :test
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.extensions = ['ext/clamrb/extconf.rb']
15
15
  s.homepage = 'https://github.com/abedra/clamrb'
16
16
  s.require_paths = ["lib"]
17
- s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
17
+ s.files = %x{git ls-files}.split("\n").reject {|file| file =~ /^(test)/ }
18
+ s.test_files = %x{git ls-files}.split("\n").select {|file| file =~ /^(test)/ }
19
+ s.add_dependency "rake-compiler", "~> 1.0"
20
20
  s.add_development_dependency "bundler", "~> 1.16"
21
21
  s.add_development_dependency "rake", "~> 10.0"
22
+ s.add_development_dependency "test-unit", "~> 3.2"
22
23
  end
@@ -5,18 +5,14 @@ static void clamav_free(void *engine) {
5
5
  cl_engine_free(engine);
6
6
  }
7
7
 
8
- VALUE constructor(VALUE self, VALUE filename)
8
+ VALUE constructor(VALUE self)
9
9
  {
10
- VALUE t_data;
11
- const char *dbDir;
12
- unsigned int signature;
13
-
14
10
  if (cl_init(CL_INIT_DEFAULT) == CL_SUCCESS) {
15
11
  struct cl_engine *engine = cl_engine_new();
16
- t_data = Data_Wrap_Struct(self, 0, clamav_free, engine);
17
- dbDir = cl_retdbdir();
12
+ VALUE t_data = Data_Wrap_Struct(self, 0, clamav_free, engine);
13
+ const char *dbDir = cl_retdbdir();
18
14
  printf("Initializing clamav engine from database located at %s\n", dbDir);
19
- signature = 0;
15
+ unsigned int signature = 0;
20
16
  if (cl_load(dbDir, engine, &signature, CL_DB_STDOPT) == CL_SUCCESS
21
17
  && cl_engine_compile(engine) == CL_SUCCESS) {
22
18
  return t_data;
@@ -33,19 +29,14 @@ VALUE constructor(VALUE self, VALUE filename)
33
29
  VALUE scan(VALUE self, VALUE filename)
34
30
  {
35
31
  struct cl_engine *engine;
36
- const char *name;
37
- long unsigned int scanned;
38
- int ret;
39
- VALUE clamrb;
40
- VALUE clamrb_result;
41
32
 
42
33
  Data_Get_Struct(self, struct cl_engine, engine);
43
- name = NULL;
44
- scanned = 0;
45
- ret = cl_scanfile(StringValueCStr(filename), &name, &scanned, engine, CL_SCAN_STDOPT);
34
+ const char *name = NULL;
35
+ long unsigned int scanned = 0;
36
+ int ret = cl_scanfile(StringValueCStr(filename), &name, &scanned, engine, CL_SCAN_STDOPT);
46
37
 
47
- clamrb = rb_const_get(rb_cObject, rb_intern("Clamrb"));
48
- clamrb_result = rb_const_get(clamrb, rb_intern("Result"));
38
+ VALUE clamrb = rb_const_get(rb_cObject, rb_intern("Clamrb"));
39
+ VALUE clamrb_result = rb_const_get(clamrb, rb_intern("Result"));
49
40
 
50
41
  switch (ret) {
51
42
  case CL_VIRUS:
@@ -55,10 +46,10 @@ VALUE scan(VALUE self, VALUE filename)
55
46
 
56
47
  case CL_CLEAN:
57
48
  return rb_funcall(clamrb_result, rb_intern("new"), 1,
58
- ID2SYM(rb_intern("clean")));
49
+ ID2SYM(rb_intern("clean")));
59
50
  default:
60
51
  return rb_funcall(clamrb_result, rb_intern("new"), 1,
61
- ID2SYM(rb_intern("unknown")));
52
+ ID2SYM(rb_intern("unknown")));
62
53
  }
63
54
  }
64
55
 
@@ -1,3 +1,4 @@
1
1
  require 'mkmf'
2
+ $CFLAGS = "--std=c99 -Wall"
2
3
  have_library("clamav")
3
4
  create_makefile('clamrb/clamrb')
@@ -1,2 +1,3 @@
1
1
  require 'clamrb/clamrb'
2
2
  require 'clamrb/result'
3
+ require 'clamrb/version'
@@ -1,3 +1,3 @@
1
- module Clamrb
2
- VERSION = "0.0.2"
1
+ class Clamrb
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'clamrb'
3
+
4
+ class ClamrbTest < Test::Unit::TestCase
5
+ @@clamrb = Clamrb.new
6
+
7
+ def test_clean_file
8
+ result = @@clamrb.scan "test/files/foo.txt"
9
+ assert_equal(:clean, result.status)
10
+ assert_equal(nil, result.identifier)
11
+ assert_true(result.safe?)
12
+ end
13
+
14
+ def test_unknown_file
15
+ result = @@clamrb.scan "test/files/missing.txt"
16
+ assert_equal(:unknown, result.status)
17
+ assert_equal(nil, result.identifier)
18
+ assert_true(result.error?)
19
+ end
20
+
21
+ def test_infected_file
22
+ result = @@clamrb.scan "test/files/eicar.txt"
23
+ assert_equal(:infected, result.status)
24
+ assert_equal("Eicar-Test-Signature", result.identifier)
25
+ assert_true(result.virus?)
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
@@ -0,0 +1 @@
1
+ Clean file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bedra
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
41
69
  description: Native Ruby extension for running clamav scans
42
70
  email: aaron@aaronbedra.com
43
71
  executables: []
@@ -46,7 +74,10 @@ extensions:
46
74
  extra_rdoc_files: []
47
75
  files:
48
76
  - ".gitignore"
77
+ - ".travis.yml"
49
78
  - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
50
81
  - README.md
51
82
  - Rakefile
52
83
  - clamrb.gemspec
@@ -58,6 +89,9 @@ files:
58
89
  - lib/clamrb.rb
59
90
  - lib/clamrb/result.rb
60
91
  - lib/clamrb/version.rb
92
+ - test/clamrb_test.rb
93
+ - test/files/eicar.txt
94
+ - test/files/foo.txt
61
95
  homepage: https://github.com/abedra/clamrb
62
96
  licenses:
63
97
  - MIT
@@ -82,4 +116,7 @@ rubygems_version: 2.7.8
82
116
  signing_key:
83
117
  specification_version: 4
84
118
  summary: Ruby interface to Clam AV
85
- test_files: []
119
+ test_files:
120
+ - test/clamrb_test.rb
121
+ - test/files/eicar.txt
122
+ - test/files/foo.txt