// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics;
using System.Security.Principal;
namespace System.Security.AccessControl
throw new ArgumentException(SR.Arg_MustBeIdentityReferenceType, nameof(targetType));
}
- CommonAcl acl = null;
+ CommonAcl? acl = null;
if (access)
{
return result;
}
- IdentityReferenceCollection irTarget = null;
+ IdentityReferenceCollection? irTarget = null;
if (targetType != typeof(SecurityIdentifier))
{
// A better way would be to have an internal method that would canonicalize the ACL
// and call it once, then use the RawAcl.
//
- QualifiedAce ace = acl[i] as QualifiedAce;
+ QualifiedAce? ace = acl[i] as QualifiedAce;
if (ace == null)
{
// A better way would be to have an internal method that would canonicalize the ACL
// and call it once, then use the RawAcl.
//
- QualifiedAce ace = acl[i] as CommonAce;
+ QualifiedAce? ace = acl[i] as CommonAce;
if (ace == null)
{
if ((includeExplicit && ((ace.AceFlags & AceFlags.Inherited) == 0)) || (includeInherited && ((ace.AceFlags & AceFlags.Inherited) != 0)))
{
- IdentityReference iref = (targetType == typeof(SecurityIdentifier)) ? ace.SecurityIdentifier : irTarget[i];
+ IdentityReference iref = (targetType == typeof(SecurityIdentifier)) ? ace.SecurityIdentifier : irTarget![i];
if (access)
{
type = AccessControlType.Deny;
}
- if (ace is ObjectAce)
+ if (ace is ObjectAce objectAce)
{
- ObjectAce objectAce = ace as ObjectAce;
-
result.AddRule(AccessRuleFactory(iref, objectAce.AccessMask, objectAce.IsInherited, objectAce.InheritanceFlags, objectAce.PropagationFlags, type, objectAce.ObjectAceType, objectAce.InheritedObjectAceType));
}
else
{
- CommonAce commonAce = ace as CommonAce;
+ CommonAce? commonAce = ace as CommonAce;
if (commonAce == null)
{
}
else
{
- if (ace is ObjectAce)
+ if (ace is ObjectAce objectAce)
{
- ObjectAce objectAce = ace as ObjectAce;
-
result.AddRule(AuditRuleFactory(iref, objectAce.AccessMask, objectAce.IsInherited, objectAce.InheritanceFlags, objectAce.PropagationFlags, objectAce.AuditFlags, objectAce.ObjectAceType, objectAce.InheritedObjectAceType));
}
else
{
- CommonAce commonAce = ace as CommonAce;
+ CommonAce? commonAce = ace as CommonAce;
if (commonAce == null)
{
}
}
- SecurityIdentifier sid = rule.IdentityReference.Translate(typeof(SecurityIdentifier)) as SecurityIdentifier;
+ SecurityIdentifier sid = (SecurityIdentifier)rule.IdentityReference.Translate(typeof(SecurityIdentifier));
+ Debug.Assert(SecurityDescriptor.DiscretionaryAcl != null);
if (rule.AccessControlType == AccessControlType.Allow)
{
switch (modification)
}
}
- SecurityIdentifier sid = rule.IdentityReference.Translate(typeof(SecurityIdentifier)) as SecurityIdentifier;
+ SecurityIdentifier sid = (SecurityIdentifier)rule.IdentityReference.Translate(typeof(SecurityIdentifier));
+ Debug.Assert(SecurityDescriptor.SystemAcl != null);
switch (modification)
{
case AccessControlModification.Add:
// SR.AccessControl_InvalidAccessRuleType,
// "rule");
//}
- return ModifyAccess(modification, rule as ObjectAccessRule, out modified);
+ return ModifyAccess(modification, (ObjectAccessRule)rule, out modified);
}
protected override bool ModifyAudit(AccessControlModification modification, AuditRule rule, out bool modified)
// SR.AccessControl_InvalidAuditRuleType,
// "rule");
//}
- return ModifyAudit(modification, rule as ObjectAuditRule, out modified);
+ return ModifyAudit(modification, (ObjectAuditRule)rule, out modified);
}
#endregion
{
}
- internal FileSystemSecurity(bool isContainer, SafeFileHandle handle, AccessControlSections includeSections, bool isDirectory)
+ internal FileSystemSecurity(bool isContainer, SafeFileHandle? handle, AccessControlSections includeSections, bool isDirectory)
: base(isContainer, s_ResourceType, handle, includeSections, _HandleErrorCode, isDirectory)
{
}
- private static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
+ private static Exception? _HandleErrorCode(int errorCode, string? name, SafeHandle? handle, object? context)
{
- Exception exception = null;
+ Exception? exception = null;
switch (errorCode)
{
for (int i = 0; i < rules.Count; i++)
{
- FileSystemAccessRule fsrule = rules[i] as FileSystemAccessRule;
-
- if ((fsrule != null) && (fsrule.FileSystemRights == rule.FileSystemRights)
+ if ((rules[i] is FileSystemAccessRule fsrule) && (fsrule.FileSystemRights == rule.FileSystemRights)
&& (fsrule.IdentityReference == rule.IdentityReference)
&& (fsrule.AccessControlType == rule.AccessControlType))
{
for (int i = 0; i < rules.Count; i++)
{
- FileSystemAccessRule fsrule = rules[i] as FileSystemAccessRule;
-
- if ((fsrule != null) && (fsrule.FileSystemRights == rule.FileSystemRights)
+ if ((rules[i] is FileSystemAccessRule fsrule) && (fsrule.FileSystemRights == rule.FileSystemRights)
&& (fsrule.IdentityReference == rule.IdentityReference)
&& (fsrule.AccessControlType == rule.AccessControlType))
{