Help: Invalid conversion error, MINGW

Hi,

What is changed about thistiny func? This used to work earlier MINGW but now it hits an error. (MINGW version 10.x.x). The idea of the func is give access to dir.

Source function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <windows.h>
#include <aclapi.h>

extern "C" bool GiveDirectoryUserFullAccess(LPCTSTR lpPath)
{	
	HANDLE hDir = CreateFile(lpPath,READ_CONTROL|WRITE_DAC,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
	if(hDir == INVALID_HANDLE_VALUE) return false;
	
	ACL* pOldDACL=NULL;
	SECURITY_DESCRIPTOR* pSD = NULL;
	GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,&pSD);
	
	EXPLICIT_ACCESS ea={0};
	ea.grfAccessMode = GRANT_ACCESS;
	ea.grfAccessPermissions = GENERIC_ALL;
	ea.grfInheritance = CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;
	ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
	ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
	ea.Trustee.ptstrName = TEXT("Users");
	
	ACL* pNewDACL = NULL;
	SetEntriesInAcl(1,&ea,pOldDACL,&pNewDACL);
	
	SetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);
	
	LocalFree(pSD);
	LocalFree(pNewDACL);
	CloseHandle(hDir);
	return true;
}


Error:

error: invalid conversion from 'SECURITY_DESCRIPTOR**' to 'void**' [-fpermissive] 11|GetsecurityInfo(hDir, SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&OldDACL,NULL,&pSD);

Calling convention from BM (BlizMax language):

Extern
Function GiveDirectoryUserFullAccess:Int(lpPath)
EndExtern



Last edited on
The problem is that the last param of GetSecurityInfo() is of type PSECURITY_DESCRIPTOR*. Ok so far.

You might have assumed that PSECURITY_DESCRIPTOR is defined as something like:

 
typedef SECURITY_DESCRIPTOR *PSECURITY_DESCRIPTOR;


But it's not! PSECURITY_DESCRIPTOR is actually defined as:

 
typedef PVOID *PSECURITY_DESCRIPTION;


With PVOID defined as :

 
typedef void *PVOID;


So when a type of PSECURITY_DESCRIPTOR* is required, it actually wants a type of void**.

So try:

 
GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,(PVOID *)&pSD);


PS. I also get an error on L19. Perhaps:

 
ea.Trustee.ptstrName = (TCHAR*)TEXT("Users");


This now compiles OK with VS2022.
Last edited on

Hi,

Thank you much. I try to compile it with MINGW. Let's see...
Last edited on
Topic archived. No new replies allowed.