Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iptables resource: Add support for other bin paths #2783

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/resources/iptables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def retrieve_rules
return @iptables_cache if defined?(@iptables_cache)

# construct iptables command to read all rules
bin = find_iptables_or_error
table_cmd = "-t #{@table}" if @table
iptables_cmd = format('iptables %s -S %s', table_cmd, @chain).strip
iptables_cmd = format('%s %s -S %s', bin, table_cmd, @chain).strip

cmd = inspec.command(iptables_cmd)
return [] if cmd.exit_status.to_i != 0
Expand All @@ -65,5 +66,15 @@ def retrieve_rules
def to_s
format('Iptables %s %s', @table && "table: #{@table}", @chain && "chain: #{@chain}").strip
end

private

def find_iptables_or_error
%w{/usr/sbin/iptables /sbin/iptables iptables}.each do |cmd|
return cmd if inspec.command(cmd).exist?
end

raise Inspec::Exceptions::ResourceFailed, 'Could not find `iptables`'
end
end
end
3 changes: 2 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ def md.directory?
# apt
"find /etc/apt/ -name *.list -exec sh -c 'cat {} || echo -n' \\;" => cmd.call('etc-apt'),
# iptables
'iptables -S' => cmd.call('iptables-s'),
'/usr/sbin/iptables -S' => cmd.call('iptables-s'),
%{bash -c 'type "/usr/sbin/iptables"'} => empty.call,
# apache_conf
"sh -c 'find /etc/apache2/ports.conf -type f -maxdepth 1'" => cmd.call('find-apache2-ports-conf'),
"sh -c 'find /etc/httpd/conf.d/*.conf -type f -maxdepth 1'" => cmd.call('find-httpd-ssl-conf'),
Expand Down