473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Determining which groups are assigned to a folder

Need any help in determining which groups have been given security
access to a folder. Searched DirectoryServices to no avail...

Any Help?
Nov 16 '05 #1
2 3601
I believe it will be all PInvoke work. There is a wrapper library on
GotDotNet that might make it easier:
http://www.gotdotnet.com/Community/U...f-e0705af065d9

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 30 Nov 2004 13:53:35 -0800, ag*******@hotmail.com (Garrett) wrote:
Need any help in determining which groups have been given security
access to a folder. Searched DirectoryServices to no avail...

Any Help?


Nov 16 '05 #2
1. Using System.DirectoryServices.
When running on W2K3 or XP, you can use the ADsSecurityUtilityClass now part
of activeds.dll, but you have to create a IA from the activeds.tlb.

using System;
using System.DirectoryServices;
using System.Collections;
using System.Runtime.InteropServices;
using activedsnet; // Interop Assembly created with tlbimp.exe from
activeds.tlb
// use activeds.dll to manage NTFS DACLs
class Tester {
public static void Main() {
// Local file system object (dir or file)
string fileSpec = @"c:\somefolderorfile";
// or remote File system object using a UNC name,
// the current logon user need network access and resource access
privileges
// to the administrative shares (C$, D$ etc...) holding the NTFS resource.

SecurityDescriptor sd = null;
AccessControlList dacl = null;
// Use ADsSecurityUtilityClass available on XP and higher (activeds.dll)
ADsSecurityUtilityClass asu = new ADsSecurityUtilityClass();
// Get DACL and OWNER info
asu.SecurityMask = (int)(ADS_SECURITY_INFO_ENUM.ADS_SECURITY_INFO_OWN ER
| ADS_SECURITY_INFO_ENUM.ADS_SECURITY_INFO_DACL);
try {
sd = asu.GetSecurityDescriptor(fileSpec,
(int)ADS_PATHTYPE_ENUM.ADS_PATH_FILE,
(int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID) as SecurityDescriptor;
}
catch(COMException ce)
{
// Be sure logon user has access to local/remote system
Console.WriteLine(ce.Message);
return;
}
dacl = sd.DiscretionaryAcl as AccessControlList;
if (dacl != null) {
Console.WriteLine("Control: {0}", sd.Control);
Console.WriteLine("Owner: {0}", sd.Owner);
Console.WriteLine("Group: {0}", sd.Group);
Console.WriteLine("Revision: {0}", sd.Revision);
DumpDacl(dacl);
}
}
static void DumpDacl(IADsAccessControlList dacl)
{
IADsAccessControlEntry ace = null;
Console.WriteLine("------- No. of ACE's {0}-----------", dacl.AceCount);
foreach(object ac in dacl) {
ace = ac as IADsAccessControlEntry;
Console.WriteLine(ace.AccessMask);
Console.WriteLine(ace.Trustee);
Console.WriteLine(ace.AceFlags);
}
}
}

2. And a more elaborated sample using System.Management:

using System;
using System.Management;
using System.Collections;
using System.Collections.Specialized;
// Access mask (see AccessMask property)
[Flags]
enum Mask : uint
{
FileReadData = 0x00000001,
FileWriteData = 0x00000002,
FileAppendData = 0x00000004,
FileReadEA = 0x00000008,
FileWriteEA = 0x00000010,
FileExecute = 0x00000020,
FileDeleteChild = 0x00000040,
FileReadAttributes = 0x00000080,
FileWriteAttributes= 0x00000100,

Delete = 0x00010000,
ReadControl = 0x00020000,
WriteDac = 0x00040000,
WriteOwner = 0x00080000,
Synchronize = 0x00100000,

AccessSystemSecurity = 0x01000000,
MaximumAllowed = 0x02000000,

GenericAll = 0x10000000,
GenericExecute= 0x20000000,
GenericWrite = 0x40000000,
GenericRead = 0x80000000
}
[Flags]
enum AceFlags : int
{
ObjectInheritAce = 1,
ContainerInheritAce = 2,
NoPropagateInheritAce = 4,
InheritOnlyAce = 8,
InheritedAce = 16
}

[Flags]
enum AceType : int
{
AccessAllowed = 0,
AccessDenied = 1,
Audit = 2
}
class Tester {
public static void Main() {
string fileObject = @"c:\\temp"; // Watch the double Backslashes

using(ManagementObject lfs = new
ManagementObject(@"Win32_LogicalFileSecuritySettin g.Path=" + "'" +
fileObject + "'"))
{
ManagementBaseObject outParams = null;
// Get the security descriptor for this object
// Dump all trustees (this includes owner)
outParams = lfs.InvokeMethod("GetSecurityDescriptor", null, null);
if (((uint)(outParams.Properties["ReturnValue"].Value)) == 0) // if
success
{
ManagementBaseObject secDescriptor =
((ManagementBaseObject)(outParams.Properties["Descriptor"].Value));
//The DACL is an array of Win32_ACE objects.
ManagementBaseObject[] dacl =
((ManagementBaseObject[])(secDescriptor.Properties["Dacl"].Value));
DumpACEs(dacl);
}
}
}

static void DumpACEs(ManagementBaseObject[] dacl)
{
NameValueCollection sidName = new NameValueCollection();

foreach(ManagementBaseObject mbo in dacl){
Console.WriteLine("\n---------\nMask: {0:X} - Flags: {1} - Type: {2}",
mbo["AccessMask"], mbo["AceFlags"], mbo["AceType"]);
// Access allowed/denied ACE
if(Convert.ToInt32(mbo["AceType"]) == (int)AceType.AccessDenied)
Console.WriteLine("DENIED ACE TYPE");
else
Console.WriteLine("ALLOWED ACE TYPE");
// Dump trustees
ManagementBaseObject Trustee = ((ManagementBaseObject)(mbo["Trustee"]));
if (Trustee != null)
{
// problem with null names and duplicates
sidName.Add(Trustee.Properties["SIDString"].Value.ToString(),
Trustee.Properties["Name"].Value==null?"null":Trustee.Properties["Name"].Value.ToString());
Console.WriteLine("Name: {0} - Domain: {1} - SID {2}\n",
Trustee.Properties["Name"].Value,
Trustee.Properties["Domain"].Value,
Trustee.Properties["SIDString"].Value);
}
// Dump ACE mask in readable form
UInt32 mask = (UInt32)mbo["AccessMask"];
Console.WriteLine(Enum.Format(typeof(Mask), mask, "g"));
}
}
}

Willy.

"Garrett" <ag*******@hotmail.com> wrote in message
news:3a**************************@posting.google.c om...
Need any help in determining which groups have been given security
access to a folder. Searched DirectoryServices to no avail...

Any Help?

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Broadbent | last post by:
Could someone who has active experience of assigning Security Policys please clarify my follow comments... Having gone through the MSDN documentation on this subject, my condensed version of the...
0
by: Garrett | last post by:
Hi all, I am looking for a sample of System.DirectoryServices code that will allow me to do three things: 1. Iterate over all shared folders on a drive (no issue here) 2. Find the groups...
1
by: timm.wong | last post by:
Hi, How would I go about determining if a current user has write access to a folder that is on a network Any feedback would be greatly appreciated Tim
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
0
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
1
by: Garrett | last post by:
Hi all, I am looking for a sample of System.DirectoryServices code that will allow me to do three things: 1. Iterate over all shared folders on a drive 2. Find the groups that are assigned to...
0
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
1
by: j.eckles | last post by:
I'm trying to determine if there is a way in VBScript, perhaps via ADO or DAO, to access what I'll term MS Access "object groups". What I mean by "object groups" are the folders that you see under...
3
by: Gordon | last post by:
I am currently working on some code for my CMS that creates a site folder, then creates all the necessary child folders inside it. The method that creates folders needs to insert into 2 tables so...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.