-
July 3rd, 2007, 05:51 AM
#1
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,
-
July 3rd, 2007, 06:24 AM
#2
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.
Boris Karadjov
Brainbench MVP for Visual C++
http://www.brainbench.com/
-
July 3rd, 2007, 06:43 AM
#3
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,
-
July 3rd, 2007, 07:10 AM
#4
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
-
July 4th, 2007, 07:29 AM
#5
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.
Boris Karadjov
Brainbench MVP for Visual C++
http://www.brainbench.com/
-
July 4th, 2007, 11:46 PM
#6
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
-
May 1st, 2013, 05:15 AM
#7
Re: How to find Directory Permissions??
Originally Posted by sachinchakote
use the pDacl to get the access rights you want..
How? I can't find any documentation on this anywhere.
-
May 1st, 2013, 06:10 AM
#8
Re: How to find Directory Permissions??
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|