예제 #1
0
        public static ADUser GetDiscoveryUserMailbox(IRecipientSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            IRecipientSession recipientSession = session;

            if (recipientSession.ConfigScope != ConfigScopes.TenantLocal)
            {
                recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(session.DomainController, true, ConsistencyMode.PartiallyConsistent, session.NetworkCredential, session.SessionSettings, 156, "GetDiscoveryUserMailbox", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxDataProvider.cs");
                recipientSession.UseGlobalCatalog    = true;
                recipientSession.EnforceDefaultScope = session.EnforceDefaultScope;
            }
            ADPagedReader <ADRecipient> adpagedReader = recipientSession.FindPaged(null, QueryScope.SubTree, MailboxDataProvider.DiscoveryUserMailboxFilter, null, 10);

            foreach (ADRecipient adrecipient in adpagedReader)
            {
                ADUser aduser  = (ADUser)adrecipient;
                ADUser aduser2 = aduser;
                if (ExchangePrincipal.FromADUser(recipientSession.SessionSettings, aduser2, RemotingOptions.AllowCrossSite).MailboxInfo.Location.ServerVersion >= Server.E14SP1MinVersion)
                {
                    return(aduser2);
                }
            }
            throw new ObjectNotFoundException(ServerStrings.UserDiscoveryMailboxNotFound);
        }
        private void RemoveAllEdgeSyncedRecipients()
        {
            IRecipientSession           tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 324, "RemoveAllEdgeSyncedRecipients", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\ExchangeServer\\RemoveEdgeSubscription.cs");
            ADPagedReader <ADRecipient> adpagedReader = tenantOrRootOrgRecipientSession.FindPaged(null, QueryScope.SubTree, new TextFilter(ADRecipientSchema.EmailAddresses, "sh:", MatchOptions.Prefix, MatchFlags.IgnoreCase), null, 0);

            foreach (ADRecipient instanceToDelete in adpagedReader)
            {
                tenantOrRootOrgRecipientSession.Delete(instanceToDelete);
            }
        }
        // Token: 0x06000066 RID: 102 RVA: 0x00003074 File Offset: 0x00001274
        private static ADUser[] GlobalFindAllArbitrationMailboxes()
        {
            Server localhost = AuditLogSearchContext.Localhost;

            if (!MapiTaskHelper.IsDatacenter)
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 99, "GlobalFindAllArbitrationMailboxes", "f:\\15.00.1497\\sources\\dev\\Management\\src\\ServiceHost\\Servicelets\\AuditLogSearch\\Program\\AuditLogSearchServicelet.cs");
                return(tenantOrRootOrgRecipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterForAuditLog(localhost.ExchangeLegacyDN), null, true, null, 0).ToArray <ADUser>());
            }
            return(PartitionDataAggregator.FindAllArbitrationMailboxes(localhost.ExchangeLegacyDN));
        }
        public static ADUser[] FindAllArbitrationMailboxes(string legDN)
        {
            List <ADUser> list = new List <ADUser>();

            foreach (PartitionId partitionId in ADAccountPartitionLocator.GetAllAccountPartitionIds())
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 367, "FindAllArbitrationMailboxes", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\PartitionDataAggregator.cs");
                ADUser[]          collection = tenantOrRootOrgRecipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterForAuditLog(legDN), null, true, null, 0).ToArray <ADUser>();
                list.AddRange(collection);
            }
            return(list.ToArray());
        }
예제 #5
0
        private static List <ADUser> InternalGetOrganizationMailboxesByCapability(IRecipientSession session, OrganizationCapability capability, QueryFilter optionalFilter)
        {
            EnumValidator.ThrowIfInvalid <OrganizationCapability>(capability, "capability");
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            List <ADUser> list        = new List <ADUser>();
            QueryFilter   queryFilter = new AndFilter(new QueryFilter[]
            {
                OrganizationMailbox.OrganizationMailboxFilterBase,
                new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.RawCapabilities, capability)
            });

            if (optionalFilter != null)
            {
                queryFilter = QueryFilter.AndTogether(new QueryFilter[]
                {
                    queryFilter,
                    optionalFilter
                });
            }
            ADObjectId rootId;
            QueryScope scope;

            OrganizationMailbox.GetQueryParameters(session, out rootId, out scope);
            ADPagedReader <ADRecipient> adpagedReader = session.FindPaged(rootId, scope, queryFilter, new SortBy(ADObjectSchema.WhenCreated, SortOrder.Ascending), 0);

            if (adpagedReader != null)
            {
                foreach (ADRecipient adrecipient in adpagedReader)
                {
                    ADUser aduser = adrecipient as ADUser;
                    if (aduser != null)
                    {
                        list.Add(aduser);
                    }
                }
            }
            return(list);
        }
예제 #6
0
        // Token: 0x06000AC2 RID: 2754 RVA: 0x00046A90 File Offset: 0x00044C90
        private Hashtable GetUMEnabledUsersEnterprise(MailboxDatabase database)
        {
            Hashtable hashtable = new Hashtable();

            if (database != null)
            {
                QueryFilter                 umenabledUserQueryFilter = UMMailbox.GetUMEnabledUserQueryFilter(database);
                ADSessionSettings           sessionSettings          = ADSessionSettings.FromRootOrgScopeSet();
                IRecipientSession           recipientSession         = DirectorySessionFactory.Default.CreateRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 1260, "GetUMEnabledUsersEnterprise", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\mwi\\MwiAssistant.cs");
                ADPagedReader <ADRecipient> adpagedReader            = recipientSession.FindPaged(null, QueryScope.SubTree, umenabledUserQueryFilter, null, 0);
                foreach (ADRecipient adrecipient in adpagedReader)
                {
                    ADUser aduser = adrecipient as ADUser;
                    if (aduser != null)
                    {
                        hashtable.Add(aduser.ExchangeGuid, aduser.OrganizationId);
                    }
                }
            }
            return(hashtable);
        }
        public override void ReadData(IConfigurationSession configurationSession)
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.FullyConsistent, configurationSession.SessionSettings, 104, "ReadData", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\SystemConfiguration\\ConfigurationCache\\TenantPublicFolderConfiguration.cs");

            this.localPublicFolderRecipients  = new Hashtable();
            this.remotePublicFolderRecipients = new Hashtable();
            this.estimatedSize = 0L;
            Organization orgContainer = configurationSession.GetOrgContainer();

            this.hierarchyMailboxInformation = orgContainer.DefaultPublicFolderMailbox;
            this.publicFoldersDeploymentType = orgContainer.PublicFoldersEnabled;
            this.estimatedSize  += (long)this.hierarchyMailboxInformation.ItemSize;
            this.HeuristicsFlags = orgContainer.Heuristics;
            this.estimatedSize  += 4L;
            this.estimatedSize  += 4L;
            ADRawEntry[] array = Array <ADRawEntry> .Empty;
            if (this.hierarchyMailboxInformation.HierarchyMailboxGuid != Guid.Empty)
            {
                array = tenantOrRootOrgRecipientSession.FindPaged <ADRawEntry>(null, QueryScope.SubTree, Filters.GetRecipientTypeDetailsFilterOptimization(RecipientTypeDetails.PublicFolderMailbox), new SortBy(ADObjectSchema.WhenCreatedUTC, SortOrder.Ascending), 0, TenantPublicFolderConfiguration.PublicFolderRecipientProperties).ReadAllPages();
            }
            List <PublicFolderRecipient> list = new List <PublicFolderRecipient>();

            if (this.PublicFoldersDeploymentType == PublicFoldersDeployment.Remote && orgContainer.RemotePublicFolderMailboxes.Count > 0)
            {
                ADObjectId[] array2 = orgContainer.RemotePublicFolderMailboxes.ToArray();
                foreach (ADObjectId adobjectId in array2)
                {
                    if (!adobjectId.IsDeleted)
                    {
                        MiniRecipient miniRecipient = tenantOrRootOrgRecipientSession.ReadMiniRecipient(adobjectId, null);
                        if (miniRecipient != null)
                        {
                            PublicFolderRecipient publicFolderRecipient = new PublicFolderRecipient(miniRecipient.Name, Guid.Empty, null, miniRecipient.PrimarySmtpAddress, miniRecipient.Id, false);
                            this.estimatedSize += publicFolderRecipient.ItemSize;
                            this.remotePublicFolderRecipients.Add(publicFolderRecipient.ObjectId, publicFolderRecipient);
                            list.Add(publicFolderRecipient);
                        }
                    }
                }
                if (list.Count > 0)
                {
                    this.consistentHashSetForRemoteMailboxes = new ConsistentHashSet <PublicFolderRecipient, Guid>(list.ToArray(), 1, 64);
                    this.estimatedSize += this.consistentHashSetForRemoteMailboxes.ItemSize;
                }
            }
            list.Clear();
            if (array.Length > 0)
            {
                for (int j = 0; j < array.Length; j++)
                {
                    PublicFolderRecipient publicFolderRecipient = new PublicFolderRecipient((string)array[j][ADRecipientSchema.DisplayName], (Guid)array[j][ADMailboxRecipientSchema.ExchangeGuid], (ADObjectId)array[j][ADMailboxRecipientSchema.Database], (SmtpAddress)array[j][ADRecipientSchema.PrimarySmtpAddress], (ADObjectId)array[j][ADObjectSchema.Id], true);
                    this.estimatedSize += publicFolderRecipient.ItemSize;
                    this.localPublicFolderRecipients.Add(publicFolderRecipient.ObjectId, publicFolderRecipient);
                    if (!(bool)array[j][ADRecipientSchema.IsExcludedFromServingHierarchy] && (bool)array[j][ADRecipientSchema.IsHierarchyReady])
                    {
                        list.Add(publicFolderRecipient);
                    }
                }
                if (list.Count > 0)
                {
                    this.consistentHashSetForLocalMailboxes = new ConsistentHashSet <PublicFolderRecipient, Guid>(list.ToArray(), 1, 64);
                    this.estimatedSize += this.consistentHashSetForLocalMailboxes.ItemSize;
                }
            }
        }
예제 #8
0
        private IList <ExchangePrincipal> GetSyncMailboxPrincipals(Guid mailboxDatabaseGuid, IDirectorySession configSession)
        {
            List <ExchangePrincipal> list = new List <ExchangePrincipal>();
            ADObjectId id = new ADObjectId(mailboxDatabaseGuid);

            Result <MailboxDatabase>[] dataBases         = null;
            ADOperationResult          adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                dataBases = configSession.FindByADObjectIds <MailboxDatabase>(new ADObjectId[]
                {
                    id
                });
            }, 3);

            if (!adoperationResult.Succeeded)
            {
                this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception);
            }
            if (dataBases != null && dataBases.Length > 0)
            {
                PartitionId[] allAccountPartitionIds = ADAccountPartitionLocator.GetAllAccountPartitionIds();
                for (int i = 0; i < allAccountPartitionIds.Length; i++)
                {
                    PartitionId       partitionId      = allAccountPartitionIds[i];
                    IRecipientSession recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 238, "GetSyncMailboxPrincipals", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\UnifiedPolicy\\NotificationLoader.cs");
                    ADUser[]          arbMbxs          = null;
                    adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
                    {
                        arbMbxs = recipientSession.FindPaged <ADUser>(RecipientFilterHelper.DiscoveryMailboxFilterUnifiedPolicy(dataBases[0].Data.Id), null, true, null, 0).ToArray <ADUser>();
                    }, 3);
                    if (!adoperationResult.Succeeded)
                    {
                        this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: failed to find sync mailboxes in database {0} in active directory because of {1}", mailboxDatabaseGuid, adoperationResult.Exception), adoperationResult.Exception);
                    }
                    if (arbMbxs != null && arbMbxs.Length > 0)
                    {
                        ADUser[] arbMbxs2 = arbMbxs;
                        int      j        = 0;
                        while (j < arbMbxs2.Length)
                        {
                            ADUser aduser = arbMbxs2[j];
                            this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: found sync mailbox {0} in database {1} in partition {2}", aduser.UserPrincipalName, mailboxDatabaseGuid, partitionId), null);
                            ExchangePrincipal item = null;
                            try
                            {
                                item = ExchangePrincipal.FromADUser(ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(aduser.OrganizationId), aduser, RemotingOptions.LocalConnectionsOnly);
                            }
                            catch (StoragePermanentException exception)
                            {
                                this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StoragePermanentException in ExchangePrincipal construction", aduser.UserPrincipalName), exception);
                                goto IL_20F;
                            }
                            catch (StorageTransientException exception2)
                            {
                                this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Error, string.Format("GetSyncMailboxPrincipals: sync mailbox {0} is skipped because of StorageTransientException in ExchangePrincipal construction", aduser.UserPrincipalName), exception2);
                                goto IL_20F;
                            }
                            goto IL_207;
IL_20F:
                            j++;
                            continue;
IL_207:
                            list.Add(item);
                            goto IL_20F;
                        }
                    }
                    else
                    {
                        this.logger.LogOneEntry("NotificationLoader", string.Empty, ExecutionLog.EventType.Verbose, string.Format("GetSyncMailboxPrincipals: there is no sync mailboxes in database {0} in active directory", mailboxDatabaseGuid), null);
                    }
                }
            }
            return(list);
        }
예제 #9
0
        internal IEnumerable <ADRecipient> FindMatchingRecipientsPaged(IRecipientSession recipientSession, OrganizationId organizationId, ADObjectId rootId, bool fixMissingAlias)
        {
            if (recipientSession == null)
            {
                throw new ArgumentNullException("recipientSession");
            }
            if (organizationId != OrganizationId.ForestWideOrgId)
            {
            }
            bool isSearch = true;
            List <QueryFilter> filters = new List <QueryFilter>();

            filters.Add(new ExistsFilter(ADRecipientSchema.Alias));
            if (!string.IsNullOrEmpty(this.LdapRecipientFilter))
            {
                filters.Add(new CustomLdapFilter(this.LdapRecipientFilter));
            }
            QueryFilter filter = null;

            if (fixMissingAlias)
            {
                QueryFilter queryFilter = new AndFilter(new QueryFilter[]
                {
                    new NotFilter(new ExistsFilter(ADRecipientSchema.Alias)),
                    new OrFilter(new QueryFilter[]
                    {
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "msExchDynamicDistributionList"),
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "publicFolder"),
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "msExchPublicMDB"),
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "msExchSystemMailbox"),
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "msExchExchangeServerRecipient"),
                        new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.ObjectCategory, "exchangeAdminService")
                    })
                });
                if (string.IsNullOrEmpty(this.LdapRecipientFilter))
                {
                    filter = queryFilter;
                }
                else
                {
                    filter = new OrFilter(new QueryFilter[]
                    {
                        new AndFilter(filters.ToArray()),
                        queryFilter
                    });
                }
            }
            else if (!string.IsNullOrEmpty(this.LdapRecipientFilter))
            {
                filter = new AndFilter(filters.ToArray());
            }
            else
            {
                isSearch = false;
            }
            if (isSearch)
            {
                ADPagedReader <ADRecipient> pagedReader = recipientSession.FindPaged(rootId ?? this.RecipientContainer, QueryScope.SubTree, filter, null, 0);
                foreach (ADRecipient item in pagedReader)
                {
                    yield return(item);
                }
                if (organizationId != OrganizationId.ForestWideOrgId && this.RecipientContainer == null && rootId == null)
                {
                    bool originalUseConfigNC = recipientSession.UseConfigNC;
                    recipientSession.UseConfigNC = !originalUseConfigNC;
                    try
                    {
                        pagedReader = recipientSession.FindPaged(null, QueryScope.SubTree, filter, null, 0);
                        foreach (ADRecipient item2 in pagedReader)
                        {
                            yield return(item2);
                        }
                    }
                    finally
                    {
                        recipientSession.UseConfigNC = originalUseConfigNC;
                    }
                }
            }
            yield break;
        }
예제 #10
0
        internal static void UpdateRecipients(AddressBookBase abb, ADObjectId[] removedAbbTreeIds, string domainController, IRecipientSession globalCatalogSession, Task.TaskWarningLoggingDelegate writeWarning, WriteProgress writeProgress, Cmdlet cmdlet)
        {
            if (abb == null)
            {
                throw new ArgumentNullException("abb");
            }
            if (Guid.Empty == abb.Guid)
            {
                throw new ArgumentNullException("abb.Guid");
            }
            if (writeWarning == null)
            {
                throw new ArgumentNullException("writeWarning");
            }
            if (writeProgress == null)
            {
                throw new ArgumentNullException("writeProgress");
            }
            int num = 0;

            try
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    return;
                }
                string domainControllerFqdn = null;
                if (!string.IsNullOrEmpty(domainController))
                {
                    try
                    {
                        domainControllerFqdn = SystemConfigurationTasksHelper.GetConfigurationDomainControllerFqdn(domainController);
                    }
                    catch (SocketException ex)
                    {
                        writeWarning(Strings.ErrorResolveFqdnForDomainController(domainController, ex.Message));
                        return;
                    }
                }
                if (string.IsNullOrEmpty(abb.LdapRecipientFilter) || removedAbbTreeIds != null)
                {
                    List <Guid> list = new List <Guid>();
                    if (removedAbbTreeIds != null)
                    {
                        foreach (ADObjectId adobjectId in removedAbbTreeIds)
                        {
                            list.Add(adobjectId.ObjectGuid);
                        }
                        list.Sort();
                    }
                    else
                    {
                        list.Add(abb.Guid);
                    }
                    QueryFilter[] array = null;
                    int           num2  = LdapFilterBuilder.MaxCustomFilterTreeSize - 1;
                    for (int j = 0; j < list.Count; j += num2)
                    {
                        int num3 = Math.Min(num2, list.Count - j);
                        if (array == null || array.Length != num3)
                        {
                            array = new QueryFilter[num3];
                        }
                        for (int k = 0; k < num3; k++)
                        {
                            array[k] = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.AddressListMembership, new ADObjectId(list[k + j]));
                        }
                        QueryFilter queryFilter = new OrFilter(array);
                        ADPagedReader <ADRecipient> adpagedReader = globalCatalogSession.FindPaged(null, QueryScope.SubTree, queryFilter, null, 0);
                        using (IEnumerator <ADRecipient> enumerator = adpagedReader.GetEnumerator())
                        {
                            UpdateAddressBookBase <TIdParameter> .InternalUpdateRecipients(enumerator, null, queryFilter, list, domainControllerFqdn, globalCatalogSession, writeWarning, writeProgress, cmdlet, ref num);
                        }
                    }
                }
                else
                {
                    IEnumerator <ADRecipient> enumerator2 = abb.FindUpdatingRecipientsPaged(globalCatalogSession, null).GetEnumerator();
                    UpdateAddressBookBase <TIdParameter> .InternalUpdateRecipients(enumerator2, abb, null, null, domainControllerFqdn, globalCatalogSession, writeWarning, writeProgress, cmdlet, ref num);
                }
            }
            finally
            {
                if (cmdlet != null && cmdlet.Stopping)
                {
                    ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_RecipientsUpdateForAddressBookCancelled, new string[]
                    {
                        string.Format("{0} (objectGUID=<{1}>)", abb.DistinguishedName ?? string.Empty, abb.Guid.ToString()),
                        abb.LdapRecipientFilter,
                        ADRecipientSchema.AddressListMembership.Name
                    });
                }
            }
            if (num != 0)
            {
                writeProgress(Strings.ProgressActivityUpdateRecipient, Strings.ProgressStatusFinished, 100);
            }
        }