Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileSystemSecurity.cs
Go to the documentation of this file.
1using System.IO;
5
7
9{
10 public override Type AccessRightType => typeof(FileSystemRights);
11
12 public override Type AccessRuleType => typeof(FileSystemAccessRule);
13
14 public override Type AuditRuleType => typeof(FileSystemAuditRule);
15
16 internal FileSystemSecurity(bool isContainer)
17 : base(isContainer, ResourceType.FileObject, _HandleErrorCode, isContainer)
18 {
19 }
20
21 internal FileSystemSecurity(bool isContainer, string name, AccessControlSections includeSections, bool isDirectory)
22 : base(isContainer, ResourceType.FileObject, System.IO.PathInternal.EnsureExtendedPrefixIfNeeded(Path.GetFullPath(name)), includeSections, _HandleErrorCode, isDirectory)
23 {
24 }
25
26 internal FileSystemSecurity(bool isContainer, SafeFileHandle handle, AccessControlSections includeSections, bool isDirectory)
27 : base(isContainer, ResourceType.FileObject, handle, includeSections, _HandleErrorCode, isDirectory)
28 {
29 }
30
31 private static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
32 {
33 Exception result = null;
34 switch (errorCode)
35 {
36 case 123:
37 result = new ArgumentException(System.SR.Argument_InvalidName, "name");
38 break;
39 case 6:
41 break;
42 case 2:
43 result = ((context != null && context is bool && (bool)context) ? ((IOException)((name == null || name.Length == 0) ? new DirectoryNotFoundException() : new DirectoryNotFoundException(name))) : ((IOException)((name == null || name.Length == 0) ? new FileNotFoundException() : new FileNotFoundException(name))));
44 break;
45 }
46 return result;
47 }
48
49 public sealed override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
50 {
51 return new FileSystemAccessRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
52 }
53
54 public sealed override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
55 {
56 return new FileSystemAuditRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
57 }
58
60 {
61 AccessControlSections accessControlSections = AccessControlSections.None;
62 if (base.AccessRulesModified)
63 {
64 accessControlSections = AccessControlSections.Access;
65 }
66 if (base.AuditRulesModified)
67 {
68 accessControlSections |= AccessControlSections.Audit;
69 }
70 if (base.OwnerModified)
71 {
72 accessControlSections |= AccessControlSections.Owner;
73 }
74 if (base.GroupModified)
75 {
76 accessControlSections |= AccessControlSections.Group;
77 }
78 return accessControlSections;
79 }
80
81 internal void Persist(string fullPath)
82 {
83 WriteLock();
84 try
85 {
86 AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
87 Persist(fullPath, accessControlSectionsFromChanges);
88 bool flag2 = (base.AccessRulesModified = false);
89 bool flag4 = (base.AuditRulesModified = flag2);
90 bool ownerModified = (base.GroupModified = flag4);
91 base.OwnerModified = ownerModified;
92 }
93 finally
94 {
96 }
97 }
98
99 internal void Persist(SafeFileHandle handle, string fullPath)
100 {
101 WriteLock();
102 try
103 {
104 AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
105 Persist(handle, accessControlSectionsFromChanges);
106 bool flag2 = (base.AccessRulesModified = false);
107 bool flag4 = (base.AuditRulesModified = flag2);
108 bool ownerModified = (base.GroupModified = flag4);
109 base.OwnerModified = ownerModified;
110 }
111 finally
112 {
113 WriteUnlock();
114 }
115 }
116
118 {
120 }
121
123 {
125 }
126
128 {
130 }
131
133 {
134 if (rule == null)
135 {
136 throw new ArgumentNullException("rule");
137 }
138 AuthorizationRuleCollection accessRules = GetAccessRules(includeExplicit: true, includeInherited: true, rule.IdentityReference.GetType());
139 for (int i = 0; i < accessRules.Count; i++)
140 {
141 if (accessRules[i] is FileSystemAccessRule fileSystemAccessRule && fileSystemAccessRule.FileSystemRights == rule.FileSystemRights && fileSystemAccessRule.IdentityReference == rule.IdentityReference && fileSystemAccessRule.AccessControlType == rule.AccessControlType)
142 {
143 return RemoveAccessRule((AccessRule)rule);
144 }
145 }
147 return RemoveAccessRule((AccessRule)rule2);
148 }
149
154
156 {
157 if (rule == null)
158 {
159 throw new ArgumentNullException("rule");
160 }
161 AuthorizationRuleCollection accessRules = GetAccessRules(includeExplicit: true, includeInherited: true, rule.IdentityReference.GetType());
162 for (int i = 0; i < accessRules.Count; i++)
163 {
164 if (accessRules[i] is FileSystemAccessRule fileSystemAccessRule && fileSystemAccessRule.FileSystemRights == rule.FileSystemRights && fileSystemAccessRule.IdentityReference == rule.IdentityReference && fileSystemAccessRule.AccessControlType == rule.AccessControlType)
165 {
167 return;
168 }
169 }
172 }
173
175 {
176 AddAuditRule((AuditRule)rule);
177 }
178
180 {
181 SetAuditRule((AuditRule)rule);
182 }
183
185 {
186 return RemoveAuditRule((AuditRule)rule);
187 }
188
190 {
192 }
193
198}
static string Argument_InvalidName
Definition SR.cs:20
static string AccessControl_InvalidHandle
Definition SR.cs:14
Definition SR.cs:7
AuthorizationRuleCollection GetAccessRules(bool includeExplicit, bool includeInherited, Type targetType)
static int AccessMaskFromRights(FileSystemRights fileSystemRights, AccessControlType controlType)
void RemoveAuditRuleSpecific(FileSystemAuditRule rule)
FileSystemSecurity(bool isContainer, string name, AccessControlSections includeSections, bool isDirectory)
void RemoveAccessRuleAll(FileSystemAccessRule rule)
override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
void Persist(SafeFileHandle handle, string fullPath)
static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
void RemoveAccessRuleSpecific(FileSystemAccessRule rule)
override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
FileSystemSecurity(bool isContainer, SafeFileHandle handle, AccessControlSections includeSections, bool isDirectory)