-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtailoring.rb
More file actions
53 lines (44 loc) · 1.5 KB
/
tailoring.rb
File metadata and controls
53 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
require 'openscap/source'
require 'openscap/xccdf/profile'
module OpenSCAP
module Xccdf
class Tailoring
attr_reader :raw
def initialize(source, benchmark)
case source
when OpenSCAP::Source
@raw = OpenSCAP.xccdf_tailoring_import_source source.raw, benchmark
else
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{source}'"
end
OpenSCAP.raise! if @raw.null?
end
def profiles
@profiles ||= profiles_init
end
def destroy
OpenSCAP.xccdf_tailoring_free @raw
@raw = nil
end
private
def profiles_init
profiles = {}
profit = OpenSCAP.xccdf_tailoring_get_profiles raw
while OpenSCAP.xccdf_profile_iterator_has_more profit
profile_p = OpenSCAP.xccdf_profile_iterator_next profit
profile = OpenSCAP::Xccdf::Profile.new profile_p
profiles[profile.id] = profile
end
OpenSCAP.xccdf_profile_iterator_free profit
profiles
end
end
end
attach_function :xccdf_tailoring_import_source, %i[pointer pointer], :pointer
attach_function :xccdf_tailoring_free, [:pointer], :void
attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer
attach_function :xccdf_profile_iterator_has_more, [:pointer], :bool
attach_function :xccdf_profile_iterator_next, [:pointer], :pointer
attach_function :xccdf_profile_iterator_free, [:pointer], :void
end