2015-01-19 8 views
5

Korzystanie z Get-Acl Próbuję uzyskać prawa dostępu do folderu. Chodzi o to, że dla niektórych grup dostaję numer zamiast typu dostępu. Przykład poniżej:Pobieranie deskryptora zabezpieczeń i numeru pobrania dla FileSystemRights

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

Czy istnieje sposób na przetłumaczenie tej liczby na jej nazwę?

Odpowiedz

4

Szybki i brudny tanslation:

268435456 - fullcontrol

-536805376 - Modyfikacja, Synchronizacja

-1610612736 - ReadAndExecute, Synchronizacja

Jeśli chcesz dowiedzieć się o procesie tłumaczenia to było najlepsze, jakie mogłem znaleźć w tej chwili: Link

9

Wartość właściwości FileSystemRights jest niepodpisaną 32-bitową liczbą całkowitą, gdzie każdy bit reprezentuje konkretne uprawnienie dostępu. Większość uprawnień jest wymienionych w Win32_ACE class documentation, z wyjątkiem "ogólnych" uprawnień (bitów 28-31) i prawa dostępu do SACL (bit   23). Więcej szczegółów można znaleźć here i here.

Jeśli chcesz przełamać dostęp maskę ACE do swoich szczególnych praw dostępu (VULGO „rozszerzone uprawnienia”) mógłby zrobić coś takiego:

$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[$_] } 

prostego uprawnienia FullControl, Modify, ReadAndExecute itp. są tylko określonymi kombinacjami tych rozszerzonych uprawnień. ReadAndExecute jest na przykład kombinacja z następujących wydłużonych uprawnień:

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

więc maskę dostępu ReadAndExecute musiałby t on wartość 131241.

Jeśli chcesz rezultatem będzie połączenie prostego zgody, a pozostałe rozszerzone uprawnienia, można zrobić coś takiego:

$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

ten powinien mieć więcej upvotes. Świetna sprawa. –

+1

Świetna odpowiedź, chociaż istnieje literówka w '$ fsr = $ fsr -band (-bNOT $ _)'. Zauważ binarny '-bNOT' zamiast logicznego' -not'. – JosefZ

+0

@JosefZ Dzięki za heads up. Naprawiony. –

Powiązane problemy