GatekeeperService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using System.Text.RegularExpressions;
  32. using OpenSim.Framework;
  33. using OpenSim.Services.Interfaces;
  34. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  35. using OpenSim.Server.Base;
  36. using OpenSim.Services.Connectors.InstantMessage;
  37. using OpenSim.Services.Connectors.Hypergrid;
  38. using OpenMetaverse;
  39. using Nini.Config;
  40. using log4net;
  41. namespace OpenSim.Services.HypergridService
  42. {
  43. public class GatekeeperService : IGatekeeperService
  44. {
  45. private static readonly ILog m_log =
  46. LogManager.GetLogger(
  47. MethodBase.GetCurrentMethod().DeclaringType);
  48. private static bool m_Initialized = false;
  49. private static IGridService m_GridService;
  50. private static IPresenceService m_PresenceService;
  51. private static IUserAccountService m_UserAccountService;
  52. private static IUserAgentService m_UserAgentService;
  53. private static ISimulationService m_SimulationService;
  54. private static IGridUserService m_GridUserService;
  55. private static IBansService m_BansService;
  56. private static string m_AllowedClients = string.Empty;
  57. private static string m_DeniedClients = string.Empty;
  58. private static bool m_ForeignAgentsAllowed = true;
  59. private static List<string> m_ForeignsAllowedExceptions = new List<string>();
  60. private static List<string> m_ForeignsDisallowedExceptions = new List<string>();
  61. private static UUID m_ScopeID;
  62. private static bool m_AllowTeleportsToAnyRegion;
  63. private static string m_ExternalName;
  64. private static Uri m_Uri;
  65. private static GridRegion m_DefaultGatewayRegion;
  66. private bool m_allowDuplicatePresences = false;
  67. public GatekeeperService(IConfigSource config, ISimulationService simService)
  68. {
  69. if (!m_Initialized)
  70. {
  71. m_Initialized = true;
  72. IConfig serverConfig = config.Configs["GatekeeperService"];
  73. if (serverConfig == null)
  74. throw new Exception(String.Format("No section GatekeeperService in config file"));
  75. string accountService = serverConfig.GetString("UserAccountService", String.Empty);
  76. string homeUsersService = serverConfig.GetString("UserAgentService", string.Empty);
  77. string gridService = serverConfig.GetString("GridService", String.Empty);
  78. string presenceService = serverConfig.GetString("PresenceService", String.Empty);
  79. string simulationService = serverConfig.GetString("SimulationService", String.Empty);
  80. string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
  81. string bansService = serverConfig.GetString("BansService", String.Empty);
  82. // These are mandatory, the others aren't
  83. if (gridService == string.Empty || presenceService == string.Empty)
  84. throw new Exception("Incomplete specifications, Gatekeeper Service cannot function.");
  85. string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString());
  86. UUID.TryParse(scope, out m_ScopeID);
  87. //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
  88. m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true);
  89. m_ExternalName = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
  90. new string[] { "Startup", "Hypergrid", "GatekeeperService" }, String.Empty);
  91. m_ExternalName = serverConfig.GetString("ExternalName", m_ExternalName);
  92. if (m_ExternalName != string.Empty && !m_ExternalName.EndsWith("/"))
  93. m_ExternalName = m_ExternalName + "/";
  94. try
  95. {
  96. m_Uri = new Uri(m_ExternalName);
  97. }
  98. catch
  99. {
  100. m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed gatekeeper address {0}", m_ExternalName);
  101. }
  102. Object[] args = new Object[] { config };
  103. m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
  104. m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
  105. if (accountService != string.Empty)
  106. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
  107. if (homeUsersService != string.Empty)
  108. m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
  109. if (gridUserService != string.Empty)
  110. m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
  111. if (bansService != string.Empty)
  112. m_BansService = ServerUtils.LoadPlugin<IBansService>(bansService, args);
  113. if (simService != null)
  114. m_SimulationService = simService;
  115. else if (simulationService != string.Empty)
  116. m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
  117. string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "GatekeeperService" };
  118. m_AllowedClients = Util.GetConfigVarFromSections<string>(
  119. config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
  120. m_DeniedClients = Util.GetConfigVarFromSections<string>(
  121. config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
  122. m_ForeignAgentsAllowed = serverConfig.GetBoolean("ForeignAgentsAllowed", true);
  123. LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_ForeignsAllowedExceptions);
  124. LoadDomainExceptionsFromConfig(serverConfig, "DisallowExcept", m_ForeignsDisallowedExceptions);
  125. if (m_GridService == null || m_PresenceService == null || m_SimulationService == null)
  126. throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function.");
  127. IConfig presenceConfig = config.Configs["PresenceService"];
  128. if (presenceConfig != null)
  129. {
  130. m_allowDuplicatePresences = presenceConfig.GetBoolean("AllowDuplicatePresences", m_allowDuplicatePresences);
  131. }
  132. m_log.Debug("[GATEKEEPER SERVICE]: Starting...");
  133. }
  134. }
  135. public GatekeeperService(IConfigSource config)
  136. : this(config, null)
  137. {
  138. }
  139. protected void LoadDomainExceptionsFromConfig(IConfig config, string variable, List<string> exceptions)
  140. {
  141. string value = config.GetString(variable, string.Empty);
  142. string[] parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  143. foreach (string s in parts)
  144. exceptions.Add(s.Trim());
  145. }
  146. public bool LinkRegion(string regionName, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason, out int sizeX, out int sizeY)
  147. {
  148. regionID = UUID.Zero;
  149. regionHandle = 0;
  150. sizeX = (int)Constants.RegionSize;
  151. sizeY = (int)Constants.RegionSize;
  152. externalName = m_ExternalName + ((regionName != string.Empty) ? " " + regionName : "");
  153. imageURL = string.Empty;
  154. reason = string.Empty;
  155. GridRegion region = null;
  156. m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName);
  157. if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty)
  158. {
  159. List<GridRegion> defs = m_GridService.GetDefaultHypergridRegions(m_ScopeID);
  160. if (defs != null && defs.Count > 0)
  161. {
  162. region = defs[0];
  163. m_DefaultGatewayRegion = region;
  164. }
  165. else
  166. {
  167. reason = "Grid setup problem. Try specifying a particular region here.";
  168. m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to send information. Please specify a default region for this grid!");
  169. return false;
  170. }
  171. }
  172. else
  173. {
  174. region = m_GridService.GetRegionByName(m_ScopeID, regionName);
  175. if (region == null)
  176. {
  177. reason = "Region not found";
  178. return false;
  179. }
  180. }
  181. regionID = region.RegionID;
  182. regionHandle = region.RegionHandle;
  183. sizeX = region.RegionSizeX;
  184. sizeY = region.RegionSizeY;
  185. string regionimage = "regionImage" + regionID.ToString();
  186. regionimage = regionimage.Replace("-", "");
  187. imageURL = region.ServerURI + "index.php?method=" + regionimage;
  188. return true;
  189. }
  190. public GridRegion GetHyperlinkRegion(UUID regionID, UUID agentID, string agentHomeURI, out string message)
  191. {
  192. message = null;
  193. if (!m_AllowTeleportsToAnyRegion)
  194. {
  195. // Don't even check the given regionID
  196. m_log.DebugFormat(
  197. "[GATEKEEPER SERVICE]: Returning gateway region {0} {1} @ {2} to user {3}{4} as teleporting to arbitrary regions is not allowed.",
  198. m_DefaultGatewayRegion.RegionName,
  199. m_DefaultGatewayRegion.RegionID,
  200. m_DefaultGatewayRegion.ServerURI,
  201. agentID,
  202. agentHomeURI == null ? "" : " @ " + agentHomeURI);
  203. message = "Teleporting to the default region.";
  204. return m_DefaultGatewayRegion;
  205. }
  206. GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID);
  207. if (region == null)
  208. {
  209. m_log.DebugFormat(
  210. "[GATEKEEPER SERVICE]: Could not find region with ID {0} as requested by user {1}{2}. Returning null.",
  211. regionID, agentID, (agentHomeURI == null) ? "" : " @ " + agentHomeURI);
  212. message = "The teleport destination could not be found.";
  213. return null;
  214. }
  215. m_log.DebugFormat(
  216. "[GATEKEEPER SERVICE]: Returning region {0} {1} @ {2} to user {3}{4}.",
  217. region.RegionName,
  218. region.RegionID,
  219. region.ServerURI,
  220. agentID,
  221. agentHomeURI == null ? "" : " @ " + agentHomeURI);
  222. return region;
  223. }
  224. #region Login Agent
  225. public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason)
  226. {
  227. reason = string.Empty;
  228. string authURL = string.Empty;
  229. if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
  230. authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  231. 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}",
  232. aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID,
  233. aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags,
  234. (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI));
  235. string curViewer = Util.GetViewerName(aCircuit);
  236. //
  237. // Check client
  238. //
  239. if (m_AllowedClients != string.Empty)
  240. {
  241. Regex arx = new Regex(m_AllowedClients);
  242. Match am = arx.Match(curViewer);
  243. if (!am.Success)
  244. {
  245. reason = "Login failed: client " + curViewer + " is not allowed";
  246. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer);
  247. return false;
  248. }
  249. }
  250. if (m_DeniedClients != string.Empty)
  251. {
  252. Regex drx = new Regex(m_DeniedClients);
  253. Match dm = drx.Match(curViewer);
  254. if (dm.Success)
  255. {
  256. reason = "Login failed: client " + curViewer + " is denied";
  257. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer);
  258. return false;
  259. }
  260. }
  261. //
  262. // Authenticate the user
  263. //
  264. if (!Authenticate(aCircuit))
  265. {
  266. reason = "Unable to verify identity";
  267. m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname);
  268. return false;
  269. }
  270. m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL);
  271. //
  272. // Check for impersonations
  273. //
  274. UserAccount account = null;
  275. if (m_UserAccountService != null)
  276. {
  277. // Check to see if we have a local user with that UUID
  278. account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID);
  279. if (account != null)
  280. {
  281. // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
  282. if (m_UserAgentService != null)
  283. {
  284. if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_ExternalName))
  285. {
  286. // Can't do, sorry
  287. reason = "Unauthorized";
  288. m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.",
  289. aCircuit.firstname, aCircuit.lastname);
  290. return false;
  291. }
  292. }
  293. }
  294. }
  295. //
  296. // Foreign agents allowed? Exceptions?
  297. //
  298. if (account == null)
  299. {
  300. bool allowed = m_ForeignAgentsAllowed;
  301. if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions))
  302. allowed = false;
  303. if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions))
  304. allowed = true;
  305. if (!allowed)
  306. {
  307. reason = "Destination does not allow visitors from your world";
  308. m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.",
  309. aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]);
  310. return false;
  311. }
  312. }
  313. //
  314. // Is the user banned?
  315. // This uses a Ban service that's more powerful than the configs
  316. //
  317. string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
  318. if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
  319. {
  320. reason = "You are banned from this world";
  321. m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
  322. return false;
  323. }
  324. UUID agentID = aCircuit.AgentID;
  325. if(agentID == new UUID("6571e388-6218-4574-87db-f9379718315e"))
  326. {
  327. // really?
  328. reason = "Invalid account ID";
  329. return false;
  330. }
  331. if(m_GridUserService != null)
  332. {
  333. string PrincipalIDstr = agentID.ToString();
  334. GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr);
  335. if(!m_allowDuplicatePresences)
  336. {
  337. if(guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero)
  338. {
  339. if(SendAgentGodKillToRegion(UUID.Zero, agentID, guinfo))
  340. {
  341. if(account != null)
  342. m_log.InfoFormat(
  343. "[GATEKEEPER SERVICE]: Login failed for {0} {1}, reason: already logged in",
  344. account.FirstName, account.LastName);
  345. reason = "You appear to be already logged in on the destination grid " +
  346. "Please wait a a minute or two and retry. " +
  347. "If this takes longer than a few minutes please contact the grid owner.";
  348. return false;
  349. }
  350. }
  351. }
  352. }
  353. m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name);
  354. bool isFirstLogin = false;
  355. //
  356. // Login the presence, if it's not there yet (by the login service)
  357. //
  358. PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID);
  359. if (presence != null) // it has been placed there by the login service
  360. isFirstLogin = true;
  361. else
  362. {
  363. if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID))
  364. {
  365. reason = "Unable to login presence";
  366. m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.",
  367. aCircuit.firstname, aCircuit.lastname);
  368. return false;
  369. }
  370. }
  371. //
  372. // Get the region
  373. //
  374. destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID);
  375. if (destination == null)
  376. {
  377. reason = "Destination region not found";
  378. return false;
  379. }
  380. m_log.DebugFormat(
  381. "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name);
  382. //
  383. // Adjust the visible name
  384. //
  385. if (account != null)
  386. {
  387. aCircuit.firstname = account.FirstName;
  388. aCircuit.lastname = account.LastName;
  389. }
  390. if (account == null)
  391. {
  392. if (!aCircuit.lastname.StartsWith("@"))
  393. aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
  394. try
  395. {
  396. Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
  397. aCircuit.lastname = "@" + uri.Authority;
  398. }
  399. catch
  400. {
  401. m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
  402. aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString();
  403. }
  404. }
  405. //
  406. // Finally launch the agent at the destination
  407. //
  408. Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin;
  409. // Preserve our TeleportFlags we have gathered so-far
  410. loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags;
  411. m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag);
  412. EntityTransferContext ctx = new EntityTransferContext();
  413. if (!m_SimulationService.QueryAccess(
  414. destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(),
  415. true, aCircuit.startpos, new List<UUID>(), ctx, out reason))
  416. return false;
  417. bool didit = m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason);
  418. if(didit)
  419. {
  420. m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);
  421. if(!isFirstLogin && m_GridUserService != null && account == null)
  422. {
  423. // Also login foreigners with GridUser service
  424. string userId = aCircuit.AgentID.ToString();
  425. string first = aCircuit.firstname, last = aCircuit.lastname;
  426. if (last.StartsWith("@"))
  427. {
  428. string[] parts = aCircuit.firstname.Split('.');
  429. if (parts.Length >= 2)
  430. {
  431. first = parts[0];
  432. last = parts[1];
  433. }
  434. }
  435. userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last;
  436. m_GridUserService.LoggedIn(userId);
  437. }
  438. }
  439. return didit;
  440. }
  441. protected bool Authenticate(AgentCircuitData aCircuit)
  442. {
  443. if (!CheckAddress(aCircuit.ServiceSessionID))
  444. return false;
  445. if (string.IsNullOrEmpty(aCircuit.IPAddress))
  446. {
  447. m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide a client IP address.");
  448. return false;
  449. }
  450. string userURL = string.Empty;
  451. if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
  452. userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  453. if (userURL == string.Empty)
  454. {
  455. m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL");
  456. return false;
  457. }
  458. if (userURL == m_ExternalName)
  459. {
  460. return m_UserAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID);
  461. }
  462. else
  463. {
  464. IUserAgentService userAgentService = new UserAgentServiceConnector(userURL);
  465. try
  466. {
  467. return userAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID);
  468. }
  469. catch
  470. {
  471. m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to contact authentication service at {0}", userURL);
  472. return false;
  473. }
  474. }
  475. }
  476. // Check that the service token was generated for *this* grid.
  477. // If it wasn't then that's a fake agent.
  478. protected bool CheckAddress(string serviceToken)
  479. {
  480. string[] parts = serviceToken.Split(new char[] { ';' });
  481. if (parts.Length < 2)
  482. return false;
  483. char[] trailing_slash = new char[] { '/' };
  484. string addressee = parts[0].TrimEnd(trailing_slash);
  485. string externalname = m_ExternalName.TrimEnd(trailing_slash);
  486. m_log.DebugFormat("[GATEKEEPER SERVICE]: Verifying {0} against {1}", addressee, externalname);
  487. Uri uri;
  488. try
  489. {
  490. uri = new Uri(addressee);
  491. }
  492. catch
  493. {
  494. m_log.DebugFormat("[GATEKEEPER SERVICE]: Visitor provided malformed service address {0}", addressee);
  495. return false;
  496. }
  497. return string.Equals(uri.GetLeftPart(UriPartial.Authority), m_Uri.GetLeftPart(UriPartial.Authority), StringComparison.OrdinalIgnoreCase) ;
  498. }
  499. #endregion
  500. #region Misc
  501. private bool IsException(AgentCircuitData aCircuit, List<string> exceptions)
  502. {
  503. bool exception = false;
  504. if (exceptions.Count > 0) // we have exceptions
  505. {
  506. // Retrieve the visitor's origin
  507. string userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
  508. if (!userURL.EndsWith("/"))
  509. userURL += "/";
  510. if (exceptions.Find(delegate(string s)
  511. {
  512. if (!s.EndsWith("/"))
  513. s += "/";
  514. return s == userURL;
  515. }) != null)
  516. exception = true;
  517. }
  518. return exception;
  519. }
  520. private bool SendAgentGodKillToRegion(UUID scopeID, UUID agentID , GridUserInfo guinfo)
  521. {
  522. UUID regionID = guinfo.LastRegionID;
  523. GridRegion regInfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  524. if(regInfo == null)
  525. return false;
  526. string regURL = regInfo.ServerURI;
  527. if(String.IsNullOrEmpty(regURL))
  528. return false;
  529. UUID guuid = new UUID("6571e388-6218-4574-87db-f9379718315e");
  530. GridInstantMessage msg = new GridInstantMessage();
  531. msg.imSessionID = UUID.Zero.Guid;
  532. msg.fromAgentID = guuid.Guid;
  533. msg.toAgentID = agentID.Guid;
  534. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  535. msg.fromAgentName = "GRID";
  536. msg.message = string.Format("New login detected");
  537. msg.dialog = 250; // God kick
  538. msg.fromGroup = false;
  539. msg.offline = (byte)0;
  540. msg.ParentEstateID = 0;
  541. msg.Position = Vector3.Zero;
  542. msg.RegionID = scopeID.Guid;
  543. msg.binaryBucket = new byte[1] {0};
  544. InstantMessageServiceConnector.SendInstantMessage(regURL,msg);
  545. m_GridUserService.LoggedOut(agentID.ToString(),
  546. UUID.Zero, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
  547. return true;
  548. }
  549. #endregion
  550. }
  551. }