Skip to content

Commit bea9ff7

Browse files
committed
(maint) Add debug messages for silently catched errors
This commit adds a debug message where errors (in the `Puppet::Util::Windows::SID::name_to_principal` method) were caught silently and increased dificulty in debugging said code (`Puppet::Util::Windows::SID::Principal::lookup_account_name` in particular).
1 parent 4be7016 commit bea9ff7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/puppet/util/windows/sid.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ def name_to_principal(name, allow_unresolved = false)
7474
string_to_sid_ptr(name) do |sid_ptr|
7575
raw_sid_bytes = sid_ptr.read_array_of_uchar(get_length_sid(sid_ptr))
7676
end
77-
rescue
77+
rescue => e
78+
Puppet.debug("Could not retrieve raw SID bytes from '#{name}': #{e.message}")
7879
end
7980

8081
raw_sid_bytes ? Principal.lookup_account_sid(raw_sid_bytes) : Principal.lookup_account_name(name)
81-
rescue
82+
rescue => e
83+
Puppet.debug("#{e.message}")
8284
(allow_unresolved && raw_sid_bytes) ? unresolved_principal(name, raw_sid_bytes) : nil
8385
end
8486
module_function :name_to_principal

spec/unit/util/windows/sid_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@
158158
# this works in French Windows, even though the account is really AUTORITE NT\\Syst\u00E8me
159159
expect(subject.name_to_principal('NT AUTHORITY\SYSTEM').sid).to eq(sid)
160160
end
161+
162+
it "should print a debug message on failures" do
163+
expect(Puppet).to receive(:debug).with(/Could not retrieve raw SID bytes from 'NonExistingUser'/)
164+
expect(Puppet).to receive(:debug).with(/No mapping between account names and security IDs was done/)
165+
subject.name_to_principal('NonExistingUser')
166+
end
161167
end
162168

163169
context "#ads_to_principal" do

0 commit comments

Comments
 (0)