2 // System.Security.SecurityManager.cs
5 // Nick Drochak(ndrochak@gol.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
9 // Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Globalization;
35 using System.Reflection;
36 using System.Runtime.CompilerServices;
37 using System.Runtime.InteropServices;
38 using System.Security.Permissions;
39 using System.Security.Policy;
44 namespace System.Security {
46 // Must match MonoDeclSecurityActions in /mono/metadata/reflection.h
47 internal struct RuntimeDeclSecurityActions {
48 public RuntimeDeclSecurityEntry cas;
49 public RuntimeDeclSecurityEntry noncas;
50 public RuntimeDeclSecurityEntry choice;
55 public static class SecurityManager {
57 public sealed class SecurityManager {
59 private SecurityManager ()
63 private static object _lockObject;
64 private static ArrayList _hierarchy;
65 private static IPermission _unmanagedCode;
66 private static Hashtable _declsecCache;
67 private static PolicyLevel _level;
69 static SecurityManager ()
72 // http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui06032003.asp?frame=true
73 _lockObject = new object ();
78 extern public static bool CheckExecutionRights {
79 [MethodImplAttribute (MethodImplOptions.InternalCall)]
82 [MethodImplAttribute (MethodImplOptions.InternalCall)]
83 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
87 extern public static bool SecurityEnabled {
88 [MethodImplAttribute (MethodImplOptions.InternalCall)]
91 [MethodImplAttribute (MethodImplOptions.InternalCall)]
92 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
99 // NOTE: This method doesn't show in the class library status page because
100 // it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
102 [MonoTODO ("works for fulltrust (empty), documentation doesn't really make sense, type wise")]
103 [StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey = "0x00000000000000000400000000000000")]
104 public static void GetZoneAndOrigin (out ArrayList zone, out ArrayList origin)
106 zone = new ArrayList ();
107 origin = new ArrayList ();
111 public static bool IsGranted (IPermission perm)
115 if (!SecurityEnabled)
119 // - Only check the caller (no stack walk required)
120 // - Not affected by overrides (like Assert, Deny and PermitOnly)
121 // - calls IsSubsetOf even for non CAS permissions
122 // (i.e. it does call Demand so any code there won't be executed)
124 // with 2.0 identity permission are unrestrictable
125 return IsGranted (Assembly.GetCallingAssembly (), perm);
127 if (perm is IUnrestrictedPermission)
128 return IsGranted (Assembly.GetCallingAssembly (), perm);
130 return IsGrantedRestricted (Assembly.GetCallingAssembly (), perm);
135 // only for permissions that do not implement IUnrestrictedPermission
136 internal static bool IsGrantedRestricted (Assembly a, IPermission perm)
138 PermissionSet granted = a.GrantedPermissionSet;
\r
139 if (granted != null) {
\r
140 CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (perm.GetType ());
141 if (!perm.IsSubsetOf (grant)) {
146 PermissionSet denied = a.DeniedPermissionSet;
147 if (denied != null) {
\r
148 CodeAccessPermission refuse = (CodeAccessPermission) a.DeniedPermissionSet.GetPermission (perm.GetType ());
149 if ((refuse != null) && perm.IsSubsetOf (refuse))
155 // note: in 2.0 *all* permissions (including identity permissions) support unrestricted
156 internal static bool IsGranted (Assembly a, IPermission perm)
158 PermissionSet granted = a.GrantedPermissionSet;
\r
159 if ((granted != null) && !granted.IsUnrestricted ()) {
\r
160 CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (perm.GetType ());
\r
161 if (!perm.IsSubsetOf (grant)) {
\r
166 PermissionSet denied = a.DeniedPermissionSet;
\r
167 if ((denied != null) && !denied.IsEmpty ()) {
\r
168 if (denied.IsUnrestricted ())
\r
170 CodeAccessPermission refuse = (CodeAccessPermission) a.DeniedPermissionSet.GetPermission (perm.GetType ());
\r
171 if ((refuse != null) && perm.IsSubsetOf (refuse))
\r
177 internal static IPermission CheckPermissionSet (Assembly a, PermissionSet ps, bool noncas)
182 foreach (IPermission p in ps) {
183 // note: this may contains non CAS permissions
184 if ((!noncas) && (p is CodeAccessPermission)) {
186 if (!IsGranted (a, p))
189 if (p is IUnrestrictedPermission) {
190 if (!IsGranted (a, p))
193 if (!IsGrantedRestricted (a, p))
198 // but non-CAS will throw on failure...
202 catch (SecurityException) {
211 internal static IPermission CheckPermissionSet (AppDomain ad, PermissionSet ps)
213 if ((ps == null) || ps.IsEmpty ())
216 PermissionSet granted = ad.GrantedPermissionSet;
220 if (granted.IsUnrestricted ())
223 if ((granted.Count == 0) && granted.IsUnrestricted ())
226 if (ps.IsUnrestricted ())
227 return new SecurityPermission (SecurityPermissionFlag.NoFlags);
229 foreach (IPermission p in ps) {
230 if (p is CodeAccessPermission) {
231 CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (p.GetType ());
233 if (!granted.IsUnrestricted () || !(p is IUnrestrictedPermission)) {
234 if (!p.IsSubsetOf (null))
237 } else if (!p.IsSubsetOf (grant)) {
241 // but non-CAS will throw on failure...
245 catch (SecurityException) {
254 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
255 public static PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type)
258 throw new ArgumentNullException ("path");
260 PolicyLevel pl = null;
262 pl = new PolicyLevel (type.ToString (), type);
263 pl.LoadFromFile (path);
265 catch (Exception e) {
266 throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e);
271 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
272 public static PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type)
275 throw new ArgumentNullException ("str");
277 PolicyLevel pl = null;
279 pl = new PolicyLevel (type.ToString (), type);
280 pl.LoadFromString (str);
282 catch (Exception e) {
283 throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e);
288 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
289 public static IEnumerator PolicyHierarchy ()
294 public static PermissionSet ResolvePolicy (Evidence evidence)
296 // no evidence, no permission
297 if (evidence == null)
298 return new PermissionSet (PermissionState.None);
300 PermissionSet ps = null;
301 // Note: can't call PolicyHierarchy since ControlPolicy isn't required to resolve policies
302 IEnumerator ple = Hierarchy;
303 while (ple.MoveNext ()) {
304 PolicyLevel pl = (PolicyLevel) ple.Current;
305 if (ResolvePolicyLevel (ref ps, pl, evidence)) {
306 break; // i.e. PolicyStatementAttribute.LevelFinal
310 ResolveIdentityPermissions (ps, evidence);
316 [MonoTODO ("(2.0) more tests are needed")]
317 public static PermissionSet ResolvePolicy (Evidence[] evidences)
319 if ((evidences == null) || (evidences.Length == 0) ||
320 ((evidences.Length == 1) && (evidences [0].Count == 0))) {
321 return new PermissionSet (PermissionState.None);
324 // probably not optimal
325 PermissionSet ps = ResolvePolicy (evidences [0]);
326 for (int i=1; i < evidences.Length; i++) {
327 ps = ps.Intersect (ResolvePolicy (evidences [i]));
332 public static PermissionSet ResolveSystemPolicy (Evidence evidence)
334 // no evidence, no permission
335 if (evidence == null)
336 return new PermissionSet (PermissionState.None);
338 // Note: can't call PolicyHierarchy since ControlPolicy isn't required to resolve policies
339 PermissionSet ps = null;
340 IEnumerator ple = Hierarchy;
341 while (ple.MoveNext ()) {
342 PolicyLevel pl = (PolicyLevel) ple.Current;
343 if (pl.Type == PolicyLevelType.AppDomain)
345 if (ResolvePolicyLevel (ref ps, pl, evidence))
346 break; // i.e. PolicyStatementAttribute.LevelFinal
349 ResolveIdentityPermissions (ps, evidence);
354 static private SecurityPermission _execution = new SecurityPermission (SecurityPermissionFlag.Execution);
356 public static PermissionSet ResolvePolicy (Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
358 PermissionSet resolved = ResolvePolicy (evidence);
359 // do we have the minimal permission requested by the assembly ?
360 if ((reqdPset != null) && !reqdPset.IsSubsetOf (resolved)) {
361 throw new PolicyException (Locale.GetText (
362 "Policy doesn't grant the minimal permissions required to execute the assembly."));
365 // do we check for execution rights ?
366 if (CheckExecutionRights) {
367 bool execute = false;
368 // an empty permissionset doesn't include Execution
369 if (resolved != null) {
370 // unless we have "Full Trust"...
371 if (resolved.IsUnrestricted ()) {
374 // ... we need to find a SecurityPermission
375 IPermission security = resolved.GetPermission (typeof (SecurityPermission));
376 execute = _execution.IsSubsetOf (security);
381 throw new PolicyException (Locale.GetText (
382 "Policy doesn't grant the right to execute the assembly."));
390 public static IEnumerator ResolvePolicyGroups (Evidence evidence)
392 if (evidence == null)
393 throw new ArgumentNullException ("evidence");
395 ArrayList al = new ArrayList ();
396 // Note: can't call PolicyHierarchy since ControlPolicy isn't required to resolve policies
397 IEnumerator ple = Hierarchy;
398 while (ple.MoveNext ()) {
399 PolicyLevel pl = (PolicyLevel) ple.Current;
400 CodeGroup cg = pl.ResolveMatchingCodeGroups (evidence);
403 return al.GetEnumerator ();
406 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
407 public static void SavePolicy ()
409 IEnumerator e = Hierarchy;
410 while (e.MoveNext ()) {
411 PolicyLevel level = (e.Current as PolicyLevel);
416 [SecurityPermission (SecurityAction.Demand, ControlPolicy = true)]
417 public static void SavePolicyLevel (PolicyLevel level)
419 // Yes this will throw a NullReferenceException, just like MS (see FDBK13121)
423 // private/internal stuff
425 private static IEnumerator Hierarchy {
428 if (_hierarchy == null)
429 InitializePolicyHierarchy ();
431 return _hierarchy.GetEnumerator ();
435 private static void InitializePolicyHierarchy ()
437 string machinePolicyPath = Path.GetDirectoryName (Environment.GetMachineConfigPath ());
438 // note: use InternalGetFolderPath to avoid recursive policy initialization
439 string userPolicyPath = Path.Combine (Environment.InternalGetFolderPath (Environment.SpecialFolder.ApplicationData), "mono");
441 PolicyLevel enterprise = new PolicyLevel ("Enterprise", PolicyLevelType.Enterprise);
443 enterprise.LoadFromFile (Path.Combine (machinePolicyPath, "enterprisesec.config"));
445 PolicyLevel machine = new PolicyLevel ("Machine", PolicyLevelType.Machine);
447 machine.LoadFromFile (Path.Combine (machinePolicyPath, "security.config"));
449 PolicyLevel user = new PolicyLevel ("User", PolicyLevelType.User);
451 user.LoadFromFile (Path.Combine (userPolicyPath, "security.config"));
453 ArrayList al = new ArrayList ();
458 _hierarchy = ArrayList.Synchronized (al);
462 internal static bool ResolvePolicyLevel (ref PermissionSet ps, PolicyLevel pl, Evidence evidence)
464 PolicyStatement pst = pl.Resolve (evidence);
467 // only for initial (first) policy level processed
468 ps = pst.PermissionSet;
470 ps = ps.Intersect (pst.PermissionSet);
472 // null is equals to None - exist that null can throw NullReferenceException ;-)
473 ps = new PermissionSet (PermissionState.None);
477 if ((pst.Attributes & PolicyStatementAttribute.LevelFinal) == PolicyStatementAttribute.LevelFinal)
483 internal static void ResolveIdentityPermissions (PermissionSet ps, Evidence evidence)
486 // in 2.0 identity permissions can now be unrestricted
487 if (ps.IsUnrestricted ())
490 // Only host evidence are used for policy resolution
491 IEnumerator ee = evidence.GetHostEnumerator ();
492 while (ee.MoveNext ()) {
493 IIdentityPermissionFactory ipf = (ee.Current as IIdentityPermissionFactory);
495 IPermission p = ipf.CreateIdentityPermission (evidence);
496 ps.AddPermission (p);
501 internal static PolicyLevel ResolvingPolicyLevel {
502 get { return _level; }
503 set { _level = value; }
506 internal static PermissionSet Decode (IntPtr permissions, int length)
508 // Permission sets from the runtime (declarative security) can be cached
509 // for performance as they can never change (i.e. they are read-only).
510 PermissionSet ps = null;
513 if (_declsecCache == null) {
514 _declsecCache = new Hashtable ();
517 object key = (object) (int) permissions;
518 ps = (PermissionSet) _declsecCache [key];
520 // create permissionset and add it to the cache
521 byte[] data = new byte [length];
522 Marshal.Copy (permissions, data, 0, length);
524 ps.DeclarativeSecurity = true;
525 _declsecCache.Add (key, ps);
531 internal static PermissionSet Decode (byte[] encodedPermissions)
533 if ((encodedPermissions == null) || (encodedPermissions.Length < 1))
534 throw new SecurityException ("Invalid metadata format.");
536 switch (encodedPermissions [0]) {
538 // Fx 1.0/1.1 declarative security permissions metadata is in Unicode-encoded XML
539 string xml = Encoding.Unicode.GetString (encodedPermissions);
540 return new PermissionSet (xml);
542 // Fx 2.0 are encoded "somewhat, but not enough, like" custom attributes
543 // note: we still support the older format!
544 return PermissionSet.CreateFromBinaryFormat (encodedPermissions);
546 throw new SecurityException (Locale.GetText ("Unknown metadata format."));
550 internal static PermissionSetCollection DecodeCollection (IntPtr permissions, int length)
552 // Permission sets from the runtime (declarative security) can be cached
553 // for performance as they can never change (i.e. they are read-only).
555 if (_declsecCache == null) {
557 if (_declsecCache == null) {
558 _declsecCache = new Hashtable ();
563 PermissionSetCollection psc = null;
565 object key = (object) (int) permissions;
566 psc = (PermissionSetCollection) _declsecCache [key];
568 // create permissionset and add it to the cache
569 byte[] data = new byte [length];
570 Marshal.Copy (permissions, data, 0, length);
571 psc = DecodeCollection (data);
572 _declsecCache.Add (key, psc);
578 internal static PermissionSetCollection DecodeCollection (byte[] encodedPermissions)
580 if ((encodedPermissions == null) || (encodedPermissions.Length < 1))
581 throw new SecurityException ("Invalid metadata format.");
583 switch (encodedPermissions [0]) {
585 // Fx 1.0/1.1 declarative security permissions metadata is in Unicode-encoded XML
586 throw new SecurityException (Locale.GetText ("1.0 metadata format doesn't support collections."));
588 // Fx 2.0 are encoded "somewhat, but not enough, like" custom attributes
589 // note: we still support the older format!
590 return PermissionSetCollection.CreateFromBinaryFormat (encodedPermissions);
592 throw new SecurityException (Locale.GetText ("Unknown metadata format."));
597 private static IPermission UnmanagedCode {
600 if (_unmanagedCode == null)
601 _unmanagedCode = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode);
603 return _unmanagedCode;
607 // security check when using reflection
609 [MethodImplAttribute(MethodImplOptions.InternalCall)]
610 private static unsafe extern bool GetLinkDemandSecurity (MethodBase method, RuntimeDeclSecurityActions *cdecl, RuntimeDeclSecurityActions *mdecl);
612 // When using reflection LinkDemand are promoted to full Demand (i.e. stack walk)
613 internal unsafe static void ReflectedLinkDemandInvoke (MethodBase mb)
615 RuntimeDeclSecurityActions klass;
616 RuntimeDeclSecurityActions method;
618 if (!GetLinkDemandSecurity (mb, &klass, &method))
621 PermissionSet ps = null;
623 if (klass.cas.size > 0) {
624 ps = Decode (klass.cas.blob, klass.cas.size);
626 if (klass.noncas.size > 0) {
627 PermissionSet p = Decode (klass.noncas.blob, klass.noncas.size);
628 ps = (ps == null) ? p : ps.Union (p);
631 if (method.cas.size > 0) {
632 PermissionSet p = Decode (method.cas.blob, method.cas.size);
633 ps = (ps == null) ? p : ps.Union (p);
635 if (method.noncas.size > 0) {
636 PermissionSet p = Decode (method.noncas.blob, method.noncas.size);
637 ps = (ps == null) ? p : ps.Union (p);
640 // in this case we union-ed the permission sets because we want to do
641 // a single stack walk (not up to 4).
645 // Process LinkDemandChoice (2.0)
646 if (klass.choice.size > 0) {
647 PermissionSetCollection psc = DecodeCollection (klass.choice.blob, klass.choice.size);
650 if (method.choice.size > 0) {
651 PermissionSetCollection psc = DecodeCollection (method.choice.blob, method.choice.size);
657 internal unsafe static bool ReflectedLinkDemandQuery (MethodBase mb)
659 RuntimeDeclSecurityActions klass;
660 RuntimeDeclSecurityActions method;
662 if (!GetLinkDemandSecurity (mb, &klass, &method))
665 return LinkDemand (mb.ReflectedType.Assembly, &klass, &method);
668 // internal - get called at JIT time
670 private static void DemandUnmanaged ()
672 UnmanagedCode.Demand ();
675 private unsafe static bool LinkDemand (Assembly a, RuntimeDeclSecurityActions *klass, RuntimeDeclSecurityActions *method)
678 PermissionSet ps = null;
680 if (klass->cas.size > 0) {
681 ps = Decode (klass->cas.blob, klass->cas.size);
682 result = (SecurityManager.CheckPermissionSet (a, ps, false) == null);
684 if (result && (klass->noncas.size > 0)) {
685 ps = Decode (klass->noncas.blob, klass->noncas.size);
686 result = (SecurityManager.CheckPermissionSet (a, ps, true) == null);
689 if (result && (method->cas.size > 0)) {
690 ps = Decode (method->cas.blob, method->cas.size);
691 result = (SecurityManager.CheckPermissionSet (a, ps, false) == null);
693 if (result && (method->noncas.size > 0)) {
694 ps = Decode (method->noncas.blob, method->noncas.size);
695 result = (SecurityManager.CheckPermissionSet (a, ps, true) == null);
698 // success if one of the permission is granted
699 if (result && (klass->choice.size > 0)) {
700 PermissionSetCollection psc = DecodeCollection (klass->choice.blob, klass->choice.size);
703 foreach (PermissionSet pset in psc) {
704 if (SecurityManager.CheckPermissionSet (a, pset, false) == null) {
711 if (result && (method->choice.size > 0)) {
712 PermissionSetCollection psc = DecodeCollection (method->choice.blob, method->choice.size);
715 foreach (PermissionSet pset in psc) {
716 if (SecurityManager.CheckPermissionSet (a, pset, false) == null) {
726 catch (SecurityException) {
731 private static bool LinkDemandFullTrust (Assembly a)
733 // FullTrust is immutable (and means Unrestricted)
734 // so we can skip the subset operations and jump to IsUnrestricted.
735 PermissionSet granted = a.GrantedPermissionSet;
736 if ((granted != null) && !granted.IsUnrestricted ())
739 PermissionSet denied = a.DeniedPermissionSet;
740 if ((denied != null) && !denied.IsEmpty ())
746 private static bool LinkDemandUnmanaged (Assembly a)
748 // note: we know that UnmanagedCode (SecurityPermission) implements IUnrestrictedPermission
749 return IsGranted (a, UnmanagedCode);
752 // we try to provide as much details as possible to help debugging
753 private static void LinkDemandSecurityException (int securityViolation, Assembly a, MethodInfo method)
755 string message = null;
756 AssemblyName an = null;
757 PermissionSet granted = null;
758 PermissionSet refused = null;
759 object demanded = null;
760 IPermission failed = null;
763 an = a.UnprotectedGetName ();
764 granted = a.GrantedPermissionSet;
765 refused = a.DeniedPermissionSet;
768 switch (securityViolation) {
769 case 1: // MONO_JIT_LINKDEMAND_PERMISSION
770 message = Locale.GetText ("Permissions refused to call this method.");
772 case 2: // MONO_JIT_LINKDEMAND_APTC
773 message = Locale.GetText ("Partially trusted callers aren't allowed to call into this assembly.");
774 demanded = (object) DefaultPolicies.FullTrust; // immutable
776 case 4: // MONO_JIT_LINKDEMAND_ECMA
777 message = Locale.GetText ("Calling internal calls is restricted to ECMA signed assemblies.");
779 case 8: // MONO_JIT_LINKDEMAND_PINVOKE
780 message = Locale.GetText ("Calling unmanaged code isn't allowed from this assembly.");
781 demanded = (object) _unmanagedCode;
782 failed = _unmanagedCode;
785 message = Locale.GetText ("JIT time LinkDemand failed.");
789 throw new SecurityException (message, an, granted, refused, method, SecurityAction.LinkDemand, demanded, failed, null);
792 private static void InheritanceDemandSecurityException (int securityViolation, Assembly a, Type t, MethodInfo method)
794 string message = null;
795 AssemblyName an = null;
796 PermissionSet granted = null;
797 PermissionSet refused = null;
800 an = a.UnprotectedGetName ();
801 granted = a.GrantedPermissionSet;
802 refused = a.DeniedPermissionSet;
805 switch (securityViolation) {
806 case 1: // MONO_METADATA_INHERITANCEDEMAND_CLASS
807 message = String.Format (Locale.GetText ("Class inheritance refused for {0}."), t);
809 case 2: // MONO_METADATA_INHERITANCEDEMAND_CLASS
810 message = Locale.GetText ("Method override refused.");
813 message = Locale.GetText ("Load time InheritDemand failed.");
817 throw new SecurityException (message, an, granted, refused, method, SecurityAction.InheritanceDemand, null, null, null);
820 // internal - get called by the class loader
823 // - class inheritance
824 // - method overrides
825 private unsafe static bool InheritanceDemand (AppDomain ad, Assembly a, RuntimeDeclSecurityActions *actions)
828 PermissionSet ps = null;
830 if (actions->cas.size > 0) {
831 ps = Decode (actions->cas.blob, actions->cas.size);
832 result = (SecurityManager.CheckPermissionSet (a, ps, false) == null);
834 // also check appdomain
835 result = (SecurityManager.CheckPermissionSet (ad, ps) == null);
838 if (actions->noncas.size > 0) {
839 ps = Decode (actions->noncas.blob, actions->noncas.size);
840 result = (SecurityManager.CheckPermissionSet (a, ps, true) == null);
842 // also check appdomain
843 result = (SecurityManager.CheckPermissionSet (ad, ps) == null);
847 // success if one of the permission is granted
848 if (result && (actions->choice.size > 0)) {
849 PermissionSetCollection psc = DecodeCollection (actions->choice.blob, actions->choice.size);
852 foreach (PermissionSet pset in psc) {
853 if (SecurityManager.CheckPermissionSet (a, pset, false) == null) {
854 result = (SecurityManager.CheckPermissionSet (ad, pset) == null);
863 catch (SecurityException) {
869 // internal - get called by JIT generated code
871 private static void InternalDemand (IntPtr permissions, int length)
873 PermissionSet ps = Decode (permissions, length);
877 private static void InternalDemandChoice (IntPtr permissions, int length)
880 PermissionSetCollection psc = DecodeCollection (permissions, length);
883 throw new SecurityException ("SecurityAction.DemandChoice is only possible in 2.0");