Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-11938) Handle more errors around Windows SID and ASID #9119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/puppet/util/windows/adsi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ def get_sids(adsi_child_collection)
sids = []
adsi_child_collection.each do |m|
sids << Puppet::Util::Windows::SID.ads_to_principal(m)
rescue Puppet::Util::Windows::Error => e
case e.code
when Puppet::Util::Windows::SID::ERROR_TRUSTED_RELATIONSHIP_FAILURE, Puppet::Util::Windows::SID::ERROR_TRUSTED_DOMAIN_FAILURE
sids << Puppet::Util::Windows::SID.unresolved_principal(m.name, m.sid)
else
raise e
end
end

sids
Expand Down
6 changes: 4 additions & 2 deletions lib/puppet/util/windows/sid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ module SID
extend FFI::Library

# missing from Windows::Error
ERROR_NONE_MAPPED = 1332
ERROR_INVALID_SID_STRUCTURE = 1337
ERROR_NONE_MAPPED = 1332
ERROR_INVALID_SID_STRUCTURE = 1337
ERROR_TRUSTED_DOMAIN_FAILURE = 1788
ERROR_TRUSTED_RELATIONSHIP_FAILURE = 1789

# Well Known SIDs
Null = 'S-1-0'
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/util/windows/adsi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@
end
end

describe '.get_sids' do
it 'returns an array of SIDs given two an array of ADSI children' do
child1 = double('child1', name: 'Administrator', sid: 'S-1-5-21-3882680660-671291151-3888264257-500')
child2 = double('child2', name: 'Guest', sid: 'S-1-5-21-3882680660-671291151-3888264257-501')
allow(Puppet::Util::Windows::SID).to receive(:ads_to_principal).with(child1).and_return('Administrator')
allow(Puppet::Util::Windows::SID).to receive(:ads_to_principal).with(child2).and_return('Guest')
sids = Puppet::Util::Windows::ADSI::ADSIObject.get_sids([child1, child2])
expect(sids).to eq(['Administrator', 'Guest'])
end

it 'returns an array of SIDs given an ADSI child and ads_to_principal returning domain failure' do
child = double('child1', name: 'Administrator', sid: 'S-1-5-21-3882680660-671291151-3888264257-500')
allow(Puppet::Util::Windows::SID).to receive(:ads_to_principal).with(child).and_raise(Puppet::Util::Windows::Error.new('', Puppet::Util::Windows::SID::ERROR_TRUSTED_DOMAIN_FAILURE))
sids = Puppet::Util::Windows::ADSI::ADSIObject.get_sids([child])
expect(sids[0]).to eq(Puppet::Util::Windows::SID::Principal.new(child.name, child.sid, child.name, nil, :SidTypeUnknown))
end

it 'returns an array of SIDs given an ADSI child and ads_to_principal returning relationship failure' do
child = double('child1', name: 'Administrator', sid: 'S-1-5-21-3882680660-671291151-3888264257-500')
allow(Puppet::Util::Windows::SID).to receive(:ads_to_principal).with(child).and_raise(Puppet::Util::Windows::Error.new('', Puppet::Util::Windows::SID::ERROR_TRUSTED_RELATIONSHIP_FAILURE))
sids = Puppet::Util::Windows::ADSI::ADSIObject.get_sids([child])
expect(sids[0]).to eq(Puppet::Util::Windows::SID::Principal.new(child.name, child.sid, child.name, nil, :SidTypeUnknown))
end
end

describe Puppet::Util::Windows::ADSI::User do
let(:username) { 'testuser' }
let(:domain) { 'DOMAIN' }
Expand Down