Entfernen Sie den Eintrag aus DACL der DateiC++

Programme in C++. Entwicklerforum
Anonymous
 Entfernen Sie den Eintrag aus DACL der Datei

Post by Anonymous »

Ich habe eine Funktion, die Datei_execute direkt in der DACL der Datei verweigern kann. So leugnen Sie die Funktion wie diese (siehe den vollständigen Code in der Hauptfunktion):

Code: Select all

AddAceToObjectsSecurityDescriptor(objectName, SE_FILE_OBJECT, (PWSTR)pSid, TRUSTEE_IS_SID, FILE_EXECUTE, DENY_ACCESS, NO_INHERITANCE);

Nachdem ich die Berechtigung von File_execute verweigert habe, möchte ich diesen Vorgang rückgängig machen. Mit anderen Worten, ich möchte aus dem DACL entfernen, den Eintrag, den File_execute verweigert wurde.

Code: Select all

#include 
#include 
#include 

#include 

DWORD AddAceToObjectsSecurityDescriptor(
LPTSTR pszObjName,          // name of object
SE_OBJECT_TYPE ObjectType,  // type of object
LPTSTR pszTrustee,          // trustee for new ACE
TRUSTEE_FORM TrusteeForm,   // format of trustee structure
DWORD dwAccessRights,       // access mask for new ACE
ACCESS_MODE AccessMode,     // type of ACE
DWORD dwInheritance         // inheritance flags for new ACE
)
{
DWORD dwRes = 0;
PACL pOldDACL = NULL, pNewDACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;
EXPLICIT_ACCESS ea;

if (NULL == pszObjName)
return ERROR_INVALID_PARAMETER;

// Get a pointer to the existing DACL.

dwRes = GetNamedSecurityInfo(pszObjName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL, &pOldDACL, NULL, &pSD);
if (ERROR_SUCCESS != dwRes) {
printf("GetNamedSecurityInfo Error %u\n", dwRes);
goto Cleanup;
}

// Initialize an EXPLICIT_ACCESS structure for the new ACE.

ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
ea.grfAccessPermissions = dwAccessRights;
ea.grfAccessMode = AccessMode;
ea.grfInheritance = dwInheritance;
ea.Trustee.TrusteeForm = TrusteeForm;
ea.Trustee.ptstrName = pszTrustee;

// Create a new ACL that merges the new ACE
// into the existing DACL.

dwRes = SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL);
if (ERROR_SUCCESS != dwRes) {
printf("SetEntriesInAcl Error %u\n", dwRes);
goto Cleanup;
}

// Attach the new ACL as the object's DACL.

dwRes = SetNamedSecurityInfo(pszObjName, ObjectType,
DACL_SECURITY_INFORMATION,
NULL, NULL, pNewDACL, NULL);
if (ERROR_SUCCESS != dwRes) {
printf("SetNamedSecurityInfo Error %u\n", dwRes);
goto Cleanup;
}

Cleanup:

if (pSD != NULL)
LocalFree((HLOCAL)pSD);
if (pNewDACL != NULL)
LocalFree((HLOCAL)pNewDACL);

return dwRes;
}

#include 

int main()
{
wchar_t objectName[] = L"C:\\Users\\Username\\Desktop\\acl.txt";

wchar_t trusteeSID[] = L"S-1-5-21-#-#-#-#";
PSID pSid;
if (!ConvertStringSidToSid(trusteeSID, &pSid)) {
std::cout

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post