protected override IStackWalk CreateStackWalk() { FileIOPermission permission = new FileIOPermission(PermissionState.Unrestricted); permission.AllFiles = attribute.AllFiles; permission.AllLocalFiles = attribute.AllLocalFiles; return permission; }
public void SetUp () { Environment.CurrentDirectory = Path.GetTempPath(); filename = Path.GetTempFileName (); int os = (int) Environment.OSVersion.Platform; unix = ((os == 4) || (os == 128) || (os == 6)); p = null; pathsInPermission = null; pathArrayGood = new string[2]; pathArrayBad = new string[2]; pathArrayGood2 = new string[3]; // FIXME: Adjust to run on Mac OS's if (Path.VolumeSeparatorChar == ':') { pathArrayGood[0] = "c:\\temp1"; pathArrayGood[1] = "d:\\temp2"; pathArrayBad[0] = "c:\\temp1"; pathArrayBad[1] = "d:\\temp*"; pathArrayGood2[0] = "c:\\temp1"; pathArrayGood2[1] = "d:\\temp2"; pathArrayGood2[2] = "z:\\something"; } else { pathArrayGood[0] = "/temp1"; pathArrayGood[1] = "/usr/temp2"; pathArrayBad[0] = "/temp1"; pathArrayBad[1] = "/usr/temp*"; // not really bad under Unix... pathArrayGood2[0] = "/temp1"; pathArrayGood2[1] = "/usr/temp2"; pathArrayGood2[2] = "/usr/bin/something"; } }
public IPermission Parse(JToken token) { var accessList = token as JArray; if (accessList == null) { return null; } var result = new FileIOPermission(PermissionState.None); foreach (var item in accessList) { var obj = item as JObject; if (obj == null) { continue; } var access = obj["access"].ToObject<string[]>(); var paths = obj["paths"].ToObject<string[]>(); var fileAccess = FileIOPermissionAccess.NoAccess; if (access.Contains("read")) fileAccess |= FileIOPermissionAccess.Read; if (access.Contains("write")) fileAccess |= FileIOPermissionAccess.Write; if (access.Contains("discover")) fileAccess |= FileIOPermissionAccess.PathDiscovery; if (access.Contains("append")) fileAccess |= FileIOPermissionAccess.Append; result.AddPathList(fileAccess, paths); } return result; }
public Image ScanImage(ImageFormat outputFormat, string fileName) { if (outputFormat == null) throw new ArgumentNullException("outputFormat"); FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileName); filePerm.Demand(); ImageFile imageObject = null; try { if (WiaManager == null) WiaManager = new CommonDialogClass(); imageObject = WiaManager.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality, outputFormat.Guid.ToString("B"), false, true, true); imageObject.SaveFile(fileName); return Image.FromFile(fileName); } catch (COMException ex) { string message = "Error scanning image"; throw new WiaOperationException(message, ex); } finally { if (imageObject != null) Marshal.ReleaseComObject(imageObject); } }
private static string _strRootFolder; //定义操作的根目录 /// <summary> /// 文件是否存在 /// </summary> /// <param name="filePath">文件路径</param> /// <returns></returns> public static bool FileExists(string filePath) { if (File.Exists(filePath)) { return true; } FileIOPermission permission = null; try { permission = new FileIOPermission(FileIOPermissionAccess.Read, filePath); } catch { return false; } try { permission.Demand(); } catch (Exception exception) { // Foe.Common.Log.ErrorFormat(string.Format("FileManager doesn't have the right to read the config file \"{0}\". Cause : {1}", filePath, exception.Message), exception); } return false; }
static void Main() { FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, AppConst.BASE_PATH); if (!SecurityManager.IsGranted(writePermission)) { MessageBox.Show("Please run this software by administrator permission"); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string email = Utility.ReadAppRegistry("settv", "ru_email"); string key = Utility.ReadAppRegistry("settv", "ru_key"); if (Register.RegisterUser(email, key) == false) { DialogResult trial_running = MessageBox.Show("Do you want to run trial?", "Saterllite TV Trial", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (trial_running == DialogResult.Yes) Application.Run(new MainApp()); else Application.Run(new RegisterForm()); } else Application.Run(new MainApp()); }
/// <summary> /// Initializes the permissions manager with the permissions required by an install script. /// </summary> internal static void Init() { permissions = new PermissionSet(PermissionState.None); //do the following paths need to add to this? // savesPath - fallout 3 var fipFilePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, new[] { Program.tmpPath, Path.GetTempPath(), Program.GameMode.InstallInfoDirectory, Program.GameMode.PluginsPath }); var lstPaths = new List<string>(Program.GameMode.SettingsFiles.Values); lstPaths.AddRange(Program.GameMode.AdditionalPaths.Values); fipFilePermission.AddPathList(FileIOPermissionAccess.AllAccess, lstPaths.ToArray()); fipFilePermission.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory); permissions.AddPermission(fipFilePermission); permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode)); permissions.AddPermission(new UIPermission(UIPermissionWindow.AllWindows)); // Not sure what permissions are needed for GetTempFileName() to work, so we add them all. permissions.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted)); }
public static bool CopyFile(string newFile, string oldFile) { var newfile = new FileInfo(newFile); var oldfile = new FileInfo(oldFile); string errorMsg = ""; var f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, oldFile); f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, newFile); try { f2.Demand(); } catch (SecurityException s) { Console.WriteLine(s.Message); } for (int x = 0; x < 100; x++) { try { File.Delete(oldfile.FullName); newfile.CopyTo(oldfile.FullName, true); return true; } catch(Exception e) { errorMsg = e.Message + " : " + e.InnerException; Thread.Sleep(200); } } Data.Logger(errorMsg); return false; }
public void FlatFileListenerWillFallbackIfNotPriviledgesToWrite() { string fileName = @"trace.log"; string fullPath = String.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), fileName); File.Delete(fileName); FileIOPermission fileIOPerm1 = new FileIOPermission(PermissionState.None); fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, fullPath); fileIOPerm1.PermitOnly(); try { FlatFileTraceListener listener = new FlatFileTraceListener(fileName, "---header---", "***footer***", new TextFormatter("DUMMY{newline}DUMMY")); // need to go through the source to get a TraceEventCache LogSource source = new LogSource("notfromconfig", new[] { listener }, SourceLevels.All); source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null)); listener.Dispose(); } catch (SecurityException) { FileIOPermission.RevertAll(); throw; } }
private static bool CanWriteToFolder(string folder) { var permission = new FileIOPermission(FileIOPermissionAccess.Write, folder); var permissionSet = new PermissionSet(PermissionState.None); permissionSet.AddPermission(permission); return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); }
private void InThread(ControllerContext context, Action<ControllerContext> functor) { var timeout = int.Parse(ConfigurationManager.AppSettings["SandboxTimeout"] ?? "5"); var thread = new Thread(()=> { try { var fileIo = new FileIOPermission(FileIOPermissionAccess.Read,AppDomain.CurrentDomain.BaseDirectory); fileIo.AllLocalFiles = FileIOPermissionAccess.NoAccess; fileIo.PermitOnly(); functor(context); } catch(Exception e) { // 全部書きだす context.HttpContext.Response.Write(e.Message); } }); thread.Start(); thread.Join(timeout*1000); if(thread.IsAlive) { thread.Abort(); throw new HttpException((int)HttpStatusCode.InternalServerError, "処理が長すぎ(" + timeout + "秒で終わらせてね)"); } }
public void SetUp () { Environment.CurrentDirectory = Path.GetTempPath(); filename = Path.GetTempFileName (); p = null; pathsInPermission = null; pathArrayGood = new string[2]; pathArrayBad = new string[2]; pathArrayGood2 = new string[3]; // FIXME: Adjust to run on Mac OS's if (Path.VolumeSeparatorChar == ':') { pathArrayGood[0] = "c:\\temp1"; pathArrayGood[1] = "d:\\temp2"; pathArrayBad[0] = "c:\\temp1"; pathArrayBad[1] = "d:\\temp*"; pathArrayGood2[0] = "c:\\temp1"; pathArrayGood2[1] = "d:\\temp2"; pathArrayGood2[2] = "z:\\something"; } else { pathArrayGood[0] = "/temp1"; pathArrayGood[1] = "/usr/temp2"; pathArrayBad[0] = "/temp1"; pathArrayBad[1] = "/usr/temp*"; pathArrayGood2[0] = "/temp1"; pathArrayGood2[1] = "/usr/temp2"; pathArrayGood2[2] = "/usr/bin/something"; } }
public virtual void Setup() { var sp = new FileIOPermission(PermissionState.Unrestricted); sp.Assert(); string prefix; if (Environment.CurrentDirectory.EndsWith("target")) { prefix = "../../"; } else { prefix = "../../../"; } sp.Deny(); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); BridgeSetup setup=new BridgeSetup (false){Verbose = true, Debug = true}; setup.IgnoreJavaHome = true; setup.AddJVMOption("-Xmx512m"); setup.AddClassPath(prefix + "jni4net.j/target/classes"); setup.AddClassPath(prefix + "jni4net.tested.j/target/classes"); setup.AddClassPath(prefix + "jni4net.test.j/target/test-classes"); //setup.JavaHome = @"c:\Program Files (x86)\Java\ibm_sdk60"; env = Bridge.CreateJVM(setup); Bridge.RegisterAssembly(typeof(TestBase).Assembly); Bridge.RegisterAssembly(typeof(JavaInstanceFields).Assembly); }
// Methods public static bool FileExists(string filePath) { if (File.Exists(filePath)) { return true; } FileIOPermission permission = null; try { permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, filePath); } catch { return false; } try { permission.Demand(); } catch (Exception exception) { // } return false; }
private AppDomain CreateAnalyzerDomain() { AppDomainSetup ads = new AppDomainSetup(); AppDomain result; PermissionSet perms; ads.ApplicationBase = Environment.CurrentDirectory; ads.ShadowCopyDirectories = "shadow"; ads.ShadowCopyFiles = "shadow"; ads.DisallowCodeDownload = true; perms = new PermissionSet(PermissionState.None); FileIOPermission fiop = new FileIOPermission(PermissionState.Unrestricted); perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags)); fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory); fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory); fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory + "Extensions\\"); fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory + "Extensions\\"); //fiop.AllLocalFiles = FileIOPermissionAccess.AllAccess //fiop.AllFiles = FileIOPermissionAccess.AllAccess perms.AddPermission(fiop); perms.AddPermission(new UIPermission(UIPermissionWindow.AllWindows, UIPermissionClipboard.OwnClipboard)); perms.AddPermission(new ReflectionPermission(PermissionState.Unrestricted)); PolicyLevel policy = PolicyLevel.CreateAppDomainLevel(); policy.RootCodeGroup.PolicyStatement = new PolicyStatement(perms); // create the Domain result = AppDomain.CreateDomain("analyzer", null, ads); result.SetAppDomainPolicy(policy); return result; }
public void Capture( OnlineCaptureInfo info ) { try { // Ensure permission to write to the archive directory. FileIOPermission p = new FileIOPermission( FileIOPermissionAccess.Write, new FileInfo( info.ArchiveDir ).FullName ); p.Demand(); logger = info.Logger; string html = CaptureText( info.AccountName, info.Credentials ); // Write HTML results to file string filename = Path.Combine( info.ArchiveDir, info.BaseName + ".htm" ); info.CapturedFiles.Add( Path.GetFileName( filename ) ); File.WriteAllText( filename, html ); } catch( SecurityException ex ) { throw new OnlineReaderException( "Security violation: " + ex.Message, ex ); } }
static void Main(string[] args) { CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"c:\audit.txt"); permission.Deny(); AuditClass.Save("some data to audit"); CodeAccessPermission.RevertDeny(); }
public override IPermission CreatePermission() { if (base.m_unrestricted) { return new FileIOPermission(PermissionState.Unrestricted); } FileIOPermission permission = new FileIOPermission(PermissionState.None); if (this.m_read != null) { permission.SetPathList(FileIOPermissionAccess.Read, this.m_read); } if (this.m_write != null) { permission.SetPathList(FileIOPermissionAccess.Write, this.m_write); } if (this.m_append != null) { permission.SetPathList(FileIOPermissionAccess.Append, this.m_append); } if (this.m_pathDiscovery != null) { permission.SetPathList(FileIOPermissionAccess.PathDiscovery, this.m_pathDiscovery); } if (this.m_viewAccess != null) { permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.View, new string[] { this.m_viewAccess }, false); } if (this.m_changeAccess != null) { permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new string[] { this.m_changeAccess }, false); } permission.AllFiles = this.m_allFiles; permission.AllLocalFiles = this.m_allLocalFiles; return permission; }
static void Main(string[] args) { CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\"); permission.Deny(); UntrustworthyClass.Method(); CodeAccessPermission.RevertDeny(); }
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { base.Initialize(name, config); if (string.IsNullOrEmpty(config["dataStorePath"])) throw new ProviderException("dataStorePath config attribute is required."); this._dataStorePath = config["dataStorePath"]; if (!VirtualPathUtility.IsAppRelative(this._dataStorePath)) throw new ArgumentException("dataStorePath must be app-relative"); string fullyQualifiedPath = VirtualPathUtility.Combine( VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), this._dataStorePath); this._dataStorePath = HostingEnvironment.MapPath(fullyQualifiedPath); config.Remove("dataStorePath"); // Make sure we have permission to read the XML data source and // throw an exception if we don't if (!Directory.Exists(this._dataStorePath)) Directory.CreateDirectory(this._dataStorePath); FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess, this._dataStorePath); permission.Demand(); if (config.Count > 0) throw new ProviderException(string.Format("Unknown config attribute '{0}'", config.GetKey(0))); }
public static bool NeedsAdministratorRights() { var permissionSet = new PermissionSet(PermissionState.None); var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, HostsFileManager.Filename); permissionSet.AddPermission(writePermission); return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); }
internal IsolatedStorageFileEnumerator(IsolatedStorageScope scope) { this.m_Scope = scope; this.m_fiop = IsolatedStorageFile.GetGlobalFileIOPerm(scope); this.m_rootDir = IsolatedStorageFile.GetRootDir(scope); this.m_fileEnum = new TwoLevelFileEnumerator(this.m_rootDir); this.Reset(); }
private static bool EnsureActivateContextCreated() { lock (typeof(EnableThemingInScope)) { if (!contextCreationSucceeded) { // Pull manifest from the .NET Framework install // directory string assemblyLoc = null; FileIOPermission fiop = new FileIOPermission(PermissionState.None); fiop.AllFiles = FileIOPermissionAccess.PathDiscovery; fiop.Assert(); try { assemblyLoc = typeof(Object).Assembly.Location; } finally { CodeAccessPermission.RevertAssert(); } string manifestLoc = null; string installDir = null; if (assemblyLoc != null) { installDir = Path.GetDirectoryName(assemblyLoc); const string manifestName = "XPThemes.manifest"; manifestLoc = Path.Combine(installDir, manifestName); } if (manifestLoc != null && installDir != null) { enableThemingActivationContext = new ACTCTX(); enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(ACTCTX)); enableThemingActivationContext.lpSource = manifestLoc; // Set the lpAssemblyDirectory to the install // directory to prevent Win32 Side by Side from // looking for comctl32 in the application // directory, which could cause a bogus dll to be // placed there and open a security hole. enableThemingActivationContext.lpAssemblyDirectory = installDir; enableThemingActivationContext.dwFlags = ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID; // Note this will fail gracefully if file specified // by manifestLoc doesn't exist. hActCtx = CreateActCtx(ref enableThemingActivationContext); contextCreationSucceeded = (hActCtx != new IntPtr(-1)); } } // If we return false, we'll try again on the next call into // EnsureActivateContextCreated(), which is fine. return contextCreationSucceeded; } }
private static FileIOPermission CreateRWAPFileIOPermission (params string[] paths) { var permission = new FileIOPermission (PermissionState.None); permission.AddPathList (FileIOPermissionAccess.Read, paths); permission.AddPathList (FileIOPermissionAccess.Write, paths); permission.AddPathList (FileIOPermissionAccess.Append, paths); permission.AddPathList (FileIOPermissionAccess.PathDiscovery, paths); return permission; }
/// <summary> /// Creates a new WebTransform. /// </summary> public WebTransform() { //[IsolatedStorageFilePermissionAttribute(SecurityAction.Demand, Unrestricted=true)] FileIOPermission filePerm = new FileIOPermission(PermissionState.None); RegistryPermission regPerm = new RegistryPermission(PermissionState.None); filePerm.Demand(); regPerm.Demand(); }
private static bool canRead(String path) { FileIOPermission readPermission = new FileIOPermission(FileIOPermissionAccess.Read, path); if (SecurityManager.IsGranted(readPermission)) { return true; } return false; }
private void ShowFileReadUI() { MessageBox.Show("Before calling demand"); FileIOPermission myPerm = new FileIOPermission(FileIOPermissionAccess.Read, "C:\\"); myPerm.Demand(); // All callers must have read permission to C drive. // Note: Using imperative syntax // Code to show UI MessageBox.Show("Showing FileRead UI"); // This is executed only if the demand is successful. }
/// <summary> /// Returns a dictionary of right names and the roles associated with them. /// </summary> /// <returns></returns> public override IDictionary<string, IEnumerable<string>> FillRights() { var path = string.Format("{0}rights.xml", BlogConfig.StorageLocation); if (!VirtualPathUtility.IsAppRelative(path)) { throw new ArgumentException("rights must be app-relative"); } var fullyQualifiedPath = VirtualPathUtility.Combine( VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), path); fullyQualifiedPath = HostingEnvironment.MapPath(fullyQualifiedPath); var rightsDict = new Dictionary<string, IEnumerable<string>>(); if (File.Exists(fullyQualifiedPath)) { // Make sure we have permission to read the XML data source and // throw an exception if we don't var permission = new FileIOPermission(FileIOPermissionAccess.Write, fullyQualifiedPath); permission.Demand(); var doc = new XmlDocument(); doc.Load(fullyQualifiedPath); foreach (XmlNode rightNode in doc.GetElementsByTagName("right")) { var rightName = rightNode.Attributes["name"].Value; var roleList = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (XmlNode roleNode in rightNode.ChildNodes) { if (roleNode.Name.Equals("role", StringComparison.OrdinalIgnoreCase)) { var roleName = roleNode.Attributes["name"].Value; roleName = roleName.Trim(); roleList.Add(roleName); } } rightsDict.Add(rightName, roleList); } } return rightsDict; }
public void Run() { var f = new FileIOPermission(PermissionState.None); f.AllLocalFiles = FileIOPermissionAccess.Read; try { f.Demand(); } catch (SecurityException s) { Console.WriteLine(s.Message); } }
public static bool IsDirectoryWritable(string directory) { if (string.IsNullOrWhiteSpace(directory)) { return false; } FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, HostingEnvironment.MapPath(directory)); PermissionSet permissionSet = new PermissionSet(PermissionState.None); permissionSet.AddPermission(permission); return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); }
private void checkBox1_CheckedChanged(object sender, EventArgs e) { RegistryKey MyKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\run", true); string filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MUSPrayer\MUSPrayer.exe"; string Dirname = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MUSPrayer"; string PDirname = Path.GetDirectoryName(Application.ExecutablePath); if (checkBox1.Checked == false) { try { MyKey.DeleteValue("MUSPrayer"); } catch (System.Exception) { } try { File.Delete(filename); } catch (System.Exception) { } return; } System.Security.Permissions.FileIOPermission permission = new System.Security.Permissions.FileIOPermission( System.Security.Permissions.FileIOPermissionAccess.Write, filename); try { Directory.CreateDirectory(Dirname); } catch (System.Exception) { } try { File.Delete(filename); } catch (System.Exception) { } try { File.Copy(Application.ExecutablePath, filename); } catch (System.Exception) { } try { File.Copy(PDirname + @"\Prayers.dll", Dirname + @"\Prayers.dll"); } catch (System.Exception) { } try { File.Copy(PDirname + @"\Azan.mp3", Dirname + @"\Azan.mp3"); } catch (System.Exception) { } try { File.Copy(PDirname + @"\AzanFajr.wav", Dirname + @"\AzanFajr.wav"); } catch (System.Exception) { } MyKey.SetValue("MUSPrayer", filename + " /hide"); }
static public PolicyLevel LoadPolicyLevelFromFile(String path, PolicyLevelType type) { if (path == null) { throw new ArgumentNullException("path"); } ConfigId id = SharedStatics.GetNextConfigId(); ConfigRetval retval = Config.InitData(id, path); if ((retval & ConfigRetval.ConfigFile) == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_PolicyFileDoesNotExist")); } String name = Enum.GetName(typeof(PolicyLevelType), type); if (name == null) { return(null); } String fullPath = Path.GetFullPath(path); FileIOPermission perm = new FileIOPermission(PermissionState.None); perm.AddPathList(FileIOPermissionAccess.Read, fullPath); perm.AddPathList(FileIOPermissionAccess.Write, fullPath); perm.Demand(); PolicyLevel level = new PolicyLevel(name, id, type == PolicyLevelType.Machine); level.ThrowOnLoadError = true; level.CheckLoaded(false); return(level); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } FileIOPermission permission = target as FileIOPermission; if (permission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } if (this.IsUnrestricted()) { return(target.Copy()); } if (permission.IsUnrestricted()) { return(this.Copy()); } FileIOAccess access = (this.m_read == null) ? null : this.m_read.Intersect(permission.m_read); FileIOAccess access2 = (this.m_write == null) ? null : this.m_write.Intersect(permission.m_write); FileIOAccess access3 = (this.m_append == null) ? null : this.m_append.Intersect(permission.m_append); FileIOAccess access4 = (this.m_pathDiscovery == null) ? null : this.m_pathDiscovery.Intersect(permission.m_pathDiscovery); FileIOAccess access5 = (this.m_viewAcl == null) ? null : this.m_viewAcl.Intersect(permission.m_viewAcl); FileIOAccess access6 = (this.m_changeAcl == null) ? null : this.m_changeAcl.Intersect(permission.m_changeAcl); if (((((access == null) || access.IsEmpty()) && ((access2 == null) || access2.IsEmpty())) && (((access3 == null) || access3.IsEmpty()) && ((access4 == null) || access4.IsEmpty()))) && (((access5 == null) || access5.IsEmpty()) && ((access6 == null) || access6.IsEmpty()))) { return(null); } return(new FileIOPermission(PermissionState.None) { m_unrestricted = false, m_read = access, m_write = access2, m_append = access3, m_pathDiscovery = access4, m_viewAcl = access5, m_changeAcl = access6 }); }
public override IPermission Copy() { FileIOPermission permission = new FileIOPermission(PermissionState.None); if (this.m_unrestricted) { permission.m_unrestricted = true; return(permission); } permission.m_unrestricted = false; if (this.m_read != null) { permission.m_read = this.m_read.Copy(); } if (this.m_write != null) { permission.m_write = this.m_write.Copy(); } if (this.m_append != null) { permission.m_append = this.m_append.Copy(); } if (this.m_pathDiscovery != null) { permission.m_pathDiscovery = this.m_pathDiscovery.Copy(); } if (this.m_viewAcl != null) { permission.m_viewAcl = this.m_viewAcl.Copy(); } if (this.m_changeAcl != null) { permission.m_changeAcl = this.m_changeAcl.Copy(); } return(permission); }
public override IPermission CreatePermission() { if (base.m_unrestricted) { return(new FileIOPermission(PermissionState.Unrestricted)); } FileIOPermission permission = new FileIOPermission(PermissionState.None); if (this.m_read != null) { permission.SetPathList(FileIOPermissionAccess.Read, this.m_read); } if (this.m_write != null) { permission.SetPathList(FileIOPermissionAccess.Write, this.m_write); } if (this.m_append != null) { permission.SetPathList(FileIOPermissionAccess.Append, this.m_append); } if (this.m_pathDiscovery != null) { permission.SetPathList(FileIOPermissionAccess.PathDiscovery, this.m_pathDiscovery); } if (this.m_viewAccess != null) { permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.View, new string[] { this.m_viewAccess }, false); } if (this.m_changeAccess != null) { permission.SetPathList(FileIOPermissionAccess.NoAccess, AccessControlActions.Change, new string[] { this.m_changeAccess }, false); } permission.AllFiles = this.m_allFiles; permission.AllLocalFiles = this.m_allLocalFiles; return(permission); }
/// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns> /// <param name="target">要与当前权限相交的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override IPermission Intersect(IPermission target) { if (target == null) { return((IPermission)null); } FileIOPermission fileIoPermission = target as FileIOPermission; if (fileIoPermission == null) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } if (this.IsUnrestricted()) { return(target.Copy()); } if (fileIoPermission.IsUnrestricted()) { return(this.Copy()); } FileIOAccess fileIoAccess1 = this.m_read == null ? (FileIOAccess)null : this.m_read.Intersect(fileIoPermission.m_read); FileIOAccess fileIoAccess2 = this.m_write == null ? (FileIOAccess)null : this.m_write.Intersect(fileIoPermission.m_write); FileIOAccess fileIoAccess3 = this.m_append == null ? (FileIOAccess)null : this.m_append.Intersect(fileIoPermission.m_append); FileIOAccess fileIoAccess4 = this.m_pathDiscovery == null ? (FileIOAccess)null : this.m_pathDiscovery.Intersect(fileIoPermission.m_pathDiscovery); FileIOAccess fileIoAccess5 = this.m_viewAcl == null ? (FileIOAccess)null : this.m_viewAcl.Intersect(fileIoPermission.m_viewAcl); FileIOAccess fileIoAccess6 = this.m_changeAcl == null ? (FileIOAccess)null : this.m_changeAcl.Intersect(fileIoPermission.m_changeAcl); if ((fileIoAccess1 == null || fileIoAccess1.IsEmpty()) && (fileIoAccess2 == null || fileIoAccess2.IsEmpty()) && ((fileIoAccess3 == null || fileIoAccess3.IsEmpty()) && (fileIoAccess4 == null || fileIoAccess4.IsEmpty())) && ((fileIoAccess5 == null || fileIoAccess5.IsEmpty()) && (fileIoAccess6 == null || fileIoAccess6.IsEmpty()))) { return((IPermission)null); } return((IPermission) new FileIOPermission(PermissionState.None) { m_unrestricted = false, m_read = fileIoAccess1, m_write = fileIoAccess2, m_append = fileIoAccess3, m_pathDiscovery = fileIoAccess4, m_viewAcl = fileIoAccess5, m_changeAcl = fileIoAccess6 }); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override bool IsSubsetOf(IPermission target) { FileIOPermission fileIOPermission = FileIOPermission.Cast(target); if (fileIOPermission == null) { return(false); } if (fileIOPermission.IsEmpty()) { return(this.IsEmpty()); } if (this.IsUnrestricted()) { return(fileIOPermission.IsUnrestricted()); } return(fileIOPermission.IsUnrestricted() || ((this.m_AllFilesAccess & fileIOPermission.AllFiles) == this.m_AllFilesAccess && (this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles) == this.m_AllLocalFilesAccess && FileIOPermission.KeyIsSubsetOf(this.appendList, fileIOPermission.appendList) && FileIOPermission.KeyIsSubsetOf(this.readList, fileIOPermission.readList) && FileIOPermission.KeyIsSubsetOf(this.writeList, fileIOPermission.writeList) && FileIOPermission.KeyIsSubsetOf(this.pathList, fileIOPermission.pathList))); }
private void AddFooterToOneHtmlFile ( string _sPathToInputFile, string _sPathToOutputFile, string _sFileNameInAndOut, string _sFooter ) { SysIo.FileStream fstreamRead, fstreamWrite; SysIo.StreamReader streamRead = null; SysIo.StreamWriter streamWrite = null; SysSecuPerm.FileIOPermission fileIoPerm; string sWholeFileContents, sWholeFilePlusFooter; // try { fileIoPerm = new SysSecuPerm.FileIOPermission(SysSecuPerm.PermissionState.Unrestricted); fileIoPerm.Assert(); fstreamRead = new SysIo.FileStream ( _sPathToInputFile + _sFileNameInAndOut, SysIo.FileMode.Open, SysIo.FileAccess.Read, SysIo.FileShare.Read ); streamRead = new SysIo.StreamReader(fstreamRead); sWholeFileContents = streamRead.ReadToEnd(); streamRead.Close(); sWholeFilePlusFooter = sWholeFileContents.Replace (@"</body>", _sFooter + @"</body>"); fstreamWrite = new SysIo.FileStream ( _sPathToOutputFile + _sFileNameInAndOut, SysIo.FileMode.Create, SysIo.FileAccess.Write, SysIo.FileShare.None ); streamWrite = new SysIo.StreamWriter(fstreamWrite); streamWrite.Write(sWholeFilePlusFooter); streamWrite.Flush(); streamWrite.Close(); } finally { if (null != streamRead) { streamRead.Dispose(); } if (null != streamWrite) { streamWrite.Dispose(); } SysSecuPerm.FileIOPermission.RevertAssert(); fileIoPerm = null; } return; }
public FileIOPermission(FileIOPermissionAccess access, string[] pathList) { FileIOPermission.VerifyAccess(access); this.AddPathList(access, pathList, false, true, false); }
public override bool Equals(Object obj) { FileIOPermission perm = obj as FileIOPermission; if (perm == null) { return(false); } if (m_unrestricted && perm.m_unrestricted) { return(true); } if (m_unrestricted != perm.m_unrestricted) { return(false); } if (m_read == null) { if (perm.m_read != null && !perm.m_read.IsEmpty()) { return(false); } } else if (!m_read.Equals(perm.m_read)) { return(false); } if (m_write == null) { if (perm.m_write != null && !perm.m_write.IsEmpty()) { return(false); } } else if (!m_write.Equals(perm.m_write)) { return(false); } if (m_append == null) { if (perm.m_append != null && !perm.m_append.IsEmpty()) { return(false); } } else if (!m_append.Equals(perm.m_append)) { return(false); } if (m_pathDiscovery == null) { if (perm.m_pathDiscovery != null && !perm.m_pathDiscovery.IsEmpty()) { return(false); } } else if (!m_pathDiscovery.Equals(perm.m_pathDiscovery)) { return(false); } if (m_viewAcl == null) { if (perm.m_viewAcl != null && !perm.m_viewAcl.IsEmpty()) { return(false); } } else if (!m_viewAcl.Equals(perm.m_viewAcl)) { return(false); } if (m_changeAcl == null) { if (perm.m_changeAcl != null && !perm.m_changeAcl.IsEmpty()) { return(false); } } else if (!m_changeAcl.Equals(perm.m_changeAcl)) { return(false); } return(true); }
/// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(FileIOPermission.GetTokenIndex()); }
internal FileIOPermission(FileIOPermissionAccess access, AccessControlActions control, string[] pathList, bool checkForDuplicates, bool needFullPath) { FileIOPermission.VerifyAccess(access); this.AddPathList(access, control, pathList, checkForDuplicates, needFullPath, true); }
public override bool Equals(object obj) { FileIOPermission fileIoPermission = obj as FileIOPermission; if (fileIoPermission == null) { return(false); } if (this.m_unrestricted && fileIoPermission.m_unrestricted) { return(true); } if (this.m_unrestricted != fileIoPermission.m_unrestricted) { return(false); } if (this.m_read == null) { if (fileIoPermission.m_read != null && !fileIoPermission.m_read.IsEmpty()) { return(false); } } else if (!this.m_read.Equals((object)fileIoPermission.m_read)) { return(false); } if (this.m_write == null) { if (fileIoPermission.m_write != null && !fileIoPermission.m_write.IsEmpty()) { return(false); } } else if (!this.m_write.Equals((object)fileIoPermission.m_write)) { return(false); } if (this.m_append == null) { if (fileIoPermission.m_append != null && !fileIoPermission.m_append.IsEmpty()) { return(false); } } else if (!this.m_append.Equals((object)fileIoPermission.m_append)) { return(false); } if (this.m_pathDiscovery == null) { if (fileIoPermission.m_pathDiscovery != null && !fileIoPermission.m_pathDiscovery.IsEmpty()) { return(false); } } else if (!this.m_pathDiscovery.Equals((object)fileIoPermission.m_pathDiscovery)) { return(false); } if (this.m_viewAcl == null) { if (fileIoPermission.m_viewAcl != null && !fileIoPermission.m_viewAcl.IsEmpty()) { return(false); } } else if (!this.m_viewAcl.Equals((object)fileIoPermission.m_viewAcl)) { return(false); } if (this.m_changeAcl == null) { if (fileIoPermission.m_changeAcl != null && !fileIoPermission.m_changeAcl.IsEmpty()) { return(false); } } else if (!this.m_changeAcl.Equals((object)fileIoPermission.m_changeAcl)) { return(false); } return(true); }
internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, string[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList) { if (pathListOrig == null) { throw new ArgumentNullException("pathList"); } if (pathListOrig.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); } FileIOPermission.VerifyAccess(access); if (this.m_unrestricted) { return; } string[] str = pathListOrig; if (copyPathList) { str = new string[pathListOrig.Length]; Array.Copy((Array)pathListOrig, (Array)str, pathListOrig.Length); } FileIOPermission.CheckIllegalCharacters(str); ArrayList listFromExpressions = StringExpressionSet.CreateListFromExpressions(str, needFullPath); if ((access & FileIOPermissionAccess.Read) != FileIOPermissionAccess.NoAccess) { if (this.m_read == null) { this.m_read = new FileIOAccess(); } this.m_read.AddExpressions(listFromExpressions, checkForDuplicates); } if ((access & FileIOPermissionAccess.Write) != FileIOPermissionAccess.NoAccess) { if (this.m_write == null) { this.m_write = new FileIOAccess(); } this.m_write.AddExpressions(listFromExpressions, checkForDuplicates); } if ((access & FileIOPermissionAccess.Append) != FileIOPermissionAccess.NoAccess) { if (this.m_append == null) { this.m_append = new FileIOAccess(); } this.m_append.AddExpressions(listFromExpressions, checkForDuplicates); } if ((access & FileIOPermissionAccess.PathDiscovery) != FileIOPermissionAccess.NoAccess) { if (this.m_pathDiscovery == null) { this.m_pathDiscovery = new FileIOAccess(true); } this.m_pathDiscovery.AddExpressions(listFromExpressions, checkForDuplicates); } if ((control & AccessControlActions.View) != AccessControlActions.None) { if (this.m_viewAcl == null) { this.m_viewAcl = new FileIOAccess(); } this.m_viewAcl.AddExpressions(listFromExpressions, checkForDuplicates); } if ((control & AccessControlActions.Change) == AccessControlActions.None) { return; } if (this.m_changeAcl == null) { this.m_changeAcl = new FileIOAccess(); } this.m_changeAcl.AddExpressions(listFromExpressions, checkForDuplicates); }