Inside and Out…

An attempt to understand technology better…

Archive for July, 2005

SetAccessRuleProtection and Inherited NTFS Permissions

Posted by Gaurav Khanna on July 12, 2005

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

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);

            sec.SetAccessRuleProtection(true, false);

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

            dir.SetAccessControl(sec);
        }
    }
}

Advertisements

Posted in .NET Framework, Development, Windows API | 1 Comment »

Working with NTFS Access Control using .NET Framework 2.0

Posted by Gaurav Khanna on July 12, 2005

.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

            DirectoryInfodir = newDirectoryInfo("e:\\kgk\\test"); 
            DirectorySecuritysec = dir.GetAccessControl(AccessControlSections.All); 

            // Create an empty Security Descp... 
            DirectorySecuritysecNew = newDirectorySecurity();

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

            // List all the explicitly set permissions on the object... 
            foreach(FileSystemAccessRulerule 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... 
            DirectoryInfoinfo2 = newDirectoryInfo("e:\\kgk\\Test\\Child"); 
            info2.Create(secNew);

        }

    }
}

Posted in .NET Framework, Development, Tips, Windows API | 1 Comment »

Understanding CLR’s Special Threads

Posted by Gaurav Khanna on July 12, 2005

There are multiple special threads which the CLR maintains and executes. Yun Jin talks about them in his blog at http://blogs.msdn.com/yunjin/archive/2005/07/05/435726.aspx.

Must read for those who want to understand CLR better!

Posted in .NET Framework, CLR, Tips | Leave a Comment »

CalendarSP Update

Posted by Gaurav Khanna on July 5, 2005

With TechED 2005 India over, I have got sometime to work on the feedback I have got on the various components I have made available at http://www.wintoolzone.com/. Amongst them was to fix the tab order of CalendarSP – the date picker for SmartPhone 2003 and SmartPhone 5.0 platform.

Download the updated control from http://www.wintoolzone.com/showpage.aspx?url=dotnet.aspx

Posted in .NET Compact Framework, Development, Downloads, Windows CE/Windows Mobile | Leave a Comment »