示例#1
0
        public void TestGetAuthorizationRules()
        {
            string  filename = "C:\\Users\\nicol\\Documents\\Graduate Classes\\SSE 554\\Project 1\\Project1.docx";
            ACLView frm      = new ACLView(filename);
            AuthorizationRuleCollection rules = frm.getAuthorizationRules(filename);

            Assert.IsTrue(rules.Count > 0);
        }
示例#2
0
        public void TestGetInheritedRulesString()
        {
            string  filename            = "C:\\Users\\nicol\\Documents\\Graduate Classes\\SSE 554\\Project 1\\Project1.docx";
            ACLView frm                 = new ACLView(filename);
            FileSystemAccessRule rule   = new FileSystemAccessRule("ident", FileSystemRights.FullControl, AccessControlType.Allow);
            string inheritedRulesString = frm.getInheritedRulesString(rule);

            Assert.IsTrue(inheritedRulesString != null && inheritedRulesString.Length > 0);
        }
示例#3
0
        private void saveAndExitButton_Click(object sender, EventArgs e)
        {
            AccessControlType ACT;

            switch (accessControlList.SelectedItem.ToString())
            {
            case "Allow":
                ACT = AccessControlType.Allow;
                break;

            case "Deny":
                ACT = AccessControlType.Deny;
                break;

            default:
                ACT = rule.AccessControlType;
                break;
            }

            FileSystemRights FSR;

            switch (fileSystemRightsList.SelectedItem.ToString())
            {
            case "Full Control":
                FSR = FileSystemRights.FullControl;
                break;

            case "Modify":
                FSR = FileSystemRights.Modify;
                break;

            case "Read and Execute":
                FSR = FileSystemRights.ReadAndExecute;
                break;

            case "Write":
                FSR = FileSystemRights.Write;
                break;

            case "Execute":
                FSR = FileSystemRights.ExecuteFile;
                break;

            case "Read":
                FSR = FileSystemRights.Read;
                break;

            case "Delete":
                FSR = FileSystemRights.Delete;
                break;

            default:
                FSR = rule.FileSystemRights;
                break;
            }

            FileSystemAccessRule FSAR = new FileSystemAccessRule(rule.IdentityReference.Value, FSR, ACT);
            bool modified;

            using (FileStream stream = File.Open(filename, FileMode.Open))
            {
                FileSecurity securityDescriptor   = stream.GetAccessControl();
                AuthorizationRuleCollection rules = securityDescriptor.GetAccessRules(true, true, typeof(NTAccount));
                securityDescriptor.ModifyAccessRule(AccessControlModification.Reset, FSAR, out modified);
                File.SetAccessControl(filename, securityDescriptor);
            }

            ACLView frm = new ACLView(filename);

            frm.Show();
            this.Hide();
        }