- Timestamp:
- 09/01/15 14:10:37 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Sandboxing/SandboxManager.cs
r12012 r12926 25 25 using System.Security.Permissions; 26 26 using HeuristicLab.PluginInfrastructure.Manager; 27 using System.IO;28 27 29 28 namespace HeuristicLab.PluginInfrastructure.Sandboxing { … … 31 30 32 31 /// <summary> 33 /// Creates a nprivileged sandbox, meaning that the executed code is fully trusted and permissions are not restricted.32 /// Creates a privileged sandbox, meaning that the executed code is fully trusted and permissions are not restricted. 34 33 /// This method is a fall back for trusted users in HeuristicLab Hive. 35 34 /// </summary> 36 public static AppDomain CreateAndInit PrivilegedSandbox(string appDomainName, string applicationBase, string configFilePath) {35 public static AppDomain CreateAndInitSandbox(string appDomainName, string applicationBase, string configFilePath) { 37 36 PermissionSet pSet; 38 37 pSet = new PermissionSet(PermissionState.Unrestricted); … … 53 52 return applicationDomain; 54 53 } 55 56 /// <summary>57 /// Creates a sandbox with restricted permissions.58 /// Code that is executed in such an AppDomain is partially-trusted and is not allowed to call or override59 /// methods that require full trust.60 /// </summary>61 public static AppDomain CreateAndInitSandbox(string appDomainName, string applicationBase, string configFilePath) {62 PermissionSet pSet;63 64 pSet = new PermissionSet(PermissionState.None);65 pSet.AddPermission(new SecurityPermission(PermissionState.None));66 pSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));67 pSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Infrastructure));68 pSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));69 pSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));70 //needed for HeuristicLab.Persistence, see DynamicMethod Constructor (String, Type, array<Type []()>[], Type, Boolean)71 pSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence));72 pSet.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));73 74 FileIOPermission ioPerm = new FileIOPermission(PermissionState.None);75 //allow path discovery for system drive, needed by HeuristicLab.Persistence: Serializer.BuildTypeCache() -> Assembly.CodeBase76 ioPerm.AddPathList(FileIOPermissionAccess.PathDiscovery, Path.GetPathRoot(Path.GetFullPath(Environment.SystemDirectory)));77 //allow full access to the appdomain's base directory78 ioPerm.AddPathList(FileIOPermissionAccess.AllAccess, applicationBase);79 pSet.AddPermission(ioPerm);80 81 AppDomainSetup setup = new AppDomainSetup();82 setup.PrivateBinPath = applicationBase;83 setup.ApplicationBase = applicationBase;84 setup.ConfigurationFile = configFilePath;85 86 Type applicationManagerType = typeof(SandboxApplicationManager);87 AppDomain applicationDomain = AppDomain.CreateDomain(appDomainName, null, setup, pSet, null);88 SandboxApplicationManager applicationManager = (SandboxApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);89 90 PluginManager pm = new PluginManager(applicationBase);91 pm.DiscoverAndCheckPlugins();92 applicationManager.PrepareApplicationDomain(pm.Applications, pm.Plugins);93 94 return applicationDomain;95 }96 54 } 97 55 }
Note: See TracChangeset
for help on using the changeset viewer.