19 private static PolicyManager polmgr =
new PolicyManager();
21 private static int[][] s_BuiltInPermissionIndexMap =
new int[6][]
65 internal static PolicyManager PolicyManager => polmgr;
71 [Obsolete(
"Because execution permission checks can no longer be turned off, the CheckExecutionRights property no longer has any effect.")]
87 [Obsolete(
"Because security can no longer be turned off, the SecurityEnabled property no longer has any effect.")]
104 [SecuritySafeCritical]
105 [Obsolete(
"IsGranted is obsolete and will be removed in a future release of the .NET Framework. Please use the PermissionSet property of either AppDomain or Assembly instead.")]
114 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
115 GetGrantedPermissions(JitHelpers.GetObjectHandleOnStack(ref o), JitHelpers.GetObjectHandleOnStack(ref o2), JitHelpers.GetStackCrawlMarkHandle(ref stackMark));
116 if (o.Contains(perm))
120 return !o2.Contains(perm);
134 if (evidence ==
null)
138 Zone hostEvidence = evidence.GetHostEvidence<
Zone>();
139 if (hostEvidence ==
null)
149 PermissionSet localIntranet = BuiltInPermissionSets.LocalIntranet;
152 if (policyStatement !=
null)
156 if (policyStatement2 !=
null)
160 return localIntranet;
166 if (policyStatement3 !=
null)
183 StackCrawlMark mark = StackCrawlMark.LookForMyCaller;
184 CodeAccessSecurityEngine.GetZoneAndOrigin(ref mark, out zone, out origin);
195 [SecuritySafeCritical]
196 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
208 if (!
File.InternalExists(path))
216 fileIOPermission.
Demand();
221 return LoadPolicyLevelFromStringHelper(streamReader.
ReadToEnd(), path, type);
233 [SecuritySafeCritical]
234 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
238 return LoadPolicyLevelFromStringHelper(str,
null, type);
248 Parser parser =
new Parser(str);
249 SecurityElement topElement = parser.GetTopElement();
250 if (topElement ==
null)
254 SecurityElement securityElement = topElement.SearchForChildByTag(
"mscorlib");
255 if (securityElement ==
null)
257 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Policy_BadXml"),
"mscorlib"));
259 SecurityElement securityElement2 = securityElement.SearchForChildByTag(
"security");
260 if (securityElement2 ==
null)
262 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Policy_BadXml"),
"security"));
264 SecurityElement securityElement3 = securityElement2.SearchForChildByTag(
"policy");
265 if (securityElement3 ==
null)
267 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Policy_BadXml"),
"policy"));
269 SecurityElement securityElement4 = securityElement3.SearchForChildByTag(
"PolicyLevel");
270 if (securityElement4 !=
null)
272 policyLevel.
FromXml(securityElement4);
275 throw new ArgumentException(
string.Format(
CultureInfo.
CurrentCulture, Environment.GetResourceString(
"Policy_BadXml"),
"PolicyLevel"));
282 [SecuritySafeCritical]
283 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
291 PolicyManager.EncodeLevel(level);
303 [SecuritySafeCritical]
304 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
311 return ResolvePolicy(evidence, reqdPset, optPset, denyPset, out denied, checkExecutionPermission:
true);
318 [SecuritySafeCritical]
319 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
326 if (evidence ==
null)
330 return polmgr.Resolve(evidence);
337 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
344 if (evidences ==
null || evidences.Length == 0)
349 if (permissionSet ==
null)
353 for (
int i = 1; i < evidences.Length; i++)
356 if (permissionSet ==
null || permissionSet.
IsEmpty())
358 return permissionSet;
361 return permissionSet;
370 return !CodeAccessSecurityEngine.QuickCheckForAllDemands();
377 [SecuritySafeCritical]
378 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
385 if (PolicyManager.IsGacAssembly(evidence))
389 return polmgr.CodeGroupResolve(evidence, systemPolicy:
true);
396 [SecuritySafeCritical]
397 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
404 return polmgr.ResolveCodeGroups(evidence);
411 [SecuritySafeCritical]
412 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
419 return polmgr.PolicyHierarchy();
425 [SecuritySafeCritical]
426 [Obsolete(
"This method is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
442 securitySpecialFlags = GetSpecialFlags(permissionSet, denied);
443 return permissionSet;
447 private static PermissionSet
ResolvePolicy(
Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied,
bool checkExecutionPermission)
449 if (executionSecurityPermission ==
null)
453 PermissionSet permissionSet =
null;
454 Exception exception =
null;
455 permissionSet = ((reqdPset !=
null) ? ((optPset ==
null) ? null : reqdPset.Union(optPset)) : optPset);
456 if (permissionSet !=
null && !permissionSet.IsUnrestricted())
458 permissionSet.AddPermission(executionSecurityPermission);
460 if (evidence ==
null)
464 PermissionSet permissionSet2 = polmgr.Resolve(evidence);
465 if (permissionSet !=
null)
467 permissionSet2.InplaceIntersect(permissionSet);
469 if (checkExecutionPermission && (!permissionSet2.Contains(executionSecurityPermission) || (denyPset !=
null && denyPset.Contains(executionSecurityPermission))))
471 throw new PolicyException(Environment.GetResourceString(
"Policy_NoExecutionPermission"), -2146233320, exception);
473 if (reqdPset !=
null && !reqdPset.IsSubsetOf(permissionSet2))
475 throw new PolicyException(Environment.GetResourceString(
"Policy_NoRequiredPermission"), -2146233321, exception);
477 if (denyPset !=
null)
479 denied = denyPset.Copy();
480 permissionSet2.MergeDeniedSet(denied);
481 if (denied.IsEmpty())
490 permissionSet2.IgnoreTypeLoadFailures =
true;
491 return permissionSet2;
494 internal static int GetSpecialFlags(PermissionSet grantSet, PermissionSet deniedSet)
496 if (grantSet !=
null && grantSet.IsUnrestricted() && (deniedSet ==
null || deniedSet.IsEmpty()))
504 CodeAccessPermission[] array =
new CodeAccessPermission[6];
505 if (grantSet !=
null)
507 if (grantSet.IsUnrestricted())
511 for (
int i = 0; i < array.Length; i++)
513 array[i] = s_UnrestrictedSpecialPermissionMap[i];
519 if (securityPermission !=
null)
521 securityPermissionFlag = securityPermission.
Flags;
524 if (reflectionPermission !=
null)
526 reflectionPermissionFlag = reflectionPermission.
Flags;
528 for (
int j = 0; j < array.Length; j++)
530 array[j] = (grantSet.GetPermission(s_BuiltInPermissionIndexMap[j][0]) as CodeAccessPermission);
534 if (deniedSet !=
null)
536 if (deniedSet.IsUnrestricted())
540 for (
int k = 0; k < s_BuiltInPermissionIndexMap.Length; k++)
548 if (securityPermission !=
null)
550 securityPermissionFlag &= ~securityPermission.
Flags;
553 if (reflectionPermission !=
null)
555 reflectionPermissionFlag &= ~reflectionPermission.
Flags;
557 for (
int l = 0; l < s_BuiltInPermissionIndexMap.Length; l++)
559 CodeAccessPermission codeAccessPermission = deniedSet.GetPermission(s_BuiltInPermissionIndexMap[l][0]) as CodeAccessPermission;
560 if (codeAccessPermission !=
null && !codeAccessPermission.IsSubsetOf(
null))
567 int num = MapToSpecialFlags(securityPermissionFlag, reflectionPermissionFlag);
570 for (
int m = 0; m < array.Length; m++)
574 num |= 1 << s_BuiltInPermissionIndexMap[m][1];
625 [SuppressUnmanagedCodeSecurity]
626 internal static extern bool IsSameType(
string strLeft,
string strRight);
630 internal static extern bool _SetThreadSecurity(
bool bThreadSecurity);
634 [SuppressUnmanagedCodeSecurity]
635 internal static extern void GetGrantedPermissions(ObjectHandleOnStack retGranted, ObjectHandleOnStack retDenied, StackCrawlMarkHandle stackMark);
SecurityPermissionFlag Flags
Gets or sets the security permission flags.
Allows a permission to expose an unrestricted state.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
ReflectionPermissionFlag
Specifies the permitted use of the N:System.Reflection and N:System.Reflection.Emit namespaces.
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
void FromXml(SecurityElement e)
Reconstructs a security object with a given state from an XML encoding.
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
PolicyLevelType
Specifies the type of a managed code policy level.
static void GetZoneAndOrigin(out ArrayList zone, out ArrayList origin)
Gets the granted zone identity and URL identity permission sets for the current assembly.
PermissionSet PermissionSet
Gets or sets the T:System.Security.PermissionSet of the policy statement.
FileMode
Specifies how the operating system should open a file.
Represents the security policy levels for the common language runtime. This class cannot be inherited...
static void SavePolicyLevel(PolicyLevel level)
Saves a modified security policy level loaded with M:System.Security.SecurityManager....
override string ReadToEnd()
Reads all characters from the current position to the end of the stream.
Implements a T:System.IO.TextReader that reads characters from a byte stream in a particular encoding...
static IEnumerator ResolvePolicyGroups(Evidence evidence)
Gets a collection of code groups matching the specified evidence.
static bool CheckExecutionRights
Gets or sets a value indicating whether code must have F:System.Security.Permissions....
Grants Web permission to the site from which the assembly was downloaded. This class cannot be inheri...
static AppDomain CurrentDomain
Gets the current application domain for the current T:System.Threading.Thread.
Represents the statement of a T:System.Security.Policy.CodeGroup describing the permissions and other...
Represents an application domain, which is an isolated environment where applications execute....
ReflectionPermissionFlag Flags
Gets or sets the type of reflection allowed for the current permission.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
void AddPathList(FileIOPermissionAccess access, string path)
Adds access for the specified file or directory to the existing state of the permission.
static PermissionSet GetStandardSandbox(Evidence evidence)
Gets a permission set that is safe to grant to an application that has the provided evidence.
Grants permission to manipulate files located in the code assemblies to code assemblies that match th...
Represents a collection that can contain many different types of permissions.
static PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type)
Loads a T:System.Security.Policy.PolicyLevel from the specified file.
bool IsEmpty()
Gets a value indicating whether the T:System.Security.PermissionSet is empty.
static bool SecurityEnabled
Gets or sets a value indicating whether security is enabled.
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
Controls the permissions related to user interfaces and the Clipboard. This class cannot be inherited...
static bool IsGranted(IPermission perm)
Determines whether a permission is granted to the caller.
Defines the underlying structure of all code access permissions.
static PermissionSet ResolveSystemPolicy(Evidence evidence)
Determines which permissions to grant to code based on the specified evidence, excluding the policy f...
override PolicyStatement Resolve(Evidence evidence)
Resolves policy for the code group and its descendants for a set of evidence.
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Represents a membership condition that matches all code. This class cannot be inherited.
override PolicyStatement Resolve(Evidence evidence)
Resolves policy for the code group and its descendants for a set of evidence.
Defines methods implemented by permission types.
static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type)
Loads a T:System.Security.Policy.PolicyLevel from the specified string.
PermissionSet Intersect(PermissionSet other)
Creates and returns a permission set that is the intersection of the current T:System....
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static void SavePolicy()
Saves the modified security policy state.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
FileAccess
Defines constants for read, write, or read/write access to a file.
Defines the set of information that constitutes input to security policy decisions....
static IEnumerator PolicyHierarchy()
Provides an enumerator to access the security policy hierarchy by levels, such as computer policy and...
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Controls access to system and user environment variables. This class cannot be inherited.
Provides the main access point for classes interacting with the security system. This class cannot be...
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides information about a specific culture (called a locale for unmanaged code development)....
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Controls the ability to access files and folders. This class cannot be inherited.
static PermissionSet ResolvePolicy(Evidence evidence)
Determines what permissions to grant to code based on the specified evidence.
SecurityZone SecurityZone
Gets the zone from which the code assembly originates.
static PermissionSet ResolvePolicy(Evidence[] evidences)
Determines what permissions to grant to code based on the specified evidence.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Controls access to non-public types and members through the N:System.Reflection APIs....
static PermissionSet ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
Determines what permissions to grant to code based on the specified evidence and requests.
The exception that is thrown when policy forbids code to run.
Supports a simple iteration over a non-generic collection.
Performs operations on T:System.String instances that contain file or directory path information....
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
static bool CurrentThreadRequiresSecurityContextCapture()
Determines whether the current thread requires a security context capture if its security state has t...
Controls the ability to access files or folders through a File dialog box. This class cannot be inher...