Groups | Blog | Home
all groups > dotnet sdk > march 2004 >

dotnet sdk : Getting Folder Permissions


Hari Shankar
3/22/2004 6:33:05 PM
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]
3/22/2004 8:47:35 PM
Could you also describe what problems you have with it.

Willy.

[quoted text, click to view]

Hari Shankar
3/23/2004 10:59:19 AM
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]
3/23/2004 11:12:56 AM

[quoted text, click to view]

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.

AddThis Social Bookmark Button