//The available settings for the partial trust sandboxes /// <summary> /// Transform from a PermSetNames enum tu a PermissionSet /// </summary> /// <param name="permSetName">The sandbox that we want</param> /// <returns>The actual permission set</returns> public static PermissionSet GetStandardPermission(PermSetNames permSetName) { PermissionSet ps = null; switch (permSetName) { case PermSetNames.Execution: ps = GetExecutionPermissionSet(); break; case PermSetNames.Internet: ps = GetInternetPermissionSet(); break; case PermSetNames.LocalIntranet: ps = GetIntranetPermissionSet(); break; case PermSetNames.Everything: ps = GetEverythingPermissionSet(); break; case PermSetNames.FullTrust: ps = GetFullTrustPermissionSet(); break; } return(ps); }
/// <summary> /// Create a new sandbox AppDomain with the permission and full trust list passed and initialize /// a new instance of the type T in it /// </summary> /// <typeparam name="T">The type that will be instantiated in the new domain. This has to be a MarshalByRefObject</typeparam> /// <param name="psName">Name of standard permission set for the new domain</param> /// <param name="fullTrustList">List of full trust assemblies. All assemblies in this list have to be fully trusted</param> /// <returns>An instance in the new sandboxed AppDomain</returns> public static T GetPartialTrustInstance <T>(PermSetNames psName, params Assembly[] fullTrustList) where T : MarshalByRefObject { return(GetPartialTrustInstance <T>(GetStandardPermission(psName), fullTrustList)); }
/// <summary> /// Command line parser. /// </summary> /// <param name="args">The command line arguments</param> /// <returns>A structure with information about the run</returns> private static CommandLineData ParseCommandLine(string[] args) { try { int i = 0; CommandLineData ret = new CommandLineData(); while (i < args.Length) { if (args[i].StartsWith("-")) { switch (args[i]) { //The partial trust PermissionSet case "-ps": PermSetNames permSet = (PermSetNames)Enum.Parse(typeof(PermSetNames), args[++i], true); ret.permission = PTRunnerLib.GetStandardPermission(permSet); break; //Add full trust assembly case "-af": Assembly asm = Assembly.LoadFrom(args[++i]); ret.fullTrustAssemblies.Add(asm); break; case "-xml": StreamReader sr = new StreamReader(args[++i]); SecurityElement elem = SecurityElement.FromString(sr.ReadToEnd()); ret.permission = new PermissionSet(PermissionState.None); ret.permission.FromXml(elem); break; default: Console.WriteLine("{0} - unknonw option", args[i]); Usage(); return(null); } ++i; } else { break; } } if (i < args.Length) { //This are the arguments for the program that will be run ret.programName = args[i++]; int argsSize = args.Length - i; ret.arguments = new string[argsSize]; if (argsSize > 0) { Array.Copy(args, i, ret.arguments, 0, argsSize); } if (ret.permission == null) { ret.permission = PTRunnerLib.GetStandardPermission(PermSetNames.Execution); } return(ret); } } catch (Exception ex) { Console.WriteLine(":RUNNER: Got exception while parsing command line: {0}", ex.Message); } Usage(); return(null); }