openscap 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openscap/version.rb +1 -1
- data/lib/openscap/xccdf/benchmark.rb +10 -10
- data/lib/openscap/xccdf/fix.rb +7 -14
- data/lib/openscap/xccdf/fixtext.rb +19 -0
- data/lib/openscap/xccdf/group.rb +6 -12
- data/lib/openscap/xccdf/ident.rb +4 -10
- data/lib/openscap/xccdf/item.rb +6 -6
- data/lib/openscap/xccdf/item_common.rb +1 -1
- data/lib/openscap/xccdf/policy.rb +3 -4
- data/lib/openscap/xccdf/policy_model.rb +6 -14
- data/lib/openscap/xccdf/profile.rb +2 -2
- data/lib/openscap/xccdf/reference.rb +5 -21
- data/lib/openscap/xccdf/rule.rb +32 -8
- data/lib/openscap/xccdf/ruleresult.rb +5 -7
- data/lib/openscap/xccdf/session.rb +11 -11
- data/lib/openscap/xccdf/status.rb +1 -2
- data/lib/openscap/xccdf/tailoring.rb +6 -12
- data/lib/openscap/xccdf/testresult.rb +12 -16
- data/lib/openscap/xccdf/value.rb +1 -2
- metadata +5 -27
- data/test/common/testcase.rb +0 -38
- data/test/data/arf.xml +0 -275156
- data/test/data/invalid.xml +0 -20
- data/test/data/sds-complex.xml +0 -132
- data/test/data/tailoring.xml +0 -31
- data/test/data/testresult.xml +0 -225
- data/test/data/xccdf.xml +0 -3047
- data/test/ds/arf_test.rb +0 -96
- data/test/ds/sds_test.rb +0 -89
- data/test/integration/arf_waiver_test.rb +0 -91
- data/test/openscap_test.rb +0 -21
- data/test/source_test.rb +0 -78
- data/test/text_test.rb +0 -19
- data/test/xccdf/arf_test.rb +0 -43
- data/test/xccdf/benchmark_test.rb +0 -201
- data/test/xccdf/item_test.rb +0 -82
- data/test/xccdf/policy_test.rb +0 -48
- data/test/xccdf/profile_test.rb +0 -62
- data/test/xccdf/session_ds_test.rb +0 -116
- data/test/xccdf/session_test.rb +0 -33
- data/test/xccdf/tailoring_test.rb +0 -30
- data/test/xccdf/testresult_test.rb +0 -99
- data/test/xccdf/value_test.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c8eddf3fa5a4c04f1655827ba4f4b8422f32f314a20f888b36c5ef85e2e04cf
|
4
|
+
data.tar.gz: 3e9d497efc4543111a4fee03d8db323c85b96360e31e23cd9ebc4387ec354d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 601b6ee58372cd9f943918611c5f10df28cf1245d1149547d2889531e4b623b3787fb70cc06c1b4a17d4fca7e4202dd27dcacc7a69eba5c99d156fcc7e2529f3
|
7
|
+
data.tar.gz: 3a47312203579d8735b19032cfe427f76ede2467bbfb63b806dbd47edd79a8442ebd40fc61062fb4ece7b51742c38350e73c69d8677aafed5a5d8aef0d473db2
|
data/lib/openscap/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openscap/source'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
require_relative 'profile'
|
5
|
+
require_relative 'item'
|
6
|
+
require_relative 'item_common'
|
7
|
+
require_relative 'value'
|
8
|
+
require_relative 'status'
|
9
9
|
|
10
10
|
module OpenSCAP
|
11
11
|
module Xccdf
|
@@ -13,7 +13,7 @@ module OpenSCAP
|
|
13
13
|
include ItemCommon
|
14
14
|
attr_reader :raw
|
15
15
|
|
16
|
-
def initialize
|
16
|
+
def initialize p
|
17
17
|
case p
|
18
18
|
when OpenSCAP::Source
|
19
19
|
@raw = OpenSCAP.xccdf_benchmark_import_source p.raw
|
@@ -35,7 +35,7 @@ module OpenSCAP
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def status_current
|
38
|
-
Status.new OpenSCAP.xccdf_benchmark_get_status_current(raw)
|
38
|
+
Status.new OpenSCAP.xccdf_benchmark_get_status_current(@raw)
|
39
39
|
end
|
40
40
|
|
41
41
|
def profiles
|
@@ -65,12 +65,12 @@ module OpenSCAP
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def policy_model
|
68
|
-
@policy_model ||= PolicyModel.new
|
68
|
+
@policy_model ||= PolicyModel.new self
|
69
69
|
end
|
70
70
|
|
71
71
|
def schema_version
|
72
|
-
pointer = OpenSCAP.xccdf_benchmark_get_schema_version
|
73
|
-
OpenSCAP.xccdf_version_info_get_version
|
72
|
+
pointer = OpenSCAP.xccdf_benchmark_get_schema_version @raw
|
73
|
+
OpenSCAP.xccdf_version_info_get_version pointer
|
74
74
|
end
|
75
75
|
|
76
76
|
def destroy
|
data/lib/openscap/xccdf/fix.rb
CHANGED
@@ -3,37 +3,30 @@
|
|
3
3
|
module OpenSCAP
|
4
4
|
module Xccdf
|
5
5
|
class Fix
|
6
|
-
def initialize
|
7
|
-
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'"
|
8
|
-
unless raw.is_a?(FFI::Pointer)
|
6
|
+
def initialize raw
|
7
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" unless raw.is_a? FFI::Pointer
|
9
8
|
|
10
9
|
@raw = raw
|
11
10
|
end
|
12
11
|
|
13
12
|
def id
|
14
|
-
OpenSCAP.xccdf_fix_get_id
|
13
|
+
OpenSCAP.xccdf_fix_get_id @raw
|
15
14
|
end
|
16
15
|
|
17
16
|
def platform
|
18
|
-
OpenSCAP.xccdf_fix_get_platform
|
17
|
+
OpenSCAP.xccdf_fix_get_platform @raw
|
19
18
|
end
|
20
19
|
|
21
|
-
# system is a reserved word in Rails, so didn't use it
|
22
20
|
def fix_system
|
23
|
-
OpenSCAP.xccdf_fix_get_system
|
21
|
+
OpenSCAP.xccdf_fix_get_system @raw
|
24
22
|
end
|
25
23
|
|
26
24
|
def content
|
27
|
-
OpenSCAP.xccdf_fix_get_content
|
25
|
+
OpenSCAP.xccdf_fix_get_content @raw
|
28
26
|
end
|
29
27
|
|
30
28
|
def to_hash
|
31
|
-
{
|
32
|
-
id:,
|
33
|
-
platform:,
|
34
|
-
system: fix_system,
|
35
|
-
content:
|
36
|
-
}
|
29
|
+
{ id:, platform:, system: fix_system, content: }
|
37
30
|
end
|
38
31
|
end
|
39
32
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenSCAP
|
4
|
+
module Xccdf
|
5
|
+
class Fixtext
|
6
|
+
def initialize(raw)
|
7
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" unless raw.is_a?(FFI::Pointer)
|
8
|
+
|
9
|
+
@raw = raw
|
10
|
+
end
|
11
|
+
|
12
|
+
def text
|
13
|
+
Text.new(OpenSCAP.xccdf_fixtext_get_text(@raw)).text
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attach_function :xccdf_fixtext_get_text, [:pointer], :pointer
|
19
|
+
end
|
data/lib/openscap/xccdf/group.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'openscap/exceptions'
|
4
4
|
require 'openscap/xccdf'
|
5
|
-
|
5
|
+
require_relative 'item'
|
6
6
|
|
7
7
|
module OpenSCAP
|
8
8
|
module Xccdf
|
@@ -20,18 +20,12 @@ module OpenSCAP
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def sub_items
|
23
|
-
@sub_items ||=
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def sub_items_init
|
29
|
-
collect = {}
|
30
|
-
each_child do |item|
|
31
|
-
collect.merge! item.sub_items
|
32
|
-
collect[item.id] = item
|
23
|
+
@sub_items ||= {}.tap do |sub_items|
|
24
|
+
each_child do |item|
|
25
|
+
sub_items.merge! item.sub_items
|
26
|
+
sub_items[item.id] = item
|
27
|
+
end
|
33
28
|
end
|
34
|
-
collect
|
35
29
|
end
|
36
30
|
end
|
37
31
|
end
|
data/lib/openscap/xccdf/ident.rb
CHANGED
@@ -3,20 +3,14 @@
|
|
3
3
|
module OpenSCAP
|
4
4
|
module Xccdf
|
5
5
|
class Ident
|
6
|
-
def initialize
|
7
|
-
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'"
|
8
|
-
unless raw.is_a?(FFI::Pointer)
|
6
|
+
def initialize raw
|
7
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" unless raw.is_a?(FFI::Pointer)
|
9
8
|
|
10
9
|
@raw = raw
|
11
10
|
end
|
12
11
|
|
13
|
-
def system
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def id
|
18
|
-
OpenSCAP.xccdf_ident_get_id(@raw)
|
19
|
-
end
|
12
|
+
def system = OpenSCAP.xccdf_ident_get_system @raw
|
13
|
+
def id = OpenSCAP.xccdf_ident_get_id @raw
|
20
14
|
end
|
21
15
|
end
|
22
16
|
attach_function :xccdf_ident_get_system, [:pointer], :string
|
data/lib/openscap/xccdf/item.rb
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'openscap/exceptions'
|
4
4
|
require 'openscap/text'
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require_relative 'item_common'
|
6
|
+
require_relative 'group'
|
7
|
+
require_relative 'rule'
|
8
8
|
|
9
9
|
module OpenSCAP
|
10
10
|
module Xccdf
|
11
11
|
class Item
|
12
12
|
include ItemCommon # reflects OpenSCAP's struct xccdf_item (thus operates with Benchmark, Profile, Group, Rule, and Value)
|
13
13
|
|
14
|
-
def self.build
|
14
|
+
def self.build t
|
15
15
|
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{t}" \
|
16
16
|
unless t.is_a?(FFI::Pointer)
|
17
17
|
|
@@ -26,13 +26,13 @@ module OpenSCAP
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def initialize
|
29
|
+
def initialize t
|
30
30
|
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} abstract base class." if instance_of?(OpenSCAP::Xccdf::Item)
|
31
31
|
|
32
32
|
@raw = t
|
33
33
|
end
|
34
34
|
|
35
|
-
def rationale
|
35
|
+
def rationale prefered_lang = nil, markup: false
|
36
36
|
TextList.extract(OpenSCAP.xccdf_item_get_rationale(@raw), lang: prefered_lang, markup:)
|
37
37
|
end
|
38
38
|
|
@@ -12,21 +12,20 @@ module OpenSCAP
|
|
12
12
|
when FFI::Pointer
|
13
13
|
@raw = p
|
14
14
|
else
|
15
|
-
raise OpenSCAP::OpenSCAPError,
|
16
|
-
"Cannot initialize OpenSCAP::Xccdf::Policy with '#{p}'"
|
15
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Xccdf::Policy with '#{p}'"
|
17
16
|
end
|
18
17
|
OpenSCAP.raise! if @raw.null?
|
19
18
|
end
|
20
19
|
|
21
20
|
def id
|
22
|
-
OpenSCAP.xccdf_policy_get_id raw
|
21
|
+
OpenSCAP.xccdf_policy_get_id @raw
|
23
22
|
end
|
24
23
|
|
25
24
|
def profile
|
26
25
|
Profile.new OpenSCAP.xccdf_policy_get_profile @raw
|
27
26
|
end
|
28
27
|
|
29
|
-
def selects_item?
|
28
|
+
def selects_item? item_idref
|
30
29
|
OpenSCAP.xccdf_policy_is_item_selected @raw, item_idref
|
31
30
|
end
|
32
31
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openscap/exceptions'
|
4
|
-
|
5
|
-
|
4
|
+
require_relative 'benchmark'
|
5
|
+
require_relative 'policy'
|
6
6
|
|
7
7
|
module OpenSCAP
|
8
8
|
module Xccdf
|
9
9
|
class PolicyModel
|
10
10
|
attr_reader :raw
|
11
11
|
|
12
|
-
def initialize
|
12
|
+
def initialize b
|
13
13
|
case b
|
14
14
|
when OpenSCAP::Xccdf::Benchmark
|
15
15
|
@raw = OpenSCAP.xccdf_policy_model_new(b.raw)
|
@@ -27,7 +27,9 @@ module OpenSCAP
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def policies
|
30
|
-
@policies ||=
|
30
|
+
@policies ||= {}.tap do |policies|
|
31
|
+
each_policy { |p| policies[p.id] = p }
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
35
|
def destroy
|
@@ -42,16 +44,6 @@ module OpenSCAP
|
|
42
44
|
yield OpenSCAP::Xccdf::Policy.new pointer
|
43
45
|
end
|
44
46
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def policies_init
|
49
|
-
policies = {}
|
50
|
-
each_policy do |policy|
|
51
|
-
policies[policy.id] = policy
|
52
|
-
end
|
53
|
-
policies
|
54
|
-
end
|
55
47
|
end
|
56
48
|
end
|
57
49
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openscap/text'
|
4
|
-
|
4
|
+
require_relative 'item_common'
|
5
5
|
|
6
6
|
module OpenSCAP
|
7
7
|
module Xccdf
|
@@ -9,7 +9,7 @@ module OpenSCAP
|
|
9
9
|
include ItemCommon
|
10
10
|
attr_reader :raw
|
11
11
|
|
12
|
-
def initialize
|
12
|
+
def initialize p
|
13
13
|
case p
|
14
14
|
when FFI::Pointer
|
15
15
|
@raw = p
|
@@ -4,31 +4,15 @@ module OpenSCAP
|
|
4
4
|
module Xccdf
|
5
5
|
class Reference
|
6
6
|
def initialize(raw)
|
7
|
-
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'"
|
8
|
-
unless raw.is_a?(FFI::Pointer)
|
7
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" unless raw.is_a?(FFI::Pointer)
|
9
8
|
|
10
9
|
@raw = raw
|
11
10
|
end
|
12
11
|
|
13
|
-
def title
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def href
|
18
|
-
OpenSCAP.oscap_reference_get_href(@raw)
|
19
|
-
end
|
20
|
-
|
21
|
-
def html_link
|
22
|
-
"<a href='#{href}'>#{title}</a>"
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_hash
|
26
|
-
{
|
27
|
-
title:,
|
28
|
-
href:,
|
29
|
-
html_link:
|
30
|
-
}
|
31
|
-
end
|
12
|
+
def title = OpenSCAP.oscap_reference_get_title @raw
|
13
|
+
def href = OpenSCAP.oscap_reference_get_href @raw
|
14
|
+
def html_link = "<a href='#{href}'>#{title}</a>"
|
15
|
+
def to_hash = { title:, href:, html_link: }
|
32
16
|
end
|
33
17
|
end
|
34
18
|
attach_function :oscap_reference_get_href, [:pointer], :string
|
data/lib/openscap/xccdf/rule.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openscap/exceptions'
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require_relative 'item'
|
5
|
+
require_relative 'fix'
|
6
|
+
require_relative 'fixtext'
|
7
|
+
require_relative 'ident'
|
7
8
|
|
8
9
|
module OpenSCAP
|
9
10
|
module Xccdf
|
10
11
|
class Rule < Item
|
11
12
|
def severity
|
12
|
-
severity = OpenSCAP.xccdf_rule_get_severity
|
13
|
+
severity = OpenSCAP.xccdf_rule_get_severity @raw
|
13
14
|
severity_mapping = {
|
14
15
|
xccdf_level_not_defined: 'Not defined',
|
15
16
|
xccdf_unknown: 'Unknown',
|
@@ -21,12 +22,30 @@ module OpenSCAP
|
|
21
22
|
severity_mapping[severity] || severity_mapping[:xccdf_unknown]
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
fixes = []
|
25
|
+
def each_fix(&)
|
26
26
|
OpenSCAP._iterate over: OpenSCAP.xccdf_rule_get_fixes(@raw), as: 'xccdf_fix' do |pointer|
|
27
|
-
|
27
|
+
yield OpenSCAP::Xccdf::Fix.new pointer
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_fixtext(&)
|
32
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_rule_get_fixtexts(@raw), as: 'xccdf_fixtext' do |pointer|
|
33
|
+
yield OpenSCAP::Xccdf::Fixtext.new pointer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fixtexts
|
38
|
+
@fixtexts ||= [].tap do |fixtexts|
|
39
|
+
each_fixtext { |ft| fixtexts << ft }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def fixes
|
44
|
+
@fixes ||= [].tap do |fixes|
|
45
|
+
each_fix do |fix|
|
46
|
+
fixes << fix
|
47
|
+
end
|
28
48
|
end
|
29
|
-
fixes
|
30
49
|
end
|
31
50
|
|
32
51
|
def idents
|
@@ -52,6 +71,11 @@ module OpenSCAP
|
|
52
71
|
attach_function :xccdf_fix_iterator_next, [:pointer], :pointer
|
53
72
|
attach_function :xccdf_fix_iterator_free, [:pointer], :void
|
54
73
|
|
74
|
+
attach_function :xccdf_rule_get_fixtexts, [:pointer], :pointer
|
75
|
+
attach_function :xccdf_fixtext_iterator_has_more, [:pointer], :bool
|
76
|
+
attach_function :xccdf_fixtext_iterator_next, [:pointer], :pointer
|
77
|
+
attach_function :xccdf_fixtext_iterator_free, [:pointer], :void
|
78
|
+
|
55
79
|
attach_function :xccdf_rule_get_idents, [:pointer], :pointer
|
56
80
|
attach_function :xccdf_ident_iterator_has_more, [:pointer], :bool
|
57
81
|
attach_function :xccdf_ident_iterator_next, [:pointer], :pointer
|
@@ -6,7 +6,7 @@ require 'openscap/text'
|
|
6
6
|
module OpenSCAP
|
7
7
|
module Xccdf
|
8
8
|
class RuleResult
|
9
|
-
def initialize
|
9
|
+
def initialize t
|
10
10
|
case t
|
11
11
|
when FFI::Pointer
|
12
12
|
@rr = t
|
@@ -20,11 +20,10 @@ module OpenSCAP
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def result
|
23
|
-
OpenSCAP.xccdf_test_result_type_get_text
|
24
|
-
OpenSCAP.xccdf_rule_result_get_result(@rr)
|
23
|
+
OpenSCAP.xccdf_test_result_type_get_text OpenSCAP.xccdf_rule_result_get_result(@rr)
|
25
24
|
end
|
26
25
|
|
27
|
-
def override!
|
26
|
+
def override! param
|
28
27
|
validate_xccdf_result! param[:new_result]
|
29
28
|
t = OpenSCAP::Text.new
|
30
29
|
t.text = param[:raw_text]
|
@@ -41,7 +40,7 @@ module OpenSCAP
|
|
41
40
|
|
42
41
|
private
|
43
42
|
|
44
|
-
def validate_xccdf_result!
|
43
|
+
def validate_xccdf_result! result_label
|
45
44
|
if OpenSCAP::XccdfResult[result_label] > OpenSCAP::XccdfResult[:fixed]
|
46
45
|
raise OpenSCAPError, "Could not recognize result type: '#{result_label}'"
|
47
46
|
end
|
@@ -63,6 +62,5 @@ module OpenSCAP
|
|
63
62
|
:notselected,
|
64
63
|
:informational,
|
65
64
|
:fixed)
|
66
|
-
attach_function :xccdf_rule_result_override,
|
67
|
-
[:pointer, XccdfResult, :string, :string, :pointer], :bool
|
65
|
+
attach_function :xccdf_rule_result_override, [:pointer, XccdfResult, :string, :string, :pointer], :bool
|
68
66
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OpenSCAP
|
4
4
|
module Xccdf
|
5
5
|
class Session
|
6
|
-
def initialize
|
6
|
+
def initialize input_filename
|
7
7
|
raise OpenSCAPError, 'No filename specified!' unless input_filename
|
8
8
|
|
9
9
|
@input_filename = input_filename
|
@@ -12,25 +12,25 @@ module OpenSCAP
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def sds?
|
15
|
-
OpenSCAP.xccdf_session_is_sds
|
15
|
+
OpenSCAP.xccdf_session_is_sds @s
|
16
16
|
end
|
17
17
|
|
18
|
-
def load
|
18
|
+
def load opts = {}
|
19
19
|
o = {
|
20
20
|
datastream_id: nil,
|
21
21
|
component_id: nil
|
22
|
-
}.merge
|
22
|
+
}.merge opts
|
23
23
|
if sds?
|
24
|
-
OpenSCAP.xccdf_session_set_datastream_id
|
25
|
-
OpenSCAP.xccdf_session_set_component_id
|
24
|
+
OpenSCAP.xccdf_session_set_datastream_id @s, o[:datastream_id]
|
25
|
+
OpenSCAP.xccdf_session_set_component_id @s, o[:component_id]
|
26
26
|
end
|
27
27
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_load(@s).zero?
|
28
28
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_load_check_engine_plugins(@s).zero?
|
29
29
|
end
|
30
30
|
|
31
|
-
def profile=
|
31
|
+
def profile= p
|
32
32
|
@profile = p
|
33
|
-
raise OpenSCAPError, "No profile '#{p}' found"
|
33
|
+
raise OpenSCAPError, "No profile '#{p}' found" unless OpenSCAP.xccdf_session_set_profile_id(@s, p)
|
34
34
|
end
|
35
35
|
|
36
36
|
def evaluate
|
@@ -49,13 +49,13 @@ module OpenSCAP
|
|
49
49
|
oval_results: false,
|
50
50
|
oval_variables: false,
|
51
51
|
engines_results: false
|
52
|
-
}.merge!
|
52
|
+
}.merge! opts
|
53
53
|
export_targets o
|
54
54
|
export
|
55
55
|
end
|
56
56
|
|
57
57
|
def destroy
|
58
|
-
OpenSCAP.xccdf_session_free
|
58
|
+
OpenSCAP.xccdf_session_free @s
|
59
59
|
@s = nil
|
60
60
|
end
|
61
61
|
|
@@ -68,7 +68,7 @@ module OpenSCAP
|
|
68
68
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_arf(@s).zero?
|
69
69
|
end
|
70
70
|
|
71
|
-
def export_targets
|
71
|
+
def export_targets opts = {}
|
72
72
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_arf_export(@s, opts[:rds_file])
|
73
73
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_xccdf_export(@s, opts[:xccdf_file])
|
74
74
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_report_export(@s, opts[:report_file])
|
@@ -4,8 +4,7 @@ module OpenSCAP
|
|
4
4
|
module Xccdf
|
5
5
|
class Status
|
6
6
|
def initialize(raw)
|
7
|
-
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'"
|
8
|
-
unless raw.is_a?(FFI::Pointer)
|
7
|
+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" unless raw.is_a?(FFI::Pointer)
|
9
8
|
|
10
9
|
@raw = raw
|
11
10
|
end
|
@@ -19,24 +19,18 @@ module OpenSCAP
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def profiles
|
22
|
-
@profiles ||=
|
22
|
+
@profiles ||= {}.tap do |profiles|
|
23
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_tailoring_get_profiles(@raw), as: 'xccdf_profile' do |pointer|
|
24
|
+
profile = OpenSCAP::Xccdf::Profile.new pointer
|
25
|
+
profiles[profile.id] = profile
|
26
|
+
end
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def destroy
|
26
31
|
OpenSCAP.xccdf_tailoring_free @raw
|
27
32
|
@raw = nil
|
28
33
|
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def profiles_init
|
33
|
-
profiles = {}
|
34
|
-
OpenSCAP._iterate over: OpenSCAP.xccdf_tailoring_get_profiles(@raw), as: 'xccdf_profile' do |pointer|
|
35
|
-
profile = OpenSCAP::Xccdf::Profile.new pointer
|
36
|
-
profiles[profile.id] = profile
|
37
|
-
end
|
38
|
-
profiles
|
39
|
-
end
|
40
34
|
end
|
41
35
|
end
|
42
36
|
|
@@ -10,7 +10,7 @@ module OpenSCAP
|
|
10
10
|
class TestResult
|
11
11
|
attr_reader :rr, :raw
|
12
12
|
|
13
|
-
def initialize
|
13
|
+
def initialize t
|
14
14
|
case t
|
15
15
|
when OpenSCAP::Source
|
16
16
|
@raw = OpenSCAP.xccdf_result_import_source(t.raw)
|
@@ -25,15 +25,23 @@ module OpenSCAP
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def id
|
28
|
-
OpenSCAP.xccdf_result_get_id
|
28
|
+
OpenSCAP.xccdf_result_get_id @raw
|
29
29
|
end
|
30
30
|
|
31
31
|
def profile
|
32
|
-
OpenSCAP.xccdf_result_get_profile
|
32
|
+
OpenSCAP.xccdf_result_get_profile @raw
|
33
33
|
end
|
34
34
|
|
35
35
|
def score
|
36
|
-
@score ||=
|
36
|
+
@score ||= {}.tap do |scores|
|
37
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_result_get_scores(@raw), as: 'xccdf_score' do |s|
|
38
|
+
scores[OpenSCAP.xccdf_score_get_system(s)] = {
|
39
|
+
system: OpenSCAP.xccdf_score_get_system(s),
|
40
|
+
value: OpenSCAP.xccdf_score_get_score(s),
|
41
|
+
max: OpenSCAP.xccdf_score_get_maximum(s)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
def score!(benchmark)
|
@@ -63,18 +71,6 @@ module OpenSCAP
|
|
63
71
|
@rr[rr.id] = rr
|
64
72
|
end
|
65
73
|
end
|
66
|
-
|
67
|
-
def score_init
|
68
|
-
scores = {}
|
69
|
-
OpenSCAP._iterate over: OpenSCAP.xccdf_result_get_scores(@raw), as: 'xccdf_score' do |s|
|
70
|
-
scores[OpenSCAP.xccdf_score_get_system(s)] = {
|
71
|
-
system: OpenSCAP.xccdf_score_get_system(s),
|
72
|
-
value: OpenSCAP.xccdf_score_get_score(s),
|
73
|
-
max: OpenSCAP.xccdf_score_get_maximum(s)
|
74
|
-
}
|
75
|
-
end
|
76
|
-
scores
|
77
|
-
end
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|