// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#if !MOONLIGHT
+
using System.Collections;
using System.Globalization;
using System.IO;
public RuntimeDeclSecurityEntry choice;
}
-#if NET_2_0
[ComVisible (true)]
public static class SecurityManager {
-#else
- public sealed class SecurityManager {
-
- private SecurityManager ()
- {
- }
-#endif
private static object _lockObject;
private static ArrayList _hierarchy;
private static IPermission _unmanagedCode;
set;
}
-#if NET_2_0
[Obsolete ("The security manager cannot be turned off on MS runtime")]
-#endif
extern public static bool SecurityEnabled {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
// methods
-#if NET_1_1
// NOTE: This method doesn't show in the class library status page because
// it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
// But it's there!
- [MonoTODO ("works for fulltrust (empty), documentation doesn't really make sense, type wise")]
+ // FIXME works for fulltrust (empty), documentation doesn't really make sense, type wise
+ [MonoTODO ("CAS support is experimental (and unsupported). This method only works in FullTrust.")]
[StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey = "0x00000000000000000400000000000000")]
public static void GetZoneAndOrigin (out ArrayList zone, out ArrayList origin)
{
zone = new ArrayList ();
origin = new ArrayList ();
}
-#endif
public static bool IsGranted (IPermission perm)
{
// - Not affected by overrides (like Assert, Deny and PermitOnly)
// - calls IsSubsetOf even for non CAS permissions
// (i.e. it does call Demand so any code there won't be executed)
-#if NET_2_0
// with 2.0 identity permission are unrestrictable
return IsGranted (Assembly.GetCallingAssembly (), perm);
-#else
- if (perm is IUnrestrictedPermission)
- return IsGranted (Assembly.GetCallingAssembly (), perm);
- else
- return IsGrantedRestricted (Assembly.GetCallingAssembly (), perm);
-#endif
}
-#if !NET_2_0
- // only for permissions that do not implement IUnrestrictedPermission
- internal static bool IsGrantedRestricted (Assembly a, IPermission perm)
+ // note: in 2.0 *all* permissions (including identity permissions) support unrestricted
+ internal static bool IsGranted (Assembly a, IPermission perm)
{
- PermissionSet granted = a.GrantedPermissionSet;\r
- if (granted != null) {\r
+ PermissionSet granted = a.GrantedPermissionSet;
+ if ((granted != null) && !granted.IsUnrestricted ()) {
CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (perm.GetType ());
if (!perm.IsSubsetOf (grant)) {
return false;
}
PermissionSet denied = a.DeniedPermissionSet;
- if (denied != null) {\r
+ if ((denied != null) && !denied.IsEmpty ()) {
+ if (denied.IsUnrestricted ())
+ return false;
CodeAccessPermission refuse = (CodeAccessPermission) a.DeniedPermissionSet.GetPermission (perm.GetType ());
if ((refuse != null) && perm.IsSubsetOf (refuse))
return false;
}
return true;
}
-#endif
- // note: in 2.0 *all* permissions (including identity permissions) support unrestricted
- internal static bool IsGranted (Assembly a, IPermission perm)
- {
- PermissionSet granted = a.GrantedPermissionSet;\r
- if ((granted != null) && !granted.IsUnrestricted ()) {\r
- CodeAccessPermission grant = (CodeAccessPermission) granted.GetPermission (perm.GetType ());\r
- if (!perm.IsSubsetOf (grant)) {\r
- return false;\r
- }\r
- }\r
-\r
- PermissionSet denied = a.DeniedPermissionSet;\r
- if ((denied != null) && !denied.IsEmpty ()) {\r
- if (denied.IsUnrestricted ())\r
- return false;\r
- CodeAccessPermission refuse = (CodeAccessPermission) a.DeniedPermissionSet.GetPermission (perm.GetType ());\r
- if ((refuse != null) && perm.IsSubsetOf (refuse))\r
- return false;\r
- }\r
- return true;\r
- }
internal static IPermission CheckPermissionSet (Assembly a, PermissionSet ps, bool noncas)
{
foreach (IPermission p in ps) {
// note: this may contains non CAS permissions
if ((!noncas) && (p is CodeAccessPermission)) {
-#if NET_2_0
if (!IsGranted (a, p))
return p;
-#else
- if (p is IUnrestrictedPermission) {
- if (!IsGranted (a, p))
- return p;
- } else {
- if (!IsGrantedRestricted (a, p))
- return p;
- }
-#endif
} else {
// but non-CAS will throw on failure...
try {
PermissionSet granted = ad.GrantedPermissionSet;
if (granted == null)
return null;
-#if NET_2_0
if (granted.IsUnrestricted ())
return null;
-#else
- if ((granted.Count == 0) && granted.IsUnrestricted ())
- return null;
-#endif
if (ps.IsUnrestricted ())
return new SecurityPermission (SecurityPermissionFlag.NoFlags);
return ps;
}
-#if NET_2_0
[MonoTODO ("(2.0) more tests are needed")]
public static PermissionSet ResolvePolicy (Evidence[] evidences)
{
ResolveIdentityPermissions (ps, evidence);
return ps;
}
-#endif
static private SecurityPermission _execution = new SecurityPermission (SecurityPermissionFlag.Execution);
internal static void ResolveIdentityPermissions (PermissionSet ps, Evidence evidence)
{
-#if NET_2_0
// in 2.0 identity permissions can now be unrestricted
if (ps.IsUnrestricted ())
return;
-#endif
+
// Only host evidence are used for policy resolution
IEnumerator ee = evidence.GetHostEnumerator ();
while (ee.MoveNext ()) {
return LinkDemand (mb.ReflectedType.Assembly, &klass, &method);
}
- // internal - get called at JIT time
-
- private static void DemandUnmanaged ()
- {
- UnmanagedCode.Demand ();
- }
-
private unsafe static bool LinkDemand (Assembly a, RuntimeDeclSecurityActions *klass, RuntimeDeclSecurityActions *method)
{
try {
}
}
+#pragma warning disable 169
private static bool LinkDemandFullTrust (Assembly a)
{
// FullTrust is immutable (and means Unrestricted)
}
// we try to provide as much details as possible to help debugging
- private static void LinkDemandSecurityException (int securityViolation, Assembly a, MethodInfo method)
+ private static void LinkDemandSecurityException (int securityViolation, IntPtr methodHandle)
{
+ RuntimeMethodHandle runtimeHandle = new RuntimeMethodHandle (methodHandle);
+ MethodInfo method = (MethodInfo)(MethodBase.GetMethodFromHandle (runtimeHandle));
+ Assembly a = method.DeclaringType.Assembly;
+
string message = null;
AssemblyName an = null;
PermissionSet granted = null;
throw new SecurityException (message, an, granted, refused, method, SecurityAction.InheritanceDemand, null, null, null);
}
+ // called by the runtime when CoreCLR is enabled
+
+ private static void ThrowException (Exception ex)
+ {
+ throw ex;
+ }
+
// internal - get called by the class loader
// Called when
}
}
+ // internal - get called at JIT time
+
+ private static void DemandUnmanaged ()
+ {
+ UnmanagedCode.Demand ();
+ }
// internal - get called by JIT generated code
{
throw new SecurityException ("SecurityAction.DemandChoice was removed from 2.0");
}
+#pragma warning restore 169
}
}
+
+#endif
+