rodsec 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 3477d1c971df8c9705a43c33d749da2bcf32957b
4
- data.tar.gz: 7a4533d4fbd215efaab0bad3c880c13765dcd77a
3
+ metadata.gz: ac2432e156ba0488621acc680796b095b29593c0
4
+ data.tar.gz: be4ecc12f5e5f56b4831e329da176f53d754c4b2
5
5
  SHA512:
6
- metadata.gz: eaa19ddd357c6b7689c4a73e33fe7293f31f4a054f1459784f14b5dcce1a8ef5fb1f9afdcb5cbab0fdb4868e1f85a08d724a1f52c0dcce133ac414d3c253df83
7
- data.tar.gz: 9fe83d648ab87829346874ac39dd37a2d1b9a795e152e5b35914af6e05e6eb31a49a0a3c223461ed22a38f4b2b3fff9bcc2bb64f93b5289a8447c21447874de7
6
+ metadata.gz: 6cce1ddf8cc5277f245dab788578c6d9f3849f9fe665818bb0f9eda8895ed4d650392fab60434d31a7ed4dd4e7dcb06b946094104ddce0f80b77cf3794937de2
7
+ data.tar.gz: 19c75b3098c58fd0a4fb363be350e84bc12e6bdf362bc72e7372f4844714fa2656f157e7d4786903715adb50ea5c333fd505d120d7c24ac465032c2d5f74d200
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
 
14
14
  # local c extensions
15
15
  lib/rodsec/*.so
16
+ lib/rodsec/modsec_lib.rb
@@ -1,5 +1,81 @@
1
1
  require 'mkmf'
2
- pkg_config 'modsecurity'
2
+
3
+ MODSECURITY_LIB_NAME = 'modsecurity'
4
+ SO_FUNC = 'msc_init'
5
+
6
+ def so_name
7
+ @so_name ||= "lib#{MODSECURITY_LIB_NAME}.#{CONFIG['DLEXT']}"
8
+ end
9
+
10
+ def intervention_header_name
11
+ @intervention_header_name ||= 'modsecurity/intervention.h'
12
+ end
13
+
14
+ # raise an exception if one of the paths doesn't exist
15
+ def confirm_include_lib include_dir, lib_dir
16
+ File.realpath(File.join include_dir, intervention_header_name)
17
+ File.realpath(File.join lib_dir, so_name)
18
+ end
19
+
20
+ def create_modsec_lib_rb so_lib_path, dst_ruby_file: 'modsec_lib.rb'
21
+ puts "runtime loads #{so_lib_path}"
22
+
23
+ # create a direct path to the library, because it's often in a nonstandard location
24
+ ruby_lib_dir = File.join CONFIG['srcdir'], '..', '..', 'lib', 'rodsec'
25
+ File.open File.join(ruby_lib_dir,dst_ruby_file), 'w' do |io|
26
+ io.write <<~EOS
27
+ # Generated by extconf.rb
28
+ module Rodsec
29
+ MODSECURITY_SO_PATH = '#{so_lib_path}'
30
+ end
31
+ EOS
32
+ end
33
+ end
34
+
35
+ def find_header_and_library include_dir, lib_dir
36
+ ok = true
37
+ ok &&= find_header intervention_header_name, include_dir
38
+ ok &&= find_library MODSECURITY_LIB_NAME, SO_FUNC, lib_dir
39
+ ok or abort
40
+ end
41
+
42
+ STANDARD_DIRS = [
43
+ %w[/usr/local/include /usr/local/lib],
44
+ %w[/usr/include /usr/lib],
45
+ ]
46
+
47
+ # get the user config, or failing that the default ModSecurity installation paths
48
+ custom_dirs = dir_config 'modsecurity', '/usr/local/modsecurity'
49
+
50
+ found_dirs = ([custom_dirs] + STANDARD_DIRS).find do |(include_dir, lib_dir)|
51
+ # try to find files from config
52
+ begin
53
+ confirm_include_lib include_dir, lib_dir
54
+ [include_dir, lib_dir]
55
+ rescue
56
+ puts "#{[include_dir, lib_dir]} not found. Continuing..."
57
+ end
58
+ end
59
+
60
+ unless found_dirs
61
+ puts 'Cannot locate libmodsecurity.so'
62
+ abort
63
+ end
64
+
65
+ so_lib_path =
66
+ if found_dirs == custom_dirs
67
+ # we have custom dirs, set a specific path for the dlload in Wrapper
68
+ File.join found_dirs.last, so_name
69
+ else
70
+ # standard dirs, so do not use a specific path in Wrapper
71
+ so_name
72
+ end
73
+
74
+ # create the file so Wrapper knows where to load the .so
75
+ create_modsec_lib_rb so_lib_path
76
+
77
+ # finally, use find_header and find_library to add the paths to the Makefile
78
+ find_header_and_library *found_dirs
3
79
 
4
80
  # don't need piles of debug info. Or maybe we do. Dunno.
5
81
  CONFIG['debugflags'] = ''
@@ -1,3 +1,3 @@
1
1
  module Rodsec
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,13 +1,15 @@
1
1
  require 'fiddle'
2
2
  require 'fiddle/import'
3
3
 
4
+ require_relative 'modsec_lib.rb'
5
+
4
6
  module Rodsec
5
7
  module Wrapper
6
8
  extend Fiddle::Importer
7
9
 
8
10
  dlext = RbConfig::CONFIG['DLEXT']
9
11
  msc_intervention = dlopen File.join __dir__, "msc_intervention.#{dlext}"
10
- dlload msc_intervention, "libmodsecurity.#{dlext}"
12
+ dlload msc_intervention, MODSECURITY_SO_PATH
11
13
 
12
14
  ###########################
13
15
  # from modsecurity/modsecurity.h
data/rodsec.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec(?!/config)|features)/})
26
+ f.match(%r{^(test|spec(?!/config)|features|modsec_lib)/})
27
27
  end
28
28
  spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodsec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Anderson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler