mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
remove os check exposure in file resource
This commit is contained in:
parent
52b42efb41
commit
4c1b6f7509
1 changed files with 6 additions and 20 deletions
|
@ -90,7 +90,9 @@ module Inspec::Resources
|
||||||
private
|
private
|
||||||
|
|
||||||
def file_permission_granted?(flag, by_usergroup, by_specific_user)
|
def file_permission_granted?(flag, by_usergroup, by_specific_user)
|
||||||
fail 'Checking file permissions is not supported on your os' unless unix?
|
unless inspec.os.unix?
|
||||||
|
fail 'Checking file permissions is not supported on your os'
|
||||||
|
end
|
||||||
|
|
||||||
if by_specific_user.nil? || by_specific_user.empty?
|
if by_specific_user.nil? || by_specific_user.empty?
|
||||||
usergroup = usergroup_for(by_usergroup, by_specific_user)
|
usergroup = usergroup_for(by_usergroup, by_specific_user)
|
||||||
|
@ -108,11 +110,11 @@ module Inspec::Resources
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_file_permission_by_user(user, flag)
|
def check_file_permission_by_user(user, flag)
|
||||||
if linux?
|
if inspec.os.linux?
|
||||||
perm_cmd = "su -s /bin/sh -c \"test -#{flag} #{path}\" #{user}"
|
perm_cmd = "su -s /bin/sh -c \"test -#{flag} #{path}\" #{user}"
|
||||||
elsif family == 'freebsd' || solaris?
|
elsif inspec.os.bsd? || inspec.os.solaris?
|
||||||
perm_cmd = "sudo -u #{user} test -#{flag} #{path}"
|
perm_cmd = "sudo -u #{user} test -#{flag} #{path}"
|
||||||
elsif family == 'aix'
|
elsif inspec.os.aix?
|
||||||
perm_cmd = "su #{user} -c test -#{flag} #{path}"
|
perm_cmd = "su #{user} -c test -#{flag} #{path}"
|
||||||
else
|
else
|
||||||
return skip_resource 'The `file` resource does not support `by_user` on your OS.'
|
return skip_resource 'The `file` resource does not support `by_user` on your OS.'
|
||||||
|
@ -131,21 +133,5 @@ module Inspec::Resources
|
||||||
usergroup
|
usergroup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unix?
|
|
||||||
inspec.os.unix?
|
|
||||||
end
|
|
||||||
|
|
||||||
def linux?
|
|
||||||
inspec.os.linux?
|
|
||||||
end
|
|
||||||
|
|
||||||
def solaris?
|
|
||||||
inspec.os.solaris?
|
|
||||||
end
|
|
||||||
|
|
||||||
def family
|
|
||||||
inspec.os[:family]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue