diff options
author | Vasu1105 <vasundhara.jagdale@msystechnologies.com> | 2020-02-26 01:19:01 -0800 |
---|---|---|
committer | Vasu1105 <vasundhara.jagdale@msystechnologies.com> | 2020-02-26 01:39:52 -0800 |
commit | 11a63c5b61ca1d703b368ddc1caecd7f16fc7e9c (patch) | |
tree | 53a0cd66b49b0f7e29fe582ef41c8c6ee7d3d230 /lib/chef/win32 | |
parent | ed559f9687b830648ae6a96d76a040c1fbeef284 (diff) | |
download | chef-11a63c5b61ca1d703b368ddc1caecd7f16fc7e9c.tar.gz |
More optimization of code and updated get_account_with_user_rights to return account_name with domain
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
Diffstat (limited to 'lib/chef/win32')
-rw-r--r-- | lib/chef/win32/security.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 2879131210..2c0f63684a 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -227,15 +227,19 @@ class Chef accounts = [] with_lsa_policy(nil) do |policy_handle, sid| result = LsaEnumerateAccountsWithUserRight(policy_handle.read_pointer, privilege_pointer, buffer, count) - win32_error = LsaNtStatusToWinError(result) - return [] if win32_error == 1313 # NO_SUCH_PRIVILEGE - https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- - - test_and_raise_lsa_nt_status(result) - - count.read_ulong.times do |i| - sid = LSA_ENUMERATION_INFORMATION.new(buffer.read_pointer + i * LSA_ENUMERATION_INFORMATION.size) - sid_name = lookup_account_sid(sid[:Sid]) - accounts << sid_name + if result == 0 + win32_error = LsaNtStatusToWinError(result) + return [] if win32_error == 1313 # NO_SUCH_PRIVILEGE - https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- + + test_and_raise_lsa_nt_status(result) + + count.read_ulong.times do |i| + sid = LSA_ENUMERATION_INFORMATION.new(buffer.read_pointer + i * LSA_ENUMERATION_INFORMATION.size) + sid_name = lookup_account_sid(sid[:Sid]) + domain, name, use = sid_name + account_name = (!domain.nil? && domain.length > 0) ? "#{domain}\\#{name}" : name + accounts << account_name + end end result = LsaFreeMemory(buffer.read_pointer) |