openscap 0.4.9 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -18
- data/Rakefile +2 -2
- data/lib/openscap/all.rb +1 -1
- data/lib/openscap/ds/arf.rb +3 -3
- data/lib/openscap/ds/sds.rb +8 -2
- data/lib/openscap/openscap.rb +9 -0
- data/lib/openscap/source.rb +10 -4
- data/lib/openscap/text.rb +34 -5
- data/lib/openscap/version.rb +1 -1
- data/lib/openscap/xccdf/benchmark.rb +67 -15
- data/lib/openscap/xccdf/fix.rb +7 -14
- data/lib/openscap/xccdf/fixtext.rb +19 -0
- data/lib/openscap/xccdf/group.rb +27 -1
- data/lib/openscap/xccdf/ident.rb +4 -10
- data/lib/openscap/xccdf/item.rb +37 -65
- data/lib/openscap/xccdf/item_common.rb +40 -0
- data/lib/openscap/xccdf/policy.rb +12 -3
- data/lib/openscap/xccdf/policy_model.rb +16 -15
- data/lib/openscap/xccdf/profile.rb +10 -10
- data/lib/openscap/xccdf/reference.rb +5 -21
- data/lib/openscap/xccdf/rule.rb +40 -20
- data/lib/openscap/xccdf/ruleresult.rb +5 -7
- data/lib/openscap/xccdf/session.rb +28 -30
- data/lib/openscap/xccdf/status.rb +34 -0
- data/lib/openscap/xccdf/tailoring.rb +7 -16
- data/lib/openscap/xccdf/testresult.rb +18 -28
- data/lib/openscap/xccdf/value.rb +1 -2
- data/lib/openscap/xccdf.rb +1 -1
- metadata +15 -48
- 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 -3046
- data/test/ds/arf_test.rb +0 -96
- data/test/ds/sds_test.rb +0 -71
- 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 -44
- data/test/xccdf/benchmark_test.rb +0 -115
- data/test/xccdf/policy_test.rb +0 -20
- data/test/xccdf/profile_test.rb +0 -20
- 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
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openscap/text'
|
4
|
+
require_relative 'reference'
|
5
|
+
|
6
|
+
module OpenSCAP
|
7
|
+
module Xccdf
|
8
|
+
module ItemCommon
|
9
|
+
def id
|
10
|
+
OpenSCAP.xccdf_item_get_id @raw
|
11
|
+
end
|
12
|
+
|
13
|
+
def version
|
14
|
+
OpenSCAP.xccdf_item_get_version @raw
|
15
|
+
end
|
16
|
+
|
17
|
+
def title lang: nil
|
18
|
+
TextList.extract OpenSCAP.xccdf_item_get_title(@raw), lang:, markup: false
|
19
|
+
end
|
20
|
+
|
21
|
+
def description prefered_lang: nil, markup: true
|
22
|
+
TextList.extract(OpenSCAP.xccdf_item_get_description(@raw), lang: prefered_lang, markup:)
|
23
|
+
end
|
24
|
+
|
25
|
+
def references
|
26
|
+
refs = []
|
27
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_item_get_references(@raw), as: 'oscap_reference' do |pointer|
|
28
|
+
refs << OpenSCAP::Xccdf::Reference.new(pointer)
|
29
|
+
end
|
30
|
+
refs
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
attach_function :xccdf_item_get_id, [:pointer], :string
|
36
|
+
attach_function :xccdf_item_get_title, [:pointer], :pointer
|
37
|
+
attach_function :xccdf_item_get_description, [:pointer], :pointer
|
38
|
+
attach_function :xccdf_item_get_references, [:pointer], :pointer
|
39
|
+
attach_function :xccdf_item_get_version, [:pointer], :string
|
40
|
+
end
|
@@ -12,17 +12,26 @@ 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
|
22
|
+
end
|
23
|
+
|
24
|
+
def profile
|
25
|
+
Profile.new OpenSCAP.xccdf_policy_get_profile @raw
|
26
|
+
end
|
27
|
+
|
28
|
+
def selects_item? item_idref
|
29
|
+
OpenSCAP.xccdf_policy_is_item_selected @raw, item_idref
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
34
|
attach_function :xccdf_policy_get_id, [:pointer], :string
|
35
|
+
attach_function :xccdf_policy_get_profile, [:pointer], :pointer
|
36
|
+
attach_function :xccdf_policy_is_item_selected, %i[pointer string], :bool
|
28
37
|
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)
|
@@ -18,10 +18,18 @@ module OpenSCAP
|
|
18
18
|
"Cannot initialize OpenSCAP::Xccdf::PolicyModel with '#{b}'"
|
19
19
|
end
|
20
20
|
OpenSCAP.raise! if @raw.null?
|
21
|
+
|
22
|
+
begin
|
23
|
+
yield self
|
24
|
+
ensure
|
25
|
+
destroy
|
26
|
+
end if block_given?
|
21
27
|
end
|
22
28
|
|
23
29
|
def policies
|
24
|
-
@policies ||=
|
30
|
+
@policies ||= {}.tap do |policies|
|
31
|
+
each_policy { |p| policies[p.id] = p }
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
def destroy
|
@@ -29,19 +37,12 @@ module OpenSCAP
|
|
29
37
|
@raw = nil
|
30
38
|
end
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
def policies_init
|
35
|
-
policies = {}
|
40
|
+
def each_policy(&)
|
36
41
|
OpenSCAP.raise! unless OpenSCAP.xccdf_policy_model_build_all_useful_policies(raw).zero?
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
policy = OpenSCAP::Xccdf::Policy.new policy_p
|
41
|
-
policies[policy.id] = policy
|
42
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_policy_model_get_policies(@raw),
|
43
|
+
as: 'xccdf_policy' do |pointer|
|
44
|
+
yield OpenSCAP::Xccdf::Policy.new pointer
|
42
45
|
end
|
43
|
-
OpenSCAP.xccdf_policy_iterator_free polit
|
44
|
-
policies
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'openscap/text'
|
4
|
+
require_relative 'item_common'
|
4
5
|
|
5
6
|
module OpenSCAP
|
6
7
|
module Xccdf
|
7
8
|
class Profile
|
9
|
+
include ItemCommon
|
8
10
|
attr_reader :raw
|
9
11
|
|
10
|
-
def initialize
|
12
|
+
def initialize p
|
11
13
|
case p
|
12
14
|
when FFI::Pointer
|
13
15
|
@raw = p
|
@@ -16,19 +18,17 @@ module OpenSCAP
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
OpenSCAP.
|
21
|
+
def status_current
|
22
|
+
pointer = OpenSCAP.xccdf_profile_get_status_current @raw
|
23
|
+
Status.new pointer unless pointer.null?
|
21
24
|
end
|
22
25
|
|
23
|
-
def
|
24
|
-
|
25
|
-
title = textlist.plaintext(prefered_lang)
|
26
|
-
textlist.destroy
|
27
|
-
title
|
26
|
+
def abstract?
|
27
|
+
OpenSCAP.xccdf_profile_get_abstract @raw
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
attach_function :
|
33
|
-
attach_function :
|
32
|
+
attach_function :xccdf_profile_get_status_current, [:pointer], :pointer
|
33
|
+
attach_function :xccdf_profile_get_abstract, [:pointer], :bool
|
34
34
|
end
|
@@ -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 => title,
|
28
|
-
:href => href,
|
29
|
-
:html_link => 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,43 +1,58 @@
|
|
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
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
15
|
+
xccdf_level_not_defined: 'Not defined',
|
16
|
+
xccdf_unknown: 'Unknown',
|
17
|
+
xccdf_info: 'Info',
|
18
|
+
xccdf_low: 'Low',
|
19
|
+
xccdf_medium: 'Medium',
|
20
|
+
xccdf_high: 'High'
|
20
21
|
}
|
21
22
|
severity_mapping[severity] || severity_mapping[:xccdf_unknown]
|
22
23
|
end
|
23
24
|
|
25
|
+
def each_fix(&)
|
26
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_rule_get_fixes(@raw), as: 'xccdf_fix' do |pointer|
|
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
|
+
|
24
43
|
def fixes
|
25
|
-
fixes
|
26
|
-
|
27
|
-
|
28
|
-
|
44
|
+
@fixes ||= [].tap do |fixes|
|
45
|
+
each_fix do |fix|
|
46
|
+
fixes << fix
|
47
|
+
end
|
29
48
|
end
|
30
|
-
OpenSCAP.xccdf_fix_iterator_free items_it
|
31
|
-
fixes
|
32
49
|
end
|
33
50
|
|
34
51
|
def idents
|
35
52
|
idents = []
|
36
|
-
|
37
|
-
|
38
|
-
idents << OpenSCAP::Xccdf::Ident.new(OpenSCAP.xccdf_ident_iterator_next(idents_it))
|
53
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_rule_get_idents(@raw), as: 'xccdf_ident' do |pointer|
|
54
|
+
idents << OpenSCAP::Xccdf::Ident.new(pointer)
|
39
55
|
end
|
40
|
-
OpenSCAP.xccdf_ident_iterator_free idents_it
|
41
56
|
idents
|
42
57
|
end
|
43
58
|
end
|
@@ -56,6 +71,11 @@ module OpenSCAP
|
|
56
71
|
attach_function :xccdf_fix_iterator_next, [:pointer], :pointer
|
57
72
|
attach_function :xccdf_fix_iterator_free, [:pointer], :void
|
58
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
|
+
|
59
79
|
attach_function :xccdf_rule_get_idents, [:pointer], :pointer
|
60
80
|
attach_function :xccdf_ident_iterator_has_more, [:pointer], :bool
|
61
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,27 +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
|
-
:
|
21
|
-
:
|
22
|
-
}.merge
|
20
|
+
datastream_id: nil,
|
21
|
+
component_id: nil
|
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
|
-
|
34
|
-
raise OpenSCAPError, "No profile '" + p + "' found"
|
35
|
-
end
|
33
|
+
raise OpenSCAPError, "No profile '#{p}' found" unless OpenSCAP.xccdf_session_set_profile_id(@s, p)
|
36
34
|
end
|
37
35
|
|
38
36
|
def evaluate
|
@@ -45,19 +43,19 @@ module OpenSCAP
|
|
45
43
|
|
46
44
|
def export_results(opts = {})
|
47
45
|
o = {
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
}.merge!
|
46
|
+
rds_file: nil,
|
47
|
+
xccdf_file: nil,
|
48
|
+
report_file: nil,
|
49
|
+
oval_results: false,
|
50
|
+
oval_variables: false,
|
51
|
+
engines_results: false
|
52
|
+
}.merge! opts
|
55
53
|
export_targets o
|
56
54
|
export
|
57
55
|
end
|
58
56
|
|
59
57
|
def destroy
|
60
|
-
OpenSCAP.xccdf_session_free
|
58
|
+
OpenSCAP.xccdf_session_free @s
|
61
59
|
@s = nil
|
62
60
|
end
|
63
61
|
|
@@ -70,7 +68,7 @@ module OpenSCAP
|
|
70
68
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_export_arf(@s).zero?
|
71
69
|
end
|
72
70
|
|
73
|
-
def export_targets
|
71
|
+
def export_targets opts = {}
|
74
72
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_arf_export(@s, opts[:rds_file])
|
75
73
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_xccdf_export(@s, opts[:xccdf_file])
|
76
74
|
OpenSCAP.raise! unless OpenSCAP.xccdf_session_set_report_export(@s, opts[:report_file])
|
@@ -94,13 +92,13 @@ module OpenSCAP
|
|
94
92
|
|
95
93
|
attach_function :xccdf_session_is_sds, [:pointer], :bool
|
96
94
|
|
97
|
-
attach_function :xccdf_session_set_profile_id, [
|
98
|
-
attach_function :xccdf_session_set_datastream_id, [
|
99
|
-
attach_function :xccdf_session_set_component_id, [
|
100
|
-
attach_function :xccdf_session_set_arf_export, [
|
101
|
-
attach_function :xccdf_session_set_xccdf_export, [
|
102
|
-
attach_function :xccdf_session_set_report_export, [
|
103
|
-
attach_function :xccdf_session_set_oval_variables_export, [
|
104
|
-
attach_function :xccdf_session_set_oval_results_export, [
|
105
|
-
attach_function :xccdf_session_set_check_engine_plugins_results_export, [
|
95
|
+
attach_function :xccdf_session_set_profile_id, %i[pointer string], :bool
|
96
|
+
attach_function :xccdf_session_set_datastream_id, %i[pointer string], :void
|
97
|
+
attach_function :xccdf_session_set_component_id, %i[pointer string], :void
|
98
|
+
attach_function :xccdf_session_set_arf_export, %i[pointer string], :bool
|
99
|
+
attach_function :xccdf_session_set_xccdf_export, %i[pointer string], :bool
|
100
|
+
attach_function :xccdf_session_set_report_export, %i[pointer string], :bool
|
101
|
+
attach_function :xccdf_session_set_oval_variables_export, %i[pointer bool], :void
|
102
|
+
attach_function :xccdf_session_set_oval_results_export, %i[pointer bool], :void
|
103
|
+
attach_function :xccdf_session_set_check_engine_plugins_results_export, %i[pointer bool], :void
|
106
104
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenSCAP
|
4
|
+
module Xccdf
|
5
|
+
class Status
|
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 status
|
13
|
+
OpenSCAP.xccdf_status_get_status @raw
|
14
|
+
end
|
15
|
+
|
16
|
+
def date
|
17
|
+
unix_t = OpenSCAP.xccdf_status_get_date @raw
|
18
|
+
Time.at unix_t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
enum :xccdf_status_type_t, [
|
24
|
+
:not_specified, # empty value
|
25
|
+
:accepted,
|
26
|
+
:deprecated,
|
27
|
+
:draft,
|
28
|
+
:incomplete,
|
29
|
+
:interim
|
30
|
+
]
|
31
|
+
|
32
|
+
attach_function :xccdf_status_get_status, [:pointer], :xccdf_status_type_t
|
33
|
+
attach_function :xccdf_status_get_date, [:pointer], :time_t
|
34
|
+
end
|
@@ -19,31 +19,22 @@ 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
|
-
profit = OpenSCAP.xccdf_tailoring_get_profiles raw
|
35
|
-
while OpenSCAP.xccdf_profile_iterator_has_more profit
|
36
|
-
profile_p = OpenSCAP.xccdf_profile_iterator_next profit
|
37
|
-
profile = OpenSCAP::Xccdf::Profile.new profile_p
|
38
|
-
profiles[profile.id] = profile
|
39
|
-
end
|
40
|
-
OpenSCAP.xccdf_profile_iterator_free profit
|
41
|
-
profiles
|
42
|
-
end
|
43
34
|
end
|
44
35
|
end
|
45
36
|
|
46
|
-
attach_function :xccdf_tailoring_import_source, [
|
37
|
+
attach_function :xccdf_tailoring_import_source, %i[pointer pointer], :pointer
|
47
38
|
attach_function :xccdf_tailoring_free, [:pointer], :void
|
48
39
|
|
49
40
|
attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
|
@@ -8,10 +8,9 @@ require 'openscap/xccdf/ruleresult'
|
|
8
8
|
module OpenSCAP
|
9
9
|
module Xccdf
|
10
10
|
class TestResult
|
11
|
-
attr_reader :rr
|
12
|
-
attr_reader :raw
|
11
|
+
attr_reader :rr, :raw
|
13
12
|
|
14
|
-
def initialize
|
13
|
+
def initialize t
|
15
14
|
case t
|
16
15
|
when OpenSCAP::Source
|
17
16
|
@raw = OpenSCAP.xccdf_result_import_source(t.raw)
|
@@ -26,15 +25,23 @@ module OpenSCAP
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def id
|
29
|
-
OpenSCAP.xccdf_result_get_id
|
28
|
+
OpenSCAP.xccdf_result_get_id @raw
|
30
29
|
end
|
31
30
|
|
32
31
|
def profile
|
33
|
-
OpenSCAP.xccdf_result_get_profile
|
32
|
+
OpenSCAP.xccdf_result_get_profile @raw
|
34
33
|
end
|
35
34
|
|
36
35
|
def score
|
37
|
-
@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
|
38
45
|
end
|
39
46
|
|
40
47
|
def score!(benchmark)
|
@@ -58,28 +65,11 @@ module OpenSCAP
|
|
58
65
|
|
59
66
|
def init_ruleresults
|
60
67
|
@rr = {}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
rr = OpenSCAP::Xccdf::RuleResult.new rr_raw
|
68
|
+
OpenSCAP._iterate over: OpenSCAP.xccdf_result_get_rule_results(@raw),
|
69
|
+
as: 'xccdf_rule_result' do |pointer|
|
70
|
+
rr = OpenSCAP::Xccdf::RuleResult.new pointer
|
65
71
|
@rr[rr.id] = rr
|
66
72
|
end
|
67
|
-
OpenSCAP.xccdf_rule_result_iterator_free(rr_it)
|
68
|
-
end
|
69
|
-
|
70
|
-
def score_init
|
71
|
-
scores = {}
|
72
|
-
scorit = OpenSCAP.xccdf_result_get_scores(@raw)
|
73
|
-
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
|
74
|
-
s = OpenSCAP.xccdf_score_iterator_next(scorit)
|
75
|
-
scores[OpenSCAP.xccdf_score_get_system(s)] = {
|
76
|
-
:system => OpenSCAP.xccdf_score_get_system(s),
|
77
|
-
:value => OpenSCAP.xccdf_score_get_score(s),
|
78
|
-
:max => OpenSCAP.xccdf_score_get_maximum(s)
|
79
|
-
}
|
80
|
-
end
|
81
|
-
OpenSCAP.xccdf_score_iterator_free(scorit)
|
82
|
-
scores
|
83
73
|
end
|
84
74
|
end
|
85
75
|
end
|
@@ -88,8 +78,8 @@ module OpenSCAP
|
|
88
78
|
attach_function :xccdf_result_free, [:pointer], :void
|
89
79
|
attach_function :xccdf_result_get_id, [:pointer], :string
|
90
80
|
attach_function :xccdf_result_get_profile, [:pointer], :string
|
91
|
-
attach_function :xccdf_result_recalculate_scores, [
|
92
|
-
attach_function :xccdf_result_export_source, [
|
81
|
+
attach_function :xccdf_result_recalculate_scores, %i[pointer pointer], :int
|
82
|
+
attach_function :xccdf_result_export_source, %i[pointer string], :pointer
|
93
83
|
|
94
84
|
attach_function :xccdf_result_get_rule_results, [:pointer], :pointer
|
95
85
|
attach_function :xccdf_rule_result_iterator_has_more, [:pointer], :bool
|
data/lib/openscap/xccdf/value.rb
CHANGED