by Marcin Policht
In his latest article, Marcin Policht illustrates how the Active Directory Services Interface (ADSI) can be used to manipulate permissions on the NTFS file system level.
Active Directory Services Interface is typically used for management of various account repositories, such as Windows NT SAM database, IIS
Metabase, or LDAP-based directories such as AD or NDS. However, the capabilities of ADSI go far beyond simple group and user account manipulation. For
example, ADSI can be used to manipulate permissions on the NTFS file system level.
In order to understand the mechanism that ADSI uses to accomplish this task, we need to take a closer look at the way the Windows operating system
secures its components. Information about security settings of an object (this applies to the NTFS file system, the Windows Registry, or Active Directory
objects) is stored in a structure called Security Descriptor.
Security Descriptor for an object contains some or all of the following information:
An access control entry consists, in turn, of several subentries:
permissions apply to this folder only, or to subfolders and files as well).
The graphical representation of these settings can be viewed by launching Windows Explorer and checking the properties of a file or folder. After
selecting Security Tab, click on the Advanced button and you will see the list of Access Control Entries presented in a friendly fashion.
Dealing with ACEs, DACLs, and SACLs using scripting (or programming) is a fairly difficult task because the objects used to represent structures
described above are rather complex. Also, even small mistakes when changing permissions on file system, registry, or Active Directory objects can
have serious implications, so make sure you test your scripts appropriately.
Fortunately, Microsoft provides a number of samples documenting the way to manipulate permissions via scripting (programming methods are
extensively documented in the MSDN Library at msdn.microsoft.com). The Knowledge Base article Q279682 “How to Use ADsSecurity.dll to Add an Access Control
Entry to an NTFS Folder” outlines such a procedure. However, the sample code sets permissions on a folder level only, and the changes do not
propagate to any of its subfolders. The reason for this is the fact that the SetSecurityInfo API function (contained in ADsSecurity.dll, which is used
by the script) fails to propagate inheritable ACEs to any of the subfolders. Q266461 “How to Use ADSI to Set Automatic Inheritance of File/Folder
Permissions” describes a workaround for this.
In order to be able to manipulate Security Descriptors through scripting, you will need to start by obtaining AdsSecurity.dll, which is available
as part of ADSI Software Development Kit (available at http://download.microsoft.com/msdownload/adsi/2.5/sdk/x86/en/Sdk.zip). Alternatively, you
can use Platform SDK, which on one hand will give you the most recent information, but on the other hand, it will force you to go through a lengthy download process (the core SDK itself is 321.7 MB). You also have an option of ordering a CD; for details, refer to
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/.
Once you get the copy of ADsSecurity.dll, copy it to your %Windir%System32 directory and register by running
REGSVR32.EXE ADsSecurity.DLL from the command prompt.
In order to fully understand the structure of a Security Descriptor (and ultimately to be able to write scripts that change it), you will need to
become familiar with a number of constants used in setting ACE masks (affecting permissions), ACE flags (affecting inheritance), and ACE types
(determining whether ACE mask is used for allowing or denying access).
The format of access masks and the listing of constants are available at msdn.microsoft.com but since you are risking an information overload by
accessing it, here is an abbreviated version:
The following are relevant constants that can be used to analyze the
granular permissions assigned to files and folders by setting appropriate
access masks:
Handling these individual permissions is typically not needed, since they tend to be assigned on a less granular level, at least when dealing with
file system permissions (controlling access to Active Directory objects is much more complex). Therefore, it might be more efficient (and easier)
to consider simply four types of basic access rights:
Here’s how these types of access rights translate into a combination of access mask bits. Each needs to be considered in combination with the value
of the ACE type:
Ace Type:
ACCESS_ALLOWED
ACE Mask:
FILE_READ_DATA
FILE_WRITE_DATA
FILE_APPEND_DATA
FILE_READ_EA
FILE_WRITE_EA
FILE_EXECUTE
FILE_DELETE_CHILD
FILE_READ_ATTRIBUTES
FILE_WRITE_ATTRIBUTES
DELETE
READ_CONTROL
WRITE_DAC
WRITE_OWNER
SYNCHRONIZE
Ace Type:
ACCESS_ALLOWED
ACE Mask:
FILE_READ_DATA
FILE_WRITE_DATA
FILE_APPEND_DATA
FILE_READ_EA
FILE_WRITE_EA
FILE_EXECUTE
FILE_READ_ATTRIBUTES
FILE_WRITE_ATTRIBUTES
DELETE
READ_CONTROL
SYNCHRONIZE
ACE Type:
ACCESS_ALLOWED
ACE Mask:
FILE_READ_DATA
FILE_READ_EA
FILE_EXECUTE
FILE_READ_ATTRIBUTES
READ_CONTROL
SYNCHRONIZE
ACE Type:
ACCESS_DENIED
ACE Mask:
FILE_READ_DATA
FILE_READ_EA
FILE_EXECUTE
FILE_READ_ATTRIBUTES
READ_CONTROL
Note that since this listing refers to ACCESS_DENIED Ace type, the SYNCHRONIZE permission is missing (comparing with the previous set of entries).
In my next article, I’ll provide a script which will allow you to display the content of DACL (ACE entries) for arbitrarily chosen files or folders.
Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.