mirror of
https://github.com/inspec/inspec
synced 2025-01-05 09:49:02 +00:00
Merge pull request #846 from chef/chris-rock/fix-xinetd-single-entry
Handle xinetd config with only one entry
This commit is contained in:
commit
968e87b6e3
3 changed files with 24 additions and 2 deletions
|
@ -66,17 +66,26 @@ module Inspec::Resources
|
||||||
def read_params
|
def read_params
|
||||||
return {} if read_content.nil?
|
return {} if read_content.nil?
|
||||||
flat_params = parse_xinetd(read_content)
|
flat_params = parse_xinetd(read_content)
|
||||||
|
# we need to map service data in order to use it with filtertable
|
||||||
params = { 'services' => {} }
|
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|
|
flat_params.each do |k, v|
|
||||||
name = k[/^service (.+)$/, 1]
|
name = k[/^service (.+)$/, 1]
|
||||||
|
# its not a service, no change required
|
||||||
if name.nil?
|
if name.nil?
|
||||||
params[k] = v
|
params[k] = v
|
||||||
|
# handle service entries
|
||||||
else
|
else
|
||||||
|
# store service
|
||||||
params['services'][name] = v
|
params['services'][name] = v
|
||||||
|
|
||||||
# add the service identifier to its parameters
|
# 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
|
||||||
end
|
end
|
||||||
params
|
params
|
||||||
|
|
|
@ -179,6 +179,7 @@ module SolarisNetstatParser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This parser for xinetd (extended Internet daemon) configuration files
|
||||||
module XinetdParser
|
module XinetdParser
|
||||||
def xinetd_include_dir(dir)
|
def xinetd_include_dir(dir)
|
||||||
return [] if dir.nil?
|
return [] if dir.nil?
|
||||||
|
@ -198,10 +199,12 @@ module XinetdParser
|
||||||
simple_conf = []
|
simple_conf = []
|
||||||
rest = raw
|
rest = raw
|
||||||
until rest.empty?
|
until rest.empty?
|
||||||
|
# extract content line
|
||||||
nl = rest.index("\n") || (rest.length-1)
|
nl = rest.index("\n") || (rest.length-1)
|
||||||
comment = rest.index('#') || (rest.length-1)
|
comment = rest.index('#') || (rest.length-1)
|
||||||
dst_idx = (comment < nl) ? comment : nl
|
dst_idx = (comment < nl) ? comment : nl
|
||||||
inner_line = (dst_idx == 0) ? '' : rest[0..dst_idx-1].strip
|
inner_line = (dst_idx == 0) ? '' : rest[0..dst_idx-1].strip
|
||||||
|
# update unparsed content
|
||||||
rest = rest[nl+1..-1]
|
rest = rest[nl+1..-1]
|
||||||
next if inner_line.empty?
|
next if inner_line.empty?
|
||||||
|
|
||||||
|
@ -213,6 +216,7 @@ module XinetdParser
|
||||||
simple_conf = []
|
simple_conf = []
|
||||||
rest = rest[rest.index("\n")+1..-1]
|
rest = rest[rest.index("\n")+1..-1]
|
||||||
elsif cur_group.nil?
|
elsif cur_group.nil?
|
||||||
|
# parse all included files
|
||||||
others = xinetd_include_dir(inner_line[/includedir (.+)/, 1])
|
others = xinetd_include_dir(inner_line[/includedir (.+)/, 1])
|
||||||
|
|
||||||
# complex merging of included configurations, as multiple services
|
# complex merging of included configurations, as multiple services
|
||||||
|
|
|
@ -57,4 +57,13 @@ describe 'Inspec::Resources::XinetdConf' do
|
||||||
_(resource.enabled?).must_equal false
|
_(resource.enabled?).must_equal false
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue