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); }
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); }
private static EhfCompanyIdentity GetEhfCompanyIdentity(string configUnitDN, EdgeSyncDiag diagSession, string missingIdAction, ExSearchResultEntry perimeterSettingsEntry) { int companyId; string text; if (!EhfCompanyItem.TryGetEhfCompanyId(perimeterSettingsEntry, diagSession, out companyId, out text)) { if (string.IsNullOrEmpty(text)) { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "EHF company ID is not set for tenant organization with ConfigUnit root DN <{0}>; {1}", new object[] { configUnitDN, missingIdAction }); } else { diagSession.LogAndTraceError("Failure occurred while retrieving EHF company ID for tenant organization with ConfigUnit root DN <{0}>; {1}; failure details: {2}", new object[] { configUnitDN, missingIdAction, text }); } } Guid objectGuid = perimeterSettingsEntry.GetObjectGuid(); return(new EhfCompanyIdentity(companyId, objectGuid)); }
private static bool TryGetPerimeterConfigEntry(string configUnitDN, EhfADAdapter adAdapter, EdgeSyncDiag diagSession, string missingIdAction, string[] attributes, out ExSearchResultEntry perimeterSettingsEntry) { ADObjectId perimeterConfigObjectIdFromConfigUnitId = EhfTargetConnection.GetPerimeterConfigObjectIdFromConfigUnitId(new ADObjectId(configUnitDN)); perimeterSettingsEntry = adAdapter.ReadObjectEntry(perimeterConfigObjectIdFromConfigUnitId.DistinguishedName, false, attributes); if (perimeterSettingsEntry == null) { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Unable to read Perimeter Settings object for ConfigUnit root DN <{0}>; {1}", new object[] { configUnitDN, missingIdAction }); return(false); } return(true); }
protected override void HandleCreateDomainResponse(DomainResponseInfoSet responseSet, List <EhfDomainItem> domainsTriedToCreate) { int num = 0; int permanentFailureCount = 0; List <EhfDomainItemVersion2> list = new List <EhfDomainItemVersion2>(); List <EhfDomainItemVersion2> list2 = new List <EhfDomainItemVersion2>(); for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { DomainResponseInfo domainResponseInfo = responseSet.ResponseInfo[i]; EhfDomainItemVersion2 ehfDomainItemVersion = domainsTriedToCreate[i] as EhfDomainItemVersion2; if (ehfDomainItemVersion == null) { throw new InvalidOperationException("Version 2 of EhfConnector should be using version 2 of EhfDomainItem"); } if (domainResponseInfo.Status == ResponseStatus.Success) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully created EHF domain: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[] { ehfDomainItemVersion.DistinguishedName, ehfDomainItemVersion.Domain.Name, domainResponseInfo.DomainGuid.Value, ehfDomainItemVersion.Domain.CompanyId }); if (ehfDomainItemVersion.TryClearForceDomainSyncFlagFromPerimeterConfig(base.ADAdapter) == EhfADResultCode.Failure) { num++; } if (!this.UpdateDuplicateDetectedFlag(ehfDomainItemVersion)) { num++; } } else if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany || domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany) { Guid domainGuid = ehfDomainItemVersion.GetDomainGuid(); if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany && domainResponseInfo.DomainGuid.Value.Equals(domainGuid)) { if (ehfDomainItemVersion.TriedToUpdateDomain && !ehfDomainItemVersion.DomainCreatedWithGuid) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a domain that already exists. Treating this as error since update is already called: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[] { ehfDomainItemVersion.DistinguishedName, ehfDomainItemVersion.Domain.Name, domainGuid, ehfDomainItemVersion.Domain.CompanyId }); base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount); } else { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a domain that already exists. Trying to update the domain. DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[] { ehfDomainItemVersion.DistinguishedName, ehfDomainItemVersion.Domain.Name, domainGuid, ehfDomainItemVersion.Domain.CompanyId }); list.Add(ehfDomainItemVersion); } } else if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany && domainResponseInfo.SourceId == ProvisioningSource.Other && !ehfDomainItemVersion.DomainCreatedWithGuid) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "A domain collision is detected for domain: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-Company-ID=<{3}>. Trying to create the domain as OutboundOnly domain.", new object[] { ehfDomainItemVersion.DistinguishedName, ehfDomainItemVersion.Name, domainGuid, ehfDomainItemVersion.Domain.CompanyId }); list2.Add(ehfDomainItemVersion); } else if (!base.HandledAllDeletedDomains) { base.AddDomainToCreateLastList(ehfDomainItemVersion); EdgeSyncDiag diagSession = base.DiagSession; EdgeSyncLoggingLevel level = EdgeSyncLoggingLevel.Low; string messageFormat = "Attempted to create a domain with the name that already exists but a different GUID: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-GUID=<{3}>; EHF-Company-ID=<{4}>"; object[] array = new object[5]; array[0] = ehfDomainItemVersion.DistinguishedName; array[1] = ehfDomainItemVersion.Name; array[2] = domainGuid; object[] array2 = array; int num2 = 3; Guid? domainGuid2 = domainResponseInfo.DomainGuid; array2[num2] = ((domainGuid2 != null) ? domainGuid2.GetValueOrDefault() : "null"); array[4] = ehfDomainItemVersion.Domain.CompanyId; diagSession.LogAndTraceInfo(level, messageFormat, array); } else if (!ehfDomainItemVersion.DomainCreatedWithGuid && domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany) { base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "A domain collision is detected for domain: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-Company-ID=<{3}>. Trying to create the domain as OutboundOnly domain.", new object[] { ehfDomainItemVersion.DistinguishedName, ehfDomainItemVersion.Name, domainGuid, ehfDomainItemVersion.Domain.CompanyId }); list2.Add(ehfDomainItemVersion); } else { base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount); } } else if (domainResponseInfo.Fault.Id == FaultId.DomainGuidIsNotUnique && !ehfDomainItemVersion.TriedToUpdateDomain) { list.Add(ehfDomainItemVersion); } else { base.HandleFailedDomain("Create Domain", ehfDomainItemVersion, domainResponseInfo, ref num, ref permanentFailureCount); } if (!ehfDomainItemVersion.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { num++; } } base.HandlePerEntryFailureCounts("Create Domain", domainsTriedToCreate.Count, num, permanentFailureCount, false); foreach (EhfDomainItemVersion2 domain in list) { this.AddDomainToUpdateBatch(domain); } foreach (EhfDomainItemVersion2 domain2 in list2) { this.AddDomainToCreateWithGuidBatch(domain2); } }
protected virtual void HandleCreateDomainResponse(DomainResponseInfoSet responseSet, List <EhfDomainItem> domainsTriedToCreate) { int num = 0; int permanentFailureCount = 0; for (int i = 0; i < responseSet.ResponseInfo.Length; i++) { DomainResponseInfo domainResponseInfo = responseSet.ResponseInfo[i]; EhfDomainItem ehfDomainItem = domainsTriedToCreate[i]; bool flag = false; if (domainResponseInfo.Status == ResponseStatus.Success) { flag = true; base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Successfully created EHF domain: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[] { ehfDomainItem.DistinguishedName, ehfDomainItem.Domain.Name, domainResponseInfo.DomainGuid.Value, ehfDomainItem.Domain.CompanyId }); } else if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany || domainResponseInfo.Fault.Id == FaultId.DomainExistOutsideThisCompany) { Guid domainGuid = ehfDomainItem.GetDomainGuid(); if (domainResponseInfo.Fault.Id == FaultId.DomainExistUnderThisCompany && domainResponseInfo.DomainGuid.Value.Equals(domainGuid)) { flag = true; base.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Attempted to create a domain that already exists: DN=<{0}>; Name=<{1}>; GUID=<{2}>; EHF-Company-ID=<{3}>", new object[] { ehfDomainItem.DistinguishedName, ehfDomainItem.Domain.Name, domainGuid, ehfDomainItem.Domain.CompanyId }); } else if (!this.handledAllDeletedDomains) { base.AddItemToLazyList <EhfDomainItem>(ehfDomainItem, ref this.domainsToCreateLast); EdgeSyncDiag diagSession = base.DiagSession; EdgeSyncLoggingLevel level = EdgeSyncLoggingLevel.Low; string messageFormat = "Attempted to create a domain with the name that already exists but a different GUID: DN=<{0}>; Name=<{1}>; AD-GUID=<{2}>; EHF-GUID=<{3}>; EHF-Company-ID=<{4}>"; object[] array = new object[5]; array[0] = ehfDomainItem.DistinguishedName; array[1] = ehfDomainItem.Name; array[2] = domainGuid; object[] array2 = array; int num2 = 3; Guid? domainGuid2 = domainResponseInfo.DomainGuid; array2[num2] = ((domainGuid2 != null) ? domainGuid2.GetValueOrDefault() : "null"); array[4] = ehfDomainItem.Domain.CompanyId; diagSession.LogAndTraceInfo(level, messageFormat, array); } else { this.HandleFailedDomain("Create Domain", ehfDomainItem, domainResponseInfo, ref num, ref permanentFailureCount); } } else { this.HandleFailedDomain("Create Domain", ehfDomainItem, domainResponseInfo, ref num, ref permanentFailureCount); } if (flag && ehfDomainItem.TryClearForceDomainSyncFlagFromPerimeterConfig(base.ADAdapter) == EhfADResultCode.Failure) { num++; } if (!ehfDomainItem.EventLogAndTryStoreSyncErrors(base.ADAdapter)) { num++; } } base.HandlePerEntryFailureCounts("Create Domain", domainsTriedToCreate.Count, num, permanentFailureCount, false); }
private EhfWellKnownGroup GetMembersOfGroupFromDN(string groupDistinguishedName, bool isPartnerAdminGroup, EdgeSyncDiag diagSession) { EhfWellKnownGroup ehfWellKnownGroup; if (isPartnerAdminGroup) { ExSearchResultEntry exSearchResultEntry = this.ehfTargetConnection.ADAdapter.ReadObjectEntry(groupDistinguishedName, false, EhfCompanyAdmins.AttributesToFetchFromMembers); if (exSearchResultEntry == null) { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Low, "Could not find wellknown partner admin group {0}", new object[] { groupDistinguishedName }); return(null); } if (!EhfCompanyAdmins.IsPartnerManagedGroup(exSearchResultEntry, diagSession)) { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Found the partner group {0}, but it is no partner Managed", new object[] { groupDistinguishedName }); return(null); } Guid externalDirectoryObjectId; if (!EhfCompanyAdmins.TryGetExternalDirectoryObjectId(exSearchResultEntry, diagSession, out externalDirectoryObjectId)) { return(null); } ehfWellKnownGroup = new EhfWellKnownGroup(groupDistinguishedName, externalDirectoryObjectId); } else { ehfWellKnownGroup = new EhfWellKnownGroup(groupDistinguishedName); } Stack <string> stack = new Stack <string>(); stack.Push(groupDistinguishedName); while (stack.Count != 0) { string text = stack.Pop(); string query = string.Format("(memberOf={0})", text); diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.High, "Expanding group {0}", new object[] { text }); IEnumerable <ExSearchResultEntry> enumerable = this.ehfTargetConnection.ADAdapter.PagedScan(this.tenantOU, query, EhfCompanyAdmins.AttributesToFetchFromMembers); int num = 0; foreach (ExSearchResultEntry exSearchResultEntry2 in enumerable) { num++; if (!exSearchResultEntry2.IsDeleted) { Guid objectGuid = exSearchResultEntry2.GetObjectGuid(); if (EhfCompanyAdmins.IsGroup(exSearchResultEntry2)) { Guid partnerGroupGuid; if (ehfWellKnownGroup.SubGroups.ContainsKey(objectGuid) || ehfWellKnownGroup.LinkedRoleGroups.ContainsKey(objectGuid)) { this.ehfTargetConnection.DiagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "Group {0} is already processed. Ignoring it.", new object[] { exSearchResultEntry2.DistinguishedName }); } else if (EhfCompanyAdmins.IsPartnerManagedLinkedRoleGroup(exSearchResultEntry2, diagSession, out partnerGroupGuid)) { ehfWellKnownGroup.LinkedRoleGroups.Add(objectGuid, new PartnerGroupAdminSyncUser(exSearchResultEntry2.DistinguishedName, objectGuid, partnerGroupGuid)); } else { ehfWellKnownGroup.SubGroups.Add(objectGuid, new AdminSyncUser(exSearchResultEntry2.DistinguishedName, objectGuid)); stack.Push(exSearchResultEntry2.DistinguishedName); } } else { string text2 = string.Empty; if (exSearchResultEntry2.Attributes.ContainsKey("msExchWindowsLiveID") && exSearchResultEntry2.Attributes["msExchWindowsLiveID"].Count != 0) { text2 = (string)exSearchResultEntry2.Attributes["msExchWindowsLiveID"][0]; if (text2 != null) { text2 = text2.Trim(); } } else { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "WindowsLiveID is not set for {0}", new object[] { exSearchResultEntry2.DistinguishedName }); } if (!ehfWellKnownGroup.GroupMembers.ContainsKey(objectGuid)) { ehfWellKnownGroup.GroupMembers.Add(objectGuid, new MailboxAdminSyncUser(text2, objectGuid, exSearchResultEntry2.DistinguishedName)); } } } else { diagSession.LogAndTraceInfo(EdgeSyncLoggingLevel.Medium, "{0} is deleted, ignoring...", new object[] { exSearchResultEntry2.DistinguishedName }); } } diagSession.Tracer.TraceDebug <string, int>((long)this.GetHashCode(), "Expanded group {0}. Found {1} children", text, num); } return(ehfWellKnownGroup); }