2015-07-26 12:53:29 +02:00
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
require 'utils/simpleconfig'
2018-03-22 21:25:45 +09:00
require 'utils/file_reader'
2015-07-26 12:53:29 +02:00
2016-03-08 13:06:55 -05:00
module Inspec::Resources
class InetdConf < Inspec . resource ( 1 )
name 'inetd_conf'
2018-02-19 06:26:49 -08:00
supports platform : 'unix'
2016-03-08 13:06:55 -05:00
desc 'Use the inetd_conf InSpec audit resource to test if a service is enabled in the inetd.conf file on Linux and UNIX platforms. inetd---the Internet service daemon---listens on dedicated ports, and then loads the appropriate program based on a request. The inetd.conf file is typically located at /etc/inetd.conf and contains a list of Internet services associated to the ports on which that service will listen. Only enabled services may handle a request; only services that are required by the system should be enabled.'
example "
describe inetd_conf do
its ( 'shell' ) { should eq nil }
its ( 'login' ) { should eq nil }
its ( 'exec' ) { should eq nil }
end
"
2018-03-22 21:25:45 +09:00
include FileReader
2016-03-08 13:06:55 -05:00
def initialize ( path = nil )
@conf_path = path || '/etc/inetd.conf'
2018-03-22 21:25:45 +09:00
@content = read_file_content ( @conf_path )
2015-11-27 14:02:38 +01:00
end
2015-07-26 12:53:29 +02:00
2016-10-27 13:49:06 +02:00
# overwrite exec to ensure it works with its
# TODO: this needs to be fixed in RSpec
def exec
read_params [ 'exec' ]
end
2016-03-08 13:06:55 -05:00
def method_missing ( name )
read_params [ name . to_s ]
2015-07-26 12:53:29 +02:00
end
2015-09-17 12:37:39 +02:00
2016-03-08 13:06:55 -05:00
def read_params
return @params if defined? ( @params )
# parse the file
conf = SimpleConfig . new (
2018-03-22 21:25:45 +09:00
@content ,
2017-04-26 23:18:14 +02:00
assignment_regex : / ^ \ s*( \ S+?) \ s+(.*?) \ s+(.*?) \ s+(.*?) \ s+(.*?) \ s+(.*?) \ s+(.*?) \ s*$ / ,
key_values : 6 ,
2016-03-08 13:06:55 -05:00
multiple_values : false ,
)
@params = conf . params
2015-07-26 12:53:29 +02:00
end
2015-10-12 13:01:58 +02:00
2016-03-08 13:06:55 -05:00
def to_s
'inetd.conf'
end
2015-10-12 13:01:58 +02:00
end
2015-08-02 17:40:08 -07:00
end