当前位置: 首页>>代码示例>>C#>>正文


C# DirectorySecurity.SetOwner方法代码示例

本文整理汇总了C#中System.Security.AccessControl.DirectorySecurity.SetOwner方法的典型用法代码示例。如果您正苦于以下问题:C# DirectorySecurity.SetOwner方法的具体用法?C# DirectorySecurity.SetOwner怎么用?C# DirectorySecurity.SetOwner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.AccessControl.DirectorySecurity的用法示例。


在下文中一共展示了DirectorySecurity.SetOwner方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Locations

 static Locations()
 {
     if (WindowsUtils.IsWindowsNT)
     {
         _secureSharedAcl = new DirectorySecurity();
         _secureSharedAcl.SetOwner(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null));
         _secureSharedAcl.SetAccessRuleProtection(isProtected: true, preserveInheritance: false);
         _secureSharedAcl.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier("S-1-1-0" /*Everyone*/), FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
         _secureSharedAcl.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
         _secureSharedAcl.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
         _secureSharedAcl.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
     }
 }
开发者ID:nano-byte,项目名称:common,代码行数:13,代码来源:Locations.cs

示例2: CreateSecurityDescriptor

            private RawSecurityDescriptor CreateSecurityDescriptor(IEnumerable<IdentityRights> allowRights,
                IEnumerable<IdentityRights> denyRights = null)
            {
                var security = new DirectorySecurity();
                security.SetOwner(CurrentIdentity);
                security.SetGroup(Group);

                if (allowRights == null)
                    allowRights = Enumerable.Empty<IdentityRights>();

                if (denyRights == null)
                    denyRights = Enumerable.Empty<IdentityRights>();

                foreach (var right in allowRights)
                {
                    security.AddAccessRule(new FileSystemAccessRule(right.Identity, right.Rights,
                        AccessControlType.Allow));
                }

                foreach (var right in denyRights)
                {
                    security.AddAccessRule(new FileSystemAccessRule(right.Identity, right.Rights, AccessControlType.Deny));
                }

                var binaryDescriptor = security.GetSecurityDescriptorBinaryForm();
                return new RawSecurityDescriptor(binaryDescriptor, 0);
            }
开发者ID:stefanschneider,项目名称:IronFrame,代码行数:27,代码来源:EffectiveAccessComputerTests.cs

示例3: GetOwnershipTest

        public void GetOwnershipTest()
        {
            // Arrange
            var tmpDir = Path.Combine(Path.GetTempPath(), "dirtools-test-" + Guid.NewGuid().ToString());
            var localSystem = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

            var dirSec = new DirectorySecurity();
            dirSec.SetOwner(localSystem);

            Directory.CreateDirectory(tmpDir, dirSec);
            

            // Act
            var curIdentity = new NTAccount(Environment.UserDomainName, Environment.UserName);
            DirectoryTools.GetOwnershipForDirectory(tmpDir, curIdentity);

            // Assert
            var curDirsec = new DirectorySecurity(tmpDir, AccessControlSections.Owner);
            IdentityReference owner = curDirsec.GetOwner(typeof(NTAccount));
            Assert.IsTrue(curIdentity == owner);
        }
开发者ID:solakian,项目名称:windows-isolation,代码行数:21,代码来源:TestDirectoryTools.cs

示例4: CreateDirSecurity

        public static DirectorySecurity CreateDirSecurity(SecurityClass securityClass)
        {
            DirectorySecurity security = new DirectorySecurity();

            WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
            if (windowsIdentity != null)
            {
                SecurityIdentifier identity = windowsIdentity.User;
                if (identity != null)
                {
                    security.SetOwner(identity);
                    FileSystemAccessRule accessRule = new FileSystemAccessRule(identity,
                                                              FileSystemRights.FullControl,
                                                              InheritanceFlags.ObjectInherit |
                                                              InheritanceFlags.ContainerInherit,
                                                              PropagationFlags.None,
                                                              AccessControlType.Allow);
                    security.SetAccessRule(accessRule);
                }
            }

            if (securityClass == SecurityClass.Everybody)
            {
                SecurityIdentifier everybodyIdentity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

                FileSystemAccessRule accessRule = new FileSystemAccessRule(everybodyIdentity,
                                                          FileSystemRights.FullControl,
                                                          InheritanceFlags.ObjectInherit |
                                                          InheritanceFlags.ContainerInherit,
                                                          PropagationFlags.None,
                                                          AccessControlType.Allow);
                security.AddAccessRule(accessRule);
            }

            return security;
        }
开发者ID:jesszgc,项目名称:VideoConvert,代码行数:36,代码来源:DirSecurity.cs

示例5: RemoverArquivos

 private static void RemoverArquivos()
 {
     Console.Write("Removendo arquivos do Gbp... ");
     foreach (var dir in CaminhosGBP)
     {
         try
         {
             var dirInfo = new DirectoryInfo(Environment.ExpandEnvironmentVariables(dir));
             if (dirInfo.Exists)
             {
                 var ds = new DirectorySecurity();
                 ds.SetOwner(new NTAccount(WindowsIdentity.GetCurrent().Name));
                 dirInfo.SetAccessControl(ds);
                 dirInfo.Delete(true);
             }
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine(ex.Message);
         }
     }
     Console.WriteLine("OK.");
 }
开发者ID:junalmeida,项目名称:gbpkiller,代码行数:23,代码来源:Program.cs

示例6: SetDirectoryOwner

 private static void SetDirectoryOwner(DirectorySecurity deploymentDirSecurity, Prison prison)
 {
     deploymentDirSecurity.SetOwner(new NTAccount(prison.User.Username));
     deploymentDirSecurity.SetAccessRule(
         new FileSystemAccessRule(
             prison.User.Username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
             PropagationFlags.None, AccessControlType.Allow));
 }
开发者ID:solakian,项目名称:windows-isolation,代码行数:8,代码来源:Filesystem.cs

示例7: GetDirectorySecurity

 private static DirectorySecurity GetDirectorySecurity()
 {
     DirectorySecurity directorySecurity = new DirectorySecurity();
       directorySecurity.SetAccessRuleProtection(true, false);
       using (WindowsIdentity current = WindowsIdentity.GetCurrent())
       {
     directorySecurity.SetOwner((IdentityReference) current.User);
     for (int index = 0; index < TemporaryDataStorage.DirectoryAccessRules.Length; ++index)
       directorySecurity.AddAccessRule(TemporaryDataStorage.DirectoryAccessRules[index]);
     if (!current.User.IsWellKnown(WellKnownSidType.LocalSystemSid) && !current.User.IsWellKnown(WellKnownSidType.NetworkServiceSid) && !current.User.IsWellKnown(WellKnownSidType.LocalServiceSid))
       directorySecurity.AddAccessRule(new FileSystemAccessRule((IdentityReference) current.User, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
     return directorySecurity;
       }
 }
开发者ID:Rhombulus,项目名称:Mime,代码行数:14,代码来源:TemporaryDataStorage.cs

示例8: SetOwner

        /// <summary>
        /// Sets the owner of a directory.
        /// </summary>
        /// <param name="path">The path to the directory to have the ownership set on.</param>
        /// <param name="security">The DirectorySecurity object of the directory that will be changed.</param>
        /// <param name="owner">The directy entry that should take ownership of the entry.</param>
        /// <param name="commitChanges">Indicates whether changes should be commited to this entry. Useful when combining multiple commands.</param>
        /// <returns>True if the ownership could be set. False otherwise.</returns>
        public static bool SetOwner(string path, ref DirectorySecurity security, DirectoryEntry owner, bool commitChanges)
        {
            // Check whether a path, security object, and owner were supplied.
            if (!string.IsNullOrEmpty(path) && security != null && owner != null)
            {
                // A path, security object, and owner were supplied.
                // Check whether the directory exists.
                if (SystemDirectory.Exists(path))
                {
                    try
                    {
                        // Get the security identifier (SID) of the owner.
                        SecurityIdentifier sid = new SecurityIdentifier((byte[])owner.Properties["objectSid"].Value, 0);

                        // Set the owner of the directory to the SID of the owner entry.
                        security.SetOwner(sid);

                        // Commit the changes if necessary.
                        if (commitChanges)
                        {
                            try
                            {
                                SystemDirectory.SetAccessControl(path, security);
                            }
                            catch (UnauthorizedAccessException)
                            {
                                // The current process does not have access to the directory specified by path.
                                // Or the current process does not have sufficient privilege to set the ACL entry.
                                return false;
                            }
                            catch (PlatformNotSupportedException)
                            {
                                // The current operating system is not Windows 2000 or later.
                                return false;
                            }
                        }
                        return true;
                    }
                    catch
                    {
                        // There was an error changing the owner of the directory.
                        return false;
                    }
                }
                else
                {
                    // The directory does not exist.
                    return false;
                }
            }
            else
            {
                // A path, security object, and owner were not supplied.
                return false;
            }
        }
开发者ID:TheHunter,项目名称:Galactic,代码行数:64,代码来源:Directory.cs


注:本文中的System.Security.AccessControl.DirectorySecurity.SetOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。