auditd resource: Add handling for sudo/no command (#3151)

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich 2018-06-20 18:27:53 -07:00 committed by Jared Quick
parent 81d0423ee0
commit cf9ce1bfdc
2 changed files with 18 additions and 2 deletions

View file

@ -30,11 +30,26 @@ module Inspec::Resources
"
def initialize
@content = inspec.command('/sbin/auditctl -l').stdout.chomp
unless inspec.command('/sbin/auditctl').exist?
raise Inspec::Exceptions::ResourceFailed,
'Command `/sbin/auditctl` does not exist'
end
auditctl_cmd = '/sbin/auditctl -l'
result = inspec.command(auditctl_cmd)
if result.exit_status != 0
raise Inspec::Exceptions::ResourceFailed,
"Command `#{auditctl_cmd}` failed with error: #{result.stderr}"
end
@content = result.stdout
@params = []
if @content =~ /^LIST_RULES:/
return skip_resource 'The version of audit is outdated. The `auditd` resource supports versions of audit >= 2.3.5'
raise Inspec::Exceptions::RsourceFailed,
'The version of audit is outdated.' \
'The `auditd` resource supports versions of audit >= 2.3.'
end
parse_content
end

View file

@ -218,6 +218,7 @@ class MockLoader
'bash -c \'type "/test/path/pip"\'' => empty.call,
'bash -c \'type "Rscript"\'' => empty.call,
'bash -c \'type "perl"\'' => empty.call,
'bash -c \'type "/sbin/auditctl"\'' => empty.call,
'type "pwsh"' => empty.call,
'type "netstat"' => empty.call,
'sh -c \'find /etc/apache2/ports.conf -type l -maxdepth 1\'' => empty.call,