2015-01-19 14 views
5

Sử dụng Get-Acl Tôi đang cố gắng nhận quyền truy cập trên một thư mục. Vấn đề là, đối với một số nhóm tôi nhận được một số thay vì một loại truy cập. Ví dụ bên dưới:Truy xuất bộ mô tả bảo mật và nhận số cho FileSystemRights

get-acl "C:\TestFolder" | % {$_.access} 
FileSystemRights : -536805376 
AccessControlType : Allow 
IdentityReference : TestDomain\Support 
IsInherited  : False 
InheritanceFlags : ObjectInherit 
PropagationFlags : InheritOnly 

Có cách nào để dịch lại số này không?

Trả lời

4

Nhanh chóng và bẩn tanslation:

268435456 - FullControl

-536805376 - Sửa đổi, Đồng bộ hóa

-1610612736 - ReadAndExecute, Đồng bộ hóa

Nếu bạn muốn tìm hiểu về quá trình dịch thuật này là điều tốt nhất tôi có thể tìm thấy tại thời điểm này: Link

9

Giá trị của thuộc tính FileSystemRights là số nguyên 32 bit không dấu, trong đó mỗi bit đại diện cho quyền truy cập cụ thể. Hầu hết các điều khoản được liệt kê trong Win32_ACE class documentation, ngoại trừ các quyền "chung" (bit 28-31) và quyền truy cập SACL (bit   23). Bạn có thể tìm thêm chi tiết herehere.

Nếu bạn muốn phá vỡ một mặt nạ truy cập ACE vào quyền truy cập cụ thể của nó (vulgo "quyền truy cập mở rộng"), bạn có thể làm một cái gì đó như thế này:

$accessMask = [ordered]@{ 
    [uint32]'0x80000000' = 'GenericRead' 
    [uint32]'0x40000000' = 'GenericWrite' 
    [uint32]'0x20000000' = 'GenericExecute' 
    [uint32]'0x10000000' = 'GenericAll' 
    [uint32]'0x02000000' = 'MaximumAllowed' 
    [uint32]'0x01000000' = 'AccessSystemSecurity' 
    [uint32]'0x00100000' = 'Synchronize' 
    [uint32]'0x00080000' = 'WriteOwner' 
    [uint32]'0x00040000' = 'WriteDAC' 
    [uint32]'0x00020000' = 'ReadControl' 
    [uint32]'0x00010000' = 'Delete' 
    [uint32]'0x00000100' = 'WriteAttributes' 
    [uint32]'0x00000080' = 'ReadAttributes' 
    [uint32]'0x00000040' = 'DeleteChild' 
    [uint32]'0x00000020' = 'Execute/Traverse' 
    [uint32]'0x00000010' = 'WriteExtendedAttributes' 
    [uint32]'0x00000008' = 'ReadExtendedAttributes' 
    [uint32]'0x00000004' = 'AppendData/AddSubdirectory' 
    [uint32]'0x00000002' = 'WriteData/AddFile' 
    [uint32]'0x00000001' = 'ReadData/ListDirectory' 
} 

$fileSystemRights = Get-Acl -LiteralPath 'C:\some\folder_or_file' | 
        Select-Object -Expand Access | 
        Select-Object -Expand FileSystemRights -First 1 

$permissions = $accessMask.Keys | 
       Where-Object { $fileSystemRights.value__ -band $_ } | 
       ForEach-Object { $accessMask[$_] } 

Các điều khoản đơn giản FullControl, Modify, ReadAndExecute vv chỉ là sự kết hợp cụ thể của các quyền mở rộng này. ReadAndExecute ví dụ là sự kết hợp của các điều khoản mở rộng sau:

  • ReadData/ListDirectory
  • Execute/Traverse
  • ReadAttributes
  • ReadExtendedAttributes
  • ReadControl

để mặt nạ truy cập cho ReadAndExecute sẽ có t ông đánh giá cao 131241.

Nếu bạn muốn kết quả là một sự kết hợp của phép đơn giản và cho phép mở rộng còn lại, bạn có thể làm một cái gì đó như thế này:

$accessMask = [ordered]@{ 
    ... 
} 

$simplePermissions = [ordered]@{ 
    [uint32]'0x1f01ff' = 'FullControl' 
    [uint32]'0x0301bf' = 'Modify' 
    [uint32]'0x0200a9' = 'ReadAndExecute' 
    [uint32]'0x02019f' = 'ReadAndWrite' 
    [uint32]'0x020089' = 'Read' 
    [uint32]'0x000116' = 'Write' 
} 

$fileSystemRights = Get-Acl -LiteralPath 'C:\some\folder_or_file' | 
        Select-Object -Expand Access | 
        Select-Object -Expand FileSystemRights -First 1 

$fsr = $fileSystemRights.value__ 

$permissions = @() 

# get simple permission 
$permissions += $simplePermissions.Keys | ForEach-Object { 
        if (($fsr -band $_) -eq $_) { 
        $simplePermissions[$_] 
        $fsr = $fsr -band (-bnot $_) 
        } 
       } 

# get remaining extended permissions 
$permissions += $accessMask.Keys | 
       Where-Object { $fsr -band $_ } | 
       ForEach-Object { $accessMask[$_] } 
+0

này nên có nhiều upvotes. Công cụ tuyệt vời. –

+1

Câu trả lời tuyệt vời mặc dù có một lỗi đánh máy trong '$ fsr = $ fsr -band (-bNOT $ _)'. Lưu ý nhị phân '-bNOT' thay vì logic' -không'. – JosefZ

+0

@JosefZ Cảm ơn những người đứng đầu. Đã sửa. –

Các vấn đề liên quan