
Look at http://msdn.microsoft.com/en-us/library/aa364399%28VS.85%29.aspx
Basically, you have to create a security descriptor.
Exemple :
if (!AllocateAndInitializeSid(&sia, 1, SECURITY_LOCAL_SYSTEM_RID,0, 0,
0, 0, 0, 0, 0, &pSidSystem))
{
dwError =3D GetLastError();
__leave;
}
// create Local Administrators alias SID
if (!AllocateAndInitializeSid(&sia, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0,0, 0, &pSidAdmins))
{
dwError =3D GetLastError();
__leave;
}
EXPLICIT_ACCESS ea[2];
ZeroMemory(&ea, sizeof(ea));
// fill an entry for the SYSTEM account
ea[0].grfAccessMode =3D GRANT_ACCESS;
ea[0].grfAccessPermissions =3D GENERIC_ALL;
ea[0].grfInheritance =3D NO_INHERITANCE;
ea[0].Trustee.MultipleTrusteeOperation =3D NO_MULTIPLE_TRUSTEE;
ea[0].Trustee.pMultipleTrustee =3D NULL;
ea[0].Trustee.TrusteeForm =3D TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType =3D TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName =3D (LPTSTR)pSidSystem;
// fill an entry for the Administrators alias
ea[1].grfAccessMode =3D GRANT_ACCESS;
ea[1].grfAccessPermissions =3D GENERIC_ALL;
ea[1].grfInheritance =3D NO_INHERITANCE;
ea[1].Trustee.MultipleTrusteeOperation =3D NO_MULTIPLE_TRUSTEE;
ea[1].Trustee.pMultipleTrustee =3D NULL;
ea[1].Trustee.TrusteeForm =3D TRUSTEE_IS_SID;
ea[1].Trustee.TrusteeType =3D TRUSTEE_IS_ALIAS;
ea[1].Trustee.ptstrName =3D (LPTSTR)pSidAdmins;
// create a DACL
dwError =3D SetEntriesInAcl(2, ea, NULL, &pDacl);
if (dwError !=3D ERROR_SUCCESS)
__leave;
pSD =3D (PSECURITY_DESCRIPTOR) EIDAlloc(SECURITY_DESCRIPTOR_MIN_LENGTH);
if (!pSD)
{
__leave;
}
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))
{
dwError =3D GetLastError();
__leave;
}
// Add the ACL to the security descriptor.
if (!SetSecurityDescriptorDacl(pSD,TRUE,pDacl,FALSE))
{
dwError =3D GetLastError();
__leave;
}
if (!SetSecurityDescriptorOwner(pSD,pSidAdmins,FALSE))
{
dwError =3D GetLastError();
__leave;
}
if (!SetSecurityDescriptorGroup (pSD,pSidAdmins,FALSE))
{
dwError =3D GetLastError();
__leave;
}
able
oup
the
iles are
he
evel
be
e