Method: Inspec::Resources::UnixFilePermissions#check_file_permission_by_user

Defined in:
lib/resources/file.rb

#check_file_permission_by_user(access_type, user, path) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/resources/file.rb', line 191

def check_file_permission_by_user(access_type, user, path)
  flag = permission_flag(access_type)
  if inspec.os.linux?
    perm_cmd = "su -s /bin/sh -c \"test -#{flag} #{path}\" #{user}"
  elsif inspec.os.bsd? || inspec.os.solaris?
    perm_cmd = "sudo -u #{user} test -#{flag} #{path}"
  elsif inspec.os.aix?
    perm_cmd = "su #{user} -c test -#{flag} #{path}"
  elsif inspec.os.hpux?
    perm_cmd = "su #{user} -c \"test -#{flag} #{path}\""
  else
    return skip_resource 'The `file` resource does not support `by_user` on your OS.'
  end

  cmd = inspec.command(perm_cmd)
  cmd.exit_status == 0 ? true : false
end