check and fix log folder permissions #752

pull/753/head
Fabian Seitz 2024-10-24 18:26:35 +02:00
parent 773579f09c
commit 2f8d854e95
1 changed files with 18 additions and 0 deletions

View File

@ -139,6 +139,24 @@ function Install-Prerequisites {
else {
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "Green"
}
if (Test-Path "$WorkingDir\logs") {
$NewAcl = Get-Acl -Path "$WorkingDir\logs"
$identity = New-Object System.Security.Principal.SecurityIdentifier "S-1-1-0" # S-1-1-0 stands for "Everyone"
$hasModifyPermission = $NewAcl.Access | Where-Object {
$_.IdentityReference -eq $identity -and $_.FileSystemRights -match "Modify" -and $_.AccessControlType -eq "Allow"
}
if (-not $hasModifyPermission) {
Write-ToLog "-> Adjusting log folder ($WorkingDir\logs) permissions to allow Modify access for Everyone" "Green"
$fileSystemRights = "Modify"
$type = "Allow"
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path "$WorkingDir\logs" -AclObject $NewAcl
}
}
Write-ToLog "Prerequisites checked. OK" "Green"