HOWTO: Specify Access Control on Window NT Container ObjectsID: Q188760
|
Programmatically specifying access control for Windows NT container objects is more complex that that of other Win32 objects. This is because access control on container objects allows you to specify access to the container and access for future objects created in the container.
A Windows NT securable object is a container if it can logically contain
other securable objects. The following table demonstrates the relationship
between a container object and the objects it might contain:
Container Object Objects Contained
-----------------------------------------------
Directory Files/Directories
Registry Key Registry Keys/Values
Windowstation Desktop
Printer Printer share
Windows NT supports ACL Inheritance. This means that when a new object is
created within a container object, the new object inherits permissions from
the parent container object by default.
Q102102 HOWTO: Add an Access-Allowed ACE to a FileOnce the ACE is in the DACL through AddAccessAllowed/DeniedAce(), set the AceFlags member of the new ACE. You do this by using the GetAce() API to retrieve a pointer to the new ACE. Use this pointer to set the AceFlags member of the ACE header structure as follows:
{ // You can add this to step 14 of Q102102, which demonstrates adding
// an Access Allowed ACE to a DACL.
// Add the access-allowed ACE to the new DACL.
if(!AddAccessAllowedAce(pNewACL,ACL_REVISION2,dwAcessMask, pSid))
{
// Handle AddAccessAllowedAce Error.
}
// Get pointer to ACE you just added, so you can change the AceFlags.
if(!GetAce( pNewACL,
0, // You know it is the first ACE in the Acl.
&pTempAce ))
{
// Handle GetAce Error.
}
// Set AceFlags member.
pTempAce->Header.AceFlags = bAceFlags;
}
This extra step is necessary because the AddAccessAllowedAce() API does not
have a parameter to specify this attribute of a new ACE.
{
DWORD bAceFlags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE;
ACCESS_ALLOWED_ACE *pAce = (ACCESS_ALLOWED_ACE *)
malloc(sizeof(ACCESS_ALLOWED_ACE) + sidlen - sizeof(DWORD));
// Fill in ACCESS_ALLOWED_ACE structure.
pAce->Mask = dwAcessMask;
pAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
pAce->Header.AceFlags = bAceFlags;
pAce->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE)
+ sidlen - sizeof(DWORD);
memcpy(&(pAce->Header.SidStart),pSid,GetLengthSid(pSid) );
if(!AddAce(pNewACL, ACL_REVISION, MAXDWORD,
pAce, pAce->Header.AceSize))
{
// Handle AddAce error.
}
}
Additional query words: directory sid special security printer
Keywords : kbKernBase kbSecurity
Version : winnt:
Platform : winnt
Issue type : kbhowto
Last Reviewed: February 6, 1999