private static bool TryGetMailFlowConnectorId(ExSearchResultEntry entry, string attribute, EdgeSyncDiag diagSession, out int connectorId)
        {
            connectorId = EhfDomainSynchronizerVersion2.InvalidConnectorId;
            DirectoryAttribute attribute2 = entry.GetAttribute(attribute);

            if (attribute2 == null)
            {
                diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.High, "ConnectorId is null or empty for <{0}>:<{1}>", new object[]
                {
                    attribute,
                    entry.DistinguishedName
                });
                return(false);
            }
            string text = (string)attribute2[0];

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            if (int.TryParse(text, out connectorId))
            {
                return(true);
            }
            diagSession.LogAndTraceError("ConnectorId '{0}' is not in the expected format for <{1}>:<{2}>", new object[]
            {
                text,
                attribute,
                entry.DistinguishedName
            });
            return(false);
        }
예제 #2
0
        private EhfAdminSyncChangeBuilder GetAdminBuilderForChange(ExSearchResultEntry entry)
        {
            string text;

            if (!EhfAdminAccountSynchronizer.TryGetOrganizationUnit(entry, base.DiagSession, out text))
            {
                return(null);
            }
            EhfAdminSyncChangeBuilder ehfAdminSyncChangeBuilder;

            if (!this.adminAccountChange.TryGetValue(text, out ehfAdminSyncChangeBuilder))
            {
                DirectoryAttribute attribute = entry.GetAttribute("msExchCU");
                if (attribute == null)
                {
                    base.DiagSession.LogAndTraceError("Could not find ConfigUnitDN for {0}. Every object is expected to contain this attribute.", new object[]
                    {
                        entry.DistinguishedName
                    });
                    return(null);
                }
                string tenantConfigUnitDN = (string)attribute[0];
                ehfAdminSyncChangeBuilder = new EhfAdminSyncChangeBuilder(text, tenantConfigUnitDN, base.EhfConnection);
                this.adminAccountChange.Add(text, ehfAdminSyncChangeBuilder);
            }
            return(ehfAdminSyncChangeBuilder);
        }
예제 #3
0
        protected static int GetFlagsValue(string flagsAttrName, ExSearchResultEntry resultEntry, EhfSyncItem syncItem)
        {
            DirectoryAttribute attribute = resultEntry.GetAttribute(flagsAttrName);

            if (attribute == null)
            {
                return(0);
            }
            string text = (string)attribute[0];

            if (string.IsNullOrEmpty(text))
            {
                return(0);
            }
            int result;

            if (!int.TryParse(text, out result))
            {
                syncItem.AddSyncError(syncItem.DiagSession.LogAndTraceError("Unable to parse flags value ({0}) of attribute {1} for AD object ({2}); using default value 0", new object[]
                {
                    text,
                    flagsAttrName,
                    resultEntry.DistinguishedName
                }));
            }
            return(result);
        }
        private static bool TryGetConfigUnit(ExSearchResultEntry entry, EdgeSyncDiag diagSession, out string configUnitDN)
        {
            configUnitDN = null;
            DirectoryAttribute attribute = entry.GetAttribute("msExchCU");

            if (attribute != null)
            {
                configUnitDN = (string)attribute[0];
            }
            if (string.IsNullOrEmpty(configUnitDN))
            {
                diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "ConfigUnit root DN is not specified for accepted domain with DN <{0}>; ignoring the object", new object[]
                {
                    entry.DistinguishedName
                });
                return(false);
            }
            if (ExSearchResultEntry.IsDeletedDN(configUnitDN))
            {
                diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "ConfigUnit root DN <{0}> for accepted domain with DN <{1}> indicates that tenant organization is deleted; ignoring the object", new object[]
                {
                    configUnitDN,
                    entry.DistinguishedName
                });
                configUnitDN = null;
                return(false);
            }
            return(true);
        }
예제 #5
0
        private bool TryGetCompanyState(string ouDN, EhfTargetConnection targetConnection, EhfADAdapter configADAdapter, out EhfAdminSyncState adminSyncState)
        {
            EhfADAdapter adadapter = this.ehfTargetConnection.ADAdapter;

            adminSyncState = null;
            ExSearchResultEntry exSearchResultEntry = adadapter.ReadObjectEntry(ouDN, false, EhfCompanyAdmins.ConfigUnitAttribute);

            if (exSearchResultEntry == null)
            {
                targetConnection.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Could not load object with DN <{0}>; Cannot determine the CompanyId", new object[]
                {
                    ouDN
                });
                return(false);
            }
            DirectoryAttribute attribute = exSearchResultEntry.GetAttribute("msExchCU");

            if (attribute == null)
            {
                targetConnection.DiagSession.LogAndTraceError("Could not load the Configuration Containter for {0}", new object[]
                {
                    ouDN
                });
                return(false);
            }
            string configUnitDN = (string)attribute[0];

            return(EhfCompanySynchronizer.TryGetEhfAdminSyncState(configUnitDN, configADAdapter, targetConnection, "Ignoring admin account changes, will retry in next sync cycle", out adminSyncState));
        }
예제 #6
0
        public static bool TryGetExternalDirectoryObjectId(ExSearchResultEntry entry, EdgeSyncDiag diagSession, out Guid externalDirectoryObjectId)
        {
            externalDirectoryObjectId = Guid.Empty;
            DirectoryAttribute attribute = entry.GetAttribute("msExchExternalDirectoryObjectId");

            if (attribute == null || attribute.Count == 0)
            {
                diagSession.LogAndTraceError("msExchExternalDirectoryObjectId attribute is not set on '{0}'", new object[]
                {
                    entry.DistinguishedName
                });
                return(false);
            }
            string text = (string)attribute[0];

            if (!GuidHelper.TryParseGuid(text, out externalDirectoryObjectId))
            {
                diagSession.LogAndTraceError("msExchExternalDirectoryObjectId attribute in '{0}' is set to an invalid Guid '{1}'", new object[]
                {
                    entry.DistinguishedName,
                    text
                });
                return(false);
            }
            return(true);
        }
예제 #7
0
        public static EhfCompanyAdmins CreateEhfCompanyAdmins(EhfAdminSyncChangeBuilder ehfAdminSyncChangeBuilder, EhfTargetConnection ehfTargetConnection, EhfADAdapter configADAdapter)
        {
            ExSearchResultEntry exSearchResultEntry = configADAdapter.ReadObjectEntry(ehfAdminSyncChangeBuilder.ConfigUnitDN, false, EhfCompanyAdmins.OtherWellKnownObjectsAttribute);

            if (exSearchResultEntry == null)
            {
                ehfTargetConnection.DiagSession.LogAndTraceError("Could not find Configuration Unit for company {0}. The config naming context is either not replicated or the organization is deleted", new object[]
                {
                    ehfAdminSyncChangeBuilder.TenantOU
                });
                return(null);
            }
            string             text      = null;
            string             text2     = null;
            DirectoryAttribute attribute = exSearchResultEntry.GetAttribute("otherWellKnownObjects");

            if (attribute == null)
            {
                ehfTargetConnection.DiagSession.LogAndTraceError("Could not find OtherWellKnownObjects attribute in Configuration Unit object for company {0}.", new object[]
                {
                    ehfAdminSyncChangeBuilder.TenantOU
                });
                return(null);
            }
            foreach (object obj in attribute.GetValues(typeof(string)))
            {
                DNWithBinary dnwithBinary;
                if (DNWithBinary.TryParse(obj as string, out dnwithBinary))
                {
                    try
                    {
                        Guid b = new Guid(dnwithBinary.Binary);
                        if (WellKnownGuid.EoaWkGuid == b)
                        {
                            text = dnwithBinary.DistinguishedName;
                        }
                        if (WellKnownGuid.EraWkGuid == b)
                        {
                            text2 = dnwithBinary.DistinguishedName;
                        }
                        if (text != null && text2 != null)
                        {
                            break;
                        }
                    }
                    catch (ArgumentException exception)
                    {
                        ehfTargetConnection.DiagSession.LogAndTraceException(exception, "OtherWellKnownObjects attribute for company {0} contains an entry with invalid Binary part.", new object[]
                        {
                            ehfAdminSyncChangeBuilder.TenantOU
                        });
                    }
                }
            }
            return(new EhfCompanyAdmins(ehfAdminSyncChangeBuilder, ehfTargetConnection, text, text2, configADAdapter));
        }
        private static bool ValidateDomainName(ExSearchResultEntry entry, EdgeSyncDiag diagSession)
        {
            DirectoryAttribute attribute = entry.GetAttribute("msExchAcceptedDomainName");
            string             text      = null;

            if (attribute != null)
            {
                text = (string)attribute[0];
            }
            if (string.IsNullOrEmpty(text))
            {
                diagSession.LogAndTraceError("Accepted domain object with DN <{0}> does not contain domain name; ignoring the object", new object[]
                {
                    entry.DistinguishedName
                });
                return(false);
            }
            if (text.StartsWith("*", StringComparison.Ordinal))
            {
                diagSession.LogAndTraceError("Wildcard accepted domain <{0}> with DN <{1}> cannot be sync'd", new object[]
                {
                    text,
                    entry.DistinguishedName
                });
                return(false);
            }
            if (text.Contains("_"))
            {
                diagSession.LogAndTraceError("Accepted domain <{0}> with DN <{1}> cannot be sync'd because it contains one or more underscore characters", new object[]
                {
                    text,
                    entry.DistinguishedName
                });
                return(false);
            }
            if (!text.Contains("."))
            {
                diagSession.LogAndTraceError("Accepted domain <{0}> with DN <{1}> cannot be sync'd because it is a top level domain", new object[]
                {
                    text,
                    entry.DistinguishedName
                });
                return(false);
            }
            if (text.Length > 255)
            {
                diagSession.LogAndTraceError("Accepted domain name <{0}> with DN <{1}> is too long; ignoring the domain", new object[]
                {
                    text,
                    entry.DistinguishedName
                });
                return(false);
            }
            return(true);
        }
        private bool TryGetEhfMailFlowPartner(ExSearchResultEntry entry, out EhfDomainSynchronizerVersion2.EhfMailFlowPartner ehfMailFlowPartner)
        {
            ehfMailFlowPartner = null;
            DirectoryAttribute attribute = entry.GetAttribute("msExchTransportResellerSettingsLink");

            if (attribute == null)
            {
                base.DiagSession.Tracer.TraceDebug(0L, "MailFlowPartner attribute not found");
                return(false);
            }
            string text = (string)attribute[0];

            if (string.IsNullOrEmpty(text))
            {
                base.DiagSession.Tracer.TraceDebug(0L, "MailFlowPartner attribute is null or empty");
                return(false);
            }
            if (ExSearchResultEntry.IsDeletedDN(text))
            {
                base.DiagSession.LogAndTraceError("Found a reference to deleted partner <{0}> from domain <{1}>. Ignoring the partner.", new object[]
                {
                    text,
                    entry.DistinguishedName
                });
                return(false);
            }
            if (this.ehfMailFlowPartnersCache == null)
            {
                base.DiagSession.Tracer.TraceDebug(0L, "Creating MailFlowPartner cache.");
                this.ehfMailFlowPartnersCache = new Dictionary <string, EhfDomainSynchronizerVersion2.EhfMailFlowPartner>();
            }
            if (!this.ehfMailFlowPartnersCache.TryGetValue(text, out ehfMailFlowPartner))
            {
                base.DiagSession.Tracer.TraceDebug(0L, "MailFlowPartner entry not found in cache. Loading from AD");
                if (this.TryGetEhfMailFlowPartnerFromAD(text, out ehfMailFlowPartner))
                {
                    this.ehfMailFlowPartnersCache.Add(text, ehfMailFlowPartner);
                }
                else
                {
                    base.DiagSession.LogAndTraceError("Could not find mailflow partner <{0}>, referenced from domain <{1}>", new object[]
                    {
                        text,
                        entry.DistinguishedName
                    });
                }
            }
            else
            {
                base.DiagSession.Tracer.TraceDebug(0L, "MailFlowPartner entry found in cache");
            }
            return(ehfMailFlowPartner != null);
        }
예제 #10
0
        private static bool TryGetFlagsValue(string flagsAttrName, ExSearchResultEntry entry, out int flagValue)
        {
            flagValue = 0;
            DirectoryAttribute attribute = entry.GetAttribute(flagsAttrName);

            if (attribute == null)
            {
                return(false);
            }
            string text = (string)attribute[0];

            return(!string.IsNullOrEmpty(text) && int.TryParse(text, out flagValue));
        }
예제 #11
0
        private static HashSet <Guid> GetAdminStateFromAttribute(ExSearchResultEntry perimeterConfigEntry, string attributeName)
        {
            DirectoryAttribute attribute = perimeterConfigEntry.GetAttribute(attributeName);

            if (attribute == null)
            {
                return(null);
            }
            HashSet <Guid> hashSet = new HashSet <Guid>();

            foreach (object obj in attribute.GetValues(typeof(byte[])))
            {
                byte[] array = obj as byte[];
                if (array != null && array.Length == 16)
                {
                    hashSet.Add(new Guid(array));
                }
            }
            return(hashSet);
        }