Author: spouliot
Date: 2005-06-22 14:35:41 -0400 (Wed, 22 Jun 2005)
New Revision: 46378
Modified:
trunk/mcs/class/corlib/System.Security/ChangeLog
trunk/mcs/class/corlib/System.Security/CodeAccessPermission.cs
trunk/mcs/class/corlib/System.Security/HostSecurityManager.cs
trunk/mcs/class/corlib/System.Security/PermissionSet.cs
trunk/mcs/class/corlib/System.Security/SecurityException.cs
trunk/mcs/class/corlib/System.Security/SecurityManager.cs
Log:
2005-06-22 Sebastien Pouliot <[EMAIL PROTECTED]>
* CodeAccessPermission.cs: Fix Unrestricted PermitOnly (which is like
a no-op). Speed up Assert if Unrestricted.
* HostSecurityManager.cs: Updated FIXME description.
* PermissionSet.cs: Remove Copy() of the permission set when non-CAS
permissions are used (replaced by an array of bools). Completed Assert
support by re-using the array of bools. Updated TODO descriptions.
* SecurityException.cs: Added evidence (if available) in the ToString
description of the exception.
* SecurityManager.cs: Reworked CheckExecutionRights to get the correct
behavior.
Modified: trunk/mcs/class/corlib/System.Security/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Security/ChangeLog 2005-06-22 18:04:17 UTC
(rev 46377)
+++ trunk/mcs/class/corlib/System.Security/ChangeLog 2005-06-22 18:35:41 UTC
(rev 46378)
@@ -1,3 +1,16 @@
+2005-06-22 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * CodeAccessPermission.cs: Fix Unrestricted PermitOnly (which is like
+ a no-op). Speed up Assert if Unrestricted.
+ * HostSecurityManager.cs: Updated FIXME description.
+ * PermissionSet.cs: Remove Copy() of the permission set when non-CAS
+ permissions are used (replaced by an array of bools). Completed Assert
+ support by re-using the array of bools. Updated TODO descriptions.
+ * SecurityException.cs: Added evidence (if available) in the ToString
+ description of the exception.
+ * SecurityManager.cs: Reworked CheckExecutionRights to get the correct
+ behavior.
+
2005-06-20 Sebastien Pouliot <[EMAIL PROTECTED]>
* CodeAccessPermission.cs: Removed redundant and unrequired TODO.
Modified: trunk/mcs/class/corlib/System.Security/CodeAccessPermission.cs
===================================================================
--- trunk/mcs/class/corlib/System.Security/CodeAccessPermission.cs
2005-06-22 18:04:17 UTC (rev 46377)
+++ trunk/mcs/class/corlib/System.Security/CodeAccessPermission.cs
2005-06-22 18:35:41 UTC (rev 46378)
@@ -321,11 +321,14 @@
// 1. CheckPermitOnly
if (frame.PermitOnly != null) {
// the demanded permission must be in one of
the permitted...
- bool permit = false;
- foreach (IPermission p in frame.PermitOnly) {
- if (CheckPermitOnly (p as
CodeAccessPermission)) {
- permit = true;
- break;
+ bool permit = frame.PermitOnly.IsUnrestricted
();
+ if (!permit) {
+ // check individual permissions
+ foreach (IPermission p in
frame.PermitOnly) {
+ if (CheckPermitOnly (p as
CodeAccessPermission)) {
+ permit = true;
+ break;
+ }
}
}
if (!permit) {
@@ -347,10 +350,11 @@
// 3. CheckAssert
if (frame.Assert != null) {
+ if (frame.Assert.IsUnrestricted ())
+ return true; // remove permission and
continue stack walk
foreach (IPermission p in frame.Assert) {
if (CheckAssert (p as
CodeAccessPermission)) {
- // FIXME: partial asserts
- return true; // stop the stack
walk
+ return true; // remove
permission and continue stack walk
}
}
}
Modified: trunk/mcs/class/corlib/System.Security/HostSecurityManager.cs
===================================================================
--- trunk/mcs/class/corlib/System.Security/HostSecurityManager.cs
2005-06-22 18:04:17 UTC (rev 46377)
+++ trunk/mcs/class/corlib/System.Security/HostSecurityManager.cs
2005-06-22 18:35:41 UTC (rev 46378)
@@ -73,7 +73,7 @@
throw new ArgumentException (string.Format
(msg, "ActivationContext", "ActivationArguments"), "applicationEvidence");
}
- // FIXME: this part is still untested
+ // FIXME: this part is still untested (requires
manifest support)
if
(ApplicationSecurityManager.DetermineApplicationTrust (aa.ActivationContext,
context)) {
if (aa.ApplicationIdentity == null)
return new ApplicationTrust ();
Modified: trunk/mcs/class/corlib/System.Security/PermissionSet.cs
===================================================================
--- trunk/mcs/class/corlib/System.Security/PermissionSet.cs 2005-06-22
18:04:17 UTC (rev 46377)
+++ trunk/mcs/class/corlib/System.Security/PermissionSet.cs 2005-06-22
18:35:41 UTC (rev 46378)
@@ -61,6 +61,7 @@
private PolicyLevel _policyLevel;
private bool _declsec;
private bool _readOnly;
+ private bool[] _ignored; // for asserts and non-CAS permissions
// constructors
@@ -206,25 +207,29 @@
if (IsEmpty ())
return;
- PermissionSet cas = this;
- // avoid copy (if possible)
- if (ContainsNonCodeAccessPermissions ()) {
- // non CAS permissions (e.g.
PrincipalPermission) do not requires a stack walk
- cas = this.Copy ();
- foreach (IPermission p in list) {
- Type t = p.GetType ();
- if (!t.IsSubclassOf (typeof
(CodeAccessPermission))) {
- p.Demand ();
- // we wont have to process this
one in the stack walk
- cas.RemovePermission (t);
- }
+ int n = list.Count;
+ if ((_ignored == null) || (_ignored.Length != n)) {
+ _ignored = new bool [n];
+ }
+
+ bool call_cas_only = this.IsUnrestricted ();
+ // non CAS permissions (e.g. PrincipalPermission) do
not requires a stack walk
+ for (int i = 0; i < n; i++) {
+ CodeAccessPermission p = (CodeAccessPermission)
list [i];
+ Type t = p.GetType ();
+ if (t.IsSubclassOf (typeof
(CodeAccessPermission))) {
+ _ignored [i] = false;
+ call_cas_only = true;
+ } else {
+ _ignored [i] = true;
+ p.Demand ();
}
}
// don't start the stack walk if
// - the permission set only contains non CAS
permissions; or
// - security isn't enabled (applis only to CAS!)
- if (!cas.IsEmpty () && SecurityManager.SecurityEnabled)
+ if (call_cas_only && SecurityManager.SecurityEnabled)
CasOnlyDemand (_declsec ? 5 : 3);
}
@@ -237,6 +242,11 @@
Assembly current = null;
AppDomain domain = null;
+ if (_ignored == null) {
+ // special case when directly called from
CodeAccessPermission.Demand
+ _ignored = new bool [list.Count];
+ }
+
ArrayList frames = SecurityFrame.GetStack (skip);
if ((frames != null) && (frames.Count > 0)) {
SecurityFrame first = ((SecurityFrame) frames
[0]);
@@ -244,8 +254,10 @@
domain = first.Domain;
// skip ourself, Demand and other security
runtime methods
foreach (SecurityFrame sf in frames) {
- if (ProcessFrame (sf, ref current, ref
domain))
- return; // reached Assert
+ if (ProcessFrame (sf, ref current, ref
domain)) {
+ if (AllIgnored ())
+ return; // reached
Assert
+ }
}
SecurityFrame last = ((SecurityFrame) frames
[frames.Count - 1]);
CheckAssembly (current, last);
@@ -256,8 +268,10 @@
CompressedStack stack =
Thread.CurrentThread.GetCompressedStack ();
if ((stack != null) && !stack.IsEmpty ()) {
foreach (SecurityFrame frame in stack.List) {
- if (ProcessFrame (frame, ref current,
ref domain))
- return; // reached Assert
+ if (ProcessFrame (frame, ref current,
ref domain)) {
+ if (AllIgnored ())
+ return; // reached
Assert
+ }
}
}
}
@@ -664,7 +678,7 @@
set { _declsec = value; }
}
- [MonoTODO()]
+ [MonoTODO ("may not be required")]
void IDeserializationCallback.OnDeserialization (object sender)
{
}
@@ -703,10 +717,9 @@
return (list.Count == 0) ? (int) state :
base.GetHashCode ();
}
- [MonoTODO ("what's it doing here?")]
+ [MonoTODO ("(2.0) what's it doing here? There's probably a
reason this was added here.")]
static public void RevertAssert ()
{
- // FIXME: There's probably a reason this was added here
?
CodeAccessPermission.RevertAssert ();
}
#endif
@@ -723,6 +736,19 @@
_readOnly = value;
}
+ private bool AllIgnored ()
+ {
+ if (_ignored == null)
+ throw new NotSupportedException ("bad bad bad");
+
+ for (int i=0; i < _ignored.Length; i++) {
+ if (!_ignored [i])
+ return false;
+ }
+ // everything is ignored (i.e. non-CAS permission or
asserted permission).
+ return true;
+ }
+
internal bool ProcessFrame (SecurityFrame frame, ref Assembly
current, ref AppDomain domain)
{
if (IsUnrestricted ()) {
@@ -738,9 +764,13 @@
// skip next steps if no Assert, Deny or PermitOnly are
present
if (frame.HasStackModifiers) {
- foreach (CodeAccessPermission cap in list) {
- if (cap.ProcessFrame (frame))
- return true; // Assert reached
- abort stack walk!
+ for (int i = 0; i < list.Count; i++) {
+ CodeAccessPermission cap =
(CodeAccessPermission) list [i];
+ if (cap.ProcessFrame (frame)) {
+ _ignored [i] = true; // asserted
+ if (AllIgnored ())
+ return true; // no
more, abort stack walk!
+ }
}
}
@@ -820,7 +850,7 @@
static object[] action = new object [1] { (SecurityAction) 0 };
- // TODO: add support for arrays and enums
+ // TODO: add support for arrays and enums (2.0)
internal static IPermission ProcessAttribute (byte[] data, ref
int position)
{
int clen = ReadEncodedInt (data, ref position);
@@ -868,7 +898,7 @@
object[] arrayIndex = null;
for (int i = 0; i < arrayLength; i++) {
if (array) {
- // TODO - setup index
+ // TODO - setup index (2.0)
}
// sadly type values doesn't match ther
TypeCode enum :(
Modified: trunk/mcs/class/corlib/System.Security/SecurityException.cs
===================================================================
--- trunk/mcs/class/corlib/System.Security/SecurityException.cs 2005-06-22
18:04:17 UTC (rev 46377)
+++ trunk/mcs/class/corlib/System.Security/SecurityException.cs 2005-06-22
18:35:41 UTC (rev 46378)
@@ -59,6 +59,7 @@
private MethodInfo _method;
private string _url;
private SecurityZone _zone;
+ private Evidence _evidence;
// Properties
@@ -259,7 +260,7 @@
_firstperm = permThatFailed;
if (_firstperm != null)
permissionType = _firstperm.GetType ();
- // FIXME ? evidence ?
+ _evidence = evidence;
}
// Methods
@@ -303,6 +304,9 @@
if (_firstperm != null) {
sb.AppendFormat ("{0}Failed Permission:
{1}", Environment.NewLine, FirstPermissionThatFailed);
}
+ if (_evidence != null) {
+ sb.AppendFormat ("{0}Evidence: {1}",
Environment.NewLine, _evidence);
+ }
}
catch (SecurityException) {
// some informations can't be displayed
Modified: trunk/mcs/class/corlib/System.Security/SecurityManager.cs
===================================================================
--- trunk/mcs/class/corlib/System.Security/SecurityManager.cs 2005-06-22
18:04:17 UTC (rev 46377)
+++ trunk/mcs/class/corlib/System.Security/SecurityManager.cs 2005-06-22
18:35:41 UTC (rev 46378)
@@ -292,19 +292,6 @@
ResolveIdentityPermissions (ps, evidence);
- // do we have the right to execute ?
- if (CheckExecutionRights) {
- // unless we have "Full Trust"...
- if (!ps.IsUnrestricted ()) {
- // ... we need to find a
SecurityPermission
- IPermission security = ps.GetPermission
(typeof (SecurityPermission));
- if (!_execution.IsSubsetOf (security)) {
- throw new PolicyException
(Locale.GetText (
- "Policy doesn't grant
the right to execute to the assembly."));
- }
- }
- }
-
return ps;
}
@@ -349,7 +336,6 @@
static private SecurityPermission _execution = new
SecurityPermission (SecurityPermissionFlag.Execution);
- [MonoTODO()]
public static PermissionSet ResolvePolicy (Evidence evidence,
PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out
PermissionSet denied)
{
PermissionSet resolved = ResolvePolicy (evidence);
@@ -359,6 +345,27 @@
"Policy doesn't grant the minimal
permissions required to execute the assembly."));
}
+ // do we check for execution rights ?
+ if (CheckExecutionRights) {
+ bool execute = false;
+ // an empty permissionset doesn't include
Execution
+ if (resolved != null) {
+ // unless we have "Full Trust"...
+ if (resolved.IsUnrestricted ()) {
+ execute = true;
+ } else {
+ // ... we need to find a
SecurityPermission
+ IPermission security =
resolved.GetPermission (typeof (SecurityPermission));
+ execute = _execution.IsSubsetOf
(security);
+ }
+ }
+
+ if (!execute) {
+ throw new PolicyException
(Locale.GetText (
+ "Policy doesn't grant the right
to execute the assembly."));
+ }
+ }
+
denied = denyPset;
return resolved;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches