Inside and Out...

An attempt to understand technology better...

  Home  |   Contact  |   Syndication    |   Login
  160 Posts | 0 Stories | 12 Comments | 181 Trackbacks

News


WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Twitter





Tag Cloud


Archives

Post Categories

Image Galleries

Links

.NET Framework 2.0 ("Whidbey") has introduced a new set of classes in the Framework Class Library (FCL) that allows you to work with the NTFS Access Control Lists. You can get object owners, security descriptors, create security descriptors, and much more. All of this resides under the System.Security.AccessControl namespace.

Below is a snippet that exemplifies how to use it. Scenario: You need to create a child folder without the permissions inherited by the parent folder, but with only permissions explicitly set on the parent folder.

 

using System;
using
System.Collections.Generic;
using
System.Text;
using
System.Security.AccessControl;
using
System.IO;
using System.Security.Principal;

namespace AceInheritRemove

{

class Program

{

static void Main(string[] args)

{

// Get the object and its SecDescp

DirectoryInfo dir = new DirectoryInfo("e:\\kgk\\test");
DirectorySecurity sec = dir.GetAccessControl(AccessControlSections.All);

// Create an empty Security Descp...
DirectorySecurity secNew = new DirectorySecurity();

// Get the explicit perms on the object.
AuthorizationRuleCollection col= sec.GetAccessRules(true, false, typeof(SecurityIdentifier));

// List all the explicitly set permissions on the object...
foreach (FileSystemAccessRule rule in col)

{

// Add the explicit permission to the new Security Descp.
secNew.AddAccessRule(rule);
Console.WriteLine("{0}", rule.FileSystemRights.ToString());

}

// Create a child folder with the explicit permissions only...
DirectoryInfo info2 = new DirectoryInfo("e:\\kgk\\Test\\Child");
info2.Create(secNew);

}

}

}

 

posted on Tuesday, July 12, 2005 12:37 PM

Feedback

# SetAccessRuleProtection and Inherited NTFS Permissions 7/10/2006 7:41 PM Inside and Out...

Continuing from my last post, the same can be achieved using SetAccessRuleProtection as shown below:...

Comments have been closed on this topic.