Skip to content

Commit

Permalink
Use SID for ALL APP PACKAGES ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePixelGamer committed Jun 13, 2022
1 parent f17e038 commit 41e6724
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ZenovaLauncher/Utils/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
Expand Down Expand Up @@ -73,13 +71,16 @@ public static IEnumerable<Package> FindPackages(string familyName)
return IsElevated ? new PackageManager().FindPackages(familyName) : new PackageManager().FindPackagesForUser(string.Empty, familyName);
}

private static readonly SecurityIdentifier ALL_APP_PACKAGES_SID = new SecurityIdentifier("S-1-15-2-1");
private static readonly FileSystemRights DefaultRights = FileSystemRights.FullControl;

public static void AddSecurityToFile(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
FileSecurity fileSecurity = fileInfo.GetAccessControl();
fileSecurity.AddAccessRule(new FileSystemAccessRule("ALL APPLICATION PACKAGES", FileSystemRights.FullControl, AccessControlType.Allow));
fileSecurity.AddAccessRule(new FileSystemAccessRule(ALL_APP_PACKAGES_SID, DefaultRights, AccessControlType.Allow));
fileInfo.SetAccessControl(fileSecurity);
}
}
Expand All @@ -91,8 +92,8 @@ public static void AddSecurityToDirectory(string dirPath)
{
DirectorySecurity dirSecurity = dirInfo.GetAccessControl();
dirSecurity.AddAccessRule(new FileSystemAccessRule(
"ALL APPLICATION PACKAGES",
FileSystemRights.FullControl,
ALL_APP_PACKAGES_SID,
DefaultRights,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Expand Down

0 comments on commit 41e6724

Please sign in to comment.