Author: spouliot
Date: 2005-04-05 09:36:32 -0400 (Tue, 05 Apr 2005)
New Revision: 42563

Modified:
   trunk/mcs/class/corlib/System/AppDomain.cs
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/_AppDomain.cs
Log:
2005-04-05  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * _AppDomain.cs: Add security checks to the interface. Declarative 
        security on events requires BOOTSTRAP_WITH_OLDLIB to work properly 
        with older MCS.
        * AppDomain.cs: Add some (not complete) security checks. Bug#74411 is
        blocking some cases from working properly. Declarative security on 
        events requires BOOTSTRAP_WITH_OLDLIB to work properly with older MCS.



Modified: trunk/mcs/class/corlib/System/AppDomain.cs
===================================================================
--- trunk/mcs/class/corlib/System/AppDomain.cs  2005-04-05 13:20:01 UTC (rev 
42562)
+++ trunk/mcs/class/corlib/System/AppDomain.cs  2005-04-05 13:36:32 UTC (rev 
42563)
@@ -67,7 +67,6 @@
                // CAS
                private Evidence _evidence;
                private PermissionSet _granted;
-               internal PermissionSet _refused;
 
                // non-CAS
                private PrincipalPolicy _principalPolicy;
@@ -95,21 +94,38 @@
 
                public string BaseDirectory {
                        get {
-                               return SetupInformationNoCopy.ApplicationBase;
+                               string path = 
SetupInformationNoCopy.ApplicationBase;
+                               if (SecurityManager.SecurityEnabled && (path != 
null) && (path.Length > 0)) {
+                                       // we cannot divulge local file 
informations
+                                       new FileIOPermission 
(FileIOPermissionAccess.PathDiscovery, path).Demand ();
+                               }
+                               return path;
                        }
                }
 
                public string RelativeSearchPath {
                        get {
-                               return SetupInformationNoCopy.PrivateBinPath;
+                               string path = 
SetupInformationNoCopy.PrivateBinPath;
+                               if (SecurityManager.SecurityEnabled && (path != 
null) && (path.Length > 0)) {
+                                       // we cannot divulge local file 
informations
+                                       new FileIOPermission 
(FileIOPermissionAccess.PathDiscovery, path).Demand ();
+                               }
+                               return path;
                        }
                }
 
                public string DynamicDirectory {
                        get {
                                AppDomainSetup setup = SetupInformationNoCopy;
-                               if (setup.DynamicBase == null) return null;
-                               return Path.Combine (setup.DynamicBase, 
setup.ApplicationName);
+                               if (setup.DynamicBase == null)
+                                       return null;
+
+                               string path = Path.Combine (setup.DynamicBase, 
setup.ApplicationName);
+                               if (SecurityManager.SecurityEnabled && (path != 
null) && (path.Length > 0)) {
+                                       // we cannot divulge local file 
informations
+                                       new FileIOPermission 
(FileIOPermissionAccess.PathDiscovery, path).Demand ();
+                               }
+                               return path;
                        }
                }
 
@@ -191,6 +207,7 @@
 #if NET_2_0
                [Obsolete ("")]
 #endif
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void AppendPrivatePath (string path)
                {
                        if (path == null || path.Length == 0)
@@ -214,11 +231,13 @@
 #if NET_2_0
                [Obsolete ("")]
 #endif
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void ClearPrivatePath ()
                {
                        SetupInformationNoCopy.PrivateBinPath = String.Empty;
                }
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void ClearShadowCopyPath ()
                {
                        SetupInformationNoCopy.ShadowCopyDirectories = 
String.Empty;
@@ -544,12 +563,13 @@
                        _granted = ps.PermissionSet;
                }
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void SetCachePath (string path)
                {
                        SetupInformationNoCopy.CachePath = path;
                }
 
-               [SecurityPermission (SecurityAction.Demand, 
Flags=SecurityPermissionFlag.ControlPolicy)]
+               [SecurityPermission (SecurityAction.Demand, ControlPrincipal = 
true)]
                public void SetPrincipalPolicy (PrincipalPolicy policy)
                {
                        if (IsFinalizingForUnload ())
@@ -559,17 +579,19 @@
                        _principal = null;
                }
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void SetShadowCopyFiles()
                {
                        SetupInformationNoCopy.ShadowCopyFiles = "true";
                }
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void SetShadowCopyPath (string path)
                {
                        SetupInformationNoCopy.ShadowCopyDirectories = path;
                }
 
-               [SecurityPermission (SecurityAction.Demand, 
Flags=SecurityPermissionFlag.ControlPolicy)]
+               [SecurityPermission (SecurityAction.Demand, ControlPrincipal = 
true)]
                public void SetThreadPrincipal (IPrincipal principal)
                {
                        if (principal == null)
@@ -676,6 +698,7 @@
                private static extern AppDomain createDomain (string 
friendlyName, AppDomainSetup info);
 
                [MonoTODO ("allow setup in the other domain")]
+               [SecurityPermission (SecurityAction.Demand, ControlAppDomain = 
true)]
                public static AppDomain CreateDomain (string friendlyName, 
Evidence securityInfo, AppDomainSetup info)
                {
                        if (friendlyName == null)
@@ -743,6 +766,7 @@
                        return Thread.GetDomainID ();
                }
 
+               [SecurityPermission (SecurityAction.Demand, ControlAppDomain = 
true)]
                public static void Unload (AppDomain domain)
                {
                        if (domain == null)
@@ -752,8 +776,10 @@
                }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public extern void SetData (string name, object data);
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                public void SetDynamicBase (string path)
                {
                        SetupInformationNoCopy.DynamicBase = path;
@@ -900,6 +926,10 @@
 
                // End of methods called from the runtime
                
+#if BOOTSTRAP_WITH_OLDLIB
+               // older MCS/corlib returns:
+               // _AppDomain.cs(138) error CS0592: Attribute 
'SecurityPermission' is not valid on this declaration type.
+               // It is valid on 'assembly' 'class' 'constructor' 'method' 
'struct'  declarations only.
                public event AssemblyLoadEventHandler AssemblyLoad;
 
                public event ResolveEventHandler AssemblyResolve;
@@ -913,7 +943,29 @@
                public event ResolveEventHandler TypeResolve;
 
                public event UnhandledExceptionEventHandler UnhandledException;
+#else
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event AssemblyLoadEventHandler AssemblyLoad;
 
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event ResolveEventHandler AssemblyResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event EventHandler DomainUnload;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event EventHandler ProcessExit;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event ResolveEventHandler ResourceResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event ResolveEventHandler TypeResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               public event UnhandledExceptionEventHandler UnhandledException;
+#endif
+
                /* Avoid warnings for events used only by the runtime */
                private void DummyUse () {
                        ProcessExit += (EventHandler)null;

Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2005-04-05 13:20:01 UTC (rev 
42562)
+++ trunk/mcs/class/corlib/System/ChangeLog     2005-04-05 13:36:32 UTC (rev 
42563)
@@ -1,3 +1,12 @@
+2005-04-05  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * _AppDomain.cs: Add security checks to the interface. Declarative 
+       security on events requires BOOTSTRAP_WITH_OLDLIB to work properly 
+       with older MCS.
+       * AppDomain.cs: Add some (not complete) security checks. Bug#74411 is
+       blocking some cases from working properly. Declarative security on 
+       events requires BOOTSTRAP_WITH_OLDLIB to work properly with older MCS.
+
 2005-04-04  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AppDomain.cs: Use the PolicyLevel to resolve the granted permissions

Modified: trunk/mcs/class/corlib/System/_AppDomain.cs
===================================================================
--- trunk/mcs/class/corlib/System/_AppDomain.cs 2005-04-05 13:20:01 UTC (rev 
42562)
+++ trunk/mcs/class/corlib/System/_AppDomain.cs 2005-04-05 13:36:32 UTC (rev 
42563)
@@ -4,10 +4,8 @@
 // Author:
 //   Duco Fijma ([EMAIL PROTECTED])
 //
-
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -29,6 +27,7 @@
 //
 
 using System.Security;
+using System.Security.Permissions;
 using System.Security.Policy;
 using System.Security.Principal;
 using System.Reflection;
@@ -51,8 +50,13 @@
                string RelativeSearchPath {get; }
                bool ShadowCopyFiles {get; }
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void AppendPrivatePath (string path);
+
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void ClearPrivatePath ();
+
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void ClearShadowCopyPath ();
 
                ObjectHandle CreateInstance (string assemblyName, string 
typeName);
@@ -95,8 +99,13 @@
                Assembly[] GetAssemblies ();
                object GetData (string name);
                int GetHashCode();
+
+               [SecurityPermission (SecurityAction.LinkDemand, Infrastructure 
= true)]
                object GetLifetimeService ();
+
                Type GetType ();
+
+               [SecurityPermission (SecurityAction.LinkDemand, Infrastructure 
= true)]
                object InitializeLifetimeService ();
 
                Assembly Load (AssemblyName assemblyRef);
@@ -107,14 +116,27 @@
                Assembly Load (string assemblyString, Evidence 
assemblySecurity);
                Assembly Load (byte[] rawAssembly, byte[] rawSymbolStore, 
Evidence securityEvidence);
 
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void SetAppDomainPolicy (PolicyLevel domainPolicy);
+
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void SetCachePath (string s);
+
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void SetData (string name, object data);
+
                void SetPrincipalPolicy (PrincipalPolicy policy);
+
+               [SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
                void SetShadowCopyPath (string s);
+
                void SetThreadPrincipal (IPrincipal principal);
                string ToString ();
 
+#if BOOTSTRAP_WITH_OLDLIB
+               // older MCS/corlib returns:
+               // _AppDomain.cs(138) error CS0592: Attribute 
'SecurityPermission' is not valid on this declaration type.
+               // It is valid on 'assembly' 'class' 'constructor' 'method' 
'struct'  declarations only.
                event AssemblyLoadEventHandler AssemblyLoad;
                event ResolveEventHandler AssemblyResolve;
                event EventHandler DomainUnload;
@@ -122,5 +144,27 @@
                event ResolveEventHandler ResourceResolve;
                event ResolveEventHandler TypeResolve;
                event UnhandledExceptionEventHandler UnhandledException;
+#else
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event AssemblyLoadEventHandler AssemblyLoad;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event ResolveEventHandler AssemblyResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event EventHandler DomainUnload;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event EventHandler ProcessExit;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event ResolveEventHandler ResourceResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event ResolveEventHandler TypeResolve;
+
+               [method: SecurityPermission (SecurityAction.LinkDemand, 
ControlAppDomain = true)]
+               event UnhandledExceptionEventHandler UnhandledException;
+#endif
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to