How to find Directory Permissions??
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,
Re: How to find Directory Permissions??
Windows - GetFileSecurity
Linux - stat, lstat, fstat
The Windows security is different and more complex than the basic *nix security.
Re: How to find Directory Permissions??
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,
Re: How to find Directory Permissions??
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
Re: How to find Directory Permissions??
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.
Re: How to find Directory Permissions??
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
Re: How to find Directory Permissions??
Quote:
Originally Posted by
sachinchakote
use the pDacl to get the access rights you want..
How? I can't find any documentation on this anywhere.
Re: How to find Directory Permissions??
Quote:
Originally Posted by
bemoore
How? I can't find any documentation on this anywhere.
pDacl is a pointer to an access control list. These contain Access Control Entries (ACE). Use GetAce to get a pointer to an ACE. Use GetAclInformation to find the number of ACE's present. Look up ACE in Microsoft documentation for more details as to what it contains.