示例#1
0
 private void ValidateParameters()
 {
     if (this.DomainName == null || string.IsNullOrEmpty(this.DomainName.Domain))
     {
         base.WriteError(new NoAccountNamespaceException(), ErrorCategory.InvalidOperation, this.DataObject.Identity);
     }
     if (!this.IsDatacenter && (this.DataObject.DelegationTrustLink == null || this.DataObject.AccountNamespace == null || string.IsNullOrEmpty(this.DataObject.AccountNamespace.Domain)))
     {
         base.WriteError(new NoTrustConfiguredException(), ErrorCategory.InvalidOperation, this.DataObject.Identity);
     }
     if (this.DataObject.DelegationTrustLink == null)
     {
         this.federationTrust = null;
     }
     else
     {
         ADObjectId deletedObjectsContainer = this.ConfigurationSession.DeletedObjectsContainer;
         ADObjectId adobjectId = ADObjectIdResolutionHelper.ResolveDN(this.DataObject.DelegationTrustLink);
         if (adobjectId != null)
         {
             if (adobjectId.Parent.Equals(deletedObjectsContainer))
             {
                 this.WriteWarning(Strings.ErrorFederationTrustNotFound(adobjectId.ToDNString()));
                 this.federationTrust = null;
             }
             else
             {
                 IConfigDataProvider configDataProvider = this.IsDatacenter ? base.GlobalConfigSession : base.DataSession;
                 this.federationTrust = (configDataProvider.Read <FederationTrust>(adobjectId) as FederationTrust);
                 if (this.federationTrust == null)
                 {
                     this.WriteWarning(Strings.ErrorFederationTrustNotFound(adobjectId.ToDNString()));
                 }
             }
         }
         else
         {
             this.WriteWarning(Strings.ErrorFederationTrustNotFound(this.DataObject.DelegationTrustLink.ToDNString()));
             this.federationTrust = null;
         }
     }
     if (!this.IsDatacenter && this.DomainName.Equals(this.DataObject.AccountNamespace) && 1 < base.FederatedAcceptedDomains.Count)
     {
         base.WriteError(new CannotRemoveAccountNamespaceException(this.DomainName.Domain), ErrorCategory.InvalidOperation, this.DataObject.Identity);
     }
     this.matchedAcceptedDomain = base.GetAcceptedDomain(this.DomainName, true);
     if (this.matchedAcceptedDomain.FederatedOrganizationLink == null && !this.DomainName.Equals(this.DataObject.AccountNamespace))
     {
         if (this.Force || this.IsDatacenter)
         {
             this.WriteWarning(Strings.ErrorDomainIsNotFederated(this.DomainName.Domain));
         }
         else
         {
             base.WriteError(new DomainIsNotFederatedException(this.DomainName.Domain), ErrorCategory.InvalidOperation, this.DataObject.Identity);
         }
     }
     TaskLogger.LogExit();
 }
        protected void RemoveSystemMailbox()
        {
            TDataObject dataObject = base.DataObject;
            ADObjectId  adobjectId = ((ADObjectId)dataObject.Identity).DomainId;

            adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects");
            adobjectId = adobjectId.GetChildId("SystemMailbox" + dataObject.Guid.ToString("B"));
            try
            {
                string identity = adobjectId.ToDNString();
                GeneralMailboxIdParameter generalMailboxIdParameter = GeneralMailboxIdParameter.Parse(identity);
                base.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(generalMailboxIdParameter, this.RecipientSessionForSystemMailbox, typeof(ADRecipient), null));
                IEnumerable <ADSystemMailbox> objects = generalMailboxIdParameter.GetObjects <ADSystemMailbox>(null, this.RecipientSessionForSystemMailbox);
                using (IEnumerator <ADSystemMailbox> enumerator = objects.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ADSystemMailbox adsystemMailbox = enumerator.Current;
                        base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.RecipientSessionForSystemMailbox));
                        base.WriteVerbose(Strings.VerboseDeleteSystemAttendantObject(adsystemMailbox.Identity.ToString()));
                        this.RecipientSessionForSystemMailbox.Delete(adsystemMailbox);
                    }
                }
            }
            catch (DataSourceTransientException ex)
            {
                TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[]
                {
                    dataObject.Identity.ToString(),
                    ex.Message
                });
                this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex.Message));
            }
            catch (DataSourceOperationException ex2)
            {
                TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[]
                {
                    dataObject.Identity.ToString(),
                    ex2.Message
                });
                this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex2.Message));
            }
            catch (DataValidationException ex3)
            {
                TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[]
                {
                    dataObject.Identity.ToString(),
                    ex3.Message
                });
                this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex3.Message));
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.RecipientSessionForSystemMailbox));
            }
            TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' succeeded.", new object[]
            {
                dataObject.Identity.ToString()
            });
        }
示例#3
0
        internal virtual void Initialize(ObjectId objectId)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            ADObjectId adobjectId = objectId as ADObjectId;

            if (adobjectId == null)
            {
                throw new ArgumentException(Strings.ErrorInvalidParameterType("objectId", typeof(ADObjectId).Name), "objectId");
            }
            if (this.InternalADObjectId != null)
            {
                throw new InvalidOperationException(Strings.ErrorChangeImmutableType);
            }
            if (string.IsNullOrEmpty(adobjectId.DistinguishedName) && adobjectId.ObjectGuid == Guid.Empty)
            {
                throw new ArgumentException(Strings.ErrorInvalidParameterFormat("objectId"), "objectId");
            }
            if (adobjectId.IsRelativeDn)
            {
                throw new ArgumentException(Strings.ErrorRelativeDn(adobjectId.ToDNString()), "objectId");
            }
            if (PiiMapManager.ContainsRedactedPiiValue(adobjectId.DistinguishedName))
            {
                string distinguishedName = this.TryResolveRedactedPii(adobjectId.DistinguishedName);
                if (this.IsRedactedPiiResolved)
                {
                    adobjectId = new ADObjectId(distinguishedName, adobjectId.ObjectGuid, adobjectId.PartitionGuid);
                }
            }
            this.adObjectId  = adobjectId;
            this.rawIdentity = adobjectId.ToDNString();
        }
        // Token: 0x06000DBE RID: 3518 RVA: 0x0003EC08 File Offset: 0x0003CE08
        private bool IsDomainMatch(int connectionIndex, ADObjectId domain)
        {
            bool flag = this.connectionInfos[connectionIndex].ADServerInfo.WritableNC.Equals(domain.DistinguishedName, StringComparison.OrdinalIgnoreCase);

            ExTraceGlobals.GetConnectionTracer.TraceDebug((long)this.GetHashCode(), "IsDomainMatch: {0} from {1} is {2} match for domain {3}", new object[]
            {
                this.connectionInfos[connectionIndex].ADServerInfo.FqdnPlusPort,
                this.connectionInfos[connectionIndex].ADServerInfo.WritableNC,
                flag ? "a" : "NO",
                domain.ToDNString()
            });
            return(flag);
        }
        // Token: 0x06000DE3 RID: 3555 RVA: 0x00040D24 File Offset: 0x0003EF24
        private void CheckVirtualIndexOnIdOrAbMembership(CompositeFilter filter)
        {
            if (this.skipCheckVirtualIndex)
            {
                return;
            }
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            Guid   a     = Guid.Empty;
            string text  = string.Empty;

            foreach (QueryFilter queryFilter in filter.Filters)
            {
                if (queryFilter is OrFilter)
                {
                    flag = true;
                }
                else
                {
                    ComparisonFilter comparisonFilter = queryFilter as ComparisonFilter;
                    if (comparisonFilter != null)
                    {
                        if (comparisonFilter.ComparisonOperator == ComparisonOperator.Equal)
                        {
                            if (comparisonFilter.Property == ADObjectSchema.Id)
                            {
                                ADObjectId adobjectId = (ADObjectId)comparisonFilter.PropertyValue;
                                a    = adobjectId.ObjectGuid;
                                text = adobjectId.ToDNString();
                            }
                            else if (comparisonFilter.Property == ADObjectSchema.Guid)
                            {
                                a = (Guid)comparisonFilter.PropertyValue;
                            }
                            else if (comparisonFilter.Property == ADObjectSchema.DistinguishedName)
                            {
                                text = (string)comparisonFilter.PropertyValue;
                            }
                            else if (comparisonFilter.Property == ADRecipientSchema.AddressListMembership)
                            {
                                flag2 = true;
                            }
                            else if (comparisonFilter.Property == ADRecipientSchema.DisplayName)
                            {
                                flag3 = true;
                            }
                        }
                    }
                    else
                    {
                        ExistsFilter existsFilter = queryFilter as ExistsFilter;
                        if (existsFilter != null)
                        {
                            if (existsFilter.Property == ADRecipientSchema.DisplayName)
                            {
                                flag3 = true;
                            }
                        }
                        else if (queryFilter is AmbiguousNameResolutionFilter)
                        {
                            flag4 = true;
                        }
                    }
                }
            }
            if (flag2 && !flag3 && !flag4 && (text != string.Empty || a != Guid.Empty || flag))
            {
                this.ldapFilter.Append("(displayName=*)");
            }
            if (flag)
            {
                if (text != string.Empty && !text.Contains(",CN=DeletedObjects,"))
                {
                    this.ldapFilter.Append("(objectCategory=*)");
                    return;
                }
                if (a != Guid.Empty)
                {
                    this.ldapFilter.Append("(objectCategory=*)");
                }
            }
        }
示例#6
0
        protected SearchResultEntryCollection GetNextResultCollection(Type controlType, out DirectoryControl responseControl)
        {
            SearchRequest searchRequest = new SearchRequest(null, this.ldapFilter, (SearchScope)this.scope, this.ldapAttributes);

            searchRequest.Controls.AddRange(this.directoryControls);
            searchRequest.SizeLimit = this.SizeLimit;
            if (this.session.ServerTimeout != null)
            {
                searchRequest.TimeLimit = this.session.ServerTimeout.Value;
            }
            SearchResponse searchResponse = null;

            responseControl = null;
            RetryManager retryManager = new RetryManager();
            ADObjectId   adobjectId   = this.rootId;
            bool         flag         = !this.session.SessionSettings.IncludeSoftDeletedObjects && !this.session.SessionSettings.IncludeInactiveMailbox && this.session.EnforceContainerizedScoping;

            for (;;)
            {
                PooledLdapConnection readConnection = this.session.GetReadConnection(this.preferredServerName, null, ref adobjectId, this.ScopeDeterminingObject);
                Guid serviceProviderRequestId       = Guid.Empty;
                try
                {
                    try
                    {
                        if (this.useNullRoot)
                        {
                            searchRequest.DistinguishedName = null;
                        }
                        else
                        {
                            searchRequest.DistinguishedName = adobjectId.ToDNString();
                            if (flag && searchRequest.Scope == SearchScope.Subtree)
                            {
                                ADObjectId domainId = adobjectId.DomainId;
                                if (domainId != null)
                                {
                                    ADObjectId childId = domainId.GetChildId("OU", "Microsoft Exchange Hosted Organizations");
                                    ADObjectId parent  = adobjectId.Parent;
                                    if (childId != null && parent != null && ADObjectId.Equals(childId, parent))
                                    {
                                        searchRequest.Scope = SearchScope.OneLevel;
                                    }
                                }
                            }
                        }
                        if (TopologyProvider.IsAdamTopology() && string.IsNullOrEmpty(searchRequest.DistinguishedName))
                        {
                            searchRequest.Controls.Add(new SearchOptionsControl(SearchOption.PhantomRoot));
                        }
                        ExTraceGlobals.ADFindTracer.TraceDebug((long)this.GetHashCode(), "ADGenericReader::GetNextResultCollection({0}) using {1} - LDAP search from {2}, scope {3}, filter {4}", new object[]
                        {
                            controlType.Name,
                            readConnection.ADServerInfo.FqdnPlusPort,
                            searchRequest.DistinguishedName,
                            (int)searchRequest.Scope,
                            searchRequest.Filter
                        });
                        serviceProviderRequestId = Trace.TraceCasStart(CasTraceEventType.ActiveDirectory);
                        searchResponse           = (SearchResponse)readConnection.SendRequest(searchRequest, LdapOperation.Search, null, this.session.ActivityScope, this.session.CallerInfo);
                        this.preferredServerName = readConnection.ServerName;
                        this.session.UpdateServerSettings(readConnection);
                        break;
                    }
                    catch (DirectoryException de)
                    {
                        if (this.customExceptionHandler != null)
                        {
                            this.customExceptionHandler(de);
                        }
                        if (readConnection.IsResultCode(de, ResultCode.NoSuchObject))
                        {
                            ExTraceGlobals.ADFindTracer.TraceWarning <string, object>((long)this.GetHashCode(), "NoSuchObject caught when searching from {0} with filter {1}", searchRequest.DistinguishedName, searchRequest.Filter);
                            return(null);
                        }
                        if (readConnection.IsResultCode(de, ResultCode.VirtualListViewError) && this.lcid != LcidMapper.DefaultLcid)
                        {
                            ExTraceGlobals.ADFindTracer.TraceWarning <int, int>((long)this.GetHashCode(), "VirtualListView error caught when performing a VLV lookup using LCID 0x{0:X}. Falling back to US English 0x{1:X}", this.lcid, LcidMapper.DefaultLcid);
                            this.RefreshSortControlWithDefaultLCID(searchRequest);
                        }
                        else
                        {
                            retryManager.Tried(readConnection.ServerName);
                            this.session.AnalyzeDirectoryError(readConnection, searchRequest, de, retryManager.TotalRetries, retryManager[readConnection.ServerName]);
                        }
                    }
                    continue;
                }
                finally
                {
                    bool isSnapshotInProgress = PerformanceContext.Current.IsSnapshotInProgress;
                    bool flag2 = ETWTrace.ShouldTraceCasStop(serviceProviderRequestId);
                    if (isSnapshotInProgress || flag2)
                    {
                        string text = string.Format(CultureInfo.InvariantCulture, "scope: {0}, filter: {1}", new object[]
                        {
                            searchRequest.Scope,
                            searchRequest.Filter
                        });
                        if (isSnapshotInProgress)
                        {
                            PerformanceContext.Current.AppendToOperations(text);
                        }
                        if (flag2)
                        {
                            Trace.TraceCasStop(CasTraceEventType.ActiveDirectory, serviceProviderRequestId, 0, 0, readConnection.ADServerInfo.FqdnPlusPort, searchRequest.DistinguishedName, "ADGenericReader::GetNextResultCollection", text, string.Empty);
                        }
                    }
                    readConnection.ReturnToPool();
                }
                break;
            }
            responseControl = this.FindControlInCollection(searchResponse.Controls, controlType);
            return(searchResponse.Entries);
        }
示例#7
0
        internal static object Getter(IPropertyBag propertyBag)
        {
            OrganizationId organizationId = OrganizationId.ForestWideOrgId;
            ADObjectId     adobjectId     = (ADObjectId)propertyBag[ADObjectSchema.OrganizationalUnitRoot];
            ADObjectId     adobjectId2    = (ADObjectId)propertyBag[ADObjectSchema.ConfigurationUnit];

            if (adobjectId != null && adobjectId2 != null)
            {
                organizationId = new OrganizationId();
                organizationId.Initialize(adobjectId, adobjectId2);
            }
            else if (adobjectId != null || adobjectId2 != null)
            {
                ADObjectId adobjectId3 = (ADObjectId)propertyBag[ADObjectSchema.Id];
                throw new DataValidationException(new PropertyValidationError(DirectoryStrings.ErrorInvalidOrganizationId((adobjectId3 != null) ? adobjectId3.ToDNString() : "<null>", (adobjectId != null) ? adobjectId.ToDNString() : "<null>", (adobjectId2 != null) ? adobjectId2.ToDNString() : "<null>"), ADObjectSchema.OrganizationId, null), null);
            }
            return(organizationId);
        }
示例#8
0
        // Token: 0x06001213 RID: 4627 RVA: 0x00038C84 File Offset: 0x00036E84
        private static Dictionary <string, MailboxDatabase> GetAllEnabledDatabases(ITopologyConfigurationSession configSession, LogMessageDelegate logger)
        {
            ADObjectId adobjectId = ProvisioningCache.Instance.TryAddAndGetGlobalData <ADObjectId>(CannedProvisioningCacheKeys.DatabaseContainerId, new ProvisioningCache.CacheObjectGetterDelegate(configSession.GetDatabasesContainerId));

            PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbDatabaseContainer(adobjectId.ToDNString()), logger);
            List <QueryFilter> list = new List <QueryFilter>
            {
                new ComparisonFilter(ComparisonOperator.Equal, MailboxDatabaseSchema.IsExcludedFromProvisioning, false),
                new ComparisonFilter(ComparisonOperator.Equal, MailboxDatabaseSchema.IsSuspendedFromProvisioning, false),
                new ComparisonFilter(ComparisonOperator.Equal, DatabaseSchema.Recovery, false)
            };
            QueryFilter filter = QueryFilter.AndTogether(list.ToArray());

            PhysicalResourceLoadBalancing.LogVerbose(TaskVerboseStringHelper.GetFindDataObjectsVerboseString(configSession, typeof(MailboxDatabase), filter, adobjectId, false), logger);
            ADPagedReader <MailboxDatabase>      adpagedReader = configSession.FindPaged <MailboxDatabase>(adobjectId, QueryScope.OneLevel, filter, null, 0);
            Dictionary <string, MailboxDatabase> dictionary    = new Dictionary <string, MailboxDatabase>();

            foreach (MailboxDatabase mailboxDatabase in adpagedReader)
            {
                dictionary[mailboxDatabase.Name] = mailboxDatabase;
            }
            PhysicalResourceLoadBalancing.LogVerbose(Strings.VerboseLbGeneralTrace(string.Format("Retrieved {0} mailbox databases enabled for provisioning in the forest.", dictionary.Count)), logger);
            return(dictionary);
        }
 // Token: 0x060050C6 RID: 20678 RVA: 0x0012B948 File Offset: 0x00129B48
 internal static object MarshalAttribute(ADPropertyDefinition property, object value)
 {
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     if (value == null)
     {
         return(null);
     }
     object[] array;
     if (!property.IsMultivalued)
     {
         array    = new object[2];
         array[0] = property.LdapDisplayName;
         if (property.IsBinary)
         {
             byte[] array2 = ADValueConvertor.ConvertValueToBinary(value, property.FormatProvider);
             array[1] = HexConverter.ByteArrayToHexString(array2);
         }
         else
         {
             ADObjectId adobjectId = value as ADObjectId;
             if (adobjectId != null)
             {
                 array[1] = adobjectId.ToDNString();
             }
             else
             {
                 array[1] = ADValueConvertor.ConvertValueToString(value, property.FormatProvider);
             }
         }
     }
     else
     {
         int         num        = 0;
         ArrayList   arrayList  = new ArrayList();
         IEnumerable enumerable = (IEnumerable)value;
         foreach (object obj in enumerable)
         {
             if (property.IsBinary)
             {
                 byte[] array3 = ADValueConvertor.ConvertValueToBinary(obj, property.FormatProvider);
                 arrayList.Add(HexConverter.ByteArrayToHexString(array3));
             }
             else
             {
                 ADObjectId adobjectId2 = obj as ADObjectId;
                 string     value2;
                 if (adobjectId2 != null)
                 {
                     value2 = adobjectId2.ToDNString();
                 }
                 else
                 {
                     value2 = ADValueConvertor.ConvertValueToString(obj, property.FormatProvider);
                 }
                 arrayList.Add(value2);
             }
             num++;
         }
         if (num == 0)
         {
             return(null);
         }
         array    = new object[num + 1];
         array[0] = property.LdapDisplayName;
         arrayList.CopyTo(array, 1);
     }
     return(array);
 }
示例#10
0
 internal static bool IsTenantConfigObjectInCorrectNC(ADObjectId tenantObjectId)
 {
     return(tenantObjectId == null || tenantObjectId.DomainId == null || ADSessionSettings.IsForefrontObject(tenantObjectId) || tenantObjectId.ToDNString().IndexOf("cn=configuration,dc=", StringComparison.OrdinalIgnoreCase) < 0 || !ADSession.IsTenantConfigInDomainNC(tenantObjectId.GetPartitionId().ForestFQDN));
 }
        // Token: 0x06000DC9 RID: 3529 RVA: 0x0003F560 File Offset: 0x0003D760
        internal PooledLdapConnection GetConnection(ADObjectId domain, string serverName, int port, ref bool newPoolAvailable, ref bool pendingConnections, ref bool serverConnectionPresentButDownOrDisconnected, ref Exception extraDownOrDisconnectedException)
        {
            PooledLdapConnection result = null;

            newPoolAvailable   = false;
            pendingConnections = false;
            serverConnectionPresentButDownOrDisconnected = false;
            int  tickCount = Environment.TickCount;
            bool flag      = serverName != null;
            bool flag2     = domain != null;
            bool flag3     = !flag2 && !flag;

            ExTraceGlobals.GetConnectionTracer.TraceDebug <ConnectionPoolType, string, string>((long)this.GetHashCode(), "LdapConnectionPool.GetConnection of type {0} by {1} ({2})", this.type, flag ? "Server" : (flag2 ? "Domain" : "Load balancing"), flag ? serverName : (flag2 ? domain.ToDNString() : "Least loaded"));
            this.CheckBadConnections();
            try
            {
                this.poolLock.AcquireReaderLock(-1);
                if (!this.isActive)
                {
                    ExTraceGlobals.GetConnectionTracer.TraceWarning((long)this.GetHashCode(), "Pool is not active, skipping GetConnection");
                    newPoolAvailable = true;
                    return(null);
                }
                bool flag4 = false;
                int  num   = int.MinValue;
                int  num2  = -1;
                for (int i = 0; i < this.connectionInfos.Length; i++)
                {
                    ConnectionInfo connectionInfo = this.connectionInfos[i];
                    if (!flag4 && connectionInfo.ConnectionState == ConnectionState.Empty)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "GetConnection: Opening connection for {0}.", connectionInfo.ADServerInfo.FqdnPlusPort);
                        this.OpenNewConnection(connectionInfo);
                    }
                    if (connectionInfo.ConnectionState == ConnectionState.Connecting)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Connection to {0} is pending, skipping.", connectionInfo.ADServerInfo.FqdnPlusPort);
                        pendingConnections = true;
                    }
                    else if (connectionInfo.ConnectionState != ConnectionState.Connected || !connectionInfo.PooledLdapConnection.IsUp)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string, int, string>((long)this.GetHashCode(), "Connection to {0} is {1}{2}, skipping.", connectionInfo.ADServerInfo.FqdnPlusPort, (int)connectionInfo.ConnectionState, (connectionInfo.ConnectionState == ConnectionState.Connected) ? (connectionInfo.PooledLdapConnection.IsUp ? "and UP" : "and DOWN") : string.Empty);
                        if (flag && this.IsServerMatch(i, serverName, port))
                        {
                            serverConnectionPresentButDownOrDisconnected = true;
                            extraDownOrDisconnectedException             = connectionInfo.LastLdapException;
                            ExTraceGlobals.GetConnectionTracer.TraceError <string, int>((long)this.GetHashCode(), "LdapConnectionPool.GetConnection: {0}:{1} is present but is down or disconnected", serverName, port);
                            break;
                        }
                    }
                    else
                    {
                        int num3 = int.MinValue;
                        if (flag3)
                        {
                            num3  = this.CalculateLoadBalancingQuality(i);
                            flag4 = (connectionInfo.PooledLdapConnection.OutstandingRequestCount == 0);
                        }
                        else if (flag)
                        {
                            num3  = this.CalculateQualityByServerMatch(i, serverName, port);
                            flag4 = (num3 > num);
                        }
                        else
                        {
                            if (this.IsDomainMatch(i, domain))
                            {
                                num3 = this.CalculateLoadBalancingQuality(i);
                            }
                            flag4 = (num3 > num);
                        }
                        ExTraceGlobals.GetConnectionTracer.TraceDebug((long)this.GetHashCode(), "Connection to {0}:{1} has quality {2}. suitableConnectionFound {3}", new object[]
                        {
                            connectionInfo.ADServerInfo.Fqdn,
                            connectionInfo.ADServerInfo.Port,
                            num3,
                            flag4
                        });
                        if (num3 > num)
                        {
                            num  = num3;
                            num2 = i;
                        }
                    }
                }
                if (num2 > -1)
                {
                    ConnectionInfo connectionInfo2 = this.connectionInfos[num2];
                    connectionInfo2.ADServerInfo.IncrementRequestCount();
                    Interlocked.Increment(ref this.totalRequestCount);
                    Interlocked.Exchange(ref this.lastUsedConnectionIndex, num2);
                    result = connectionInfo2.PooledLdapConnection.BorrowFromPool();
                    ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Returning connection to {0}.", connectionInfo2.ADServerInfo.FqdnPlusPort);
                }
            }
            finally
            {
                try
                {
                    this.poolLock.ReleaseReaderLock();
                    ExTraceGlobals.GetConnectionTracer.TracePerformance <ulong>((long)this.GetHashCode(), "GetConnection time spend {0} milliseconds.", Globals.GetTickDifference(tickCount, Environment.TickCount));
                }
                catch (ApplicationException)
                {
                }
            }
            return(result);
        }
示例#12
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter(new object[]
     {
         this.DataObject
     });
     try
     {
         try
         {
             MailboxDatabase mailboxDatabase  = this.ConfigurationSession.Read <MailboxDatabase>((ADObjectId)this.DataObject.Identity);
             Server          server           = null;
             ADComputer      adcomputer       = null;
             bool            useConfigNC      = this.ConfigurationSession.UseConfigNC;
             bool            useGlobalCatalog = this.ConfigurationSession.UseGlobalCatalog;
             if (mailboxDatabase != null)
             {
                 server = mailboxDatabase.GetServer();
                 try
                 {
                     this.ConfigurationSession.UseConfigNC      = false;
                     this.ConfigurationSession.UseGlobalCatalog = true;
                     adcomputer = ((ITopologyConfigurationSession)this.ConfigurationSession).FindComputerByHostName(server.Name);
                 }
                 finally
                 {
                     this.ConfigurationSession.UseConfigNC      = useConfigNC;
                     this.ConfigurationSession.UseGlobalCatalog = useGlobalCatalog;
                 }
                 if (adcomputer == null)
                 {
                     base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorDBOwningServerNotFound(mailboxDatabase.Identity.ToString())), ErrorCategory.ObjectNotFound, server.Identity);
                 }
                 ADObjectId adobjectId = adcomputer.Id.DomainId;
                 adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects");
                 adobjectId = adobjectId.GetChildId("SystemMailbox" + mailboxDatabase.Guid.ToString("B"));
                 string identity = adobjectId.ToDNString();
                 GeneralMailboxIdParameter generalMailboxIdParameter = GeneralMailboxIdParameter.Parse(identity);
                 base.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(generalMailboxIdParameter, this.RecipientSession, typeof(ADRecipient), null));
                 IEnumerable <ADSystemMailbox> objects = generalMailboxIdParameter.GetObjects <ADSystemMailbox>(adobjectId, this.RecipientSession);
                 using (IEnumerator <ADSystemMailbox> enumerator = objects.GetEnumerator())
                 {
                     if (enumerator.MoveNext())
                     {
                         ADSystemMailbox adsystemMailbox = enumerator.Current;
                     }
                     else
                     {
                         NewMailboxDatabase.SaveSystemMailbox(mailboxDatabase, mailboxDatabase.GetServer(), base.RootOrgContainerId, (ITopologyConfigurationSession)this.ConfigurationSession, this.RecipientSession, null, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                     }
                 }
             }
             base.WriteVerbose(Strings.VerboseMountDatabase(this.Identity.ToString()));
             this.RequestMount(MountFlags.None);
             if (!this.DataObject.DatabaseCreated)
             {
                 this.DataObject.DatabaseCreated = true;
                 base.InternalProcessRecord();
             }
         }
         catch (AmServerException ex)
         {
             Exception ex2;
             if (ex.TryGetInnerExceptionOfType(out ex2))
             {
                 TaskLogger.Trace("Database already mounted (database={0}, exception={1})", new object[]
                 {
                     this.DataObject.Name,
                     ex2.Message
                 });
             }
             else if (ex.TryGetInnerExceptionOfType(out ex2) || ex.TryGetInnerExceptionOfType(out ex2))
             {
                 this.AttemptForcedMountIfNecessary(this.Force, Strings.ContinueMountWhenDBFilesNotExist, Strings.VerboseMountDatabaseForcely(this.Identity.ToString()), Strings.ErrorFailedToMountReplicatedDbWithMissingEdbFile(this.Identity.ToString()), ex, MountFlags.ForceDatabaseCreation);
             }
             else if (ex.TryGetInnerExceptionOfType(out ex2))
             {
                 this.PromptForMountIfNecessary(this.AcceptDataLoss, Strings.ContinueMountWithDataLoss, Strings.VerboseMountDatabaseDataLoss(this.Identity.ToString()), MountFlags.AcceptDataLoss);
             }
             else
             {
                 TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[]
                 {
                     ex.Message
                 });
                 base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex.Message), ex), ErrorCategory.InvalidOperation, this.DataObject.Identity);
             }
         }
     }
     catch (AmServerException ex3)
     {
         TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[]
         {
             ex3.Message
         });
         base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex3.Message), ex3), ErrorCategory.InvalidOperation, this.DataObject.Identity);
     }
     catch (AmServerTransientException ex4)
     {
         TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[]
         {
             ex4.Message
         });
         base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex4.Message), ex4), ErrorCategory.InvalidOperation, this.DataObject.Identity);
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
示例#13
0
        private void ValidateParameters()
        {
            if (this.DomainName == null || string.IsNullOrEmpty(this.DomainName.Domain))
            {
                base.WriteError(new NoAccountNamespaceException(), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            if (this.DataObject.DelegationTrustLink == null || this.DataObject.AccountNamespace == null || string.IsNullOrEmpty(this.DataObject.AccountNamespace.Domain))
            {
                base.WriteError(new NoTrustConfiguredException(), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            ADObjectId deletedObjectsContainer = base.GlobalConfigSession.DeletedObjectsContainer;
            ADObjectId adobjectId = ADObjectIdResolutionHelper.ResolveDN(this.DataObject.DelegationTrustLink);

            if (adobjectId.Parent.Equals(deletedObjectsContainer))
            {
                base.WriteError(new NoTrustConfiguredException(), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            this.federationTrust = base.GlobalConfigSession.Read <FederationTrust>(adobjectId);
            if (this.federationTrust == null)
            {
                base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorFederationTrustNotFound(adobjectId.ToDNString())), ErrorCategory.ObjectNotFound, null);
            }
            this.matchedAcceptedDomain = base.GetAcceptedDomain(this.DomainName, false);
            if (this.matchedAcceptedDomain.FederatedOrganizationLink != null && !this.matchedAcceptedDomain.FederatedOrganizationLink.Parent.Equals(deletedObjectsContainer))
            {
                base.WriteError(new DomainAlreadyFederatedException(this.DomainName.Domain), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            TaskLogger.LogExit();
        }