diff --git a/lib/resources/xinetd.rb b/lib/resources/xinetd.rb index c7064e118..473768800 100644 --- a/lib/resources/xinetd.rb +++ b/lib/resources/xinetd.rb @@ -66,17 +66,26 @@ module Inspec::Resources def read_params return {} if read_content.nil? flat_params = parse_xinetd(read_content) + # we need to map service data in order to use it with filtertable params = { 'services' => {} } - # parse services that were defined: + # map services that were defined and map it to the service hash flat_params.each do |k, v| name = k[/^service (.+)$/, 1] + # its not a service, no change required if name.nil? params[k] = v + # handle service entries else + # store service params['services'][name] = v + # add the service identifier to its parameters - v.each { |service| service.params['service'] = name } + if v.is_a?(Array) + v.each { |service| service.params['service'] = name } + else + v.params['service'] = name + end end end params diff --git a/lib/utils/parser.rb b/lib/utils/parser.rb index 513de5c7e..7ab91b4c8 100644 --- a/lib/utils/parser.rb +++ b/lib/utils/parser.rb @@ -179,6 +179,7 @@ module SolarisNetstatParser end end +# This parser for xinetd (extended Internet daemon) configuration files module XinetdParser def xinetd_include_dir(dir) return [] if dir.nil? @@ -198,10 +199,12 @@ module XinetdParser simple_conf = [] rest = raw until rest.empty? + # extract content line nl = rest.index("\n") || (rest.length-1) comment = rest.index('#') || (rest.length-1) dst_idx = (comment < nl) ? comment : nl inner_line = (dst_idx == 0) ? '' : rest[0..dst_idx-1].strip + # update unparsed content rest = rest[nl+1..-1] next if inner_line.empty? @@ -213,6 +216,7 @@ module XinetdParser simple_conf = [] rest = rest[rest.index("\n")+1..-1] elsif cur_group.nil? + # parse all included files others = xinetd_include_dir(inner_line[/includedir (.+)/, 1]) # complex merging of included configurations, as multiple services diff --git a/test/unit/resources/xinetd_test.rb b/test/unit/resources/xinetd_test.rb index e17a82adc..7fee622e7 100644 --- a/test/unit/resources/xinetd_test.rb +++ b/test/unit/resources/xinetd_test.rb @@ -57,4 +57,13 @@ describe 'Inspec::Resources::XinetdConf' do _(resource.enabled?).must_equal false end end + + describe 'with single services and no child configs' do + let (:resource) { load_resource('xinetd_conf', '/etc/xinetd.d/chargen-stream') } + + it 'checks if all are disabled on one disabled service' do + one = resource.ids('chargen-stream') + _(one.disabled?).must_equal true + end + end end