示例#1
0
 private static void SetSecurityAttribute(File file, string secDesc)
 {
     NtfsStream rootSecurityStream = file.CreateStream(AttributeType.SecurityDescriptor, null);
     SecurityDescriptor sd = new SecurityDescriptor();
     sd.Descriptor = new RawSecurityDescriptor(secDesc);
     rootSecurityStream.SetContent(sd);
 }
示例#2
0
        private void DoSetSecurity(File file, RawSecurityDescriptor securityDescriptor)
        {
            NtfsStream legacyStream = file.GetStream(AttributeType.SecurityDescriptor, null);
            if (legacyStream != null)
            {
                SecurityDescriptor sd = new SecurityDescriptor();
                sd.Descriptor = securityDescriptor;
                legacyStream.SetContent(sd);
            }
            else
            {
                uint id = _context.SecurityDescriptors.AddDescriptor(securityDescriptor);

                // Update the standard information attribute - so it reflects the actual file state
                NtfsStream stream = file.GetStream(AttributeType.StandardInformation, null);
                StandardInformation si = stream.GetContent<StandardInformation>();
                si.SecurityId = id;
                stream.SetContent(si);

                // Write attribute changes back to the Master File Table
                file.UpdateRecordInMft();
            }
        }