【问题标题】:ACL rights, multiple inheritance from string valueACL 权限,来自字符串值的多重继承
【发布时间】:2015-06-28 13:43:43
【问题描述】:

我正在尝试创建一个设置 ACL 权限的函数,所有来自 XML 的数据都是字符串,但继承部分有问题。使用此代码...

$workingPermissions = Get-Acl $target
                $acRights = [System.Security.AccessControl.FileSystemRights]$rights 
                $acInheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::$inheritance
                $acPropagationFlag = [System.Security.AccessControl.PropagationFlags]::$propagation 
                $acType =[System.Security.AccessControl.AccessControlType]::Allow 
                $acUser = New-Object System.Security.Principal.NTAccount($principal) 
                $acEntry = New-Object System.Security.AccessControl.FileSystemAccessRule ($acUser, $acRights, $acInheritanceFlag, $acPropagationFlag, $acType)

当只使用一个继承标志时一切正常,但当 $inheritance = "ContainerInherit,ObjectInherit" 时它会失败。 $rights 的构建方式相同,但我的理解是,无论出于何种原因,继承(和传播?)的行为方式都不相同。 几年前我发现了this thread,但我没有看到基于 -bor 的解决方案在哪里允许任何基于字符串的输入。事实上,我根本不理解它,因为似乎 $is 只是被设置为一个枚举,它当然包含设置了 $flag 的两个枚举。 无论如何,希望有人能提供我自己的代码所需的功能,或许还能让我了解链接解决方案中真正发生的事情。

【问题讨论】:

    标签: powershell permissions acl


    【解决方案1】:

    将 Propogation 标志保留为 None,

    试试这个,它对我有用

    $SAMAccountName = "SamAccountName" ## Type your User/Group SamAccountName
    $Rights = "ReadAndExecute"
    $InheritanceFlag = @("ContainerInherit","ObjectInherit")
    $PropagationFlag = "None"
    $AccessType = "Allow"
    
    $NTAccount = [System.Security.Principal.NTAccount]($SAMAccountName)
    $IdentityReference = $NTAccount.Translate([System.Security.Principal.SecurityIdentifier])
    $AccessRights = [System.Security.AccessControl.FileSystemRights] $Rights
    $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]$InheritanceFlag
    $PropagationFlags = [System.Security.AccessControl.PropagationFlags]$PropagationFlag
    $Type = [System.Security.AccessControl.AccessControlType]$AccessType
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($IdentityReference, $AccessRights, $InheritanceFlags,$PropagationFlags,$Type)
    $ACL = Get-Acl $Folder
    $ACL.AddAccessRule($AccessRule)
    Set-Acl -Path $Folder -AclObject $ACL
    

    【讨论】:

    • 该死,我怎么会错过它需要一个数组。当然,为什么 Right 可以使用字符串,而 Inheritance 需要数组呢?无论如何......通过一点 -replace 和 .split 我将人类可读的字符串转换为数组,然后我就可以参加比赛了。谢谢!
    猜你喜欢
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2015-06-17
    • 1970-01-01
    • 2022-09-23
    • 2018-01-19
    • 2021-07-02
    相关资源
    最近更新 更多