示例#1
0
        public void Run(LdapEntry lhs, LdapEntry rhs)
        {
            Log.Debug("Starting LdapEntryAnalyzer");

            if (lhs.CompareTo(rhs) != 0)
            {
                Log.Debug("Entry DNs don't match\nlhs: {0}\nrhs: {1}", lhs.DN, rhs.DN);
                return;
            }

            LdapAttributeSet las = lhs.getAttributeSet();

            foreach (LdapAttribute la in las)
            {
                LdapAttribute rla = rhs.getAttribute(la.Name);
                if (rla == null)
                {
                    Log.Debug("Delete attribute {0} from {1}", la.Name, lhs.DN);
                    LdapAttribute    a = new LdapAttribute(la.Name);
                    LdapModification m = new LdapModification(LdapModification.DELETE, a);
                    mods.Add(m);
                }
                else
                {
                    if (rla.StringValueArray.Length > 1)
                    {
                        Log.Debug("Replacing attribute {0} with multiple values", la.Name);
                        LdapAttribute    a = new LdapAttribute(la.Name, rla.StringValueArray);
                        LdapModification m = new LdapModification(LdapModification.REPLACE, a);
                        mods.Add(m);
                    }
                    else if (la.StringValue != rla.StringValue)
                    {
                        LdapAttribute    newattr;
                        LdapModification lm;

                        if (rla.StringValue == "" || rla.StringValue == null)
                        {
                            Log.Debug("Delete attribute {0} from {1}", la.Name, lhs.DN);
                            newattr = new LdapAttribute(la.Name);
                            lm      = new LdapModification(LdapModification.DELETE, newattr);
                        }
                        else
                        {
                            Log.Debug("Replace attribute {0} value from {1} to {2} ", la.Name, la.StringValue, rla.StringValue);
                            newattr = new LdapAttribute(la.Name, rla.StringValue);
                            lm      = new LdapModification(LdapModification.REPLACE, newattr);
                        }

                        mods.Add(lm);
                    }
                }
            }

            LdapAttributeSet rlas = rhs.getAttributeSet();

            foreach (LdapAttribute la in rlas)
            {
                LdapAttribute lla = lhs.getAttribute(la.Name);
                if (lla == null && la.StringValue != string.Empty)
                {
                    Log.Debug("Add attribute {0} value [{1}] to {2}", la.Name, la.StringValue, lhs.DN);
                    LdapAttribute    a = new LdapAttribute(la.Name, la.StringValue);
                    LdapModification m = new LdapModification(LdapModification.ADD, a);
                    mods.Add(m);
                }
            }

            Log.Debug("End LdapEntryAnalyzer");
        }