add inetd resource

This commit is contained in:
Christoph Hartmann 2015-07-26 12:53:29 +02:00
parent 17476fd634
commit 32c4575642
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,44 @@
# encoding: utf-8
# copyright: 2015, Vulcano Security GmbH
# license: All rights reserved
require 'utils/simpleconfig'
class InetdConf < Vulcano::Resource
def initialize
@runner = Specinfra::Runner
@conf_path = '/etc/inetd.conf'
@files_contents = {}
@content = nil
@params = nil
read_content
end
def method_missing name
@params || read_content
@params[name.to_s]
end
def read_content
# read the file
if !@runner.check_file_is_file(@conf_path)
return skip_resource "Can't find file \"#{@conf_path}\""
end
@content = read_file(@conf_path)
if @content.empty? && @runner.get_file_size(@conf_path).stdout.strip.to_i > 0
return skip_resource "Can't read file \"#{@conf_path}\""
end
# parse the file
@params = SimpleConfig.new(@content,
assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
key_vals: 6,
multiple_values: false
).params
@content
end
def read_file(path)
@files_contents[path] ||= @runner.get_file_content(path).stdout
end
end

View file

@ -8,6 +8,7 @@ require 'resources/env'
require 'resources/etc_group'
require 'resources/file'
require 'resources/group_policy'
require 'resources/inetd_conf'
require 'resources/limits_conf'
require 'resources/login_def'
require 'resources/mysql_conf'
@ -47,6 +48,10 @@ module Serverspec
GroupPolicy.new(policy_path)
end
def inetd_conf()
InetdConf.new()
end
def limits_conf()
LimitsConf.new()
end