using System; using System.Collections; using System.IO; using System.Runtime.InteropServices; using System.Security.AccessControl; namespace System.Security.Permissions { /// Controls the ability to access files and folders. This class cannot be inherited. // Token: 0x02000544 RID: 1348 [ComVisible(true)] [Serializable] public sealed class FileIOPermission : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission { /// Initializes a new instance of the class with fully restricted or unrestricted permission as specified. /// One of the enumeration values. /// The parameter is not a valid value of . // Token: 0x06003144 RID: 12612 RVA: 0x000A9864 File Offset: 0x000A7A64 public FileIOPermission(PermissionState state) { if (CodeAccessPermission.CheckPermissionState(state, true) == PermissionState.Unrestricted) { this.m_Unrestricted = true; this.m_AllFilesAccess = FileIOPermissionAccess.AllAccess; this.m_AllLocalFilesAccess = FileIOPermissionAccess.AllAccess; } this.CreateLists(); } /// Initializes a new instance of the class with the specified access to the designated file or directory. /// A bitwise combination of the enumeration values. /// The absolute path of the file or directory. /// The parameter is not a valid value of .-or- The parameter is not a valid string.-or- The parameter does not specify the absolute path to the file or directory. // Token: 0x06003145 RID: 12613 RVA: 0x000A98A4 File Offset: 0x000A7AA4 public FileIOPermission(FileIOPermissionAccess access, string path) { if (path == null) { throw new ArgumentNullException("path"); } this.CreateLists(); this.AddPathList(access, path); } /// Initializes a new instance of the class with the specified access to the designated files and directories. /// A bitwise combination of the enumeration values. /// An array containing the absolute paths of the files and directories. /// The parameter is not a valid value of .-or- An entry in the array is not a valid string. // Token: 0x06003146 RID: 12614 RVA: 0x000A98D8 File Offset: 0x000A7AD8 public FileIOPermission(FileIOPermissionAccess access, string[] pathList) { if (pathList == null) { throw new ArgumentNullException("pathList"); } this.CreateLists(); this.AddPathList(access, pathList); } /// Initializes a new instance of the class with the specified access to the designated file or directory and the specified access rights to file control information. /// A bitwise combination of the enumeration values. /// A bitwise combination of the enumeration values. /// The absolute path of the file or directory. /// The parameter is not a valid value of .-or- The parameter is not a valid string.-or- The parameter does not specify the absolute path to the file or directory. // Token: 0x06003147 RID: 12615 RVA: 0x000A990C File Offset: 0x000A7B0C [MonoTODO("(2.0) Access Control isn't implemented")] public FileIOPermission(FileIOPermissionAccess access, AccessControlActions control, string path) { throw new NotImplementedException(); } /// Initializes a new instance of the class with the specified access to the designated files and directories and the specified access rights to file control information. /// A bitwise combination of the enumeration values. /// A bitwise combination of the enumeration values. /// An array containing the absolute paths of the files and directories. /// The parameter is not a valid value of .-or- An entry in the array is not a valid string. // Token: 0x06003148 RID: 12616 RVA: 0x000A991C File Offset: 0x000A7B1C [MonoTODO("(2.0) Access Control isn't implemented")] public FileIOPermission(FileIOPermissionAccess access, AccessControlActions control, string[] pathList) { throw new NotImplementedException(); } // Token: 0x0600314A RID: 12618 RVA: 0x000A9944 File Offset: 0x000A7B44 int IBuiltInPermission.GetTokenIndex() { return 2; } // Token: 0x0600314B RID: 12619 RVA: 0x000A9948 File Offset: 0x000A7B48 internal void CreateLists() { this.readList = new ArrayList(); this.writeList = new ArrayList(); this.appendList = new ArrayList(); this.pathList = new ArrayList(); } /// Gets or sets the permitted access to all files. /// The set of file I/O flags for all files. // Token: 0x170009A3 RID: 2467 // (get) Token: 0x0600314C RID: 12620 RVA: 0x000A9984 File Offset: 0x000A7B84 // (set) Token: 0x0600314D RID: 12621 RVA: 0x000A998C File Offset: 0x000A7B8C public FileIOPermissionAccess AllFiles { get { return this.m_AllFilesAccess; } set { if (!this.m_Unrestricted) { this.m_AllFilesAccess = value; } } } /// Gets or sets the permitted access to all local files. /// The set of file I/O flags for all local files. // Token: 0x170009A4 RID: 2468 // (get) Token: 0x0600314E RID: 12622 RVA: 0x000A99A0 File Offset: 0x000A7BA0 // (set) Token: 0x0600314F RID: 12623 RVA: 0x000A99A8 File Offset: 0x000A7BA8 public FileIOPermissionAccess AllLocalFiles { get { return this.m_AllLocalFilesAccess; } set { if (!this.m_Unrestricted) { this.m_AllLocalFilesAccess = value; } } } /// Adds access for the specified file or directory to the existing state of the permission. /// A bitwise combination of the values. /// The absolute path of a file or directory. /// The parameter is not a valid value of .-or- The parameter is not a valid string.-or- The parameter did not specify the absolute path to the file or directory. /// The parameter is null. // Token: 0x06003150 RID: 12624 RVA: 0x000A99BC File Offset: 0x000A7BBC public void AddPathList(FileIOPermissionAccess access, string path) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(path); this.AddPathInternal(access, path); } /// Adds access for the specified files and directories to the existing state of the permission. /// A bitwise combination of the values. /// An array containing the absolute paths of the files and directories. /// The parameter is not a valid value of .-or- An entry in the array is not valid. /// The parameter is null. // Token: 0x06003151 RID: 12625 RVA: 0x000A99E0 File Offset: 0x000A7BE0 public void AddPathList(FileIOPermissionAccess access, string[] pathList) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(pathList); foreach (string text in pathList) { this.AddPathInternal(access, text); } } // Token: 0x06003152 RID: 12626 RVA: 0x000A9A28 File Offset: 0x000A7C28 internal void AddPathInternal(FileIOPermissionAccess access, string path) { path = Path.InsecureGetFullPath(path); if ((access & FileIOPermissionAccess.Read) == FileIOPermissionAccess.Read) { this.readList.Add(path); } if ((access & FileIOPermissionAccess.Write) == FileIOPermissionAccess.Write) { this.writeList.Add(path); } if ((access & FileIOPermissionAccess.Append) == FileIOPermissionAccess.Append) { this.appendList.Add(path); } if ((access & FileIOPermissionAccess.PathDiscovery) == FileIOPermissionAccess.PathDiscovery) { this.pathList.Add(path); } } /// Creates and returns an identical copy of the current permission. /// A copy of the current permission. // Token: 0x06003153 RID: 12627 RVA: 0x000A9A98 File Offset: 0x000A7C98 public override IPermission Copy() { if (this.m_Unrestricted) { return new FileIOPermission(PermissionState.Unrestricted); } return new FileIOPermission(PermissionState.None) { readList = (ArrayList)this.readList.Clone(), writeList = (ArrayList)this.writeList.Clone(), appendList = (ArrayList)this.appendList.Clone(), pathList = (ArrayList)this.pathList.Clone(), m_AllFilesAccess = this.m_AllFilesAccess, m_AllLocalFilesAccess = this.m_AllLocalFilesAccess }; } /// Reconstructs a permission with a specified state from an XML encoding. /// The XML encoding used to reconstruct the permission. /// The parameter is null. /// The parameter is not a valid permission element.-or- The parameter's version number is not compatible. // Token: 0x06003154 RID: 12628 RVA: 0x000A9B30 File Offset: 0x000A7D30 public override void FromXml(SecurityElement esd) { CodeAccessPermission.CheckSecurityElement(esd, "esd", 1, 1); if (CodeAccessPermission.IsUnrestricted(esd)) { this.m_Unrestricted = true; } else { this.m_Unrestricted = false; string text = esd.Attribute("Read"); if (text != null) { string[] array = text.Split(new char[] { ';' }); this.AddPathList(FileIOPermissionAccess.Read, array); } text = esd.Attribute("Write"); if (text != null) { string[] array = text.Split(new char[] { ';' }); this.AddPathList(FileIOPermissionAccess.Write, array); } text = esd.Attribute("Append"); if (text != null) { string[] array = text.Split(new char[] { ';' }); this.AddPathList(FileIOPermissionAccess.Append, array); } text = esd.Attribute("PathDiscovery"); if (text != null) { string[] array = text.Split(new char[] { ';' }); this.AddPathList(FileIOPermissionAccess.PathDiscovery, array); } } } /// Gets all files and directories with the specified . /// An array containing the paths of the files and directories to which access specified by the parameter is granted. /// One of the values that represents a single type of file access. /// /// is not a valid value of .-or- is , which represents more than one type of file access, or , which does not represent any type of file access. // Token: 0x06003155 RID: 12629 RVA: 0x000A9C1C File Offset: 0x000A7E1C public string[] GetPathList(FileIOPermissionAccess access) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } ArrayList arrayList = new ArrayList(); switch (access) { case FileIOPermissionAccess.NoAccess: goto IL_9D; case FileIOPermissionAccess.Read: arrayList.AddRange(this.readList); goto IL_9D; case FileIOPermissionAccess.Write: arrayList.AddRange(this.writeList); goto IL_9D; case FileIOPermissionAccess.Append: arrayList.AddRange(this.appendList); goto IL_9D; case FileIOPermissionAccess.PathDiscovery: arrayList.AddRange(this.pathList); goto IL_9D; } FileIOPermission.ThrowInvalidFlag(access, false); IL_9D: return (arrayList.Count <= 0) ? null : ((string[])arrayList.ToArray(typeof(string))); } /// Creates and returns a permission that is the intersection of the current permission and the specified permission. /// A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty. /// A permission to intersect with the current permission. It must be the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003156 RID: 12630 RVA: 0x000A9CF0 File Offset: 0x000A7EF0 public override IPermission Intersect(IPermission target) { FileIOPermission fileIOPermission = FileIOPermission.Cast(target); if (fileIOPermission == null) { return null; } if (this.IsUnrestricted()) { return fileIOPermission.Copy(); } if (fileIOPermission.IsUnrestricted()) { return this.Copy(); } FileIOPermission fileIOPermission2 = new FileIOPermission(PermissionState.None); fileIOPermission2.AllFiles = this.m_AllFilesAccess & fileIOPermission.AllFiles; fileIOPermission2.AllLocalFiles = this.m_AllLocalFilesAccess & fileIOPermission.AllLocalFiles; FileIOPermission.IntersectKeys(this.readList, fileIOPermission.readList, fileIOPermission2.readList); FileIOPermission.IntersectKeys(this.writeList, fileIOPermission.writeList, fileIOPermission2.writeList); FileIOPermission.IntersectKeys(this.appendList, fileIOPermission.appendList, fileIOPermission2.appendList); FileIOPermission.IntersectKeys(this.pathList, fileIOPermission.pathList, fileIOPermission2.pathList); return (!fileIOPermission2.IsEmpty()) ? fileIOPermission2 : null; } /// Determines whether the current permission is a subset of the specified permission. /// true if the current permission is a subset of the specified permission; otherwise, false. /// A permission that is to be tested for the subset relationship. This permission must be the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x06003157 RID: 12631 RVA: 0x000A9DCC File Offset: 0x000A7FCC 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)); } /// Returns a value indicating whether the current permission is unrestricted. /// true if the current permission is unrestricted; otherwise, false. // Token: 0x06003158 RID: 12632 RVA: 0x000A9EB0 File Offset: 0x000A80B0 public bool IsUnrestricted() { return this.m_Unrestricted; } /// Sets the specified access to the specified file or directory, replacing the existing state of the permission. /// A bitwise combination of the values. /// The absolute path of the file or directory. /// The parameter is not a valid value of .-or- The parameter is not a valid string.-or- The parameter did not specify the absolute path to the file or directory. // Token: 0x06003159 RID: 12633 RVA: 0x000A9EB8 File Offset: 0x000A80B8 public void SetPathList(FileIOPermissionAccess access, string path) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(path); this.Clear(access); this.AddPathInternal(access, path); } /// Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths. /// A bitwise combination of the values. /// An array containing the absolute paths of the files and directories. /// The parameter is not a valid value of .-or- An entry in the parameter is not a valid string. // Token: 0x0600315A RID: 12634 RVA: 0x000A9EEC File Offset: 0x000A80EC public void SetPathList(FileIOPermissionAccess access, string[] pathList) { if ((FileIOPermissionAccess.AllAccess & access) != access) { FileIOPermission.ThrowInvalidFlag(access, true); } FileIOPermission.ThrowIfInvalidPath(pathList); this.Clear(access); foreach (string text in pathList) { this.AddPathInternal(access, text); } } /// Creates an XML encoding of the permission and its current state. /// An XML encoding of the permission, including any state information. // Token: 0x0600315B RID: 12635 RVA: 0x000A9F3C File Offset: 0x000A813C public override SecurityElement ToXml() { SecurityElement securityElement = base.Element(1); if (this.m_Unrestricted) { securityElement.AddAttribute("Unrestricted", "true"); } else { string[] array = this.GetPathList(FileIOPermissionAccess.Append); if (array != null && array.Length > 0) { securityElement.AddAttribute("Append", string.Join(";", array)); } array = this.GetPathList(FileIOPermissionAccess.Read); if (array != null && array.Length > 0) { securityElement.AddAttribute("Read", string.Join(";", array)); } array = this.GetPathList(FileIOPermissionAccess.Write); if (array != null && array.Length > 0) { securityElement.AddAttribute("Write", string.Join(";", array)); } array = this.GetPathList(FileIOPermissionAccess.PathDiscovery); if (array != null && array.Length > 0) { securityElement.AddAttribute("PathDiscovery", string.Join(";", array)); } } return securityElement; } /// Creates a permission that is the union of the current permission and the specified permission. /// A new permission that represents the union of the current permission and the specified permission. /// A permission to combine with the current permission. It must be the same type as the current permission. /// The parameter is not null and is not of the same type as the current permission. // Token: 0x0600315C RID: 12636 RVA: 0x000AA028 File Offset: 0x000A8228 public override IPermission Union(IPermission other) { FileIOPermission fileIOPermission = FileIOPermission.Cast(other); if (fileIOPermission == null) { return this.Copy(); } if (this.IsUnrestricted() || fileIOPermission.IsUnrestricted()) { return new FileIOPermission(PermissionState.Unrestricted); } if (this.IsEmpty() && fileIOPermission.IsEmpty()) { return null; } FileIOPermission fileIOPermission2 = (FileIOPermission)this.Copy(); fileIOPermission2.AllFiles |= fileIOPermission.AllFiles; fileIOPermission2.AllLocalFiles |= fileIOPermission.AllLocalFiles; string[] array = fileIOPermission.GetPathList(FileIOPermissionAccess.Read); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.readList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.Write); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.writeList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.Append); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.appendList, array); } array = fileIOPermission.GetPathList(FileIOPermissionAccess.PathDiscovery); if (array != null) { FileIOPermission.UnionKeys(fileIOPermission2.pathList, array); } return fileIOPermission2; } /// Determines whether the specified object is equal to the current . /// true if the specified is equal to the current object; otherwise, false. /// The object to compare with the current . // Token: 0x0600315D RID: 12637 RVA: 0x000AA11C File Offset: 0x000A831C [MonoTODO("(2.0)")] [ComVisible(false)] public override bool Equals(object obj) { return false; } /// Gets a hash code for the object that is suitable for use in hashing algorithms and data structures such as a hash table. /// A hash code for the current object. // Token: 0x0600315E RID: 12638 RVA: 0x000AA120 File Offset: 0x000A8320 [MonoTODO("(2.0)")] [ComVisible(false)] public override int GetHashCode() { return base.GetHashCode(); } // Token: 0x0600315F RID: 12639 RVA: 0x000AA128 File Offset: 0x000A8328 private bool IsEmpty() { return !this.m_Unrestricted && this.appendList.Count == 0 && this.readList.Count == 0 && this.writeList.Count == 0 && this.pathList.Count == 0; } // Token: 0x06003160 RID: 12640 RVA: 0x000AA184 File Offset: 0x000A8384 private static FileIOPermission Cast(IPermission target) { if (target == null) { return null; } FileIOPermission fileIOPermission = target as FileIOPermission; if (fileIOPermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(FileIOPermission)); } return fileIOPermission; } // Token: 0x06003161 RID: 12641 RVA: 0x000AA1B8 File Offset: 0x000A83B8 internal static void ThrowInvalidFlag(FileIOPermissionAccess access, bool context) { string text; if (context) { text = Locale.GetText("Unknown flag '{0}'."); } else { text = Locale.GetText("Invalid flag '{0}' in this context."); } throw new ArgumentException(string.Format(text, access), "access"); } // Token: 0x06003162 RID: 12642 RVA: 0x000AA200 File Offset: 0x000A8400 internal static void ThrowIfInvalidPath(string path) { string directoryName = Path.GetDirectoryName(path); if (directoryName != null && directoryName.LastIndexOfAny(FileIOPermission.BadPathNameCharacters) >= 0) { string text = string.Format(Locale.GetText("Invalid path characters in path: '{0}'"), path); throw new ArgumentException(text, "path"); } string fileName = Path.GetFileName(path); if (fileName != null && fileName.LastIndexOfAny(FileIOPermission.BadFileNameCharacters) >= 0) { string text2 = string.Format(Locale.GetText("Invalid filename characters in path: '{0}'"), path); throw new ArgumentException(text2, "path"); } if (!Path.IsPathRooted(path)) { string text3 = Locale.GetText("Absolute path information is required."); throw new ArgumentException(text3, "path"); } } // Token: 0x06003163 RID: 12643 RVA: 0x000AA2A8 File Offset: 0x000A84A8 internal static void ThrowIfInvalidPath(string[] paths) { foreach (string text in paths) { FileIOPermission.ThrowIfInvalidPath(text); } } // Token: 0x06003164 RID: 12644 RVA: 0x000AA2D8 File Offset: 0x000A84D8 internal void Clear(FileIOPermissionAccess access) { if ((access & FileIOPermissionAccess.Read) == FileIOPermissionAccess.Read) { this.readList.Clear(); } if ((access & FileIOPermissionAccess.Write) == FileIOPermissionAccess.Write) { this.writeList.Clear(); } if ((access & FileIOPermissionAccess.Append) == FileIOPermissionAccess.Append) { this.appendList.Clear(); } if ((access & FileIOPermissionAccess.PathDiscovery) == FileIOPermissionAccess.PathDiscovery) { this.pathList.Clear(); } } // Token: 0x06003165 RID: 12645 RVA: 0x000AA338 File Offset: 0x000A8538 internal static bool KeyIsSubsetOf(IList local, IList target) { bool flag = false; foreach (object obj in local) { string text = (string)obj; foreach (object obj2 in target) { string text2 = (string)obj2; if (Path.IsPathSubsetOf(text2, text)) { flag = true; break; } } if (!flag) { return false; } } return true; } // Token: 0x06003166 RID: 12646 RVA: 0x000AA420 File Offset: 0x000A8620 internal static void UnionKeys(IList list, string[] paths) { foreach (string text in paths) { int count = list.Count; if (count == 0) { list.Add(text); } else { int j; for (j = 0; j < count; j++) { string text2 = (string)list[j]; if (Path.IsPathSubsetOf(text, text2)) { list[j] = text; break; } if (Path.IsPathSubsetOf(text2, text)) { break; } } if (j == count) { list.Add(text); } } } } // Token: 0x06003167 RID: 12647 RVA: 0x000AA4C4 File Offset: 0x000A86C4 internal static void IntersectKeys(IList local, IList target, IList result) { foreach (object obj in local) { string text = (string)obj; foreach (object obj2 in target) { string text2 = (string)obj2; if (text2.Length > text.Length) { if (Path.IsPathSubsetOf(text, text2)) { result.Add(text2); } } else if (Path.IsPathSubsetOf(text2, text)) { result.Add(text); } } } } // Token: 0x04001420 RID: 5152 private const int version = 1; // Token: 0x04001421 RID: 5153 private static char[] BadPathNameCharacters = Path.GetInvalidPathChars(); // Token: 0x04001422 RID: 5154 private static char[] BadFileNameCharacters = Path.GetInvalidFileNameChars(); // Token: 0x04001423 RID: 5155 private bool m_Unrestricted; // Token: 0x04001424 RID: 5156 private FileIOPermissionAccess m_AllFilesAccess; // Token: 0x04001425 RID: 5157 private FileIOPermissionAccess m_AllLocalFilesAccess; // Token: 0x04001426 RID: 5158 private ArrayList readList; // Token: 0x04001427 RID: 5159 private ArrayList writeList; // Token: 0x04001428 RID: 5160 private ArrayList appendList; // Token: 0x04001429 RID: 5161 private ArrayList pathList; } }