How to find Directory Permissions??
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: How to find Directory Permissions??

  1. #1
    Join Date
    Jul 2007
    Posts
    3

    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,

  2. #2
    Join Date
    Aug 2004
    Posts
    294

    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/

  3. #3
    Join Date
    Jul 2007
    Posts
    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,

  4. #4
    Join Date
    Jul 2007
    Posts
    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,

    Pls do reply

  5. #5
    Join Date
    Aug 2004
    Posts
    294

    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/

  6. #6
    Join Date
    Jun 2007
    Posts
    21

    Arrow 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

  7. #7
    Join Date
    May 2013
    Posts
    1

    Re: How to find Directory Permissions??

    Quote Originally Posted by sachinchakote View Post

    use the pDacl to get the access rights you want..
    How? I can't find any documentation on this anywhere.

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,862

    Re: How to find Directory Permissions??

    Quote Originally Posted by bemoore View Post
    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center