Esempio n. 1
0
 internal static void Start()
 {
     ServerFqdnCache.InitializeCache();
     if (RfriServer.instance == null)
     {
         bool flag = false;
         try
         {
             RfriServer.instance = (RfriServer)RpcServerBase.RegisterAutoListenInterfaceSupportingAnonymous(typeof(RfriServer), RpcServerBase.DefaultMaxRpcCalls, "Microsoft Exchange RFR Interface", true);
             flag = true;
         }
         catch (RpcException ex)
         {
             RfriServer.ReferralTracer.TraceError <string>(0L, "Error registering the RFR RPC interface: {0}", ex.Message);
             RfriServer.eventLog.LogEvent(AddressBookEventLogConstants.Tuple_RpcRegisterInterfaceFailure, string.Empty, new object[]
             {
                 "RFR",
                 ServiceHelper.FormatWin32ErrorString(ex.ErrorCode)
             });
         }
         finally
         {
             if (!flag)
             {
                 RfriServer.rfriAsyncDispatch = null;
                 RfriServer.Stop();
                 RfriServer.instance = null;
             }
         }
     }
 }
Esempio n. 2
0
 internal static void Stop()
 {
     if (RfriServer.instance != null)
     {
         RpcServerBase.UnregisterInterface(RfriAsyncRpcServer.RpcIntfHandle, true);
         RfriServer.instance = null;
     }
     ServerFqdnCache.TerminateCache();
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        internal RfriStatus GetNewDSA(string userDN, out string serverFQDN)
        {
            serverFQDN = null;
            RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "Requested user DN: {0}", RfriContext.GetString(userDN));
            string     str;
            RfriStatus rfriStatus;

            if (this.IsUsingHttp())
            {
                str = userDN;
                if (!this.TryGetPersonalizedServer(userDN, out serverFQDN))
                {
                    rfriStatus = ServerFqdnCache.LookupFQDNByLegacyDN(null, out serverFQDN);
                    RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "ServerFqdnCache.LookupFQDNByLegacyDN(null): {0}", serverFQDN ?? "(null)");
                }
                else
                {
                    rfriStatus = RfriStatus.Success;
                }
            }
            else
            {
                string clientAccessServerLegacyDN = this.GetClientAccessServerLegacyDN(userDN);
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "RfriContext.GetClientAccessServerLegacyDN: {0}", clientAccessServerLegacyDN ?? "(null)");
                str        = clientAccessServerLegacyDN;
                rfriStatus = ServerFqdnCache.LookupFQDNByLegacyDN(clientAccessServerLegacyDN, out serverFQDN);
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "ServerFqdnCache.LookupFQDNByLegacyDN: {0}", serverFQDN ?? "(null)");
            }
            if (rfriStatus != RfriStatus.Success || string.IsNullOrEmpty(serverFQDN))
            {
                if (rfriStatus == RfriStatus.Success)
                {
                    rfriStatus = RfriStatus.NoSuchObject;
                }
                this.ProtocolLogSession[ProtocolLog.Field.Failures] = RfriContext.GetString(str);
            }
            else
            {
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "Referring to {0}", serverFQDN);
            }
            return(rfriStatus);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        private static void ReloadCache(object state)
        {
            ServerFqdnCache.ReferralTracer.TraceDebug(0L, "Reloading RFR server FQDN cache");
            if (Interlocked.CompareExchange(ref ServerFqdnCache.reloadCacheInProgress, 1, 0) == 1)
            {
                ServerFqdnCache.ReferralTracer.TraceDebug(0L, "Reload already running on another thread, skipping.");
                return;
            }
            ComparisonFilter comparisonFilter = null;

            try
            {
                Dictionary <string, string> dictionary = null;
                try
                {
                    ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 186, "ReloadCache", "f:\\15.00.1497\\sources\\dev\\DoMT\\src\\Service\\ServerFqdnCache.cs");
                    topologyConfigurationSession.ServerTimeout = Configuration.ADTimeout;
                    if (DateTime.UtcNow - ServerFqdnCache.lastFullSync < ServerFqdnCache.FullSyncInterval && ServerFqdnCache.lastDeltaSync != DateTime.MinValue)
                    {
                        comparisonFilter = new ComparisonFilter(ComparisonOperator.GreaterThanOrEqual, ADObjectSchema.WhenChanged, ServerFqdnCache.lastDeltaSync - ServerFqdnCache.ReplicationDelayTolerance);
                    }
                    else
                    {
                        ServerFqdnCache.lastFullSync  = DateTime.UtcNow;
                        ServerFqdnCache.lastDeltaSync = DateTime.MinValue;
                    }
                    dictionary = ((ServerFqdnCache.serverFqdnDictionary == null || comparisonFilter == null) ? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) : new Dictionary <string, string>(ServerFqdnCache.serverFqdnDictionary, StringComparer.OrdinalIgnoreCase));
                    IEnumerable <Server> enumerable = topologyConfigurationSession.FindPaged <Server>(null, QueryScope.SubTree, comparisonFilter, null, 0);
                    DateTime             dateTime   = DateTime.MinValue;
                    foreach (Server server in enumerable)
                    {
                        if (server.WhenChanged != null && server.WhenChanged > dateTime)
                        {
                            dateTime = server.WhenChanged.Value;
                        }
                        if (!string.IsNullOrEmpty(server.ExchangeLegacyDN) && !string.IsNullOrEmpty(server.Fqdn))
                        {
                            dictionary[server.ExchangeLegacyDN] = server.Fqdn;
                            ServerFqdnCache.ReferralTracer.TraceDebug <string, string>(0L, "Server {0}: {1}", server.ExchangeLegacyDN, server.Fqdn);
                        }
                    }
                    if (dateTime != DateTime.MinValue)
                    {
                        ServerFqdnCache.lastDeltaSync = dateTime;
                    }
                    ADObjectId adobjectId = null;
                    Server     server2    = topologyConfigurationSession.ReadLocalServer();
                    if (server2 != null && !string.IsNullOrEmpty(server2.Fqdn))
                    {
                        ServerFqdnCache.ReferralTracer.TraceDebug <string>(0L, "Default server: {0}", server2.Fqdn);
                        dictionary["//default//"] = server2.Fqdn;
                        adobjectId = server2.ServerSite;
                    }
                    IEnumerable <ClientAccessArray> enumerable2 = topologyConfigurationSession.FindPaged <ClientAccessArray>(null, QueryScope.SubTree, ClientAccessArray.PriorTo15ExchangeObjectVersionFilter, null, 0);
                    foreach (ClientAccessArray clientAccessArray in enumerable2)
                    {
                        if (!string.IsNullOrEmpty(clientAccessArray.Fqdn) && !string.IsNullOrEmpty(clientAccessArray.ExchangeLegacyDN))
                        {
                            dictionary[clientAccessArray.ExchangeLegacyDN] = clientAccessArray.Fqdn;
                            ServerFqdnCache.ReferralTracer.TraceDebug <string, string>(0L, "Array {0}: {1}", clientAccessArray.ExchangeLegacyDN, clientAccessArray.Fqdn);
                        }
                        if (adobjectId != null && adobjectId.Equals(clientAccessArray.Site))
                        {
                            dictionary["//default//"] = clientAccessArray.Fqdn;
                            ServerFqdnCache.ReferralTracer.TraceDebug <string>(0L, "Default server: {0} (array)", clientAccessArray.Fqdn);
                        }
                    }
                }
                catch (ADTransientException arg)
                {
                    ServerFqdnCache.ReferralTracer.TraceError <ADTransientException>(0L, "Exception reloading RFR server FQDN cache: {0}", arg);
                    ServerFqdnCache.RestartTimer(ServerFqdnCache.ErrorRetryInterval, ServerFqdnCache.ReloadInterval);
                    return;
                }
                catch (DataSourceOperationException arg2)
                {
                    ServerFqdnCache.ReferralTracer.TraceError <DataSourceOperationException>(0L, "Exception reloading RFR server FQDN cache: {0}", arg2);
                    ServerFqdnCache.RestartTimer(ServerFqdnCache.ErrorRetryInterval, ServerFqdnCache.ReloadInterval);
                    return;
                }
                ServerFqdnCache.serverFqdnDictionary = dictionary;
                ServerFqdnCache.RestartTimer(ServerFqdnCache.ReloadInterval, ServerFqdnCache.ReloadInterval);
                ServerFqdnCache.ReferralTracer.TraceDebug(0L, "Reload complete");
            }
            finally
            {
                Interlocked.Exchange(ref ServerFqdnCache.reloadCacheInProgress, 0);
            }
        }