Esempio n. 1
0
        private void WeedKillerEventProcessor(object sender, WeedKillerEventArgs e)
        {
            switch (e.Action)
            {
            case WeedKillerEventArgs.WeedKillerActionType.BeginServer:
                AppendToScrollingTextbox(ref this.txtResults, string.Format("\r\nServer: \\{0} ...", e.Message));
                break;

            case WeedKillerEventArgs.WeedKillerActionType.EndServer:
                ServerName = string.Empty;
                break;

            case WeedKillerEventArgs.WeedKillerActionType.ResolvedRootDirectory:
                AppendToScrollingTextbox(ref this.txtResults, string.Format("\r\n{0} ACL: {1}",
                                                                            this.rbAddAccess.Checked ? "Add to" : "Remove from",
                                                                            e.Path));
                string result = "OK";
                try
                {
                    if (this.rbAddAccess.Checked)
                    {
                        g.AddDirectorySecurity(e.Path, this.txtNTAccount.Text,
                                               System.Security.AccessControl.FileSystemRights.ListDirectory |
                                               System.Security.AccessControl.FileSystemRights.Traverse |
                                               System.Security.AccessControl.FileSystemRights.Delete |
                                               System.Security.AccessControl.FileSystemRights.DeleteSubdirectoriesAndFiles,
                                               System.Security.AccessControl.InheritanceFlags.ContainerInherit |
                                               System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                                               System.Security.AccessControl.PropagationFlags.None,
                                               System.Security.AccessControl.AccessControlType.Allow);
                    }
                    else
                    {
                        g.RemoveDirectorySecurity(e.Path, this.txtNTAccount.Text,
                                                  System.Security.AccessControl.FileSystemRights.ListDirectory |
                                                  System.Security.AccessControl.FileSystemRights.Traverse |
                                                  System.Security.AccessControl.FileSystemRights.Delete |
                                                  System.Security.AccessControl.FileSystemRights.DeleteSubdirectoriesAndFiles,
                                                  System.Security.AccessControl.InheritanceFlags.ContainerInherit |
                                                  System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                                                  System.Security.AccessControl.PropagationFlags.None,
                                                  System.Security.AccessControl.AccessControlType.Allow);
                    }
                }
                catch (Exception err)
                {
                    result = string.Format("ERR: {0}", err.Message);
                }
                AppendToScrollingTextbox(ref this.txtResults, "\r\n" + result);

                break;

            default:
                // not one we deal with.
                break;
            }
        }
Esempio n. 2
0
        static void AdjustNtPermissions(string rootFolder, string NTcredential, bool Add)
        {
            NTGroup g1 = new NTGroup();

            if (Add)
            {
                Console.Write("Adding permission for credential .. ");
                try
                {
                    g1.AddDirectorySecurity(rootFolder, NTcredential,
                                            System.Security.AccessControl.FileSystemRights.ListDirectory |
                                            System.Security.AccessControl.FileSystemRights.Traverse |
                                            System.Security.AccessControl.FileSystemRights.Delete |
                                            System.Security.AccessControl.FileSystemRights.DeleteSubdirectoriesAndFiles,
                                            System.Security.AccessControl.InheritanceFlags.ContainerInherit |
                                            System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                                            System.Security.AccessControl.PropagationFlags.None,
                                            System.Security.AccessControl.AccessControlType.Allow);
                    Console.WriteLine("done");
                }
                catch (Exception errAdd)
                {
                    Console.WriteLine("err: {0}", errAdd.Message);
                }
            }
            else
            {
                Console.Write("Removing permission for credential .. ");
                try
                {
                    g1.RemoveDirectorySecurity(rootFolder, NTcredential,
                                               System.Security.AccessControl.FileSystemRights.ListDirectory |
                                               System.Security.AccessControl.FileSystemRights.Traverse |
                                               System.Security.AccessControl.FileSystemRights.Delete |
                                               System.Security.AccessControl.FileSystemRights.DeleteSubdirectoriesAndFiles,
                                               System.Security.AccessControl.InheritanceFlags.ContainerInherit |
                                               System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                                               System.Security.AccessControl.PropagationFlags.None,
                                               System.Security.AccessControl.AccessControlType.Allow);
                    Console.WriteLine("done");
                }
                catch (Exception errRemove)
                {
                    Console.WriteLine("err: {0}", errRemove.Message);
                }
            }
        }