我们最近被迫迁移到世界各地的一个新的域服务器一半。这可能似乎不是很多的变化,但我们运行经常突然消失形成2第二命令以5分钟的命令处理中的一个。

原因?我们正在更新基于一个“模板”目录结构许多目录的权限。

我们已经发现,XCOPY可以在同旧两秒钟的窗口更新大多数这些设置。其余的设置,当然,得到离开。

什么我想是图了,怎么可以做的XCopy更快的安全等级应该做什么.NET本身?很显然,我失去了一些东西。

什么是复制目录的ACL信息,而无需执行ping命令(或最小爆震)域/ Active Directory服务器的最佳方法是什么?

下面是我有:

    ... 

    DirectorySecurity TemplateSecurity = new DirectorySecurity(TemplateDir, AccessControlSections.All);

    ... 


    public static void UpdateSecurity(string destination, DirectorySecurity TemplateSecurity)
    {
        DirectorySecurity dSecurity = Directory.GetAccessControl(destination);

        // Remove previous security settings. (We have all we need in the other TemplateSecurity setting!!)
        AuthorizationRuleCollection acl_old = dSecurity.GetAccessRules(true, true, typeof(NTAccount));
        foreach (FileSystemAccessRule ace in acl_old)
        {
            // REMOVE IT IF YOU CAN... if you can't don't worry about it.
            try
            {
                dSecurity.RemoveAccessRule(ace);
            }
            catch { }
        }

        // Remove the inheritance for the folders... 
        // Per the business unit, we must specify permissions per folder.
        dSecurity.SetAccessRuleProtection(true, true);

        // Copy the permissions from TemplateSecurity to Destination folder.
        AuthorizationRuleCollection acl = TemplateSecurity.GetAccessRules(true, true, typeof(NTAccount));

        foreach (FileSystemAccessRule ace in acl)
        {
            // Set the existing security.
            dSecurity.AddAccessRule(ace);

            try
            {
                // Remove folder inheritance...
                dSecurity.AddAccessRule(new FileSystemAccessRule(
                    ace.IdentityReference, ace.FileSystemRights,
                    InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                    PropagationFlags.None,
                    ace.AccessControlType));
            }
            catch { }
        }

        // Apply the new changes.
        Directory.SetAccessControl(destination, dSecurity);
    }

有帮助吗?

解决方案

好吧...我有挖掘互联网上一吨后一个工作原型。不用说,有很多的ACL的错误信息网上。我不能完全肯定,如果将这些信息位将是一个天赐良机,以上错误信息。我将不得不离开,对您的用户,来决定。

我最终得到的是干净,光滑,而且非常,非常快的,因为它不会永远碰域服务器。我直接复制SDDL条目。等等,你说......因为你得到了可怕的错误SeSecurityPrivilege权限,你不能这样做的一个目录!

若您限制为仅访问控制列表拷贝(ACL)。

下面的代码:

    public static void UpdateSecurity(string destination, DirectorySecurity templateSecurity)
    {
        DirectorySecurity dSecurity = Directory.GetAccessControl(destination);

        string sddl = templateSecurity.GetSecurityDescriptorSddlForm(AccessControlSections.Access);
        try
        {
            // TOTALLY REPLACE The existing access rights with the new ones.
            dSecurity.SetSecurityDescriptorSddlForm(sddl, AccessControlSections.Access);

            // Disable inheritance for this directory.
            dSecurity.SetAccessRuleProtection(true, true);


            // Apply these changes.
            Directory.SetAccessControl(destination, dSecurity);
        }
        catch (Exception ex)
        {
            // Note the error on the console... we can formally log it later.
            Console.WriteLine(pth1 + " : " + ex.Message);
        }


        // Do some other settings stuff here...

    }

请注意在SDDL方法AccessControlSections.Access标志。这是魔术的关键,使这一切工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top