rendered paste bodybool TakeOwnership(LPTSTR lpszOwnFile, PSID pSIDOwner);
int main()
{
if (TakeOwnership(L"test.txt", "testuser") )
{
printf("Worked like a champ\n");
return 0;
}
else
{
printf("Epic fail\n");
return 1;
}
}
bool TakeOwnership(LPTSTR lpszOwnFile, PSID pSIDOwner)
{
bool bRetval = FALSE;
PACL pACL = NULL;
DWORD dwRes;
dwRes = SetNamedSecurityInfo(
lpszOwnFile, // name of the object
SE_FILE_OBJECT, // type of object
OWNER_SECURITY_INFORMATION, // change only the object's DACL
pSIDOwner, NULL, // do not change owner or group
pACL, // DACL specified
NULL); // do not change SACL
if (ERROR_SUCCESS == dwRes)
{
printf("Successfully changed DACL\n");
bRetval = TRUE;
// No more processing needed.
goto Cleanup;
}
Cleanup:
if (pSIDOwner)
FreeSid(pSIDOwner);
if (pACL)
LocalFree(pACL);
return bRetval;
}