16 private FileIOAccess m_read;
18 private FileIOAccess m_write;
20 private FileIOAccess m_append;
22 private FileIOAccess m_pathDiscovery;
24 [OptionalField(VersionAdded = 2)]
25 private FileIOAccess m_viewAcl;
27 [OptionalField(VersionAdded = 2)]
28 private FileIOAccess m_changeAcl;
30 private bool m_unrestricted;
43 if (m_read !=
null && m_read.AllLocalFiles)
47 if (m_write !=
null && m_write.AllLocalFiles)
51 if (m_append !=
null && m_append.AllLocalFiles)
55 if (m_pathDiscovery !=
null && m_pathDiscovery.AllLocalFiles)
59 return fileIOPermissionAccess;
67 m_read =
new FileIOAccess();
69 m_read.AllLocalFiles =
true;
71 else if (m_read !=
null)
73 m_read.AllLocalFiles =
false;
79 m_write =
new FileIOAccess();
81 m_write.AllLocalFiles =
true;
83 else if (m_write !=
null)
85 m_write.AllLocalFiles =
false;
91 m_append =
new FileIOAccess();
93 m_append.AllLocalFiles =
true;
95 else if (m_append !=
null)
97 m_append.AllLocalFiles =
false;
101 if (m_pathDiscovery ==
null)
103 m_pathDiscovery =
new FileIOAccess(pathDiscovery:
true);
105 m_pathDiscovery.AllLocalFiles =
true;
107 else if (m_pathDiscovery !=
null)
109 m_pathDiscovery.AllLocalFiles =
false;
125 if (m_read !=
null && m_read.AllFiles)
129 if (m_write !=
null && m_write.AllFiles)
133 if (m_append !=
null && m_append.AllFiles)
137 if (m_pathDiscovery !=
null && m_pathDiscovery.AllFiles)
141 return fileIOPermissionAccess;
147 m_unrestricted =
true;
154 m_read =
new FileIOAccess();
156 m_read.AllFiles =
true;
158 else if (m_read !=
null)
160 m_read.AllFiles =
false;
166 m_write =
new FileIOAccess();
168 m_write.AllFiles =
true;
170 else if (m_write !=
null)
172 m_write.AllFiles =
false;
176 if (m_append ==
null)
178 m_append =
new FileIOAccess();
180 m_append.AllFiles =
true;
182 else if (m_append !=
null)
184 m_append.AllFiles =
false;
188 if (m_pathDiscovery ==
null)
190 m_pathDiscovery =
new FileIOAccess(pathDiscovery:
true);
192 m_pathDiscovery.AllFiles =
true;
194 else if (m_pathDiscovery !=
null)
196 m_pathDiscovery.AllFiles =
false;
209 m_unrestricted =
true;
212 m_unrestricted =
false;
223 [SecuritySafeCritical]
226 VerifyAccess(access);
227 string[] pathListOrig =
new string[1]
231 AddPathList(access, pathListOrig, checkForDuplicates:
false, needFullPath:
true, copyPathList:
false);
238 [SecuritySafeCritical]
241 VerifyAccess(access);
242 AddPathList(access, pathList, checkForDuplicates:
false, needFullPath:
true, copyPathList:
false);
250 [SecuritySafeCritical]
253 VerifyAccess(access);
254 string[] pathListOrig =
new string[1]
258 AddPathList(access, control, pathListOrig, checkForDuplicates:
false, needFullPath:
true, copyPathList:
false);
266 [SecuritySafeCritical]
268 : this(access, control, pathList, checkForDuplicates: true, needFullPath: true)
275 VerifyAccess(access);
276 AddPathList(access, pathList, checkForDuplicates, needFullPath, copyPathList:
true);
282 VerifyAccess(access);
283 AddPathList(access, control, pathList, checkForDuplicates, needFullPath, copyPathList:
true);
292 string[] pathList = (path !=
null) ?
new string[1]
296 SetPathList(access, pathList, checkForDuplicates:
false);
305 SetPathList(access, pathList, checkForDuplicates:
true);
313 [SecuritySafeCritical]
316 VerifyAccess(access);
331 m_pathDiscovery =
null;
341 m_unrestricted =
false;
342 AddPathList(access, control, pathList, checkForDuplicates, needFullPath:
true, copyPathList:
true);
351 [SecuritySafeCritical]
354 string[] pathListOrig = (path !=
null) ?
new string[1]
358 AddPathList(access, pathListOrig, checkForDuplicates:
false, needFullPath:
true, copyPathList:
false);
367 [SecuritySafeCritical]
370 AddPathList(access, pathList, checkForDuplicates:
true, needFullPath:
true, copyPathList:
true);
382 if (pathListOrig ==
null)
386 if (pathListOrig.Length == 0)
390 VerifyAccess(access);
395 string[] array = pathListOrig;
398 array =
new string[pathListOrig.Length];
399 Array.Copy(pathListOrig, array, pathListOrig.Length);
401 CheckIllegalCharacters(array, needFullPath);
402 ArrayList values = StringExpressionSet.CreateListFromExpressions(array, needFullPath);
407 m_read =
new FileIOAccess();
409 m_read.AddExpressions(values, checkForDuplicates);
415 m_write =
new FileIOAccess();
417 m_write.AddExpressions(values, checkForDuplicates);
421 if (m_append ==
null)
423 m_append =
new FileIOAccess();
425 m_append.AddExpressions(values, checkForDuplicates);
429 if (m_pathDiscovery ==
null)
431 m_pathDiscovery =
new FileIOAccess(pathDiscovery:
true);
433 m_pathDiscovery.AddExpressions(values, checkForDuplicates);
437 if (m_viewAcl ==
null)
439 m_viewAcl =
new FileIOAccess();
441 m_viewAcl.AddExpressions(values, checkForDuplicates);
445 if (m_changeAcl ==
null)
447 m_changeAcl =
new FileIOAccess();
449 m_changeAcl.AddExpressions(values, checkForDuplicates);
459 [SecuritySafeCritical]
462 VerifyAccess(access);
463 ExclusiveAccess(access);
470 return m_read.ToStringArray();
478 return m_write.ToStringArray();
482 if (m_append ==
null)
486 return m_append.ToStringArray();
490 if (m_pathDiscovery ==
null)
494 return m_pathDiscovery.ToStringArray();
513 if ((access & (access - 1)) != 0)
515 throw new ArgumentException(Environment.GetResourceString(
"Arg_EnumNotSingleFlag"));
519 private static void CheckIllegalCharacters(
string[] str,
bool onlyCheckExtras)
524 if (num < str.Length)
526 if (str[num] ==
null)
528 throw new ArgumentNullException(
"path");
530 if (CheckExtraPathCharacters(str[num]))
534 if (!onlyCheckExtras)
536 Path.CheckInvalidPathChars(str[num]);
543 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidPathChars"));
547 [SecuritySafeCritical]
548 private static bool CheckExtraPathCharacters(
string path)
550 int num = (CodeAccessSecurityEngine.QuickCheckForAllDemands() && !AppContextSwitches.UseLegacyPathHandling) ? (PathInternal.IsDevice(path) ? 4 : 0) : 0;
551 for (
int i = num; i < path.Length; i++)
554 if (c ==
'*' || c ==
'?' || c ==
'\0')
567 private bool IsEmpty()
569 if (!m_unrestricted && (m_read ==
null || m_read.IsEmpty()) && (m_write ==
null || m_write.IsEmpty()) && (m_append ==
null || m_append.IsEmpty()) && (m_pathDiscovery ==
null || m_pathDiscovery.IsEmpty()) && (m_viewAcl ==
null || m_viewAcl.IsEmpty()))
571 if (m_changeAcl !=
null)
573 return m_changeAcl.IsEmpty();
585 return m_unrestricted;
600 if (fileIOPermission ==
null)
612 if ((m_read ==
null || m_read.IsSubsetOf(fileIOPermission.m_read)) && (m_write ==
null || m_write.IsSubsetOf(fileIOPermission.m_write)) && (m_append ==
null || m_append.IsSubsetOf(fileIOPermission.m_append)) && (m_pathDiscovery ==
null || m_pathDiscovery.IsSubsetOf(fileIOPermission.m_pathDiscovery)) && (m_viewAcl ==
null || m_viewAcl.IsSubsetOf(fileIOPermission.m_viewAcl)))
614 if (m_changeAcl !=
null)
616 return m_changeAcl.IsSubsetOf(fileIOPermission.m_changeAcl);
634 if (fileIOPermission ==
null)
640 return target.
Copy();
646 FileIOAccess fileIOAccess = (m_read ==
null) ?
null : m_read.Intersect(fileIOPermission.m_read);
647 FileIOAccess fileIOAccess2 = (m_write ==
null) ?
null : m_write.Intersect(fileIOPermission.m_write);
648 FileIOAccess fileIOAccess3 = (m_append ==
null) ?
null : m_append.Intersect(fileIOPermission.m_append);
649 FileIOAccess fileIOAccess4 = (m_pathDiscovery ==
null) ?
null : m_pathDiscovery.Intersect(fileIOPermission.m_pathDiscovery);
650 FileIOAccess fileIOAccess5 = (m_viewAcl ==
null) ?
null : m_viewAcl.Intersect(fileIOPermission.m_viewAcl);
651 FileIOAccess fileIOAccess6 = (m_changeAcl ==
null) ?
null : m_changeAcl.Intersect(fileIOPermission.m_changeAcl);
652 if ((fileIOAccess ==
null || fileIOAccess.IsEmpty()) && (fileIOAccess2 ==
null || fileIOAccess2.IsEmpty()) && (fileIOAccess3 ==
null || fileIOAccess3.IsEmpty()) && (fileIOAccess4 ==
null || fileIOAccess4.IsEmpty()) && (fileIOAccess5 ==
null || fileIOAccess5.IsEmpty()) && (fileIOAccess6 ==
null || fileIOAccess6.IsEmpty()))
657 fileIOPermission2.m_unrestricted =
false;
658 fileIOPermission2.m_read = fileIOAccess;
659 fileIOPermission2.m_write = fileIOAccess2;
660 fileIOPermission2.m_append = fileIOAccess3;
661 fileIOPermission2.m_pathDiscovery = fileIOAccess4;
662 fileIOPermission2.m_viewAcl = fileIOAccess5;
663 fileIOPermission2.m_changeAcl = fileIOAccess6;
664 return fileIOPermission2;
678 if (fileIOPermission ==
null)
686 FileIOAccess fileIOAccess = (m_read ==
null) ? fileIOPermission.m_read : m_read.Union(fileIOPermission.m_read);
687 FileIOAccess fileIOAccess2 = (m_write ==
null) ? fileIOPermission.m_write : m_write.Union(fileIOPermission.m_write);
688 FileIOAccess fileIOAccess3 = (m_append ==
null) ? fileIOPermission.m_append : m_append.Union(fileIOPermission.m_append);
689 FileIOAccess fileIOAccess4 = (m_pathDiscovery ==
null) ? fileIOPermission.m_pathDiscovery : m_pathDiscovery.Union(fileIOPermission.m_pathDiscovery);
690 FileIOAccess fileIOAccess5 = (m_viewAcl ==
null) ? fileIOPermission.m_viewAcl : m_viewAcl.Union(fileIOPermission.m_viewAcl);
691 FileIOAccess fileIOAccess6 = (m_changeAcl ==
null) ? fileIOPermission.m_changeAcl : m_changeAcl.Union(fileIOPermission.m_changeAcl);
692 if ((fileIOAccess ==
null || fileIOAccess.IsEmpty()) && (fileIOAccess2 ==
null || fileIOAccess2.IsEmpty()) && (fileIOAccess3 ==
null || fileIOAccess3.IsEmpty()) && (fileIOAccess4 ==
null || fileIOAccess4.IsEmpty()) && (fileIOAccess5 ==
null || fileIOAccess5.IsEmpty()) && (fileIOAccess6 ==
null || fileIOAccess6.IsEmpty()))
697 fileIOPermission2.m_unrestricted =
false;
698 fileIOPermission2.m_read = fileIOAccess;
699 fileIOPermission2.m_write = fileIOAccess2;
700 fileIOPermission2.m_append = fileIOAccess3;
701 fileIOPermission2.m_pathDiscovery = fileIOAccess4;
702 fileIOPermission2.m_viewAcl = fileIOAccess5;
703 fileIOPermission2.m_changeAcl = fileIOAccess6;
704 return fileIOPermission2;
714 fileIOPermission.m_unrestricted =
true;
718 fileIOPermission.m_unrestricted =
false;
721 fileIOPermission.m_read = m_read.Copy();
725 fileIOPermission.m_write = m_write.Copy();
727 if (m_append !=
null)
729 fileIOPermission.m_append = m_append.Copy();
731 if (m_pathDiscovery !=
null)
733 fileIOPermission.m_pathDiscovery = m_pathDiscovery.Copy();
735 if (m_viewAcl !=
null)
737 fileIOPermission.m_viewAcl = m_viewAcl.Copy();
739 if (m_changeAcl !=
null)
741 fileIOPermission.m_changeAcl = m_changeAcl.Copy();
744 return fileIOPermission;
754 if (m_read !=
null && !m_read.IsEmpty())
758 if (m_write !=
null && !m_write.IsEmpty())
762 if (m_append !=
null && !m_append.IsEmpty())
766 if (m_pathDiscovery !=
null && !m_pathDiscovery.IsEmpty())
770 if (m_viewAcl !=
null && !m_viewAcl.IsEmpty())
774 if (m_changeAcl !=
null && !m_changeAcl.IsEmpty())
783 return securityElement;
790 [SecuritySafeCritical]
794 if (XMLUtil.IsUnrestricted(esd))
796 m_unrestricted =
true;
799 m_unrestricted =
false;
800 string text = esd.Attribute(
"Read");
803 m_read =
new FileIOAccess(text);
809 text = esd.Attribute(
"Write");
812 m_write =
new FileIOAccess(text);
818 text = esd.Attribute(
"Append");
821 m_append =
new FileIOAccess(text);
827 text = esd.Attribute(
"PathDiscovery");
830 m_pathDiscovery =
new FileIOAccess(text);
831 m_pathDiscovery.PathDiscovery =
true;
835 m_pathDiscovery =
null;
837 text = esd.Attribute(
"ViewAcl");
840 m_viewAcl =
new FileIOAccess(text);
846 text = esd.Attribute(
"ChangeAcl");
849 m_changeAcl =
new FileIOAccess(text);
857 int IBuiltInPermission.GetTokenIndex()
859 return GetTokenIndex();
862 internal static int GetTokenIndex()
875 if (fileIOPermission ==
null)
879 if (m_unrestricted && fileIOPermission.m_unrestricted)
883 if (m_unrestricted != fileIOPermission.m_unrestricted)
889 if (fileIOPermission.m_read !=
null && !fileIOPermission.m_read.IsEmpty())
894 else if (!m_read.Equals(fileIOPermission.m_read))
900 if (fileIOPermission.m_write !=
null && !fileIOPermission.m_write.IsEmpty())
905 else if (!m_write.Equals(fileIOPermission.m_write))
909 if (m_append ==
null)
911 if (fileIOPermission.m_append !=
null && !fileIOPermission.m_append.IsEmpty())
916 else if (!m_append.Equals(fileIOPermission.m_append))
920 if (m_pathDiscovery ==
null)
922 if (fileIOPermission.m_pathDiscovery !=
null && !fileIOPermission.m_pathDiscovery.IsEmpty())
927 else if (!m_pathDiscovery.Equals(fileIOPermission.m_pathDiscovery))
931 if (m_viewAcl ==
null)
933 if (fileIOPermission.m_viewAcl !=
null && !fileIOPermission.m_viewAcl.IsEmpty())
938 else if (!m_viewAcl.Equals(fileIOPermission.m_viewAcl))
942 if (m_changeAcl ==
null)
944 if (fileIOPermission.m_changeAcl !=
null && !fileIOPermission.m_changeAcl.IsEmpty())
949 else if (!m_changeAcl.Equals(fileIOPermission.m_changeAcl))
961 return base.GetHashCode();
964 [SecuritySafeCritical]
965 internal static void QuickDemand(
FileIOPermissionAccess access,
string fullPath,
bool checkForDuplicates =
false,
bool needFullPath =
true)
967 if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
972 }, checkForDuplicates, needFullPath).
Demand();
976 EmulateFileIOPermissionChecks(fullPath);
980 [SecuritySafeCritical]
981 internal static void QuickDemand(
FileIOPermissionAccess access,
string[] fullPathList,
bool checkForDuplicates =
false,
bool needFullPath =
true)
983 if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
985 new FileIOPermission(access, fullPathList, checkForDuplicates, needFullPath).Demand();
988 foreach (
string fullPath
in fullPathList)
990 EmulateFileIOPermissionChecks(fullPath);
994 [SecuritySafeCritical]
997 if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
1003 [SecuritySafeCritical]
1006 if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
1011 }, checkForDuplicates, needFullPath).
Demand();
1015 EmulateFileIOPermissionChecks(fullPath);
1019 [SecuritySafeCritical]
1022 if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
1024 new FileIOPermission(access, control, fullPathList, checkForDuplicates, needFullPath).Demand();
1027 foreach (
string fullPath
in fullPathList)
1029 EmulateFileIOPermissionChecks(fullPath);
1033 internal static void EmulateFileIOPermissionChecks(
string fullPath)
1035 if (AppContextSwitches.UseLegacyPathHandling || !PathInternal.IsDevice(fullPath))
1037 if (PathInternal.HasWildCardCharacters(fullPath))
1039 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidPathChars"));
1041 if (PathInternal.HasInvalidVolumeSeparator(fullPath))
1043 throw new NotSupportedException(Environment.GetResourceString(
"Argument_PathFormatNotSupported"));
override SecurityElement ToXml()
Creates an XML encoding of the permission and its current state.
Allows a permission to expose an unrestricted state.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
FileIOPermissionAccess
Specifies the type of file access requested.
void SetPathList(FileIOPermissionAccess access, string path)
Sets the specified access to the specified file or directory, replacing the existing state of the per...
IPermission Copy()
Creates and returns an identical copy of the current permission.
bool IsUnrestricted()
Returns a value indicating whether the current permission is unrestricted.
FileIOPermission(PermissionState state)
Initializes a new instance of the T:System.Security.Permissions.FileIOPermission class with fully res...
override int GetHashCode()
Gets a hash code for the T:System.Security.Permissions.FileIOPermission object that is suitable for u...
string [] GetPathList(FileIOPermissionAccess access)
Gets all files and directories with the specified T:System.Security.Permissions.FileIOPermissionAcces...
static string Escape(string str)
Replaces invalid XML characters in a string with their valid XML equivalent.
override void FromXml(SecurityElement esd)
Reconstructs a permission with a specified state from an XML encoding.
override IPermission Union(IPermission other)
Creates a permission that is the union of the current permission and the specified permission.
Provides information about, and means to manipulate, the current environment and platform....
void AddPathList(FileIOPermissionAccess access, string path)
Adds access for the specified file or directory to the existing state of the permission.
Represents the XML object model for encoding security objects. This class cannot be inherited.
Defines the underlying structure of all code access permissions.
FileIOPermission(FileIOPermissionAccess access, string path)
Initializes a new instance of the T:System.Security.Permissions.FileIOPermission class with the speci...
MethodImplOptions
Defines the details of how a method is implemented.
FileIOPermissionAccess AllFiles
Gets or sets the permitted access to all files.
void SetPathList(FileIOPermissionAccess access, string[] pathList)
Sets the specified access to the specified files and directories, replacing the current state for the...
Defines methods implemented by permission types.
AccessControlActions
Specifies the actions that are permitted for securable objects.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
FileIOPermission(FileIOPermissionAccess access, string[] pathList)
Initializes a new instance of the T:System.Security.Permissions.FileIOPermission class with the speci...
override bool Equals(object obj)
Determines whether the specified T:System.Security.Permissions.FileIOPermission object is equal to th...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
override IPermission Copy()
Creates and returns an identical copy of the current permission.
FileIOPermission(FileIOPermissionAccess access, AccessControlActions control, string path)
Initializes a new instance of the T:System.Security.Permissions.FileIOPermission class with the speci...
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
Controls the ability to access files and folders. This class cannot be inherited.
FileIOPermission(FileIOPermissionAccess access, AccessControlActions control, string[] pathList)
Initializes a new instance of the T:System.Security.Permissions.FileIOPermission class with the speci...
FileIOPermissionAccess AllLocalFiles
Gets or sets the permitted access to all local files.
override bool IsSubsetOf(IPermission target)
Determines whether the current permission is a subset of the specified permission.
Performs operations on T:System.String instances that contain file or directory path information....
void AddPathList(FileIOPermissionAccess access, string[] pathList)
Adds access for the specified files and directories to the existing state of the permission.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
override IPermission Intersect(IPermission target)
Creates and returns a permission that is the intersection of the current permission and the specified...