|
11 | 11 | using System.Security.AccessControl; |
12 | 12 | using System.Threading; |
13 | 13 | using System.Threading.Tasks; |
| 14 | +using System.Security.Principal; |
14 | 15 |
|
15 | 16 | namespace CustomActions |
16 | 17 | { |
@@ -339,10 +340,29 @@ public static void CongigureSecurity(string folder) |
339 | 340 |
|
340 | 341 | var dSecurity = dInfo.GetAccessControl(); |
341 | 342 |
|
342 | | - dSecurity.AddAccessRule(new FileSystemAccessRule("IUSR", FileSystemRights.FullControl, AccessControlType.Allow)); |
343 | | - dSecurity.AddAccessRule(new FileSystemAccessRule("IIS_IUSRS", FileSystemRights.FullControl, AccessControlType.Allow)); |
| 343 | + IdentityReference eid = new SecurityIdentifier(WellKnownSidType.WorldSid, null); |
| 344 | + dSecurity.AddAccessRule(new FileSystemAccessRule("IUSR", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); |
| 345 | + dSecurity.AddAccessRule(new FileSystemAccessRule("IIS_IUSRS", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); |
344 | 346 |
|
345 | 347 | dInfo.SetAccessControl(dSecurity); |
| 348 | + |
| 349 | + ReplaceAllDescendantPermissionsFromObject(dInfo, dSecurity); |
| 350 | + } |
| 351 | + |
| 352 | + private static void ReplaceAllDescendantPermissionsFromObject(DirectoryInfo dInfo, DirectorySecurity dSecurity) |
| 353 | + { |
| 354 | + dInfo.SetAccessControl(dSecurity); |
| 355 | + |
| 356 | + foreach (FileInfo fi in dInfo.GetFiles()) |
| 357 | + { |
| 358 | + var ac = fi.GetAccessControl(); |
| 359 | + |
| 360 | + ac.SetAccessRuleProtection(false, false); |
| 361 | + |
| 362 | + fi.SetAccessControl(ac); |
| 363 | + } |
| 364 | + |
| 365 | + dInfo.GetDirectories().ToList().ForEach(d => ReplaceAllDescendantPermissionsFromObject(d, dSecurity)); |
346 | 366 | } |
347 | 367 |
|
348 | 368 | private static void BuildAngularApp(string appLocation) |
|
0 commit comments