Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check foder access.

Status
Not open for further replies.

WilliamGS

Programmer
Jan 21, 2004
54
PE
Hi all. I have to copy and move files, sometimes the destination folder could be protect (the user doesn't have access), is important to detect the folder access before copy/move. Some advice about this?

Thanks in advance,

William GS.
 
Use CFile::Open with CFile::modecreate, if fails you can't write.
 
I suppose you have NTFS partitions otherwise this does no make sense on FAT32 whaere you cannont set the folder and file access so acurate.

below is some code that helps you read the access rigts on a folder. this should work for every user because every user can see the access permision of a directory from Windows Explorer
Below is a sample I have used to read the acces permision for a directory. The second half of my program was setting access to the directory (but you cannot do that because the user will be an usual user not an administrator so you simply give him some Message box saying he cannot save there)


Code:
	BOOL bReturn=TRUE;
	//get directory handle
	HANDLE hFile = CreateFile(strDirName, 
				READ_CONTROL | WRITE_DAC,
				FILE_SHARE_READ | FILE_SHARE_WRITE,
				NULL,
				OPEN_EXISTING,
				FILE_FLAG_BACKUP_SEMANTICS,
				NULL);
	if (hFile == INVALID_HANDLE_VALUE)
		printf("Cound not open dir");

	//declaration
	DWORD dwRes;
	PACL pOldDACL = NULL, pNewDACL = NULL;
	PSECURITY_DESCRIPTOR pSD = NULL;
	EXPLICIT_ACCESS ea;
	ACL* pdaclNew = 0;

	// Allocate memory for the security descriptor structure.
	pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(
          GMEM_FIXED,
          sizeof(PSECURITY_DESCRIPTOR));
	pOldDACL = (ACL*)LocalAlloc(
          GMEM_FIXED,
          sizeof(ACL));

	// get object security information
	dwRes = GetSecurityInfo(hFile, SE_FILE_OBJECT, 
		DACL_SECURITY_INFORMATION,
		NULL, NULL, &pOldDACL, NULL, &pSD);
	if (ERROR_SUCCESS != dwRes) {
	    printf( "GetSecurityInfo Error %u\n", dwRes );
		bReturn = FALSE;
		goto Cleanup;
	}

hth,

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top