clamrb 0.0.2 → 0.0.4

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: edae5b1daaf257d6492cf0618dd3ae8f0720de57167e9eaa4c205ba6d314183e
4
+ data.tar.gz: f04b48f11fdfdaa4ef44d59360a86dff5d7bb1e616e7c7df3d74c18211eaa7de
5
5
  SHA512:
6
- metadata.gz: 0bd8f61cd8cca53b0c2fd696db4fb6976d620d8a4a38d72b0d66c282b7d9a2a1ae384313b580da93ac8f54256c6ea7495ddbb7ae329a43458aad8e329ce9f422
7
- data.tar.gz: f65c82ba6877d67747c90dcf0fa903fcd3f5fdb39405f25e8d06d64de17ffeab5f8ae37a10c351e44c16276c6940998228035084c6c870d31e37e635a44e6c05
6
+ metadata.gz: 93262571c569c10ed803dca31178db1868529396e83ed606a7b577d355609846692d6090a595c7fd48bd32cc5ddd69af0a061707af3aae586fcf3ff1d0b72f5d
7
+ data.tar.gz: aa4fad33101cabc1eff5e036d9e75dfa80c5e9895d64bc5151ed3bf9af02cfde07ac1956d638f6256147cabdb72d0a1cc1056d23508321fa51056f1842484daf
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  *.gem
4
4
  Makefile
5
5
  *.log
6
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ before_install:
11
+ - sudo apt-get install gcc make pkg-config clamav libclamav-dev clamav-freshclam
12
+ - sudo freshclam
13
+
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
 
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
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 (2.0.4)
11
+ rake (13.2.1)
12
+ rake-compiler (1.2.8)
13
+ rake
14
+ test-unit (3.6.2)
15
+ power_assert
16
+
17
+ PLATFORMS
18
+ ruby
19
+ x86_64-linux-gnu
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 2.5)
23
+ clamrb!
24
+ rake (>= 12.3.3)
25
+ test-unit (~> 3.2)
26
+
27
+ BUNDLED WITH
28
+ 2.5.21
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,5 @@
1
- # clamrb
1
+ # clamrb [![Build Status](https://secure.travis-ci.org/abedra/clamrb.png)](http://travis-ci.org/abedra/clamrb?branch=master) ![Gem](https://img.shields.io/gem/dt/clamrb.svg) [![Gem Version](http://img.shields.io/gem/v/clamrb.svg)](https://rubygems.org/gems/clamrb)
2
+
2
3
 
3
4
  This project is a Ruby gem that interfaces with the Clam AV engine using libclamav.
4
5
 
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
data/clamrb.gemspec CHANGED
@@ -5,7 +5,7 @@ require "clamrb/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'clamrb'
7
7
  s.version = Clamrb::VERSION
8
- s.date = '2018-11-23'
8
+ s.date = '2024-10-04'
9
9
  s.licenses = ['MIT']
10
10
  s.summary = 'Ruby interface to Clam AV'
11
11
  s.description = 'Native Ruby extension for running clamav scans'
@@ -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
20
- s.add_development_dependency "bundler", "~> 1.16"
21
- s.add_development_dependency "rake", "~> 10.0"
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
+ s.add_development_dependency "bundler", "~> 2.5"
21
+ s.add_development_dependency "rake", "~> 12.3.3"
22
+ s.add_development_dependency "test-unit", "~> 3.2"
22
23
  end
data/ext/clamrb/clamrb.c CHANGED
@@ -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,18 @@ 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
+ struct cl_scan_options scanoptions;
37
+ memset(&scanoptions, 0, sizeof(struct cl_scan_options));
38
+ scanoptions.parse |= -0;
39
+ scanoptions.general |= CL_SCAN_GENERAL_ALLMATCHES;
40
+ int ret = cl_scanfile(StringValueCStr(filename), &name, &scanned, engine, &scanoptions);
46
41
 
47
- clamrb = rb_const_get(rb_cObject, rb_intern("Clamrb"));
48
- clamrb_result = rb_const_get(clamrb, rb_intern("Result"));
42
+ VALUE clamrb = rb_const_get(rb_cObject, rb_intern("Clamrb"));
43
+ VALUE clamrb_result = rb_const_get(clamrb, rb_intern("Result"));
49
44
 
50
45
  switch (ret) {
51
46
  case CL_VIRUS:
@@ -55,10 +50,10 @@ VALUE scan(VALUE self, VALUE filename)
55
50
 
56
51
  case CL_CLEAN:
57
52
  return rb_funcall(clamrb_result, rb_intern("new"), 1,
58
- ID2SYM(rb_intern("clean")));
53
+ ID2SYM(rb_intern("clean")));
59
54
  default:
60
55
  return rb_funcall(clamrb_result, rb_intern("new"), 1,
61
- ID2SYM(rb_intern("unknown")));
56
+ ID2SYM(rb_intern("unknown")));
62
57
  }
63
58
  }
64
59
 
@@ -67,4 +62,5 @@ void Init_clamrb(void)
67
62
  VALUE klass = rb_define_class("Clamrb", rb_cObject);
68
63
  rb_define_singleton_method(klass, "new", constructor, 0);
69
64
  rb_define_method(klass, "scan", scan, 1);
65
+ rb_undef_alloc_func(klass);
70
66
  }
@@ -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,3 +1,3 @@
1
- module Clamrb
2
- VERSION = "0.0.2"
1
+ class Clamrb
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/clamrb.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'clamrb/clamrb'
2
2
  require 'clamrb/result'
3
+ require 'clamrb/version'
@@ -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-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,43 +1,71 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bedra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2024-10-04 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
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.16'
33
+ version: '2.5'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.16'
40
+ version: '2.5'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.0'
47
+ version: 12.3.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 12.3.3
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'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: '10.0'
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,11 +89,14 @@ 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
64
98
  metadata: {}
65
- post_install_message:
99
+ post_install_message:
66
100
  rdoc_options: []
67
101
  require_paths:
68
102
  - lib
@@ -77,9 +111,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
111
  - !ruby/object:Gem::Version
78
112
  version: '0'
79
113
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.7.8
82
- signing_key:
114
+ rubygems_version: 3.4.20
115
+ signing_key:
83
116
  specification_version: 4
84
117
  summary: Ruby interface to Clam AV
85
- test_files: []
118
+ test_files:
119
+ - test/clamrb_test.rb
120
+ - test/files/eicar.txt
121
+ - test/files/foo.txt