private static ADObjectId FindServerIdWithClientAccess(ITopologyConfigurationSession adSession, ADObjectId mountedSiteId, ADObjectId preferredServerId) { ADObjectId adobjectId = null; List <ADObjectId> list = new List <ADObjectId>(8); foreach (KeyValuePair <Server, ExchangeRpcClientAccess> keyValuePair in ExchangeRpcClientAccess.GetServersWithRpcClientAccessEnabled(ExchangeRpcClientAccess.GetAllPossibleServers(adSession, mountedSiteId), ExchangeRpcClientAccess.GetAll(adSession))) { if ((keyValuePair.Value.Responsibility & RpcClientAccessResponsibility.Mailboxes) != RpcClientAccessResponsibility.None) { if (preferredServerId != null && preferredServerId.Equals(keyValuePair.Key.Id)) { adobjectId = keyValuePair.Key.Id; break; } list.Add(keyValuePair.Key.Id); } } if (adobjectId == null && list.Count > 0) { adobjectId = list[0]; if (list.Count > 1) { adobjectId = list[(Environment.TickCount & int.MaxValue) % list.Count]; } } return(adobjectId); }
private static void ExchangeRpcClientAccessChangeNotification(ADNotificationEventArgs args) { Configuration.GeneralTracer.TraceDebug(0L, "ExchangeRpcClientAccessChangeNotification called"); ADNotificationAdapter.TryRunADOperation(delegate() { ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 280, "ExchangeRpcClientAccessChangeNotification", "f:\\15.00.1497\\sources\\dev\\DoMT\\src\\Service\\Configuration.cs"); topologyConfigurationSession.ServerTimeout = Configuration.ADTimeout; Server server = topologyConfigurationSession.ReadLocalServer(); if (server == null) { Configuration.GeneralTracer.TraceError(0L, "Failed to find local server in AD"); Configuration.eventLog.LogEvent(AddressBookEventLogConstants.Tuple_FailedToFindLocalServerInAD, string.Empty, new object[0]); if (args == null) { Configuration.ServiceEnabled = false; return; } Configuration.stopService(); return; } else { ExchangeRpcClientAccess exchangeRpcClientAccess = topologyConfigurationSession.Read <ExchangeRpcClientAccess>(ExchangeRpcClientAccess.FromServerId(server.Id)); if (exchangeRpcClientAccess != null) { if (Configuration.exchangeRCANotificationCookie == null) { Configuration.exchangeRCANotificationCookie = ADNotificationAdapter.RegisterChangeNotification <ExchangeRpcClientAccess>(exchangeRpcClientAccess.Id, new ADNotificationCallback(Configuration.ExchangeRpcClientAccessChangeNotification)); } if (Configuration.EncryptionRequired != exchangeRpcClientAccess.EncryptionRequired) { Configuration.GeneralTracer.TraceDebug <bool, bool>(0L, "Changing EncryptionRequired from {0} to {1}", Configuration.EncryptionRequired, exchangeRpcClientAccess.EncryptionRequired); Configuration.EncryptionRequired = exchangeRpcClientAccess.EncryptionRequired; } return; } Configuration.GeneralTracer.TraceDebug(0L, "ExchangeRpcClientAccess disabled"); Configuration.eventLog.LogEvent(AddressBookEventLogConstants.Tuple_ExchangeRpcClientAccessDisabled, string.Empty, new object[0]); if (args == null) { Configuration.ServiceEnabled = false; return; } Configuration.stopService(); return; } }); }
protected override void WriteResult(IConfigurable dataObject) { TaskLogger.LogEnter(new object[] { dataObject.Identity, dataObject }); ClientAccessArray clientAccessArray = (ClientAccessArray)dataObject; if (clientAccessArray.IsPriorTo15ExchangeObjectVersion) { Server[] cachedServers = ExchangeRpcClientAccess.GetAllPossibleServers((ITopologyConfigurationSession)this.ConfigurationSession, this.siteId).ToArray <Server>(); ExchangeRpcClientAccess[] all = ExchangeRpcClientAccess.GetAll((ITopologyConfigurationSession)this.ConfigurationSession); clientAccessArray.CompleteAllCalculatedProperties(cachedServers, all); } base.WriteResult(dataObject); TaskLogger.LogExit(); }
internal RfriStatus GetFQDNFromLegacyDN(string legacyDN, out string serverFQDN) { RfriStatus rfriStatus = RfriStatus.Success; serverFQDN = null; RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "Requested DN: {0}", RfriContext.GetString(legacyDN)); if (legacyDN.Contains("@")) { LegacyDN legacyDN2; if (LegacyDN.TryParse(legacyDN, out legacyDN2)) { string text; legacyDN2.GetParentLegacyDN(out text, out serverFQDN); if (string.IsNullOrEmpty(serverFQDN) || !serverFQDN.Contains("@")) { rfriStatus = RfriStatus.NoSuchObject; } } else { rfriStatus = RfriStatus.NoSuchObject; } } else { legacyDN = ExchangeRpcClientAccess.FixFakeRedirectLegacyDNIfNeeded(legacyDN); rfriStatus = ServerFqdnCache.LookupFQDNByLegacyDN(legacyDN, out serverFQDN); } if (rfriStatus != RfriStatus.Success || string.IsNullOrEmpty(serverFQDN)) { if (rfriStatus == RfriStatus.Success) { rfriStatus = RfriStatus.NoSuchObject; } this.ProtocolLogSession[ProtocolLog.Field.Failures] = RfriContext.GetString(legacyDN); } else { RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "Referring to {0}", serverFQDN); } return(rfriStatus); }
private bool TryGetPersonalizedServer(string userLegacyDN, out string personalizedServer) { personalizedServer = string.Empty; bool flag = true; NspiPrincipal nspiPrincipal; if (string.IsNullOrEmpty(userLegacyDN) || LegacyDN.StringComparer.Equals(userLegacyDN, this.LegacyDistinguishedName)) { this.protocolLogSession[ProtocolLog.Field.OperationSpecific] = "Self"; nspiPrincipal = this.nspiPrincipal; } else { this.protocolLogSession[ProtocolLog.Field.OperationSpecific] = "Other"; nspiPrincipal = this.NspiPrincipalFromLegacyDN(userLegacyDN); flag = false; if (nspiPrincipal == null) { return(false); } } if (!flag && nspiPrincipal.ExchangeVersion != null && nspiPrincipal.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012)) { string clientAccessServerLegacyDN = this.GetClientAccessServerLegacyDN(userLegacyDN); RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "RfriContext.GetClientAccessServerLegacyDN: {0}", RfriContext.GetString(clientAccessServerLegacyDN)); ServerFqdnCache.LookupFQDNByLegacyDN(clientAccessServerLegacyDN, out personalizedServer); RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "ServerFqdnCache.LookupFQDNByLegacyDN: {0}", RfriContext.GetString(personalizedServer)); return(true); } SmtpAddress primarySmtpAddress = nspiPrincipal.PrimarySmtpAddress; if (nspiPrincipal.ExchangeGuid != Guid.Empty) { personalizedServer = ExchangeRpcClientAccess.CreatePersonalizedServer(nspiPrincipal.ExchangeGuid, nspiPrincipal.PrimarySmtpAddress.Domain); RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "RfriContext.GetPersonalizedServer: {0}", RfriContext.GetString(personalizedServer)); return(true); } return(false); }
internal string FindRpcClientAccessArrayOrServer(ITopologyConfigurationSession session, ADObjectId localServerId) { ADSite localSite = session.GetLocalSite(); if (localSite == null) { return(null); } ClientAccessArray[] array = session.Find <ClientAccessArray>(null, QueryScope.SubTree, QueryFilter.AndTogether(new QueryFilter[] { this.GetSiteFilter(localSite.Id), ClientAccessArray.PriorTo15ExchangeObjectVersionFilter }), null, 2); if (array.Length > 0) { return(array[0].ExchangeLegacyDN); } List <string> list = new List <string>(); foreach (KeyValuePair <Server, ExchangeRpcClientAccess> keyValuePair in ExchangeRpcClientAccess.GetServersWithRpcClientAccessEnabled(ExchangeRpcClientAccess.GetAllPossibleServers(session, localSite.Id), ExchangeRpcClientAccess.GetAll(session))) { if ((keyValuePair.Value.Responsibility & RpcClientAccessResponsibility.Mailboxes) != RpcClientAccessResponsibility.None) { if (localServerId.Equals(keyValuePair.Key.Id)) { return(keyValuePair.Key.ExchangeLegacyDN); } list.Add(keyValuePair.Key.ExchangeLegacyDN); } } if (list.Count == 0) { return(null); } return(NewRpcClientAccess.SelectServerWithEqualProbability(list)); }
public ClientAccessServerIdParameter(ExchangeRpcClientAccess rpcClientAccess) : base(rpcClientAccess.Server) { }
// Token: 0x0600070D RID: 1805 RVA: 0x000296EC File Offset: 0x000278EC protected override AnchorMailbox ResolveAnchorMailbox() { UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url); if (string.IsNullOrEmpty(base.ClientRequest.Url.Query)) { throw new HttpProxyException(HttpStatusCode.NotFound, 3001, "No proxy destination is specified!"); } RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query); this.rpcServerTarget = rpcHttpQueryString.RcaServer; if (SmtpAddress.IsValidSmtpAddress(this.rpcServerTarget)) { string text; HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text); Guid guid; string domain; string text2; if (RequestQueryStringParser.TryGetMailboxGuid(this.rpcServerTarget, text, ref guid, ref domain, ref text2)) { MailboxGuidAnchorMailbox result; if (!string.IsNullOrEmpty(text2)) { this.rpcServerTarget = ExchangeRpcClientAccess.CreatePersonalizedServer(guid, text2); base.Logger.AppendString(3, "MailboxGuidWithDomain-ChangedToUserDomain"); result = new MailboxGuidAnchorMailbox(guid, text2, this); } else { base.Logger.AppendString(3, "MailboxGuidWithDomain"); result = new MailboxGuidAnchorMailbox(guid, domain, this); } this.updateRpcServer = true; return(result); } return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "InvalidFormat")); } else { ProxyDestination proxyDestination; if (RpcHttpProxyRules.Instance.TryGetProxyDestination(this.rpcServerTarget, out proxyDestination)) { string text3 = proxyDestination.GetHostName(this.GetKeyForCasAffinity()); if (proxyDestination.IsDynamicTarget) { try { text3 = DownLevelServerManager.Instance.GetDownLevelClientAccessServerWithPreferredServer <RpcHttpService>(new ServerInfoAnchorMailbox(text3, this), text3, 1, base.Logger, proxyDestination.Version).Fqdn; } catch (NoAvailableDownLevelBackEndException) { throw new HttpProxyException(HttpStatusCode.NotFound, 3001, string.Format("Cannot find a healthy E12 or E14 CAS to proxy to: {0}", this.rpcServerTarget)); } } uriBuilder.Host = text3; uriBuilder.Port = proxyDestination.Port; uriBuilder.Scheme = Uri.UriSchemeHttps; base.Logger.Set(3, "RpcHttpProxyRules"); this.updateRpcServer = false; return(new UrlAnchorMailbox(uriBuilder.Uri, this)); } return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "UnknownServerName")); } }
public ClientAccessServerOrArrayIdParameter(ExchangeRpcClientAccess rpcClientAccess) : this(rpcClientAccess.Server) { }
// Token: 0x06000773 RID: 1907 RVA: 0x0001CFD4 File Offset: 0x0001B1D4 internal static AutodiscoverCommonUserSettings GetSettingsFromRecipient(ADUser user, string emailAddress) { bool flag = AutodiscoverCommonUserSettings.IsArchiveMailUser(user) || AutodiscoverCommonUserSettings.IsEmailAddressTargetingArchive(user, emailAddress); string domain = user.PrimarySmtpAddress.Domain; Guid mailboxGuid = flag ? user.ArchiveGuid : user.ExchangeGuid; return(new AutodiscoverCommonUserSettings(flag ? AutodiscoverCommonUserSettings.GetArchiveDisplayName(user) : user.DisplayName, flag ? user.GetAlternateMailboxLegDN(user.ArchiveGuid) : user.LegacyExchangeDN, user.PrimarySmtpAddress, ExchangeRpcClientAccess.CreatePersonalizedServer(mailboxGuid, domain), mailboxGuid)); }
protected override AnchorMailbox ResolveAnchorMailbox() { UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url); if (string.IsNullOrEmpty(base.ClientRequest.Url.Query)) { throw new HttpProxyException(HttpStatusCode.NotFound, HttpProxySubErrorCode.EndpointNotFound, "No proxy destination is specified!"); } RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query); this.rpcServerTarget = rpcHttpQueryString.RcaServer; if (SmtpAddress.IsValidSmtpAddress(this.rpcServerTarget)) { Guid mailboxGuid = Guid.Empty; string text = string.Empty; try { SmtpAddress smtpAddress = new SmtpAddress(this.rpcServerTarget); mailboxGuid = new Guid(smtpAddress.Local); text = smtpAddress.Domain; } catch (FormatException) { return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "InvalidFormat")); } base.Logger.Set(HttpProxyMetadata.RoutingHint, "MailboxGuidWithDomain"); if (!text.Contains(".")) { string text2 = base.HttpContext.Items[Constants.WLIDMemberName] as string; if (!string.IsNullOrEmpty(text2)) { SmtpAddress smtpAddress2 = new SmtpAddress(text2); string domain = smtpAddress2.Domain; if (domain != null && !string.Equals(domain, text, StringComparison.OrdinalIgnoreCase)) { ExTraceGlobals.BriefTracer.TraceError((long)this.GetHashCode(), "[RpcHttpProxyRequestHandler::ResolveAnchorMailbox]: Fixing up invalid domain name from client: {0} to {1}; Context {2}; State {3}", new object[] { text, domain, base.TraceContext, base.State }); text = domain; this.rpcServerTarget = ExchangeRpcClientAccess.CreatePersonalizedServer(mailboxGuid, text); base.Logger.AppendString(HttpProxyMetadata.RoutingHint, "-ChangedToUserDomain"); } } } this.updateRpcServer = true; return(new MailboxGuidAnchorMailbox(mailboxGuid, text, this)); } ProxyDestination proxyDestination; if (this.proxyRules.TryGetProxyDestination(this.rpcServerTarget, out proxyDestination)) { string text3 = proxyDestination.GetHostName(this.GetKeyForCasAffinity()); if (proxyDestination.IsDynamicTarget) { try { text3 = DownLevelServerManager.Instance.GetDownLevelClientAccessServerWithPreferredServer <RpcHttpService>(new ServerInfoAnchorMailbox(text3, this), text3, ClientAccessType.External, base.Logger, proxyDestination.Version).Fqdn; } catch (NoAvailableDownLevelBackEndException) { throw new HttpProxyException(HttpStatusCode.NotFound, HttpProxySubErrorCode.EndpointNotFound, string.Format("Cannot find a healthy E12 or E14 CAS to proxy to: {0}", this.rpcServerTarget)); } } uriBuilder.Host = text3; uriBuilder.Port = proxyDestination.Port; uriBuilder.Scheme = Uri.UriSchemeHttps; base.Logger.Set(HttpProxyMetadata.RoutingHint, "RpcHttpProxyRules"); this.updateRpcServer = false; return(new UrlAnchorMailbox(uriBuilder.Uri, this)); } return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "UnknownServerName")); }