當前位置: 首頁>>代碼示例>>C#>>正文


C# FileSecurity.RemoveAccessRule方法代碼示例

本文整理匯總了C#中System.Security.AccessControl.FileSecurity.RemoveAccessRule方法的典型用法代碼示例。如果您正苦於以下問題:C# FileSecurity.RemoveAccessRule方法的具體用法?C# FileSecurity.RemoveAccessRule怎麽用?C# FileSecurity.RemoveAccessRule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.AccessControl.FileSecurity的用法示例。


在下文中一共展示了FileSecurity.RemoveAccessRule方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExecuteOnFile

 protected override void ExecuteOnFile(FileInfo file)
 {
     FileSecurity fileSec = new FileSecurity(file.FullName, AccessControlSections.Access);
     IList<FileSystemAccessRule> targetRules = FindAccessRules(fileSec);
     if (targetRules.Count == 0)
     {
         Log(Level.Info, Resources.RemoveAccessRuleEmpty, NTAccount, file.FullName);
     }
     else
     {
         foreach (FileSystemAccessRule fileSystemAccessRule in targetRules)
         {
             Log(Level.Info, Resources.RemoveAccessRuleRemoving, NTAccount, file.FullName);
             fileSec.RemoveAccessRule(fileSystemAccessRule);
         }
         file.SetAccessControl(fileSec);
     }
 }
開發者ID:jcde,項目名稱:NAntWithContrib,代碼行數:18,代碼來源:RemoveAccessRuleTask.cs

示例2: RemoveAllExplicitAccessRules

        /// <summary>
        /// Removes all explicit access rules from the supplied file.
        /// </summary>
        /// <param name="path">The path to the file to have access removed on.</param>
        /// <param name="security">The FileSecurity object of the file once changed.</param>
        /// <param name="commitChanges">Indicates whether changes should be commited to this file. Useful when combining multiple commands.</param>
        /// <returns>True if access was removed. False otherwise.</returns>
        public static bool RemoveAllExplicitAccessRules(string path, out FileSecurity security, bool commitChanges)
        {
            // Check that a path was supplied.
            if (!string.IsNullOrEmpty(path))
            {
                // The path was supplied.

                // Check whether the file exists.
                if (SystemFile.Exists(path))
                {
                    // The file exists.

                    // Remove existing explicit permissions.
                    security = GetSecurityObject(path);
                    if (security != null)
                    {
                        AuthorizationRuleCollection rules = security.GetAccessRules(true, false, typeof(System.Security.Principal.SecurityIdentifier));
                        foreach (AuthorizationRule rule in rules)
                        {
                            security.RemoveAccessRule((FileSystemAccessRule)rule);
                        }
                        // Commit the changes if necessary.
                        if (commitChanges)
                        {
                            try
                            {
                                SystemFile.SetAccessControl(path, security);
                            }
                            catch (IOException)
                            {
                                // An I/O error occurred while opening the file.
                                return false;
                            }
                            catch (UnauthorizedAccessException)
                            {
                                // The path parameter specified a file that is read-only.
                                // The operation is not supported on the current platform.
                                // Or the current process does not have the required permission.
                                return false;
                            }
                        }
                        return true;
                    }
                    else
                    {
                        // Unable to get the file's security object.
                        return false;
                    }
                }
                else
                {
                    // The file does not exist.
                    security = null;
                    return false;
                }
            }
            else
            {
                // A path was not supplied.
                security = null;
                return false;
            }
        }
開發者ID:TheHunter,項目名稱:Galactic,代碼行數:70,代碼來源:File.cs

示例3: ProjectCanNotBeOpened

        public void ProjectCanNotBeOpened()
        {
            string projectFile = null;

            IdentityReference identity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            FileSystemAccessRule rule = new FileSystemAccessRule(identity, FileSystemRights.Read, AccessControlType.Deny);

            FileSecurity security = null;

            try
            {
                // Does not have .sln or .vcproj extension so loads as project
                projectFile = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();

                security = new FileSecurity(projectFile, System.Security.AccessControl.AccessControlSections.All);
                security.AddAccessRule(rule);

                File.SetAccessControl(projectFile, security);

                ProjectRootElement p = ProjectRootElement.Open(projectFile);
            }
            catch (PrivilegeNotHeldException)
            {
                throw new InvalidProjectFileException("Running unelevated so skipping the scenario.");
            }
            finally
            {
                if (security != null)
                {
                    security.RemoveAccessRule(rule);
                }

                File.Delete(projectFile);
                Assert.AreEqual(false, File.Exists(projectFile));
            }
        }
開發者ID:ravpacheco,項目名稱:msbuild,代碼行數:36,代碼來源:ProjectRootElement_Tests.cs

示例4: SolutionCanNotBeOpened

        public void SolutionCanNotBeOpened()
        {
            string solutionFile = null;
            string tempFileSentinel = null;

            IdentityReference identity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            FileSystemAccessRule rule = new FileSystemAccessRule(identity, FileSystemRights.Read, AccessControlType.Deny);

            FileSecurity security = null;

            try
            {
                tempFileSentinel = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
                solutionFile = Path.ChangeExtension(tempFileSentinel, ".sln");
                File.Copy(tempFileSentinel, solutionFile);

                security = new FileSecurity(solutionFile, System.Security.AccessControl.AccessControlSections.All);

                security.AddAccessRule(rule);

                File.SetAccessControl(solutionFile, security);

                ProjectRootElement p = ProjectRootElement.Open(solutionFile);
            }
            catch (PrivilegeNotHeldException)
            {
                throw new InvalidProjectFileException("Running unelevated so skipping this scenario.");
            }
            finally
            {
                if (security != null)
                {
                    security.RemoveAccessRule(rule);
                }

                File.Delete(solutionFile);
                File.Delete(tempFileSentinel);
                Assert.AreEqual(false, File.Exists(solutionFile));
            }
        }
開發者ID:ravpacheco,項目名稱:msbuild,代碼行數:40,代碼來源:ProjectRootElement_Tests.cs

示例5: RevokeReadAccess

        /// <summary>
        /// Tpo revoke read access
        /// </summary>
        /// <param name="identity">Identity to revoke read access</param>
        public void RevokeReadAccess(string identity)
        {
            if (!Exists())
            {
                throw new KeyDoesNotExistsException(ContainerName);
            }

            // Get the unique filename associated and
            string path = UniqueKeyContainerFileName;

            FileSecurity fileSecurity = new FileSecurity(path, AccessControlSections.Access);
            fileSecurity.RemoveAccessRule(new FileSystemAccessRule(identity, FileSystemRights.ReadPermissions, AccessControlType.Allow));

            File.SetAccessControl(path, fileSecurity);
        }
開發者ID:VKeCRM,項目名稱:V2,代碼行數:19,代碼來源:KeyContainer.cs


注:本文中的System.Security.AccessControl.FileSecurity.RemoveAccessRule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。