From ccec3c7239baaaa75983a94f14c0de5674f717a2 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Fri, 19 Apr 2024 11:52:18 -0700 Subject: [PATCH 1/2] Fixing changelog. --- CHANGELOG.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a4c9c..8135858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,21 +15,21 @@ from Carbon to Carbon.FileSystem, do the following: * Replace usages of the `Test-CNtfsPermission` function's `-Exact` switch to `-Strict`. * Using the table below, replace usages of `Grant-CNtfsPermission` and `Test-CNtfsPermission` arguments in the left column with the new arguments from the right column. - | Old Argument | New Argument(s) - |---------------------------------------------------------|--------------------------------------------------------- - | `-Permission Container` | `-Permission FolderOnly` - | `-Permission SubContainers` | `-Permission SubfoldersOnly` - | `-Permission Leaves` | `-Permission FilesOnly` - | `-Permission ChildContainers` | `-Permission SubfoldersOnly -OnlyApplyToChildFilesAndFolders` - | `-Permission ChildLeaves` | `-Permission FilesOnly -OnlyApplyToChildFilesAndFolders` - | `-Permission ContainerAndSubContainers` | `-Permission FolderAndSubfolders` - | `-Permission ContainerAndLeaves` | `-Permission FolderAndFiles` - | `-Permission SubContainerAndLeaves` | `-Permission SubfoldersAndFilesOnly` - | `-Permission ContainerAndChildContainers` | `-Permission FolderAndSubfolders -OnlyApplyToChildFilesAndFolders` - | `-Permission ContainerAndChildLeaves` | `-Permission FolderAndFiles -OnlyApplyToChildFilesAndFolders` - | `-Permission ContainerAndChildContainersAndChildLeaves` | `-Permission FolderSubfoldersAndFiles -OnlyApplyToChildFilesAndFolders` - | `-Permission ContainerAndSubContainersAndLeaves` | `-Permission FolderSubfoldersAndFiles` - | `-Permission ChildContainersAndChildLeaves` | `-Permission SubfoldersAndFilesOnly -OnlyApplyToChildFilesAndFolders` + | Old Argument | New Argument(s) + |------------------------------------------------------|--------------------------------------------------------------------- + | `-ApplyTo Container` | `-ApplyTo FolderOnly` + | `-ApplyTo SubContainers` | `-ApplyTo SubfoldersOnly` + | `-ApplyTo Leaves` | `-ApplyTo FilesOnly` + | `-ApplyTo ChildContainers` | `-ApplyTo SubfoldersOnly -OnlyApplyToChildFilesAndFolders` + | `-ApplyTo ChildLeaves` | `-ApplyTo FilesOnly -OnlyApplyToChildFilesAndFolders` + | `-ApplyTo ContainerAndSubContainers` | `-ApplyTo FolderAndSubfolders` + | `-ApplyTo ContainerAndLeaves` | `-ApplyTo FolderAndFiles` + | `-ApplyTo SubContainerAndLeaves` | `-ApplyTo SubfoldersAndFilesOnly` + | `-ApplyTo ContainerAndChildContainers` | `-ApplyTo FolderAndSubfolders -OnlyApplyToChildFilesAndFolders` + | `-ApplyTo ContainerAndChildLeaves` | `-ApplyTo FolderAndFiles -OnlyApplyToChildFilesAndFolders` + | `-ApplyTo ContainerAndChildContainersAndChildLeaves` | `-ApplyTo FolderSubfoldersAndFiles -OnlyApplyToChildFilesAndFolders` + | `-ApplyTo ContainerAndSubContainersAndLeaves` | `-ApplyTo FolderSubfoldersAndFiles` + | `-ApplyTo ChildContainersAndChildLeaves` | `-ApplyTo SubfoldersAndFilesOnly -OnlyApplyToChildFilesAndFolders` ### Added From eddb1a7bd1e115664f7bc908bab1d86cae9e081e Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Fri, 19 Apr 2024 11:53:15 -0700 Subject: [PATCH 2/2] Fixed: Grant-CNtfsPermission shows a warning when granting permissions on files. --- .../Functions/Grant-CNtfsPermission.ps1 | 7 +++++-- Tests/Grant-CNtfsPermission.Tests.ps1 | 16 ++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Carbon.FileSystem/Functions/Grant-CNtfsPermission.ps1 b/Carbon.FileSystem/Functions/Grant-CNtfsPermission.ps1 index add459d..f718162 100644 --- a/Carbon.FileSystem/Functions/Grant-CNtfsPermission.ps1 +++ b/Carbon.FileSystem/Functions/Grant-CNtfsPermission.ps1 @@ -126,12 +126,15 @@ function Grant-CNtfsPermission Set-StrictMode -Version 'Latest' Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState - if (-not $ApplyTo) + if (-not $ApplyTo -and (Test-Path -Path $Path -PathType Container)) { $ApplyTo = 'FolderSubfoldersAndFiles' } - $PSBoundParameters['ApplyTo'] = $ApplyTo | ConvertTo-CarbonSecurityApplyTo + if ($ApplyTo) + { + $PSBoundParameters['ApplyTo'] = $ApplyTo | ConvertTo-CarbonSecurityApplyTo + } if ($PSBoundParameters.ContainsKey('OnlyApplyToChildFilesAndFolders')) { diff --git a/Tests/Grant-CNtfsPermission.Tests.ps1 b/Tests/Grant-CNtfsPermission.Tests.ps1 index 67eec61..b7d498b 100644 --- a/Tests/Grant-CNtfsPermission.Tests.ps1 +++ b/Tests/Grant-CNtfsPermission.Tests.ps1 @@ -70,6 +70,7 @@ BeforeAll { function Invoke-GrantPermissions { + [CmdletBinding()] param( $Identity, $Permissions, @@ -175,12 +176,15 @@ Describe 'Grant-CNtfsPermission' { $file = New-TestFile $identity = 'BUILTIN\Administrators' $permissions = 'Read','Write' + $warnings = @() Invoke-GrantPermissions -Identity $identity ` -Permissions $permissions ` -Path $file ` -InheritanceFlag 'None' ` - -PropagationFlag 'None' + -PropagationFlag 'None' ` + -WarningVariable 'warnings' + $warnings | Should -BeNullOrEmpty } It 'grants permissions on directories' { @@ -388,16 +392,16 @@ Describe 'Grant-CNtfsPermission' { $item = Get-Item -Path $script:path $item.Attributes = $item.Attributes -bor [IO.FileAttributes]::Hidden - $result = Invoke-GrantPermissions -Identity $script:user -Permission Read -Path $script:path + Invoke-GrantPermissions -Identity $script:user -Permission Read -Path $script:path $Global:Error.Count | Should -Be 0 } It 'fails if the path does not exist' { $result = Grant-CNtfsPermission -Identity $script:user ` - -Permission Read ` - -Path 'C:\I\Do\Not\Exist' ` - -PassThru ` - -ErrorAction SilentlyContinue + -Permission Read ` + -Path 'C:\I\Do\Not\Exist' ` + -PassThru ` + -ErrorAction SilentlyContinue $result | Should -BeNullOrEmpty $Global:Error.Count | Should -BeGreaterThan 0 $Global:Error[0] | Should -Match 'that path does not exist'