Click to See Complete Forum and Search --> : How to find Directory Permissions??


inform.srk
July 3rd, 2007, 06:51 AM
Hi,

Can anybody tell me any API or sample code snippet to find out the Directory access permissions, to find out whether or not a directory have write protection.

I found "GetNamedSecurityInfo" API, but don't know how to use it.

I want this in both Window and linux.

Any help will be appreciated.

Thanks,

Boris K K
July 3rd, 2007, 07:24 AM
Windows - GetFileSecurity (http://msdn2.microsoft.com/En-US/library/aa446639.aspx)

Linux - stat, lstat, fstat

The Windows security is different and more complex than the basic *nix security.

inform.srk
July 3rd, 2007, 07:43 AM
Thanks for your prompt reply,

Can you please tell me how to find this on linux via code,

Is there any common API(for Windows and Linux) for this?

Do you have any sample code for "GetFileSecurity"?

Thanks,

inform.srk
July 3rd, 2007, 08:10 AM
Thanks for your prompt reply,

Can you please tell me how to find this on linux via code,

Is there any common API(for Windows and Linux) for this?

Do you have any sample code for "GetFileSecurity"?

Thanks,

Pls do reply

Boris K K
July 4th, 2007, 08:29 AM
I don't think there is any common API between Windows and Linux, except part of socket library.

A lot of sample code can be found on by googling, as long as you know what you want to do.

sachinchakote
July 5th, 2007, 12:46 AM
PSID ppsidOwner;
PSID ppsidGroup;
PACL ppSacl= NULL;
PACL pOldDACL = NULL, pNewDACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;


char read[]="D:\\temp\\read";

DWORD dwRes = GetNamedSecurityInfo(read, SE_FILE_OBJECT,DACL_SECURITY_INFORMATION, &ppsidOwner, &ppsidGroup, &pOldDACL, &ppSacl, &pSD);

if (ERROR_SUCCESS != dwRes)
{
cout<<"GetNamedSecurityInfo Error \n"<<dwRes;
}


BOOL lpbDaclPresent;
PACL pDacl;
BOOL lpbDaclDefaulted;

if (! GetSecurityDescriptorDacl(pSD, &lpbDaclPresent, &pDacl, &lpbDaclDefaulted))
{
cout<<GetLastError();
}

if ( lpbDaclPresent == FALSE)
{
cout<<"\n No DACL Present";
}

if ( lpbDaclPresent && pDacl == NULL)
{
cout<<"\n A NULL DACL implicitly allows all access to an object";
}

if ( lpbDaclDefaulted == TRUE)
{
cout<<"\n the DACL was retrieved by a default mechanism";
}
else
{
cout<<"\n the DACL was explicitly specified by a user.";
}


use the pDacl to get the access rights you want..


sachin