16 [SecuritySafeCritical]
23 private object _exceptionContext;
25 private readonly uint ProtectedDiscretionaryAcl = 2147483648u;
27 private readonly uint ProtectedSystemAcl = 1073741824u;
29 private readonly uint UnprotectedDiscretionaryAcl = 536870912u;
31 private readonly uint UnprotectedSystemAcl = 268435456u;
40 _resourceType = resourceType;
50 : this(isContainer, resourceType)
52 _exceptionContext = exceptionContext;
53 _exceptionFromErrorCode = exceptionFromErrorCode;
58 : this(resourceType, securityDescriptor, null)
64 : base(securityDescriptor)
66 _resourceType = resourceType;
67 _exceptionFromErrorCode = exceptionFromErrorCode;
78 [SecuritySafeCritical]
80 : this(resourceType, CreateInternal(resourceType, isContainer, name, null, includeSections, createByName: true, exceptionFromErrorCode, exceptionContext), exceptionFromErrorCode)
91 : this(isContainer, resourceType, name, includeSections, null, null)
103 [SecuritySafeCritical]
105 : this(resourceType, CreateInternal(resourceType, isContainer, null, handle, includeSections, createByName: false, exceptionFromErrorCode, exceptionContext), exceptionFromErrorCode)
115 [SecuritySafeCritical]
117 : this(isContainer, resourceType, handle, includeSections, null, null)
124 if (createByName && name ==
null)
128 if (!createByName && handle ==
null)
132 RawSecurityDescriptor resultSd;
133 int securityInfo = Win32.GetSecurityInfo(resourceType, name, handle, includeSections, out resultSd);
134 if (securityInfo != 0)
137 if (exceptionFromErrorCode !=
null)
139 ex = exceptionFromErrorCode(securityInfo, name, handle, exceptionContext);
143 switch (securityInfo)
146 ex =
new UnauthorizedAccessException();
149 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_InvalidOwner"));
152 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_InvalidGroup"));
155 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_UnexpectedError", securityInfo));
158 ex =
new ArgumentException(Environment.GetResourceString(
"Argument_InvalidName"),
"name");
164 ex =
new NotSupportedException(Environment.GetResourceString(
"AccessControl_NoAssociatedSecurity"));
167 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_UnexpectedError", securityInfo));
173 return new CommonSecurityDescriptor(isContainer, isDS:
false, resultSd, trusted:
true);
190 owner = _securityDescriptor.Owner;
195 group = _securityDescriptor.Group;
200 sacl = ((!_securityDescriptor.IsSystemAclPresent || _securityDescriptor.SystemAcl ==
null || _securityDescriptor.SystemAcl.Count <= 0) ?
null : _securityDescriptor.SystemAcl);
201 securityInfos = (
SecurityInfos)(((_securityDescriptor.ControlFlags &
ControlFlags.SystemAclProtected) ==
ControlFlags.None) ? ((
int)securityInfos | (int)UnprotectedSystemAcl) : ((int)securityInfos | (
int)ProtectedSystemAcl));
203 if ((includeSections &
AccessControlSections.Access) != 0 && _securityDescriptor.IsDiscretionaryAclPresent)
206 dacl = ((!_securityDescriptor.DiscretionaryAcl.EveryOneFullAccessForNullDacl) ? _securityDescriptor.DiscretionaryAcl :
null);
207 securityInfos = (
SecurityInfos)(((_securityDescriptor.ControlFlags &
ControlFlags.DiscretionaryAclProtected) ==
ControlFlags.None) ? ((
int)securityInfos | (int)UnprotectedDiscretionaryAcl) : ((int)securityInfos | (
int)ProtectedDiscretionaryAcl));
209 if (securityInfos != 0)
211 int num = Win32.SetSecurityInfo(_resourceType, name, handle, securityInfos, owner, group, sacl, dacl);
215 if (_exceptionFromErrorCode !=
null)
217 ex = _exceptionFromErrorCode(num, name, handle, exceptionContext);
224 ex =
new UnauthorizedAccessException();
227 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_InvalidOwner"));
230 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_InvalidGroup"));
233 ex =
new ArgumentException(Environment.GetResourceString(
"Argument_InvalidName"),
"name");
236 ex =
new NotSupportedException(Environment.GetResourceString(
"AccessControl_InvalidHandle"));
242 ex =
new NotSupportedException(Environment.GetResourceString(
"AccessControl_NoAssociatedSecurity"));
245 ex =
new InvalidOperationException(Environment.GetResourceString(
"AccessControl_UnexpectedError", num));
251 base.OwnerModified =
false;
252 base.GroupModified =
false;
253 base.AccessRulesModified =
false;
254 base.AuditRulesModified =
false;
269 Persist(name, includeSections, _exceptionContext);
277 [SecuritySafeCritical]
284 Persist(name,
null, includeSections, exceptionContext);
291 [SecuritySafeCritical]
294 Persist(handle, includeSections, _exceptionContext);
302 [SecuritySafeCritical]
309 Persist(
null, handle, includeSections, exceptionContext);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Represents a security descriptor. A security descriptor includes an owner, a primary group,...
NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class with the...
SecurityInfos
Specifies the section of a security descriptor to be queried or set.
Represents a wrapper class for operating system handles. This class must be inherited.
Provides the ability to control access to native objects without direct manipulation of Access Contro...
NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class with the...
sealed override void Persist(SafeHandle handle, AccessControlSections includeSections)
Saves the specified sections of the security descriptor associated with this T:System....
sealed override void Persist(string name, AccessControlSections includeSections)
Saves the specified sections of the security descriptor associated with this T:System....
Controls access to objects without direct manipulation of access control lists (ACLs)....
ControlFlags
These flags affect the security descriptor behavior.
void Persist(SafeHandle handle, AccessControlSections includeSections, object exceptionContext)
Saves the specified sections of the security descriptor associated with this T:System....
NativeObjectSecurity(bool isContainer, ResourceType resourceType)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class with the...
ResourceType
Specifies the defined native object types.
void Persist(string name, AccessControlSections includeSections, object exceptionContext)
Saves the specified sections of the security descriptor associated with this T:System....
Specifies the discretionary access control list (DACL).
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
NativeObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class with the...
internal delegate Exception ExceptionFromErrorCode(int errorCode, string name, SafeHandle handle, object context)
Provides a way for integrators to map numeric error codes to specific exceptions that they create.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Represents a security identifier (SID) and provides marshaling and comparison operations for SIDs.
Specifies the system access control list (SACL).
NativeObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle handle, AccessControlSections includeSections)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class with the...
AccessControlSections
Specifies which sections of a security descriptor to save or load.
NativeObjectSecurity(bool isContainer, ResourceType resourceType, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)
Initializes a new instance of the T:System.Security.AccessControl.NativeObjectSecurity class by using...