Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public SyncResult OnDeleteEntry(byte[] guid)
        {
            string            str               = ADValueConvertor.EscapeBinaryValue(guid);
            SearchRequest     request           = new SearchRequest(this.GetTargetBaseSearchPath(), "(msExchEdgeSyncSourceGuid=" + str + ")", System.DirectoryServices.Protocols.SearchScope.Subtree, new string[0]);
            SearchResultEntry searchResultEntry = null;
            SearchResponse    searchResponse    = (SearchResponse)this.SendRequest(request);

            if (searchResponse.Entries.Count > 0)
            {
                searchResultEntry = searchResponse.Entries[0];
                try
                {
                    DeleteRequest request2 = new DeleteRequest(searchResultEntry.DistinguishedName);
                    this.SendRequest(request2);
                }
                catch (ExDirectoryException ex)
                {
                    if (ex.ResultCode != ResultCode.NoSuchObject)
                    {
                        if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.ErrorTrace))
                        {
                            ExTraceGlobals.SynchronizationJobTracer.TraceError <string, Guid>((long)this.GetHashCode(), "Failed to delete entry {0} with sourceGuid {1}", searchResultEntry.DistinguishedName, new Guid(guid));
                        }
                        throw;
                    }
                    this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, string.Format(CultureInfo.InvariantCulture, "DN:{0}, Guid:{1}", new object[]
                    {
                        searchResultEntry.DistinguishedName,
                        new Guid(guid).ToString()
                    }), "Skip deleting non-existing entry after sourceGuid has been confirmed. It must have been deleted in between.");
                    return(SyncResult.None);
                }
                if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    ExTraceGlobals.SynchronizationJobTracer.TraceDebug <string, Guid>((long)this.GetHashCode(), "Deleted object {0} with sourceGuid {1}", searchResultEntry.DistinguishedName, new Guid(guid));
                }
                return(SyncResult.Deleted);
            }
            if (ExTraceGlobals.SynchronizationJobTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                ExTraceGlobals.SynchronizationJobTracer.TraceDebug <Guid>((long)this.GetHashCode(), "Delete non-existing entry with sourceGUID {0}", new Guid(guid));
            }
            this.logSession.LogEvent(EdgeSyncLoggingLevel.Medium, EdgeSyncEvent.TargetConnection, new Guid(guid).ToString(), "Skip deleting non-existing entry");
            return(SyncResult.None);
        }
        // Token: 0x06000DD8 RID: 3544 RVA: 0x0003FF84 File Offset: 0x0003E184
        private void ConvertComparisonFilterInternal(ComparisonFilter comparisonFilter, QueryFilter parentFilter, bool isSoftLink, byte softLinkPrefix = 0)
        {
            ADPropertyDefinition adpropertyDefinition = (ADPropertyDefinition)comparisonFilter.Property;
            object obj             = comparisonFilter.PropertyValue;
            string ldapDisplayName = adpropertyDefinition.LdapDisplayName;

            if (isSoftLink && adpropertyDefinition.IsSoftLinkAttribute)
            {
                ldapDisplayName = adpropertyDefinition.SoftLinkShadowProperty.LdapDisplayName;
                if (obj != null)
                {
                    obj = ADObjectIdResolutionHelper.ResolveSoftLink((ADObjectId)obj);
                }
            }
            bool flag = adpropertyDefinition.Type.IsGenericType && adpropertyDefinition.Type.GetGenericTypeDefinition() == typeof(Unlimited <>);

            if (flag)
            {
                bool flag2 = adpropertyDefinition.DefaultValue.Equals(obj);
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    if (flag2)
                    {
                        this.IncrementFilterSize(2);
                        this.ldapFilter.Append("(!(");
                        this.ldapFilter.Append(ldapDisplayName);
                        this.ldapFilter.Append("=*))");
                        return;
                    }
                    break;

                case ComparisonOperator.NotEqual:
                case ComparisonOperator.LessThan:
                    if (flag2)
                    {
                        this.IncrementFilterSize();
                        this.ldapFilter.Append('(');
                        this.ldapFilter.Append(ldapDisplayName);
                        this.ldapFilter.Append("=*)");
                        return;
                    }
                    break;

                case ComparisonOperator.LessThanOrEqual:
                    if (flag2)
                    {
                        this.IncrementFilterSize();
                        this.ldapFilter.Append("(objectclass=*)");
                        return;
                    }
                    break;

                case ComparisonOperator.GreaterThan:
                    if (flag2)
                    {
                        this.IncrementFilterSize();
                        this.ldapFilter.Append("(!(objectclass=*))");
                        return;
                    }
                    break;

                case ComparisonOperator.GreaterThanOrEqual:
                    if (flag2)
                    {
                        this.IncrementFilterSize(2);
                        this.ldapFilter.Append("(!(");
                        this.ldapFilter.Append(ldapDisplayName);
                        this.ldapFilter.Append("=*))");
                        return;
                    }
                    this.IncrementFilterSize(4);
                    this.ldapFilter.Append("(|(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append(">=");
                    ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, obj, this.ldapFilter, isSoftLink, softLinkPrefix);
                    this.ldapFilter.Append(")(!(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append("=*)))");
                    return;
                }
            }
            switch (comparisonFilter.ComparisonOperator)
            {
            case ComparisonOperator.LessThan:
                this.ConvertCompositeFilter(new AndFilter(new QueryFilter[]
                {
                    new ComparisonFilter(ComparisonOperator.LessThanOrEqual, comparisonFilter.Property, obj),
                    new ComparisonFilter(ComparisonOperator.NotEqual, comparisonFilter.Property, obj)
                }), parentFilter);
                return;

            case ComparisonOperator.GreaterThan:
                this.ConvertCompositeFilter(new AndFilter(new QueryFilter[]
                {
                    new ComparisonFilter(ComparisonOperator.GreaterThanOrEqual, comparisonFilter.Property, obj),
                    new ComparisonFilter(ComparisonOperator.NotEqual, comparisonFilter.Property, obj)
                }), parentFilter);
                return;
            }
            if (!adpropertyDefinition.PersistDefaultValue && !flag && adpropertyDefinition.DefaultValue != null && adpropertyDefinition.DefaultValue.Equals(comparisonFilter.PropertyValue))
            {
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    this.IncrementFilterSize(4);
                    this.ldapFilter.Append("(|(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append("=");
                    ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, adpropertyDefinition.DefaultValue, this.ldapFilter, isSoftLink, softLinkPrefix);
                    this.ldapFilter.Append(")(!(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append("=*)))");
                    return;

                case ComparisonOperator.NotEqual:
                    this.IncrementFilterSize(4);
                    this.ldapFilter.Append("(&(!(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append("=");
                    ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, adpropertyDefinition.DefaultValue, this.ldapFilter, isSoftLink, softLinkPrefix);
                    this.ldapFilter.Append("))(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append("=*))");
                    return;

                default:
                    throw new ADFilterException(DirectoryStrings.ExceptionUnsupportedDefaultValueFilter(adpropertyDefinition.Name, comparisonFilter.ComparisonOperator.ToString(), (comparisonFilter.PropertyValue == null) ? string.Empty : obj.ToString()));
                }
            }
            else
            {
                string value = string.Empty;
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    value = "=";
                    goto IL_49B;

                case ComparisonOperator.NotEqual:
                    value = "=";
                    goto IL_49B;

                case ComparisonOperator.LessThanOrEqual:
                    value = "<=";
                    goto IL_49B;

                case ComparisonOperator.GreaterThanOrEqual:
                    value = ">=";
                    goto IL_49B;
                }
                throw new ADFilterException(DirectoryStrings.ExceptionUnsupportedOperator(comparisonFilter.ComparisonOperator.ToString(), typeof(ComparisonFilter).ToString()));
IL_49B:
                if (comparisonFilter.ComparisonOperator == ComparisonOperator.NotEqual)
                {
                    this.IncrementFilterSize(2);
                    this.ldapFilter.Append("(!(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append(value);
                    ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, obj, this.ldapFilter, isSoftLink, softLinkPrefix);
                    this.ldapFilter.Append("))");
                    return;
                }
                if (adpropertyDefinition == ADObjectSchema.Id && Guid.Empty != ((ADObjectId)obj).ObjectGuid && this.tenantScoped && comparisonFilter.ComparisonOperator == ComparisonOperator.Equal)
                {
                    this.IncrementFilterSize(3);
                    this.ldapFilter.Append("(|(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append(value);
                    ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, obj, this.ldapFilter, false, softLinkPrefix);
                    this.ldapFilter.Append(")(");
                    this.ldapFilter.Append(ADObjectSchema.CorrelationIdRaw.LdapDisplayName);
                    this.ldapFilter.Append(value);
                    this.ldapFilter.Append(ADValueConvertor.EscapeBinaryValue(((ADObjectId)obj).ObjectGuid.ToByteArray()));
                    this.ldapFilter.Append("))");
                    return;
                }
                if (adpropertyDefinition == ADObjectSchema.Guid && this.tenantScoped && comparisonFilter.ComparisonOperator == ComparisonOperator.Equal)
                {
                    string value2 = ADValueConvertor.EscapeBinaryValue(((Guid)obj).ToByteArray());
                    this.IncrementFilterSize(3);
                    this.ldapFilter.Append("(|(");
                    this.ldapFilter.Append(ldapDisplayName);
                    this.ldapFilter.Append(value);
                    this.ldapFilter.Append(value2);
                    this.ldapFilter.Append(")(");
                    this.ldapFilter.Append(ADObjectSchema.CorrelationIdRaw.LdapDisplayName);
                    this.ldapFilter.Append(value);
                    this.ldapFilter.Append(value2);
                    this.ldapFilter.Append("))");
                    return;
                }
                this.IncrementFilterSize();
                this.ldapFilter.Append("(");
                this.ldapFilter.Append(ldapDisplayName);
                this.ldapFilter.Append(value);
                ADValueConvertor.ConvertToAndAppendFilterString(adpropertyDefinition, obj, this.ldapFilter, isSoftLink, softLinkPrefix);
                this.ldapFilter.Append(")");
                return;
            }
        }