openscap 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +7 -18
- data/Rakefile +4 -2
- data/lib/openscap/all.rb +2 -11
- data/lib/openscap/ds/arf.rb +5 -13
- data/lib/openscap/ds/sds.rb +9 -12
- data/lib/openscap/exceptions.rb +1 -10
- data/lib/openscap/libc.rb +1 -10
- data/lib/openscap/openscap.rb +11 -11
- data/lib/openscap/source.rb +12 -17
- data/lib/openscap/text.rb +35 -15
- data/lib/openscap/version.rb +2 -11
- data/lib/openscap/xccdf/benchmark.rb +65 -22
- data/lib/openscap/xccdf/fix.rb +6 -14
- data/lib/openscap/xccdf/group.rb +33 -10
- data/lib/openscap/xccdf/ident.rb +2 -10
- data/lib/openscap/xccdf/item.rb +36 -71
- data/lib/openscap/xccdf/item_common.rb +40 -0
- data/lib/openscap/xccdf/policy.rb +11 -10
- data/lib/openscap/xccdf/policy_model.rb +16 -16
- data/lib/openscap/xccdf/profile.rb +10 -19
- data/lib/openscap/xccdf/reference.rb +5 -13
- data/lib/openscap/xccdf/rule.rb +12 -25
- data/lib/openscap/xccdf/ruleresult.rb +1 -10
- data/lib/openscap/xccdf/session.rb +20 -30
- data/lib/openscap/xccdf/status.rb +35 -0
- data/lib/openscap/xccdf/tailoring.rb +4 -16
- data/lib/openscap/xccdf/testresult.rb +11 -26
- data/lib/openscap/xccdf/value.rb +1 -10
- data/lib/openscap/xccdf.rb +2 -11
- data/lib/openscap.rb +1 -10
- data/test/common/testcase.rb +2 -11
- data/test/data/sds-complex.xml +1 -1
- data/test/data/xccdf.xml +2 -1
- data/test/ds/arf_test.rb +11 -20
- data/test/ds/sds_test.rb +24 -15
- data/test/integration/arf_waiver_test.rb +6 -15
- data/test/openscap_test.rb +1 -10
- data/test/source_test.rb +14 -23
- data/test/text_test.rb +1 -10
- data/test/xccdf/arf_test.rb +2 -12
- data/test/xccdf/benchmark_test.rb +97 -20
- data/test/xccdf/item_test.rb +82 -0
- data/test/xccdf/policy_test.rb +36 -17
- data/test/xccdf/profile_test.rb +51 -18
- data/test/xccdf/session_ds_test.rb +14 -23
- data/test/xccdf/session_test.rb +3 -12
- data/test/xccdf/tailoring_test.rb +1 -10
- data/test/xccdf/testresult_test.rb +10 -19
- data/test/xccdf/value_test.rb +67 -0
- metadata +16 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 31f300d3cdcf9b72dcc0e552f4ce9c6113d54b1f9b5316441bff1133a09106ed
|
4
|
+
data.tar.gz: fdcb823bf21e22ed25cdd77f0bf534227db14af84f0f7383d7f74c65cf690932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a21ae53d6e42bd055058423e54615780483bec7f8c0514a55dfa953ef6e37d88256c0404135a432e964339a9e26fb0a79ba9963e51ffd0317ba28428d7a70c5a
|
7
|
+
data.tar.gz: 790d230ca7fc2b54f9188f5362851d428152000d84d30f935222a323a8276838b491c640a81708f11b592d0c48dfa759f90718d7b80ae1201c9a4344b37513e4
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
ruby-OpenSCAP <img alt="icon" src="http://isimluk.fedorapeople.org/ruby-OpenSCAP-small.png" width="100">
|
2
2
|
=============
|
3
3
|
|
4
4
|
Description
|
5
5
|
-------------
|
6
|
-
|
6
|
+
An FFI wrapper around the OpenSCAP library.
|
7
7
|
|
8
8
|
Features/problems
|
9
9
|
-------------
|
10
|
-
Current version supports minimal set of functions needed to build own scanner. This
|
10
|
+
Current version supports minimal set of functions needed to build own scanner. This gem
|
11
11
|
is self documented by its test suite.
|
12
12
|
|
13
13
|
Sample Scanner Implementation
|
@@ -23,28 +23,17 @@ Sample Scanner Implementation
|
|
23
23
|
|
24
24
|
Development Requirements
|
25
25
|
-------------
|
26
|
-
On Fedora,
|
26
|
+
On Fedora, commands are
|
27
27
|
|
28
|
-
dnf install
|
29
|
-
|
30
|
-
On RHEL you can install requirements by issuing
|
31
|
-
|
32
|
-
yum install ruby-devel rubygem-rake rubygem-bundler openscap
|
33
|
-
gem install ffi # or install rubygem-ffi RPM package from EPEL
|
28
|
+
dnf install openscap
|
29
|
+
bundle install
|
34
30
|
|
35
31
|
|
36
32
|
Test Requirements
|
37
33
|
-------------
|
38
34
|
On Fedora, more packages are necessary, but rubocop can be of the latest version
|
39
35
|
|
40
|
-
dnf install
|
41
|
-
gem install rubocop
|
42
|
-
|
43
|
-
For tests on RHEL7, you need minitest package and specific older version of rubocop.
|
44
|
-
Newer versions of rubocop requires Ruby >= 2.1.0
|
45
|
-
|
46
|
-
yum install rubygem-minitest bzip2
|
47
|
-
gem install rubocop -v 0.50.0
|
36
|
+
dnf install bzip2
|
48
37
|
|
49
38
|
Tests are then performed using script
|
50
39
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
|
3
|
-
Bundler::GemHelper.install_tasks :
|
5
|
+
Bundler::GemHelper.install_tasks name: 'openscap'
|
4
6
|
|
5
7
|
task :test do
|
6
8
|
$LOAD_PATH.unshift('lib')
|
7
9
|
$LOAD_PATH.unshift('test')
|
8
|
-
Dir.glob('./test/**/*_test.rb') { |f| require f }
|
10
|
+
Dir.glob('./test/**/*_test.rb').each { |f| require f }
|
9
11
|
end
|
data/lib/openscap/all.rb
CHANGED
@@ -1,12 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
|
-
Dir.glob(File.join(File.dirname(__FILE__), '{xccdf,ds,}', '*.rb')
|
3
|
+
# Dir.glob(File.join(File.dirname(__FILE__), '{xccdf,ds,}', '*.rb')).each(&method(:require))
|
data/lib/openscap/ds/arf.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/ds/sds'
|
13
4
|
require 'openscap/source'
|
@@ -57,6 +48,7 @@ module OpenSCAP
|
|
57
48
|
html_p = OpenSCAP.ds_rds_session_get_html_report @session
|
58
49
|
OpenSCAP.raise! if OpenSCAP.error?
|
59
50
|
return nil if html_p.null?
|
51
|
+
|
60
52
|
html = html_p.read_string
|
61
53
|
OpenSCAP::LibC.free html_p
|
62
54
|
html
|
@@ -66,8 +58,8 @@ module OpenSCAP
|
|
66
58
|
|
67
59
|
attach_function :ds_rds_session_new_from_source, [:pointer], :pointer
|
68
60
|
attach_function :ds_rds_session_free, [:pointer], :void
|
69
|
-
attach_function :ds_rds_session_select_report, [
|
70
|
-
attach_function :ds_rds_session_replace_report_with_source, [
|
71
|
-
attach_function :ds_rds_session_select_report_request, [
|
61
|
+
attach_function :ds_rds_session_select_report, %i[pointer string], :pointer
|
62
|
+
attach_function :ds_rds_session_replace_report_with_source, %i[pointer pointer], :int
|
63
|
+
attach_function :ds_rds_session_select_report_request, %i[pointer string], :pointer
|
72
64
|
attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
|
73
65
|
end
|
data/lib/openscap/ds/sds.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/source'
|
13
4
|
|
@@ -24,6 +15,12 @@ module OpenSCAP
|
|
24
15
|
OpenSCAP.ds_sds_session_new_from_source param[:source].raw
|
25
16
|
end
|
26
17
|
OpenSCAP.raise! if @raw.null?
|
18
|
+
|
19
|
+
begin
|
20
|
+
yield self
|
21
|
+
ensure
|
22
|
+
destroy
|
23
|
+
end if block_given?
|
27
24
|
end
|
28
25
|
|
29
26
|
def select_checklist(p = {})
|
@@ -52,6 +49,6 @@ module OpenSCAP
|
|
52
49
|
|
53
50
|
attach_function :ds_sds_session_new_from_source, [:pointer], :pointer
|
54
51
|
attach_function :ds_sds_session_free, [:pointer], :void
|
55
|
-
attach_function :ds_sds_session_select_checklist, [
|
56
|
-
attach_function :ds_sds_session_get_html_guide, [
|
52
|
+
attach_function :ds_sds_session_select_checklist, %i[pointer string string string], :pointer
|
53
|
+
attach_function :ds_sds_session_get_html_guide, %i[pointer string], :string
|
57
54
|
end
|
data/lib/openscap/exceptions.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
module OpenSCAP
|
13
4
|
class OpenSCAPError < StandardError
|
data/lib/openscap/libc.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'ffi'
|
13
4
|
|
data/lib/openscap/openscap.rb
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'ffi'
|
13
4
|
|
14
5
|
module OpenSCAP
|
15
6
|
extend FFI::Library
|
16
|
-
ffi_lib ['libopenscap.so.8', 'openscap']
|
7
|
+
ffi_lib ['libopenscap.so.8', 'libopenscap.so.25', 'openscap']
|
17
8
|
|
18
9
|
def self.error?
|
19
10
|
oscap_err
|
@@ -34,6 +25,15 @@ module OpenSCAP
|
|
34
25
|
raise OpenSCAPError, err
|
35
26
|
end
|
36
27
|
|
28
|
+
def self._iterate(over:, as:, &)
|
29
|
+
has_more_method = "#{as}_iterator_has_more"
|
30
|
+
next_method = "#{as}_iterator_next"
|
31
|
+
free_method = "#{as}_iterator_free"
|
32
|
+
|
33
|
+
yield send(next_method, over) while send(has_more_method, over)
|
34
|
+
send(free_method, over)
|
35
|
+
end
|
36
|
+
|
37
37
|
attach_function :oscap_init, [], :void
|
38
38
|
attach_function :oscap_cleanup, [], :void
|
39
39
|
attach_function :oscap_get_version, [], :string
|
data/lib/openscap/source.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap'
|
13
4
|
|
@@ -29,6 +20,12 @@ module OpenSCAP
|
|
29
20
|
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{param}'"
|
30
21
|
end
|
31
22
|
OpenSCAP.raise! if @raw.null?
|
23
|
+
|
24
|
+
begin
|
25
|
+
yield self
|
26
|
+
ensure
|
27
|
+
destroy
|
28
|
+
end if block_given?
|
32
29
|
end
|
33
30
|
|
34
31
|
def type
|
@@ -37,9 +34,7 @@ module OpenSCAP
|
|
37
34
|
|
38
35
|
def validate!
|
39
36
|
e = FFI::MemoryPointer.new(:char, 4096)
|
40
|
-
unless OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e).zero?
|
41
|
-
OpenSCAP.raise! e.read_string
|
42
|
-
end
|
37
|
+
OpenSCAP.raise!(e.read_string) unless OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e).zero?
|
43
38
|
end
|
44
39
|
|
45
40
|
def save(filepath = nil)
|
@@ -62,13 +57,13 @@ module OpenSCAP
|
|
62
57
|
end
|
63
58
|
|
64
59
|
attach_function :oscap_source_new_from_file, [:string], :pointer
|
65
|
-
attach_function :oscap_source_new_from_memory, [
|
60
|
+
attach_function :oscap_source_new_from_memory, %i[pointer int string], :pointer
|
66
61
|
attach_function :oscap_source_get_scap_type, [:pointer], :int
|
67
62
|
attach_function :oscap_source_free, [:pointer], :void
|
68
|
-
attach_function :oscap_source_save_as, [
|
63
|
+
attach_function :oscap_source_save_as, %i[pointer string], :int
|
69
64
|
|
70
|
-
callback :xml_reporter, [
|
71
|
-
attach_function :oscap_source_validate, [
|
65
|
+
callback :xml_reporter, %i[string int string pointer], :int
|
66
|
+
attach_function :oscap_source_validate, %i[pointer xml_reporter pointer], :int
|
72
67
|
XmlReporterCallback = proc do |filename, line_number, error_message, e|
|
73
68
|
offset = e.get_string(0).length
|
74
69
|
msg = "#{filename}:#{line_number}: #{error_message}"
|
data/lib/openscap/text.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
module OpenSCAP
|
13
4
|
class Text
|
14
5
|
attr_reader :raw
|
15
6
|
|
16
|
-
def initialize
|
17
|
-
@raw =
|
7
|
+
def initialize(t = nil)
|
8
|
+
@raw = case t
|
9
|
+
when FFI::Pointer
|
10
|
+
t
|
11
|
+
when nil
|
12
|
+
OpenSCAP.oscap_text_new
|
13
|
+
end
|
18
14
|
end
|
19
15
|
|
20
16
|
def text=(str)
|
@@ -22,7 +18,7 @@ module OpenSCAP
|
|
22
18
|
end
|
23
19
|
|
24
20
|
def text
|
25
|
-
OpenSCAP.oscap_text_get_text(raw)
|
21
|
+
OpenSCAP.oscap_text_get_text(@raw).force_encoding Encoding::UTF_8
|
26
22
|
end
|
27
23
|
|
28
24
|
def destroy
|
@@ -34,22 +30,46 @@ module OpenSCAP
|
|
34
30
|
class TextList
|
35
31
|
def initialize(oscap_text_iterator)
|
36
32
|
@raw = oscap_text_iterator
|
33
|
+
|
34
|
+
begin
|
35
|
+
yield self
|
36
|
+
ensure
|
37
|
+
destroy
|
38
|
+
end if block_given?
|
37
39
|
end
|
38
40
|
|
39
41
|
def plaintext(lang = nil)
|
40
42
|
OpenSCAP.oscap_textlist_get_preferred_plaintext @raw, lang
|
41
43
|
end
|
42
44
|
|
45
|
+
def markup(lang:)
|
46
|
+
text_pointer = OpenSCAP.oscap_textlist_get_preferred_text @raw, lang
|
47
|
+
return nil if text_pointer.null?
|
48
|
+
|
49
|
+
Text.new(text_pointer).text
|
50
|
+
end
|
51
|
+
|
43
52
|
def destroy
|
44
53
|
OpenSCAP.oscap_text_iterator_free @raw
|
45
54
|
end
|
55
|
+
|
56
|
+
def self.extract(pointer, lang:, markup:)
|
57
|
+
new(pointer) do |list|
|
58
|
+
if markup
|
59
|
+
return list.markup(lang:)
|
60
|
+
else
|
61
|
+
return list.plaintext(lang)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
46
65
|
end
|
47
66
|
|
48
67
|
attach_function :oscap_text_new, [], :pointer
|
49
|
-
attach_function :oscap_text_set_text, [
|
68
|
+
attach_function :oscap_text_set_text, %i[pointer string], :bool
|
50
69
|
attach_function :oscap_text_get_text, [:pointer], :string
|
51
70
|
attach_function :oscap_text_free, [:pointer], :void
|
52
71
|
|
53
|
-
attach_function :oscap_textlist_get_preferred_plaintext, [
|
72
|
+
attach_function :oscap_textlist_get_preferred_plaintext, %i[pointer string], :string
|
73
|
+
attach_function :oscap_textlist_get_preferred_text, %i[pointer string], :pointer
|
54
74
|
attach_function :oscap_text_iterator_free, [:pointer], :void
|
55
75
|
end
|
data/lib/openscap/version.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2018 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
module OpenSCAP
|
13
|
-
VERSION = '0.
|
4
|
+
VERSION = '0.5.0'
|
14
5
|
end
|
@@ -1,21 +1,16 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2014--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/source'
|
13
4
|
require 'openscap/xccdf/profile'
|
14
5
|
require 'openscap/xccdf/item'
|
6
|
+
require 'openscap/xccdf/item_common'
|
7
|
+
require 'openscap/xccdf/value'
|
8
|
+
require 'openscap/xccdf/status'
|
15
9
|
|
16
10
|
module OpenSCAP
|
17
11
|
module Xccdf
|
18
12
|
class Benchmark
|
13
|
+
include ItemCommon
|
19
14
|
attr_reader :raw
|
20
15
|
|
21
16
|
def initialize(p)
|
@@ -27,6 +22,20 @@ module OpenSCAP
|
|
27
22
|
"Cannot initialize OpenSCAP::Xccdf::Benchmark with '#{p}'"
|
28
23
|
end
|
29
24
|
OpenSCAP.raise! if @raw.null?
|
25
|
+
|
26
|
+
begin
|
27
|
+
yield self
|
28
|
+
ensure
|
29
|
+
destroy
|
30
|
+
end if block_given?
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolved?
|
34
|
+
OpenSCAP.xccdf_benchmark_get_resolved @raw
|
35
|
+
end
|
36
|
+
|
37
|
+
def status_current
|
38
|
+
Status.new OpenSCAP.xccdf_benchmark_get_status_current(raw)
|
30
39
|
end
|
31
40
|
|
32
41
|
def profiles
|
@@ -37,8 +46,40 @@ module OpenSCAP
|
|
37
46
|
@items ||= items_init
|
38
47
|
end
|
39
48
|
|
49
|
+
def each_item(&)
|
50
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_item_get_content(@raw), as: 'xccdf_item' do |pointer|
|
51
|
+
yield OpenSCAP::Xccdf::Item.build(pointer)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def each_profile(&)
|
56
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_benchmark_get_profiles(@raw), as: 'xccdf_profile' do |pointer|
|
57
|
+
yield OpenSCAP::Xccdf::Profile.new pointer
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def each_value(&)
|
62
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_benchmark_get_values(@raw), as: 'xccdf_value' do |pointer|
|
63
|
+
yield OpenSCAP::Xccdf::Value.new pointer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def policy_model
|
68
|
+
@policy_model ||= PolicyModel.new(self)
|
69
|
+
end
|
70
|
+
|
71
|
+
def schema_version
|
72
|
+
pointer = OpenSCAP.xccdf_benchmark_get_schema_version(@raw)
|
73
|
+
OpenSCAP.xccdf_version_info_get_version(pointer)
|
74
|
+
end
|
75
|
+
|
40
76
|
def destroy
|
41
|
-
|
77
|
+
# Policy Model takes ownership of Xccdf::Benchmark. It is one of these lovely quirks of libopenscap
|
78
|
+
if @policy_model
|
79
|
+
@policy_model.destroy
|
80
|
+
else
|
81
|
+
OpenSCAP.xccdf_benchmark_free @raw
|
82
|
+
end
|
42
83
|
@raw = nil
|
43
84
|
end
|
44
85
|
|
@@ -46,27 +87,18 @@ module OpenSCAP
|
|
46
87
|
|
47
88
|
def profiles_init
|
48
89
|
profiles = {}
|
49
|
-
|
50
|
-
while OpenSCAP.xccdf_profile_iterator_has_more profit
|
51
|
-
profile_p = OpenSCAP.xccdf_profile_iterator_next profit
|
52
|
-
profile = OpenSCAP::Xccdf::Profile.new profile_p
|
90
|
+
each_profile do |profile|
|
53
91
|
profiles[profile.id] = profile
|
54
92
|
end
|
55
|
-
OpenSCAP.xccdf_profile_iterator_free profit
|
56
93
|
profiles
|
57
94
|
end
|
58
95
|
|
59
96
|
def items_init
|
60
97
|
items = {}
|
61
|
-
|
62
|
-
while OpenSCAP.xccdf_item_iterator_has_more items_it
|
63
|
-
item_p = OpenSCAP.xccdf_item_iterator_next items_it
|
64
|
-
item = OpenSCAP::Xccdf::Item.build item_p
|
98
|
+
each_item do |item|
|
65
99
|
items.merge! item.sub_items
|
66
100
|
items[item.id] = item
|
67
|
-
# TODO: iterate through childs
|
68
101
|
end
|
69
|
-
OpenSCAP.xccdf_item_iterator_free items_it
|
70
102
|
items
|
71
103
|
end
|
72
104
|
end
|
@@ -75,8 +107,19 @@ module OpenSCAP
|
|
75
107
|
attach_function :xccdf_benchmark_import_source, [:pointer], :pointer
|
76
108
|
attach_function :xccdf_benchmark_free, [:pointer], :void
|
77
109
|
|
110
|
+
attach_function :xccdf_benchmark_get_status_current, [:pointer], :pointer
|
111
|
+
attach_function :xccdf_benchmark_get_resolved, [:pointer], :pointer
|
78
112
|
attach_function :xccdf_benchmark_get_profiles, [:pointer], :pointer
|
79
113
|
attach_function :xccdf_profile_iterator_has_more, [:pointer], :bool
|
80
114
|
attach_function :xccdf_profile_iterator_next, [:pointer], :pointer
|
81
115
|
attach_function :xccdf_profile_iterator_free, [:pointer], :void
|
116
|
+
attach_function :xccdf_benchmark_get_values, [:pointer], :pointer
|
117
|
+
attach_function :xccdf_value_iterator_has_more, [:pointer], :bool
|
118
|
+
attach_function :xccdf_value_iterator_next, [:pointer], :pointer
|
119
|
+
attach_function :xccdf_value_iterator_free, [:pointer], :void
|
120
|
+
|
121
|
+
attach_function :xccdf_benchmark_get_schema_version, [:pointer], :pointer
|
122
|
+
attach_function :xccdf_version_info_get_version, [:pointer], :string
|
82
123
|
end
|
124
|
+
|
125
|
+
require_relative 'policy_model'
|
data/lib/openscap/xccdf/fix.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2015--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
module OpenSCAP
|
13
4
|
module Xccdf
|
@@ -15,6 +6,7 @@ module OpenSCAP
|
|
15
6
|
def initialize(raw)
|
16
7
|
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" \
|
17
8
|
unless raw.is_a?(FFI::Pointer)
|
9
|
+
|
18
10
|
@raw = raw
|
19
11
|
end
|
20
12
|
|
@@ -37,10 +29,10 @@ module OpenSCAP
|
|
37
29
|
|
38
30
|
def to_hash
|
39
31
|
{
|
40
|
-
|
41
|
-
|
42
|
-
:
|
43
|
-
:
|
32
|
+
id:,
|
33
|
+
platform:,
|
34
|
+
system: fix_system,
|
35
|
+
content:
|
44
36
|
}
|
45
37
|
end
|
46
38
|
end
|
data/lib/openscap/xccdf/group.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2015 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
require 'openscap/exceptions'
|
13
4
|
require 'openscap/xccdf'
|
@@ -16,6 +7,38 @@ require 'openscap/xccdf/item'
|
|
16
7
|
module OpenSCAP
|
17
8
|
module Xccdf
|
18
9
|
class Group < Item
|
10
|
+
def each_child(&)
|
11
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_item_get_content(@raw), as: 'xccdf_item' do |pointer|
|
12
|
+
yield OpenSCAP::Xccdf::Item.build pointer
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def each_value(&)
|
17
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_group_get_values(@raw), as: 'xccdf_value' do |pointer|
|
18
|
+
yield OpenSCAP::Xccdf::Value.new pointer
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def sub_items
|
23
|
+
@sub_items ||= sub_items_init
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def sub_items_init
|
29
|
+
collect = {}
|
30
|
+
each_child do |item|
|
31
|
+
collect.merge! item.sub_items
|
32
|
+
collect[item.id] = item
|
33
|
+
end
|
34
|
+
collect
|
35
|
+
end
|
19
36
|
end
|
20
37
|
end
|
38
|
+
|
39
|
+
attach_function :xccdf_item_get_content, [:pointer], :pointer
|
40
|
+
attach_function :xccdf_item_iterator_has_more, [:pointer], :bool
|
41
|
+
attach_function :xccdf_item_iterator_next, [:pointer], :pointer
|
42
|
+
attach_function :xccdf_item_iterator_free, [:pointer], :void
|
43
|
+
attach_function :xccdf_group_get_values, [:pointer], :pointer
|
21
44
|
end
|
data/lib/openscap/xccdf/ident.rb
CHANGED
@@ -1,13 +1,4 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2015--2016 Red Hat Inc.
|
3
|
-
#
|
4
|
-
# This software is licensed to you under the GNU General Public License,
|
5
|
-
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
6
|
-
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
-
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
8
|
-
# along with this software; if not, see
|
9
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
10
|
-
#
|
1
|
+
# frozen_string_literal: true
|
11
2
|
|
12
3
|
module OpenSCAP
|
13
4
|
module Xccdf
|
@@ -15,6 +6,7 @@ module OpenSCAP
|
|
15
6
|
def initialize(raw)
|
16
7
|
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" \
|
17
8
|
unless raw.is_a?(FFI::Pointer)
|
9
|
+
|
18
10
|
@raw = raw
|
19
11
|
end
|
20
12
|
|