|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using System.Security.AccessControl;
|
|
|
|
|
|
|
|
|
|
namespace Security2
|
|
|
|
|
{
|
|
|
|
|
public partial class FileSystemAuditRule2
|
|
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
private FileSystemAuditRule fileSystemAuditRule;
|
|
|
|
|
private string fullName;
|
|
|
|
|
private bool inheritanceEnabled;
|
|
|
|
|
private string inheritedFrom;
|
|
|
|
|
|
|
|
|
|
public string Name { get { return System.IO.Path.GetFileName(fullName); } }
|
|
|
|
|
public string FullName { get { return fullName; } set { fullName = value; } }
|
|
|
|
|
public bool InheritanceEnabled { get { return inheritanceEnabled; } set { inheritanceEnabled = value; } }
|
|
|
|
|
public string InheritedFrom { get { return inheritedFrom; } set { inheritedFrom = value; } }
|
|
|
|
|
public AuditFlags AuditFlags { get { return fileSystemAuditRule.AuditFlags; } }
|
|
|
|
|
public FileSystemRights2 AccessRights { get { return (FileSystemRights2)fileSystemAuditRule.FileSystemRights; } }
|
|
|
|
|
public IdentityReference2 Account { get { return (IdentityReference2)fileSystemAuditRule.IdentityReference; } }
|
|
|
|
|
public InheritanceFlags InheritanceFlags { get { return fileSystemAuditRule.InheritanceFlags; } }
|
|
|
|
|
public bool IsInherited { get { return fileSystemAuditRule.IsInherited; } }
|
|
|
|
|
public PropagationFlags PropagationFlags { get { return fileSystemAuditRule.PropagationFlags; } }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule)
|
|
|
|
|
{
|
|
|
|
|
this.fileSystemAuditRule = fileSystemAuditRule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule, FileSystemInfo item)
|
|
|
|
|
{
|
|
|
|
|
this.fileSystemAuditRule = fileSystemAuditRule;
|
|
|
|
|
this.fullName = item.FullName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileSystemAuditRule2(FileSystemAuditRule fileSystemAuditRule, string path)
|
|
|
|
|
{
|
|
|
|
|
this.fileSystemAuditRule = fileSystemAuditRule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Conversion
|
|
|
|
|
public static implicit operator FileSystemAuditRule(FileSystemAuditRule2 ace2)
|
|
|
|
|
{
|
|
|
|
|
return ace2.fileSystemAuditRule;
|
|
|
|
|
}
|
|
|
|
|
public static implicit operator FileSystemAuditRule2(FileSystemAuditRule ace)
|
|
|
|
|
{
|
|
|
|
|
return new FileSystemAuditRule2(ace);
|
|
|
|
|
}
|
|
|
|
|
// Like the entries of .NET, two objects are equal when they wrap the same entry; an entry of .NET is never equal,
|
|
|
|
|
// so that equality is the same in both directions. A cast instead of "as" threw an InvalidCastException.
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
fix: compare output objects and report InheritedFrom correctly
Equals of FileSystemAccessRule2, FileSystemAuditRule2, and
FileSystemSecurity2 cast its argument to the .NET type, which throws for
the wrapper types themselves: -eq and -contains, and in PowerShell 7 also
Select-Object -Unique and Compare-Object, stopped with an
InvalidCastException. GetHashCode of FileSystemSecurity2 read a field
that is never set and threw a NullReferenceException. Two objects are now
equal when they hold the same entry or descriptor, like the .NET types.
InheritedFrom: Win32.GetInheritedFrom returned the sources of the SACL
whenever the descriptor had one, also for the access entries, and the
callers gave the filtered entries of -ExcludeExplicit the sources of the
first entries of the ACL. Get-NTFSAccess -SecurityDescriptor stopped with
an ArgumentOutOfRangeException for a descriptor with audit entries, as
Get-NTFSSecurityDescriptor reads them in an elevated session. The method
now takes the ACL of the entries, and the callers map the sources before
they filter.
The coverage report of rc6 pointed at both; each test fails without its
fix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: AI Assistant <ai@example.com>
3 weeks ago
|
|
|
var other = obj as FileSystemAuditRule2;
|
|
|
|
|
return other != null && ReferenceEquals(fileSystemAuditRule, other.fileSystemAuditRule);
|
|
|
|
|
}
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return this.fileSystemAuditRule.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return fileSystemAuditRule.ToString();
|
|
|
|
|
}
|
|
|
|
|
public SimpleFileSystemAuditRule ToSimpleFileSystemAuditRule2()
|
|
|
|
|
{
|
|
|
|
|
return new SimpleFileSystemAuditRule(this.fullName, this.Account, this.AccessRights);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|