In my program, I have to set the group policy setting of certain files to ALL APPLICATION PACKAGES
. To accomplish this, I'm using the following function which takes the FilePath
to a file and sets the ALL APPLICATION PACKAGES
group policy on that file:
DWORD AdjustGroupPolicy(std::wstring wstrFilePath)
{
PACL pOldDACL = NULL, pNewDACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;
EXPLICIT_ACCESS eaAccess;
SECURITY_INFORMATION siInfo = DACL_SECURITY_INFORMATION;
DWORD dwResult = ERROR_SUCCESS;
dwResult = GetNamedSecurityInfo(wstrFilePath.c_str(), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pOldDACL, NULL, &pSD);
if (dwResult != ERROR_SUCCESS)
{
if (pSD != NULL)
LocalFree((HLOCAL)pSD);
}
ZeroMemory(&eaAccess, sizeof(EXPLICIT_ACCESS));
eaAccess.grfAccessPermissions = GENERIC_READ | GENERIC_EXECUTE;
eaAccess.grfAccessMode = SET_ACCESS;
eaAccess.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
eaAccess.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
eaAccess.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
eaAccess.Trustee.ptstrName = L"ALL APPLICATION PACKAGES";
dwResult = SetEntriesInAcl(1, &eaAccess, pOldDACL, &pNewDACL);
if (ERROR_SUCCESS != dwResult)
{
if (pSD != NULL)
LocalFree((HLOCAL)pSD);
if (pNewDACL != NULL)
LocalFree((HLOCAL)pNewDACL);
}
dwResult = SetNamedSecurityInfo((LPWSTR)wstrFilePath.c_str(), SE_FILE_OBJECT, siInfo, NULL, NULL, pNewDACL, NULL);
if (ERROR_SUCCESS != dwResult)
{
if (pSD != NULL)
LocalFree((HLOCAL)pSD);
if (pNewDACL != NULL)
LocalFree((HLOCAL)pNewDACL);
}
return dwResult;
}
The problem is, some users are reporting that this function is failing for some reason. After digging into the issue a bit, I found that on PC's with languages settings other than English, the function fails at SetEntiresInAcl
with the error code 1332 (0x534). In the MSDN documentation, the error code corresponds to the error ERROR_NONE_MAPPED
, with the description:
No mapping between account names and security IDs was done.
My guess is that the error is thrown because ALL APPLICATION PACKAGES
is named something differently depending on the language settings and thus Windows can't find the security ID for it; however, I'm unsure of how to fix this error. How could I go about fixing this error so that the function works reliably regardless of the users language settings?