2
0
Эх сурвалжийг харах

2004-12-21 Sebastien Pouliot <[email protected]>

	* Assembly.cs: Added private LoadAssemblyPermissions to get the 
	declarative security permission sets (minimum, optional and refused)
	for the assembly.


svn path=/trunk/mcs/; revision=38031
Sebastien Pouliot 21 жил өмнө
parent
commit
35cfe26d59

+ 38 - 0
mcs/class/corlib/System.Reflection/Assembly.cs

@@ -708,6 +708,10 @@ namespace System.Reflection {
 		internal void Resolve () 
 		{
 			lock (this) {
+				// FIXME: As we (currently) delay the resolution until the first CAS
+				// Demand it's too late to evaluate the Minimum permission set as a 
+				// condition to load the assembly into the AppDomain
+				LoadAssemblyPermissions ();
 				_granted = SecurityManager.ResolvePolicy (Evidence, _minimum, _optional,
 					_refuse, out _denied);
 			}
@@ -745,5 +749,39 @@ namespace System.Reflection {
 				return _denied;
 			}
 		}
+
+		[MethodImplAttribute (MethodImplOptions.InternalCall)]
+		extern internal static bool LoadPermissions (Assembly a, 
+			ref IntPtr minimum, ref int minLength,
+			ref IntPtr optional, ref int optLength,
+			ref IntPtr refused, ref int refLength);
+
+		// Support for SecurityAction.RequestMinimum, RequestOptional and RequestRefuse
+		private void LoadAssemblyPermissions ()
+		{
+			IntPtr minimum = IntPtr.Zero, optional = IntPtr.Zero, refused = IntPtr.Zero;
+			int minLength = 0, optLength = 0, refLength = 0;
+			if (LoadPermissions (this, ref minimum, ref minLength, ref optional,
+				ref optLength, ref refused, ref refLength)) {
+
+				// Note: no need to cache these permission sets as they will only be created once
+				// at assembly resolution time.
+				if (minLength > 0) {
+					byte[] data = new byte [minLength];
+					Marshal.Copy (minimum, data, 0, minLength);
+					_minimum = SecurityManager.Decode (data);
+				}
+				if (optLength > 0) {
+					byte[] data = new byte [optLength];
+					Marshal.Copy (optional, data, 0, optLength);
+					_optional = SecurityManager.Decode (data);
+				}
+				if (refLength > 0) {
+					byte[] data = new byte [refLength];
+					Marshal.Copy (refused, data, 0, refLength);
+					_refuse = SecurityManager.Decode (data);
+				}
+			}
+		}
 	}
 }

+ 6 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,9 @@
+2004-12-21  Sebastien Pouliot  <[email protected]> 
+
+	* Assembly.cs: Added private LoadAssemblyPermissions to get the 
+	declarative security permission sets (minimum, optional and refused)
+	for the assembly.
+
 2004-12-20  Sebastien Pouliot  <[email protected]>
 
 	* Assembly.cs: Removed old Demand support (moved in System.Security).