mirror of
https://github.com/inspec/inspec
synced 2024-11-15 01:17:08 +00:00
3bf8037638
This has been inspired in its calling structure by the wonderful work done in Vagrant. Kudos to all contributors! Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
66 lines
1.3 KiB
Ruby
66 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
# copyright: 2015, Vulcano Security GmbH
|
|
# license: All rights reserved
|
|
|
|
require 'utils/simpleconfig'
|
|
|
|
class SshConf < Vulcano.resource(1)
|
|
name 'ssh_config'
|
|
|
|
def initialize( conf_path = nil, type = nil )
|
|
@conf_path = conf_path || '/etc/ssh/ssh_conf'
|
|
@conf_dir = File.expand_path(File.dirname @conf_path)
|
|
@conf = nil
|
|
@params = {}
|
|
typename = ( @conf_path.include?('sshd') ? 'Server' : 'Client' )
|
|
@type = type || "SSH #{typename} configuration #{conf_path}"
|
|
read_content
|
|
end
|
|
|
|
def to_s
|
|
@type
|
|
end
|
|
|
|
def content
|
|
@conf.contents
|
|
end
|
|
|
|
def params *opts
|
|
res = @params
|
|
opts.each do |opt|
|
|
res = res[opt] unless res.nil?
|
|
end
|
|
res
|
|
end
|
|
|
|
def method_missing name
|
|
@params[name.to_s]
|
|
end
|
|
|
|
def read_content
|
|
@conf = @vulcano.file(@conf_path)
|
|
# read the file
|
|
if !@conf.is_file?
|
|
return skip_resource "Can't find file \"#{@conf_path}\""
|
|
end
|
|
|
|
if @conf.contents.empty? && @conf.size > 0
|
|
return skip_resource "Can't read file \"#{@conf_path}\""
|
|
end
|
|
|
|
# parse the file
|
|
@params = SimpleConfig.new(@conf.contents,
|
|
assignment_re: /^\s*(\S+?)\s+(.*?)\s*$/,
|
|
multiple_values: false
|
|
).params
|
|
end
|
|
|
|
end
|
|
|
|
class SshdConf < SshConf
|
|
name 'sshd_config'
|
|
|
|
def initialize(path = nil)
|
|
super(path || '/etc/ssh/sshd_config')
|
|
end
|
|
end
|