Skip to content

Commit bf791a1

Browse files
authored
Merge pull request #12 from ianwatsonrh/master
adding ident support for getting CVE names and urls
2 parents e7e0be4 + f2dec8e commit bf791a1

File tree

4 files changed

+275258
-0
lines changed

4 files changed

+275258
-0
lines changed

lib/openscap/xccdf/ident.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
#
11+
12+
module OpenSCAP
13+
module Xccdf
14+
class Ident
15+
def initialize(raw)
16+
raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{raw}'" \
17+
unless raw.is_a?(FFI::Pointer)
18+
@raw = raw
19+
end
20+
21+
def system
22+
OpenSCAP.xccdf_ident_get_system(@raw)
23+
end
24+
25+
def id
26+
OpenSCAP.xccdf_ident_get_id(@raw)
27+
end
28+
end
29+
end
30+
attach_function :xccdf_ident_get_system, [:pointer], :string
31+
attach_function :xccdf_ident_get_id, [:pointer], :string
32+
end

lib/openscap/xccdf/rule.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require 'openscap/exceptions'
1313
require 'openscap/xccdf/item'
1414
require 'openscap/xccdf/fix'
15+
require 'openscap/xccdf/ident'
1516

1617
module OpenSCAP
1718
module Xccdf
@@ -38,6 +39,17 @@ def fixes
3839
OpenSCAP.xccdf_fix_iterator_free items_it
3940
fixes
4041
end
42+
43+
def idents
44+
idenss = []
45+
idenss_it = OpenSCAP.xccdf_rule_get_idents(@raw)
46+
while OpenSCAP.xccdf_ident_iterator_has_more idenss_it
47+
idens = OpenSCAP::Xccdf::Ident.new(OpenSCAP.xccdf_ident_iterator_next(idenss_it))
48+
idenss << idens
49+
end
50+
OpenSCAP.xccdf_ident_iterator_free idenss_it
51+
idenss
52+
end
4153
end
4254
end
4355
XccdfSeverity = enum(
@@ -53,4 +65,9 @@ def fixes
5365
attach_function :xccdf_fix_iterator_has_more, [:pointer], :bool
5466
attach_function :xccdf_fix_iterator_next, [:pointer], :pointer
5567
attach_function :xccdf_fix_iterator_free, [:pointer], :void
68+
69+
attach_function :xccdf_rule_get_idents, [:pointer], :pointer
70+
attach_function :xccdf_ident_iterator_has_more, [:pointer], :bool
71+
attach_function :xccdf_ident_iterator_next, [:pointer], :pointer
72+
attach_function :xccdf_ident_iterator_free, [:pointer], :void
5673
end

0 commit comments

Comments
 (0)