Question

I have been set a task to allow a user to enter a UNC path (i.e. \\bla.org.dom\temp\test\lowest) and from the lowest folder to the highest, construct a list of groups and users that have read/write permissions on each folder. I have spent quite some time looking at activedirectory services and have turned up nothing but dead ends. Whilst I have quite a grasp of c# the activedirectory and ldap seems to go over my head. Any suggestions of material to read over will be welcomed.

As this is my first post, any criticism on my question format is welcome!

EDIT: Given further research using Directory Security method's, and AccessRules, I have gotten to the stage that I can recursively call a list of the account names. This is close to what I need but I'm finding it harder to implement it to call on a unc path.

Was it helpful?

Solution

The answer itself lied within the DirectoryInfo and DirectorySecurity namespaces. Using the information provided earlier from checking-for-directory-and-file-write-permissions-in-net I managed to create a recursively calling method that generates a list of the users/groups who have read/write on the folders, starting at the top and working down to the lowest directory.

string dir = "";
        if (input.Text.Contains(@"\\"))
        {
            dir += @"\\";
        }
        string[] folders = input.Text.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);


        foreach (string folder in folders)
        {

            if (dir.Contains(@"\\") && folder == folders[0])
            {
                dir += folder + @"\";
            }
            else
            {
                dir += folder + @"\";
                ResultGroup newbox = new ResultGroup(folder);

                newbox.label1.Click += (x, y) =>
                {
                    splitContainer1.Panel2Collapsed = false;
                    listBox1.Items.Add(newbox.label1.Text);
                };
                flowLayoutPanel1.Controls.Add(newbox);


                DirectoryInfo di = new DirectoryInfo(dir);
                DirectorySecurity ds = di.GetAccessControl();
                foreach (AccessRule rule in ds.GetAccessRules(true, true, typeof(NTAccount)))
                {
                    newbox.listBox1.Items.Add(string.Format("{0}", rule.IdentityReference.Value));
                }
            }
        }

This allows the user to enter a local path, e.g. "C:\Temp\Test Folder" OR a UNC Path "\Server\Share\Temp\Network Test Folder", which will then get processed folder by folder, populating the form I am using to display the data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top