public SecurityAttributes(CommonObjectSecurity objectSecurity) { _length = Marshal.SizeOf(typeof(SecurityAttributes)); byte[] src = objectSecurity.GetSecurityDescriptorBinaryForm(); _securityDescriptor = Marshal.AllocHGlobal(src.Length); Marshal.Copy(src, 0, _securityDescriptor, src.Length); _inheritHandle = false; }
private FileSystemRights GetFileSystemRights(CommonObjectSecurity objectSecurity) { AuthorizationRuleCollection accessRules = objectSecurity.GetAccessRules(true, true, typeof (SecurityIdentifier)); FileSystemRights fileSystemAllowRights = 0; FileSystemRights fileSystemDenyRights = 0; foreach (FileSystemAccessRule accessRule in accessRules) { IdentityReference identityReference = accessRule.IdentityReference; if (identityReference != _currentUserIdentifier && _currentUserGroups.All(reference => reference != identityReference)) continue; if (accessRule.AccessControlType == AccessControlType.Deny) { fileSystemDenyRights = fileSystemDenyRights | accessRule.FileSystemRights; } else { fileSystemAllowRights = fileSystemAllowRights | accessRule.FileSystemRights; } } return fileSystemAllowRights & (~fileSystemDenyRights); }
private FileSystemObjectProperties GetFileSystemObjectProperties(FileSystemInfo info, CommonObjectSecurity objectSecurity) { IdentityReference owner = objectSecurity.GetOwner(typeof (NTAccount)); string objectOwner = owner != null ? owner.Value : "Unknown"; return new FileSystemObjectProperties { Name = info.Name, CreationTime = info.CreationTime, LastWriteTime = info.LastWriteTime, LastAccessTime = info.LastAccessTime, Attributes = info.Attributes, FileSystemRights = GetFileSystemRights(objectSecurity), Owner = objectOwner }; }