CFINSPEC-94: encrypted_password works with getent utility on BSD/Solaris

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-03-28 16:34:35 +05:30
parent 96103a8785
commit 6dfa1e23db

View file

@ -374,10 +374,10 @@ module Inspec::Resources
# Helper method for encrypted_password property
def encrypted_password_info
# Todo:
# [-] Linux
# [-] BSD
# [+] Linux
# [+] BSD: works same as linux; using getent
# [-] Check if feasible on: Darwin, hpux, and aix
bin = 'getent'
bin = find_getent_or_equiv_utility
cmd = inspec.command("#{bin} passwd #{@username}")
raise Inspec::Exceptions::ResourceSkipped, "Cannot view encrypted_password information" if cmd.exit_status != 0
@ -385,6 +385,14 @@ module Inspec::Resources
shadow_info = cmd.stdout.split(":").map(&:strip)
shadow_info[1]
end
def find_getent_or_equiv_utility
%w{/usr/bin/getent /bin/getent getent}.each do |cmd|
return cmd if inspec.command(cmd).exist?
end
raise Inspec::Exceptions::ResourceFailed, "Could not find `getent`"
end
end
# Class defined to compare for groups without case-sensitivity