diff --git a/Duplicati/Library/Common/IO/SystemIOWindows.cs b/Duplicati/Library/Common/IO/SystemIOWindows.cs
index 9e4b5476c..c6102b106 100644
--- a/Duplicati/Library/Common/IO/SystemIOWindows.cs
+++ b/Duplicati/Library/Common/IO/SystemIOWindows.cs
@@ -45,14 +45,19 @@ namespace Duplicati.Library.Common.IO
private static readonly string DIRSEP = Util.DirectorySeparatorString;
///
- /// The current user name
+ /// The current user SID
///
- private static readonly string CURRENT_USERNAME = WindowsIdentity.GetCurrent().Name;
+ private static readonly SecurityIdentifier CURRENT_USER_SID = WindowsIdentity.GetCurrent().User;
///
- /// The LocalSystem user name
+ /// The LocalSystem user SID
///
- private static readonly string LOCAL_SYSTEM_NAME = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null).Translate(typeof(NTAccount)).Value;
+ private static readonly SecurityIdentifier LOCAL_SYSTEM_SID = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
+
+ ///
+ /// The Administrator user SID
+ ///
+ private static readonly SecurityIdentifier ADMINISTRATORS_SID = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
///
/// Prefix path with one of the extended device path prefixes
@@ -685,7 +690,7 @@ namespace Duplicati.Library.Common.IO
}
///
- /// Sets the unix permission user read-write Only.
+ /// Sets the file permissions to user read-write only.
///
/// The file to set permissions on.
public void FileSetPermissionUserRWOnly(string path)
@@ -696,25 +701,26 @@ namespace Duplicati.Library.Common.IO
// Remove inherited permissions to ensure only the current user has access
security.SetAccessRuleProtection(true, false);
- // Grant the current user read access
- security.AddAccessRule(new FileSystemAccessRule(
- CURRENT_USERNAME,
- FileSystemRights.FullControl,
- AccessControlType.Allow
- ));
+ var users = new[] {
+ CURRENT_USER_SID,
+ LOCAL_SYSTEM_SID,
+ ADMINISTRATORS_SID
+ }.ToHashSet();
- security.AddAccessRule(new FileSystemAccessRule(
- LOCAL_SYSTEM_NAME,
- FileSystemRights.FullControl,
- AccessControlType.Allow
- ));
+ // Grant the users read access
+ foreach (var user in users)
+ security.AddAccessRule(new FileSystemAccessRule(
+ user,
+ FileSystemRights.FullControl,
+ AccessControlType.Allow
+ ));
// Adjust with the new security settings
new FileInfo(path).SetAccessControl(security);
}
///
- /// Sets the permission to read-write only for the current user.
+ /// Sets the directory permissions to read-write only for the current user.
///
/// The directory to set permissions on.
public void DirectorySetPermissionUserRWOnly(string path)
@@ -725,22 +731,21 @@ namespace Duplicati.Library.Common.IO
// Remove inherited permissions to ensure only the current user has access
security.SetAccessRuleProtection(true, false);
- // Grant the current user read access
- security.AddAccessRule(new FileSystemAccessRule(
- CURRENT_USERNAME,
- FileSystemRights.FullControl,
- InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, // Apply to subfolders & files
- PropagationFlags.None, // Keeps inheritance settings intact
- AccessControlType.Allow
- ));
+ var users = new[] {
+ CURRENT_USER_SID,
+ LOCAL_SYSTEM_SID,
+ ADMINISTRATORS_SID
+ }.ToHashSet();
- security.AddAccessRule(new FileSystemAccessRule(
- LOCAL_SYSTEM_NAME,
- FileSystemRights.FullControl,
- InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, // Apply to subfolders & files
- PropagationFlags.None, // Keeps inheritance settings intact
- AccessControlType.Allow
- ));
+ // Grant the users full access
+ foreach (var user in users)
+ security.AddAccessRule(new FileSystemAccessRule(
+ user,
+ FileSystemRights.FullControl, // Using full-control to allow changing permissions as well
+ InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, // Apply to subfolders & files
+ PropagationFlags.None, // Keeps inheritance settings intact
+ AccessControlType.Allow
+ ));
// Adjust with the new security settings
new DirectoryInfo(path).SetAccessControl(security);