Cannot Restore Inherited Permissions

Jan 13, 2012 at 8:47 PM

I'm trying to restore inherited permissions.

Here's the piece of code I wrote:

using System.Security;
using System.Security.Principal;
using System.Security.AccessControl;
using Alphaleonis.Win32.Filesystem;
....
private static void ResetInherited(string path, bool viaAlpha)
{
	var ds = viaAlpha? Directory.GetAccessControl(path, AccessControlSections.Access): System.IO.Directory.GetAccessControl(path, AccessControlSections.Access);
	var rules = ds.GetAccessRules(truefalsetypeof(NTAccount));
	foreach (FileSystemAccessRule rule in rules)
	{
		ds.RemoveAccessRule(rule);
	}
	ds.SetAccessRuleProtection(false, true);
	if (viaAlpha)
		Directory.SetAccessControl(path, ds, AccessControlSections.Access);
	else
		System.IO.Directory.SetAccessControl(path, ds);
 
}

When I use System.IO.Directory (viaAlpha: false)  it works like a charm.

However, when I'm using AlphaFS.Directory (viaAlpha: true) it removes explicit permissions allright, but inherited ones are not restored :-(

Apparently the highlighted call (which is the key to restore the inherited permissions) doesn't work if the security is obtained via Alpha.

Please note that only the first and last lines (geting and setting ACL) are library-specific. The middle part is all standard System.Security.

When debugging, I have discovered that as soon as I obtain ds,  ds.AreAccessRulesProtected and ds.AreAuditRulesProtected are true for System.IO, but false for Alpha. That's likely the key to the problem, but I don't know why it happens.

Please advise on a workaround (or maybe you guys can fix the whole thing:-)

TIA

Nikolai

Jan 13, 2012 at 8:58 PM
Edited Jan 13, 2012 at 9:03 PM

Jeffrey,

thanks for the prompt response!

I tried it (with MachineAccount) - didn't help, same behaviour. :-(

Maybe I had to use a different privilege? If so, which one?

--

Nikolai

Jan 13, 2012 at 9:07 PM

I just tried Backup. Same thing :-(

Jan 13, 2012 at 9:50 PM

Yessir, I did. Same thing... :-(

Darn. :-(((

Jan 13, 2012 at 9:57 PM

So, it looks like it pretty much boils down to the very first line: how come Alpha's GetAccessControl returns security with different AreXxxRulesProtected values than System.IO?

Anybody?

Jan 13, 2012 at 10:12 PM

We need a clear test case to start from that compares regular sys.io and alpha and clearly shows differences. After fix it should pass the test.

On Jan 13, 2012 4:57 PM, "nsklobovsky" <notifications@codeplex.com> wrote:

From: nsklobovsky

So, it looks like it pretty much boils down to the very first line: how come Alpha's GetAccessControl returns security with different AreXxxRulesProtected values than System.IO?

Anybody?

Read the full discussion online.

To add a post to this discussion, reply to this email (alphafs@discussions.codeplex.com)

To start a new discussion for this project, email alphafs@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jan 13, 2012 at 11:41 PM

I can't attach file here, so I created another issue with a unit test file (VS2010 SP1)

http://alphafs.codeplex.com/workitem/17258

HTH

Nikolai