693 lines
30 KiB
C#
693 lines
30 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.AccessControl;
|
|
|
|
namespace System.Security.Permissions
|
|
{
|
|
/// <summary>Controls the ability to access files and folders. This class cannot be inherited.</summary>
|
|
// Token: 0x02000544 RID: 1348
|
|
[ComVisible(true)]
|
|
[Serializable]
|
|
public sealed class FileIOPermission : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileIOPermission" /> class with fully restricted or unrestricted permission as specified.</summary>
|
|
/// <param name="state">One of the <see cref="T:System.Security.Permissions.PermissionState" /> enumeration values. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="state" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.PermissionState" />. </exception>
|
|
// 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();
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileIOPermission" /> class with the specified access to the designated file or directory.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> enumeration values. </param>
|
|
/// <param name="path">The absolute path of the file or directory. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- The <paramref name="path" /> parameter is not a valid string.-or- The <paramref name="path" /> parameter does not specify the absolute path to the file or directory. </exception>
|
|
// 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);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileIOPermission" /> class with the specified access to the designated files and directories.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> enumeration values. </param>
|
|
/// <param name="pathList">An array containing the absolute paths of the files and directories. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- An entry in the <paramref name="pathList" /> array is not a valid string. </exception>
|
|
// 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);
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileIOPermission" /> class with the specified access to the designated file or directory and the specified access rights to file control information.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> enumeration values.</param>
|
|
/// <param name="control">A bitwise combination of the <see cref="T:System.Security.AccessControl.AccessControlActions" /> enumeration values.</param>
|
|
/// <param name="path">The absolute path of the file or directory.</param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- The <paramref name="path" /> parameter is not a valid string.-or- The <paramref name="path" /> parameter does not specify the absolute path to the file or directory. </exception>
|
|
// 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();
|
|
}
|
|
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Permissions.FileIOPermission" /> class with the specified access to the designated files and directories and the specified access rights to file control information.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> enumeration values. </param>
|
|
/// <param name="control">A bitwise combination of the <see cref="T:System.Security.AccessControl.AccessControlActions" /> enumeration values.</param>
|
|
/// <param name="pathList">An array containing the absolute paths of the files and directories.</param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- An entry in the <paramref name="pathList" /> array is not a valid string. </exception>
|
|
// 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();
|
|
}
|
|
|
|
/// <summary>Gets or sets the permitted access to all files.</summary>
|
|
/// <returns>The set of file I/O flags for all files.</returns>
|
|
// 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets or sets the permitted access to all local files.</summary>
|
|
/// <returns>The set of file I/O flags for all local files.</returns>
|
|
// 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Adds access for the specified file or directory to the existing state of the permission.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param>
|
|
/// <param name="path">The absolute path of a file or directory. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- The <paramref name="path" /> parameter is not a valid string.-or- The <paramref name="path" /> parameter did not specify the absolute path to the file or directory. </exception>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="path" /> parameter is null. </exception>
|
|
// 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);
|
|
}
|
|
|
|
/// <summary>Adds access for the specified files and directories to the existing state of the permission.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param>
|
|
/// <param name="pathList">An array containing the absolute paths of the files and directories. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- An entry in the <paramref name="pathList" /> array is not valid. </exception>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="pathList" /> parameter is null. </exception>
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates and returns an identical copy of the current permission.</summary>
|
|
/// <returns>A copy of the current permission.</returns>
|
|
// 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
|
|
};
|
|
}
|
|
|
|
/// <summary>Reconstructs a permission with a specified state from an XML encoding.</summary>
|
|
/// <param name="esd">The XML encoding used to reconstruct the permission. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="esd" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="esd" /> parameter is not a valid permission element.-or- The <paramref name="esd" /> parameter's version number is not compatible. </exception>
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets all files and directories with the specified <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.</summary>
|
|
/// <returns>An array containing the paths of the files and directories to which access specified by the <paramref name="access" /> parameter is granted.</returns>
|
|
/// <param name="access">One of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values that represents a single type of file access. </param>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="access" /> is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- <paramref name="access" /> is <see cref="F:System.Security.Permissions.FileIOPermissionAccess.AllAccess" />, which represents more than one type of file access, or <see cref="F:System.Security.Permissions.FileIOPermissionAccess.NoAccess" />, which does not represent any type of file access. </exception>
|
|
// 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)));
|
|
}
|
|
|
|
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
|
|
/// <returns>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.</returns>
|
|
/// <param name="target">A permission to intersect with the current permission. It 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>
|
|
// 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;
|
|
}
|
|
|
|
/// <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>
|
|
// 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));
|
|
}
|
|
|
|
/// <summary>Returns a value indicating whether the current permission is unrestricted.</summary>
|
|
/// <returns>true if the current permission is unrestricted; otherwise, false.</returns>
|
|
// Token: 0x06003158 RID: 12632 RVA: 0x000A9EB0 File Offset: 0x000A80B0
|
|
public bool IsUnrestricted()
|
|
{
|
|
return this.m_Unrestricted;
|
|
}
|
|
|
|
/// <summary>Sets the specified access to the specified file or directory, replacing the existing state of the permission.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param>
|
|
/// <param name="path">The absolute path of the file or directory. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- The <paramref name="path" /> parameter is not a valid string.-or- The <paramref name="path" /> parameter did not specify the absolute path to the file or directory. </exception>
|
|
// 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);
|
|
}
|
|
|
|
/// <summary>Sets the specified access to the specified files and directories, replacing the current state for the specified access with the new set of paths.</summary>
|
|
/// <param name="access">A bitwise combination of the <see cref="T:System.Security.Permissions.FileIOPermissionAccess" /> values. </param>
|
|
/// <param name="pathList">An array containing the absolute paths of the files and directories. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="access" /> parameter is not a valid value of <see cref="T:System.Security.Permissions.FileIOPermissionAccess" />.-or- An entry in the <paramref name="pathList" /> parameter is not a valid string. </exception>
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>Creates an XML encoding of the permission and its current state.</summary>
|
|
/// <returns>An XML encoding of the permission, including any state information.</returns>
|
|
// 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;
|
|
}
|
|
|
|
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
|
|
/// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
|
|
/// <param name="other">A permission to combine with the current permission. It must be the same type as the current permission. </param>
|
|
/// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
|
|
// 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;
|
|
}
|
|
|
|
/// <summary>Determines whether the specified <see cref="T:System.Security.Permissions.FileIOPermission" /> object is equal to the current <see cref="T:System.Security.Permissions.FileIOPermission" />.</summary>
|
|
/// <returns>true if the specified <see cref="T:System.Security.Permissions.FileIOPermission" /> is equal to the current <see cref="T:System.Security.Permissions.FileIOPermission" /> object; otherwise, false.</returns>
|
|
/// <param name="obj">The <see cref="T:System.Security.Permissions.FileIOPermission" /> object to compare with the current <see cref="T:System.Security.Permissions.FileIOPermission" />. </param>
|
|
// Token: 0x0600315D RID: 12637 RVA: 0x000AA11C File Offset: 0x000A831C
|
|
[MonoTODO("(2.0)")]
|
|
[ComVisible(false)]
|
|
public override bool Equals(object obj)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Gets a hash code for the <see cref="T:System.Security.Permissions.FileIOPermission" /> object that is suitable for use in hashing algorithms and data structures such as a hash table.</summary>
|
|
/// <returns>A hash code for the current <see cref="T:System.Security.Permissions.FileIOPermission" /> object.</returns>
|
|
// 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;
|
|
}
|
|
}
|