Ejemplo n.º 1
0
        internal static bool IsTenantIdentity(ADObjectId id, string partitionFqdn)
        {
            if (ADSession.IsBoundToAdam || id.DomainId == null)
            {
                return(false);
            }
            if (!string.Equals(id.GetPartitionId().ForestFQDN, partitionFqdn, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("Object partition FQDN doesn't match partitionFqdn parameter.");
            }
            ADObjectId configurationNamingContext = ADSession.GetConfigurationNamingContext(partitionFqdn);

            if (id.Equals(configurationNamingContext))
            {
                return(false);
            }
            ADObjectId domainNamingContext = ADSession.GetDomainNamingContext(partitionFqdn);

            if (id.Equals(domainNamingContext))
            {
                return(false);
            }
            ADObjectId configurationUnitsRoot = ADSession.GetConfigurationUnitsRoot(partitionFqdn);

            if (id.IsDescendantOf(configurationUnitsRoot))
            {
                return(true);
            }
            ADObjectId hostedOrganizationsRoot = ADSession.GetHostedOrganizationsRoot(partitionFqdn);

            return(id.IsDescendantOf(hostedOrganizationsRoot) && !id.Equals(hostedOrganizationsRoot));
        }
 internal bool IsUnderTenantScope(ADObjectId value)
 {
     if (string.IsNullOrEmpty(value.DistinguishedName))
     {
         throw new ArgumentException("value.DistinguishedName must not be null");
     }
     return(value.IsDescendantOf(this.TenantConfigurationUnitRoot) || value.IsDescendantOf(this.TenantOrganizationUnit));
 }
        public static bool TryGetTenantRelocationStateByObjectId(ADObjectId identity, out TenantRelocationState state, out bool isSourceTenant)
        {
            ArgumentValidator.ThrowIfNull("identity", identity);
            state          = null;
            isSourceTenant = true;
            PartitionId partitionId = identity.GetPartitionId();

            if (!ForestTenantRelocationsCache.IsTenantRelocationAllowed(partitionId.ForestFQDN))
            {
                return(false);
            }
            ITenantConfigurationSession tenantConfigurationSession = DirectorySessionFactory.Default.CreateTenantConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsPartitionId(partitionId), 595, "TryGetTenantRelocationStateByObjectId", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\RelocationCache\\TenantRelocationStateCache.cs");
            ADObjectId configurationUnitsRoot = tenantConfigurationSession.GetConfigurationUnitsRoot();

            if (configurationUnitsRoot.Equals(identity))
            {
                return(false);
            }
            ADObjectId adobjectId = null;

            if (identity.IsDescendantOf(configurationUnitsRoot))
            {
                adobjectId = identity.GetFirstGenerationDecendantOf(configurationUnitsRoot);
            }
            else
            {
                ADObjectId hostedOrganizationsRoot = tenantConfigurationSession.GetHostedOrganizationsRoot();
                if (hostedOrganizationsRoot.Equals(identity))
                {
                    return(false);
                }
                if (identity.IsDescendantOf(hostedOrganizationsRoot))
                {
                    adobjectId = identity.GetFirstGenerationDecendantOf(hostedOrganizationsRoot);
                }
            }
            if (adobjectId == null)
            {
                return(false);
            }
            try
            {
                state = TenantRelocationStateCache.GetTenantRelocationState(adobjectId.Name, partitionId, out isSourceTenant, false);
            }
            catch (CannotResolveTenantNameException)
            {
                return(false);
            }
            return(true);
        }
        private bool TryGetSupportedSharedConfigurations(IConfigurationSession session, string cuObjectDN, TenantRelocationSyncData syncData, out MultiValuedProperty <ADObjectId> links)
        {
            ADObjectId adobjectId  = new ADObjectId(cuObjectDN);
            bool       useConfigNC = session.UseConfigNC;

            session.UseConfigNC = adobjectId.IsDescendantOf(syncData.Target.PartitionConfigNcRoot);
            bool result;

            try
            {
                ADRawEntry adrawEntry = session.ReadADRawEntry(adobjectId, ExchangeConfigurationUnitHandler.sharedConfigurationsPropertyList);
                if (adrawEntry == null)
                {
                    links  = null;
                    result = false;
                }
                else
                {
                    links  = (MultiValuedProperty <ADObjectId>)adrawEntry[OrganizationSchema.SupportedSharedConfigurations];
                    result = true;
                }
            }
            finally
            {
                session.UseConfigNC = useConfigNC;
            }
            return(result);
        }
        public void ProcessSecurityDescriptor(ADObjectId sourceId, ADObjectId targetId, bool forceResetTargetSD)
        {
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)this.GetHashCode(), "ProcessSecurityDescriptor: process object {0}.", sourceId.DistinguishedName);
            RawSecurityDescriptor rsd            = TenantRelocationSecurityDescriptorHandler.ReadSecurityDescriptorWrapper(this.sourceSession, sourceId, sourceId.IsDescendantOf(this.sourceConfigNC));
            List <GenericAce>     customizedAces = this.GetCustomizedAces(rsd);

            if (!forceResetTargetSD && customizedAces.Count == 0)
            {
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)this.GetHashCode(), "ProcessSecurityDescriptor: no customized ACEs found on source found {0}, skip update.", sourceId.DistinguishedName);
                return;
            }
            bool useConfigNC = targetId.IsDescendantOf(this.targetConfigNC);
            RawSecurityDescriptor targetSd = TenantRelocationSecurityDescriptorHandler.ReadSecurityDescriptorWrapper(this.targetSession, targetId, useConfigNC);
            RawSecurityDescriptor sd       = this.ApplyAcesToTargetSecurityDescriptor(targetSd, customizedAces);
            bool useConfigNC2 = this.targetSession.UseConfigNC;

            this.targetSession.UseConfigNC = useConfigNC;
            try
            {
                this.targetSession.SaveSecurityDescriptor(targetId, sd);
            }
            finally
            {
                this.targetSession.UseConfigNC = useConfigNC2;
            }
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)this.GetHashCode(), "ProcessSecurityDescriptor: process done object {0}.", sourceId.DistinguishedName);
        }
Ejemplo n.º 6
0
 private static bool IsRoleInListOrDerived(ADObjectId roleId, IList <ExchangeRole> roles)
 {
     foreach (ExchangeRole exchangeRole in roles)
     {
         if (roleId.IsDescendantOf(exchangeRole.Id))
         {
             return(true);
         }
     }
     return(false);
 }
        internal static IEnumerable <ExtendedSecurityPrincipal> PerformSearch(ExtendedSecurityPrincipalSearcher searcher, IConfigDataProvider session, ADObjectId rootId, ADObjectId includeDomailLocalFrom, MultiValuedProperty <SecurityPrincipalType> types)
        {
            if (types.Contains(SecurityPrincipalType.WellknownSecurityPrincipal))
            {
                IRecipientSession     dataSession     = (IRecipientSession)session;
                ADSessionSettings     sessionSettings = ADSessionSettings.FromRootOrgScopeSet();
                IConfigurationSession configSession;
                if (dataSession.ConfigScope == ConfigScopes.TenantSubTree)
                {
                    configSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(dataSession.DomainController, dataSession.ReadOnly, dataSession.ConsistencyMode, dataSession.NetworkCredential, sessionSettings, dataSession.ConfigScope, 60, "PerformSearch", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Management\\ExtendedSecurityPrincipalSearchHelper.cs");
                }
                else
                {
                    configSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(dataSession.DomainController, dataSession.ReadOnly, dataSession.ConsistencyMode, dataSession.NetworkCredential, sessionSettings, 70, "PerformSearch", "f:\\15.00.1497\\sources\\dev\\data\\src\\directory\\Management\\ExtendedSecurityPrincipalSearchHelper.cs");
                }
                foreach (ExtendedSecurityPrincipal wellknown in searcher(configSession, null, ExtendedSecurityPrincipalSearchHelper.GenerateTargetFilterForWellknownSecurityPrincipal()))
                {
                    yield return(wellknown);
                }
            }
            IRecipientSession recipientSession = (IRecipientSession)session;

            if (types.Contains(SecurityPrincipalType.GlobalSecurityGroup) || types.Contains(SecurityPrincipalType.UniversalSecurityGroup) || types.Contains(SecurityPrincipalType.User) || types.Contains(SecurityPrincipalType.Group))
            {
                recipientSession.UseGlobalCatalog = (rootId == null);
                foreach (ExtendedSecurityPrincipal recipient in searcher(recipientSession, rootId, ExtendedSecurityPrincipalSearchHelper.GenerateTargetFilterForUserAndNonDomainLocalGroup(types)))
                {
                    yield return(recipient);
                }
            }
            if (includeDomailLocalFrom != null)
            {
                recipientSession.UseGlobalCatalog = false;
                ADObjectId searchRoot = null;
                if (rootId == null || includeDomailLocalFrom.IsDescendantOf(rootId))
                {
                    searchRoot = includeDomailLocalFrom;
                }
                else if (rootId.DomainId.Equals(includeDomailLocalFrom))
                {
                    searchRoot = rootId;
                }
                if (searchRoot != null)
                {
                    foreach (ExtendedSecurityPrincipal group in searcher(recipientSession, searchRoot, ExtendedSecurityPrincipalSearchHelper.GenerateTargetFilterForSecurityGroup(GroupTypeFlags.DomainLocal)))
                    {
                        yield return(group);
                    }
                }
            }
            yield break;
        }
 internal IConfigurationSession GetWritableSession(ADObjectId identity)
 {
     this.writableConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromAllTenantsOrRootOrgAutoDetect(identity), 106, "GetWritableSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\permission\\SetADPermissionTaskBase.cs");
     if (identity.IsDescendantOf(this.writableConfigurationSession.ConfigurationNamingContext))
     {
         return(this.writableConfigurationSession);
     }
     if (base.DomainControllerDomainId == null || base.DomainControllerDomainId.Equals(identity.DomainId))
     {
         return(this.writableSessionOnSpcecifiedDC);
     }
     return(this.writableSession);
 }
Ejemplo n.º 9
0
 internal static EphemeralIdTable.NamingContext GetNamingContext(ADObjectId id)
 {
     if (id.IsDescendantOf(ADSession.GetConfigurationNamingContext(id.GetPartitionId().ForestFQDN)))
     {
         if (!ADSession.IsTenantIdentity(id, id.GetPartitionId().ForestFQDN))
         {
             return(EphemeralIdTable.NamingContext.Config);
         }
         return(EphemeralIdTable.NamingContext.TenantConfig);
     }
     else
     {
         if (!ADSession.IsTenantIdentity(id, id.GetPartitionId().ForestFQDN))
         {
             return(EphemeralIdTable.NamingContext.Domain);
         }
         if (!id.IsDescendantOf(ADSession.GetConfigurationUnitsRoot(id.GetPartitionId().ForestFQDN)))
         {
             return(EphemeralIdTable.NamingContext.Domain);
         }
         return(EphemeralIdTable.NamingContext.TenantConfig);
     }
 }
 private ADObjectId GetRoleGroupIdForEmptinessCheck(ADObjectId roleGroupId)
 {
     if (this.sharedConfig == null || !roleGroupId.IsDescendantOf(this.sharedConfig.SharedConfigId.OrganizationalUnit))
     {
         return(roleGroupId);
     }
     ADObjectId[] tinyTenantGroupIds = this.sharedConfig.GetTinyTenantGroupIds(new ADObjectId[]
     {
         roleGroupId
     });
     if (!tinyTenantGroupIds.IsNullOrEmpty <ADObjectId>())
     {
         return(tinyTenantGroupIds[0]);
     }
     return(null);
 }
 private ADObjectId GetRoleGroupIdForRoleAssignementCheck(ADObjectId roleGroupId)
 {
     if (this.sharedConfig == null || !roleGroupId.IsDescendantOf(this.sharedConfig.TinyTenantId.OrganizationalUnit))
     {
         return(roleGroupId);
     }
     ADObjectId[] sharedRoleGroupIds = this.sharedConfig.GetSharedRoleGroupIds(new ADObjectId[]
     {
         roleGroupId
     });
     if (!sharedRoleGroupIds.IsNullOrEmpty <ADObjectId>())
     {
         return(sharedRoleGroupIds[0]);
     }
     return(null);
 }
Ejemplo n.º 12
0
        public IEnumerable <T> GetObjects <T>(ObjectId rootId, IConfigDataProvider session, OptionalIdentityData optionalData, out LocalizedString?notFoundReason) where T : IConfigurable, new()
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (!(session is IDirectorySession))
            {
                throw new ArgumentException("Session should be an IDirectorySession", "session");
            }
            if (rootId != null && !(rootId is ADObjectId))
            {
                throw new ArgumentException("RootId must be an ADObjectId", "rootId");
            }
            IDirectorySession directorySession  = (IDirectorySession)session;
            IDirectorySession directorySession2 = null;

            if (!(this is OrganizationIdParameter) && VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && rootId == null && ADSessionSettings.GetProcessServerSettings() == null && directorySession is IConfigurationSession)
            {
                IConfigurationSession configurationSession   = directorySession as IConfigurationSession;
                ADObjectId            configurationUnitsRoot = directorySession.GetConfigurationUnitsRoot();
                bool flag = !string.IsNullOrEmpty(this.rawIdentity) && this.rawIdentity.IndexOf("\\") != -1;
                if (this.InternalADObjectId != null)
                {
                    flag = !string.IsNullOrEmpty(this.InternalADObjectId.DistinguishedName);
                }
                if (!flag && configurationSession.UseConfigNC && !configurationUnitsRoot.IsDescendantOf(directorySession.GetConfigurationNamingContext()) && typeof(ADConfigurationObject).IsAssignableFrom(typeof(T)) && !typeof(ADNonExchangeObject).IsAssignableFrom(typeof(T)))
                {
                    T                    t        = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
                    ADObject             adobject = t as ADObject;
                    ObjectScopeAttribute objectScopeAttribute;
                    bool                 flag2 = adobject.IsApplicableToTenant(out objectScopeAttribute);
                    if (directorySession.SessionSettings.ExecutingUserOrganizationId.Equals(OrganizationId.ForestWideOrgId) && directorySession.SessionSettings.CurrentOrganizationId.Equals(directorySession.SessionSettings.ExecutingUserOrganizationId) && flag2)
                    {
                        directorySession2 = directorySession;
                    }
                }
            }
            if (directorySession2 == null)
            {
                directorySession2 = ADSession.RescopeSessionToTenantSubTree(directorySession);
            }
            return(this.GetObjects <T>((ADObjectId)rootId, directorySession, directorySession2, optionalData, out notFoundReason));
        }
Ejemplo n.º 13
0
        // Token: 0x06000354 RID: 852 RVA: 0x00012094 File Offset: 0x00010294
        private static ADNotificationRequestCookie RegisterChangeNotification <T>(T dummyObject, ADObjectId baseDN, ADNotificationCallback callback, object context) where T : ADConfigurationObject, new()
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (baseDN == null || string.IsNullOrEmpty(baseDN.DistinguishedName))
            {
                throw new ArgumentNullException("baseDN");
            }
            string forestFQDN = baseDN.GetPartitionId().ForestFQDN;

            if (!baseDN.IsDescendantOf(ADSession.GetConfigurationNamingContext(forestFQDN)) && !ADSession.IsTenantIdentity(baseDN, forestFQDN))
            {
                throw new ArgumentException(DirectoryStrings.ExArgumentException("baseDN", baseDN), "baseDN");
            }
            ADNotificationRequest adnotificationRequest = new ADNotificationRequest(typeof(T), dummyObject.MostDerivedObjectClass, baseDN, callback, context);

            ADNotificationListener.RegisterChangeNotification(adnotificationRequest);
            return(new ADNotificationRequestCookie(new ADNotificationRequest[]
            {
                adnotificationRequest
            }));
        }
Ejemplo n.º 14
0
 private void ValidateSingleADObjectLinkValue(ADPropertyDefinition propertyDefinition, ADObjectId value, List <ValidationError> errors)
 {
     if (this.m_Session != null && this.m_Session.GetType().Name.Equals("TopologyDiscoverySession"))
     {
         return;
     }
     if (this.m_Session != null && !value.IsDescendantOf(this.m_Session.GetRootDomainNamingContext()))
     {
         return;
     }
     if (propertyDefinition.IsValidateInFirstOrganization && this.m_Session != null)
     {
         ADObjectId adobjectId = null;
         try
         {
             adobjectId = this.m_Session.SessionSettings.RootOrgId;
         }
         catch (OrgContainerNotFoundException)
         {
         }
         if (adobjectId != null && !value.IsDescendantOf(adobjectId) && adobjectId.DomainId == value.DomainId && !value.DistinguishedName.ToLower().Contains(",cn=deleted objects,"))
         {
             errors.Add(new PropertyValidationError(DirectoryStrings.ErrorLinkedADObjectNotInFirstOrganization(propertyDefinition.Name, value.ToString(), this.Identity.ToString(), adobjectId.ToString()), propertyDefinition, value));
             return;
         }
     }
     else if (propertyDefinition.IsValidateInSameOrganization)
     {
         if (this.OrganizationId.Equals(OrganizationId.ForestWideOrgId) && this.m_Session != null)
         {
             ADObjectId adobjectId2 = null;
             try
             {
                 adobjectId2 = this.m_Session.SessionSettings.RootOrgId;
             }
             catch (OrgContainerNotFoundException)
             {
             }
             catch (TenantOrgContainerNotFoundException)
             {
             }
             bool flag = true;
             try
             {
                 if (adobjectId2 != null && adobjectId2.DescendantDN(1).Name.ToLower().Equals("configuration"))
                 {
                     flag = false;
                 }
             }
             catch (InvalidOperationException)
             {
             }
             if (adobjectId2 != null && flag)
             {
                 ADObjectId childId = value.DomainId.GetChildId("OU", "Microsoft Exchange Hosted Organizations");
                 ADObjectId configurationUnitsRoot = this.m_Session.GetConfigurationUnitsRoot();
                 if ((value.IsDescendantOf(childId) || value.IsDescendantOf(configurationUnitsRoot)) && (!(this is ADConfigurationObject) || !base.Id.IsDescendantOf(configurationUnitsRoot)))
                 {
                     errors.Add(new PropertyValidationError(DirectoryStrings.ErrorLinkedADObjectNotInSameOrganization(propertyDefinition.Name, value.ToString(), this.Identity.ToString(), this.OrganizationId.ToString()), propertyDefinition, value));
                     return;
                 }
             }
         }
         else if (!this.OrganizationId.Equals(OrganizationId.ForestWideOrgId) && !value.DistinguishedName.ToLower().Contains(",cn=deleted objects,") && !value.IsDescendantOf(this.OrganizationId.OrganizationalUnit) && !value.IsDescendantOf(this.OrganizationId.ConfigurationUnit) && (!propertyDefinition.IsValidateInSharedConfig || this.SharedConfiguration == null || !value.IsDescendantOf(this.SharedConfiguration)))
         {
             errors.Add(new PropertyValidationError(DirectoryStrings.ErrorLinkedADObjectNotInSameOrganization(propertyDefinition.Name, value.ToString(), this.Identity.ToString(), this.OrganizationId.ToString()), propertyDefinition, value));
         }
     }
 }
Ejemplo n.º 15
0
        // Token: 0x0600049E RID: 1182 RVA: 0x000108B0 File Offset: 0x0000EAB0
        protected override void InternalBeginProcessing()
        {
            base.InternalBeginProcessing();
            if (!string.IsNullOrEmpty(this.ExternalDirectoryObjectId))
            {
                ITenantRecipientSession tenantRecipientSession = base.TenantGlobalCatalogSession as ITenantRecipientSession;
                if (tenantRecipientSession != null)
                {
                    bool useGlobalCatalog = tenantRecipientSession.UseGlobalCatalog;
                    tenantRecipientSession.UseGlobalCatalog = false;
                    Result <ADRawEntry>[] array = null;
                    try
                    {
                        array = tenantRecipientSession.FindByExternalDirectoryObjectIds(new string[]
                        {
                            this.ExternalDirectoryObjectId
                        }, true, new ADPropertyDefinition[]
                        {
                            DeletedObjectSchema.LastKnownParent
                        });
                    }
                    finally
                    {
                        tenantRecipientSession.UseGlobalCatalog = useGlobalCatalog;
                    }
                    if (array != null)
                    {
                        for (int i = 0; i < array.Length; i++)
                        {
                            if (array[i].Error != ProviderError.NotFound || array[i].Data != null)
                            {
                                ADObjectId adobjectId = null;
                                if (array[i].Error == null)
                                {
                                    adobjectId = (ADObjectId)array[i].Data[DeletedObjectSchema.LastKnownParent];
                                }
                                if (array[i].Error != null || adobjectId == null || (adobjectId.DomainId != null && !adobjectId.IsDescendantOf(ADSession.GetDeletedObjectsContainer(adobjectId.DomainId))))
                                {
                                    base.ThrowTerminatingError(new DuplicateExternalDirectoryObjectIdException(this.Name, this.ExternalDirectoryObjectId), ExchangeErrorCategory.Client, null);
                                }
                            }
                        }
                    }
                }
            }
            bool useConfigNC       = this.ConfigurationSession.UseConfigNC;
            bool useGlobalCatalog2 = this.ConfigurationSession.UseGlobalCatalog;

            this.ConfigurationSession.UseConfigNC      = false;
            this.ConfigurationSession.UseGlobalCatalog = true;
            IConfigurationSession cfgSession = this.ConfigurationSession;

            if (!cfgSession.IsReadConnectionAvailable())
            {
                cfgSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, this.ConfigurationSession.SessionSettings, 623, "InternalBeginProcessing", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\BaseTasks\\NewAdObjectTask.cs");
                cfgSession.UseGlobalCatalog = true;
                cfgSession.UseConfigNC      = false;
            }
            try
            {
                ExchangeOrganizationalUnit exchangeOrganizationalUnit = null;
                if (this.OrganizationalUnit != null)
                {
                    exchangeOrganizationalUnit = base.ProvisioningCache.TryAddAndGetGlobalDictionaryValue <ExchangeOrganizationalUnit, string>(CannedProvisioningCacheKeys.OrganizationalUnitDictionary, this.OrganizationalUnit.RawIdentity, () => (ExchangeOrganizationalUnit)this.GetDataObject <ExchangeOrganizationalUnit>(this.OrganizationalUnit, cfgSession, (this.CurrentOrganizationId != null) ? this.CurrentOrganizationId.OrganizationalUnit : null, null, new LocalizedString?(Strings.ErrorOrganizationalUnitNotFound(this.OrganizationalUnit.ToString())), new LocalizedString?(Strings.ErrorOrganizationalUnitNotUnique(this.OrganizationalUnit.ToString()))));
                }
                if (exchangeOrganizationalUnit != null)
                {
                    this.containerId = exchangeOrganizationalUnit.Id;
                }
                else if (base.CurrentOrganizationId != null && base.CurrentOrganizationId.OrganizationalUnit != null)
                {
                    this.containerId = base.CurrentOrganizationId.OrganizationalUnit;
                }
                else
                {
                    string defaultOUForRecipient = RecipientTaskHelper.GetDefaultOUForRecipient(base.ServerSettings.RecipientViewRoot);
                    if (string.IsNullOrEmpty(defaultOUForRecipient))
                    {
                        base.ThrowTerminatingError(new TaskArgumentException(Strings.ErrorCannotDiscoverDefaultOrganizationUnitForRecipient), ExchangeErrorCategory.Client, null);
                    }
                    exchangeOrganizationalUnit = (ExchangeOrganizationalUnit)base.GetDataObject <ExchangeOrganizationalUnit>(new OrganizationalUnitIdParameter(defaultOUForRecipient), cfgSession, null, null, new LocalizedString?(Strings.ErrorOrganizationalUnitNotFound(defaultOUForRecipient)), new LocalizedString?(Strings.ErrorOrganizationalUnitNotUnique(defaultOUForRecipient)), ExchangeErrorCategory.Client);
                    this.containerId           = exchangeOrganizationalUnit.Id;
                }
                if (exchangeOrganizationalUnit != null)
                {
                    RecipientTaskHelper.IsOrgnizationalUnitInOrganization(cfgSession, base.CurrentOrganizationId, exchangeOrganizationalUnit, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
                }
            }
            finally
            {
                this.ConfigurationSession.UseConfigNC      = useConfigNC;
                this.ConfigurationSession.UseGlobalCatalog = useGlobalCatalog2;
            }
        }
Ejemplo n.º 16
0
        private IEnumerable <ADRawEntry> ReadSpecialObjects()
        {
            ADObjectId exchangeServiceObject = base.RootOrgConfigurationSession.ConfigurationNamingContext.GetChildId("Services").GetChildId("Microsoft Exchange");
            int        numberOfLinksToRead   = 1500;
            int        rangeStart            = 0;
            int        rangeEnd = rangeStart + numberOfLinksToRead - 1;

            ADPropertyDefinition[] propertiesToRetrieve = new ADPropertyDefinition[]
            {
                ADObjectSchema.Id
            };
            ADObjectId configUnitDn = new ADObjectId(this.PageToken.TenantConfigUnitObjectGuid);
            ADRawEntry dnResolve    = base.TenantConfigurationSession.ReadADRawEntry(configUnitDn, propertiesToRetrieve);

            configUnitDn = dnResolve.Id;
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects tenant CU DN = {0}", configUnitDn);
            MultiValuedProperty <LinkMetadata> resultValues = new MultiValuedProperty <LinkMetadata>();
            ADRawEntry entry       = null;
            long       maxEntryUSN = 0L;
            bool       done        = false;

            while (!done)
            {
                ADPropertyDefinition      adpropertyDefinition = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(rangeStart, rangeEnd));
                List <PropertyDefinition> list = new List <PropertyDefinition>();
                list.Add(adpropertyDefinition);
                list.Add(ADRecipientSchema.UsnChanged);
                entry = base.RootOrgConfigurationSession.RetrieveTenantRelocationSyncObject(exchangeServiceObject, list);
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects object read: {0}", entry.Id.DistinguishedName);
                if ((long)entry[ADRecipientSchema.UsnChanged] < this.PageToken.SpecialObjectsUSN)
                {
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug <object, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects USNChanged({0} < this.PageToken.SpecialObjectsUSN({1})", entry[ADRecipientSchema.UsnChanged], this.PageToken.SpecialObjectsUSN);
                    break;
                }
                MultiValuedProperty <LinkMetadata> multiValuedProperty = (MultiValuedProperty <LinkMetadata>)entry[adpropertyDefinition];
                foreach (LinkMetadata linkMetadata in multiValuedProperty)
                {
                    if (linkMetadata.LocalUpdateSequenceNumber >= this.PageToken.SpecialObjectsUSN)
                    {
                        ADObjectId adobjectId = new ADObjectId(linkMetadata.TargetDistinguishedName);
                        if (adobjectId.IsDescendantOf(configUnitDn))
                        {
                            ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects valid link found: {0}, USN={1}", linkMetadata.TargetDistinguishedName, linkMetadata.LocalUpdateSequenceNumber);
                            if (linkMetadata.LocalUpdateSequenceNumber > maxEntryUSN)
                            {
                                maxEntryUSN = linkMetadata.LocalUpdateSequenceNumber;
                            }
                            resultValues.Add(linkMetadata);
                        }
                    }
                }
                if (multiValuedProperty.ValueRange != null && multiValuedProperty.ValueRange.UpperBound != 2147483647)
                {
                    rangeStart += numberOfLinksToRead;
                    rangeEnd    = rangeStart + numberOfLinksToRead - 1;
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug <int, int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects retrieve next page: rangeStart={0}, rangeEnd={1}", rangeStart, rangeEnd);
                }
                else
                {
                    done = true;
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects page retrieval ends");
                }
            }
            this.PageToken.SpecialObjectsUSN = ((maxEntryUSN == 0L) ? long.MaxValue : (maxEntryUSN + 1L));
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects SpecialObjectsUSN is set to {0}", this.PageToken.SpecialObjectsUSN);
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects Number of values found = {0}", resultValues.Count);
            if (resultValues.Count > 0)
            {
                ADPropertyBag propertyBag = new ADPropertyBag();
                propertyBag.SetField(ADObjectSchema.Id, entry.Id);
                propertyBag.SetField(ADRecipientSchema.UsnChanged, entry[ADRecipientSchema.UsnChanged]);
                propertyBag.SetField(ADRecipientSchema.LinkMetadata, resultValues);
                propertyBag.SetField(SyncObjectSchema.Deleted, false);
                TenantRelocationSyncObject specialObject = new TenantRelocationSyncObject(propertyBag, new DirectoryAttribute[0]);
                yield return(specialObject);
            }
            yield break;
        }