win_acl_inheritance - fix glob like paths (#53829)

This commit is contained in:
Jordan Borean 2019-03-15 14:57:59 +10:00 committed by GitHub
commit 3cfa71bff0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 94 deletions

View file

@ -16,12 +16,12 @@ $path = Get-AnsibleParam -obj $params "path" -type "path" -failifempty $true
$state = Get-AnsibleParam -obj $params "state" -type "str" -default "absent" -validateSet "present","absent" -resultobj $result
$reorganize = Get-AnsibleParam -obj $params "reorganize" -type "bool" -default $false -resultobj $result
If (-Not (Test-Path -Path $path)) {
If (-Not (Test-Path -LiteralPath $path)) {
Fail-Json $result "$path file or directory does not exist on the host"
}
Try {
$objACL = Get-ACL -Path $path
$objACL = Get-ACL -LiteralPath $path
# AreAccessRulesProtected - $false if inheritance is set ,$true if inheritance is not set
$inheritanceDisabled = $objACL.AreAccessRulesProtected
@ -31,9 +31,9 @@ Try {
If ($reorganize) {
# it wont work without intermediate save, state would be the same
Set-ACL -Path $path -AclObject $objACL -WhatIf:$check_mode
Set-ACL -LiteralPath $path -AclObject $objACL -WhatIf:$check_mode
$result.changed = $true
$objACL = Get-ACL -Path $path
$objACL = Get-ACL -LiteralPath $path
# convert explicit ACE to inherited ACE
ForEach($inheritedRule in $objACL.Access) {
@ -53,11 +53,11 @@ Try {
}
}
Set-ACL -Path $path -AclObject $objACL -WhatIf:$check_mode
Set-ACL -LiteralPath $path -AclObject $objACL -WhatIf:$check_mode
$result.changed = $true
} Elseif (($state -eq "absent") -And (-not $inheritanceDisabled)) {
$objACL.SetAccessRuleProtection($True, $reorganize)
Set-ACL -Path $path -AclObject $objACL -WhatIf:$check_mode
Set-ACL -LiteralPath $path -AclObject $objACL -WhatIf:$check_mode
$result.changed = $true
}
} Catch {