File permissions do not inherit directory permissions

前端 未结 1 1869
生来不讨喜
生来不讨喜 2020-12-15 14:19

I have a program that\'s creating a secure directory for user output. This is working correctly, but the files I create in it (or copy to it) are ending up with only admini

相关标签:
1条回答
  • 2020-12-15 14:29

    It looks like you should be setting the InheritanceFlags and PropagationFlags when setting the DirectorySecurity (I believe it overwrite whatever you've manually set).

    private DirectorySecurity GetDirectorySecurity(string owner)
    {
        const string LOG_SOURCE = "GetDirectorySecurity";
        DirectorySecurity ds = new DirectorySecurity();
    
        System.Security.Principal.NTAccount ownerAccount =
            new System.Security.Principal.NTAccount(owner);
    
        ds.SetOwner(ownerAccount);
    
        ds.AddAccessRule(
            new FileSystemAccessRule(owner,
            FileSystemRights.FullControl,
            InheritanceFlags.ObjectInherit, 
            PropagationFlags.InheritOnly,
            AccessControlType.Allow));
    
        //AdminUsers is a List<string> that contains a list from configuration
        //  That represents the admins who should be allowed
        foreach (string adminUser in AdminUsers)
        {
            ds.AddAccessRule(
                new FileSystemAccessRule(adminUser,
                FileSystemRights.FullControl,
                InheritanceFlags.ObjectInherit,
                PropagationFlags.InheritOnly,
                AccessControlType.Allow));
        }
        return ds;
    }
    
    0 讨论(0)
提交回复
热议问题