Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / March 2004

Tip: Looking for answers? Try searching our database.

Getting Folder Permissions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hari Shankar - 22 Mar 2004 14:03 GMT
Hello folks

I have to get the NTFS permissions of a folder programmatically. I am using
C#. Pls hint me if i am missing anything in the code below.

private void GetSecurityPermission(string strShareName)

{

   NERR eRetVal = NERR.ERROR_FAILURE;

   EXPLICIT_ACCESS oEA;

   IntPtr pZero = IntPtr.Zero; IntPtr pSidOwner = pZero; IntPtr pSidGroup =
pZero; IntPtr pSACL = pZero; IntPtr pDACL = pZero;IntPtr psd = pZero;

   int nExplicitEntriesCount = 0;bool bDaclPresent;IntPtr ppDacl;bool
bDaclDefaulted;

   ///Get the DACL information of strShareName using GetNamedSecurityInfo()
API.

   /// SE_FILE_OBJECT constant says that the named securable object is a
file or folder

   eRetVal = CDecls.GetNamedSecurityInfo(strShareName,
SE_OBJECT_TYPE.SE_FILE_OBJECT,
SECURITY_INFORMATION.DACL_SECURITY_INFORMATION,   out pSidOwner,
out pSidGroup, out pDACL, out pSACL, out psd);

   if (eRetVal == NERR.ERROR_SUCCESS)

   {

       eRetVal = CDecls.GetExplicitEntriesFromAcl(pDACL, ref
nExplicitEntriesCount, out oEA);

       if(eRetVal == NERR.ERROR_SUCCESS)

       {

           for (int nIndex = 0; nIndex < nExplicitEntriesCount; nIndex++)

           {

           }

       }

   }

}

Thanx a ton.

Ciao

Hari
Willy Denoyette [MVP] - 22 Mar 2004 20:47 GMT
Could you also describe what problems you have with it.

Willy.

> Hello folks
>
[quoted text clipped - 57 lines]
>
> Hari
Hari Shankar - 23 Mar 2004 06:29 GMT
Actually i am trying to get the security permissions of a share. I am
getting the return value as SUCCESS. But i am not getting the correct data
in oEA structure.

Hari
Willy Denoyette [MVP] - 23 Mar 2004 11:12 GMT
> Actually i am trying to get the security permissions of a share. I am
> getting the return value as SUCCESS. But i am not getting the correct data
> in oEA structure.
>
> Hari

It's very hard to see from the code snip you posted as you don't process the
oEA structure in your code, so I guess you run this from the debugger, but
you can start by correcting this...

SE_OBJECT_TYPE.SE_FILE_OBJECT,
Should be:
SE_OBJECT_TYPE.SE_LMSHARE

I would also suggest you use the System.DirectoryServices (and ADSI interop)
or System.Management (and WMI) to check ACL's on File or Share objects.
Another option is to use Managed C++, C# is not the right language for this
kind of job.

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.