class Inspec::Resources::XinetdConf
Public Class Methods
new(conf_path = "/etc/xinetd.conf")
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 23 def initialize(conf_path = "/etc/xinetd.conf") @conf_path = conf_path @contents = {} read_content(@conf_path) end
Public Instance Methods
params()
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 33 def params @params ||= read_params end
to_s()
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 29 def to_s "Xinetd config #{@conf_path}#{@filters}" end
Private Instance Methods
default_protocol(type)
click to toggle source
Method used to derive the default protocol used from the socket_type
# File lib/inspec/resources/xinetd_conf.rb, line 85 def default_protocol(type) case type when "stream" "tcp" when "dgram" "udp" else "unknown" end end
read_content(path = @conf_path)
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 50 def read_content(path = @conf_path) return @contents[path] if @contents.key?(path) @contents[path] = read_file_content(path) end
read_params()
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 56 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" => {} } # 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 if v.is_a?(Array) v.each { |service| service.params["service"] = name } else v.params["service"] = name end end end params end
service_lines()
click to toggle source
# File lib/inspec/resources/xinetd_conf.rb, line 96 def service_lines @services ||= params["services"].values.flatten.map do |service| service.params["protocol"] ||= default_protocol(service.params["socket_type"]) service.params end end