mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
add limits.conf resource
This commit is contained in:
parent
8e16decccd
commit
17476fd634
3 changed files with 69 additions and 2 deletions
44
lib/resources/limits_conf.rb
Normal file
44
lib/resources/limits_conf.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
# copyright: 2015, Vulcano Security GmbH
|
||||||
|
# license: All rights reserved
|
||||||
|
|
||||||
|
require 'utils/simpleconfig'
|
||||||
|
|
||||||
|
class LimitsConf < Vulcano::Resource
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@runner = Specinfra::Runner
|
||||||
|
@conf_path = '/etc/security/limits.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*$/,
|
||||||
|
key_vals: 3,
|
||||||
|
multiple_values: true
|
||||||
|
).params
|
||||||
|
@content
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_file(path)
|
||||||
|
@files_contents[path] ||= @runner.get_file_content(path).stdout
|
||||||
|
end
|
||||||
|
end
|
|
@ -8,6 +8,7 @@ require 'resources/env'
|
||||||
require 'resources/etc_group'
|
require 'resources/etc_group'
|
||||||
require 'resources/file'
|
require 'resources/file'
|
||||||
require 'resources/group_policy'
|
require 'resources/group_policy'
|
||||||
|
require 'resources/limits_conf'
|
||||||
require 'resources/login_def'
|
require 'resources/login_def'
|
||||||
require 'resources/mysql_conf'
|
require 'resources/mysql_conf'
|
||||||
require 'resources/mysql_session'
|
require 'resources/mysql_session'
|
||||||
|
@ -46,6 +47,10 @@ module Serverspec
|
||||||
GroupPolicy.new(policy_path)
|
GroupPolicy.new(policy_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def limits_conf()
|
||||||
|
LimitsConf.new()
|
||||||
|
end
|
||||||
|
|
||||||
def login_def()
|
def login_def()
|
||||||
LoginDef.new()
|
LoginDef.new()
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,23 @@ class SimpleConfig
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def parse_values (match, values)
|
||||||
|
start_idx = 2
|
||||||
|
i = 0
|
||||||
|
count = values - 1
|
||||||
|
if (values == 1) then
|
||||||
|
return match[start_idx]
|
||||||
|
else
|
||||||
|
# iterate over expected parameters
|
||||||
|
values = Array.new
|
||||||
|
begin
|
||||||
|
values.push(match[start_idx+i])
|
||||||
|
i +=1;
|
||||||
|
end until i > count
|
||||||
|
return values
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def parse_rest( rest, opts )
|
def parse_rest( rest, opts )
|
||||||
idx_nl = rest.index("\n")
|
idx_nl = rest.index("\n")
|
||||||
idx_comment = rest.index('#')
|
idx_comment = rest.index('#')
|
||||||
|
@ -56,9 +73,9 @@ class SimpleConfig
|
||||||
if !m.nil?
|
if !m.nil?
|
||||||
if opts[:multiple_values]
|
if opts[:multiple_values]
|
||||||
@params[m[1]] ||= []
|
@params[m[1]] ||= []
|
||||||
@params[m[1]].push(m[2])
|
@params[m[1]].push(parse_values(m, opts[:key_vals]))
|
||||||
else
|
else
|
||||||
@params[m[1]] = m[2]
|
@params[m[1]] = parse_values(m, opts[:key_vals])
|
||||||
end
|
end
|
||||||
elsif !is_empty_line(line)
|
elsif !is_empty_line(line)
|
||||||
if opts[:multiple_values]
|
if opts[:multiple_values]
|
||||||
|
@ -82,6 +99,7 @@ class SimpleConfig
|
||||||
multiline: false,
|
multiline: false,
|
||||||
comment_char: '#',
|
comment_char: '#',
|
||||||
assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
|
assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
|
||||||
|
key_vals: 1, # default for key=value, may require for 'key val1 val2 val3'
|
||||||
standalone_comments: false,
|
standalone_comments: false,
|
||||||
multiple_values: true
|
multiple_values: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue