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

win_group_membership - fix random issue with CI on 2012 R2 #45462

Merged
merged 1 commit into from
Sep 11, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/win_group_membership-com-marshal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- win_group_membership - fix intermittent issue where it failed to convert the ADSI object to the .NET object after using it once
24 changes: 16 additions & 8 deletions lib/ansible/modules/windows/win_group_membership.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ function Get-GroupMember {
[System.DirectoryServices.DirectoryEntry]$Group
)

$members = @()

$current_members = $Group.psbase.Invoke("Members") | ForEach-Object {
$bytes = ([ADSI]$_).InvokeGet("objectSID")
$sid = New-Object -TypeName Security.Principal.SecurityIdentifier -ArgumentList $bytes, 0
$adspath = ([ADSI]$_).InvokeGet("ADsPath")

@{sid = $sid; adspath = $adspath} | Write-Output
# instead of using ForEach pipeline we use a standard loop and cast the
# object to the ADSI adapter type before using it to get the SID and path
# this solves an random issue where multiple casts could fail once the raw
# object is invoked at least once
$raw_members = $Group.psbase.Invoke("Members")
$current_members = [System.Collections.ArrayList]@()
foreach ($raw_member in $raw_members) {
$raw_member = [ADSI]$raw_member
$sid_bytes = $raw_member.InvokeGet("objectSID")
$ads_path = $raw_member.InvokeGet("ADsPath")
$member_info = @{
sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList $sid_bytes, 0
adspath = $ads_path
}
$current_members.Add($member_info) > $null
}

$members = @()
foreach ($current_member in $current_members) {
$parsed_member = @{
sid = $current_member.sid
Expand Down