Exemplo n.º 1
0
        private ModifyRequest AddAttributeModifications(ExSearchResultEntry entry, SortedList <string, DirectoryAttribute> attributes, ModifyRequest modificationRequest)
        {
            DirectoryAttributeModification directoryAttributeModification = null;

            foreach (KeyValuePair <string, DirectoryAttribute> keyValuePair in attributes)
            {
                directoryAttributeModification           = new DirectoryAttributeModification();
                directoryAttributeModification.Name      = keyValuePair.Key;
                directoryAttributeModification.Operation = DirectoryAttributeOperation.Replace;
                foreach (object obj in keyValuePair.Value)
                {
                    if (obj is byte[])
                    {
                        directoryAttributeModification.Add((byte[])obj);
                    }
                    else
                    {
                        directoryAttributeModification.Add((string)obj);
                    }
                    if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        this.TraceAttributeValue(keyValuePair.Value);
                    }
                }
                modificationRequest.Modifications.Add(directoryAttributeModification);
            }
            directoryAttributeModification           = new DirectoryAttributeModification();
            directoryAttributeModification.Name      = "msExchEdgeSyncSourceGuid";
            directoryAttributeModification.Operation = DirectoryAttributeOperation.Replace;
            directoryAttributeModification.Add((byte[])entry.Attributes["objectGUID"][0]);
            modificationRequest.Modifications.Add(directoryAttributeModification);
            return(modificationRequest);
        }
Exemplo n.º 2
0
        public ExSearchResultEntry ReadObjectEntry(string absolutePath, params string[] attributes)
        {
            ExSearchResultEntry result = null;

            try
            {
                SearchResponse searchResponse = (SearchResponse)this.SendRequest(new SearchRequest(absolutePath, Schema.Query.QueryAll, System.DirectoryServices.Protocols.SearchScope.Base, attributes)
                {
                    Attributes =
                    {
                        "objectClass"
                    }
                });
                if (searchResponse.Entries.Count > 0)
                {
                    result = new ExSearchResultEntry(searchResponse.Entries[0]);
                }
            }
            catch (ExDirectoryException ex)
            {
                if (ex.ResultCode != ResultCode.NoSuchObject)
                {
                    throw;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        public virtual string GetTargetPath(ExSearchResultEntry entry)
        {
            string text;

            if (this.type == SyncTreeType.Recipients)
            {
                DirectoryAttribute directoryAttribute = entry.Attributes["objectGUID"];
                Guid guid = new Guid((byte[])directoryAttribute.GetValues(typeof(byte[]))[0]);
                text = "cn=" + guid.ToString() + ",CN=Recipients,OU=MSExchangeGateway";
            }
            else
            {
                if (LdapTargetConnection.rootOrgContainerDN == null)
                {
                    LdapTargetConnection.rootOrgContainerDN = ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest().DistinguishedName;
                }
                string text2      = entry.DistinguishedName;
                int    startIndex = -1;
                int    count      = 0;
                if (entry.IsCollisionObject(out startIndex, out count))
                {
                    text2 = text2.Remove(startIndex, count);
                }
                text = text2.Replace(LdapTargetConnection.rootOrgContainerDN, this.adamRootOrgContainerDN);
            }
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Translate source DN {0} to target DN {1}", entry.DistinguishedName, text);
            return(text);
        }
Exemplo n.º 4
0
        public virtual ExSearchResultEntry ReadObjectEntry(string absolutePath, bool readDeleted, params string[] attributes)
        {
            ExSearchResultEntry result = null;

            try
            {
                SearchRequest searchRequest = new SearchRequest(absolutePath, Schema.Query.QueryAll, SearchScope.Base, attributes);
                searchRequest.Attributes.Add("objectClass");
                if (readDeleted)
                {
                    searchRequest.Controls.Add(new ShowDeletedControl());
                }
                SearchResponse searchResponse = (SearchResponse)this.SendRequest(searchRequest);
                if (searchResponse.Entries.Count > 0)
                {
                    result = new ExSearchResultEntry(searchResponse.Entries[0]);
                }
            }
            catch (ExDirectoryException ex)
            {
                if (ex.ResultCode != ResultCode.NoSuchObject)
                {
                    throw;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        public override SyncResult OnModifyEntry(ExSearchResultEntry entry, SortedList <string, DirectoryAttribute> sourceAttributes)
        {
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "About to modify target from source DN {0}", entry.DistinguishedName);
            ModifyRequest modifyRequest = new ModifyRequest();

            modifyRequest.DistinguishedName = this.GetTargetPath(entry);
            this.SendRequest(this.AddAttributeModifications(entry, sourceAttributes, modifyRequest));
            this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, "Updated: " + entry.DistinguishedName, "Succcessfully Updated Entry");
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Modified entry {0}", modifyRequest.DistinguishedName);
            return(SyncResult.Modified);
        }
Exemplo n.º 6
0
        protected virtual ExSearchResultEntry GetTargetEntry(ExSearchResultEntry entry)
        {
            DirectoryAttribute directoryAttribute = entry.Attributes["objectGUID"];

            byte[]         value          = (byte[])directoryAttribute.GetValues(typeof(byte[]))[0];
            string         str            = ADValueConvertor.EscapeBinaryValue(value);
            SearchRequest  request        = new SearchRequest(this.GetTargetBaseSearchPath(), "(msExchEdgeSyncSourceGuid=" + str + ")", System.DirectoryServices.Protocols.SearchScope.Subtree, new string[0]);
            SearchResponse searchResponse = (SearchResponse)this.SendRequest(request);

            if (searchResponse.Entries.Count > 0)
            {
                return(new ExSearchResultEntry(searchResponse.Entries[0]));
            }
            return(null);
        }
Exemplo n.º 7
0
        public override SyncResult OnDeleteEntry(ExSearchResultEntry entry)
        {
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "About to delete target with source DN {0}", entry.DistinguishedName);
            DirectoryAttribute directoryAttribute = entry.Attributes["objectGUID"];

            byte[]     array      = (byte[])directoryAttribute.GetValues(typeof(byte[]))[0];
            SyncResult syncResult = this.OnDeleteEntry(array);

            if (syncResult == SyncResult.Deleted)
            {
                this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "Deleted: DN:{0}, Guid:{1}", new object[]
                {
                    entry.DistinguishedName,
                    new Guid(array).ToString()
                }), "Succcessfully Deleted Entry");
            }
            return(syncResult);
        }
Exemplo n.º 8
0
        public bool MultiValuedAttributeContain(string attributeName, string valueToFind)
        {
            DirectoryAttribute directoryAttribute;

            if (!this.Attributes.TryGetValue(attributeName, out directoryAttribute))
            {
                throw new ArgumentException("The entry should contain the attribute " + attributeName);
            }
            foreach (object obj in directoryAttribute)
            {
                if (obj != null)
                {
                    string asciiStringValueOfAttribute = ExSearchResultEntry.GetAsciiStringValueOfAttribute(obj, attributeName);
                    if (asciiStringValueOfAttribute != null && asciiStringValueOfAttribute.Equals(valueToFind, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        public override SyncResult OnRenameEntry(ExSearchResultEntry entry)
        {
            if (this.type != SyncTreeType.Configuration)
            {
                return(SyncResult.None);
            }
            ExSearchResultEntry targetEntry = this.GetTargetEntry(entry);

            if (targetEntry == null)
            {
                Guid empty = Guid.Empty;
                DirectoryAttribute directoryAttribute = null;
                if (entry.Attributes.TryGetValue("objectGUID", out directoryAttribute))
                {
                    byte[] b = (byte[])directoryAttribute.GetValues(typeof(byte[]))[0];
                    empty = new Guid(b);
                }
                this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "Rename convert into Add/Modify for {0} because can't locate target object based on sourceGuid {1}", new object[]
                {
                    entry.DistinguishedName,
                    empty
                }), "Rename");
                return(SyncResult.None);
            }
            string          text            = DistinguishedName.ExtractRDN(entry.DistinguishedName);
            ModifyDNRequest modifyDNRequest = new ModifyDNRequest();

            modifyDNRequest.NewName                    = text;
            modifyDNRequest.DistinguishedName          = targetEntry.DistinguishedName;
            modifyDNRequest.NewParentDistinguishedName = DistinguishedName.Parent(targetEntry.DistinguishedName);
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, string>((long)this.GetHashCode(), "About to rename target DN {0} with new RDN {1}", targetEntry.DistinguishedName, text);
            this.SendRequest(modifyDNRequest);
            this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "Rename: Target:{0}, NewRDN:{1}", new object[]
            {
                targetEntry.DistinguishedName,
                text
            }), "Successfully Renamed Entry");
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Rename target {0} with new RDN {1}", targetEntry.DistinguishedName, text);
            return(SyncResult.Renamed);
        }
Exemplo n.º 10
0
 protected virtual void EnsureTargetContainer(ExSearchResultEntry entry)
 {
     if (this.type == SyncTreeType.Recipients)
     {
         SearchResponse searchResponse = (SearchResponse)this.SendRequest(new SearchRequest(DistinguishedName.Parent("CN=Recipients,OU=MSExchangeGateway"), Schema.Query.QueryRecipientsContainer, System.DirectoryServices.Protocols.SearchScope.OneLevel, null));
         if (searchResponse.Entries.Count == 0)
         {
             AddRequest request = new AddRequest("CN=Recipients,OU=MSExchangeGateway", "msExchContainer");
             this.SendRequest(request);
             return;
         }
     }
     else
     {
         string text = DistinguishedName.Parent(this.GetTargetPath(entry));
         if (!this.Exists(text))
         {
             AddRequest request2 = new AddRequest(text, "msExchContainer");
             this.SendRequest(request2);
         }
     }
 }
Exemplo n.º 11
0
        public override SyncResult OnAddEntry(ExSearchResultEntry entry, SortedList <string, DirectoryAttribute> sourceAttributes)
        {
            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "About to add to target from source DN {0}", entry.DistinguishedName);
            string targetPath = this.GetTargetPath(entry);

            try
            {
                AddRequest addRequest = new AddRequest(targetPath, entry.ObjectClass);
                foreach (DirectoryAttribute directoryAttribute in sourceAttributes.Values)
                {
                    if (!directoryAttribute.Name.Equals("objectClass", StringComparison.OrdinalIgnoreCase))
                    {
                        if (directoryAttribute.Count == 0)
                        {
                            ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Skip attribute {0} because it is null", directoryAttribute.Name);
                        }
                        else
                        {
                            addRequest.Attributes.Add(directoryAttribute);
                            if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.DebugTrace))
                            {
                                this.TraceAttributeValue(directoryAttribute);
                            }
                        }
                    }
                }
                DirectoryAttribute attribute = new DirectoryAttribute("msExchEdgeSyncSourceGuid", new object[]
                {
                    entry.Attributes["objectGUID"][0]
                });
                addRequest.Attributes.Add(attribute);
                if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Guid guid = new Guid((byte[])entry.Attributes["objectGUID"][0]);
                    ExTraceGlobals.SynchronizationJobTracer.TraceError <string>((long)this.GetHashCode(), "Adding sourceGuid {0}", guid.ToString());
                }
                DirectoryAttribute attribute2 = new DirectoryAttribute("systemFlags", 1107296256.ToString());
                addRequest.Attributes.Add(attribute2);
                this.SendRequest(addRequest);
                this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, "Added: " + entry.DistinguishedName, "Succcessfully Added Entry");
                ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Added entry {0}", targetPath);
            }
            catch (ExDirectoryException ex)
            {
                ResultCode resultCode = ex.ResultCode;
                if (resultCode == ResultCode.NoSuchObject)
                {
                    ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "{0}'s parent container doesn't exist. Create one and retry", targetPath);
                    this.EnsureTargetContainer(entry);
                    return(this.OnAddEntry(entry, sourceAttributes));
                }
                if (resultCode == ResultCode.EntryAlreadyExists)
                {
                    ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string>((long)this.GetHashCode(), "Add entry already exists for {0}. Try to modify instead.", targetPath);
                    this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, entry.DistinguishedName, "Convert Add to Update");
                    return(this.OnModifyEntry(entry, sourceAttributes));
                }
                ExTraceGlobals.SynchronizationJobTracer.TraceError <string, ExDirectoryException>((long)this.GetHashCode(), "Failed to add entry {0} because {1}", targetPath, ex);
                throw;
            }
            return(SyncResult.Added);
        }
Exemplo n.º 12
0
 public abstract SyncResult OnRenameEntry(ExSearchResultEntry entry);
Exemplo n.º 13
0
 public abstract SyncResult OnDeleteEntry(ExSearchResultEntry entry);
Exemplo n.º 14
0
 public abstract SyncResult OnModifyEntry(ExSearchResultEntry entry, SortedList <string, DirectoryAttribute> sourceAttributes);