1

私たちは最近、世界中の途中で新しいドメインサーバーに移動することを余儀なくされました。これはそれほど大きな変化ではないように思われるかもしれませんが、頻繁に実行するプロセスの1つが、突然2秒のコマンドから5分のコマンドになりました。

理由?「テンプレート」ディレクトリ構造に基づいて、多くのディレクトリのアクセス許可を更新しています。

XCOPYは、同じ古い2秒のウィンドウでこれらの設定の大部分を更新できることを発見しました。もちろん、残りの設定は省略されます。

私が理解しようとしているのは、XCopyが.NETセキュリティクラスがネイティブに実行する必要があることをどのように高速化できるかということです。明らかに私は何かが欠けています。

ドメイン/ActiveDirectoryサーバーにping(または最小限のping)を実行せずにディレクトリのACL情報をコピーするための最良の方法は何ですか?

これが私が持っているものです:

    ... 

    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);
    }

4

1 に答える 1

2

わかりました...インターネットでATONOF DIGGINGを実行した後、プロトタイプが動作しています。言うまでもなく、オンラインの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...

    }

AccessControlSections.AccessSDDLメソッドのフラグに注意してください。それがすべてを機能させるための魔法の鍵でした。

于 2009-09-22T19:19:12.407 に答える