From 3d536944153d4931cf891d6a788a47484f3e6f4d Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 18 Jan 2010 16:34:23 -0800 Subject: [PATCH] Go Home works. With security!! --- .../ClientStack/LindenUDP/LLUDPServer.cs | 20 +++ .../EntityTransfer/EntityTransferModule.cs | 10 +- .../EntityTransfer/HGEntityTransferModule.cs | 69 ++++++++- .../Resources/CoreModulePlugin.addin.xml | 2 +- .../HypergridServiceInConnectorModule.cs | 3 +- .../Hypergrid/GatekeeperServerConnector.cs | 4 + .../HomeUsersSecurityServerConnector.cs | 122 ++++++++++++++++ .../HomeUsersSecurityServiceConnector.cs | 132 ++++++++++++++++++ .../HypergridService/GatekeeperService.cs | 53 ++++--- .../HomeUsersSecurityService.cs | 67 +++++++++ .../Services/Interfaces/IGatekeeperService.cs | 11 ++ .../Services/Interfaces/IHypergridService.cs | 1 + bin/config-include/StandaloneHypergrid.ini | 3 + 13 files changed, 471 insertions(+), 26 deletions(-) rename OpenSim/Region/CoreModules/ServiceConnectorsIn/{Grid => Hypergrid}/HypergridServiceInConnectorModule.cs (96%) create mode 100644 OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs create mode 100644 OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs create mode 100644 OpenSim/Services/HypergridService/HomeUsersSecurityService.cs diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 3c4fa72363..ffd2546b6e 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -38,6 +38,7 @@ using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Statistics; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; using OpenMetaverse; using TokenBucket = OpenSim.Region.ClientStack.LindenUDP.TokenBucket; @@ -900,6 +901,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!m_scene.TryGetClient(agentID, out existingClient)) { + IHomeUsersSecurityService security = m_scene.RequestModuleInterface(); + if (security != null) + { + IPEndPoint ep = security.GetEndPoint(sessionID); + if (ep != null && ep.ToString() != remoteEndPoint.ToString()) + { + // uh-oh, this is fishy + m_log.WarnFormat("[LLUDPSERVER]: Agent {0} with session {1} connecting with unidentified end point. Refusing service.", agentID, sessionID); + m_log.WarnFormat("[LLUDPSERVER]: EP was {0}, now is {1}", ep.ToString(), remoteEndPoint.ToString()); + return; + } + else if (ep != null) + { + // ok, you're home, welcome back + m_log.InfoFormat("LLUDPSERVER]: Agent {0} is coming back to this grid", agentID); + security.RemoveEndPoint(sessionID); + } + } + // Create the LLClientView LLClientView client = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); client.OnLogout += LogoutHandler; diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index e85f270343..ed8c0fd8f5 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -134,8 +134,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (!sp.Scene.Permissions.CanTeleport(sp.UUID)) return; - bool destRegionUp = true; - IEventQueue eq = sp.Scene.RequestModuleInterface(); // Reset animations; the viewer does that in teleports. @@ -240,8 +238,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq) { m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation to {0} in {1}", - position, reg.RegionName); + "[ENTITY TRANSFER MODULE]: Request Teleport to {0}:{1}:{2}/{3} final destination {4}", + reg.ExternalHostName, reg.HttpPort, reg.RegionName, position, finalDestination.RegionName); uint newRegionX = (uint)(reg.RegionHandle >> 40); uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); @@ -297,7 +295,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer string reason = String.Empty; // Let's create an agent there if one doesn't exist yet. - if (!CreateAgent(reg, finalDestination, agentCircuit, teleportFlags, out reason)) + if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason)) { sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", reason)); @@ -458,7 +456,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } - protected virtual bool CreateAgent(GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) + protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) { return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); } diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 0e6323b22f..d39537dc8a 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -34,6 +34,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Connectors.Hypergrid; using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; using GridRegion = OpenSim.Services.Interfaces.GridRegion; @@ -59,6 +60,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } private GatekeeperServiceConnector m_GatekeeperConnector; + private IHomeUsersSecurityService m_Security; #region ISharedRegionModule @@ -77,12 +79,42 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { m_agentsInTransit = new List(); m_GatekeeperConnector = new GatekeeperServiceConnector(); + + IConfig config = source.Configs["HGEntityTransferModule"]; + if (config != null) + { + string dll = config.GetString("HomeUsersSecurityService", string.Empty); + if (dll != string.Empty) + { + Object[] args = new Object[] { source }; + m_Security = ServerUtils.LoadPlugin(dll, args); + if (m_Security == null) + m_log.Debug("[HG ENTITY TRANSFER MODULE]: Unable to load Home Users Security service"); + else + m_log.Debug("[HG ENTITY TRANSFER MODULE]: Home Users Security service loaded"); + } + } + m_Enabled = true; m_log.InfoFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); } } } + public override void AddRegion(Scene scene) + { + base.AddRegion(scene); + if (m_Enabled) + scene.RegisterModuleInterface(m_Security); + } + + public override void RemoveRegion(Scene scene) + { + base.AddRegion(scene); + if (m_Enabled) + scene.UnregisterModuleInterface(m_Security); + } + #endregion @@ -98,13 +130,25 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return true; } - protected override bool CreateAgent(GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) + protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) { reason = string.Empty; - if (reg.RegionLocX != finalDestination.RegionLocX && reg.RegionLocY != finalDestination.RegionLocY) + if (reg.RegionLocX != finalDestination.RegionLocX || reg.RegionLocY != finalDestination.RegionLocY) { // this user is going to another grid reg.RegionName = finalDestination.RegionName; + reg.RegionID = finalDestination.RegionID; + reg.RegionLocX = finalDestination.RegionLocX; + reg.RegionLocY = finalDestination.RegionLocY; + + // Log their session and remote endpoint in the home users security service + IHomeUsersSecurityService security = sp.Scene.RequestModuleInterface(); + if (security != null) + security.SetEndPoint(sp.ControllingClient.SessionId, sp.ControllingClient.RemoteEndPoint); + + // Log them out of this grid + sp.Scene.PresenceService.LogoutAgent(agentCircuit.SessionID, sp.AbsolutePosition, sp.Lookat); + return m_GatekeeperConnector.CreateAgent(reg, agentCircuit, teleportFlags, out reason); } @@ -145,6 +189,26 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; GridRegion finalDestination = m_GatekeeperConnector.GetHomeRegion(homeGatekeeper, aCircuit.AgentID, out position, out lookAt); + if (finalDestination == null) + { + client.SendTeleportFailed("Your home region could not be found"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's home region not found"); + return; + } + + ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(client.AgentId); + if (sp == null) + { + client.SendTeleportFailed("Internal error"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be"); + return; + } + + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}:{5}", + aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ExternalHostName, homeGatekeeper.HttpPort, homeGatekeeper.RegionName); + + IEventQueue eq = sp.Scene.RequestModuleInterface(); + DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome), eq); } #endregion @@ -159,6 +223,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer region.ExternalHostName = uri.Host; region.HttpPort = (uint)uri.Port; region.RegionName = string.Empty; + region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0); return region; } } diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml index c61198d8fe..0e3739ae8a 100644 --- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml +++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml @@ -62,7 +62,7 @@ \ - \ + \ \ \ \ diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs similarity index 96% rename from OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs rename to OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs index 6ec0fcf9cf..6e6946c64f 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs @@ -40,7 +40,7 @@ using OpenSim.Server.Handlers.Hypergrid; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; -namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid +namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Hypergrid { public class HypergridServiceInConnectorModule : ISharedRegionModule { @@ -119,6 +119,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid ISimulationService simService = scene.RequestModuleInterface(); m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); + scene.RegisterModuleInterface(m_HypergridHandler.GateKeeper); } } diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index f03d33a97e..15b29d2e60 100644 --- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -46,6 +46,10 @@ namespace OpenSim.Server.Handlers.Hypergrid MethodBase.GetCurrentMethod().DeclaringType); private IGatekeeperService m_GatekeeperService; + public IGatekeeperService GateKeeper + { + get { return m_GatekeeperService; } + } public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : base(config, server, String.Empty) diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs new file mode 100644 index 0000000000..5379784acb --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; + +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; + +namespace OpenSim.Server.Handlers.Hypergrid +{ + public class HomeUsersSecurityServerConnector : ServiceConnector + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IHomeUsersSecurityService m_HomeUsersService; + + public HomeUsersSecurityServerConnector(IConfigSource config, IHttpServer server) : + base(config, server, String.Empty) + { + IConfig gridConfig = config.Configs["HomeUsersSecurityService"]; + if (gridConfig != null) + { + string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); + Object[] args = new Object[] { config }; + m_HomeUsersService = ServerUtils.LoadPlugin(serviceDll, args); + } + if (m_HomeUsersService == null) + throw new Exception("HomeUsersSecurity server connector cannot proceed because of missing service"); + + server.AddXmlRPCHandler("ep_get", GetEndPoint, false); + server.AddXmlRPCHandler("ep_set", SetEndPoint, false); + server.AddXmlRPCHandler("ep_remove", RemoveEndPoint, false); + + } + + public XmlRpcResponse GetEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + //string host = (string)requestData["host"]; + //string portstr = (string)requestData["port"]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + + IPEndPoint ep = m_HomeUsersService.GetEndPoint(sessionID); + + Hashtable hash = new Hashtable(); + if (ep == null) + hash["result"] = "false"; + else + { + hash["result"] = "true"; + hash["ep_addr"] = ep.Address.ToString(); + hash["ep_port"] = ep.Port.ToString(); + } + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + public XmlRpcResponse SetEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + string host = (string)requestData["ep_addr"]; + string portstr = (string)requestData["ep_port"]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + int port = 0; + Int32.TryParse(portstr, out port); + + IPEndPoint ep = null; + try + { + ep = new IPEndPoint(IPAddress.Parse(host), port); + } + catch + { + m_log.Debug("[HOME USERS SECURITY]: Exception in creating EndPoint"); + } + + m_HomeUsersService.SetEndPoint(sessionID, ep); + + Hashtable hash = new Hashtable(); + hash["result"] = "true"; + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + public XmlRpcResponse RemoveEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + + m_HomeUsersService.RemoveEndPoint(sessionID); + + Hashtable hash = new Hashtable(); + hash["result"] = "true"; + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + } +} diff --git a/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs new file mode 100644 index 0000000000..150690b808 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using OpenSim.Services.Interfaces; + +using OpenMetaverse; +using log4net; +using Nwc.XmlRpc; +using Nini.Config; + +namespace OpenSim.Services.Connectors.Hypergrid +{ + public class HomeUsersSecurityServiceConnector : IHomeUsersSecurityService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + string m_ServerURL; + public HomeUsersSecurityServiceConnector(string url) + { + m_ServerURL = url; + } + + public HomeUsersSecurityServiceConnector(IConfigSource config) + { + } + + public void SetEndPoint(UUID sessionID, IPEndPoint ep) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + hash["ep_addr"] = ep.Address.ToString(); + hash["ep_port"] = ep.Port.ToString(); + + Call("ep_set", hash); + } + + public void RemoveEndPoint(UUID sessionID) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + + Call("ep_remove", hash); + } + + public IPEndPoint GetEndPoint(UUID sessionID) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest("ep_get", paramList); + //m_log.Debug("[HGrid]: Linking to " + uri); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception " + e.Message); + return null; + } + + if (response.IsFault) + { + m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); + return null; + } + + hash = (Hashtable)response.Value; + //foreach (Object o in hash) + // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); + try + { + bool success = false; + Boolean.TryParse((string)hash["result"], out success); + if (success) + { + IPEndPoint ep = null; + int port = 0; + if (hash["ep_port"] != null) + Int32.TryParse((string)hash["ep_port"], out port); + if (hash["ep_addr"] != null) + ep = new IPEndPoint(IPAddress.Parse((string)hash["ep_addr"]), port); + + return ep; + } + + } + catch (Exception e) + { + m_log.Error("[HGrid]: Got exception while parsing GetEndPoint response " + e.StackTrace); + return null; + } + + return null; + } + + private void Call(string method, Hashtable hash) + { + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest(method, paramList); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception " + e.Message); + return ; + } + + if (response.IsFault) + { + m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); + return ; + } + + } + + } +} diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs index 55d9ce11d9..169cfa34a7 100644 --- a/OpenSim/Services/HypergridService/GatekeeperService.cs +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Net; using System.Reflection; using OpenSim.Framework; @@ -51,6 +52,7 @@ namespace OpenSim.Services.HypergridService IPresenceService m_PresenceService; IAuthenticationService m_AuthenticationService; IUserAccountService m_UserAccountService; + IHomeUsersSecurityService m_HomeUsersSecurityService; ISimulationService m_SimulationService; string m_AuthDll; @@ -66,14 +68,15 @@ namespace OpenSim.Services.HypergridService throw new Exception(String.Format("No section GatekeeperService in config file")); string accountService = serverConfig.GetString("UserAccountService", String.Empty); + string homeUsersSecurityService = serverConfig.GetString("HomeUsersSecurityService", string.Empty); string gridService = serverConfig.GetString("GridService", String.Empty); string presenceService = serverConfig.GetString("PresenceService", String.Empty); string simulationService = serverConfig.GetString("SimulationService", String.Empty); m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty); - if (accountService == string.Empty || gridService == string.Empty || - presenceService == string.Empty || m_AuthDll == string.Empty) + // These 3 are mandatory, the others aren't + if (gridService == string.Empty || presenceService == string.Empty || m_AuthDll == string.Empty) throw new Exception("Incomplete specifications, Gatekeeper Service cannot function."); string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString()); @@ -82,16 +85,20 @@ namespace OpenSim.Services.HypergridService m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true); Object[] args = new Object[] { config }; - m_UserAccountService = ServerUtils.LoadPlugin(accountService, args); m_GridService = ServerUtils.LoadPlugin(gridService, args); m_PresenceService = ServerUtils.LoadPlugin(presenceService, args); + + if (accountService != string.Empty) + m_UserAccountService = ServerUtils.LoadPlugin(accountService, args); + if (homeUsersSecurityService != string.Empty) + m_HomeUsersSecurityService = ServerUtils.LoadPlugin(homeUsersSecurityService, args); + if (simService != null) m_SimulationService = simService; else if (simulationService != string.Empty) m_SimulationService = ServerUtils.LoadPlugin(simulationService, args); - if (m_UserAccountService == null || m_GridService == null || - m_PresenceService == null || m_SimulationService == null) + if (m_GridService == null || m_PresenceService == null || m_SimulationService == null) throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function."); m_log.Debug("[GATEKEEPER SERVICE]: Starting..."); @@ -183,17 +190,31 @@ namespace OpenSim.Services.HypergridService } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); - // Check to see if we have a local user with that UUID - UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); - if (account != null) - { - // No, sorry; go away - reason = "User identifier not allowed on this grid"; - m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has UUID of local user {3}. Refusing service.", - aCircuit.firstname, aCircuit.lastname, aCircuit.AgentID); - return false; - } - m_log.DebugFormat("[GATEKEEPER SERVICE]: User ID ok"); + //if (m_UserAccountService != null && m_HomeUsersSecurityService != null) + //{ + // // Check to see if we have a local user with that UUID + // UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); + + // // See if that user went out of this home grid + // IPEndPoint ep = m_HomeUsersSecurityService.GetEndPoint(aCircuit.AgentID); + + // if (account != null) + // { + // if ((ep == null) || // there's no memory of this agent going out + // (ep != null && (ep.Address != aCircuit.ClientEndPoint.Address || ep.Port != aCircuit.ClientEndPoint.Port))) // fake agent + // { + // // No, sorry; go away + // reason = "User identifier not allowed on this grid"; + // m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has UUID of local user {2}. Refusing service.", + // aCircuit.firstname, aCircuit.lastname, aCircuit.AgentID); + // return false; + // } + // else + // { + // } + // } + // m_log.DebugFormat("[GATEKEEPER SERVICE]: User ID ok"); + //} // May want to authorize diff --git a/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs b/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs new file mode 100644 index 0000000000..a7adfc1f3f --- /dev/null +++ b/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using OpenSim.Services.Interfaces; + +using OpenMetaverse; +using log4net; +using Nini.Config; + +namespace OpenSim.Services.HypergridService +{ + /// + /// This service is for HG1.5 only, to make up for the fact that clients don't + /// keep any private information in themselves, and that their 'home service' + /// needs to do it for them. + /// Once we have better clients, this shouldn't be needed. + /// + public class HomeUsersSecurityService : IHomeUsersSecurityService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + // + // This is a persistent storage wannabe for dealing with the + // quirks of HG1.5. We don't really want to store this in a table. + // But this is the necessary information for securing clients + // coming home. + // + protected static Dictionary m_ClientEndPoints = new Dictionary(); + + public HomeUsersSecurityService(IConfigSource config) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Starting..."); + } + + public void SetEndPoint(UUID sessionID, IPEndPoint ep) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Set EndPoint {0} for session {1}", ep.ToString(), sessionID); + + lock (m_ClientEndPoints) + m_ClientEndPoints[sessionID] = ep; + } + + public IPEndPoint GetEndPoint(UUID sessionID) + { + lock (m_ClientEndPoints) + if (m_ClientEndPoints.ContainsKey(sessionID)) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Get EndPoint {0} for session {1}", m_ClientEndPoints[sessionID].ToString(), sessionID); + return m_ClientEndPoints[sessionID]; + } + + return null; + } + + public void RemoveEndPoint(UUID sessionID) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Remove EndPoint for session {0}", sessionID); + lock (m_ClientEndPoints) + if (m_ClientEndPoints.ContainsKey(sessionID)) + m_ClientEndPoints.Remove(sessionID); + } + } +} diff --git a/OpenSim/Services/Interfaces/IGatekeeperService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs index 59e0f82702..5b5c9d1811 100644 --- a/OpenSim/Services/Interfaces/IGatekeeperService.cs +++ b/OpenSim/Services/Interfaces/IGatekeeperService.cs @@ -26,6 +26,7 @@ */ using System; +using System.Net; using System.Collections.Generic; using OpenSim.Framework; @@ -43,4 +44,14 @@ namespace OpenSim.Services.Interfaces GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); } + + /// + /// HG1.5 only + /// + public interface IHomeUsersSecurityService + { + void SetEndPoint(UUID sessionID, IPEndPoint ep); + IPEndPoint GetEndPoint(UUID sessionID); + void RemoveEndPoint(UUID sessionID); + } } diff --git a/OpenSim/Services/Interfaces/IHypergridService.cs b/OpenSim/Services/Interfaces/IHypergridService.cs index dd3c053813..86ef1b4198 100644 --- a/OpenSim/Services/Interfaces/IHypergridService.cs +++ b/OpenSim/Services/Interfaces/IHypergridService.cs @@ -43,6 +43,7 @@ namespace OpenSim.Services.Interfaces GridRegion GetRegionByName(string name); List GetRegionsByName(string name); List GetRegionRange(int xmin, int xmax, int ymin, int ymax); + } } diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index eb887a68cb..28b9d478d0 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -82,6 +82,9 @@ GridService = "OpenSim.Services.GridService.dll:GridService" AuthenticationService = "OpenSim.Services.Connectors.dll:AuthenticationServicesConnector" +[HGEntityTransferModule] + HomeUsersSecurityService = "OpenSim.Services.HypergridService.dll:HomeUsersSecurityService" + [PresenceService] LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService"