protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID) { if (m_SimulationService == null) { m_log.Debug("[AGENT HANDLER]: Agent QUERY called. Harmless but useless."); responsedata["content_type"] = "application/json"; responsedata["int_response_code"] = HttpStatusCode.NotImplemented; responsedata["str_response_string"] = string.Empty; return; } // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); OSDMap args = Utils.GetOSDMap((string)request["body"]); Vector3 position = Vector3.Zero; if (args.ContainsKey("position")) { position = Vector3.Parse(args["position"].AsString()); } string agentHomeURI = null; if (args.ContainsKey("agent_home_uri")) { agentHomeURI = args["agent_home_uri"].AsString(); } string theirVersion = string.Empty; if (args.ContainsKey("my_version")) { theirVersion = args["my_version"].AsString(); } GridRegion destination = new GridRegion(); destination.RegionID = regionID; string reason; string version; bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, position, theirVersion, out version, out reason); responsedata["int_response_code"] = HttpStatusCode.OK; OSDMap resp = new OSDMap(3); resp["success"] = OSD.FromBoolean(result); resp["reason"] = OSD.FromString(reason); resp["version"] = OSD.FromString(version); // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); }
private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason) { string version; if ( !simConnector.QueryAccess( region, aCircuit.AgentID, null, true, aCircuit.startpos, "SIMULATION/0.3", out version, out reason)) { return(false); } return(simConnector.CreateAgent(null, region, aCircuit, (uint)flags, out reason)); }
protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) { if (m_SimulationService == null) { m_log.Debug("[AGENT HANDLER]: Agent QUERY called. Harmless but useless."); responsedata["content_type"] = "application/json"; responsedata["int_response_code"] = HttpStatusCode.NotImplemented; responsedata["str_response_string"] = string.Empty; return; } // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); OSDMap args = Utils.GetOSDMap((string)request["body"]); Vector3 position = Vector3.Zero; if (args.ContainsKey("position")) { position = Vector3.Parse(args["position"].AsString()); } GridRegion destination = new GridRegion(); destination.RegionID = regionID; string reason; string version; bool result = m_SimulationService.QueryAccess(destination, id, position, out version, out reason); responsedata["int_response_code"] = HttpStatusCode.OK; OSDMap resp = new OSDMap(2); resp["success"] = OSD.FromBoolean(result); resp["reason"] = OSD.FromString(reason); resp["version"] = OSD.FromString(version); responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); }
public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason) { reason = string.Empty; string authURL = string.Empty; if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) { authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); } m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9}, Teleport Flags: {10}. From region {11}", aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID, aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags, (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI)); string curViewer = Util.GetViewerName(aCircuit); // // Check client // if (m_AllowedClients != string.Empty) { Regex arx = new Regex(m_AllowedClients); Match am = arx.Match(curViewer); if (!am.Success) { reason = "Login failed: client " + curViewer + " is not allowed"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer); return(false); } } if (m_DeniedClients != string.Empty) { Regex drx = new Regex(m_DeniedClients); Match dm = drx.Match(curViewer); if (dm.Success) { reason = "Login failed: client " + curViewer + " is denied"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer); return(false); } } // // Authenticate the user // if (!Authenticate(aCircuit)) { reason = "Unable to verify identity"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); // // Check for impersonations // UserAccount account = null; if (m_UserAccountService != null) { // Check to see if we have a local user with that UUID account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); if (account != null) { // Make sure this is the user coming home, and not a foreign user with same UUID as a local user if (m_UserAgentService != null) { if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_ExternalName)) { // Can't do, sorry reason = "Unauthorized"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } } } } // // Foreign agents allowed? Exceptions? // if (account == null) { bool allowed = m_ForeignAgentsAllowed; if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions)) { allowed = false; } if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions)) { allowed = true; } if (!allowed) { reason = "Destination does not allow visitors from your world"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.", aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]); return(false); } } // // Is the user banned? // This uses a Ban service that's more powerful than the configs // string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit)); if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL)) { reason = "You are banned from this world"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui); return(false); } m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name); bool isFirstLogin = false; // // Login the presence, if it's not there yet (by the login service) // PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID); if (presence != null) // it has been placed there by the login service { isFirstLogin = true; } else { if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) { reason = "Unable to login presence"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name); // Also login foreigners with GridUser service if (m_GridUserService != null && account == null) { string userId = aCircuit.AgentID.ToString(); string first = aCircuit.firstname, last = aCircuit.lastname; if (last.StartsWith("@")) { string[] parts = aCircuit.firstname.Split('.'); if (parts.Length >= 2) { first = parts[0]; last = parts[1]; } } userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last; m_GridUserService.LoggedIn(userId); } } // // Get the region // destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID); if (destination == null) { reason = "Destination region not found"; return(false); } m_log.DebugFormat( "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name); // // Adjust the visible name // if (account != null) { aCircuit.firstname = account.FirstName; aCircuit.lastname = account.LastName; } if (account == null) { if (!aCircuit.lastname.StartsWith("@")) { aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; } try { Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString()); aCircuit.lastname = "@" + uri.Authority; } catch { m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]); aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); } } // // Finally launch the agent at the destination // Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin; // Preserve our TeleportFlags we have gathered so-far loginFlag |= (Constants.TeleportFlags)aCircuit.teleportFlags; m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag); EntityTransferContext ctx = new EntityTransferContext(); if (!m_SimulationService.QueryAccess( destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(), true, aCircuit.startpos, new List <UUID>(), ctx, out reason)) { return(false); } return(m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason)); }
private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason) { string version; if ( !simConnector.QueryAccess( region, aCircuit.AgentID, null, true, aCircuit.startpos, "SIMULATION/0.3", out version, out reason)) return false; return simConnector.CreateAgent(null, region, aCircuit, (uint)flags, out reason); }
protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID) { if (m_SimulationService == null) { m_log.Debug("[AGENT HANDLER]: Agent QUERY called. Harmless but useless."); responsedata["content_type"] = "application/json"; responsedata["int_response_code"] = HttpStatusCode.NotImplemented; responsedata["str_response_string"] = string.Empty; return; } // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); OSDMap args = Utils.GetOSDMap((string)request["body"]); bool viaTeleport = true; if (args.ContainsKey("viaTeleport")) { viaTeleport = args["viaTeleport"].AsBoolean(); } Vector3 position = Vector3.Zero; if (args.ContainsKey("position")) { position = Vector3.Parse(args["position"].AsString()); } string agentHomeURI = null; if (args.ContainsKey("agent_home_uri")) { agentHomeURI = args["agent_home_uri"].AsString(); } // Decode the legacy (string) version and extract the number float theirVersion = 0f; if (args.ContainsKey("my_version")) { string theirVersionStr = args["my_version"].AsString(); string[] parts = theirVersionStr.Split(new char[] { '/' }); if (parts.Length > 1) { theirVersion = float.Parse(parts[1]); } } // Decode the new versioning data float minVersionRequired = 0f; float maxVersionRequired = 0f; float minVersionProvided = 0f; float maxVersionProvided = 0f; if (args.ContainsKey("simulation_service_supported_min")) { minVersionProvided = (float)args["simulation_service_supported_min"].AsReal(); } if (args.ContainsKey("simulation_service_supported_max")) { maxVersionProvided = (float)args["simulation_service_supported_max"].AsReal(); } if (args.ContainsKey("simulation_service_accepted_min")) { minVersionRequired = (float)args["simulation_service_accepted_min"].AsReal(); } if (args.ContainsKey("simulation_service_accepted_max")) { maxVersionRequired = (float)args["simulation_service_accepted_max"].AsReal(); } responsedata["int_response_code"] = HttpStatusCode.OK; OSDMap resp = new OSDMap(3); float version = 0f; float outboundVersion = 0f; float inboundVersion = 0f; if (minVersionProvided == 0f) // string version or older { // If there is no version in the packet at all we're looking at 0.6 or // even more ancient. Refuse it. if (theirVersion == 0f) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString("Your region is running a old version of opensim no longer supported. Consider updating it"); responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); return; } version = theirVersion; if (version < VersionInfo.SimulationServiceVersionAcceptedMin || version > VersionInfo.SimulationServiceVersionAcceptedMax) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("Your region protocol version is {0} and we accept only {1} - {2}. No version overlap.", theirVersion, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); return; } } else { // Test for no overlap if (minVersionProvided > VersionInfo.SimulationServiceVersionAcceptedMax || maxVersionProvided < VersionInfo.SimulationServiceVersionAcceptedMin) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("Your region provide protocol versions {0} - {1} and we accept only {2} - {3}. No version overlap.", minVersionProvided, maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); return; } if (minVersionRequired > VersionInfo.SimulationServiceVersionSupportedMax || maxVersionRequired < VersionInfo.SimulationServiceVersionSupportedMin) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("You require region protocol versions {0} - {1} and we provide only {2} - {3}. No version overlap.", minVersionRequired, maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax)); responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); return; } // Determine versions to use // This is intentionally inverted. Inbound and Outbound refer to the direction of the transfer. // Therefore outbound means from the sender to the receier and inbound means from the receiver to the sender. // So outbound is what we will accept and inbound is what we will send. Confused yet? outboundVersion = Math.Min(maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMax); inboundVersion = Math.Min(maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMax); } List <UUID> features = new List <UUID>(); if (args.ContainsKey("features")) { OSDArray array = (OSDArray)args["features"]; foreach (OSD o in array) { features.Add(new UUID(o.AsString())); } } GridRegion destination = new GridRegion(); destination.RegionID = regionID; string reason; // We're sending the version numbers down to the local connector to do the varregion check. EntityTransferContext ctx = new EntityTransferContext(); ctx.InboundVersion = inboundVersion; ctx.OutboundVersion = outboundVersion; if (minVersionProvided == 0f) { ctx.InboundVersion = version; ctx.OutboundVersion = version; } bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason); resp["success"] = OSD.FromBoolean(result); resp["reason"] = OSD.FromString(reason); string legacyVersion = String.Format("SIMULATION/{0}", version); resp["version"] = OSD.FromString(legacyVersion); resp["negotiated_inbound_version"] = OSD.FromReal(inboundVersion); resp["negotiated_outbound_version"] = OSD.FromReal(outboundVersion); resp["variable_wearables_count_supported"] = OSD.FromBoolean(true); OSDArray featuresWanted = new OSDArray(); foreach (UUID feature in features) { featuresWanted.Add(OSD.FromString(feature.ToString())); } resp["features"] = featuresWanted; // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); }
protected virtual void DoQueryAccess(OSDMap args, IOSHttpResponse httpResponse, UUID agentID, UUID regionID) { bool viaTeleport = true; OSD tmpOSD; if (args.TryGetValue("viaTeleport", out tmpOSD)) { viaTeleport = tmpOSD.AsBoolean(); } Vector3 position = Vector3.Zero; if (args.TryGetValue("position", out tmpOSD)) { position = Vector3.Parse(tmpOSD.AsString()); } string agentHomeURI = null; if (args.TryGetValue("agent_home_uri", out tmpOSD)) { agentHomeURI = tmpOSD.AsString(); } // Decode the legacy (string) version and extract the number float theirVersion = 0f; if (args.TryGetValue("my_version", out tmpOSD)) { string theirVersionStr = tmpOSD.AsString(); string[] parts = theirVersionStr.Split(new char[] { '/' }); if (parts.Length > 1) { theirVersion = float.Parse(parts[1], Culture.FormatProvider); } } EntityTransferContext ctx = new EntityTransferContext(); if (args.TryGetValue("context", out tmpOSD) && tmpOSD is OSDMap) { ctx.Unpack((OSDMap)tmpOSD); } // Decode the new versioning data float minVersionRequired = 0f; float maxVersionRequired = 0f; float minVersionProvided = 0f; float maxVersionProvided = 0f; if (args.TryGetValue("simulation_service_supported_min", out tmpOSD)) { minVersionProvided = (float)tmpOSD.AsReal(); } if (args.TryGetValue("simulation_service_supported_max", out tmpOSD)) { maxVersionProvided = (float)tmpOSD.AsReal(); } if (args.TryGetValue("simulation_service_accepted_min", out tmpOSD)) { minVersionRequired = (float)tmpOSD.AsReal(); } if (args.TryGetValue("simulation_service_accepted_max", out tmpOSD)) { maxVersionRequired = (float)tmpOSD.AsReal(); } OSDMap resp = new OSDMap(3); float version = 0f; httpResponse.StatusCode = (int)HttpStatusCode.OK; float outboundVersion = 0f; float inboundVersion = 0f; if (minVersionProvided == 0f) // string version or older { // If there is no version in the packet at all we're looking at 0.6 or // even more ancient. Refuse it. if (theirVersion == 0f) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString("Your region is running a old version of opensim no longer supported. Consider updating it"); httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp, true)); return; } version = theirVersion; if (version < VersionInfo.SimulationServiceVersionAcceptedMin || version > VersionInfo.SimulationServiceVersionAcceptedMax) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("Your region protocol version is {0} and we accept only {1} - {2}. No version overlap.", theirVersion, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp, true)); return; } } else { // Test for no overlap if (minVersionProvided > VersionInfo.SimulationServiceVersionAcceptedMax || maxVersionProvided < VersionInfo.SimulationServiceVersionAcceptedMin) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("Your region provide protocol versions {0} - {1} and we accept only {2} - {3}. No version overlap.", minVersionProvided, maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp, true)); return; } if (minVersionRequired > VersionInfo.SimulationServiceVersionSupportedMax || maxVersionRequired < VersionInfo.SimulationServiceVersionSupportedMin) { resp["success"] = OSD.FromBoolean(false); resp["reason"] = OSD.FromString(String.Format("You require region protocol versions {0} - {1} and we provide only {2} - {3}. No version overlap.", minVersionRequired, maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax)); httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp, true)); return; } // Determine versions to use // This is intentionally inverted. Inbound and Outbound refer to the direction of the transfer. // Therefore outbound means from the sender to the receier and inbound means from the receiver to the sender. // So outbound is what we will accept and inbound is what we will send. Confused yet? outboundVersion = Math.Min(maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMax); inboundVersion = Math.Min(maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMax); } List <UUID> features = new List <UUID>(); if (args.TryGetValue("features", out tmpOSD) && tmpOSD is OSDArray) { OSDArray array = (OSDArray)tmpOSD; foreach (OSD o in array) { features.Add(new UUID(o.AsString())); } } GridRegion destination = new GridRegion(); destination.RegionID = regionID; string reason; // We're sending the version numbers down to the local connector to do the varregion check. ctx.InboundVersion = inboundVersion; ctx.OutboundVersion = outboundVersion; if (minVersionProvided == 0f) { ctx.InboundVersion = version; ctx.OutboundVersion = version; } bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason); m_log.DebugFormat("[AGENT HANDLER]: QueryAccess returned {0} ({1}). Version={2}, {3}/{4}", result, reason, version, inboundVersion, outboundVersion); resp["success"] = OSD.FromBoolean(result); resp["reason"] = OSD.FromString(reason); string legacyVersion = String.Format(Culture.FormatProvider, "SIMULATION/{0}", version); resp["version"] = OSD.FromString(legacyVersion); resp["negotiated_inbound_version"] = OSD.FromReal(inboundVersion); resp["negotiated_outbound_version"] = OSD.FromReal(outboundVersion); OSDArray featuresWanted = new OSDArray(); foreach (UUID feature in features) { featuresWanted.Add(OSD.FromString(feature.ToString())); } resp["features"] = featuresWanted; if (result) { httpResponse.KeepAlive = true; } // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! httpResponse.RawBuffer = Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp, true)); // console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); }
private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason) { EntityTransferContext ctx = new EntityTransferContext(); if (!simConnector.QueryAccess( region, aCircuit.AgentID, null, true, aCircuit.startpos, new List<UUID>(), ctx, out reason)) return false; return simConnector.CreateAgent(null, region, aCircuit, (uint)flags, ctx, out reason); }
public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason) { reason = string.Empty; string authURL = string.Empty; if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) { authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); } m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9}, Teleport Flags: {10}. From region {11}", aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID, aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags, (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI)); string curViewer = Util.GetViewerName(aCircuit); string curMac = aCircuit.Mac.ToString(); // // Check client // if (!String.IsNullOrWhiteSpace(m_AllowedClients)) { Regex arx = new Regex(m_AllowedClients); Match am = arx.Match(curViewer); if (!am.Success) { reason = "Login failed: client " + curViewer + " is not allowed"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer); return(false); } } if (!String.IsNullOrWhiteSpace(m_DeniedClients)) { Regex drx = new Regex(m_DeniedClients); Match dm = drx.Match(curViewer); if (dm.Success) { reason = "Login failed: client " + curViewer + " is denied"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer); return(false); } } if (!String.IsNullOrWhiteSpace(m_DeniedMacs)) { m_log.InfoFormat("[GATEKEEPER SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs); if (m_DeniedMacs.Contains(curMac)) { reason = "Login failed: client with Mac " + curMac + " is denied"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client with mac {0} is denied", curMac); return(false); } } // // Authenticate the user // if (!Authenticate(aCircuit)) { reason = "Unable to verify identity"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); // // Check for impersonations // UserAccount account = null; if (m_UserAccountService != null) { // Check to see if we have a local user with that UUID account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); if (account != null) { // Make sure this is the user coming home, and not a foreign user with same UUID as a local user if (m_UserAgentService != null) { if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_ExternalName)) { // Can't do, sorry reason = "Unauthorized"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } } } } // // Foreign agents allowed? Exceptions? // if (account == null) { bool allowed = m_ForeignAgentsAllowed; if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions)) { allowed = false; } if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions)) { allowed = true; } if (!allowed) { reason = "Destination does not allow visitors from your world"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.", aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]); return(false); } } // // Is the user banned? // This uses a Ban service that's more powerful than the configs // // string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit)); // if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL)) // { // reason = "You are banned from this world"; // m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui); // return false; // } // Check if the hardware or IP is banned if (m_AccessControlService != null) { if (m_AccessControlService.IsHardwareBanned(aCircuit.Mac, aCircuit.Id0) || m_AccessControlService.IsIPBanned(aCircuit.IPAddress)) { reason = "You are banned from this grid."; m_log.InfoFormat("[GATEKEEPER SERVICE] Login failed for {0}, reason: hardware or ip is banned", aCircuit.AgentID); return(false); } } UUID agentID = aCircuit.AgentID; if (agentID == new UUID("6571e388-6218-4574-87db-f9379718315e")) { // really? reason = "Invalid account ID"; return(false); } if (m_GridUserService != null) { string PrincipalIDstr = agentID.ToString(); GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr); if (!m_allowDuplicatePresences) { if (guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero) { if (SendAgentGodKillToRegion(UUID.Zero, agentID, guinfo)) { if (account != null) { m_log.InfoFormat( "[GATEKEEPER SERVICE]: Login failed for {0} {1}, reason: already logged in", account.FirstName, account.LastName); } reason = "You appear to be already logged in on the destination grid " + "Please wait a a minute or two and retry. " + "If this takes longer than a few minutes please contact the grid owner."; return(false); } } } } m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name); bool isFirstLogin = false; // // Login the presence, if it's not there yet (by the login service) // PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID); if (presence != null) // it has been placed there by the login service { isFirstLogin = true; } else { if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) { reason = "Unable to login presence"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } } // // Get the region // destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID); if (destination == null) { reason = "Destination region not found"; return(false); } m_log.DebugFormat( "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name); // // Adjust the visible name // if (account != null) { aCircuit.firstname = account.FirstName; aCircuit.lastname = account.LastName; aCircuit.displayname = account.DisplayName; } if (account == null) { if (!aCircuit.lastname.StartsWith("@")) { aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; } try { Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString()); aCircuit.lastname = "@" + uri.Authority; } catch { m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]); aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); } } // // Finally launch the agent at the destination // Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin; // Preserve our TeleportFlags we have gathered so-far loginFlag |= (Constants.TeleportFlags)aCircuit.teleportFlags; m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag); EntityTransferContext ctx = new EntityTransferContext(); if (!m_SimulationService.QueryAccess( destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(), true, aCircuit.startpos, new List <UUID>(), ctx, out reason)) { return(false); } bool didit = m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason); if (didit) { m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name); if (!isFirstLogin && m_GridUserService != null && account == null) { // Also login foreigners with GridUser service string userId = aCircuit.AgentID.ToString(); string first = aCircuit.firstname, last = aCircuit.lastname; if (last.StartsWith("@")) { string[] parts = aCircuit.firstname.Split('.'); if (parts.Length >= 2) { first = parts[0]; last = parts[1]; } } userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last; m_GridUserService.LoggedIn(userId); if (aCircuit.hasDisplayName) { m_log.InfoFormat("[GATEKEEPER SERVICE]: {0} {1} has arrived with a display name -> {2}", aCircuit.firstname, aCircuit.lastname, aCircuit.displayname); m_GridUserService.SetDisplayName(userId, aCircuit.displayname); } else { // todo: maybe have it retrieve it? m_log.InfoFormat("[GATEKEEPER SERVICE]: {0} {1} has arrived without a display name in the circuit.", aCircuit.firstname, aCircuit.lastname); } } } return(didit); }
private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason) { string myversion = String.Format("SIMULATION/{0}", VersionInfo.SimulationServiceVersion); string version; if (!simConnector.QueryAccess( region, aCircuit.AgentID, null, true, aCircuit.startpos, myversion, new List<UUID>(), out version, out reason)) return false; return simConnector.CreateAgent(null, region, aCircuit, (uint)flags, out reason); }